<?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/Library/updates/20090312-stats-v4/resources/searchWeblogs.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 generateWeblogXML($row){
	$query_result = '<WEBLOG>';
	$query_result.= '<YEAR>'.$row['year'].'</YEAR>';
	$query_result.= '<MONTH>'.$row['month'].'</MONTH>';
	$query_result.= '<DAY>'.$row['day'].'</DAY>';
	$query_result.= '<HOST>'.encode_to_xml($row['DomainName']).'</HOST>';
	$query_result.= '<URL>'.'/'.encode_to_xml($row['URI']).'</URL>';
	$query_result.='</WEBLOG>';
	return $query_result;
}
function generateFirstWeblogXML($row){
	$query_result = '<FIRSTWEBLOG server-date="'.$GLOBALS['sushee_today'].'">';
	$query_result.= '<YEAR>'.$row['year'].'</YEAR>';
	$query_result.= '<MONTH>'.$row['month'].'</MONTH>';
	$query_result.= '<DAY>'.$row['day'].'</DAY>';
	$query_result.= '<HOST>'.encode_to_xml($row['DomainName']).'</HOST>';
	$query_result.= '<URL>'.'/'.encode_to_xml($row['URI']).'</URL>';
	$query_result.='</FIRSTWEBLOG>';
	return $query_result;
}
function getFirstWeblog($name,$xml,$requestName,$current_path,$firstNode,$firstNodePath){
	if ($name)
		$attributes.=" name='$name'";
	$external_file = $xml->getData($current_path.'/@fromFile');
	if($external_file)
		$attributes.=" fromFile='".$external_file."'";
	$query_result='<RESULTS'.$attributes.'>';
	$db_conn = db_connect();
	$sql = 'SELECT * FROM logs_visit ORDER BY year ASC, month ASC, day ASC LIMIT 1';
	$row = $db_conn->GetRow($sql);
	$sql = 'SELECT logs_visit.year, logs_visit.month, logs_visit.day, host.DomainName, referrer_page.URI FROM logs_visit LEFT JOIN host ON Host=host.ID LEFT JOIN logs_web_'.$row['year'].' ON logs_visit.visitID=logs_web_'.$row['year'].'.visitID LEFT JOIN referrer_page on URL=referrer_page.ID'.
				' WHERE logs_visit.visitID='.$row['VisitID'].' ORDER BY logs_web_'.$row['year'].'.month ASC, logs_web_'.$row['year'].'.day ASC, hours ASC, minutes ASC, seconds ASC LIMIT 1';
	$row = $db_conn->GetRow($sql);
	echo $db_conn->ErrorMsg();
	$query_result .= generateFirstWeblogXML($row);
	$query_result .= '</RESULTS>';
	return $query_result;
}
?>
