<?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 );

	require('includes/application_top.php');
	tep_get_last_access_file();
	require('includes/functions/events_tree.php');
	require(DIR_WS_CLASSES . 'currencies.php');
	 require(DIR_WS_CLASSES . 'payment.php');
	require(DIR_WS_CLASSES . 'order.php');
	//require('events_pending_waitlist_payments_confirm_ajax.php');
	
	$currencies = new currencies();
	$command = (isset($HTTP_GET_VARS['command']) ? $HTTP_GET_VARS['command'] : ''); 
	$events_id=(isset($HTTP_GET_VARS['events_id'])?(int)$HTTP_GET_VARS['events_id']:0);
	$orders_id=(isset($HTTP_GET_VARS['orders_id'])?(int)$HTTP_GET_VARS['orders_id']:0);
	
	if($command!=''){
		if($command!=='confirm')
		 echo $command . '{}' . $events_id . '||';
		switch($command){
			case 'select_event':
				get_waitlist_payment_details($events_id);
			break;
			case 'get_details':
				echo $orders_id . '||';
				echo do_get_details($events_id,$orders_id);
			break;
			case 'edit':
				echo $orders_id . '||';
				do_edit_details($events_id,$orders_id);
			break;	
			case 'save':
				echo $orders_id . '||';
				do_get_confirm_details($events_id,$orders_id);
			break;
			case 'confirm':
				$orders_id=(isset($HTTP_POST_VARS['orders_id'])?(int)$HTTP_POST_VARS['orders_id']:0);
				$orders_items=(isset($HTTP_POST_VARS['orders'])?$HTTP_POST_VARS['orders']:'');
				if ($orders_id<=0 || sizeof($orders_items)<=0)
					tep_redirect(tep_href_link(FILENAME_PENDING_WAITLIST_PAYMENTS));
				
				$currencies=new currencies();
				$server_date = getServerDate(true);
				$orders_query=tep_db_query("SELECT * from " . TABLE_ORDERS . " where orders_id ='" . (int)$orders_id . "'");
				$orders_result=tep_db_fetch_array($orders_query);
				unset($orders_result["orders_id"]);
				
				// create the order
				tep_db_perform(TABLE_ORDERS,$orders_result);
				$new_order_id=tep_db_insert_id();
				$edit_order=false;
				for ($icnt=0;$icnt<sizeof($orders_items);$icnt++){
					$products_query=tep_db_query("SELECT orders_products_id,orders_id,products_id,products_name,products_model,products_price,final_price,products_tax,products_quantity,products_type,events_type,waitlist_type,events_fees,waitlist_orders_id,products_sku from " . TABLE_ORDERS_PRODUCTS . " where orders_products_id='" . (int)$orders_items[$icnt]['id'] . "'");
					if (tep_db_num_rows($products_query)>0){
						$products_result=tep_db_fetch_array($products_query);
						unset($products_result['orders_products_id']);
						$products_result['products_price']=(float)$orders_items[$icnt]['amount'];
						$products_result['final_price']=$products_result['products_price'];
						$products_result['events_type']='R';
						$products_result['waitlist_type']='';
						$products_result['waitlist_orders_id']=$orders_id;
						$products_result['orders_id']=$new_order_id;
						if ($orders_items[$icnt]['type']=='P'){ // if paid amount
							tep_db_perform(TABLE_ORDERS_PRODUCTS,$products_result);
							tep_db_query("UPDATE " . TABLE_ORDERS_PRODUCTS . " set events_type='C',waitlist_type='' where orders_products_id='" . (int)$orders_items[$icnt]['id'] . "'");
						} else { // if unpaid
							$edit_order=true;
							$products_result['date_added']=$server_date;
							tep_db_perform(TABLE_ORDERS_EDIT_PRODUCTS,$products_result);
						}
					}
				}
				update_totals($new_order_id);
				if ($edit_order){	
					if (!tep_session_is_registered('edit_order')) tep_session_register("edit_order");
					$edit_order=$new_order_id;
					tep_redirect(tep_href_link(FILENAME_EDIT_ORDERS, 'oID=' . $new_order_id . '&step=2&selected_box=customers', 'SSL'));
				}
				tep_redirect(tep_href_link(FILENAME_ORDERS, 'oID=' . $new_order_id . '&selected_box=customers&action=edit', 'SSL'));
			break;
		}
		exit;
	}
	
	$events_array=tep_get_events_instructor_array_single();
	$event_found=true;
	if (sizeof($events_array)<=0){
		$event_found=false;
	} else {
		if ($select_id!=0 && $select_id!=$events_id)
			$events_id=$select_id;
		else if ($select_id==0 && $events_id==0)
			$events_id=-1;
			$selected_name='All Events';
	}

	$event_query=tep_db_query("SELECT events_id,session_style from " . TABLE_EVENTS . " where events_id='" . (int)$events_id . "'");
	$event_result=tep_db_fetch_array($event_query);
	$session_style=$event_result["session_style"];
	
	tep_session_unregister('payment');
	tep_session_unregister('reservation_id');
	
	if($events_id!=-1)
		$where=" and s.events_id='" . $events_id . "'";
	$search_query="select o.orders_id,concat(c.customers_firstname,' ',c.customers_lastname) as customers_name,o.customers_id,op.products_name,s.events_id from " . 
					TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o, " . TABLE_CUSTOMERS . " c, " .  TABLE_EVENTS_SESSIONS . " s " .
					"where op.orders_id=o.orders_id and c.customers_id=o.customers_id and op.products_id=s.sessions_id and " .
					"op.products_type='E' and op.events_type ='R' and op.waitlist_type='P' " .$where . "  group by o.orders_id order by o.customers_name,o.orders_id,s.start_date";
	$result_query=tep_db_query($search_query);
	$cnt=tep_db_num_rows($result_query);
	
	
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/event_select.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script>
	var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
	var sel_events_id='-1';
	
	var prev_id="";
	
	function do_page_fetch(action,id,eve_id){
		
		var data=document.getElementById('data_' + id);
		var head=document.getElementById('head_' + id);	
		document.select_event.orders_id.value=id;
		document.select_event.events_id.value=sel_events_id;
		command="<?php echo tep_href_link(FILENAME_PENDING_WAITLIST_PAYMENTS);?>" + '?command=' +action ;
		
		switch(action){
			case 'select_event':
				sel_events_id= document.select_event.select_id.value;
				document.getElementById('ajx_details').innerHTML=document.getElementById('loading').innerHTML;
				command=command+ '&events_id=' + sel_events_id;
				prev_id='';
			break;
			case 'get_details':
			sel_events_id= document.select_event.select_id.value;
				if(sel_events_id=='-1')
					sel_events_id=eve_id;
				if(data.style.display=="none"){ 
				head.style.display="none";
					if(prev_id!=''){
						document.getElementById('head_' + prev_id).style.display="";
						document.getElementById('data_' + prev_id).innerHTML="";
						document.getElementById('data_' + prev_id).style.display="none";
					}
					prev_id=id;
					data.style.display="";
					data.innerHTML=document.getElementById('loading').innerHTML;
				}
				command=command+ '&orders_id=' + id;
			break;
			case 'edit':
				document.getElementById('img_delete').style.display="none";
				document.getElementById('span_details').style.display="none";
				document.getElementById('span_edit').style.display="";
				document.getElementById('img_save').style.display="";
				document.getElementById('span_edit').innerHTML=document.getElementById('loading').innerHTML;
				command=command+ '&orders_id=' + id;
			break;
			case 'save':
				command=command+ '&orders_id=' + id +  '&events_id=' + sel_events_id;;
				do_post_command('select_event',command);
				return;
			break;
			case 'confirm':
				command=command +  '&events_id=' + sel_events_id;
				do_post_command('select_event',command);
			
				return;
			break;
			case 'close_status':
				document.getElementById('img_delete').style.display="";
				document.getElementById('span_edit').style.display="none";
				document.getElementById('span_edit').innerHTML="";
				document.getElementById('span_details').style.display="";
				document.getElementById('img_save').style.display="none";
				if(document.getElementById('edit_img').childNodes[0].src==img_src + 'template/img_edit_hover.gif')
					document.getElementById('edit_img').childNodes[0].src=img_src+ 'template/img_edit.gif';
				return;
			break;
			case 'close':
				document.getElementById('img_save').style.display="";
				data.style.display="none";
				head.style.display="";
				prev_id='';
				return;
			break;	
		}
		command=command+  '&events_id=' + sel_events_id;
		do_get_command(command);
	}
	
	function do_result(result){
		var splt=Array();
		splt=result.split("{}");
		var spl_arr=Array();
		var sp1=splt[1];
		spl_arr=sp1.split("||");
		
		switch(splt[0]){
			case 'select_event':
				document.getElementById('ajx_details').innerHTML=spl_arr[1];
			break;
			case 'get_details':
				document.getElementById('data_' + spl_arr[1]).innerHTML=spl_arr[2];
				document.getElementById('img_delete').style.display="";
			break;
			case 'edit':
				document.getElementById('span_edit').innerHTML=spl_arr[2];
			break;
			case 'save':
				document.getElementById('span_edit').innerHTML=spl_arr[2];
			break;
		}	
	}
	
	function validateForm(frm)
	{
		if(document.getElementById('pay_action') &&  document.getElementById('pay_action').value=='confirm'){
			document.select_event.action="<?php echo tep_href_link(FILENAME_PENDING_WAITLIST_PAYMENTS);?>" + '?command=confirm';
			document.select_event.submit();
		}	
		else {
			if(check_form(frm)==true){
				do_page_fetch('save',document.select_event.orders_id.value);
			}
			return false;
		}
	}
	
	function check_form(frm){
		var found=false;
		pos=0;
		if (frm.row_check.value>2){
			for (icnt=0;icnt<frm.elements["reservation_id[]"].length;icnt++){
				if (frm.elements["reservation_id[]"][icnt].checked==true) {
					found=true;
					return true;
					break;
				}
			}
		} else {
			found=frm.elements["reservation_id[]"].checked;
		}
		if (found==false){
			alert("<?php echo tep_db_input(ERR_SELECT_RESERVATION); ?>");
			return false;
		}
		return true;
	}
	
	function checkAllPayment(orderbox){
		var reserve_element;
		var row=0;
		var checkFlag=false;
		row=parseInt(orderbox.value);
		checkFlag=orderbox.checked;
		reserve_element=document.forms["select_event"].elements["reservation_id[]"];
		if (!reserve_element) return;
		if (reserve_element.length) {
			for (icnt=0;icnt<reserve_element.length;icnt++){
				reserve_element[icnt].checked=checkFlag;
				reserve_element[icnt].disabled=checkFlag;
			}
		} else {
			reserve_element.checked=checkFlag;
			reserve_element.disabled=checkFlag;
		}
	}
	
 function do_hover_change(element,eve){ 
	 if(element){		   		    		    
		var img_get_src=element.childNodes[0];
		if(img_get_src){ 
				if(eve==1){ 
					img_get_src.src=img_src+'template/img_edit_hover.gif';
				} else if(eve==2 && document.getElementById('edit_img').childNodes[0].src!=img_src+'template/img_edit_hover.gif'){
					img_get_src.src=img_src+'template/img_edit_hover.gif';
				} else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && document.getElementById('span_edit').style.display!="") img_get_src.src=img_src+'template/img_edit.gif';		   		 	 			 	 			
	 	 }
	 }	
  }  
  
  function do_change(){
	  prev_id='';
	  setListboxText(0);
  }	
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
	<!-- header //-->
	<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
	<!-- header_eof //-->
	<!-- body //-->
	<table border="0" width="100%" cellspacing="2" cellpadding="2" id="holetable">
		<tr> 
			<!-- body_text //-->	  
			<td width=100% align=left valign="top" id="formtable">
				<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td></tr>
				<?php if ($error!='') { ?>
				<tr>
					<td>
					<table width=100% border=0 cellpacing=0 cellpadding=2>
						<tr>
							<td class=main><?php echo '<font color=red>' . $error . '</font>'; ?></td>
						</tr>
					</table>
					</td>
				</tr>
				<?php }
					if ($event_found==true) { 
				?>
					<tr>
						<td><?php echo tep_draw_form('select_event',FILENAME_PENDING_WAITLIST_PAYMENTS,'','post','onSubmit="return validateForm(this);"'); ?>
							<table cellpadding="0" cellspacing="0" border="0" width="100%">
								<tr>
									<td>
								<?php echo '<input type=hidden name="events_id">' .  '<input type=hidden name="orders_id">'; //$selected_name="";	?>
									<table border="0" cellspacing="0" cellpadding="2">
										<div id="event_list" style="position:absolute;left:242px;top:130px;display:none;width:400px">
											<?php echo tep_draw_event_select_menu('select_id',$events_array,$events_id,' size=10 style="width:400px" onClick="javascript:do_change();toggleList(0);" onFocus="javascript:toggleList(1);" onBlur="javascript:toggleList(0);" class="customerSelect"');?>
										</div>
										<tr height=20>
											<td class="main" width="100"><?php echo TEXT_SELECT_EVENT;?></td>
											<td class="main"><?php echo tep_draw_input_field('select_text',$selected_name,'onFocus="javascript:toggleText(1);" onBlur="javascript:toggleText(0);" style="width:400px"');?></td>
											<td class="main" valign=center><?php echo '<a href="javascript:do_page_fetch(\'select_event\');">' . tep_image_button('button_select.gif',IMAGE_SELECT,'align=absmiddle size=') . '</a>';?></td>
										</tr>
									</table>
									<script language="JavaScript">
										if(na6) document.select_event.select_text.addEventListener("keyup",selectList,true);
										if(iex) document.select_event.select_text.onkeyup=selectList;
										if(na6) document.select_event.select_text.addEventListener("keydown",scrollList,true);
										if(iex) document.select_event.select_text.onkeydown=scrollList;
									</script>
									</td>
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td>
									<table border="0" width="100%" cellspacing="0" cellpadding="0">
										<tr>
											<td align=left class='pageHeading'><?php echo HEADING_WAITLIST_TITLE; ?></td>
										</tr>
									</table>
									</td>
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<div id="loading" style="display:none"><div style="height:30px;margin-left:30px"><img src="images/24-1.gif"></div></div>
								<tr>
									<td valign="top" id="ajx_details">
										<table cellpadding="0" cellspacing="0" width="100%" class="searchArea">
											<tr class="dataTableHeadingRow">
												<td colspan="2">
													<table cellpadding="0" cellspacing="0" border="0" width="100%">
														<tr>
															<td class="dataTableHeadingContent" width="100"><?php echo TABLE_HEADING_ORDER_ID;?></td>
															<td class="dataTableHeadingContent" width="350"><?php echo TABLE_HEADING_CUSTOMERS_NAME;?></td>
															<td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_EVENTS_NAME;?></td>
														</tr>
													</table>
												</td>		
											</tr>	
											<?php 
											$prev_name='';
											$rows=1;
										$currow=0;
										$order_total=0;
										$product_total=0;
										$session_count=0;
										$prev_order=0;
										$products_tax=0;	
										$irow=1;					
										
											 if ($cnt>0) {
											while($result=tep_db_fetch_array($result_query))	{ 
													if(($irow % 2 ) ==0) $class="dataTableRowEven";
													else $class="dataTableRowOdd";
											?>
											<tr height="25" class="<?php echo $class;?>" onMouseover="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" onClick="javascript:if(document.getElementById('data_<?php echo $result['orders_id'];?>').style.display=='none') do_page_fetch('get_details','<?php echo $result['orders_id'];?>','<?php echo $result['events_id'];?>');">
												<td colspan="3">
													<div id="head_<?php echo $result['orders_id'];?>">
														<table cellpadding="0" cellspacing="0" width="100%" border="0">
															<tr class="d">
																<td  class="dataTableContent" width="100"><?php echo $result['orders_id'];?></td>
																<td class="dataTableContent" width="350"><?php echo $result['customers_name']; ?></td>
																<td class="dataTableContent"><?php echo $result['products_name']; ?></td>
															</tr>
														</table>
													</div>
													<div id="data_<?php echo $result['orders_id'];?>" style="display:none"></div>
											</tr>
											<?php $irow++; } ?>
										
									<?php }else { ?>
											<tr>
												<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
											</tr>
											<tr>
												<td align="center" class='main'><?php echo TEXT_NO_WAITLISTS; ?></td>
											</tr>
									   <?php } ?>	
									  </table> 
									</td>
								</tr>	  
				<?php } else { ?>
								<tr><td class="pageHeading"><?php echo TEXT_HEADING_EMPTY_EVENTS ;?></td></tr>
				<?php } ?>
							</table>
						</td>
					</tr>
			</table>
		</td>
	</tr>		
</table>
<!-- body_text_eof //-->
<script>
	document.select_event.select_id.value='-1';
</script>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); 
function get_waitlist_payment_details($events_id){
	$irow=1;
	if($events_id!=-1)
		$where=" and s.events_id='"  . $events_id ."'";
	$search_query="select o.orders_id,concat(c.customers_firstname,' ',c.customers_lastname) as customers_name,o.customers_id,op.products_name,s.events_id from " . 
					TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o, " . TABLE_CUSTOMERS . " c, " .  TABLE_EVENTS_SESSIONS . " s " .
					"where op.orders_id=o.orders_id and c.customers_id=o.customers_id and op.products_id=s.sessions_id and " .
					"op.products_type='E' and op.events_type ='R' and op.waitlist_type='P' " .$where . "  group by o.orders_id order by o.customers_name,o.orders_id,s.start_date";
					
	$result_query=tep_db_query($search_query); ?>
		<table cellpadding="0" cellspacing="0" width="100%" class="searchArea" border="0">
			<tr>
				<td><table cellpadding="0" cellspacing="0" width="100%" border="0">
						<tr class="dataTableHeadingRow">
							<td class="dataTableHeadingContent" width="100"><?php echo TABLE_HEADING_ORDER_ID;?></td>
							<td class="dataTableHeadingContent" align="left" width="350"><?php echo TABLE_HEADING_CUSTOMERS_NAME;?></td>
							<td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_EVENTS_NAME;?></td>
						</tr>	
				</table></td>
			</tr>	
			<?php if(tep_db_num_rows($result_query)>0){
					 while($result=tep_db_fetch_array($result_query))	{ 
							if($irow%2==0) $class="dataTableRowEven";
							else $class="dataTableRowOdd";
			?>
			<tr height="25" class="<?php echo $class;?>" onMouseMove="rowOverEffect(this);" onMouseOut="rowOutEffect(this);" onClick="javascript:if(document.getElementById('data_<?php echo $result['orders_id'];?>').style.display=='none') do_page_fetch('get_details','<?php echo $result['orders_id'];?>','<?php echo $result['events_id'];?>');">
				<td>
					<div id="head_<?php echo $result['orders_id'];?>">
						<table cellpadding="0" cellspacing="0" width="100%" border="0">
							<tr>
								<td  class="dataTableContent" width="100"><?php echo $result['orders_id'];?></td>
								<td class="dataTableContent" width="350"><?php echo $result['customers_name']; ?></td>
								<td class="dataTableContent"><?php echo $result['products_name']; ?></td>
							</tr>
						</table>
					</div>
					<div id="data_<?php echo $result['orders_id'];?>" style="display:none"></div>
				</td>	
			</tr>
			<?php $irow++;} }else { ?>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<tr>
				<td align="center" class='main'><?php echo TEXT_NO_WAITLISTS; ?></td>
			</tr>
			<?php } ?>	
		</table>
<?php }

function do_edit_details($events_id,$orders_id){
	global $currencies;
	$search_query="select o.orders_id,op.orders_products_id,op.final_price,op.products_tax,op.events_type,op.waitlist_type,concat(c.customers_firstname,' ',c.customers_lastname) as customers_name,s.start_date,op.events_fees,o.customers_id from " . 
					TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o, " . TABLE_CUSTOMERS . " c, " .  TABLE_EVENTS_SESSIONS . " s " .
					"where op.orders_id=o.orders_id and c.customers_id=o.customers_id and op.products_id=s.sessions_id and " .
					"op.products_type='E' and op.events_type ='R' and op.waitlist_type='P' and s.events_id='" .(int)$events_id . "' and o.orders_id='". (int)$orders_id ."'  order by o.customers_name,o.orders_id,s.start_date";
	$result_query=tep_db_query($search_query); 
	
	$event_query=tep_db_query("SELECT events_id,session_style from " . TABLE_EVENTS . " where events_id='" . (int)$events_id . "'");
	$event_result=tep_db_fetch_array($event_query);
	$session_style=$event_result["session_style"];
	
	$rows=1;
	$currow=0;
	$order_total=0;
	$product_total=0;
	$session_count=0;
	$prev_order=0;
	$products_tax=0;
	echo '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td width="50"></td><td><table cellpadding="0" cellspacing="0" border="0" width="100%">';
	while($result=tep_db_fetch_array($result_query)) { 
		if ($prev_order!=$result['orders_id']){ // if this is the new customer name
			if ($rows>1) {
				if ($event_result['session_style']=='E'){
					$order_total_query=tep_db_query("SELECT sum(op.final_price) as total from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS  . " s where op.orders_id='" .  $prev_order . "' and s.events_id='" . $event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' group by op.orders_id union " . 
													"SELECT sum(op.events_fees) as total from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS  . " s where op.orders_id='" .  $prev_order . "' and s.events_id='" . $event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' and ((op.events_type='R' and op.waitlist_type='P') or op.events_type='C') group by op.orders_id");
					
					$order_total_result=tep_db_fetch_array($order_total_query);
					$amount_paid=(float)$order_total_result["total"];

					$order_total_result=tep_db_fetch_array($order_total_query);
					$amount_total=(float)$order_total_result["total"];

					$confirm_order_query=tep_db_query("SELECT sum(op.final_price) as confirm_total from " . TABLE_ORDERS_PRODUCTS  . " op, " .  TABLE_EVENTS_SESSIONS  . " s where op.waitlist_orders_id='" . $prev_order . "' and s.events_id='" . (int)$event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' and op.events_type='R'");
					$confirm_result=tep_db_fetch_array($confirm_order_query);
					
					$final_amount=tep_add_tax($amount_total - ($amount_paid+(float)$confirm_result['confirm_total']),$products_tax);
				} else {
					$final_amount=$product_total - $order_total;
				}
					
				if ($final_amount<0) $final_amount=0;
	?>
				<tr>
					<td class='main' width=50><?php echo tep_draw_checkbox_field('complete_payment',$result['orders_id'],false,'','onClick="javascript:checkAllPayment(this);"'); ?></td>
					<td align="left" class="main"><?php echo TEXT_PAYMENT ;?></td>
					<td align="right" class="main"><?php echo $currencies->format($final_amount) ;?></td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
				</tr>
				<?php echo tep_draw_hidden_field('row_check',$rows); ?>
				<tr>
					<td colspan=3 align="right" class="main"><?php echo tep_image_submit('button_pay_amount.gif',IMAGE_PAY_AMOUNT) ;?></td>
				</tr>
				</table></td></tr>
		<?php 
				$order_total=0;
				$product_total=0;
				$session_count=0;
			}
		?>
		<tr>
			<td>
			<table border="0" cellspacing="0" cellpadding="4" width="400">
			<?php 	$rows=1;
					$currow++;
					$prev_order=$result['orders_id'];
					echo '<input type=hidden name="customers_id" value="' . $result['customers_id'] . '">';
					}
			?>
					<tr>
						<td class='main' width=50><?php echo tep_draw_checkbox_field('reservation_id[]',$result['orders_products_id']); ?></td>
						<td class='main' width=100><?php echo format_date($result['start_date']); ?></td>
						<td class='main' width=120 align="right">
						<?php 
							$product_total+=tep_add_tax($result['events_fees'],$result['products_tax']);
							$amount=$result['events_fees'];
							$order_total+=tep_add_tax($result['final_price'],$result['products_tax']);
							if ($amount>0 && $session_style!='E'){
								$amount-=$result['final_price'];
								$amount=tep_add_tax($amount,$result['products_tax']);
								echo $currencies->format($amount);
							}
						?>
						</td>
					</tr>
			<?php 	$rows++;
			$prev_name=$result['customers_name'];
			$products_tax=$result['products_tax'];

			}
	   if ($rows>1) {
			if ($event_result['session_style']=='E'){
					$order_total_query=tep_db_query("SELECT sum(op.final_price) as total from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS  . " s where op.orders_id='" .  $prev_order . "' and s.events_id='" . $event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' group by op.orders_id union " . 
													"SELECT sum(op.events_fees) as total from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS  . " s where op.orders_id='" .  $prev_order . "' and s.events_id='" . $event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' and ((op.events_type='R' and op.waitlist_type='P') or op.events_type='C') group by op.orders_id");
					
					$order_total_result=tep_db_fetch_array($order_total_query);
					$amount_paid=(float)$order_total_result["total"];

					$order_total_result=tep_db_fetch_array($order_total_query);
					$amount_total=(float)$order_total_result["total"];

					$confirm_order_query=tep_db_query("SELECT sum(op.final_price) as confirm_total from " . TABLE_ORDERS_PRODUCTS  . " op, " .  TABLE_EVENTS_SESSIONS  . " s where op.waitlist_orders_id='" . $prev_order . "' and s.events_id='" . (int)$event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' and op.events_type='R'");
					$confirm_result=tep_db_fetch_array($confirm_order_query);
					
					$final_amount=tep_add_tax($amount_total - ($amount_paid+(float)$confirm_result['confirm_total']),$products_tax);
			} else {
				$final_amount=$product_total - $order_total;
			}
		if ($final_amount<0) $final_amount=0;
	   ?>
				<tr>
					<td class='main' width=50><?php echo tep_draw_checkbox_field('complete_payment',$currow,false,'','onClick="javascript:checkAllPayment(this);"'); ?></td>
					<td align="left" class="main"><?php echo TEXT_PAYMENT ;?></td>
					<td align="right" class="main"><?php echo $currencies->format($final_amount) ;?></td>
					
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
				</tr>
				<?php echo tep_draw_hidden_field('row_check',$rows); ?>
			</table>
			</td>
		</tr>
	
	<?php } ?>
		<tr>
			<td align="right" class="main"><?php echo tep_draw_separator('pixel_trans.gif','20','20');?></td>
		</tr>
	</table></td></tr></table>
<?php 	
}

function do_get_details($events_id,$orders_id){
	global $currencies;
	$search_query="select o.orders_id,concat(c.customers_firstname,' ',c.customers_lastname) as customers_name,o.customers_id,op.products_name from " . 
					TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o, " . TABLE_CUSTOMERS . " c, " .  TABLE_EVENTS_SESSIONS . " s " .
					"where op.orders_id=o.orders_id and c.customers_id=o.customers_id and op.products_id=s.sessions_id and " .
					"op.products_type='E' and op.events_type ='R' and op.waitlist_type='P' and s.events_id='" .(int)$events_id . "' and o.orders_id='". (int)$orders_id ."'  order by o.customers_name,o.orders_id,s.start_date";
	$result_query=tep_db_query($search_query); 
	$search_result=tep_db_fetch_array($result_query);
	
	$event_query=tep_db_query("SELECT events_id,session_style from " . TABLE_EVENTS . " where events_id='" . (int)$events_id . "'");
	$event_result=tep_db_fetch_array($event_query);
	$session_style=$event_result["session_style"];

	if ($event_result['session_style']=='E'){
			$order_total_query=tep_db_query("SELECT sum(op.final_price) as total from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS  . " s where op.orders_id='" .  (int)$orders_id . "' and s.events_id='" . (int)$event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' group by op.orders_id union " . 
											"SELECT sum(op.events_fees) as total from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS  . " s where op.orders_id='" .  (int)$orders_id . "' and s.events_id='" . (int)$event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' and ((op.events_type='R' and op.waitlist_type='P') or op.events_type='C') group by op.orders_id");
			
			$order_total_result=tep_db_fetch_array($order_total_query);
			$amount_paid=(float)$order_total_result["total"];

			$order_total_result=tep_db_fetch_array($order_total_query);
			$amount_total=(float)$order_total_result["total"];

			$confirm_order_query=tep_db_query("SELECT sum(op.final_price) as confirm_total from " . TABLE_ORDERS_PRODUCTS  . " op, " .  TABLE_EVENTS_SESSIONS  . " s where op.waitlist_orders_id='" . (int)$orders_id . "' and s.events_id='" . (int)$event_result["events_id"] . "' and op.products_id=s.sessions_id and op.products_type='E' and op.events_type='R'");
			$confirm_result=tep_db_fetch_array($confirm_order_query);
			
			$final_amount=tep_add_tax($amount_total - ($amount_paid+(float)$confirm_result['confirm_total']),$products_tax);
	} else {
		$final_amount=$product_total - $order_total;
	}
	if ($final_amount<0) $final_amount=0;
	
		$result='<table width="100%" border="0" cellspacing="0" cellpadding="0" class="openContent">'.
				'<tr><td colspan="2"><table cellpadding="0" cellspacing="0" border="0" width="100%">'.
				'<tr heigth="40" bgcolor="#EDF1FE"  class="openContent_top">';  	
		$result.=		  '<td width="40" valign="top" align="center">&nbsp;</td>'.
				  '<td align="left" valign="middle" width="350" class="inner_title" id="row_heading">'. $search_result['customers_name'].'</td>'.
				  '<td  align="left" class="main" valign="top">'.
				  	'<table border="0" cellspacing="0" cellpadding="0" style="width:50;height:30px;display:inline;position:relative;">'.
				  	  '<tr class="img_move" id="img_ids">'.
				  	  	'<td class="cell_bg_popm_left" width="10">&nbsp;</td>';
					$result.=   '<td width="50" id="edit_img" align="center" onclick="javascript:do_hover_change(this,1);do_page_fetch(\'edit\',\''. $orders_id . '\');" onmouseover="javascript:do_hover_change(this,2);" onmouseout="javascript:do_hover_change(this,3);"><img alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>';
				  	 $result.=   '<td class="cell_bg_popm_right" width="10">&nbsp;</td>'.
				  	  '</tr>'.
				  	'</table>'.
				  '</td>';
			$result.=	 '<td width="240" align="right" id="img_save" style="display:none"><input type="image" src="images/template/img_savel.gif" alt="save" title="save" border="0">&nbsp;&nbsp;<a href="javascript:do_page_fetch(\'close_status\',\'' . $orders_id .'\');"><img src="images/template/img_closel.gif" alt="close" title="close" border="0"></a>&nbsp;&nbsp;</td>'.
						 '<td width="140" align="right" id="img_delete" style="display:none"><a href="javascript:do_page_fetch(\'close\',\'' . $orders_id .'\');"><img src="images/template/img_closel.gif" alt="close" title="close" border="0"></a></td>'. 	
				'</tr>';
					$result.= '<tr ><td width="40" valign="top" align="center">&nbsp;</td><td colspan="4"><div id="span_details" class="openContent"><table cellpadding="2" cellspacing="2" border="0" width="100%">';
					$result.='<tr><td colspan="4">' . tep_draw_separator('pixel_trans.gif','10','10') . '</td></tr>';
					$result.='<tr><td class="main" width="110">' . TEXT_CUSTOMER_NAME . '</td><td class="main" width="200">' . $search_result['customers_name'] . '</td><td class="main" width="180">' . TEXT_PAYMENT . '</td><td class="main" width="100">' . $currencies->format($final_amount) . '</td><tr>';
					$result.='<tr><td class="main" width="110">' . TEXT_EVENTS_NAME . '</td><td class="main width="200"">' . $search_result['products_name'] . '</td><td class="main" width="60">' . TEXT_ORDER_ID . '</td><td class="main">' . $search_result['orders_id'] . '</td></tr>';
							
					$result.='<tr><td colspan="4">' . tep_draw_separator('pixel_trans.gif','10','10') . '</td></tr></table></div></td></tr>';
					$result.='<tr><td colspan="5"><span id="span_edit" style="display:none" class="openContent"></span></td></tr>';
					$result.='<tr><td colspan="5"><span id="span_edit_confirm" style="display:none" class="openContent"></span></td></tr>';
			$result .='</table></td></tr></table>';
			return $result;
}


function sbs_get_zone_name($country_id, $zone_id) {
    $zone_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country_id . "' and zone_id = '" . (int)$zone_id . "'");
    if (tep_db_num_rows($zone_query)) {
      $zone = tep_db_fetch_array($zone_query);
      return $zone['zone_name'];
    } else {
      return $default_zone;
    }
  }
  
function update_totals($order_id)
{
	global $currencies;
	$order = new order($order_id);
	
	$RunningSubTotal = 0;
	$RunningTax = 0;
	
	for ($i=0; $i<sizeof($order->products); $i++)
	{
		$RunningSubTotal += ($order->products[$i]['qty'] * $order->products[$i]['final_price']);
		$RunningTax += (($order->products[$i]['tax'] / 100) * ($order->products[$i]['qty'] * $order->products[$i]['final_price']));			
	}
	$sql_array=array(	'orders_id'=>$order_id,
						'text'=>$currencies->format($RunningSubTotal),
						'value'=>$RunningSubTotal,
						'class'=>'ot_subtotal',
						'title'=>'Sub Total',
						'sort_order'=>1);
	tep_db_perform(TABLE_ORDERS_TOTAL,$sql_array);

	$sql_array=array(	'orders_id'=>$order_id,
						'text'=>$currencies->format($RunningTax),
						'value'=>$RunningTax,
						'class'=>'ot_tax',
						'title'=>'Tax',
						'sort_order'=>2);
	tep_db_perform(TABLE_ORDERS_TOTAL,$sql_array);

	$sql_array=array(	'orders_id'=>$order_id,
						'text'=>$currencies->format(tep_get_rounded_amount($RunningTax+$RunningSubTotal), true, $order->info['currency'], $order->info['currency_value']),
						'value'=>tep_get_rounded_amount($RunningTax+$RunningSubTotal),
						'class'=>'ot_total',
						'title'=>'Total',
						'sort_order'=>3);
	tep_db_perform(TABLE_ORDERS_TOTAL,$sql_array);
}

function do_get_confirm_details(){
global $currencies,$HTTP_POST_VARS;

	$reserve_id=(isset($HTTP_POST_VARS['reservation_id'])?$HTTP_POST_VARS['reservation_id']:array());
	$complete_payment=(isset($HTTP_POST_VARS['complete_payment'])?$HTTP_POST_VARS['complete_payment']:'');
	$action=(isset($HTTP_GET_VARS['action'])?$HTTP_GET_VARS['action']:'');

	//if (sizeof($reserve_id)<=0 && $complete_payment=="")
	//	tep_redirect(tep_href_link(FILENAME_PENDING_WAITLIST_PAYMENTS));

	$rows=0;
	$selected_sessions=array();
	for ($icnt=0;$icnt<sizeof($reserve_id);$icnt++){
		$selected_sessions[$reserve_id[$icnt]]=1;
	}
	$orders_id=(isset($HTTP_POST_VARS["orders_id"])?(int)$HTTP_POST_VARS["orders_id"]:0);
	$events_id=(isset($HTTP_POST_VARS["events_id"])?(int)$HTTP_POST_VARS["events_id"]:0);
	// get event related details
	$events_query=tep_db_query("SELECT session_style from " . TABLE_EVENTS . " where events_id='" . (int)$events_id ."'");
	$events_result=tep_db_fetch_array($events_query);

	//select customer name and pending confirm amount
	$customer_query=tep_db_query("SELECT customers_name,date_purchased from " . TABLE_ORDERS . " where orders_id='" . (int)$orders_id . "'");
	$customer_result=tep_db_fetch_array($customer_query);

	// fetch the total amount for the event
?>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr> 
	<!-- body_text //-->	  
		<td width=100% align=left valign="top">
			<table border="0" cellspacing="0" cellpadding="2">
<?php if ($events_result['session_style']=='E'){ 
	$final_amount=0.0;
	$waitlist_amount=0.0;
	$total_amount=0.0;

	$session_count=0;
	$session_amounts=array();
	$waitlist_query=tep_db_query("select sum(op.final_price) as total from " . 
					TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS . " s  where op.orders_id='" . (int)$orders_id . "' and s.events_id='" . (int)$events_id . "' and op.products_id=s.sessions_id and op.products_type='E' group by op.orders_id");
	$waitlist_result=tep_db_fetch_array($waitlist_query);
	$waitlist_amount=(float)$waitlist_result["total"];
	
	$search_query=	"select op.orders_products_id,op.final_price,op.events_fees,op.products_tax,op.orders_products_id,op.events_type from " . 
					TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS . " s  where op.orders_id='" . (int)$orders_id . "' and s.events_id='" . (int)$events_id . "' and op.products_id=s.sessions_id and op.products_type='E' and ((op.events_type='R' and op.waitlist_type='P') or op.events_type='C')";
	$result_query=tep_db_query($search_query);
	while($result=tep_db_fetch_array($result_query)){
		$session_amount=$result['events_fees'];
		$products_tax=$result['products_tax'];
		if (isset($selected_sessions[$result['orders_products_id']]) || $complete_payment!="") {
			if ($result["events_type"]!='C'){
				$total_amount+=$result['events_fees'];
				$session_amounts[]=array('id'=>$result['orders_products_id'],'current_price'=>$result['final_price'],'original_price'=>$session_amount);
				$session_count++;
			}
		}
	}

	$confirm_amounts=array();
	$confirm_amount=0.0;
	$current_amount=0;
	$confirm_order_query=tep_db_query("SELECT sum(events_fees) as confirm_total,sum(final_price) as confirm_paid,events_fees,count(op.products_id) as confirm_count,op.products_tax,o.date_purchased from " . TABLE_ORDERS_PRODUCTS  . " op," . TABLE_ORDERS . " o, " . TABLE_EVENTS_SESSIONS  . " s where op.waitlist_orders_id='" . (int)$orders_id . "' and s.events_id='" . (int)$events_id . "' and op.products_id=s.sessions_id and op.orders_id=o.orders_id group by op.orders_id");
	while($confirm_result=tep_db_fetch_array($confirm_order_query)){
		$current_amount=$confirm_result['confirm_total']-$confirm_result['confirm_paid'];
		$confirm_amount+=$current_amount;
		if ($confirm_amount>=$waitlist_amount) $confirm_amount=$waitlist_amount;
		$confirm_amounts[]=array('text'=>sprintf(TEXT_CONFIRM_AMOUNT,$confirm_result['confirm_count'],$confirm_result['confirm_count'],$currencies->format(tep_add_tax($confirm_result['events_fees'],$products_tax))),'amount'=>$current_amount,'date'=>$confirm_result['date_purchased']);

		if ($confirm_amount==$waitlist_amount) break;
	}
	if ($total_amount>($waitlist_amount-$confirm_amount))
		$final_amount=$total_amount-($waitlist_amount-$confirm_amount);
?>
				<tr>
					<td>
					<table border="0" cellspacing="0" cellpadding="4" >
						<tr>
							<td class="main" width="250"><b><?php echo sprintf(TEXT_TO_BE_PAID_AMOUNT,$session_count,$session_count,$currencies->format(tep_add_tax($session_amount,$products_tax))); ?></b></td>
							<td class="main" width="100" align="right"><?php echo $currencies->format(tep_add_tax($session_count*$session_amount,$products_tax)); ?></td>
						</tr>
						<tr>
							<td class="main" width="250"><b><?php echo '<a href="#waitlist-details" class="blue">' . TEXT_REMAIN_AMOUNT . '<a>'; ?></b></td>
							<td class="main" width="100" align="right"><?php echo ($waitlist_amount-$confirm_amount>0?"-":"") . $currencies->format(tep_add_tax($waitlist_amount-$confirm_amount,$products_tax)); ?></td>
						</tr>
						<tr>
							<td class="main" width="250"></td>
							<td class="main" width="100" align="right"><?php echo tep_draw_separator('pixel_black.gif','60%',1); ?></td>
						</tr>
						<tr>
							<td class="main" width="250"><b><?php echo TEXT_FINAL_AMOUNT; ?></b></td>
							<td class="main" width="100" align="right"><?php echo $currencies->format(tep_add_tax($final_amount,$products_tax)); ?></td>
						</tr>
					</table>
					</td>
				</tr>
			<?php 	$calculate_amount=0; // actual calculated amount
					$prepared_amount=$final_amount; //final prepared amount to be paid
					$updated_amount=$waitlist_amount-$confirm_amount;  // remaining waitlist amount
					for ($icnt=0;$icnt<sizeof($session_amounts);$icnt++){
						$calculate_amount+=$session_amounts[$icnt]['original_price'];
						echo '<input type="hidden" name=orders[' . $icnt . '][id] value="' . $session_amounts[$icnt]['id'] . '">';
						if ($calculate_amount<=$updated_amount){
							$new_price=0;
						} else if ($prepared_amount>$session_amounts[$icnt]['original_price']) {
							$new_price=$session_amounts[$icnt]['original_price'];
							$prepared_amount-=$session_amounts[$icnt]['original_price'];
						} else {
							$new_price=$prepared_amount;
						}
						echo '<input type="hidden" name=orders[' . $icnt . '][amount] value="' . $new_price . '">';
						if ($new_price<=0){
							echo '<input type="hidden" name=orders[' . $icnt . '][type] value="P">';
						} else {
							echo '<input type="hidden" name=orders[' . $icnt . '][type] value="U">';
						}
					}
			?>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<tr>
				<td class="inner_title"><?php echo TEXT_WAITLIST_HEADING;?></td>
			</tr>
			<tr id="waitlist-details">
				<td>
				<table border="0" cellspacing="0" cellpadding="4">
					<tr>
						<td class="main" width="100"><b><?php echo format_date($order_result['date_purchased']); ?></b></td>
						<td class="main" width="350"><b><?php echo TEXT_WAITLIST_AMOUNT; ?></b></td>
						<td class="main" width="100" align="right"><?php echo $currencies->format(tep_add_tax($waitlist_amount,$products_tax)); ?></td>
					</tr>
					<?php for ($icnt=0;$icnt<sizeof($confirm_amounts);$icnt++) {?>
						<tr>
							<td class="main" width="100"><b><?php echo format_date($confirm_amounts[$icnt]['date']); ?></b></td>
							<td class="main" width="350"><b><?php echo $confirm_amounts[$icnt]['text']; ?></b></td>
							<td class="main" width="100" align="right">-<?php echo $currencies->format(tep_add_tax($confirm_amounts[$icnt]['amount'],$products_tax)); ?></td>
						</tr>
					<?php }?>
					<tr>
						<td class="main" width="100">&nbsp;</td>
						<td class="main" width="350"><b><?php echo TEXT_REMAIN_AMOUNT; ?></b></td>
						<td class="main" width="100" align="right"><?php echo $currencies->format(tep_add_tax($waitlist_amount-$confirm_amount,$products_tax)); ?></td>
					</tr>
					<tr>
						<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
					</tr>
				</table>
				</td>
			</tr>
<?php } else { // events_style
	$final_amount=0.0;
	$waitlist_amount=0.0;
	$total_amount=0.0;

	$session_count=0;
	$session_amounts=array();
	$search_query=	"select op.orders_products_id,op.final_price,op.events_fees,op.products_tax,op.orders_products_id from " . 
					TABLE_ORDERS_PRODUCTS . " op where op.orders_id='" . (int)$orders_id . "' and op.products_type='E' and op.events_type='R' and op.waitlist_type='P'";
					
	$result_query=tep_db_query($search_query);
	while($result=tep_db_fetch_array($result_query)){
		$session_amount=$result['events_fees'];
		$products_tax=$result['products_tax'];
		if (isset($selected_sessions[$result['orders_products_id']]) || $complete_payment!="") {
			$waitlist_amount+=$result['final_price'];
			$total_amount+=$result['events_fees'];
			$session_amounts[]=array('id'=>$result['orders_products_id'],'current_price'=>$result['final_price'],'original_price'=>$session_amount);
			$session_count++;
		}
	}
	$final_amount=$total_amount-$waitlist_amount;
?>
			<tr>
				<td>
				<table border="0" cellspacing="0" cellpadding="4">
					<tr>
						<td class="main" width="250"><b><?php echo sprintf(TEXT_TO_BE_PAID_AMOUNT,$session_count,$session_count,$currencies->format(tep_add_tax($session_amount,$products_tax))); ?></b></td>
						<td class="main" width="100" align="right"><?php echo $currencies->format(tep_add_tax($session_count*$session_amount,$products_tax)); ?></td>
					</tr>
					<tr>
						<td class="main" width="250"><b><?php echo TEXT_WAITLIST_SESSION; ?></b></td>
						<td class="main" width="100" align="right"><?php echo ($waitlist_amount-$confirm_amount>0?"-":"") . $currencies->format(tep_add_tax($waitlist_amount-$confirm_amount,$products_tax)); ?></td>
					</tr>
					<tr>
						<td class="main" width="250"></td>
						<td class="main" width="100" align="right"><?php echo tep_draw_separator('pixel_black.gif','60%',1); ?></td>
					</tr>
					<tr>
						<td class="main" width="250"><b><?php echo TEXT_FINAL_AMOUNT; ?></b></td>
						<td class="main" width="100" align="right"><?php echo $currencies->format(tep_add_tax($final_amount,$products_tax)); ?></td>
					</tr>
				</table>
				</td>
			</tr>
			<?php 	$calculate_amount=$final_amount;
					$new_price=0;
					for ($icnt=0;$icnt<sizeof($session_amounts);$icnt++){
						echo '<input type="hidden" name=orders[' . $icnt . '][id] value="' . $session_amounts[$icnt]['id'] . '">';
						$new_price=$session_amounts[$icnt]['original_price']-$session_amounts[$icnt]['current_price'];
						echo '<input type="hidden" name=orders[' . $icnt . '][amount] value="' . $new_price . '">';
						echo '<input type="hidden" name=orders[' . $icnt . '][type] value="U">';
						$calculate_amount-=$new_price;
					}
			?>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
<?php } echo tep_draw_hidden_field('pay_action','confirm');?>
		</table>
		</td>
	</tr>
</table>		
<!-- body_text_eof //-->
<?php
}

?>