<?php
/*
  $Id$

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

  Copyright (c) 2011 osCommerce

  Released under the GNU General Public License
*/

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

    function bm_add_bannershow() {
      $this->title = MODULE_BOXES_BANNERSHOW_TITLE;
      $this->description = MODULE_BOXES_BANNERSHOW_DESCRIPTION;
      $this->box_title = MODULE_BOXES_BANNERSHOW_BOX_TITLE;

      if ( defined('MODULE_BOXES_BANNERSHOW_STATUS') ) {
        $this->sort_order = MODULE_BOXES_BANNERSHOW_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_BANNERSHOW_STATUS == 'True');
        $this->pages = MODULE_BOXES_BANNERSHOW_DISPLAY_PAGES;
				if	(MODULE_BOXES_BANNERSHOW_CONTENT_PLACEMENT == 'Left Column')	{
					$this->group = 'boxes_column_left';
				}
				if	(MODULE_BOXES_BANNERSHOW_CONTENT_PLACEMENT == 'Right Column')	{
					$this->group = 'boxes_column_right';
				}
				if	(MODULE_BOXES_BANNERSHOW_CONTENT_PLACEMENT == 'Under Header Block')	{
					$this->group = 'boxes_under_header';
				}
				if	(MODULE_BOXES_BANNERSHOW_CONTENT_PLACEMENT == 'Above Footer Block')	{
					$this->group = 'boxes_above_footer';
				}	
				if	(MODULE_BOXES_BANNERSHOW_CONTENT_PLACEMENT == 'Content Block Top')	{
					$this->group = 'boxes_content_top';
				}
				if	(MODULE_BOXES_BANNERSHOW_CONTENT_PLACEMENT == 'Content Block Bottom')	{
					$this->group = 'boxes_content_bottom';
				}				
      }
    }
	
    function execute() {
	  global $oscTemplate;
	  $data = '';
	  $execute = false;
	  $grid = ((LAYOUT_TYPE == 'Responsive Layout') ? 'span' : 'grid_');
	  $contentWidth = $oscTemplate->getGridContentWidth();
	  $contentWidth_value = ((LAYOUT_TYPE == 'Responsive Layout') ? 4 : 8);	  
	// select slideshow_banners_group to be used
	  $new_slideshow_banner_search = osc_build_slideshow_banners_group(BANNERSHOW);
	  $sql = "select slideshow_banners_id from " . TABLE_SLIDER_BANNERS . " where status = 1 " . $new_slideshow_banner_search; // " order by slideshow_banners_sort_order";
	  $slideshow_banners_query = tep_db_query($sql);
	// if no active banner in the specified banner group then the box will not show
	  $slideshow_banner_cnt = 0;
	  while ($slideshow_banners_all = tep_db_fetch_array($slideshow_banners_query)) {
		$slideshow_banner_cnt++;
		$banner = tep_slideshow_banner_exists('dynamic', BANNERSHOW);
		$data1 .= '<li class="item-'.$slideshow_banner_cnt.' '.$grid.$contentWidth_value.'">'.tep_display_bannershow_banner('static', $slideshow_banners_all['slideshow_banners_id']).'</li>';
		$execute = true;		
	  }
	   $data .= '<div class="banner_set"><ul>'.$data1.'</ul></div>';
	  	  
	  if($execute){
      	$oscTemplate->addBlock($data, $this->group);
	  }
    }

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

    function check() {
      return defined('MODULE_BOXES_BANNERSHOW_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 Content Coin Slider Module', 'MODULE_BOXES_BANNERSHOW_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_BANNERSHOW_CONTENT_PLACEMENT', 'Under Header Block', 'Should the module be loaded in the Left Column, Right Column, Content Block Top, Content Block Bottom, Under Header Block, or Above Footer Block?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\',\'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_BANNERSHOW_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_BANNERSHOW_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_BANNERSHOW_STATUS', 'MODULE_BOXES_BANNERSHOW_CONTENT_PLACEMENT', 'MODULE_BOXES_BANNERSHOW_SORT_ORDER', 'MODULE_BOXES_BANNERSHOW_DISPLAY_PAGES');
    }
  }
  
?>