Follow Me, Call Forward, DND: List view updates.

This commit is contained in:
Nate
2019-10-29 20:18:51 -06:00
parent c2bfcb4bc4
commit 5c69d7345e
5 changed files with 635 additions and 135 deletions
+139 -1
View File
@@ -264,6 +264,144 @@ include "root.php";
$p->delete("extension_edit", 'temp');
} //function
/**
* 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 = 'follow_me';
$this->list_page = 'calls.php';
$this->table = 'extensions';
$this->uuid_prefix = 'extension_';
$this->toggle_field = 'follow_me_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, 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'];
}
}
unset($sql, $parameters, $rows, $row);
}
//build update array
$x = 0;
foreach ($extensions as $uuid => $extension) {
//count destinations
$destinations_exist = false;
if (
$extension['state'] == $this->toggle_values[1] //false becoming true
&& is_uuid($extension['follow_me_uuid'])
) {
$sql .= "select count(*) from v_follow_me_destinations where follow_me_uuid = :follow_me_uuid";
$parameters['follow_me_uuid'] = $extension['follow_me_uuid'];
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
$destinations_exist = $num_rows ? true : false;
unset($sql, $parameters, $num_rows);
}
//determine new state
$new_state = $extension['state'] == $this->toggle_values[1] && $destinations_exist ? $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;
$array['follow_me'][$x]['follow_me_uuid'] = $extension['follow_me_uuid'];
$array['follow_me'][$x]['follow_me_enabled'] = $new_state;
}
//disable other features
if ($new_state == $this->toggle_values[0]) { //true
$array[$this->table][$x]['forward_all_enabled'] = $this->toggle_values[1]; //false
$array[$this->table][$x]['do_not_disturb'] = $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');
$p->add('follow_me_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');
$p->delete('follow_me_edit', 'temp');
//set message
message::add($text['message-toggle']);
}
unset($records, $states);
}
}
} //function
} //class
?>
?>