Copyright (C) 2008-2013 All Rights Reserved. Contributor(s): Mark J Crane */ 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 = 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"]); //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++; } //set the default $save = true; //save the profile if ($save) { $orm = new orm; $orm->name('device_profiles'); if (strlen($device_profile_uuid) > 0) { $orm->uuid($device_profile_uuid); } $orm->save($_POST); $response = $orm->message; if (strlen($response['uuid']) > 0) { $device_profile_uuid = $response['uuid']; } } //write the provision files if (strlen($_SESSION['switch']['provision']['dir']) > 0) { require_once "app/provision/provision_write.php"; } //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") { $orm = new orm; $orm->name('device_profiles'); $orm->uuid($device_profile_uuid); $result = $orm->find()->get(); //$message = $orm->message; 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 .= "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 "; $sql .= " 100 "; $sql .= "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_label'] = ''; //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 " "; 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 " ".$text['label-profile_name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-profile_name']."\n"; echo "
".$text['label-keys'].""; 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_keys as $row) { //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"; echo " \n"; echo " \n"; //increment the array key $x++; } echo "
".$text['label-device_key_category']."".$text['label-device_key_id']."".$text['label-device_key_type']."".$text['label-device_key_line']."".$text['label-device_key_value']."".$text['label-device_key_extension']."".$text['label-device_key_label']." 
\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; ?> \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) { echo " $v_link_label_delete\n"; } echo "
\n"; if (strlen($text['description-keys']) > 0) { echo "
".$text['description-keys']."\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"; ?>