<?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/searchCommentsConfig.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 searchCommentsConfig($name,&$xml,$requestName,$current_path,$firstNode,$firstNodePath){
	$db_conn = db_connect();
	
	$languageID = $xml->getData($firstNodePath."/@languageID");
	$module = $xml->getData($firstNodePath."/@module");
	$moduleInfo = moduleInfo($module);
	
	if ($moduleInfo->loaded==FALSE){
		$query_result = generateMsgXML(1,"The informations about the module $module couldn't be found.",0,'',$name);//"<MESSAGE name='$name' msgType='1'>The informations about the module couldn't be found.</MESSAGE>";
		return $query_result;
	}
	
	$sql='SELECT * FROM `commentsconfig` WHERE `ModuleID`='.$moduleInfo->ID.' ';
	if($languageID)
		$sql.=' AND `LanguageID`="'.$languageID.'"';
		
	$rs = $db_conn->Execute($sql);
	if (!is_object($rs)){
		sql_log($sql);
		return generateMsgXML(1,"Internal problem: sql request failed.",0,'',$name);
	}
	if ($name)
		$attributes.=" name='$name'";
	$external_file = $xml->getData($current_path.'/@fromFile');
	if($external_file)
		$attributes.=" fromFile='".$external_file."'";
	$query_result='<RESULTS'.$attributes.'>';
	while($row = $rs->FetchRow()){
		$query_result.='<COMMENTSCONFIG ID="'.$row['ID'].'" languageID="'.$row['LanguageID'].'" module="'.$moduleInfo->name.'">';
		$query_result.='<CONFIG>'.$row['Config'].'</CONFIG>';
		$query_result.='</COMMENTSCONFIG>';
	}
	$query_result.="</RESULTS>";
	
	return $query_result;
}
?>
