<?
/**
* 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 2.2.1
*/
session_start();
$handle = fopen("$_POST[file]", "r") or die("Impossible de lire le fichier");

$ret = "";
$premier_ligne=0;

//CONFIGURATION DE L'IMPORT

//Vц╘rification unicitц╘ des donneц╘s et renvoi les infos identiques de la bdd s'il y a
function verif_donnees($table,$keytable){
	// Recherche dans la table config les champs uniques dans une table en particulier
	$requete_unique = mysql_query("SELECT * FROM CONFIG WHERE Table_Id=$keytable AND IsUnique='true'");
	while($result_unique=mysql_fetch_object($requete_unique)){
		//recherche s'il existe dans la bdd une valeur identique pour ce champ 	
		$requete_recherche = mysql_query("SELECT * FROM $keytable WHERE ".$result_unique->Colonne_Id."=".$table[$keytable][$result_unique->Colonne_Id]."");
		if (mysql_num_rows($requete_recherche)!=0){
			return false;
		}else{
			return true;
		}
	}
}
//TRI DES INFORMATIONS
function tri($_POST,$count,$tableau){

	for($i = 0 ; $i< $count;$i++){
		if (($_POST[row.$i]!="NM")){
			$table[$_POST[table.$i]][$_POST[row.$i]].=$tableau[$i]." ";
		} 
	}
	return $table;
}

while (!feof ($handle)) {
        $ligne = fgets($handle);
	
        $ligne = str_replace("'","\'",$ligne);
        $ligne = str_replace("\"","",$ligne);
        $ligne = str_replace("\n","",$ligne);
	$lignetest=str_replace(";","",$ligne);
	$lignetest=str_replace(" ","",$lignetest);
	
        $tableau = explode(";", $ligne);
	$count = count($tableau);
	//echo $ligne;
	$table="";
	if (($premier_ligne!=0)&&($lignetest!="")){
		
		$table=tri($_POST,$count,$tableau);
		$i=0;
			
		//Vérification des données
		foreach($table as $keytable => $valuetable) {
			if (!verif_donnees($table,$keytable)){
				
			}
		}

	}
	$premier_ligne=1;	

}
?>