Statistiques
| Branche: | Révision :

root / index.php @ a92b1e9783dadded7408eb11b51b181884d2dcda

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