You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
4.6 KiB
130 lines
4.6 KiB
<?php
|
|
/*****************************************************************************
|
|
IP Reg, a PHP/MySQL IPAM tool
|
|
Copyright (C) 2008 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
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
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.
|
|
|
|
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
|
|
*****************************************************************************/
|
|
|
|
// includes
|
|
include("includes.php");
|
|
|
|
// 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
|
|
if (empty($search)) {
|
|
$tp->parse("nosearch");
|
|
$tp->hide("asset");
|
|
$tp->hide("location");
|
|
$tp->hide("node");
|
|
$tp->hide("subnet");
|
|
$tp->hide("vlan");
|
|
$tp->hide("resultcount");
|
|
} else {
|
|
$tp->hide("nosearch");
|
|
|
|
// set needle and counter
|
|
$needle = '%' . $search . '%';
|
|
$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");
|
|
|
|
// 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");
|
|
|
|
// 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");
|
|
|
|
// 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");
|
|
|
|
// 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");
|
|
|
|
$tp->set("resultcounter", $resultcounter);
|
|
$tp->parse("resultcount");
|
|
}
|
|
|
|
// output
|
|
$tp->parse();
|
|
$tp->spit();
|
|
|
|
include("footer.php");
|
|
?>
|