Update device_profile_copy.php
Fix the device profile copy.
This commit is contained in:
parent
806113292d
commit
2b595bf2bc
|
|
@ -23,71 +23,43 @@
|
||||||
Contributor(s):
|
Contributor(s):
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
*/
|
*/
|
||||||
include "root.php";
|
|
||||||
require_once "resources/require.php";
|
//includes
|
||||||
require_once "resources/check_auth.php";
|
include "root.php";
|
||||||
if (permission_exists('device_add')) {
|
require_once "resources/require.php";
|
||||||
//access granted
|
require_once "resources/check_auth.php";
|
||||||
}
|
|
||||||
else {
|
//check permissions
|
||||||
echo "access denied";
|
if (permission_exists('device_add')) {
|
||||||
exit;
|
//access granted
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
echo "access denied";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
//add multi-lingual support
|
//add multi-lingual support
|
||||||
$language = new text;
|
$language = new text;
|
||||||
$text = $language->get();
|
$text = $language->get();
|
||||||
|
|
||||||
//set the http get/post variable(s) to a php variable
|
//set the http get/post variable(s) to a php variable
|
||||||
if (isset($_REQUEST["id"]) && isset($_REQUEST["mac"])) {
|
if (isset($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
|
||||||
$device_uuid = check_str($_REQUEST["id"]);
|
$device_profile_uuid = $_REQUEST["id"];
|
||||||
$mac_address_new = check_str($_REQUEST["mac"]);
|
|
||||||
$mac_address_new = preg_replace('#[^a-fA-F0-9./]#', '', $mac_address_new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//set the default
|
//set the default
|
||||||
$save = true;
|
$save = true;
|
||||||
|
|
||||||
//check to see if the mac address exists
|
|
||||||
if ($mac_address_new == "" || $mac_address_new == "000000000000") {
|
|
||||||
//allow duplicates to be used as templaes
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$sql = "SELECT count(*) AS num_rows FROM v_devices ";
|
|
||||||
$sql .= "WHERE device_mac_address = '".$mac_address_new."' ";
|
|
||||||
$prep_statement = $db->prepare($sql);
|
|
||||||
if ($prep_statement) {
|
|
||||||
$prep_statement->execute();
|
|
||||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
|
||||||
if ($row['num_rows'] == "0") {
|
|
||||||
$save = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$save = false;
|
|
||||||
$_SESSION['message'] = $text['message-duplicate'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($prep_statement);
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the device
|
//get the device
|
||||||
$sql = "SELECT * FROM v_devices ";
|
$sql = "SELECT * FROM v_device_profiles ";
|
||||||
$sql .= "where device_uuid = '".$device_uuid."' ";
|
$sql .= "where device_profile_uuid = '".$device_profile_uuid."' ";
|
||||||
$prep_statement = $db->prepare(check_sql($sql));
|
$prep_statement = $db->prepare(check_sql($sql));
|
||||||
$prep_statement->execute();
|
$prep_statement->execute();
|
||||||
$devices = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
$device_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||||
|
|
||||||
//get device lines
|
|
||||||
$sql = "SELECT * FROM v_device_lines ";
|
|
||||||
$sql .= "where device_uuid = '".$device_uuid."' ";
|
|
||||||
$sql .= "order by line_number asc ";
|
|
||||||
$prep_statement = $db->prepare(check_sql($sql));
|
|
||||||
$prep_statement->execute();
|
|
||||||
$device_lines = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
||||||
|
|
||||||
//get device keys
|
//get device keys
|
||||||
$sql = "SELECT * FROM v_device_keys ";
|
$sql = "SELECT * FROM v_device_keys ";
|
||||||
$sql .= "WHERE device_uuid = '".$device_uuid."' ";
|
$sql .= "WHERE device_profile_uuid = '".$device_profile_uuid."' ";
|
||||||
$sql .= "ORDER by ";
|
$sql .= "ORDER by ";
|
||||||
$sql .= "CASE device_key_category ";
|
$sql .= "CASE device_key_category ";
|
||||||
$sql .= "WHEN 'line' THEN 1 ";
|
$sql .= "WHEN 'line' THEN 1 ";
|
||||||
|
|
@ -101,61 +73,52 @@ else {
|
||||||
$device_keys = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
$device_keys = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||||
|
|
||||||
//get device settings
|
//get device settings
|
||||||
$sql = "SELECT * FROM v_device_settings ";
|
//$sql = "SELECT * FROM v_device_settings ";
|
||||||
$sql .= "WHERE device_uuid = '".$device_uuid."' ";
|
//$sql .= "WHERE device_uuid = '".$device_uuid."' ";
|
||||||
$sql .= "ORDER by device_setting_subcategory asc ";
|
//$sql .= "ORDER by device_setting_subcategory asc ";
|
||||||
$prep_statement = $db->prepare(check_sql($sql));
|
//$prep_statement = $db->prepare(check_sql($sql));
|
||||||
$prep_statement->execute();
|
//$prep_statement->execute();
|
||||||
$device_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
//$device_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||||
|
|
||||||
//prepare the devices array
|
//prepare the devices array
|
||||||
unset($devices[0]["device_uuid"]);
|
unset($device_profiles[0]["device_profile_uuid"]);
|
||||||
|
|
||||||
//add copy to the device description
|
//add copy to the device description
|
||||||
$devices[0]["device_description"] = $text['button-copy']." ".$devices[0]["device_description"];
|
$device_profiles[0]["device_profile_name"] = $device_profiles[0]["device_profile_name"]."-".strtolower($text['button-copy']);
|
||||||
|
$device_profiles[0]["device_profile_description"] = $text['button-copy']." ".$device_profiles[0]["device_profile_description"];
|
||||||
//prepare the device_lines array
|
|
||||||
$x = 0;
|
|
||||||
foreach ($device_lines as $row) {
|
|
||||||
unset($device_lines[$x]["device_uuid"]);
|
|
||||||
unset($device_lines[$x]["device_line_uuid"]);
|
|
||||||
$x++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//prepare the device_keys array
|
//prepare the device_keys array
|
||||||
$x = 0;
|
$x = 0;
|
||||||
foreach ($device_keys as $row) {
|
foreach ($device_keys as $row) {
|
||||||
unset($device_keys[$x]["device_uuid"]);
|
unset($device_keys[$x]["device_profile_uuid"]);
|
||||||
unset($device_keys[$x]["device_key_uuid"]);
|
unset($device_keys[$x]["device_key_uuid"]);
|
||||||
$x++;
|
$x++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//prepare the device_settings array
|
//prepare the device_settings array
|
||||||
$x = 0;
|
//$x = 0;
|
||||||
foreach ($device_settings as $row) {
|
//foreach ($device_settings as $row) {
|
||||||
unset($device_settings[$x]["device_uuid"]);
|
// unset($device_settings[$x]["device_uuid"]);
|
||||||
unset($device_settings[$x]["device_setting_uuid"]);
|
// unset($device_settings[$x]["device_setting_uuid"]);
|
||||||
$x++;
|
// $x++;
|
||||||
}
|
//}
|
||||||
|
|
||||||
//create the device array
|
//create the device array
|
||||||
$device = $devices[0];
|
$device_profile = $device_profiles[0];
|
||||||
$device["device_mac_address"] = $mac_address_new;
|
$device_profile["device_keys"] = $device_keys;
|
||||||
$device["device_lines"] = $device_lines;
|
//$device["device_settings"] = $device_settings;
|
||||||
$device["device_keys"] = $device_keys;
|
|
||||||
$device["device_settings"] = $device_settings;
|
|
||||||
|
|
||||||
//copy the device
|
//copy the device
|
||||||
if ($save) {
|
if ($save) {
|
||||||
$orm = new orm;
|
$orm = new orm;
|
||||||
$orm->name('devices');
|
$orm->name('device_profiles');
|
||||||
$orm->save($device);
|
$orm->save($device_profile);
|
||||||
$response = $orm->message;
|
$response = $orm->message;
|
||||||
$_SESSION["message"] = $text['message-copy'];
|
$_SESSION["message"] = $text['message-copy'];
|
||||||
}
|
}
|
||||||
|
|
||||||
//redirect
|
//redirect
|
||||||
header("Location: devices.php");
|
header("Location: device_profiles.php");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue