<?php
/** 
* @package	uForum 
* @file		common.php
* @version	$Id$ 
* @copyright	2007-2010 (c) PioDer <pioder@wp.pl>
* @link    		http://www.pioder.pl/
* @license	see LICENSE.txt
**/

if (is_dir('install'))
{
	die('<font color="red" face="Verdana" size="6">Please delete or rename catalog "install"</font>');
}

if (phpversion()<'5.0.7')
{
	die('&micro;Forum requires PHP 5.0.7 or later');
}
//set global preferences from DataBase
$sql="SELECT * FROM ".CONFIG_TABLE."";
$query=DataBase::sql_query($sql,CRITICAL,'Could not obtain config information');
while($result=DataBase::fetch($query))
{
	if (($result['name']=='') or ($result['name']=='0'))
	{
 		$forum_config['name']==false;
 	}
 	else
 	{
		$forum_config[$result['name']] = $result['value'];
	}
}
//check for disable forum
if ($_SESSION>0)
{
	if (($forum_config['disable_forum']) and (User::UserInformation($_SESSION['uid'],'rank')<2))
	{
		die($forum_config['disable_forum']);
	}
}
else
{
	if ($forum_config['disable_forum'])
	{
		die($forum_config['disable_forum']);
	}
}

define('TABLES_WIDTH',$forum_config['tables_width']);

//check for banned user
if ($_SESSION['uid']>0)
{
	$ip = $_SERVER['REMOTE_ADDR'];
	$uid = $_SESSION['uid'];
	$sql = "SELECT `IP`, `u_id`,  `motive` FROM ".BANLIST_TABLE." WHERE `IP`='$ip' OR `u_id`='$uid'";
	$result = DataBase::fetch(DataBase::sql_query($sql,GENERAL,'Could not obtain ban information'));
	$motive = $result['motive'];
	$db_ip = $result['IP'];
	$db_uid = $result['u_id'];
	if (($db_ip==$ip) || ($db_uid==$uid))
	{
   		require('./includes/misc_functions.php');
   		require('./lngs/'.DefaultLang(true).'/main.php');
 		SessDelete($_SESSION['uid']);
 		$_SESSION['uid']='0';
 		message_forum($motive,'index.php', '10');	
 	}
}

//set to variable userdata loged user informations
if ($_SESSION['uid']>0)
{
	$sql = "SELECT * FROM ".USERS_TABLE." WHERE `u_id`=".$_SESSION['uid']." LIMIT 1";
}
else
{
	$sql = "SELECT * FROM ".USERS_TABLE." WHERE `u_id`='-1'";
}
$query = DataBase::sql_query($sql, GENERAL,'Could not obtain loged user information');
$userdata = DataBase::fetch($query);
define('RANK', $userdata['rank']);


//protect of database - add the backslashes
/*foreach ($_POST as $name => $value)
{
	$_POST[$name] = mysql_real_escape_string($value);
}*/
?>