Follow Me, Call Forward, DND: List view updates.
This commit is contained in:
@@ -30,6 +30,7 @@ include "root.php";
|
||||
|
||||
//define the call_forward class
|
||||
class call_forward {
|
||||
|
||||
public $debug;
|
||||
public $domain_uuid;
|
||||
public $domain_name;
|
||||
@@ -87,8 +88,7 @@ include "root.php";
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
//revoke temporary permissions
|
||||
$p->delete('extension_add', 'temp');
|
||||
|
||||
//delete extension from the cache
|
||||
@@ -99,6 +99,131 @@ include "root.php";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* declare private variables
|
||||
*/
|
||||
private $app_name;
|
||||
private $app_uuid;
|
||||
private $permission;
|
||||
private $list_page;
|
||||
private $table;
|
||||
private $uuid_prefix;
|
||||
private $toggle_field;
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
*/
|
||||
public function toggle($records) {
|
||||
|
||||
//assign private variables
|
||||
$this->app_name = 'calls';
|
||||
$this->app_uuid = '19806921-e8ed-dcff-b325-dd3e5da4959d';
|
||||
$this->permission = 'call_forward';
|
||||
$this->list_page = 'calls.php';
|
||||
$this->table = 'extensions';
|
||||
$this->uuid_prefix = 'extension_';
|
||||
$this->toggle_field = 'forward_all_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
|
||||
if (permission_exists($this->permission)) {
|
||||
|
||||
//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, forward_all_destination, follow_me_uuid from v_".$this->table." ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$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) {
|
||||
$extensions[$row['uuid']]['state'] = $row['toggle'];
|
||||
$extensions[$row['uuid']]['follow_me_uuid'] = $row['follow_me_uuid'];
|
||||
$extensions[$row['uuid']]['forward_all_destination'] = $row['forward_all_destination'];
|
||||
}
|
||||
}
|
||||
unset($sql, $parameters, $rows, $row);
|
||||
}
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($extensions as $uuid => $extension) {
|
||||
|
||||
//check destination
|
||||
$destination_exists = $extension['forward_all_destination'] != '' ? true : false;
|
||||
|
||||
//determine new state
|
||||
$new_state = $extension['state'] == $this->toggle_values[1] && $destination_exists ? $this->toggle_values[0] : $this->toggle_values[1];
|
||||
|
||||
//toggle feature
|
||||
if ($new_state != $extension['state']) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $new_state;
|
||||
}
|
||||
|
||||
//disable other features
|
||||
if ($new_state == $this->toggle_values[0]) { //true
|
||||
$array[$this->table][$x]['do_not_disturb'] = $this->toggle_values[1]; //false
|
||||
$array[$this->table][$x]['follow_me_enabled'] = $this->toggle_values[1]; //false
|
||||
$array['follow_me'][$x]['follow_me_uuid'] = $extension['follow_me_uuid'];
|
||||
$array['follow_me'][$x]['follow_me_enabled'] = $this->toggle_values[1]; //false
|
||||
}
|
||||
|
||||
//increment counter
|
||||
$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');
|
||||
|
||||
//set message
|
||||
message::add($text['message-toggle']);
|
||||
|
||||
}
|
||||
unset($records, $states);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} //function
|
||||
|
||||
}// class
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user