<?php
/*
  $osCommRes, Services Oline 
  http://www.oscommres.com 
  Copyright (c) 2005 osCommRes 
	
  Freeway eCommerce 
  http://www.zac-ware.com/freeway 
  Copyright (c) 2007 ZacWare

  Released under the GNU General Public License 

*/



// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	
  require('includes/application_top.php');

// check date user setting of this survey.

	$survey_result="";
	$events_id=(isset($HTTP_POST_VARS['events_id'])?(int)$HTTP_POST_VARS['events_id']:0);
	$success=false;
	if (tep_session_is_registered('customer_id')) {
		$cuID=$HTTP_SESSION_VARS['customer_id'];
	} else if(isset($HTTP_COOKIE_VARS[$sName])){
		$cuID=$HTTP_COOKIE_VARS[$sName];
	} else if(isset($HTTP_GET_VARS[$sName])){
		$cuID=tep_db_prepare_input($HTTP_GET_VARS[$sName]);
	}

	
	if ($cuID!="" && CUSTOMER_BOOKING_DETAILS=="1") {
		$survey_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS . " where events_id='" . tep_db_input($events_id) ."' and survey_type='CD' and survey_visibility_flag=1 and survey_expiration_date>=curdate()");
		$survey_result=tep_db_fetch_array($survey_query);
		$sur_cnt=tep_db_num_rows($survey_query);
		if (tep_db_num_rows($survey_query)>0)
		{
			$question_query = tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_QUESTION . " where survey_id='" . (int)$survey_result['survey_id'] . "' order by sort_order asc");
			$qcount=tep_db_num_rows($question_query);
			if (tep_db_num_rows($question_query)>0){  
				$flag_query=tep_db_query("SELECT date_add(survey_flag_date, interval '" . $survey_result['survey_time_period'] . "' month) as check_date,survey_flag_date from " . TABLE_EVENTS_SURVEYS_FLAG . " where survey_id='" . $survey_result['survey_id'] . "' and survey_flag_email='" . tep_db_input($cuID) . "' order by check_date desc");
				if (tep_db_num_rows($flag_query)<=0){
					$success=true;				
				}  else {
					$flag_result=tep_db_fetch_array($flag_query);
					if ($flag_result['check_date']<=date('Y-m-d'))
						$success=true;
				} //flag query
			} // question query
		} //survey query
	}
	if (!$success){
		$no_attendees=(isset($HTTP_POST_VARS['no_attendees'])?(int)$HTTP_POST_VARS['no_attendees']:1);
		echo '<html><head><title></title></head><body>';
		$process="cart";
		if ($no_attendees>1){
			if ($cart->get_max_attendees()<=0){
				$process="attendees";
			}
		}
		if ($process=="attendees"){
			echo tep_draw_form("checkout_event",tep_href_link(FILENAME_CHECKOUT_ATTENDEES,tep_get_all_get_params()));
		} else {
			echo tep_draw_form("checkout_event",tep_href_link(FILENAME_CHECKOUT_EVENT,tep_get_all_get_params() . "event_action=buy_product&element_type=E"));
		}
		
		reset($HTTP_POST_VARS);
		while(list($key,$value)=each($HTTP_POST_VARS)){
			if (is_array($value)){
				for ($icnt=0;$icnt<count($value);$icnt++){
					echo tep_draw_hidden_field($key . "[]",$value[$icnt]);	
				}
			} else {
				echo tep_draw_hidden_field($key,$value);
			}
		}
		echo '</form>';
		echo '<script language="javascript">document.checkout_event.submit();</script>';
		echo '</script>';
		echo '</body></html>';
		exit;
	}
	$content = CONTENT_EVENTS_BOOKING_DETAILS;
	
	require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_EVENTS_BOOKING_DETAILS);
	
	require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
	
	require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
