Statistiques
| Branche: | Révision :

root / index.php @ 179d8f278eb65ab790586bd55b21ae7e2763fb89

Historique | Voir | Annoter | Télécharger (7,97 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&ecirc;te du travail";
19
                if ($mois == "05" && $jour == "08") return "victoire 1945";
20
                if ($mois == "07" && $jour == "14") return "f&ecirc;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&euml;l";
25
                $tsPaques = easter_date($annee);
26
                if ($mois == date("m", $tsPaques) && $jour == date("d", $tsPaques)) return "P&acirc;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&acirc;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&ocirc;te";
35
                $ts = strtotime("+50 days", $tsPaques);
36
                if ($mois == date("m", $ts) && $jour == date("d", $ts)) return "lundi de Pentec&ocirc;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
        $demi_jour = $_POST['demi_jour'];
73
        getConges("datas", $employes, $conges);
74
        if ($_POST['action'] == 'add') {
75
                if (!$conges[$nom] || !in_array($str_date, $conges[$nom])) {
76
                        if ($conges[$nom]) {
77
                                # On supprime l'autre demi-journée au cas où
78
                                $key = array_search("$str_date AM", $conges[$nom]);
79
                                if ($key !== FALSE) unset($conges[$nom][$key]);
80
                                $key = array_search("$str_date PM", $conges[$nom]);
81
                                if ($key !== FALSE) unset($conges[$nom][$key]);
82
                        }
83
                        $conges[$nom][] = $str_date.($demi_jour ? " $demi_jour" : "");
84
                        setConges('datas', $nom, $conges);
85
                }
86
        } elseif ($_POST['action'] == 'del') {
87
                if ($conges[$nom] && in_array($str_date, $conges[$nom])) {
88
                        $key = array_search($str_date, $conges[$nom]);
89
                        unset($conges[$nom][$key]);
90
                        setConges('datas', $nom, $conges);
91
                }
92
        }
93
94
        $vue = $_GET['vue'];
95
        $date = $_GET['date'];
96
        if (!$date) {
97
                $ts = time();
98
        } else {
99
                $ts = strtotime($date);
100
        }
101
102
        switch ($_GET['action']) {
103
                case '<<':
104
                        $ts = strtotime("-1 month", $ts);
105
                        break;
106
                case '>>':
107
                        $ts = strtotime("+1 month", $ts);
108
                        break;
109
                case 'mois':
110
                case 'trimestre':
111
                case 'année':
112
                        $vue = $_GET['action'];
113
                        break;
114
        }
115
116
        if (!$vue) $vue = "mois";
117
        $date = date("Y/m/d", $ts);
118
119
        /*
120
        echo "<pre>\n";
121
        print_r($_POST);
122
        //print_r($employes);
123
        print_r($conges);
124
        echo "</pre>\n";
125
        */
126
127
?>
128
<html>
129
<head>
130
        <title>Gestion de cong&eacute;s</title>
131
        <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
132
        <meta http-equiv="Content-language" content="fr" />
133
        <meta name="copyright" content="Tous droits réservés - All Rights Reserved" />
134
        <meta name="author" content="Romuald DELAVERGNE">
135
        <script language=JavaScript>
136
                function updateConges(jour, nom, str_date, action) {
137
                        document.forms["update"].action.value = action;
138
                        document.forms["update"].nom.value = nom;
139
                        document.forms["update"].str_date.value = str_date;
140
                        document.forms["update"].submit();
141
                }
142
        </script>
143
</head>
144
<html>
145
<body>
146
        <form id="update" method="post">
147
                <input type="hidden" name="nom" value="" />
148
                <input type="hidden" name="str_date" value="" />
149
                <input type="hidden" name="action" value="" />
150
                <select name="demi_jour">
151
                        <option value=""></option>
152
                        <option value="AM">AM</option>
153
                        <option value="PM">PM</option>
154
                </select>
155
        </form>
156
        <form method="get">
157
                <input type="hidden" name="date" value="<?=$date?>" />
158
                <input type="hidden" name="vue" value="<?=$vue?>" />
159
        <table>
160
        <tr>
161
                <td align="left"><input type="submit" name="action" value="<<" /></td>
162
                <td align="center">
163
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="mois"> |
164
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="trimestre"> |
165
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="ann&eacute;e">
166
                <td align="right"><input type="submit" name="action" value=">>" /></td>
167
        </tr>
168
<?php
169
        for ($v = 0; $v == 0 || ($vue == "trimestre" && $v < 3) || ($vue == "année" && $v < 12); $v++) {
170
                $ts2 = strtotime("+$v month", $ts);
171
                $date_annee = date("Y", $ts2);
172
                $date_mois = date("m", $ts2);
173
                $nom_mois = date("F", $ts2);
174
                $nb_jours = date("t", $ts2);
175
?>
176
        <tr><td colspan="3">
177
        <table border="1" width="100%">
178
                <tr>
179
                        <th rowspan="2">&nbsp;</th>
180
                        <th colspan="<?=2*$nb_jours?>" align="center"><?=$nom_mois?> <?=$date_annee?></th>
181
                </tr>
182
                <tr>
183
<?php for ($n = 1; $n <= $nb_jours; $n++) { ?>
184
                        <th colspan="2"><?=sprintf("%02d", $n)?></th>
185
<?php } ?>
186
                </tr>
187
<?php foreach ($employes as $nom) { ?>
188
                <tr>
189
                        <td align="right"><?=$nom?></td>
190
<?php for ($n = 1; $n <= $nb_jours; $n++) {
191
                                $date_jour = sprintf("%02d", $n);
192
                                $str_date = "$date_annee/$date_mois/$date_jour";
193
                                $ts3 = strtotime($str_date);
194
                                $jour_semaine = date("w", $ts3);
195
                                $libOnClick = "";
196
                                $libTitle = "";
197
                                if (($libFerie = jourFeries($ts3))) {
198
                                        $color = "gray";
199
                                        $libTitle = " title=\"$libFerie\"";
200
                                } elseif ($jour_semaine == 0 || $jour_semaine == 6) {
201
                                        $color = "lightgray";
202
                                } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) {
203
                                        $color = "blue";
204
                                        $libOnClick = " onClick=\"updateConges(this, '$nom', '$str_date', 'del')\"";
205
                                } else if (isset($conges[$nom]) && in_array("$str_date AM", $conges[$nom])) {
206
                                        $colorAM = "blue";
207
                                        $colorPM = "white";
208
                                        $libOnClickAM = " onClick=\"updateConges(this, '$nom', '$str_date AM', 'del')\"";
209
                                        $libOnClickPM = " onClick=\"updateConges(this, '$nom', '$str_date', 'add')\"";
210
                                } else if (isset($conges[$nom]) && in_array("$str_date PM", $conges[$nom])) {
211
                                        $colorAM = "white";
212
                                        $colorPM = "blue";
213
                                        $libOnClickAM = " onClick=\"updateConges(this, '$nom', '$str_date', 'add')\"";
214
                                        $libOnClickPM = " onClick=\"updateConges(this, '$nom', '$str_date PM', 'del')\"";
215
                                } else {
216
                                        $color = "white";
217
                                        $libOnClick = " onClick=\"updateConges(this, '$nom', '$str_date', 'add')\"";
218
                                }
219
?>
220
<?php
221
                                if (isset($conges[$nom]) && (in_array("$str_date AM", $conges[$nom]) || in_array("$str_date PM", $conges[$nom]))) {
222
?>
223
                        <td style="cursor: pointer; background-color: <?=$colorAM?>"<?=$libOnClickAM?><?=$libTitle?>>&nbsp;</td>
224
                        <td style="cursor: pointer; background-color: <?=$colorPM?>"<?=$libOnClickPM?><?=$libTitle?>>&nbsp;</td>
225
<?php         } else {?>
226
                        <td colspan="2" style="cursor: pointer; background-color: <?=$color?>"<?=$libOnClick?><?=$libTitle?>>&nbsp;</td>
227
<?php         } ?>
228
<?php } ?>
229
                </tr>
230
<?php
231
        }
232
?>
233
        </td></tr>
234
        </table>
235
<?php
236
        }
237
?>
238
        </table>
239
        </form>
240
</body>
241
</html>