<?php
// +------------------------------------------------------------------------+
// | PHP Melody version 1.6.7 ( 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');

if( ! $logged_in)
{
	header("Location: "._URL. "/index."._FEXT);
}

// define meta tags & common variables
$meta_title	 = ucfirst($userdata['username'])." - ".$lang['my_favorites'];
$video_id 	 = secure_sql($_GET['vid']);
$action 	 = trim($_GET['a']);
$add_problem = '';
$meta_description = '';

if( ! empty($userdata['id']) && $action == 'show')
{
	$sql	 = "SELECT * 
				FROM pm_favorites 
				WHERE user_id = '".$userdata['id']."' 
				ORDER BY id DESC";
				
	$query 	 = @mysql_query($sql);
	
	if(@mysql_num_rows($query) == 0) 
	{
		$problem = $lang['profile_msg_list_empty'];
	} 
	else 
	{
		$item = '';
		$i = 1;
		$first_video = array();
		
		while($row = mysql_fetch_array($query)) 
		{
			$video = request_video($row['uniq_id'], 'favorites');
			
			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 .= '<tr class="table_row1" id="favorite-'. $i .'">';
			$item .= "\n";
			$item .= '<td width="49">';
			$item .= ' <a href="#videoplayer" onClick=\''. $onClick .'\'>';
			$item .= '  <img src="'. show_thumb($video['uniq_id']) .'"  alt="'. $thumb_alt .'" ';
			$item .= '  class="imag" width="116" height="87" align="left" />';
			$item .= ' </a>';
			$item .= '</td>';
			$item .= "\n";
			$item .= '<td>';
			$item .= ' <a href="#videoplayer" onClick=\''. $onClick .'\'>';
			$item .= '  <span class="artist_name">'. stripslashes($video['artist']) .'</span>';
			$item .= '  <br />';
			$item .= '  <span class="song_name">'. fewchars(stripslashes($video['video_title']), 80) .'</span>';
			$item .= ' </a>';
			$item .= '</td>';
			$item .= "\n";
			$item .= '<td width="10">';
			$item .= ' <a href="#" onclick=\'onpage_delete_favorite("'. $video['uniq_id'] .'", "#favorite-'. $i .'"); return false;\'>';
			$item .= '  <img src="'. _URL .'/templates/'. $template_f .'/images/ico_delete.gif" alt="Delete" border="0" />';
			$item .= ' </a>';
			$item .= '</td>';
			$item .= "\n";
			$item .= '</tr>';
			
			$i++;
		}
	}
} 
else 
{
	header("Location: index."._FEXT);
	exit();
}

//	generate share link
$share_link = _URL."/";
if(_SEOMOD)
{
	$share_link .= "playlist/".$userdata['username'];
}
else
{
	$share_link .= "myfavorites.php?u=".$userdata['username'];
}

if($userdata['favorite'] == 1)
{
	$smarty->assign('share_link', $share_link);
}
 
$smarty->assign('action', 		$action);
$smarty->assign('add_problem', 	$add_problem);
$smarty->assign('problem', 		$problem);
$smarty->assign('favorite_videos_list', $item);
$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);

if($action == 'add') 
{
	$smarty->display('favorites_add.tpl');
} 
else 
{
	$smarty->display('favorites.tpl');
}
?>