commit 52f6d60a6e9afb781cfaec354a29b0263d454936
parent 63212ad368e2d0cffb6be823b6ab7ac07b0654d9
Author: Yoann <yoann.b87@voila.fr>
Date: Thu, 31 Mar 2011 13:00:45 +0200
Petit nettoyage du code et continuation de la page de création de
partie.
Diffstat:
4 files changed, 43 insertions(+), 113 deletions(-)
diff --git a/code/serveur/php/createGamejs.php b/code/serveur/php/createGamejs.php
@@ -175,109 +175,10 @@ else
<?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="center">Mot central</div>
<div id="wordLines"></div>
- <input type="button" id="addLine" value="Ajouter un ligne" />
-
- <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>';
- }
-
- 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>
- </form>
+ <div id="button"></div>
</div>
<?php include("ressources/footer.inc"); ?>
</body>
diff --git a/code/serveur/php/pticlic.php b/code/serveur/php/pticlic.php
@@ -24,6 +24,7 @@ require_once("db.php");
* normalizeProbas($row);
* setGame($user, $pgid, $gid, $answers);
* get_game_relations();
+ getGameRelationsJSON();
* setGameGetScore($user, $pgid, $gid, $answers);
* insertNode($node);
* getNodeEid($node);
@@ -627,6 +628,20 @@ function get_game_relations()
return $relations;
}
+function getGameRelationsJSON() {
+ $json = "{";
+
+ foreach($stringRelations as $id=>$description)
+ if($id == -1)
+ $json .= '"'.$id.'":"'.$description.'"';
+ else
+ $json .= ',"'.$id.'":"'.$description.'"';
+
+ $json .= '}';
+
+ return $json;
+}
+
function setGameGetScore($user, $pgid, $gid, $answers) {
$scores = setGame($user, intval($pgid), intval($gid), $answers);
// On renvoie une nouvelle partie pour garder le client toujours bien alimenté.
diff --git a/code/serveur/php/ressources/createGame.js b/code/serveur/php/ressources/createGame.js
@@ -1,16 +1,13 @@
$(function () {
var numWord = 1;
+ var user = "foo";
+ var passwd = "bar";
var displayNWordLines = function (nb) {
- var wLines = "";
for(var i=numWord; i<numWord+nb; i++){
- wLines += '<div><label for="word'+i+'">'+i+' </label><input id="word'+i+'" /></div>';
- }
-
- $("#wordLines").html(wLines);
-
- for(var i=numWord; i<numWord+nb; i++){
+ $("#wordLines").append('<div><label for="word'+i+'">'+i+' </label><input id="word'+i+'" /></div>');
+
function f(id) {
$("#word"+id).focusout(function () {
var input = "word"+id;
@@ -20,20 +17,27 @@ $(function () {
f(i);
}
-
+
numWord += nb;
}
var displayCentralWord = function () {
$("#center").html('<label for="centralWord"> Le mot central : </label><input type="text" id="centralWord" name="centralWord" />');
$("#centralWord").focusout(function () {
- var input = "centralWord";
-
- checkWord(input)
+ var input = "centralWord";
+ checkWord(input)
}
);
}
+ var displayButtons = function () {
+ $("#button").html('<input type="button" id="addLine" name="addLine" value="Ajouter" />');
+ $("#addLine").click(function(){displayNWordLines(1)});
+
+ $("#button").append('<input type="button" id="validate" name="validate" value="Valider" />');
+ $("#validate").click(function(){});
+ }
+
var checkWord = function (inputId) {
var input = "#"+inputId;
var word = $(input).val();
@@ -42,7 +46,7 @@ $(function () {
$(input).css("background-color", "white");
else {
$.ajax({type: "GET", url: "server.php?",
- data: "action=4&word="+word+"&user=foo&passwd=bar",
+ data: "action=4&word="+word+"&user="+user+"&passwd="+passwd,
success: function(msg){
if(msg == "false")
$(input).css("background-color", "orange");
@@ -52,6 +56,13 @@ $(function () {
}
}
+ var getRelationsList = function () {
+ $.getJSON("server.php?action=5&user=foo&passwd=ba",function (data) {
+ $.debug(data);
+ });
+ }
+ getRelationsList();
displayCentralWord();
displayNWordLines(10);
+ displayButtons();
});
diff --git a/code/serveur/php/server.php b/code/serveur/php/server.php
@@ -83,6 +83,9 @@ function main()
else
echo 'false';
}
+ else if($action == 5) { // Get relations (JSON)
+ echo "mqslkjfmlqskjfqmskf";//echo getGameRaltionsJSON();
+ }
else {
throw new Exception("Commande inconnue", 2);
}