Exemple #1
0
     deletePlant($_REQUEST['uid'], $_REQUEST['pid']);
     break;
 case 'getOptimalSettings':
     getOptimalSettings($_REQUEST['plantID']);
     break;
 case 'setAlertType':
     $type = $_REQUEST['alert'];
     setAlertType($type);
     break;
 case 'sendAlert':
     $userID = $_REQUEST['uid'];
     $pid = $_REQUEST['pid'];
     $temp = $_REQUEST['temp'];
     $moisture = $_REQUEST['moisture'];
     $light = $_REQUEST['light'];
     sendAlert($userID, $pid, $temp, $moisture, $light);
     break;
 case 'getStatsHistory':
     $info = array();
     $i = 0;
     $query = mysql_query("SELECT `key`, `value`, `timestamp` FROM `user_plant_stats` WHERE (`pid` = 3 AND `key` = 'light' AND `id` % 9 = 0) ORDER BY `timestamp` DESC") or die('error querying:' . mysql_error());
     //
     while ($result = mysql_fetch_assoc($query)) {
         $info[$i]['key'] = $result['key'];
         $info[$i]['value'] = $result['value'];
         $info[$i]['timestamp'] = $result['timestamp'];
         $i += 1;
     }
     echo json_encode($info);
     break;
 default:
Exemple #2
0
function smsmAlertFunc($gid, $aid, $src, $nooftime, $inout, $devDateTime, $devImei, $inorout)
{
    $db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
    $db->connect();
    //print_r($_GET);
    //echo $aid."  ".$nooftime." cs ". $inorout." ds ".$inout." ".$devDateTime."<br><br>";
    //echo "<br><br>";
    $getAlertImeiInfo = "SELECT * FROM tb_geoalertinfo WHERE tgai_assignDevId = '" . $devImei . "' AND tgai_createDate like '" . date("Y-m-d", strtotime($devDateTime)) . "%' ORDER BY tgai_id DESC LIMIT 0,1";
    $resAlertImeiInfo = $db->query($getAlertImeiInfo);
    if ($db->affected_rows == 0) {
        if ($inout == 'in' && $inorout == $inout) {
            $smsStatus = sendAlert($aid, $devDateTime);
            //echo "<br>";
            if ($smsStatus) {
                $data['tgai_assignDevId'] = $devImei;
                $data['tgai_geoAssignId'] = $aid;
                $data['tgai_inoutStatus'] = 0;
                $data['tgai_alertCount'] = 1;
                $data['tgai_alertType'] = $inout;
                $data['tgai_reachdevTime1'] = date("Y-m-d H:i:s", strtotime($devDateTime));
                //print_r($data);
                //exit;
                if ($db->query_insert("tb_geoalertinfo", $data)) {
                    $res = 1;
                } else {
                    $res = 0;
                }
                echo "SMS";
            }
        } elseif ($inout == 'out' && $inorout != $inout) {
            $data['tgai_assignDevId'] = $devImei;
            $data['tgai_geoAssignId'] = $aid;
            $data['tgai_inoutStatus'] = 0;
            $data['tgai_alertCount'] = 1;
            $data['tgai_alertType'] = $inout;
            $data['tgai_reachdevTime1'] = date("Y-m-d H:i:s", strtotime($devDateTime));
            //print_r($data);
            //exit;
            if ($db->query_insert("tb_geoalertinfo", $data)) {
                $res = 1;
            } else {
                $res = 0;
            }
        }
    } else {
        $fetAlertImeiInfo = $db->fetch_array($resAlertImeiInfo);
        $getAlertInfo = "SELECT count(*) as pastTotal FROM tb_geoalertinfo WHERE tgai_geoAssignId = " . $aid . " AND tgai_inoutStatus = 1 AND tgai_createDate like '" . date("Y-m-d", strtotime($devDateTime)) . "%'";
        $resAlertInfo = $db->query($getAlertInfo);
        $fetAlertInfo = $db->fetch_array($resAlertInfo);
        //echo "<br>".$fetAlertImeiInfo[tgai_geoAssignId]." ".$aid." ".$fetAlertImeiInfo[tgai_inoutStatus]." ".$nooftime." ".$fetAlertImeiInfo[tgai_alertCount]." ". $inorout." ".$inout."<br>";
        //print_r($fetAlertInfo);
        /*echo "<pre>";
        		print_r($fetAlertImeiInfo);
        		//
        		echo "</pre>";*/
        //echo $fetAlertImeiInfo[tgai_id];
        //echo "<br> 1 ".$fetAlertInfo[pastTotal]." ".$fetAlertImeiInfo[tgai_alertCount]."<".$nooftime."<br>";
        if ($fetAlertImeiInfo[tgai_geoAssignId] == $aid && $fetAlertInfo[pastTotal] < $nooftime) {
            //echo "<br>".$fetAlertInfo[pastTotal]." ".$fetAlertImeiInfo[tgai_alertCount]."<".$nooftime."<br>";
            if ($fetAlertImeiInfo[tgai_inoutStatus] == 0) {
                //echo $fetAlertImeiInfo[tgai_alertCount]."<".$nooftime."<br>";
                if ($inout == 'in' && $inorout != $inout) {
                    $data['tgai_inoutStatus'] = 1;
                    $data['tgai_reachdevTime2'] = date("Y-m-d H:i:s", strtotime($devDateTime));
                    //print_r($data);
                    //exit;
                    if ($db->query_update("tb_geoalertinfo", $data, "tgai_id=" . $fetAlertImeiInfo[tgai_id])) {
                        $res = 1;
                    } else {
                        $res = 0;
                    }
                } elseif ($inout == 'out' && $inorout == $inout) {
                    $smsStatus = sendAlert($aid, $devDateTime);
                    if ($smsStatus) {
                        $data['tgai_inoutStatus'] = 1;
                        $data['tgai_reachdevTime2'] = date("Y-m-d H:i:s", strtotime($devDateTime));
                        //print_r($data);
                        //exit;
                        if ($db->query_update("tb_geoalertinfo", $data, "tgai_id=" . $fetAlertImeiInfo[tgai_id])) {
                            $res = 1;
                        } else {
                            $res = 0;
                        }
                        echo "SMS";
                    }
                }
            } else {
                //echo $fetAlertImeiInfo[tgai_alertCount]."<".$nooftime."<br>";
                //echo "<br>".$inout." ".$inorout;
                if ($inout == 'in' && $inorout == $inout) {
                    $smsStatus = sendAlert($aid, $devDateTime);
                    if ($smsStatus) {
                        $data['tgai_assignDevId'] = $devImei;
                        $data['tgai_geoAssignId'] = $aid;
                        $data['tgai_inoutStatus'] = 0;
                        $data['tgai_alertCount'] = $fetAlertInfo[tgai_alertCount] + 1;
                        $data['tgai_alertType'] = $inout;
                        $data['tgai_reachdevTime1'] = date("Y-m-d H:i:s", strtotime($devDateTime));
                        //print_r($data);
                        //exit;
                        if ($db->query_insert("tb_geoalertinfo", $data)) {
                            $res = 1;
                        } else {
                            $res = 0;
                        }
                        echo "SMS";
                    }
                } elseif ($inout == 'out' && $inorout != $inout) {
                    $data['tgai_assignDevId'] = $devImei;
                    $data['tgai_geoAssignId'] = $aid;
                    $data['tgai_inoutStatus'] = 0;
                    $data['tgai_alertCount'] = $fetAlertInfo[tgai_alertCount] + 1;
                    $data['tgai_alertType'] = $inout;
                    $data['tgai_reachdevTime1'] = date("Y-m-d H:i:s", strtotime($devDateTime));
                    //print_r($data);
                    //exit;
                    if ($db->query_insert("tb_geoalertinfo", $data)) {
                        $res = 1;
                    } else {
                        $res = 0;
                    }
                }
            }
        } elseif ($fetAlertImeiInfo[tgai_geoAssignId] != $aid && $fetAlertImeiInfo[tgai_inoutStatus] == 1 && $fetAlertInfo[tgai_alertCount] < $nooftime) {
            //print_r($fetAlertImeiInfo);
            if ($inout == 'in' && $inorout == $inout) {
                $smsStatus = sendAlert($aid, $devDateTime);
                if ($smsStatus) {
                    $data['tgai_assignDevId'] = $devImei;
                    $data['tgai_geoAssignId'] = $aid;
                    $data['tgai_inoutStatus'] = 0;
                    $data['tgai_alertCount'] = $fetAlertInfo[tgai_alertCount] + 1;
                    $data['tgai_alertType'] = $inout;
                    $data['tgai_reachdevTime1'] = date("Y-m-d H:i:s", strtotime($devDateTime));
                    //print_r($data);
                    //exit;
                    if ($db->query_insert("tb_geoalertinfo", $data)) {
                        $res = 1;
                    } else {
                        $res = 0;
                    }
                    echo "SMS";
                }
            } elseif ($inout == 'out' && $inorout != $inout) {
                $data['tgai_assignDevId'] = $devImei;
                $data['tgai_geoAssignId'] = $aid;
                $data['tgai_inoutStatus'] = 0;
                $data['tgai_alertCount'] = $fetAlertInfo[tgai_alertCount] + 1;
                $data['tgai_alertType'] = $inout;
                $data['tgai_reachdevTime1'] = date("Y-m-d H:i:s", strtotime($devDateTime));
                //print_r($data);
                //exit;
                if ($db->query_insert("tb_geoalertinfo", $data)) {
                    $res = 1;
                } else {
                    $res = 0;
                }
            }
        }
    }
}
Exemple #3
0
            $config->previousJobs[] = $guid;
            continue;
        } else {
            $foundKeyword = false;
            foreach ($keywordsToSearch as $keyword) {
                if (stripos($title . ' ' . $desc, $keyword) !== false) {
                    // TODO implement budget
                    // TODO implement location
                    echo "\nKeyword {$keyword} found!";
                    $foundKeyword = true;
                    break;
                }
            }
            if ($foundKeyword) {
                echo "\nWill alert {$currEmail} now\n";
                sendAlert($currEmail, $title, $emailBody);
                continue;
            }
        }
        $config->previousJobs[] = $guid;
    }
    // foreach item
    break;
}
// foreach queries
$config->updatePreviousJobs();
function sendAlert($emailAddress, $subjectLine, $jobInfoStr)
{
    echo <<<EOC

Would mail
Exemple #4
0
        //echo($result['id']."\n");
        array_push($plants, array($user => $result['id']));
    }
}
//print_r($plants);
foreach ($plants as $plant) {
    reset($plant);
    $uid = key($plant);
    $pid = current($plant);
    echo "THIS IS USER: {$pid}\n";
    checkStats($pid);
    $notifications = getNotifications($pid);
    $light = 'good';
    $temp = 'good';
    $moisture = 'good';
    foreach ($notifications as $notif) {
        reset($notif);
        switch (key($notif)) {
            case 'light':
                $light = current($notif);
                break;
            case 'temp':
                $temp = current($notif);
                break;
            case 'moisture':
                $moisture = current($notif);
                break;
        }
    }
    sendAlert($uid, $pid, $light, $temp, $moisture);
}
                        print "Could not creat lock file {$filename}";
                    } else {
                        fwrite($mylock, "Locked");
                        fclose($mylock);
                    }
                }
            }
            print "\n";
        } else {
            print ": NO TEMPS AVAILABLE. ERROR. ";
            // Check for a lockfile
            $filename = $label . ".lock";
            if (file_exists($filename)) {
                print " Lock file detected. No alert sent.";
            } else {
                sendAlert($result, $threshold, $db_name, $label, $graphname[$receiver], $contactfile);
                $mylock = fopen($filename, "w");
                if ($mylock == false) {
                    print "Could not create lock file {$filename}";
                } else {
                    fwrite($mylock, "Locked");
                    fclose($mylock);
                }
            }
            print "\n";
        }
    }
    print "\n";
}
// Make Graphs
print "Making graphs...\n";