$value) {
$text[$key] = $value[$_SESSION['domain']['language']['code']];
}
//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_type = check_str($_POST["device_key_type"]);
$device_key_value = check_str($_POST["device_key_value"]);
$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_type) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_type']."
\n"; }
//if (strlen($device_key_value) == 0) { $msg .= $text['message-required']." ".$text['label-device_key_value']."
\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_type, ";
$sql .= "device_key_value, ";
$sql .= "device_key_label ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$domain_uuid', ";
$sql .= "'".uuid()."', ";
$sql .= "'$device_uuid', ";
$sql .= "'$device_key_id', ";
$sql .= "'$device_key_type', ";
$sql .= "'$device_key_value', ";
$sql .= "'$device_key_label' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
require_once "resources/header.php";
echo "\n";
echo "\n";
echo " ".$text['message-add']."\n";
echo "
\n";
require_once "resources/footer.php";
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_type = '$device_key_type', ";
$sql .= "device_key_value = '$device_key_value', ";
$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);
require_once "resources/header.php";
echo "\n";
echo "\n";
echo " ".$text['message-update']."\n";
echo "
\n";
require_once "resources/footer.php";
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_key_id = $row["device_key_id"];
$device_key_type = $row["device_key_type"];
$device_key_value = $row["device_key_value"];
$device_key_label = $row["device_key_label"];
}
unset ($prep_statement);
}
//show the header
require_once "resources/header.php";
//show the content
echo "";
echo "
\n";
echo "\n";
echo " \n";
echo " ";
echo " | ";
echo "
";
echo "
";
echo "
";
//include the footer
require_once "resources/footer.php";
?>