<?php
/*
Officity - Web application platform - Version 6.0 - 2011-07-05

François Dispaux, Boris Verdeyen, Thomas Hermant,
Jérémie Roy, Grégory Meurice, Abdelila Harbi, 
Marc Mignonsin, Jonathan Sanchez, Julien Gonzalez, Pierre Fouchez

Sushee and Officity is © Copyright 2011 Nectil SA.

`/sushee-source/sushee/private/updateDescConfig.inc.php` is part of Officity.

Sushee 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 3 of the License, or
(at your option) any later version.

Officity and Sushee are distributed in the hope that they 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 Sushee. If not, see <http://www.gnu.org/licenses/>.
*/
function updateDescConfig($name,&$xml,$requestName,$current_path,$firstNode,$firstNodePath){
	$db_conn = db_connect();
	
	$sql = "SELECT * FROM `descriptionsconfig` WHERE ID=-1;";
	$pseudo_rs = $db_conn->Execute($sql);
	// cleaning descriptionsconfig for this module
	$moduleInfo = moduleInfo($xml->getData($current_path."/DESCRIPTIONCONFIG[1]/@module"));
	$clean_sql = "DELETE FROM `descriptionsconfig` WHERE `ModuleID`=".$moduleInfo->ID.";";
	$db_conn->Execute($clean_sql);
	
	$desc_config_array = $xml->match($current_path."/DESCRIPTIONCONFIG");
	foreach($desc_config_array as $path){
		/*$descID = $xml->getData($path."/@ID");*/
		$languageID = $xml->getData($path."/@languageID");
		//$moduleInfo = moduleInfo($xml->getData($path."/@module"));
		$DescConfig = $xml->toString($path."/CONFIG/*");
		$Alingual = $xml->getData($path."/@alingual");
		if($Alingual!=1)
			$Alingual = 0;
		$desc_row = array("LanguageID"=>$languageID,"ModuleID"=>$moduleInfo->ID,"Config"=>$DescConfig,"Alingual"=>$Alingual );
		/*if($descID){
			$recup_sql = "SELECT * FROM `descriptionsconfig` WHERE `ID`='$descID';";
			$former_rs = $db_conn->Execute($recup_sql);
			$sql = $db_conn->GetUpdateSQL($former_rs, $desc_row);
		}else{*/
		$sql = $db_conn->GetInsertSQL($pseudo_rs, $desc_row);
		//}
		$db_conn->Execute($sql);
		//debug_log($sql);
	}
	$query_result = generateMsgXML(0,'DescriptionConfigs successfully modified.',0,'',$name);
	return $query_result;
}
?>
