Location: PHPKode > projects > Network Asset Management Archive > nama/getcounts.php
<?php
$now = date("m/j/y h:i:s",time());
include "connect.php";

$now = date("j/m/y h:i:s",time());
echo '<body bgcolor="#FFFFCC">';

$sortorder = $_POST['sortorder'];
$LABlist = $_POST['LABlist'];
$SUBNET = $_POST['SUBNET'];
$OSlist = $_POST['OSlist'];
$stmt = "select  c.lab, a.OS, count(*) as total from arp_table a, subnets b, lab c ";
$stmt = $stmt . " where (a.subnet = b.subnet) and (b.lab = c.serial) and (a.ip_address<>'0.0.0.0') ";
if (sizeof($LABlist) != 0) {
        $hadlab = true;
        if (sizeof($LABlist) == 1) {
        $stmt = $stmt . " and ((b.LAB = '$LABlist[0]')";
        }
        else {
                $stmt = $stmt . " and ((b.LAB in (";
                for ($i=0; $i < sizeof($LABlist); $i++) {
                    $stmt = $stmt . $LABlist[$i];
                    if ($i < sizeof($LABlist)-1) {
                        $stmt = $stmt . ",";
                    }
                    else {
                        $stmt = $stmt . "))";
                    }
                }
        }
}
if (sizeof($SUBNET) != 0) {
        $hadlab = true;
        if (sizeof($SUBNET) == 1) {
                if (sizeof($LABlist) == 0) {
                     $stmt = $stmt . " and (a.SUBNET = '$SUBNET[0]')";
                }
                else {
                     $stmt = $stmt . " or (a.SUBNET = '$SUBNET[0]')";
                }
        }
        else {
                if (sizeof($LABlist) == 0) {
                        $stmt = $stmt . " and (a.SUBNET in ('";
                }
                else {
                        $stmt = $stmt . " or (a.SUBNET in ('";
                }
                for ($i=0; $i < sizeof($SUBNET); $i++) {
                    $stmt = $stmt . $SUBNET[$i];
                    if ($i < sizeof($SUBNET)-1) {
                        $stmt = $stmt . "','";
                    }
                    else {
                        $stmt = $stmt . "'))";
                    }
                }
        }
}
if (sizeof($LABlist) != 0) {
	$stmt = $stmt . ")";
}
if (sizeof($OSlist) != 0) {
        $hadlab = true;
        if (sizeof($OSlist) == 1) {
        $stmt = $stmt . " and (OS = '$OSlist[0]')";
        }
        else {
                $stmt = $stmt . " and (OS in ('";
                for ($i=0; $i < sizeof($OSlist); $i++) {
                    $stmt = $stmt . $OSlist[$i];
                    if ($i < sizeof($OSlist)-1) {
                        $stmt = $stmt . "','";
                    }
                    else {
                        $stmt = $stmt . "'))";
                    }
                }
        }
}
if ($Submit=='No Green') {
$stmt = $stmt .  'and ((owner is null) or (building is null) or (room is null) or (barcode is null) or (owner is null) or (os is null))';
}
if ($sortorder == 'LAB') {
	$stmt = $stmt . "group by c.lab, a.os";
}
else {
	$stmt = $stmt . "group by a.os, c.lab";
}
//echo $stmt . '<br>';
echo '<table width="500" border="3">';
$sth = ibase_query($dbh, $stmt);
$i = 0;
$oldos = "";
$oldlab = "";
$subtotal=0;
while ($row = ibase_fetch_object($sth)) {
        $thislab = $row->LAB;
        $thisos = explode(" - ", $row->OS);
        if ($oldos!="") {
            if ($thisos[0]!=$oldos) { echo '<tr><td></td><td><b>Total ' . $oldos . ': ' . $totalos . '</b></td></tr>'; $totalos = 0; }
        }
        if ($sortorder == 'LAB') {
           if ($oldlab != "") {
               if ($thislab!=$oldlab) { echo '<tr><td>&nbsp</td><td><b>Total ' . $oldlab . ':</td><td><b> ' . $subtotal . '</b></td></tr>'; $subtotal = 0; }

           }
        }
	$i = $i + $row->TOTAL;
        $totalos = $totalos + $row->TOTAL;
        $subtotal = $subtotal + $row->TOTAL;
	echo '<TR border = "1"><TD>';
	echo $row->LAB . '</TD><TD>';
	echo $row->OS  . '</TD><TD>'; 
	echo $row->TOTAL . '</TD></TR>';
        $oldos = $thisos[0];
        $oldlab = $thislab;
}
       if ($sortorder == 'LAB') {
                echo '<tr><td>&nbsp</td><td><b>Total ' . $oldlab . ':</td><td><b>' . $subtotal . '</b></td></tr>'; $subtotal = 0; 

        }


echo "<TR><td>&nbsp</td><td><B>Total</td><TD><B>" . $i . "</TD></TR>";
echo "</table>";
?>

Return current item: Network Asset Management Archive