Changes adopted from version 0.5
This commit is contained in:
357
search.php
357
search.php
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
IP Reg, a PHP/MySQL IPAM tool
|
||||
Copyright (C) 2008 Wietse Warendorff
|
||||
Copyright (C) 2007-2009 Wietse Warendorff
|
||||
|
||||
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
|
||||
@@ -20,21 +20,25 @@
|
||||
or contact me at wietsew@users.sourceforge.net
|
||||
*****************************************************************************/
|
||||
|
||||
// includes
|
||||
include("includes.php");
|
||||
// start page
|
||||
// includes
|
||||
include("includes.php");
|
||||
|
||||
// start output
|
||||
include("header.php");
|
||||
|
||||
// set template
|
||||
$tp = new Template("tpl/search.tpl", $config_yapter_error);
|
||||
|
||||
// set language variables
|
||||
$tp->setvars($lang);
|
||||
|
||||
// start output
|
||||
include("header.php");
|
||||
|
||||
// set template
|
||||
$tp = new Template("tpl/search.tpl");
|
||||
|
||||
// set language variables
|
||||
$tp->setvars($lang);
|
||||
|
||||
// get string that was searched for
|
||||
// get string that was searched for ($search is allready set in header.php)
|
||||
if (empty($search)) {
|
||||
// parse nosearch box
|
||||
$tp->parse("nosearch");
|
||||
|
||||
// hide others
|
||||
$tp->hide("asset");
|
||||
$tp->hide("location");
|
||||
$tp->hide("node");
|
||||
@@ -42,89 +46,276 @@
|
||||
$tp->hide("vlan");
|
||||
$tp->hide("resultcount");
|
||||
} else {
|
||||
// hide nosearch box
|
||||
$tp->hide("nosearch");
|
||||
|
||||
// set needle and counter
|
||||
// set needle
|
||||
$needle = '%' . $search . '%';
|
||||
|
||||
// set counter
|
||||
$resultcounter = 0;
|
||||
|
||||
// search assets
|
||||
$result = mysql_query("SELECT asset_id, asset_name FROM asset WHERE asset_name LIKE '$needle' OR asset_info LIKE '%$needle%' ORDER BY asset_name") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("counter", $i+1);
|
||||
$tp->set("item_name", $lang['lang_assets']);
|
||||
$tp->set("item", "asset");
|
||||
$tp->set("id", $row->asset_id);
|
||||
$tp->set("name", $row->asset_name);
|
||||
$resultcounter++;
|
||||
$tp->parse("row");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("asset") : $tp->hide("asset"));
|
||||
$tp->clear("row");
|
||||
// setup asset
|
||||
// build query
|
||||
$query = "SELECT
|
||||
asset.asset_id AS asset_id,
|
||||
asset.asset_name AS asset_name
|
||||
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";
|
||||
|
||||
// run query
|
||||
$assets = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$counter = count($assets);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("counter", $counter);
|
||||
|
||||
// search locations
|
||||
$result = mysql_query("SELECT location_id, location_name FROM location WHERE location_name LIKE '$needle' OR location_info LIKE '%$needle%' ORDER BY location_name") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("counter", $i+1);
|
||||
$tp->set("item_name", $lang['lang_locations']);
|
||||
$tp->set("item", "location");
|
||||
$tp->set("id", $row->location_id);
|
||||
$tp->set("name", $row->location_name);
|
||||
$resultcounter++;
|
||||
$tp->parse("row");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("location") : $tp->hide("location"));
|
||||
$tp->clear("row");
|
||||
// any assets?
|
||||
if ($counter>0) {
|
||||
// get objects
|
||||
foreach($assets AS $asset) {
|
||||
// send to tpl
|
||||
$tp->set("item_name", $lang['lang_assets']);
|
||||
$tp->set("item", "asset");
|
||||
$tp->set("id", $asset['asset_id']);
|
||||
$tp->set("name", $asset['asset_name']);
|
||||
|
||||
// parse block
|
||||
$tp->parse("row");
|
||||
|
||||
// update counter
|
||||
$resultcounter++;
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("asset");
|
||||
} else {
|
||||
// parse block
|
||||
$tp->hide("asset");
|
||||
}
|
||||
|
||||
// clear row
|
||||
$tp->clear("row");
|
||||
|
||||
// search node
|
||||
$result = mysql_query("SELECT node_id, ip FROM node WHERE ip LIKE '$needle' OR mac LIKE '$needle' OR dns1 LIKE '$needle' OR dns2 LIKE '$needle' OR node_info LIKE '$needle' ORDER BY ip") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("counter", $i+1);
|
||||
$tp->set("item_name", $lang['lang_nodes']);
|
||||
$tp->set("item", "node");
|
||||
$tp->set("id", $row->node_id);
|
||||
$tp->set("name", $row->ip);
|
||||
$resultcounter++;
|
||||
$tp->parse("row");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("node") : $tp->hide("node"));
|
||||
$tp->clear("row");
|
||||
// setup location
|
||||
// build query
|
||||
$query = "SELECT
|
||||
location.location_id AS location_id,
|
||||
location.location_name AS location_name
|
||||
FROM
|
||||
location
|
||||
WHERE
|
||||
location.location_name LIKE '" . $needle . "'
|
||||
OR location.location_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
location.location_name";
|
||||
|
||||
// run query
|
||||
$locations = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$counter = count($locations);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("counter", $counter);
|
||||
|
||||
// search subnet
|
||||
$result = mysql_query("SELECT subnet_id, subnet_address FROM subnet WHERE subnet_address LIKE '$needle' OR subnet_info LIKE '%$needle%' ORDER BY INET_ATON(subnet_address)") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("counter", $i+1);
|
||||
$tp->set("item_name", $lang['lang_subnets']);
|
||||
$tp->set("item", "subnet");
|
||||
$tp->set("id", $row->subnet_id);
|
||||
$tp->set("name", $row->subnet_address);
|
||||
$resultcounter++;
|
||||
$tp->parse("row");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("subnet") : $tp->hide("subnet"));
|
||||
$tp->clear("row");
|
||||
// any locations?
|
||||
if ($counter>0) {
|
||||
// get objects
|
||||
foreach($locations AS $location) {
|
||||
// send to tpl
|
||||
$tp->set("item_name", $lang['lang_locations']);
|
||||
$tp->set("item", "location");
|
||||
$tp->set("id", $location['location_id']);
|
||||
$tp->set("name", $location['location_name']);
|
||||
|
||||
// parse block
|
||||
$tp->parse("row");
|
||||
|
||||
// update counter
|
||||
$resultcounter++;
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("location");
|
||||
} else {
|
||||
// parse block
|
||||
$tp->hide("location");
|
||||
}
|
||||
|
||||
// clear row
|
||||
$tp->clear("row");
|
||||
|
||||
// search vlan
|
||||
$result = mysql_query("SELECT vlan_id, vlan_name FROM vlan WHERE vlan_name LIKE '$needle' OR vlan_info LIKE '%$needle%' ORDER BY vlan_name") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("counter", $i+1);
|
||||
$tp->set("item_name", $lang['lang_vlans']);
|
||||
$tp->set("item", "vlan");
|
||||
$tp->set("id", $row->vlan_id);
|
||||
$tp->set("name", $row->vlan_name);
|
||||
$resultcounter++;
|
||||
$tp->parse("row");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("vlan") : $tp->hide("vlan"));
|
||||
$tp->clear("row");
|
||||
// setup node
|
||||
// build query
|
||||
$query = "SELECT
|
||||
node.node_id AS node_id,
|
||||
node.node_ip AS node_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";
|
||||
|
||||
// run query
|
||||
$nodes = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$counter = count($nodes);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("counter", $counter);
|
||||
|
||||
// any nodes?
|
||||
if ($counter>0) {
|
||||
// get objects
|
||||
foreach($nodes AS $node) {
|
||||
// send to tpl
|
||||
$tp->set("item_name", $lang['lang_nodes']);
|
||||
$tp->set("item", "node");
|
||||
$tp->set("id", $node['node_id']);
|
||||
$tp->set("name", $node['node_ip']);
|
||||
|
||||
// parse block
|
||||
$tp->parse("row");
|
||||
|
||||
// update counter
|
||||
$resultcounter++;
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("node");
|
||||
} else {
|
||||
// parse block
|
||||
$tp->hide("node");
|
||||
}
|
||||
|
||||
// clear row
|
||||
$tp->clear("row");
|
||||
|
||||
// setup subnet
|
||||
// build query
|
||||
$query = "SELECT
|
||||
subnet.subnet_id AS subnet_id,
|
||||
subnet.subnet_address AS subnet_address
|
||||
FROM
|
||||
subnet
|
||||
WHERE
|
||||
subnet.subnet_address LIKE '" . $needle . "'
|
||||
OR subnet.subnet_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
subnet.subnet_address";
|
||||
|
||||
// run query
|
||||
$subnets = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$counter = count($subnets);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("counter", $counter);
|
||||
|
||||
// any subnets?
|
||||
if ($counter>0) {
|
||||
// get objects
|
||||
foreach($subnets AS $subnet) {
|
||||
// send to tpl
|
||||
$tp->set("item_name", $lang['lang_subnets']);
|
||||
$tp->set("item", "subnet");
|
||||
$tp->set("id", $subnet['subnet_id']);
|
||||
$tp->set("name", $subnet['subnet_address']);
|
||||
|
||||
// parse block
|
||||
$tp->parse("row");
|
||||
|
||||
// update counter
|
||||
$resultcounter++;
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("subnet");
|
||||
} else {
|
||||
// parse block
|
||||
$tp->hide("subnet");
|
||||
}
|
||||
|
||||
// clear row
|
||||
$tp->clear("row");
|
||||
|
||||
// setup vlan
|
||||
// build query
|
||||
$query = "SELECT
|
||||
vlan.vlan_id AS vlan_id,
|
||||
vlan.vlan_name AS vlan_name
|
||||
FROM
|
||||
vlan
|
||||
WHERE
|
||||
vlan.vlan_name LIKE '" . $needle . "'
|
||||
OR vlan.vlan_info LIKE '" . $needle . "'
|
||||
ORDER BY
|
||||
vlan.vlan_name";
|
||||
|
||||
// run query
|
||||
$vlans = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$counter = count($vlans);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("counter", $counter);
|
||||
|
||||
// any vlans?
|
||||
if ($counter>0) {
|
||||
// get objects
|
||||
foreach($vlans AS $vlan) {
|
||||
// send to tpl
|
||||
$tp->set("item_name", $lang['lang_vlans']);
|
||||
$tp->set("item", "vlan");
|
||||
$tp->set("id", $vlan['vlan_id']);
|
||||
$tp->set("name", $vlan['vlan_name']);
|
||||
|
||||
// parse block
|
||||
$tp->parse("row");
|
||||
|
||||
// update counter
|
||||
$resultcounter++;
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("vlan");
|
||||
} else {
|
||||
// parse block
|
||||
$tp->hide("vlan");
|
||||
}
|
||||
|
||||
// clear row
|
||||
$tp->clear("row");
|
||||
|
||||
// to tpl
|
||||
$tp->set("resultcounter", $resultcounter);
|
||||
|
||||
// parse block
|
||||
$tp->parse("resultcount");
|
||||
}
|
||||
|
||||
// output
|
||||
$tp->parse();
|
||||
$tp->spit();
|
||||
// end page
|
||||
// output
|
||||
$tp->parse();
|
||||
$tp->spit();
|
||||
|
||||
include("footer.php");
|
||||
// end output
|
||||
include("footer.php");
|
||||
?>
|
||||
Reference in New Issue
Block a user