############################################################## 
## :	    
## :	 	   _Xz_
## TP2 :  TorrentPier.me
## :        
## 
## Installation Level: 	Easy 
## Installation Time: 	2 Minutes 
##############################################################

#
#-----[ SQL ]------------------------------------------
#
CREATE TABLE IF NOT EXISTS `bb_user_view` (

  `user_id` int(11) NOT NULL DEFAULT '0',

  `profile_id` int(11) NOT NULL DEFAULT '0',

  `time` int(11) NOT NULL DEFAULT '0'

) ENGINE=MyISAM DEFAULT CHARSET=latin1;
#
#-----[  ]------------------------------------------
#
usercp_viewprofile.php
#
#-----[  ]------------------------------------------
#
// Report [END]
#
#-----[   ]------------------------------------------
#
$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");
        }
    }
}
#
#-----[  ]------------------------------------------
#
templates/default/usercp_viewprofile.tpl
#
#-----[  ]------------------------------------------
#
<th colspan="2" class="thHead">{L_VIEWING_PROFILE}</th>
#
#-----[  ]------------------------------------------
#
<th colspan="3" class="thHead">{L_VIEWING_PROFILE}</th>
#
#-----[  ]------------------------------------------
#

	<!-- IF IS_AM --><span id="ip_list"></span><!-- ENDIF -->
	
	</td>
#
#-----[   ]------------------------------------------
#
td class="row1 pad_4 vTop" width="170px">
        <div class="bold cat border bw_TB vTop tCenter gensmall">{L_PP}</div> 
                 
        <!-- BEGIN view -->
        <div class="pad_4 border bw_B tLeft {view.CLASS}"<!-- IF view.HIDE --> style="background-color: #F9FCFF;"<!-- ENDIF -->>
        <div class="floatL"><img style="padding-right: 10px;" src="{AVATARS_URL}/{view.POSTER_AVATAR}" height="32" width="32"></div>
        {view.USERNAME}<br />
        <div class="spacer_2"></div>
        <span class="med"><i>{view.TIME}</i></span>
        <div class="clear"></div>
        </div>
        <!-- END view -->
        <!-- BEGIN not_view -->
        <div class="med pad_4 border bw_B row1">
            {L_NO_P}
        </div>
        <!-- END not_view -->
        <div class="spacer_4"></div>
        <!-- ENDIF -->
        </div>
#
#-----[  ]------------------------------------------
#
<td class="catBottom" align="center" colspan="2"><a href="{U_REPORT_USER}" class="gen">{L_REPORT_USER}</a></td>
#
#-----[  ]------------------------------------------
#
<td class="catBottom" align="center" colspan="3"><a href="{U_REPORT_USER}" class="gen">{L_REPORT_USER}</a></td>
#
#-----[ ]------------------------------------------
#
language/lang_russian/lang_main.php
#
#-----[  ]------------------------------------------
#
?>
#
#-----[   ]------------------------------------------
#
$lang['PP'] = ' ';
$lang['NO_P'] = ' ';
#
#-----[  ]------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[  ]------------------------------------------
#
?>
#
#-----[   ]------------------------------------------
#
$lang['PP'] = 'Last visitors';
$lang['NO_P'] = 'No visit';
# 
#-----[ /   ]------------------------------------------ 
# 
# EoM