commit 748471df31c421f16c608b3379296d1209843b2d
Author: Romuald <devnull@localhost>
Date:   Wed Nov 26 23:21:45 2008 +0100

    Import de données exportées.

diff --git a/TODO b/TODO
index be810d8..0440a8f 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-* Import des donn�es (toutes, une liste de championnats ou un seul)
+* Am�liorer l'affichage lors de l'import
 * Gestion des p�nalit�s.
 * compte admin + comptes capitaines (uniquement modifier journ�e) (par exemple nouveau r�pertoire 'maj/')
 * Javascript pour �viter de faire � chaque fois [s�lectionner]
diff --git a/admin/admin.php b/admin/admin.php
index 3c36dbd..c3324db 100644
--- a/admin/admin.php
+++ b/admin/admin.php
@@ -30,6 +30,7 @@
 			<input type="submit" value="<?=$button?>" />
 		</form>
 <?php }
+
 	/*
 	echo "<pre>\n";
 	print_r($_POST);
@@ -66,17 +67,15 @@
 	$message = "";
 
 	if ($_POST['saison'] && $_POST['div1']) {
-		$champPath = $_POST['saison']."/".$_POST['div1'];
-		if ($_POST['div2']) $champPath .= $SEP_DIV.$_POST['div2'];
-		if ($_POST['poule'] || $_POST['phase']) $champPath .= "/";
-		if ($_POST['poule']) $champPath .= $_POST['poule'];
-		if ($_POST['phase']) $champPath .= $SEP_DIV.$_POST['phase'];
-		$path = ((IamAdmin()) ? "../datas" : "datas")."/$champPath";
-	} else {
-		$message = "Donn&eacute;es manquantes !";
+		$path = (IamAdmin()) ? "../datas" : "datas";
+		$path .= "/".$_POST['saison']."/".$_POST['div1'];
+		if ($_POST['div2']) $path .= $SEP_DIV.$_POST['div2'];
+		if ($_POST['poule'] || $_POST['phase']) $path .= "/";
+		if ($_POST['poule']) $path .= $_POST['poule'];
+		if ($_POST['phase']) $path .= $SEP_DIV.$_POST['phase'];
 	}
 
-	if ($_POST['exporter-tout'] == "tout exporter") {
+	if ($_POST['exporter'] == "exporter") {
 		$zip = new zipfile();
 		backup($zip, "../datas", "datas");
 		$archive = $zip->file();
@@ -84,19 +83,29 @@
 		header("Content-Disposition: inline; filename=datas-".date("Y-m-d").".zip");
 		echo $archive;
 		exit;
-	} elseif ($_POST['validation-importer'] == "importer") {
+	} elseif ($_POST['validation_importer'] == "importer") {
 		if ($_FILES['zipfile']['error'] == 0) {
-			$dest = "/tmp";
+			$dest = "..";
 			$zip = new SimpleUnzip($_FILES['zipfile']['tmp_name']);
 			if ($zip) {
+				$needToImport = array();
+				$alreadyExist = array();
 				foreach ($zip->Entries as $extr) {
 					if (!file_exists($dest."/".$extr->Path)) {
 						mkdirRecursive($dest."/".$extr->Path);
+						$needToImport[] = $extr->Path;
+					} else {
+						if (!in_array($extr->Path, $needToImport)) {
+							if (!in_array($extr->Path, $alreadyExist)) {
+								$message .= "<p>Le championnat ".$extr->Path." n'a pas &eacute;t&eacute; import&eacute; car il existe d&eacute;j&agrave; !</p>";
+								$alreadyExist[] = $extr->Path;
+							}
+						}
+					}
+					if (in_array($extr->Path, $needToImport)) {
 						$fh = fopen($dest."/".$extr->Path."/".$extr->Name, 'w');
 						fwrite($fh, $extr->Data);
 						fclose($fh);
-					} else {
-						$message .= "<p>Le championnat ".$extr->Path." existe d&eacute;j&agrave; !</p>";
 					}
 				}
 				$message .= "Donn&eacute;es import&eacute;es";
@@ -146,20 +155,6 @@
 				}
 				$message = "Le championnat a &eacute;t&eacute; supprim&eacute;.";
 				break;
-			case "exporter":
-				$filename = $_POST['saison']."-".$_POST['div1'];
-				if ($_POST['div2']) $filename .= $_POST['div2'];
-				if ($_POST['poule'] || $_POST['phase']) $filename .= "-";
-				if ($_POST['poule']) $filename .= $_POST['poule'];
-				if ($_POST['phase']) $filename .= $_POST['phase'];
-				$zip = new zipfile();
-				backup($zip, $path, "datas/$champPath");
-				$archive = $zip->file();
-				header("Content-Type: application/x-zip");
-				header("Content-Disposition: inline; filename=datas-$filename.zip");
-				echo $archive;
-				exit;
-				break;
 		}
 		switch ($rencontre) {
 			case "ajouter":
@@ -301,7 +296,7 @@
 	</form>
 <?php retour("annuler"); ?>
 <?php } else if ($rencontre == "ajouter" || $rencontre == "modifier") { ?>
-	<form name="admin" method="post" action="<?=$_SERVER['PHP_SELF']?>">
+	<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
 		<table border="0">
 			<tr>
 				<td colspan="3">
@@ -371,7 +366,7 @@
 		<form method="post" enctype="multipart/form-data">
 <?php hiddenVars() ?>
 			<input type="file" name="zipfile" value="" />
-			<input type="submit" name="selection-importer" value="importer" />
+			<input type="submit" name="validation_importer" value="importer" />
 		</form>
 <?php retour("annuler"); ?>
 <?php
