\n";
} else {
fwrite($fp, "$order\n;quit\n");
$errormessage= fgets($fp, 1024);
fclose($fp);
}
}
return $errormessage;
}
###### make an array from the xmllist
unset($output);
$stack = array();
$output=array();
$version = explode('.', phpversion());
if ( $version[0] == 4 )
{
$xmllist="$fhz1000_pl $fhz1000port xmllist";
exec($xmllist,$output);
}
else
{
$fp = stream_socket_client("tcp://$fhz1000:$fhz1000port", $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno) \n";
} else {
fwrite($fp, "xmllist\r\n;quit\r\n");
while (!feof($fp)) {
$outputvar = fgets($fp, 1024);
array_push($output,$outputvar);
}
fclose($fp);
}
}
# start_element_handler ( resource parser, string name, array attribs )
function startElement($parser, $name, $attribs)
{
global $stack;
$tag=array("name"=>$name,"attrs"=>$attribs);
array_push($stack,$tag);
}
# end_element_handler ( resource parser, string name )
function endElement($parser, $name)
{
global $stack;
$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
array_pop($stack);
}
function new_xml_parser($live)
{
global $parser_live;
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!is_array($parser_live)) {
settype($parser_live, "array");
}
$parser_live[$xml_parser] = $live;
return array($xml_parser, $live);
}
# go parsing
if (!(list($xml_parser, $live) = new_xml_parser($live))) {
die("could not parse XML input");
}
foreach($output as $data) {
if (!xml_parse($xml_parser, $data)) {
die(sprintf("XML error: %s at line %d\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
#for testing
#print_r($stack);exit;
#searching for rooms/fs20
$rooms=array();
$fs20devs=array();
$fhtdevs=array();
if ($showroombuttons==1)
for($i=0; $i < count($stack[0][children]); $i++)
{
if ($stack[0][children][$i][name]=='FS20_DEVICES')
{
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$fs20devxml=$stack[0][children][$i][children][$j][attrs][name];
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
$check=$stack[0][children][$i][children][$j][children][$k][attrs][name];
if ($check='ATTR')
{
if (($stack[0][children][$i][children][$j][children][$k][attrs][key])=='room')
{
$room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
if (! in_array($room,$rooms)) array_push($rooms,$room);
}
}
}
if ((! in_array($fs20devxml,$fs20devs)) AND ( $room != 'hidden')) array_push($fs20devs,$fs20devxml);
}
}#FS20
elseif ($stack[0][children][$i][name]=='FHT_DEVICES')
{
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$fhtdevxml=$stack[0][children][$i][children][$j][attrs][name];
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
$check=$stack[0][children][$i][children][$j][children][$k][attrs][key];
if ( $check=="room")
{$room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
if (! in_array($room,$rooms)) array_push($rooms,$room);
}
}
if ((! in_array($fhtdevxml,$fhtdevs)) AND ( $room != 'hidden')) array_push($fhtdevs,$fhtdevxml);
}
} #FHT
elseif ($stack[0][children][$i][name]=='HMS_DEVICES')
{
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
if ( $stack[0][children][$i][children][$j][children][$k][attrs][key]=="room")
{$room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
if (! in_array($room,$rooms)) array_push($rooms,$room);
}
}
}
} # HMS
elseif ($stack[0][children][$i][name]=='KS300_DEVICES')
{
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
$check=$stack[0][children][$i][children][$j][children][$k][attrs][name];
if ($check='ATTR')
{
if (($stack[0][children][$i][children][$j][children][$k][attrs][key])=='room')
{
$room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
if (! in_array($room,$rooms)) array_push($rooms,$room);
}
}
}
}
}
} # end searching rooms
array_push($rooms,'ALL');
sort($rooms);
#print_r($rooms); echo "Count: $countrooms"; exit;
#print_r($fs20devs); exit;
# Print Array on Screen
$now=date($timeformat);
echo "
$titel ";
include ("include/style.css");
echo " ";
echo"
$errormessage
$titel
$now
v$pgm3version
";
############################ FHZ
echo "";
echo " ";
if (($show_general=='1') AND ($showmenu=='1'))
{echo "
General:
";
};
if (($show_fs20pulldown=='1') AND ($showmenu=='1')) include 'include/fs20pulldown.php';
if (($show_fhtpulldown=='1') AND ($showmenu=='1')) include 'include/fhtpulldown.php';
############################ ROOMS
if (($showroombuttons==1) and (count($rooms)>1))
{
echo "";
echo "ROOMS ";
echo " ";
echo "";
$counter=0;
for($i=0; $i < count($rooms); $i++)
{
$room=$rooms[$i];
if ($room != 'hidden')
{
echo" ";
$counter++;
if (fmod($counter,$roommaxiconperline)== 0.0) echo " ";
} else $counter--;
}
echo " ";
}
#####################################################################################################################
##### Let's go.... :-)))))
for($i=0; $i < count($stack[0][children]); $i++)
{
############################
if ($stack[0][children][$i][name]=='FS20_DEVICES')
{
$type=$stack[0][children][$i][name];
echo "";
echo "$type ";
$counter=0;
echo "";
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$fs20=$stack[0][children][$i][children][$j][attrs][name];
$state=$stack[0][children][$i][children][$j][attrs][state];
$room='';
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
$check=$stack[0][children][$i][children][$j][children][$k][attrs][name];
if ($check='STATE')
{
$measured=$stack[0][children][$i][children][$j][children][$k][attrs][measured];
}
if ($check='ATTR')
{
if (($stack[0][children][$i][children][$j][children][$k][attrs][key])=='room')
{
$room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
}
}
}
if (($state=='on') or ($state=='dimup'))
{$order="set $fs20 off";}
else
{$order="set $fs20 on";};
if (($room != 'hidden') and ($showroom=='ALL' or $showroom==$room))
{
$counter++;
echo" ";
if (fmod($counter,$fs20maxiconperline)== 0.0) echo " ";
};
}
echo " ";
}
############################
elseif ($stack[0][children][$i][name]=='FHT_DEVICES')
{
$type=$stack[0][children][$i][name];
echo "";
echo "$type ";
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$room="";
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
$check=$stack[0][children][$i][children][$j][children][$k][attrs][key];
if ( $check=="room")
{$room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
}
}
if (($room != 'hidden') and ($showroom=='ALL' or $showroom==$room))
{
$FHTdev=$stack[0][children][$i][children][$j][attrs][name];
if ($showfht == $FHTdev)
{echo "
";}
else
{echo "
";
};
echo "
$FHTdev
";
echo "
";
echo " ";
if ($showfht==$FHTdev and $showgnuplot == 1)
{
drawgnuplot($FHTdev,"FHT",$gnuplot,$pictype,$logpath);
$FHTdev1=$FHTdev.'1';
echo "
";
}
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
if ( $showfht==$FHTdev)
{
$name=$stack[0][children][$i][children][$j][children][$k][attrs][name];
$value=$stack[0][children][$i][children][$j][children][$k][attrs][value];
$measured=$stack[0][children][$i][children][$j][children][$k][attrs][measured];
echo " $FHTdev (FHT): $name $value
$measured ";
}
}
}
}
}
############################
elseif ($stack[0][children][$i][name]=='HMS_DEVICES')
{
$type=$stack[0][children][$i][name];
echo "";
echo "$type ";
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$room="";
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
if ( $stack[0][children][$i][children][$j][children][$k][attrs][key]=="room")
{$room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
}
if ( $stack[0][children][$i][children][$j][children][$k][attrs][name]=="type")
{$type=$stack[0][children][$i][children][$j][children][$k][attrs][value];};
}
if (($room != 'hidden') and ($showroom=='ALL' or $showroom==$room))
{
$HMSdev=$stack[0][children][$i][children][$j][attrs][name];
if ($type=="HMS100T" or $type=="HMS100TF")
{
if ($showhmsgnu== $HMSdev)
{$formvalue="hide";$gnuvalue="";}
else {$formvalue="show";$gnuvalue=$HMSdev;};
echo "
";
}
else
echo " ";
echo " $HMSdev
";
if ($showhmsgnu == $HMSdev and $showgnuplot == 1)
{ drawgnuplot($HMSdev,$type,$gnuplot,$pictype,$logpath);
$HMSdev1=$HMSdev.'1';
echo "
";
}
}
}
}
############################
elseif ($stack[0][children][$i][name]=='KS300_DEVICES')
{
$type=$stack[0][children][$i][name];
echo "";
echo "$type ";
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$KSdev=$stack[0][children][$i][children][$j][attrs][name];
$room='';
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
$check=$stack[0][children][$i][children][$j][children][$k][attrs][name];
if ($check='STATE')
{
$name=$stack[0][children][$i][children][$j][children][$k][attrs][name];
$value=$stack[0][children][$i][children][$j][children][$k][attrs][value];
$measured=$stack[0][children][$i][children][$j][children][$k][attrs][measured];
if ($name=='temperature') {$KSmeasured=$measured;}
elseif ($name=='avg_month') {$KSavgmonth=$value;}
elseif ($name=='avg_day') {$KSavgday=$value;};
}
if ($check='ATTR')
{
if (($stack[0][children][$i][children][$j][children][$k][attrs][key])=='room')
{
$room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
}
}
}
if (($room != 'hidden') and ($showroom=='ALL' or $showroom==$room))
{
$Xks=$imgmaxxks;
$Yks=$imgmaxyks*4;
##gnuplot
if ($showks == $KSdev)
{echo "
";}
else
{echo "
";
};
echo " $KSdev ";
echo " ";
echo " ";
if (($showks == $KSdev) and $showgnuplot=='1')
{
if ($kstyp=="1")drawgnuplot($KSdev,"KS300_t1",$gnuplot,$pictype,$logpath);
else drawgnuplot($KSdev,"KS300_t2",$gnuplot,$pictype,$logpath);
$KSdev1=$KSdev.'1';
echo "
";
}
}
}
}
############################
elseif ($stack[0][children][$i][name]=='LOGS')
{
echo "
LOGS ";
if (! isset ($showlogs))
{ echo "show ";}
else
{
echo "hide ";}
echo "
";
if (isset ($showlogs))
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$name=$stack[0][children][$i][children][$j][attrs][name];
$definition=$stack[0][children][$i][children][$j][attrs][definition];
if ($definition != "")
{echo "Log:
$definition ";
}
}
}
############################
elseif ($stack[0][children][$i][name]=='NOTIFICATIONS')
{
echo "
NOTIFICATIONS ";
if (! isset ($shownoti))
{ echo "show ";}
else
{ echo "hide ";}
echo "
";
if (isset ($shownoti))
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$event=$stack[0][children][$i][children][$j][attrs][event];
$command=$stack[0][children][$i][children][$j][attrs][command];
$measured=$stack[0][children][$i][children][$j][children][0][attrs][measured];
echo "Notification: $event $command ";
}
}
############################
elseif ($stack[0][children][$i][name]=='AT_JOBS')
{
echo "
AT_JOBS ";
if (! isset ($showat))
{ echo "show ";}
else
{ echo "hide ";}
echo "
";
if (isset ($showat))
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$command=$stack[0][children][$i][children][$j][attrs][command];
$next=$stack[0][children][$i][children][$j][attrs][next];
$order=$command;
$order=str_replace("+","@",$order);
$order='del at '.$order;
if ($next != '') {$nexttxt='('.$next .')';} else {$nexttxt='';};
echo " AT-Job: del $command $nexttxt ";
}
}
};
if ($taillog==1)
{
echo "
$taillogorder ";
if (! isset ($showhist))
{ echo "show ";}
else
{ echo "hide ";}
echo "
";
if (isset ($showhist)) {foreach($tailoutput as $data) echo "History $data ";};
};
echo "
";
?>