<?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_ADVANCED_SEARCH);

  $error = false;

    $dfrom = '';
    $dto = '';
    $pfrom = '';
    $pto = '';
    $keywords = '';

    if (isset($HTTP_GET_VARS['dfrom'])) {
      $dfrom = (($HTTP_GET_VARS['dfrom'] == DOB_FORMAT_STRING) ? '' : tep_db_prepare_input($HTTP_GET_VARS['dfrom']));
    }

    if (isset($HTTP_GET_VARS['dto'])) {
      $dto = (($HTTP_GET_VARS['dto'] == DOB_FORMAT_STRING) ? '' : tep_db_prepare_input($HTTP_GET_VARS['dto']));
    }

    if (isset($HTTP_GET_VARS['pfrom'])) {
      $pfrom = tep_db_prepare_input($HTTP_GET_VARS['pfrom']);
    }

    if (isset($HTTP_GET_VARS['pto'])) {
      $pto = tep_db_prepare_input($HTTP_GET_VARS['pto']);
    }

    if (isset($HTTP_GET_VARS['keywords'])) {
      $keywords = tep_db_prepare_input($HTTP_GET_VARS['keywords']);
    }
	if(HIDE_FROM_BACKEND_MENU_SERVICES=='false') {
		if(isset($HTTP_GET_VARS['inc_service'])){
			$include_service=tep_db_prepare_input($HTTP_GET_VARS['inc_service']);
		}
	}
	
	if(HIDE_FROM_BACKEND_MENU_EVENTS=='false') {
		if(isset($HTTP_GET_VARS['inc_event'])){
			$include_event=tep_db_prepare_input($HTTP_GET_VARS['inc_event']);
		}
	}
	
	if(HIDE_FROM_BACKEND_MENU_SUBSCRIPTIONS=='false') {
		if(isset($HTTP_GET_VARS['inc_subscription'])){
			$include_subscription=tep_db_prepare_input($HTTP_GET_VARS['inc_subscription']);
		}
	}
	
	if(HIDE_FROM_BACKEND_MENU_PRODUCTS=='false') {	 
		if(isset($HTTP_GET_VARS['inc_product'])){
			$include_product=tep_db_prepare_input($HTTP_GET_VARS['inc_product']);
		}
	}	
	if(HIDE_FROM_BACKEND_MENU_SERVICES=='false') {
		if(isset($HTTP_GET_VARS['inc_service'])){
			$include_service=tep_db_prepare_input($HTTP_GET_VARS['inc_service']);
		}
	}
	
	if($include_service)
	{
		$service_category_id=isset($HTTP_GET_VARS['service_category_id'])?tep_db_prepare_input($HTTP_GET_VARS['service_category_id']):'';
		$service_subcat=isset($HTTP_GET_VARS['inc_subcat_service'])?tep_db_prepare_input($HTTP_GET_VARS['inc_subcat_service']):'';
	}
	if($include_event)
	{
		$event_category_id=isset($HTTP_GET_VARS['event_category_id'])?tep_db_prepare_input($HTTP_GET_VARS['event_category_id']):'';
		$event_subcat=isset($HTTP_GET_VARS['inc_subcat_event'])?tep_db_prepare_input($HTTP_GET_VARS['inc_subcat_event']):'';
	}
	if($include_subscription)
	{
		$subscription_category_id=isset($HTTP_GET_VARS['subscription_category_id'])?tep_db_prepare_input($HTTP_GET_VARS['subscription_category_id']):'';
		$subscription_subcat=isset($HTTP_GET_VARS['inc_subcat_subscription'])?tep_db_prepare_input($HTTP_GET_VARS['inc_subcat_subscription']):'';
	}
 	if($include_product)
	{
		$product_category_id=isset($HTTP_GET_VARS['product_category_id'])?tep_db_prepare_input($HTTP_GET_VARS['product_category_id']):'';
		$product_subcat=isset($HTTP_GET_VARS['inc_subcat_product'])?tep_db_prepare_input($HTTP_GET_VARS['inc_subcat_product']):'';
	}
 
	$date_check_error = false;
    if (tep_not_null($dfrom)) {
      if (!tep_checkdate($dfrom, DOB_FORMAT_STRING, $dfrom_array)) {
        $error = true;
        $date_check_error = true;
        $messageStack->add_session('search', ERROR_INVALID_FROM_DATE);
      }
    }

    if (tep_not_null($dto)) {
      if (!tep_checkdate($dto, DOB_FORMAT_STRING, $dto_array)) {
        $error = true;
        $date_check_error = true;
        $messageStack->add_session('search', ERROR_INVALID_TO_DATE);
      }
    }

    if (($date_check_error == false) && tep_not_null($dfrom) && tep_not_null($dto)) {
      if (mktime(0, 0, 0, $dfrom_array[1], $dfrom_array[2], $dfrom_array[0]) > mktime(0, 0, 0, $dto_array[1], $dto_array[2], $dto_array[0])) {
        $error = true;

        $messageStack->add_session('search', ERROR_TO_DATE_LESS_THAN_FROM_DATE);
      }
    }

    $price_check_error = false;
    if (tep_not_null($pfrom)) {
      if (!settype($pfrom, 'double')) {
        $error = true;
        $price_check_error = true;

        $messageStack->add_session('search', ERROR_PRICE_FROM_MUST_BE_NUM);
      }
    }

    if (tep_not_null($pto)) {
      if (!settype($pto, 'double')) {
        $error = true;
        $price_check_error = true;

        $messageStack->add_session('search', ERROR_PRICE_TO_MUST_BE_NUM);
      }
    }

    if (($price_check_error == false) && is_float($pfrom) && is_float($pto)) {
      if ($pfrom >= $pto) {
        $error = true;

        $messageStack->add_session('search', ERROR_PRICE_TO_LESS_THAN_PRICE_FROM);
      }
    }

    if (tep_not_null($keywords)) {
      if (!tep_parse_search_string($keywords, $search_keywords)) {
        $error = true;

        $messageStack->add_session('search', ERROR_INVALID_KEYWORDS);
      }
    }


  if ($error == true) {
    tep_redirect(tep_href_link(FILENAME_ADVANCED_SEARCH, tep_get_all_get_params(), 'NONSSL', true, false));
  }

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ADVANCED_SEARCH));
  $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, tep_get_all_get_params(), 'NONSSL', true, false));

  $content = CONTENT_ADVANCED_SEARCH_RESULT;

  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);

  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
