X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=php%2Fparticipant.php;h=e940f74854c03dc2f59c16bfc922bcf230f548c8;hb=424a8f0a34fc72fe64daaac4686f991a298933a3;hp=7e549e12b64eef94441bb659d2d2a83b06ab231f;hpb=117b0123aca7e5f286289975b8fc56371192fb12;p=cl7.git diff --git a/php/participant.php b/php/participant.php index 7e549e1..e940f74 100644 --- a/php/participant.php +++ b/php/participant.php @@ -6,7 +6,8 @@ class Participant { public $info; # Toute les infos du membre sous la forme d'un objet. - public $valide; # Savoir si le participant existe. + + private $id = 0; static private $NB_VOTES_PAR_PARTICIPANT = 3; # Concerne les votes des jeux joueés. @@ -15,42 +16,66 @@ class Participant * 1) $v1 = NULL, $v2 = NULL : participant non-valide * 2) $v1 = id, $v2 = NULL : la participant existe et est chargé à partir de son id * 3) $v1 = pseudo, $v2 = password : le participant existe et est chargé à partir de son pseudo et de son password + * Le mot de passe est donné en clair. */ - function Participant($v1=NULL, $v2=NULL) + 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) - { - $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 - $res = mysql_query("SELECT * FROM participants WHERE pseudo = '" . addslashes($v1) . "' AND password = '" . addslashes($v2) . "'"); + { + $res = pg_query_params("SELECT id FROM participants WHERE pseudo = $1 AND password = $2", array($v1, sha1($v2))); + } else # Sinon c'est l'id - $res = mysql_query("SELECT * FROM participants WHERE id = " . addslashes($v1)); + $res = pg_query_params("SELECT id FROM participants WHERE id = $1", array($v1)); - if (mysql_error() || mysql_num_rows($res) == 0) + if (pg_result_status($res) == PGSQL_TUPLES_OK && pg_num_rows($res) === 1) { - $this->valide = FALSE; + $this->id = pg_fetch_object($res)->id; + $this->chargerInfos(); } + } + + public function chargerInfos($v1=NULL, $v2=NULL) + { + $this->authentifier($v1, $v2); + + if (!$this->existe()) + return; + + $res = pg_query_params("SELECT * FROM participants WHERE id = $1", array($this->id)); + + if (pg_result_status($res) == PGSQL_TUPLES_OK && pg_num_rows($res) === 1) + $this->info = pg_fetch_object($res); else - { - $this->info = mysql_fetch_object($res); - $this->valide = TRUE; - } - } + $this->id = 0; + } /** * Renvoie le nombre de votes restant pour le participant. */ function nb_vote_restant() { - $nombre_de_vote = mysql_fetch_array(mysql_query(" + $nombre_de_vote = pg_fetch_array(pg_query_params(" SELECT COUNT(*) FROM participants RIGHT JOIN jeux_choisis ON participants.id = jeux_choisis.participant_id - WHERE participants.id = " . $this->info->id . " + WHERE participants.id = $1 GROUP BY participants.id - ")); + ", array($this->id))); return Participant::$NB_VOTES_PAR_PARTICIPANT - $nombre_de_vote[0]; } @@ -60,11 +85,7 @@ class Participant */ 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'); + return Participant::nombre_place_restante() <= 0; } /** @@ -73,8 +94,8 @@ class Participant static function nombre_place_restante() { global $config; - $res_SQL = mysql_query("SELECT COUNT(*) FROM participants"); - $nb_participant = mysql_fetch_row($res_SQL); + $res_SQL = pg_query("SELECT COUNT(*) FROM participants"); + $nb_participant = pg_fetch_row($res_SQL); return $config->get('nb_max_participant') - $nb_participant[0]; }