<?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_header_shopping_cart {
    var $code = 'bm_add_header_shopping_cart';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;
    var $pages;	

    function bm_add_header_shopping_cart() {
      $this->title = MODULE_BOXES_CART_DROPDOWN_TITLE;
      $this->description = MODULE_BOXES_CART_DROPDOWN_DESCRIPTION;

      if ( defined('MODULE_BOXES_CART_DROPDOWN_STATUS') ) {
        $this->sort_order = MODULE_BOXES_CART_DROPDOWN_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_CART_DROPDOWN_STATUS == 'True');
        $this->pages = MODULE_BOXES_CART_DROPDOWN_DISPLAY_PAGES;
        $this->group = 'boxes_header';
      }
    }

    function execute() {
      global $oscTemplate, $cart, $count, $new_products_id_in_cart, $currencies;
				$image_width = MODULE_BOXES_CART_DROPDOWN_BOX_IMAGE_WIDTH;
				$image_height = MODULE_BOXES_CART_DROPDOWN_BOX_IMAGE_HEIGHT;
				if ($cart->count_contents() > 0) {
					if ($cart->count_contents() == 1 ){		   	
						$cart_header_string .= '<strong>'.$cart->count_contents().' '.MODULE_BOXES_CART_DROPDOWN_EMPTY.'</strong>';
					}else{
						$cart_header_string .= '<strong>'.$cart->count_contents().' '.MODULE_BOXES_CART_DROPDOWN_EMPTY_S.'</strong>';
					}
					$cart_contents_string .= '<ul id="submenu" class="submenu">';
					$products = $cart->get_products();
					for ($i=0, $n=sizeof($products); $i<$n; $i++) {
						$cart_contents_string .= '<li class="items">'.tep_image(DIR_WS_IMAGES. $products[$i]['image'], '', $image_width, $image_height, '') .'<div class="item">';
						$cart_contents_string .= '<h5 class="item1"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">';
						if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
							$cart_contents_string .= '<span class="newItemInCart">';
						}
						$cart_contents_string .= $products[$i]['name'];
					
						if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
							$cart_contents_string .= '</span>';
						}
						$cart_contents_string .= '</a></h5><span class="item2">';
						
						if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
							$cart_contents_string .= '<span class="newItemInCart">';
						}
						$cart_contents_string .= $products[$i]['quantity'] . '&nbsp;x&nbsp;'.$currencies->format($products[$i]['price']).' = '.$currencies->format(($products[$i]['quantity'] * $products[$i]['price']));
					
						if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
							$cart_contents_string .= '</span>';
						}
						$cart_contents_string .= '</span></div></li>';				 
					
						if ((tep_session_is_registered('new_products_id_in_cart')) && ($new_products_id_in_cart == $products[$i]['id'])) {
							tep_session_unregister('new_products_id_in_cart');
						}
					}
				$cart_contents_string .= '' .
																 '<li class="total"><span class="productSpecialPrice">' . $currencies->format($cart->show_total()) . '</span></li>' .
																 '<li>' .tep_draw_button2_top() . '<a href="'.tep_href_link(FILENAME_SHOPPING_CART).'"><span class="ui-button-text">'.MODULE_BOXES_CART_DROPDOWN_MYCART.'</span></a>' .tep_draw_button2_bottom() .  ' ' .tep_draw_button1_top() . '<a href="'.tep_href_link(FILENAME_CHECKOUT_SHIPPING).'"><span class="ui-button-text">'.MODULE_BOXES_CART_DROPDOWN_CHECKOUT.'</span></a>' .tep_draw_button1_bottom() . '</li>' .
																 '</ul>';
				 
				
				}else{
				$cart_header_string .= '<strong>0</strong>'.MODULE_BOXES_CART_DROPDOWN_EMPTY_S.''.
															 '<ul id="submenu" class="submenu">
															 		<li>'.MODULE_BOXES_CART_DROPDOWN_EMPTY_TEXT.'</li>
															 </ul>';
				}
		
      $data = "\n" .
			'<script type="text/javascript">
			$(document).ready(function() {
				$(\'div.cart_header_inner\').click(function () {
					$(\'#submenu\').slideToggle('.MODULE_BOXES_CART_DROPDOWN_BOX_TOOGLE.');
				});
			});
			</script>' . "\n" .
			'<div id="box_header_cart"><div class="cart_header_wrapper">' . "\n" .
			'					<div class="cart_header_inner">' . "\n" .
			'												<div class="title"><label>'.MODULE_BOXES_CART_DROPDOWN_BOX_TITLE.'</label>'.$cart_header_string.'</div>' . "\n" .
			'											 '.$cart_contents_string.' </div>' . "\n" .
			'</div></div>' . "\n" ;                                
     

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

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

    function check() {
      return defined('MODULE_BOXES_CART_DROPDOWN_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 Information Module', 'MODULE_BOXES_CART_DROPDOWN_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_CART_DROPDOWN_CONTENT_PLACEMENT', 'Header Block', 'Should the module be loaded in the Header Block?', '6', '1', 'tep_cfg_select_option(array(\'Header 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_CART_DROPDOWN_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_CART_DROPDOWN_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_CART_DROPDOWN_STATUS', 'MODULE_BOXES_CART_DROPDOWN_CONTENT_PLACEMENT', 'MODULE_BOXES_CART_DROPDOWN_SORT_ORDER','MODULE_BOXES_CART_DROPDOWN_DISPLAY_PAGES');
    }
  }
  
?>