<?php // BEGIN PHP
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/categories.lib.php';

$tag = GETPOST('tag', 'alpha');
$cat_id = GETPOST('cat', 'alpha');
$cat_extid = GETPOST('extcat', 'alpha');
$search = GETPOST('search_query', 'alpha');

$isHomePage = !GETPOST('tag', 'alpha') && !GETPOST('cat', 'alpha') && !GETPOST('list', 'alpha') && !GETPOST('search_query', 'alpha') && !GETPOST('extcat', 'alpha');

// END PHP 
?>
<div id="page">
  <div class="header-container">
    <?php includeContainer('header'); ?>
  </div>
  <div class="columns-container">
    <div id="columns" class="container">
      <?php includeContainer('breadcrumb'); ?>
      <div id="slider_row" class="row">
        <div id="top_column" class="center_column col-xs-12 col-sm-12"></div>
      </div>
      <div class="row">
        <!-- include left sidebar container -->
        <?php includeContainer('sidebar', 0, 0); 
        
        // TODO Use includeContainer('sidebar', 0, 60) mais mettre le js dynamic ici.
        ?>

        <div id="center_column" class="center_column col-xs-12 col-sm-9">
          <div class="clearfix divhomepage">
            
            <!-- To remove later -->
            <?php if (!empty(getDolGlobalInt("MARKETPLACE_IN_MIGRATION"))) : ?>
                <div style="color: red; font-weight: bold; font-size: 1.2em;"><br>
                [EN] This site is currently under maintenance. Please do not create account, submit, edit or buy modules yet.<br>
                [FR] Ce site est toujours en maintenance. Merci de ne pas creer de compte, soumettre, éditer ou acheter des modules.<br>
                <br><br>
                </div>
            <?php endif ?>
            <!-- To remove later -->

            <!-- include welcome message -->
            <?php
                $__PAGE__TITLE__ = $weblangs->trans("indexPageTitle");
                $__PAGE__KEYWORDS__ = $weblangs->trans("indexPageKeywords");
                $__PAGE__DESC__ = $weblangs->trans("indexPageDescription");
                
                if ($isHomePage) {
                    $current_lang = $_SESSION['lang']['shortcode'];
                    
                    if ($current_lang == 'fr') {
                        $welcomecontainer = 'message-de-bienvenue';
                    } elseif ($current_lang == 'es') {
                        $welcomecontainer = 'mensaje-de-bienvenida';
                    } elseif ($current_lang == 'it') {
                        $welcomecontainer = 'messaggio-di-benvenuto';
                    } elseif ($current_lang == 'de') {
                        $welcomecontainer = 'willkommensnachricht ';
                    } else {
                        $welcomecontainer = 'welcome-message';
                    }
                    /*
                    $welcome_message = $websitepage->fetchAll($website->id, '', '', 0, 1, array('pageurl' => 'welcome-message', 'status' => '1', 'lang' => $website->lang));
                    if ($website->lang == $current_lang) {
                        includeContainer($welcome_message[key($welcome_message)]->pageurl);
                    } else {
                        $trans_welcome_message = $websitepage->fetchAll($website->id, '', '', 0, 1, array('fk_page' => $welcome_message[key($welcome_message)]->id, 'status' => '1', 'lang' => $current_lang));
                        includeContainer($trans_welcome_message[key($trans_welcome_message)]->pageurl);
                    }*/
                    includeContainer($welcomecontainer);
                } else {
                    // Define SEO meta tags
                    $root_cat_object = new Categorie($db);
                    if (!empty($cat_extid)) {
                        $result = $root_cat_object->fetch('', '', Categorie::TYPE_PRODUCT, $cat_extid);
            	    } 
            	    if (!empty($cat_id)) {
            	        $result = $root_cat_object->fetch($cat_id,"");
            	    }

        	        $__PAGE__TITLE__ = $root_cat_object->label;
                    $__PAGE__DESC__ = $root_cat_object->description;
                    
                    if (!empty($tag) || !empty($search)) {
                        $__PAGE__TITLE__ = $weblangs->trans("search");
                    }

                }
                ?>
            <!-- include product container -->
            <?php includeContainer('products-list-grid'); ?>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- .columns-container -->
  <div class="footer-container">
    <?php includeContainer('footer'); ?>
  </div>
</div>