<?php
if(count(get_included_files())==1) exit("Direct access not permitted.");
$mod = basename(__FILE__, '.php');
$page->tbCss($mod);
$page->tbJs($mod);
?>
<div class="box_daftargallery">
	<?php
	$judulhalaman="GALLERY BALAI";
	$linkkategori="?";
	
	$wh="";
	$datapush=array();
	$kategori=0;
	if(isset($_GET['kategori'])){
		$kategori=$_GET['kategori'];
		$wh.="and t1.idkategori=? ";
		array_push($datapush,$kategori);
		
		$query="select nama from tb_album_kategori where id=?";
		$rskat=$db->loadAssoc($query,array($kategori));
		
		if(isset($rskat['nama'])) $judulhalaman=$rskat['nama'];
		
		$linkkategori.="kategori=".$kategori."&";
	}
	?>
	<h2><?php echo strtoupper($judulhalaman);?></h2>
	<?php
	$halaman=1;
	$jumlahbaris=14;
	if(isset($_GET['page']) && $_GET['page']>0){
		$halaman=$_GET['page'];
	}
	
	$datapost=array("idkategori"=>$kategori,"halaman"=>$halaman);
	$page->addLoad("daftargallery.sethalaman(".json_encode($datapost,true).")");
	
	$posisihalaman=$halaman-1;
	
	
	array_push($datapush,$posisihalaman,$jumlahbaris);
	
	$query="select SQL_CALC_FOUND_ROWS t1.id,
			t1.id,t1.tanggal,t1.nama,
			t1.idkategori,
			t1.keterangan,t1.idgambar,
			t3.nama as kategori,
			t2.nama_baru,t2.folder,
			t3.nama as kategori
		from tb_album as t1
		inner join tb_dokumen as t2 on t1.idgambar=t2.id
		inner join tb_album_kategori as t3 on t1.idkategori=t3.id
		where t1.status=1 ".$wh."order by t1.tanggal desc limit ?,? ";
	$rsinformasi=$db->loadAll($query,$datapush);
	
	$jumlahhalaman=1;
	$qrow="SELECT FOUND_ROWS() as totalbaris;";
	$rsrow=$db->loadAssoc($qrow);
	if(isset($rsrow['totalbaris'])){
		$jumlahhalaman=ceil($rsrow['totalbaris']/$jumlahbaris);
	}
	$posisifambar=0;
	foreach ($rsinformasi as $obj) {
		$haltgl=explode(" ", $db->halfdate($obj['tanggal']));
		$dd="";
		$mm="";
		$yy="";
		if(sizeof($haltgl)==3){
			$dd=$haltgl[0];
			$mm=$haltgl[1];
			$yy=$haltgl[2];
		}
		
		$arrtgl=explode(" ", $obj['tanggal']);
		$jam="";
		if(sizeof($arrtgl)==2){
			$jam=substr($arrtgl[1], 0,5);
		}
		$marginkiri="";
		if(($posisifambar % 2) != 0){
			$marginkiri="box_mod_album_margin";
		}
		$gambargallery=NPAGE.$obj['folder'].$obj['nama_baru'];
		$linkgallery=NPAGE.'album/?id='.$obj['id'];
		$linkkategori=NPAGE.'album/?kategori='.$obj['idkategori'];
		?>
		<div class="box_mod_album <?php echo $marginkiri;?>">
			<a href="<?php echo $linkgallery;?>">
				<div class="box_mod_album_gambar">
					<img src="<?php echo $gambargallery;?>" />
				</div>
			</a>
			<div style="clear: both;"></div>
			<div class="box_mod_album_isi">
				<div class="nama_gallery"><?php echo $haltgl[0]." ".$haltgl[1]." ".$haltgl[2]." - ".$jam;?></div>
				<div>Nama Gallery</div>
				<div class="nama_gallery"><?php echo $obj['nama'];?></div>
				<div>Kategori</div>
				<a href="<?php echo $linkkategori;?>">
					<div class="nama_gallery"><?php echo $obj['kategori'];?></div>
				</a>
			</div>
			<div style="clear: both;"></div>
		</div>
		<?php
		$posisifambar++;
	}
	?>
	
</div>
<div class="box_halaman">
	Halaman: <select id="sl_halaman" onchange="daftargallery.gantihalaman()">
		<?php
		for($i=0;$i<$jumlahhalaman;$i++){
			?>
			<option value="<?php echo ($i+1);?>"><?php echo ($i+1);?></option>
			<?php
		}
		?>
	</select>
</div>