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