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