<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  class bm_add_brands {
    var $code = 'bm_add_brands';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;
    var $pages;	

    function bm_add_brands() {
      $this->title = MODULE_BOXES_BRANDS_TITLE;
      $this->description = MODULE_BOXES_BRANDS_DESCRIPTION;

      if ( defined('MODULE_BOXES_BRANDS_STATUS') ) {
        $this->sort_order = MODULE_BOXES_BRANDS_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_BRANDS_STATUS == 'True');
        $this->pages = MODULE_BOXES_BRANDS_DISPLAY_PAGES;
				if	(MODULE_BOXES_BRANDS_CONTENT_PLACEMENT == 'Under Header Block')	{
					$this->group = 'boxes_under_header';
				}
				if	(MODULE_BOXES_BRANDS_CONTENT_PLACEMENT == 'Above Footer Block')	{
					$this->group = 'boxes_above_footer';
				}	
				if	(MODULE_BOXES_BRANDS_CONTENT_PLACEMENT == 'Content Block Top')	{
					$this->group = 'boxes_content_top';
				}
				if	(MODULE_BOXES_BRANDS_CONTENT_PLACEMENT == 'Content Block Bottom')	{
					$this->group = 'boxes_content_bottom';
				}				
      }
    }

    function getData() {
      global $HTTP_GET_VARS, $oscTemplate;
//if (isset($HTTP_GET_VARS['manufacturers_id'])) {
      $data = '';
     $manufacturers_query = tep_db_query("select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, COUNT(*) as total from " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS . " p where m.manufacturers_id = p.manufacturers_id GROUP BY manufacturers_id order by manufacturers_name");	
		$image_width = MODULE_BOXES_BRANDS_IMAGE_WIDTH;
		$image_height = MODULE_BOXES_BRANDS_IMAGE_HEIGHT;
      if ($number_of_rows = tep_db_num_rows($manufacturers_query)) {
// Display a list
		  $extra = 'list';
          $manufacturers_list = ''."\n";
          while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
            $manufacturers_list .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '">' . tep_image(DIR_WS_IMAGES . $manufacturers['manufacturers_image'], $manufacturers['manufacturers_image'], $image_width, $image_height, '') . '</a>';
          }
          $manufacturers_list .= ''."\n";
} 				
          $data = '' . "\n" .
'<script type="text/javascript">
	$(document).ready(function(){
		$("#foo1").carouFredSel({
			circular: '.JCL_CIRCULAR.',
			mousewheel: '.JCL_MOUSEWHEEL.',
			infinite: false,
			width : "100%",
			auto 	: '.JCL_AUTO.',
			prev	: {	
				button	: "#foo1_prev",
				key		: "left"
			},
			next	: { 
				button	: "#foo1_next",
				key		: "right"
			}
		});
	});
</script>
' . "\n" .
'									<div class="brands_wrapper"><div id="foo1">' . "\n" .
'												' . $manufacturers_list.' ' . "\n".
'									</div><div class="clearfix"></div>' . "\n" .
'									<a class="prev" id="foo1_prev" href="#"><span>prev</span></a>
									<a class="next" id="foo1_next" href="#"><span>next</span></a>
									</div>' . "\n";

      return $data;
    }

    function execute() {
      global $SID, $oscTemplate;
      if ((USE_CACHE == 'true') && empty($SID)) {
        $output = tep_cache_manufacturers_box();
      } else {
        $output = $this->getData();
      }

      $oscTemplate->addBlock($output, $this->group);
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_BOXES_BRANDS_STATUS');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Manufacturers Module', 'MODULE_BOXES_BRANDS_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_BRANDS_CONTENT_PLACEMENT', 'Content Block Bottom', 'Should the module be loaded in the Content Block Top, Content Block Bottom, Under Header Block, or Above Footer Block?', '6', '1', 'tep_cfg_select_option(array(\'Content Block Top\', \'Content Block Bottom\', \'Under Header Block\', \'Above Footer Block\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_BRANDS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display in pages.', 'MODULE_BOXES_BRANDS_SORT_DISPLAY_PAGES', 'all', 'select pages where this box should be displayed. ', '6', '0','tep_cfg_select_pages(' , now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_BOXES_BRANDS_STATUS', 'MODULE_BOXES_BRANDS_CONTENT_PLACEMENT', 'MODULE_BOXES_BRANDS_SORT_ORDER','MODULE_BOXES_BRANDS_DISPLAY_PAGES');
    }
  }
?>
