X-Git-Url: http://russells-world.com/code/?p=home-automation.git;a=blobdiff_plain;f=includes.php;fp=includes.php;h=a4ef0cc204011055d92c38a2b8edc5d8a5d25357;hp=f55dd8b0ff9d5b84429841859859709917a3b129;hb=2302283047d4580aa4b97bc8987dd1525480c3ba;hpb=22502eb7a498183fada4a50994fa2bb25e4bb790 diff --git a/includes.php b/includes.php index f55dd8b..a4ef0cc 100644 --- a/includes.php +++ b/includes.php @@ -13,32 +13,37 @@ function get_data($item) { } function summon($person,$status) { - if ($person == "russ") { - $myFile = "russ.txt"; - $fh = fopen($myFile, 'w') or die("can't open file"); - fwrite($fh, $status); + $myFile = "summon.txt"; + $list = file("summon.txt"); + $fh = fopen($myFile, 'w') or die("can't open file"); + $matched=0; + foreach ($list as $summoned) { + list($item,$flag) = split("=",trim($summoned)); + if ($person == $item) { + fwrite($fh, "$person=$status\n"); + $matched=1; + } else { + if (strlen($item) > 0) { + fwrite($fh, "$item=$flag\n"); + } + } + } + fclose($fh); + if ($matched==0) { + $fh = fopen($myFile, 'a') or die("can't open file"); + fwrite($fh, "$person=$status\n"); fclose($fh); } - if ($person == "beth") { - $myFile = "beth.txt"; - $fh = fopen($myFile, 'w') or die("can't open file"); - fwrite($fh, $status); - fclose($fh); - } } function summon_status($person) { - if ($person == "russ") { - $myFile = "russ.txt"; - $fh = fopen($myFile, 'r') or die("can't open file"); - $status = fread($fh, 5); - fclose($fh); - } - if ($person == "beth") { - $myFile = "beth.txt"; - $fh = fopen($myFile, 'r') or die("can't open file"); - $status = fread($fh, 5); - fclose($fh); + $myFile = "summon.txt"; + $list = file("summon.txt"); + foreach ($list as $summoned) { + list($item,$flag) = split("=",$summoned); + if ($person == $item) { + return($flag); + } } return($status); }