function dbase_parse($cmd, $message) { global $pisql, $dbhost, $dbuser, $dbpass, $dbname; global $log; // Used by daemon global $apperr, $appmsg; // For ajax usage if (!$pisql || !$pisql->ping()) { $log->lwrite("dbase_parse:: Ping failed, making new pisql connection to server", 1); $pisql = new mysqli($dbhost, $dbuser, $dbpass, $dbname); } // If there is an error if ($pisql->connect_errno) { $log->lwrite("dbase_parse:: Failed to connect to MySQL: (" . $pisql->connect_errno . ") " . $pisql->connect_error, 1); return -1; } // For logging only if (is_array($message)) { $str = ""; foreach ($message as $key => $val) { $str .= " {" . $key . ":" . $val . "},"; } $log->lwrite("dbase_parse:: " . $cmd . ": " . $str, 1); } else { $log->lwrite("dbase_parse:: message: " . $cmd . ": " . $message, 1); } // // Depending on $cmd execute database function switch ($cmd) { // Database case "load_database": $ret = load_database(); break; // Device // Device case "load_devices": $ret = load_devices(); break; case "add_device": $ret = add_device($message); break; case "delete_device": $ret = delete_device($message); break; case "store_device": $ret = store_device($message); break; // Room // Room case "add_room": $ret = add_room($message); break; case "delete_room": $ret = delete_room($message); break; // Scene // Scene case "read_scene": $ret = load_scene($message); break; case "load_scenes": $ret = load_scenes(); break; case "add_scene": $ret = add_scene($message); break; case "delete_scene": $ret = delete_scene($message); break; case "upd_scene": $ret = upd_scene($message); break; case "store_scene": $ret = store_scene($message); break; // Timer // Timer case "add_timer": $ret = add_timer($message); break; case "delete_timer": $ret = delete_timer($message); break; case "store_timer": $ret = store_timer($message); break; // Handset // Handset case "add_handset": $ret = add_handset($message); break; case "delete_handset": $ret = delete_handset($message); break; case "store_handset": $ret = store_handset($message); break; // Weather // Weather case "add_weather": $ret = add_weather($message); break; case "delete_weather": $ret = delete_weather($message); break; // Setting // Setting case "store_setting": $ret = store_setting($message); break; default: } if ($ret >= 0) { // Prepare structure to send back to the calling ajax client (in stdout) $send = array('tcnt' => $ret, 'appmsg' => $appmsg, 'status' => 'OK', 'apperr' => $apperr); $output = json_encode($send); } else { // Functions need to fill apperr themselves! $send = array('tcnt' => $ret, 'appmsg' => $appmsg, 'status' => 'ERR', 'apperr' => $apperr); $output = json_encode($send); } return $output; }
if ($time_last_run > $secs_stop) { $log->lwrite("Timer has possibly already stopped, so we should not proceed any further", 2); } else { $log->lwrite("TIMER STOPPED: " . $timers[$i]['name'], 1); // probably stopped last time } } else { if ($tim > $secs_start && $tim > $secs_today) { if ($time_last_run > $secs_today) { // We have already started at least one loop before $log->lwrite("Timer " . $timers[$i]['name'] . " planned at: " . date('l jS \\of F Y h:i:s A', $secs_today) . " started already before " . date('l jS \\of F Y h:i:s A', $time_last_run) . "\n", 3); } else { if ($timers[$i]['skip'] == "1") { $log->lwrite("main:: Timer Cancel Once execution was active", 1); $timers[$i]['skip'] = "0"; store_timer($timers[$i]); } else { // make the command and queue it (in step 1) $log->lwrite("STARTING TIMER " . $timers[$i]['name'] . ", scene: " . $timers[$i]['scene'] . " at " . date('Y-m-d', $tim), 1); $log->lwrite("STARTING TIMER last_run: " . date('l jS \\of F Y h:i:s A', $time_last_run) . ", tim: " . date('l jS \\of F Y h:i:s A', $tim), 2); $log->lwrite("STARTING TIMER secs_start: " . date('l jS \\of F Y h:i:s A', $secs_start) . ", tim: " . date('l jS \\of F Y h:i:s A', $tim), 2); $log->lwrite("STARTING TIMER secs_today: " . date('l jS \\of F Y h:i:s A', $secs_today) . ", tim: " . date('l jS \\of F Y h:i:s A', $tim), 2); $scene = load_scene($timers[$i]['scene']); if ($scene == -1) { // Command not found in database $log->lwrite("main:: Cannot find scene: " . $timers[$i]['scene'] . " in the database", 1); break; } $scene_name = $scene['name']; $scene_seq = $scene['seq']; if ($scene_seq == "") {
$apperr .= "Calling delete_scene:: json: " . json_decode($icsmsg) . "\n"; $tcnt = delete_scene($icsmsg); $apperr .= "\nScene deleted "; $ret = $tcnt; break; // Timer database functions // Timer database functions case "add_timer": $apperr .= "Calling add_timer:: icsmsg: " . $icsmsg . ", json: " . json_decode($icsmsg) . "\n"; $tcnt = add_timer($icsmsg); $apperr .= "\nAdd timer "; $ret = $tcnt; break; case "store_timer": $apperr .= "Calling store_timer:: icsmsg: " . $icsmsg . ", json: " . json_decode($icsmsg) . "\n"; $tcnt = store_timer($icsmsg); $apperr .= "\nStore timer "; $ret = $tcnt; break; case "delete_timer": $apperr .= "Calling delete_timer:: icsmsg: " . $icsmsg . ", json: " . json_decode($icsmsg) . "\n"; $tcnt = delete_timer($icsmsg); $apperr .= "\nDelete timer "; $ret = $tcnt; break; // Handset Functions // // Handset Functions // case "add_handset": $apperr .= "Calling add_handset:: icsmsg: " . $icsmsg . ", json: " . json_decode($icsmsg) . "\n";