<?php
require 'database.inc.php';
if (Test_User($lg_user, $lg_password) == TRUE) {
	$file = fopen("Ok.txt", "r");
	while (($line = fgets($file)) !== false) {
		//echo $line . "<br/>";
		$fields = explode("\t", $line);
		//echo $fields[1] . "<br/>";
		$date = "";
		if (strlen($fields[6]) > 0) {
			$date = substr($fields[6], 6, 4) . "-" . substr($fields[6], 3, 2) . "-" . substr($fields[6], 0, 2);
		}
		$requette = "INSERT INTO clients (Allocution, Nom, Prenom, Adresse, NPA, Localite, DateNaissance, TelPriv, Fax, Natel, Email) VALUES ('" . Connection::getConnection()->quote($fields[0]) . "', '" . Connection::getConnection()->quote($fields[1]) . "', '" . Connection::getConnection()->quote($fields[2]) . "', '" . Connection::getConnection()->quote($fields[3]) . "', '" . Connection::getConnection()->quote($fields[4]) . "', '" . Connection::getConnection()->quote($fields[5]) . "', '" . Connection::getConnection()->quote($date) . "', '" . Connection::getConnection()->quote($fields[7]) . "', '" . Connection::getConnection()->quote($fields[8]) . "', '" . Connection::getConnection()->quote($fields[9]) . "', '" . Connection::getConnection()->quote(str_replace("\r\n", "", $fields[10])) . "')";
		Connection::executeRawQuery($requette);
		echo $requette . "<br/>";
	}
	fclose($file);
}
