Location: PHPKode > projects > Network Managment / Inventory System > clearsite/include/aloe/aloe_search.php
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2006-2008 Xinn.org                                        |
 |                                                                         |
 | 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 2          |
 | 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.                            |
 +-------------------------------------------------------------------------+
 | ClearSite/ALOE, A Long Overdue Enterprise network managment solution!   |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Xinn.org. See     |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://aloeusers.net                                                    |
 | http://clearsite.sourceforge.net                                        |
 | http://aloenms.net                                                      |
 | http://clear-site.net                                                   |
 | http://clear-site.info                                                  |
 | http://xinn.org/ClearSite.html                                          |
 +-------------------------------------------------------------------------+
*/

include_once("../config.php");
include_once("$cs_base_path/include/aloe/aloe_config.php");

extract($_GET);
extract($_POST);

$weekagotimestamp = date('Y-m-d G:i:s', strtotime("-8 days"));
$searchtext = trim($searchtext);

if ($field == "mac" or $field == "host_name" or $field == "host_ip") {
  if ($field == "mac") {
    $searchtext = str_replace(array("-", ":", "."), "", $searchtext);
    $st_array   = str_split($searchtext, 2);
    $searchtext = "";
    for ($x=0; $x<count($st_array); $x++) {
      if ($x != 0) {
        $searchtext .= ":";
      };
      $searchtext .= $st_array[$x];
    };
  };
  $devicetable = "interfaces";
  $selects  = "t1.interface_ID, t1.ifname, t1.mac, t1.host_ip, t1.host_name, t2.device_name";
  $where = " and t1.iscdpneighbor != \"Y\"";
  $oby = "host_name";
} else if ($field == "owner_name") {
  $devicetable = "css_owner";
  $selects = "t1.owner_ID, t1.owner_name, t2.device_name";
  $where = "";
  $oby = "owner_name";
} else if ($field == "cr_name") {
  $devicetable = "css_cr";
  $selects = "t1.cr_ID, t1.cr_name, t1.cr_vip, t2.device_name";
  $where = "";
  $oby = "cr_name";
} else if ($field == "sv_name") {
  $devicetable = "css_sv";
  $selects = "t1.sv_ID, t1.sv_name, t1.sv_ip, t2.device_name";
  $where = "";
  $oby = "sv_name";
};

mysql_connect("$DBhost:$DBport",$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
$sqlquery = "SELECT $selects FROM $devicetable AS t1, devices AS t2 WHERE t1.$field LIKE \"%$searchtext%\" and t1.device_ID = t2.device_ID$where ORDER BY $oby LIMIT 50";
$result = mysql_query($sqlquery);

print "

<b>Search Results:</b><br /> 
<div id=\"sResults\">";
$rowclass = "alt_even_cells";
while($row = mysql_fetch_assoc($result)) {
  if ($rowclass == "alt_even_cells"){
    $rowclass = "alt_odd_cells";
  } else {
    $rowclass = "alt_even_cells";
  };
  if ($devicetable == "interfaces") {
    $ifname_display = str_replace("-", "/", $row["ifname"]);
    $href = "$ClearsiteBaseURL/include/aloe/aloe_details.php?interface_type=$devicetable&interface_ID=$row[interface_ID]";
    print "
           <div class=\"$rowclass\">
            <div class=\"alt_table_row\">
             <div class=\"left_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[device_name]:$ifname_display</a></p>
             </div>
             <div class=\"left_center_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[host_name]</a></p>
             </div>
             <div class=\"right_center_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[host_ip]</a></p>
             </div>
             <div class=\"right_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[mac]</a></p>
             </div>
             <div class=\"tbl_spacer\"></div>
            </div>
           </div>
    ";
  } else if ($devicetable == "css_owner") {
    $href = "$ClearsiteBaseURL/include/aloe/aloe_details.php?interface_type=$devicetable&owner_ID=$row[owner_ID]";
    print "
           <div class=\"$rowclass\">
            <div class=\"alt_table_row\">
             <div class=\"left_cell\">
              <p>$row[device_name]</p>
             </div>
             <div class=\"right_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[owner_name]</a></p>
             </div>
             <div class=\"tbl_spacer\"></div>
            </div>
           </div>
    ";
  } else if ($devicetable == "css_cr") {
    $href = "$ClearsiteBaseURL/include/aloe/aloe_details.php?interface_type=$devicetable&cr_ID=$row[cr_ID]";
    print "
           <div class=\"$rowclass\">
            <div class=\"alt_table_row\">
             <div class=\"left_cell\">
              <p>$row[device_name]</p>
             </div>
             <div class=\"left_center_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[cr_name]</a></p>
             </div>
             <div class=\"right_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[cr_vip]</a></p>
             </div>
             <div class=\"tbl_spacer\"></div>
            </div>
           </div>
    ";
  } else if ($devicetable == "css_sv") {
    $href = "$ClearsiteBaseURL/include/aloe/aloe_details.php?interface_type=$devicetable&sv_ID=$row[sv_ID]";
    print "
           <div class=\"$rowclass\">
            <div class=\"alt_table_row\">
             <div class=\"left_cell\">
              <p>$row[device_name]</p>
             </div>
             <div class=\"left_center_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[sv_name]</a></p>
             </div>
             <div class=\"right_cell\">
              <p><a class=\"loadinto-targetArea\" href=\"$href\">$row[sv_ip]</a></p>
             </div>
             <div class=\"tbl_spacer\"></div>
            </div>
           </div>
    ";
  };
};
print "
</div>
       <p>
";
mysql_close();
?>
Return current item: Network Managment / Inventory System