www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 8ff4b00dca6c7dde7d0ff4ae5578272e9aabb268
parent 04b86bf7ee5aed52a10bf4b354802f95456dc03e
Author: Yoann <yoann.b87@voila.fr>
Date:   Wed, 25 May 2011 22:48:32 +0200

La création de partie prend maintenant en compte le nombre d'autorisation de création de parties remportées par les joueurs.
Le compteur est bien mis à jours lorsque la personne crée un partie de sorte qu'une fois qu'il est épuisé tout ses crédits il ne puisse plus en
créer.

Diffstat:
Mcode/serveur/php/createGame.php | 287+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Mcode/serveur/php/ressources/backend.inc | 13++++++++++---
Mcode/serveur/php/signup.php | 2+-
3 files changed, 160 insertions(+), 142 deletions(-)

diff --git a/code/serveur/php/createGame.php b/code/serveur/php/createGame.php @@ -6,7 +6,8 @@ session_start(); if(!isset($_SESSION['userId'])) header("location:login.php?return=createGame&showmsg=oth_login_createGame_nauth"); - + +$cgCount = getNbGameCreationRemained($_SESSION['userId']); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> @@ -15,151 +16,161 @@ if(!isset($_SESSION['userId'])) <title>PtiClic - 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: #20FF20; - visibility: visible; - } - .invalid .status, #center.invalid .status, #center .status { - color: #FF2020; - 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 : #F0F0D0; - } - - .wordLinesTable td:first-child { - text-align : right; - } + + <?php if($cgCount > 0) {?> + <script type="text/javascript" src="ressources/jquery-1.5.1.min.js" /></script> + <script type="text/javascript" src="ressources/createGame.js" /></script> + <?php } ?> + <style type="text/css"> + #wordLines input{ + border : 2px solid grey; + } + .status { + visibility: hidden; + } + .valid .status, #center.valid .status { + color: #20FF20; + visibility: visible; + } + .invalid .status, #center.invalid .status, #center .status { + color: #FF2020; + 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 : #F0F0D0; + } + + .wordLinesTable td:first-child { + text-align : right; + } - #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> + #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"); ?> - <form 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="successDiv" class="message success" style="display:none;"></div> - <a id="newCreationLink" style="display:none;" href="createGame.php">Créer une autre partie</a> - - <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 value="" class="word" type="text" id="word-"/> - </td> - <td> - <span class="status">●</span> - </td> - <td> - <input type="checkbox" id="r1-"/><label class="r1 relationLabel" for="r1-">Blabla</label> - </td> - <td> - <input type="checkbox" id="r2-"/><label class="r2 relationLabel" for="r2-">Blabla</label> - </td> - <td> - <input type="checkbox" id="r3-"/><label class="r3 relationLabel" for="r3-">Blabla</label> - </td> - <td> - <input type="checkbox" id="r4-"/><label class="r4 relationLabel" for="r4-">Blabla</label> - </td> - </tr> - </tbody> + <h2>Création de parties</h2> + <?php if($cgCount > 0) { ?> + <h3>Vous pouvez créer encore <?php echo $cgCount;?> partie(s).</h3> + <form class="content creategame"> + <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="successDiv" class="message success" style="display:none;"></div> + <a id="newCreationLink" style="display:none;" href="createGame.php">Créer une autre partie</a> + + <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 value="" class="word" type="text" id="word-"/> + </td> + <td> + <span class="status">●</span> + </td> + <td> + <input type="checkbox" id="r1-"/><label class="r1 relationLabel" for="r1-">Blabla</label> + </td> + <td> + <input type="checkbox" id="r2-"/><label class="r2 relationLabel" for="r2-">Blabla</label> + </td> + <td> + <input type="checkbox" id="r3-"/><label class="r3 relationLabel" for="r3-">Blabla</label> + </td> + <td> + <input type="checkbox" id="r4-"/><label class="r4 relationLabel" for="r4-">Blabla</label> + </td> + </tr> + </tbody> + </table> + </div> + + <table class="wordLinesTable"> + <tr><td></td></tr> </table> </div> - - <table class="wordLinesTable"> - <tr><td></td></tr> - </table> - </div> - <div id="button"></div> - </form> + <div id="button"></div> + </form> + <?php } + else { + echo '<span class="message warning">Vous ne disposez pas assez de points pour pouvoir créer des partes.</span>'; + }?> <?php include("ressources/footer.inc"); ?> </body> </html> diff --git a/code/serveur/php/ressources/backend.inc b/code/serveur/php/ressources/backend.inc @@ -34,6 +34,7 @@ require_once("ressources/db.inc"); * getJAimePgid($user, $pgid); * setJAimePgid($user, $pgid, $value); * addGameCreationBonus($user, $nb); +* function deleteOneGameCreation($user); * getNbGameCreationRemained($user); */ @@ -300,6 +301,7 @@ function decodeAndInsertGame($user,$game) { echo JSON_encode(false); } else { insertCreatedGame($centerEid,$cloud,$r1,$r2,10,$user); + deleteOneGameCreation($user); echo JSON_encode(true); } } @@ -752,15 +754,20 @@ function setJAimePgid($user, $pgid, $value) { function addGameCreationBonus($user, $nb) { if($nb > 0) { - getDB()->exec('UPDATE user SET cgCount = cgCount + '.$ng.' WHERE user='.$user); + getDB()->exec('UPDATE user SET cgCount = cgCount + '.$ng.' WHERE login=\''.$user.'\''); return true; } return false; } -function getNbGameCreationRemained() { - return getDB()->querySingle('SELECT cgCount FROM user WHERE user='.$user); +function deleteOneGameCreation($user) { + if(getNbGameCreationRemained($user) > 0) + getDB()->exec('UPDATE user SET cgCount=cgCount-1 WHERE login=\''.$user.'\''); +} + +function getNbGameCreationRemained($user) { + return getDB()->querySingle('SELECT cgCount FROM user WHERE login=\''.$user.'\''); } ?> diff --git a/code/serveur/php/signup.php b/code/serveur/php/signup.php @@ -79,7 +79,7 @@ if(isset($_POST['signuppswd2'])){ if(count($msg) == 0 && $newpage == false) { - $ok = ($db->query("INSERT INTO user(mail, login, hash_passwd, score, ugroup, sgCount) VALUES ('" . SQLite3::escapeString($signupemail) + $ok = ($db->query("INSERT INTO user(mail, login, hash_passwd, score, ugroup, cgCount) VALUES ('" . SQLite3::escapeString($signupemail) . "', '" . SQLite3::escapeString($signupid) . "', '" . SQLite3::escapeString(md5($signuppswd1)) . "', 0, 1, 0);"));