From 5793de2851f8e0752884ca3b3d9b32364ece1703 Mon Sep 17 00:00:00 2001 From: reliberate Date: Mon, 28 Mar 2016 15:21:05 -0600 Subject: [PATCH] Destinations/Extensions/Voicemails: Better sorting ability. --- app/calls/calls.php | 2 +- app/destinations/destinations.php | 18 +++++++++++++----- app/extensions/extensions.php | 12 +++++------- app/voicemails/voicemails.php | 12 ++++++++++-- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/calls/calls.php b/app/calls/calls.php index 9ba6322017..236fcff45d 100644 --- a/app/calls/calls.php +++ b/app/calls/calls.php @@ -102,7 +102,7 @@ else { //rework select data query $sql = str_replace('count(extension_uuid) as count', '*', $sql); - $sql .= ' order by cast(extension as int)'; + $sql .= ' order by cast(extension as int) asc'; $sql .= " limit ".$rows_per_page." offset ".$offset." "; //execute select data query diff --git a/app/destinations/destinations.php b/app/destinations/destinations.php index 6bd8a315d0..f48e785139 100644 --- a/app/destinations/destinations.php +++ b/app/destinations/destinations.php @@ -40,10 +40,8 @@ else { //get the http values and set them as variables $search = check_str($_GET["search"]); - if (isset($_GET["order_by"])) { - $order_by = check_str($_GET["order_by"]); - $order = check_str($_GET["order"]); - } + $order_by = check_str($_GET["order_by"]); + $order = check_str($_GET["order"]); //includes and title require_once "resources/header.php"; @@ -113,7 +111,17 @@ else { $sql .= " or destination_description like '%".$search."%' "; $sql .= ") "; } - if (strlen($order_by) > 0) { $sql .= "order by $order_by $order "; } + if (strlen($order_by) > 0) { + if ($order_by == 'destination_type') { + $sql .= "order by destination_type ".$order.", destination_number asc "; + } + else { + $sql .= "order by ".$order_by." ".$order." "; + } + } + else { + $sql .= "order by destination_type asc, destination_number asc "; + } $sql .= "limit $rows_per_page offset $offset "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); diff --git a/app/extensions/extensions.php b/app/extensions/extensions.php index bb036da90d..a3b3e9130d 100644 --- a/app/extensions/extensions.php +++ b/app/extensions/extensions.php @@ -40,10 +40,8 @@ else { //get the http values and set them as variables $search = check_str($_GET["search"]); - if (isset($_GET["order_by"])) { - $order_by = check_str($_GET["order_by"]); - $order = check_str($_GET["order"]); - } + $order_by = check_str($_GET["order_by"]); + $order = check_str($_GET["order"]); //handle search term $search = check_str($_GET["search"]); @@ -100,11 +98,11 @@ require_once "resources/paging.php"; $sql = "select * from v_extensions "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= $sql_mod; //add search mod from above - if (isset($order_by)) { - $sql .= "order by $order_by $order "; + if (strlen($order_by) > 0) { + $sql .= ($order_by == 'extension') ? "order by cast(extension as int) ".$order." " : "order by ".$order_by." ".$order." "; } else { - $sql .= "order by extension asc "; + $sql .= "order by cast(extension as int) asc "; } $sql .= " limit $rows_per_page offset $offset "; $prep_statement = $db->prepare(check_sql($sql)); diff --git a/app/voicemails/voicemails.php b/app/voicemails/voicemails.php index 349a391743..a5b425a6f8 100644 --- a/app/voicemails/voicemails.php +++ b/app/voicemails/voicemails.php @@ -38,6 +38,10 @@ else { $language = new text; $text = $language->get(); +//retrieve order by + $order_by = check_str($_GET["order_by"]); + $order = check_str($_GET["order"]); + //set the voicemail id and voicemail uuid arrays foreach ($_SESSION['user']['extension'] as $index => $row) { if (strlen($row['number_alias']) > 0) { @@ -104,7 +108,6 @@ else { $rows_per_page = 150; $param = ""; if ($search != '') { $param .= "&search=".$search; } - if ($order_by != '') { $param .= "&order_by=".$order_by."&order=".$order; } $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); @@ -112,7 +115,12 @@ else { //get the list $sql = str_replace('count(*) as num_rows', '*', $sql); - $sql .= ($order_by != '') ? "order by ".$order_by." ".$order." " : "order by voicemail_id asc "; + if (strlen($order_by) > 0) { + $sql .= ($order_by == 'voicemail_id') ? "order by cast(voicemail_id as int) ".$order." " : "order by ".$order_by." ".$order." "; + } + else { + $sql .= "order by cast(voicemail_id as int) asc "; + } $sql .= "limit ".$rows_per_page." offset ".$offset." "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute();