<?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/createWeblogTable.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/>.
*/
require_once(dirname(__FILE__)."/../common/common_functions.inc.php");
require_once(dirname(__FILE__)."/../common/nql.class.php");
require_once(dirname(__FILE__)."/../common/date.class.php");

$today=new Date(date('Y-m-d'));
$db_conn = db_connect();
$sql="SELECT * FROM logs_web_years WHERE year=".$today->getYear().";";
$table = $db_conn->getRow($sql);

if(!$table){
	$sql="
	INSERT INTO logs_web_years (year) VALUES (".$today->getYear().");";
	debug_log($sql);
	$db_conn->Execute($sql);

	$sql="
	CREATE TABLE IF NOT EXISTS logs_web_".$today->getYear()." (
		month tinyint(1) NOT NULL DEFAULT '0',
		day tinyint(1) NOT NULL DEFAULT '0',
		hours tinyint(1) NOT NULL DEFAULT '0',
		minutes tinyint(1) NOT NULL DEFAULT '0',
		seconds tinyint(1) NOT NULL DEFAULT '0',
		VisitID bigint(20) NOT NULL DEFAULT '0',
		URL bigint(20) NOT NULL DEFAULT '0' REFERENCES referer_page(ID),
		elementID bigint(20) NOT NULL DEFAULT '0',
		ViewingCode varchar(250) NOT NULL DEFAULT '',
		LanguageID varchar(10) NOT NULL DEFAULT '',
		referrerHost bigint(20) NOT NULL DEFAULT '0' REFERENCES referer(ID),
		referrerPage bigint(20) NOT NULL DEFAULT '0' REFERENCES referer_page(ID),
		isSearch tinyint(1) NOT NULL DEFAULT '0',
		keyword text NOT NULL DEFAULT '',
		referrerCode varchar(255) NOT NULL DEFAULT '',
		bannerCode varchar(255) NOT NULL DEFAULT '',
		KEY(month, day),
		KEY(VisitID)
	) TYPE=MyISAM;";
	$db_conn->Execute($sql);
	echo "table logs_web_".$today->getYear()." created<br/>";
}else{
	echo "table logs_web_".$today->getYear()." already exist<br/>";
}

$today->addYear(1);

$sql="SELECT * FROM logs_web_years WHERE year=".$today->getYear().";";
$table = $db_conn->getRow($sql);
if(!$table){
	$sql="
	INSERT INTO logs_web_years (year) VALUES (".$today->getYear().");";
	debug_log($sql);
	$db_conn->Execute($sql);

	$sql="
	CREATE TABLE IF NOT EXISTS logs_web_".$today->getYear()." (
		month tinyint(1) NOT NULL DEFAULT '0',
		day tinyint(1) NOT NULL DEFAULT '0',
		hours tinyint(1) NOT NULL DEFAULT '0',
		minutes tinyint(1) NOT NULL DEFAULT '0',
		seconds tinyint(1) NOT NULL DEFAULT '0',
		VisitID bigint(20) NOT NULL DEFAULT '0',
		URL bigint(20) NOT NULL DEFAULT '0' REFERENCES referer_page(ID),
		elementID bigint(20) NOT NULL DEFAULT '0',
		ViewingCode varchar(250) NOT NULL DEFAULT '',
		LanguageID varchar(10) NOT NULL DEFAULT '',
		referrerHost bigint(20) NOT NULL DEFAULT '0' REFERENCES referer(ID),
		referrerPage bigint(20) NOT NULL DEFAULT '0' REFERENCES referer_page(ID),
		isSearch tinyint(1) NOT NULL DEFAULT '0',
		keyword text NOT NULL DEFAULT '',
		referrerCode varchar(255) NOT NULL DEFAULT '',
		bannerCode varchar(255) NOT NULL DEFAULT '',
		KEY(month, day),
		KEY(VisitID)
	) TYPE=MyISAM;";
	$db_conn->Execute($sql);
	echo "table logs_web_".$today->getYear()." created<br/>";
}else{
	echo "table logs_web_".$today->getYear()." already exist<br/>";
}

?>