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

$uniq_id = trim($_GET['vid']);

if(strlen($uniq_id) < 10 && strlen($uniq_id) > 5)
{
	if(!ctype_alnum($uniq_id))
		die("Invalid video ID");
	else
		$uniq_id = secure_sql($uniq_id);
}
else
{
	die("Invalid video ID");
}

if( isset($_POST['Submit']) && $uniq_id != '') {
	foreach($_POST as $k => $v)
	{
		$_POST[$k] = htmlspecialchars($v);
	}
	// check captcha code
    include ("include/securimage.php");
    $img = new Securimage();
    $valid = $img->check($_POST['imagetext']);

	$post_email = trim($_POST['email']);
	$post_name = magicSlashes(trim($_POST['name']));

	if (!is_real_email_address($post_email)) {
		$err_email = $lang['register_err_msg2'];
		$smarty->assign('err_email', $err_email);
	}
	if( !$valid ) {
		$err_captcha = $lang['register_err_msg1'];
	} elseif ($valid && is_real_email_address($post_email)) {
		$confirm_send = '1';
		$smarty->assign('confirm_send', $confirm_send);
		
		$query = @mysql_query("SELECT artist, video_title FROM pm_videos WHERE uniq_id = '".$uniq_id."'"); 
		$result = @mysql_fetch_array($query);
		if(!$query || !is_array($result))
		{
			die("An error occured! Mail not sent!");
		}
		$video_artist = $result['artist'];
		$video_title = $result['video_title'];
			// ** SENDING EMAIL ** //

			require_once("include/class.phpmailer.php");
			
				//*** DEFINING E-MAIL VARS
				$mailsubject = sprintf($lang['mailer_subj5'], $post_name);
				
				$array_content[]=array("mail_from", $post_name);  
				$array_content[]=array("video_id", $uniq_id);
				$array_content[]=array("artist", $video_artist);
				$array_content[]=array("video_name", $video_title);
				$array_content[]=array("site_url", _URL);
				//*** END DEFINING E-MAIL VARS
			
				if(file_exists('./email_template/'.$language.'/email_send_to_friend.html'))
				{
					$mail = send_a_mail($array_content, $post_email, $mailsubject, 'email_template/'.$language.'/email_send_to_friend.html');
				}
				elseif(file_exists('./email_template/english/email_send_to_friend.html'))
				{
					$mail = send_a_mail($array_content, $post_email, $mailsubject, 'email_template/english/email_send_to_friend.html');
				}
				elseif(file_exists('./email_template/email_send_to_friend.html'))
				{
					$mail = send_a_mail($array_content, $post_email, $mailsubject, 'email_template/email_send_to_friend.html');
				}
				else
				{
					@log_error(secure_sql('Error: Email template "email_send_to_friend.html" not found!'), 'Share Video', 1);
					$mail = TRUE;
				}
				if($mail !== TRUE)
				{
					@log_error($mail, 'Share Video', 1);
				}

			// ** END SENDING EMAIL ** //

	}
} 
	// ASSIG ERRORS 
	$smarty->assign('err_captcha', $err_captcha);
	// END ERRORS 
	$smarty->assign('template_dir', $template_f);
	$smarty->assign('vid', $uniq_id);
	$smarty->assign('post_email', $post_email);
	$smarty->assign('post_name', $post_name);
	$smarty->assign('title', 'Share this video with your friends');
	$smarty->display('share_header.tpl');
	$smarty->display('share_sendtofriend.tpl');
	$smarty->display('share_footer.tpl');
?>
