Blame view

orga.php 6.98 KB
97d25235   Erwan Nanrocki   ajout d un titre ...
1
2
  <h2> Organisation </h2>
  
27f3beb9   Geoffrey Bontoux-Preud-Homme   Ajout de orga.php
3
  <?php
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
4
  
27f3beb9   Geoffrey Bontoux-Preud-Homme   Ajout de orga.php
5
6
  # DEBUG
  # e_ : est
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
7
8
9
10
  $e_connecte = false;
  $e_modo = true;
  
  $droits  = array('voir', 'voter', 'ajouter', 'proposer', 'annuler', 'supprimer', 'modifier', 'valider');
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
11
  $time = time();
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
12
13
14
  
  class Evenement
  {
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
15
16
17
      private $id = 0;
      private $creationTime = 0;
  
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
18
19
20
21
      public $nom = "Sans nom";
      public $description = "Sans description";
      public $annule = false;
      public $valide = false;
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
22
23
      public $duree = 3600;
      public $supprime = false;
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
24
25
  
      public $dates = array();
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
26
      public $datesVotes = array();
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
27
28
  
      public function html() {
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
29
30
31
32
33
34
35
          $html = '   <li class="list-group-item">';
  
          # Titre
          $html .= '<h3 class="list-group-item-heading">'.$this->nom;
          if ($this->annule) {
              $html .= ' <span class="label label-danger">Annulé</span>';
          }
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
36
          if ($this->p_annuler()) {
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
37
38
              $html .= ' <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon glyphicon-remove"></span></button>';
          }
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
39
          if ($this->p_supprimer()) {
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
40
41
42
43
44
45
46
47
              $html .= ' <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon glyphicon-trash"></span></button>';
          }
          $html .= '</h3>';
  
          # Description
          $html .= '<div class="panel panel-default">';
          $html .= '<div class="panel-heading">';
          $html .= '<h4 class="panel-title">Description';
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
48
          if ($this->p_modifier()) {
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
49
50
51
52
53
54
55
56
57
58
              $html .= ' <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></button>';
          }
          $html .= '</h4>';
          $html .= '</div>';
          $html .= '<div class="panel-body">';
          $html .= '<p>';
          $html .= nl2br(htmlspecialchars($this->description));
          $html .= '</p>';
          // $html .= '<hr/>';
          $html .= '<p>';
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
59
60
61
62
          $heures = floor($this->duree/3600);
          $minutes = floor($this->duree%3600/60);
          $secondes = floor($this->duree%3600%60);
          $html .= 'Durée : '.($heures > 0 ? $heures.' heure'.($heures > 1 ? 's' : '').' ' : '').($minutes > 0 ? $minutes.' minute'.($minutes > 1 ? 's' : '').' ' : '').($secondes > 0 ? $secondes.' seconde'.($secondes > 1 ? 's' : '').' ' : '').'<br/>';
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
63
          if ($this->valide) {
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
64
              $html .= 'Date : le '.date('j/m/o', $this->valide).' à '.date('H:i', $this->valide).'<br/>';
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
65
66
67
68
69
70
71
72
73
74
75
76
77
78
          }
          $html .= '</p>';
          if ($this->annule) {
              $html .= '<p class="alert alert-danger" role="alert">Annulé</p>';
  
          }
          $html .= '</div>';
          $html .= '</div>';
  
          # Dates
          if (!$this->valide && !$this->annule) {
              $html .= '<div class="panel panel-default">';
              $html .= '<div class="panel-heading">';
              $html .= '<h4 class="panel-title">Dates possibles';
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
79
80
              if ($this->p_proposer()) {
                  $html .= ' <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span></button>';
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
81
82
83
84
              }
              $html .= '</h4>';
              $html .= '</div>';
              $html .= '<div class="panel-body">';
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
85
86
              $html .= '<div class="list-group">';
              $time = time();
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
87
              foreach ($this->dates as $dateIndex => $date) {
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
88
89
90
91
92
                  $html .= '<a href="#"class="list-group-item';
                  if ($date < $time) {
                      $html .= ' disabled';
                  }
                  $html .= '">Le '.date('j/m/o', $date).' à '.date('H:i', $date).' ('.$this->datesVotes[$dateIndex].' <span class="glyphicon glyphicon-user"></span>)</a>';
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
93
              }
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
94
95
              $html .= '</div>';
              if ($this->p_valider()) {
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
96
97
98
99
100
101
102
103
104
                  $html .= '<p><button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-ok"></span> Valider la date</button></p>';
              }
              $html .= '</div>';
              $html .= '</div>';
          }
  
          $html .= '</li>';
          return $html;
      }
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  
      public function passe() {
          global $time;
          if ($this->valide) {
              return $this->valide+$this->duree < $time;
          } else {
              return false;
          }
      }
  
      # p_ : Il est possible de ...
      function p_annuler() {
          global $droits;
          return in_array('annuler', $droits) && !$this->annule && !$this->passe();
      }
  
      function p_supprimer() {
          global $droits;
          return in_array('supprimer', $droits) && !$this->valide;
      }
  
      function p_modifier() {
          global $droits;
          return in_array('modifier', $droits);
      }
  
      function p_proposer() {
          global $droits;
          return in_array('proposer', $droits);
      }
  
      function p_valider() {
          global $droits;
          return in_array('valider', $droits) && !$this->valide;
      }
  
  }
  
  # a_ : Récupérer depuis la base de donnée
  function a_evenement() {
      # DEBUG
      $test1 = new Evenement;
      $test1->nom = 'Évènement de test n°1';
      $test1->valide = time();
      
      $test2 = new Evenement;
      $test2->nom = 'Évènement de test n°2';
      $test2->valide = time();
      $test2->annule = true;
      
      $test3 = new Evenement;
      $test3->nom = 'Évènement de test n°3';
      $test3->dates[] = 1415482197;
      $test3->datesVotes[] = 42;
      $test3->dates[] = time();
      $test3->datesVotes[] = 5;
      $test3->dates[] = time()+365*24*3600;
      $test3->datesVotes[] = 1;
      
      $test4 = new Evenement;
      $test4->nom = 'Évènement de test n°4';
      $test4->dates[] = time();
      $test4->datesVotes[] = 5;
      $test4->dates[] = time()+365*24*3600;
      $test4->datesVotes[] = 1;
      $test4->dates[] = time();
      $test4->annule = true;
  
      $test5 = new Evenement;
      $test5->nom = 'Évènement de test n°5';
      $test5->dates[] = time();
      $test5->datesVotes[] = 0;
      $test5->supprime = true;
  
      $test6 = new Evenement;
      $test6->nom = 'Évènement de test n°6';
      $test6->valide = 1415452197;
  
      return array($test1, $test2, $test3, $test4, $test5, $test6);
  }
  
  # Tri des évènements
  $evenements = a_evenement();
  $evenementsPlanifies = array();
  $evenementsAPlanifier = array();
  $evenementsPasses = array();
  
  $time = time();
  
  foreach ($evenements as $evenement) {
      if (!$evenement->supprime) {
          if ($evenement->valide) {
              if ($evenement->passe()) {
                  $evenementsPasses[] = $evenement;
              } else {
                  $evenementsPlanifies[] = $evenement;
              }
          } else {
              $evenementsAPlanifier[] = $evenement;
          }
      }
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
206
207
  }
  
27f3beb9   Geoffrey Bontoux-Preud-Homme   Ajout de orga.php
208
  ?>
27f3beb9   Geoffrey Bontoux-Preud-Homme   Ajout de orga.php
209
  
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
210
211
212
213
214
  <h1>Évènements</h1>
  
  <h2>Plannifiés <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2>
  <ul class="list-group">
  <?
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
215
216
217
  foreach ($evenementsPlanifies as $evenement) {
      echo $evenement->html();
  }
27f3beb9   Geoffrey Bontoux-Preud-Homme   Ajout de orga.php
218
  ?>
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
219
220
  </ul>
  
27f3beb9   Geoffrey Bontoux-Preud-Homme   Ajout de orga.php
221
  
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
222
223
224
  <h2>À plannifier <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2>
  <ul class="list-group">
  <?
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
225
226
227
  foreach ($evenementsAPlanifier as $evenement) {
      echo $evenement->html();
  }
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
228
229
230
231
232
233
  ?>
  </ul>
  
  
  <h2>Évènements passés</h2>
  <ul class="list-group">
5f2f48c7   Geoffrey PREUD'HOMME   [Orga] Modificati...
234
235
236
237
238
  <?
  foreach ($evenementsPasses as $evenement) {
      echo $evenement->html();
  }
  ?>
f84e30e3   Geoffrey PREUD'HOMME   [Orga] Retravail
239
  </ul>