Example #1
0
     $response = array("version" => $version, "response" => $jobs);
     echo json_encode($response);
 } elseif ('equipments' == $_GET['uri'] && isset($_GET['id'])) {
     send_headers();
     $equipment = get_equipment_by_id($_GET['id']);
     $response = array("version" => $version, "response" => $equipment);
     echo json_encode($response);
 } elseif ('equipments' == $_GET['uri']) {
     send_headers();
     $equipments = get_all_equipments();
     echo json_encode($equipments);
 } elseif ('coffees' == $_GET['uri'] && isset($_GET['id'])) {
     // This is a payment request
     $user = get_user_by_uid($_GET['id']);
     if ($user && $_SERVER['REQUEST_METHOD'] == 'GET') {
         $coffees_user_today = get_coffees_today_by_uid($user['uid']);
         $coffees_user_month = get_coffees_this_month_by_uid($user['uid']);
         $coffees = array("today" => intval($coffees_user_today), "this_month" => intval($coffees_user_month));
         send_headers();
         $response = array("version" => $version, "response" => "OK", "uid" => $user['uid'], "balance" => floatval($user['balance']), "coffees" => $coffees);
         echo json_encode($response);
     } else {
         if ($user) {
             $order = array();
             $order['client'] = $user['uid'];
             $order['snack_2'] = 1;
             new_order($order);
             // get the new user balance
             $user = get_user_by_uid($user['uid']);
             send_headers();
             $response = array("version" => $version, "response" => "OK", "uid" => $user['uid'], "balance" => floatval($user['balance']));
Example #2
0
function stats_json_action($uid)
{
    header('Content-type: application/json; charset=utf-8');
    header("Cache-Control: no-cache, must-revalidate");
    $user = get_user_by_uid($uid);
    $coffees_user_today = get_coffees_today_by_uid($user['uid']);
    $coffees_user_month = get_coffees_this_month_by_uid($user['uid']);
    $money_user_today = get_money_spent_today_by_uid($user['uid']);
    $money_user_month = get_money_spent_this_month_by_uid($user['uid']);
    $json = array("coffees_user_today" => $coffees_user_today, "coffees_user_month" => $coffees_user_month, "money_user_today" => $money_user_today, "money_user_month" => $money_user_month);
    echo json_encode($json);
}