Example #1
0
$sql .= " HAVING distance < " . $distance . " ";
$sql .= " AND WHERE " . $where . " ";
$sql .= " ORDER BY distance ASC";
if (isset($_GET['userlongitude']) && isset($_GET['userlatitude']) && $_GET['userlongitude'] != "" && $_GET['userlongitude'] != "0" && $_GET['userlatitude'] != "" && $_GET['userlatitude'] != "0") {
    $items = Store::get_by_sql($sql);
} else {
    $items = Store::get_by_sql("SELECT * FROM " . T_STORES . " WHERE " . $where . $sort . $limit);
}
$filename = 0;
foreach ($items as $item) {
    $item->distance = round($item->distance) > 0 ? round($item->distance) + "km" : round($item->distance / 0.001) + "m";
    $sql = "SELECT * FROM traffics WHERE storeid = " . $item->id;
    if (!isset($_GET['1hour'])) {
        $sql .= " AND " . C_TRAFFIC_DATETIME . " BETWEEN DATE_SUB(NOW(), INTERVAL 1 HOUR) AND NOW()";
    }
    $traffics = Traffic::get_by_sql($sql);
    $totaltraffics = 0;
    $lasttrafficdatetime = 0;
    if (count($traffics) > 0) {
        foreach ($traffics as $traffic) {
            $totaltraffics += $traffic->status;
        }
    }
    $item->averagestatus = true;
    $item->trafficcount = count($traffics);
    if ($item->trafficcount > 0) {
        $item->trafficlevel = $totaltraffics / $item->trafficcount;
    }
    if (count($traffics) > 0) {
        $item->lasttrafficdatetime = $traffics[count($traffics) - 1]->datetime;
    }
    if ($searchOper == 'eq') {
        $searchString = $searchString;
    }
    if ($searchOper == 'bw' || $searchOper == 'bn') {
        $searchString .= '%';
    }
    if ($searchOper == 'ew' || $searchOper == 'en') {
        $searchString = '%' . $searchString;
    }
    if ($searchOper == 'cn' || $searchOper == 'nc' || $searchOper == 'in' || $searchOper == 'ni') {
        $searchString = '%' . $searchString . '%';
    }
    $where = "{$searchField} {$ops} '{$searchString}'";
    $objects = Traffic::get_by_sql("SELECT * FROM " . T_TRAFFICS . " WHERE " . $where . " ORDER BY {$sidx} {$sord} LIMIT {$start} , {$limit}");
} else {
    $objects = Traffic::get_by_sql("SELECT * FROM " . T_TRAFFICS . " ORDER BY {$sidx} {$sord} LIMIT {$start} , {$limit}");
}
header("Content-type: text/xml;charset=utf-8");
$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>" . $page . "</page>";
$s .= "<total>" . $total_pages . "</total>";
$s .= "<records>" . $count . "</records>";
foreach ($objects as $object) {
    $s .= "<row id='" . $object->id . "'>";
    $s .= "<cell></cell>";
    $s .= "<cell>" . $object->id . "</cell>";
    $s .= "<cell>" . $object->picture . "</cell>";
    $s .= "<cell>" . $object->userid . "</cell>";
    $s .= "<cell>" . $object->storeid . "</cell>";
    $s .= "<cell>" . $object->status . "</cell>";
Example #3
0
}
if (isset($_GET['enabled'])) {
    $where .= " AND " . C_TRAFFIC_ENABLED . equallike($_GET['enabled'], "int");
}
//======================================================
if (isset($_GET['limit'])) {
    $limit = " LIMIT " . $_GET['limit'] . " ";
}
if (isset($_GET['sortby']) && isset($_GET['sortorder'])) {
    $sort = " ORDER BY " . $_GET['sortby'] . " " . $_GET['sortorder'] . " ";
}
if (isset($_GET['sortby']) && !isset($_GET['sortorder'])) {
    $sort = " ORDER BY " . $_GET['sortby'] . $sortorder . " ";
}
//======================================================
$items = Traffic::get_by_sql("SELECT * FROM " . T_TRAFFICS . " WHERE " . $where . $sort . $limit);
$filename = 0;
if (!isset($_GET['blob'])) {
    foreach ($items as $item) {
        $filename++;
        $random = rand(0, 1);
        file_put_contents("images/" . $filename . "x" . $random . ".jpg", base64_decode($item->picture));
        $item->picture = HOST . "includes/webservices/images/" . $filename . "x" . $random . ".jpg";
    }
}
echo str_replace('\\/', '/', json_encode($items));
//echo json_encode($items, JSON_UNESCAPED_SLASHES);
function equallike($field, $type)
{
    $string = "";
    if ($type == "string") {