<?php
session_start();
	if (isset($_POST['k1'])) {
		$id = $_POST['k1'];
		$nazwa = $_POST['k2'];
		$sciezka_img = $_SESSION['strona'].'pliki/upload/'.$nazwa.'/foto/';
		require_once('../wiras_php/wa_baza/wa_polacz.php');
		$zap = 'SELECT * FROM strona_setup WHERE id_user='.$id;
		$pobierz = mysqli_query($db, $zap);
			$ustawienia = array();
			while ($wiersz = mysqli_fetch_row($pobierz)) 
			{
				$ustawienia[] = $wiersz;
			}
		$w[0] = $ustawienia[0][2];		//ramka rozmiar
		$w[1] = $ustawienia[0][3];		//ramka kolor
		$w[2] = $ustawienia[0][4];		//tytul kolor
		$w[3] = $ustawienia[0][5];		//tlo kolor
		$w[4] = $ustawienia[0][6];		//tresc kolor
		$w[5] = $ustawienia[0][7];		//font tytul kolor
		$w[6] = $ustawienia[0][8];		//font tytul rodzaj
		$w[7] = $ustawienia[0][9];		//font tresc kolor
		$w[8] = $ustawienia[0][10];		//font tresc rodzaj
		$w[9] = $ustawienia[0][11];		//img tytul
		$w[10] = $ustawienia[0][12];		//img rodzaj
		//------------------------------------
		$tab_font[0] = "'Alegreya', serif";
		$tab_font[1] = "'Righteous', cursive";
		$tab_font[2] = "'Eagle Lake', cursive";
		$tab_font[3] = "'Shadows Into Light Two', cursive";
		$tab_font[4] = "'Pangolin', cursive";
		$tab_font[5] = "Mogra, cursive";
		$tab_font[6] = "'Merriweather', serif";
		$tab_font[7] = "'Patrick Hand', cursive";
		$tab_font[8] = "'Arima Madurai', cursive";
		$tab_font[9] = "'New Rocker', cursive";
		$tab_font[10] = "'Comic Sans MS', cursive";
		$tab_font[11] = "'Times New Roman', Georgia, Serif";
		$tab_font[12] = "Arial, Helvetica, sans-serif";
		$tab_font[13] = "Verdana, sans-serif";
		$tab_font[14] = "Courier, 'Courier New', monospace";
		$tab_font[15] = "'Trebuchet MS', Helvetica, sans-serif";
		$font_tytul = $tab_font[($w[6]-1)];
		$font_tresc = $tab_font[($w[8]-1)];
		//-----------------------------------------------------
		$zap = 'SELECT * FROM strona_tresc WHERE id_user='.$id;
		$pobierz = mysqli_query($db, $zap);
		$dane = array();
		while ($wiersz = mysqli_fetch_row($pobierz)) 
		{
			$dane[] = $wiersz;
		}
		
		$w[11] = $dane[0][4];	//tytul
		$w[12] = $dane[0][5];	//tresc
		$w[13] = $dane[0][2];	//nazwa
		$w[14] = $dane[0][6];	//data
		
		//----------------------------------------------
		
		$dir = $_SESSION['strona'].'pliki/upload/'.$nazwa.'/pliki/';
		$zap = 'SELECT * FROM strona_pliki WHERE id_user='.$id;
		$pobierz = mysqli_query($db, $zap);
		$dane = array();
		while ($wiersz = mysqli_fetch_row($pobierz)) 
		{
			$dane[] = $wiersz;
		}
		$lp = count($dane);
		if ($lp>0) {
			$tup = '<div style="width: 750px; margin: 5px auto; height: 0; border: 1px dotted #F00; clear: both;"></div>';
			$tup = $tup.'<div id="strona_upload_tlo">';
			$tup = $tup.'<h1 id="h3_tytul" style="color: #48F">Pliki do pobrania</h1>';
			$styl = '<span style="color: #AEF; font-weight: bold;">';
			for ($i=0; $i<$lp; $i++) {
				$tup = $tup.'<div id="strona_upload_plik">';
				$tup = $tup.'<div id="strona_upload_sekcja1">';
				$tup = $tup.$styl.'Nazwa pliku</span><br />';
				$tup = $tup.$dane[$i][2];
				$tup = $tup.'</div>';
				$tup = $tup.'<div id="strona_upload_sekcja2">';
				$tup = $tup.$styl.'Data dodania</span><br />';
				$tup = $tup.$dane[$i][4];
				$tup = $tup.'</div>';
				$tup = $tup.'<div id="strona_upload_sekcja3" class="l'.$i.'">';
				$tup = $tup.$styl.'Link do pobrania</span><br />';
				$tup = $tup.'<a id="'.$dane[$i][0].'" class="wiz_link" href="'.$dir.$dane[$i][2].'" target="_blank">Pobierz</a>';
				$tup = $tup.'</div>';
				$tup = $tup.'<div id="strona_upload_sekcja4" class="lip'.$i.'">';
				$tup = $tup.$styl.'Liczba pobrań</span><br />';
				$tup = $tup.$dane[$i][5];
				$tup = $tup.'</div>';
				$tup = $tup.'</div>';
			}
			$tup = $tup.'</div>';
		} else $tup='';
	} else {
		header('Location: ../login.php');
		exit();
	}
?>

<style>
#wiz_content {
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
}

#wiz_tresc {
	width: 820px;
	min-height: 500px;
	position: relative;
	background: #111;
	margin: 0px auto;
	padding: 10px 30px 10px 20px;
	overflow-y: auto;
	border-radius: 25px 15px 0px 0px;
	box-shadow: 5px 3px 8px rgba(0, 0, 0, 0.7);
	font-size: 1em;
	text-shadow: 5px 3px 7px rgba(0, 0, 0, 0.6);
	letter-spacing: 1px;
	z-index: 0;
	left: 0px;
	bottom: 60px;
	color: #FED;
}

#wiz_tytul {
	width: 970px;
	height: 40px;
	position: relative;
	right: 30px;
	top: 20px;
	background: #182028;
	margin: 0px auto;
	border-radius: 15px 15px 10px 10px;
	font-family: 'Roboto Mono', monospace;
	padding: 5px 10px;
	text-align: center;
	font-size: 1.5em;
	box-shadow: 5px 3px 8px rgba(0, 0, 0, 0.7);
	color: #F64;
	z-index: 1;
}

#strona_img {
		border-radius: 5px;
		padding: 3px;
		margin: 10px 0;
		float: right;
	}

#wiz_button {
	width: 120px;
	margin: 0px auto;
	position: relative;
	right: 455px;
	top: 58px;
	z-index: 2;
}

#strona_upload_tlo {
		width: 825px;
		margin: 10px 0 5px -15px;
		padding: 10px 5px;
		background: #123;
		border: 2px ridge #666;
		border-radius: 12px 12px 10px 10px;
		box-shadow: 5px 3px 8px rgba(0, 0, 0, 0.7);
		border:2px solid #1c1c1c; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;font-size:12px;
		font-family:arial, helvetica, sans-serif; text-decoration:none; display:inline-block;
		text-shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #FFFFFF;
 background-color: #000000; background-image: -webkit-gradient(linear, left top, left bottom, from(#000000), to(#565756));
 background-image: -webkit-linear-gradient(top, #000000, #565756);
 background-image: -moz-linear-gradient(top, #000000, #565756);
 background-image: -ms-linear-gradient(top, #000000, #565756);
 background-image: -o-linear-gradient(top, #000000, #565756);
 background-image: linear-gradient(to bottom, #000000, #565756);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#000000, endColorstr=#565756);
	}
	
	#strona_upload_plik {
		width: 805px;
		margin: 5px auto;
		padding: 5px 5px;
		font-family: times, Times New Roman, times-roman, georgia, serif;
		font-size: 0.7em;
		color: #FED;
		text-align: left;
		box-shadow: 5px 3px 8px rgba(0, 0, 0, 0.7);
		background: #014;
		border: 1px ridge #aaa;
		border-bottom: 3px outset #888;
		border-radius: 10px 10px 5px 5px;
		overflow-y: auto;
		
		border:2px solid #13167c; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;
		font-size:12px;font-family:arial, helvetica, sans-serif; 
		text-decoration:none; display:inline-block;text-shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #FFFFFF;
 background-color: #1A1FAD; background-image: -webkit-gradient(linear, left top, left bottom, from(#1A1FAD), to(#000036));
 background-image: -webkit-linear-gradient(top, #1A1FAD, #000036);
 background-image: -moz-linear-gradient(top, #1A1FAD, #000036);
 background-image: -ms-linear-gradient(top, #1A1FAD, #000036);
 background-image: -o-linear-gradient(top, #1A1FAD, #000036);
 background-image: linear-gradient(to bottom, #1A1FAD, #000036);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#1A1FAD, endColorstr=#000036);
	}
	
	#strona_upload_sekcja1, #strona_upload_sekcja2, #strona_upload_sekcja3, #strona_upload_sekcja4  {		
		width: 380px;
		font-family: times, Times New Roman, times-roman, georgia, serif;
		font-size: 1em;
		color: #FED;
		padding: 0px;
		float: left;
		text-align: center;
		margin: 0 5px;
	}
	
	#strona_upload_sekcja2 {
		width: 140px;
	}
	
	#strona_upload_sekcja3 {
		width: 120px;
	}
	
	#strona_upload_sekcja4 {
		width: 100px;
	}
	
	.wiz_link {
		outline: none;
		text-decoration: none;
		padding: 2px 1px 0;
		transition: color 2s;
		color: #265C83;
	}
	
	.wiz_link:link {
		color: #80C0FF;
		
	}
	
	.wiz_link:visited {
		color: #20FF20;
	}
	
	.wiz_link:focus {
		border-bottom: 1px solid;
		background: #FAE498;
	}
	
	.wiz_link:hover {
		border-bottom: 1px solid;     
		background: #E0F0FF;
		color: #03a;
		transition: color 3s;
		cursor: pointer;
		text-transform:uppercase;
	}
	
	.wiz_link:active {
		background: #265301;
		transition: color 1s;
		color: #007BE6;
	}
	#wiz_stopka {
		width: 810px;
		height: 18px;
		margin: 0px auto;
		padding: 5px 30px;
		font-family: Pangolin, cursive;
		font-size: 0.9em;
		text-align: center;
		box-shadow: 5px 3px 8px rgba(0, 0, 0, 0.7);
		border-radius: 0px 0px 8px 10px;
		position: relative;
		bottom: 60px;
	}
</style>

<div id="wiz_content" style="background: <?php  echo $w[3]; ?>">
	<div id="wiz_button">
		<input type="button" style="width: 100px" id="button_menu4" class="wiz_zamknij" value="Zamknij">
	</div>
	<div id="wiz_tytul" style="background: <?php  echo $w[2].'; font-family: '.$font_tytul.'; color: '.$w[5]; ?>">
		<?php echo $w[11]; ?>
	</div>
	<div id="wiz_tresc" style="background: <?php  echo $w[4].'; border: '.$w[0].'px ridge '.$w[1].'; font-family: '.$font_tresc.'; color: '.$w[7].';'; ?>">
	<div style="width: 800px; height: 50px; margin: 10px auto;"></div>
<?php
		if (($w[9]!='bf') &&($w[9]!='')) {
			$txt = '';
			if ($w[10]>450) {
				$margin = (900-$w[10])/2;
				$fot = '<div style="margin: 10px '.$margin.'px 10px 0" id="strona_img"><img src="'.$sciezka_img.$w[9].'"></div>';
				$txt = $w[12].$fot;
			} else {
				$fot = '<div style="margin: 0px 0px 0px 10px" id="strona_img"><img src="'.$sciezka_img.$w[9].'"></div>';
				$txt = $fot.$w[12];
			}
		echo $txt;
		} else echo $w[12];
		echo $tup;

	echo '</div>';
	echo '<div id="wiz_stopka" style="background: '.$w[4].'; color: '.$w[7].'">';
			echo '<div style="float: left; margin: 0 0 0 30px">';
				echo 'Autor strony: '.$w[13];
			echo '</div>';
			echo '<div style="float: right; margin: 0 30px 0 0">';
				echo 'Data ostatniej aktualizacji: '.$w[14];
			echo '</div>';	
		echo '</div>';
	echo '</div>';
echo '</body>';
?>

<script type="text/javascript">
	var el = $('#wiz_tytul');
<?php
	echo 'var strona_ns = "'.$_SESSION['strona'].'";';
?>
	$(document).ready(function(){
	
	$('.wiz_zamknij').on("click", function(){
			 $("#wiz_content").animate({
					opacity: '0.0'}, 
					{
					duration: 500,
					easing: 'easeInCubic',
					complete: function() {
						window.location.href = strona_ns+"index.php?m=18";
					}});
	});
	
	$('.wiz_link').on("click", function(){
		var id = $(this).attr('id');
		var idd = $(this).parent().attr('class');
		var nr = idd.slice(1, idd.length);
		$.ajax({
				type:"POST",
				url:"pliki/pobierz.php", 
				dataType: 'json',
				data: {k1: id},
				async: false,
                success: function(json) {					
					var k = json;
					$(".lip"+nr).html(k);
                },
					error: function(blad) {
                    console.log(blad); 
                }
			});
	});
	

		 $(window).bind("keydown", function(Event){
			  if ( event.which == 32 ) {
				window.location.href = "http://localhost/strona/index.php?m=18";
			    event.preventDefault();
			  }
         });
		
 });
</script>