get();
//action add or update
if (is_uuid($_REQUEST["id"])) {
$action = "update";
$sofia_global_setting_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
}
//get http post variables and set them to php variables
if (is_array($_POST)) {
$global_setting_name = $_POST["global_setting_name"];
$global_setting_value = $_POST["global_setting_value"];
$global_setting_enabled = $_POST["global_setting_enabled"];
$global_setting_description = $_POST["global_setting_description"];
}
//process the user data and save it to the database
if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: sofia_global_settings.php');
exit;
}
//process the http post data by submitted action
if ($_POST['action'] != '' && !empty($_POST['action'])) {
//prepare the array(s)
//send the array to the database class
switch ($_POST['action']) {
case 'copy':
if (permission_exists('sofia_global_setting_add')) {
$obj = new database;
$obj->copy($array);
}
break;
case 'delete':
if (permission_exists('sofia_global_setting_delete')) {
$obj = new database;
$obj->delete($array);
}
break;
case 'toggle':
if (permission_exists('sofia_global_setting_update')) {
$obj = new database;
$obj->toggle($array);
}
break;
}
//redirect the user
if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) {
header('Location: sofia_global_setting_edit.php?id='.$id);
exit;
}
}
//check for all required data
$msg = '';
if (empty($global_setting_name)) { $msg .= $text['message-required']." ".$text['label-global_setting_name']."
\n"; }
if (empty($global_setting_value)) { $msg .= $text['message-required']." ".$text['label-global_setting_value']."
\n"; }
if (empty($global_setting_enabled)) { $msg .= $text['message-required']." ".$text['label-global_setting_enabled']."
\n"; }
//if (empty($global_setting_description)) { $msg .= $text['message-required']." ".$text['label-global_setting_description']."
\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
| \n";
echo $msg." "; echo " |