<?php
/**
 * 
 * @file inc_laodtpl.php
 * @copyright (c) 2005 - 2007 eifr.com
 * @license http://www.gnu.org/copyleft/gpl.html gnu/gpl
 * eifr is free software
 */
 
$layout_array = array();
$layout_title_array = array();
$layout_id_array = array();
$layout_sql_array = array();
$layout_ad_array = array();
$layout_link_array = array();

if (!isset($template_array) || ! $template_array) {
    if (!isset($programe_file)) {
        $programe_file = basename($_SERVER['PHP_SELF']);
    }
    
    if ($is_preview && kGet('tpl_file') != '') {
        $tpl_file = kGet('tpl_file');
    }
    if (!isset($tpl_file)) {
        $tpl_file = basename($_SERVER['PHP_SELF'], '.php');
    }

    $template_array = getTemplate($programe_file, $tpl_file);
} 

if ($template_array) {
    $layout_array = getTemplateLayoutArray($template_array['id']);
    $tpl_file = $template_array['template_filename'];
} else {
    goErrorPage($lang['tpl_inexistence']);
}

foreach($layout_array as $row) {
    $layout_title_array[$row['layout_code']] = $row['title'];
    $layout_id_array[$row['layout_code']] = $row['id']; 
    // $layout_sql_array[$row['layout_code']] = $row['sql_select'];
    $layout_sql_array[$row['layout_code']] = evalSql($row['sql_select']);
    if ($row['type'] == 1) {
        $layout_ad_array[$row['layout_code']] = getAdvertisement($row['id']);
    } 
    if ($row['type'] == 2) {
        $layout_link_array[$row['layout_code']] = getLink($row['id']);
    } 
} 

require_once(getTemplatePath($tpl_file));
?>