Example #1
0
<?php

namespace u311\carexperiment\ctrl;

include_once __DIR__ . '/../../../vendor/autoload.php';
use u311\carexperiment\ctrl\GameDataCtrl;
use u311\carexperiment\view\JSONMessageSender;
session_start();
/* @var $msg_sender JSONMessageSender. Sends JSON encdoded text to the client*/
$msg_sender = new JSONMessageSender();
$stats = null;
try {
    //Create the datahandler and insert the data
    /* @var $game_data_ctrl GameDataCtrl */
    $game_data_ctrl = new GameDataCtrl();
    /*
     * Call the $game_data_ctrl to save the data passed from the client
     */
    $stats = $game_data_ctrl->getSystemStats();
} catch (Exception $e) {
    $err_msg = "Operation failed: Error code " . $e->getMessage();
    /*
     * By convention, code = 0 means that this is non-system error.
     * In this case we can display the message text itself. 
     */
    if ($e->getCode() == 0) {
        $err_msg = "Operation failed: " . $e->getMessage();
    }
    $msg_sender->onError(null, $err_msg);
}
/*
Example #2
0
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace u311\carexperiment\ctrl;

include_once __DIR__ . '/../../../vendor/autoload.php';
use u311\carexperiment\view\JSONMessageSender;
use u311\carexperiment\ctrl\GameDataCtrl;
session_start();
/* @var $msg_sender JSONMessageSender. Sends JSON encdoded text to the client*/
$msg_sender = new JSONMessageSender();
/**
 * Expected POST values
 * action=1&state=1
 */
$action = null;
$state = null;
$user_id = null;
if (!isset($_SESSION['user_id'])) {
    $msg_sender->onError(null, "User not logged in.");
}
$user_id = $_SESSION['user_id'];
//Check the $_POST['action']
$score = filter_input(INPUT_POST, 'score');
if (is_null($score)) {
    $msg_sender->onError(null, "Score missing");
}
Example #3
0
<?php

namespace u311\carexperiment\ctrl;

include_once __DIR__ . '/../../../vendor/autoload.php';
/*
 * Change log.
 * 2/21/15 Added check if a user is logged in through $_SESSION
 */
use u311\carexperiment\view\JSONMessageSender;
use u311\carexperiment\ctrl\GameDataCtrl;
session_start();
/* @var $msg_sender JSONMessageSender. Sends JSON encdoded text to the client*/
$msg_sender = new JSONMessageSender();
/**
 * Expected POST values
 * action=1&state=1
 */
$action = null;
$state = null;
$user_id = null;
if (!isset($_SESSION['user_id'])) {
    $msg_sender->onError(null, "User not logged in.");
}
$user_id = $_SESSION['user_id'];
try {
    //Create the datahandler and insert the data
    /* @var $game_data_ctrl GameDataCtrl */
    $game_data_ctrl = new GameDataCtrl();
    /*
     * Call the $game_data_ctrl to save the data passed from the client
Example #4
0
<?php

namespace u311\carexperiment\ctrl;

include_once __DIR__ . '/../../../vendor/autoload.php';
use u311\carexperiment\view\JSONMessageSender;
use u311\carexperiment\ctrl\GameDataCtrl;
session_start();
/* @var $msg_sender JSONMessageSender. Sends JSON encdoded text to the client*/
$msg_sender = new JSONMessageSender();
if (isset($_POST['popup'])) {
    $popup = $_POST['popup'];
    $_SESSION['show_popup'] = $popup;
}
/*
 * No error, Send reponseo with OK message.
 */
$msg_sender->onResult(null, 'OK');
Example #5
0
<?php

namespace u311\carexperiment\ctrl;

include_once __DIR__ . '/../../../vendor/autoload.php';
/*
 * Change log.
 * 2/21/15 Added check if a user is logged in through $_SESSION
 */
use u311\carexperiment\view\JSONMessageSender;
use u311\carexperiment\ctrl\GameDataCtrl;
session_start();
/* @var $msg_sender JSONMessageSender. Sends JSON encdoded text to the client*/
$msg_sender = new JSONMessageSender();
/**
 * Expected POST values
 * action=1&state=1
 */
$action = null;
$state = null;
$user_id = null;
if (!isset($_SESSION['user_id'])) {
    $msg_sender->onError(null, "User not logged in.");
}
$user_id = $_SESSION['user_id'];
//Check the $_POST['action']
if (isset($_POST['action']) && !empty($_POST['action'])) {
    $action = $_POST['action'];
} else {
    $msg_sender->onError(null, "Action missing");
}