<?php
/**
* MiniClick
* Gestionnaire de tableau collaboratif
* Copyright (C) 2006 Guillaume Monet <gm@ibreizh.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
*
* @package miniclick
* @version 5.0.0
* @deprecated
*/
//Test de l'appel par le main ou un descendant 
if($GLOBALS['main'] != 1){
	die("Cannot acces directly to this page");
}
?>
<form action="main.php?page=engine/miniclic/valider_import_include.php" method="POST">
<?php
$ret = "";

$repertoireDestination = SMARTY_CACHE_DIR;
    $nomDestination        = $_FILES["monfichier"]["name"];
    
    // Pour raison de s�urit�nous ajouterons aux fichiers
    // portant une extension .php .php3, l'extension .txt
if (eregi(".php", $nomDestination)) {
	$nomDestination .= ".txt";
}

if (is_uploaded_file($_FILES["monfichier"]["tmp_name"])) {
	if (rename($_FILES["monfichier"]["tmp_name"],
		$repertoireDestination.$nomDestination)) {
		echo "Le fichier temporaire ".$_FILES["monfichier"]["tmp_name"]." a ��d�lac�vers ".$repertoireDestination.$nomDestination;
	} else {
		echo "Le dé";
	}
} else {
	echo "Le fichier n'a pas ��upload�(trop gros ?)";
}


$handle = fopen($repertoireDestination.$nomDestination, "r") or die("Impossible de lire le fichier");


$ct = 0;
echo "<table border=\"1\">";
while (!feof ($handle) && $ct < 1) {
        $ligne = fgets($handle);

        $ligne = str_replace("'","\'",$ligne);
        $ligne = str_replace("\"","",$ligne);
        $ligne = str_replace("\n","",$ligne);
	
        $tableau = explode(";", $ligne);
	$count = count($tableau);
	for($i = 0 ; $i< $count;$i++){
		$ret .= "<tr><td><select name=\"row$i\">";
		$table1 = mysql_query("SHOW COLUMNS FROM $_POST[modules]");
		$cnt = 0;
		$ok = 0;
		while($ligne1=mysql_fetch_object($table1)){
			$ret.= "<option value=\"$ligne1->Field\"";
			if($i == $cnt){
				$ret.= " SELECTED ";
				$ok = 1;
			}
		$ret.= ">$ligne1->Field</option>\n";
		$cnt++;
		}
		
		$ret.= "<option value=\"NM\"";
		if($ok == 0){
			$ret .=" SELECTED";
		}
		$ret.=">Not mapped</option>";
		
		$ret.= "</select></td>";
		$ret.= "<td>$tableau[$i]</td></tr>";
	}
	$ct++;
}
echo $ret;
echo "</table>";
echo "<input type=\"hidden\" name=\"file\" value=\"$nomDestination\">";
echo "<input type=\"hidden\" name=\"module\" value=\"$_POST[modules]\">";
echo "<br><button type=\"submit\">Valider</button>";
?>
</>
</html>
