<?php
/*
###################################################################################
  Bigware Shop 2.3
  Release Datum: 23.08.2015
  
  Bigware Shop
  http://www.bigware.de

  Copyright (c) 2015 Bigware LTD
  (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
  (c) 2015	Bigware LTD

  Copyrightvermerke duerfen nicht entfernt werden.
  ------------------------------------------------------------------------
  Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
  der GNU General Public License, wie von der Free Software Foundation
  veroeffentlicht, weitergeben und/oder modifizieren, entweder gemaess Version 2 
  der Lizenz oder (nach Ihrer Option) jeder spaeteren Version.
  Die Veroeffentlichung dieses Programms erfolgt in der Hoffnung, dass es Ihnen
  von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die
  implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FUER EINEN
  BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
  
  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
  Programm erhalten haben. Falls nicht, schreiben Sie an die Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

  Infos:
  ------------------------------------------------------------------------
  Der Bigware Shop wurde vor vielen Jahren bereits aus dem bekannten Shopsystem osCommerce
  weiter- und neuentwickelt.
  Der Bigware Shop legt im hohen Masse Wert auf Bedienerfreundlichkeit, beinhaltet eine leichte
  Installation, viele neue professionelle Werkzeuge und zeichnet sich aus durch eine grosse 
  Community, die bei Problemen weiterhelfen kann.
  
  Der Bigware Shop ist auf jedem System lauffaehig, welches eine PHP Umgebung
  (ab PHP 4.1.3) und mySQL zur Verfuegung stellt und auf Linux basiert.
 
  Hilfe erhalten Sie im Forum auf www.bigware.de 
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/
?>
<?php
require('load_this/load_this_bigware_10.php');
$date_availability = 'AND (to_days(items_date_available_end) IS NULL OR (to_days(items_date_available_end) IS NOT NULL AND to_days(now()) <= to_days(items_date_available_end)))';

$page_query = go_db_query("select pages_id, pages_title, pages_html_text, sort_order, status from " . DB_TBL_PAGES . " where status = 1 and pages_title = 'Index' ");
$page_check = go_db_fetch_array($page_query); 
$category_depth = 'top';
if (isset($bigPfad) && go_not_null($bigPfad)) {
	$categories_items_query = go_db_query("select count(*) as total from " . DB_TBL_ITEMS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
	$cateqories_items = go_db_fetch_array($categories_items_query);
	if ($cateqories_items['total'] > 0) {
		$category_depth = 'items'; 
	} else {
		$category_parent_query = go_db_query("select count(*) as total from " . DB_TBL_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
		$category_parent = go_db_fetch_array($category_parent_query);
		if ($category_parent['total'] > 0) {
			$category_depth = 'nested'; 
		} else {
			$category_depth = 'items'; 
		}
	}
}
require(FOLDER_RELATIV_LANGUAGES . $language . '/' . $GLOBALS['CONFIG_NAME_FILE']['main_bigware_29']);
if ($category_depth == 'nested') {
	$category_query = go_db_query("select cd.categories_name, c.categories_picture from " . DB_TBL_CATEGORIES . " c, " . DB_TBL_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$current_category_id . "' and cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'");
	$category = go_db_fetch_array($category_query);
	$content = $GLOBALS[CONFIG_SHOW_FILE][main_bigware_29_n];
} elseif ($category_depth == 'items' || isset($_GET['producers_id'])) { 
	$define_list = array('ITEM_LIST_MODEL' => ITEM_LIST_MODEL,
			'ITEM_LIST_NAME' => ITEM_LIST_NAME,
			'ITEM_LIST_PRODUCER' => ITEM_LIST_PRODUCER,
			'ITEM_LIST_PRICE' => ITEM_LIST_PRICE,
			'ITEM_LIST_QUANTITY' => ITEM_LIST_QUANTITY,
			'ITEM_LIST_WEIGHT' => ITEM_LIST_WEIGHT,
			'ITEM_LIST_PICTURE' => ITEM_LIST_PICTURE,
			'ITEM_LIST_INFO' => ITEM_LIST_INFO,
			'ITEM_LIST_BUY_NOW' => ITEM_LIST_BUY_NOW);
	asort($define_list);
	$column_list = array();
	reset($define_list);
	while (list($key, $value) = each($define_list)) {
		if ($value > 0) $column_list[] = $key;
	}
	$select_column_list = '';
	for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
		switch ($column_list[$i]) {
			case 'ITEM_LIST_MODEL':
				$select_column_list .= 'p.items_model, ';
				break;
			case 'ITEM_LIST_NAME':
				$select_column_list .= 'pd.items_name, pd.items_name2, ';
				break;
			case 'ITEM_LIST_PRODUCER':
				$select_column_list .= 'm.producers_name, ';
				break;
			case 'ITEM_LIST_QUANTITY':
				$select_column_list .= 'p.items_quantity, ';
				break;
			case 'ITEM_LIST_PICTURE':
				$select_column_list .= 'p.items_picture, ';
				break;
			case 'ITEM_LIST_WEIGHT':
				$select_column_list .= 'p.items_weight, ';
				break;
		}
	}

	$attendee_group_query = go_db_query("select attendees_group_id from " . DB_TBL_ATTENDEES . " where attendees_id =  '" . $attendee_id . "'");
	$attendee_group = go_db_fetch_array($attendee_group_query);

	if (isset($_GET['producers_id'])) {
		if (isset($_GET['filter_id']) && go_not_null($_GET['filter_id'])) {  
			$listing_sql = "select DISTINCTROW " . $select_column_list . " max(p.items_id), p.items_id, p.producers_id, p.items_price, p.items_tax_class_id, s.specials_new_items_price from (((" . DB_TBL_ITEMS . " p, " . DB_TBL_ITEMS_DESCRIPTION . " pd, " . DB_TBL_PRODUCERS . " m, " . DB_TBL_ITEMS_TO_CATEGORIES . " p2c) left join " . DB_TBL_SPECIALS . " s on p.items_id = s.items_id) left join " . DB_TBL_CATEGORIES . " c on p2c.categories_id = c.categories_id) where c.categories_status = '1' and p.items_status = '1' and p.producers_id = m.producers_id and m.producers_id = '" . (int)$_GET['producers_id'] . "' and p.items_id = p2c.items_id and pd.items_id = p2c.items_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$_GET['filter_id'] . "' $date_availability GROUP BY p.items_id";
		} else {  
			$listing_sql = "select DISTINCTROW " . $select_column_list . " max(p.items_id), p.items_id, p.producers_id, p.items_price, p.items_tax_class_id, s.specials_new_items_price from ((((" . DB_TBL_ITEMS . " p, " . DB_TBL_ITEMS_DESCRIPTION . " pd, " . DB_TBL_PRODUCERS . " m) left join " . DB_TBL_SPECIALS . " s on p.items_id = s.items_id) left join " . DB_TBL_ITEMS_TO_CATEGORIES . " p2c on p.items_id = p2c.items_id) left join " . DB_TBL_CATEGORIES . " c on p2c.categories_id = c.categories_id) where c.categories_status = '1' and p.items_status = '1' and pd.items_id = p.items_id and pd.language_id = '" . (int)$languages_id . "' and p.producers_id = m.producers_id and m.producers_id = '" . (int)$_GET['producers_id'] . "' $date_availability GROUP BY p.items_id"; 

		}
	} else { 
		if (isset($_GET['filter_id']) && go_not_null($_GET['filter_id'])) {  
			$listing_sql = "select DISTINCTROW " . $select_column_list . " p.items_id, p.producers_id, p.items_price, p.items_tax_class_id, s.specials_new_items_price from (((" . DB_TBL_ITEMS . " p, " . DB_TBL_ITEMS_DESCRIPTION . " pd, " . DB_TBL_PRODUCERS . " m, " . DB_TBL_ITEMS_TO_CATEGORIES . " p2c) left join " . DB_TBL_SPECIALS . " s on p.items_id = s.items_id) left join " . DB_TBL_CATEGORIES . " c on c.categories_id = p2c.categories_id) where c.categories_status = '1' and p.items_status = '1' and p.producers_id = m.producers_id and m.producers_id = '" . (int)$_GET['filter_id'] . "' and p.items_id = p2c.items_id and pd.items_id = p2c.items_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "' $date_availability ";
		} else {  
			$listing_sql = "select DISTINCTROW " . $select_column_list . " p.items_id, p.producers_id, p.items_price, p.items_tax_class_id, s.specials_new_items_price from ((((" . DB_TBL_ITEMS_DESCRIPTION . " pd, " . DB_TBL_ITEMS . " p) left join " . DB_TBL_PRODUCERS . " m on p.producers_id = m.producers_id, " . DB_TBL_ITEMS_TO_CATEGORIES . " p2c) left join " . DB_TBL_SPECIALS . " s on p.items_id = s.items_id) left join " . DB_TBL_CATEGORIES . " c on c.categories_id = p2c.categories_id) where c.categories_status = '1' and p.items_status = '1' and p.items_id = p2c.items_id and pd.items_id = p2c.items_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "' $date_availability ";
		}
	}
	if ( (!isset($_GET['sort'])) || (!preg_match('/[1-8][ad]/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
		for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
			if ($column_list[$i] == 'ITEM_LIST_NAME') {
				$_GET['sort'] = $i+1 . 'a';
				$listing_sql .= " order by p.items_sort,pd.items_name";
				break;
			}
		}
	} else {
		$sort_col = substr($_GET['sort'], 0 , 1);
		$sort_order = substr($_GET['sort'], 1);
		$listing_sql .= ' order by ';
		switch ($column_list[$sort_col-1]) {
			case 'ITEM_LIST_MODEL':
				$listing_sql .= "p.items_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.items_name";
				break;
			case 'ITEM_LIST_NAME':
				$listing_sql .= "p.items_sort,pd.items_name " . ($sort_order == 'd' ? 'desc' : '');
				break;
			case 'ITEM_LIST_PRODUCER':
				$listing_sql .= "m.producers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.items_name";
				break;
			case 'ITEM_LIST_QUANTITY':
				$listing_sql .= "p.items_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.items_name";
				break;
			case 'ITEM_LIST_PICTURE':
				$listing_sql .= "pd.items_name";
				break;
			case 'ITEM_LIST_WEIGHT':
				$listing_sql .= "p.items_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.items_name";
				break;
			case 'ITEM_LIST_PRICE':
				$listing_sql .= "items_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.items_name";
				break;
		}
	}
	$content = $GLOBALS['CONFIG_SHOW_FILE']['main_bigware_29_i'];
} else { 
	$content = $GLOBALS['CONFIG_SHOW_FILE']['main_bigware_29_d']; 
}
require(FOLDER_RELATIV_TEMPLATES . TEMPLATENAME_MAIN_PAGE);
require(FOLDER_RELATIV_INCLUDES . 'load_this_bigware_3.php');
?>
