<?php
/*
  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd 
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	include('includes/application_top.php');
	include('includes/classes/currencies.php');
  
	$reserve_ids=isset($HTTP_POST_VARS["reservation_id"])?$HTTP_POST_VARS["reservation_id"]:array();
	$type=(isset($HTTP_POST_VARS['process_type']) ? $HTTP_POST_VARS['process_type'] : 'single');
	$orders_id=(isset($HTTP_POST_VARS['oID']) ? (int)$HTTP_POST_VARS['oID'] : 0);
	$events_id=(isset($HTTP_POST_VARS['eID']) ? (int)$HTTP_POST_VARS['eID'] : 0);
	// if no reservation ids found just return to search reservation page
	if (sizeof($reserve_ids)<=0) {
		tep_redirect(tep_href_link(FILENAME_SEARCH_RESERVATIONS));
	}
	$params=array("tx_fname","tx_lname","page","tx_words","tx_code",
							"tx_from","tx_until","tx_event","tx_reserve","tx_waitlist","tx_rtype","tx_session","tx_current","orders_id","events_id","tx_pending");
	$search_params=tep_prepare_hidden_params($params,"post","get");

	$select_string=" op.orders_products_id in (" . join(",",$reserve_ids) . ") ";
	$session_query="SELECT o.orders_id,op.orders_id,o.customers_id,op.products_id,op.orders_products_id,s.start_date from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS . " s, " . TABLE_ORDERS . " o where " . $select_string . " and op.products_id=s.sessions_id and o.orders_id=op.orders_id";
	
	$session_fetch=tep_db_query($session_query);
	
	$currencies=new currencies();
	$mail_order=array();
	while ($session_detail=tep_db_fetch_array($session_fetch)){
	    tep_db_query("update " . TABLE_ORDERS_PRODUCTS . " set events_type='T' where orders_products_id='" . (int)$session_detail["orders_products_id"] . "'");
		if ($type=='single') {
			if (!isset($mail_order[$session_detail["orders_id"]])) $mail_order[$session_detail["orders_id"]]=array();
			$mail_order[$session_detail["orders_id"]][]=$session_detail["orders_products_id"];
		}
   	}
	if ($type=="group"){
		tep_send_event_group_email($orders_id,$events_id,'WTR','T');
	} else {
		if (sizeof($mail_order)>0){
			reset($mail_order);
			while(list($oID,)=each($mail_order)){
				if (sizeof($mail_order[$oID])>0){
					$id_string=join("','",$mail_order[$oID]);
					tep_send_event_email($id_string,'WTR');
				}
			}
		}
	}

	$messageStack->add(TEXT_WITHDRAW_SUCCESS,'success');
	
	
	//tep_process_waiting_list($HTTP_POST_VARS['event_id'],$HTTP_POST_VARS['reservation_id']);
	tep_redirect(tep_href_link(FILENAME_SEARCH_RESERVATIONS, "action=search&" . $search_params, 'SSL'));
?>