<?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 );
	
if (!function_exists('tep_db_connect')){
  require('includes/application_top.php');
}
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SUBSCRIPTION_INFO);
  if(isset($HTTP_GET_VARS['action'])) //Added line 18-26 by sobi
  {
  	if($HTTP_GET_VARS['action']=='set_subscribe')
	{
		tep_session_register('subscribed_already');
		$subscribed_already=true;
		tep_redirect(tep_href_link(FILENAME_SHOPPING_CART,''));
	}
  }
	  

  $subscription_check_query = tep_db_query("select count(*) as total from " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud where su.subscription_status = '1' and su.subscription_id = '" . (int)$HTTP_GET_VARS['subscription_id'] . "' and sud.subscription_id = su.subscription_id and sud.language_id = '" . (int)$languages_id . "'");
  $subscription_check = tep_db_fetch_array($subscription_check_query);
  //subscription type
   $subscription_details="";
  	$split_date_format = split("-",EVENTS_DATE_FORMAT);
	$database_date_format = '';
	for($i=0;$i<sizeof($split_date_format);$i++){
		$database_date_format .= "%" . $split_date_format[$i];
		if($i!=(sizeof($split_date_format)-1))
			$database_date_format .= "-";
	}
	if($database_date_format=='')$database_date_format='%d-%m-%Y';
	$subscription_sql = "select subscription_type,subscription_date_type,deliveries,deliveries_perday,subscription_period,deliveries_name, " .
						" date_format(su.subscription_finish_date,'" . $database_date_format . "') as display_finish_date, " .
						" date_format(su.subscription_start_date,'" . $database_date_format . "') as display_start_date " .
						" from " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud where su.subscription_status = '1' and su.subscription_id = '" . (int)$HTTP_GET_VARS['subscription_id'] . "' and sud.subscription_id = su.subscription_id and sud.language_id = '" . (int)$languages_id . "'";
  	$subscription_query=tep_db_query($subscription_sql);
   if(tep_db_num_rows($subscription_query)){
   	$subscription_info=tep_db_fetch_array($subscription_query);
	?>
 <?php
 	if($subscription_info['subscription_type']=='C' || $subscription_info['subscription_type']=='S'){
   		$deliveries=$subscription_info['deliveries'];
		$deliveries_name=$subscription_info['deliveries_name'];
	}
   	if($subscription_info['subscription_type']=='C')
   		$deliveries_perday=$subscription_info['deliveries_perday'];	
   	
   	if($subscription_info['subscription_type']=='C' && $deliveries && $deliveries_perday && $subscription_info['subscription_date_type'] == 'F')
   	 	 $subscription_details=sprintf(TEXT_SUBSCRIPTION_CASUAL_PER_FIXED,$deliveries,$deliveries_name,int_to_words($deliveries_perday),$subscription_info['display_start_date'],$subscription_info['display_finish_date']);
   	else if($subscription_info['subscription_type']=='C' && $deliveries && $deliveries_perday && $subscription_info['subscription_date_type'] == 'L')
		 $subscription_details=sprintf(TEXT_SUBSCRIPTION_CASUAL_PER_FLEXIBLE,$deliveries,$deliveries_name,int_to_words($deliveries_perday),$subscription_info['subscription_period'],$subscription_info['display_start_date'],$subscription_info['display_finish_date']);
   	else if($subscription_info['subscription_type']=='C' && $deliveries && $deliveries_perday && $subscription_info['subscription_date_type'] == 'P')
		 $subscription_details=sprintf(TEXT_SUBSCRIPTION_CASUAL_PER_PREDEFINED,$deliveries,$deliveries_name,int_to_words($deliveries_perday),$subscription_info['subscription_period'],$subscription_info['display_start_date'],$subscription_info['display_finish_date']);

   	else if($subscription_info['subscription_type']=='S' && $deliveries && $subscription_info['subscription_date_type'] == 'F') 
   		$subscription_details=sprintf(TEXT_SUBSCRIPTION_SEASON_DELIVERIES_FIXED,$deliveries,$deliveries_name,$subscription_info['display_start_date'],$subscription_info['display_finish_date']);
   	else if($subscription_info['subscription_type']=='S' && $deliveries && $subscription_info['subscription_date_type'] == 'L') 
   		$subscription_details=sprintf(TEXT_SUBSCRIPTION_SEASON_DELIVERIES_FLEXIBLE,$deliveries,$deliveries_name,$subscription_info['subscription_period'],$subscription_info['display_start_date'],$subscription_info['display_finish_date']);
   	else if($subscription_info['subscription_type']=='S' && $deliveries && $subscription_info['subscription_date_type'] == 'P') 
   		$subscription_details=sprintf(TEXT_SUBSCRIPTION_SEASON_DELIVERIES_PREDEFINED,$deliveries,$deliveries_name,$subscription_info['subscription_period'],$subscription_info['display_start_date'],$subscription_info['display_finish_date']);

   	else if($subscription_info['subscription_type']=='B' && $subscription_info['subscription_date_type'] == 'F') 
   		$subscription_details=sprintf(TEXT_SUBSCRIPTION_BASIC_DELIVERIES_FIXED,$subscription_info['display_start_date'],$subscription_info['display_finish_date']);
   	else if($subscription_info['subscription_type']=='B' && $subscription_info['subscription_date_type'] == 'L') 
   		$subscription_details=sprintf(TEXT_SUBSCRIPTION_BASIC_DELIVERIES_FLEXIBLE,$subscription_info['subscription_period'],$subscription_info['display_start_date'],$subscription_info['display_finish_date']);
   	else if($subscription_info['subscription_type']=='B' && $subscription_info['subscription_date_type'] == 'P') 
   		$subscription_details=sprintf(TEXT_SUBSCRIPTION_BASIC_DELIVERIES_PREDEFINED,$subscription_info['subscription_period'],$subscription_info['display_start_date'],$subscription_info['display_finish_date']);
   }
  //subscription type
  $content = CONTENT_SUBSCRIPTION_INFO;

  $javascript = 'popup_window.js';

  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
