Statistiques
| Branche: | Révision :

root / index.php @ 483b03436b4b832bf1086fdf442243bbe80a14de

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