Copyright (C) 2013 All Rights Reserved. Contributor(s): Mark J Crane */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists('device_key_add') || permission_exists('device_key_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_key_uuid = check_str($_REQUEST["id"]); $device_uuid = check_str($_REQUEST["device_uuid"]); } else { $action = "add"; } //set the parent uuid if (strlen($_GET["device_key_uuid"]) > 0) { $device_key_uuid = check_str($_GET["device_key_uuid"]); } //get http post variables and set them to php variables if (count($_POST)>0) { $device_key_id = check_str($_POST["device_key_id"]); $device_key_category = check_str($_POST["device_key_category"]); $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"]); } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $device_key_uuid = check_str($_POST["device_key_uuid"]); } //check for all required data //if (strlen($device_key_id) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_id']."
\n"; } //if (strlen($device_key_category) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_category']."
\n"; } //if (strlen($device_key_type) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_type']."
\n"; } //if (strlen($device_key_line) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_line']."
\n"; } //if (strlen($device_key_value) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_value']."
\n"; } //if (strlen($device_key_extension) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_extension']."
\n"; } //if (strlen($device_key_label) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_label']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persistformvar.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") { if ($action == "add" && permission_exists('device_key_add')) { $sql = "insert into v_device_keys "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "device_key_uuid, "; $sql .= "device_uuid, "; $sql .= "device_key_id, "; $sql .= "device_key_category, "; $sql .= "device_key_type, "; $sql .= "device_key_line, "; $sql .= "device_key_value, "; $sql .= "device_key_extension, "; $sql .= "device_key_label "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'".uuid()."', "; $sql .= "'$device_uuid', "; $sql .= "'$device_key_id', "; $sql .= "'$device_key_category', "; $sql .= "'$device_key_type', "; $sql .= "'$device_key_line', "; $sql .= "'$device_key_value', "; $sql .= "'$device_key_extension', "; $sql .= "'$device_key_label' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); $_SESSION["message"] = $text['message-add']; header("Location: device_edit.php?id=".$device_uuid); return; } //if ($action == "add") if ($action == "update" && permission_exists('device_key_edit')) { $sql = "update v_device_keys set "; $sql .= "device_key_id = '$device_key_id', "; $sql .= "device_key_category = '$device_key_category', "; $sql .= "device_key_type = '$device_key_type', "; $sql .= "device_key_line = '$device_key_line', "; $sql .= "device_key_value = '$device_key_value', "; $sql .= "device_key_extension = '$device_key_extension', "; $sql .= "device_key_label = '$device_key_label' "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and device_key_uuid = '$device_key_uuid' "; $db->exec(check_sql($sql)); unset($sql); $_SESSION["message"] = $text['message-update']; header("Location: device_edit.php?id=".$device_uuid); return; } //if ($action == "update") } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $device_key_uuid = check_str($_GET["id"]); $sql = "select * from v_device_keys "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and device_key_uuid = '$device_key_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $device_uuid = $row["device_uuid"]; $device_key_id = $row["device_key_id"]; $device_key_category = $row["device_key_category"]; $device_key_type = $row["device_key_type"]; $device_key_line = $row["device_key_line"]; $device_key_value = $row["device_key_value"]; $device_key_extension = $row["device_key_extension"]; $device_key_label = $row["device_key_label"]; } unset ($prep_statement); } //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 " \n"; echo " "; echo "
".$text['title-device_key']."
\n"; echo " ".$text['label-device_key_category']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_key_category']."\n"; echo "
\n"; echo " ".$text['label-device_key_id']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_key_id']."\n"; echo "
\n"; echo " ".$text['label-device_key_line']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_key_line']."\n"; echo "
\n"; echo " ".$text['label-device_key_type']."\n"; echo "\n"; ?> \n"; echo $text['description-device_key_type']."\n"; echo "
\n"; echo " ".$text['label-device_key_value']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_key_value']."\n"; echo "
\n"; echo " ".$text['label-device_key_extension']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_key_extension']."\n"; echo "
\n"; echo " ".$text['label-device_key_label']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_key_label']."\n"; echo "
\n"; echo " \n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo "
"; echo "

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