From 02b35a7a990f05ad09a5413631c1f8619f621a8d Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 7 Nov 2019 09:00:29 -0700 Subject: [PATCH] Device: List view updates. --- app/contacts/contacts.php | 2 +- app/destinations/destinations.php | 2 +- app/devices/devices.php | 237 +++++++++++++++-------- app/devices/resources/classes/device.php | 175 ++++++++++++++--- app/xml_cdr/xml_cdr.php | 2 +- themes/default/app_config.php | 18 +- 6 files changed, 318 insertions(+), 118 deletions(-) diff --git a/app/contacts/contacts.php b/app/contacts/contacts.php index 00dc3239cb..7a712272eb 100644 --- a/app/contacts/contacts.php +++ b/app/contacts/contacts.php @@ -263,7 +263,7 @@ echo "".$paging_controls_mini.""; } if (permission_exists('contact_add')) { - echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>'file-import','link'=>'contact_import.php','style'=>'margin-left: 15px;']); + echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'link'=>'contact_import.php','style'=>'margin-left: 15px;']); } echo " \n"; echo " \n"; diff --git a/app/destinations/destinations.php b/app/destinations/destinations.php index 90d4ac9545..a4984a6a3c 100644 --- a/app/destinations/destinations.php +++ b/app/destinations/destinations.php @@ -198,7 +198,7 @@ echo button::create(['type'=>'button','label'=>$text['button-outbound'],'icon'=>'location-arrow','link'=>'?type=outbound'.($_GET['show'] == 'all' ? '&show=all' : null).($search != '' ? "&search=".urlencode($search) : null)]); echo button::create(['type'=>'button','label'=>$text['button-local'],'icon'=>'vector-square','link'=>'?type=local'.($_GET['show'] == 'all' ? '&show=all' : null).($search != '' ? "&search=".urlencode($search) : null)]); if (permission_exists('destination_import')) { - echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>'file-import','link'=>'destination_imports.php']); + echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'link'=>'destination_imports.php']); } echo " \n"; echo " \n"; diff --git a/app/devices/devices.php b/app/devices/devices.php index d105d903f4..0ccf7056a3 100644 --- a/app/devices/devices.php +++ b/app/devices/devices.php @@ -17,7 +17,8 @@ The Initial Developer of the Original Code is Mark J Crane - Copyright (C) 2008-2015 All Rights Reserved. + Portions created by the Initial Developer are Copyright (C) 2008 - 2019 + the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane @@ -27,6 +28,7 @@ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; + require_once "resources/paging.php"; //check permissions if (permission_exists('device_view')) { @@ -37,16 +39,42 @@ exit; } -//additional includes - require_once "resources/header.php"; - require_once "resources/paging.php"; - //add multi-lingual support $language = new text; $text = $language->get(); -//get the http values and set them as variables - $search = $_GET["search"]; +//get posted data + if (is_array($_POST['devices'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $devices = $_POST['devices']; + } + +//toggle the devices + if (permission_exists('device_edit')) { + if ($action == 'toggle' && is_array($devices) && @sizeof($devices) != 0) { + //toggle + $obj = new device; + $obj->toggle($devices); + //redirect + header('Location: devices.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + } + +//delete the devices + if (permission_exists('device_delete')) { + if ($action == 'delete' && is_array($devices) && @sizeof($devices) != 0) { + //delete + $obj = new device; + $obj->delete($devices); + //redirect + header('Location: devices.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + } + +//get order and order by and sanatize the values $order_by = $_GET["order_by"]; $order = $_GET["order"]; @@ -110,12 +138,14 @@ $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { $param = "&search=".$search."&show=all"; - } else { + } + else { $param = "&search=".$search; } $page = $_GET['page']; if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } - list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $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; //get the list @@ -174,54 +204,78 @@ } } +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//include the header + require_once "resources/header.php"; + //show the content - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['header-devices']." (".$total_devices.")\n"; - echo " \n"; - echo "
\n"; + echo "
\n"; + echo "
".$text['header-devices']." (".$num_rows.")
\n"; + echo "
\n"; + if (permission_exists('device_add') && (!is_numeric($_SESSION['limit']['devices']['numeric']) || ($total_devices < $_SESSION['limit']['devices']['numeric']))) { + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'device_edit.php']); + } + if (permission_exists('device_edit') && $devices) { + echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + if (permission_exists('device_delete') && $devices) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + echo "\n"; if (permission_exists('device_all')) { - if (isset($_GET['show']) && $_GET['show'] == 'all') { - echo " \n"; + if ($_GET['show'] == 'all') { + echo " "; } else { - echo " \n"; + echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']); } } - if (permission_exists('device_vendor_view')) { - echo " \n"; - } - if (permission_exists('device_profile_view')) { - echo " \n"; + echo ""; + 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'=>'devices.php','style'=>($search == '' ? 'display: none;' : null)]); + if ($paging_controls_mini != '') { + echo "".$paging_controls_mini.""; } + $margin_left = permission_exists('device_import') || permission_exists('device_export') || permission_exists('device_vendor_view') || permission_exists('device_profile_view') ? "margin-left: 15px;" : null; if (permission_exists('device_import')) { - echo " \n"; + echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'style'=>$margin_left,'link'=>'device_imports.php']); + unset($margin_left); } if (permission_exists('device_export')) { - echo " \n"; + echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'style'=>$margin_left,'link'=>'device_download.php']); + unset($margin_left); } - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['description-devices']; - echo "
\n"; - echo "
\n"; + if (permission_exists('device_vendor_view')) { + echo button::create(['type'=>'button','label'=>$text['button-vendors'],'icon'=>'fax','style'=>$margin_left,'link'=>'device_vendors.php']); + unset($margin_left); + } + if (permission_exists('device_profile_view')) { + echo button::create(['type'=>'button','label'=>$text['button-profiles'],'icon'=>'clone','style'=>$margin_left,'link'=>'device_profiles.php']); + unset($margin_left); + } + echo " \n"; + echo " \n"; + echo "
\n"; + echo "\n"; - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; + echo $text['description-devices']."\n"; + echo "

\n"; - echo "\n"; - echo "\n"; - if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo "\n"; + if (permission_exists('device_edit') || permission_exists('device_delete')) { + echo " \n"; + } + if ($_GET['show'] == "all" && permission_exists('device_all')) { echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param); } echo th_order_by('device_mac_address', $text['label-device_mac_address'], $order_by, $order); @@ -232,22 +286,16 @@ echo th_order_by('device_vendor', $text['label-device_vendor'], $order_by, $order); echo th_order_by('device_template', $text['label-device_template'], $order_by, $order); echo "\n"; - echo th_order_by('device_enabled', $text['label-device_enabled'], $order_by, $order); + echo th_order_by('device_enabled', $text['label-device_enabled'], $order_by, $order, null, "class='center'"); echo th_order_by('device_status', $text['label-device_status'], $order_by, $order); - echo th_order_by('device_description', $text['label-device_description'], $order_by, $order); - echo "\n"; } - else { - echo "  \n"; - } - echo "\n"; - echo "\n"; + echo "\n"; if (is_array($devices) && @sizeof($devices) != 0) { + $x = 0; foreach($devices as $row) { $device_profile_name = ''; @@ -257,50 +305,67 @@ } } - $tr_link = (permission_exists('device_edit')) ? "href='device_edit.php?id=".escape($row['device_uuid'])."'" : null; - echo "\n"; - if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { - echo " \n"; + if (permission_exists('device_edit')) { + $list_row_url = "device_edit.php?id=".urlencode($row['device_uuid']); } - echo " \n"; - echo " \n"; - if ($device_alternate) { - echo " \n"; + if (permission_exists('device_edit') || permission_exists('device_delete')) { + echo " \n"; } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; } - if (permission_exists('device_delete')) { - echo "$v_link_label_delete\n"; + echo " \n"; + echo " \n"; + if ($device_alternate) { + if (strlen($row['device_uuid_alternate']) > 0) { + echo " \n"; + } + else { + echo " \n"; + } + } + echo " \n"; + echo " \n"; + echo " \n"; + if (permission_exists('device_edit')) { + echo " \n"; + echo " \n"; + echo " \n"; + if (permission_exists('device_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; + } echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } + $x++; } } - unset($devices, $row); + unset($devices); - echo "\n"; echo "
\n"; + echo " \n"; + echo " ". $text['label-device_profiles']."\n"; - if (permission_exists('device_add')) { - if ($_SESSION['limit']['devices']['numeric'] == '' || ($_SESSION['limit']['devices']['numeric'] != '' && $total_devices < $_SESSION['limit']['devices']['numeric'])) { - echo " ".$v_link_label_add."\n"; - } + echo th_order_by('device_description', $text['label-device_description'], $order_by, $order, null, "class='hide-sm-dn'"); + if (permission_exists('device_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo "  
".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."\n"; - echo (permission_exists('device_edit')) ? "".format_mac(escape($row['device_mac_address']))."" : format_mac(escape($row['device_mac_address'])); - echo " ".escape($row['device_label'])." \n"; - if (strlen($row['device_uuid_alternate']) > 0) { - echo " ".escape($row['alternate_label'])."\n"; - } + echo "
\n"; + echo " \n"; + echo " \n"; echo " ".escape($row['device_vendor'])." ".escape($row['device_template'])." ".escape($device_profile_name)." ".$text['label-'.escape($row['device_enabled'])]." ".escape($row['device_provisioned_date'])." - ".escape($row['device_provisioned_method'])." - ".escape($row['device_provisioned_ip'])." ".escape($row['device_description'])." \n"; - if (permission_exists('device_edit')) { - echo "$v_link_label_edit\n"; + if ($_GET['show'] == "all" && permission_exists('device_all')) { + echo " ".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name']).""; + echo permission_exists('device_edit') ? "".escape(format_mac($row['device_mac_address']))."" : escape(format_mac($row['device_mac_address'])); + echo " ".escape($row['device_label'])."  ".escape($row['device_vendor'])." ".escape($row['device_template'])." ".escape($device_profile_name)." "; + echo $text['label-'.$row['device_enabled']]; } echo " ".escape($row['device_description'])." "; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo "
\n"; echo "
\n"; + echo "
".$paging_controls."
\n"; - echo $paging_controls."\n"; - echo "

\n"; + echo "\n"; + + echo "\n"; //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/devices/resources/classes/device.php b/app/devices/resources/classes/device.php index 3da5492c1a..f76fcbedc0 100644 --- a/app/devices/resources/classes/device.php +++ b/app/devices/resources/classes/device.php @@ -31,8 +31,31 @@ include "root.php"; public $domain_uuid; public $template_dir; + /** + * 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; + public function __construct() { //require_once "resources/classes/database.php"; + + //assign private variables + $this->app_name = 'devices'; + $this->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; + $this->permission_prefix = 'device_'; + $this->list_page = 'devices.php'; + $this->table = 'devices'; + $this->uuid_prefix = 'device_'; + $this->toggle_field = 'device_enabled'; + $this->toggle_values = ['true','false']; + } public function __destruct() { @@ -258,12 +281,11 @@ include "root.php"; return $this->template_dir; } - /** - * delete drives + * delete records */ - public function delete($devices) { - if (permission_exists('device_delete')) { + public function delete($records) { + if (permission_exists($this->permission_prefix.'delete')) { //add multi-lingual support $language = new text; @@ -273,39 +295,136 @@ include "root.php"; $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); - header('Location: devices.php'); + header('Location: '.$this->list_page); exit; } - //delete multiple devices - if (is_array($devices)) { - //get the action - foreach($devices as $row) { - if ($row['action'] == 'delete') { - $action = 'delete'; - break; + //delete multiple records + if (is_array($records) && @sizeof($records) != 0) { + + //build the delete array + foreach ($records as $x => $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid']; + $array['device_settings'][$x]['device_uuid'] = $record['uuid']; + $array['device_lines'][$x]['device_uuid'] = $record['uuid']; + $array['device_keys'][$x]['device_uuid'] = $record['uuid']; } } + //delete the checked rows - if ($action == 'delete') { - $database = new database; - foreach($devices as $x => $row) { - if ($row['action'] == 'delete' or $row['checked'] == 'true') { - $array['devices'][$x]['device_uuid'] = $row['device_uuid']; - $array['devices'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; - } - } - if (is_array($array) && @sizeof($array) != 0) { - $database->app_name = 'devices'; - $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; + if (is_array($array) && @sizeof($array) != 0) { + + //grant temporary permissions + $p = new permissions; + $p->add('device_setting_delete', 'temp'); + $p->add('device_line_delete', 'temp'); + $p->add('device_key_delete', 'temp'); + + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; $database->delete($array); unset($array); - } - unset($devices); + + //revoke temporary permissions + $p->delete('device_setting_delete', 'temp'); + $p->delete('device_line_delete', 'temp'); + $p->delete('device_key_delete', 'temp'); + + //write the provision files + if (strlen($_SESSION['provision']['path']['text']) > 0) { + $prov = new provision; + $prov->domain_uuid = $_SESSION['domain_uuid']; + $response = $prov->write(); + } + + //set message + message::add($text['message-delete']); + } + unset($records); } } - } //end the delete function - } + } -?> + /** + * toggle records + */ + public function toggle($records) { + if (permission_exists($this->permission_prefix.'edit')) { + + //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 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) { + $states[$row['uuid']] = $row['toggle']; + } + } + unset($sql, $parameters, $rows, $row); + } + + //build update array + $x = 0; + foreach($states as $uuid => $state) { + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid; + $array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0]; + $x++; + } + + //save the changes + if (is_array($array) && @sizeof($array) != 0) { + + //save the array + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->save($array); + unset($array); + + //write the provision files + if (strlen($_SESSION['provision']['path']['text']) > 0) { + $prov = new provision; + $prov->domain_uuid = $_SESSION['domain_uuid']; + $response = $prov->write(); + } + + //set message + message::add($text['message-toggle']); + } + unset($records, $states); + } + + } + } //method + + } //class + +?> \ No newline at end of file diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index 27493890ff..005c5d9ab5 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -161,7 +161,7 @@ if (permission_exists('xml_cdr_archive')) { echo button::create(['type'=>'button','label'=>$text['button-archive'],'icon'=>'archive','link'=>'xml_cdr_archive.php'.($_REQUEST['show'] == 'all' ? '?show=all' : null)]); } - echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>'file-export','onclick'=>"toggle_select('export_format'); this.blur();"]); + echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'onclick'=>"toggle_select('export_format'); this.blur();"]); echo "