예제 #1
0
function context_activate_ext($id, $timeout = 0, $timeout_code = '', $timeout_context_id = 0)
{
    $user_id = context_getuser();
    $user = SQLSelectOne("SELECT * FROM users WHERE ID='" . (int) $user_id . "'");
    $user['ACTIVE_CONTEXT_ID'] = $id;
    if ($id) {
        $user['ACTIVE_CONTEXT_EXTERNAL'] = 1;
    } else {
        $user['ACTIVE_CONTEXT_EXTERNAL'] = 0;
    }
    $user['ACTIVE_CONTEXT_UPDATED'] = date('Y-m-d H:i:s');
    DebMes("setting external context: " . $id);
    SQLUpdate('users', $user);
    if ($id) {
        //execute pattern
        if (!$timeout) {
            $timeout = 60;
        }
        $ev = '';
        if ($timeout_code) {
            $ev .= $timeout_code;
        }
        if ($timeout_context_id) {
            $ev .= "context_activate_ext(" . (int) $timeout_context_id . ");";
        } else {
            $ev .= "context_clear();";
        }
        setTimeOut('user_' . $user_id . '_contexttimeout', $ev, $timeout);
    } else {
        context_clear();
        clearTimeOut('user_' . $user_id . '_contexttimeout');
    }
}
예제 #2
0
파일: gps.php 프로젝트: cdkisa/majordomo
     $user = SQLSelectOne($sqlQuery);
     if ($user['LINKED_OBJECT']) {
         setGlobal($user['LINKED_OBJECT'] . '.Coordinates', $rec['LAT'] . ',' . $rec['LON']);
         setGlobal($user['LINKED_OBJECT'] . '.CoordinatesUpdated', date('H:i'));
         setGlobal($user['LINKED_OBJECT'] . '.CoordinatesUpdatedTimestamp', time());
         setGlobal($user['LINKED_OBJECT'] . '.BattLevel', $rec['BATTLEVEL']);
         setGlobal($user['LINKED_OBJECT'] . '.Charging', $rec['CHARGING']);
         $sqlQuery = "SELECT *\n                        FROM gpslog\n                       WHERE ID        != '" . $rec['ID'] . "'\n                         AND DEVICE_ID = '" . $device['ID'] . "'\n                       ORDER BY ID DESC\n                       LIMIT 1";
         $prev_log = SQLSelectOne($sqlQuery);
         if ($prev_log['ID']) {
             $distance = calculateTheDistance($rec['LAT'], $rec['LON'], $prev_log['LAT'], $prev_log['LON']);
             if ($distance > 100) {
                 //we're moving
                 $objectIsMoving = $user['LINKED_OBJECT'] . '.isMoving';
                 setGlobal($objectIsMoving, 1);
                 clearTimeOut($user['LINKED_OBJECT'] . '_moving');
                 // stopped after 15 minutes of inactivity
                 setTimeOut($user['LINKED_OBJECT'] . '_moving', "setGlobal('" . $objectIsMoving . "', 0);", 15 * 60);
             }
         }
     }
 }
 // checking locations
 $lat = (double) $_REQUEST['latitude'];
 $lon = (double) $_REQUEST['longitude'];
 $locations = SQLSelect("SELECT * FROM gpslocations");
 $total = count($locations);
 $location_found = 0;
 for ($i = 0; $i < $total; $i++) {
     if (!$locations[$i]['RANGE']) {
         $locations[$i]['RANGE'] = GPS_LOCATION_RANGE_DEFAULT;
예제 #3
0
/**
* Title
*
* Description
*
* @access public
*/
function setTimeOut($title, $commands, $timeout)
{
    clearTimeOut($title);
    return addScheduledJob($title, $commands, time() + $timeout);
}