View file includes/usercp_viewprofile.php

File size: 22.75Kb
<?php

if ( !defined('IN_PHPBB') )
{
	die("Hacking attempt");
	exit;
}

if ( empty($HTTP_GET_VARS[POST_USERS_URL]) || $HTTP_GET_VARS[POST_USERS_URL] == ANONYMOUS )
{
	message_die(GENERAL_MESSAGE, $lang['No_user_id_specified']);
}
$profiledata = get_userdata($HTTP_GET_VARS[POST_USERS_URL]);

if ( isset($HTTP_GET_VARS['action']) || isset($HTTP_POST_VARS['action']) )
{
	$action = ( isset($HTTP_POST_VARS['action']) ) ? htmlspecialchars($HTTP_POST_VARS['action']) : htmlspecialchars($HTTP_GET_VARS['action']);
}
else
{
	$action = '';
}

//
// Update the profile view list
//
$user = $profiledata['user_id'];
$viewer = addslashes($userdata['username']);
$viewer_id = $userdata['user_id'];
$current_time = time();
if (( $user <> $viewer_id ) && $userdata['session_logged_in'] )
{
	$sql = "UPDATE " . USERS_TABLE . "
		SET user_profile_view = '1'
		WHERE user_id = '" . $user . "'";
	if ( !$db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, "Could not update user data.", '', __LINE__, __FILE__, $sql);
	}

	$sql = "SELECT * FROM " . PROFILE_VIEW_TABLE . "
		WHERE user_id = " . $user . "
		AND viewer_id = " . $viewer_id;

	if ( $result = $db->sql_query($sql) )
	{
		if ( !$row = $db->sql_fetchrow($result) )
		$sql = "INSERT INTO " . PROFILE_VIEW_TABLE . " (user_id, viewername, viewer_id, view_stamp, counter)
		        VALUES ('$user', '$viewer', '$viewer_id', '$current_time', '1')";
		if ( !$db->sql_query($sql) )
		{
		   message_die(GENERAL_ERROR, "Could not insert profile views.", '', __LINE__, __FILE__, $sql);
		}
		else
		{
			$count = $row['counter'] + 1;
			$sql = "UPDATE " . PROFILE_VIEW_TABLE . "
				SET view_stamp = '$current_time', counter = '$count'
				WHERE user_id = " . $user. "
				AND viewer_id = " . $viewer_id;
			if ( !$db->sql_query($sql) )
			{
			   message_die(GENERAL_ERROR, "Could not update profile views.", '', __LINE__, __FILE__, $sql);
			}
		}
	}
}

if (!$profiledata)
{
	message_die(GENERAL_MESSAGE, $lang['No_user_id_specified']);
}

if ($profiledata['user_allow_showprofile'] == 1 || $userdata['user_level'] == ADMIN || $userdata['user_id'] == $profiledata['user_id']) 

$sql = 'SELECT count(*) AS total
	FROM ' . ATTACHMENTS_TABLE . '
	WHERE user_id_1 = '.$profiledata['user_id'].' 
	AND user_id_2 = 0';
$result = $db->sql_query($sql);
if (!$result)
{
	message_die(GENERAL_ERROR, 'Unable to get attachment information.', '', __LINE__, __FILE__, $sql);
}
$rowatt = $db->sql_fetchrow($result);
if ( $rowatt['total'] > 0 )
{
	$totalfiles = '<a href="' . append_sid("profile.$phpEx?mode=viewfiles&amp;" . POST_USERS_URL .'=' . $profiledata['user_id']) . '">' . $rowatt['total'] . '</a>';
} 
else 
{
	$totalfiles = 0;
}

$sql = "SELECT *
	FROM " . RANKS_TABLE . " 
	ORDER BY rank_special, rank_min";
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not obtain ranks information', '', __LINE__, __FILE__, $sql);
}

$ranksrow = array();
while ( $row = $db->sql_fetchrow($result) )
{
	$ranksrow[] = $row;
}
$db->sql_freeresult($result);

$regdate = $profiledata['user_regdate'];
$memberdays = max(1, round( ( time() - $regdate ) / 86400 ));
$posts_per_day = $profiledata['user_posts'] / $memberdays;
if ( $profiledata['user_topics'] != 0  )
{
	$total_topics = get_db_stat('topiccount');
}
else
{
	$total_topics = 0;
}

if ( $profiledata['user_posts'] != 0  )
{
	$total_posts = get_db_stat('postcount');
	$percentage = ( $total_posts ) ? min(100, ($profiledata['user_posts'] / $total_posts) * 100) : 0;
}
else
{
	$percentage = 0;
}
                   
$user_status = 'No status';
if ( $profiledata['user_status'] )
{
	$user_status = $profiledata['user_status'];
} 

$poster_rank = '';
$rank_image = '';

if ( $profiledata['user_rank'] )
{
	for($i = 0; $i < count($ranksrow); $i++)
	{
		if ( $profiledata['user_rank'] == $ranksrow[$i]['rank_id'] && $ranksrow[$i]['rank_special'] )
		{
			$poster_rank = $ranksrow[$i]['rank_title'];
			$rank_image = ( $ranksrow[$i]['rank_image'] ) ? '<img src="' . $ranksrow[$i]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '"/><br />' : '';
		}
	}
}
else
{
	for($i = 0; $i < count($ranksrow); $i++)
	{
		if ( $profiledata['user_posts'] >= $ranksrow[$i]['rank_min'] && !$ranksrow[$i]['rank_special'] )
		{
			$poster_rank = $ranksrow[$i]['rank_title'];
			$rank_image = ( $ranksrow[$i]['rank_image'] ) ? '<img src="' . $ranksrow[$i]['rank_image'] . '" alt="' . $poster_rank . '" title="' . $poster_rank . '"/><br />' : '';
		}
	}
}

$temp_url = append_sid("privmsg.$phpEx?mode=post&amp;" . POST_USERS_URL . "=" . $profiledata['user_id']);
$pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a><br/>';

if ( !empty($profiledata['user_viewemail']) || $userdata['user_level'] == ADMIN )
{
	$template->assign_block_vars('email', array());
	$email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&amp;" . POST_USERS_URL .'=' . $profiledata['user_id']) : 'mailto:' . $profiledata['user_email'];
	$email = '<a href="' . $email_uri . '">' . $profiledata['user_email'] . '</a>';
}

if ( !empty($profiledata['user_website']) ) 
{ 
	if (preg_match('@^(?:http://vkontakte.ru/id)@i', $profiledata['user_website']))
        {
               $websitename = str_replace('http://vkontakte.ru/', 'VK ', $profiledata['user_website']);      
        }
        else
        {
               $websitename = str_replace('http://', '', $profiledata['user_website']);
        }
	$template->assign_block_vars('www', array());
	$www = '<a href="' . $profiledata['user_website'] . '">' . $websitename . '</a>';
}

if ( !empty($profiledata['user_icq']) ) 
{ 
	$template->assign_block_vars('icq', array());
	$icq_status_img = '<a href="http://wwp.icq.com/' . $profiledata['user_icq'] . '#pager"><img src="http://web.icq.com/whitepages/online?icq=' . $profiledata['user_icq'] . '&img=5" width="18" height="18" border="0" /></a>';
	if ( $board_config['send_user_icq'] && $profiledata['user_icq_send'] )
	{
		$icq = '<a href="' . append_sid("profile.$phpEx?mode=sendicq&amp;" . POST_USERS_URL .'=' . $profiledata['user_id']) . '">' . $profiledata['user_icq'] . '</a>';
	} 
	else 
	{
		$icq = $profiledata['user_icq'];
	}
}

if ( !empty($profiledata['user_number']) ) 
{ 
	$template->assign_block_vars('number', array());
	$number = $profiledata['user_number'];
}

if ( !empty($profiledata['user_aim']) ) 
{ 
	$template->assign_block_vars('aim', array());
	$aim = $profiledata['user_aim'];
}

if ( !empty($profiledata['user_msnm']) ) 
{ 
	$template->assign_block_vars('msn', array());
	$msn = $profiledata['user_msnm'];
}

if ( !empty($profiledata['user_yim']) ) 
{ 
	$template->assign_block_vars('yim', array());
	$yim = $profiledata['user_yim'];
}

if ( !empty($profiledata['user_from']) ) 
{ 
	$template->assign_block_vars('from', array());
	$from = $profiledata['user_from'];
}

if ( !empty($profiledata['user_occ']) ) 
{ 
	$template->assign_block_vars('occ', array());
	$occ = $profiledata['user_occ'];
}

if ( !empty($profiledata['user_interests']) ) 
{ 
	$template->assign_block_vars('interests', array());
	$interests = $profiledata['user_interests'];
}

$temp_url = append_sid("search.$phpEx?search_author=" . urlencode($profiledata['username']) . "&amp;showresults=posts");
$search = '<a href="' . $temp_url . '">' . sprintf($lang['Search_user_posts'], $profiledata['username']) . '</a>';

// Delete User MOD
if ( $userdata['user_level'] == ADMIN && $profiledata['user_id'] != ANONYMOUS )
{
	$temp_url = append_sid("delete_user.$phpEx?" . POST_USERS_URL .'=' . $profiledata['user_id'] . "&amp;file=profile&amp;sid=" . $userdata['session_id']);	
	$delete_user = '- <a href="' . $temp_url . '">' . sprintf($lang['Delete_user'], $profiledata['username']) . '</a>';
}
else
{
	$delete_user = '';
}

	
$user_points = ($userdata['user_level'] == ADMIN || user_is_authed($userdata['user_id'])) ? '<a href="' . append_sid("pointscp.$phpEx?" . POST_USERS_URL . "=" . $profiledata['user_id']) . '" title="' . sprintf($lang['Points_link_title'], $points_config['points_name']) . '">' . $profiledata['user_points'] . '</a>' : $profiledata['user_points'];

if ($points_config['points_donate'] && $userdata['user_id'] != ANONYMOUS && $userdata['user_id'] != $profiledata['user_id'])
{
	$donate_points = '<br />' . sprintf($lang['Points_donate'], '<a href="' . append_sid("pointscp.$phpEx?mode=donate&amp;" . POST_USERS_URL . "=" . $profiledata['user_id']) . '" title="' . sprintf($lang['Points_link_title_2'], $points_config['points_name']) . '">', '</a>');
}
	
$template->assign_block_vars('switch_user_points', array());

if ($profiledata['user_birthday']!=999999)
{ 
	$template->assign_block_vars('birthday', array());
	$user_birthday = realdate($lang['DATE_FORMAT'], $profiledata['user_birthday']);
} 

if ( !empty($profiledata['user_gender'])) 
{ 
	$template->assign_block_vars('gender', array());
           switch ($profiledata['user_gender']) 
           { 
                      case 1: $gender=$lang['Male'];break; 
                      case 2: $gender=$lang['Female'];break; 
                      default: $gender=$lang['No_gender_specify']; 
           } 
}

if ( $profiledata['user_weblog'] )
{
	$sql = "SELECT weblog_name FROM " . WEBLOGS_TABLE . " WHERE weblog_id = " . $profiledata['user_weblog'];
	if( !$result = $db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, "Couldn't obtain weblogs information.", "", __LINE__, __FILE__, $sql);
	}

	if( $row = $db->sql_fetchrow($result) )
	{
		$weblog = '<a href="' . append_sid("weblog.$phpEx?" . POST_WEBLOG_URL . "=" . $profiledata['user_weblog']) . '">' . $row['weblog_name'] . '</a>';
	}
}

$page_title = $lang['Viewing_profile'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

avatar_img($profiledata['user_avatar_type'], $profiledata['user_allowavatar'], $profiledata['user_avatar'], $avatar_img, $avatar_mini);
  
include($phpbb_root_path . 'includes/usercp_profile_gb.'.$phpEx);

if(isset($HTTP_GET_VARS['gb']))
{
	$gb = new guestbook($profiledata, $HTTP_GET_VARS['gb']);
}
else
{
	$gb = new guestbook($profiledata, 'view');
}

display_upload_attach_box_limits($profiledata['user_id']);

if ( $action == 'gb' )
{
        $template->set_filenames(array(
	        'body' => 'profile_gb_view.tpl')
        );
}
else if ( $action == 'inform' )
{
        $template->set_filenames(array(
	        'body' => 'profile_info_view.tpl')
        );
}
else
{
        $template->set_filenames(array(
	        'body' => 'profile_view_body.tpl')
        );
}        

if (function_exists('get_html_translation_table'))
{
	$u_search_author = urlencode(strtr($profiledata['username'], array_flip(get_html_translation_table(HTML_ENTITIES))));
}
else
{
	$u_search_author = urlencode(str_replace(array('&amp;', '&#039;', '&quot;', '&lt;', '&gt;'), array('&', "'", '"', '<', '>'), $profiledata['username']));
}
if ($board_config['warnings_enabled'] || $board_config['reputation_enabled'])
{
	include($phpbb_root_path . 'includes/functions_reputation.' . $phpEx);

	$is_auth = reputation_auth(NO_ID, $userdata, $profiledata);

	if ($board_config['warnings_enabled'] && !$is_auth['no_warn'])
	{
		$warn_img = $warn = $ban_img = $ban = '';

		if ($is_auth['auth_warn'])
		{
			$temp_url = "reputation.$phpEx?mode=warning&amp;" . POST_USERS_URL . "=" . $profiledata['user_id'] . "&amp;sid=" . $userdata['session_id'];
			$warn_img = '<a href="' . $temp_url . '">' . $lang['reputation_warn_user'] . '</a><br/>';
			$warn = '<a href="' . $temp_url . '">' . $lang['reputation_warn'] . '</a>';
		}
		if ($is_auth['auth_ban'])
		{
			$temp_url = "reputation.$phpEx?mode=ban&amp;" . POST_USERS_URL . "=" . $profiledata['user_id'] . "&amp;sid=" . $userdata['session_id'];
			$ban_img = '<a href="' . $temp_url . '">' . $lang['reputation_ban_user'] . '</a>';
			$ban = '<a href="' . $temp_url . '">' . $lang['reputation_ban'] . '</a>';
		}

		$template->assign_block_vars('warnings', array(
			'L_WARNINGS' => $lang['Warnings'],
			'WARNINGS' => $profiledata['user_warnings'],

			'RED' => $ban,
			'RED_IMG' => $ban_img,
			'YELLOW' => $warn,
			'YELLOW_IMG' => $warn_img)
		);

		if ($is_auth['auth_view_warns'] && $profiledata['user_warnings'])
		{
			$template->assign_block_vars('warnings.details', array(
				'U_SEARCH' => append_sid("profile.$phpEx?mode=warnings&amp;" . POST_USERS_URL . '=' . $profiledata['user_id']),
				'L_SEARCH' => sprintf($lang['reputation_search_warnings'], $profiledata['username']))
			);
		}
	}
	if ($board_config['reputation_enabled'] && !$is_auth['no_rep'])
	{
		if ( ($board_config['reputation_display'] == REPUTATION_PLUSMINUS) && ((($profiledata['user_reputation_plus'] - $profiledata['user_reputation']) + $profiledata['user_reputation_plus']) > 0) )
		{
			$poloska = @round(($profiledata['user_reputation_plus'])/(($profiledata['user_reputation_plus'] - $profiledata['user_reputation']) + $profiledata['user_reputation_plus'])*100,0);
			$poloska = '<img src="images/rate.php?i=' . $poloska . '" alt=""/><br/>';
		} 
		else 
		{
			$poloska = '';
		}
		$template->assign_block_vars('reputation', array(
			'L_REPUTATION' => $lang['Reputation'],
			'POLOSKA' => $poloska,
			'U_VIEW_REPUTATION' => append_sid("profile.$phpEx?mode=reputation&amp;" . POST_USERS_URL . '=' . $profiledata['user_id']),
			'REPUTATION' => reputation_display($profiledata, $is_auth, false))
		);

		if ($is_auth['auth_view_rep'] && ($profiledata['user_reputation'] || $profiledata['user_reputation_plus']))
		{
			$template->assign_block_vars('reputation.details', array(
				'U_SEARCH' => append_sid("profile.$phpEx?mode=reputation&amp;" . POST_USERS_URL . '=' . $profiledata['user_id']),
				'L_SEARCH' => sprintf($lang['reputation_search_reputation'], $profiledata['username']))
			);
		}
	}
}

$sql = "SELECT g.group_id, g.group_name, g.group_type,g.group_moderator, ug.user_pending
        FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
        WHERE ug.user_id = " . $_GET['u'] . "
        AND ug.group_id = g.group_id
        AND g.group_single_user <> " . TRUE . "
        ORDER BY g.group_name, g.group_moderator, ug.user_id";
if ( !($result = $db->sql_query($sql)) )
{
        message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
}

if ( $row = $db->sql_fetchrow($result) )
{
       $in_group = array();
       $s_member_groups_opt = '';
       $s_pending_groups_opt = '';
       $p = 1;

       do
       {
                 $in_group[] = $row['group_id'];
                 $moder = ($row['group_moderator'] == $_GET['u']) ? ' ('.$lang['Group_Moderator'].')' : null;  
                 if ( $row['user_pending'] )
                 {
                         $s_pending_groups_opt .= '<br/><a href="groupcp.'.$phpEx.'?&g=' . $row['group_id'] . '">' . $row['group_name'] . '</a>';
                 } 
                 else 
                 {
                         $s_member_groups_opt .= '<br/><a href="groupcp.'.$phpEx.'?g=' . $row['group_id'] . '">' . $row['group_name'] . '</a>' . $moder;
                 }              
        }
        while( $row = $db->sql_fetchrow($result) );

        if($s_pending_groups_opt == null && $s_member_groups_opt == null)
        {
                 $s_pending_groups=null;
                 $s_member_groups=null;
        }
        else
        {
                 $s_pending_groups = $s_pending_groups_opt;
                 $s_member_groups = $lang['Profile_groups'].$s_member_groups_opt;
        }
}
                
$template->assign_vars(array(
	'USERNAME' => $profiledata['username'],
	'GROUPS_MEMBER' => $s_member_groups,	
	'DELETE_USER' => $delete_user, // Delete User MOD
	'JOINED' => create_date($lang['DATE_FORMAT'], $profiledata['user_regdate'], $board_config['board_timezone']),
	'LASTVISIT' => create_date('G:i, d M Y', $profiledata['user_lastvisit'], $board_config['board_timezone']),
	'USER_STATUS' => $user_status,
	'POSTER_RANK' => $poster_rank,
	'RANK_IMAGE' => $rank_image,
	'EDIT_STATUS' => $edit_status, 
	'POSTS_PER_DAY' => $posts_per_day,
	'POSTS' => $profiledata['user_posts'],
	'ATTACH' => $totalfiles,
	'PERCENTAGE' => $percentage . '%', 
	'POST_DAY_STATS' => sprintf($lang['User_post_day_stats'], $posts_per_day), 
	'POST_PERCENT_STATS' => sprintf($lang['User_post_pct_stats'], $percentage), 
	'TOPICS' => $profiledata['user_topics'],
	'L_TOPICS' => $lang['Topics'] ,
	'U_SEARCH_USER_TOPICS' => append_sid("search.$phpEx?search_id=usertopics&amp;user=" . $profiledata['user_id']),
        'SEARCH' => $search,
	'PM' => $pm,
	'EMAIL' => $email,
	'WWW' => $www,
	'ICQ_STATUS_IMG' => $icq_status_img,
	'ICQ' => $icq, 
	'NUMBER' => $number, 
	'AIM' => $aim,
	'MSN' => $msn,
	'YIM' => $yim,
	'WEBLOG' => $weblog,
	'L_WEBLOG' => $lang['Weblog'],
	'POINTS' => $user_points,
	'DONATE_POINTS' => $donate_points,

	'LOCATION' => $from,
	'OCCUPATION' => $occ,
	'INTERESTS' => $interests,
        'GENDER' => $gender, 
	'BIRTHDAY' => $user_birthday,
	'AVATAR_IMG' => $avatar_img,
        'L_VIEWING_PROFILE' => sprintf($lang['Viewing_user_profile'], $profiledata['username']), 
	'L_ABOUT_USER' => sprintf($lang['About_user'], ''), 
	'L_AVATAR' => $lang['Avatar'], 
	'L_POSTER_RANK' => $lang['Poster_rank'], 
	'L_JOINED' => $lang['Joined'], 
	'L_TOTAL_POSTS' => $lang['Total_posts'], 
	'L_SEARCH_USER_POSTS' => sprintf($lang['Search_user_posts'], $profiledata['username']), 
	'L_CONTACT' => $lang['Contact'],
	'L_EMAIL_ADDRESS' => $lang['Email_address'],
	'L_EMAIL' => $lang['Email'],
	'L_PM' => $lang['Private_Message'],
	'L_ICQ_NUMBER' => $lang['ICQ'],
	'L_NUMBER' => $lang['Number'],
	'L_YAHOO' => $lang['YIM'],
	'L_AIM' => $lang['AIM'],
	'L_MESSENGER' => $lang['MSNM'],
	'L_WEBSITE' => $lang['Website'],
	'L_LOCATION' => $lang['Location'],
	'L_OCCUPATION' => $lang['Occupation'],
	'L_INTERESTS' => $lang['Interests'],
	'L_POINTS' => $points_config['points_name'],
        'L_GENDER' => $lang['Gender'], 
	'L_BIRTHDAY' => $lang['Birthday'],
	'S_STAT' => '<a href="'.append_sid('profile.'.$phpEx.'?mode=viewprofile&u=' . $profiledata['user_id']) . '&amp;action=stat">Моя Статистика</a><br/>',
	'S_INFO' => '<a href="'.append_sid('profile.'.$phpEx.'?mode=viewprofile&u=' . $profiledata['user_id']) . '&amp;action=inform">Мои данные</a><br/>',
	'S_GB' => '<a href="'.append_sid('profile.'.$phpEx.'?mode=viewprofile&u=' . $profiledata['user_id']) . '&amp;action=gb">Моя Гостевая</a><br/>',
	'S_VISITS' => '<a href="' . append_sid("profile_view_user.$phpEx?".POST_USERS_URL."=" . $profiledata['user_id'] . "&amp;".POST_POST_URL."=0").'">Мои Гости</a><br/>',	
	'U_EDITPROFILE' => '&#8226; <a href="'.append_sid('profile.'.$phpEx.'?mode=editprofile').'">'.$lang['Edit_Prorile_Reg'].'</a>',
	'U_EDITSTYLE' => '&#8226; <a href="'.append_sid('profile.'.$phpEx.'?mode=editstyle').'">'.$lang['Edit_Prorile_Style'].'</a>',
	'U_EDITCONFIG' => '&#8226; <a href="'.append_sid('profile.'.$phpEx.'?mode=editconfig').'">'.$lang['Edit_Prorile_Config'].'</a>',
	'U_EDITPROFILEINFO' => '&#8226; <a href="'.append_sid('profile.'.$phpEx.'?mode=editprofileinfo').'">'.$lang['Edit_Prorile_Info'].'</a>',
	'SMENA_CVETA' => '<a href="'.append_sid('profile.'.$phpEx.'?mode=money&amp;color').'">Сменить цвет ника</a>(' . $points_config['color_points'] . ')',
	'SMENA_ZVANIYA' => '<a href="'.append_sid('profile.'.$phpEx.'?mode=money&amp;status').'">Установить статус</a>('.$points_config['status_points'].')',
	'USER_POINT' => $userdata['user_points'], 
	'POINT_NAME' => $points_config['points_name'],
	'U_SEARCH_USER' => append_sid("search.$phpEx?search_author=" . $u_search_author),
	'U_PRESENTS' => append_sid("present.$phpEx?" . POST_USERS_URL . "=" . $profiledata['user_id']),
	'U_PERSONAL_GALLERY' => append_sid("album_personal.$phpEx?user_id=" . $profiledata['user_id']),
	'L_PERSONAL_GALLERY' => sprintf($lang['Personal_Gallery_Of_User'], $profiledata['username']),
	'S_PROFILE_ACTION' => append_sid("profile.$phpEx"))
);
if ( $action == 'stat' && $template_name == 'wap')
{
        $template->assign_block_vars('stat', array());
}
if ( $userdata['user_id'] == $profiledata['user_id'] )
{
	$template->assign_block_vars('editprofile', array() );
		
} 

include($phpbb_root_path . 'module/lenta.'.$phpEx);
include($phpbb_root_path . 'module/gallery.'.$phpEx);

$sql = "SELECT present_img, message FROM " . $table_prefix . "present
        WHERE present_user_id = " . $profiledata['user_id'] . "
        ORDER BY donate_time DESC LIMIT 0, 4";    	
if(!$result = $db->sql_query($sql))
{
	message_die(GENERAL_ERROR, 'Could not query guestbook', '', __LINE__, __FILE__, $sql);
}
while ($row = $db->sql_fetchrow($result))
{
       $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $row['message']);
       $template->assign_block_vars("present", array(                
              'PRESENT_IMAGE' => '<img src="images/present/' . $row['present_img'] . '" width="68" height="68" alt="' . $message . '"/>')
       );                        
}

//------------------GUEST_USERS----------------------------
$user_id = (isset($HTTP_POST_VARS[POST_USERS_URL])) ? intval($HTTP_POST_VARS[POST_USERS_URL]) : intval($HTTP_GET_VARS[POST_USERS_URL]);

$sql = "SELECT p.*, u.user_avatar_type, u.user_allowavatar, u.user_avatar FROM " . PROFILE_VIEW_TABLE . " p, " . USERS_TABLE . " u
	WHERE u.user_id = p.viewer_id
	AND p.user_id = " . $user_id . "
	ORDER BY p.view_stamp DESC LIMIT 6";
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, "Could not read profile views.", '', __LINE__, __FILE__, $sql);
}
$viewrow = array();
while( $row = $db->sql_fetchrow($result) )
{
	$viewrow[] = $row;
}
for ($i = 0; $i < count($viewrow); $i += 3)
{
	$template->assign_block_vars('table', array());
	for ($j = $i; $j < ($i + 3); $j++)
	{
		if( $j >= count($viewrow) )
		{
			break;
		}
	        $viewer = $viewrow[$j]['viewer_id'];

                avatar_img($viewrow[$j]['user_avatar_type'], $viewrow[$j]['user_allowavatar'], $viewrow[$j]['user_avatar'], $avatar_img, $avatar_mini);
                $row_class = ( !($j % 2) ) ? 'row_easy' : 'row_hard';
	        $template->assign_block_vars('table.userguest', array(
	               'ROW_CLASS' => $row_class,
		       'AVATAR_MINI' => $avatar_mini,
		       'USER_VIEW' => '<a href="'.append_sid("profile.$phpEx?mode=viewprofile&amp;".POST_USERS_URL."=$viewer").'">'.$viewrow[$j]['viewername'].'</a>',
		       'COUNTER_VIEW' => $viewrow[$j]['counter'],
		       'DATE_VIEW' => create_date('G:i, d M Y', $viewrow[$j]['view_stamp'], $board_config['board_timezone']))
	        );
	}
}
//-------------------------END-------------------------------------------
		
$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>