root / index.php @ e464d4d043e647c9dd9875a6fbe1a197fdc9d018
Historique | Voir | Annoter | Télécharger (6,69 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 getConges($path, &$employes, &$conges) { |
14 | $employes = array(); |
15 | $conges = array(); |
16 | if ($dir = opendir($path)) { |
17 | while (($file = readdir($dir)) !== FALSE) { |
18 | if (is_file("$path/$file")) { |
19 | $employes[] = $file; |
20 | $dates = file("$path/$file"); |
21 | foreach ($dates as $date) $conges[$file][] = rtrim($date); |
22 | } |
23 | } |
24 | closedir($dir); |
25 | } |
26 | } |
27 | |
28 | function setConges($path, $nom, $conges) { |
29 | $fh = @fopen("$path/$nom", 'w'); |
30 | if ($fh) { |
31 | if ($conges[$nom]) { |
32 | asort($conges[$nom]); |
33 | foreach ($conges[$nom] as $str_date) { |
34 | fwrite($fh, "$str_date\n"); |
35 | } |
36 | } |
37 | fclose($fh); |
38 | } else {
|
39 | echo "ERROR d'écriture dans $path/$nom"; |
40 | } |
41 | } |
42 | |
43 | $str_date = $_POST['str_date']; |
44 | $nom = $_POST['nom']; |
45 | $demi_jour = $_POST['demi_jour']; |
46 | getConges("datas", $employes, $conges); |
47 | if ($_POST['action'] == 'add') { |
48 | if (!$conges[$nom] || !in_array($str_date, $conges[$nom])) { |
49 | $conges[$nom][] = $str_date.($demi_jour ? " $demi_jour" : ""); |
50 | setConges('datas', $nom, $conges); |
51 | } |
52 | } elseif ($_POST['action'] == 'delete') { |
53 | if ($conges[$nom] && in_array($str_date, $conges[$nom])) { |
54 | $key = array_search($str_date, $conges[$nom]); |
55 | unset($conges[$nom][$key]); |
56 | setConges('datas', $nom, $conges); |
57 | } |
58 | } |
59 | |
60 | $vue = $_GET['vue']; |
61 | $date = $_GET['date']; |
62 | if (!$date) { |
63 | $ts = time(); |
64 | } else {
|
65 | $ts = strtotime($date); |
66 | } |
67 | |
68 | switch ($_GET['action']) { |
69 | case '<<': |
70 | $ts = strtotime("-1 month", $ts); |
71 | break;
|
72 | case '>>': |
73 | $ts = strtotime("+1 month", $ts); |
74 | break;
|
75 | case 'mois': |
76 | case 'trimestre': |
77 | case 'année': |
78 | $vue = $_GET['action']; |
79 | break; |
80 | } |
81 | |
82 | if (!$vue) $vue = "mois"; |
83 | $date = date("Y/m/d", $ts); |
84 | |
85 | /* |
86 | echo "<pre>\n"; |
87 | print_r($_POST); |
88 | //print_r($employes); |
89 | print_r($conges); |
90 | echo "</pre>\n"; |
91 | */ |
92 | |
93 | ?> |
94 | <html> |
95 | <head> |
96 | <title>Gestion de congés</title> |
97 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
98 | <meta http-equiv="Content-language" content="fr" /> |
99 | <meta name="copyright" content="Tous droits réservés - All Rights Reserved" /> |
100 | <meta name="author" content="Romuald DELAVERGNE"> |
101 | <script language=JavaScript> |
102 | function updateConges(jour, nom, str_date) { |
103 | if (jour.style.backgroundColor == 'white') { |
104 | //jour.style.backgroundColor='lightblue'; |
105 | document.forms["update"].action.value = 'add'; |
106 | } else { |
107 | //jour.style.backgroundColor='white'; |
108 | document.forms["update"].action.value = 'delete'; |
109 | } |
110 | document.forms["update"].nom.value = nom; |
111 | document.forms["update"].str_date.value = str_date; |
112 | document.forms["update"].submit(); |
113 | } |
114 | </script> |
115 | </head> |
116 | <html> |
117 | <body> |
118 | <form id="update" method="post"> |
119 | <input type="hidden" name="nom" value="" /> |
120 | <input type="hidden" name="str_date" value="" /> |
121 | <input type="hidden" name="action" value="" /> |
122 | <select name="demi_jour"> |
123 | <option value=""></option> |
124 | <option value="AM">AM</option> |
125 | <option value="PM">PM</option> |
126 | </select> |
127 | </form> |
128 | <form method="get"> |
129 | <input type="hidden" name="date" value="<?=$date?>" /> |
130 | <input type="hidden" name="vue" value="<?=$vue?>" /> |
131 | <table> |
132 | <tr> |
133 | <td align="left"><input type="submit" name="action" value="<<" /></td> |
134 | <td align="center"> |
135 | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="mois"> | |
136 | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="trimestre"> | |
137 | <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="année"> |
138 | <td align="right"><input type="submit" name="action" value=">>" /></td> |
139 | </tr> |
140 | <?php |
141 | for ($v = 0; $v == 0 || ($vue == "trimestre" && $v < 3) || ($vue == "année" && $v < 12); $v++) { |
142 | $ts2 = strtotime("+$v month", $ts); |
143 | $date_annee = date("Y", $ts2); |
144 | $date_mois = date("m", $ts2); |
145 | $nom_mois = date("F", $ts2); |
146 | $nb_jours = date("t", $ts2); |
147 | ?> |
148 | <tr><td colspan="3"> |
149 | <table border="1" width="100%"> |
150 | <tr> |
151 | <th rowspan="2"> </th> |
152 | <th colspan="<?=2*$nb_jours?>" align="center"><?=$nom_mois?> <?=$date_annee?></th> |
153 | </tr> |
154 | <tr> |
155 | <?php for ($n = 1; $n <= $nb_jours; $n++) { ?> |
156 | <th colspan="2"><?=sprintf("%02d", $n)?></th> |
157 | <?php } ?> |
158 | </tr> |
159 | <?php foreach ($employes as $nom) { ?> |
160 | <tr> |
161 | <td align="right"><?=$nom?></td> |
162 | <?php for ($n = 1; $n <= $nb_jours; $n++) { |
163 | $date_jour = sprintf("%02d", $n); |
164 | $str_date = "$date_annee/$date_mois/$date_jour"; |
165 | $jour_semaine = date("w", strtotime($str_date)); |
166 | if ($jour_semaine == 0 || $jour_semaine == 6) { |
167 | $color = "lightgray"; |
168 | $day = "we"; |
169 | } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) { |
170 | $color = "blue"; |
171 | $day = "congé"; |
172 | } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom]) && in_array("$str_date PM", $conges[$nom])) { |
173 | $color = "blue"; |
174 | $day = "congé AP"; |
175 | } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom])) { |
176 | $color = "blue"; |
177 | $day = "congé AM"; |
178 | } else if (isset($conges[$nom]) && in_array("$str_date PM", $conges[$nom])) { |
179 | $color = "blue"; |
180 | $day = "congé PM"; |
181 | } else { |
182 | $color = "white"; |
183 | $day = "ouvré"; |
184 | } |
185 | ?> |
186 | <?php |
187 | if ($day == "congé AM") { |
188 | ?> |
189 | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')"> </td> |
190 | <td style="cursor: pointer; background-color: white" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')"> </td> |
191 | <?php } elseif ($day == "congé PM") { ?> |
192 | <td style="cursor: pointer; background-color: white" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')"> </td> |
193 | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')"> </td> |
194 | <?php } elseif ($day == "congé AP") { ?> |
195 | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> AM')"> </td> |
196 | <td style="cursor: pointer; background-color: <?=$color?>" onClick="updateConges(this, '<?=$nom?>', '<?=$str_date?> PM')"> </td> |
197 | <?php } else {?> |
198 | <td colspan="2" style="cursor: pointer; background-color: <?=$color?>"<?=($day == "we") ? "" : " onClick=\"updateConges(this, '$nom', '$str_date')\""?>> </td> |
199 | <?php } ?> |
200 | <?php } ?> |
201 | </tr>
|
202 | <?php
|
203 | } |
204 | ?>
|
205 | </td></tr> |
206 | </table>
|
207 | <?php
|
208 | } |
209 | ?>
|
210 | </table>
|
211 | </form>
|
212 | </body>
|
213 | </html>
|