<?php

function TELBOX_SHOW_MINI($ARG1,$ARG1_VAL) {
global $SQL_USER,$SQL_DATABASE,$INTERFACE_ADDR,$SQL_USER_PASS,$MENU_INIT,$CURRENT_MENU;
//echo "ARG1=$ARG1 , ARG1_VAL=$ARG1_VAL";
//echo "<table background=icon/TELBOX_S-R2.gif border=0><tr><td>test</td></tr></table>";

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); 
//print_r($_SESSION);

    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);   
//   $A_TELBOX_ICON
  echo "<table width=100% border=1 cellspacing=0 cellpadding=1 bordercolor=blue><tr>";
 $zap_SQLMIN="select * from BUILDINGS where S_ADDRESS_STREET='".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_BUILDING_IN]]."' and S_ADDRESS_STREET!='' ";
//echo $zap_SQLMIN; 
 $result_min = mysql_query($zap_SQLMIN,$conn) or die("Blad zapytania5!\n $zap_SQLMIN");
  while ($ll=mysql_fetch_row($result_min)) {
   $MIN_A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][A_PROBLEM]],bgcolor);   
   $MIN_A_STATUS_COLOR=USERS_COLUMN_COLOR_RETURN(A_STATUS,$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][A_STATUS]],bgcolor);   
//   $MIN_B_INVENTORY_DATE_COLOR=USERS_COLUMN_COLOR_RETURN(L_APPOITMENT_DATE,$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][B_INVENTORY_DATE]],bgcolor);   
   echo "<td colspan=2 $MIN_A_STATUS_COLOR><b>".$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][S_ADDRESS_STREET]]."</b> ".$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][S_ADMIN_NAME]]."</font></td><td colspan=2 $MIN_A_PROBLEM_COLOR><font size=-1>P_DATE:".$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][A_PROBLEM_DATE]]." |S_INF: ".$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][A_PROBLEM_DESC]]." | Typ:".$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][T_BUILDING_TYPE]]." |Zabezp: ".$ll[$_SESSION[BUILDING_COLUMN][DESC_TO_KEY][T_BUILDING_SAVE]]." |V: ".$ll[$_SESSION[BUILDING_COLUMN][DESC_TO_KEY][T_BUILDING_POWER]]." </font></td><td $MIN_B_INVENTORY_DATE_COLOR><font size=-1>Inwent:".$ll[$_SESSION[BUILDINGS_COLUMN][DESC_TO_KEY][B_INVENTORY_DATE]]."</td>";
  }
  echo "<table width=100% style=\"background-image: url(icon/TELBOX_S-R2.gif);
  background-position:100%;background-repeat:no-repeat;\" border=1><tr>";
  echo "<td height=30 colspan=3 $A_STATUS_COLOR><font size=+1><b>".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NAME]]."</b></td><td $A_PROBLEM_COLOR><font size=-1>PR:".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM]]."(".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DESC]]."|".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DATE]]." )<br>";
  echo "</td></tr>";

 $zap_SQLMIN="select * from TELBOXES where T_TELBOX_NAME='".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NEIGHBOUR_IN]]."' ";
//echo $zap_SQLMIN;
 $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]],bgcolor);   
   $MIN_A_STATUS_COLOR=USERS_COLUMN_COLOR_RETURN(A_STATUS,$l[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_STATUS]],bgcolor);   
   echo "<tr><td colspan=2 $MIN_A_STATUS_COLOR><font 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></td><td colspan=2 $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></td>";
  }
 //echo "<tr><td colspan=2 $MIN_A_STATUS_COLOR><font size=-1><b>".$h[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][T_TELBOX_NEIGHBOUR_IN]]."---&gt;</font></b></td><td colspan=2 $MIN_A_PROBLEM_COLOR></td></tr>";
 $zap_SQLABO="select S_ADDRESS_STREET,A_STATUS,A_PROBLEM,A_PROBLEM_DESC from USERS2 where T_TELBOX_ADDRESS='$ARG1_VAL' ORDER BY A_STATUS,(substring_index(S_ADDRESS_STREET,'/',-1)+0),ID";
 $result_abo = mysql_query($zap_SQLABO,$conn) or die("Blad zapytania3!\n $zap_SQLABO");
  while ($i=mysql_fetch_row($result_abo)) {
   echo "<tr><td></td><td ";
   $ABO_A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$i[2],bgcolor);   
   USERS_COLUMN_COLOR(A_STATUS,$i[1],bgcolor);
   echo "><font size=-1>$i[0]</font></td><td colspan=2 $ABO_A_PROBLEM_COLOR><font size=-1>$i[1] $i[2] $i[3]</font></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]],bgcolor);   
   $DEV_A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][A_PROBLEM]],bgcolor);   
   echo "<tr><td></td><td $DEV_A_STATUS_COLOR><font size=-1>".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_TYPE]]."(".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_PORTS_OK]].")</font></td><td colspan=2 $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: ".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_SERIAL]]." |P: ".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_PRODUCER]]." |gw.:".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_GUARRANTY_EXPIRE]]." |V: ".$j[$_SESSION[DEVICES_COLUMN][DESC_TO_KEY][T_DEVICE_POWER]]."</font></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]],bgcolor);   
   $MOUT_A_PROBLEM_COLOR=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM]],bgcolor);   
   echo "<tr><td colspan=2 $MOUT_A_STATUS_COLOR><font 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></td><td colspan=2 $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]]."Data:".$k[$_SESSION[TELBOX_COLUMN][DESC_TO_KEY][A_PROBLEM_DATE]]." | 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></td>";
  }

echo "</tr></table></td></tr></table>";    
    }

 }
$MENU_INIT="DOL";
}

