41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: leanderschmedemann
|
|
* Date: 27/03/2017
|
|
* Time: 14:07
|
|
*/
|
|
|
|
require_once('includes.inc.php');
|
|
$data = '';
|
|
$error = 0;
|
|
$values = null;
|
|
$uid = $_GET['uid'];
|
|
$length = $_GET['length'];
|
|
$length = (($length === '0') || ($length && gettype(+$length) == 'integer')) ? +$_GET['length'] : 10;
|
|
$database = new Database();
|
|
$questions_count = $database->query('SELECT COUNT(*) FROM "Questions"')['data'][0]['count'];
|
|
|
|
function create_game($length) {
|
|
for($i = 0; $i < $length; $i++) {
|
|
do {
|
|
|
|
} while(pg_last_error != '');
|
|
}
|
|
}
|
|
|
|
if($length == 0) {
|
|
$error = 12101;
|
|
} else if($length > $questions_count) {
|
|
$error = 12102;
|
|
$values = array($questions_count);
|
|
} else {
|
|
if($database->query('SELECT EXISTS (SELECT 1 fROM "Games" WHERE "ID" = $1)', array($uid)) == 't') {
|
|
$database->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid));
|
|
}
|
|
$database->query('INSERT INTO "Games" ("ID") VALUES ($1)', array($uid));
|
|
create_game($length);
|
|
}
|
|
$response = Database::create_response($data, $error, $values);
|
|
print $response;
|
|
?>
|