From ca33eb6a816b02a621896aa446cc9317e770993d Mon Sep 17 00:00:00 2001 From: gburri Date: Sun, 9 Nov 2008 17:38:03 +0000 Subject: [PATCH] FIX #97 git-svn-id: svn://localhost/cl7/trunk@19 4c3d3983-c6fa-4c6c-9935-18c3bbef1bf0 --- php/class_participant.php | 120 +++++++++++++++++++------------------- php/config.php | 6 +- php/config_bd.php | 15 ++--- php/connexion.php | 52 ++++++++++++----- 4 files changed, 110 insertions(+), 83 deletions(-) diff --git a/php/class_participant.php b/php/class_participant.php index a402402..ea27ffa 100644 --- a/php/class_participant.php +++ b/php/class_participant.php @@ -1,79 +1,79 @@ - ce n'est pas un participant valide + function Participant($v1=NULL, $v2=NULL) + { +# aucunes valeurs transmise => ce n'est pas un participant valide if ($v1 == NULL && $v2 == NULL) - { - $this->valide = 0; - return; - } + { + $this->valide = 0; + return; + } - if (is_string($v1) && is_string($v2)) # Aucun des arguments n'est vide alors c'est le pseudo et le password qui ont été transmis + if (is_string($v1) && is_string($v2)) # Aucun des arguments n'est vide alors c'est le pseudo et le password qui ont été transmis $res = mysql_query("SELECT * FROM participants WHERE pseudo = '" . addslashes($v1) . "' AND password = '" . addslashes($v2) . "'"); else # Sinon c'est l'id - $res = mysql_query("SELECT * FROM participants WHERE id = " . addslashes($v1)); + $res = mysql_query("SELECT * FROM participants WHERE id = " . addslashes($v1)); - if (mysql_error() || mysql_num_rows($res) == 0) - { - $this->valide = FALSE; - } - else + if (mysql_error() || mysql_num_rows($res) == 0) + { + $this->valide = FALSE; + } + else { $this->info = mysql_fetch_object($res); - $this->valide = TRUE; + $this->valide = TRUE; } - } - - /** - * Renvoie le nombre de votes restant pour le participant. - */ - function nb_vote_restant() - { - $nombre_de_vote = mysql_fetch_array(mysql_query(" - SELECT COUNT(*) FROM participants RIGHT JOIN jeux_choisis ON participants.id = jeux_choisis.participant_id - WHERE participants.id = " . $this->info->id . " - GROUP BY participants.id - ")); - - return Participant::$NB_VOTES_PAR_PARTICIPANT - $nombre_de_vote[0]; - } - - /** - * Renvois TRUE si le nombre de participant max est atteint. - */ - static function nombre_participant_max_atteint() - { - global $config; - $res_SQL = mysql_query("SELECT COUNT(*) FROM participants"); - $nb_participant = mysql_fetch_row($res_SQL); - - return $nb_participant[0] >= $config->get('nb_max_participant'); - } - - /** - * Renvois le nombre de places restantes. - */ - static function nombre_place_restante() - { - global $config; - $res_SQL = mysql_query("SELECT COUNT(*) FROM participants"); - $nb_participant = mysql_fetch_row($res_SQL); - - return $config->get('nb_max_participant') - $nb_participant[0]; + } + + /** + * Renvoie le nombre de votes restant pour le participant. + */ + function nb_vote_restant() + { + $nombre_de_vote = mysql_fetch_array(mysql_query(" + SELECT COUNT(*) FROM participants RIGHT JOIN jeux_choisis ON participants.id = jeux_choisis.participant_id + WHERE participants.id = " . $this->info->id . " + GROUP BY participants.id + ")); + + return Participant::$NB_VOTES_PAR_PARTICIPANT - $nombre_de_vote[0]; + } + + /** + * Renvois TRUE si le nombre de participant max est atteint. + */ + static function nombre_participant_max_atteint() + { + global $config; + $res_SQL = mysql_query("SELECT COUNT(*) FROM participants"); + $nb_participant = mysql_fetch_row($res_SQL); + + return $nb_participant[0] >= $config->get('nb_max_participant'); + } + + /** + * Renvois le nombre de places restantes. + */ + static function nombre_place_restante() + { + global $config; + $res_SQL = mysql_query("SELECT COUNT(*) FROM participants"); + $nb_participant = mysql_fetch_row($res_SQL); + + return $config->get('nb_max_participant') - $nb_participant[0]; } } diff --git a/php/config.php b/php/config.php index c7f5ee5..3ae649f 100644 --- a/php/config.php +++ b/php/config.php @@ -1,4 +1,4 @@ - +$config = new Config(); +?> diff --git a/php/config_bd.php b/php/config_bd.php index 10e53f8..4b52821 100644 --- a/php/config_bd.php +++ b/php/config_bd.php @@ -1,7 +1,8 @@ - + + \ No newline at end of file diff --git a/php/connexion.php b/php/connexion.php index 0701270..fc3b050 100644 --- a/php/connexion.php +++ b/php/connexion.php @@ -1,18 +1,44 @@ -'); + fclose($f); + echo "Le fichier a été créé, veuillez le compléter et recommencer."; + exit(); +} + include_once("config_bd.php"); -include_once("class_participant.php"); +include_once("class_participant.php"); $lien_mysql = mysql_connect($SQL_HOTE, $SQL_LOGIN, $SQL_PASS); -mysql_select_db($NOM_BASE); -mysql_set_charset("UTF8"); +if (!$lien_mysql || !mysql_select_db($NOM_BASE)) +{ + echo "Connexion à la base de données impossible. Voir le fichier 'php/config_bd.php'"; + exit(); +} + +mysql_set_charset("UTF8"); mysql_query('SET AUTOCOMMIT=0'); -if (isset($_POST['effacer_cookie'])) # le membre se délogue +if (isset($_POST['effacer_cookie'])) # le membre se délogue { setcookie("COOKIE_INFO_PATICIPANT", "", time() - 100); # 'efface' le cookie membre unset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]); @@ -27,13 +53,13 @@ if (isset($_POST['log'])) # le membre se logue setcookie ("COOKIE_INFO_PATICIPANT", $le_participant->info->id, time() + 31104000); } } -else if (isset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"])) # le cookie existe deja chez le participant +else if (isset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"])) # le cookie existe deja chez le participant { - $le_participant = new Participant($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]); + $le_participant = new Participant($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]); } -else +else { - $le_participant = new Participant(); + $le_participant = new Participant(); } ?> \ No newline at end of file -- 2.43.0