diff --git a/app/devices/device_dashboard.php b/app/devices/device_dashboard.php new file mode 100644 index 0000000000..edcbd8e6ec --- /dev/null +++ b/app/devices/device_dashboard.php @@ -0,0 +1,531 @@ + + Copyright (C) 2008-2015 All Rights Reserved. + +*/ + +//includes + require_once "root.php"; + require_once "resources/require.php"; + +//check permissions + require_once "resources/check_auth.php"; + if (permission_exists('device_add') || permission_exists('device_edit')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get($_SESSION['domain']['language']['code'], 'app/devices'); + +//include the device class + require_once "app/devices/resources/classes/device.php"; + +//action add or update + $action = "update"; + +//add or update the database + if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { + + //add or update the database + if ($_POST["persistformvar"] != "true") { + + //update the device keys + foreach ($_POST['device_keys'] as &$row) { + //validate the data + $valid_data = true; + if (!is_uuid($row["device_key_uuid"])) { $valid_data = false; } + if (!is_numeric($row["device_key_id"])) { $valid_data = false; } + if (strlen($row["device_key_type"]) > 25) { $valid_data = false; } + if (strlen($row["device_key_value"]) > 25) { $valid_data = false; } + if (strlen($row["device_key_label"]) > 25) { $valid_data = false; } + //escape characters in the string + $device_key_uuid = check_str($row["device_key_uuid"]); + $device_key_id = check_str($row["device_key_id"]); + $device_key_type = check_str($row["device_key_type"]); + $device_key_value = check_str($row["device_key_value"]); + $device_key_label = check_str($row["device_key_label"]); + //sql update + $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 = '".$_SESSION['domain_uuid']."' "; + $sql .= "and device_key_uuid = '".$device_key_uuid."' "; + if ($valid_data) { + $db->exec(check_sql($sql)); + //echo "valid: ".$sql."\n"; + } + else { + //echo "invalid: ".$sql."\n"; + } + unset($sql); + } + + //write the provision files + if (strlen($_SESSION['provision']['path']['text']) > 0) { + require_once "app/provision/provision_write.php"; + } + + //set the message + if (!isset($_SESSION['message'])) { + //set the message + 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: /core/user_settings/user_dashboard.php"); + exit; + } + + } //if ($_POST["persistformvar"] != "true") + } //(count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) + +//set the sub array index + $x = "999"; + +//get device keys + $sql = "SELECT * from v_device_keys "; + $sql .= "where device_uuid in "; + $sql .= "( "; + $sql .= " select device_uuid from "; + $sql .= " v_devices where user_uuid = '".$_SESSION['user_uuid']."' "; + $sql .= ") "; + $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); + +//show the header + //require_once "resources/header.php"; + +//show the content + echo "
"; + +//show the footer + //require_once "resources/footer.php"; + +?>