<?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  16/06/10, 10:52
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/

/**
  SQL
  @package oscss-2 <www http://www.oscss.org>
  @author oscim <mail oscim@oscss.org> <www http://www.oscim.fr>
*/
function sql_upcoming_products(){
  global $new_products_category_id;

  $page=page::getInstance();
  $DB=Database::getInstance();
  $languages_id=$page->the_var('languages_id');

  $expected_query = $DB->query($sql="select distinct p.products_id, pd.products_name,p.products_image, products_price,products_tax_class_id,products_quantity, products_date_available as date_expected, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_products_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id,  " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where to_days(products_date_available) >= to_days(now()) and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p.products_id = pd.products_id and p.products_status='1' and c.categories_status = '1' and  pd.language_id = '" . (int)$languages_id . "' order by " . $page->_conf_value('EXPECTED_PRODUCTS_FIELD') . " " . $page->_conf_value('EXPECTED_PRODUCTS_SORT'). " limit " . $page->_conf_value('MAX_DISPLAY_UPCOMING_PRODUCTS'));

  if ($expected_query->__get('NumRows') > 0) return $expected_query;
  else return false;
}


/**
  Prepa et passage en object du module, affichage au seins boxe des modules
  @package oscss-2 <www http://www.oscss.org>
  @author oscim <mail oscim@oscss.org> <www httP://www.oscim.fr>
*/
function in_obj_upcoming_products(){

  $page=page::getInstance();
  $p=array();
  /** init aca module */
  $aca_listing=$page->new_class('listing');

  if( ($res=$page->oscss_modules->_resultsql('upcoming_products')) ==false ) return null;
  while ($new_products = $res->fetchAssoc() ){
    $pd=product::get_item($new_products['products_id']);
    $pd->aca=$aca_listing->return_db_min($new_products['products_id']);
    $p[]=$pd;
  }

  return new objectInfo(array('title'=>__('table heading upcoming products'), 'content'=>$p ));

}

?>