Statistiques
| Branche: | Révision :

root / index.php @ dfb6ddbf80a95f26af07817ecbe9864ed1dd848e

Historique | Voir | Annoter | Télécharger (8,31 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îne de caractère 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
        $demi_jour = $_POST['demi_jour'];
73
        getConges("datas", $employes, $conges);
74
        if ($_POST['action'] == 'add') {
75
                if (!$conges[$nom] || !in_array($str_date, $conges[$nom])) {
76
                        $conges[$nom][] = $str_date.($demi_jour ? " $demi_jour" : "");
77
                        setConges('datas', $nom, $conges);
78
                }
79
        } elseif ($_POST['action'] == 'delete') {
80
                if ($conges[$nom] && in_array($str_date, $conges[$nom])) {
81
                        $key = array_search($str_date, $conges[$nom]);
82
                        unset($conges[$nom][$key]);
83
                        setConges('datas', $nom, $conges);
84
                }
85
        }
86
87
        $vue = $_GET['vue'];
88
        $date = $_GET['date'];
89
        if (!$date) {
90
                $ts = time();
91
        } else {
92
                $ts = strtotime($date);
93
        }
94
95
        switch ($_GET['action']) {
96
                case '<<':
97
                        $ts = strtotime("-1 month", $ts);
98
                        break;
99
                case '>>':
100
                        $ts = strtotime("+1 month", $ts);
101
                        break;
102
                case 'mois':
103
                case 'trimestre':
104
                case 'année':
105
                        $vue = $_GET['action'];
106
                        break;
107
        }
108
109
        if (!$vue) $vue = "mois";
110
        $date = date("Y/m/d", $ts);
111
112
        /*
113
        echo "<pre>\n";
114
        print_r($_POST);
115
        //print_r($employes);
116
        print_r($conges);
117
        echo "</pre>\n";
118
        */
119
120
?>
121
<html>
122
<head>
123
        <title>Gestion de cong&eacute;s</title>
124
        <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
125
        <meta http-equiv="Content-language" content="fr" />
126
        <meta name="copyright" content="Tous droits réservés - All Rights Reserved" />
127
        <meta name="author" content="Romuald DELAVERGNE">
128
        <script language=JavaScript>
129
                function updateConges(jour, nom, str_date) {
130
                        if (jour.style.backgroundColor == 'white') {
131
                                //jour.style.backgroundColor='lightblue';
132
                                document.forms["update"].action.value = 'add';
133
                        } else {
134
                                //jour.style.backgroundColor='white';
135
                                document.forms["update"].action.value = 'delete';
136
                        }
137
                        document.forms["update"].nom.value = nom;
138
                        document.forms["update"].str_date.value = str_date;
139
                        document.forms["update"].submit();
140
                }
141
        </script>
142
</head>
143
<html>
144
<body>
145
        <form id="update" method="post">
146
                <input type="hidden" name="nom" value="" />
147
                <input type="hidden" name="str_date" value="" />
148
                <input type="hidden" name="action" value="" />
149
                <select name="demi_jour">
150
                        <option value=""></option>
151
                        <option value="AM">AM</option>
152
                        <option value="PM">PM</option>
153
                </select>
154
        </form>
155
        <form method="get">
156
                <input type="hidden" name="date" value="<?=$date?>" />
157
                <input type="hidden" name="vue" value="<?=$vue?>" />
158
        <table>
159
        <tr>
160
                <td align="left"><input type="submit" name="action" value="<<" /></td>
161
                <td align="center">
162
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="mois"> |
163
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="trimestre"> |
164
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="ann&eacute;e">
165
                <td align="right"><input type="submit" name="action" value=">>" /></td>
166
        </tr>
167
<?php
168
        for ($v = 0; $v == 0 || ($vue == "trimestre" && $v < 3) || ($vue == "année" && $v < 12); $v++) {
169
                $ts2 = strtotime("+$v month", $ts);
170
                $date_annee = date("Y", $ts2);
171
                $date_mois = date("m", $ts2);
172
                $nom_mois = date("F", $ts2);
173
                $nb_jours = date("t", $ts2);
174
?>
175
        <tr><td colspan="3">
176
        <table border="1" width="100%">
177
                <tr>
178
                        <th rowspan="2">&nbsp;</th>
179
                        <th colspan="<?=2*$nb_jours?>" align="center"><?=$nom_mois?> <?=$date_annee?></th>
180
                </tr>
181
                <tr>
182
<?php for ($n = 1; $n <= $nb_jours; $n++) { ?>
183
                        <th colspan="2"><?=sprintf("%02d", $n)?></th>
184
<?php } ?>
185
                </tr>
186
<?php foreach ($employes as $nom) { ?>
187
                <tr>
188
                        <td align="right"><?=$nom?></td>
189
<?php for ($n = 1; $n <= $nb_jours; $n++) {
190
                                $date_jour = sprintf("%02d", $n);
191
                                $str_date = "$date_annee/$date_mois/$date_jour";
192
                                $ts3 = strtotime($str_date);
193
                                $jour_semaine = date("w", $ts3);
194
                                $libOnClick = "";
195
                                $libTitle = "";
196
                                $day = "";
197
                                if (($libFerie = jourFeries($ts3))) {
198
                                        $color = "gray";
199
                                        $libTitle = " title=\"$libFerie\"";
200
                                } elseif ($jour_semaine == 0 || $jour_semaine == 6) {
201
                                        $color = "lightgray";
202
                                } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) {
203
                                        $color = "blue";
204
                                        $day = "congé";
205
                                        $libOnClick = " onClick=\"updateConges(this, '$nom', '$str_date')\"";
206
                                } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom]) && in_array("$str_date PM", $conges[$nom])) {
207
                                        $color = "blue";
208
                                        $day = "congé AP";
209
                                } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom])) {
210
                                        $color = "blue";
211
                                        $day = "congé AM";
212
                                } else if (isset($conges[$nom]) && in_array("$str_date PM", $conges[$nom])) {
213
                                        $color = "blue";
214
                                        $day = "congé PM";
215
                                } else {
216
                                        $color = "white";
217
                                        $libOnClick = " onClick=\"updateConges(this, '$nom', '$str_date')\"";
218
                                }
219
?>
220
<?php
221
                                if ($day == "congé AM") {
222
?>
223
                        <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')">&nbsp;</td>
224
                        <td style="cursor: pointer; background-color: white" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')">&nbsp;</td>
225
<?php         } elseif ($day == "congé PM") { ?>
226
                        <td style="cursor: pointer; background-color: white" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')">&nbsp;</td>
227
                        <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')">&nbsp;</td>
228
<?php         } elseif ($day == "congé AP") { ?>
229
                        <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')">&nbsp;</td>
230
                        <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')">&nbsp;</td>
231
<?php         } else {?>
232
                        <td colspan="2" style="cursor: pointer; background-color: <?=$color?>"<?=$libOnClick?><?=$libTitle?>>&nbsp;</td>
233
<?php         } ?>
234
<?php } ?>
235
                </tr>
236
<?php
237
        }
238
?>
239
        </td></tr>
240
        </table>
241
<?php
242
        }
243
?>
244
        </table>
245
        </form>
246
</body>
247
</html>