<?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 );
// ajax code start
require ('includes/application_top.php');
require (DIR_WS_CLASSES . 'currencies.php');
require (DIR_WS_CLASSES . 'payment.php');
$currencies = new currencies();
$payment_modules = new payment();
$selection = $payment_modules->selection();
$server_date = getServerDate(true);
$costs = $HTTP_POST_VARS["service_costs"];
$current_order_total = "";
$service_id = (isset ($HTTP_POST_VARS['service_id']) ? $HTTP_POST_VARS['service_id'] : '');
$select_action = ((isset ($HTTP_POST_VARS["select_action"])) ? $HTTP_POST_VARS["select_action"] : '');
$service_action = ((isset ($HTTP_POST_VARS["ser_action"])) ? $HTTP_POST_VARS["ser_action"] : '');
$booking_ids = (isset ($HTTP_POST_VARS['booking_id']) ? $HTTP_POST_VARS['booking_id'] : '');
$start_date = $HTTP_POST_VARS['start_date'];
$start_time = $HTTP_POST_VARS['start_time'];
if ($start_time == '24:00')
	$start_time = "12:00";
$end_times = $HTTP_POST_VARS['end_times'];
if ($end_times) {
	$end_time_split = split(" ", $end_times);
	$end_date = $end_time_split[0];
	$end_time = $end_time_split[1];
}
if (isset ($HTTP_POST_VARS['start_times'])) {
	$start_times = $HTTP_POST_VARS["start_times"];
	$start_time_split = split(' ', $start_times);
	$start_date = $start_time_split[0];
	$start_time = $start_time_split[1];
}
$arg = "";
if ($HTTP_POST_VARS || $HTTP_GET_VARS) {
	if ($HTTP_POST_VARS)
		$get_post_vars = & $HTTP_POST_VARS;
	else
		if ($HTTP_GET_VARS)
			$get_post_vars = & $HTTP_GET_VARS;
	$arg = 'search&tx_code=' . $get_post_vars['tx_code'] . '&tx_fname=' . $get_post_vars['tx_fname'] . '&tx_from=' . $get_post_vars['tx_from'] . '&tx_lname=' . $get_post_vars['tx_lname'] . '&tx_pending=' . $get_post_vars['tx_pending'] . '&tx_resource=' . $get_post_vars['tx_resource'] . '&tx_service=' . $get_post_vars['tx_service'] . '&tx_until=' . $get_post_vars['tx_until'];
}
if ($service_id) {
	$service_details = get_services_info($service_id);
	$current_date_string=getServerDate(false);	
	$combo_start_date=getServerDate(); // combo start_date
	$combo_end_date=date('Y-m-d',tep_dateadd(strtotime($combo_start_date),"day",30));
	$service_start_time="00:00:00"; // start_time
	$service_end_time="23:59:00"; // end time
	$time_length=(int)($service_details["service_total_time"])?$service_details["service_total_time"]:1;
	$granular=(int)($service_details["booking_granular"])?$service_details["booking_granular"]:1;	
	//$booking_total = services_dates($service_id, 'no_booking_dates');		
	/*for($bk=0;$bk<sizeof($booking_total);$bk++){
		 $nbstime=$booking_total[$bk]['start_time'];
		 $nbetime=$booking_total[$bk]['end_time'];
		 $nb_sdate=$booking_total[$bk]['start_date'];
		 $nb_edate=$booking_total[$bk]['end_date'];
		if($nbstime=="12:00:00"){ $nbstime="00:00:00";} 
		if($nb_sdate!=$nb_edate || $nbstime>$nbetime){
			$details.=format_date($nb_sdate).'#'.$nbstime.'#'.'24:00:00' . "?";
			$details.=format_date($nb_sdate).'#'.'00:00:00'.'#'.$nbetime . "?";	
	    }else  $details.=format_date($nb_sdate).'#'.$nbstime.'#'.$nbetime . "?";	   
	}*/
	// get no booking dates
			 $bk_query=tep_db_query("select no_booking_start_date,no_booking_end_date,no_booking_start_time,no_booking_end_time,recurring_type,recurring_details from ".TABLE_SERVICES_NO_BOOKING_DAYS ." snd where snd.service_id='".(int)$service_id."' and (('$combo_start_date'>=no_booking_start_date and '$combo_start_date'<=no_booking_start_date) OR  ('$combo_end_date'>=no_booking_start_date and '$combo_end_date'<=no_booking_end_date) OR ('$combo_start_date'<=no_booking_start_date and '$combo_end_date'>=no_booking_end_date)) order by no_booking_start_date,no_booking_end_date,no_booking_start_time,no_booking_end_time");
			 $shour=0;
			 $ehour=23;
			 $nbd_array=array();
			 $no_booking_sdate='';
			 $no_booking_edate='';
			 $cur_time=date("H",$current_date_string) .':00:00';
			 while($nbk=tep_db_fetch_array($bk_query)){
				$recurring_type=$nbk['recurring_type'];
				if($recurring_type!='DD'){	
					$sInfo=$nbk;
					$nb_dates=tep_get_dates_array($sInfo,$recurring_type);
					$start_date=$combo_start_date;
					$end_date=$combo_end_date;  
					$nbd_array[]=formated_type_dates('dates');
					$nb_dates_array[]=formated_type_dates('n_dates');
				}else if($recurring_type=='DD'){
					 if($booking_type=='D') $no_booking_sdate_array[]=array('start_date'=>$nbk['no_booking_start_date'],'end_date'=>$nbk['no_booking_end_date']);
					 $temp_month_start_date=$combo_start_date;
					 while($temp_month_start_date<=$combo_end_date){
					 	if($nbk['no_booking_start_date']<=$temp_month_start_date && $nbk['no_booking_end_date']>=$temp_month_start_date  && $current_date<=$temp_month_start_date){
					 		$no_b_stime=$nbk['no_booking_start_time'];
							$no_b_etime=$nbk['no_booking_end_time'];
							if($booking_type=='D'){
								$no_b_stime="00:00:00";
								$no_b_etime="24:00:00";
							}
							$no_b_sdate=$temp_month_start_date;
							$no_b_edate=$temp_month_start_date;	
					 		if($no_b_etime<=$no_b_stime && $span_days=='Y')
								$no_b_edate=date("Y-m-d",tep_dateadd(@strtotime($temp_month_start_date),"day",1));
							else if($no_b_etime<=$no_b_stime && $span_days=='N')
								$no_b_etime="24:00:00";
							if($temp_month_start_date<=$no_b_sdate && $month_end_date>=$no_b_sdate){
								$nbd_array[][]=array('type'=>$recurring_type,'n_s_date'=>$no_b_sdate,'n_e_date'=>$no_b_edate,'n_s_time'=>$no_b_stime,'n_e_time'=>$no_b_etime);
								$nb_split=split(':',$no_b_etime);
								if($no_b_stime=='00:00:00' && ($no_b_etime>=(24-$time_length).':05:00' && $no_b_etime<='24:00:00') || (($booking_type=='H' || $booking_type=='M')  && $time_length!='' && date("d",mktime(($nb_split[0]+$time_length),$mt,0,1,1,1987))=="02")) 
									$nb_dates_array[][format_date($no_b_sdate)]='full';									
							 	if($no_b_stime<=$cur_time && ($no_b_etime>=(24-$time_length).':05:00' && $no_b_etime<='24:00:00') && $no_b_sdate<=$combo_start_date && $no_b_edate>=$combo_start_date)
									$nb_dates_array[][format_date($no_b_sdate)]='full';							 	
							}
					 	} 
					    if($temp_month_start_date) $temp_month_start_date=date('Y-m-d',tep_dateadd(@strtotime($temp_month_start_date),"day",1));
					 }
				}		
			}
		$block_dates=$nb_dates_array;
		$ser_date=tep_get_service_dates_array($combo_start_date,$combo_end_date,$service_details['booking_type']);			
	   //get no booking dates
 }
//get old order total 
$booking_detail = "select o.*,c.*,op.*,os.*,se.service_location,os.resource_name,sd.service_name,se.service_id,os.start_time,os.end_time,os.start_date,os.end_date,op.products_price,op.products_tax,op.products_quantity,op.final_price " . $fields . " from " .
TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o, " . TABLE_CUSTOMERS . " c, " . TABLE_ORDERS_SERVICES . " os, " . TABLE_SERVICES . " se, " . TABLE_SERVICES_DESCRIPTION . " sd " .
" where op.products_type='V' and op.orders_id=os.orders_id and op.orders_products_id=os.orders_products_id " .
" and  op.orders_id=o.orders_id and c.customers_id=o.customers_id and op.products_id=os.products_id and os.products_id=se.service_id and sd.service_id=se.service_id and sd.language_id='" . $languages_id . "'" . " and op.orders_products_id ='" . (int) $booking_ids[0] . "'";
$booking_query = tep_db_query($booking_detail);
$old_order_price = "";
$old_order_tax = "";
if (tep_db_num_rows($booking_query) > 0) {
	$booking = tep_db_fetch_array($booking_query);
	$product_id = (int) $booking['products_id'];
	$orders_id = (int) $booking['orders_id'];
	$orders_products_id = (int) $booking['orders_products_id'];
	$service = get_services_info((int) $product_id, (int) $languages_id);
	$orders_products_id = $booking_ids[0];
	$old_order_tax = tep_calculate_tax($booking["final_price"], $booking["products_tax"]);
	// get amount for this service
	$old_order_price = get_amount_for_orders($orders_id, $orders_products_id, $product_id);
	$error = "";
	if ($booking['start_date'] . ' ' . $booking['start_time'] <= date('Y-m-d h:i A')) 
		$error = ERR_SERVICE_INVALID;
	$order_status = $booking["orders_status"];
	$customer_id = $booking["customers_id"];
	if ($old_order_price == 0) $error = ERR_OLD_ORDER_AMOUNT_IS_LOW;
}
//get old order total 
if ($service_action == 'check_service') {
	$service_costs = "";
	$service_tax = "";
	$service_found = false;
	$resource_array = array ();
	$quantity = 1;
	$product_price = $service_price;
	if ($service_details["include_resource"] == 'N' && $service_details["multiple_purchase"] == 'Y') {
		$quantity = (isset ($HTTP_POST_VARS["txt_quantity"]) ? $HTTP_POST_VARS["txt_quantity"] : 1);
		if ($quantity == 0)
			$quantity = 1;
	}
	$service = $service_details;
	$error = tep_check_service_found($service_id, $start_date, $end_date, $start_time, $end_time, 'error');
	if ($error == "")  $service_found = true;
	else if ($service_details["include_resource"] == 'Y') {
			$reserved_resource = get_resource_ids((int) $service_id, $start_date, $end_date, $start_time, $end_time, $service_details["booking_type"]);
			if ($reserved_resource) {
				while (list ($key, $value) = each($reserved_resource)) {
					if ($value > 0)
						$reserved_resource_id .= str_replace(",", "','", $value . ((sizeof($reserved_resource) == $key +1) ? "" : ','));
				}
			}
			if ($service_details["include_resource"] == 'N' || $service_details["include_resource"] == 'Y' && $service_details["include_resource_price"] == 'N') {
				$service_costs = $service_details["service_costs"];
				$service_tax = $service_details["service_tax_class_id"];
			}
			$resource_query = tep_db_query("select red.resource_name,red.resource_description,re.resource_id,re.resource_costs,re.resource_tax_class_id from " . TABLE_RESOURCES . " re, " . TABLE_RESOURCES_DESCRIPTION . " red," . TABLE_SERVICES_TO_SERVICES_RESOURCES . " seTre where seTre.service_id='" . (int) $service_id . "' and re.resource_id not in('" . $reserved_resource_id . "')  and red.language_id='" . (int) $languages_id . "' and seTre.service_resource_id=re.resource_id and re.resource_id=red.resource_id order by red.resource_name");
			if (tep_db_num_rows($resource_query) > 0) {
				while ($resource = tep_db_fetch_array($resource_query)) {
					$service_found = true;
					if ($service_details["include_resource"] == 'Y' && $service_details["include_resource_price"] == 'Y') {
						$service_costs = $resource["resource_costs"];
						$service_tax = $resource["resource_tax_class_id"];
					}
					$service_price = tep_add_tax($service_costs, tep_get_tax_rate($service_tax));
					$resource_array[] = array (
						'id' => $resource["resource_id"] . '-' . $service_price . '-' . $resource["resource_tax_class_id"],
						'text' => $resource["resource_name"] . '-' . $currencies->format($service_price
					));
				}
		  }
	 }
	$service_price = $service_details["service_costs"];
	$service_price_tax = $service_details["service_tax_class_id"];
	$option_price = "";
	$price_split = split("-", $HTTP_POST_VARS['resource']);
	$resource_id = $price_split[0];
	if ($service_details["include_resource"] == 'Y' && $service_details["include_resource_price"] == 'Y' && isset ($HTTP_POST_VARS['resource'])) {
		$service_price = $price_split[1];
		$service_price_tax = $price_split[2];
	}
	// get attribute price
	$attrib_array = array ();
	$get_attribute = tep_db_query("SELECT so.services_options_name,so.services_options_id FROM " . TABLE_SERVICES_ATTRIBUTES . " sa LEFT JOIN " . TABLE_SERVICES_OPTIONS . " so ON so.services_options_id=sa.options_id LEFT JOIN " . TABLE_SERVICES_OPTIONS_VALUES . " sov ON sov.services_options_values_id=sa.options_values_id WHERE sa.service_id='" . (int) $service_id . "' and so.language_id='" . $languages_id . "' and sov.language_id='" . $languages_id . "' group by so.services_options_id");
	if (tep_db_num_rows($get_attribute) > 0) {
		while ($get_result = tep_db_fetch_array($get_attribute)) {
			$attrib = $HTTP_POST_VARS["id"];
			$att_ids .= $attrib[$get_result["services_options_id"]] . ',';
			$attrib_array[] = array (
				'attrib_id' => $get_result["services_options_id"],
				'attrib_name' => $get_result["services_options_name"],
				'option_id' => $attrib[$get_result["services_options_id"]]
			);
		}
	}
	$option_ids = str_replace(",", "','", substr($att_ids, 0, (strlen($att_ids) - 1)));
	$option_price_query = tep_db_query("select sum(options_values_price) as option_price from " . TABLE_SERVICES_ATTRIBUTES . " sa, " . TABLE_SERVICES_OPTIONS_VALUES . " sov where sa.service_id = '" . $service_id . "' and sa.options_values_id in('" . $option_ids . "') and sa.options_values_id = sov.services_options_values_id and sov.language_id = '" . $languages_id . "'" . " order by sa.services_options_sort_order, sa.options_values_price");
	if (tep_db_num_rows($option_price_query) > 0) {
		$option = tep_db_fetch_array($option_price_query);
		$option_price += $option['option_price'];
	}
	$current_price = "";
	$current_tax = "";
	$loading_price_dates = get_loading_array($service_id);
	$loading_dates = array (
		'loading_price_dates' => $loading_price_dates,
		'start_date' => $start_date,
		'end_date' => $end_date,
		'start_time' => $start_time,
		'end_time' => $end_time
	);	
	$current_price = tep_calc_service_cost($service_details, $start_date . ' ' . $start_time, $end_date . ' ' . $end_time, $option_price, $loading_dates,1,$service_price);
	$current_tax = tep_calculate_tax($current_price, tep_get_tax_rate($service_price_tax));
	$current_total = $current_price;	
	$current_price = tep_add_tax($current_price, tep_get_tax_rate($service_price_tax));
	$currect_total = TEXT_TOTAL . ' : ' . $currencies->format($current_price);
	if ($old_order_price < $current_price) {
		$balance = round($current_price - $old_order_price);
		$current_order_total = TEXT_BALANCE . ' : ' . $currencies->format($balance);
	} else if ($current_price != 0 && $old_order_price > $current_price) {
		$refund = round($old_order_price - $current_price);
		$current_order_total = TEXT_REFUND . ' : ' . $currencies->format($refund);
	}
}

	$booking_ids = (isset ($HTTP_POST_VARS['booking_id']) ? $HTTP_POST_VARS['booking_id'] : '');
//move service into order
$flg = 0;
if ($select_action == 'move') {
	$service_action = TEXT_SERVICE_SUCCESSFULLY_MOVED;
	$order_timestamp = (isset ($HTTP_SESSION_VARS['order_timestamp']) ? $HTTP_SESSION_VARS['order_timestamp'] : 0);
	$oID = $orders_id;
	$order_status_query = tep_db_query("SELECT orders_status from " . TABLE_ORDERS . " where orders_id='" . $oID . "'");
	$order_status_result = tep_db_fetch_array($order_status_query);
	$status = $order_status_result["orders_status"];
	$add_comments = "<b>Order Updated</b><br>" . $update_string;
	$user_name = tep_admin_name($login_id);
	if ($resource_id == '')
		$resource_id = '0';
	// service details 
	$service_array = array (
		'orders_products_id' => $orders_products_id,
		'orders_id' => $orders_id,
		'start_date' => $start_date,
		'start_time' => $start_time,
		'end_date' => $end_date,
		'end_time' => $end_time,
		'products_id' => $service_id,
		'resource_id' => $resource_id,
		'resource_name' => (($resource_id
	) ? tep_get_resource_name($resource_id) : ''));
	if($HTTP_POST_VARS['id'] && is_array($HTTP_POST_VARS['id'])){
		$option_ids="";
		$option_value_ids="";
		while(list($key,$val)=each($HTTP_POST_VARS['id'])){
			$option_ids.=$key.',';
			$option_value_ids.=$val.',';
		}
	}
	$option_ids=substr($option_ids,0,-1);
	$option_value_ids=substr($option_value_ids,0,-1);
	$attribute_array=tep_db_query("select sa.options_values_price,sa.price_prefix,so.services_options_id,so.services_options_name,sov.services_options_values_id,sov.services_options_values_name from ".TABLE_SERVICES_ATTRIBUTES." sa,".TABLE_SERVICES_OPTIONS." so,".TABLE_SERVICES_OPTIONS_VALUES." sov where sa.service_id='".(int)$service_id."' and sa.options_id in('".$option_ids."') and sa.options_values_id in('".$option_value_ids."') and sa.options_id=so.services_options_id and so.language_id='".(int)$languages_id."' and sa.options_values_id=sov.services_options_values_id");
	if(tep_db_num_rows($attribute_array)>0){
		while($attribute=tep_db_fetch_array($attribute_array)){
			$products_array_list=array(
					'orders_id'=>$orders_id,
					'orders_products_id'=>$orders_products_id,
					'products_options'=>$attribute['services_options_name'],
					'products_options_values'=>$attribute['services_options_values_name'],
					'options_values_price'=>$attribute['options_values_price'],
					'price_prefix'=>$attribute['price_prefix'],
					'products_options_id'=>$attribute['services_options_id'],
					'products_options_values_id'=>$attribute['services_options_values_id'],
					'products_type'=>'V'
			);
			tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES,$products_array_list);											
		}
	}
	$products_array = array (
		'orders_id' => $orders_id,
		'products_id' => $service_id,
		'products_name' => tep_get_service_name($service_id), 'products_price' => $service_price, 'final_price' => $current_total, 'products_tax' => tep_get_tax_rate($service_price_tax), 'products_quantity' => $quantity, 'products_type' => 'V','orders_products_status'=>$status);
	tep_db_query("DELETE from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id='" . (int) $orders_id . "' and orders_products_id='" . (int) $orders_products_id . "'");
	tep_db_perform(TABLE_ORDERS_SERVICES, $service_array, $action = 'update', "orders_products_id='" . (int) $orders_products_id . "' and orders_id='" . (int) $orders_id . "'");
	tep_db_perform(TABLE_ORDERS_PRODUCTS, $products_array, $action = 'update', "orders_products_id='" . (int) $orders_products_id . "' and orders_id='" . (int) $orders_id . "'");
	//
	for ($at = 0; $at < sizeof($attrib_array); $at++) {
		$option_id = $attrib_array[$at]['option_id'];
		$attribute_array = array (
			'orders_id' => $orders_id,
			'orders_products_id' => $orders_products_id,
			'products_options' => $attrib_array[$at]['attrib_name'],
			'products_options_values' => tep_services_values_name($attrib_array[$at]['option_id']
		), 'options_values_price' => tep_services_option('options_values_price', $attrib_array[$at]['option_id'], $service_id), 'price_prefix' => tep_services_option('price_prefix', $attrib_array[$at]['option_id'], $service_id), 'products_type' => 'V');
		tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $attribute_array);
	}
	//get order total using order_id 
	$order_price = 0;
	$order_tax = 0;
	$order_total_query = tep_db_query("select value,class from " . TABLE_ORDERS_TOTAL . " where orders_id='" . (int) $orders_id . "' and class in('ot_total','ot_tax')");
	if (tep_db_num_rows($order_total_query) > 0) {
		while ($order_total = tep_db_fetch_array($order_total_query)) {
			if ($order_total["class"] == 'ot_total')
				$order_price += $order_total["value"];
			if ($order_total["class"] == 'ot_tax')
				$order_tax += $order_total["value"];
		}
	}
	if ($balance) {
		$current_price = $order_price + $balance;
		$order_tax -= $old_order_tax;
		$current_tax += $order_tax;
		//get order total using order_id
		tep_db_query("UPDATE " . TABLE_ORDERS_TOTAL . " set title='Sub-Total:',text='" . $currencies->format($current_price, true, $booking['currency'], $booking['currency_value']) . "',value='" . number_format($current_price, '2', '.', '') . "' where orders_id='" . $orders_id . "' and class='ot_subtotal'");
		tep_db_query("UPDATE " . TABLE_ORDERS_TOTAL . " set title='Tax:',text='" . $currencies->format($current_tax, true, $booking['currency'], $booking['currency_value']) . "',value='" . number_format($current_tax, '2', '.', '') . "' where orders_id='" . $orders_id . "' and class='ot_tax'");
		tep_db_query("UPDATE " . TABLE_ORDERS_TOTAL . " set title='Total:',text='<b>" . $currencies->format($current_price, true, $booking['currency'], $booking['currency_value']) . "</b>',value='" . number_format($current_price, '2', '.', '') . "' where orders_id='" . $orders_id . "' and class='ot_total'");
	} else
		if ($current_price == $old_order_price) {
			tep_db_query("UPDATE " . TABLE_ORDERS_TOTAL . " set title='Sub-Total:',text='" . $currencies->format($current_price, true, $booking['currency'], $booking['currency_value']) . "',value='" . number_format($current_price, '2', '.', '') . "' where orders_id='" . $orders_id . "' and class='ot_subtotal'");
			tep_db_query("UPDATE " . TABLE_ORDERS_TOTAL . " set title='Tax:',text='" . $currencies->format($current_tax, true, $booking['currency'], $booking['currency_value']) . "',value='" . number_format($current_tax, '2', '.', '') . "' where orders_id='" . $orders_id . "' and class='ot_tax'");
			tep_db_query("UPDATE " . TABLE_ORDERS_TOTAL . " set title='Total:',text='<b>" . $currencies->format($current_price, true, $booking['currency'], $booking['currency_value']) . "</b>',value='" . number_format($current_price, '2', '.', '') . "' where orders_id='" . $orders_id . "' and class='ot_total'");
		}
	$wallet_account = false;
	$check_wallet = tep_db_query("select amount from " . TABLE_WALLET_HISTORY . " where customers_id='" . (int) $customer_id . "'");
	/*$status = 1;
	$payment_type = $GLOBALS[$payment]->title;
	if ($payment_type == 'Credit Card' || $payment_type == 'Cash' || $payment_type == 'Wallet Payment')
		$status = 2; */
	if (tep_db_fetch_array($check_wallet) > 0)
		$wallet_account = true;
	$wallet_amount = tep_db_query("select sum(amount) as amount from " . TABLE_WALLET_UPLOADS . " where customers_id=" . $customer_id . " group by customers_id");
	if (tep_db_fetch_array($wallet_amount) > 0) {
		$wallet_amount = tep_db_fetch_array($wallet_amount);
		$wallet_price = $wallet_amount['amount'];
	}
	if ($wallet_account && $payment_type == 'Wallet Payment' || $refund) {
		if ($wallet_price >= $current_price || $refund) {
			$amount = $wallet_price - $current_price;
			if ($refund) {
				$amount = $refund;
				$sql_wallet_array = array (
					'customers_id' => $customer_id,
					'payment_date' => $server_date,
					'payment_method' => $payment_type,
					'payment_status' => $status,
					'payment_info' => $GLOBALS['payment_info'],
					'comments' => TEXT_MOVE_SERVICE_INTO_WALLET,
					'amount' => $amount
				);
				tep_db_perform(TABLE_WALLET_UPLOADS, $sql_wallet_array);
			} else {
				$wallet_query = tep_db_query("SELECT customers_id from " . TABLE_WALLET_HISTORY . " where orders_id=" . $oID);
				if (tep_db_num_rows($wallet_query) > 0) {
					tep_db_query("UPDATE " . TABLE_WALLET_HISTORY . " set amount=" . $amount . " where orders_id=" . (int) $orders_id . " and customers_id=" . (int) $customer_id);
				} else {
					$sql_wallet_array = array (
						'drawn_date' => $server_date,
						'customers_id' => $customer_id,
						'orders_id' => $oID,
						'amount' => $refund
					);
					tep_db_perform(TABLE_WALLET_HISTORY, $sql_wallet_array);
				}
			}

		} else {
			$error = ERR_WALLET_AMOUNT_IS_LOW;
		}
	}
	if ($error == '') {
		if ($customer_notify == '')
			$customer_notify = '0';
		// insert orders status
		tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " 
					(orders_id, orders_status_id, date_added, customer_notified, comments,user_added) 
					values ('" . $oID . "', '" . $status . "','" . $server_date . "', '" . $customer_notify . "', '" . tep_db_input($add_comments) . "','" . tep_db_input($user_name) . "')");

		//update the payment type 
		$UpdateOrders = "update " . TABLE_ORDERS . " set ";
		$update_info_cc_type = (isset ($GLOBALS['cc_type']) ? tep_db_input(stripslashes($GLOBALS['cc_type'])) : '');
		$update_info_cc_owner = (isset ($GLOBALS['cc_owner']) ? tep_db_input(stripslashes($GLOBALS['cc_owner'])) : '');
		$update_info_cc_number = (isset ($GLOBALS['cc_number']) ? tep_db_input(stripslashes($GLOBALS['cc_number'])) : '');
		$update_info_cc_cvv = '';
		$update_info_cc_expires = (isset ($GLOBALS['cc_expires']) ? tep_db_input(stripslashes($GLOBALS['cc_expires'])) : '');
		$update_info_payment = (isset ($GLOBALS['payment_info']) ? tep_db_input(stripslashes($GLOBALS['payment_info'])) : '');
		$UpdateOrders .= "payment_method = '" . tep_db_input(stripslashes($GLOBALS[$payment]->title)) . "',
										 cc_type = '" . tep_db_input(stripslashes($update_info_cc_type)) . "',
										 cc_owner = '" . tep_db_input(stripslashes($update_info_cc_owner)) . "',
										 cc_cvv_number='" . tep_db_input(stripslashes($update_info_cc_cvv)) . "',";
		$UpdateOrders .= "cc_number = '" . tep_db_input(stripslashes($update_info_cc_number)) . "',";
		$UpdateOrders .= "payment_info = '" . tep_db_input(stripslashes($GLOBALS[$payment]->email_footer)) . "',";
		$UpdateOrders .= "cc_expires = '" . tep_db_input(stripslashes($update_info_cc_expires)) . "'";
		// check payment method
		/*$status=1;
		$payment_type=$GLOBALS[$payment]->title; 
		if($payment_type=='Credit Card' || $payment_type=='Cash' || $payment_type=='Wallet Payment')
			$status=2;*/
		if ((int) $status > 0) {
			$UpdateOrders .= ",orders_status = '" . tep_db_prepare_input($status) . "'";
			$comments = "Automatic Updation";
		}
		if ($UpdateOrders != '') {
			$UpdateOrders .= ",last_modified ='" . $server_date . "'";
			$UpdateOrders .= "  where orders_id = '" . tep_db_prepare_input($oID) . "';";			
			tep_db_query($UpdateOrders);
		}
		tep_send_service_order_email($oID);
		$merge_details = array ();
		$send_details = array ();
		$merge_details[ORDR_NO] = $oID;
		$merge_details[ORDR_OL] = tep_catalog_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $oID, 'SSL', false);
		$merge_details[ORDR_OP] = strftime(DATE_FORMAT_LONG);
		// customer query start
		$customer_query = tep_db_query("SELECT customers_firstname,customers_lastname from " . TABLE_CUSTOMERS . " where customers_id='" . (int) $customer_id . "'");
		$customer_result = tep_db_fetch_array($customer_query);
		// customer query end
		// add ausbank info start
		$comments = (($GLOBALS[$payment]->code == 'ausbank') ? MODULE_AUSBANK_INFO : '');
		if ($comments != '') {
			$comments .= TEXT_REFERENCEID . ' : ' . substr(strtolower($customer_result['customers_firstname']), 0, 3) . substr(strtolower($customer_result['customers_lastname']), 0, 3) . $order_timestamp . '</b>';
		}
		$merge_details[ORDR_OM] = $comments;
		// ausbank info end
		$merge_details[ORDR_PO] = $products_ordered;
		$order_totals_str = "";
		//$order_totals_str .= $order->totals[$i]['title'] . ' ' . $order->totals[$i]['text']  .  "<br>";
		$merge_details[ORDR_OT] = $order_totals_str;
		$merge_details[CUST_CF] = $customer_result['customers_firstname'];
		$merge_details[CUST_CL] = $customer_result['customers_lastname'];
		$merge_details[CUST_CM] = $booking['company'];
		$merge_details[CUST_CT] = $booking['street_address'];
		$merge_details[CUST_CS] = $booking['suburb'];
		$merge_details[CUST_CC] = $booking['city'];
		$merge_details[CUST_CP] = $booking['postcode'];
		$merge_details[CUST_CE] = $booking['state'];
		$merge_details[CUST_CU] = $booking['country'];
		$merge_details[CUST_CO] = $booking['telephone'];
		$merge_details[CUST_CA] = $booking['email_address'];
		//Billing details
		$merge_details[BILL_NA] = $booking['customers_firstname'] . ' ' . $booking['customers_lastname'];
		$merge_details[BILL_CM] = $booking['company'];
		$merge_details[BILL_CT] = $booking['street_address'];
		$merge_details[BILL_CS] = $booking['suburb'];
		$merge_details[BILL_CC] = $booking['city'];
		$merge_details[BILL_CP] = $booking['postcode'];
		$merge_details[BILL_CE] = $booking['state'];
		$merge_details[BILL_CU] = $booking['country'];
		//delivery details 
		$merge_details[DELI_NA] = $booking['customers_firstname'] . ' ' . $booking['customers_lastname'];
		$merge_details[DELI_CM] = $booking['company'];
		$merge_details[DELI_CT] = $booking['street_address'];
		$merge_details[DELI_CS] = $booking['suburb'];
		$merge_details[DELI_CC] = $booking['city'];
		$merge_details[DELI_CP] = $booking['postcode'];
		$merge_details[DELI_CE] = $booking['state'];
		$merge_details[DELI_CU] = $booking['country'];

		if (is_object($$payment)) {
			$payment_class = $$payment;
			$merge_details[ORDR_PM] = $payment_class->title;
			//for direct deposit module 
			if ($payment_class->code == 'ausbank') $merge_details[ORDR_DD] = sprintf(TEXT_DIRECT_DEPOSIT, substr(strtolower($customer_result['customers_firstname']), 0, 3), substr(strtolower($customer_result['customers_lastname']), 0, 3), $order_timestamp);
			else $merge_details[ORDR_DD] = '';
			if ($payment_class->email_footer) $merge_details[ORDR_PF] .= $payment_class->email_footer;			
		}
		$send_details[0]['to_name'] = $booking['customers_firstname'] . ' ' . $booking['customers_lastname'];
		$send_details[0]['to_email'] = $booking['email_address'];
		$send_details[0]['from_name'] = STORE_OWNER;
		$send_details[0]['from_email'] = STORE_OWNER_EMAIL_ADDRESS;
		if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
			$send_details[1]['to_name'] = "";
			$send_details[1]['to_email'] = SEND_EXTRA_ORDER_EMAILS_TO;
			$send_details[1]['from_name'] = STORE_OWNER;
			$send_details[1]['from_email'] = STORE_OWNER_EMAIL_ADDRESS;
		}
		tep_send_default_email("PRD", $merge_details, $send_details);
		$customer_notify = 1;
		$user_name = tep_admin_name($login_id);
		tep_session_unregister('payment');
	}
	//update payment type 
}
?>    
   <table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr> 
	<!-- body_text //-->
	<td width=100% align=left valign="top">
	<!-- header_eof //-->
	<?PHP
		echo tep_draw_form('move_booking_confirm', FILENAME_MOVE_BOOKINGS_CONFIRM);
		$resources_query = tep_db_query("SELECT red.resource_id,red.resource_name from " . TABLE_RESOURCES . " re, " . TABLE_RESOURCES_DESCRIPTION . " red where red.language_id='" . $languages_id . "'  and re.resource_id=red.resource_id order by red.resource_name");
		while ($resource_result = tep_db_fetch_array($resources_query))
			$resources_array[] = array ('id' => $resource_result['resource_id'],
										'text' => $resource_result['resource_name']);
	?>
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
			   <tr class="openContent_top">
			   		<td class="pageHeading"><?PHP echo TEXT_MOVE_SERVICE_CONFIRMATION; ?></td>
			   </tr>
			   <?php if ($service_action != 'Service successfully moved') { ?>
			   	<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '3', '10'); ?></td>
				</tr>
			   <tr>
				  <Td>
				  	<table border="0" width='100%'cellspacing="1" cellpadding="1">
						<tr class='dataTableHeadingRow'>
							<td class='dataTableHeadingContent'><?php echo TEXT_RESULT_FIRSTNAME; ?></td>
							<td class='dataTableHeadingContent'><?php echo TEXT_RESULT_LASTNAME; ?></td>
							<td class='dataTableHeadingContent'><?php echo TEXT_RESULT_SERVICE; ?></td>
							<td class='dataTableHeadingContent'><?php echo TEXT_RESULT_RESOURCE; ?></td>
							<td class='dataTableHeadingContent'><?php echo TEXT_RESULT_STARTDATE ; ?></td>
							<td class='dataTableHeadingContent'><?php echo TEXT_RESULT_ENDDATE ; ?></td>
							<td class='dataTableHeadingContent'><?php echo TEXT_PAYMENT_TYPE ;?></td>
							<td class='dataTableHeadingContent'><?php echo TEXT_AMOUNT; ?></td>
						</tr>
						<?php
							$booking_query = tep_db_query($booking_detail);
							if (tep_db_num_rows($booking_query) > 0) {
								$booking = tep_db_fetch_array($booking_query);
							if(defined('TIME_FORMAT')) $time_format=TIME_FORMAT;
							$start_times=date('h:i A',strtotime($booking['start_time']));							
							$end_time_string=strtotime($booking['end_date'].' '.$booking['end_time']);
							$end_date=date('Y-m-d',$end_time_string);
							$end_times=date('h:i A',$end_time_string);							
							if($time_format==24){
								$start_times=date('H:i',strtotime($booking['start_time']));
								$end_times=date('H:i',$end_time_string);
							}	
						?>
						<tr class="attributes-odd">
							<td class="smallText"><?php echo $booking['customers_firstname']; ?></td>
							<td class="smallText"><?php echo $booking['customers_lastname']; ?></td>
							<td class="smallText"><?php echo $booking['service_name']; ?></td>
							<td class="smallText"><?php echo (($booking['resource_id']>0)?$booking['resource_name']:$booking['products_quantity']);?></td>
							<td class="smallText"><?php echo format_date($booking['start_date']) . ' '.$start_times; ?></td>
							<td class="smallText"><?php echo format_date($end_date) . ' '.$end_times; ?></td>
							<td class="smalltext"><?php echo $booking["payment_method"];?></td>
							<td class="smallText" align="right"><?php echo $currencies->format($old_order_price); ?></td>	
						</tr>
					 <?php } ?>
					</table>
				  </Td>
				</tr>				
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
			<?php }?>	
			</table> 
			<table border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td colspan="2" class="main"><?php echo (($service_action==TEXT_SERVICE_SUCCESSFULLY_MOVED && $error=='')?'<font color="blue">'.TEXT_SERVICE_SUCCESSFULLY_MOVED.'</font><br><br><a href="javascript:doactions(\'back_search_form\');">'.tep_image_button('button_back.gif',IMAGE_BACK,'align=absmiddle').'</a>':'');?></td>
				</tr>
			</table>
         <?PHP

	if ($error != '') {
?>
         	<table border="0" cellspacing="0" cellpadding="0" width="100%">
         		<tr><td colspan="2" align="left" class="errortext"><?php echo $error;?></td></tr>
         		<tr>
         			<td colspan="2" align="left"><?PHP echo '<a href="javascript:doactions(\''.$arg.'\',\'step2\');">' . tep_image_button('button_back.gif',IMAGE_BACK,'align=absmiddle') . '</a>&nbsp;' . "\n";?></td>
					</tr>			
         	</table> 
       	<?php

	} else
		if ($service_action != 'Service successfully moved') {
			$service_array = tep_get_services_array();
			$vals = (int) $service_details["max_bookings"] . '{}' . (int) $service_details["service_total_time"] . '{}' . $service_details["booking_type"] . '{}' . (int) $service_details["booking_granular"] . '{}' . (int) $service_details["quantity"] . '{}' . $service_details["span_days"] . '{}' . $service_details["include_resource"] . '{}' . $service_details["multiple_purchase"].'{}'.$HTTP_POST_VARS['start_time'];
	?>             
			<table border="0" width="100%" cellspacing="3" cellpadding="2" class="searchArea">
			<tr>
				<td class="smalltext"><?php echo TEXT_MOVE_TO_SERVICE  ?></td>
				<td class="smalltext"><?php	echo tep_draw_pull_down_menu('nservice',$service_array,'','onchange="javascript:do_submit(\'sel_service\');" style="width:100"');?></td>
			</tr>
			<input type="hidden" name="times_val" id="times_val" value="<?php echo $vals;?>"/>
			<?php if(($service_details["booking_type"]=='H' || $service_details["booking_type"]=='M') && $ser_date){?>
			<tr>
				<td class="smalltext" align="left"><?php echo TEXT_START_DATE;?></td>
				<td class="smalltext" align="left"><?php echo tep_draw_pull_down_menu("start_date",$ser_date,'','style="width:100" onchange="javascript:add_start_times();"') . '  '. tep_draw_pull_down_menu('start_time',array(),'','onChange="javascript:add_end_times();"');?></td>
			</tr> 
			<?php }else if($ser_date) { ?>
			<tr>
				<td class="smalltext" align="left"><?php echo TEXT_START_DATE;?></td>			 
				<td class="smalltext" align="left"><?php echo tep_draw_pull_down_menu("start_times",$ser_date,'','style="width:170" onchange="javascript:add_end_times();"');?></td>   
  	 		</tr>
			<?php

		}
	if ($service_info["include_resource"] == 'N' && $service_info["include_resource_price"] == 'N') {
?>
			<tr>
				<td  class="smalltext"><?php echo TEXT_COSTS;?></td>
				<td  class="smalltext"><?php echo $currencies->format(tep_add_tax($service_info["service_costs"],tep_get_tax_rate($service_info["service_tax_class_id"])));?></td>
			</tr>
			<?php } ?>
			<?php if($ser_date){ ;?>
			<tr>
				<td class="smalltext"><?php echo TEXT_END_DATE; ?><br></td>
				<td class="smalltext"><?php echo tep_draw_pull_down_menu("end_times",array(),'','style="width:170"');?>
			</tr>
			<?php } ?>
			<tr> 
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<?php if($service_action=='check_service' && $service_action!='Service successfully moved' && count($resource_array)>0){	?>
			<tr>
				<td class="smalltext" align="left"><?php echo (($service_found && $service_details["include_resource"]=='Y')?TEXT_RESOURCES:(($service_found && $service_details["include_resource"]=='N' && $service_details["multiple_purchase"]=='Y')?TEXT_HOW_MANY:(($service_found)?TEXT_QUANTITY:'')));?></td>
				<td class="smalltext" align="left"><?php echo (($service_found && $service_details["include_resource"]=='Y')?tep_draw_pull_down_menu('resource',$resource_array,$HTTP_POST_VARS["resource"],'onchange="javascript:price();"'):(($service_found && $service_details["include_resource"]=='N' && $service_details["multiple_purchase"]=='Y')?tep_draw_input_field('txt_quantity',1,'size="10" maxlength="6"'):(($service_found)?'1':'<div id="error"><font color="red">'.(($service_action=='check_service')?ERR_TIME_ALREADY_RESERVED:'').'</font></div>'))); ?></td>
			</tr>
			<?php

	}
//main while		
?>
			<tr>
				<td colspan="2">
					<table border="0" cellspacing="2" cellpadding="2" width="50%">
				<?php
				$result = tep_db_query("SELECT * FROM " . TABLE_SERVICES_ATTRIBUTES . " sa LEFT JOIN " . TABLE_SERVICES_OPTIONS . " so ON so.services_options_id=sa.options_id LEFT JOIN " . TABLE_SERVICES_OPTIONS_VALUES . " sov ON sov.services_options_values_id=sa.options_values_id WHERE sa.service_id='" . (int) $service_id . "' and so.language_id='" . $languages_id . "' and sov.language_id='" . $languages_id . "' group by so.services_options_id");
				$rows = tep_db_num_rows($result);
				if ($rows > 0 && $service_action != 'Service successfully moved') {
				?> 
					<tr> 
						<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
					</tr>
				<?php
				$display_array = array ();
				while ($services_options_name_values = tep_db_fetch_array($result)) {
					$selected = 0;
					$services_options_array = array ();
				?> 
				<tr valign="middle">
					<td class="smalltext" nowrap="nowrap"><?php echo $services_options_name_values['services_options_name'];?>: </td>
					<?php
			    $services_options = tep_db_query("select sa.services_options_sort_order, sov.services_options_values_id, sov.services_options_values_name, sa.options_values_price, sa.price_prefix,sa.options_values_id from " . TABLE_SERVICES_ATTRIBUTES . " sa, " . TABLE_SERVICES_OPTIONS_VALUES . " sov where sa.service_id = '" . $service_id . "' and sa.options_id = '" . $services_options_name_values['services_options_id'] . "' and sa.options_values_id = sov.services_options_values_id and sov.language_id = '" . $languages_id . "'" . " order by sa.services_options_sort_order, sa.options_values_price");
			    while ($services_options_values = tep_db_fetch_array($services_options)) {
					$display_array[] = array (
					'attrib_id' => $services_options_name_values['services_options_id'],
					'attrib_name' => $services_options_name_values['services_options_name'],
					'option_id' => $services_options_values['services_options_values_id'],
					'option_name' => $services_options_values['services_options_values_name'],
					'option_price' => tep_add_tax($services_options_values['options_values_price'],
					tep_get_tax_rate($service_info["service_tax_class_id"]
					)));
				$services_options_array[] = array (
					'id' => $services_options_values['services_options_values_id'],
					'text' => $services_options_values['services_options_values_name']
				);
			if ($services_options_values['options_values_price'] != '0') 
				$services_options_array[sizeof($services_options_array) - 1]['text'] .= ' (' . $services_options_values['price_prefix'] . $currencies->display_price($services_options_values['options_values_price'], tep_get_tax_rate($service_info["service_tax_class_id"]), '1', true) . ') ';
		} // while option values 
		$id .= $services_options_name_values['services_options_id'] . '-';
		$id1 = 'id[' . $services_options_name_values['services_options_id'] . ']';
	?>
				<td align="center">
						<?php echo tep_draw_pull_down_menu($id1, $services_options_array,$attrib[$services_options_name_values['services_options_id']],'onchange="javascript:price();"') ;?>
				</td>		
				<?php
	}
   }
 }	
?>
				<tr>
					</tr>
				</table>
			  </td>
			</tr> 
			<tr> 
			<?php if($service_action!='Service successfully moved' && $error==""){?>
			<tr>
				<td class="smalltext" align="left"><?php echo '<a href="javascript:doactions(\''.$arg.'\',\'step2\');">'.tep_image_button('button_back.gif',IMAGE_BACK,'align=absmiddle').'</a>';?></td>
				<td class="smalltext" align="right"><?php echo tep_image_button('button_select.gif',TEXT_SELECT,' style="cursor:pointer;cursor:hand" onclick="javascript:do_submit(\'select\');"').'</a>';?></td>
			</tr>
			<?php

}
if ($service_id && $select_action && $service_found && $service_action != 'Service successfully moved') {
?>
			<tr>
				<td colspan="2" class="smalltext" align="right"><?php echo TEXT_OLDORDER_TOTAL .' : ' .$currencies->format($old_order_price);?></td>
			</tr>
			<tr>
				<td colspan="2" class="smalltext" align="right"><?php echo $currect_total;?></td>
			</tr>
			<tr>
				<td colspan="2" align="right" class="smalltext"><?php echo $current_order_total;?></td>
			</tr>
			<tr> 
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<?php

	$radio_buttons = 0;
	$cnt = 1;
	$wallet_account = false;
	$check_wallet = tep_db_query("select amount from " . TABLE_WALLET_HISTORY . " where customers_id='" . (int) $customer_id . "'");
	if (tep_db_num_rows($check_wallet) > 0)
		$wallet_account = true;
	for ($i = 0, $n = sizeof($selection); $i < $n; $i++) {
		if (($order_status == 1 || ($order_status > 1 && ($selection[$i]['id'] == 'cash' || $selection[$i]['id'] == 'securepay' || ($selection[$i]['id'] == 'wallet' && $wallet_account))))) {
?>
              <tr>
                   <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
			<?php

			if (($selection[$i]['id'] == $payment) || ($n == 1))
				echo '<tr id="defaultSelected" style="cursor:hand;cursor:pointer;"  onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect2(this, ' . $radio_buttons . ',\'', $selection[$i]['id'] . '\')">' . "\n";
			else
				echo '<tr  style="cursor:hand;cursor:pointer;" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect2(this, ' . $radio_buttons . ',\'', $selection[$i]['id'] . '\')">' . "\n";
?>
        	<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
        	<td class="main" colspan="3"><b><?php echo $selection[$i]['module']; ?></b></td>
        	<td class="main" align="right">
			<?php

			$single_payment = false;
			if (sizeof($selection) > 1) {
				echo tep_draw_radio_field('payment', $selection[$i]['id']);
			} else {
				$single_payment = true;
				echo tep_draw_hidden_field('payment', $selection[$i]['id']);
			}
			echo "<input type=hidden id=check_payment name=check_payment value='" . $selection[$i]['module'] . "'>";
?>
                    </td>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                  </tr>
				<?php

			if (isset ($selection[$i]['error'])) {
?>
                  <tr>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                    <td class="main" colspan="4"><?php echo $selection[$i]['error']; ?></td>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                  </tr>
<?php

			}
			elseif (isset ($selection[$i]['fields']) && is_array($selection[$i]['fields'])) {
?>
             
                  <tr <?php if(!$single_payment){ echo " id='" . $selection[$i]['id'] . "'"; echo (($payment!=$selection[$i]['id'])?'style="display:none"':'');}?>>
                    <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                    <td colspan="4"><table border="0" cellspacing="0" cellpadding="2">
<?php

				for ($j = 0, $n2 = sizeof($selection[$i]['fields']); $j < $n2; $j++) {
?>
                      <tr>
                        <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                        <td class="main"><?php echo $selection[$i]['fields'][$j]['title']; ?></td>
                        <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                        <td class="main"><?php echo $selection[$i]['fields'][$j]['field']; ?></td>
                        <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                      </tr>
<?php }	  ?> 
                  </table></td></tr>					          
                    <tr><td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                  </tr>
                    
                    <tr><td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                  </tr>
<?php } ?>
                 </table></td>
                <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
<?php

					$radio_buttons++;
					$cnt++;
				}
			}
?>
   			<script language="javascript">initpage('<?php echo $payment; ?>');</script>	
			<tr>
			 <td></td>
			  <td align="right"><?PHP echo tep_image_button('button_move.gif',TEXT_MOVE,'align=absmiddle style="cursor:pointer;cursor:hand" onclick="javscript:do_submit(\'move\')"') ;?></td>
			</tr>
			<?php }  ?>
			</td>
     		<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
        	</tr>
    		<input type="hidden" id="ser_action" name="ser_action" value="check_service">
    		<input type="hidden" name="booking_id[]" id="booking_id[]" value="<?php echo $booking_ids[0];?>">
    		<input type="hidden" name="service_id" id="service_id">
    		<input type="hidden" name="resource_id" id="resource_id">
    		<input type="hidden" name="option_ids" id="option_ids"> 
    		<input type="hidden" name="qty" id="qty">
    		<input type="hidden" name="select_action" id="select_action">
    		<input type="hidden" name="nb_dates" id="nb_dates" value="<?php echo $details;?>">
    		<?PHP echo '</form>';?>
		</table>
	<!-- body_text_eof //-->
</body>
</html>
