<?php


// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
	$MAINPAGE_COLS=(isset($MAINPAGE_COLS)?$MAINPAGE_COLS:1);
	$main_page_cols_width=(100/$MAINPAGE_COLS) . "%";
?>
<table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
<?php 
// BOF: Lango Added for template MOD
$HIDE_INDEX_TITLE=true;
$current_table_box_count=-5;
if (SHOW_HEADING_TITLE_ORIGINAL == 'yes') {
$header_text = '&nbsp;';
//EOF: Lango Added for template MOD
?>
      <tr>
        <td>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading">
             <?php 
               if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($category['categories_heading_title'])) ) {
                 echo $category['categories_heading_title'];
               } else {
                 echo HEADING_TITLE;
               }
             ?>
            </td>
            <td class="pageHeading" align="left"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_default.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
	     </table>
		</td>
      </tr>
	
<?php
// BOF: Lango Added for template MOD
}else{
$header_text = HEADING_TITLE;
}
// EOF: Lango Added for template MOD
?>
<!-- Start Modules Display -->
 <tr>
	<td valign="bottom"> <?php 
		include(DIR_WS_MODULES . "mainpage.php");
		$loaded_modules=array('mainpage.php'=>1);
		
	?>
	</td>
</tr> 
<tr>
		<td>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
<?php
// EOF: Lango Added for template MOD

	$include_modules=array('TWO'=>'featured_products.php','THREE'=>'upcoming_products.php','FOUR'=>'faq.php','FIVE'=>'information.php','SIX'=>'');
	$count=array('TWO','THREE','FOUR','FIVE','SIX');
	$loaded_modules=array();
	for($icnt=0,$n=sizeof($count);$icnt<$n;$icnt++){
		$module=trim(constant('INCLUDE_MODULE_' . $count[$icnt]));
		if($module !='' && file_exists(DIR_FS_CATALOG . DIR_WS_TEMPLATES . TEMPLATE_NAME . "/content/" . $module))

		$loaded_modules[]=$module;
	}
	if(sizeof($loaded_modules) <4){
	while(list(,$module) = each($include_modules)){
		if(!in_array($module,$loaded_modules) && $module!=''){
			$loaded_modules[]=$module;
		}	
	}
	}
	$icnt=0;	
	reset($loaded_modules);

	//reset($include_modules);
	//while(list($key,$module)=each($include_modules)){
	for($jcnt=0,$n=sizeof($loaded_modules);$jcnt<$n;$jcnt++){
		$module_filename=$loaded_modules[$jcnt];
		//$module_filename=$module;
		//$module=trim(constant('INCLUDE_MODULE_' . $key));
		
		//if (tep_not_null($module) && $module!='')  $module_filename=$module;
		//if ($module_filename=='') continue;

		//if (isset($loaded_modules[$module_filename])) continue;
		$content=tep_load_template_content($module_filename);
		//$loaded_modules[$module_filename]=1;
		if (file_exists(DIR_WS_LANGUAGES . $language . "/" . $module_filename)){
			require DIR_WS_LANGUAGES . $language . "/" . $module_filename;
			
		}

		if ($content!=''){
			$row_class="rowOdd";
			if ($module_filename=='faq.php' || $module_filename=='information.php') $row_class="rowEven";
			$replace_array=array("VALUE_COL_CLASS"=>$row_class);
			$replace_array['VALUE_TITLE_ICON']=tep_template_image('arrow2.gif','','align=absmiddle') . '&nbsp;';
			$replace_array['VALUE_SEEALL_ICON']=tep_template_image('arrow3.gif','','align=absmiddle') . '&nbsp;';
			$replace_array['VALUE_INFO_IMAGE']=tep_template_image('arrow3.gif','','align=absmiddle') . '&nbsp;';
			$replace_array['VALUE_FAG_IMAGE']=tep_template_image('arrow3.gif','','align=absmiddle') . '&nbsp;';
		
			switch($module_filename){
				case "featured_products.php":
				case 'upcoming_products.php':

					$customer_exists = '';
					if(tep_session_is_registered('customer_id'))
					$customer_exists = "OR(p.restrict_to_customers like '%," . $customer_id . ",%' OR p.restrict_to_groups like '%," . $customers_groups_id . ",%')";
					if ($module_filename=='featured_products.php'){
						$items_sql = "select p.products_id, pd.products_name, pd.products_description, p.products_image_1,p.products_title_1,p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, p.products_date_added, m.manufacturers_name,p.products_status from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id left join " . TABLE_FEATURED . " f on p.products_id = f.products_id and pd.language_id = '" . $languages_id . "' where p.products_status = '1' and f.status = '1' " . 
							" and (" . 
									"(p.restrict_to_customers = '' OR ISNULL(p.restrict_to_customers))" . 
									"and(p.restrict_to_groups = '' OR ISNULL(p.restrict_to_groups))" . $customer_exists . 
							") order by rand($mtm) limit 4";
						$items_query = tep_db_query($items_sql);
						$replace_array['VALUE_TITLE']=HEADING_FEATURED_PRODUCTS;
					} else {
						$items_sql = "select p.products_id, pd.products_description, pd.products_name, p.products_image_1, p.products_title_1, p.products_price, p.products_tax_class_id, p.products_date_added,  p.products_date_available as date_expected,p.products_status from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where products_date_available >'" . getServerDate() . "' and p.products_id = pd.products_id  and pd.language_id = '" . (int)$languages_id . "' " . 
							" and (" . 
									"(p.restrict_to_customers = '' OR ISNULL(p.restrict_to_customers))" . 
									"and(p.restrict_to_groups = '' OR ISNULL(p.restrict_to_groups))" . $customer_exists . 
							") order by rand() limit 4 ";
						$items_query = tep_db_query($items_sql);
						$replace_array['VALUE_TITLE']=HEADING_NEW_PRODUCTS;	
					}
					if (tep_db_num_rows($items_query)<=0) continue 2;
	
					$replace_array['VALUE_SEE_ALL']='<a href="'.tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT,'inc_product=1&inc_subcat_product=1&sort=1&page=1').'">'.HEADING_SEE_ALL.'</a>';
					
					$temp_items=array();
					while ($items_result = tep_db_fetch_array($items_query)) {
						if ($items_result['specials_new_products_price']) {
						$products_price = '<s>' .  $currencies->display_price($items_result['products_price'], tep_get_tax_rate($items_result['products_tax_class_id']),1,true) . '</s>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($items_result['specials_new_products_price'], tep_get_tax_rate($items_result['products_tax_class_id'])) . '</span>';
						} else {
						$products_price = $currencies->display_price($items_result['products_price'], tep_get_tax_rate($items_result['products_tax_class_id']),1,true);
						}
						$pstatus=$items_result['products_status'];
						
						$description=substr(strip_tags($items_result['products_description']),0,150);
						$temp_items[] = array(	'ID' => $items_result['products_id'],
											'NAME' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $items_result['products_id'], 'NONSSL') . '">' . $items_result['products_name'] . '</a>',
											'IMAGE' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $items_result['products_id'], 'NONSSL') . '">' . tep_product_small_image($items_result['products_image_1'],$items_result['products_title_1']) . '</a>',
											'PRICE' => $products_price,
											'DESCRIPTION' => $description
										);
					}
					$replace_array['VALUE_ITEM_IMAGE_WIDTH']=SMALL_IMAGE_WIDTH;
					$replace_array['REPEAT_ITEMS']=$temp_items;
					unset($temp_items);
					break;
				case 'faq.php':
					$faq_query = tep_db_query(
					'select p.faqdesk_id, pd.language_id, pd.faqdesk_question, pd.faqdesk_answer_long, pd.faqdesk_answer_short, pd.faqdesk_extra_url,
					p.faqdesk_image, p.faqdesk_date_added, p.faqdesk_last_modified,
					p.faqdesk_date_available, p.faqdesk_status  from ' . TABLE_FAQDESK . ' p, ' . TABLE_FAQDESK_DESCRIPTION . '
					pd WHERE pd.faqdesk_id = p.faqdesk_id and pd.language_id = "' . $languages_id . '" and faqdesk_status = 1 ORDER BY faqdesk_date_added DESC LIMIT 4');
										
					if (tep_db_num_rows($faq_query)<=0) continue 2;
					$replace_array['VALUE_TITLE']=HEADING_FAQ;
					while($faq_result=tep_db_fetch_array($faq_query)){
						$temp_items[]=array('NAME' => '<a href="' . tep_href_link(FILENAME_FAQDESK_INFO, 'faqdesk_id=' . $faq_result['faqdesk_id']) . '">' . $faq_result['faqdesk_question'] . '</a>','ID'=>$latest_news['faqdesk_id'],'date' => $faq_result['faqdesk_date_added']);
					}
	
					$replace_array['REPEAT_ITEMS']=$temp_items;
					unset($temp_items);
					break;
				case 'information.php':
					$info_query = tep_db_query("select md.page_name, md.page_id from " . TABLE_MAINPAGE . " m, " . TABLE_MAINPAGE_DESCRIPTIONS . " md where m.parent_id = '0' and m.page_id=md.page_id and m.page_status=1 and md.language_id='" . $languages_id ."' order by sort_order, md.page_name limit 4");
					if (tep_db_num_rows($info_query)<=0) continue 2;
					$replace_array['VALUE_TITLE']=HEADING_INFORMATION;
					while($info_result=tep_db_fetch_array($info_query)){
						$temp_items[]=array('NAME'=>'<a href="' . tep_href_link(FILENAME_DEFAULT,'stcPath=' . $info_result["page_id"]) . '">' . $info_result['page_name'] . '</a>');
					}
					$temp_items[]=array('NAME'=>'<a href="' . tep_href_link(FILENAME_CONTACT_US) . '">Contact us</a>');
					$replace_array['REPEAT_ITEMS']=$temp_items;
					unset($temp_items);
					break;
			}
			replace_content($content,$replace_array);
		} 
		if ($icnt%$MAINPAGE_COLS==0){
			if ($icnt>1) '</tr>';
			//echo'<tr><td class="products_bottom" colspan="2"></td></tr><tr height="10"></tr>';
			echo '<tr>';
		}
		if ($content!=''){
			echo '<td valign="top" class="rowOdd" height="140" width="' . $main_page_cols_width . '">' . $content . '</td>';
		} else { 
			@include(DIR_WS_MODULES . $module_filename);
		}
		$icnt++;
	}
	/*if ($icnt>1 && $icnt%$MAINPAGE_COLS!=0){
		while($icnt%$MAINPAGE_COLS!=0){
			echo '<td valign="top" height="140" width="' . $mainpag_cols_width . '">' . tep_draw_separator('pixel_trans.gif',100,1) . '</td>';
			$icnt++;
		}
		echo '</tr>';
	}*/
?>
     </table>
	   </td>
   </tr>
</table>
