Code formatting improved and some bugfixng
This commit is contained in:
277
search.php
277
search.php
@@ -1,178 +1,145 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
IP Reg, a PHP/MySQL IPAM tool
|
||||
Copyright (C) 2007-2009 Wietse Warendorff
|
||||
/*****************************************************************************
|
||||
IP Reg, a PHP/MySQL IPAM tool
|
||||
Copyright (C) 2007-2009 Wietse Warendorff (up to v0.5)
|
||||
Copyright (C) 2011-2023 Thomas Hooge
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*****************************************************************************/
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
include("includes.php");
|
||||
include("header.php");
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
For more information, visit http://sourceforge.net/projects/ipreg,
|
||||
or contact me at wietsew@users.sourceforge.net
|
||||
*****************************************************************************/
|
||||
// get string that was searched for ($search is already set in header.php)
|
||||
if (empty($search)) {
|
||||
// parse nosearch box
|
||||
$smarty->assign("nosearch", TRUE);
|
||||
} else {
|
||||
// hide nosearch box
|
||||
$smarty->assign("nosearch", FALSE);
|
||||
$smarty->assign("search", $search);
|
||||
|
||||
// start page
|
||||
// includes
|
||||
include("includes.php");
|
||||
// set needle
|
||||
$needle = '%' . $search . '%';
|
||||
|
||||
// start output
|
||||
include("header.php");
|
||||
// set counter
|
||||
$resultcounter = 0;
|
||||
|
||||
// set language variables
|
||||
$smarty->assign($lang);
|
||||
// asset
|
||||
$query = "SELECT
|
||||
asset_id AS id,
|
||||
asset_name AS name,
|
||||
asset_info AS description
|
||||
FROM
|
||||
asset
|
||||
WHERE
|
||||
asset_name LIKE '" . $needle . "'
|
||||
OR asset_hostname LIKE '" . $needle . "'
|
||||
OR asset_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
asset_name";
|
||||
|
||||
// get string that was searched for ($search is already set in header.php)
|
||||
if (empty($search)) {
|
||||
// parse nosearch box
|
||||
$smarty->assign("nosearch", TRUE);
|
||||
} else {
|
||||
// hide nosearch box
|
||||
$smarty->assign("nosearch", FALSE);
|
||||
$smarty->assign("search", $search);
|
||||
$assets = $db->db_select($query);
|
||||
$resultcounter += count($assets);
|
||||
$smarty->assign("assets", $assets);
|
||||
|
||||
// set needle
|
||||
$needle = '%' . $search . '%';
|
||||
// location
|
||||
$query = "SELECT
|
||||
location_id AS id,
|
||||
location_name AS name
|
||||
FROM
|
||||
location
|
||||
WHERE
|
||||
location_name LIKE '" . $needle . "'
|
||||
OR location_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
location_name";
|
||||
|
||||
// set counter
|
||||
$resultcounter = 0;
|
||||
$locations = $db->db_select($query);
|
||||
$resultcounter += count($locations);
|
||||
$smarty->assign("locations", $locations);
|
||||
|
||||
// setup asset
|
||||
// build query
|
||||
$query = "SELECT
|
||||
asset.asset_id AS id,
|
||||
asset.asset_name AS name,
|
||||
asset.asset_info AS description
|
||||
FROM
|
||||
asset
|
||||
WHERE
|
||||
asset.asset_name LIKE '" . $needle . "'
|
||||
OR asset.asset_hostname LIKE '" . $needle . "'
|
||||
OR asset.asset_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
asset.asset_name";
|
||||
// node
|
||||
$query = "SELECT
|
||||
node_id AS id,
|
||||
node_ip AS ip
|
||||
FROM
|
||||
node
|
||||
WHERE
|
||||
node_ip LIKE '" . $needle . "'
|
||||
OR node_mac LIKE '" . $needle . "'
|
||||
OR node_dns1 LIKE '" . $needle . "'
|
||||
OR node_dns2 LIKE '" . $needle . "'
|
||||
OR node_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
node_ip";
|
||||
|
||||
// run query
|
||||
$assets = $db->db_select($query);
|
||||
$resultcounter += count($assets);
|
||||
$smarty->assign("assets", $assets);
|
||||
$nodes = $db->db_select($query);
|
||||
$resultcounter += count($nodes);
|
||||
$smarty->assign("nodes", $nodes);
|
||||
|
||||
// setup location
|
||||
// build query
|
||||
$query = "SELECT
|
||||
location.location_id AS id,
|
||||
location.location_name AS name
|
||||
FROM
|
||||
location
|
||||
WHERE
|
||||
location.location_name LIKE '" . $needle . "'
|
||||
OR location.location_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
location.location_name";
|
||||
// subnet
|
||||
$query = "SELECT
|
||||
subnet_id AS id,
|
||||
subnet_address AS address
|
||||
FROM
|
||||
subnet
|
||||
WHERE
|
||||
subnet_address LIKE '" . $needle . "'
|
||||
OR subnet_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
subnet_address";
|
||||
|
||||
// run query
|
||||
$locations = $db->db_select($query);
|
||||
$resultcounter += count($locations);
|
||||
$smarty->assign("locations", $locations);
|
||||
// run query
|
||||
$subnets = $db->db_select($query);
|
||||
$resultcounter += count($subnets);
|
||||
$smarty->assign("subnets", $subnets);
|
||||
|
||||
// setup node
|
||||
// build query
|
||||
$query = "SELECT
|
||||
node.node_id AS id,
|
||||
node.node_ip AS ip
|
||||
FROM
|
||||
node
|
||||
WHERE
|
||||
node.node_ip LIKE '" . $needle . "'
|
||||
OR node.node_mac LIKE '" . $needle . "'
|
||||
OR node.node_dns1 LIKE '" . $needle . "'
|
||||
OR node.node_dns2 LIKE '" . $needle . "'
|
||||
OR node.node_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
node.node_ip";
|
||||
// vlan
|
||||
$query = "SELECT
|
||||
vlan_id AS id,
|
||||
vlan_name AS name
|
||||
FROM
|
||||
vlan
|
||||
WHERE
|
||||
vlan_name LIKE '" . $needle . "'
|
||||
OR vlan_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
vlan_name";
|
||||
|
||||
// run query
|
||||
$nodes = $db->db_select($query);
|
||||
$resultcounter += count($nodes);
|
||||
$smarty->assign("nodes", $nodes);
|
||||
$vlans = $db->db_select($query);
|
||||
$resultcounter += count($vlans);
|
||||
$smarty->assign("vlans", $vlans);
|
||||
|
||||
// setup subnet
|
||||
// build query
|
||||
$query = "SELECT
|
||||
subnet.subnet_id AS id,
|
||||
subnet.subnet_address AS address
|
||||
FROM
|
||||
subnet
|
||||
WHERE
|
||||
subnet.subnet_address LIKE '" . $needle . "'
|
||||
OR subnet.subnet_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
subnet.subnet_address";
|
||||
// setup zone
|
||||
$query = "SELECT
|
||||
zone_id AS id,
|
||||
zone_origin AS origin
|
||||
FROM
|
||||
zone
|
||||
WHERE
|
||||
zone_origin LIKE '" . $needle . "'
|
||||
OR zone_soa LIKE '" . $needle . "'
|
||||
OR zone_hostmaster LIKE '" . $needle . "'
|
||||
OR zone_ns1 LIKE '" . $needle . "'
|
||||
OR zone_ns2 LIKE '" . $needle . "'
|
||||
OR zone_ns3 LIKE '" . $needle . "'
|
||||
OR zone_mx1 LIKE '" . $needle . "'
|
||||
OR zone_mx2 LIKE '" . $needle . "'
|
||||
OR zone_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
zone_origin";
|
||||
|
||||
// run query
|
||||
$subnets = $db->db_select($query);
|
||||
$resultcounter += count($subnets);
|
||||
$smarty->assign("subnets", $subnets);
|
||||
$zones = $db->db_select($query);
|
||||
$resultcounter += count($zones);
|
||||
$smarty->assign("zones", $zones);
|
||||
|
||||
// setup vlan
|
||||
// build query
|
||||
$query = "SELECT
|
||||
vlan.vlan_id AS id,
|
||||
vlan.vlan_name AS name
|
||||
FROM
|
||||
vlan
|
||||
WHERE
|
||||
vlan.vlan_name LIKE '" . $needle . "'
|
||||
OR vlan.vlan_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
vlan.vlan_name";
|
||||
// grand totals
|
||||
$smarty->assign("resultcounter", $resultcounter);
|
||||
}
|
||||
|
||||
// run query
|
||||
$vlans = $db->db_select($query);
|
||||
$resultcounter += count($vlans);
|
||||
$smarty->assign("vlans", $vlans);
|
||||
$smarty->display("search.tpl");
|
||||
|
||||
// setup zone
|
||||
// build query
|
||||
$query = "SELECT
|
||||
zone_id AS id,
|
||||
zone_origin AS origin
|
||||
FROM
|
||||
zone
|
||||
WHERE
|
||||
zone_origin LIKE '" . $needle . "'
|
||||
OR zone_soa LIKE '" . $needle . "'
|
||||
OR zone_hostmaster LIKE '" . $needle . "'
|
||||
OR zone_ns1 LIKE '" . $needle . "'
|
||||
OR zone_ns2 LIKE '" . $needle . "'
|
||||
OR zone_ns3 LIKE '" . $needle . "'
|
||||
OR zone_mx1 LIKE '" . $needle . "'
|
||||
OR zone_mx2 LIKE '" . $needle . "'
|
||||
OR zone_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
zone_origin";
|
||||
|
||||
// run query
|
||||
$zones = $db->db_select($query);
|
||||
$resultcounter += count($zones);
|
||||
$smarty->assign("zones", $zones);
|
||||
|
||||
// grand totals
|
||||
$smarty->assign("resultcounter", $resultcounter);
|
||||
}
|
||||
|
||||
// end page
|
||||
// output
|
||||
$smarty->display("search.tpl");
|
||||
|
||||
// end output
|
||||
include("footer.php");
|
||||
include("footer.php");
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user