<?php
/*

	osCommRes, Services Oline 
	http://www.oscommres.com 
	Copyright (c) 2005 osCommRes 
	
	Freeway eCommerce 
	http://www.zac-ware.com/freeway 
	Copyright (c) 2007 ZacWare
	
	Released under the GNU General Public License
*/



// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	
	require('includes/application_top.php');

	require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SUBSCRIPTION_INVITE_FRIEND);
	
	if (!tep_session_is_registered("customer_id")){
		$navigation->set_snapshot();
		$return=tep_db_prepare_input((isset($HTTP_GET_VARS["R"])?"R=1":''));
		tep_redirect(tep_href_link(FILENAME_LOGIN, $return, 'SSL'));
	}
	
	if (isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action']=='invite'){
		if (isset($HTTP_POST_VARS['suID'])==false || is_numeric($HTTP_POST_VARS['suID'])==false)
			tep_redirect(tep_href_link(FILENAME_ACCOUNT,'','SSL'));

		if (isset($HTTP_POST_VARS['invite_address'])==false || $HTTP_POST_VARS['invite_address']=="")
			tep_redirect(tep_href_link(FILENAME_ACCOUNT,'','SSL'));
		
		$invite_address=split(";",tep_db_prepare_input($HTTP_POST_VARS["invite_address"]));

		$subscription_id=(int)$HTTP_POST_VARS['suID'];
		$to_address=array();
		$to_name=array();
		for ($icnt=0;$icnt<sizeof($invite_address);$icnt++){
			if ($invite_address[$icnt]!=""){
				$split_arr=split(":>",$invite_address[$icnt]);
				if (sizeof($split_arr)>1){
					$to_name[]=$split_arr[0];
					$to_address[]=$split_arr[1];
				}
			}
		}
	
		if (sizeof($to_address)>0){
			$send_details['address']=&$to_address;
			$send_details['name']=&$to_name;
			$send_details['subscription_id']=$subscription_id;
			$send_details['customers_id']=$customer_id;
			$send_details['comments']=tep_db_prepare_input($HTTP_POST_VARS['invite_comments']);
			$send_details['mail_type']='INV';
	
			tep_send_subscription_invite_email($send_details);
			$messageStack->add_session('account', SUCCESS_INVITE_FRIENDS, 'success');
		}
		tep_redirect(tep_href_link(FILENAME_ACCOUNT,'','SSL'));
	}
	if (isset($HTTP_GET_VARS['suID'])==false || is_numeric($HTTP_GET_VARS['suID'])==false)
		tep_redirect(tep_href_link(FILENAME_ACCOUNT,'','SSL'));
    
	$subscription_id=(int)$HTTP_GET_VARS['suID'];
	
	$breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNTS_RESERVATIONS));
	$breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_SUBSCRIPTION_INVITE_FRIEND));
	
	$content = CONTENT_SUBSCRIPTION_INVITE_FRIEND;
	$javascript = 'popup_window.js';
	require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
	
	require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
