<?php

/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

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

  $input_params="";
  $error = isset($HTTP_GET_VARS['error'])?tep_db_prepare_input($HTTP_GET_VARS['error']):tep_db_prepare_input($HTTP_GET_VARS['payment_error']);
  if ($error!="") {
	  //error count start
			$error_count+=1;
			tep_set_session_value('error_count',$error_count);
		  	$exp_count=3;
	   	if(defined('CHECKOUT_FAIL_RETRY')) 	$exp_count=(int)CHECKOUT_FAIL_RETRY;
	       if($HTTP_SESSION_VARS['error_count']>$exp_count){
		   	tep_session_destroy();
		   	tep_session_unregister('login_id');
		  		tep_session_unregister('login_firstname');
			   tep_session_unregister('login_groups_id');
			   tep_session_unregister('login_groups_type');
			   tep_session_unregister('login_email');
			   tep_session_unregister('top_admin_email');
		     	tep_redirect(tep_href_link(FILENAME_LOGOFF));	
	   	 }
	   	 //echo $HTTP_SESSION_VARS['error_count']; 
	 $input_params.='error=' . urlencode(tep_db_prepare_input($HTTP_GET_VARS['error'])) . '&';
    $input_params.=tep_get_all_get_params(); 
   //error count end 
  }
  if (tep_session_is_registered('payment_page')){
    if ($payment_page=='default'){
       tep_redirect(tep_href_link(FILENAME_CREATE_ORDER_NEW,$input_params . '&step=4&payment_error_flag=yes','SSL'));
    } else if ($payment_page=='refund'){
       tep_redirect(tep_href_link(FILENAME_REFUND_RESERVATIONS,$input_params . $HTTP_SESSION_VARS['payment_params'],'SSL'));
    } else if ($payment_page=='waitlist'){
       tep_redirect(tep_href_link(FILENAME_PENDING_WAITLIST_PAYMENTS_CONFIRM,$input_params . $HTTP_SESSION_VARS['payment_params'],'SSL')); 
	} else if ($payment_page=='wallet'){
       tep_redirect(tep_href_link(FILENAME_WALLET_PAYMENT,$input_params,'SSL'));
	}
  }
  tep_redirect(tep_href_link(FILENAME_FORBIDEN));
?>
