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