<?php
/* Include Files ***************************/
require_once('../db-config.php');
require_once('../inc/lib-compat-class.php');
require_once('../inc/lib-db-class.php');
require_once('../inc/lib-email-class.php');
require_once('../inc/lib-login-class.php');
/*******************************************/
global $rSdb;

$user	= new userManagement();
if(  !$user->_logged_in  )
	die(__('Access denied.','recipeshelf'));

if( ! check_ajax_referer('send-email', false) )
	die('0|'.__('Security Alert: Direct access not permitted!','recipeshelf'));

$_P['email'] 		= _rem_magic_quote($_POST['email']);
$_P['recipe-id'] 	= (int)$_POST['recipe-id'];
$_P['subject'] 		= _rem_magic_quote($_POST['subject']);
$_P['msg'] 			= _rem_magic_quote($_POST['msg']);
$_P['layout'] 		= _rem_magic_quote($_POST['layout']);
	
### Save email in addressbook
$sql		= "INSERT IGNORE INTO {$rSdb->DBobjects} (type,object,uid) VALUES ('4','".$_P['email']."','".(int)$user->_user_id."')";
$r2			= $rSdb->fetch( $sql );
$newEmail   = ($rSdb->affected_rows()>0)?1:0;

$email 	= new recipeEmail($_P['recipe-id'], $_P['email'],stripslashes($_P['subject']),str_replace("\n","<br />",stripslashes($_P['msg'])),stripslashes($_P['layout']));
$r 		= $email->send();

if( $r )
    echo '1|'.__('Email sent.','recipeshelf').'|'.$newEmail;
else
    echo '0|'.__('ERROR! Email could not be sent!','recipeshelf').'|'.$newEmail;

?>