Copyright (C) 2008-2016 All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions 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 = check_str($_REQUEST["id"]); } else { $action = "add"; } //get http post variables and set them to php variables if (count($_POST) > 0) { //echo ""; exit; $device_profile_name = check_str($_POST["device_profile_name"]); $device_profile_enabled = check_str($_POST["device_profile_enabled"]); $device_profile_description = check_str($_POST["device_profile_description"]); $device_key_category = check_str($_POST["device_key_category"]); $device_key_id = check_str($_POST["device_key_id"]); $device_key_type = check_str($_POST["device_key_type"]); $device_key_line = check_str($_POST["device_key_line"]); $device_key_value = check_str($_POST["device_key_value"]); $device_key_extension = check_str($_POST["device_key_extension"]); $device_key_label = check_str($_POST["device_key_label"]); //$device_setting_category = check_str($_POST["device_setting_category"]); $device_setting_subcategory = check_str($_POST["device_setting_subcategory"]); //$device_setting_name = check_str($_POST["device_setting_name"]); $device_setting_value = check_str($_POST["device_setting_value"]); $device_setting_enabled = check_str($_POST["device_setting_enabled"]); $device_setting_description = check_str($_POST["device_setting_description"]); //allow the domain_uuid to be changed only with the device_profile_domain permission if (permission_exists('device_profile_domain')) { $domain_uuid = check_str($_POST["domain_uuid"]); } else { $_POST["domain_uuid"] = $_SESSION['domain_uuid']; } } //add or update 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-profile_name']."
\n"; } if (strlen($msg) > 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 or update the database if ($_POST["persistformvar"] != "true") { //add domain_uuid to the array foreach ($_POST as $key => $value) { if (is_array($value)) { $y = 0; foreach ($value as $k => $v) { if (!isset($v["domain_uuid"])) { $_POST[$key][$y]["domain_uuid"] = $_POST["domain_uuid"]; } $y++; } } } //array cleanup $x = 0; foreach ($_POST["device_keys"] as $row) { //unset the empty row if (strlen($row["device_key_category"]) == 0) { unset($_POST["device_keys"][$x]); } //unset device_detail_uuid if the field has no value if (strlen($row["device_key_uuid"]) == 0) { unset($_POST["device_keys"][$x]["device_key_uuid"]); } //increment the row $x++; } $x = 0; foreach ($_POST["device_settings"] as $row) { //unset the empty row if (strlen($row["device_setting_subcategory"]) == 0) { unset($_POST["device_settings"][$x]); } //unset device_detail_uuid if the field has no value if (strlen($row["device_setting_uuid"]) == 0) { unset($_POST["device_settings"][$x]["device_setting_uuid"]); } //increment the row $x++; } //prepare the array $array['device_profiles'][] = $_POST; //set the default $save = true; //save the profile if ($save) { $database = new database; $database->app_name = 'devices'; $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; if (strlen($device_profile_uuid) > 0) { $database->uuid($device_profile_uuid); } $database->save($array); $response = $database->message; if (strlen($response['uuid']) > 0) { $device_profile_uuid = $response['uuid']; } } //write the provision files if (strlen($_SESSION['provision']['path']['text']) > 0) { $prov = new provision; $prov->domain_uuid = $domain_uuid; $response = $prov->write(); } //set the message if (!isset($_SESSION['message'])) { if ($save) { if ($action == "add") { //save the message to a session variable $_SESSION['message'] = $text['message-add']; } if ($action == "update") { //save the message to a session variable $_SESSION['message'] = $text['message-update']; } //redirect the browser header("Location: device_profile_edit.php?id=".$device_profile_uuid); exit; } } } //if ($_POST["persistformvar"] != "true") } //(count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $sql = "select * from v_device_profiles "; $sql .= "where device_profile_uuid = '$device_profile_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $device_profile_name = $row["device_profile_name"]; $device_profile_domain_uuid = $row["domain_uuid"]; $device_profile_enabled = $row["device_profile_enabled"]; $device_profile_description = $row["device_profile_description"]; } unset ($prep_statement); } //set the sub array index $x = "999"; //get device keys $sql = "SELECT * FROM v_device_keys "; $sql .= "WHERE device_profile_uuid = '".$device_profile_uuid."' "; $sql .= "ORDER by "; $sql .= "device_key_vendor asc, "; $sql .= "CASE device_key_category "; $sql .= "WHEN 'line' THEN 1 "; $sql .= "WHEN 'memory' THEN 2 "; $sql .= "WHEN 'programmable' THEN 3 "; $sql .= "WHEN 'expansion' THEN 4 "; $sql .= "ELSE 100 END, "; if ($db_type == "mysql") { $sql .= "device_key_id asc "; } else { $sql .= "cast(device_key_id as numeric) asc "; } $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $device_keys = $prep_statement->fetchAll(PDO::FETCH_NAMED); $device_keys[$x]['device_key_category'] = ''; $device_keys[$x]['device_key_id'] = ''; $device_keys[$x]['device_key_type'] = ''; $device_keys[$x]['device_key_line'] = ''; $device_keys[$x]['device_key_value'] = ''; $device_keys[$x]['device_key_extension'] = ''; $device_keys[$x]['device_key_protected'] = ''; $device_keys[$x]['device_key_label'] = ''; //get the vendors $sql = "SELECT * "; $sql .= "FROM v_device_vendors as v "; $sql .= "where enabled = 'true' "; $sql .= "order by name asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $vendors = $prep_statement->fetchAll(PDO::FETCH_NAMED); //get the vendor functions $sql = "SELECT v.name as vendor_name, f.name, f.value "; $sql .= "FROM v_device_vendors as v, v_device_vendor_functions as f "; $sql .= "where v.device_vendor_uuid = f.device_vendor_uuid "; $sql .= "and v.enabled = 'true' "; $sql .= "and f.enabled = 'true' "; $sql .= "order by v.name asc, f.name asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $vendor_functions = $prep_statement->fetchAll(PDO::FETCH_NAMED); //get the vendor count $vendor_count = 0; foreach($device_keys as $row) { if ($previous_vendor != $row['device_key_vendor']) { $previous_vendor = $row['device_key_vendor']; $vendor_count++; } } //get device settings $sql = "SELECT * FROM v_device_settings "; $sql .= "WHERE device_profile_uuid = '".$device_profile_uuid."' "; $sql .= "ORDER by device_setting_subcategory asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $device_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); $device_settings[$x]['device_setting_name'] = ''; $device_settings[$x]['device_setting_value'] = ''; $device_settings[$x]['enabled'] = ''; $device_settings[$x]['device_setting_description'] = ''; //show the header require_once "resources/header.php"; $document['title'] = $text['title-profile']; //javascript to change select to input and back again ?> \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " "; echo " "; echo " "; echo " "; //device settings echo " "; echo " "; echo " \n"; echo " \n"; if (permission_exists('device_profile_domain')) { 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 "
"; echo " ".$text['header-profile'].""; echo "

"; echo " ".$text['description-profile']; echo "

"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-profile_name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-profile_name']."\n"; echo "
".$text['label-keys'].""; echo " \n"; if ($vendor_count == 0) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('device_key_extension')) { echo " \n"; } if (permission_exists('device_key_protected')) { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; } $x = 0; foreach($device_keys as $row) { //set the device vendor $device_vendor = $row['device_key_vendor']; //get the device key vendor from the key type foreach ($vendor_functions as $function) { if ($row['device_key_vendor'] == $function['vendor_name'] && $row['device_key_type'] == $function['value']) { $device_key_vendor = $function['vendor_name']; } } //set the column names if ($previous_device_key_vendor != $row['device_key_vendor']) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('device_key_extension')) { echo " \n"; } if (permission_exists('device_key_protected')) { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; } //determine whether to hide the element if (strlen($device_key_uuid) == 0) { $element['hidden'] = false; $element['visibility'] = "visibility:visible;"; } else { $element['hidden'] = true; $element['visibility'] = "visibility:hidden;"; } //add the primary key uuid if (strlen($row['device_key_uuid']) > 0) { echo " \n"; } //show all the rows in the array echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('device_key_extension')) { echo "\n"; } if (permission_exists('device_key_protected')) { echo " \n"; } echo "\n"; echo "\n"; echo " \n"; //set the previous vendor $previous_device_key_vendor = $row['device_key_vendor']; //increment the array key $x++; } echo "
".$text['label-device_key_category']."".$text['label-device_key_id']."".$text['label-device_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_category']."".$text['label-device_key_id']."".$text['label-device_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']." 
\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"; if (strlen($row['device_key_uuid']) > 0) { if (permission_exists('device_key_delete')) { echo " $v_link_label_delete\n"; } } echo "
\n"; if (strlen($text['description-keys']) > 0) { echo "
".$text['description-keys']."\n"; } echo "
".$text['label-settings'].""; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x = 0; foreach($device_settings as $row) { //determine whether to hide the element if (strlen($device_setting_uuid) == 0) { $element['hidden'] = false; $element['visibility'] = "visibility:visible;"; } else { $element['hidden'] = true; $element['visibility'] = "visibility:hidden;"; } //add the primary key uuid if (strlen($row['device_setting_uuid']) > 0) { echo " \n"; } //show alls rows in the array echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (strlen($text['description-settings']) > 0) { echo "
".$text['description-settings']."\n"; } echo " "; 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"; if (strlen($row['device_setting_uuid']) > 0) { echo " $v_link_label_delete\n"; } echo "
\n"; echo " \n"; */ echo "
\n"; echo "
\n"; echo " ".$text['label-profile_domain']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo " ".$text['label-profile_enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-profile_enabled']."\n"; echo "
\n"; echo " ".$text['label-profile_description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-profile_description']."\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo "
"; echo "

"; echo ""; //show the footer require_once "resources/footer.php"; ?>