Portions created by the Initial Developer are Copyright (C) 2018 - 2020
the Initial Developer. All Rights Reserved.
*/
// includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
// check permissions
if (!(permission_exists('service_add') || permission_exists('service_edit'))) {
echo "access denied";
exit;
}
// add multi-lingual support
$language = new text;
$text = $language->get();
// add the settings object
$settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
// set from session variables
$button_icon_back = $settings->get('theme', 'button_icon_back', '');
$button_icon_copy = $settings->get('theme', 'button_icon_copy', '');
$button_icon_delete = $settings->get('theme', 'button_icon_delete', '');
$button_icon_save = $settings->get('theme', 'button_icon_save', '');
$input_toggle_style = $settings->get('theme', 'input_toggle_style', 'switch round');
// action add or update
if (is_uuid($_REQUEST["id"])) {
$action = "update";
$service_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
}
// get http post variables and set them to php variables
if (!empty($_POST)) {
$service_name = $_POST["service_name"];
$service_category = $_POST["service_category"];
$service_enabled = $_POST["service_enabled"];
$service_description = $_POST["service_description"];
}
// process the data and save it to the database
if (!empty($_POST) && empty($_POST["persistformvar"])) {
// validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: services.php');
exit;
}
// process the http post data by submitted action
if ($_POST['action'] != '' && strlen($_POST['action']) > 0) {
// prepare the array(s)
switch ($_POST['action']) {
case 'delete':
if (permission_exists('service_delete')) {
$obj = new services;
$obj->delete($array);
}
break;
case 'toggle':
if (permission_exists('service_update')) {
$obj = new services;
$obj->toggle($array);
}
break;
}
// redirect the user
if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) {
header('Location: service_edit.php?id='.$id);
exit;
}
}
// check for all required data
$msg = '';
if (strlen($service_name) == 0) { $msg .= $text['message-required']." ".$text['label-service_name']."
\n"; }
if (strlen($service_category) == 0) { $msg .= $text['message-required']." ".$text['label-service_category']."
\n"; }
if (strlen($service_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-service_enabled']."
\n"; }
// if (strlen($service_description) == 0) { $msg .= $text['message-required']." ".$text['label-service_description']."
\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
| \n";
echo $msg." "; echo " |