T201704040053

This commit is contained in:
Leander
2017-04-04 00:53:29 +02:00
parent 55aff9f0e4
commit d72bf7fd36
3 changed files with 36 additions and 10 deletions

View File

@@ -14,3 +14,8 @@
12102 - 0 questions wanted, no game without a question! 12102 - 0 questions wanted, no game without a question!
12103 - More questions wanted then existing 12103 - More questions wanted then existing
12104 - User name not existing 12104 - User name not existing
= answer.php =
13101 - User ID not specified
13102 - No valid time specified
13103 - No chosen answer specified

View File

@@ -60,14 +60,18 @@ class Database
return 'User name does not match rules. User name must be 6 to 20 characters and consist of English letters and numbers only.'; return 'User name does not match rules. User name must be 6 to 20 characters and consist of English letters and numbers only.';
case 11102: case 11102:
return 'User name already exists. Please pick a different name.'; return 'User name already exists. Please pick a different name.';
case 12101: case 12101 || 13101:
return 'User name not specified. This is an internal error.'; return 'User ID not specified. This is an internal error.';
case 12102: case 12102:
return 'A game without a question is not possible. Please select new game length.'; return 'A game without a question is not possible. Please select new game length.';
case 12103: case 12103:
return 'Sorry, we only have '.$values[0].' questions. Please try again.'; return 'Sorry, we only have '.$values[0].' questions. Please try again.';
case 12104: case 12104:
return 'The specified user name does not exist.'; return 'The specified user name does not exist. This is an internal error.';
case 13102:
return 'No valid time specified. This is an internal error.';
case 13103:
return 'No chosen answer specified. This is an internal error.';
default: default:
return 'An unknown error occurred.'; return 'An unknown error occurred.';
} }

View File

@@ -9,18 +9,35 @@
require_once('includes.inc.php'); require_once('includes.inc.php');
$data = ''; $data = '';
$error = 0; $error = 0;
$user = isset($_GET['uid']) ? $_GET['uid'] : ''; $uid = isset($_GET['uid']) ? $_GET['uid'] : '';
$time = isset($_GET['time']) ? $_GET['time'] : ''; $time = isset($_GET['time']) ? $_GET['time'] : '';
$time = (($time === '0') || ($time && gettype(+$time) == 'integer')) ? +$_GET['time'] : 0; $time = (($time === '0') || ($time && gettype(+$time) == 'integer')) ? +$_GET['time'] : 0;
$answer = isset($_GET['answer']) ? $_GET['answer'] : ''; $db = new Database();
$answer = (($answer === '0') || ($answer && gettype(+$answer) == 'integer')) ? +$_GET['answer'] : -1; $chosen_answer = isset($_GET['answer']) ? $_GET['answer'] : '';
$chosen_answer = (($chosen_answer === '0') || ($chosen_answer && gettype(+$chosen_answer) == 'integer')) ? +$_GET['answer'] : -1;
function calculate_points($time) { function calculate_points($time) {
$points = $time < 2000 ? 100 : 141.1421 - 0.02842916 * $time + 0.000004132312 * pow($time, 2)
- 3.432331e-10 * pow($time, 3) + 1.391508e-14 * pow($time, 4) - 2.166078e-19 * pow($time, 5);
$points = $points < 10 ? 10 : intval($points);
return $points;
} }
//if user is ''... if($uid == '') {
//if time is 0... $error = 13101;
//if answer is -1... } else if($time == 0) {
$error = 13102;
} else if($chosen_answer == -1) {
$error = 13103;
} else {
$correct_answer = $db->query('SELECT "current_right_answer" FROM "Games" WHERE "ID" = $1', array($uid))
['data'][0]['current_right_answer'];
$correct = $correct_answer == $chosen_answer ? true : false;
$score = $correct_answer == $chosen_answer ? calculate_points($time) : 0;
}
$results = array('correct' => $correct, 'score', $score);
$next_question = Question::get_next_question($db, $uid);
$data = array('results' => $results, 'next' => $next_question);
?> ?>