root / index.php @ 4b5c5da989254603c00328740d7b8041362be61d
Historique | Voir | Annoter | Télécharger (8,16 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ê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 | $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'] == 'del') { |
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é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, action) { |
130 | document.forms["update"].action.value = action; |
131 | document.forms["update"].nom.value = nom; |
132 | document.forms["update"].str_date.value = str_date; |
133 | document.forms["update"].submit(); |
134 | } |
135 | </script>
|
136 | </head>
|
137 | <html>
|
138 | <body>
|
139 | <form id="update" method="post"> |
140 | <input type="hidden" name="nom" value="" /> |
141 | <input type="hidden" name="str_date" value="" /> |
142 | <input type="hidden" name="action" value="" /> |
143 | <select name="demi_jour"> |
144 | <option value=""></option> |
145 | <option value="AM">AM</option> |
146 | <option value="PM">PM</option> |
147 | </select>
|
148 | </form>
|
149 | <form method="get"> |
150 | <input type="hidden" name="date" value="<?=$date?>" /> |
151 | <input type="hidden" name="vue" value="<?=$vue?>" /> |
152 | <table>
|
153 | <tr>
|
154 | <td align="left"><input type="submit" name="action" value="<<" /></td> |
155 | <td align="center"> |
156 | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="mois"> | |
157 | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="trimestre"> | |
158 | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="année"> |
159 | <td align="right"><input type="submit" name="action" value=">>" /></td> |
160 | </tr>
|
161 | <?php
|
162 | for ($v = 0; $v == 0 || ($vue == "trimestre" && $v < 3) || ($vue == "année" && $v < 12); $v++) { |
163 | $ts2 = strtotime("+$v month", $ts); |
164 | $date_annee = date("Y", $ts2); |
165 | $date_mois = date("m", $ts2); |
166 | $nom_mois = date("F", $ts2); |
167 | $nb_jours = date("t", $ts2); |
168 | ?>
|
169 | <tr><td colspan="3"> |
170 | <table border="1" width="100%"> |
171 | <tr>
|
172 | <th rowspan="2"> </th> |
173 | <th colspan="<?=2*$nb_jours?>" align="center"><?=$nom_mois?> <?=$date_annee?></th> |
174 | </tr>
|
175 | <tr>
|
176 | <?php for ($n = 1; $n <= $nb_jours; $n++) { ?> |
177 | <th colspan="2"><?=sprintf("%02d", $n)?></th> |
178 | <?php } ?> |
179 | </tr>
|
180 | <?php foreach ($employes as $nom) { ?> |
181 | <tr>
|
182 | <td align="right"><?=$nom?></td> |
183 | <?php for ($n = 1; $n <= $nb_jours; $n++) { |
184 | $date_jour = sprintf("%02d", $n); |
185 | $str_date = "$date_annee/$date_mois/$date_jour"; |
186 | $ts3 = strtotime($str_date); |
187 | $jour_semaine = date("w", $ts3); |
188 | $libOnClick = ""; |
189 | $libTitle = ""; |
190 | $day = ""; |
191 | if (($libFerie = jourFeries($ts3))) { |
192 | $color = "gray"; |
193 | $libTitle = " title=\"$libFerie\""; |
194 | } elseif ($jour_semaine == 0 || $jour_semaine == 6) { |
195 | $color = "lightgray"; |
196 | } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) { |
197 | $color = "blue"; |
198 | $day = "congé"; |
199 | $libOnClick = " onClick=\"updateConges(this, '$nom', '$str_date', 'del')\""; |
200 | } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom]) && in_array("$str_date PM", $conges[$nom])) { |
201 | $color = "blue"; |
202 | $day = "congé AP"; |
203 | } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom])) { |
204 | $color = "blue"; |
205 | $day = "congé AM"; |
206 | } else if (isset($conges[$nom]) && in_array("$str_date PM", $conges[$nom])) { |
207 | $color = "blue"; |
208 | $day = "congé PM"; |
209 | } else {
|
210 | $color = "white"; |
211 | $libOnClick = " onClick=\"updateConges(this, '$nom', '$str_date', 'add')\""; |
212 | } |
213 | ?>
|
214 | <?php
|
215 | if ($day == "congé AM") { |
216 | ?>
|
217 | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM', 'del')"> </td> |
218 | <td style="cursor: pointer; background-color: white" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM', 'add')"> </td> |
219 | <?php } elseif ($day == "congé PM") { ?> |
220 | <td style="cursor: pointer; background-color: white" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM', 'add')"> </td> |
221 | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM', 'del')"> </td> |
222 | <?php } elseif ($day == "congé AP") { ?> |
223 | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM', 'del')"> </td> |
224 | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM', 'del')"> </td> |
225 | <?php } else {?> |
226 | <td colspan="2" style="cursor: pointer; background-color: <?=$color?>"<?=$libOnClick?><?=$libTitle?>> </td> |
227 | <?php } ?> |
228 | <?php } ?> |
229 | </tr>
|
230 | <?php
|
231 | } |
232 | ?>
|
233 | </td></tr> |
234 | </table>
|
235 | <?php
|
236 | } |
237 | ?>
|
238 | </table>
|
239 | </form>
|
240 | </body>
|
241 | </html>
|