orga.php
6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<h2> Organisation </h2>
<?php
# DEBUG
# e_ : est
$e_connecte = false;
$e_modo = true;
$droits = array('voir', 'voter', 'ajouter', 'proposer', 'annuler', 'supprimer', 'modifier', 'valider');
$time = time();
class Evenement
{
private $id = 0;
private $creationTime = 0;
public $nom = "Sans nom";
public $description = "Sans description";
public $annule = false;
public $valide = false;
public $duree = 3600;
public $supprime = false;
public $dates = array();
public $datesVotes = array();
public function html() {
$html = ' <li class="list-group-item">';
# Titre
$html .= '<h3 class="list-group-item-heading">'.$this->nom;
if ($this->p_annuler()) {
$html .= ' <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon glyphicon-remove"></span></button>';
}
if ($this->p_supprimer()) {
$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';
if ($this->p_modifier()) {
$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>';
$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/>';
if ($this->valide) {
$html .= 'Date : le '.date('j/m/o', $this->valide).' à '.date('H:i', $this->valide).'<br/>';
}
$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';
if ($this->p_proposer()) {
$html .= ' <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span></button>';
}
$html .= '</h4>';
$html .= '</div>';
$html .= '<div class="panel-body">';
$html .= '<div class="list-group">';
$time = time();
foreach ($this->dates as $dateIndex => $date) {
$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>';
}
$html .= '</div>';
if ($this->p_valider()) {
$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;
}
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;
}
}
}
?>
<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">
<?
foreach ($evenementsPlanifies as $evenement) {
echo $evenement->html();
}
?>
</ul>
<h2>À plannifier <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2>
<ul class="list-group">
<?
foreach ($evenementsAPlanifier as $evenement) {
echo $evenement->html();
}
?>
</ul>
<h2>Évènements passés</h2>
<ul class="list-group">
<?
foreach ($evenementsPasses as $evenement) {
echo $evenement->html();
}
?>
</ul>