fusionpbx/app/devices/device_vendor_restore.php

160 lines
5.4 KiB
PHP
Raw Permalink Normal View History

<?php
/*
2019-08-04 04:21:56 +02:00
FusionPBX
Version: MPL 1.1
2019-08-04 04:21:56 +02:00
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/
2019-08-04 04:21:56 +02:00
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.
2019-08-04 04:21:56 +02:00
The Original Code is FusionPBX
2019-08-04 04:21:56 +02:00
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2016-2024
2019-08-04 04:21:56 +02:00
the Initial Developer. All Rights Reserved.
2019-08-04 04:21:56 +02:00
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
*/
2022-10-11 00:35:14 +02:00
//includes files
Use magic constant dir (#6711) * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ to load only functions.php * replace spaces with tab character * update dirname command to use levels instead of nesting * use magic constant __DIR__ * update dirname command to use levels instead of nesting * Update access_control_edit.php * Update access_control_import.php * Update access_controls.php * Update dnd.php * Update access_controls_reload.php * Update call_center_agents.php * Update call_center_agents.php * Update fax_queue.php * Update login.php * Update pdo.php * Update pdo_vm.php * Update switch.php * Update index.php * Update css.php * Update v_mailto.php * Update fax_to_email.php --------- Co-authored-by: FusionPBX <markjcrane@gmail.com>
2023-06-15 19:28:23 +02:00
require_once dirname(__DIR__, 2) . "/resources/require.php";
//check permissions
2019-08-04 04:21:56 +02:00
require_once "resources/check_auth.php";
if (permission_exists('device_vendor_restore')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
2019-08-04 04:21:56 +02:00
$language = new text;
$text = $language->get();
//flush everything
2019-08-04 04:21:56 +02:00
$sql = "delete from v_device_vendors";
$database = new database;
$database->execute($sql);
unset($sql);
2019-08-04 04:21:56 +02:00
$sql = "delete from v_device_vendor_functions";
$database = new database;
$database->execute($sql);
unset($sql);
2019-08-04 04:21:56 +02:00
$sql = "delete from v_device_vendor_function_groups";
$database = new database;
$database->execute($sql);
unset($sql);
//add device vendor functions to the database
2019-08-04 04:21:56 +02:00
$sql = "select count(*) from v_device_vendors; ";
$database = new database;
$num_rows = $database->select($sql, null, 'column');
unset($sql);
if ($num_rows == 0) {
//get the vendor array
$x = 0;
2019-08-04 04:21:56 +02:00
require_once $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/app/devices/app_config.php';
//get the groups and create an array to use the name to get the uuid
$sql = "select * from v_groups ";
$database = new database;
$groups = $database->select($sql, null, 'all');
if (is_array($groups) && @sizeof($groups) != 0) {
foreach ($groups as $row) {
if (!is_uuid($row['domain_uuid'])) {
$group_uuids[$row['group_name']] = $row['group_uuid'];
}
}
}
unset($sql);
//create insert array
$x = $z = 0;
2019-10-02 05:46:08 +02:00
foreach ($vendors as $vendor) {
2019-08-04 04:21:56 +02:00
//insert the data into the database
$device_vendor_uuid = uuid();
2019-10-02 05:46:08 +02:00
$array['device_vendors'][$x]['device_vendor_uuid'] = $device_vendor_uuid;
$array['device_vendors'][$x]['name'] = $vendor['name'];
$array['device_vendors'][$x]['enabled'] = 'true';
//add the device vendor functions
$y = 0;
if (!empty($vendor['functions']) && is_array($vendor['functions']) && @sizeof($vendor['functions']) != 0) {
foreach ($vendor['functions'] as $function) {
//add the device vendor function
$device_vendor_function_uuid = uuid();
$array['device_vendors'][$x]['device_vendor_functions'][$y]['device_vendor_uuid'] = $device_vendor_uuid;
$array['device_vendors'][$x]['device_vendor_functions'][$y]['device_vendor_function_uuid'] = $device_vendor_function_uuid;
//$array['device_vendors'][$x]['device_vendor_functions'][$y]['label'] = $function['label'];
$array['device_vendors'][$x]['device_vendor_functions'][$y]['type'] = $function['type'] ?? null;
$array['device_vendors'][$x]['device_vendor_functions'][$y]['subtype'] = $function['subtype'] ?? null;
$array['device_vendors'][$x]['device_vendor_functions'][$y]['value'] = $function['value'];
$array['device_vendors'][$x]['device_vendor_functions'][$y]['enabled'] = 'true';
$array['device_vendors'][$x]['device_vendor_functions'][$y]['description'] = $function['description'] ?? null;
//add the device vendor function groups
if (is_array($function['groups']) && @sizeof($function['groups']) != 0) {
foreach ($function['groups'] as $group_name) {
$device_vendor_function_group_uuid = uuid();
$array['device_vendor_function_groups'][$z]['device_vendor_function_group_uuid'] = $device_vendor_function_group_uuid;
$array['device_vendor_function_groups'][$z]['device_vendor_function_uuid'] = $device_vendor_function_uuid;
$array['device_vendor_function_groups'][$z]['device_vendor_uuid'] = $device_vendor_uuid;
$array['device_vendor_function_groups'][$z]['group_name'] = $group_name;
$array['device_vendor_function_groups'][$z]['group_uuid'] = $group_uuids[$group_name];
$z++;
}
2019-08-04 04:21:56 +02:00
}
//increment the device vendor function index
$y++;
}
2019-08-04 04:21:56 +02:00
}
2019-10-02 05:46:08 +02:00
//increment the devic vendor index
$x++;
2019-08-04 04:21:56 +02:00
}
//assign temp permissions
2024-11-29 21:57:01 +01:00
$p = permissions::new();
2019-08-04 04:21:56 +02:00
$p->add('device_vendor_add', 'temp');
$p->add('device_vendor_function_add', 'temp');
$p->add('device_vendor_function_group_add', 'temp');
//process array
$database = new database;
$database->app_name = 'devices';
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
$database->save($array);
unset($array);
//remove temp permissions
$p->delete('device_vendor_add', 'temp');
$p->delete('device_vendor_function_add', 'temp');
$p->delete('device_vendor_function_group_add', 'temp');
//set message
message::add($text['message-restore']);
}
unset($num_rows);
//redirect
header('Location: device_vendors.php');
exit;
?>