From 6b57ca1ff9dfcb2c469805b461eb18d9dbc27bf2 Mon Sep 17 00:00:00 2001 From: Yoann Date: Sun, 17 Apr 2011 17:10:19 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Page=20de=20cr=C3=A9ation=20de=20partie=20:?= =?UTF-8?q?=20-=20Pr=C3=A9sentation=20du=20formulaire.=20-=20v=C3=A9rifica?= =?UTF-8?q?tion=20des=20relations=20affect=C3=A9es=20au=20mots.=20-=20cons?= =?UTF-8?q?truction=20de=20la=20chaine=20JSON=20=C3=A0=20passer=20au=20ser?= =?UTF-8?q?veur.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/serveur/php/createGamejs.php | 109 +++++++++++++++++++--- code/serveur/php/ressources/createGame.js | 61 ++++++++---- 2 files changed, 137 insertions(+), 33 deletions(-) diff --git a/code/serveur/php/createGamejs.php b/code/serveur/php/createGamejs.php index dadea1f..845c371 100644 --- a/code/serveur/php/createGamejs.php +++ b/code/serveur/php/createGamejs.php @@ -169,17 +169,79 @@ else #wordLines input{ border : 2px solid grey; } - .wordLine .status { + .status { visibility: hidden; } - .wordLine.valid .status, #center.valid .status { + .valid .status, #center.valid .status { color: green; visibility: visible; } - .wordLine.invalid .status, #center.invalid .status, #center .status { + .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; + } + @@ -202,18 +264,39 @@ else -
+
+ + + +
diff --git a/code/serveur/php/ressources/createGame.js b/code/serveur/php/ressources/createGame.js index f9e1592..28f7c2e 100644 --- a/code/serveur/php/ressources/createGame.js +++ b/code/serveur/php/ressources/createGame.js @@ -15,7 +15,7 @@ $(function() { var user = "foo"; var passwd = "bar"; var relations = data; - var nbWordMin = 10; + var nbWordMin = 3; var wordsOK = new Array(); var centerOK = false; @@ -26,9 +26,10 @@ $(function() { $("#templates .wordLine") .clone() .changeId(i) + .addClass(i%2==0 ? "lightLine" : "") // .find("label").attr("for", "word"+i).text(i).end() // .find("input").attr("id", "word"+i).end() - .appendTo("#wordLines"); + .appendTo(".wordLinesTable tbody"); (function (i) { $("#word-"+i).focusout(checkWord); @@ -79,7 +80,7 @@ $(function() { var input = $(this); var word = input.val(); - input.parent(".wordLine, #center").removeClass("valid invalid"); + input.parent("td, #center").removeClass("valid invalid"); if (word != "") { $.ajax({ @@ -87,7 +88,7 @@ $(function() { url: "server.php?", data: "action=4&word="+word+"&user="+user+"&passwd="+passwd, success: function(msg){ - input.parent(".wordLine, #center").addClass((msg == false) ? "invalid" : "valid"); + input.parent("td, #center").addClass((msg == false) ? "invalid" : "valid"); wordsOK[input.attr("id")] = !(msg == false); }}); } @@ -95,19 +96,21 @@ $(function() { var formOK = function() { displayError(""); - - console.log(wordsOK); - if ($("#relation1").val() == $("#relation2").val()) - displayError("Les deux relation doivent être différents"); - else if ($("#centralWord").val() == "") - displayError("Le mot central doit être renseigné."); - else if (badWord()) - displayError("Il existe des mots incorrects"); - else if (nbWordOK() < nbWordMin) - displayError("Le nuage doit contenir au moins "+nbWordMin+" mots valides."); - else if (!relationsOK()) - displayError("Tout les mots ne sont pas liés à une relation"); + if ($("#relation1").val() == $("#relation2").val()) + displayError("Les deux relation doivent être différents"); + else if ($("#centralWord").val() == "") + displayError("Le mot central doit être renseigné."); + else if (badWord()) + displayError("Il existe des mots incorrects"); + else if (nbWordOK() < nbWordMin) + displayError("Le nuage doit contenir au moins "+nbWordMin+" mots valides."); + else if (!relationsOK()) + displayError("Tout les mots ne sont pas liés à une relation"); + else + sendGame(); + + return false; }; var nbWordOK = function() { @@ -129,16 +132,34 @@ $(function() { } var relationsOK = function() { - for(i = 0; i < numWord; i++) + for(i = 1; i < numWord; i++) { if(wordsOK["word-"+i]) { - console.log("mot ok"); - if(!$("r1-"+i).is(":checked") && !$("r2-"+i).is(":checked") && !$("r3-"+i).is(":checked") && !$("r4-"+i).is(":checked")) + if(!$("#r1-"+i).is(":checked") && !$("#r2-"+i).is(":checked") && !$("#r3-"+i).is(":checked") && !$("#r4-"+i).is(":checked")) return false; } + } return true; } + + var sendGame = function() { + var exit; + var cloud = ""; + exit = {center:$("#centralWord").val(), + relations:[$("#relation1").val(),$("#relation2").val(),0,-1], + cloud:[]}; + + for(i=1;i Date: Sun, 17 Apr 2011 17:31:17 +0200 Subject: [PATCH 2/3] Petit nettoyage du code et correction d'un bug. --- code/serveur/php/createGamejs.php | 151 ---------------------- code/serveur/php/ressources/createGame.js | 4 +- 2 files changed, 3 insertions(+), 152 deletions(-) diff --git a/code/serveur/php/createGamejs.php b/code/serveur/php/createGamejs.php index 845c371..505eaaf 100644 --- a/code/serveur/php/createGamejs.php +++ b/code/serveur/php/createGamejs.php @@ -4,157 +4,6 @@ require_once("relations.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(); - - $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; - } - - 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']; - } - else { - $state = 1; - $relations = get_game_relations(); - } - - 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']; - } - } - elseif (isset($_POST['centralword']) && empty($_POST['centralword'])) { - $err = true; - $msg = $strings['err_creategame_cloud_fill_all']; - } - - 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']; - } - - $state = 3; - $msg = $strings['ok_creategame_game_create']; - } - - cgInsert($centralword, $cloud, $r1, $r2, $totalDifficulty); - } - elseif($state == 2) { - $err = true; - $msg = $strings['err_creategame_fill_all']; - } -} -else - $err = true; - ?> diff --git a/code/serveur/php/ressources/createGame.js b/code/serveur/php/ressources/createGame.js index 28f7c2e..5be3ddb 100644 --- a/code/serveur/php/ressources/createGame.js +++ b/code/serveur/php/ressources/createGame.js @@ -124,14 +124,16 @@ $(function() { }; var badWord = function() { + console.log(wordsOK); for (word in wordsOK) - if (wordsOK[word] == false) + if ($("#"+word).val() != "" && wordsOK[word] == false) return true; return false; } var relationsOK = function() { + console.log(wordsOK); for(i = 1; i < numWord; i++) { if(wordsOK["word-"+i]) { if(!$("#r1-"+i).is(":checked") && !$("#r2-"+i).is(":checked") && !$("#r3-"+i).is(":checked") && !$("#r4-"+i).is(":checked")) From 7ed8a078caa64dfe165528dea14fe120ff04fbf6 Mon Sep 17 00:00:00 2001 From: Yoann Date: Sun, 17 Apr 2011 18:12:26 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Reprise=20du=20code=20php=20et=20ajout=20de?= =?UTF-8?q?=20la=20v=C3=A9rification=20d'autentification=20avant=20de=20po?= =?UTF-8?q?uvoir=20cr=C3=A9er=20un=20partie.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/serveur/php/createGame.php | 381 ++++++++-------------- code/serveur/php/createGamejs.php | 156 --------- code/serveur/php/ressources/locations.inc | 1 + code/serveur/php/ressources/strings.inc | 1 + 4 files changed, 136 insertions(+), 403 deletions(-) delete mode 100644 code/serveur/php/createGamejs.php diff --git a/code/serveur/php/createGame.php b/code/serveur/php/createGame.php index 1505bbe..1cfdf8a 100644 --- a/code/serveur/php/createGame.php +++ b/code/serveur/php/createGame.php @@ -1,160 +1,12 @@ $w) { - if(isset($_POST['rd'.$key])) { - $respwords[$key] = array(); - $respwords[$key][0] = $words[$key]; - $respwords[$key][1] = $_POST['rd'.$key]; - } - else - return -1; - } - - 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']; - } - else { - $state = 1; - $relations = get_game_relations(); - } - - 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']; - } - } - elseif (isset($_POST['centralword']) && empty($_POST['centralword'])) { - $err = true; - $msg = $strings['err_creategame_cloud_fill_all']; - } - - 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']; - } - - $state = 3; - $msg = $strings['ok_creategame_game_create']; - } - - cgInsert($centralword, $cloud, $r1, $r2, $totalDifficulty); - } - elseif($state == 2) { - $err = true; - $msg = $strings['err_creategame_fill_all']; - } -} -else - $err = true; - ?> @@ -163,109 +15,144 @@ else PtiClic Android - Création de partie + + +

Création de parties

- 0) - echo '

Remplissez le mot central ainsi que les différents mots du nuage pour réaliser un partie personalisée.
- Une fois satisfait de votre partie cliquez sur "Enregistrer la partie"'; - else - echo '

Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.

- Veuillez entrer le nombre de mots composant le nuage dans le formulaire ci-dessous avant de continuer.


'; - ?> -
- '.$msg.''; - else if ($msg != "") - echo ''.$msg.''; - - if($state == 0) { - echo ''; - echo ''; - echo ''; - echo ''; - } - elseif($state == 1) { - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; +

Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.

+

+ +
+ + + +
+
+ + + + +
+
+






+ + + + + + + + + + + +
+ + + + + + + + + + + + +
+
- for($i = 0; $i < $nbwords; $i++) { - if($i % 2 == 0) - echo ''; - - echo ''; - echo ''; - } - - if($nbwords % 2 != 0) - echo ''; - - echo ''; - } - elseif($state == 2) { - echo 'Mot central : '; - echo $centralword; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - foreach($words as $key=>$w) { - echo ''; - - if($key%2 != 0) - echo ''; - } - - if(count($words)%2 != 0) - echo ''; - - echo ''; - echo ''; - echo ''; - - echo ''; - } - elseif($state == 3) { - echo '

nombre de mots ajoutés dans la base de données : '.$addedWords; - } - ?> +

'.$w.''; - echo ''; - echo ''; - echo '
'; - echo ''; - echo '
'; - echo ''; - echo '
'; - echo ''; - echo '
+
- + +
+ + diff --git a/code/serveur/php/createGamejs.php b/code/serveur/php/createGamejs.php deleted file mode 100644 index 505eaaf..0000000 --- a/code/serveur/php/createGamejs.php +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - PtiClic Android - Création de partie - - - - - - - - -
-

Création de parties

-

Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.

-

- -
- - - -
-
- - - - -
-
- - - - -
-
-
-
- - - - diff --git a/code/serveur/php/ressources/locations.inc b/code/serveur/php/ressources/locations.inc index 195b699..205cc1a 100644 --- 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 index 5e27ffd..e886ee2 100644 --- 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'.";