<?php

function BUILDING_SHOW_INVENTORY($ARG1,$ARG1_VAL) {
global $SQL_USER,$SQL_DATABASE,$INTERFACE_ADDR,$SQL_USER_PASS,$MENU_INIT,$CURRENT_MENU;
if(($ARG1==T_TELBOX_NAME) && ($ARG1_VAL)) {
 $zapSQL="select * from TELBOXES where T_TELBOX_NAME='$ARG1_VAL' and A_ADM_COMPANY like '".$_SESSION[ADM_COMPANY]."%' limit 0,1;"  ;
 } else if($ARG1_VAL) {
 }
if($error) {
 echo "Error $error ";
 } else {
$conn=mysql_pconnect($INTERFACE_ADDR,$SQL_USER,$SQL_USER_PASS);
mysql_select_db($SQL_DATABASE) or die("ERROR podczas wyboru bazy R50!");
$result = mysql_query($zapSQL,$conn) or die("Blad zapytania2!\n$zapSQL");
$num_rows = mysql_num_rows($result); 

    while ($h=mysql_fetch_row($result)) {
   $A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM]],bgcolor);   
   $A_STATUS_COLOR=USERS_COLUMN_COLOR_RETURN(A_STATUS,$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_STATUS]],bgcolor);   

  echo "<tr><td>";
   echo "<table  border=0 cellspacing=0 cellpadding=0 width=100%><tr><td>";
    echo "<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td height=25 $A_STATUS_COLOR><font size=+1><b>".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]]."</b></td></tr></table>";
   echo "</td></tr></table>";
    echo "</td><td>";
     echo "<table cellspacing=0 cellpadding=0 border=0 width=100%><tr><td $A_PROBLEM_COLOR height=25><font size=+1>
      (".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM]].") Typ:<b>".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_TYPE]]."</b>[.............................................] Zabezpiecznie:<b>".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_SAVE]]."</b>[.........................] <nobr>Zasilanie:<b>".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_POWER]]."</b>[...............................]</nobr>[OK]</td></tr></table>";
    echo "</td></tr>";
 echo "<tr><td>Abonenci</td><td>";
 $zap_SQLABO="select S_ADDRESS_STREET,A_STATUS,A_PROBLEM,A_PROBLEM_DESC from USERS2 where T_TELBOX_ADDRESS='$ARG1_VAL'";
 $result_abo = mysql_query($zap_SQLABO,$conn) or die("Blad zapytania3!\n $zap_SQLABO");
 $TEMPTOT=0;  $TEMPOK=0;
  while ($i=mysql_fetch_row($result_abo)) {
   $ABO_A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$i[2],color);   
   echo "(<font size=-1><b>$i[0]</b></font><font $ABO_A_PROBLEM_COLOR size=-1> $i[1] $i[2] </font>), "; 
   $TEMPTOT++;
   if(($i[1]==NORMAL) || ($i[1]==WARNING) ||  ($i[1]==OFF_SOFT) ) $TEMPOK++;
  }
    echo "($TEMPTOT uzytkownikow ($TEMPOK aktywnych)) [OK]";
    echo "</td></tr>";

  echo "<tr><td colspan=1>Urzadzenia</td><td>";
 $zap_SQLDEV="select * from DEVICES where T_TELBOX_NEIGHBOUR_IN='$ARG1_VAL'";
 $result_dev = mysql_query($zap_SQLDEV,$conn) or die("Blad zapytania3!\n $zap_SQLDEV");
  while ($j=mysql_fetch_row($result_dev)) {
   $DEV_A_STATUS_COLOR=USERS_COLUMN_COLOR_RETURN(A_STATUS,$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][A_STATUS]],color);   
   $DEV_A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][A_PROBLEM]],color);   
   echo "<font $DEV_A_STATUS_COLOR size=+1>X</font>".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_TYPE]]."(spr. <b>".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_PORTS_OK]]."</b> [......])</font> $DEV_A_PROBLEM_COLOR<font size=+1>S_INF: ".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][A_STATUS_INFO]]." | ".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_INFO]]." |SN:<b>".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_SERIAL]]."</b>[........................] |Producent:<b>".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_PRODUCER]]."</b>[.......................] |gwarancja do:<b>".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_GUARRANTY_EXPIRE]]."</b>[.............] |Zasil.:<b>".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_POWER]]."</b>[..............] [OK]</font><br>";
  }
   echo "X Typ:[.................] Sprawnych_Portow:[..............] Nr/Ser:[..............................] Producent:[..............................] Gwarancja_do:[.............] Zasil.:[..................]";
   echo "</td></tr>";  



  echo "<tr><td colspan=1 rowspan=1>Magistrale</td><td>";

    echo "<table border=1 cellspacing=0 cellpadding=0 width=100% bordercolor=black><tr><td height=20>";
 $zap_SQLMIN="select * from TELBOXES where T_TELBOX_NAME='".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NEIGHBOUR_IN]]."' ";
 $result_min = mysql_query($zap_SQLMIN,$conn) or die("Blad zapytania5!\n $zap_SQLMIN");
  while ($l=mysql_fetch_row($result_min)) {
   $MIN_A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM]],color);   
   $MIN_A_STATUS_COLOR=USERS_COLUMN_COLOR_RETURN(A_STATUS,$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_STATUS]],color);   
//   echo "<font $MIN_A_STATUS_COLOR size=-1><a href=$PHP_SELF?FUNCTION_INIT=TELBOX_SHOW_MINI&ARG1=T_TELBOX_NAME&ARG1_VAL=".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]]."><b>".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]]."</a></b></font> $MIN_A_PROBLEM_COLOR<font size=-1>P_DATE:".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DATE]]." |S_INF: ".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DESC]]." | Opis:".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DESC]]."Data:".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DATE]]." | Typ:".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_TYPE]]." |Zabezp: ".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_SAVE]]." |V: ".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_POWER]]." </font><br>";
   echo "<font $MIN_A_STATUS_COLOR size=-1><a href=$PHP_SELF?FUNCTION_INIT=TELBOX_SHOW_MINI&ARG1=T_TELBOX_NAME&ARG1_VAL=".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]]."><b>".$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]]."</a></b></font>[.....................][OK]</td>";
  }
//echo "</td></tr><tr><td>";
 $zap_SQLMOUT="select * from TELBOXES where T_TELBOX_NEIGHBOUR_IN='$ARG1_VAL'";
 $result_mout = mysql_query($zap_SQLMOUT,$conn) or die("Blad zapytania4!\n $zap_SQLMOUT");
  while ($k=mysql_fetch_row($result_mout)) {
   $MOUT_A_STATUS_COLOR=USERS_COLUMN_COLOR_RETURN(A_STATUS,$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_STATUS]],color);   
   $MOUT_A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM]],color);   
//   echo "<font $MOUT_A_STATUS_COLOR size=-1><b><a href=$PHP_SELF?FUNCTION_INIT=TELBOX_SHOW_MINI&ARG1=T_TELBOX_NAME&ARG1_VAL=".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]].">".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]]."</a></b></font>$MOUT_A_PROBLEM_COLOR <font size=-1>S_INF: ".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DESC]]." | Opis:".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DESC]]." Typ:".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_TYPE]]." |Zabezp: ".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_SAVE]]." |V: ".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_POWER]]." </font><br>";
   echo "<td><font $MOUT_A_STATUS_COLOR size=-1><b><a href=$PHP_SELF?FUNCTION_INIT=TELBOX_SHOW_MINI&ARG1=T_TELBOX_NAME&ARG1_VAL=".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]].">".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]]."</a></b></font>[.....................][OK]</td>";
  }

    echo "<td>[.....................]</td><td>[.....................]</td><td>[.....................]</td></tr></table>";
  echo "</td></tr>";    
    }

 }
$MENU_INIT="DOL";
}

