<?php
/*
  $Id: checkout_success.php,v 1.2 2003/09/24 15:34:26 wilt Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );

  require('includes/application_top.php');

// if the customer is not logged on, redirect them to the shopping cart page
 // if (!tep_session_is_registered('customer_id')) {
  //  tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  //}

  if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'update')) {
    $notify_string = 'action=notify&';
    $notify = tep_db_prepare_input($HTTP_POST_VARS['notify']);
    if (!is_array($notify)) $notify = array($notify);
    for ($i=0, $n=sizeof($notify); $i<$n; $i++) {
      $notify_string .= 'notify[]=' . $notify[$i] . '&';
    }
    if (strlen($notify_string) > 0) $notify_string = substr($notify_string, 0, -1);

    tep_redirect(tep_href_link(FILENAME_ORDERS, $notify_string));
  }
  $paypalipn_query = tep_db_query("select o.orders_status,p.* from " . TABLE_ORDERS . " o LEFT JOIN " . TABLE_PAYPALIPN_TXN . " p on p.item_number = o.orders_id AND o.customers_id = '" . (int)$customer_id . "' order by o.date_purchased desc limit 1");
  $paypalipn = tep_db_fetch_array($paypalipn_query);

  if ($paypalipn['ipn_result']=='VERIFIED') {
    if ($paypalipn['payment_status']=='Completed') {
      $NAVBAR_TITLE_2 = PAYPAL_NAVBAR_TITLE_2_OK;
      $HEADING_TITLE = PAYPAL_HEADING_TITLE_OK; 
      $TEXT_SUCCESS = PAYPAL_TEXT_SUCCESS_OK; 
    } else if ($paypalipn['payment_status']=='Pending') { 
      $NAVBAR_TITLE_2 = PAYPAL_NAVBAR_TITLE_2_PENDING; 
      $HEADING_TITLE = PAYPAL_HEADING_TITLE_PENDING; 
      $TEXT_SUCCESS = PAYPAL_TEXT_SUCCESS_PENDING; 
    }; 
    $cart->reset(TRUE); 
  } else if ($paypalipn['ipn_result']=='INVALID') { 
    $NAVBAR_TITLE_2 = PAYPAL_NAVBAR_TITLE_2_FAILED; 
    $HEADING_TITLE = PAYPAL_HEADING_TITLE_FAILED; 
    $TEXT_SUCCESS = PAYPAL_TEXT_SUCCESS_FAILED; 
  } else if ($paypalipn['orders_status']==99999) { 
      $NAVBAR_TITLE_2 = PAYPAL_NAVBAR_TITLE_2_PENDING; 
      $HEADING_TITLE = PAYPAL_HEADING_TITLE_PENDING; 
      $TEXT_SUCCESS = PAYPAL_TEXT_SUCCESS_PENDING; 
  } else { 
    $NAVBAR_TITLE_2 = NAVBAR_TITLE_2; 
    $HEADING_TITLE = HEADING_TITLE; 
    $TEXT_SUCCESS = TEXT_SUCCESS; 
  };
	$order_id=(int)$HTTP_GET_VARS["order_id"];
	 $payment=(isset($HTTP_GET_VARS["payment"])?tep_db_prepare_input($HTTP_GET_VARS["payment"]):'');
  $global_query = tep_db_query("select global_product_notifications from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customer_id . "'");
  $global = tep_db_fetch_array($global_query);

	$orders_query = tep_db_query("select orders_id,payment_return1,payment_return2,payment_method from " . TABLE_ORDERS . " where customers_id = '" . (int)$customer_id . "'  and orders_id= '" .(int)$order_id . "' order by date_purchased desc limit 1");
	$orders = tep_db_fetch_array($orders_query);
	$orders_result=$orders;

	if ($global['global_product_notifications'] != '1') {
		$products_array = array();
		$products_query = tep_db_query("select products_id, products_name from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' and products_type='P' order by products_name");
		while ($products = tep_db_fetch_array($products_query)) {
			$products_array[] = array(	'id' => $products['products_id'],
										'text' => $products['products_name']
										);
		}
		
		$subscription_array = array();
		$subscription_query = tep_db_query("select products_id, products_name from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' and products_type='S' order by products_name");
		while ($products = tep_db_fetch_array($subscription_query)) {
			$subscription_array[] = array(	'id' => $products['products_id'],
										'text' => $products['products_name']
										);
		}


		$events_query = tep_db_query("select s.start_date,s.events_id,op.products_id, op.products_name from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS_SESSIONS . " s where orders_id = '" . (int)$orders['orders_id'] . "' and products_type='E' and s.sessions_id=op.products_id order by s.events_id,s.start_date");
		$prev_events_id=0;
		$events_array=array();
		while ($events = tep_db_fetch_array($events_query)) {
			if ($prev_events_id!=$events['events_id']){
				$events_array[$events['events_id']] = array('id' => $events['events_id'],
															'text' =>$events['products_name'],
															'dates'=>'');
				$prev_events_id=$events['events_id'];
			}
			$events_array[$events['events_id']]['dates'].="<br>" . date(EVENTS_DATE_FORMAT,strtotime($events['start_date']));
		}
		
		$service_array = array();
		$service_query = tep_db_query("select products_id, products_name from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' and products_type='V' order by products_name");
		//echo "select products_id, products_name from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' and products_type='V' order by products_name";
		while ($products = tep_db_fetch_array($service_query)) {
			$service_array[] = array(	'id' => $products['products_id'],
										'text' => $products['products_name']
										);
		}
	}
?>
	<!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>Step-by-Step Manual Order Entry - Step 3</title>
	<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
		<style>
	.checkoutBarCurrent { font-family: Verdana, Arial, sans-serif; font-size: 10px; color: #000000; }
	.checkoutBarFrom, .checkoutBarTo { font-family: Verdana, Arial, sans-serif; font-size: 10px; color: #8c8c8c; }
	</style>

	<?php require('includes/form_check.js.php'); ?>
	<script language="javascript" src="includes/menu.js"></script>
	<script language="javascript" src="includes/general.js"></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 //-->
<table id="holetable" border="0" width="100%" cellspacing="2" cellpadding="1">
	<tr>
	
	<!-- body_text //-->
	<td id="formtable" valign="top" width="100%">

<?php echo tep_draw_form('order', FILENAME_CHECKOUT_SUCCESS. '?action=update'); ?>
<table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB;?>">
      
	<tr>
		<td>
		<?php
			 /* if ($messageStack->size('checkout_success') > 0) {
				echo $messageStack->output('checkout_success');
			  }*/
		?>
		</td>
	</tr>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
<tr>
	<td>
	<table border="0" width="100%" cellspacing="4" cellpadding="2">
		<tr>
			<td valign="top"><?php echo tep_image(DIR_WS_TEMPLATES . DEFAULT_TEMPLATE . '/images/' . COMPANY_LOGO , $HEADING_TITLE,'',''); ?></td>
			<td valign="top" class="main" ><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?>
			<div align="left" class="pageHeading"><?php echo $HEADING_TITLE; ?></div>
			<br><?php echo $TEXT_SUCCESS; ?><br><br>
			<?php
				if ($payment=="commbank"){
					echo '<b>' . TEXT_RECEIPT_NO . '</b> ' . $orders_result["payment_return1"] . '<br>';
					echo '<b>' . TEXT_TRANSACTION_NO . '</b> ' . $orders_result["payment_return2"] . '<br>';
				}
				if ($global['global_product_notifications'] != '1') {
					echo '<br>' . TEXT_NOTIFY_PRODUCTS .'<br><br>';
					if (sizeof($products_array)>0){
						echo '<b>' . TEXT_PRODUCTS . '</b><br><div class="productsNotifications">';
						$products_displayed = array();
						for ($i=0, $n=sizeof($products_array); $i<$n; $i++) {
							if (!in_array($products_array[$i]['id'], $products_displayed)) {
								echo tep_draw_checkbox_field('notify[]', $products_array[$i]['id']) . ' ' . $products_array[$i]['text'] . '<br>';
						}
						$products_displayed[] = $products_array[$i]['id'];
						echo '</div>';
					}
				}
				if (sizeof($events_array)>0){
					echo '<br><b>' . TEXT_EVENTS . '</b><br><span class="productsNotifications"><table border="0" cellspacing="0" cellpadding="2" width="100%"';
					reset($events_array);
					$icnt=0;
					while(list($id,)=each($events_array)){
						echo '<tr>';
						echo '<td valign="top" class="main" width="10">' . tep_draw_checkbox_field('notify[]', $events_array[$id]['id']) . '<td class="main" nowrap> ' . $events_array[$id]['text'] . '<br><span class="productListing-data">' . substr($events_array[$id]['dates'],4) . '</span></td>';
						$icnt++;
					}
					echo '</table></span>';
				}
				if (sizeof($subscription_array)>0){
					echo '<br><b>' . TEXT_SUBSCRIPTIONS . '</b><br><span class="productsNotifications"><table border="0" cellspacing="0" cellpadding="2" width="100%"';
					reset($subscription_array);
					$icnt=0;
					while(list($id,)=each($subscription_array)){
						echo '<tr>';
						echo '<td valign="top" class="main" width="10">' . tep_draw_checkbox_field('notify[]', $subscription_array[$id]['id']) . '<td class="main" nowrap> ' . $subscription_array[$id]['text'] .  '</span></td>';
						$icnt++;
					}
					echo '</table></span>';
				}
				if (sizeof($service_array)>0){
					echo '<br><b>' . TEXT_SERVICE . '</b><br><span class="productsNotifications"><table border="0" cellspacing="0" cellpadding="2" width="100%"';
					reset($service_array);
					$icnt=0;
					while(list($id,)=each($service_array)){
						echo '<tr>';
						echo '<td valign="top" class="main" width="10">' . tep_draw_checkbox_field('notify[]', $service_array[$id]['id']) . '<td class="main" nowrap> ' . $service_array[$id]['text'] .  '</span></td>';
						$icnt++;
					}
					echo '</table></span>';
				}
		} else {
			echo TEXT_SEE_ORDERS . '<br><br>' . TEXT_CONTACT_STORE_OWNER;
		}
?>
				<h3><?php echo TEXT_THANKS_FOR_SHOPPING; ?></h3></td></tr>
			</table>
		</td>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	  <tr>
		<td>
		<table border="0" width="100%" cellspacing="1" cellpadding="2" >
		  <tr >
		  <td>
		  <table border="0" width="100%" cellspacing="0" cellpadding="2">
			<tr> 
				<td align="right" class="main"><?php echo tep_image_submit('button_continue.gif'); ?></td>
			</tr>
		</table>
		</td>
		</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	<tr>
		<td>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
			<tr>
			<td width="25%">
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td width="50%" align="right"><?php echo tep_draw_separator('pixel_black.gif', '1', '5'); ?></td>
					<td width="50%"><?php echo tep_draw_separator('pixel_black.gif', '100%', '1'); ?></td>
				</tr>
            </table>
			</td>
            <td width="25%"><?php echo tep_draw_separator('pixel_black.gif', '100%', '1'); ?></td>
            <td width="25%"><?php echo tep_draw_separator('pixel_black.gif', '100%', '1'); ?></td>
            <td width="25%">
				<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td width="50%"><?php echo tep_draw_separator('pixel_black.gif', '100%', '1'); ?></td>
					<td width="50%"><?php echo tep_image(DIR_WS_IMAGES . 'checkout_bullet.gif'); ?></td>
				</tr>
            	</table>
			</td>
			</tr>
			<tr>
				<td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_DELIVERY; ?></td>
				<td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_PAYMENT; ?></td>
				<td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_CONFIRMATION; ?></td>
				<td align="center" width="25%" class="checkoutBarCurrent"><?php echo CHECKOUT_BAR_FINISHED; ?></td>
			</tr>
			</table>
		</td>
      </tr>
	</table>
</td>
</tr>
</td></tr>
	<tr><td colspan=2 align="center">
	</td></tr></table>
	<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<br>
</body>
</html>
 <?php  require(DIR_WS_INCLUDES . 'application_bottom.php');?>
