<?php
$error5="error5 Przykro nam, serwis jest dostepny wylacznie dla autoryzowanych uzytkownikow $REMOTE_ADDR";


if(file_exists(".config.php")) include(".config.php");



require("$komputery_arr");

if(in_array("$REMOTE_ADDR",$KOMPUTERY))  $czy_error_5=1 ;

$czy_error_5=1;

if($czy_error_5) {

foreach ($_GET as $k => $v) {
	$_GET[$k]=addslashes($_GET[$k]);
	$v=addslashes($v);
	// $v=ereg_replace(';','',$v);
	eval(" \$$k = \"$v\" ;");
}
foreach ($_POST as $k => $v) {
	$_POST[$k]=addslashes($_POST[$k]);
	$v=addslashes($v);
	// $v=ereg_replace(';','',$v);
	eval(" \$$k = \"$v\" ;");
}
      


$ADM_USER=$SQL_USER ;
$ADM_USER_PASS=$SQL_USER_PASS ;
$SQL_TABLE_USERS="USERS2";
$SQL_TABLE_ADMIN_USERS="ADMIN_USERS";

$conn=mysql_pconnect($INTERFACE_ADDR,$ADM_USER,$ADM_USER_PASS);
if (!$conn) die("ERROR podczas tworzenia polaczenia do bazy $SQL_DATABASE !\n");
mysql_select_db($SQL_DATABASE) or die("ERROR podczas wyboru bazy!");

function get_telboxes($T_TELBOX_NAME) {
	$telboxes[]=$T_TELBOX_NAME;
	$query="select T_TELBOX_NAME from TELBOXES where T_TELBOX_NEIGHBOUR_IN='".$T_TELBOX_NAME."' and A_STATUS='NORMAL'";
	$result=mysql_query($query);
	while ($row=mysql_fetch_object($result)) {
		$T_TELBOX_NAME=$row->T_TELBOX_NAME;
		$telboxes=array_merge($telboxes,get_telboxes($T_TELBOX_NAME));
	}
	return $telboxes;
}

$telboxes=get_telboxes("BI19A-PIW");

unset($s_telboxes);
echo count($telboxes)."\n";
foreach ($telboxes as $telbox) {
	if (isset($s_telboxes)) $s_telboxes.=",";
	$s_telboxes.="'".$telbox."'";
}

if (isset($s_telboxes)) {
	$query="select count(*) as count from USERS2 where T_TELBOX_ADDRESS in (".$s_telboxes.") and A_STATUS in ('NORMAL','WAITING') group by S_ADDRESS_STREET";
	$result=mysql_query($query);
	$row=mysql_fetch_object($result);
	//echo $row->count;
	echo mysql_num_rows($result);
}// else echo "0";

echo "\n";

} else {
echo $error5 ;
}
?>
