<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.0.9
  @date  11/09/10, 10:53
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/
class cat_home
    implements InterfaceModule {

  /**
    Id cat home
  */
  const CAT_HOME_ID = 3;
  /**
    Cesure nbr carat dans les cms
  */
  const CMS_CESURE = 50;

  public $code;
  public $title;
  public $description;
  public $sort_order;
  public $enabled;

  public static $list;

  function __construct() {
    $this->code =__CLASS__;
    $this->title = __('module cat_home text title');
    $this->description =  __('module cat_home text description') ;
    $this->sort_order = (defined('MODULE_HOME_FEATURED_SORT_ORDER')) ? MODULE_HOME_FEATURED_SORT_ORDER : 0 ;
    $this->enabled = true;

    global $page;
    if(!is_object($page)) return false;
    $this->language = $page->the_var('language');
    $this->languages_id = $page->the_var('languages_id');



  }

 /**
    Object db _value
  */
  public function obj_db_values(){
    $res=$this->load_db_values();
    while ($featured_products = tep_db_fetch_array($res))  $re[]=new objectInfo($featured_products);
    if(is_array($re)) return $re;
    else return array();
  }


  /**
  */
  public function load_db_values($_id=''){
    global $page;
    $DB=Database::getInstance();

    $listing_sql = " select distinct p.*, pd.products_name, pd.products_chapo from  " . TABLE_CATEGORIES . " cat,".TABLE_V_PRODUCTS." p   LEFT JOIN  " . TABLE_PRODUCTS_DESCRIPTION . " pd on pd.products_id = p.products_id LEFT JOIN   " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c on p2c.products_id= p.products_id where cat.categories_id=p2c.categories_id and cat.categories_status='1'and pd.language_id = '" . (int)$this->languages_id . "' and  p2c.categories_id = '" . (int)self::CAT_HOME_ID . "' order by products_date_added limit 5";
    $pr=$DB->query($listing_sql);
    $product=$pr->fetchAllAssoc();

    $listing_sql = "select  c.content_id,ctc.categories_id, content_name,content_title,content_text, c.date_added, c.last_modified, content_status, ctc.categories_id   from " . TABLE_CONTENT_DESCRIPTION . " cd, " . TABLE_CONTENT . " c,   " . TABLE_CONTENT_TO_CATEGORIES . " ctc, " . TABLE_CATEGORIES . " cat where cat.categories_id=ctc.categories_id and cat.categories_status='1' and c.content_status = '1' and c.content_id = ctc.content_id and cd.content_id = ctc.content_id and cd.language_id = '" . (int)$this->languages_id . "' and cat.categories_id = '" . (int)self::CAT_HOME_ID . "' order by date_added  limit 5";
    $ct=$DB->query($listing_sql);
    $content=$ct->fetchAllAssoc();

// print_r($content);
    foreach($product as $item)
      $res[]=new objectInfo($item);

    foreach($content as $item){
// print_r($item);
//       if( ($s=strpos($item['content_text'],'<!-- pagebreak -->')) >0 ) $item['content_text']=substr($item['content_text'], 0, $s-self::CMS_CESURE );
      $res[]=new objectInfo($item);
    }
    srand(time());
    shuffle($res);

    self::$list= $res;
  }

/*
  Function ACA option
*/
  /**

    @param
      @a int l'ID de la categorie en cours
  */
  public function display_view($categorie_id=''){
    $this->load_db_values();
    $v['title']=__('heading cat_home text title');
    $v['content']=tep_output_string_protected(tep_get_include_contents(__CLASS__.'.'.__FUNCTION__), false, true);
    return new objectInfo($v);
  }




/** implements InterfaceModule depend */
  public function check() {
  }

  public function install() {
  }

  public  function remove() {
  }

  public  function keys() {
    return array( );
  }

}

?>