root / admin / admin.php @ 4e7797f7365583f6db77d93a32c266b0c30fb783
Historique | Voir | Annoter | Télécharger (11,57 ko)
1 | <?php
|
---|---|
2 | /*
|
3 | * admin.php - Administration du championnat |
4 | * Copyright (C) 2008 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 | require_once 'zip.lib.php'; |
11 | |
12 | if (basename(dirname($_SERVER['PHP_SELF'])) == "admin") |
13 | require_once '../functions.php'; |
14 | else
|
15 | require_once 'functions.php'; |
16 | |
17 | function hiddenVars() { ?> |
18 | <input type="hidden" name="saison" value="<?=$_POST['saison']?>" /> |
19 | <input type="hidden" name="div1" value="<?=$_POST['div1']?>" /> |
20 | <input type="hidden" name="div2" value="<?=$_POST['div2']?>" /> |
21 | <input type="hidden" name="poule" value="<?=$_POST['poule']?>" /> |
22 | <input type="hidden" name="phase" value="<?=$_POST['phase']?>" /> |
23 | <?php }
|
24 | |
25 | function retour($button, $message = "") { ?>
|
26 | <form method="post" action="index.php"> |
27 | <?php if ($message != "") echo "\t\t\t$message"; ?> |
28 | <?php hiddenVars() ?> |
29 | <input type="submit" value="<?=$button?>" /> |
30 | </form>
|
31 | <?php }
|
32 | /* |
33 | echo "<pre>\n";
|
34 | print_r($_POST); |
35 | echo "</pre>\n";
|
36 | */ |
37 | |
38 | // Données reçues par l'index ou cette page |
39 | $championnat = $_POST['championnat']; |
40 | if ($championnat == "ajouter un championnat") $championnat = "ajouter"; |
41 | if ($_POST['validation_championnat'] == "ajouter") $championnat = "validation_ajouter"; |
42 | if ($_POST['validation_championnat'] == "modifier") $championnat = "validation_modifier"; |
43 | |
44 | if (isset($_POST['rencontre-ajouter'])) { |
45 | $rencontre = "ajouter"; |
46 | } else { |
47 | $vars = preg_grep("/^rencontre-/", array_keys($_POST)); |
48 | if ($vars) { |
49 | $rencontre = $_POST[current($vars)]; |
50 | $rencontreId = current($vars); |
51 | } |
52 | } |
53 | if ($_POST['validation_rencontre'] == "ajouter") $rencontre = "validation_ajouter"; |
54 | if ($_POST['validation_rencontre'] == "modifier") $rencontre = "validation_modifier"; |
55 | |
56 | $equipes = get_magic_quotes_gpc() ? stripslashes($_POST['equipes']) : $_POST['equipes']; |
57 | $journee = get_magic_quotes_gpc() ? stripslashes($_POST['journee']) : $_POST['journee']; |
58 | $domicile = get_magic_quotes_gpc() ? stripslashes($_POST['domicile']) : $_POST['domicile']; |
59 | $visiteur = get_magic_quotes_gpc() ? stripslashes($_POST['visiteur']) : $_POST['visiteur']; |
60 | $ptsDom = get_magic_quotes_gpc() ? stripslashes($_POST['ptsDom']) : $_POST['ptsDom']; |
61 | $ptsVis = get_magic_quotes_gpc() ? stripslashes($_POST['ptsVis']) : $_POST['ptsVis']; |
62 | $scoreDom = get_magic_quotes_gpc() ? stripslashes($_POST['scoreDom']) : $_POST['scoreDom']; |
63 | $scoreVis = get_magic_quotes_gpc() ? stripslashes($_POST['scoreVis']) : $_POST['scoreVis']; |
64 | |
65 | $message = ""; |
66 | |
67 | if ($_POST['saison'] && $_POST['div1']) { |
68 | $champPath = $_POST['saison']."/".$_POST['div1']; |
69 | if ($_POST['div2']) $champPath .= $SEP_DIV.$_POST['div2']; |
70 | if ($_POST['poule'] || $_POST['phase']) $champPath .= "/"; |
71 | if ($_POST['poule']) $champPath .= $_POST['poule']; |
72 | if ($_POST['phase']) $champPath .= $SEP_DIV.$_POST['phase']; |
73 | $path = ((IamAdmin()) ? "../datas" : "datas")."/$champPath"; |
74 | } else { |
75 | $message = "Données manquantes !";
|
76 | } |
77 | |
78 | if ($_POST['exporter-tout'] == "tout exporter") { |
79 | $zip = new zipfile(); |
80 | backup($zip, "../datas", "datas"); |
81 | $archive = $zip->file();
|
82 | header("Content-Type: application/x-zip"); |
83 | header("Content-Disposition: inline; filename=datas-".date("Y-m-d").".zip"); |
84 | echo $archive; |
85 | exit; |
86 | } elseif ($_POST['importer-tout'] == "tout importer") { |
87 | $message = "pas implémenté."; |
88 | } elseif ($_POST['supprimer-tout'] == "tout supprimer") { |
89 | $message = "pas implémenté."; |
90 | } |
91 | |
92 | if ($path) { |
93 | //echo "<p>path=$path.</p>\n"; |
94 | switch ($championnat) { |
95 | case "modifier": |
96 | if (file_exists("$path/equipes")) { |
97 | $equipes = file_get_contents("$path/equipes"); |
98 | } |
99 | break; |
100 | case "validation_ajouter": |
101 | if (!file_exists($path)) { |
102 | mkdirRecursive($path); |
103 | my_file_put_contents("$path/equipes", $equipes); |
104 | $message = "Le championnat a été ajouté."; |
105 | } else { |
106 | $message = "Le championnat existe déjà !"; |
107 | } |
108 | break; |
109 | case "validation_modifier": |
110 | my_file_put_contents("$path/equipes", $equipes); |
111 | $message = "Le championnat a été mis à jour."; |
112 | break; |
113 | case "supprimer": |
114 | // Suppression de tous les fichiers du répertoire |
115 | if ($dir = opendir($path)) { |
116 | while (($file = readdir($dir)) !== FALSE) { |
117 | if (is_file("$path/$file")) unlink("$path/$file"); |
118 | } |
119 | closedir($dir); |
120 | } |
121 | // Suppression du maximum de répertoires |
122 | while (isEmptyDir($path) && basename($path) != "datas") { |
123 | monRmdir($path); |
124 | $path = dirname($path); |
125 | } |
126 | $message = "Le championnat a été supprimé."; |
127 | break; |
128 | case "exporter": |
129 | $filename = $_POST['saison']."-".$_POST['div1']; |
130 | if ($_POST['div2']) $filename .= $_POST['div2']; |
131 | if ($_POST['poule'] || $_POST['phase']) $filename .= "-"; |
132 | if ($_POST['poule']) $filename .= $_POST['poule']; |
133 | if ($_POST['phase']) $filename .= $_POST['phase']; |
134 | $zip = new zipfile(); |
135 | backup($zip, $path, "datas/$champPath"); |
136 | $archive = $zip->file();
|
137 | header("Content-Type: application/x-zip"); |
138 | header("Content-Disposition: inline; filename=datas-$filename.zip"); |
139 | echo $archive; |
140 | exit; |
141 | break; |
142 | } |
143 | switch ($rencontre) { |
144 | case "ajouter": |
145 | $equipes = getEquipes($path); |
146 | break; |
147 | case "modifier": |
148 | $equipes = getEquipes($path); |
149 | list($prefix, $journee, $domicile, $visiteur) = explode("-", $rencontreId); |
150 | $file = "$path/match-".$journee."-".$domicile."-".$visiteur; |
151 | if (file_exists($file)) { |
152 | $resu = file_get_contents($file); |
153 | list($ptsDom, $ptsVis, $scoreDom, $scoreVis) = explode(":", $resu); |
154 | } |
155 | break; |
156 | case "validation_ajouter": |
157 | if ($journee == "" || $domicile == "" || $visiteur == "") { |
158 | $message = "Vous devez saisir le numéro de la journée, l'équipe qui reçoit et qui se déplace !"; |
159 | } else { |
160 | $file = "$path/match-".$journee."-".$domicile."-".$visiteur; |
161 | if (!file_exists($file)) { |
162 | my_file_put_contents($file, $ptsDom.":".$ptsVis.":".$scoreDom.":".$scoreVis); |
163 | $message = "La nouvelle rencontre a été ajoutée."; |
164 | } else { |
165 | $message = "La rencontre existe déjà !"; |
166 | } |
167 | } |
168 | break; |
169 | case "validation_modifier": |
170 | $file = "$path/match-".$journee."-".$domicile."-".$visiteur; |
171 | my_file_put_contents($file, $ptsDom.":".$ptsVis.":".$scoreDom.":".$scoreVis); |
172 | $message = "La rencontre a été mise à jour."; |
173 | break; |
174 | case "supprimer": |
175 | list($prefix, $journee, $domicile, $visiteur) = explode("-", $rencontreId); |
176 | $file = "match-".$journee."-".$domicile."-".$visiteur; |
177 | if (file_exists("$path/$file")) { |
178 | unlink("$path/$file"); |
179 | $message = "La rencontre a été supprimée."; |
180 | } |
181 | break; |
182 | } |
183 | } |
184 | ?>
|
185 | <html>
|
186 | <head>
|
187 | <title>Administration</title> |
188 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
189 | <meta http-equiv="Content-language" content="fr" /> |
190 | <meta name="copyright" content="Tous droits réservés - All Rights Reserved" /> |
191 | <meta name="author" content="Romuald DELAVERGNE"> |
192 | </head>
|
193 | <html>
|
194 | <body>
|
195 | <?php if ($championnat == "ajouter" || $championnat == "modifier" ) { ?> |
196 | <form name="admin" method="post" action="<?=$_SERVER['PHP_SELF']?>"> |
197 | <table border="0"> |
198 | <tr>
|
199 | <td>Saison</td> |
200 | <td>
|
201 | : |
202 | <?php if ($championnat == "ajouter") { ?> |
203 | <input type="text" name="saison" size="5" value="" /> |
204 | <?php } else { ?> |
205 | <input type="hidden" name="saison" value="<?=$_POST['saison']?>" /> |
206 | <?=$_POST['saison']."/".($_POST['saison']+1)."\n"?> |
207 | <?php } ?> |
208 | </td>
|
209 | </tr>
|
210 | <tr>
|
211 | <td>Division</td> |
212 | <td>
|
213 | : |
214 | <?php if ($championnat == "ajouter") { ?> |
215 | <select name="div1"> |
216 | <option value=""></option> |
217 | <?php
|
218 | foreach ($DIVISION as $n => $d) { |
219 | echo "\t\t\t\t\t\t<option value=\"$n\">$d</option>\n"; |
220 | } |
221 | ?>
|
222 | </select>
|
223 | <input type="text" name="div2" size="3" value="" /> |
224 | <?php } else { ?> |
225 | <input type="hidden" name="div1" value="<?=$_POST['div1']?>" /> |
226 | <input type="hidden" name="div2" value="<?=$_POST['div2']?>" /> |
227 | <?=$_POST['div1'].$_POST['div2']."\n"?> |
228 | <?php } ?> |
229 | </td>
|
230 | </tr>
|
231 | <?php if ($championnat == "ajouter" || $_POST['poule']) { ?> |
232 | <tr>
|
233 | <td>Poule</td> |
234 | <td>
|
235 | : |
236 | <?php if ($championnat == "ajouter") { ?> |
237 | <input type="text" name="poule" size="3" value="" /> |
238 | <?php } else { ?> |
239 | <input type="hidden" name="poule" value="<?=$_POST['poule']?>" /> |
240 | <?=$_POST['poule']."\n"?> |
241 | <?php } ?> |
242 | </td>
|
243 | </tr>
|
244 | <?php } ?> |
245 | <?php if ($championnat == "ajouter" || $_POST['phase']) { ?> |
246 | <tr>
|
247 | <td>Phase</td> |
248 | <td>
|
249 | : |
250 | <?php if ($championnat == "ajouter") { ?> |
251 | <select name="phase"> |
252 | <option value=""></option> |
253 | <option value="1">1</option> |
254 | <option value="2">2</option> |
255 | </select>
|
256 | <?php } else { ?> |
257 | <input type="hidden" name="phase" value="<?=$_POST['phase']?>" /> |
258 | <?=$_POST['phase']."\n"?> |
259 | <?php } ?> |
260 | </td>
|
261 | </tr>
|
262 | <?php } ?> |
263 | <tr>
|
264 | <td colspan="2"> |
265 | Liste des équipes :
|
266 | </td>
|
267 | </tr>
|
268 | <tr>
|
269 | <td colspan="2"> |
270 | <textarea name="equipes" cols="30" rows="10"><?=$equipes?></textarea> |
271 | </td>
|
272 | </tr>
|
273 | </table>
|
274 | <?php if ($championnat == "ajouter") { ?> |
275 | <input type="submit" name="validation_championnat" value="ajouter" /> |
276 | <?php } ?> |
277 | <?php if ($championnat == "modifier" ) { ?> |
278 | <input type="submit" name="validation_championnat" value="modifier" /> |
279 | <?php } ?> |
280 | </form>
|
281 | <?php retour("annuler"); ?> |
282 | <?php } else if ($rencontre == "ajouter" || $rencontre == "modifier") { ?> |
283 | <form name="admin" method="post" action="<?=$_SERVER['PHP_SELF']?>"> |
284 | <table border="0"> |
285 | <tr>
|
286 | <td colspan="3"> |
287 | Journée<?=($rencontre == "modifier") ? " $journee\n" : "\n"?> |
288 | <?php if ($rencontre == "ajouter") { ?> |
289 | <input type="text" name="journee" size="3" value="" /> |
290 | <?php } else { ?> |
291 | <input type="hidden" name="journee" value="<?=$journee?>" /> |
292 | <?php } ?> |
293 | </td>
|
294 | </tr>
|
295 | <tr>
|
296 | <td>
|
297 | <?php if ($rencontre == "ajouter") { ?> |
298 | Équipe à domicile : |
299 | <select name="domicile"> |
300 | <option value=""></option> |
301 | <?php
|
302 | foreach ($equipes as $n => $e) { |
303 | echo "\t\t\t\t\t\t<option value=\"$n\""; |
304 | if ($domicile && $n == $domicile) echo " selected"; |
305 | echo ">$e</option>\n"; |
306 | } |
307 | ?>
|
308 | </select>
|
309 | <?php } else { ?> |
310 | <input type="hidden" name="domicile" value="<?=$domicile?>" /> |
311 | <?=$equipes[$domicile]."\n"?> |
312 | <?php } ?> |
313 | </td>
|
314 | <td> points : <input type="text" name="ptsDom" size="3" value="<?=$ptsDom?>" /></td> |
315 | <td> score : <input type="text" name="scoreDom" size="3" value="<?=$scoreDom?>" /></td> |
316 | </tr>
|
317 | <tr>
|
318 | <td>
|
319 | <?php if ($rencontre == "ajouter") { ?> |
320 | Équipe à l'extérieure : |
321 | <select name="visiteur"> |
322 | <option value=""></option> |
323 | <?php
|
324 | foreach ($equipes as $n => $e) { |
325 | echo "\t\t\t\t\t\t<option value=\"$n\""; |
326 | if ($visiteur && $n == $visiteur) echo " selected"; |
327 | echo ">$e</option>\n"; |
328 | } |
329 | ?>
|
330 | </select>
|
331 | <?php } else { ?> |
332 | <input type="hidden" name="visiteur" value="<?=$visiteur?>" /> |
333 | <?=$equipes[$visiteur]."\n"?> |
334 | <?php } ?> |
335 | </td>
|
336 | <td> points : <input type="text" name="ptsVis" size="3" value="<?=$ptsVis?>" /></td> |
337 | <td> score : <input type="text" name="scoreVis" size="3" value="<?=$scoreVis?>" /></td> |
338 | </tr>
|
339 | </table>
|
340 | <?php hiddenVars() ?> |
341 | <?php if ($rencontre == "ajouter") { ?> |
342 | <input type="submit" name="validation_rencontre" value="ajouter" /> |
343 | <?php } ?> |
344 | <?php if ($rencontre == "modifier") { ?> |
345 | <input type="submit" name="validation_rencontre" value="modifier" /> |
346 | <?php } ?> |
347 | </form>
|
348 | <?php retour("annuler"); ?> |
349 | <?php
|
350 | } else { |
351 | retour("continuer", $message); |
352 | } |
353 | ?>
|
354 | </body>
|
355 | </html>
|