<?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_main_download">
	<a href="<?php echo NPAGE.'download';?>">
		<h2>DAFTAR DOWNLOAD</h2>
	</a>
	<?php
	include 'module/mod_cari/mod_cari.php';
	$halaman=1;
	$jumlahbaris=20;
	if(isset($_GET['page']) && $_GET['page']>0){
		$halaman=$_GET['page'];
	}
	$page->addLoad("daftardownload.sethalaman(".$halaman.")");
	$posisihalaman=$halaman-1;
	
	$whd="";
	$datapush=array();
	if(isset($_GET['mcari'])){
		$mcari=$_GET['mcari'];
		$mcr="%$mcari%";
		$whd.="and t1.nama like ? ";
		array_push($datapush,$mcr);
	}
	
	array_push($datapush,$posisihalaman,$jumlahbaris);
	
	$query="select SQL_CALC_FOUND_ROWS t1.id,
			t1.id,
			t1.tanggal,t1.nama,t1.keterangan,
			t2.nama_awal,t1.iddokumen from tb_download as t1
			inner join tb_dokumen as t2 on t1.iddokumen=t2.id
			where t1.status=1 ".$whd."order by tanggal desc limit ?,? ";
	$rsdownload=$db->getObj($query,$datapush);
	echo "<div class='box_ket_download'>";
	if(sizeof($rsdownload)>0){
		?>
		<p class="default_text" style="margin-bottom: 30px;">Silahkan klik pada tombol download file untuk mengunduh file sesuai nama file yang diinginkan.</p>
		<?php
	}else{
		?>
		<p class="default_text" style="margin-bottom: 30px;">Tidak ada data.</p>
		<?php
	}
	echo "</div>";
	$jumlahhalaman=1;
	$qrow="SELECT FOUND_ROWS() as totalbaris;";
	$rsrow=$db->loadAssoc($qrow);
	if(isset($rsrow['totalbaris'])){
		$jumlahhalaman=ceil($rsrow['totalbaris']/$jumlahbaris);
	}
	
	foreach ($rsdownload 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);
		}
		$tautan=NPAGE."unduh/".$obj->iddokumen;
		?>
		<div class="box_mainfile_download">
			<div class="box_file_download">
				<div style="float: left;">
					<b>Nama File</b>
					<div><?php echo $obj->nama;?></div>
				</div>
				<div style="float: right;"><?php echo $obj->tanggal;?></div>
				<div style="clear: both;"></div>
				
				<div style="margin-top: 5px;">
					<a class="button orange" style="padding: 5px 3px;" href="<?php echo $tautan;?>">DOWNLOAD FILE</a>
				</div>
				<div style="margin-top: 6px;">Keterangan</div>
				<i><?php echo $obj->keterangan;?></i>
			</div>
			<div style="clear: both;"></div>
			
		</div>
		<?php
	}
	?>
	
</div>
<div class="box_halaman">
	Halaman: <select id="sl_halaman" onchange="daftardownload.gantihalaman()">
		<?php
		for($i=0;$i<$jumlahhalaman;$i++){
			?>
			<option value="<?php echo ($i+1);?>"><?php echo ($i+1);?></option>
			<?php
		}
		?>
	</select>
</div>