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