summaryrefslogtreecommitdiff
path: root/app/v1_php/api/game
diff options
context:
space:
mode:
Diffstat (limited to 'app/v1_php/api/game')
-rw-r--r--app/v1_php/api/game/form.html22
-rw-r--r--app/v1_php/api/game/index.php28
2 files changed, 36 insertions, 14 deletions
diff --git a/app/v1_php/api/game/form.html b/app/v1_php/api/game/form.html
new file mode 100644
index 0000000..ed4ad72
--- /dev/null
+++ b/app/v1_php/api/game/form.html
@@ -0,0 +1,22 @@
+<html>
+<head>
+</head>
+
+<body>
+<form method="POST" action="index.php">
+ <div class="form_line">
+ <label name="authentication_key">authentication_key</label>
+ <input type="text" name="authentication_key" value="azertyuiop" />
+ </div>
+ <div class="form_line">
+ <label name="parameters">parameters</label>
+ <textarea rows="10" cols="80" name="parameters">
+{ "longpollingduration" : "60", "nbusersthreshold" : "2", "questiontimeframe" : "10", "nbquestions" : "20", "flushusertable" : "true" }
+ </textarea>
+ </div>
+ <div class="form_line">
+ <input type="submit" />
+ </div>
+</form>
+</body>
+</html>
diff --git a/app/v1_php/api/game/index.php b/app/v1_php/api/game/index.php
index a8658ac..154d905 100644
--- a/app/v1_php/api/game/index.php
+++ b/app/v1_php/api/game/index.php
@@ -2,7 +2,6 @@
/*
Table Game
-Unique key :
*/
require_once("../mysql_connect.inc.php");
@@ -10,14 +9,14 @@ require_once("../mysql_connect.inc.php");
$authentication_key=$_POST['authentication_key'];
if ($authentication_key !== "azertyuiop") {
- // header 401, "Clé d'authentification non reconnue"
- echo "401, Clé d'authentification non reconnue\n";
+ header("Clé d'authentification non reconnue", true, 401);
+ exit();
}
-$parameters=json_decode($_POST['parameters']);
+$parameters=json_decode($_POST['parameters'], true);
if ( !is_array($parameters) || !is_numeric($parameters['longpollingduration']) ){
- // header 400, "Erreur"
- echo "header 400, Erreur paramètres\n";
+ header("Erreur paramètres", true, 400);
+ exit();
}
$longpollingduration=$parameters['longpollingduration'];
@@ -26,19 +25,20 @@ $questiontimeframe=$parameters['questiontimeframe'];
$nbquestions=$parameters['nbquestions'];
if ( $parameters['flushusertable'] === "true" ) {
- $req="TRUNCATE TABLE User;"
- $res=mysql_query($req);
+ $req="TRUNCATE TABLE User;";
+ mysql_query($req);
//TODO check result
}
-$req="INSERT INTO Game (NULL, $longpollingduration, $nbusersthreshold, $questiontimeframe, $nbquestions)";
+$req="INSERT INTO Game VALUES (NULL, $longpollingduration, $nbusersthreshold, $questiontimeframe, $nbquestions)";
$res=mysql_query($req);
-if ( mysql_num_rows() === 1 ) {
- //TODO header 201, "OK : CREATED"
- echo "header 201, OK : CREATED\n";
+
+echo mysql_error();
+
+if ( $res===true && mysql_affected_rows() === 1 ) {
+ header("OK : CREATED", true, 201);
} else {
- // header 400, "Erreur"
- echo "header 400, Erreur insertion SQL\n";
+ header("erreur", true, 400);
}
?>