Statistiques
| Branche: | Révision :

root / index.php @ 0acd179274bea62b8150a4e8192b3321c90e721d

Historique | Voir | Annoter | Télécharger (10,49 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&ecirc;te du travail";
19
                if ($mois == "05" && $jour == "08") return "victoire 1945";
20
                if ($mois == "07" && $jour == "14") return "f&ecirc;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&euml;l";
25
                $tsPaques = easter_date($annee);
26
                if ($mois == date("m", $tsPaques) && $jour == date("d", $tsPaques)) return "P&acirc;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&acirc;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&ocirc;te";
35
                $ts = strtotime("+50 days", $tsPaques);
36
                if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "lundi de Pentec&ocirc;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
                        $dateDeb = date("Y/m/01", strtotime("-1 month", $tsCurrent));
118
                        break;
119
                case "année":
120
                        $dateDeb = date("Y/01/01", $tsCurrent);
121
                        break;
122
                case "mois":
123
                default:
124
                        $dateDeb = date("Y/m/01", $tsCurrent);
125
                        break;
126
        }
127
        $dateCurrent = date("Y/m/d", $tsCurrent);
128
129
        /*
130
        echo "<pre>\n";
131
        print_r($_POST);
132
        //print_r($employes);
133
        print_r($conges);
134
        echo "</pre>\n";
135
        */
136
137
?>
138
<html>
139
<head>
140
        <title>Gestion de cong&eacute;s</title>
141
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
142
        <meta http-equiv="Content-language" content="fr" />
143
        <meta name="copyright" content="Tous droits réservés - All Rights Reserved" />
144
        <meta name="author" content="Romuald DELAVERGNE">
145
        <style type="text/css">
146
                a.popupmenu {
147
                        display: block;
148
                        width: 100%;
149
                        background-color: white;
150
                        color: black;
151
                        text-decoration: none;
152
                        text-align: center;
153
                        font-family: Arial, Helvetica, sans-serif;
154
                        font-weight: bold;
155
                        cursor: pointer;
156
                }
157
                a.popupmenu:hover {
158
                        background-color: gray;
159
                        color: white;
160
                }
161
        </style>
162
        <script language=JavaScript>
163
                var ie = document.all;
164
                var ns6 = document.getElementById&&!document.all;
165
                var isMenu = false;
166
                var overpopupmenu = false;
167
                var selectNom = '';
168
                var selectDate = '';
169
170
                function $(id) {
171
                        return document.getElementById(id);
172
                }
173
174
                function updateConges(nom, str_date, action) {
175
                        document.forms["update"].action.value = action;
176
                        document.forms["update"].nom.value = nom;
177
                        document.forms["update"].str_date.value = str_date;
178
                        document.forms["update"].submit();
179
                }
180
181
                function mouseSelect(e) {
182
                        var evt = e || window.event;
183
                        var obj = ns6 ? evt.target.parentNode : evt.srcElement.parentElement;
184
                        if (isMenu) {
185
                                if (overpopupmenu == false) {
186
                                        isMenu = false;
187
                                        overpopupmenu = false;
188
                                        $('popupMenu').style.display = "none";
189
                                        if (obj.id == 'AM' || obj.id == 'PM' ) {
190
                                                updateConges(selectNom, selectDate+' '+obj.id, 'add');
191
                                        }
192
                                        selectNom = '';
193
                                        selectDate = '';
194
                                        return true;
195
                                }
196
                                return true;
197
                        }
198
                        return false;
199
                }
200
201
                function ItemSelMenu(e, nom, strDate) {
202
                        var evt = e || window.event;
203
                        var obj = ns6 ? evt.target : evt.srcElement;
204
                        if (obj.className != 'menu') return false;
205
                        if (ns6) {
206
                                $('popupMenu').style.left = evt.clientX+document.body.scrollLeft;
207
                                $('popupMenu').style.top = evt.clientY+document.body.scrollTop;
208
                        } else {
209
                                $('popupMenu').style.pixelLeft = event.clientX + document.body.scrollLeft;
210
                                $('popupMenu').style.pixelTop = event.clientY + document.body.scrollTop;
211
                        }
212
                        $('popupMenu').style.display = "";
213
                        $('AM').style.backgroundColor = 'white';
214
                        $('PM').style.backgroundColor = 'white';
215
                        $('annuler').style.backgroundColor = 'white';
216
                        isMenu = true;
217
                        selectNom = nom;
218
                        selectDate = strDate;
219
                        return false;
220
                }
221
222
                document.onmousedown = mouseSelect;
223
        </script>
224
</head>
225
<html>
226
<body>
227
        <form id="update" method="post">
228
                <input type="hidden" name="nom" value="" />
229
                <input type="hidden" name="str_date" value="" />
230
                <input type="hidden" name="action" value="" />
231
        </form>
232
        <form method="get">
233
                <input type="hidden" name="date" value="<?=$dateCurrent?>" />
234
                <input type="hidden" name="vue" value="<?=$vue?>" />
235
        <table>
236
        <tr>
237
                <td align="left"><input type="submit" name="action" value="<<" /></td>
238
                <td align="center">
239
                        <a href="?date=<?=$dateCurrent?>&vue=mois">mois</a> |
240
                        <a href="?date=<?=$dateCurrent?>&vue=trimestre">trimestre</a> |
241
                        <a href="?date=<?=$dateCurrent?>&vue=ann&eacute;e">ann&eacute;e</a>
242
                <td align="right"><input type="submit" name="action" value=">>" /></td>
243
        </tr>
244
<?php
245
        for ($v = 0; $v == 0 || ($vue == "trimestre" && $v < 3) || ($vue == "année" && $v < 12); $v++) {
246
                $ts = strtotime("+$v month", strtotime($dateDeb));
247
                $date_annee = date("Y", $ts);
248
                $date_mois = date("m", $ts);
249
                $nom_mois = date("F", $ts);
250
                $nb_jours = date("t", $ts);
251
?>
252
        <tr><td colspan="3">
253
        <table border="1" width="100%">
254
                <tr>
255
                        <th rowspan="2">&nbsp;</th>
256
                        <th colspan="<?=2*$nb_jours?>" align="center"><a href="?date=<?=$date_annee?>/<?=$date_mois?>/01&vue=<?=$vue?>"><?=$nom_mois?> <?=$date_annee?></a></th>
257
                </tr>
258
                <tr>
259
<?php for ($n = 1; $n <= $nb_jours; $n++) {
260
                                $date_jour = sprintf("%02d", $n);
261
                                $str_date = "$date_annee/$date_mois/$date_jour";
262
                                $bgColor = ($str_date == $dateNow) ? "red" : "white";
263
?>
264
                        <th colspan="2" bgcolor="<?=$bgColor?>"><?=$date_jour?></th>
265
<?php } ?>
266
                </tr>
267
<?php foreach ($employes as $nom) { ?>
268
                <tr>
269
                        <td align="right"><?=$nom?></td>
270
<?php for ($n = 1; $n <= $nb_jours; $n++) {
271
                                $date_jour = sprintf("%02d", $n);
272
                                $str_date = "$date_annee/$date_mois/$date_jour";
273
                                $ts3 = strtotime($str_date);
274
                                $jour_semaine = date("w", $ts3);
275
                                $libOnClick = "";
276
                                $libTitle = "";
277
                                $menu = "";
278
                                if (($libFerie = jourFeries($ts3))) {
279
                                        $color = "gray";
280
                                        $libTitle = " title=\"$libFerie\"";
281
                                } elseif ($jour_semaine == 0 || $jour_semaine == 6) {
282
                                        $color = "lightgray";
283
                                } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) {
284
                                        $color = "blue";
285
                                        $libOnClick = " onClick=\"updateConges('$nom', '$str_date', 'del')\"";
286
                                } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom])) {
287
                                        $colorAM = "blue";
288
                                        $colorPM = "white";
289
                                        $libOnClickAM = " onClick=\"updateConges('$nom', '$str_date AM', 'del')\"";
290
                                        $libOnClickPM = " onClick=\"updateConges('$nom', '$str_date', 'add')\"";
291
                                } else if (isset($conges[$nom]) && in_array("$str_date PM", $conges[$nom])) {
292
                                        $colorAM = "white";
293
                                        $colorPM = "blue";
294
                                        $libOnClickAM = " onClick=\"updateConges('$nom', '$str_date', 'add')\"";
295
                                        $libOnClickPM = " onClick=\"updateConges('$nom', '$str_date PM', 'del')\"";
296
                                } else {
297
                                        $color = "white";
298
                                        $libOnClick = " onClick=\"updateConges('$nom', '$str_date', 'add')\"";
299
                                        $menu = " class=\"menu\" onContextMenu=\"ItemSelMenu(event, '$nom', '$str_date'); return false;\"";
300
                                }
301
?>
302
<?php
303
                                if (isset($conges[$nom]) && (in_array("$str_date AM", $conges[$nom]) || in_array("$str_date PM", $conges[$nom]))) {
304
?>
305
                        <td style="cursor: pointer; background-color: <?=$colorAM?>"<?=$libOnClickAM?><?=$libTitle?>>&nbsp;</td>
306
                        <td style="cursor: pointer; background-color: <?=$colorPM?>"<?=$libOnClickPM?><?=$libTitle?>>&nbsp;</td>
307
<?php         } else {?>
308
                        <td colspan="2" style="cursor: pointer; background-color: <?=$color?>"<?=$libOnClick?><?=$menu?><?=$libTitle?>>&nbsp;</td>
309
<?php         } ?>
310
<?php } ?>
311
                </tr>
312
<?php
313
        }
314
?>
315
        </td></tr>
316
        </table>
317
<?php
318
        }
319
?>
320
        </table>
321
        </form>
322
        <div id="popupMenu" style="position: absolute; display: none; top: 0px; left: 0px; z-index: 10000;" onMouseOver="javascript:overPopupMenu=true;" onMouseOut="javascript:overPopupMenu=false;">
323
                <table border="0" bgcolor="lightgray">
324
                        <tr><td id="AM"><a class="popupmenu" href="#">Matin</a></td></tr>
325
                        <tr><td id="PM"><a class="popupmenu" href="#">Apr&egrave;s-midi</a></td></tr>
326
                        <tr><td id="annuler"><a class="popupmenu" href="#">Annuler</a></td></tr>
327
                </table>
328
        </div>
329
</body>
330
</html>