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 "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } // add the service_uuid if (!is_uuid($_POST["service_uuid"])) { $service_uuid = uuid(); } // prepare the array $array['services'][0]['service_uuid'] = $service_uuid; $array['services'][0]['service_name'] = $service_name; $array['services'][0]['service_category'] = $service_category; $array['services'][0]['service_enabled'] = $service_enabled; $array['services'][0]['service_description'] = $service_description; // save the data $database->save($array); // redirect the user if (isset($action)) { if ($action == "add") { $_SESSION["message"] = $text['message-add']; } if ($action == "update") { $_SESSION["message"] = $text['message-update']; } // header('Location: services.php'); header('Location: service_edit.php?id='.urlencode($service_uuid)); return; } } // pre-populate the form if (is_array($_GET) && $_POST["persistformvar"] != "true") { $sql = "select "; $sql .= " service_uuid, "; $sql .= " service_name, "; $sql .= " service_category, "; $sql .= " service_enabled , "; $sql .= " service_description "; $sql .= "from v_services "; $sql .= "where service_uuid = :service_uuid "; $parameters['service_uuid'] = $service_uuid; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $service_name = $row["service_name"]; $service_category = $row["service_category"]; $service_enabled = $row["service_enabled"]; $service_description = $row["service_description"]; } unset($sql, $parameters, $row); } // create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); // show the header $document['title'] = $text['title-service']; require_once "resources/header.php"; // show the content echo "
\n"; echo "\n"; echo "
\n"; echo "
".$text['title-service']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$button_icon_back,'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'services.php']); if ($action == 'update') { if (permission_exists('_add')) { echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$button_icon_copy,'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); } if (permission_exists('_delete')) { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$button_icon_delete,'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } } echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$button_icon_save,'id'=>'btn_save','collapse'=>'hide-xs']); echo "
\n"; echo "
\n"; echo "
\n"; echo $text['title_description-services']."\n"; echo "

\n"; if ($action == 'update') { if (permission_exists('service_add')) { echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]); } if (permission_exists('service_delete')) { echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]); } } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-service_name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-service_name']."\n"; echo "
\n"; echo " ".$text['label-service_category']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-service_category']."\n"; echo "
\n"; echo " ".$text['label-service_enabled']."\n"; echo "\n"; if ($input_toggle_style_switch) { echo " \n"; } echo " \n"; if ($input_toggle_style_switch) { echo " \n"; echo " \n"; } echo "
\n"; echo $text['description-service_enabled']."\n"; echo "
\n"; echo " ".$text['label-service_description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-service_description']."\n"; echo "
"; echo "

"; echo "\n"; echo "
"; // include the footer require_once "resources/footer.php"; ?>