From b54487ae821da5e7574bf2135b90d0669b30b181 Mon Sep 17 00:00:00 2001
From: Ludovic Pouzenc <ludovic@pouzenc.fr>
Date: Sat, 22 Jan 2011 10:52:39 +0000
Subject: Ajout du code fait par ludo dans le métro pour commencer à vraiment
 intégrer les specs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

git-svn-id: file:///var/svn/2011-usi/trunk@6 db941bf7-0cb3-4dda-9634-87faf64f93a7
---
 app/v1_php/api/game/index.php        | 44 ++++++++++++++++++++++++++++++++++++
 app/v1_php/api/mysql_connect.inc.php | 11 +++++++++
 app/v1_php/api/user/form.html        | 28 +++++++++++++++++++++++
 app/v1_php/api/user/index.php        | 25 ++++++++++++++++++++
 4 files changed, 108 insertions(+)
 create mode 100644 app/v1_php/api/game/index.php
 create mode 100644 app/v1_php/api/mysql_connect.inc.php
 create mode 100644 app/v1_php/api/user/form.html
 create mode 100644 app/v1_php/api/user/index.php

(limited to 'app/v1_php/api')

diff --git a/app/v1_php/api/game/index.php b/app/v1_php/api/game/index.php
new file mode 100644
index 0000000..a8658ac
--- /dev/null
+++ b/app/v1_php/api/game/index.php
@@ -0,0 +1,44 @@
+<?php
+
+/*
+Table Game 
+Unique key : 
+*/
+
+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";
+}
+
+$parameters=json_decode($_POST['parameters']);
+if ( !is_array($parameters) || !is_numeric($parameters['longpollingduration']) ){
+	// header 400, "Erreur"
+	echo "header 400, Erreur paramètres\n";
+}
+
+$longpollingduration=$parameters['longpollingduration'];
+$nbusersthreshold=$parameters['nbusersthreshold'];
+$questiontimeframe=$parameters['questiontimeframe'];
+$nbquestions=$parameters['nbquestions'];
+
+if ( $parameters['flushusertable'] === "true" ) {
+	$req="TRUNCATE TABLE User;"
+	$res=mysql_query($req);
+	//TODO check result
+}
+
+$req="INSERT INTO Game (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";
+} else {
+	// header 400, "Erreur"
+	echo "header 400, Erreur insertion SQL\n";
+}
+?>
diff --git a/app/v1_php/api/mysql_connect.inc.php b/app/v1_php/api/mysql_connect.inc.php
new file mode 100644
index 0000000..0414480
--- /dev/null
+++ b/app/v1_php/api/mysql_connect.inc.php
@@ -0,0 +1,11 @@
+<?php
+
+$mysqlcon=mysql_connect("localhost", "usi2011", "usi2011");
+$res=mysql_select_db("usi2011");
+
+if ( ! is_resource($mysqlcon) || $res !== 0) {
+	//header 400, Erreur connexion SQL
+	echo "Erreur connexion SQL\n";
+	exit();
+}
+?>
diff --git a/app/v1_php/api/user/form.html b/app/v1_php/api/user/form.html
new file mode 100644
index 0000000..a01d2dd
--- /dev/null
+++ b/app/v1_php/api/user/form.html
@@ -0,0 +1,28 @@
+<html>
+<head>
+</head>
+
+<body>
+<form method="POST">
+	<div class="form_line">
+		<label name="firstname">firstname</label>
+		<input type="text" name="firstname"></input>
+	</div>
+	<div class="form_line">
+		<label name="lastname">lastname</label>
+		<input type="text" name="lastname"></input>
+	</div>
+	<div class="form_line">
+		<label name="mail">mail</label>
+		<input type="text" name="mail"></input>
+	</div>
+	<div class="form_line">
+		<label name="password">password</label>
+		<input type="text" name="password"></input>
+	</div>
+	<div class="form_line">
+		<input type="submit" />
+	</div>
+</form>
+</body>
+</html>
diff --git a/app/v1_php/api/user/index.php b/app/v1_php/api/user/index.php
new file mode 100644
index 0000000..495bd2a
--- /dev/null
+++ b/app/v1_php/api/user/index.php
@@ -0,0 +1,25 @@
+<?php
+
+/*
+Table User : id, firstname, lastname, mail, password
+Unique key : mail
+*/
+
+require_once("../mysql_connect.inc.php");
+
+$firstname=mysql_real_escape_string($_POST['firstname']);
+$lastname=mysql_real_escape_string($_POST['lastname']);
+$mail=mysql_real_escape_string($_POST['mail']);
+$password=mysql_real_escape_string($_POST['password']);
+
+$req="INSERT INTO User (NULL,'$firstname', '$lastname', '$mail', '$password')";
+$res=mysql_query($req);
+
+if ( mysql_num_rows() === 1 ) {
+	//TODO header 201, "OK : CREATED"
+	echo "header 201, OK : CREATED\n";
+} else {
+	// header 400, "Erreur"
+	echo "header 400, Erreur\n";
+}
+?>
-- 
cgit v1.2.3