<?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');

$who = trim($_GET['u']);
$who = str_replace( array('"', "/"), "", $who);
$who = username_to_id($who);

if($who == 0)
{
	header("Location: "._URL. "/index."._FEXT);
	exit();
}

$owner = fetch_user_advanced($who);

if($owner['id'] == $userdata['id'])
{
	header('Location: '._URL.'/favorites.php?a=show');
	exit();
}

if($owner['favorite'] == 0)
{
	$error_msg = $lang['favorites_msg2'];
}
else
{
	$videos = array();
	$videos = request_user_playlist($owner['id']);
	
	if($videos === false || (count($videos) == 0))
	{
		$error_msg = $lang['favorites_msg3'];
	}
	else
	{
		$item = '';
		$i = 1;
		$first_video = array();
		foreach($videos as $uniq_id => $video)
		{
			if($i == 1)
			{
				$first_video = $video;
			}
		
			$thumb_alt = stripslashes($video['video_title']);
			$thumb_alt = htmlspecialchars($thumb_alt);
			
			$onClick = 'ajax_request("video", "p=favorites&do=request&vid='. $video['uniq_id'] .'", "#embed_Playerholder", "html", true);';
			
			
			$item .='<div class="fav-playlist"><table class="table-rows"><tbody><tr><td class="play-fav-td">';
			$item .= '<a class="play-fav" href="#videoplayer" onClick=\''. $onClick .'\'></a></td><td class="play-fav-img-td">';
			$item .= '<a href="#videoplayer" onClick=\''. $onClick .'\'>';
			$item .= '<img src="'. show_thumb($video['uniq_id']) .'"  alt="'. $thumb_alt .'" /></a></td><td>';
			$item .= '<a href="#videoplayer" onClick=\''. $onClick .'\'>';
			$item .= '<span class="artist_name">'. stripslashes($video['artist']) .'</span>';
			$item .= '<span class="song_name">'. fewchars(stripslashes($video['video_title']), 20) .'</span></a></td></tr></tbody></table></div>';
			
			$i++;
	 	}
	}
}

$meta_title = sprintf($lang['myfavorites_title'], $owner['username']);

$smarty->assign('action', 	'show');
$smarty->assign('favorite_videos_list', $item);
$smarty->assign('problem', 	$error_msg);
$smarty->assign('video', 	$first_video);

// --- 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('myfavorites.tpl');
?>