root / index.php @ dfb6ddbf80a95f26af07817ecbe9864ed1dd848e
Historique | Voir | Annoter | Télécharger (8,31 ko)
1 | 52a3c866 | Romuald | <?php
|
---|---|---|---|
2 | 52a3c866 | Romuald | /*
|
3 | 3a9db70f | Romuald | * index.php - Visualisation des congés |
4 | 52a3c866 | Romuald | * Copyright (C) 2011 Romuald DELAVERGNE <delavergne@free.fr> |
5 | 52a3c866 | Romuald | * |
6 | 52a3c866 | Romuald | * This source code is licensed under the GNU General Public License, |
7 | 52a3c866 | Romuald | * Version 2. See the file COPYING for more details. |
8 | e464d4d0 | Romuald | * |
9 | 3a9db70f | Romuald | * Le système de fichiers doit être au même encodage |
10 | 3a9db70f | Romuald | * que les chaîne de caractère de PHP (default_charset). |
11 | 52a3c866 | Romuald | */ |
12 | 52a3c866 | Romuald | |
13 | dfb6ddbf | Romuald | function jourFeries($ts) { |
14 | dfb6ddbf | Romuald | $annee = date("Y", $ts); |
15 | dfb6ddbf | Romuald | $mois = date("m", $ts); |
16 | dfb6ddbf | Romuald | $jour = date("d", $ts); |
17 | dfb6ddbf | Romuald | if ($mois == "01" && $jour == "01") return "jour de l'an"; |
18 | dfb6ddbf | Romuald | if ($mois == "05" && $jour == "01") return "fête du travail"; |
19 | dfb6ddbf | Romuald | if ($mois == "05" && $jour == "08") return "victoire 1945"; |
20 | dfb6ddbf | Romuald | if ($mois == "07" && $jour == "14") return "fête Nationale"; |
21 | dfb6ddbf | Romuald | if ($mois == "08" && $jour == "15") return "l'Assomption"; |
22 | dfb6ddbf | Romuald | if ($mois == "11" && $jour == "01") return "la Toussaint"; |
23 | dfb6ddbf | Romuald | if ($mois == "11" && $jour == "11") return "armistice 1918"; |
24 | dfb6ddbf | Romuald | if ($mois == "12" && $jour == "25") return "Noël"; |
25 | dfb6ddbf | Romuald | $tsPaques = easter_date($annee); |
26 | dfb6ddbf | Romuald | if ($mois == date("m", $tsPaques) && $jour == date("d", $tsPaques)) return "Pâques"; |
27 | dfb6ddbf | Romuald | $ts = strtotime("-7 days", $tsPaques); |
28 | dfb6ddbf | Romuald | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "les Rameaux"; |
29 | dfb6ddbf | Romuald | $ts = strtotime("+1 day", $tsPaques); |
30 | dfb6ddbf | Romuald | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "lundi de Pâques"; |
31 | dfb6ddbf | Romuald | $ts = strtotime("+39 days", $tsPaques); |
32 | dfb6ddbf | Romuald | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "l'Ascension"; |
33 | dfb6ddbf | Romuald | $ts = strtotime("+49 days", $tsPaques); |
34 | dfb6ddbf | Romuald | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "la Pentecôte"; |
35 | dfb6ddbf | Romuald | $ts = strtotime("+50 days", $tsPaques); |
36 | dfb6ddbf | Romuald | if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "lundi de Pentecôte"; |
37 | dfb6ddbf | Romuald | return ""; |
38 | dfb6ddbf | Romuald | } |
39 | dfb6ddbf | Romuald | |
40 | 52a3c866 | Romuald | function getConges($path, &$employes, &$conges) { |
41 | 52a3c866 | Romuald | $employes = array(); |
42 | 52a3c866 | Romuald | $conges = array(); |
43 | 52a3c866 | Romuald | if ($dir = opendir($path)) { |
44 | 52a3c866 | Romuald | while (($file = readdir($dir)) !== FALSE) { |
45 | 52a3c866 | Romuald | if (is_file("$path/$file")) { |
46 | e464d4d0 | Romuald | $employes[] = $file; |
47 | 52a3c866 | Romuald | $dates = file("$path/$file"); |
48 | 52a3c866 | Romuald | foreach ($dates as $date) $conges[$file][] = rtrim($date); |
49 | 52a3c866 | Romuald | } |
50 | 52a3c866 | Romuald | } |
51 | 52a3c866 | Romuald | closedir($dir); |
52 | 52a3c866 | Romuald | } |
53 | 52a3c866 | Romuald | } |
54 | 52a3c866 | Romuald | |
55 | 52a3c866 | Romuald | function setConges($path, $nom, $conges) { |
56 | 52a3c866 | Romuald | $fh = @fopen("$path/$nom", 'w'); |
57 | 52a3c866 | Romuald | if ($fh) { |
58 | 52a3c866 | Romuald | if ($conges[$nom]) { |
59 | 52a3c866 | Romuald | asort($conges[$nom]); |
60 | 52a3c866 | Romuald | foreach ($conges[$nom] as $str_date) { |
61 | 52a3c866 | Romuald | fwrite($fh, "$str_date\n"); |
62 | 52a3c866 | Romuald | } |
63 | 52a3c866 | Romuald | } |
64 | 52a3c866 | Romuald | fclose($fh); |
65 | 52a3c866 | Romuald | } else {
|
66 | 3a9db70f | Romuald | echo "ERROR d'écriture dans $path/$nom"; |
67 | 52a3c866 | Romuald | } |
68 | 52a3c866 | Romuald | } |
69 | 52a3c866 | Romuald | |
70 | 52a3c866 | Romuald | $str_date = $_POST['str_date']; |
71 | 52a3c866 | Romuald | $nom = $_POST['nom']; |
72 | a92b1e97 | Romuald | $demi_jour = $_POST['demi_jour']; |
73 | 52a3c866 | Romuald | getConges("datas", $employes, $conges); |
74 | 52a3c866 | Romuald | if ($_POST['action'] == 'add') { |
75 | 52a3c866 | Romuald | if (!$conges[$nom] || !in_array($str_date, $conges[$nom])) { |
76 | a92b1e97 | Romuald | $conges[$nom][] = $str_date.($demi_jour ? " $demi_jour" : ""); |
77 | 52a3c866 | Romuald | setConges('datas', $nom, $conges); |
78 | 52a3c866 | Romuald | } |
79 | 52a3c866 | Romuald | } elseif ($_POST['action'] == 'delete') { |
80 | 52a3c866 | Romuald | if ($conges[$nom] && in_array($str_date, $conges[$nom])) { |
81 | 52a3c866 | Romuald | $key = array_search($str_date, $conges[$nom]); |
82 | 52a3c866 | Romuald | unset($conges[$nom][$key]); |
83 | 52a3c866 | Romuald | setConges('datas', $nom, $conges); |
84 | 52a3c866 | Romuald | } |
85 | 52a3c866 | Romuald | } |
86 | 52a3c866 | Romuald | |
87 | 52a3c866 | Romuald | $vue = $_GET['vue']; |
88 | 52a3c866 | Romuald | $date = $_GET['date']; |
89 | 52a3c866 | Romuald | if (!$date) { |
90 | 52a3c866 | Romuald | $ts = time(); |
91 | 52a3c866 | Romuald | } else {
|
92 | 52a3c866 | Romuald | $ts = strtotime($date); |
93 | 52a3c866 | Romuald | } |
94 | 52a3c866 | Romuald | |
95 | 52a3c866 | Romuald | switch ($_GET['action']) { |
96 | 52a3c866 | Romuald | case '<<': |
97 | 52a3c866 | Romuald | $ts = strtotime("-1 month", $ts); |
98 | 52a3c866 | Romuald | break;
|
99 | 52a3c866 | Romuald | case '>>': |
100 | 52a3c866 | Romuald | $ts = strtotime("+1 month", $ts); |
101 | 52a3c866 | Romuald | break;
|
102 | 52a3c866 | Romuald | case 'mois': |
103 | 52a3c866 | Romuald | case 'trimestre': |
104 | 3a9db70f | Romuald | case 'année': |
105 | 52a3c866 | Romuald | $vue = $_GET['action']; |
106 | 52a3c866 | Romuald | break;
|
107 | 52a3c866 | Romuald | } |
108 | 52a3c866 | Romuald | |
109 | 52a3c866 | Romuald | if (!$vue) $vue = "mois"; |
110 | 52a3c866 | Romuald | $date = date("Y/m/d", $ts); |
111 | 52a3c866 | Romuald | |
112 | 52a3c866 | Romuald | /*
|
113 | 52a3c866 | Romuald | echo "<pre>\n"; |
114 | 52a3c866 | Romuald | print_r($_POST); |
115 | 52a3c866 | Romuald | //print_r($employes); |
116 | 52a3c866 | Romuald | print_r($conges); |
117 | 52a3c866 | Romuald | echo "</pre>\n"; |
118 | 52a3c866 | Romuald | */ |
119 | 52a3c866 | Romuald | |
120 | 52a3c866 | Romuald | ?>
|
121 | 52a3c866 | Romuald | <html>
|
122 | 52a3c866 | Romuald | <head>
|
123 | e464d4d0 | Romuald | <title>Gestion de congés</title> |
124 | 3a9db70f | Romuald | <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> |
125 | 52a3c866 | Romuald | <meta http-equiv="Content-language" content="fr" /> |
126 | 3a9db70f | Romuald | <meta name="copyright" content="Tous droits réservés - All Rights Reserved" /> |
127 | 52a3c866 | Romuald | <meta name="author" content="Romuald DELAVERGNE"> |
128 | 52a3c866 | Romuald | <script language=JavaScript> |
129 | 52a3c866 | Romuald | function updateConges(jour, nom, str_date) { |
130 | 52a3c866 | Romuald | if (jour.style.backgroundColor == 'white') { |
131 | 52a3c866 | Romuald | //jour.style.backgroundColor='lightblue'; |
132 | 52a3c866 | Romuald | document.forms["update"].action.value = 'add'; |
133 | 52a3c866 | Romuald | } else { |
134 | 52a3c866 | Romuald | //jour.style.backgroundColor='white'; |
135 | 52a3c866 | Romuald | document.forms["update"].action.value = 'delete'; |
136 | 52a3c866 | Romuald | } |
137 | 52a3c866 | Romuald | document.forms["update"].nom.value = nom; |
138 | 52a3c866 | Romuald | document.forms["update"].str_date.value = str_date; |
139 | 52a3c866 | Romuald | document.forms["update"].submit(); |
140 | 52a3c866 | Romuald | } |
141 | 52a3c866 | Romuald | </script>
|
142 | 52a3c866 | Romuald | </head>
|
143 | 52a3c866 | Romuald | <html>
|
144 | 52a3c866 | Romuald | <body>
|
145 | 52a3c866 | Romuald | <form id="update" method="post"> |
146 | 52a3c866 | Romuald | <input type="hidden" name="nom" value="" /> |
147 | 52a3c866 | Romuald | <input type="hidden" name="str_date" value="" /> |
148 | 52a3c866 | Romuald | <input type="hidden" name="action" value="" /> |
149 | a92b1e97 | Romuald | <select name="demi_jour"> |
150 | a92b1e97 | Romuald | <option value=""></option> |
151 | a92b1e97 | Romuald | <option value="AM">AM</option> |
152 | a92b1e97 | Romuald | <option value="PM">PM</option> |
153 | a92b1e97 | Romuald | </select>
|
154 | 52a3c866 | Romuald | </form>
|
155 | 52a3c866 | Romuald | <form method="get"> |
156 | 52a3c866 | Romuald | <input type="hidden" name="date" value="<?=$date?>" /> |
157 | 52a3c866 | Romuald | <input type="hidden" name="vue" value="<?=$vue?>" /> |
158 | 52a3c866 | Romuald | <table>
|
159 | 52a3c866 | Romuald | <tr>
|
160 | 52a3c866 | Romuald | <td align="left"><input type="submit" name="action" value="<<" /></td> |
161 | 52a3c866 | Romuald | <td align="center"> |
162 | 52a3c866 | Romuald | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="mois"> | |
163 | 52a3c866 | Romuald | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="trimestre"> | |
164 | 52a3c866 | Romuald | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="année"> |
165 | 52a3c866 | Romuald | <td align="right"><input type="submit" name="action" value=">>" /></td> |
166 | 52a3c866 | Romuald | </tr>
|
167 | 52a3c866 | Romuald | <?php
|
168 | 3a9db70f | Romuald | for ($v = 0; $v == 0 || ($vue == "trimestre" && $v < 3) || ($vue == "année" && $v < 12); $v++) { |
169 | 52a3c866 | Romuald | $ts2 = strtotime("+$v month", $ts); |
170 | 52a3c866 | Romuald | $date_annee = date("Y", $ts2); |
171 | 52a3c866 | Romuald | $date_mois = date("m", $ts2); |
172 | 52a3c866 | Romuald | $nom_mois = date("F", $ts2); |
173 | 52a3c866 | Romuald | $nb_jours = date("t", $ts2); |
174 | 52a3c866 | Romuald | ?>
|
175 | 52a3c866 | Romuald | <tr><td colspan="3"> |
176 | 52a3c866 | Romuald | <table border="1" width="100%"> |
177 | 52a3c866 | Romuald | <tr>
|
178 | 52a3c866 | Romuald | <th rowspan="2"> </th> |
179 | a92b1e97 | Romuald | <th colspan="<?=2*$nb_jours?>" align="center"><?=$nom_mois?> <?=$date_annee?></th> |
180 | 52a3c866 | Romuald | </tr>
|
181 | 52a3c866 | Romuald | <tr>
|
182 | 52a3c866 | Romuald | <?php for ($n = 1; $n <= $nb_jours; $n++) { ?> |
183 | a92b1e97 | Romuald | <th colspan="2"><?=sprintf("%02d", $n)?></th> |
184 | 52a3c866 | Romuald | <?php } ?> |
185 | 52a3c866 | Romuald | </tr>
|
186 | 52a3c866 | Romuald | <?php foreach ($employes as $nom) { ?> |
187 | 52a3c866 | Romuald | <tr>
|
188 | 52a3c866 | Romuald | <td align="right"><?=$nom?></td> |
189 | 52a3c866 | Romuald | <?php for ($n = 1; $n <= $nb_jours; $n++) { |
190 | 52a3c866 | Romuald | $date_jour = sprintf("%02d", $n); |
191 | 52a3c866 | Romuald | $str_date = "$date_annee/$date_mois/$date_jour"; |
192 | dfb6ddbf | Romuald | $ts3 = strtotime($str_date); |
193 | dfb6ddbf | Romuald | $jour_semaine = date("w", $ts3); |
194 | dfb6ddbf | Romuald | $libOnClick = ""; |
195 | dfb6ddbf | Romuald | $libTitle = ""; |
196 | dfb6ddbf | Romuald | $day = ""; |
197 | dfb6ddbf | Romuald | if (($libFerie = jourFeries($ts3))) { |
198 | dfb6ddbf | Romuald | $color = "gray"; |
199 | dfb6ddbf | Romuald | $libTitle = " title=\"$libFerie\""; |
200 | dfb6ddbf | Romuald | } elseif ($jour_semaine == 0 || $jour_semaine == 6) { |
201 | 52a3c866 | Romuald | $color = "lightgray"; |
202 | 52a3c866 | Romuald | } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) { |
203 | 52a3c866 | Romuald | $color = "blue"; |
204 | 3a9db70f | Romuald | $day = "congé"; |
205 | dfb6ddbf | Romuald | $libOnClick = " onClick=\"updateConges(this, '$nom', '$str_date')\""; |
206 | a92b1e97 | Romuald | } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom]) && in_array("$str_date PM", $conges[$nom])) { |
207 | a92b1e97 | Romuald | $color = "blue"; |
208 | 3a9db70f | Romuald | $day = "congé AP"; |
209 | a92b1e97 | Romuald | } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom])) { |
210 | a92b1e97 | Romuald | $color = "blue"; |
211 | 3a9db70f | Romuald | $day = "congé AM"; |
212 | a92b1e97 | Romuald | } else if (isset($conges[$nom]) && in_array("$str_date PM", $conges[$nom])) { |
213 | a92b1e97 | Romuald | $color = "blue"; |
214 | 3a9db70f | Romuald | $day = "congé PM"; |
215 | 52a3c866 | Romuald | } else {
|
216 | 52a3c866 | Romuald | $color = "white"; |
217 | dfb6ddbf | Romuald | $libOnClick = " onClick=\"updateConges(this, '$nom', '$str_date')\""; |
218 | 52a3c866 | Romuald | } |
219 | 52a3c866 | Romuald | ?>
|
220 | a92b1e97 | Romuald | <?php
|
221 | 3a9db70f | Romuald | if ($day == "congé AM") { |
222 | a92b1e97 | Romuald | ?>
|
223 | dfb6ddbf | Romuald | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')"> </td> |
224 | dfb6ddbf | Romuald | <td style="cursor: pointer; background-color: white" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')"> </td> |
225 | 3a9db70f | Romuald | <?php } elseif ($day == "congé PM") { ?> |
226 | dfb6ddbf | Romuald | <td style="cursor: pointer; background-color: white" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')"> </td> |
227 | dfb6ddbf | Romuald | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')"> </td> |
228 | 3a9db70f | Romuald | <?php } elseif ($day == "congé AP") { ?> |
229 | dfb6ddbf | Romuald | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')"> </td> |
230 | dfb6ddbf | Romuald | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')"> </td> |
231 | a92b1e97 | Romuald | <?php } else {?> |
232 | dfb6ddbf | Romuald | <td colspan="2" style="cursor: pointer; background-color: <?=$color?>"<?=$libOnClick?><?=$libTitle?>> </td> |
233 | a92b1e97 | Romuald | <?php } ?> |
234 | 52a3c866 | Romuald | <?php } ?> |
235 | 52a3c866 | Romuald | </tr>
|
236 | 52a3c866 | Romuald | <?php
|
237 | 52a3c866 | Romuald | } |
238 | 52a3c866 | Romuald | ?>
|
239 | 52a3c866 | Romuald | </td></tr> |
240 | 52a3c866 | Romuald | </table>
|
241 | 52a3c866 | Romuald | <?php
|
242 | 52a3c866 | Romuald | } |
243 | 52a3c866 | Romuald | ?>
|
244 | 52a3c866 | Romuald | </table>
|
245 | 52a3c866 | Romuald | </form>
|
246 | 52a3c866 | Romuald | </body>
|
247 | 52a3c866 | Romuald | </html> |