T201704210853

This commit is contained in:
Leander
2017-04-21 08:53:17 +02:00
parent 8537240770
commit 7981dac12a
4 changed files with 14 additions and 2 deletions

View File

@@ -12,9 +12,10 @@ $error = 0;
$uid = isset($_GET['uid']) ? $_GET['uid'] : '';
$time = isset($_GET['time']) ? $_GET['time'] : '';
$time = (($time === '0') || ($time && gettype(+$time) == 'integer')) ? +$_GET['time'] : 0;
$db = new Database();
$chosen_answer = isset($_GET['answer']) ? $_GET['answer'] : '';
$chosen_answer = (($chosen_answer === '0') || ($chosen_answer && gettype(+$chosen_answer) == 'integer')) ? +$_GET['answer'] : -1;
$token = isset($_GET['token']) ? $_GET['token'] : '';
$db = new Database();
function calculate_points($time) {
$points = 0;
@@ -33,6 +34,8 @@ function calculate_points($time) {
$correct_answer = $db->query('SELECT "current_right_answer" FROM "Games" WHERE "ID" = $1', array($uid))
['data'][0]['current_right_answer'];
$correct_token = $db->query('SELECT "current_token" FROM "Games" WHERE "ID" = $1', array($uid))
['data'][0]['current_token'];
$correct = $correct_answer == $chosen_answer ? true : false;
$score = $correct_answer == $chosen_answer ? calculate_points($time) : 0;
if($uid == '') {
@@ -44,6 +47,8 @@ if($uid == '') {
} else if($db->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid))
['data'][0]['exists'] == 'f') {
$error = 13104;
} else if($token != $correct_token) {
$error = 13105;
} else {
//set time and points
$old_q_count = $db->query('SELECT "answered_questions" FROM "Games" WHERE "ID" = $1',