<?php
/*
+--------------------------------------------------------------------------
|   CubeCart v3.0.11
|   ========================================
|   by Alistair Brookbanks
|	CubeCart is a Trade Mark of Devellion Limited
|   Copyright Devellion Limited 2005 - 2006. All rights reserved.
|   Devellion Limited,
|   22 Thomas Heskin Court,
|   Station Road,
|   Bishops Stortford,
|   HERTFORDSHIRE.
|   CM23 3EE
|   UNITED KINGDOM
|   http://www.devellion.com
|	UK Private Limited Company No. 5323904
|   ========================================
|   Web: http://www.cubecart.com
|   Date: Thursday, 27th July 2006
|   Email: sales (at) cubecart (dot) com
|	License Type: CubeCart is NOT Open Source Software and Limitations Apply 
|   Licence Info: http://www.cubecart.com/site/faq/license.php
+--------------------------------------------------------------------------
|	tellafriend.inc.php
|   ========================================
|	Tell a friend about a product	
+--------------------------------------------------------------------------
*/
if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || ereg(".inc.php",$_SERVER['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}

// query database
$_GET['productId'] = treatGet($_GET['productId']) ;
$result = $db->select("SELECT name FROM ".$glob['dbprefix']."CubeCart_inventory WHERE productId = ".$db->mySQLSafe($_GET['productId'])); 

	if($lang_folder !== $config['defaultLang']){
	
		$foreignVal = $db->select("SELECT name FROM ".$glob['dbprefix']."CubeCart_inv_lang WHERE prod_master_id = ".$db->mySQLSafe($_GET['productId'])." AND prod_lang=".$db->mySQLSafe($lang_folder));
		
		if($foreignVal==TRUE){
		
			$result[0]['name'] = $foreignVal[0]['name'];
			
		}
	
	}

// send email if form is submit
if(isset($_POST['submit'])){

// make email
		include("classes/htmlMimeMail.php");
		
		$mail = new htmlMimeMail();
        
		$text = sprintf($lang['front']['tellafriend']['email_body'],treatGet($_POST['recipName']),stripslashes(treatGet($_POST['message'])),$GLOBALS['storeURL'],treatGet($_GET['productId']),$GLOBALS['storeURL'],$_SERVER['REMOTE_ADDR']);
		
		// it must be 3ast3r
		if($_POST['senderName']=="senderName"){
			print_r(array($_POST['senderName'],$_POST['senderEmail']));
			exit;
		}
		
		$mail->setText($text);
		$mail->setReturnPath($_POST['senderEmail']);
		$mail->setFrom($_POST['senderName'].' <'.$_POST['senderEmail'].'>');
		$mail->setSubject(sprintf($lang['front']['tellafriend']['email_subject'],$_POST['senderName']));
		$mail->setHeader('X-Mailer', 'CubeCart Mailer');
		$send = $mail->send(array($_POST['recipEmail']), $config['mailMethod']);

}

$tellafriend=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/tellafriend.tpl");

	$tellafriend->assign("PRODUCT_ID",$_GET['productId']);
	
	$tellafriend->assign("TAF_TITLE",$lang['front']['tellafriend']['tellafriend']);
	
	if(isset($_POST['submit'])){
		$tellafriend->assign("TAF_DESC",sprintf($lang['front']['tellafriend']['message_sent'],$_POST['recipName'],$result[0]['name']));
	} else {
		$tellafriend->assign("TAF_DESC",sprintf($lang['front']['tellafriend']['fill_out_below'],$result[0]['name']));
	}
	
	$tellafriend->assign("TXT_RECIP_NAME",$lang['front']['tellafriend']['friends_name']);
	
	$tellafriend->assign("TXT_RECIP_EMAIL",$lang['front']['tellafriend']['friends_email']);
	
	
	$tellafriend->assign("TXT_SENDER_NAME",$lang['front']['tellafriend']['your_name']);
	
	if(isset($_POST['senderName'])){
		$tellafriend->assign("VAL_SENDER_NAME",$_POST['senderName']);
	}
	
	$tellafriend->assign("TXT_SENDER_EMAIL",$lang['front']['tellafriend']['your_email']);
	
	if(isset($_POST['senderName'])){
		$tellafriend->assign("VAL_SENDER_EMAIL",$_POST['senderEmail']);
	}
	
	$tellafriend->assign("TXT_MESSAGE",$lang['front']['tellafriend']['message']);
	
	if(isset($_POST['message'])){
		$tellafriend->assign("VAL_MESSAGE",stripslashes($_POST['message']));
	} else {
		$tellafriend->assign("VAL_MESSAGE",sprintf($lang['front']['tellafriend']['default_message'],$result[0]['name']));
	}
	
	$tellafriend->assign("TXT_SUBMIT",$lang['front']['tellafriend']['send']);


$tellafriend->parse("tellafriend");
$page_content = $tellafriend->text("tellafriend");
?>