Files
fusionpbx/app/devices/device_profile_copy.php
T

126 lines
3.5 KiB
PHP
Raw Normal View History

2016-04-25 20:30:23 -05:00
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
2016-10-23 00:12:58 -06:00
Portions created by the Initial Developer are Copyright (C) 2008-2016
2016-04-25 20:30:23 -05:00
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
2016-07-29 11:13:29 -06:00
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('device_add')) {
//access granted
}
else {
echo "access denied";
exit;
}
2016-04-25 20:30:23 -05:00
//add multi-lingual support
$language = new text;
$text = $language->get();
//set the http get/post variable(s) to a php variable
2016-07-29 11:13:29 -06:00
if (isset($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$device_profile_uuid = $_REQUEST["id"];
2016-04-25 20:30:23 -05:00
}
//set the default
$save = true;
//get the device
2016-07-29 11:13:29 -06:00
$sql = "SELECT * FROM v_device_profiles ";
$sql .= "where device_profile_uuid = '".$device_profile_uuid."' ";
2017-01-10 10:12:03 -05:00
$database = new database;
$database->select($sql);
$device_profiles = $database->result;
2016-04-25 20:30:23 -05:00
//get device keys
$sql = "SELECT * FROM v_device_keys ";
2016-07-29 11:13:29 -06:00
$sql .= "WHERE device_profile_uuid = '".$device_profile_uuid."' ";
2016-04-25 20:30:23 -05:00
$sql .= "ORDER by ";
$sql .= "CASE device_key_category ";
$sql .= "WHEN 'line' THEN 1 ";
$sql .= "WHEN 'memort' THEN 2 ";
$sql .= "WHEN 'programmable' THEN 3 ";
$sql .= "WHEN 'expansion' THEN 4 ";
$sql .= "ELSE 100 END, ";
$sql .= "cast(device_key_id as numeric) asc ";
2017-01-10 10:12:03 -05:00
$database = new database;
$database->select($sql);
$device_keys = $database->result;
2016-04-25 20:30:23 -05:00
//get device settings
2017-01-10 10:12:03 -05:00
$sql = "SELECT * FROM v_device_settings ";
$sql .= "WHERE device_profile_uuid = '".$device_profile_uuid."' ";
$sql .= "ORDER by device_setting_subcategory asc ";
$database = new database;
$database->select($sql);
$device_settings = $database->result;
2016-04-25 20:30:23 -05:00
//prepare the devices array
2016-07-29 11:13:29 -06:00
unset($device_profiles[0]["device_profile_uuid"]);
2016-04-25 20:30:23 -05:00
//add copy to the device description
2016-10-23 10:58:51 -06:00
//$device_profiles[0]["device_profile_name"] = $device_profiles[0]["device_profile_name"]."-".strtolower($text['button-copy']);
2016-07-29 11:13:29 -06:00
$device_profiles[0]["device_profile_description"] = $text['button-copy']." ".$device_profiles[0]["device_profile_description"];
2016-04-25 20:30:23 -05:00
//prepare the device_keys array
$x = 0;
foreach ($device_keys as $row) {
2016-07-29 11:13:29 -06:00
unset($device_keys[$x]["device_profile_uuid"]);
2016-04-25 20:30:23 -05:00
unset($device_keys[$x]["device_key_uuid"]);
$x++;
}
//prepare the device_settings array
2017-01-10 10:12:03 -05:00
$x = 0;
foreach ($device_settings as $row) {
unset($device_settings[$x]["device_profile_uuid"]);
unset($device_settings[$x]["device_setting_uuid"]);
$x++;
}
2016-04-25 20:30:23 -05:00
//create the device array
2016-10-23 10:58:51 -06:00
$array["device_profiles"] = $device_profiles;
$array["device_profiles"][0]["device_keys"] = $device_keys;
2017-01-10 10:12:03 -05:00
$array["device_profiles"][0]["device_settings"] = $device_settings;
2016-04-25 20:30:23 -05:00
//copy the device
if ($save) {
2016-10-23 00:12:58 -06:00
$database = new database;
$database->app_name = 'devices';
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
$database->save($array);
$response = $database->message;
messages::add($text['message-copy']);
2016-04-25 20:30:23 -05:00
}
//redirect
2016-07-29 11:13:29 -06:00
header("Location: device_profiles.php");
2016-04-25 20:30:23 -05:00
return;
2016-07-29 11:13:29 -06:00
?>