fusionpbx/app/extensions/extensions.php

341 lines
14 KiB
PHP
Raw Normal View History

<?php
/*
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/
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>
2019-09-05 07:15:10 +02:00
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>
*/
//includes
2019-11-30 19:12:41 +01:00
include_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
2019-11-18 21:31:06 +01:00
require_once "resources/paging.php";
//check permissions
if (permission_exists('extension_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
2019-11-18 21:31:06 +01:00
//get posted data
if (is_array($_POST['extensions'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$extensions = $_POST['extensions'];
}
2019-11-30 19:12:41 +01:00
//process posted data by action
if ($action != '' && is_array($extensions) && @sizeof($extensions) != 0) {
$obj = new extension;
switch ($action) {
case 'toggle':
if (permission_exists('extension_enabled')) {
$obj->toggle($extensions);
}
break;
2019-11-18 21:31:06 +01:00
2019-11-30 19:12:41 +01:00
case 'delete':
if (permission_exists('extension_delete')) {
$obj->delete($extensions);
}
break;
2019-11-18 21:31:06 +01:00
}
2019-11-30 19:12:41 +01:00
header('Location: extensions.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
2019-11-18 21:31:06 +01:00
}
//get order and order by
$order_by = $_GET["order_by"];
$order = $_GET["order"];
2015-03-22 09:48:50 +01:00
2019-11-18 21:31:06 +01:00
//add the search term
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
2019-11-18 21:31:06 +01:00
$sql_search = " and ( ";
$sql_search .= "lower(extension) like :search ";
$sql_search .= "or lower(number_alias) like :search ";
$sql_search .= "or lower(effective_caller_id_name) like :search ";
$sql_search .= "or lower(effective_caller_id_number) like :search ";
$sql_search .= "or lower(outbound_caller_id_name) like :search ";
$sql_search .= "or lower(outbound_caller_id_number) like :search ";
$sql_search .= "or lower(emergency_caller_id_name) like :search ";
$sql_search .= "or lower(emergency_caller_id_number) like :search ";
$sql_search .= "or lower(directory_first_name) like :search ";
$sql_search .= "or lower(directory_last_name) like :search ";
$sql_search .= "or lower(call_group) like :search ";
$sql_search .= "or lower(user_context) like :search ";
$sql_search .= "or lower(enabled) like :search ";
$sql_search .= "or lower(description) like :search ";
2017-12-09 21:08:09 +01:00
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
}
2019-11-18 21:31:06 +01:00
//get total extension count for domain
if (is_numeric($_SESSION['limit']['extensions']['numeric'])) {
$sql = "select count(*) from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$total_extensions = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
}
//get total extension count
2019-11-18 21:31:06 +01:00
$sql = "select count(*) from v_extensions where true ";
if (!($_GET['show'] == "all" && permission_exists('extension_all'))) {
2019-11-18 21:31:06 +01:00
$sql .= "and domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
}
2019-09-05 07:15:10 +02:00
$sql .= $sql_search;
$database = new database;
2019-11-18 21:31:06 +01:00
$num_rows = $database->select($sql, $parameters, 'column');
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
2019-11-18 21:31:06 +01:00
$param = "&search=".$search;
if ($_GET['show'] == "all" && permission_exists('extension_all')) {
$param .= "&show=all";
}
$page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
2019-11-18 21:31:06 +01:00
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page); //bottom
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true); //top
$offset = $rows_per_page * $page;
//get the extensions
2019-11-18 21:31:06 +01:00
$sql = str_replace('count(*)', '*', $sql);
if ($order_by == '' || $order_by == 'extension') {
if ($db_type == 'pgsql') {
$sql .= 'order by natural_sort(extension) '.$order; //function in app_defaults.php
}
else {
$sql .= 'order by extension '.$order;
}
}
else {
$sql .= order_by($order_by, $order);
}
2019-09-05 07:15:10 +02:00
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
2019-09-05 07:15:10 +02:00
$extensions = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
2019-11-18 21:31:06 +01:00
//get the registrations
if (permission_exists('extension_registered')) {
$obj = new registrations;
$registrations = $obj->get('all');
}
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
2019-09-05 07:15:10 +02:00
//include the header
2019-11-18 21:31:06 +01:00
$document['title'] = $text['title-extensions'];
2019-09-05 07:15:10 +02:00
require_once "resources/header.php";
2015-09-05 07:12:36 +02:00
//show the content
2019-11-18 21:31:06 +01:00
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['header-extensions']." (".$num_rows.")</b></div>\n";
echo " <div class='actions'>\n";
if (permission_exists('extension_import') && (!is_numeric($_SESSION['limit']['extensions']['numeric']) || $total_extensions < $_SESSION['limit']['extensions']['numeric'])) {
echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'link'=>'extension_imports.php']);
}
if (permission_exists('extension_export')) {
echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'link'=>'extension_download.php']);
}
$margin_left = permission_exists('extension_import') || permission_exists('extension_export') ? "margin-left: 15px;" : null;
if (permission_exists('extension_add') && (!is_numeric($_SESSION['limit']['extensions']['numeric']) || $total_extensions < $_SESSION['limit']['extensions']['numeric'])) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'style'=>$margin_left,'link'=>'extension_edit.php']);
unset($margin_left);
}
if (permission_exists('extension_enabled') && $extensions) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'style'=>$margin_left,'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
unset($margin_left);
}
if (permission_exists('extension_delete') && $extensions) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'style'=>$margin_left,'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
unset($margin_left);
}
echo "<form id='form_search' class='inline' method='get'>\n";
2017-12-09 21:08:09 +01:00
if (permission_exists('extension_all')) {
if ($_GET['show'] == 'all') {
2019-11-18 21:31:06 +01:00
echo " <input type='hidden' name='show' value='all'>";
2017-12-09 21:08:09 +01:00
}
else {
2019-11-18 21:31:06 +01:00
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
2017-12-09 21:08:09 +01:00
}
}
2019-11-18 21:31:06 +01:00
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'=>'extensions.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
2019-11-18 21:31:06 +01:00
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
2015-09-05 07:12:36 +02:00
echo " </form>\n";
2019-11-18 21:31:06 +01:00
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo $text['description-extensions']."\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 (permission_exists('extension_enabled') || permission_exists('extension_delete')) {
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";
}
2017-12-09 21:08:09 +01:00
if ($_GET['show'] == "all" && permission_exists('extension_all')) {
2019-11-18 21:31:06 +01:00
echo "<th>".$text['label-domain']."</th>\n";
//echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
2017-12-09 21:08:09 +01:00
}
echo th_order_by('extension', $text['label-extension'], $order_by, $order);
2019-11-18 21:31:06 +01:00
echo th_order_by('effective_caller_id_name', $text['label-effective_cid_name'], $order_by, $order, null, "class='hide-xs'");
echo th_order_by('outbound_caller_id_name', $text['label-outbound_cid_name'], $order_by, $order, null, "class='hide-sm-dn'");
echo th_order_by('call_group', $text['label-call_group'], $order_by, $order);
2019-08-16 19:25:32 +02:00
if (permission_exists("extension_user_context")) {
echo th_order_by('user_context', $text['label-user_context'], $order_by, $order);
}
if (permission_exists('extension_registered')) {
2019-06-03 21:50:56 +02:00
echo "<th>".$text['label-is_registered']."</th>\n";
}
2019-11-18 21:31:06 +01:00
echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'");
if (permission_exists('extension_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
echo "</tr>\n";
2019-11-03 04:12:12 +01:00
if (is_array($extensions) && @sizeof($extensions) != 0) {
2019-11-18 21:31:06 +01:00
$x = 0;
2015-09-05 07:12:36 +02:00
foreach($extensions as $row) {
if (permission_exists('extension_edit')) {
2019-11-18 21:31:06 +01:00
$list_row_url = "extension_edit.php?id=".urlencode($row['extension_uuid']).(is_numeric($page) ? '&page='.urlencode($page) : null);
}
2019-11-18 21:31:06 +01:00
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('extension_enabled') || permission_exists('extension_delete')) {
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";
}
2017-12-09 21:08:09 +01:00
if ($_GET['show'] == "all" && permission_exists('extension_all')) {
2019-11-18 21:31:06 +01:00
echo " <td>".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."</td>\n";
2017-12-09 21:08:09 +01:00
}
2019-11-18 21:31:06 +01:00
echo " <td>";
if (permission_exists('extension_edit')) {
2019-11-18 21:31:06 +01:00
echo "<a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['extension'])."</a>";
}
else {
2018-06-03 05:25:11 +02:00
echo escape($row['extension']);
}
2019-11-18 21:31:06 +01:00
echo " </td>\n";
echo " <td class='hide-xs'>".escape($row['effective_caller_id_name'])."&nbsp;</td>\n";
echo " <td class='hide-sm-dn'>".escape($row['outbound_caller_id_name'])."&nbsp;</td>\n";
echo " <td>".escape($row['call_group'])."&nbsp;</td>\n";
2019-08-16 19:25:32 +02:00
if (permission_exists("extension_user_context")) {
2019-11-18 21:31:06 +01:00
echo " <td>".escape($row['user_context'])."</td>\n";
2019-08-16 19:25:32 +02:00
}
if (permission_exists('extension_registered')) {
2019-11-18 21:31:06 +01:00
echo " <td>";
$extension_number = $row['extension'].'@'.$_SESSION['domain_name'];
$extension_number_alias = $row['number_alias'];
if(strlen($extension_number_alias) > 0) {
$extension_number_alias .= '@'.$_SESSION['domain_name'];
}
$found_count = 0;
2019-09-27 23:52:14 +02:00
if (is_array($registrations)) {
foreach ($registrations as $array) {
2019-11-18 21:31:06 +01:00
if ($extension_number == $array['user'] || ($extension_number_alias != '' && $extension_number_alias == $array['user'])) {
2019-09-27 23:52:14 +02:00
$found_count++;
}
}
}
if ($found_count > 0) {
2019-11-18 21:31:06 +01:00
echo $text['label-true']." (".$found_count.")";
}
else {
echo $text['label-false'];
}
2018-06-30 06:58:48 +02:00
unset($extension_number, $extension_number_alias, $found_count, $array);
echo "&nbsp;</td>\n";
}
2019-11-18 21:31:06 +01:00
if (permission_exists('extension_enabled')) {
echo " <td class='no-link center'>";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
}
2019-11-18 21:31:06 +01:00
else {
echo " <td class='center'>";
echo $text['label-'.$row['enabled']];
}
2019-11-18 21:31:06 +01:00
echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['description'])."</td>\n";
if (permission_exists('extension_edit') && $_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";
}
2019-11-18 21:31:06 +01:00
echo "</tr>\n";
$x++;
}
}
2019-11-18 21:31:06 +01:00
echo "</table>\n";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
2019-11-18 21:31:06 +01:00
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
2019-11-18 21:31:06 +01:00
echo "</form>\n";
2019-11-18 21:31:06 +01:00
//define keyboard shortcuts
if ($extensions) {
// check all
key_press('ctrl+a', 'down', 'document', null, null, "list_all_check();", true);
2019-11-18 21:31:06 +01:00
// delete checked
if (permission_exists('extension_delete')) {
key_press('delete', 'up', 'document', array('#search'), $text['confirm-delete'], "list_action_set('delete'); list_form_submit('form_list');", true);
}
}
2019-11-18 21:31:06 +01:00
unset($extensions);
//show the footer
require_once "resources/footer.php";
2017-12-09 21:08:09 +01:00
2019-11-03 04:12:12 +01:00
?>