commit 7ed8a078caa64dfe165528dea14fe120ff04fbf6
parent 637dccaaa822200baa976a162e5005355cc2e253
Author: Yoann <yoann.b87@voila.fr>
Date: Sun, 17 Apr 2011 18:12:26 +0200
Reprise du code php et ajout de la vérification d'autentification avant
de pouvoir créer un partie.
Diffstat:
4 files changed, 131 insertions(+), 398 deletions(-)
diff --git a/code/serveur/php/createGame.php b/code/serveur/php/createGame.php
@@ -1,271 +1,158 @@
<?php
require_once("ressources/strings.inc");
require_once("relations.php");
-require_once("pticlic.php");
+require_once("server.php");
session_start();
-$state = 0;
-$err = false;
-$msg = "";
-$rels = array();
-
-function getWords($nbwords)
-{
- global $msg;
- global $err;
- $words = array();
-
- for($i = 0; $i < $nbwords; $i++)
- if(!isset($_POST['word'.$i]) || empty($_POST['word'.$i])) {
- $err = true;
- $msg = $strings['err_creategame_fill_all'];
- return -1;
- }
- else
- $words[$i] = $_POST['word'.$i];
-
- return $words;
-}
-
-function getWordsAndResponses($nbwords)
-{
- global $err;
- global $msg;
- $words = array();
- $respwords = array();
+if(!isset($_SESSION['userId']))
+ header("location:login.php?return=createGame&showmsg=oth_login_createGame_nauth");
- $words = getWords($nbwords);
-
- if($words == -1)
- return -1;
+?>
- foreach($words as $key=>$w) {
- if(isset($_POST['rd'.$key])) {
- $respwords[$key] = array();
- $respwords[$key][0] = $words[$key];
- $respwords[$key][1] = $_POST['rd'.$key];
- }
- else
- return -1;
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
+ <head>
+ <title>PtiClic Android - Création de partie</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" href="ressources/simple.css" />
+ <script type="text/javascript" src="ressources/jquery-1.5.1.min.js" /></script>
+ <script type="text/javascript" src="ressources/createGame.js" /></script>
+<style type="text/css">
+ #wordLines input{
+ border : 2px solid grey;
}
-
- return $respwords;
-}
-
-function checked($name, $value) {
- if(isset($_POST[$name]) && $_POST[$name] == $value)
- return 'checked';
-}
-
-function probaOf($relation, $relation2) {
- if (($relation == "r1" && $relation2 == 0)
- || ($relation == "r2" && $relation2 == 1)
- || ($relation == "r0" && $relation2 == 2)
- || ($relation == "trash" && $relation2 == 3))
- return 1;
-
- return 0;
-}
-
-if(isset($_POST['nbcloudwords'])) {
- $nbwords = $_POST['nbcloudwords'];
-
- if(!is_numeric($nbwords) || $nbwords <= 0) {
- $err = true;
- $msg = $strings['err_creategame_nbwords_value'];
+ .status {
+ visibility: hidden;
+ }
+ .valid .status, #center.valid .status {
+ color: green;
+ visibility: visible;
}
- else {
- $state = 1;
- $relations = get_game_relations();
+ .invalid .status, #center.invalid .status, #center .status {
+ color: red;
+ visibility: visible;
}
- if($state == 1 && isset($_POST['centralword']) && !empty($_POST['centralword'])) {
- if($_POST['relation1'] != $_POST['relation2']) {
- $centralword = $_POST['centralword'];
- $rels[0] = $stringRelations[$_POST['relation1']];
- $rels[1] = $stringRelations[$_POST['relation2']];
- $rels[2] = $stringRelations[0];
- $rels[3] = $stringRelations[-1];
-
- $words = getWords($nbwords);
-
- if($err != true)
- $state = 2;
- else {
- $err = true;
- $msg = $strings['err_creategame_cloud_fill_all'];
- }
-
- }
- else {
- $err = true;
- $msg = $strings['err_creategame_eq_relations'];
- }
+ .wordLinesTable {
+ min-height : 20px;
+ min-width : 20px;
+ border-collapse : collapse;
+ border-spacing : 0px;
+ margin-left : 30px;
}
- elseif (isset($_POST['centralword']) && empty($_POST['centralword'])) {
- $err = true;
- $msg = $strings['err_creategame_cloud_fill_all'];
+
+ .wordLinesTable td {
+ padding : 6px;
+ padding-left : 10px;
}
- if($state == 2) {
- $respwords = getWordsAndResponses($nbwords);
- $r1 = $_POST['relation1'];
- $r2 = $_POST['relation2'];
- $cloud = array();
- $totalDifficulty = 0;
- $addedWords = 0;
-
- if($respwords != -1 && isset($_POST['tDifficulty'])) {
- if(is_numeric($totalDifficulty = $_POST['tDifficulty'])) {
-
- if(insertNode($centralword))
- $addedWords++;
-
- $centralword = getNodeEid($centralword);
-
- foreach($respwords as $key=>$rw) {
- $difficulty = $totalDifficulty / count($respwords);
-
- if(insertNode($respwords[$key][0]))
- $addedWords++;
-
- $cloud[$key] = array('pos'=>$key, 'd'=> $difficulty, 'eid'=>getNodeEid($respwords[$key][0]),
- 'probaR1'=> probaOf("r1", $rw[1]),
- 'probaR2'=> probaOf('r2', $rw[1]),
- 'probaR0'=> probaOf('r0', $rw[1]),
- 'probaTrash'=> probaOf('trash', $rw[1]));
- }
- }
- else {
- $err = true;
- $msg = $strings['err_creategame_isNumeric_tDifficulty'];
- }
+ .wordLinesTable .lightLine {
+ background-color : #F0F0D0;
+ }
- $state = 3;
- $msg = $strings['ok_creategame_game_create'];
- }
- cgInsert($centralword, $cloud, $r1, $r2, $totalDifficulty);
+ #center {
+ margin-left : 100px;
+ margin-top : 20px;
+ margin-bottom : 30px;
}
- elseif($state == 2) {
- $err = true;
- $msg = $strings['err_creategame_fill_all'];
+
+ #center label {
+ border-bottom : 1px solid grey;
+ border-left : 1px solid grey;
+ -moz-border-radius : 100%;
+ padding-left : 10px;
}
-}
-else
- $err = true;
-
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
- <head>
- <title>PtiClic Android - Création de partie</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <link rel="stylesheet" href="ressources/simple.css" />
+
+ #relations {
+ margin-bottom : 20px;
+ margin-top : 10px;
+ }
+
+ #relations label {
+ margin-left : 40px;
+ border-bottom : 1px solid grey;
+ border-left : 1px solid grey;
+ -moz-border-radius : 100%;
+ padding-left : 10px;
+ padding-right : 10px;
+ }
+
+ #button {
+ margin-top : 30px;
+ margin-left : 50px;
+ margin-bottom : 40px;
+ }
+
+ #button input {
+ margin-left : 10px;
+ margin-right : 40px;
+ padding : 4px;
+ padding-left : 8px;
+ padding-right : 8px;
+ font-weight : bold;
+ }
+
+</style>
</head>
<body>
<?php include("ressources/menu.inc"); ?>
<div class="content creategame">
<h2>Création de parties</h2>
- <?php
- if(isset($_POST['nbcloudwords']) && $_POST['nbcloudwords'] > 0)
- echo '<p>Remplissez le mot central ainsi que les différents mots du nuage pour réaliser un partie personalisée.<br />
- Une fois satisfait de votre partie cliquez sur "Enregistrer la partie"';
- else
- echo '<p>Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.<br /><br />
- Veuillez entrer le nombre de mots composant le nuage dans le formulaire ci-dessous avant de continuer.</p><br />';
- ?>
- <form action="createGame.php" method="POST">
- <?php
- if($err == true && $msg != "")
- echo '<span class="message warning">'.$msg.'</span>';
- else if ($msg != "")
- echo '<span class="message success">'.$msg.'</span>';
-
- if($state == 0) {
- echo '<table>';
- echo '<tr><td><label for="nbcloudwords"> Nombre de mots du nuage : </label></td>';
- echo '<td><input type="text" name="nbcloudwords" /></td></tr>';
- echo '<tr><td></td><td><input type="submit" value="suivant" /></td></tr>';
- }
- elseif($state == 1) {
- echo '<table class="wordsform">';
- echo '<tr><td><label for="relation1">Relation 1 : </label></td>';
- echo '<td class="inputcell"><select name="relation1">';
- foreach($relations as $key=>$r)
- echo '<option value="'.$r.'">'.$stringRelations[$r].'</option>';
- echo '</select></td>';
- echo '<td><label for="relation2">Relation 2 : </label></td>';
- echo '<td class="inputcell"><select name="relation2">';
- foreach($relations as $key=>$r)
- echo '<option value="'.$r.'">'.$stringRelations[$r].'</option>';
- echo '</select></td>';
- echo '<input type="hidden" name="nbcloudwords" value="'.$nbwords.'" />';
- echo '<tr><td colspan="2"><br /><label for="centralword">Mot central : </label><br /><br /></td>';
- echo '<td colspan="2" class="inputcell"><br /><input type="text" name="centralword" value="';
- if(isset($_POST['centralword'])) echo $_POST['centralword'];
- echo '"/><br /><br /></td>';
-
- for($i = 0; $i < $nbwords; $i++) {
- if($i % 2 == 0)
- echo '</tr><tr>';
-
- echo '<td><label for="word'.$i.'">Mot '.($i+1).' : </label></td>';
- echo '<td class="inputcell"><input type="text" name="word'.$i.'" value="';
- if(isset($_POST['word'.$i])) echo $_POST['word'.$i];
- echo '" /></td>';
- }
+ <p>Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.<br /><br />
+ <div id="errorDiv" class="message warning" style="display:none;"></div>
+
+ <div id="center">
+ <label for="centralWord"> Le mot central : </label>
+ <input type="text" id="centralWord" name="centralWord" />
+ <span class="status">●</span>
+ </div>
+ <div id="relations">
+ <label for="relation1">Relation 1</label>
+ <select name="relation1" id="relation1">
+ </select>
+ <label for="relation2">Relation 2</label>
+ <select name="relation2" id="relation2">
+ </select>
+ </div>
+ <div id="wordLines">
+ <div id="templates" style="display:none">
+ <table>
+ <thead> </thead>
+ <tbody>
+ <tr class="wordLine">
+ <td>
+ <label for="word-"></label>
+ </td>
+ <td>
+ <input type="text" id="word-"/>
+ <span class="status">●</span>
+ </td>
+ <td>
+ <input type="checkbox" id="r1-"/><label class="r1" for="r1-">Blabla</label>
+ </td>
+ <td>
+ <input type="checkbox" id="r2-"/><label class="r2" for="r2-">Blabla</label>
+ </td>
+ <td>
+ <input type="checkbox" id="r3-"/><label class="r3" for="r3-">Blabla</label>
+ </td>
+ <td>
+ <input type="checkbox" id="r4-"/><label class="r4" for="r4-">Blabla</label>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
- if($nbwords % 2 != 0)
- echo '<td></td>';
-
- echo '</tr><tr><td colspan="2"></td><td colspan="2" class="td2"><input type="submit" value="Enregistrer la partie" /></td></tr>';
- }
- elseif($state == 2) {
- echo 'Mot central : ';
- echo $centralword;
- echo '<input type="hidden" name="centralword" value="'.$centralword.'" />';
- echo '<input type="hidden" name="nbcloudwords" value="'.$nbwords.'" />';
- echo '<input type="hidden" name="relation1" value="'.$_POST['relation1'].'" />';
- echo '<input type="hidden" name="relation2" value="'.$_POST['relation2'].'" />';
- echo '<table class="wordsform">';
- echo '<tr>';
-
- foreach($words as $key=>$w) {
- echo '<td>'.$w.'</td><td class="inputcell">';
- echo '<input type="hidden" name="word'.$key.'" value="'.$w.'" />';
- echo '<input type="radio" name="rd'.$key.'" id="'.$key.'_r1" value="0" '.checked("rd".$key,0).'>';
- echo '<label for="'.$key.'_r1">'.$rels[0].'</label><br />';
- echo '<input type="radio" name="rd'.$key.'" id="'.$key.'_r2" value="1" '.checked("rd".$key,1).'>';
- echo '<label for="'.$key.'_r2">'.$rels[1].'</label><br />';
- echo '<input type="radio" name="rd'.$key.'" id="'.$key.'_r3" value="2" '.checked("rd".$key,2).'>';
- echo '<label for="'.$key.'_r3">'.$rels[2].'</label><br />';
- echo '<input type="radio" name="rd'.$key.'" id="'.$key.'_r4" value="3" '.checked("rd".$key,3).'>';
- echo '<label for="'.$key.'_r4">'.$rels[3].'</label></td>';
-
- if($key%2 != 0)
- echo '</tr><tr>';
- }
-
- if(count($words)%2 != 0)
- echo '<td colspan="2"></td>';
-
- echo '</tr>';
- echo '<tr><td colspan="2"><label for="tDifficulty">Difficulté de la partie</label></td>';
- echo '<td class="inputcell" colspan="2"><select name="tDifficulty">';
- for($i = 1; $i < 11; $i++)
- echo '<option value="'.$i.'">'.$i.'</option>';
- echo '</select></td></tr>';
-
- echo '<tr><td colspan="4"><input type="submit" value="Enregistrer" /></td></tr>';
- }
- elseif($state == 3) {
- echo '<p>nombre de mots ajoutés dans la base de données : '.$addedWords;
- }
- ?>
+ <table class="wordLinesTable">
+ <tr><td></td></tr>
</table>
- </form>
+ </div>
+ <div id="button"></div>
+ </div>
+ <div id="templates" style="display:none">
</div>
<?php include("ressources/footer.inc"); ?>
</body>
diff --git a/code/serveur/php/createGamejs.php b/code/serveur/php/createGamejs.php
@@ -1,156 +0,0 @@
-<?php
-require_once("ressources/strings.inc");
-require_once("relations.php");
-require_once("server.php");
-session_start();
-
-?>
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
- <head>
- <title>PtiClic Android - Création de partie</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <link rel="stylesheet" href="ressources/simple.css" />
- <script type="text/javascript" src="ressources/jquery-1.5.1.min.js" /></script>
- <script type="text/javascript" src="ressources/createGame.js" /></script>
-<style type="text/css">
- #wordLines input{
- border : 2px solid grey;
- }
- .status {
- visibility: hidden;
- }
- .valid .status, #center.valid .status {
- color: green;
- visibility: visible;
- }
- .invalid .status, #center.invalid .status, #center .status {
- color: red;
- visibility: visible;
- }
-
- .wordLinesTable {
- min-height : 20px;
- min-width : 20px;
- border-collapse : collapse;
- border-spacing : 0px;
- margin-left : 30px;
- }
-
- .wordLinesTable td {
- padding : 6px;
- padding-left : 10px;
- }
-
- .wordLinesTable .lightLine {
- background-color : #DADADA;
- }
-
-
- #center {
- margin-left : 100px;
- margin-top : 20px;
- margin-bottom : 30px;
- }
-
- #center label {
- border-bottom : 1px solid grey;
- border-left : 1px solid grey;
- -moz-border-radius : 100%;
- padding-left : 10px;
- }
-
-
- #relations {
- margin-bottom : 20px;
- margin-top : 10px;
- }
-
- #relations label {
- margin-left : 40px;
- border-bottom : 1px solid grey;
- border-left : 1px solid grey;
- -moz-border-radius : 100%;
- padding-left : 10px;
- padding-right : 10px;
- }
-
- #button {
- margin-top : 30px;
- margin-left : 50px;
- margin-bottom : 40px;
- }
-
- #button input {
- margin-left : 10px;
- margin-right : 40px;
- padding : 4px;
- padding-left : 8px;
- padding-right : 8px;
- font-weight : bold;
- }
-
-</style>
- </head>
- <body>
- <?php include("ressources/menu.inc"); ?>
- <div class="content creategame">
- <h2>Création de parties</h2>
- <p>Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.<br /><br />
- <div id="errorDiv" class="message warning" style="display:none;"></div>
-
- <div id="center">
- <label for="centralWord"> Le mot central : </label>
- <input type="text" id="centralWord" name="centralWord" />
- <span class="status">●</span>
- </div>
- <div id="relations">
- <label for="relation1">Relation 1</label>
- <select name="relation1" id="relation1">
- </select>
- <label for="relation2">Relation 2</label>
- <select name="relation2" id="relation2">
- </select>
- </div>
- <div id="wordLines">
- <div id="templates" style="display:none">
- <table>
- <thead> </thead>
- <tbody>
- <tr class="wordLine">
- <td>
- <label for="word-"></label>
- </td>
- <td>
- <input type="text" id="word-"/>
- <span class="status">●</span>
- </td>
- <td>
- <input type="checkbox" id="r1-"/><label class="r1" for="r1-">Blabla</label>
- </td>
- <td>
- <input type="checkbox" id="r2-"/><label class="r2" for="r2-">Blabla</label>
- </td>
- <td>
- <input type="checkbox" id="r3-"/><label class="r3" for="r3-">Blabla</label>
- </td>
- <td>
- <input type="checkbox" id="r4-"/><label class="r4" for="r4-">Blabla</label>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
-
- <table class="wordLinesTable">
- <tr><td></td></tr>
- </table>
- </div>
- <div id="button"></div>
- </div>
- <div id="templates" style="display:none">
- </div>
- <?php include("ressources/footer.inc"); ?>
- </body>
-</html>
diff --git a/code/serveur/php/ressources/locations.inc b/code/serveur/php/ressources/locations.inc
@@ -6,6 +6,7 @@ $location_list['contact'] = "contact.php";
$location_list['createGame'] = "createGame.php";
$location_list['login'] = "login.php";
$location_list['signup'] = "signup.php";
+$location_list['createGame'] = 'createGame.php';
function return_to($location, $params = "") {
global $location_list;
diff --git a/code/serveur/php/ressources/strings.inc b/code/serveur/php/ressources/strings.inc
@@ -26,6 +26,7 @@ $strings['err_login_bad_user_pass'] = "Mauvais nom d'utilisateur ou mot de passe
$strings['err_login_fill_all'] = "Veuillez remplir tous les champs.";
$strings['err_login_dbopen'] = "Erreur lors de l'ouverture de la base de données SQLite3. Merci de nous signaler le problème.";
$strings['oth_login_download_nauth'] = "Afin d'accéder à la page de téléchargement et obtenir l'application vous devez être authentifié.";
+$strings['oth_login_createGame_nauth'] = "Afin de pouvoir créer des parties vous devez être authentifié.";
$strings['err_signup_dbopen'] = "Erreur lors de l'ouverture de la base de données SQLite3. Merci de nous signaler le problème.";
$strings['err_signup_fill_mail'] = "Veuillez renseigner le champ 'Saisissez votre adresse mail'.";