updated removed
[home-automation.git] / includes.php
1 <?
2 function get_data($item) {
3   $doc = new DOMDocument();
4   $doc->load('http://weather/weather/all-output.xml');
5   $arrFeeds = array();
6   foreach ($doc->getElementsByTagName('weather') as $node) {
7     $itemRSS = array ( 
8       $item => $node->getElementsByTagName($item)->item(0)->nodeValue,
9       );
10     array_push($arrFeeds, $itemRSS);
11   }
12   echo $itemRSS[$item];
13 }
14
15 function summon($person,$status) {
16   $myFile = "summon.txt";
17   $list = file("summon.txt");
18   $fh = fopen($myFile, 'w') or die("can't open file");
19   $matched=0;
20   foreach ($list as $summoned) {
21     list($item,$flag) = split("=",trim($summoned));
22     if ($person == $item) {
23       fwrite($fh, "$person=$status\n");
24       $matched=1; 
25     } else {
26       if (strlen($item) > 0) {
27         fwrite($fh, "$item=$flag\n");
28       }
29     }
30   }
31   fclose($fh);
32   if ($matched==0) {
33     $fh = fopen($myFile, 'a') or die("can't open file");
34     fwrite($fh, "$person=$status\n");
35     fclose($fh);
36   }
37 }
38
39 function summon_status($person) {
40   $myFile = "summon.txt";
41   $list = file("summon.txt");
42   foreach ($list as $summoned) {
43     list($item,$flag) = split("=",$summoned);
44     if ($person == $item) {
45       return($flag);
46     }    
47   }
48   return($status);
49 }
50 ?>