Extensions: List view updates.

This commit is contained in:
Nate
2019-11-18 13:31:06 -07:00
parent 6eddd05cba
commit 0e56d1b7e5
6 changed files with 511 additions and 188 deletions

View File

@@ -1,35 +1,38 @@
<?php
/*
FusionPBX
Version: MPL 1.1
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/
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.
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 Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2010 - 2016
All Rights Reserved.
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>
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//define the directory class
if (!class_exists('extension')) {
class extension {
/**
* declare public variables
*/
public $domain_uuid;
public $domain_name;
private $app_uuid;
public $extension_uuid;
public $extension;
public $voicemail_id;
@@ -70,11 +73,39 @@ if (!class_exists('extension')) {
public $enabled;
public $description;
/**
* declare private variables
*/
private $app_name;
private $app_uuid;
private $permission_prefix;
private $list_page;
private $table;
private $uuid_prefix;
private $toggle_field;
private $toggle_values;
/**
* called when the object is created
*/
public function __construct() {
//set the application id
//assign private variables
$this->app_name = 'extensions';
$this->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
$this->permission_prefix = 'extension_';
$this->list_page = 'extensions.php';
$this->table = 'extensions';
$this->uuid_prefix = 'extension_';
$this->toggle_field = 'enabled';
$this->toggle_values = ['true','false'];
}
/**
* called when there are no references to a particular object
* unset the variables used in the class
*/
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
@@ -512,6 +543,221 @@ if (!class_exists('extension')) {
$_SESSION["reload_xml"] = true;
}
}
/**
* delete records
*/
public function delete($records) {
if (permission_exists($this->permission_prefix.'delete')) {
//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');
header('Location: '.$this->list_page);
exit;
}
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
//build the delete array
$y = @sizeof($records) + 1;
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
//get the extension details
$sql = "select extension, number_alias, user_context, follow_me_uuid from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and extension_uuid = :extension_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['extension_uuid'] = $record['uuid'];
$database = new database;
$row = $database->execute($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
//for use below and to clear cache (bottom)
$extensions[$x] = $row;
//build delete array
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array['extension_users'][$x]['extension_uuid'] = $record['uuid'];
$array['follow_me'][$x]['follow_me_uuid'] = $extensions[$x]['follow_me_uuid'];
$array['follow_me_destinations'][$x]['follow_me_uuid'] = $extensions[$x]['follow_me_uuid'];
//include ring group destinations, if exists
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/ring_groups/app_config.php")) {
$array['ring_group_destinations'][$x]['destination_number'] = $extensions[$x]['extension'];
$array['ring_group_destinations'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
if ($extensions[$x]['number_alias'] != '') {
$array['ring_group_destinations'][$y]['destination_number'] = $extensions[$x]['number_alias'];
$array['ring_group_destinations'][$y]['domain_uuid'] = $_SESSION['domain_uuid'];
}
$y++;
}
}
unset($sql, $parameters, $row);
}
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('extension_user_delete', 'temp');
$p->add('follow_me_delete', 'temp');
$p->add('follow_me_destination_delete', 'temp');
$p->add('ring_group_destination_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('extension_user_delete', 'temp');
$p->delete('follow_me_delete', 'temp');
$p->delete('follow_me_destination_delete', 'temp');
$p->delete('ring_group_destination_delete', 'temp');
//clear the cache
foreach ($extensions as $x => $extension) {
$cache = new cache;
$cache->delete("directory:".$extension['extension']."@".$extension['user_context']);
if (permission_exists('number_alias') && strlen($extension['number_alias']) > 0) {
$cache->delete("directory:".$extension['number_alias']."@".$extension['user_context']);
}
}
unset($extensions);
//synchronize configuration
if (is_writable($_SESSION['switch']['extensions']['dir'])) {
$this->xml();
}
//set message
message::add($text['message-delete']);
}
unset($records);
}
}
}
/**
* toggle records
*/
public function toggle($records) {
if (permission_exists($this->permission_prefix.'enabled')) {
//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');
header('Location: '.$this->list_page);
exit;
}
//toggle the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get current toggle state
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
}
}
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, extension, number_alias, user_context from v_".$this->table." ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$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) {
//for use below and to clear cache (bottom)
$extensions[$row['uuid']]['state'] = $row['toggle'];
$extensions[$row['uuid']]['extension'] = $row['extension'];
$extensions[$row['uuid']]['number_alias'] = $row['number_alias'];
$extensions[$row['uuid']]['user_context'] = $row['user_context'];
}
}
unset($sql, $parameters, $rows, $row);
}
//build update array
$x = 0;
foreach($extensions as $uuid => $extension) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->toggle_field] = $extension['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++;
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('extension_edit', 'temp');
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('extension_edit', 'temp');
//synchronize configuration
if (is_writable($_SESSION['switch']['extensions']['dir'])) {
$this->xml();
}
//write the provision files
if (strlen($_SESSION['provision']['path']['text']) > 0) {
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
$prov = new provision;
$prov->domain_uuid = $_SESSION['domain_uuid'];
$response = $prov->write();
}
}
//clear the cache
foreach ($extensions as $uuid => $extension) {
$cache = new cache;
$cache->delete("directory:".$extension['extension']."@".$extension['user_context']);
if (permission_exists('number_alias') && strlen($extension['number_alias']) > 0) {
$cache->delete("directory:".$extension['number_alias']."@".$extension['user_context']);
}
}
unset($extensions);
//set message
message::add($text['message-toggle']);
}
unset($records);
}
}
}
}
}