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

View File

@ -69,7 +69,7 @@ if (!class_exists('bridges')) {
if (is_array($records) && @sizeof($records) != 0) {
//build the delete array
foreach($records as $x => $record) {
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];

View File

@ -28,6 +28,7 @@
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
if (permission_exists('follow_me') || permission_exists('call_forward') || permission_exists('do_not_disturb')) {
@ -38,28 +39,69 @@
exit;
}
//get the domain_uuid from the session
$domain_uuid = $_SESSION['domain_uuid'];
//handle search term
$search = $_GET["search"];
if (strlen($search) > 0) {
$sql_mod = "and ( ";
$sql_mod .= "extension like :search ";
$sql_mod .= "or description like :search ";
$sql_mod .= ") ";
}
//add multi-lingual support
$language = new text;
$text = $language->get($_SESSION['domain']['language']['code'], 'app/calls');
//begin the content
require_once "resources/header.php";
require_once "resources/paging.php";
//get posted data
if (is_array($_POST['extensions'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$extensions = $_POST['extensions'];
}
//toggle the call forward feature
if (permission_exists('call_forward')) {
if ($action == 'toggle_call_forward' && is_array($extensions) && @sizeof($extensions) != 0) {
//toggle
$obj = new call_forward;
$obj->toggle($extensions);
//redirect
header('Location: calls.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//toggle the follow me feature
if (permission_exists('follow_me')) {
if ($action == 'toggle_follow_me' && is_array($extensions) && @sizeof($extensions) != 0) {
//toggle
$obj = new follow_me;
$obj->toggle($extensions);
//redirect
header('Location: calls.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//toggle the do not disturb feature
if (permission_exists('do_not_disturb')) {
if ($action == 'toggle_do_not_disturb' && is_array($extensions) && @sizeof($extensions) != 0) {
//toggle
$obj = new do_not_disturb;
$obj->toggle($extensions);
//redirect
header('Location: calls.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//get order and order by
$order_by = $_GET["order_by"];
$order = $_GET["order"];
//handle search term
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_search = "and ( ";
$sql_search .= "extension like :search ";
$sql_search .= "or lower(description) like :search ";
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
}
//define select count query
$sql = "select count(extension_uuid) as count from v_extensions ";
$sql = "select count(*) from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and enabled = 'true' ";
if (!(if_group("admin") || if_group("superadmin"))) {
@ -78,13 +120,12 @@
$sql .= "and extension = 'disabled' ";
}
}
$sql .= $sql_mod; //add search mod from above
$sql .= $sql_search;
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
if (strlen($search) > 0) {
$parameters['search'] = '%'.$search.'%';
}
$database = new database;
$result_count = $database->select($sql, $parameters, 'column');
$num_rows = $database->select($sql, $parameters, 'column');
//prepare to page the results
if ($is_included) {
$rows_per_page = 10;
}
@ -94,138 +135,218 @@
$param = "&search=".$search;
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls_mini, $rows_per_page, $var_3) = paging($result_count, $param, $rows_per_page, true);
list($paging_controls, $rows_per_page, $var_3) = paging($result_count, $param, $rows_per_page);
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
//select the extensions
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and enabled = 'true' ";
if (!(if_group("admin") || if_group("superadmin"))) {
if (count($_SESSION['user']['extension']) > 0) {
$sql .= "and (";
$x = 0;
foreach($_SESSION['user']['extension'] as $row) {
if ($x > 0) { $sql .= "or "; }
$sql .= "extension = '".$row['user']."' ";
$x++;
}
$sql .= ") ";
}
else {
//used to hide any results when a user has not been assigned an extension
$sql .= "and extension = 'disabled' ";
}
}
$sql .= $sql_mod; //add search mod from above
$sql .= "order by extension asc ";
//get the list
$sql = str_replace('count(*)', '*', $sql);
$sql .= order_by($order_by, $order, 'extension', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$extensions = $database->select($sql, $parameters, 'all');
unset($parameters);
//set the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//start the content
echo "<table cellpadding='0' cellspacing='0' border='0' width='100%'>\n";
echo " <tr>\n";
echo " <td valign='top'>";
echo " <b>".$text['header-call_routing']."</b><br />";
echo " </td>\n";
echo " <td valign='top' style='text-align: right; white-space: nowrap;'>\n";
if ($result_count > 10 && $is_included) {
echo " <input id='btn_viewall_callrouting' type='button' class='btn' value='".$text['button-view_all']."' onclick=\"document.location.href='".PROJECT_PATH."/app/calls/calls.php';\">";
}
if (!$is_included) {
echo " <form method='get' action='' style='display: inline-block;'>\n";
echo " <input type='text' class='txt' style='width: 150px' name='search' value='".escape($search)."'>";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
echo " </form>\n";
if ($paging_controls_mini != '') {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
//include header
$document['title'] = $text['title'];
require_once "resources/header.php";
//javascript for toggle select box
echo "<script language='javascript' type='text/javascript'>\n";
echo " function toggle_select() {\n";
echo " $('#call_control_feature').fadeToggle(400, function() {\n";
echo " document.getElementById('call_control_feature').selectedIndex = 0;\n";
echo " document.getElementById('call_control_feature').focus();\n";
echo " });\n";
echo " }\n";
echo "</script>\n";
//show the content
if ($is_included) {
echo "<b>".$text['header-call_routing']."</b>\n";
if ($num_rows > 10) {
echo "<div align='right'>\n";
echo button::create(['type'=>'button','label'=>$text['button-view_all'],'link'=>PROJECT_PATH.'/app/calls/calls.php']);
echo "</div>\n";
}
} echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td colspan='2' valign='top'>";
if (!$is_included) {
echo $text['description-call_routing']."<br />";
}
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<br />";
else {
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['header-call_routing']." (".$num_rows.")</b></div>\n";
echo " <div class='actions'>\n";
if ($extensions) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"toggle_select(); this.blur();"]);
}
echo "<select class='formfld' style='display: none; width: auto;' id='call_control_feature' onchange=\"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle_' + this.options[this.selectedIndex].value); list_form_submit('form_list'); } else { this.blur(); this.style.display = 'none'; return false; }\">";
echo " <option value='' selected='selected'>".$text['label-select']."</option>";
if (permission_exists('call_forward')) {
echo " <option value='call_forward'>".$text['label-call-forward']."</option>";
}
if (permission_exists('follow_me')) {
echo " <option value='follow_me'>".$text['label-follow-me']."</option>";
}
if (permission_exists('do_not_disturb')) {
echo " <option value='do_not_disturb'>".$text['label-dnd']."</option>";
}
echo " </select>";
echo "<form id='form_search' class='inline' method='get'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'calls.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
echo " <span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
echo " </form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<th>".$text['table-extension']."</th>\n";
if (permission_exists('call_forward')) { echo "<th>".$text['label-call-forward']."</th>\n"; }
if (permission_exists('follow_me')) { echo "<th>".$text['label-follow-me']."</th>\n"; }
if (permission_exists('do_not_disturb')) { echo "<th>".$text['label-dnd']."</th>\n"; }
echo "<th>".$text['label-description']."</th>\n";
echo " <td class='list_control_icon'>&nbsp;</td>\n";
echo $text['description-call_routing']."\n";
echo "<br /><br />\n";
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
}
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (!$is_included) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($extensions ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
echo " <th>".$text['label-extension']."</th>\n";
if (permission_exists('call_forward')) {
echo " <th>".$text['label-call-forward']."</th>\n";
}
if (permission_exists('follow_me')) {
echo " <th>".$text['label-follow-me']."</th>\n";
}
if (permission_exists('do_not_disturb')) {
echo " <th>".$text['label-dnd']."</th>\n";
}
echo " <th class='".($is_included ? 'hide-md-dn' : 'hide-sm-dn')."'>".$text['label-description']."</th>\n";
if ($_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
echo "</tr>\n";
if (is_array($extensions)) {
$x = 0;
foreach($extensions as $row) {
$tr_url = PROJECT_PATH."/app/calls/call_edit.php?id=".$row['extension_uuid']."&return_url=".urlencode($_SERVER['REQUEST_URI']);
$tr_link = (permission_exists('call_forward') || permission_exists('follow_me') || permission_exists('do_not_disturb')) ? "href='".$tr_url."'" : null;
echo "<tr ".$tr_link.">\n";
echo " <td valign='top' class='".$row_style[$c]."'><a ".$tr_link.">".escape($row['extension'])."</a></td>\n";
$list_row_url = PROJECT_PATH."/app/calls/call_edit.php?id=".$row['extension_uuid']."&return_url=".urlencode($_SERVER['REQUEST_URI']);
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (!$is_included && $extensions) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='extensions[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='extensions[$x][uuid]' value='".escape($row['extension_uuid'])."' />\n";
echo " </td>\n";
}
echo " <td><a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['extension'])."</a></td>\n";
if (permission_exists('call_forward')) {
echo " <td valign='top' class='".$row_style[$c]."'>".(($row['forward_all_enabled'] == 'true') ? escape(format_phone($row['forward_all_destination'])) : '&nbsp;')."</td>";
//-- inline toggle -----------------
//$button_label = $row['forward_all_enabled'] == 'true' ? ($row['forward_all_destination'] != '' ? escape(format_phone($row['forward_all_destination'])) : '('.$text['label-invalid'].')') : null;
//if (!$is_included) {
// echo " <td class='no-link'>";
// echo button::create(['type'=>'submit','class'=>'link','label'=>($button_label != '' ? $button_label : $text['label-disabled']),'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle_call_forward'); list_form_submit('form_list')"]);
// echo " </td>\n";
//}
//else {
// echo " <td>".$button_label."</td>";
//}
//unset($button_label);
//----------------------------------
echo " <td>\n";
echo $row['forward_all_enabled'] == 'true' ? escape(format_phone($row['forward_all_destination'])) : '&nbsp;';
echo " </td>\n";
}
if (permission_exists('follow_me')) {
if (is_uuid($row['follow_me_uuid'])) {
//get destination count if enabled
$follow_me_destination_count = 0;
if ($row['follow_me_enabled'] == 'true') {
$sql = "select count(follow_me_destination_uuid) as destination_count ";
$sql .= "from v_follow_me_destinations ";
$sql .= "where follow_me_uuid = :follow_me_uuid ";
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['follow_me_uuid'] = $row['follow_me_uuid'];
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$follow_me_destination_count = $database->select($sql, $parameters, 'column');
}
//-- inline toggle -----------------
//get destination count
//if ($row['follow_me_enabled'] == 'true' && is_uuid($row['follow_me_uuid'])) {
// $sql = "select count(*) from v_follow_me_destinations ";
// $sql .= "where follow_me_uuid = :follow_me_uuid ";
// $sql .= "and domain_uuid = :domain_uuid ";
// $parameters['follow_me_uuid'] = $row['follow_me_uuid'];
// $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
// $database = new database;
// $follow_me_destination_count = $database->select($sql, $parameters, 'column');
// $button_label = $follow_me_destination_count ? $text['label-enabled'].' ('.$follow_me_destination_count.')' : $text['label-invalid'];
// unset($sql, $parameters);
//}
//if (!$is_included) {
// echo " <td class='no-link'>\n";
// echo button::create(['type'=>'submit','class'=>'link','label'=>($button_label != '' ? $button_label : $text['label-disabled']),'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle_follow_me'); list_form_submit('form_list')"]);
// echo " </td>\n";
//}
//else {
// echo " <td>".$button_label."</td>";
//}
//unset($button_label);
//----------------------------------
//get destination count
$follow_me_destination_count = 0;
if ($row['follow_me_enabled'] == 'true' && is_uuid($row['follow_me_uuid'])) {
$sql = "select count(*) from v_follow_me_destinations ";
$sql .= "where follow_me_uuid = :follow_me_uuid ";
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['follow_me_uuid'] = $row['follow_me_uuid'];
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$follow_me_destination_count = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
}
echo " <td valign='top' class='".$row_style[$c]."'>\n";
if ($row['follow_me_enabled'] == 'true' && $follow_me_destination_count > 0) {
echo ' '.$text['label-enabled']." (".$follow_me_destination_count.")\n";
}
else {
echo " &nbsp;\n";
}
echo "</td>\n";
echo " <td>\n";
echo $follow_me_destination_count ? $text['label-enabled'].' ('.$follow_me_destination_count.')' : '&nbsp;';
echo " </td>\n";
}
if (permission_exists('do_not_disturb')) {
echo " <td valign='top' class='".$row_style[$c]."'>".(($row['do_not_disturb'] == 'true') ? $text['label-enabled'] : '&nbsp;')."</td>";
//-- inline toggle -----------------
//$button_label = $row['do_not_disturb'] == 'true' ? $text['label-enabled'] : null;
//if (!$is_included) {
// echo " <td class='no-link'>";
// echo button::create(['type'=>'submit','class'=>'link','label'=>($button_label != '' ? $button_label : $text['label-disabled']),'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle_do_not_disturb'); list_form_submit('form_list')"]);
// echo " </td>\n";
//}
//else {
// echo " <td>".$button_label."</td>";
//}
//----------------------------------
echo " <td>\n";
echo $row['do_not_disturb'] == 'true' ? $text['label-enabled'] : '&nbsp;';
echo " </td>\n";
}
echo " <td class='description overflow ".($is_included ? 'hide-md-dn' : 'hide-sm-dn')."'>".escape($row['description'])."&nbsp;</td>\n";
if ($_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
}
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['description'])."&nbsp;</td>\n";
echo " <td class='list_control_icon'><a href='".$tr_url."' alt='".$text['button-edit']."'>".$v_link_label_edit."</a></td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
} //end foreach
unset($sql, $extensions);
} //end if results
echo "</table>";
echo "<br />";
if (strlen($paging_controls) > 0 && (!$is_included)) {
echo "<center>".$paging_controls."</center>\n";
echo "<br /><br />\n";
$x++;
}
unset($extensions);
}
echo "</table>\n";
if (!$is_included) {
echo "<br />";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
require_once "resources/footer.php";
}
?>
?>

View File

@ -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
?>

View File

@ -121,7 +121,123 @@ include "root.php";
$cache->delete("directory:".$this->number_alias."@".$this->domain_name);
}
}
}
} //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 = 'do_not_disturb';
$this->list_page = 'calls.php';
$this->table = 'extensions';
$this->uuid_prefix = 'extension_';
$this->toggle_field = 'do_not_disturb';
$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) {
//toggle feature
$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];
//disable other features
if ($array[$this->table][$x][$this->toggle_field] == $this->toggle_values[0]) { //true
$array[$this->table][$x]['forward_all_enabled'] = $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
?>

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
?>
?>