+ $this->traiter_donnees_inscription();
+ if (!$this->login_deja_pris() && # vérification des données
+ $this->donnees_inscription_valides() &&
+ $_POST['accord'] == "on"
+ )
+ {
+ pg_query("BEGIN");
+
+ // Cherche un id libre.
+ // Pour des questions de sécurité, les ids ne sont pas générés sequentiellement
+ // car ils sont mémorisé dans un cookie et permette l'authentification.
+ $id = 0;
+ do
+ {
+ $id = rand(1, PHP_INT_MAX);
+ $row = pg_fetch_row(pg_query_params("SELECT count(*) FROM participants WHERE id = $1", array($id)));
+ } while ($row[0] != 0);
+
+ pg_query_params("
+ INSERT INTO participants
+ (id, pseudo, password, clan_nom, clan_tag, nom, prenom, age, e_mail, remarques)
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
+ ",
+ array(
+ $id,
+ $_POST['pseudo'],
+ sha1($_POST['pass1']),
+ $_POST['clan_nom'],
+ $_POST['clan_tag'],
+ $_POST['nom'],
+ $_POST['prenom'],
+ $_POST['age'],
+ $_POST['e_mail'],
+ $_POST['remarques'],
+ )
+ );
+
+ $this->set_periodes($id);
+ pg_query("COMMIT");
+
+ $this->participant = new participant($_POST['pseudo'], $_POST['pass1']);
+ setcookie("COOKIE_INFO_PARTICIPANT", $this->participant->info->id, time() + 31104000);
+ $this->nouvel_inscrit = TRUE;
+ }
+ }
+ # un participant modifie ses infos
+ else if(isset($_POST['modification_participant']) && $this->participant->existe())
+ {
+ if ($this->config->get("inscription_terminees"))
+ return;
+
+ $this->traiter_donnees_inscription();
+ if (!$this->login_deja_pris() && $this->donnees_inscription_valides())
+ {
+ 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));
+ 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));
+ pg_query_params("UPDATE participants SET prenom = $1 WHERE id = $2", array($_POST['prenom'], $this->participant->info->id));
+ pg_query_params("UPDATE participants SET age = $1 WHERE id = $2", array($_POST['age'], $this->participant->info->id));
+ pg_query_params("UPDATE participants SET e_mail = $1 WHERE id = $2", array($_POST['e_mail'], $this->participant->info->id));
+ pg_query_params("UPDATE participants SET remarques = $1 WHERE id = $2", array($_POST['remarques'], $this->participant->info->id));
+ $this->set_periodes($this->participant->info->id);
+ pg_query("COMMIT");
+ //header("Location: /inscrits.html");
+ $this->message_utilisateur = "Les modifications ont été enregistrées";
+
+ // Puisque les données du participant ont changés il faut les re-charger.
+ $this->participant->chargerInfos();
+ }
+ }
+ # vote pour des jeux (autorisé même lorsque les inscriptions sont terminées)
+ else if (isset($_POST['set_jeux_joues']) && $this->participant->existe() && !$config->get("inscription_terminees"))
+ {
+ $votes = $_POST['votes'];
+ if (!$votes)
+ $votes = array();
+
+ pg_query("BEGIN");
+
+ # l'utilisateur peut proposer le nom d'un jeu qui ne se trouve pas dans la liste
+ $jeu = trim($_POST['jeu']);
+ if ($jeu !== '')
+ {
+ if(@pg_query_params("INSERT INTO jeux (nom) VALUES ($1)", array($jeu)))
+ {
+ $row = pg_fetch_row(pg_query("SELECT LASTVAL()"));
+ $id = $row[0];
+ if ($id != 0) # si le jeu se trouve déjà dans la liste alors $id == 0
+ array_unshift($votes, $id);
+ }
+ else # Puisque le jeu existe déjà, on le recherche
+ {
+ pg_query("ROLLBACK");
+ pg_query("BEGIN");
+ $res = pg_query_params("SELECT id FROM jeux WHERE nom = $1", array($jeu));
+ if ($id = pg_fetch_object($res))
+ if (!in_array($id->id, $votes))
+ array_unshift($votes, $id->id);
+ }
+ }
+
+ # suppression des anciens votes (remplacement par les nouveaux)
+ pg_query_params("DELETE FROM jeux_choisis WHERE participant_id = $1", array($this->participant->info->id));
+
+ # traite les trois premiers votes
+ for ($i = 0; $i < count($votes) && $i < $this->config->get('nb_votes_jeux'); $i++)
+ {
+ pg_query_params("INSERT INTO jeux_choisis (participant_id, jeu_id) VALUES ($1, $2)", array($this->participant->info->id, (int)$votes[$i]));
+ }
+
+ pg_query("COMMIT");
+ }
+ }