<?php
/** 
* @package	uForum 
* @file		user.php
* @version	$Id$ 
* @copyright	2007-2010 (c) PioDer <pioder@wp.pl>
* @link    		http://www.pioder.pl/
* @license	see LICENSE.txt
**/
define('IN_uF', true);
//include files
require('./config.php');
require('./includes/constants.php');
require('./includes/db.php');
require('./includes/errors.php');
//connect to database
DataBase::db_connect();
require('./includes/sessions.php');
require('./includes/classes/class_user.php');
require('./common.php');
require('./includes/misc_functions.php');
require('./includes/classes/class_forum.php');
require('./includes/classes/secure.php');
$default_lang = DefaultLang();
require('./lngs/'.$default_lang.'/main.php');
$start = TimeGeneration();
$default_skin =  ViewSkinName();
SessDelInvalid();	
SessRegister();
SessDeleteOld();	
$uid = intval($_GET['id']);
//check online for user
$sql = "SELECT `s_id`, `u_id`, `time` FROM ".SESSIONS_TABLE." WHERE `u_id`='$uid' AND time+1250>".$_SERVER['REQUEST_TIME']." LIMIT 1";
$query = DataBase::sql_query($sql, GENERAL, 'Could not read user active.');
$result = DataBase::fetch($query);
if ($result['u_id']==$uid)
{
	$active = 1;
}
else
{
	$active = 0;
}
unset($sql, $query, $result);
$userwarn = 0;
$sql = "SELECT `u_id`,`value` FROM `".WARNINGS_TABLE."` WHERE `u_id`='$uid'";
$query = DataBase::sql_query($sql,GENERAL,'Could not obtain user warns information');
$result = DataBase::num_rows($query);
while ($result = DataBase::fetch($query))
{
	if ($result['value']=='-')
    	{	
		$userwarn -=1;
	}
	else
 	{
		$userwarn +=1;
	}
}
$userwarn = ($userwarn>0) ? $userwarn*10 : $userwarn;
//add skin variables
$sql = "SELECT * FROM `".USERS_TABLE."` WHERE u_id='$uid'";
$query = DataBase::sql_query($sql,CRITICAL,'Could not obtain user information');
$user_info = DataBase::fetch($query);
if ($user_info['u_id']=='')
{
	message_forum($lng['no_user'],'index.php');
}
$skin = array(
'u_id'=>$_GET['id'],
'lang'=>$default_lang,
'sig'=>$user_info['sig'],
'lsig'=>$lng['sig'],
'posts'=>$user_info['posts'],
'luposts'=>$lng['posts'],
'lstat'=>$lng['stat'],
'stat'=>($active==1) ? 'online.gif' : 'offline.gif',
'prposts'=>User::PostWithForum($user_info['posts']),
'lastvisit'=>($user_info['lastvisit']!='0') ? date('d-m-Y, G:i',$user_info['lastvisit']) : $lng['never'],
'llastvisit'=>$lng['lulastvisit'],
'avatar'=>($user_info['avatar']!='') ? '<img src="'.$user_info['avatar'].'"  alt="av">' : '<br><br><br><br>',
'lavatar'=>$lng['avatar'],
'regdate'=>date('d-m-Y, G:i',$user_info['regdate']),
'lpalf'=>$lng['witch_all_post_forum'],
'lregdate'=>$lng['luregister'],
'interests'=>$user_info['interests'],
'linterests'=>$lng['luinterests'],
'userrank'=>User::UserRank($user_info['rank']),
'luserrank'=>$lng['lurank'],
'lwarns'=> $lng['warns'],
'show_topics'=> $lng['view_user_topics'],
'warnlevel' => $userwarn,
'warncolor'=>($userwarn>0) ? 'red' : 'green',
'lcontact'=>$lng['contact'],
'user_gg'=>(($user_info['allow_gg'])&& ($user_info['gg']!='0')) ?  '<a href="gg:'.$user_info['gg'].'"><img border="0" src="skins/'.$default_skin.'/images/gg.gif" onMouseOver="this.style.cursor=\'hand\'; this.src=\'skins/'.$default_skin.'/images/gg_active.gif\'"�
        onMouseOut="this.src=\'skins/'.$default_skin.'/images/gg.gif\'" alt="gg"></a>' : '',
'user_email'=>($user_info['allow_email']=='1') ?  '<a href="mailto:'.$user_info['email'].'"><img border="0" src="skins/'.$default_skin.'/images/email.gif" onMouseOver="this.style.cursor=\'hand\'; this.src=\'skins/'.$default_skin.'/images/email_active.gif\'"�
        onMouseOut="this.src=\'skins/'.$default_skin.'/images/email.gif\'" alt="email"></a>' : '',
);
$skin = array_push_assoc($skin,GenerateHeader($lng['showprofile'].': '.$user_info['nick'], '<a href="user.php?id='.$_GET['id'].'" class="navigator">'.$lng['showprofile'].': '.$user_info['nick']));
//do it!
require('./skins/'.$default_skin.'/overall_header.tpl');
require('./skins/'.$default_skin.'/user_body.tpl');
if($_SESSION['uid']>0)
{
	if(RANK==2)
	{
		$skin['pa_link']='<a href="admin/index.php" class="fsmall"><b>'.$lng['pa_link'].'</b></a>';
	}
	else
	{
		$skin['pa_link']='';
	}
}
else
{
	$skin['pa_link']=''; 
}
$stop = TimeGeneration();
$skin['queries'] =  ShowQueries($start, $stop);
require('./skins/'.$default_skin.'/overall_footer.tpl');
?>