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

$datei = "aktionen.php";

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

if ( !empty($_GET['rubrik']) )
{
$rubrik = intval($_GET['rubrik']);
}

if ( !empty($_GET['marke']) )
{
	$marke = intval($_GET['marke']);
	$result_marke = mysqli_query($dbi,"SELECT marke FROM marken WHERE nummer='".$marke."'");
	$row_marke = $result_marke->fetch_assoc();
	
	if ( mysqli_num_rows($result_marke) == 0 )
	{
		header("Location: http://www.fuxtools.ch/404.php");
		exit;
	}
}
?>
<!DOCTYPE html>
<html lang="de-CH">
<head>

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

	<title>Aktionen <?php if ( !empty($row_marke['marke']) ) { echo ' '.$row_marke['marke'].''; } ?> - Fux Elektrowerkzeuge GmbH, Rümlingen</title>

<?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>

	<h1>Aktionen<?php if ( !empty($row_marke['marke']) ) { echo ' '.$row_marke['marke'].''; } ?></h1>

	<article>
<?php 
if ( empty($marke) )
{
echo '<strong>Klicken Sie auf das gew&uuml;nschte Markenlogo um die Aktionen des jeweiligen Herstellers zu betrachten.</strong><br><br><br>';
}

if ( empty($marke) )
{
	if ( $rubrik == '' )
	{
	$result = mysqli_query($dbi,"SELECT nummer, marke, www, bildname, bild_w_1, bild_h_1, bildtitel FROM marken WHERE aktiv='1' ORDER BY marke");
	}
	else
	{
	$result = mysqli_query($dbi,"SELECT nummer, marke, www, bildname, bild_w_1, bild_h_1, bildtitel FROM marken WHERE aktiv='1' AND rubrik='$rubrik' ORDER BY sort, marke");
	}

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

	$result_produkt = mysqli_query($dbi,"SELECT nummer FROM produkte WHERE marke='".$row['nummer']."' AND aktion='1'");

		if ( mysqli_num_rows($result_produkt) != 0 )
		{
			$link = ''.$datei.'?marke='.$row['nummer'].'';

			echo '
			<div class="box_marken">
				<a href="'.$link.'" class="rubrik rahmen rund">
					<div class="marken_titel navi">'.$row['marke'].'</div>
					<div class="marken_nur_logo">';

					$filemarke = 'images/logos/'.$row['bildname'].'.svg';

					if (file_exists($filemarke))
					{
						echo '<img src="images/logos/'.$row['bildname'].'.svg" alt="'.$row['bildtitel'].'" width="'.$row['bild_w_1'].'" height="'.$row['bild_h_1'].'"/>';
					}
					else
					{	
						$bild_groesse = getimagesize ("images/logos/".$row['bildname'].".png");
						$bild_breite = $bild_groesse[0];
						$bild_hoehe = $bild_groesse[1];
						echo '<img src="images/logos/'.$row['bildname'].'.png" alt="'.$row['bildtitel'].'" height="'.$bild_hoehe.'" width="'.$bild_breite.'"/>';
					}
					echo '</div>
				</a>
			</div>';
		}
	}
}
else
{
include('produkte_layout_result.php');
$result .= "WHERE p.aktion='1' AND p.marke='".$marke."' ORDER BY p.art, p.produkt";
$result = mysqli_query($dbi, $result);

// Prüfen ob Black aktiv
$result_black = mysqli_query($dbi,"SELECT black_von FROM black WHERE black_von <= '$datum' AND black_bis >= '$datum'");

while($row = mysqli_fetch_assoc($result)) {
include('produkte_layout.php');
}
}
?>
	</article>

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

</section>

</div>

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

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

</body>
</html>