$sql = DB()->fetch_rowset("SELECT v.*, u.username, u.user_opt, u.user_rank, u.user_avatar, u.user_avatar_type
FROM bb_user_view v
LEFT JOIN bb_users u ON(u.user_id = v.profile_id)
WHERE v.user_id = {$profiledata['user_id']}
ORDER BY v.time DESC");
$insert = true;
$limit = 0;
foreach($sql as $i => $row)
{
if($row['profile_id'] == $userdata['user_id'])
{
$insert = false;
if($i) $time = '';
else $time = $row['time'];
}
if($hide = bf($row['user_opt'], 'user_opt', 'allow_viewonline'))
{
if(!IS_ADMIN) continue;
}
$limit++;
if($limit > 5) continue; //Скока выводить
$user_avatar = 'images/avatars/gallery/noavatar.png';
switch($row['user_avatar_type'])
{
case USER_AVATAR_UPLOAD:
$user_avatar = ($bb_cfg['allow_avatar_upload']) ? $bb_cfg['avatar_path'] .'/'. $row['user_avatar'] : '';
break;
case USER_AVATAR_REMOTE:
$user_avatar = ($bb_cfg['allow_avatar_remote']) ? $row['user_avatar'] .'" alt="'. $lang['AVATAR'] : '';
break;
case USER_AVATAR_GALLERY:
$user_avatar = ($bb_cfg['allow_avatar_local']) ? $bb_cfg['avatar_gallery_path'] .'/'. $row['user_avatar'] : '';
break;
}
$template->assign_block_vars('view', array(
'CLASS' => ($i % 2) ? 'row2' : 'row1',
'HIDE' => $hide,
'POSTER_AVATAR' => $user_avatar,
'USERNAME' => '<a href="'. PROFILE_URL . $row['profile_id'] .'">'. wbr($row['username']) .'</a>',
'TIME' => bb_date($row['time'])
));
}
if(!$limit) $template->assign_block_vars('not_view', array());
if(!($profiledata['user_id'] == $userdata['user_id']) && !IS_GUEST)
{
$data = array(
'user_id' => $profiledata['user_id'],
'profile_id' => $userdata['user_id'],
'time' => TIMENOW,
);
if($insert)
{
$sql = DB()->build_array('INSERT', $data);
DB()->query("INSERT INTO bb_user_view ". $sql);
}
else
{
if($time < (TIMENOW - 300))
{
DB()->query("UPDATE bb_user_view SET time = '". TIMENOW ."'
WHERE user_id = {$profiledata['user_id']}
AND profile_id = {$userdata['user_id']}
LIMIT 1");
}
}
}