Statistiques
| Branche: | Révision :

root / index.php @ 52a3c8660baea32585939fe022e779bfddb1bae0

Historique | Voir | Annoter | Télécharger (5,17 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
        getConges("datas", $employes, $conges);
43
        if ($_POST['action'] == 'add') {
44
                if (!$conges[$nom] || !in_array($str_date, $conges[$nom])) {
45
                        $conges[$nom][] = $str_date;
46
                        setConges('datas', $nom, $conges);
47
                }
48
        } elseif ($_POST['action'] == 'delete') {
49
                if ($conges[$nom] && in_array($str_date, $conges[$nom])) {
50
                        $key = array_search($str_date, $conges[$nom]);
51
                        unset($conges[$nom][$key]);
52
                        setConges('datas', $nom, $conges);
53
                }
54
        }
55
56
        $vue = $_GET['vue'];
57
        $date = $_GET['date'];
58
        if (!$date) {
59
                $ts = time();
60
        } else {
61
                $ts = strtotime($date);
62
        }
63
64
        switch ($_GET['action']) {
65
                case '<<':
66
                        $ts = strtotime("-1 month", $ts);
67
                        break;
68
                case '>>':
69
                        $ts = strtotime("+1 month", $ts);
70
                        break;
71
                case 'mois':
72
                case 'trimestre':
73
                case 'année':
74
                        $vue = $_GET['action'];
75
                        break;
76
        }
77
78
        if (!$vue) $vue = "mois";
79
        $date = date("Y/m/d", $ts);
80
81
        /*
82
        echo "<pre>\n";
83
        print_r($_POST);
84
        //print_r($employes);
85
        print_r($conges);
86
        echo "</pre>\n";
87
        */
88
89
?>
90
<html>
91
<head>
92
        <title>Gestion de congés
93
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
94
        <meta http-equiv="Content-language" content="fr" />
95
        <meta name="copyright" content="Tous droits réservés - All Rights Reserved" />
96
        <meta name="author" content="Romuald DELAVERGNE">
97
        <script language=JavaScript>
98
                function updateConges(jour, nom, str_date) {
99
                        if (jour.style.backgroundColor == 'white') {
100
                                //jour.style.backgroundColor='lightblue';
101
                                document.forms["update"].action.value = 'add';
102
                        } else {
103
                                //jour.style.backgroundColor='white';
104
                                document.forms["update"].action.value = 'delete';
105
                        }
106
                        document.forms["update"].nom.value = nom;
107
                        document.forms["update"].str_date.value = str_date;
108
                        document.forms["update"].submit();
109
                }
110
        </script>
111
</head>
112
<html>
113
<body>
114
        <form id="update" method="post">
115
                <input type="hidden" name="nom" value="" />
116
                <input type="hidden" name="str_date" value="" />
117
                <input type="hidden" name="action" value="" />
118
        </form>
119
        <form method="get">
120
                <input type="hidden" name="date" value="<?=$date?>" />
121
                <input type="hidden" name="vue" value="<?=$vue?>" />
122
        <table>
123
        <tr>
124
                <td align="left"><input type="submit" name="action" value="<<" /></td>
125
                <td align="center">
126
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="mois"> |
127
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="trimestre"> |
128
                        <input type="submit" style="border:0; background:transparent; color:blue; cursor:pointer; text-decoration:underline;" name="action" value="ann&eacute;e">
129
                <td align="right"><input type="submit" name="action" value=">>" /></td>
130
        </tr>
131
<?php
132
        for ($v = 0; $v == 0 || ($vue == "trimestre" && $v < 3) || ($vue == "année" && $v < 12); $v++) {
133
                $ts2 = strtotime("+$v month", $ts);
134
                $date_annee = date("Y", $ts2);
135
                $date_mois = date("m", $ts2);
136
                $nom_mois = date("F", $ts2);
137
                $nb_jours = date("t", $ts2);
138
?>
139
        <tr><td colspan="3">
140
        <table border="1" width="100%">
141
                <tr>
142
                        <th rowspan="2">&nbsp;</th>
143
                        <th colspan="<?=$nb_jours?>" align="center"><?=$nom_mois?> <?=$date_annee?></th>
144
                </tr>
145
                <tr>
146
<?php for ($n = 1; $n <= $nb_jours; $n++) { ?>
147
                        <th><?=sprintf("%02d", $n)?></th>
148
<?php } ?>
149
                </tr>
150
<?php foreach ($employes as $nom) { ?>
151
                <tr>
152
                        <td align="right"><?=$nom?></td>
153
<?php for ($n = 1; $n <= $nb_jours; $n++) {
154
                                $date_jour = sprintf("%02d", $n);
155
                                $str_date = "$date_annee/$date_mois/$date_jour";
156
                                $jour_semaine = date("w", strtotime($str_date));
157
                                if ($jour_semaine == 0 || $jour_semaine == 6) {
158
                                        $color = "lightgray";
159
                                        $day = "we";
160
                                } else if (isset($conges[$nom]) && in_array($str_date, $conges[$nom])) {
161
                                        $color = "blue";
162
                                        $day = "congé";
163
                                } else {
164
                                        $color = "white";
165
                                        $day = "travaillé";
166
                                }
167
                        /*
168
                        <td style="background-color: <?=$color?>"<?=($day == "we") ? "" : "onClick=\"updateConges(this)\""?>>&nbsp;</td>
169
                        <td style="background-color: <?=$color?>">&nbsp;</td>
170
                        */
171
?>
172
                        <td style="background-color: <?=$color?>"<?=($day == "we") ? "" : "onClick=\"updateConges(this, '$nom', '$str_date')\""?>>&nbsp;</td>
173
<?php } ?>
174
                </tr>
175
<?php
176
        }
177
?>
178
        </td></tr>
179
        </table>
180
<?php
181
        }
182
?>
183
        </table>
184
        </form>
185
</body>
186
</html>
187