<?php

	/**
	 * Template für die Produktübersichtsseite (Gitteransicht)
	 */ 

	/* Modus für das Vorschaubild */
	$bPicMode = 'c';

	/* Höhe und Breite für das Vorschaubild (CSS Layout muss entsprechend angepasst werden) */
	$nPicWidth = 140;
	$nPicHeight = 140;
	
	/* Wenn es auf false gesetzt wird, wird das erste Bild als Vorschaubild verwendet */
	$nPicRand = true;
	
	$col = 4;
	
?>

<?php

	remove_filter('the_content', array($GLOBALS['wpsg_sc'], 'content_filter'));
	the_content();
	add_filter('the_content', array($GLOBALS['wpsg_sc'], 'content_filter'));	
	
?>

<div class="wpsg_mod_productindex wpsg_mod_productindex_grid">
 
	<form method="get" id="wpsg_mod_productindex_form" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
 		
 		<?php parse_str($_SERVER['QUERY_STRING'], $arGET); if (wpsg_isSizedArray($arGET)) { foreach ($arGET as $key => $value) { if (!wpsg_isSizedArray($value)) { ?>
 		<input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>" />
 		<?php } } } ?>
 		
		<input type="hidden" id="wpsg_mod_productindex_filter_page" name="wpsg_mod_productindex[filter][page]" value="<?php echo $this->view['wpsg_mod_productindex']['filter']['page']; ?>" />
		<input type="hidden" id="wpsg_mod_productindex_filter_order" name="wpsg_mod_productindex[filter][order]" value="<?php echo $this->view['wpsg_mod_productindex']['filter']['order']; ?>" /> 
		<input type="hidden" id="wpsg_mod_productindex_template" name="wpsg_mod_productindex[template]" value="<?php echo $this->view['wpsg_mod_productindex']['template']; ?>" />
	
	</form>
	
	<div class="wpsg_mod_productindex_toolbar wpsg_mod_productindex_toolbar_top">
		
		<?php if ($this->view['hideOrder'] != '1') { ?>
		<div class="wpsg_mod_productindex_order">		
			<span><?php echo __('Sortierung:', 'wpsg'); ?></span>
			<select name="wpsg_mod_productindex[filter][order]" class="wpsg_mod_productindex_filter_order">
				<option value="price_asc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'price_asc')?'selected="selected"':''); ?>><?php echo __('Preis (Kleinster zuerst)', 'wpsg'); ?></option>
				<option value="price_desc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'price_desc')?'selected="selected"':''); ?>><?php echo __('Preis (Größter zuerst)', 'wpsg'); ?></option>
				<option value="name_asc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'name_asc')?'selected="selected"':''); ?>><?php echo __('Name Aufsteigend', 'wpsg'); ?></option>
				<option value="name_desc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'name_desc')?'selected="selected"':''); ?>><?php echo __('Name Absteigend', 'wpsg'); ?></option>
				<option value="cdate_asc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'cdate_asc')?'selected="selected"':''); ?>><?php echo __('Erstellungsdatum (Älteste zuerst)', 'wpsg'); ?></option>
				<option value="cdate_desc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'cdate_desc')?'selected="selected"':''); ?>><?php echo __('Erstellungsdatum (Neueste zuerst)', 'wpsg'); ?></option>
				<option value="anr_asc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'anr_asc')?'selected="selected"':''); ?>><?php echo __('Artikelnummer Aufsteigend', 'wpsg'); ?></option>
				<option value="anr_desc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'anr_desc')?'selected="selected"':''); ?>><?php echo __('Artikelnummer Absteigend', 'wpsg'); ?></option>
			</select>
		</div>
		<?php } ?>
		
		<?php if ($this->view['wpsg_mod_productindex']['filter']['pages'] > 1) { ?>
		<div class="wpsg_mod_productindex_pager">
			<span><?php echo __('Seite:', 'wpsg'); ?></span>
			<ul>
				<?php for ($i = 1; $i <= $this->view['wpsg_mod_productindex']['filter']['pages']; $i ++) { ?>
				<li>
					<?php if ($i == $this->view['wpsg_mod_productindex']['filter']['page']) { ?>
					<span><?php echo $i; ?></span>
					<?php } else { ?>
					<a title="<?php echo wpsg_translate(__('Zu Seite #1# wechseln', 'wpsg'), $i); ?>" href="#" onclick="return wpsg_mod_productindex_goPage(<?php echo $i; ?>);"><?php echo $i; ?></a>
					<?php } ?>
				</li>
				<?php } ?>
			</ul>
		</div>
		<?php } ?>
		
		<?php if ($this->view['hideViewSelect'] != '1') { ?>
		<div class="wpsg_mod_productindex_viewselect">
			<a href="#" onclick="return wpsg_mod_productindex_viewselect('list.phtml');" title="<?php echo __('Zur Listansicht wechseln.', 'wpsg'); ?>">
				<img src="<?php echo $this->getRessourceURL('mods/mod_productindex/gfx/icon_list.png'); ?>" alt="<?php echo __('Zur Listansicht wechseln.', 'wpsg'); ?>" />
			</a>
		</div>
		<?php } ?>
		
		<div class="wpsg_clear"></div>
		
	</div>

	<?php if (wpsg_isSizedArray($this->view['arProducts'])) { ?>
	
		<?php $i = 0; foreach ($this->view['arProducts'] as $p) { $i ++; ?>
		
			<?php if (($i - 1) % $col == 0) { ?><div class="wpsg_mod_productindex_productrow"><?php } ?>
		 
			<div class="wpsg_mod_productindex_product <?php echo (($i == sizeof($this->view['arProducts']))?'wpsg_mod_productindex_product_last':''); ?> <?php echo (($i == 1)?'wpsg_mod_productindex_product_first':''); ?>" style="width:<?php echo round((100 / $col), 2) ?>%;"> 
				<div class="wpsg_mod_productindex_product_inner">
					<?php if ($this->hasMod('wpsg_mod_produktbilder')) { $arBilder = $this->callMod('wpsg_mod_produktbilder', 'getProduktBilder', array($p['id'])); ?>
					<div class="wpsg_mod_productindex_pic">
						<?php if (wpsg_isSizedArray($arBilder)) { ?>
						<a title="<?php echo __('Zur Detailseite des Produkts', 'wpsg'); ?>" href="<?php echo wpsg_url($p['url']); ?>">
							<?php if ($nPicRand === true) $nPicIndex = array_rand($arBilder); else $nPicIndex = 0; ?> 
							<img src="<?php echo $this->callMod('wpsg_mod_produktbilder', 'makeTn', array($p['id'], $arBilder[$nPicIndex], $nPicWidth, $nPicHeight, $bPicMode)); ?>" alt="<?php wpsg_hspc($p['name']); ?>" />
						</a>
						<?php } ?>
					</div>
					<?php } ?>
					<div class="wpsg_mod_productindex_content">
						<div class="wpsg_mod_productindex_title">
							<a title="<?php echo __('Zur Detailseite des Produkts', 'wpsg'); ?>" href="<?php echo wpsg_url($p['url']); ?>"><?php echo $this->getProductName($this->getProduktID($p['id']), true); ?></a>
						</div> 
						<div class="wpsg_mod_productindex_infos"> 
							<div class="wpsg_mod_productindex_weight">
								<?php if ($this->hasMod('wpsg_mod_weight') && $this->get_option('wpsg_mod_weight_showProductindex') == '1') { ?>
								<?php if ($p['min_weight'] == $p['max_weight']) { ?>
								<?php echo wpsg_translate(__('Gewicht: #1#', 'wpsg'), wpsg_ff($p['weight'], $this->get_option('wpsg_mod_weight_unit'))); ?> 
								<?php } else { ?>
								<?php echo wpsg_translate(__('Gewicht: ab #1#', 'wpsg'), wpsg_ff($p['min_weight'], $this->get_option('wpsg_mod_weight_unit'))); ?>
								<?php } ?>
								<?php } ?>
							</div>
							
							<div class="wpsg_mod_productindex_fmenge">
								<?php if ($this->hasMod('wpsg_mod_fuellmenge') && $this->get_option('wpsg_mod_fuellmenge_showProductindex_fmenge') == '1') { ?>
								<?php echo wpsg_translate(__('Füllmenge: #1#', 'wpsg'), wpsg_ff($p['fmenge'], $p['feinheit'])); ?>
								<?php } ?>
							</div>					
							
							<div class="wpsg_mod_productindex_gpreis">
								<?php if ($this->hasMod('wpsg_mod_fuellmenge') && $this->get_option('wpsg_mod_fuellmenge_showProductindex_grundpreis') == '1') { ?>
								<?php echo wpsg_translate(__('Grundpreis: #1# / #2#', 'wpsg'), 
										wpsg_ff($p['fmenge_preis'], $this->get_option('wpsg_currency')),
										wpsg_ff($this->get_option('wpsg_mod_fuellmenge_bezug'), $p['feinheit'])
								); ?>
								<?php } ?>
							</div>	
						</div>			
																		
						<?php if ($this->hasMod('wpsg_mod_stock') && $this->get_option('wpsg_mod_stock_showProductindex') == '1') { ?>
							<div class="wpsg_mod_produktindex_stock">
								<?php echo wpsg_translate(__('Lagerbestand: #1#','wpsg'), $p['stock']);  ?>	
							</div>
						<?php } ?>
								
						<div class="wpsg_mod_productindex_price">
							<?php if ($p['min_preis'] == $p['max_preis']) { ?>
								<?php echo wpsg_ff($p['preis'], $this->get_option('wpsg_currency')); ?>
							<?php } else { ?>
								<?php echo wpsg_translate(__('ab #1#', 'wpsg'), wpsg_ff($p['min_preis'], $this->get_option('wpsg_currency'))); ?>
							<?php } ?>
						</div>
						<?php if ($this->get_option('wpsg_kleinunternehmer')) { /* Kleinunternehmerregelung aktiviert START */ ?>		
						<div class="wpsg_produkt_preishinweis">
							<?php echo wpsg_translate(__('#2# zzgl. #1#', 'wpsg'), '<a href="'.$this->getURL(wpsg_ShopController::URL_VERSANDKOSTEN).'">'.__('Versandkosten', 'wpsg').'</a>', '<a href="#kkhint" title="'.wpsg_hspc($this->get_option('wpsg_kleinunternehmer_text')).'">Endpreis</a>'); ?>
						</div>
						<?php } else { /* Kleinunternehmerregelung aktiviert ENDE */ ?>	
						<div class="wpsg_produkt_preishinweis">		
							<?php if ($this->getFrontendTaxview() == WPSG_NETTO) { /* Frontend = NETTO Preise */ ?>
							<?php echo wpsg_translate(__('(zzgl. #1#% MwSt. und zzgl. #2#)', 'wpsg'), wpsg_ff($p['mwst_value']), '<a href="'.$this->getURL(wpsg_ShopController::URL_VERSANDKOSTEN).'">'.__('Versandkosten', 'wpsg').'</a>'); ?>
							<?php } else { /* Frontend = BRUTTO Preise */ ?>
							<?php echo wpsg_translate(__('(inkl. #1#% MwSt. und zzgl. #2#)', 'wpsg'), wpsg_ff($p['mwst_value']), '<a href="'.$this->getURL(wpsg_ShopController::URL_VERSANDKOSTEN).'">'.__('Versandkosten', 'wpsg').'</a>'); ?>
							<?php } ?>
						</div>	
						<?php } ?>
																		
						<div class="wpsg_mod_productindex_button">
						
							<?php if ($this->hasMod('wpsg_mod_stock') && $this->callMod('wpsg_mod_stock', 'checkBestand', array($p['id'], 1)) === false) { ?>
							<span class="wpsg_produkt_soldout"><?php echo __('Produkt ausverkauft', 'wpsg'); ?></span>
							<?php } else { ?>						
							<a class="wpsg_button" title="<?php echo __('Zur Detailseite des Produkts', 'wpsg'); ?>" href="<?php echo wpsg_url($p['url']); ?>"><?php echo __('Zum Produkt', 'wpsg'); ?></a>
							<?php } ?>
							
						</div>
						
					</div>
					<div class="wpsg_clear"></div>
				</div>				
			</div> 
		
			<?php if (($i - 1) % $col == ($col - 1)) { ?><div class="wpsg_clear"></div></div><?php } ?>
		
		<?php } ?>
		
		<?php if (($i - 1) % $col != ($col - 1)) { ?><div class="wpsg_clear"></div></div><?php } ?>
	
	<?php } else { ?>
	<div class="wpsg_mod_productindex_empty"><?php echo __('Keine passenden Produkte gefunden.', 'wpsg'); ?></div>
	<?php } ?>
	
	<div class="wpsg_mod_productindex_toolbar wpsg_mod_productindex_toolbar_bottom">
		
		<?php if ($this->view['hideOrder'] != '1') { ?>
		<div class="wpsg_mod_productindex_order">
			<span><?php echo __('Sortierung:', 'wpsg'); ?></span>
			<select name="wpsg_mod_productindex[filter][order]" class="wpsg_mod_productindex_filter_order">
				<option value="price_asc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'price_asc')?'selected="selected"':''); ?>><?php echo __('Preis (Kleinster zuerst)', 'wpsg'); ?></option>
				<option value="price_desc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'price_desc')?'selected="selected"':''); ?>><?php echo __('Preis (Größter zuerst)', 'wpsg'); ?></option>
				<option value="name_asc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'name_asc')?'selected="selected"':''); ?>><?php echo __('Name Aufsteigend', 'wpsg'); ?></option>
				<option value="name_desc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'name_desc')?'selected="selected"':''); ?>><?php echo __('Name Absteigend', 'wpsg'); ?></option>
				<option value="cdate_asc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'cdate_asc')?'selected="selected"':''); ?>><?php echo __('Erstellungsdatum (Älteste zuerst)', 'wpsg'); ?></option>
				<option value="cdate_desc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'cdate_desc')?'selected="selected"':''); ?>><?php echo __('Erstellungsdatum (Neueste zuerst)', 'wpsg'); ?></option>
				<option value="anr_asc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'anr_asc')?'selected="selected"':''); ?>><?php echo __('Artikelnummer Aufsteigend', 'wpsg'); ?></option>
				<option value="anr_desc" <?php echo (($this->view['wpsg_mod_productindex']['filter']['order'] == 'anr_desc')?'selected="selected"':''); ?>><?php echo __('Artikelnummer Absteigend', 'wpsg'); ?></option>
			</select>
		</div>
		<?php } ?>
		
		<?php if ($this->view['wpsg_mod_productindex']['filter']['pages'] > 1) { ?>
		<div class="wpsg_mod_productindex_pager">
			<span><?php echo __('Seite:', 'wpsg'); ?></span>
			<ul>
				<?php for ($i = 1; $i <= $this->view['wpsg_mod_productindex']['filter']['pages']; $i ++) { ?>
				<li>
					<?php if ($i == $this->view['wpsg_mod_productindex']['filter']['page']) { ?>
					<span><?php echo $i; ?></span>
					<?php } else { ?>
					<a title="<?php echo wpsg_translate(__('Zu Seite #1# wechseln', 'wpsg'), $i); ?>" href="#" onclick="return wpsg_mod_productindex_goPage(<?php echo $i; ?>);"><?php echo $i; ?></a>
					<?php } ?>
				</li>
				<?php } ?>
			</ul>
		</div>
		<?php } ?>
		
		<?php if ($this->view['hideViewSelect'] != '1') { ?>
		<div class="wpsg_mod_productindex_viewselect">
			<a href="#" onclick="return wpsg_mod_productindex_viewselect('list.phtml');" title="<?php echo __('Zur Listansicht wechseln.', 'wpsg'); ?>">
				<img src="<?php echo $this->getRessourceURL('mods/mod_productindex/gfx/icon_list.png'); ?>" alt="<?php echo __('Zur Listansicht wechseln.', 'wpsg'); ?>" />
			</a>
		</div>
		<?php } ?>
		
		<div class="wpsg_clear"></div>
		
	</div>

	<?php if ($this->get_option('wpsg_kleinunternehmer')) { ?>
	<a name="kkhint"></a>
	<div class="wpsg_mod_productindex_kuhint"><?php echo $this->get_option('wpsg_kleinunternehmer_text'); ?></div>
	<?php } ?>

</div>

<script type="text/javascript">/* <![CDATA[ */

	function wpsg_mod_productindex_goPage(page)
	{

		jQuery('#wpsg_mod_productindex_filter_page').val(page);
		jQuery('#wpsg_mod_productindex_form').submit();

		return false;
		
	} // function wpsg_mod_productindex_goPage(page)

	function wpsg_mod_productindex_viewselect(template)
	{

		jQuery('#wpsg_mod_productindex_template').val(template);
		jQuery('#wpsg_mod_productindex_form').submit();

		return false;
		
	} // function wpsg_mod_productindex_viewselect(template)
	
	jQuery(document).ready(function() {

		jQuery('.wpsg_mod_productindex_filter_order').bind('change', function() {
			
			jQuery('#wpsg_mod_productindex_filter_order').val(jQuery(this).find('option:selected').attr('value'));
			jQuery('#wpsg_mod_productindex_filter_page').val('1');
			jQuery('#wpsg_mod_productindex_form').submit(); 
					
		} );
		
	} );

/* ]]> */</script>