Update device_dashboard.php

Fix device key dashboard edit only.
This commit is contained in:
FusionPBX 2016-06-10 12:23:01 -06:00 committed by GitHub
parent c30efdaa21
commit e75a09d01d
1 changed files with 72 additions and 59 deletions

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2008-2016 All Rights Reserved. Copyright (C) 2016 All Rights Reserved.
*/ */
@ -40,10 +40,7 @@
$text = $language->get($_SESSION['domain']['language']['code'], 'app/devices'); $text = $language->get($_SESSION['domain']['language']['code'], 'app/devices');
//include the device class //include the device class
require_once "app/devices/resources/classes/device.php"; //require_once "app/devices/resources/classes/device.php";
//action add or update
$action = "update";
//add or update the database //add or update the database
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
@ -51,15 +48,17 @@
//add or update the database //add or update the database
if ($_POST["persistformvar"] != "true") { if ($_POST["persistformvar"] != "true") {
//update the device keys //add or update the device keys
foreach ($_POST['device_keys'] as &$row) { foreach ($_POST['device_keys'] as &$row) {
//validate the data //validate the data
$valid_data = true; $valid_data = true;
//if (!is_uuid($row["device_key_uuid"])) { $valid_data = false; } //if (!is_uuid($row["device_key_uuid"])) { $valid_data = false; }
if (!is_numeric($row["device_key_id"])) { $valid_data = false; } if (isset($row["device_key_id"])) {
if (strlen($row["device_key_type"]) > 25) { $valid_data = false; } if (!is_numeric($row["device_key_id"])) { $valid_data = false; echo $row["device_key_id"]." id "; }
if (strlen($row["device_key_value"]) > 25) { $valid_data = false; } }
if (strlen($row["device_key_label"]) > 25) { $valid_data = false; } if (strlen($row["device_key_type"]) > 25) { $valid_data = false; echo "type "; }
if (strlen($row["device_key_value"]) > 25) { $valid_data = false; echo "value "; }
if (strlen($row["device_key_label"]) > 25) { $valid_data = false; echo "label "; }
//escape characters in the string //escape characters in the string
$device_uuid = check_str($row["device_uuid"]); $device_uuid = check_str($row["device_uuid"]);
$device_key_uuid = check_str($row["device_key_uuid"]); $device_key_uuid = check_str($row["device_key_uuid"]);
@ -70,48 +69,60 @@
$device_key_label = check_str($row["device_key_label"]); $device_key_label = check_str($row["device_key_label"]);
$device_key_category = check_str($row["device_key_category"]); $device_key_category = check_str($row["device_key_category"]);
$device_key_vendor = check_str($row["device_key_vendor"]); $device_key_vendor = check_str($row["device_key_vendor"]);
//sql update //sql update
if (strlen($device_key_uuid) == 0) { if (strlen($device_key_uuid) == 0) {
if (permission_exists('device_key_add') && strlen($device_key_type) > 0 && strlen($device_key_value) > 0) { if (permission_exists('device_key_add') && strlen($device_key_type) > 0 && strlen($device_key_value) > 0) {
$device_key_uuid = uuid();
$sql = "insert into v_device_keys "; //create the primary keys
$sql .= "("; $device_key_uuid = uuid();
$sql .= "domain_uuid, ";
$sql .= "device_key_uuid, "; //insert the keys
$sql .= "device_uuid, "; $sql = "insert into v_device_keys ";
$sql .= "device_key_id, "; $sql .= "(";
$sql .= "device_key_type, "; $sql .= "domain_uuid, ";
$sql .= "device_key_line, "; $sql .= "device_key_uuid, ";
$sql .= "device_key_value, "; $sql .= "device_uuid, ";
$sql .= "device_key_label, "; $sql .= "device_key_id, ";
$sql .= "device_key_category, "; $sql .= "device_key_type, ";
$sql .= "device_key_vendor "; $sql .= "device_key_line, ";
$sql .= ") "; $sql .= "device_key_value, ";
$sql .= "VALUES ("; $sql .= "device_key_label, ";
$sql .= "'".$_SESSION['domain_uuid']."', "; $sql .= "device_key_category, ";
$sql .= "'".$device_key_uuid."', "; $sql .= "device_key_vendor ";
$sql .= "'".$device_uuid."', "; $sql .= ") ";
$sql .= "'".$device_key_id."', "; $sql .= "VALUES (";
$sql .= "'".$device_key_type."', "; $sql .= "'".$_SESSION['domain_uuid']."', ";
$sql .= "'".$device_key_line."', "; $sql .= "'".$device_key_uuid."', ";
$sql .= "'".$device_key_value."', "; $sql .= "'".$device_uuid."', ";
$sql .= "'".$device_key_label."', "; $sql .= "'".$device_key_id."', ";
$sql .= "'".$device_key_category."', "; $sql .= "'".$device_key_type."', ";
$sql .= "'".$device_key_vendor."' "; $sql .= "'".$device_key_line."', ";
$sql .= ")"; $sql .= "'".$device_key_value."', ";
//echo $sql; $sql .= "'".$device_key_label."', ";
$sql .= "'".$device_key_category."', ";
$sql .= "'".$device_key_vendor."' ";
$sql .= ");";
//echo $sql;
//action add or update
$action = "add";
} }
} }
else { else {
$sql = "update v_device_keys set "; //action add or update
if (permission_exists('device_key_id')) { $action = "update";
$sql .= "device_key_id = '".$device_key_id."', ";
} //update the device keys
$sql .= "device_key_type = '".$device_key_type."', "; $sql = "update v_device_keys set ";
$sql .= "device_key_value = '".$device_key_value."', "; if (permission_exists('device_key_id')) {
$sql .= "device_key_label = '".$device_key_label."' "; $sql .= "device_key_id = '".$device_key_id."', ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; }
$sql .= "and device_key_uuid = '".$device_key_uuid."' "; $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) { if ($valid_data) {
$db->exec(check_sql($sql)); $db->exec(check_sql($sql));
@ -120,13 +131,12 @@
else { else {
//echo "invalid: ".$sql."\n"; //echo "invalid: ".$sql."\n";
} }
unset($sql);
} }
//write the provision files //write the provision files
if (strlen($_SESSION['provision']['path']['text']) > 0) { //if (strlen($_SESSION['provision']['path']['text']) > 0) {
require_once "app/provision/provision_write.php"; //require_once "app/provision/provision_write.php";
} //}
//set the message //set the message
if (!isset($_SESSION['message'])) { if (!isset($_SESSION['message'])) {
@ -150,14 +160,20 @@
//set the sub array index //set the sub array index
$x = "999"; $x = "999";
//get device keys
$sql = "SELECT device_uuid, device_profile_uuid FROM v_devices ";
$sql .= "WHERE user_uuid = '".$_SESSION['user_uuid']."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_NAMED);
$device_uuid = $row['device_uuid'];
$device_profile_uuid = $row['device_profile_uuid'];
unset($row);
//get device keys //get device keys
$sql = "SELECT * from v_device_keys "; $sql = "SELECT * from v_device_keys ";
$sql .= "where device_uuid in "; $sql .= "WHERE device_uuid = '".$device_uuid."' ";
$sql .= "( "; $sql .= "ORDER BY ";
$sql .= " select device_uuid from ";
$sql .= " v_devices where user_uuid = '".$_SESSION['user_uuid']."' ";
$sql .= ") ";
$sql .= "ORDER by ";
$sql .= "device_key_vendor asc, "; $sql .= "device_key_vendor asc, ";
$sql .= "CASE device_key_category "; $sql .= "CASE device_key_category ";
$sql .= "WHEN 'line' THEN 1 "; $sql .= "WHEN 'line' THEN 1 ";
@ -217,9 +233,6 @@
echo " </div>\n"; echo " </div>\n";
echo "<div style='float: right;'>\n"; echo "<div style='float: right;'>\n";
if ($num_rows > 10) {
echo " <input id='btn_viewall_ringgroups' type='button' class='btn' value='".$text['button-view_all']."' onclick=\"document.location.href='".PROJECT_PATH."/app/ring_groups/ring_group_forward.php';\">\n";
}
echo " <input type='submit' class='btn' value='".$text['button-save']."'>"; echo " <input type='submit' class='btn' value='".$text['button-save']."'>";
echo "</div>\n"; echo "</div>\n";