<?php
$navloc = '';
$title = 'Search Results';
include ('includes/func_vars_inc.php');
include ('includes/auth_check.php');
include ('templates/template_top.inc.php');
if (isset($_GET['msg'])){
echo "<p style=\"color:red;\" >".$_GET['msg']."</p>";
}
//print_R($_POST);
//exit;
//define the array for our search
$where = array();
//create our where
if ($_POST['wildcard'] == "mac" AND strlen($_POST['input']) != 0){
$where[] = "`mac` LIKE '%".$_POST['input']."%'";
//$searchdisp = "'".$_POST['input']."' in mac addresses";
} elseif ($_POST['wildcard'] == "name" AND strlen($_POST['input']) != 0){
$where[] = "`machinename` LIKE '%".$_POST['input']."%'";
//$searchdisp = "'".$_POST['input']."' in machine names";
} elseif ($_POST['wildcard'] == "room" AND strlen($_POST['input']) != 0){
$where[] = "`room` LIKE '%".$_POST['input']."%'";
//$searchdisp = "'".$_POST['input']."' room names";
}
if ($_POST['search_network'] == 'DHCP') {
$where[] = "`net_mode` = 'dhcp'";
} elseif ($_POST['search_network'] != 0 AND $_POST['search_network'] != 'DHCP'){
$where[] = "`net_mode` = 'manual' AND `netID` = '".$_POST['search_network']."'";
}
if ($_POST['search_initial_build'] != 0){
$where[] = "`initial_buildID` = '".$_POST['search_initial_build']."'";
}
if ($_POST['search_after_build'] != 0){
$where[] = "`after_buildID` = '".$_POST['search_after_build']."'";
}
$whereCount = count($where);
if ($whereCount > 0){
$whereQuery .= " WHERE ";
for ($i = 0; $i < $whereCount; $i++){
$whereQuery .= " ".$where[$i];
if ($i != $whereCount-1 AND $whereCount != 0){
$whereQuery .= " AND ";
}
}
}
//set the ordering. we want IPs order by IP
if ($_POST['search_network'] != 0 AND $_POST['search_network'] != 'DHCP'){
$whereQuery .= " ORDER BY `ip`";
} else {
$whereQuery .= " ORDER BY `machinename`";
}
$query = "SELECT * FROM `machines`".$whereQuery;
//echo $query;
$result = dbase_query($query);
$numres = mysql_num_rows($result);
if ($numres > 0){
echo "<p>Your search for ".$searchdisp." returned <b>".$numres."</b> result(s).";
?>
<table cellspacing="0" cellpadding="2" border="0">
<tr class="headrow">
<td>Name</td>
<td>IP</td>
<td>MAC</td>
<td>Room</td>
<td>Location</td>
<td>Run Once</td>
<td>Initial Build</td>
<td>After Build</td>
<td>Printers</td>
<td>Log</td>
<td> </td>
<td> </td>
</tr>
<?php
for ($i = 0; $i < $numres; $i++){
$row = mysql_fetch_array($result);
if ($row['net_mode'] == "manual"){
$query = "SELECT * FROM `network` where `netID` = '".$row['netID']."' LIMIT 1;";
$result2 = dbase_query($query);
$row2 = mysql_fetch_array($result2);
$myip = $row2['ip_range'].".".$row['ip'];
} else {
$myip = "dhcp";
}
$mymod = $i % 2;
?>
<tr class="row<?php echo $mymod; ?>">
<td><?php echo $row['machinename']; ?></td>
<td><?php echo $myip; ?></td>
<td><?php echo $row['mac']; ?></td>
<td><?php echo $row['room']; ?></td>
<td><?php echo $row['location']; ?></td>
<td><?php echo $row['run_suc']; ?></td>
<td><?php echo buildname($row['initial_buildID']); ?></td>
<td><?php echo buildname($row['after_buildID']); ?></td>
<td><a href="#" onclick="window.open('pop_printers.php?machineID=<?php echo $row['machineID']; ?>','downwindow','width=350,height=500,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrolling=1,scrollbars=1');">Show printers</a></td>
<td><a href="#" onclick="window.open('pop_log.php?machineID=<?php echo $row['machineID']; ?>','downwindow','width=350,height=500,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrolling=1,scrollbars=1');">View Log</a></td>
<td><form action="mod_machine.php" method="post">
<input type="hidden" name="machineID" value="<?php echo $row['machineID']; ?>">
<input type="submit" value="Modify"></form>
</td>
<td><form action="del_machine.php" method="post">
<input type="hidden" name="machineID" value="<?php echo $row['machineID']; ?>">
<input type="submit" value="Delete"></form>
</td>
</tr>
<?php
}
} else {
?>
<p><b>Your search returned 0 results.</b></p>
<?php
include ('includes/search_form.inc.php');
}
?>
</table>
<?php
include ('templates/template_bottom.inc.php');
?>