From 424a8f0a34fc72fe64daaac4686f991a298933a3 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 21 Sep 2009 22:59:28 +0200 Subject: [PATCH] ADD #143 (80%) --- css/style.css | 16 +++++++++++++++- index.php | 1 + js/cl7.js | 34 ++++++++++++++++++++++++++++++---- php/controller.php | 18 ++++++++++-------- php/pages/inscription.php | 4 ++-- php/pages/jeux_joues.php | 18 ++++++++++++++---- php/participant.php | 25 ++++++++++++++++--------- php/update_db.php | 20 ++++++++++++-------- 8 files changed, 100 insertions(+), 36 deletions(-) diff --git a/css/style.css b/css/style.css index 86de936..63c475b 100644 --- a/css/style.css +++ b/css/style.css @@ -133,9 +133,19 @@ ul#menu { #contenu col#inscriptionColonneValeur { width: 70%; } -#contenu #formulaireJeuxJoues .aVote { +#contenu #formulaireJeuxJoues .aVote, #contenu #formulaireJeuxJoues .aVote a { color: #ffff00; } +#contenu #formulaireJeuxJoues a { + padding-right: 12px; + background:transparent url(../images/lien_externe.png) no-repeat scroll right center; +} +#contenu #formulaireJeuxJoues .aVote a { + color: #ffff00; +} +#contenu #formulaireJeuxJoues .aVote a:hover { + color: #ffffaa; +} #contenu #formulaireInscription p { margin-top: 1px; margin-bottom: 0px; @@ -195,6 +205,10 @@ form textarea:hover, form textarea:focus { border: #ffff00 1px solid; } +form input.info { + color: #999999; +} + /***** La boite d'information (s'apparente à une MessageBox) *****/ div#info { text-align: center; diff --git a/index.php b/index.php index eb24013..3025188 100644 --- a/index.php +++ b/index.php @@ -50,6 +50,7 @@ echo ''; echo ''; $nbPeriodes = pg_fetch_array(pg_query("SELECT COUNT(*) FROM periodes")); echo ''; + echo ''; ?> Corcelles-Lan 8 diff --git a/js/cl7.js b/js/cl7.js index f66218c..208322a 100644 --- a/js/cl7.js +++ b/js/cl7.js @@ -7,11 +7,13 @@ var cl7 = {}; cl7.verification_formulaire_inscription = function(util) { + var estLogge = $('meta[name="estLogge"]').attr('content'); + if ($('#formulaireInscription input[name="pseudo"]').val() === "") { util.messageDialogue("Le pseudo ne peut pas être vide"); return false; } - if ($('#formulaireInscription input[name="pass1"]').val() === "" && + if (!estLogge && $('#formulaireInscription input[name="pass1"]').val() === "" && $('#formulaireInscription input[name="pass2"]').val() === "") { util.messageDialogue("Le password ne peut pas être vide"); return false; @@ -20,7 +22,7 @@ cl7.verification_formulaire_inscription = function(util) { util.messageDialogue("Les passwords ne correspondent pas"); return false; } - if ($('#formulaireInscription input[name="pass1"]').val().length < 3) { + if ((!estLogge || $('#formulaireInscription input[name="pass1"]').val() != '') && $('#formulaireInscription input[name="pass1"]').val().length < 3) { util.messageDialogue("La taille de password doit être d'au moins 3 caractères"); return false; } @@ -61,15 +63,19 @@ cl7.maj_prix_inscription = function() { $(document).ready( function() { var util = new cl7.Util(); + + // Check du formulaire d'inscription. $('form#formulaireInscription').submit(function() { return cl7.verification_formulaire_inscription(util); }); + // Affichage d'un message si disponible au chargement de la page. var messageUtilisateur = $('meta[name="messageUtilisateur"]').attr('content'); if (messageUtilisateur !== undefined) { util.messageDialogue(messageUtilisateur); } - + + // Met à jour les champs en rapport avec le clan existant choisi. $('form#formulaireInscription select[name="clanChoix"]').change(function() { if ($(this).val() === '0') { return; @@ -89,7 +95,7 @@ $(document).ready( // met à jour le prix d'inscription cl7.maj_prix_inscription(); - // permet d'éviter de faire plus de choix qu'il n'en faut sur la page des jeux joués + // Permet d'éviter de faire plus de choix qu'il n'en faut sur la page des jeux joués. var nbVotesMax = 3; var coches = []; $('#formulaireJeuxJoues input[name="votes[]"]:checked').each(function() { @@ -110,5 +116,25 @@ $(document).ready( } } }); + + // Enlève ou affiche les informations (p.e. '') concernant les champs des formulaires. + $('form input.info').focus(function() { + if (!$(this).hasClass('info')) + return; + + var value = $(this).val(); + $(this).blur(function() { + if ($(this).val().trim() === '') { + $(this).val(value).addClass('info'); + $(this).unbind('blur'); + } + }); + + $(this).val('').removeClass('info'); + }); + + $('form').submit(function() { + $('input.info', this).val(''); + }); } ); diff --git a/php/controller.php b/php/controller.php index 41381ac..a42051a 100644 --- a/php/controller.php +++ b/php/controller.php @@ -62,7 +62,7 @@ class Controller $this->set_periodes($id); pg_query("COMMIT"); - $this->participant = new participant($_POST['pseudo'], $_POST['pass1']); + $this->participant->chargerInfos($_POST['pseudo'], $_POST['pass1']); setcookie("COOKIE_INFO_PARTICIPANT", $this->participant->info->id, time() + 31104000); $this->nouvel_inscrit = TRUE; } @@ -74,11 +74,12 @@ class Controller return; $this->traiter_donnees_inscription(); - if (!$this->login_deja_pris() && $this->donnees_inscription_valides()) + if (!$this->login_deja_pris() && $this->donnees_inscription_valides(true)) { pg_query("BEGIN"); pg_query_params("UPDATE participants SET pseudo = $1 WHERE id = $2", array($_POST['pseudo'], $this->participant->info->id)); - pg_query_params("UPDATE participants SET password = $1 WHERE id = $2", array(sha1($_POST['pass1']), $this->participant->info->id)); + if ($_POST['pass1'] != '') // Uniquement si un nouveau password est donné. + pg_query_params("UPDATE participants SET password = $1 WHERE id = $2", array(sha1($_POST['pass1']), $this->participant->info->id)); pg_query_params("UPDATE participants SET clan_nom = $1 WHERE id = $2", array($_POST['clan_nom'], $this->participant->info->id)); pg_query_params("UPDATE participants SET clan_tag = $1 WHERE id = $2", array($_POST['clan_tag'], $this->participant->info->id)); pg_query_params("UPDATE participants SET nom = $1 WHERE id = $2", array($_POST['nom'], $this->participant->info->id)); @@ -108,7 +109,7 @@ class Controller $jeu = trim($_POST['jeu']); if ($jeu !== '') { - if(@pg_query_params("INSERT INTO jeux (nom) VALUES ($1)", array($jeu))) + if(@pg_query_params("INSERT INTO jeux (participant_id, nom, type, url) VALUES ($1, $2, $3, $4)", array($this->participant->info->id, $jeu, $_POST['type'], $_POST['url']))) { $row = pg_fetch_row(pg_query("SELECT LASTVAL()")); $id = $row[0]; @@ -163,14 +164,15 @@ class Controller /** * Renvoie TRUE si les données d'une inscription sont valides (POST). + * $maj : égal 'TRUE' si c'est une mise à jour, dans ce cas le password est traité différement */ - private function donnees_inscription_valides() + private function donnees_inscription_valides($maj = FALSE) { return - $_POST['pseudo'] != "" && - $_POST['pass1'] != "" && + $_POST['pseudo'] != "" && + ($maj || $_POST['pass1'] != "") && $_POST['pass1'] == $_POST['pass2'] && - strlen($_POST['pass1']) >= 3 && + (($maj && $_POST['pass1'] == "") || strlen($_POST['pass1']) >= 3) && $_POST['nom'] != "" && $_POST['prenom'] != "" && $_POST['e_mail'] != ""; diff --git a/php/pages/inscription.php b/php/pages/inscription.php index dd603ac..e858b9a 100644 --- a/php/pages/inscription.php +++ b/php/pages/inscription.php @@ -37,8 +37,8 @@ else password (pour pouvoir par la suite modifier mes infos) - " /> - re: " /> + " /> + re: " /> diff --git a/php/pages/jeux_joues.php b/php/pages/jeux_joues.php index 9c531ec..276c8f5 100644 --- a/php/pages/jeux_joues.php +++ b/php/pages/jeux_joues.php @@ -17,7 +17,7 @@ echo '

- ', ($vote_possible ? '' : ''), ''; + ', ($vote_possible ? '' : ''), ''; # /!\ Attention, requête un poil tricky : # On souhait avoir une liste des jeux joués avec pour chaque tuple : @@ -28,12 +28,14 @@ $jeux_query = pg_query(" SELECT jeux.id, jeux.nom, + jeux.type, + jeux.url, array_agg(jeux_choisis.participant_id) AS participants, (COUNT(*) + (CASE WHEN bool_and(jeux_choisis.participant_id is null) THEN -1 ELSE 0 END)) as nb_vote FROM jeux LEFT JOIN jeux_choisis ON jeux.id = jeux_choisis.jeu_id - GROUP BY jeux.id, jeux.nom + GROUP BY jeux.id, jeux.nom, jeux.type, jeux.url ORDER BY nb_vote DESC, jeux.nom "); @@ -50,11 +52,15 @@ while ($jeu = pg_fetch_object($jeux_query)) $a_vote = in_array($participant->info->id, $participants); } + + $a_url = preg_match('/^https?:\/\/.+$/', $jeu->url); echo '', $vote_possible ? '' : '', '', - ''; + '', + '', + ''; } echo ' @@ -62,7 +68,11 @@ echo ' if ($vote_possible) echo ' -

Autre :

+

Ajouter : + + + +

'; echo ''; diff --git a/php/participant.php b/php/participant.php index e2b47be..e940f74 100644 --- a/php/participant.php +++ b/php/participant.php @@ -20,6 +20,19 @@ class Participant */ public function Participant($v1=NULL, $v2=NULL) { + $this->authentifier($v1, $v2); + } + + /** + * Est-ce que le participant existe ? C-à-d qu'il est inscrit. + */ + public function existe() + { + return $this->id != 0; + } + + private function authentifier($v1=NULL, $v2=NULL) + { # Aucunes valeurs transmise => ce n'est pas un participant valide. if ($v1 == NULL && $v2 == NULL) return; @@ -36,18 +49,12 @@ class Participant $this->id = pg_fetch_object($res)->id; $this->chargerInfos(); } - } - - /** - * Est-ce que le participant existe ? C-à-d qu'il est inscrit. - */ - public function existe() - { - return $this->id != 0; } - public function chargerInfos() + public function chargerInfos($v1=NULL, $v2=NULL) { + $this->authentifier($v1, $v2); + if (!$this->existe()) return; diff --git a/php/update_db.php b/php/update_db.php index a2d9ffe..969f8a1 100644 --- a/php/update_db.php +++ b/php/update_db.php @@ -26,14 +26,6 @@ function creer_db() PRIMARY KEY (id) ); "); - pg_query(" - CREATE TABLE jeux ( - id serial NOT NULL, - nom varchar(200) NOT NULL, - PRIMARY KEY (id), - UNIQUE (nom) - ); - "); // participants.password est un hash calculé à l'aide de sha1(). pg_query(" CREATE TABLE participants ( @@ -56,6 +48,18 @@ function creer_db() FOREIGN KEY (pizza) REFERENCES pizzas (id) ON DELETE SET NULL ON UPDATE SET NULL ); "); + pg_query(" + CREATE TABLE jeux ( + id serial NOT NULL, + participant_id int default NULL, + nom varchar(200) NOT NULL, + type varchar(100) DEFAULT NULL, + url varchar(200) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE (nom), + FOREIGN KEY (participant_id) REFERENCES participants (id) ON DELETE SET NULL ON UPDATE SET NULL + ); + "); pg_query(" CREATE TABLE jeux_choisis ( participant_id int NOT NULL, -- 2.43.0
VotesJeux
VotesNomType
' . $jeu->nb_vote . '' . traitement_pre_affichage($jeu->nom) . '
' . ($a_url ? '' : '') . traitement_pre_affichage($jeu->nom) . ($a_url ? '' : '') . '' . traitement_pre_affichage($jeu->type) . 'x