2018-03-19 04:05:08 +01:00
|
|
|
<?php
|
2019-11-02 20:40:17 +01:00
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
2018-03-19 04:05:08 +01:00
|
|
|
|
2019-11-02 20:40:17 +01: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/
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2019
|
|
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//define the bridges class
|
2018-03-19 04:05:08 +01:00
|
|
|
class bridges {
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-22 01:03:59 +02:00
|
|
|
* declare private variables
|
|
|
|
|
*/
|
|
|
|
|
private $app_name;
|
|
|
|
|
private $app_uuid;
|
|
|
|
|
private $permission_prefix;
|
|
|
|
|
private $list_page;
|
|
|
|
|
private $table;
|
|
|
|
|
private $uuid_prefix;
|
2019-10-29 17:11:18 +01:00
|
|
|
private $toggle_field;
|
|
|
|
|
private $toggle_values;
|
2019-10-22 01:03:59 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* called when the object is created
|
2018-03-19 04:05:08 +01:00
|
|
|
*/
|
|
|
|
|
public function __construct() {
|
2019-08-29 04:59:42 +02:00
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
//assign private variables
|
|
|
|
|
$this->app_name = 'bridges';
|
|
|
|
|
$this->app_uuid = 'a6a7c4c5-340a-43ce-bcbc-2ed9bab8659d';
|
2019-10-22 01:13:21 +02:00
|
|
|
$this->permission_prefix = 'bridge_';
|
2019-10-22 01:03:59 +02:00
|
|
|
$this->list_page = 'bridges.php';
|
|
|
|
|
$this->table = 'bridges';
|
|
|
|
|
$this->uuid_prefix = 'bridge_';
|
2019-10-29 17:11:18 +01:00
|
|
|
$this->toggle_field = 'bridge_enabled';
|
|
|
|
|
$this->toggle_values = ['true','false'];
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2018-03-19 04:05:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-22 01:03:59 +02:00
|
|
|
* delete records
|
2018-03-19 04:05:08 +01:00
|
|
|
*/
|
2019-10-22 01:03:59 +02:00
|
|
|
public function delete($records) {
|
2019-10-22 01:13:21 +02:00
|
|
|
if (permission_exists($this->permission_prefix.'delete')) {
|
2018-03-19 04:05:08 +01:00
|
|
|
|
2019-09-19 16:59:00 +02:00
|
|
|
//add multi-lingual support
|
|
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
|
|
|
|
|
2019-09-19 16:50:37 +02:00
|
|
|
//validate the token
|
|
|
|
|
$token = new token;
|
|
|
|
|
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
|
|
|
|
message::add($text['message-invalid_token'],'negative');
|
2019-10-22 01:03:59 +02:00
|
|
|
header('Location: '.$this->list_page);
|
2019-09-19 16:50:37 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
//delete multiple records
|
|
|
|
|
if (is_array($records) && @sizeof($records) != 0) {
|
|
|
|
|
|
2019-10-19 17:07:07 +02:00
|
|
|
//build the delete array
|
2019-10-30 03:18:51 +01:00
|
|
|
foreach ($records as $x => $record) {
|
2023-05-20 01:48:01 +02:00
|
|
|
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
2019-10-22 01:03:59 +02:00
|
|
|
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
|
|
|
|
$array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
|
2018-03-19 04:05:08 +01:00
|
|
|
}
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2019-10-19 17:07:07 +02:00
|
|
|
//delete the checked rows
|
2019-10-08 02:31:11 +02:00
|
|
|
if (is_array($array) && @sizeof($array) != 0) {
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2019-10-08 02:31:11 +02:00
|
|
|
//execute delete
|
|
|
|
|
$database = new database;
|
2019-10-22 01:03:59 +02:00
|
|
|
$database->app_name = $this->app_name;
|
|
|
|
|
$database->app_uuid = $this->app_uuid;
|
2019-08-29 05:16:15 +02:00
|
|
|
$database->delete($array);
|
|
|
|
|
unset($array);
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2020-11-30 22:15:57 +01:00
|
|
|
//clear the destinations session array
|
|
|
|
|
if (isset($_SESSION['destinations']['array'])) {
|
|
|
|
|
unset($_SESSION['destinations']['array']);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 02:31:11 +02:00
|
|
|
//set message
|
|
|
|
|
message::add($text['message-delete']);
|
|
|
|
|
}
|
2019-10-22 01:03:59 +02:00
|
|
|
unset($records);
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-22 01:03:59 +02:00
|
|
|
* toggle records
|
2019-10-08 02:31:11 +02:00
|
|
|
*/
|
2019-10-22 01:03:59 +02:00
|
|
|
public function toggle($records) {
|
2019-10-22 01:13:21 +02:00
|
|
|
if (permission_exists($this->permission_prefix.'edit')) {
|
2019-10-08 02:31:11 +02:00
|
|
|
|
|
|
|
|
//add multi-lingual support
|
|
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
|
|
|
|
|
|
|
|
|
//validate the token
|
|
|
|
|
$token = new token;
|
|
|
|
|
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
|
|
|
|
message::add($text['message-invalid_token'],'negative');
|
2019-10-22 01:03:59 +02:00
|
|
|
header('Location: '.$this->list_page);
|
2019-10-08 02:31:11 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
//toggle the checked records
|
|
|
|
|
if (is_array($records) && @sizeof($records) != 0) {
|
|
|
|
|
|
2019-10-29 17:11:18 +01:00
|
|
|
//get current toggle state
|
2019-12-01 05:42:15 +01:00
|
|
|
foreach ($records as $x => $record) {
|
2023-05-20 01:48:01 +02:00
|
|
|
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
2019-11-30 21:41:25 +01:00
|
|
|
$uuids[] = "'".$record['uuid']."'";
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-30 21:41:25 +01:00
|
|
|
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
2019-10-29 17:11:18 +01:00
|
|
|
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
2019-10-08 02:31:11 +02:00
|
|
|
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
2019-11-30 21:41:25 +01:00
|
|
|
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
2019-10-08 02:31:11 +02:00
|
|
|
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
|
|
|
|
$database = new database;
|
|
|
|
|
$rows = $database->select($sql, $parameters, 'all');
|
|
|
|
|
if (is_array($rows) && @sizeof($rows) != 0) {
|
|
|
|
|
foreach ($rows as $row) {
|
2019-10-29 17:11:18 +01:00
|
|
|
$states[$row['uuid']] = $row['toggle'];
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unset($sql, $parameters, $rows, $row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//build update array
|
|
|
|
|
$x = 0;
|
2019-12-01 05:42:15 +01:00
|
|
|
foreach ($states as $uuid => $state) {
|
2019-10-22 01:03:59 +02:00
|
|
|
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
2019-10-29 17:11:18 +01:00
|
|
|
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
2019-10-08 02:31:11 +02:00
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-19 17:07:07 +02:00
|
|
|
//save the changes
|
|
|
|
|
if (is_array($array) && @sizeof($array) != 0) {
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2019-10-19 17:07:07 +02:00
|
|
|
//save the array
|
|
|
|
|
$database = new database;
|
2019-10-22 01:03:59 +02:00
|
|
|
$database->app_name = $this->app_name;
|
|
|
|
|
$database->app_uuid = $this->app_uuid;
|
2019-10-19 17:07:07 +02:00
|
|
|
$database->save($array);
|
|
|
|
|
unset($array);
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2020-11-30 22:15:57 +01:00
|
|
|
//clear the destinations session array
|
|
|
|
|
if (isset($_SESSION['destinations']['array'])) {
|
|
|
|
|
unset($_SESSION['destinations']['array']);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-19 17:07:07 +02:00
|
|
|
//set message
|
|
|
|
|
message::add($text['message-toggle']);
|
|
|
|
|
}
|
2019-10-22 01:03:59 +02:00
|
|
|
unset($records, $states);
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-22 01:03:59 +02:00
|
|
|
* copy records
|
2019-10-08 02:31:11 +02:00
|
|
|
*/
|
2019-10-22 01:03:59 +02:00
|
|
|
public function copy($records) {
|
2019-10-22 01:13:21 +02:00
|
|
|
if (permission_exists($this->permission_prefix.'add')) {
|
2019-10-08 02:31:11 +02:00
|
|
|
|
|
|
|
|
//add multi-lingual support
|
|
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
|
|
|
|
|
|
|
|
|
//validate the token
|
|
|
|
|
$token = new token;
|
|
|
|
|
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
|
|
|
|
message::add($text['message-invalid_token'],'negative');
|
2019-10-22 01:03:59 +02:00
|
|
|
header('Location: '.$this->list_page);
|
2019-10-08 02:31:11 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
//copy the checked records
|
|
|
|
|
if (is_array($records) && @sizeof($records) != 0) {
|
2019-10-08 02:31:11 +02:00
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
//get checked records
|
2019-12-01 05:42:15 +01:00
|
|
|
foreach ($records as $x => $record) {
|
2023-05-20 01:48:01 +02:00
|
|
|
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
2019-11-30 21:41:25 +01:00
|
|
|
$uuids[] = "'".$record['uuid']."'";
|
2019-08-29 05:16:15 +02:00
|
|
|
}
|
2018-03-19 04:05:08 +01:00
|
|
|
}
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2019-10-08 02:31:11 +02:00
|
|
|
//create insert array from existing data
|
2019-11-30 21:41:25 +01:00
|
|
|
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
2019-10-22 01:03:59 +02:00
|
|
|
$sql = "select * from v_".$this->table." ";
|
2019-10-08 02:31:11 +02:00
|
|
|
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
2019-11-30 21:41:25 +01:00
|
|
|
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
2019-10-08 02:31:11 +02:00
|
|
|
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
|
|
|
|
$database = new database;
|
|
|
|
|
$rows = $database->select($sql, $parameters, 'all');
|
|
|
|
|
if (is_array($rows) && @sizeof($rows) != 0) {
|
|
|
|
|
foreach ($rows as $x => $row) {
|
2019-10-26 03:40:28 +02:00
|
|
|
|
|
|
|
|
//copy data
|
|
|
|
|
$array[$this->table][$x] = $row;
|
|
|
|
|
|
|
|
|
|
//overwrite
|
|
|
|
|
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = uuid();
|
|
|
|
|
$array[$this->table][$x]['bridge_description'] = trim($row['bridge_description'].' ('.$text['label-copy'].')');
|
|
|
|
|
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unset($sql, $parameters, $rows, $row);
|
|
|
|
|
}
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2019-10-19 17:07:07 +02:00
|
|
|
//save the changes and set the message
|
2019-10-08 02:31:11 +02:00
|
|
|
if (is_array($array) && @sizeof($array) != 0) {
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2019-10-19 17:07:07 +02:00
|
|
|
//save the array
|
2019-10-19 18:07:18 +02:00
|
|
|
$database = new database;
|
2019-10-22 01:03:59 +02:00
|
|
|
$database->app_name = $this->app_name;
|
|
|
|
|
$database->app_uuid = $this->app_uuid;
|
2019-10-19 18:07:18 +02:00
|
|
|
$database->save($array);
|
|
|
|
|
unset($array);
|
2019-10-19 17:07:07 +02:00
|
|
|
|
|
|
|
|
//set message
|
2019-10-19 18:07:18 +02:00
|
|
|
message::add($text['message-copy']);
|
2019-10-22 01:03:59 +02:00
|
|
|
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|
2019-10-22 01:03:59 +02:00
|
|
|
unset($records);
|
2018-03-19 04:05:08 +01:00
|
|
|
}
|
2019-10-08 02:31:11 +02:00
|
|
|
|
2018-03-19 04:05:08 +01:00
|
|
|
}
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|
2018-03-19 04:05:08 +01:00
|
|
|
|
2019-10-08 02:31:11 +02:00
|
|
|
}
|