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