<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/*
* Special Products Module
*
* @version $Id: mod_phpshop_featureprod.php,v 1.6 2004/12/06 21:08:08 soeren_nb Exp $
* @package Mambo_4.5.1
* @subpackage mambo-phpShop
*
* 	@copyright (C) 2000 - 2004 Mr PHP
// W: www.mrphp.com.au
// E: info@mrphp.com.au
// P: +61 418 436 690
* Conversion to Mambo and the rest:
* 	@copyright (C) 2004 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
*/ 
global $mosConfig_absolute_path;

/* Load the phpshop main parse code */
require_once( $mosConfig_absolute_path.'/components/com_phpshop/phpshop_parser.php' );

//maximum number of items to display
$max_items = $params->get( 'max_items', 2 );
$category_id = $params->get( 'category_id', null );

require_once ( CLASSPATH. 'ps_product.php');
$ps_product = new ps_product;
$db = new ps_DB;

if ( $category_id ) {
  $q  = "SELECT DISTINCT product_sku FROM #__pshop_product, #__pshop_product_category_xref, #__pshop_category WHERE ";
  $q .= "(#__pshop_product.product_parent_id='' OR #__pshop_product.product_parent_id='0') ";
  $q .= "AND #__pshop_product.product_id=#__pshop_product_category_xref.product_id ";
  $q .= "AND #__pshop_category.category_id=#__pshop_product_category_xref.category_id ";
  $q .= "AND #__pshop_category.category_id='$category_id'";
  $q .= "AND #__pshop_product.product_publish='Y' ";
  $q .= "AND #__pshop_product.product_special='Y' ";
  $q .= "ORDER BY product_name ASC LIMIT 0, $max_items";
}
else {
  $q  = "SELECT DISTINCT product_sku FROM #__pshop_product WHERE ";
  $q .= "product_parent_id='' AND vendor_id='".$_SESSION['ps_vendor_id']."' ";
  $q .= "AND #__pshop_product.product_publish='Y' ";
  $q .= "AND #__pshop_product.product_special='Y' ";
  $q .= "ORDER BY product_name ASC LIMIT 0, $max_items";
}
$db->query($q);
$i = 1;

?>
<table border="0" cellpadding="0" cellspacing="0" width="100%"><?php
    while($db->next_record()){
      if ($i++ % 2)
        $class="sectiontableentry1";
      else
        $class="sectiontableentry2";
      ?>
      <tr align="center" class="<?php echo $class ?>">
        <td><br />
        <?php
          $ps_product->show_snapshot($db->f("product_sku"));
        ?>
        </td>
      </tr>
      <?php
    }
  ?>
</table>
