<?php
// +------------------------------------------------------------------------+
// | PHP Melody version 1.6.6 ( www.phpsugar.com )
// +------------------------------------------------------------------------+
// | PHP Melody IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2011 PhpSugar.com. All rights reserved.
// +------------------------------------------------------------------------+

session_start();
require('config.php');
require_once('include/functions.php');
require_once('include/user_functions.php');
require_once('include/islogged.php');

$username = secure_sql( urldecode($_GET['u']) );
$query = mysql_query("SELECT * FROM pm_users where username = '".$username."'");
$rows = mysql_num_rows($query);
$r = mysql_fetch_array($query);

// ** IF USER DOESN'T EXIST REDIRECT TO HOMEPAGE ** //
if($rows == '0') {
header("Location: "._URL.""); 
exit;
}
$username = $r['username'];
//$gender = ucwords($r['gender']);
$gender = ucwords($lang[ $r['gender'] ]);
$country = countryid2name($r['country']);
$reg_date = ucwords(time_since($r['reg_date'])).' '.$lang['ago'];
$last_seen = ucwords(time_since($r['last_signin'])).' '.$lang['ago'];
$about = $r['about'];
$favorite = $r['favorite'];

if( $favorite == 1 ) 
{
	$query = @mysql_query("SELECT * FROM pm_favorites WHERE user_id = '".$r['id']."'");
	$results = @mysql_num_rows($query);
	if($results == 0) 
	{
		$problem = $lang['profile_msg_list_empty'];
	} 
	else 
	{
		$item = '';
		while($row = mysql_fetch_array($query)) {
		$uniq_id = $row['uniq_id'];
		
			$q = mysql_query("SELECT uniq_id, video_title, artist FROM pm_videos WHERE uniq_id = '".$uniq_id."'");
			while($result = mysql_fetch_array($q)) {	
			$item .= "
			<tr class=\"table_row1\">
			  <td width=\"32\"><a href=\"".makevideolink($row['uniq_id'], $row['artist'], $row['video_title'])."\"><img src=\"".show_thumb($result['uniq_id'])."\"  alt=\"".stripslashes($result['video_title'])."\" class=\"imag\" width=\"50\" height=\"38\" align=\"left\" /></a></td>
			  <td><a href=\"".makevideolink($row['uniq_id'], $row['artist'], $row['video_title'])."\"><span class=\"artist_name\">".stripslashes($result['artist'])."</span>
			  <br /><span class=\"song_name\">".fewchars(stripslashes($result['video_title']), 20)."</span></a></td>
			</tr>";
			}
		@mysql_free_result($q);
		}
	}
	@mysql_free_result($query);
	
	$share_link = _URL."/";
	if(_SEOMOD)
	{
		$share_link .= "playlist/".$r['username'];
	}
	else
	{
		$share_link .= "myfavorites.php?u=".$r['username'];
	}
	if($results == 0)
		$share_link = '';
}

if(empty($r['avatar']) || $r['avatar'] == 'no_avatar.gif') {

	if($r['gender'] == "male" || $r['gender'] == "female")
		$avatar = _URL."/"._UPFOLDER."/avatars/".$r['gender'].".gif";
	else
		$avatar = _URL."/"._UPFOLDER."/avatars/no_avatar.gif";

} else {
$avatar = _URL."/"._UPFOLDER."/avatars/".$r['avatar'];
}

// videos suggested by this user
$submitted_videos = array();

$sql = "SELECT uniq_id, artist, video_title 
		FROM pm_videos 
		WHERE submitted = '". secure_sql($username) ."' 
		ORDER BY id DESC
		LIMIT 5";
$result = @mysql_query($sql);

if ($result)
{
	$i = 0;
	while ($row = mysql_fetch_assoc($result))
	{
		$submitted_videos[$i] = $row;
		$submitted_videos[$i]['thumb'] = show_thumb($row['uniq_id']);
		$submitted_videos[$i]['link'] = makevideolink($row['uniq_id'], $row['artist'], $row['video_title']);
		$submitted_videos[$i]['video_title'] = fewchars(stripslashes($row['video_title']), 80);
		$i++;
	}	
	mysql_free_result($result);
}


$islive = islive($r['last_signin']);
if($islive == 1) 
	$status = '<img src="'._URL.'/templates/'._TPLFOLDER.'/images/ico_offline.gif"> '.$lang['memberlist_off'];
else 
	$status = '<img src="'._URL.'/templates/'._TPLFOLDER.'/images/ico_online.gif"> '.$lang['memberlist_on'];

// define meta tags & common variables
$meta_title = sprintf($lang['profile_title'], $username, _SITENAME);
$meta_description = '';
// end

$top_videos = top_videos($config['top_videos_sort'], _TOPVIDS);
$smarty->assign('top_videos', $top_videos);

$smarty->assign('username', $username);
$smarty->assign('gender', $gender);
$smarty->assign('country', $country);
$smarty->assign('reg_date', $reg_date);
$smarty->assign('last_seen', $last_seen);
$smarty->assign('status', $status);
$smarty->assign('about', $about);
$smarty->assign('avatar', $avatar);
$smarty->assign('favorite', $favorite);
$smarty->assign('items', $item);
$smarty->assign('share_link', $share_link);

$smarty->assign('social_website', $r['website']);
$smarty->assign('social_facebook', $r['facebook']);
$smarty->assign('social_twitter', $r['twitter']);
$smarty->assign('social_lastfm', $r['lastfm']);
$smarty->assign('power', $r['power']);
$smarty->assign('submitted_videos', $submitted_videos);

// --- DEFAULT SYSTEM FILES - DO NOT REMOVE --- //
$smarty->assign('meta_title', $meta_title);
$smarty->assign('meta_description', $meta_description);
$smarty->assign('template_dir', $template_f);
$smarty->display('profile.tpl');
?>