<?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_id=(isset($HTTP_POST_VARS['survey_id'])?(int)$HTTP_POST_VARS['survey_id']:0);
	$question_id=(isset($HTTP_POST_VARS['question_id'])?(tep_db_prepare_input($HTTP_POST_VARS['question_id'])):array());
	$question_type=(isset($HTTP_POST_VARS['question_type'])?(tep_db_prepare_input($HTTP_POST_VARS['question_type'])):array());
	$login_id=(isset($HTTP_POST_VARS['login_id'])?(int)$HTTP_POST_VARS['login_id']:0);
	$serverDate = date('Y-m-d H:i:s',getServerDate(false));
	
	if ($survey_id>0 && sizeof($question_id)>0 && sizeof($question_type)>0 && $login_id!="") {
		//tep_redirect(tep_href_link(FILENAME_DEFAULT));
	
	$flag_id=0;
	for($icnt=0;$icnt<sizeof($question_id);$icnt++){
		$choices=tep_db_prepare_input($HTTP_POST_VARS['choices_' . $question_id[$icnt]]);
		if (tep_not_null($choices) && is_array($choices)){
			if ($flag_id==0){
				$sql_array=array(	'survey_flag_email'=>tep_db_prepare_input($login_id),
									'survey_flag_date' =>$serverDate,
									'survey_id'=>$survey_id);
				tep_db_perform(TABLE_EVENTS_SURVEYS_FLAG,$sql_array);
				$flag_id=tep_db_insert_id();
			}
			switch($question_type[$icnt]){
				case 1:
				case 2:
				case 3:
					for($jcnt=0;$jcnt<sizeof($choices);$jcnt++){
						$sql_array=array('survey_flag_id'=>tep_db_prepare_input($flag_id),
											'question_id'=>tep_db_prepare_input($question_id[$icnt]),
											'choice_id'=>tep_db_prepare_input($choices[$jcnt]));
						tep_db_perform(TABLE_EVENTS_SURVEYS_ANSWER,$sql_array);
					}
					break;
				case 4:
				case 5:
					$sql_array=array(	'survey_flag_id'=>tep_db_prepare_input($flag_id),
										'question_id'=>tep_db_prepare_input($question_id[$icnt]),
										'answer_text'=>tep_db_prepare_input($choices[0]));
					tep_db_perform(TABLE_EVENTS_SURVEYS_TEXT,$sql_array);
					break;
				case 7:
					$sql_array=array(	'survey_flag_id'=>tep_db_prepare_input($flag_id),
										'question_id'=>tep_db_prepare_input($question_id[$icnt]),
										'answer_text'=>tep_convert_date_raw(tep_db_prepare_input($choices[0])));
					tep_db_perform(TABLE_EVENTS_SURVEYS_TEXT,$sql_array);
					break;
			}
		}
	}
	}
	echo '<html><head><title></title></head><body>';
	echo tep_draw_form("checkout_event",tep_href_link(FILENAME_CHECKOUT_EVENT,tep_get_all_get_params() . "event_action=buy_product&element_type=E"));

	// draw the hidden field
	echo tep_draw_hidden("old_orders_id",(int)$HTTP_POST_VARS["old_orders_id"]);
	echo tep_draw_hidden("events_id",(int)$HTTP_POST_VARS["events_id"]);
	echo tep_draw_hidden("event_question_type",(tep_db_prepare_input($HTTP_POST_VARS["event_question_type"])));
	echo tep_draw_hidden("event_question_value_data",(tep_db_prepare_input($HTTP_POST_VARS["event_question_value_data"])));
	$session_id=(int)$HTTP_POST_VARS["session_id"];
	$session_type=tep_db_prepare_input($HTTP_POST_VARS["session_type"]);
	$session_group=tep_db_prepare_input($HTTP_POST_VARS["session_group"]);
	$session_date=tep_db_prepare_input($HTTP_POST_VARS["session_date"]);
	for ($icnt=0;$icnt<count($session_id);$icnt++){
		echo tep_draw_hidden("session_select_" . $session_id[$icnt],tep_db_prepare_input($HTTP_POST_VARS["session_select_" . $session_id[$icnt]]));
		echo tep_draw_hidden("session_id[]",$session_id[$icnt]);
		echo tep_draw_hidden("session_type[]",$session_type[$icnt]);
		echo tep_draw_hidden("session_group[]",$session_group[$icnt]);
		echo tep_draw_hidden("session_date[]",$session_date[$icnt]);
	}
	echo '</form>';
	echo '<script language="javascript">document.checkout_event.submit();</script>';
	echo '</script>';
	echo '</body></html>';
	require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
