root / index.php @ 41e59592d2c2274b7aa047a3985034d9d06219ea
Historique | Voir | Annoter | Télécharger (11,1 ko)
1 | <?php
|
---|---|
2 | /*
|
3 | * index.php - Visualisation des congés |
4 | * Copyright (C) 2011 Romuald DELAVERGNE <delavergne@free.fr> |
5 | * |
6 | * This source code is licensed under the GNU General Public License, |
7 | * Version 2. See the file COPYING for more details. |
8 | * |
9 | * Le système de fichiers doit être au même encodage |
10 | * que les chaînes de caractères de PHP (default_charset). |
11 | */ |
12 | |
13 | function jourFeries($ts) { |
14 | $annee = date("Y", $ts); |
15 | $mois = date("m", $ts); |
16 | $jour = date("d", $ts); |
17 | if ($mois == "01" && $jour == "01") return "jour de l'an"; |
18 | if ($mois == "05" && $jour == "01") return "fête du travail"; |
19 | if ($mois == "05" && $jour == "08") return "victoire 1945"; |
20 | if ($mois == "07" && $jour == "14") return "fête Nationale"; |
21 | if ($mois == "08" && $jour == "15") return "l'Assomption"; |
22 | if ($mois == "11" && $jour == "01") return "la Toussaint"; |
23 | if ($mois == "11" && $jour == "11") return "armistice 1918"; |
24 | if ($mois == "12" && $jour == "25") return "Noël"; |
25 | $tsPaques = easter_date($annee); |
26 | if ($mois == date("m", $tsPaques) && $jour == date("d", $tsPaques)) return "Pâques"; |
27 | $ts = strtotime("-7 days", $tsPaques); |
28 | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "les Rameaux"; |
29 | $ts = strtotime("+1 day", $tsPaques); |
30 | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "lundi de Pâques"; |
31 | $ts = strtotime("+39 days", $tsPaques); |
32 | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "l'Ascension"; |
33 | $ts = strtotime("+49 days", $tsPaques); |
34 | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "la Pentecôte"; |
35 | $ts = strtotime("+50 days", $tsPaques); |
36 | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "lundi de Pentecôte"; |
37 | return ""; |
38 | } |
39 | |
40 | function getConges($path, &$employes, &$conges) { |
41 | $employes = array(); |
42 | $conges = array(); |
43 | if ($dir = opendir($path)) { |
44 | while (($file = readdir($dir)) !== FALSE) { |
45 | if (is_file("$path/$file")) { |
46 | $employes[] = $file; |
47 | $dates = file("$path/$file"); |
48 | foreach ($dates as $date) $conges[$file][] = rtrim($date); |
49 | } |
50 | } |
51 | closedir($dir); |
52 | } |
53 | } |
54 | |
55 | function setConges($path, $nom, $conges) { |
56 | $fh = @fopen("$path/$nom", 'w'); |
57 | if ($fh) { |
58 | if ($conges[$nom]) { |
59 | asort($conges[$nom]); |
60 | foreach ($conges[$nom] as $str_date) { |
61 | fwrite($fh, "$str_date\n"); |
62 | } |
63 | } |
64 | fclose($fh); |
65 | } else {
|
66 | echo "ERROR d'écriture dans $path/$nom"; |
67 | } |
68 | } |
69 | |
70 | $str_date = $_POST['str_date']; |
71 | $nom = $_POST['nom']; |
72 | getConges("datas", $employes, $conges); |
73 | if ($_POST['action'] == 'add') { |
74 | if (!$conges[$nom] || !in_array($str_date, $conges[$nom])) { |
75 | if ($conges[$nom]) { |
76 | # On supprime l'autre demi-journée au cas où
|
77 | $key = array_search("$str_date AM", $conges[$nom]); |
78 | if ($key !== FALSE) unset($conges[$nom][$key]); |
79 | $key = array_search("$str_date PM", $conges[$nom]); |
80 | if ($key !== FALSE) unset($conges[$nom][$key]); |
81 | } |
82 | $conges[$nom][] = $str_date; |
83 | setConges('datas', $nom, $conges); |
84 | } |
85 | } elseif ($_POST['action'] == 'del') { |
86 | if ($conges[$nom] && in_array($str_date, $conges[$nom])) { |
87 | $key = array_search($str_date, $conges[$nom]); |
88 | unset($conges[$nom][$key]); |
89 | setConges('datas', $nom, $conges); |
90 | } |
91 | } |
92 | |
93 | $tsNow = time(); |
94 | $dateNow = date("Y/m/d", $tsNow); |
95 | |
96 | $vue = $_GET['vue']; |
97 | if (!$vue) $vue = "mois"; |
98 | |
99 | $dateCurrent = $_GET['date']; |
100 | if (!$dateCurrent) { |
101 | $tsCurrent = strtotime(date("Y/m/01", $tsNow)); |
102 | } else {
|
103 | $tsCurrent = strtotime(date("Y/m/01", strtotime($dateCurrent))); |
104 | } |
105 | |
106 | switch ($_GET['action']) { |
107 | case '<<': |
108 | $tsCurrent = strtotime("-1 month", $tsCurrent); |
109 | break;
|
110 | case '>>': |
111 | $tsCurrent = strtotime("+1 month", $tsCurrent); |
112 | break;
|
113 | } |
114 | |
115 | switch ($vue) { |
116 | case "trimestre": |
117 | $nbMois = 3; |
118 | $dateDeb = date("Y/m/01", strtotime("-1 month", $tsCurrent)); |
119 | break;
|
120 | case "année": |
121 | $nbMois = 12; |
122 | $dateDeb = date("Y/01/01", $tsCurrent); |
123 | break;
|
124 | case "mois": |
125 | default:
|
126 | $nbMois = 1; |
127 | $dateDeb = date("Y/m/01", $tsCurrent); |
128 | break;
|
129 | } |
130 | $dateCurrent = date("Y/m/d", $tsCurrent); |
131 | |
132 | /*
|
133 | echo "<pre>\n"; |
134 | print_r($_POST); |
135 | //print_r($employes); |
136 | print_r($conges); |
137 | echo "</pre>\n"; |
138 | */ |
139 | |
140 | ?>
|
141 | <html>
|
142 | <head>
|
143 | <title>Gestion de congés</title> |
144 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
145 | <meta http-equiv="Content-language" content="fr" /> |
146 | <meta name="copyright" content="Tous droits réservés - All Rights Reserved" /> |
147 | <meta name="author" content="Romuald DELAVERGNE"> |
148 | <style type="text/css"> |
149 | a.button:link, a.button:visited { |
150 | float: left; |
151 | padding: 2px; |
152 | width: 50px; |
153 | border-top: 1px solid #cccccc; |
154 | border-bottom: 1px solid black; |
155 | border-left: 1px solid #cccccc; |
156 | border-right: 1px solid black; |
157 | background: #cccccc; |
158 | text-align: center; |
159 | text-decoration: none; |
160 | color: black; |
161 | } |
162 | |
163 | a.button:hover { |
164 | background: #eeeeee; |
165 | } |
166 | |
167 | a.button:active { |
168 | border-bottom: 1px solid #eeeeee; |
169 | border-top: 1px solid black; |
170 | border-right: 1px solid #eeeeee; |
171 | border-left: 1px solid black; |
172 | } |
173 | |
174 | a.popupmenu { |
175 | display: block; |
176 | width: 100%; |
177 | background-color: white; |
178 | color: black; |
179 | text-decoration: none; |
180 | text-align: center; |
181 | font-family: Arial, Helvetica, sans-serif; |
182 | font-weight: bold; |
183 | cursor: pointer; |
184 | } |
185 | a.popupmenu:hover { |
186 | background-color: gray; |
187 | color: white; |
188 | } |
189 | </style>
|
190 | <script language=JavaScript> |
191 | var ie = document.all; |
192 | var ns6 = document.getElementById&&!document.all; |
193 | var isMenu = false; |
194 | var overpopupmenu = false; |
195 | var selectNom = ''; |
196 | var selectDate = ''; |
197 | |
198 | function $(id) { |
199 | return document.getElementById(id); |
200 | } |
201 | |
202 | function updateConges(nom, str_date, action) { |
203 | document.forms["update"].action.value = action; |
204 | document.forms["update"].nom.value = nom; |
205 | document.forms["update"].str_date.value = str_date; |
206 | document.forms["update"].submit(); |
207 | } |
208 | |
209 | function mouseSelect(e) { |
210 | var evt = e || window.event; |
211 | var obj = ns6 ? evt.target.parentNode : evt.srcElement.parentElement; |
212 | if (isMenu) { |
213 | if (overpopupmenu == false) { |
214 | isMenu = false; |
215 | overpopupmenu = false; |
216 | $('popupMenu').style.display = "none"; |
217 | if (obj.id == 'AM' || obj.id == 'PM' ) { |
218 | updateConges(selectNom, selectDate+' '+obj.id, 'add'); |
219 | } |
220 | selectNom = ''; |
221 | selectDate = ''; |
222 | return true; |
223 | } |
224 | return true; |
225 | } |
226 | return false; |
227 | } |
228 | |
229 | function ItemSelMenu(e, nom, strDate) { |
230 | var evt = e || window.event; |
231 | var obj = ns6 ? evt.target : evt.srcElement; |
232 | if (obj.className != 'menu') return false; |
233 | if (ns6) { |
234 | $('popupMenu').style.left = evt.clientX+document.body.scrollLeft; |
235 | $('popupMenu').style.top = evt.clientY+document.body.scrollTop; |
236 | } else { |
237 | $('popupMenu').style.pixelLeft = event.clientX + document.body.scrollLeft; |
238 | $('popupMenu').style.pixelTop = event.clientY + document.body.scrollTop; |
239 | } |
240 | $('popupMenu').style.display = ""; |
241 | $('AM').style.backgroundColor = 'white'; |
242 | $('PM').style.backgroundColor = 'white'; |
243 | $('annuler').style.backgroundColor = 'white'; |
244 | isMenu = true; |
245 | selectNom = nom; |
246 | selectDate = strDate; |
247 | return false; |
248 | } |
249 | |
250 | document.onmousedown = mouseSelect; |
251 | </script>
|
252 | </head>
|
253 | <html>
|
254 | <body>
|
255 | <form id="update" method="post"> |
256 | <input type="hidden" name="nom" value="" /> |
257 | <input type="hidden" name="str_date" value="" /> |
258 | <input type="hidden" name="action" value="" /> |
259 | </form>
|
260 | <table>
|
261 | <tr>
|
262 | <td><a class="button" title="<?=$vue?> précédent<?=$vue=="année" ? "e" : ""?>" href="?date=<?=date("Y/m/01", strtotime("-$nbMois month", $tsCurrent))?>&vue=<?=$vue?>"><<</a></td> |
263 | <td align="center"> |
264 | <a href="?date=<?=$dateCurrent?>&vue=mois">mois</a> | |
265 | <a href="?date=<?=$dateCurrent?>&vue=trimestre">trimestre</a> | |
266 | <a href="?date=<?=$dateCurrent?>&vue=année">année</a> |
267 | <td><a class="button" title="<?=$vue?> suivant<?=$vue=="année" ? "e" : ""?>" style="float: right" href="?date=<?=date("Y/m/01", strtotime("+$nbMois month", $tsCurrent))?>&vue=<?=$vue?>">>></a></td> |
268 | </tr>
|
269 | <?php
|
270 | for ($v = 0; $v < $nbMois; $v++) { |
271 | $ts = strtotime("+$v month", strtotime($dateDeb)); |
272 | $date_annee = date("Y", $ts); |
273 | $date_mois = date("m", $ts); |
274 | $nom_mois = date("F", $ts); |
275 | $nb_jours = date("t", $ts); |
276 | ?>
|
277 | <tr><td colspan="3"> |
278 | <table border="1" width="100%"> |
279 | <tr>
|
280 | <th rowspan="2"> </th> |
281 | <th colspan="<?=2*$nb_jours?>" align="center"><a href="?date=<?=$date_annee?>/<?=$date_mois?>/01&vue=<?=$vue?>"><?=$nom_mois?> <?=$date_annee?></a></th> |
282 | </tr>
|
283 | <tr>
|
284 | <?php for ($n = 1; $n <= $nb_jours; $n++) { |
285 | $date_jour = sprintf("%02d", $n); |
286 | $str_date = "$date_annee/$date_mois/$date_jour"; |
287 | $bgColor = ($str_date == $dateNow) ? "red" : "white"; |
288 | ?>
|
289 | <th colspan="2" bgcolor="<?=$bgColor?>"><?=$date_jour?></th> |
290 | <?php } ?> |
291 | </tr>
|
292 | <?php foreach ($employes as $nom) { ?> |
293 | <tr>
|
294 | <td align="right"><?=$nom?></td> |
295 | <?php for ($n = 1; $n <= $nb_jours; $n++) { |
296 | $date_jour = sprintf("%02d", $n); |
297 | $str_date = "$date_annee/$date_mois/$date_jour"; |
298 | $ts3 = strtotime($str_date); |
299 | $jour_semaine = date("w", $ts3); |
300 | $libOnClick = ""; |
301 | $libTitle = ""; |
302 | $menu = ""; |
303 | if (($libFerie = jourFeries($ts3))) { |
304 | $color = "gray"; |
305 | $libTitle = " title=\"$libFerie\""; |
306 | } elseif ($jour_semaine == 0 || $jour_semaine == 6) { |
307 | $color = "lightgray"; |
308 | } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) { |
309 | $color = "blue"; |
310 | $libOnClick = " onClick=\"updateConges('$nom', '$str_date', 'del')\""; |
311 | } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom])) { |
312 | $colorAM = "blue"; |
313 | $colorPM = "white"; |
314 | $libOnClickAM = " onClick=\"updateConges('$nom', '$str_date AM', 'del')\""; |
315 | $libOnClickPM = " onClick=\"updateConges('$nom', '$str_date', 'add')\""; |
316 | } else if (isset($conges[$nom]) && in_array("$str_date PM", $conges[$nom])) { |
317 | $colorAM = "white"; |
318 | $colorPM = "blue"; |
319 | $libOnClickAM = " onClick=\"updateConges('$nom', '$str_date', 'add')\""; |
320 | $libOnClickPM = " onClick=\"updateConges('$nom', '$str_date PM', 'del')\""; |
321 | } else {
|
322 | $color = "white"; |
323 | $libOnClick = " onClick=\"updateConges('$nom', '$str_date', 'add')\""; |
324 | $menu = " class=\"menu\" onContextMenu=\"ItemSelMenu(event, '$nom', '$str_date'); return false;\""; |
325 | } |
326 | ?>
|
327 | <?php
|
328 | if (isset($conges[$nom]) && (in_array("$str_date AM", $conges[$nom]) || in_array("$str_date PM", $conges[$nom]))) { |
329 | ?>
|
330 | <td style="cursor: pointer; background-color: <?=$colorAM?>"<?=$libOnClickAM?><?=$libTitle?>> </td> |
331 | <td style="cursor: pointer; background-color: <?=$colorPM?>"<?=$libOnClickPM?><?=$libTitle?>> </td> |
332 | <?php } else {?> |
333 | <td colspan="2" style="cursor: pointer; background-color: <?=$color?>"<?=$libOnClick?><?=$menu?><?=$libTitle?>> </td> |
334 | <?php } ?> |
335 | <?php } ?> |
336 | </tr>
|
337 | <?php
|
338 | } |
339 | ?>
|
340 | </td></tr> |
341 | </table>
|
342 | <?php
|
343 | } |
344 | ?>
|
345 | </table>
|
346 | <div id="popupMenu" style="position: absolute; display: none; top: 0px; left: 0px; z-index: 10000;" onMouseOver="javascript:overPopupMenu=true;" onMouseOut="javascript:overPopupMenu=false;"> |
347 | <table border="0" bgcolor="lightgray"> |
348 | <tr><td id="AM"><a class="popupmenu" href="#">Matin</a></td></tr> |
349 | <tr><td id="PM"><a class="popupmenu" href="#">Après-midi</a></td></tr> |
350 | <tr><td id="annuler"><a class="popupmenu" href="#">Annuler</a></td></tr> |
351 | </table>
|
352 | </div>
|
353 | </body>
|
354 | </html>
|