<?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); } /*
$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 */ $performance = $game_data_ctrl->get_performance(); } 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); }
if (isset($_POST[$fname])) { $field->setValue($_POST[$fname]); } } /* @var $validator FormValidator */ $validator = new FormValidator($fields); /* @var $errors array of validation errors NAME=>VALUE pairs */ $errors = $validator->validate(); if (!empty($errors)) { $_SESSION['form_err'] = "Please correct errors below"; $_SESSION['f_errs'] = $errors; $url = $router->getDestination('survey'); header('Location: ' . $url); exit; } $data_crl = new GameDataCtrl(); try { $data_crl->recordSuveyResult($fields, $user_id); } catch (\Exception $ex) { $_SESSION['form_err'] = "Error writing to the database: " . $ex->getMessage(); $url = $router->getDestination('survey6'); header('Location: ' . $url); exit; } foreach ($fields as $field) { $fname = $field->getName(); if (strcmp($fname, "Q3") == 0) { $fval = $field->getValue(); if (strcmp($fval, "Yes") == 0) { $_SESSION['show_popup'] = 1; } elseif (strcmp($fval, "Half") == 0) {
//Check the $_POST['action'] if (isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; } else { $msg_sender->onError(null, "Action missing"); } //Check the $_POST['state'] if (isset($_POST['state']) && !empty($_POST['state'])) { $state = $_POST['state']; } else { $msg_sender->onError(null, "Game state missing"); } 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 */ $game_data_ctrl->recordSurveyClick($user_id, $action, $state); } 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); }