Esempio n. 1
0
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
/*
 * API_NAME: Calculate events after some id
 * API_DESCRIPTION: Method for calculate last events
 * API_ACCESS: all
 * API_INPUT: id - integer, after this id will be calculate count of events
 * API_INPUT: type - string, filter by type
 */
$curdir_events_count = dirname(__FILE__);
include_once $curdir_events_count . "/../api.lib/api.base.php";
include_once $curdir_events_count . "/../api.lib/api.security.php";
include_once $curdir_events_count . "/../api.lib/api.helpers.php";
include_once $curdir_events_count . "/../../config/config.php";
$response = APIHelpers::startpage($config);
$conn = APIHelpers::createConnection($config);
if (!APIHelpers::issetParam('id')) {
    APIHelpers::showerror(1225, 'Not found parameter "id"');
}
$type = APIHelpers::getParam('type', '');
$id = APIHelpers::getParam('id', 0);
if (!is_numeric($id)) {
    APIHelpers::showerror(1226, 'id must be integer');
}
try {
    $params = array();
    $params[] = $id;
    $query = 'SELECT count(*) as cnt FROM public_events WHERE id > ?';
    if ($type != '') {
        $query .= ' AND type = ?';
        $params[] = $type;
Esempio n. 2
0
 static function startpage($config)
 {
     header("Access-Control-Allow-Origin: *");
     header('Content-Type: application/json');
     APIHelpers::$TIMESTART = microtime(true);
     $issetToken = APIHelpers::issetParam('token');
     if ($issetToken) {
         APIHelpers::$TOKEN = APIHelpers::getParam('token', '');
         $conn = APIHelpers::createConnection($config);
         try {
             $stmt = $conn->prepare('SELECT data FROM users_tokens WHERE token = ? AND status = ? AND end_date > NOW()');
             $stmt->execute(array(APIHelpers::$TOKEN, 'active'));
             if ($row = $stmt->fetch()) {
                 APIHelpers::$FHQSESSION = json_decode($row['data'], true);
                 APIHelpers::$FHQSESSION_ORIG = json_decode($row['data'], true);
             }
         } catch (PDOException $e) {
             APIHelpers::showerror(1188, $e->getMessage());
         }
     } else {
         APIHelpers::$FHQSESSION = $_SESSION;
         APIHelpers::$FHQSESSION_ORIG = $_SESSION;
     }
     $response = array('result' => 'fail', 'lead_time_sec' => 0, 'data' => array());
     return $response;
 }