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

	$subscription_id=(isset($HTTP_GET_VARS["subscription_id"])?(int)$HTTP_GET_VARS["subscription_id"]:0);
	
	if ($subscription_id<=0){
		tep_redirect(tep_href_link(FILENAME_DEFAULT));
	}
	
	// if the customer is not logged on, redirect them to the login page
	if (!tep_session_is_registered('customer_id')) {
		$navigation->set_snapshot();
		tep_redirect(tep_href_link(FILENAME_LOGIN, 'trial=1', 'SSL'));
	}

    $check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$billto . "'");
    $check_address = tep_db_fetch_array($check_address_query);

    if ($check_address['total'] != '1') {
      $billto = $customer_default_address_id;
    }

	$subscription_query=tep_db_query("SELECT sud.subscription_name,su.subscription_free_days from ".  
										TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud " .
										" where su.subscription_id=sud.subscription_id and su.subscription_id='" . tep_db_input($subscription_id). "'"
									);
	$subscription=tep_db_fetch_array($subscription_query);

	// check for already free trail had taken
	$take_free=false;
	$check_free_query=tep_db_query("SELECT count(*) as total from orders o,orders_products op where o.customers_id='" . (int)$customer_id . "' and op.products_id='" .tep_db_input($subscription_id) . "' and op.products_type='S' and o.orders_id=op.orders_id and op.products_price<=0");
	$check_free=tep_db_fetch_array($check_free_query);

	if ((int)$check_free["total"]<=0) $take_free=true;

	
	require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SUBSCRIPTION_TRIAL_CONFIRM);

	$breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
	$breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));

	$content = CONTENT_SUBSCRIPTION_TRIAL_CONFIRM;

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

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