<?php

$accessControl = array(
    "Admin" => true
);
require_once "../../AccessControl.php";

$default_settings = array(
	"profileLimit" => 1,
	"trackermode_0" => false,
	"trackermode_1" => true,
	"trackermode_2" => false,
	"trackermode_3" => false,
	"accessUpdateLogs" => false,
	"accessAddProfile" => false,
	"accessEditProfile" => false,
	"changeAccountInfo" => true
);

$signup = getGlobalSetting("SignupPage", 0 );
$settings = getGlobalSetting("SignupPageSettings", json_encode($default_settings) );
$settings = json_decode($settings , true);


if(isset($_POST['profileLimit'])){
	# Set the variable to 0 when empty
	if(empty($_POST['profileLimit'])){ 
		$settings['profileLimit'] = 0; 
	} else {
		$settings['profileLimit'] = $_POST['profileLimit'];
	}

	foreach ($default_settings as $key => $v) {
		if($key != "profileLimit"){
			$settings[$key] = (isset($_POST[$key])); 
		}
	}
	setGlobalSetting("SignupPageSettings", json_encode($settings) );
	echo '{ "Status": "Success", "Message": "'. _SETTINGS_SAVED .'", "Settings" : '. json_encode($settings) .' }';

} else if (isset($_REQUEST["toggle"])==1) {

	if($signup){
		setGlobalSetting("SignupPage", 0);
		echo '{ "Status": "Success", "Message": "'. _DISABLED .'" }';
    } else {
		setGlobalSetting("SignupPage", 1);
		echo '{ "Status": "Success", "Message": "'. _ENABLED .'" }';
    }
} else {
	if($signup == 1){
		echo '{ "Status": "Enabled", "Settings" : '. json_encode($settings) .' }';
	} else {
	    echo '{ "Status": "Disabled", "Settings" : '. json_encode($settings) .' }';
	}	
}
?>