\n";
} else {
fwrite($fp, "$order\n;quit\n");
$errormessage= fgets($fp);
fclose($fp);
}
}
#}
return $errormessage;
}
###### make an array from the xmllist
unset($output);
$stack = array();
$output=array();
unset($longxml);
$version = explode('.', phpversion());
# get the xmllist from fhem
$fp = stream_socket_client("tcp://$fhem:$fhemport", $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno) \n";
} else {
fwrite($fp, "xmllist\r\n;quit\r\n");
$outputvar=stream_get_contents($fp);
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);
#print_r($stack);
#exit;
#searching for rooms/fs20/Logpaths
$rooms=array();
$fs20devs=array();
$fhtdevs=array();
$logpaths=array();
for($i=0; $i < count($stack[0][children]); $i++)
{
if ((substr($stack[0][children][$i][name],0,5)=='FS20_')
|| (substr($stack[0][children][$i][name],0,4)=='X10_'))
{
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
#################################################### FHTs
elseif (substr($stack[0][children][$i][name],0,4)=='FHT_')
{
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
#################################################### HMS and CUL_WS
elseif ((substr($stack[0][children][$i][name],0,4)=='HMS_') || (substr($stack[0][children][$i][name],0,7)=='CUL_WS_'))
{
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 and CUL_WS
#################################################### LogpathFileLOG
elseif (substr($stack[0][children][$i][name],0,8)=='FileLog_')
{
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]=="currentlogfile")
{$logpathstack=$stack[0][children][$i][children][$j][children][$k][attrs][value];
if (! in_array($logpathistack,$logpaths)) array_push($logpaths,$logpathstack);
}
}
}
} # FileLog
#################################################### INTERNAL Logpath
elseif (substr($stack[0][children][$i][name],0,9)=='_internal')
{
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]=="currentlogfile")
{$fhemlog=$stack[0][children][$i][children][$j][children][$k][attrs][value];
if (! in_array($fhemlog,$logpaths)) array_push($logpaths,$fhemlog);
}
}
}
} # _internal_
#################################################### SCIVT
elseif (substr($stack[0][children][$i][name],0,6)=='SCIVT_')
{
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);
}
}
}
} # SCIVT
#################################################### SCIVT
elseif (substr($stack[0][children][$i][name],0,6)=='KS300_')
{
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 /logpaths in the array from fhem
# user defined rooms?
if ($UserDefs==1)
{
for($i=0; $i < count($userdef); $i++)
{
$room=$userdef[$i]['room'];
if (! in_array($room,$rooms)) array_push($rooms,$room);
}
}
array_push($rooms,'ALL');
sort($rooms);
#print_r($rooms); echo "Count: $countrooms"; exit;
#print_r($fs20devs); exit;
#echo count($stack[0][children]);exit;
#print_r($logpaths); exit;
#exit;
# Print Array on Screen
$now=date($timeformat);
# only RSS-Feeds??
if (isset($showrss)) { include "include/rssfeeds.php"; exit; }
###### write the header on screen
echo "
$titel ";
include ("include/style.css");
echo " ";
echo"
$errormessage
\r
\r
\r
\r
$titel
$now
v$pgm3version
";
###################### Webcam
if ($showwebcam==1)
{
echo "
\r
WEBCAM ";
if (! isset($showpics))
{ echo "show pics ";}
else
{ echo "hide pics ";}
echo"
";
if (($webcamroom != 'hidden')
and ($showroom=='ALL' or $showroom==$webcamroom or $webcamroom=='donthide'))
if (isset($showpics))
{
for($i=0; $i < count($webcam); $i++)
{
$webcam1=$webcam[$i];
$pos = strpos($webcam1,'://'); # e.g. http://..
if ($pos === false) # picture instead of an URL
{
$webcamname=$webcam[$i];
}
else
{
$webcamname=str_replace("/","",$webcam1);
$webcamname=str_replace(":","",$webcamname);
# $order="$wgetpath -O tmp/$webcamname $webcam1; /usr/bin/touch tmp/$webcamname";
$order="$wgetpath -O tmp/$webcamname $webcam1";
exec($order,$res);
$errormessage = $res[0];
echo $errormessage;
}
echo" ";
}
}
echo"
\r
";
};
############################ WEATHER
if ($enableweather==1)
{
echo "\r
WEATHER ";
if ($showweath != '1')
{ echo "show ";}
else
{ echo "hide ";}
echo " \r
";
echo " ";
if (($weatherroom != 'hidden')
and ($showroom=='ALL' or $showroom==$weatherroom or $weatherroom=='donthide')
and ($showweath==1)) include 'include/weather.php';
}
############################ FHZ
if ($show_fs20pulldown==1 or $show_general==1 or $show_fhtpulldown==1)
{
echo "\r
FHZ_DEVICE ";
if ($showmenu != '1')
{ echo "show ";}
else
{ echo "hide ";}
echo " \r
";
echo " ";
}
if ($showmenu=='1')
{
if ($show_general=='1')
{echo "
General:
";
};
if ($show_fs20pulldown=='1') include 'include/fs20pulldown.php';
if ($show_fhtpulldown=='1') include 'include/fhtpulldown.php';
if ($show_logpulldown=='1') include 'include/logpulldown.php';
};
############################ ROOMS
if (($showroombuttons==1) and (count($rooms)>1))
{
echo "\r\r
\r\r \r";
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 " ";
}
#####################################################################################################################
##### Check Version of FHEM
if (! ($stack[0][children][0][name]=='_internal__LIST')) ##older FHZ100 have no Internal_LIST
{echo "Error!! There is no FHEM. You need at least FHEM-4.0 to run this pgm3!!";}
## now the xmllist will be writen on screen as html
##### Let's go.... :-)))))
for($i=0; $i < count($stack[0][children]); $i++)
{
############################
if ((substr($stack[0][children][$i][name],0,5)=='FS20_') || (substr( $stack[0][children][$i][name],0,4)=='X10_'))
{
$type=$stack[0][children][$i][name];
#echo "\r";
#echo "$type ";
echo "\r\r
\r\r \r";
$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 " \r";
if (isset($showfs20) and $showgnuplot == 1)
{
drawgnuplot($showfs20,"FS20",$gnuplot,$pictype,$logpath, $FHTyrange,$FHTy2range,$DBUse);
$FS20dev1=$showfs20.'1';
echo "\r
";
}
}
############################
elseif (substr($stack[0][children][$i][name],0,4)=='FHT_')
{
$type=$stack[0][children][$i][name];
#echo "";
#echo "$type \r";
echo "\r\r
\r\r \r";
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 ( $check=="warnings")
{$battery=$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 "\r
adjust ";
}
else
{echo "\r
adjust ";
};
echo "\r
";
echo " ";
if ($showfht==$FHTdev and $showgnuplot == 1)
{
drawgnuplot($FHTdev,"FHT",$gnuplot,$pictype,$logpath, $FHTyrange,$FHTy2range,$DBUse);
$FHTdev1=$FHTdev.'1';
echo "\r
";
}
if ( $showfht==$FHTdev)
{
echo "\r\r";
for($k=0; $k < count($stack[0][children][$i][children][$j][children]); $k++)
{
$name=$stack[0][children][$i][children][$j][children][$k][attrs][key];
$value=$stack[0][children][$i][children][$j][children][$k][attrs][value];
$measured=$stack[0][children][$i][children][$j][children][$k][attrs][measured];
echo "\r $FHTdev (FHT): $name $value
$measured ";
}
echo "\r
\r\r";
}
}
}
}
############################
elseif ((substr($stack[0][children][$i][name],0,4)=='HMS_') or (substr($stack[0][children][$i][name],0,6)=='CUL_WS'))
{
$type=$stack[0][children][$i][name];
#echo "\r";
# echo "$type ";
echo "\r\r
\r\r \r";
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]=="battery")
{$battery=$stack[0][children][$i][children][$j][children][$k][attrs][value];
}
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][key]=="type") or
( $stack[0][children][$i][children][$j][children][$k][attrs][key]=="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" or $type=="CUL_WS")
{
if ($showhmsgnu== $HMSdev) {$formvalue="hide";$gnuvalue="";}
else {$formvalue="show";$gnuvalue=$HMSdev;};
echo "\r
";
}
else
{echo "\ ";}
echo " ";
if ($showhmsgnu == $HMSdev and $showgnuplot == 1)
{ drawgnuplot($HMSdev,$type,$gnuplot,$pictype,$logpath,0,0,$DBUse);
$HMSdev1=$HMSdev.'1';
echo "\r
";
}
}
}
}
############################
elseif (substr($stack[0][children][$i][name],0,6)=='KS300_' or substr($stack[0][children][$i][name],0,6)=='WS300_')
{
$type=$stack[0][children][$i][name];
#echo "\r";
#echo "$type ";
echo "\r\r
\r\r \r";
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][key];
$check2=$stack[0][children][$i][children][$j][children][$k][attrs][name];
if ($check=='room') $room=$stack[0][children][$i][children][$j][children][$k][attrs][value];
elseif ($check=='willi') $willi=1;
elseif ($check=='avg_day') $KSavgday=$stack[0][children][$i][children][$j][children][$k][attrs][value];
elseif ($check=='temperature') $KSmeasured=$stack[0][children][$i][children][$j][children][$k][attrs][measured];
elseif ($check=='avg_month') $KSavgmonth=$stack[0][children][$i][children][$j][children][$k][attrs][value];
# for older versions...
if ($check2=='avg_month') $KSavgmonth=$stack[0][children][$i][children][$j][children][$k][attrs][value];
elseif ($check2=='avg_day') $KSavgday=$stack[0][children][$i][children][$j][children][$k][attrs][value];
elseif ($check2=='temperature') $KSmeasured=$stack[0][children][$i][children][$j][children][$k][attrs][measured];
elseif ($check2=='willi') $willi=1;
}
if (($room != 'hidden') and ($showroom=='ALL' or $showroom==$room))
{
$Xks=$imgmaxxks;
$Yks=$imgmaxyks*4;
##gnuplot
if ($showks == $KSdev)
{echo "\r
";}
else
{echo "\r
";
};
echo "\r";
echo " ";
echo " ";
if (! isset ($willi)) $drawtype="KS300"; else $drawtype="WS300";
if (($showks == $KSdev) and $showgnuplot=='1')
{
if ($kstyp=="1")
{
drawgnuplot($KSdev,$drawtype."_t1",$gnuplot,$pictype,$logpath,0,0,$DBUse);
}
else
{
drawgnuplot($KSdev,$drawtype."_t2",$gnuplot,$pictype,$logpath,0,0,$DBUse);
}
$KSdev1=$KSdev.'1';
echo "\r
";
}
}
}
}
############################
elseif ($stack[0][children][$i][name]=='LOGS'or $stack[0][children][$i][name]=='FileLog_LIST')
{
echo "\r
\r
LOGS ";
if (! isset ($showlogs))
{ echo "show ";}
else
{
echo "hide ";}
echo " \r
\r";
if (isset ($showlogs))
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][key];
if ($check=='DEF')
{
$value=$stack[0][children][$i][children][$j][children][$k][attrs][value];
}
}
$name=$stack[0][children][$i][children][$j][attrs][name];
echo "\rLog:
$value / $name ";
}
}
############################
elseif ($stack[0][children][$i][name]=='NOTIFICATIONS' or $stack[0][children][$i][name]=='notify_LIST')
{
echo "\r
\r
NOTIFICATIONS ";
if (! isset ($shownoti))
{ echo "show ";}
else
{ echo "hide ";}
echo " \r
\r\r";
if (isset ($shownoti))
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][key];
if ($check=='DEF')
{
$value=$stack[0][children][$i][children][$j][children][$k][attrs][value];
}
}
$name=$stack[0][children][$i][children][$j][attrs][name];
echo "\rNotification: $value / $name ";
}
}
############################
elseif ($stack[0][children][$i][name]=='AT_JOBS' or $stack[0][children][$i][name]=='at_LIST')
{
echo "\r
\r
AT_JOBS ";
if (! isset ($showat))
{ echo "show ";}
else
{ echo "hide ";}
echo " \r
\r\r";
if (isset ($showat))
for($j=0; $j < count($stack[0][children][$i][children]); $j++)
{
$command=$stack[0][children][$i][children][$j][attrs][name];
$next=$stack[0][children][$i][children][$j][attrs][state];
$order=$command;
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=='DEF')
{
$value=$stack[0][children][$i][children][$j][children][$k][attrs][value];
}
}
$order='delete '.$order;
echo "\r AT-Job: del $value / $next / $command ";
}
}
};
## that is all of fhem
##################### User defined graphics??
if ($UserDefs==1)
{
echo "\r\r
\r\r \r";
$type='userdef';
for($i=0; $i < count($userdef); $i++)
{
$room=$userdef[$i]['room'];
$UserDef=$userdef[$i]['name'];
$imgmaxxuserdef=$userdef[$i]['imagemax'];
$imgmaxyuserdef=$userdef[$i]['imagemay'];
if (($room != 'hidden') and ($showroom=='ALL' or $showroom==$room))
{
if ($showuserdefgnu== $UserDef) {$formvalue="hide";$gnuvalue="";}
else {$formvalue="show";$gnuvalue=$UserDef;};
echo "\r
\r \r";
echo "\r ";
if ($showuserdefgnu == $UserDef and $showgnuplot == 1)
{ drawgnuplot($UserDef,$type,$gnuplot,$pictype,$logpath,$userdef[$i],$i,$DBUse);
$UserDef1=$UserDef.'1';
echo "\r
";
}
}# /not room hidden
}
} #/userdefs
##################### taillog
if ($taillog==1)
{
echo "\r\r
\r\r
$taillogorder ";
if (! isset ($showhist))
{ echo "show ";}
else
{ echo "hide ";}
echo " \r
";
if (isset ($showhist)) {foreach($tailoutput as $data) echo "\rHistory $data ";};
};
echo "\r\r
\r
\r
";
?>