<?php
	include "admin/functions.php";
	include "lang.php";
	
	$gallery = isset( $_REQUEST['galerie'] ) ? $_REQUEST['galerie'] : "";
	$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : "";
	$lang = isset( $_REQUEST['lang'] ) ? $_REQUEST['lang'] : "de";
	$filter = isset( $_REQUEST['filter'] ) ? $_REQUEST['filter'] : "";
	$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : "gallery";

	DBConnect();
?>

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
	<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Klaus Friese</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="description" content="klausfriese.de - little planets" />
	<meta name="keywords" content="" />
	<meta name="author" content="Klaus Friese" />

  <!-- 
	//////////////////////////////////////////////////////

	FREE HTML5 TEMPLATE 
	DESIGNED & DEVELOPED by FREEHTML5.CO
		
	Website: 		http://freehtml5.co/
	Email: 			info@freehtml5.co
	Twitter: 		http://twitter.com/fh5co
	Facebook: 		https://www.facebook.com/fh5co

	//////////////////////////////////////////////////////
	 -->

  <!-- Facebook and Twitter integration -->
	<meta property="og:title" content="panoramicum"/>
	<meta property="og:image" content=""/>
	<meta property="og:url" content=""/>
	<meta property="og:site_name" content=""/>
	<meta property="og:description" content=""/>
	<meta name="twitter:title" content="" />
	<meta name="twitter:image" content="" />
	<meta name="twitter:url" content="" />
	<meta name="twitter:card" content="" />

	<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
	<link rel="shortcut icon" href="favicon.ico">

	<!-- Google Webfonts
	<link href='http://fonts.googleapis.com/css?family=Roboto:400,300,100,500' rel='stylesheet' type='text/css'>
	<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
	-->
	
	<!-- Animate.css -->
	<link rel="stylesheet" href="css/animate.css">
	<!-- Icomoon Icon Fonts-->
	<link rel="stylesheet" href="css/icomoon.css">
	<!-- Magnific Popup -->
	<link rel="stylesheet" href="css/magnific-popup.css">
	<!-- Salvattore -->
	<link rel="stylesheet" href="css/salvattore.css">
	<!-- Theme Style -->
	<link rel="stylesheet" href="css/style.css">
	<!-- Modernizr JS -->
	<script src="js/modernizr-2.6.2.min.js"></script>
	<!-- FOR IE9 below -->
	<!--[if lt IE 9]>
	<script src="js/respond.min.js"></script>
	<![endif]-->

	</head>
	<body>
		
	<div id="fh5co-offcanvass">
		<a href="#" class="fh5co-offcanvass-close js-fh5co-offcanvass-close">Menu <i class="icon-cross"></i> </a>
		<h1 class="fh5co-logo"><a class="navbar-brand" href="index.php"><img src="images/panoramicum_small.png"/></a></h1>
		<ul>
			<?php
				print menuItem( $action , "gallery" , ID_HOME  , $lang );
				print menuItem( $action , "about"   , ID_ABOUT , $lang );
				print menuItem( $action , "dontbuy" , ID_PRINTS , $lang );
				print menuItem( $action , "wall" 		, ID_WALL , $lang );
//				print menuItem( $action , "search"  , ID_SEARCH , $lang );
				print menuItem( $action , "contact" , ID_CONTACT , $lang );
				
				function menuItem( $action , $active , $textID , $lang ) {
					global $texte;
					$result  = ( $action == $active ? '<li class="active">' : '<li>' );
					$result .= '<a href="index.php?lang='.$lang.'&action='.$active.'">';
					$result .= getTextforID( $textID , $lang );
					$result .= "</a></li>";
					return $result;
				}
				
				function getTextforID( $textID , $lang ) {
					global $texte;
					$text = htmlspecialchars( $texte[$textID][$lang] , ENT_COMPAT | ENT_HTML401 , ini_get("default_charset") , false );
					$text = str_replace("[", "<", $text );
					$text = str_replace("]", ">", $text );

					return $text;
				}
			?>
		</ul>
		<h3 class="fh5co-lead"><?php print getTextforID( ID_SOCIAL , $lang ) ?></h3>
		<p class="fh5co-social-icons">
			<!-- a href="https://www.facebook.com/panoramicum/"><i class="icon-facebook"></i></a-->
			<a href="https://www.instagram.com/klausfriese/"><i class="icon-instagram"></i></a>
			<!--a href="https://www.flickr.com/photos/hamburgerjung/"><i class="icon-flickr"></i></a>
			<a href="https://www.patreon.com/panoramicum"><svg xmlns="http://www.w3.org/2000/svg"
     viewBox="0 0 8 8"
     width="16px"
     height="16px"
     fill="#ce7f7d">
    <path d="M2.32081783.3678855c.869042-.40526652 1.88661925-.47774603 2.80665096-.20727372.80652418.2346745 1.53190822.73363407 2.0426921 1.3983242.5050198.6523156.79854318 1.4641745.82647667 2.28752405.0354711.8511923-.21060967 1.71122356-.6952336 2.4134793-.71030882 1.0518368-1.9482503 1.72713368-3.22254963 1.73950823-.63803645.0008839-1.2760729.00044195-1.91366597 0 .00532067-1.34042898.0004434-2.68085797.00310373-4.0217289.00221694-.50647268.23011877-1.00499028.60921618-1.34131288.36180524-.3279256.85973083-.5002854 1.3474585-.46404565.50457642.03093638.98831357.2859405 1.30267622.68015833.3232304.3968695.46422805.93295272.38131434 1.4376576-.08114014.53122177-.41368172 1.01603898-.87790977 1.2882791-.5373872.3252739-1.2406018.3345548-1.7935076.04021728.00044338.43487706-.0008868.86975412.00044338 1.30463118.4934917.14407512 1.02201113.16838228 1.52392723.0539177.7431196-.16219502 1.4144102-.6174017 1.8444973-1.24187455.40969124-.5855814.59946164-1.31788962.52851943-2.02810043-.06030086-.6514317-.34052257-1.27944013-.78302457-1.7620476-.41013462-.4507872-.95860653-.77561914-1.55363427-.913507-.6837055-.162195-1.42372137-.07866678-2.05200326.23600036C1.64553673 1.7542771.962718 2.8206982.95207668 3.932198.95030312 5.2876532.95163328 6.6435504.9511899 7.99944755c-.3165796.0008839-.63360256.00044195-.95062554.00044195-.0004434-1.32584468.0004434-2.65168938-.0004434-3.97709212-.00443387-.56569374.11306415-1.13227137.3440697-1.6493508C.73215587 1.49662128 1.44778534.7691745 2.32081784.3678855z" />
</svg></a-->		</p>
	</div>
	<header id="fh5co-header" role="banner">
		<div class="container">
			<div class="row">
				<div class="col-md-12">
					<?php
						$fullUrl = basename($_SERVER['REQUEST_URI']);
						$pos = strpos( $fullUrl , "lang" );
						if ($pos !== false) {
							$fullUrlDE = str_replace("lang=de", "lang=en", $fullUrl );
							$fullUrlEN = str_replace("lang=en", "lang=de", $fullUrl );
						} else {
							$fullUrlDE = $fullUrl."?lang=de";
							$fullUrlEN = $fullUrl."?lang=en";
						}
						print '<a href="'.$fullUrlDE.'" class="fh5co-menu-btn"><img src="images/en.png" width="20" height="20"/></i></a>';
						print '<a href="'.$fullUrlEN.'" class="fh5co-menu-btn"><img src="images/de.png" width="20" height="20"/></i></a>';
					?>
					<a href="#" class="fh5co-menu-btn js-fh5co-menu-btn">Menu <i class="icon-menu"></i></a>
					<a class="navbar-brand" href="index.php"><img id="logo"/></a>		
					<script>
						var logoImage = document.getElementById("logo");
						if( window.innerWidth < 400 ) {
	       			logoImage.src = "images/panoramicum250.png";
						} else {
	       			logoImage.src = "images/panoramicum.png";
						}
					</script>
				</div>
			</div>
		</div>
	</header>
	<!-- END .header -->
	
	
	<div id="fh5co-main">
		<div class="container">
			<div class="row">
				<?php
					if( $action == "gallery" ) {
						if( $filter == "" ) {
				    	$query = "SELECT p.ID,p.Name,p.Name_en,p.Datei FROM planeten p order by Upload desc,id desc";
				    } else {
							$searchField = ( $lang == "de" ? "tag" : "tag_en" );
					    $query = "SELECT tag,tag_en,id FROM tag where id=".$filter;
							$result = $db->query( $query );
							$line = $result->fetch();
							$searchVal = ( $lang == "de" ? $line['tag'] : $line['tag_en'] );
				    	$query = "SELECT p.ID,p.Name,p.Name_en,p.Datei FROM planeten p, tag t, planet_tag pt where p.ID=pt.planet and t.ID=pt.tag and t.".$searchField."=\"".$searchVal."\" order by Upload desc,id desc";
							print '<h2>'.getTextforID( ID_SEARCHFOR , $lang ).' <i>'.$searchVal.'</i></h2>';
				    }
						print '<div class="fh5co-spacer fh5co-spacer-sm"></div>';
						print "<div id='fh5co-board' data-columns>";

						$files = glob($fulldir."planeten/small/*.jpg" );
						usort($files, function($a, $b) {
                            if( $a < $b ) { return -1; }
                            if( $a == $b ) { return 0; }
                            if( $a > $b ) { return 1; }
						});
						
						foreach($files as $file) {
							if (!preg_match("/^\.{1,2}$/i",$file)) {
								$file = str_replace( $fulldir."planeten/small/" , "" , $file );
								print "<div class='item'><div class='animate-box'>\n";
								print "\t<a href='planeten/".$file."' class='image-popup fh5co-board-img' download='".getTextforID( ID_DOWNLOAD , $lang )."' interactive='".getTextforID( ID_INTERACTIVE , $lang )."' title='' image='".$file."'><img src='planeten/small/".$file."'></a>";
								print "</div></div>\n";
							}
			    	}				    	
					}
					
					if( $action == "wall" ) {
						print '<h2>'.getTextforID( ID_WALL , $lang ).'</h2>';
						print '<div class="fh5co-spacer fh5co-spacer-sm"></div>';
						print getTextforID( ID_WALL_TXT , $lang );
						print "<div id='fh5co-board' data-columns>";
						$handle = @opendir( $fulldir."onthewall/small/" );
						$count = 1;
						while ($file = readdir ($handle)) {
							if (!preg_match("/^\.{1,2}$/i",$file)) {
								print "<div class='item'><div class='animate-box'>\n";
								print "\t<a href='onthewall/".$file."' download='' interactive='' title='' class='image-popup fh5co-board-img' image='".$file."'><img src='onthewall/small/".$file."'></a>";
								print "</div></div>\n";
							}
						}
						@closedir($handle); 
					}
					
					if( $action == "about" ) {
						?>
						<div class="col-md-8 col-md-offset-2">
							<h2><?php print getTextforID( ID_ABOUT , $lang ) ?></h2>
							<div class="fh5co-spacer fh5co-spacer-sm"></div>
							<p><?php print getTextforID( ID_ABOUT_TXT1 , $lang ) ?></p>
							<p><?php print getTextforID( ID_ABOUT_TXT2 , $lang ) ?></p>
							<p><?php print getTextforID( ID_ABOUT_TXT3 , $lang ) ?></p>
							<a href='images/myself_planet.jpg' download='' interactive='' title='' class='image-popup fh5co-board-img' image=''><img src="images/myself_planet_small.jpg" align=center"/></a>
						</div>
						<?php
					}
				
					if( $action == "large" ) {
						$image = isset( $_REQUEST['image'] ) ? $_REQUEST['image'] : "";
						?>
						<div class="col-md-8 col-md-offset-2">
							<h2><?php print getTextforID( ID_LARGE , $lang ) ?></h2>
							<div class="fh5co-spacer fh5co-spacer-sm"></div>
							<p><?php print getTextforID( ID_LARGE_TXT , $lang ) ?></p>
							<a href='planeten/large/<?php print $image; ?>' title='' target='_blank'><img src="planeten/small/<?php print $image; ?>" align=center"/></a>
						</div>
						<?php
					}
				
					if( $action == "contact" ) {
						?>
						<div class="col-md-8 col-md-offset-2">
							<h2><?php print getTextforID( ID_CONTACT , $lang ) ?></h2>
							<div class="fh5co-spacer fh5co-spacer-sm"></div>
							<form action="index.php">
								<input type=hidden name="action" value="send">
								<div class="row">
									<div class="col-md-6">
										<div class="form-group">
											<input type="text" name="vorname" class="form-control" placeholder="<?php print getTextforID( ID_FIRSTNAME , $lang ) ?>">	
										</div>
									</div>
									<div class="col-md-6">
										<div class="form-group">
											<input type="text" name="nachname" class="form-control" placeholder="<?php print getTextforID( ID_LASTNAME , $lang ) ?>">
										</div>
									</div>
									<div class="col-md-12">
										<div class="form-group">
											<input type="email" name="email" class="form-control" placeholder="<?php print getTextforID( ID_EMAIL , $lang ) ?>">
										</div>
										<div class="form-group">
											<textarea name="message" id="message" cols="30" class="form-control" rows="10"></textarea>
										</div>
										<div class="form-group">
											<input type="submit" class="btn btn-primary" value="<?php print getTextforID( ID_SENDMESSAGE , $lang ) ?>">
										</div>
									</div>
								</div>
							</form>
							
						</div>
						<?php
					}
				
					if( $action == "send" ) {
						$vorname = isset( $_REQUEST['vorname'] ) ? $_REQUEST['vorname'] : "";
						$nachname = isset( $_REQUEST['nachname'] ) ? $_REQUEST['nachname'] : "";
						$email = isset( $_REQUEST['email'] ) ? $_REQUEST['email'] : "";
						$message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : "";
						$send = "Panoramicum-Nachricht von $vorname $nachname:<br>";
						$send .= "$message";
						$to      = "Klaus.Friese@hamburg.de";
						$subject = "Panoramicum Kontakt ..";
						$xtra    = "From: $email ($vorname $nachname)\r\n";
						$xtra   .= "Content-Type: text/html\r\nContent-Transfer-Encoding: 8bit\r\n";
						$xtra   .= "X-Mailer: PHP ". phpversion();
						print "<h2>".getTextforID( ID_CONTACT , $lang )."</h2><div class='fh5co-spacer fh5co-spacer-sm'></div>";
						if( mail($to,$subject,$send,$xtra) ) {
							print "<p>Wir bedanken uns f&uuml;r Ihre Nachricht und werden diese schnellstm&ouml;glich bearbeiten.</p>";
						} else {
							print "<p>Fehler beim Senden der Nachricht.</p>";
						}
					}
				
					if( $action == "dontbuy" ) {
						?>
						<div class="col-md-8 col-md-offset-2">
							<h2><?php print getTextforID( ID_PRINTS , $lang ) ?></h2>
							<div class="fh5co-spacer fh5co-spacer-sm"></div>
							<p><?php print getTextforID( ID_PRINT_TXT , $lang ) ?></p>
							<a href='images/myself_planet.jpg' download='' interactive='' title='' class='image-popup fh5co-board-img' image=''><img src="images/myself_planet_small.jpg" align=center"/></a>
						</div>
						<?php
					}
					
					if( $action == "search" ) {
						print '<h2>'.getTextforID( ID_SEARCH , $lang ).'</h2>';
						print '<div class="fh5co-spacer fh5co-spacer-sm"></div>';
				    
				    $query = "SELECT count(*) as count FROM planeten";
						$result = $db->query( $query );
						$line = $result->fetch();
		  		  $planetcount = $line['count'];
		  		  
				    $query = "SELECT tag,tag_en,id FROM tag";
						$result = $db->query( $query );
	
		  		  $data = array();
						foreach( $result as $line ) {
					    $query1 = "SELECT count(*) as count FROM planet_tag pt,tag t where t.id=pt.tag and pt.planet=".$line['id'];
							$result = $db->query( $query1 );
							$line1 = $result->fetchColumn();
			  		  $weight = $line1 / $planetcount * 100;
			  		  $data[] = array('Weight' => $weight, 'Tag' => $line['tag'], 'Tag_en' => $line['tag_en'] , 'id' => $line['id'] );
						}
						
						$html = '<p id="tag_cloud">';
				    $weight = 0;
				    foreach($data as $key => $value) {
				        if(!isset($value['Weight']) || !isset($value['Tag'])) return false;
				         
				        if(!isset($tmin)) $tmin = $value['Weight'];
				        if(!isset($tmax)) $tmax = $value['Weight']; 
				          
				        if($value['Weight'] < $tmin) {
				            $tmin = $value['Weight'];
				        }
				         
				        if($value['Weight'] > $tmax) {
				            $tmax = $value['Weight'];
				        }
				         
				        if($value['Weight'] <= 0) $value['Weight'] = 1;
				        $weight += $value['Weight'];        
				    }

						$min = 10;
						$max = 40;
				    foreach($data as $key => $value) {
				        $ti = $value['Weight'];
				        $q = $ti - $tmin;
				        $div = $tmax-$tmin;
				        if($div <= 0) $div = 1;     
				        $font_size = ceil($max*(($q)/($div)));
				        if($q<=0) $font_size = $min;   
				        if($font_size < $min) $font_size = $min;    
				        $displayTag = ( $lang == "de" ? $value['Tag'] : $value['Tag_en'] );
				        	
				        $html .= '<a href="index.php?lang='.$lang.'&filter='.$value['id'].'" style="font-size:'.$font_size.'px" class="tagcloud">'.htmlspecialchars($displayTag).'</a> ';
				    }   
				    $html .= '</p>';
				    print $html;  						
				    print "</div>";
				    print "</div>";
						
        	}
				
				?>

        </div>
        </div>
       </div>
	</div>

	<footer id="fh5co-footer">
		
		<div class="container">
			<div class="row row-padded">
				<div class="col-md-12 text-center">
					<p class="fh5co-social-icons">
						<a href="https://www.facebook.com/panoramicum/"><i class="icon-facebook"></i></a>
						<a href="https://www.instagram.com/klausfriese/"><i class="icon-instagram"></i></a>
						<a href="https://www.flickr.com/photos/hamburgerjung/"><i class="icon-flickr"></i></a>
						<a href="https://www.patreon.com/panoramicum"><svg xmlns="http://www.w3.org/2000/svg"
     viewBox="0 0 8 8"
     width="16px"
     height="16px"
     fill="#ce7f7d">
    <path d="M2.32081783.3678855c.869042-.40526652 1.88661925-.47774603 2.80665096-.20727372.80652418.2346745 1.53190822.73363407 2.0426921 1.3983242.5050198.6523156.79854318 1.4641745.82647667 2.28752405.0354711.8511923-.21060967 1.71122356-.6952336 2.4134793-.71030882 1.0518368-1.9482503 1.72713368-3.22254963 1.73950823-.63803645.0008839-1.2760729.00044195-1.91366597 0 .00532067-1.34042898.0004434-2.68085797.00310373-4.0217289.00221694-.50647268.23011877-1.00499028.60921618-1.34131288.36180524-.3279256.85973083-.5002854 1.3474585-.46404565.50457642.03093638.98831357.2859405 1.30267622.68015833.3232304.3968695.46422805.93295272.38131434 1.4376576-.08114014.53122177-.41368172 1.01603898-.87790977 1.2882791-.5373872.3252739-1.2406018.3345548-1.7935076.04021728.00044338.43487706-.0008868.86975412.00044338 1.30463118.4934917.14407512 1.02201113.16838228 1.52392723.0539177.7431196-.16219502 1.4144102-.6174017 1.8444973-1.24187455.40969124-.5855814.59946164-1.31788962.52851943-2.02810043-.06030086-.6514317-.34052257-1.27944013-.78302457-1.7620476-.41013462-.4507872-.95860653-.77561914-1.55363427-.913507-.6837055-.162195-1.42372137-.07866678-2.05200326.23600036C1.64553673 1.7542771.962718 2.8206982.95207668 3.932198.95030312 5.2876532.95163328 6.6435504.9511899 7.99944755c-.3165796.0008839-.63360256.00044195-.95062554.00044195-.0004434-1.32584468.0004434-2.65168938-.0004434-3.97709212-.00443387-.56569374.11306415-1.13227137.3440697-1.6493508C.73215587 1.49662128 1.44778534.7691745 2.32081784.3678855z" />
</svg></a>
					</p>
					<p><small>Based on the &copy; Hydrogen Free HTML5 Template by: <a href="http://freehtml5.co/" target="_blank">FREEHTML5.co</a></small></p>
				</div>
			</div>
		</div>
	</footer>


	<!-- jQuery -->
	<script src="js/jquery.min.js"></script>
	<!-- jQuery Easing -->
	<script src="js/jquery.easing.1.3.js"></script>
	<!-- Bootstrap -->
	<script src="js/bootstrap.min.js"></script>
	<!-- Waypoints -->
	<script src="js/jquery.waypoints.min.js"></script>
	<!-- Magnific Popup -->
	<script src="js/jquery.magnific-popup.min.js"></script>
	<!-- Salvattore -->
	<script src="js/salvattore.min.js"></script>
	<!-- Main JS -->
	<script src="js/main.js"></script>

	

	
	</body>
</html>
