<?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();
define_syslog_variables();
include("../../../../includes/config.php");
include("../../../../includes/db/db_interface.php");
$db = db_interface::getInstance();
$db->db_connect();
$db->db_select($_SESSION['database']);

$module_id = strip_tags($_GET['module_id']);
$object_id = strip_tags($_GET['object_id']);
$colonne = strip_tags($_GET['colonne']);
$value = html_entity_decode(strip_tags(urldecode($_GET['value'])));

//On recupere la clee de la table
$keys = $db->db_query("SELECT `Colonne`,MODULE.`Table` FROM CONFIG,MODULE WHERE IsKey='1' AND CONFIG.Module_Id='$module_id' AND CONFIG.Module_Id = MODULE.Module_Id");
syslog(LOG_DEBUG,"Num Rows:".$db->db_num_rows($keys));
$key = $db->db_fetch_object($keys);
syslog(LOG_DEBUG,"Test:".$key->Colonne);
$table = $key->Table;
$table_key = $key->Colonne;

//On recupere l'ancienne valeur
$old_resultats = $db->db_query("SELECT $colonne FROM $table WHERE ".$key->Colonne."='$object_id'");
$old_resultat = $db->db_fetch_object($old_resultats);

if($old_resultat->$colonne != $value){
	$db->db_update("UPDATE $table SET $colonne = '$value' WHERE ".$key->Colonne."='$object_id'");
	$db->db_insert("INSERT INTO ARCHIVAGE VALUES('','$table','$object_id','$colonne','$value','".date('ymdHis')."','".$_SESSION['user_id']."','')");
	$resultats = $db->db_query("SELECT $colonne FROM $table WHERE ".$key->Colonne."='$object_id'");
	$resultat = $db->db_fetch_object($resultats);
	if($resultat->$colonne == $value){
		echo "OK";
	}else{
		echo "KO";
	}
}else{
	echo "OK";
}
$db->db_close();
?>