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