<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<link rel="stylesheet" href="css/opencabling.css" type="text/css"></link>
<?php
require_once 'js/functions.js';
require_once 'phplayersmenu.inc.php';
require_once 'primitives/getobject.php';
#$DEBUG=1;
$mid->printHeader();
?>
</head>
<body>
<?php
$mid->printMenu('hormenu1');
$object=$_REQUEST['object'];
echo "<script lang=javascript>";
echo "var selobject = top.left.document.getElementById('selobject');";
echo "selobject.value=".$object.";";
echo "</script>";
include "opendb.php";
if (($result=getobject($object))!=FALSE) {
$html=$result['html'];
$html_back=$result['html_back'];
$options=$result['options'];
$nospan=stristr($options,"nospan");
$vlan=stristr($options,"vlan");
$out_avail=$result['out_available'];
$out_names=$result['out_names'];
if ($out_names=="") {
for ($i=1;$i<$out_avail;$i++)
$out_names=$out_names."$i;";
$out_names=$out_names."$out_avail";
}
// Explode outnames
$out_name=explode(";",$out_names);
// Explode extravalues;
$extra=explode(";",$result['obj_extravalues']);
array_unshift($extra,"");
$i=1;
while (strpos($html,"@@EXTRA".$i."@@")>0) {
if ($extra[$i]=="") {
$extra[$i]="_";
}
$link="<a href='javascript:popUp(\"edit_extra.php?object=".$object."&extra=".$i."\",\"EditExtra\",400,300)'>".$extra[$i]."</a>";
$html=str_replace("@@EXTRA".$i."@@",$link,$html);
$i++;
}
$i=1;
while (strpos($html_back,"@@EXTRA".$i."@@")>0) {
if ($extra[$i]=="") {
$extra[$i]="_";
}
$link="<a href='javascript:popUp(\"edit_extra.php?object=".$object."&extra=".$i."\",\"EditExtra\",400,300)'>".$extra[$i]."</a>";
$html_back=str_replace("@@EXTRA".$i."@@",$link,$html_back);
$i++;
}
// Set default item content
for ($i=1; $i<=($result['hpos_available']*$result['vpos_available']); $i++) {
$item[$i]="<td align='center' valign='middle'><a href=\"new_object.php?parent_object=$object&position=$i&towards=F\">".$result['void_item']."</a></td>";
$item_back[$i]="<td align='center' valign='middle'><a href=\"new_object.php?parent_object=$object&position=$i&towards=B\">".$result['void_item_back']."</a></td>";
$free_item[$i]=TRUE;
$free_item_back[$i]=TRUE;
}
// Setup front items
$subsql="select * from objects,objtypes where objtypes.id_obj_type=objects.obj_type
and parent_obj=".$object;
$subquery=mysql_query($subsql,$mysql_conn);
while ($subresult=mysql_fetch_assoc($subquery)) {
if ($nospan==false) {
$cspan=$subresult['hpos_used'];
$rspan=$subresult['vpos_used'];
}
else {
$cspan=1;
$rspan=1;
}
if ($subresult['towards']=='B') {
for ($j=$subresult['position'];$j>$subresult['position']-($cspan*$rspan);$j--) {
$item_back[$j]="";
$free_item_back[$j]=FALSE;
}
$item_back[$subresult['position']]="<td rowspan=".$rspan." colspan=".$cspan." align='center' valign='middle' title='".$subresult['name']."'><a href='javascript:select_obj(".$subresult['id_object'].")'>".str_replace("@@HEIGHT@@","",$subresult['html_small'])."</a></td>";
} else {
for ($j=$subresult['position'];$j>$subresult['position']-($cspan*$rspan);$j--) {
$item[$j]="";
$free_item[$j]=FALSE;
}
$item[$subresult['position']]="<td rowspan=".$rspan." colspan=".$cspan." align='center' valign='middle' title='".$subresult['name']."'><a href='javascript:select_obj(".$subresult['id_object'].")'>".str_replace("@@HEIGHT@@","",$subresult['html_small'])."</a></td>";
}
}
// Setup back items
$subsql="select * from objects,objtypes where objtypes.id_obj_type=objects.obj_type
and parent_obj=".$object;
$subquery=mysql_query($subsql,$mysql_conn);
while ($subresult=mysql_fetch_assoc($subquery)) {
if ($nospan==false) {
$cspan=$subresult['hpos_used'];
$rspan=$subresult['vpos_used'];
}
else {
$cspan=1;
$rspan=1;
}
if ($subresult['towards']=='B') {
$allfree=TRUE;
for ($j=$subresult['position'];$j>$subresult['position']-($cspan*$rspan);$j--) {
$allfree=$allfree && $free_item[$j];
}
if ($allfree) {
for ($j=$subresult['position'];$j>$subresult['position']-($cspan*$rspan);$j--) {
$item[$j]="";
}
$item[$subresult['position']]="<td rowspan=".$rspan." colspan=".$cspan." align='center' valign='middle' title='".$subresult['name']."'><a href='javascript:select_obj(".$subresult['id_object'].")'>".str_replace("@@HEIGHT@@","",$subresult['html_back_small'])."</a></td>";
}
} else {
$allfree=TRUE;
for ($j=$subresult['position'];$j>$subresult['position']-($cspan*$rspan);$j--) {
$allfree=$allfree && $free_item_back[$j];
}
if ($allfree) {
for ($j=$subresult['position'];$j>$subresult['position']-($cspan*$rspan);$j--) {
$item_back[$j]="";
}
$item_back[$subresult['position']]="<td rowspan=".$rspan." colspan=".$cspan." align='center' valign='middle' title='".$subresult['name']."'><a href='javascript:select_obj(".$subresult['id_object'].")'>".str_replace("@@HEIGHT@@","",$subresult['html_back_small'])."</a></td>";
}
}
}
for ($i=1; $i<=($result['hpos_available']*$result['vpos_available']); $i++) {
$html=str_replace("@@ITEM".$i."@@",$item[$i],$html);
$html=str_replace("@@ITEMBACK".$i."@@",$item_back[$i],$html);
$html_back=str_replace("@@ITEM".$i."@@",$item[$i],$html_back);
$html_back=str_replace("@@ITEMBACK".$i."@@",$item_back[$i],$html_back);
}
for ($i=1; $i<=$result['out_available']; $i++)
$connection[$i]="N";
$connsql="select start_item,start_outspan from connections,conntypes where start_obj=$object and connections.connection_type=conntypes.id_conn_type";
$connquery=mysql_query($connsql,$mysql_conn);
while ($connresult=mysql_fetch_assoc($connquery)) {
$start_item=$connresult['start_item'];
$index=array_search($start_item,$out_name);
for ($i=0; $i<$connresult['start_outspan']; $i++) {
$connection[$out_name[$index+$i]]="Y";
}
}
$connsql="select end_item,end_outspan from connections,conntypes where end_obj=$object and connections.connection_type=conntypes.id_conn_type";
$connquery=mysql_query($connsql,$mysql_conn);
while ($connresult=mysql_fetch_assoc($connquery)) {
$end_item=$connresult['end_item'];
$index=array_search($end_item,$out_name);
for ($i=0; $i<$connresult['end_outspan']; $i++)
$connection[$out_name[$index+$i]]="Y";
}
while (ereg("@@IFCONN@@([A-Za-z0-9\.\;\'\"]*)@@",$html,$command)) {
list($numitem,$wimg,$woimg)=explode(";",$command[1]);
if ($connection[$numitem]=="Y")
$html=str_replace($command[0],$wimg,$html);
else
$html=str_replace($command[0],$woimg,$html);
}
while (ereg("@@IFCONN@@([A-Za-z0-9\.\;\'\"]*)@@",$html_back,$command)) {
list($numitem,$wimg,$woimg)=explode(";",$command[1]);
if ($connection[$numitem]=="Y")
$html_back=str_replace($command[0],$wimg,$html_back);
else
$html_back=str_replace($command[0],$woimg,$html_back);
}
$html_detail=$result['html_detail'];
$html_detail=str_replace("@@HTML@@",$html,$html_detail);
$html_detail=str_replace("@@HTMLBACK@@",$html_back,$html_detail);
$html_detail=str_replace("@@DESCRIPTION@@","<table width=100% frame=box><tr><td>".$result['obj_description']."</td></tr><tr><td align=right class=verysmalltext><a href='javascript:popUp(\"edit_field_object.php?object=".$object."&field=obj_description\",\"EditObject\",400,300)'>Edit</a></td></tr></table>",$html_detail);
$htmllink="";
// Explode links if any
$links=explode(" ",$result['obj_links']);
foreach ($links as $linkvalue) {
if (trim($linkvalue)!="") {
if (strpos($linkvalue,"NAGIOS=")!==FALSE && strpos($linkvalue,"NAGIOS=")==0) {
$htmllink=$htmllink."<a target=_blank href='".substr($linkvalue,7)."'><img vspace=2 src='images/link/miniNagios.png'></img></a><br>";
} else if (strpos($linkvalue,"MRTG=")!==FALSE && strpos($linkvalue,"MRTG=")==0) {
$htmllink=$htmllink."<a href='".substr($linkvalue,5)."'><img vspace=2 src='images/link/miniMRTG.png'></img></a><br>";
} else
$htmllink=$htmllink."<a href='".$linkvalue."'><img vspace=2 src='images/link/miniLink.png'></img></a><br>";
}
}
$html_detail=str_replace("@@LINK@@",$htmllink,$html_detail);
print "<div class=smalltext align=right>[ID #".$result['id_object']."]</div>";
print "<table width=100%><tr><td><table width=100% frame=box><tr><td class='detailname'>".$result['name']."</td></tr>";
print "<tr><td align=right class=verysmalltext><a href='javascript:popUp(\"edit_field_object.php?object=".$object."&field=name\",\"EditObject\",400,300)'>Edit</a></td></tr></table></td></tr></table>";
print "$html_detail";
if ($vlan==true) {
echo "<!--";
print_r($out_names);
echo "-->";
print "<table width=100%><tr><td>";
print "<table width=100% frame=box><tr>";
print "<td class=smalltext><b>VlanID</b></td><td class=smalltext><b>LocalID</b></td><td class=smalltext><b>Name</b></td>";
for ($i=0;$i<$out_avail;$i++) {
if (strstr($out_name[$i],"bis")==FALSE) {
print "<td align=center class=smalltext>$out_name[$i]</td>";
}
}
$sql="select distinct vlannames.localid,vlannames.vlanid,vlannames.name,vlannames.vlanname_id from vlannames where vlannames.obj_id=$object order by vlannames.localid,vlannames.vlanid";
$query=mysql_query($sql,$mysql_conn);
while ($result=mysql_fetch_assoc($query)) {
if ($bgcolor=='#aaaaaa')
$bgcolor='#cccccc';
else
$bgcolor='#aaaaaa';
for ($i=1;$i<=$out_avail;$i++) {
if (strstr($out_name[$i],"bis")==FALSE) {
$localid=$result['localid'];
$vlanid=$result['vlanid'];
$vlanname=$result['name'];
$vlanname_id=$result['vlanname_id'];
$vlanitem[$i]="<td><a href='javascript:popUp(\"confirm_toggle_vlan_port.php?object=".$object."&port=".$i."&vlanname_id=".$vlanname_id."&action=add\",\"ToggleVLAN\",400,300)'> </a></td>";
}
}
$subsql="select nport from vlanports where obj_id=$object and vlanname_id=$vlanname_id";
$subquery=mysql_query($subsql,$mysql_conn);
while ($subresult=mysql_fetch_assoc($subquery)) {
$vlanitem[$subresult['nport']]="<td align=center class=smalltext><a href='javascript:popUp(\"confirm_toggle_vlan_port.php?object=".$object."&port=".$subresult['nport']."&vlanname_id=".$vlanname_id."&action=remove\",\"ToggleVLAN\",400,300)'>x</a></td>";
}
print "<tr bgcolor='$bgcolor'><td class=smalltext><a href='javascript:popUp(\"edit_vlan.php?object=".$object."&vlanname_id=".$vlanname_id."\",\"EditVLAN\",400,300)'>$vlanid</a></td><td class=smalltext><a href='javascript:popUp(\"edit_vlan.php?object=".$object."&vlanname_id=".$vlanname_id."\",\"EditVLAN\",400,300)'>$localid</a></td><td class=smalltext><a href='javascript:popUp(\"edit_vlan.php?object=".$object."&vlanname_id=".$vlanname_id."\",\"EditVLAN\",400,300)'>$vlanname</a></td>";
for ($i=1;$i<=$out_avail;$i++) {
if (strstr($out_name[$i],"bis")==FALSE) {
print $vlanitem[$i];
}
}
print "<td class=smalltext><a href='javascript:popUp(\"confirm_delete_vlan.php?object=".$object."&vlanname_id=".$vlanname_id."\",\"DeleteVLAN\",400,300)'>Delete</a></td></tr>";
}
print "<tr><td class=verysmalltext><a href='javascript:popUp(\"edit_vlan.php?object=".$object."\",\"EditVLAN\",400,300)'>Add</a></td></tr>";
print "</table>";
print "</td></tr></table>";
}
}
mysql_close($mysql_conn);
?>
<?php
$mid->printFooter();
?>
</body>
</html>