From d00f55b609fa92c9069945a0afd397614b0c1cd2 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Wed, 14 Aug 2019 17:23:14 -0600 Subject: [PATCH] Update device_profiles.php --- app/devices/device_profiles.php | 240 +++++++++++++++++++++++--------- 1 file changed, 172 insertions(+), 68 deletions(-) diff --git a/app/devices/device_profiles.php b/app/devices/device_profiles.php index 9237c91a24..4493b76f71 100644 --- a/app/devices/device_profiles.php +++ b/app/devices/device_profiles.php @@ -17,12 +17,13 @@ The Initial Developer of the Original Code is Mark J Crane - Copyright (C) 2008-2012 All Rights Reserved. + Copyright (C) 2019 All Rights Reserved. Contributor(s): Mark J Crane */ + //includes require_once "root.php"; require_once "resources/require.php"; @@ -41,125 +42,228 @@ $language = new text; $text = $language->get(); -//get the http values and set them as variables - $search = $_GET["search"]; +//get the action + if (is_array($_POST["device_profiles"])) { + $device_profiles = $_POST["device_profiles"]; + foreach($device_profiles as $row) { + if ($row['action'] == 'delete') { + $action = 'delete'; + break; + } + } + } + +//delete the device_profiles + if (permission_exists('device_profile_delete')) { + if ($action == "delete") { + //download + $obj = new device_profiles; + $obj->delete($device_profiles); + //delete message + message::add($text['message-delete']); + } + } + +//get variables used to control the order $order_by = $_GET["order_by"]; $order = $_GET["order"]; +//validate the order by + if (strlen($order_by) > 0) { + $order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', $order_by); + } + +//validate the order + switch ($order) { + case 'asc': + break; + case 'desc': + break; + default: + $order = ''; + } + +//search string + if (isset($_GET["search"])) { + $search = strtolower($_GET["search"]); + } + +//add the search + if (isset($search)) { + $sql_search = "and ("; + $sql_search .= " lower(device_profile_name) like :search "; + $sql_search .= " or lower(device_profile_description) like :search "; + $sql_search .= ") "; + $parameters['search'] = $search; + } + //additional includes require_once "resources/header.php"; - $document['title'] = $text['title-profiles']; require_once "resources/paging.php"; -//common sql - $sql_where = "where (domain_uuid = :domain_uuid or domain_uuid is null) "; - if ($search != '') { - $sql_where .= "and ("; - $sql_where .= " device_profile_name like :search "; - $sql_where .= " or device_profile_description like :search "; - $sql_where .= ") "; - $parameters['search'] = '%'.$search.'%'; +//get the count + $sql = "select count(device_profile_uuid) from v_device_profiles "; + if ($_GET['show'] == "all" && permission_exists('device_profile_all')) { + $sql .= "where 1 = 1 "; + } + else { + $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; + } + if (isset($sql_search)) { + $sql .= $sql_search; } $parameters['domain_uuid'] = $domain_uuid; - -//prepare to page the results - $sql = "select count(*) from v_device_profiles "; - $sql .= $sql_where; $database = new database; $num_rows = $database->select($sql, $parameters, 'column'); //prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - $param = ""; + $param = "&search=".$search; + if ($_GET['show'] == "all" && permission_exists('device_profile_all')) { + $param .= "&show=all"; + } $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_mini, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page, true); //top + list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); //bottom $offset = $rows_per_page * $page; -//get the device profiles - $sql = str_replace('count(*)', '*', $sql); - $sql .= order_by($order_by, $order, 'device_profile_name'); - $sql .= limit_offset($rows_per_page, $offset); +//get the list + $sql = "select * from v_device_profiles "; + if ($_GET['show'] == "all" && permission_exists('device_profile_all')) { + $sql .= "where 1 = 1 "; + } + else { + $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; + } + if (isset($sql_search)) { + $sql .= $sql_search; + } + if (strlen($order_by) > 0) { $sql .= "order by $order_by $order "; } + $sql .= "limit :rows_per_page offset :offset "; + $parameters['domain_uuid'] = $domain_uuid; + $parameters['rows_per_page'] = $rows_per_page; + $parameters['offset'] = $offset; $database = new database; $device_profiles = $database->select($sql, $parameters, 'all'); - unset($sql, $parameters); + unset ($sql, $parameters); -//set row styles +//alternate the row style $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; +//define the checkbox_toggle function + echo "\n"; + //show the content - echo "\n"; + echo "
\n"; echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + if ($paging_controls_mini != '') { + echo " \n"; + } + echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; echo "
"; - echo " ".$text['header-profiles'].""; - echo "

"; - echo " ".$text['description-profiles']; + echo "
\n"; + echo " ".$text['title-device_profiles']." (".$num_rows.")\n"; echo " \n"; - echo "
\n"; - echo "     "; - echo " "; - echo " "; - echo "
\n"; + echo "
\n"; + echo "
\n"; + + if (permission_exists('device_profile_all')) { + if ($_GET['show'] == 'all') { + echo " "; + } + else { + echo " \n"; + } + } + + + //add buttons + if (!isset($id)) { + echo " "; + } + echo " \n"; + echo " \n"; + echo " ".$paging_controls_mini."
\n"; + echo " ".$text['description-device_profiles']."

\n"; echo "
\n"; - echo "
"; + echo "
\n"; echo "\n"; echo "\n"; - echo th_order_by('name', $text['label-profile_name'], $order_by, $order); - echo th_order_by('enabled', $text['label-profile_enabled'], $order_by, $order); - echo th_order_by('description', $text['label-profile_description'], $order_by, $order); - echo "\n"; + echo th_order_by('device_profile_name', $text['label-device_profile_name'], $order_by, $order); + echo th_order_by('device_profile_enabled', $text['label-device_profile_enabled'], $order_by, $order); + echo th_order_by('device_profile_description', $text['label-device_profile_description'], $order_by, $order); + echo " \n"; - echo "\n"; + else { + echo " \n"; + } + echo " \n"; + echo "\n"; if (is_array($device_profiles) && @sizeof($device_profiles) != 0) { + $x = 0; foreach($device_profiles as $row) { - $tr_link = (permission_exists('device_profile_edit')) ? "href='device_profile_edit.php?id=".escape($row['device_profile_uuid'])."'" : null; + if (permission_exists('device_profile_edit')) { + $tr_link = "href='device_profile_edit.php?id=".escape($row['device_profile_uuid'])."'"; + } echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; echo "\n"; - $c = ($c == 0) ? 1 : 0; - } - } - unset($device_profiles); + $x++; + if ($c==0) { $c=1; } else { $c=0; } + } //end foreach + unset($sql, $device_profiles); + } //end if results echo "\n"; - echo "\n"; + echo " \n"; echo "\n"; echo "
\n"; + echo " \n"; + echo " \n"; + echo " "; if (permission_exists('device_profile_add')) { - echo " ".$v_link_label_add."\n"; + echo " $v_link_label_add"; } - echo "
"; - echo (permission_exists('device_profile_edit')) ? "".escape($row['device_profile_name'])."" : escape($row['device_profile_name']); - echo !is_uuid($row['domain_uuid']) ? "    ".$text['select-global']."" : null; + echo " ".$text['label-'.escape($row['device_profile_enabled'])]." ".escape($row['device_profile_description'])." ".escape($row['device_profile_name'])." ".escape($row['device_profile_enabled'])." ".escape($row['device_profile_description'])." "; if (permission_exists('device_profile_edit')) { - echo "".$v_link_label_edit.""; + echo "$v_link_label_edit"; } if (permission_exists('device_profile_delete')) { - echo "".$v_link_label_delete.""; + echo ""; } echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 ".$paging_controls.""; - if (permission_exists('device_profile_add')) { - echo " ".$v_link_label_add.""; - } - echo "
\n"; - echo "
\n"; + echo "
\n"; + echo " ".$paging_controls; + echo "
"; + echo "
\n"; echo "

"; //include the footer