<?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.1.0
  @date  16/09/10, 22:19
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/

if(!function_exists('sql_listing_cat')) {
  function sql_listing_cat(){
  global $page;

  $languages_id=$page->the_var('languages_id');
  $cPath=$page->the_var('cPath');
  $category_links=$page->the_var('cPath_array');
  $current_category_id=$page->the_var('current_category_id');
  $currencies=$page->currencies;
  if (tep_not_null($cPath) ) {
// check to see if there are deeper categories within the current category
    $category_links = array_reverse($category_links);
      for($i=0, $n=sizeof($category_links); $i<$n; $i++) {
        $categories_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
        $categories = tep_db_fetch_array($categories_query);
        if ($categories['total'] < 1) {
          // do nothing, go through the loop
        } else {
            $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and c.categories_status='1' and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
            break; // we've found the deepest category the customer is in
        }
      }
    } else {
      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and c.categories_status='1' and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
    }

    if (tep_db_num_rows($categories_query) > 0) return $categories_query;
    else return false;
  }
}



/**
  Prepa et passage en object du module, affichage au seins boxe des modules
*/
function in_obj_listing_cat(){
  global $page;
  $languages_id=$page->the_var('languages_id');
  $currencies=$page->return_object('currencies');
  $mod=$page->oscss_modules->_return('product_listing');
  /** init aca module */
  $aca_listing=$page->new_class('listing');
  $p=array();
  if( ($res=$page->oscss_modules->_resultsql('listing_cat')) ==false ) return null;
  while ($ele_db = tep_db_fetch_array($res)){
    $p[]=new objectInfo(array_merge($ele_db,array('cPath'=>tep_get_path($ele_db['categories_id'])) ) );
  }

  return new objectInfo(array('title'=>HEADING_CHILD_CAT, 'content'=>$p ));

}


?>