<?php
	$id = intval($_GET['id']);
	$userid = intval($_GET['user']);
	$data = DB :: $pdo -> queryFetch("SELECT * FROM `{$table_a}` WHERE `id` = ? AND `id_user` = ? LIMIT 1;", array($id, $userid));
	
	if(!isset($data['id'])){ system :: redirect("Альбома не существует.", "{$thisLink}{$userid}", 1); }
	
	if(isset($_GET['upload']) && $user['id'] == $data['id_user']){ require("upload_photo.php"); }
	if(isset($_GET['edits']) && $user['id'] == $data['id_user']){ require("edit_album.php"); }
	if(isset($_GET['vid'])){ require("vid.php"); }

    /*
        Author: Serezha
        Date: 11.05.18
    */
    
	if (isset($_GET['remove']) && $user['id'] == $data['id_user'])
	{
	    require_once ("remove_album.php"); 
	    
	    exit;
	}
	
	$title = "Фотографии - Просмотр альбома";
	$l = "Фотографии - Просмотр альбома";
	$lBack = "{$thisLink}{$userid}";
	require (CORE."head.php");
	echo "<div class=\"app-block\">";
	$back = system :: back("{$thisLink}{$userid}", "Все альбомы", true);
	

	?>
		<?php
	 if ($user['vid'] == 0) {
		$query = "SELECT * FROM `{$table}` WHERE `id_user` = ? AND `id_album` = ? ORDER by `time` DESC ";
	 }else{
	     	$query = "SELECT * FROM `{$table}` WHERE `id_user` = ? AND `id_album` = ? ORDER by `time` ASC ";
	 }
	
	    $total = $data['count'];
		if($total > 12) {
		$p = (($_GET['p']) ? intval($_GET['p']) : 1);
		$pagination = new pagination(12, $total, $p);
		$query .= $pagination -> limit;
		}
		$q = DB :: $pdo -> query("{$query}", array($data['id_user'], $data['id']));

		$i = 0;
		$in = 0;
		
		?>

	
		<?php
				if($user['id'] == $data['id_user'] ){ 
					echo "<div class=\"_oh\" style=\"background: #FFF;\"><a href=\"{$thisLink}{$user['id']}/album{$data['id']}/?upload=1\" class=\"app-action\">".system :: ico('add')." ".language::text('add', $language, 'photo')."</a></div>"; }
					echo "	<div class=\"_photos-main list\">
						<div class=\"_center\">
							<div><span class=\"_font-big _bold\">{$data['name']}</span> <span class=\"_fl-r\">".($user['vid'] == 0 ? "<a href=\"{$thisLink}{$data['id_user']}/album{$data['id']}?vid=1\"><i class=\"our our-reverse\"></i></a>" : "<a href=\"{$thisLink}{$data['id_user']}/album{$data['id']}?vid=1\"><i class=\"our our-reverse2\"></i></a>" )." </span></div> 
							<span class=\"_gray\">".( $data['text'] != NULL ? "{$data['text']}<span class=\"divide\">|</span>" : '' )."{$data['count']} фотографи".profile :: getPhrase($data['count'], array('я','ии','ий'))." ".($user['id'] == $data['id_user'] ? "<span class=\"divide\">|</span><a href=\"{$thisLink}{$user['id']}/album{$data['id']}/?edits=1\">Редактировать альбом</a>" : '' )."</span>
						</div><div class=\"_m-top-x2\">
						";



		while($r = $q -> fetch()) {
			++$i;
		?>
			<a href="<?=$thisLink."{$userid}/view{$r['id']}?{$att['l']}"?>" class="_photos-item">
				<div class="_photos-item-padd">
				<div class="_photos-cont">
					<div class="_photos-ph">
						<div class="_photos-ph-t"><img src="<?=FILES_SERVER.system :: photosGetView($r['hash'],3)?>" class="_photos-prew">
						</div>
					</div>
				</div>
				</div>
			</a>
		<?php
		}
		if($i == 0){
			echo "<div class=\"_center _gray _font-s\" style=\"padding: 10px;\">Фотографии в альбоме отсутствуют.</div>";
		}
	echo "</div></div>";
	if($total > 12) echo $pagination -> printPages("{$thisLink}{$userid}/album{$id}?{$att['l']}&"); 
	echo $back;
	echo "</div>";
	require (CORE."foot.php");