diff --git a/app/number_translations/number_translations.php b/app/number_translations/number_translations.php index 20abeef2d8..396e9b8a72 100644 --- a/app/number_translations/number_translations.php +++ b/app/number_translations/number_translations.php @@ -2,34 +2,31 @@ /* 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 - Portions created by the Initial Developer are Copyright (C) 2008-2017 + Portions created by the Initial Developer are Copyright (C) 2017 the Initial Developer. All Rights Reserved. - - Contributor(s): - Matthew Vale */ -require_once "root.php"; -require_once "resources/require.php"; +//includes + require_once "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; //check permissions - require_once "resources/check_auth.php"; - if (!permission_exists('number_translation_view')) { + if (permission_exists('number_translation_view')) { + //access granted + } + else { echo "access denied"; exit; } @@ -38,40 +35,57 @@ require_once "resources/require.php"; $language = new text; $text = $language->get(); -//handle enable toggle - $number_translation_uuid = check_str($_REQUEST['id']); - $number_translation_enabled = check_str($_REQUEST['enabled']); - if ($number_translation_uuid != '' && $number_translation_enabled != '') { - $array['number_translations'][0]['number_translation_uuid'] = $number_translation_uuid; - $array['number_translations'][0]['number_translation_enabled'] = $number_translation_enabled; - $database = new database; - $database->app_name = 'number_translations'; - $database->save($array); - $number_translation = new number_translation; - $number_translation->xml(); - messages::add($text['message-update']); - unset($array, $number_translation); +//get the action + if (is_array($_POST["number_translations"])) { + $number_translations = $_POST["number_translations"]; + foreach($number_translations as $row) { + if ($row['action'] == 'delete') { + $action = 'delete'; + break; + } + } } -//set the http values as php variables - if (isset($_REQUEST["search"])) { $search = check_str($_REQUEST["search"]); } else { $search = null; } - if (isset($_REQUEST["order_by"])) { $order_by = check_str($_REQUEST["order_by"]); } else { $order_by = null; } - if (isset($_REQUEST["order"])) { $order = check_str($_REQUEST["order"]); } else { $order = null; } +//delete the number_translations + if (permission_exists('number_translation_delete')) { + if ($action == "delete") { + //download + $obj = new number_translations; + $obj->delete($number_translations); + //delete message + messages::add($text['message-delete']); + } + } -//includes +//get variables used to control the order + $order_by = check_str($_GET["order_by"]); + $order = check_str($_GET["order"]); + +//add the search term + $search = strtolower(check_str($_GET["search"])); + if (strlen($search) > 0) { + $sql_search = " ("; + $sql_search .= ") "; + } + +//additional includes require_once "resources/header.php"; require_once "resources/paging.php"; -//get the number of rows in the number_translation - $sql = "select count(*) as num_rows from v_number_translations "; - $sql .= "where true "; - if (strlen($search) > 0) { - $sql .= "and ("; - $sql .= " number_translation_name like '%".$search."%' "; - $sql .= " or number_translation_description like '%".$search."%' "; - $sql .= ") "; +//prepare to page the results + $sql = "select count(number_translation_uuid) as num_rows from v_number_translations "; + if ($_GET['show'] == "all" && permission_exists('number_translation_all')) { + if (isset($sql_search)) { + $sql .= "where ".$sql_search; + } + } else { + $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; + if (isset($sql_search)) { + $sql .= "and ".$sql_search; + } } - $prep_statement = $db->prepare(check_sql($sql)); + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $prep_statement = $db->prepare($sql); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); @@ -82,160 +96,159 @@ require_once "resources/require.php"; $num_rows = '0'; } } - unset($prep_statement, $result); +//prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - $param = ""; - if (strlen($app_uuid) > 0) { $param = "&app_uuid=".$app_uuid; } + $param = "&search=".$search; + if ($_GET['show'] == "all" && permission_exists('number_translation_all')) { + $param .= "&show=all"; + } $page = $_GET['page']; if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } - list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); + list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); $offset = $rows_per_page * $page; -//get the list of number_translations +//get the list $sql = "select * from v_number_translations "; - $sql .= "where true "; - if (strlen($search) > 0) { - $sql .= "and ("; - $sql .= " number_translation_name like '%".$search."%' "; - $sql .= " or number_translation_description like '%".$search."%' "; - $sql .= ") "; + if ($_GET['show'] == "all" && permission_exists('number_translation_all')) { + if (isset($sql_search)) { + $sql .= "where ".$sql_search; + } + } else { + $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; + if (isset($sql_search)) { + $sql .= "and ".$sql_search; + } } - if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } else { $sql .= "order by number_translation_name asc "; } - $sql .= " limit $rows_per_page offset $offset "; + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $sql .= "limit $rows_per_page offset $offset "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); - $number_translations = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $result_count = count($number_translations); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset ($prep_statement, $sql); -//set the alternating row style +//alternate the row style $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; -//set the title - $document['title'] = $text['title-number_translation']; +//define the checkbox_toggle function + echo "\n"; //show the content - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - + echo "
\n"; - echo " \n"; - echo " ".$text['header-number_translation']."\n"; - echo " \n"; - echo "

\n"; - echo "
\n"; - echo "
\n"; - echo " "; - if (strlen($order_by) > 0) { - echo " "; - echo " "; - } - echo " "; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; echo " \n"; - echo " \n"; - echo "\n"; - echo "
\n"; - echo " \n"; - echo " " . $text['description-number_translation'] . "\n"; - echo " \n"; - echo "
"; - echo "
"; + echo " ".$text['title-number_translations']."\n"; + echo "
\n"; + echo " \n"; - echo "\n"; + if (permission_exists('number_translation_all')) { + if ($_GET['show'] == 'all') { + echo " "; + } + else { + echo " \n"; + } + } + + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " ".$text['title_description-number_translation']."

\n"; + echo " \n"; + echo " \n"; + echo "\n"; + + echo "
\n"; echo "\n"; echo "\n"; - if (permission_exists('number_translation_delete') && $result_count > 0) { - echo ""; + echo " \n"; + echo th_order_by('number_translation_name', $text['label-number_translation_name'], $order_by, $order); + echo th_order_by('number_translation_enabled', $text['label-number_translation_enabled'], $order_by, $order); + echo th_order_by('number_translation_description', $text['label-number_translation_description'], $order_by, $order); + echo " \n"; - echo "\n"; + echo " \n"; + echo "\n"; - if ($result_count > 0) { - foreach($number_translations as $row) { - $tr_link = "href='number_translation_edit.php?id=".$row['number_translation_uuid']."'"; - echo "\n"; - if (permission_exists("number_translation_delete")) { - echo " \n"; - $number_translation_ids[] = 'checkbox_'.$row['number_translation_uuid']; - } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; + //echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; echo "\n"; + $x++; if ($c==0) { $c=1; } else { $c=0; } } //end foreach unset($sql, $result, $row_count); } //end if results echo "\n"; - echo "
\n"; + echo " \n"; + echo " "; + if (permission_exists('number_translation_add')) { + echo " $v_link_label_add"; } - echo th_order_by('number_translation_name', $text['label-name'], $order_by, $order, $app_uuid, null, (($search != '') ? "search=".$search : null)); - echo th_order_by('number_translation_enabled', $text['label-enabled'], $order_by, $order, $app_uuid, "style='text-align: center;'", (($search != '') ? "search=".$search : null)); - echo th_order_by('number_translation_description', $text['label-description'], $order_by, $order, $app_uuid, null, (($search != '') ? "search=".$search : null)); - echo ""; - if (permission_exists('number_translation_delete') && $result_count > 0) { - echo "".$v_link_label_delete.""; + else { + echo " \n"; } - echo "
"; - echo $row['number_translation_name']; - echo " ".((strlen($row['number_translation_description']) > 0) ? $row['number_translation_description'] : " ")."\n"; + if (is_array($result)) { + $x = 0; + foreach($result as $row) { if (permission_exists('number_translation_edit')) { - echo " $v_link_label_edit"; + $tr_link = "href='number_translation_edit.php?id=".$row['number_translation_uuid']."'"; + } + echo "
".$row['number_translation_name']." ".$row['number_translation_details']." ".$row['number_translation_enabled']." ".$row['number_translation_description']." "; + if (permission_exists('number_translation_edit')) { + echo "$v_link_label_edit"; } if (permission_exists('number_translation_delete')) { - echo " $v_link_label_delete"; + echo ""; } echo "
\n"; + echo "\n"; echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; echo " \n"; - echo "
 ".$paging_controls." $paging_controls"; - if (permission_exists('number_translation_edit')) { - echo " $v_link_label_add"; + if (permission_exists('number_translation_add')) { + echo "$v_link_label_add"; } - if (permission_exists('number_translation_delete') && $result_count > 0) { - echo " ".$v_link_label_delete.""; + else { + echo " "; } echo "
\n"; + echo "
\n"; echo "\n"; echo "\n"; - echo ""; - echo "

"; - echo "
"; - - if (sizeof($number_translation_ids) > 0) { - echo "\n"; - } + echo "\n"; + echo "

"; //include the footer require_once "resources/footer.php"; -//unset the variables - unset ($result_count); - unset ($result); - unset ($key); - unset ($val); - unset ($c); - -?> \ No newline at end of file +?>