<?php
/**
  @licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.0.9
  @date  20/05/10, 11:41
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/

Class child_cat {

  var $leflux;

  /**
    @param int cID passé en get
  */
  function child_cat(){
    global $page,$languages_id,$currencies;

    if(!isset($_GET['cID'])) return false;
    $this->current_category_id=(int)$_GET['cID'];

    //! Recup des element cat en cours
      $category_query = tep_db_query($sql="select cd.categories_name,cd.categories_description, c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . $this->current_category_id . "' and cd.categories_id = '" . $this->current_category_id . "' and c.categories_status='1'  and cd.language_id = '" . (int)$languages_id . "'");
      $categories = tep_db_fetch_array($category_query);
//       if($current_category_id !=0 && tep_db_num_rows($category_query) ==0) $category_depth='nofound' ;
      tep_db_free_result($category_query);


    $this->title=sprintf(CL_TITLE_FEEDS, $categories['categories_name']);
    $this->description=htmlspecialchars(sprintf(CL_DESC_FEEDS, $categories['categories_name']).";  \n".$categories['categories_description']);
    $this->link=tep_href_link(FILENAME_DEFAULT);

    $this->leflux=array();
  }


  /**
    Calcul des enfants de la cat en cours, produist et page de cms
  */
  function feed(){

    global $page,$languages_id,$currencies;

    $listing_sql = " select distinct p.*, pd.products_name from  ".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 pd.language_id = '" . (int)$languages_id . "' and  p2c.categories_id = '" . $this->current_category_id . "' ";

    $query = tep_db_query($listing_sql);

    while($ele = tep_db_fetch_array($query)) {

      $whats_new_price =  $currencies->display_price($ele['products_price'], tep_get_tax_rate($ele['products_tax_class_id']));
      $ele['specials_new_products_price'] = tep_get_products_special_price($ele['products_id']);

      if ($ele['specials_new_products_price']) $whats_new_price_special = $currencies->display_price($ele['specials_new_products_price'], tep_get_tax_rate($ele['products_tax_class_id']));

      $list['title']=htmlspecialchars($ele['products_name']) ;
      $list['link']=tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $ele['products_id'], 'NONSSL') ;
      $list['image']=htmlspecialchars(tep_image(DIR_WS_IMAGES . $ele['products_image'], $ele['products_name'], $page->_conf_value('SMALL_IMAGE_WIDTH'), $page->_conf_value('SMALL_IMAGE_HEIGHT')));
      $list['description']=htmlspecialchars($ele['products_description']);

      $this->leflux[]=new objectInfo($list);
    }


    $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)$languages_id . "' and cat.categories_id = '" . $this->current_category_id . "'";

    $query = tep_db_query($listing_sql);


    while($ele = tep_db_fetch_array($query)) {
      $list['title']=htmlspecialchars($ele['content_title']) ;
      $list['link']=tep_href_link(FILENAME_PRODUCT_INFO, 'content_id=' . $ele['content_id'], 'NONSSL') ;
      $list['description']=htmlspecialchars($ele['content_text']);

      $this->leflux[]=new objectInfo($list);
    }


    return $this->leflux;
  }

}
?>