Copyright (C) 2019 All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; //check permissions require_once "resources/check_auth.php"; if (permission_exists('device_profile_add') || permission_exists('device_profile_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $device_profile_uuid = $_REQUEST["id"]; $id = $_REQUEST["id"]; } else { $action = "add"; } //get http post variables and set them to php variables if (is_array($_POST)) { $device_profile_uuid = $_POST["device_profile_uuid"]; $device_profile_name = $_POST["device_profile_name"]; $device_profile_keys = $_POST["device_profile_keys"]; $device_profile_settings = $_POST["device_profile_settings"]; $device_profile_enabled = $_POST["device_profile_enabled"]; $device_profile_description = $_POST["device_profile_description"]; } //process the user data and save it to the database if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //check for all required data $msg = ''; if (strlen($device_profile_name) == 0) { $msg .= $text['message-required']." ".$text['label-device_profile_name']."
\n"; } //if (strlen($device_profile_keys) == 0) { $msg .= $text['message-required']." ".$text['label-device_profile_keys']."
\n"; } //if (strlen($device_profile_settings) == 0) { $msg .= $text['message-required']." ".$text['label-device_profile_settings']."
\n"; } //if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; } if (strlen($device_profile_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-device_profile_enabled']."
\n"; } //if (strlen($device_profile_description) == 0) { $msg .= $text['message-required']." ".$text['label-device_profile_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; } //set the domain_uuid $_POST["domain_uuid"] = $_SESSION["domain_uuid"]; //add the device_profile_uuid if (strlen($_POST["device_profile_uuid"]) == 0) { $device_profile_uuid = uuid(); } //prepare the array $array['device_profiles'][0]["device_profile_uuid"] = $device_profile_uuid; $array['device_profiles'][0]["device_profile_name"] = $device_profile_name; $array['device_profiles'][0]["domain_uuid"] = $domain_uuid; $array['device_profiles'][0]["device_profile_enabled"] = $device_profile_enabled; $array['device_profiles'][0]["device_profile_description"] = $device_profile_description; $y = 0; foreach ($device_profile_keys as $row) { if (strlen($row['profile_key_category']) > 0) { $array['device_profiles'][0]['device_profile_keys'][$y]["device_profile_key_uuid"] = $row["device_profile_key_uuid"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_category"] = $row["profile_key_category"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_id"] = $row["profile_key_id"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_vendor"] = $row["profile_key_vendor"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_type"] = $row["profile_key_type"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_line"] = $row["profile_key_line"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_value"] = $row["profile_key_value"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_extension"] = $row["profile_key_extension"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_protected"] = $row["profile_key_protected"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_label"] = $row["profile_key_label"]; $array['device_profiles'][0]['device_profile_keys'][$y]["profile_key_icon"] = $row["profile_key_icon"]; $y++; } } $y = 0; foreach ($device_profile_settings as $row) { if (strlen($row['profile_setting_name']) > 0) { $array['device_profiles'][0]['device_profile_settings'][$y]["device_profile_setting_uuid"] = $row["device_profile_setting_uuid"]; $array['device_profiles'][0]['device_profile_settings'][$y]["profile_setting_name"] = $row["profile_setting_name"]; $array['device_profiles'][0]['device_profile_settings'][$y]["profile_setting_value"] = $row["profile_setting_value"]; $array['device_profiles'][0]['device_profile_settings'][$y]["profile_setting_enabled"] = $row["profile_setting_enabled"]; $array['device_profiles'][0]['device_profile_settings'][$y]["profile_setting_description"] = $row["profile_setting_description"]; $y++; } } //save to the data $database = new database; $database->app_name = 'Device Profiles'; $database->app_uuid = 'bb2531c3-97e6-428f-9a19-cbac1b96f5b7'; $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: device_profile_edit.php?id='.$device_profile_uuid); return; } } //(is_array($_POST) && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (is_array($_GET) && $_POST["persistformvar"] != "true") { $device_profile_uuid = $_GET["id"]; $sql = "select * from v_device_profiles "; $sql .= "where device_profile_uuid = :device_profile_uuid "; //$sql .= "and domain_uuid = :domain_uuid "; //$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['device_profile_uuid'] = $device_profile_uuid; $database = new database; $result = $database->execute($sql, $parameters, 'all'); foreach ($result as &$row) { $device_profile_name = $row["device_profile_name"]; $device_profile_keys = $row["device_profile_keys"]; $device_profile_settings = $row["device_profile_settings"]; $device_profile_enabled = $row["device_profile_enabled"]; $device_profile_description = $row["device_profile_description"]; } unset ($sql, $parameters); } //get the child data if (strlen($device_profile_uuid) > 0) { $sql = "select * from v_device_profile_keys "; $sql .= "where device_profile_uuid = :device_profile_uuid "; //$sql .= "and domain_uuid = '".$domain_uuid."' "; $sql .= "order by profile_key_id asc"; //$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['device_profile_uuid'] = $device_profile_uuid; $database = new database; $device_profile_keys = $database->execute($sql, $parameters, 'all'); unset ($sql, $parameters); } //add the $device_profile_key_uuid if (strlen($device_profile_key_uuid) == 0) { $device_profile_key_uuid = uuid(); } //add an empty row $x = count($device_profile_keys); $device_profile_keys[$x]['domain_uuid'] = $_SESSION['domain_uuid']; $device_profile_keys[$x]['device_profile_uuid'] = $device_profile_uuid; $device_profile_keys[$x]['device_profile_key_uuid'] = uuid(); $device_profile_keys[$x]['profile_key_category'] = ''; $device_profile_keys[$x]['profile_key_id'] = ''; $device_profile_keys[$x]['profile_key_vendor'] = ''; $device_profile_keys[$x]['profile_key_type'] = ''; $device_profile_keys[$x]['profile_key_line'] = ''; $device_profile_keys[$x]['profile_key_value'] = ''; $device_profile_keys[$x]['profile_key_extension'] = ''; $device_profile_keys[$x]['profile_key_protected'] = ''; $device_profile_keys[$x]['profile_key_label'] = ''; $device_profile_keys[$x]['profile_key_icon'] = ''; //get the child data if (strlen($device_profile_uuid) > 0) { $sql = "select * from v_device_profile_settings "; $sql .= "where device_profile_uuid = :device_profile_uuid "; //$sql .= "and domain_uuid = '".$domain_uuid."' "; $sql .= "order by profile_setting_name asc"; //$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['device_profile_uuid'] = $device_profile_uuid; $database = new database; $device_profile_settings = $database->execute($sql, $parameters, 'all'); unset ($sql, $parameters); } //add the $device_profile_setting_uuid if (strlen($device_profile_setting_uuid) == 0) { $device_profile_setting_uuid = uuid(); } //add an empty row $x = count($device_profile_settings); $device_profile_settings[$x]['domain_uuid'] = $_SESSION['domain_uuid']; $device_profile_settings[$x]['device_profile_uuid'] = $device_profile_uuid; $device_profile_settings[$x]['device_profile_setting_uuid'] = uuid(); $device_profile_settings[$x]['profile_setting_name'] = ''; $device_profile_settings[$x]['profile_setting_value'] = ''; $device_profile_settings[$x]['profile_setting_enabled'] = ''; $device_profile_settings[$x]['profile_setting_description'] = ''; //show the header require_once "resources/header.php"; //show the content 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 "\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 " "; echo "
".$text['title-device_profile']."

\n"; echo " "; echo " "; echo " "; echo "
\n"; echo " ".$text['description-device_profiles']."

\n"; echo "
\n"; echo " ".$text['label-device_profile_name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_profile_name']."\n"; echo "
\n"; echo " ".$text['label-device_profile_keys']."\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"; $x = 0; foreach($device_profile_keys as $row) { 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"; $x++; } echo "
".$text['label-device_key_category']."".$text['label-device_key_id']."".$text['label-device_key_vendor']."".$text['label-device_key_type']."".$text['label-device_key_line']."".$text['label-device_key_value']."".$text['label-device_key_extension']."".$text['label-device_key_protected']."".$text['label-device_key_label']."".$text['label-device_key_icon']."
\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 " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo $text['description-profile_key_icon']."\n"; echo "
\n"; echo " ".$text['label-device_profile_settings']."\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x = 0; foreach($device_profile_settings as $row) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x++; } echo "
".$text['label-device_setting_name']."".$text['label-device_setting_value']."".$text['label-enabled']."".$text['label-device_setting_description']."
\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['description-profile_setting_description']."\n"; echo "
\n"; echo " ".$text['label-domain_uuid']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-domain_uuid']."\n"; echo "
\n"; echo " ".$text['label-device_profile_enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_profile_enabled']."\n"; echo "
\n"; echo " ".$text['label-device_profile_description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_profile_description']."\n"; echo "
\n"; echo " \n"; echo " \n"; echo "
"; echo "
"; echo "

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