MOD #134
[cl7.git] / php / pages / jeux_joues.php
1 <?php # coding: utf-8
2
3 include_once("php/traitement_pre_affichage.php");
4
5 if (!$participant->existe())
6 {
7 echo '<p><em>Remarque : </em>Il faut être inscrit pour pouvoir voter.</p>';
8 }
9 else if ($config->get("inscription_terminees"))
10 {
11 echo '<p><em>Remarque : </em>Les inscriptions sont terminées, il n\'est plus possible de voter.</p>';
12 }
13
14 $vote_possible = !$config->get("inscription_terminees") && $participant->existe();
15
16 echo '
17 <form id="formulaireJeuxJoues" method="post" action="index.php?page=jeux_joues">
18 <p><input type="hidden" name="set_jeux_joues" value="1" /></p>
19 <table>
20 <tr>', ($vote_possible ? '<th></th>' : ''), '<th>Votes</th><th>Jeux</th></tr>';
21
22 # /!\ Attention, requête un poil tricky :
23 # On souhait avoir une liste des jeux joués avec pour chaque tuple :
24 # - l'id du jeu et son nom
25 # - Un tableau des participants ayant voté pour ce jeu
26 # De plus il faut que le résultat soit trié par le nombre de vote
27 $jeux_query = pg_query("
28 SELECT
29 jeux.id,
30 jeux.nom,
31 array_agg(jeux_choisis.participant_id) AS participants,
32 (COUNT(*) + (CASE WHEN bool_and(jeux_choisis.participant_id is null) THEN -1 ELSE 0 END)) as nb_vote
33 FROM
34 jeux
35 LEFT JOIN jeux_choisis ON jeux.id = jeux_choisis.jeu_id
36 GROUP BY jeux.id, jeux.nom
37 ORDER BY nb_vote DESC, jeux.nom
38 ");
39
40 while ($jeu = pg_fetch_object($jeux_query))
41 {
42 $a_vote = FALSE;
43
44 # est-ce que le participant courant à voté pour ce jeu ?
45 if ($vote_possible)
46 {
47 $participants = split(",", ereg_replace("[{-}]", "", $jeu->participants));
48 for($i = 0; $i < count($participants); $i++)
49 $participants[$i] = (int)$participants[$i];
50
51 $a_vote = in_array($participant->info->id, $participants);
52 }
53
54 echo '<tr>',
55 $vote_possible ? '<td><input type="checkbox" name="votes[]" '. ($a_vote ? 'checked="checked"' : '') .' value="'.$jeu->id.'" /></td>' : '',
56 '<td>' . $jeu->nb_vote . '</td>',
57 '<td ' . ($a_vote ? 'class="aVote" ': '').'>' . traitement_pre_affichage($jeu->nom) . '</td></tr>';
58 }
59
60 echo '
61 </table>';
62
63 if ($vote_possible)
64 echo '
65 <p>Autre : <input type="text" maxlength="50" name="jeu" /></p>
66 <p><input type="submit" value="Voter" /></p>';
67
68 echo '</form>';
69
70 # affichage du nombre de vote restant
71 if ($vote_possible)
72 echo '<p>Nombre de votes restant : ' . $participant->nb_vote_restant() . '</p>';
73
74 ?>