<?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');
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SERVICES_ATTRIBUTES);
  // if the customer is not logged on, redirect them to the login page
  if($HTTP_POST_VARS['start_date'] && $HTTP_POST_VARS['start_time'] && $HTTP_POST_VARS['end_date'] && $HTTP_POST_VARS['end_time']){
  	$services->start_date=tep_db_prepare_input($HTTP_POST_VARS['start_date']);
	$services->start_time=tep_db_prepare_input($HTTP_POST_VARS['start_time']);
	$services->end_date=tep_db_prepare_input($HTTP_POST_VARS['end_date']);
	$services->end_time=tep_db_prepare_input($HTTP_POST_VARS['end_time']);
  }
  $services->resource_id=tep_db_prepare_input($HTTP_POST_VARS['resource_ids']);
  if($HTTP_POST_VARS['resource_costs'])$services->resource_costs=tep_db_prepare_input($HTTP_POST_VARS['resource_costs']);
  if($HTTP_POST_VARS['tax_class_id'])$services->tax_class_id=tep_db_prepare_input($HTTP_POST_VARS['tax_class_id']);
  
  //print_r ($HTTP_POST_VARS);
  $category_id=isset($HTTP_GET_VARS['secPath'])?tep_db_prepare_input($HTTP_GET_VARS['secPath']):'0';
  $service_id=(int)$HTTP_GET_VARS["service_id"];
  if ($service_id<=0) tep_redirect(FILENAME_DEFAULT);
  if($category_id==0){
    $category_query=tep_db_query("select sc.services_categories_id,scd.services_categories_name from ".TABLE_SERVICES_CATEGORIES." sc,". TABLE_SERVICES_CATEGORIES_DESCRIPTION. " scd where sc.services_categories_id=scd.services_categories_id order by sc.services_categories_id ");
    $category=tep_db_fetch_array($category_query);  
    $category_id=$category['services_categories_id'];
    $category_name=$category['services_categories_name'];
  }	
  $service_id_string = tep_get_service_uprid($service_id,$services->attributes);
  if($service_id_string!=""){
  	$time_string=strtotime($services->start_date)+strtotime($services->end_date)+strtotime($services->start_time)+strtotime($services->end_time);
  	$service_id_string.="-".$time_string;
  	if($services->resource_id) $service_id_string.='-'.$services->resource_id;
	$cart->remove($service_id_string);
  }
  $result = tep_db_query("SELECT * FROM " . TABLE_SERVICES_ATTRIBUTES . " sa LEFT JOIN " . TABLE_SERVICES_OPTIONS . " so ON so.services_options_id=sa.options_id LEFT JOIN " . TABLE_SERVICES_OPTIONS_VALUES . " sov ON sov.services_options_values_id=sa.options_values_id WHERE sa.service_id='" . (int)$HTTP_GET_VARS['service_id'] . "' and so.language_id='" . tep_db_input($languages_id) . "' and sov.language_id='" . tep_db_input($languages_id) . "' group by services_options_id");
  $rows=tep_db_num_rows($result);
  $service_info=get_services_info((int)$service_id,(int)$languages_id);
  $check_products=$cart->get_products();
  $quantity=isset($HTTP_POST_VARS['products_qty'])?(int)$HTTP_POST_VARS['products_qty']:1;
  $error="";
  if($services){
  	$start_date=$services->start_date;
	$start_time=$services->start_time;
	$end_date=$services->end_date;
	$end_time=$services->end_time;
  }
  if(!tep_check_service_found($service_id ,$start_date,$end_date,$start_time,$end_time) && $service_info['include_resource']=='N') $error=ERR_TIME_ALREADY_RESERVED;  
  $find_customers_details=tep_db_query("SELECT * FROM ".TABLE_SERVICES_SURVEYS ." WHERE service_id = '".(int)$service_id."' AND survey_visibility_flag =1 AND survey_expiration_date >= '".getServerDate()."' and survey_type='CD'");
  if($rows==0 && $error==''){
        echo '<html><head><title></title></head><body>';
		echo tep_draw_form("checkout_attributes",tep_href_link(FILENAME_SERVICES_SURVEYS_ANSWER,tep_get_all_get_params() . '&type=CD' ));
		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_attributes.submit();</script>';
		echo '</script>';
		echo '</body></html>';
  }
 
  if($service['include_resource']=='Y' || $error) $quantity=1;	
    $content = CONTENT_SERVICES_ATTRIBUTES;
    $javascript = 'popup_window.js';
  
  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>