<?php
error_reporting(E_ALL ^ E_DEPRECATED); ini_set('display_errors', 1);
session_start();
include('script/variablen.php');
include('connect.php');

if ( !is_numeric($_GET['marke']) )
{
	header("Location: http://www.fuxtools.ch/404.php");
	exit;
}

$marke = intval($_GET['marke']);
$result_marke = mysqli_query($dbi,"SELECT marke, www, url, rubrik, text, bildname, bild_w_1, bild_h_1, bildtitel FROM marken WHERE nummer='$marke' AND aktiv='1'");
$row_marke = $result_marke->fetch_assoc();

if ( mysqli_num_rows($result_marke) == 0 )
{
	header("Location: http://www.fuxtools.ch/404.php");
	exit;
}

$top = '';
$set = '';
$banner = '';

if ( $marke == '1' ) { include("marken/makita.php"); }
if ( $marke == '2' ) { include("marken/bosch.php"); }
if ( $marke == '5' ) { include("marken/flex.php"); }
if ( $marke == '6' ) { include("marken/collomix.php"); }
if ( $marke == '8' ) { include("marken/hikoki.php"); }
if ( $marke == '10' ) { include("marken/metabo.php"); }
if ( $marke == '14' ) { include("marken/panasonic.php"); }
if ( $marke == '15' ) { include("marken/technocraft.php"); }
if ( $marke == '28' ) { include("marken/jet_holz.php"); }
if ( $marke == '31' ) { include("marken/jet_handwerkzeug.php"); }
if ( $marke == '34' ) { include("marken/profit.php"); }
if ( $marke == '42' ) { include("marken/eibenstock.php"); }
if ( $marke == '45' ) { include("marken/amb.php"); }
if ( $marke == '50' ) { include("marken/milwaukee.php"); }
if ( $marke == '60' ) { include("marken/mafell.php"); }
?>
<!DOCTYPE html>
<html lang="de-CH">
<head>

<?php
// Wenn über www.fuxtools.ch aufgerufen
if ( empty($head) )
{
include('page_meta.php');

echo '	<title>Verkauf ';

if ( $row_marke['rubrik'] == 2 )
{
	echo 'Werkzeuge';
}
else
{
	echo 'Maschinen';	
}
echo ' '.$row_marke['marke'].' - Fux Elektrowerkzeuge GmbH, Rümlingen</title>'."\n";
}
else
{
echo $head;
}
?>

<?php include('page_css.php'); ?>

<?php include('page_script_top.php'); ?>

</head>

<?php
// WENN Cookie Admin aktiv
if ( !empty($_COOKIE["administrator"]) == 1 )
{
	echo '<body class="admin">'."\n";
}
else
{
	echo '<body oncontextmenu="return false">'."\n";
}

include('page_header.php'); ?>

<div id="content">

<section>

	<div class="titel_flex">
	<h1 class="flex">Verkauf Maschinen <? echo $row_marke['marke'] ?></h1>
<?php
echo '<div class="navi_back"><a href="';

	// Link ändern zu Markenauswahl Maschinen oder Werkzeug
	if ( $row_marke['rubrik'] == 2 )
	{
		echo 'marken_werkzeuge.php';
	}
	else
	{
		echo 'marken.php';	
	}

echo '">Zur Markenauswahl</a></div></div>';
?>
	<article>
<?php
if ( $_SERVER['HTTP_HOST'] != "www.fuxtools.ch" OR $_SERVER['HTTP_HOST'] == "fuxtools.ch" )
{
echo $top;

include('page_ferien.php');
include('page_oeffnungszeiten.php');
include('page_banner.php');
}
else
{
	$filemarke = 'images/logos/'.$row_marke['bildname'].'.svg';

	if (file_exists($filemarke))
	{
		echo '			<img src="images/logos/'.$row_marke['bildname'].'.svg" alt="'.$row_marke['bildtitel'].'" width="'.$row_marke['bild_w_1'].'" height="'.$row_marke['bild_h_1'].'" id="marken_logo_svg"/>';
	}
	else
	{	
		$bild_groesse = getimagesize ("images/logos/".$row_marke['bildname'].".png");
		$bild_breite = $bild_groesse[0];
		$bild_hoehe = $bild_groesse[1];
		echo '			<a href="hauptrubrik.php?marke='.$row_marke['nummer'].'"><img src="images/logos/'.$row_marke['bildname'].'.png" alt="'.$row_marke['bildtitel'].'" width="'.$bild_breite.'" height="'.$bild_hoehe.'" id="marken_logo"/></a>';
	}
}

// S Sonderaktion
$result_rabatt = mysqli_query($dbi,"SELECT marke, rabatt FROM rabatt WHERE von <= '$datum' AND bis >= '$datum' AND marke = '$marke'");
$row_rabatt = $result_rabatt->fetch_assoc();
$num = mysqli_num_rows($result_rabatt);

if ( $num > '0' )
{
// Text Marke
$result_marke_aktion = mysqli_query($dbi,"SELECT marke FROM marken WHERE nummer='".$row_rabatt['marke']."'");
$row_marke_aktion = $result_marke_aktion->fetch_assoc();

// Wieviele Rubriken Total
$result_rubrik_total = mysqli_query($dbi,"SELECT name FROM rubrik WHERE marke='".$row_rabatt['marke']."' AND rubrikart='1'");
$num_rubrik_total = mysqli_num_rows($result_rubrik_total);

// Wieviele Rubriken Rabatt
$result_rubrik = mysqli_query($dbi,"SELECT nummer, name FROM rubrik WHERE marke='".$row_rabatt['marke']."' AND rubrikart='1' AND rabatt='1'");
$num_rubrik = mysqli_num_rows($result_rubrik);

// Rubriken *
$result_exkl = mysqli_query($dbi,"SELECT name FROM rubrik WHERE marke='".$row_rabatt['marke']."' AND rubrikart='1' AND rabatt='0'");

	// wenn alle Rubriken
	if ( $num_rubrik_total == $num_rubrik )
	{
	echo '<div class="navi titel rund abstand_top abstand_bottom">
		Heute auf fast alle '.$row_marke_aktion['marke'].' Produkte '.$row_rabatt['rabatt'].'% Rabatt!
	</div>';
	}

	// wenn einzelne nicht
	elseif ( $num_rubrik_total > $num_rubrik AND $num_rubrik > '4' )
	{

	echo '<div class="navi titel_aktion rund abstand_top abstand_bottom">Heute auf alle* '.$row_marke_aktion['marke'].' Maschinen '.$row_rabatt['rabatt'].'% Rabatt!
	<br><font class="klein">* Ausser auf ';

	$string = "";
	while($row = mysqli_fetch_assoc($result_exkl)) {

	$string .= "".$row['name']." & ";
	}

	echo substr($string, 0, strlen($string)-2);
	echo '</font></div>';
	}


	// wenn maximal 4
	elseif ( $num_rubrik <= '4' )
	{
	echo '<div class="navi titel_aktion rund abstand_top abstand_bottom">Heute auf ';

	$string = '';
	while($row = mysqli_fetch_assoc($result_rubrik)) {

	$string .= '<a href="unterrubrik.php?marke='.$row_rabatt['marke'].'&amp;hauptrubrik='.$row['nummer'].'">'.$row['name'].' & </a>';
	}

	echo substr($string, 0, strlen($string)-6);

	echo '</a> von '.$row_marke_aktion['marke'].' '.$row_rabatt['rabatt'].'% Rabatt!</div>';

	}

}
// E Sonderaktion
		
echo $set;

// S PDF
$result = mysqli_query($dbi,"SELECT nummer, titel, dateiname, text, m1, m2, m3, m4, m5, m6, m7, m8, von, DATE_FORMAT(von, '%d.%m.%Y') AS von_change, DATE_FORMAT(bis, '%d.%m.%Y') AS bis_change, click FROM aktionen WHERE von <= '$datum' AND bis >= '$datum' AND ( m1 = '".$_GET['marke']."' OR m2 = '".$_GET['marke']."' OR m3 = '".$_GET['marke']."' OR m4 = '".$_GET['marke']."' OR m5 = '".$_GET['marke']."' OR m6 = '".$_GET['marke']."' OR m7 = '".$_GET['marke']."' OR m8 = '".$_GET['marke']."' ) ORDER BY titel");

while($row = mysqli_fetch_assoc($result)) {

$link = 'flip/'.$row['dateiname'].'';

$bild_groesse = getimagesize ('aktion/'.$row['dateiname'].'.jpg');
$bild_breite = $bild_groesse[0];
$bild_hoehe = $bild_groesse[1];

if ( $bild_breite > $bild_hoehe )
{
	$height = 80;
}
else
{
	$height = 150;
}

echo '
<div class="box_marken">
	<a href="'.$link.'" target="_blank" class="katalog_box rahmen rund">';

$ausblenden = strtotime($row['von']);
$ausblenden = $ausblenden  + 2592000;

if ($timestamp <= $ausblenden)
{
echo '
	<div class="positionieren">
		<div class="pos_pdf_neu"><img src="images/neu.png" width="132" height="58" alt="Neu"/></div>
	</div>';
}

if ( $row['click'] == 1 )
{
echo '
	<div class="positionieren">
		<div class="pos_pdf_tipp klein"><b>Tipp:</b> Die Produkte sind mit unserem Shop verlinkt!</div>
	</div>';
}
echo'
		<div class="katalog_titel navi">'.$row['titel'].'</div>
		<div class="katalog_bild"><img src="aktion/'.$row['dateiname'].'.jpg" alt="'.$row['titel'].'" height="'.$height.'"/></div>
		<div class="katalog_text">
			<div class="katalog_pdf">Anschauen</div><br><br>
			<div class="klein">Gültig vom '.$row['von_change'].' - '.$row['bis_change'].'</div>
		</div>
	</a>
</div>';
}
// E PDF

echo '<div class="clear"></div>';

echo $banner;

// S Special
$result_jquery = mysqli_query($dbi,"SELECT nummer, produkt FROM produkte WHERE marke='".intval($_GET['marke'])."' AND special='1' AND bild='1' ORDER BY RAND() LIMIT 10");
if ( mysqli_num_rows($result_jquery) >= 1 )
{
echo '
<div class="box_marken box_special">
	<div class="rubrik rubrik_special rahmen rund">
		<div class="marken_titel navi_klein">'; if ( mysqli_num_rows($result_jquery) != 1 ) { echo '<div class="positionieren"><a href="specials.php?marke='.$marke.'" class="hauptrubrik_button rund" id="hauptrubrik_button_special">Alle Specials anzeigen</a></div>'; } echo ''.$row_marke['marke'].' Special'; if ( mysqli_num_rows($result_jquery) != 1 ) { echo 's'; } echo '</div>
		<div class="hauptrubrik_neuheit">
		<div class="cycle-slideshow" data-cycle-swipe="true" data-cycle-swipe-fx="scrollHorz" data-cycle-timeout="5000" data-cycle-speed="2000" data-cycle-manual-speed="700" data-cycle-carousel-visible="1" data-cycle-pause-on-hover="true" data-cycle-slides="> a" data-cycle-pager="#pager2">';
		
while($row = mysqli_fetch_assoc($result_jquery)) {

	echo '			<a href="produkt.php?produkt='.$row['nummer'].'">';

// überprüfen ob Foto vorhanden.
$filemarke = "images/produkte/neuheit/".$row['nummer'].".jpg";

if (file_exists($filemarke))
{
echo '<img src="images/produkte/neuheit/'.$row['nummer'].'.jpg" height="245" width="245" alt="'.$row['produkt'].'"/>';
}
else
{
echo '<img src="images/produkte/neuheit/bild_folgt.jpg" alt="Bild folgt" height="245" width="245" />';
}

	echo '</a>'."\n";
			}
		
		echo '</div></div>'; if ( mysqli_num_rows($result_jquery) != 1 ) { echo '<div class="cycle-pager" id="pager2"></div>'; } echo '
	</div>
</div>';
}
// E Special

// START jQuery
	if ( $num_special == 0 )
	{
		// START Neuheiten
		$result_jquery = mysqli_query($dbi,"SELECT nummer, produkt FROM produkte WHERE marke='".intval($_GET['marke'])."' AND neu='1' AND bild='1' ORDER BY RAND() LIMIT 10");
		$num_neuheit = mysqli_num_rows($result_jquery);
		$jquery = 2;
		// ENDE Neuheiten

		// START Produkt
		if ( $num_neuheit == 0 )
		{
			$result_jquery = mysqli_query($dbi,"SELECT nummer, produkt FROM produkte WHERE marke='".intval($_GET['marke'])."' AND aktion='1' AND bild='1' ORDER BY RAND() LIMIT 10");
			$jquery = 3;

			if ( mysqli_num_rows($result_jquery) == 0 )
			{
			$result_jquery = mysqli_query($dbi,"SELECT nummer, produkt FROM produkte WHERE marke='".intval($_GET['marke'])."' AND bild='1' ORDER BY RAND() LIMIT 10");
			$jquery = 4;
			}
		}
	// ENDE Produkt
	}

echo '
<div class="box_marken box_special">
	<div class="rubrik rubrik_special rahmen rund">
		<div class="marken_titel navi_klein">';
			if ( $jquery == 2 )
			{
			echo ''; if ( $num_neuheit != 1 ) { echo '<div class="positionieren"><a href="neuheiten.php?marke='.$marke.'" class="hauptrubrik_button rund" id="hauptrubrik_button_neu">Alle Neuheiten anzeigen</a></div>'; } echo ''.$row_marke['marke'].' Neuheit'; if ( $num_neuheit != 1 ) { echo 'en'; }
			}
			elseif ( $jquery == 3 )
			{
			echo '<div class="positionieren"><a href="aktionen.php?marke='.$marke.'" class="hauptrubrik_button rund" id="hauptrubrik_button_neu">Alle Aktionen anzeigen</a></div>'.$row_marke['marke'].' Aktionen';
			}
			else
			{
				echo "".$row_marke['marke']."";
			}
		echo '</div>
		<div class="hauptrubrik_neuheit">
		<div class="cycle-slideshow" data-cycle-swipe="true" data-cycle-swipe-fx="scrollHorz" data-cycle-timeout="5000" data-cycle-speed="2000" data-cycle-manual-speed="700" data-cycle-carousel-visible="1" data-cycle-pause-on-hover="true" data-cycle-slides="> a" data-cycle-pager="#pager">';
		
while($row = mysqli_fetch_assoc($result_jquery)) {

	echo '			<a href="produkt.php?produkt='.$row['nummer'].'">';

// überprüfen ob Foto vorhanden.
$filemarke = "images/produkte/neuheit/".$row['nummer'].".jpg";

if (file_exists($filemarke))
{
echo '<img src="images/produkte/neuheit/'.$row['nummer'].'.jpg" height="245" width="245" alt="'.$row['produkt'].'"/>';
}
else
{
echo '<img src="images/produkte/neuheit/bild_folgt.jpg" alt="Bild folgt" height="245" width="245" />';
}

	echo '</a>'."\n";
			}
		
		echo '</div></div>'; if ( $num_neuheit != 1 ) { echo '<div class="cycle-pager" id="pager"></div>'; } echo '
	</div>
</div>';

// fortec switch werkzeuge
if ( $_GET['marke'] == 54 )
{
echo '<div class="box_marken">
	<a href="hauptrubrik.php?marke=64" class="rubrik rahmen rund">
		<div class="marken_titel navi_klein">Zu fortec Werkzeuge</div>
		<div class="hauptrubrik_marken_switch"><img src="images/marken_switch/fortec_werkzeuge.png" height="90" width="204" alt="fortec Werkzeuge"></div>
	</a>
</div>';
}

// fortec switch maschinen
if ( $_GET['marke'] == 64 )
{
echo '<div class="box_marken">
	<a href="hauptrubrik.php?marke=54" class="rubrik rahmen rund">
		<div class="marken_titel navi_klein">Zu fortec Maschinen</div>
		<div class="hauptrubrik_marken_switch"><img src="images/marken_switch/fortec_maschinen.png" height="83" width="207" alt="fortec Maschinen"></div>
	</a>
</div>';
}

$result = mysqli_query($dbi,"SELECT nummer, name FROM rubrik WHERE marke=".intval($_GET['marke'])." AND rubrikart='1' ORDER by name");

$num = mysqli_num_rows($result);

// überprüfen ob unterrubrik eingetragen
$result_rubrik = mysqli_query($dbi,"SELECT nummer FROM rubrik WHERE marke=".intval($_GET['marke'])." AND rubrikart='2'");
$num_rubrik = mysqli_num_rows($result_rubrik);

if ( $num_rubrik != '0' )
{

while($row = mysqli_fetch_assoc($result)) {

// überprüfen wenn unterrubrik eingetragen ob Produkt eingetragn

// Wenn mehr als 3 Neuheiten pro Rubrik
$result_produkt = mysqli_query($dbi,"SELECT nummer FROM produkte WHERE marke=".intval($_GET['marke'])." AND hauptrubrik='".$row['nummer']."' AND neu='1' ORDER BY RAND() LIMIT 3");
$num = mysqli_num_rows($result_produkt);

// Wenn weniger als 3 Neuheiten pro Rubrik
if ( $num != 3 )
{
$result_produkt = mysqli_query($dbi,"SELECT nummer FROM produkte WHERE marke=".intval($_GET['marke'])." AND hauptrubrik='".$row['nummer']."' ORDER BY RAND() LIMIT 3");
}

$num_produkt = mysqli_num_rows($result_produkt);

// Wenn nur 1 unterrubrik
$result_unterrubrik = mysqli_query($dbi,"SELECT nummer, rubrik FROM rubrik WHERE rubrik='".$row['nummer']."'");
$row_unterrubrik = $result_unterrubrik->fetch_assoc();

if ( mysqli_num_rows($result_unterrubrik) == 1 )
{
	$link = 'produkte.php?marke='.$_GET['marke'].'&amp;hauptrubrik='.$row_unterrubrik['rubrik'].'&amp;unterrubrik='.$row_unterrubrik['nummer'].'';
}
else
{
	$link = 'unterrubrik.php?marke='.$_GET['marke'].'&amp;hauptrubrik='.$row['nummer'].'';
}

if ( $num_produkt != '0' )
{
echo '
<div class="box_marken">
	<a href="'.$link.'" class="rubrik rahmen rund">';

if ( $row['nummer'] == 490 )
{
	echo '<div class="positionieren">
			<div id="pos_hd_logo"><img src="images/metabo_lihd_partner.png" alt="Metabo LiHD Partner" width="91" height="45"/></div>
		</div>';
}

/*
// Neu
if ( $row['nummer'] == 8135 )
{
	echo '<div class="positionieren">
			<div id="pos_rubrik_neu"><img src="images/neu.png" alt="Neu" width="100" height="43"/></div>
		</div>';
}
*/

echo '		<div class="marken_titel navi_klein">'.stripslashes($row['name']).'</div>
		<div class="hauptrubrik_bilder">';
	$count = 1;
	while($row_produkt = mysqli_fetch_assoc($result_produkt)) {

	// überprüfen ob Foto vorhanden.
	$filemarke = 'images/produkte/klein/'.$row_produkt['nummer'].'.jpg';

		if (file_exists($filemarke))
		{
			echo '<img src="images/produkte/klein/'.$row_produkt['nummer'].'.jpg?time='.filemtime('images/produkte/klein/'.$row_produkt['nummer'].'.jpg').'" height="110" width="110" alt="'.$row['name'].' '.$count.'"/>';
		}
		else
		{
			echo '<img src="images/produkte/klein/bild_folgt.jpg" height="110" width="110" alt="'.$row['name'].'"/>';
		}
	$count++;
	}
	echo '</div>
	</a>
</div>';
}

}
}

echo '<div class="clear"></div>';

// Text zu Marke
if ( $row_marke['text'] != '' )
{
echo'	<div class="navi titel rund_oben">'.$row_marke['bildtitel'].'</div>
	<div id="hauptrubrik_text" class="rahmen rund_unten">
	'.$row_marke['text'].'
	</div>';
}
?>
<div class="clear"></div>
<br>
<?php include('page_vorteile.php'); ?>
	</article>

<?php include('page_last.php'); ?>

</section>

</div>

<?php include('page_footer.php'); ?>

<?php include('page_script_bottom.php'); ?>

</body>
</html>