From dc7ecc0133e84e18df8e902499c5d2b74921f24e Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 30 Sep 2015 20:11:18 +0000 Subject: [PATCH 1/2] Added bills to graph-widget --- html/ajax_search.php | 11 ++++++ html/includes/common/generic-graph.inc.php | 44 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/html/ajax_search.php b/html/ajax_search.php index 7d82a1ac9e..13328fce18 100644 --- a/html/ajax_search.php +++ b/html/ajax_search.php @@ -318,6 +318,17 @@ if (isset($_REQUEST['search'])) { $json = json_encode($device); die($json); + } + else if ($_REQUEST['type'] == 'bill') { + // Device search + if (is_admin() === true || is_read() === true) { + $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` WHERE `bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%' LIMIT 8"); + } + else { + $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` INNER JOIN `bill_perms` ON `bills`.bill_id = `bill_perms`.bill_id WHERE `bill_perms`.user_id = ? AND (`bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%')LIMIT 8", array($_SESSION['user_id'], $_SESSION['user_id'])); + } + $json = json_encode($results); + die($json); }//end if }//end if }//end if diff --git a/html/includes/common/generic-graph.inc.php b/html/includes/common/generic-graph.inc.php index e7cf4b9ed2..87bb883738 100644 --- a/html/includes/common/generic-graph.inc.php +++ b/html/includes/common/generic-graph.inc.php @@ -66,6 +66,8 @@ if( defined('show_settings') || empty($widget_settings) ) { + +
@@ -140,6 +142,14 @@ if( defined('show_settings') || empty($widget_settings) ) { $common_output[] = '
+
+
+ +
+
+ +
+
@@ -301,6 +311,40 @@ function '.$unique_id.'() { } }); + var '.$unique_id.'_bill = new Bloodhound({ + datumTokenizer: Bloodhound.tokenizers.obj.whitespace("munin"), + queryTokenizer: Bloodhound.tokenizers.whitespace, + remote: { + url: "ajax_search.php?search=%QUERY&type=bill", + filter: function (output) { + return $.map(output, function (item) { + return { + name: item.bill_name, + bill_id: item.bill_id, + }; + }); + }, + wildcard: "%QUERY" + } + }); + '.$unique_id.'_bill.initialize(); + $(".input_'.$unique_id.'_bill").typeahead({ + hint: true, + highlight: true, + minLength: 1, + classNames: { + menu: "typeahead-left" + } + }, + { + source: '.$unique_id.'_bill.ttAdapter(), + async: false, + templates: { + header: "
 Bill
", + suggestion: Handlebars.compile(\'

{{name}}

\') + } + }); + switch_'.$unique_id.'($("#select_'.$unique_id.'").val()); } function switch_'.$unique_id.'(data) { From c8c9f489cefa15c313a3f4977c77dc989bf4f288 Mon Sep 17 00:00:00 2001 From: f0o Date: Thu, 1 Oct 2015 11:02:15 +0000 Subject: [PATCH 2/2] SQL Typo --- html/ajax_search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/ajax_search.php b/html/ajax_search.php index 13328fce18..fd66756820 100644 --- a/html/ajax_search.php +++ b/html/ajax_search.php @@ -325,7 +325,7 @@ if (isset($_REQUEST['search'])) { $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` WHERE `bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%' LIMIT 8"); } else { - $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` INNER JOIN `bill_perms` ON `bills`.bill_id = `bill_perms`.bill_id WHERE `bill_perms`.user_id = ? AND (`bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%')LIMIT 8", array($_SESSION['user_id'], $_SESSION['user_id'])); + $results = dbFetchRows("SELECT `bills`.bill_id, `bills`.bill_name FROM `bills` INNER JOIN `bill_perms` ON `bills`.bill_id = `bill_perms`.bill_id WHERE `bill_perms`.user_id = ? AND (`bill_name` LIKE '%".$search."%' OR `bill_notes` LIKE '%".$search."%') LIMIT 8", array($_SESSION['user_id'])); } $json = json_encode($results); die($json);