Statistiques
| Branche: | Révision :

root / index.php @ 00cab91c664a3f4f3d778cd034fdef247816e179

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