<?php

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

/**
* @desc This function will enable or disable the emailalerts.
*/
function toggleEmailAlerts() {
    $using_emailalerts = getGlobalSetting("ToggleEmailAlerts",1);
    if($using_emailalerts == 1){
        setGlobalSetting("ToggleEmailAlerts",0);
        $using_emailalerts = 0;
        return _DISABLED_ALERTS;
    } else if($using_emailalerts == 0){
        setGlobalSetting("ToggleEmailAlerts",1);
        $using_emailalerts = 1;
        return _ENABLED_ALERTS;
    }
    return false;
}


if (isset($_REQUEST["toggle_emailalerts"])==1) {
    $res = toggleEmailAlerts();
    if ($res==false) {
    	echo '{ "Status": "Error", "Message": "'. _TOGGLE_ALERTS_ERROR .'" }';
    } else {
    	echo '{ "Status": "Success", "Message": "'.$res.'" }';
    }
     
} else {
	
	# we are not setting the value, just requesting it
	if (getGlobalSetting("ToggleEmailAlerts",1)==1) {
        echo '{ "Status": "'. _ENABLED .'" }';

    } else {
        echo '{ "Status": "'. _DISABLED .'" }';
    }
}
?>