From b3cad9b434625fe6285e5c07935481ac6b9e648c Mon Sep 17 00:00:00 2001
From: phpipam <miha.petkovsek@telemach.si>
Date: Tue, 19 Dec 2023 08:58:49 +0100
Subject: [PATCH] Added tools and admin menu search

---
 app/admin/admin-menu-config.php        | 78 +++++++++++++-------------
 app/admin/index.php                    | 52 ++++++++++++++++-
 app/sections/menu/menu-tools-admin.php |  3 +-
 app/sections/menu/menu-tools.php       |  2 +-
 app/sections/user-menu.php             | 14 ++---
 app/tools/index.php                    | 52 ++++++++++++++++-
 app/tools/tools-menu-config.php        | 68 +++++++++++-----------
 js/magic.js                            |  8 ++-
 misc/CHANGELOG                         |  1 -
 9 files changed, 189 insertions(+), 89 deletions(-)

diff --git a/app/admin/admin-menu-config.php b/app/admin/admin-menu-config.php
index 08be4193..f6bfa72e 100644
--- a/app/admin/admin-menu-config.php
+++ b/app/admin/admin-menu-config.php
@@ -74,44 +74,44 @@ $admin_menu[_('Tools')][] =                 ["show"=>true, "icon"=>"fa-search-pl
 
 # inclusion check
 $admin_menu_items = [
-                    "api" => _("api"),
+                    "api"                    => _("api"),
                     "authentication-methods" => _("authentication-methods"),
-                    "password-policy" => _("password-policy"),
-                    "custom-fields" => _("custom-fields"),
-                    "dhcp" => _("dhcp"),
-                    "devices" => _("devices"),
-                    "device-types" => _("device-types"),
-                    "filter-fields" => _("filter-fields"),
-                    "required-fields" => _("required-fields"),
-                    "firewall-zones" => _("firewall-zones"),
-                    "groups" => _("groups"),
-                    "import-export" => _("import-export"),
-                    "instructions" => _("instructions"),
-                    "languages" => _("languages"),
-                    "mail" => _("mail"),
-                    "nameservers" => _("nameservers"),
-                    "powerDNS" => _("powerDNS"),
-                    "racks" => _("racks"),
-                    "replace-fields" => _("replace-fields"),
-                    "requests" => _("requests"),
-                    "ripe-import" => _("ripe-import"),
-                    "scan-agents" => _("scan-agents"),
-                    "sections" => _("sections"),
-                    "settings" => _("settings"),
-                    "snmp" => _("snmp"),
-                    "subnets" => _("subnets"),
-                    "tags" => _("tags"),
-                    "users" => _("users"),
-                    "verify-database" => _("verify-database"),
-                    "version-check" => _("version-check"),
-                    "vlans" => _("vlans"),
-                    "vrf" => _("vrf"),
-                    "widgets" => _("widgets"),
-                    "nat" => _("nat"),
-                    "locations" => _("locations"),
-                    "circuits" => _("circuits"),
-                    "pstn-prefixes" => _("pstn-prefixes"),
-                    "2fa" => _("2fa"),
-                    "customers" => _("customers"),
-                    "routing" => _("routing"),
+                    "password-policy"        => _("password-policy"),
+                    "custom-fields"          => _("custom-fields"),
+                    "dhcp"                   => _("dhcp"),
+                    "devices"                => _("devices"),
+                    "device-types"           => _("device-types"),
+                    "filter-fields"          => _("filter-fields"),
+                    "required-fields"        => _("required-fields"),
+                    "firewall-zones"         => _("firewall-zones"),
+                    "groups"                 => _("groups"),
+                    "import-export"          => _("import-export"),
+                    "instructions"           => _("instructions"),
+                    "languages"              => _("languages"),
+                    "mail"                   => _("mail"),
+                    "nameservers"            => _("nameservers"),
+                    "powerDNS"               => _("powerDNS"),
+                    "racks"                  => _("racks"),
+                    "replace-fields"         => _("replace-fields"),
+                    "requests"               => _("requests"),
+                    "ripe-import"            => _("ripe-import"),
+                    "scan-agents"            => _("scan-agents"),
+                    "sections"               => _("sections"),
+                    "settings"               => _("settings"),
+                    "snmp"                   => _("snmp"),
+                    "subnets"                => _("subnets"),
+                    "tags"                   => _("tags"),
+                    "users"                  => _("users"),
+                    "verify-database"        => _("verify-database"),
+                    "version-check"          => _("version-check"),
+                    "vlans"                  => _("vlans"),
+                    "vrf"                    => _("vrf"),
+                    "widgets"                => _("widgets"),
+                    "nat"                    => _("nat"),
+                    "locations"              => _("locations"),
+                    "circuits"               => _("circuits"),
+                    "pstn-prefixes"          => _("pstn-prefixes"),
+                    "2fa"                    => _("2fa"),
+                    "customers"              => _("customers"),
+                    "routing"                => _("routing"),
 			];
diff --git a/app/admin/index.php b/app/admin/index.php
index 5ba67cdf..3bee5f55 100755
--- a/app/admin/index.php
+++ b/app/admin/index.php
@@ -3,13 +3,19 @@
 <div id='dashboard' class="tools-all">
 <div class="row">
 
+<div class="col-lg-6 col-xs-12"></div>
+<div class="col-lg-6 col-xs-12" style="padding:5px 20px;">
+    <input type="text" class="form-control tools-filter-string" placeholder="<?php print _("Filter string"); ?>">
+</div>
+</div>
+
 <?php
 # print
 foreach($admin_menu as $k=>$menu) {
 
 	# headers
 	print "<h4>".$k."</h4>";
-	print "<hr>";
+	print "<hr class='hr-h4'>";
 
 	# items
 	foreach($menu as $t) {
@@ -29,4 +35,46 @@ foreach($admin_menu as $k=>$menu) {
 ?>
 </div>
 </div>
-</div>
\ No newline at end of file
+</div>
+
+<script type="text/javascript">
+$(document).ready(function () {
+	// focus search on load
+	$('.tools-filter-string').focus();
+
+	// start search
+	$('.tools-filter-string').keyup(function (e) {
+		doFilter()
+	});
+	// focus out filter
+	$('.tools-filter-string').focusout(function () {
+		doFilter()
+	});
+
+	// function
+	function doFilter () {
+	    var searchStringTools = $('.tools-filter-string').val().toLowerCase();
+
+	    // if null show all
+	    if(searchStringTools == "") {
+	        $('.widget-dash').show()
+	        $('.tools-all h4').show()
+	        $('.tools-all .hr-h4').show()
+	        return
+	    }
+
+	    // hide all titles
+	    $('.tools-all h4').hide();
+	    $('.tools-all .hr-h4').hide();
+
+	    // search
+	    $( ".widget-dash" ).each(function( index ) {
+	        var content = $(this).text().toLowerCase();
+	        // show or hide
+	        if(content.search(searchStringTools)===-1)  { $(this).hide() }
+	        else                                        { $(this).show() }
+	    });
+	}
+
+})
+</script>
\ No newline at end of file
diff --git a/app/sections/menu/menu-tools-admin.php b/app/sections/menu/menu-tools-admin.php
index 816ab677..c6f50675 100644
--- a/app/sections/menu/menu-tools-admin.php
+++ b/app/sections/menu/menu-tools-admin.php
@@ -15,6 +15,7 @@ if($User->is_admin(false)) {
 	print "		<ul class='dropdown-menu admin'>";
 
 	# all items
+	print "		<li class='nav-header'>"._('Available IPAM tools')."</li>";
 	print "		<li><a href='".create_link("administration")."'>"._('Show all settings')."</a></li>";
 	print "		<li class='divider'></li>";
 	# print admin items
@@ -37,11 +38,9 @@ if($User->is_admin(false)) {
 	}
 
 	print "		</ul>";
-
 	print "	</li>";
 	print "</ul>";
 }
-
 ?>
 
 
diff --git a/app/sections/menu/menu-tools.php b/app/sections/menu/menu-tools.php
index 434c48ef..c15f9cb5 100644
--- a/app/sections/menu/menu-tools.php
+++ b/app/sections/menu/menu-tools.php
@@ -151,7 +151,7 @@ $tool_items["search"] = array (
 	# first item - tools or dashboard
 	if ($_GET['page']=="dashboard") {
         print "<li class='first-item'>";
-        print " <a href='".create_link()."'><i class='fa fa-angle-right'></i> "._('Dashboard')."</a>";
+        print " <a href='".create_link()."'><i class='fa fa-dashboard'></i> "._('Dashboard')."</a>";
         print "</li>";
 	}
 	else {
diff --git a/app/sections/user-menu.php b/app/sections/user-menu.php
index 12075a90..7d9c8c60 100755
--- a/app/sections/user-menu.php
+++ b/app/sections/user-menu.php
@@ -25,13 +25,13 @@ foreach ($params as $k => $p) {
 
 # if all are off print all on!
 if($Params->subnets!="on" && $Params->addresses!="on" && $Params->vlans!="on" && $Params->vrf!="on" && $Params->pstn!="on" && $Params->circuits!="on" && $Params->customers!="on") {
-	$Params->subnets="on";
-	$Params->addresses="on";
-	$Params->vlans="on";
-	$Params->vrf="on";
-	$Params->pstn="on";
-	$Params->circuits="on";
-	$Params->customers="on";
+	$Params->subnets   ="on";
+	$Params->addresses ="on";
+	$Params->vlans     ="on";
+	$Params->vrf       ="on";
+	$Params->pstn      ="on";
+	$Params->circuits  ="on";
+	$Params->customers ="on";
 }
 ?>
 
diff --git a/app/tools/index.php b/app/tools/index.php
index fc435330..3c888aff 100755
--- a/app/tools/index.php
+++ b/app/tools/index.php
@@ -3,6 +3,12 @@
 <div id='dashboard' class="tools-all">
 <div class="row">
 
+<div class="col-lg-6 col-xs-12"></div>
+<div class="col-lg-6 col-xs-12" style="padding:5px 20px;">
+   	<input type="text" class="form-control tools-filter-string" placeholder="<?php print _("Filter string"); ?>">
+</div>
+</div>
+
 <?php
 # print
 foreach($tools_menu as $k=>$tool) {
@@ -11,7 +17,7 @@ foreach($tools_menu as $k=>$tool) {
 	if (sizeof($tool)>0) {
 		# headers
 		print "<h4>".$k."</h4>";
-		print "<hr>";
+		print "<hr class='hr-h4'>";
 
 		# items
 		foreach($tool as $t) {
@@ -32,4 +38,46 @@ foreach($tools_menu as $k=>$tool) {
 ?>
 </div>
 </div>
-</div>
\ No newline at end of file
+</div>
+
+<script type="text/javascript">
+$(document).ready(function () {
+	// focus search on load
+	$('.tools-filter-string').focus();
+
+	// start search
+	$('.tools-filter-string').keyup(function (e) {
+		doFilter()
+	});
+	// focus out filter
+	$('.tools-filter-string').focusout(function () {
+		doFilter()
+	});
+
+	// function
+	function doFilter () {
+	    var searchStringTools = $('.tools-filter-string').val().toLowerCase();
+
+	    // if null show all
+	    if(searchStringTools == "") {
+	        $('.widget-dash').show()
+	        $('.tools-all h4').show()
+	        $('.tools-all .hr-h4').show()
+	        return
+	    }
+
+	    // hide all titles
+	    $('.tools-all h4').hide();
+	    $('.tools-all .hr-h4').hide();
+
+	    // search
+	    $( ".widget-dash" ).each(function( index ) {
+	        var content = $(this).text().toLowerCase();
+	        // show or hide
+	        if(content.search(searchStringTools)===-1)  { $(this).hide() }
+	        else                                        { $(this).show() }
+	    });
+	}
+
+})
+</script>
\ No newline at end of file
diff --git a/app/tools/tools-menu-config.php b/app/tools/tools-menu-config.php
index 19a80c6c..f5c3f054 100644
--- a/app/tools/tools-menu-config.php
+++ b/app/tools/tools-menu-config.php
@@ -16,40 +16,40 @@ $tools_menu_icons[_('Devices')]   = "fa-desktop";
 
 # inclusion check
 $tools_menu_items = [
-					"changelog" => _("changelog"),
-					"dhcp" => _("dhcp"),
-					"devices" => _("devices"),
-					"favourites" => _("favourites"),
-					"firewall-zones" => _("firewall-zones"),
-					"instructions" => _("instructions"),
-					"ip-calculator" => _("ip-calculator"),
-					"logs" => _("logs"),
-					"multicast-networks" => _("multicast-networks"),
-					"pass-change" => _("pass-change"),
-					"powerDNS" => _("powerDNS"),
-					"request-ip" => _("request-ip"),
-					"requests" => _("requests"),
-					"racks" => _("racks"),
-					"scanned-networks" => _("scanned-networks"),
-					"documentation"=> _("documentation"),
-					"search" => _("search"),
-					"subnet-masks" => _("subnet-masks"),
-					"subnets" => _("subnets"),
-					"temp-shares" => _("temp-shares"),
-					"user-menu" => _("user-menu"),
-					"vlan" => _("vlan"),
-					"vrf" => _("vrf"),
-					"inactive-hosts" => _("inactive-hosts"),
-					"threshold" => _("threshold"),
-					"nat" => _("nat"),
-					"locations" => _("locations"),
-					"pstn-prefixes" => _("pstn-prefixes"),
-					"mac-lookup" => _("mac-lookup"),
-					"circuits" => _("circuits"),
-					"customers" => _("customers"),
-					"duplicates" => _("duplicates"),
-					"routing" => _("routing"),
- 					"vaults" => _("vaults"),
+						"changelog"          => _("changelog"),
+						"dhcp"               => _("dhcp"),
+						"devices"            => _("devices"),
+						"favourites"         => _("favourites"),
+						"firewall-zones"     => _("firewall-zones"),
+						"instructions"       => _("instructions"),
+						"ip-calculator"      => _("ip-calculator"),
+						"logs"               => _("logs"),
+						"multicast-networks" => _("multicast-networks"),
+						"pass-change"        => _("pass-change"),
+						"powerDNS"           => _("powerDNS"),
+						"request-ip"         => _("request-ip"),
+						"requests"           => _("requests"),
+						"racks"              => _("racks"),
+						"scanned-networks"   => _("scanned-networks"),
+						"documentation"      => _("documentation"),
+						"search"             => _("search"),
+						"subnet-masks"       => _("subnet-masks"),
+						"subnets"            => _("subnets"),
+						"temp-shares"        => _("temp-shares"),
+						"user-menu"          => _("user-menu"),
+						"vlan"               => _("vlan"),
+						"vrf"                => _("vrf"),
+						"inactive-hosts"     => _("inactive-hosts"),
+						"threshold"          => _("threshold"),
+						"nat"                => _("nat"),
+						"locations"          => _("locations"),
+						"pstn-prefixes"      => _("pstn-prefixes"),
+						"mac-lookup"         => _("mac-lookup"),
+						"circuits"           => _("circuits"),
+						"customers"          => _("customers"),
+						"duplicates"         => _("duplicates"),
+						"routing"            => _("routing"),
+						"vaults"             => _("vaults"),
 					];
 
 
diff --git a/js/magic.js b/js/magic.js
index 2e9e7055..75eee28f 100755
--- a/js/magic.js
+++ b/js/magic.js
@@ -32,6 +32,13 @@ $(document).keydown(function(e) {
     }
 });
 
+
+
+$(document).on("click", "a", function() {
+    hideTooltips()
+});
+
+
 // no enter in sortfields
 $(document).on("submit", ".searchFormClass", function() {
     return false;
@@ -1140,7 +1147,6 @@ $(document).on("mouseleave", '#user_menu', function(event){
     object1.slideUp();
 });
 
-
 //search export
 $(document).on("click", "#exportSearch", function(event){
     var searchTerm = $(this).attr('data-post');
diff --git a/misc/CHANGELOG b/misc/CHANGELOG
index 2005ad75..663cab65 100755
--- a/misc/CHANGELOG
+++ b/misc/CHANGELOG
@@ -11,7 +11,6 @@
     + Fixed php8 constructor fix for radius class (#3985);
     + Fixed Force mac address update during status update scan (#3791);
 
-
     Enhancements, changes:
     ----------------------------
     + Added support for redundant PowerDNS databases (#3981);
-- 
GitLab