prepare($query); if($sth) { # 1 is server, 2 networking device $res = $sth->execute(); $numRows = $sth->rows(); if ($numRows < 1) { PRINT "Looks like a lonely device to me. No ports found.
"; return; } PRINT ""; PRINT ""; for($i = 0; $i < $numRows; $i++) { $result = $sth->fetchrow_hash(); $ID = $result["ID"]; $name = $result["name"]; $logical_number = $result["logical_number"]; $iface = $result["iface"]; $ifaddr = $result["ifaddr"]; $ifmac = $result["ifmac"]; $wquery = "SELECT * FROM networking_wire WHERE (end1 = $ID OR end2 = $ID)"; $wsth = $adb->prepare($wquery); if($wsth) { $wres = $wsth->execute(); $wnumRows = $wsth->rows(); if ($wnumRows > 0) { $wresult = $wsth->fetchrow_hash(); $wID = $wresult["ID"]; $wend1 = $wresult["end1"]; $wend2 = $wresult["end2"]; if ($wend1 == $ID) { $pquery = "SELECT * FROM networking_ports WHERE (ID = $wend2)"; } else { $pquery = "SELECT * FROM networking_ports WHERE (ID = $wend1)"; } $psth = $adb->prepare($pquery); if($psth) { $pres = $psth->execute(); $presult = $psth->fetchrow_hash(); $pID = $presult["ID"]; $pNum = $presult["logical_number"]; $pOn = $presult["device_on"]; $pType = $presult["device_type"]; } else { PRINT "Could not prepare query: ".$psth->errstr."
\n"; } if ($pType == 1) { $nquery = "SELECT ID,name FROM computers WHERE (ID = $pOn)"; } else if ($pType == 2) { $nquery = "SELECT ID,name FROM networking WHERE (ID = $pOn)"; } $nsth = $adb->prepare($nquery); if($nsth) { $nres = $nsth->execute(); $nresult = $nsth->fetchrow_hash(); $nname = $nresult["name"]; $nID = $nresult["ID"]; $found = 1; } else { PRINT "Could not prepare query: ".$nsth->errstr."
\n"; } } else { $found = 0; $pType = 0; } } else { PRINT "Could not prepare query: ".$wsth->errstr."
\n"; } PRINT ""; PRINT ""; } PRINT "
Port #NameInterfaceIface AddrIf MACConnected to...
$logical_number$name$iface$ifaddr$ifmac"; if ($pType == 1) { //jim PRINT "Port $pNum on computer $nname ($nID)."; PRINT "Port $pNum on computer $nname."; } else if ($pType == 2) { PRINT "Port $pNum on network device $nname."; } else if ($found != 1) { PRINT "Port available. Connect"; } $found = 0; $pType=0; PRINT "

"; } else { PRINT "Could not prepare query: ".$sth->errstr."
\n"; } commonFooter(); ?>