<?php
	//Gets the available administration sections
	$url = "https://afsshareportal.com/siteContent/adminTypes.php";
  
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, false);
	$offeringsResult=curl_exec($ch);
	$theOfferings = json_decode($offeringsResult, true);
	
	curl_close($ch);
	
	
	//Gets store specific add-ons
	$url2 = "https://afsshareportal.com/lookUpFeatures.php?action=getASite&website_url=" . urlencode(WEB_URL);
	  
	$ch2 = curl_init();
	curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch2, CURLOPT_URL, $url2);
	curl_setopt($ch2, CURLOPT_HEADER, false);
	$result=curl_exec($ch2);
	
	$websiteInfo = json_decode($result, true);
	$websiteInfo = $websiteInfo[0];
	curl_close($ch2);
	
	
	$finalOfferings = array();
	
	//limits which add-on portions are visible in the admin dashboard
	foreach($theOfferings as $key => $offering){
	  if($offering['level'] <= $websiteInfo['website_level']){
		array_push($finalOfferings, $offering);
	  }
	  else if($key == "noPurchase"){
		if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/rewards.php')){
		  array_push($finalOfferings, $theOfferings['noPurchase']);
		}
	  }
	  else if(array_key_exists($key, $websiteInfo) && $websiteInfo[$key] == 1){
		array_push($finalOfferings, $offering);
	  }
	}
?>