<?php
/*
  $Id: mainpage.php,v 2.0 2003/06/13

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();


// BOF: Lango Added for template MOD

if (MAIN_TABLE_BORDER == 'yes' && !isset($HIDE_INDEX_TITLE)){
	table_image_border_top(false, false, HEADING_TITLE);
}
?>
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top">
<?php
// EOF: Lango Added for template MOD
		// if the content for the mainpage is empty try to give the details of current mainpage category
		$content=@file_get_contents(DIR_WS_TEMPLATES . TEMPLATE_NAME . "/content/" . $language . '/' . FILENAME_DEFINE_MAINPAGE);
		if ($content==""){ 
			$content=@file_get_contents(DIR_WS_LANGUAGES . $language . '/' . FILENAME_DEFINE_MAINPAGE);
		}
		if (defined("DEFINEPAGE_TYPE") && defined("DEFINEPAGE_CATEGORIES") && (int)DEFINEPAGE_CATEGORIES>0){ 
			$type=strtolower(DEFINEPAGE_TYPE);
			$default_category=(int)DEFINEPAGE_CATEGORIES;
			if ($type=='event' &&  HIDE_FROM_BACKEND_MENU_EVENTS!='true'){
					$define_events_list = array(	'EVENT_LIST_IMAGE' => EVENT_LIST_IMAGE,
													'EVENT_LIST_NAME' => EVENT_LIST_NAME,
													'EVENT_LIST_FEES'=>EVENT_LIST_FEES,
													'EVENT_LIST_MAX_REGT' => EVENT_LIST_MAX_REGT,
													'EVENT_LIST_MAX_RES' => EVENT_LIST_MAX_RES,
													'EVENT_LIST_SESSIONS' => EVENT_LIST_SESSIONS);
			
			
					$column_events_list = array();
					reset($define_events_list);
					while (list($events_key, $events_value) = each($define_events_list)) {
						if ($events_value > 0) $t=10;$column_events_list[] = $events_key;
					}
			
					$select_events_column_list = '';
					
					for ($i=0, $n=sizeof($column_events_list); $i<$n; $i++) {
						switch ($column_events_list[$i]) {
							case 'EVENT_LIST_NAME':
								$select_events_column_list .= 'ed.events_name, ';
								break;
							case 'EVENT_LIST_FEES':
								$select_events_column_list .= 'e.events_fees, ';
								break;
							case 'EVENT_LIST_IMAGE':
								$select_events_column_list .= 'e.events_image, ';
								break;
							case 'EVENT_LIST_MAX_RES':
								$select_events_column_list .= 'e.events_max_reserve, ';
								break;
						}
					}
					$listing_sql = "SELECT " . $select_events_column_list . " e.events_id,e.events_tax_class_id from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed, " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " e2c where e.events_status = '1' and e.events_id = e2c.events_id and ed.events_id = e2c.events_id and ed.language_id = '" . (int)$languages_id . "' " . EVENTS_CONDITION_STATUS . " and e2c.events_categories_id = '" . (int)$default_category . "'";
					$sucPath=str_replace("sucPath=","",tep_get_subscription_path($default_category));
					include(DIR_WS_MODULES . FILENAME_EVENT_LISTING_COL);
			} else if ($type=="subscription" && HIDE_FROM_BACKEND_MENU_SUBSCRIPTIONS!='true'){
					$define_subscription_list = array(	'SUBSCRIPTION_LIST_IMAGE' => SUBSCRIPTION_LIST_IMAGE,
														'SUBSCRIPTION_LIST_NAME' => SUBSCRIPTION_LIST_NAME,
														'SUBSCRIPTION_LIST_COSTS'=>SUBSCRIPTION_LIST_COSTS,
														'SUBSCRIPTION_LIST_PERIOD' => SUBSCRIPTION_LIST_PERIOD,
														'SUBSCRIPTION_LIST_BUY_NOW' => SUBSCRIPTION_LIST_BUY_NOW);
			
				
					$column_subscription_list = array();
			
					reset($define_subscription_list);
					while (list($subscription_key, $subscription_value) = each($define_subscription_list)) {
						if ($subscription_value > 0) $t=10;$column_subscription_list[] = $subscription_key;
					}
			
					$select_subscription_column_list = '';
					for ($i=0, $n=sizeof($column_subscription_list); $i<$n; $i++) {
						switch ($column_subscription_list[$i]) {
							case 'SUBSCRIPTION_LIST_NAME':
								$select_subscription_column_list .= 'sud.subscription_name, ';
								break;
							case 'SUBSCRIPTION_LIST_COSTS':
								$select_subscription_column_list .= 'su.subscription_costs, ';
								break;
							case 'SUBSCRIPTION_LIST_IMAGE':
								$select_subscription_column_list .= 'su.subscription_image, ';
								break;
							case 'SUBSCRIPTION_LIST_PERIOD':
								$select_subscription_column_list .= 'su.subscription_period, ';
								break;
						}
					}
					$listing_sql = "SELECT  " . $select_subscription_column_list . "subscription_tax_class_id,su.subscription_id from " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud, " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " su2c where su.subscription_id = su2c.subscription_id and sud.subscription_id = su2c.subscription_id and sud.language_id = '" . (int)$languages_id . "' and su2c.subscription_categories_id = '" . (int)$default_category . "' " .  SUBSCRIPTION_CONDITION_STATUS;
					$ecPath=str_replace('ecPath=',"",tep_get_path($default_category));
					include(DIR_WS_MODULES . FILENAME_SUBSCRIPTION_LISTING_COL);
			} else if ($type=="product" && HIDE_FROM_BACKEND_MENU_PRODUCTS!='true'){ 
					$define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
										 'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
										 'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
										 'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
										 'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
										 'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
										 'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE,
										 'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);
				
					asort($define_list);
				
					$column_list = array();
					reset($define_list);
					while (list($key, $value) = each($define_list)) {
					  if ($value > 0) $column_list[] = $key;
					}
				
					$select_column_list = '';
				
					for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
					  switch ($column_list[$i]) {
						case 'PRODUCT_LIST_MODEL':
						  $select_column_list .= 'p.products_model, ';
						  break;
						case 'PRODUCT_LIST_NAME':
						  $select_column_list .= 'pd.products_name, ';
						  break;
						case 'PRODUCT_LIST_MANUFACTURER':
						  $select_column_list .= 'm.manufacturers_name, ';
						  break;
						case 'PRODUCT_LIST_QUANTITY':
						  $select_column_list .= 'p.products_quantity, ';
						  break;
						case 'PRODUCT_LIST_IMAGE':
						  $select_column_list .= 'p.products_image_1,p.products_title_1, ';
						  break;
						case 'PRODUCT_LIST_WEIGHT':
						  $select_column_list .= 'p.products_weight, ';
						  break;
					  }
					}
					$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, "  . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$default_category . "'";
					$cPath=str_replace("cPath=","",tep_get_path($default_category));
					include(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING_COL);
			}
		} else {
			echo $content;
		}
		unset($content);
?>
		</td>
	</tr>
    </table>
<!-- default_specials_eof //-->
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes' && !isset($HIDE_INDEX_TITLE)){
	table_image_border_bottom();
}
// EOF: Lango Added for template MOD
?>