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