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