From 41dfedd7737aa6a2b926a3b8379586a95af0217a Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Wed, 15 Apr 2015 06:08:18 +0000 Subject: [PATCH] Default Settings: Better/cleaner search functionality. --- .../default_settings/default_setting_edit.php | 6 +- core/default_settings/default_settings.php | 163 +++++++++--------- 2 files changed, 88 insertions(+), 81 deletions(-) diff --git a/core/default_settings/default_setting_edit.php b/core/default_settings/default_setting_edit.php index 5ad378321a..afbcb8638e 100644 --- a/core/default_settings/default_setting_edit.php +++ b/core/default_settings/default_setting_edit.php @@ -42,6 +42,7 @@ else { if (isset($_REQUEST["id"])) { $action = "update"; $default_setting_uuid = check_str($_REQUEST["id"]); + $search = check_str($_REQUEST['search']); } else { $action = "add"; @@ -136,7 +137,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { unset($sql); $_SESSION["message"] = $text['message-update']; - header("Location: default_settings.php#".$default_setting_category); + header("Location: default_settings.php".(($search != '') ? "?search=".$search : null)."#".$default_setting_category); return; } //if ($action == "update") } //if ($_POST["persistformvar"] != "true") @@ -183,7 +184,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "".$text['header-default_setting-edit']."\n"; } echo ""; - echo " "; + echo " "; echo " \n"; echo "\n"; echo "\n"; @@ -551,6 +552,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " \n"; if ($action == "update") { echo " \n"; + echo " \n"; } echo "
"; echo " \n"; diff --git a/core/default_settings/default_settings.php b/core/default_settings/default_settings.php index 29471a53d6..8d533b9874 100644 --- a/core/default_settings/default_settings.php +++ b/core/default_settings/default_settings.php @@ -44,6 +44,7 @@ else { $default_setting_uuids = $_REQUEST["id"]; $enabled = check_str($_REQUEST['enabled']); $category = check_str($_REQUEST['category']); + $search = check_str($_REQUEST['search']); if (sizeof($default_setting_uuids) == 1 && $enabled != '') { $sql = "update v_default_settings set "; @@ -53,7 +54,7 @@ else { unset($sql); $_SESSION["message"] = $text['message-update']; - header("Location: default_settings.php#".$category); + header("Location: default_settings.php".(($search != '') ? "?search=".$search : null)."#".$category); exit; } @@ -164,7 +165,7 @@ else { $_SESSION["message"] = $text['message-copy_failed']; } - header("Location: default_settings.php"); + header("Location: default_settings.php".(($search != '') ? "?search=".$search : null)); exit; } @@ -188,7 +189,7 @@ else { $_SESSION["message_mood"] = "negative"; } - header("Location: default_settings.php"); + header("Location: default_settings.php".(($search != '') ? "?search=".$search : null)); exit; } } // post @@ -225,20 +226,20 @@ else { echo " }\n"; echo "\n"; echo " $( document ).ready(function() {\n"; - echo " // scroll to previous category\n"; - echo " var category_span_id;\n"; - echo " var url = document.location.href;\n"; - echo " var hashindex = url.indexOf('#');\n"; - echo " if (hashindex == -1) { }\n"; - echo " else {\n"; - echo " category_span_id = url.substr(hashindex + 1);\n"; - echo " }\n"; - echo " if (category_span_id) {\n"; - echo " $('#page').animate({scrollTop: $('#anchor_'+category_span_id).offset().top - 200}, 'slow');\n"; - echo " }\n"; - echo " else {\n"; - echo " $('#default_setting_search').focus();\n"; - echo " }\n"; + echo " $('#default_setting_search').focus();\n"; + if ($search == '') { + echo " // scroll to previous category\n"; + echo " var category_span_id;\n"; + echo " var url = document.location.href;\n"; + echo " var hashindex = url.indexOf('#');\n"; + echo " if (hashindex == -1) { }\n"; + echo " else {\n"; + echo " category_span_id = url.substr(hashindex + 1);\n"; + echo " }\n"; + echo " if (category_span_id) {\n"; + echo " $('#page').animate({scrollTop: $('#anchor_'+category_span_id).offset().top - 200}, 'slow');\n"; + echo " }\n"; + } echo " });\n"; echo ""; } @@ -255,7 +256,7 @@ else { echo " ".$text['description-default_settings']; echo " \n"; echo " "; - echo " \n"; + echo " \n"; if (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) { echo " "; echo " "; @@ -316,37 +317,28 @@ else { $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; - echo "\n"; - if ($result_count > 0) { $previous_category = ''; foreach($result as $row) { if ($previous_category != $row['default_setting_category']) { $c = 0; - echo "\n"; - echo "
\n"; if ($previous_category != '') { - echo " "; - echo "
"; + echo "
"; + echo ""; } - echo "
\n"; - echo " \n"; - if (strtolower($row['default_setting_category']) == "api") { - echo " API"; + echo "
"; + echo ""; + echo ""; + switch (strtolower($row['default_setting_category'])) { + case "api" : echo "API"; break; + case "cdr" : echo "CDR"; break; + case "ldap" : echo "LDAP"; break; + default: echo ucwords(str_replace("_", " ", $row['default_setting_category'])); } - else if (strtolower($row['default_setting_category']) == "cdr") { - echo " CDR"; - } - else if (strtolower($row['default_setting_category']) == "ldap") { - echo " LDAP"; - } - else { - echo " ".ucwords(str_replace("_", " ", $row['default_setting_category'])); - } - echo " \n"; - echo " \n"; - echo "\n"; + echo "\n"; + + echo "\n"; echo "\n"; if ( (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) || @@ -370,7 +362,7 @@ else { echo "\n"; } - $tr_link = (permission_exists('default_setting_edit')) ? "href='default_setting_edit.php?id=".$row['default_setting_uuid']."'" : null; + $tr_link = (permission_exists('default_setting_edit')) ? "href=\"javascript:document.location.href='default_setting_edit.php?id=".$row['default_setting_uuid']."&search='+$('#default_setting_search').val();\"" : null; echo "\n"; if ( (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) || @@ -381,7 +373,7 @@ else { } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; //populate search/filter arrays + $array_categories[] = $row['default_setting_category']; $array_setting_uuids[] = $row['default_setting_uuid']; $array_setting_subcategories[] = $row['default_setting_subcategory']; $array_setting_types[] = $row['default_setting_name']; @@ -441,30 +438,13 @@ else { $c = ($c == 0) ? 1 : 0; } //end foreach + + echo "
"; if (permission_exists('default_setting_edit')) { - echo "".$row['default_setting_subcategory'].""; + echo "".$row['default_setting_subcategory'].""; } else { echo $row['default_setting_subcategory']; @@ -406,10 +398,14 @@ else { echo " ".ucwords($row['default_setting_value']); } else if ($category == "email" && $subcategory == "smtp_password" && $name == "var" ) { - echo " ********  \n"; + echo " "; + for ($d = 1; $d <= strlen($row['default_setting_value']); $d++) { echo "*"; } + echo " \n"; } else if ($category == "provision" && $subcategory == "password" && $name == "var" ) { - echo " ********  \n"; + echo " "; + for ($d = 1; $d <= strlen($row['default_setting_value']); $d++) { echo "*"; } + echo " \n"; } else { echo " ".htmlspecialchars($row['default_setting_value']); @@ -417,20 +413,21 @@ else { echo "  \n"; echo " ".$row['default_setting_description']." "; if (permission_exists('default_setting_edit')) { - echo "$v_link_label_edit"; + echo "$v_link_label_edit"; } if (permission_exists('default_setting_delete')) { - echo "$v_link_label_delete"; + echo "$v_link_label_delete"; } echo "
"; + echo "
"; + unset($sql, $result, $row_count); } //end if results - echo "\n"; - if ( - (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) || - permission_exists("domain_delete") - ) { - $colspan = 7; - } - else { - $colspan = 6; - } - echo "\n"; - if (permission_exists('default_setting_add')) { - echo "$v_link_label_add"; - } - if (permission_exists('default_setting_delete')) { - echo "".$v_link_label_delete.""; - } - echo "\n"; - echo "\n"; - - echo ""; echo "
"; echo $paging_controls; echo "


"; @@ -486,31 +466,56 @@ else { echo "\n"; } +//echo "

".print_r($array_categories, true)."



"; + //setting search script echo "\n"; + + + //include the footer require_once "resources/footer.php"; ?> \ No newline at end of file