<?php 



class ControllerEmailfriend extends Controller {



	function index(){



		$customer =& $this->locator->get('customer');



		$module   =& $this->locator->get('module');



		$request  =& $this->locator->get('request');



		$response =& $this->locator->get('response');



		$template =& $this->locator->get('template');



		$url      =& $this->locator->get('url');



		$mail     =& $this->locator->get('mail');



		$database =& $this->locator->get('database');



		$config    =& $this->locator->get('config');



		if ($request->isPost()) {



			$product_id = $request->get('pro_id');



		   



			$results = $database->getRow("select p.weight,p.product_id,p.model,p.price,image.filename,product_description.name from product as p left join image on p.image_id=image.image_id left join product_description on p.product_id = product_description.product_id where p.product_id='$product_id'");



			



			$html ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



				<html xmlns="http://www.w3.org/1999/xhtml">



					<head>



					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />



					<title></title>



					<body>



					<table cellspacing="0" cellpadding="5" border="0" style="margin-left: 40px;">



					  <tbody><tr>



					    <td valign="top"><a target="_blank" href="https://www.beststoreitems.com/index.php?controller=product&product_id='.$results['product_id'].'"><img border="0" width="150" src="'.HTTP_IMAGE.$results['filename'].'"></a></td>



					    <td valign="top"><table cellspacing="1" cellpadding="8" border="0" bgcolor="#e7e7e7" align="center">



					      <tbody><tr>



					        <th bgcolor="#f6f6f6" align="right" scope="row"><p>Item Name:<br>



					        </p></th>



					        <td bgcolor="#ffffff"><a target="_blank" href="https://www.beststoreitems.com/index.php?controller=product&product_id='.$results['product_id'].'"><strong></strong>'.$results['name'].'</a></td>



					      </tr>



					      <tr>



					        <th bgcolor="#f6f6f6" align="right" scope="row">Item Code:</th>



					        <td bgcolor="#ffffff">'.$results['product_id'].'</td>



					      </tr>



					      <tr>



					        <th bgcolor="#f6f6f6" align="right" scope="row">beststoreitems Price:</th>



					        <td bgcolor="#ffffff"><strong>US$ '.$results['price'].'</strong></td>



					      </tr>



					      <tr>



					        <th bgcolor="#f6f6f6" align="right" scope="row">Weight:</th>



					        <td bgcolor="#ffffff">'.$results['weight'].'</td>



					      </tr>



					    </tbody></table></td>



					  </tr>



					</tbody></table>



					</body>



				 </html>';



			



			if($product_id > 0){



				$mail->setTo($request->get('Toemail','post'));







				$mail->setFrom($request->get('FromEmail','post'));







	    		$mail->setSender($config->get('config_store'));







	    		$mail->setSubject($request->get('Content', 'post'));



                



				$mail->setHtml($html);



	    		$mail->send();



	    		echo "<script>alert('Success.');window.location.href='/index.php?controller=product&product_id=$product_id';</script>";



	    		exit;



			}else{



		       	    echo '<script type="text/javascript">';



	    			echo 'alert("send fail!");';



	    			echo 'history.back()';	



	    			echo '</script>';



		     }



      		$response->redirect('https://www.beststoreitems.com/index.php?controller=product&product_id='.$product_id);



    	}



	}



}