root / index.php @ 46a8277fdb39fed4ccbdf84679803a1f669b844f
Historique | Voir | Annoter | Télécharger (10,98 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înes de caractères 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 | getConges("datas", $employes, $conges); |
| 73 | if ($_POST['action'] == 'add') { |
| 74 | if (!$conges[$nom] || !in_array($str_date, $conges[$nom])) { |
| 75 | if ($conges[$nom]) { |
| 76 | # On supprime l'autre demi-journée au cas où
|
| 77 | $key = array_search("$str_date AM", $conges[$nom]); |
| 78 | if ($key !== FALSE) unset($conges[$nom][$key]); |
| 79 | $key = array_search("$str_date PM", $conges[$nom]); |
| 80 | if ($key !== FALSE) unset($conges[$nom][$key]); |
| 81 | } |
| 82 | $conges[$nom][] = $str_date; |
| 83 | setConges('datas', $nom, $conges); |
| 84 | } |
| 85 | } elseif ($_POST['action'] == 'del') { |
| 86 | if ($conges[$nom] && in_array($str_date, $conges[$nom])) { |
| 87 | $key = array_search($str_date, $conges[$nom]); |
| 88 | unset($conges[$nom][$key]); |
| 89 | setConges('datas', $nom, $conges); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | $tsNow = time(); |
| 94 | $dateNow = date("Y/m/d", $tsNow); |
| 95 | |
| 96 | $vue = $_GET['vue']; |
| 97 | if (!$vue) $vue = "mois"; |
| 98 | |
| 99 | $dateCurrent = $_GET['date']; |
| 100 | if (!$dateCurrent) { |
| 101 | $tsCurrent = strtotime(date("Y/m/01", $tsNow)); |
| 102 | } else {
|
| 103 | $tsCurrent = strtotime(date("Y/m/01", strtotime($dateCurrent))); |
| 104 | } |
| 105 | |
| 106 | switch ($_GET['action']) { |
| 107 | case '<<': |
| 108 | $tsCurrent = strtotime("-1 month", $tsCurrent); |
| 109 | break;
|
| 110 | case '>>': |
| 111 | $tsCurrent = strtotime("+1 month", $tsCurrent); |
| 112 | break;
|
| 113 | } |
| 114 | |
| 115 | switch ($vue) { |
| 116 | case "trimestre": |
| 117 | $dateDeb = date("Y/m/01", strtotime("-1 month", $tsCurrent)); |
| 118 | break;
|
| 119 | case "année": |
| 120 | $dateDeb = date("Y/01/01", $tsCurrent); |
| 121 | break;
|
| 122 | case "mois": |
| 123 | default:
|
| 124 | $dateDeb = date("Y/m/01", $tsCurrent); |
| 125 | break;
|
| 126 | } |
| 127 | $dateCurrent = date("Y/m/d", $tsCurrent); |
| 128 | |
| 129 | /*
|
| 130 | echo "<pre>\n"; |
| 131 | print_r($_POST); |
| 132 | //print_r($employes); |
| 133 | print_r($conges); |
| 134 | echo "</pre>\n"; |
| 135 | */ |
| 136 | |
| 137 | ?>
|
| 138 | <html>
|
| 139 | <head>
|
| 140 | <title>Gestion de congés</title> |
| 141 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 142 | <meta http-equiv="Content-language" content="fr" /> |
| 143 | <meta name="copyright" content="Tous droits réservés - All Rights Reserved" /> |
| 144 | <meta name="author" content="Romuald DELAVERGNE"> |
| 145 | <style type="text/css"> |
| 146 | a.button:link, a.button:visited {
|
| 147 | float: left; |
| 148 | padding: 2px; |
| 149 | width: 50px; |
| 150 | border-top: 1px solid #cccccc; |
| 151 | border-bottom: 1px solid black; |
| 152 | border-left: 1px solid #cccccc; |
| 153 | border-right: 1px solid black; |
| 154 | background: #cccccc; |
| 155 | text-align: center; |
| 156 | text-decoration: none; |
| 157 | color: black; |
| 158 | } |
| 159 | |
| 160 | a.button:hover {
|
| 161 | background: #eeeeee; |
| 162 | } |
| 163 | |
| 164 | a.button:active {
|
| 165 | border-bottom: 1px solid #eeeeee; |
| 166 | border-top: 1px solid black; |
| 167 | border-right: 1px solid #eeeeee; |
| 168 | border-left: 1px solid black; |
| 169 | } |
| 170 | |
| 171 | a.popupmenu {
|
| 172 | display: block; |
| 173 | width: 100%; |
| 174 | background-color: white; |
| 175 | color: black; |
| 176 | text-decoration: none; |
| 177 | text-align: center; |
| 178 | font-family: Arial, Helvetica, sans-serif; |
| 179 | font-weight: bold; |
| 180 | cursor: pointer; |
| 181 | } |
| 182 | a.popupmenu:hover {
|
| 183 | background-color: gray; |
| 184 | color: white; |
| 185 | } |
| 186 | </style>
|
| 187 | <script language=JavaScript> |
| 188 | var ie = document.all; |
| 189 | var ns6 = document.getElementById&&!document.all; |
| 190 | var isMenu = false; |
| 191 | var overpopupmenu = false; |
| 192 | var selectNom = ''; |
| 193 | var selectDate = ''; |
| 194 | |
| 195 | function $(id) {
|
| 196 | return document.getElementById(id); |
| 197 | } |
| 198 | |
| 199 | function updateConges(nom, str_date, action) {
|
| 200 | document.forms["update"].action.value = action; |
| 201 | document.forms["update"].nom.value = nom; |
| 202 | document.forms["update"].str_date.value = str_date; |
| 203 | document.forms["update"].submit(); |
| 204 | } |
| 205 | |
| 206 | function mouseSelect(e) {
|
| 207 | var evt = e || window.event; |
| 208 | var obj = ns6 ? evt.target.parentNode : evt.srcElement.parentElement; |
| 209 | if (isMenu) {
|
| 210 | if (overpopupmenu == false) {
|
| 211 | isMenu = false; |
| 212 | overpopupmenu = false; |
| 213 | $('popupMenu').style.display = "none";
|
| 214 | if (obj.id == 'AM' || obj.id == 'PM' ) {
|
| 215 | updateConges(selectNom, selectDate+' '+obj.id, 'add'); |
| 216 | } |
| 217 | selectNom = ''; |
| 218 | selectDate = ''; |
| 219 | return true; |
| 220 | } |
| 221 | return true; |
| 222 | } |
| 223 | return false; |
| 224 | } |
| 225 | |
| 226 | function ItemSelMenu(e, nom, strDate) {
|
| 227 | var evt = e || window.event; |
| 228 | var obj = ns6 ? evt.target : evt.srcElement; |
| 229 | if (obj.className != 'menu') return false; |
| 230 | if (ns6) {
|
| 231 | $('popupMenu').style.left = evt.clientX+document.body.scrollLeft;
|
| 232 | $('popupMenu').style.top = evt.clientY+document.body.scrollTop;
|
| 233 | } else {
|
| 234 | $('popupMenu').style.pixelLeft = event.clientX + document.body.scrollLeft;
|
| 235 | $('popupMenu').style.pixelTop = event.clientY + document.body.scrollTop;
|
| 236 | } |
| 237 | $('popupMenu').style.display = "";
|
| 238 | $('AM').style.backgroundColor = 'white';
|
| 239 | $('PM').style.backgroundColor = 'white';
|
| 240 | $('annuler').style.backgroundColor = 'white';
|
| 241 | isMenu = true; |
| 242 | selectNom = nom; |
| 243 | selectDate = strDate; |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | document.onmousedown = mouseSelect; |
| 248 | </script>
|
| 249 | </head>
|
| 250 | <html>
|
| 251 | <body>
|
| 252 | <form id="update" method="post"> |
| 253 | <input type="hidden" name="nom" value="" /> |
| 254 | <input type="hidden" name="str_date" value="" /> |
| 255 | <input type="hidden" name="action" value="" /> |
| 256 | </form>
|
| 257 | <table>
|
| 258 | <tr>
|
| 259 | <td><a class="button" href="?date=<?=date("Y/m/01", strtotime("-1 month", $tsCurrent))?>&vue=<?=$vue?>"><<</a></td> |
| 260 | <td align="center"> |
| 261 | <a href="?date=<?=$dateCurrent?>&vue=mois">mois</a> | |
| 262 | <a href="?date=<?=$dateCurrent?>&vue=trimestre">trimestre</a> | |
| 263 | <a href="?date=<?=$dateCurrent?>&vue=année">année</a> |
| 264 | <td><a class="button" style="float: right" href="?date=<?=date("Y/m/01", strtotime("+1 month", $tsCurrent))?>&vue=<?=$vue?>">>></a></td> |
| 265 | </tr>
|
| 266 | <?php
|
| 267 | for ($v = 0; $v == 0 || ($vue == "trimestre" && $v < 3) || ($vue == "année" && $v < 12); $v++) { |
| 268 | $ts = strtotime("+$v month", strtotime($dateDeb)); |
| 269 | $date_annee = date("Y", $ts); |
| 270 | $date_mois = date("m", $ts); |
| 271 | $nom_mois = date("F", $ts); |
| 272 | $nb_jours = date("t", $ts); |
| 273 | ?>
|
| 274 | <tr><td colspan="3"> |
| 275 | <table border="1" width="100%"> |
| 276 | <tr>
|
| 277 | <th rowspan="2"> </th> |
| 278 | <th colspan="<?=2*$nb_jours?>" align="center"><a href="?date=<?=$date_annee?>/<?=$date_mois?>/01&vue=<?=$vue?>"><?=$nom_mois?> <?=$date_annee?></a></th> |
| 279 | </tr>
|
| 280 | <tr>
|
| 281 | <?php for ($n = 1; $n <= $nb_jours; $n++) { |
| 282 | $date_jour = sprintf("%02d", $n); |
| 283 | $str_date = "$date_annee/$date_mois/$date_jour"; |
| 284 | $bgColor = ($str_date == $dateNow) ? "red" : "white"; |
| 285 | ?>
|
| 286 | <th colspan="2" bgcolor="<?=$bgColor?>"><?=$date_jour?></th> |
| 287 | <?php } ?> |
| 288 | </tr>
|
| 289 | <?php foreach ($employes as $nom) { ?> |
| 290 | <tr>
|
| 291 | <td align="right"><?=$nom?></td> |
| 292 | <?php for ($n = 1; $n <= $nb_jours; $n++) { |
| 293 | $date_jour = sprintf("%02d", $n); |
| 294 | $str_date = "$date_annee/$date_mois/$date_jour"; |
| 295 | $ts3 = strtotime($str_date); |
| 296 | $jour_semaine = date("w", $ts3); |
| 297 | $libOnClick = ""; |
| 298 | $libTitle = ""; |
| 299 | $menu = ""; |
| 300 | if (($libFerie = jourFeries($ts3))) { |
| 301 | $color = "gray"; |
| 302 | $libTitle = " title=\"$libFerie\""; |
| 303 | } elseif ($jour_semaine == 0 || $jour_semaine == 6) { |
| 304 | $color = "lightgray"; |
| 305 | } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) { |
| 306 | $color = "blue"; |
| 307 | $libOnClick = " onClick=\"updateConges('$nom', '$str_date', 'del')\""; |
| 308 | } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom])) { |
| 309 | $colorAM = "blue"; |
| 310 | $colorPM = "white"; |
| 311 | $libOnClickAM = " onClick=\"updateConges('$nom', '$str_date AM', 'del')\""; |
| 312 | $libOnClickPM = " onClick=\"updateConges('$nom', '$str_date', 'add')\""; |
| 313 | } else if (isset($conges[$nom]) && in_array("$str_date PM", $conges[$nom])) { |
| 314 | $colorAM = "white"; |
| 315 | $colorPM = "blue"; |
| 316 | $libOnClickAM = " onClick=\"updateConges('$nom', '$str_date', 'add')\""; |
| 317 | $libOnClickPM = " onClick=\"updateConges('$nom', '$str_date PM', 'del')\""; |
| 318 | } else {
|
| 319 | $color = "white"; |
| 320 | $libOnClick = " onClick=\"updateConges('$nom', '$str_date', 'add')\""; |
| 321 | $menu = " class=\"menu\" onContextMenu=\"ItemSelMenu(event, '$nom', '$str_date'); return false;\""; |
| 322 | } |
| 323 | ?>
|
| 324 | <?php
|
| 325 | if (isset($conges[$nom]) && (in_array("$str_date AM", $conges[$nom]) || in_array("$str_date PM", $conges[$nom]))) { |
| 326 | ?>
|
| 327 | <td style="cursor: pointer; background-color: <?=$colorAM?>"<?=$libOnClickAM?><?=$libTitle?>> </td> |
| 328 | <td style="cursor: pointer; background-color: <?=$colorPM?>"<?=$libOnClickPM?><?=$libTitle?>> </td> |
| 329 | <?php } else {?> |
| 330 | <td colspan="2" style="cursor: pointer; background-color: <?=$color?>"<?=$libOnClick?><?=$menu?><?=$libTitle?>> </td> |
| 331 | <?php } ?> |
| 332 | <?php } ?> |
| 333 | </tr>
|
| 334 | <?php
|
| 335 | } |
| 336 | ?>
|
| 337 | </td></tr> |
| 338 | </table>
|
| 339 | <?php
|
| 340 | } |
| 341 | ?>
|
| 342 | </table>
|
| 343 | <div id="popupMenu" style="position: absolute; display: none; top: 0px; left: 0px; z-index: 10000;" onMouseOver="javascript:overPopupMenu=true;" onMouseOut="javascript:overPopupMenu=false;"> |
| 344 | <table border="0" bgcolor="lightgray"> |
| 345 | <tr><td id="AM"><a class="popupmenu" href="#">Matin</a></td></tr> |
| 346 | <tr><td id="PM"><a class="popupmenu" href="#">Après-midi</a></td></tr> |
| 347 | <tr><td id="annuler"><a class="popupmenu" href="#">Annuler</a></td></tr> |
| 348 | </table>
|
| 349 | </div>
|
| 350 | </body>
|
| 351 | </html>
|