<?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
*/
session_start();
include("../../../../includes/connection.php");
if ($_GET['val']) {
	if($_GET['val'] == " "){
		$_GET['val'] = "";
	}
	$table = $_GET['table'];
	$colonne = $_GET['colonne'];
	$configs = mysql_query("SELECT * FROM CONFIG WHERE Table_Id='$table' AND Colonne_Id='$colonne'");
	$config = mysql_fetch_object($configs);
	$table = $config->Defaut;
	$filter = $config->Value;
	$configs = mysql_query("SELECT * FROM CONFIG WHERE Table_Id='$table' AND IsKey='true'");
	$config = mysql_fetch_object($configs);
	$key = $config->Colonne_Id;
	$datas = mysql_query("SELECT $key,$filter FROM $table WHERE $filter like '".$_GET['val']."%' AND Societe_Id='".$_SESSION['societe']."' LIMIT 30");
	$completion = array();
	$i = 0;
	while($data = mysql_fetch_object($datas)){
		$completion[$i] = '"'.$data->$filter.";".$data->$key.'"';
		$i++;
	}
	sort($completion);
	echo '['.join(',',$completion).']' ;
}
?>