<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
require_once('include/global.php');
if (!isset($_SESSION)) session_start();
$db=pDatabase::getInstance();

if(isset($_GET['id'])){
	$query="select 
			t1.`id`,
			t1.`idpelatihan`,
			t1.`iddokumen`,
			t1.`judul`,
			t1.`keterangan`,
			t2.nama_awal,
			t2.nama_baru,
			t2.folder,
			t2.tipefile
		from db_singa.tb_master_pelatihan_dokkonten as t1
		inner join db_singa.tb_dokumen as t2 on t1.iddokumen=t2.id 
		WHERE t1.id=?";
	$rs=$db->loadAssoc($query,array($_GET['id']));
	if(isset($rs['id'])){
		$tipe=strtolower($rs['tipefile']);
		$namaawal=$rs['nama_awal'];
		$filed=HOME_SINDI.'public_html/'.$rs['folder']."/".$rs['nama_baru'];
		if($tipe=="pdf"){
			header('Content-type: application/pdf');
			header('Content-Disposition: inline; filename="'.$namaawal.'"');
			header('Content-Transfer-Encoding: binary');
			header('Content-Length: ' . filesize($filed));
			header('Accept-Ranges: bytes');
		}else if($tipe=="png" || $tipe=="jpg" || $tipe=="jpeg" || $tipe=="bmp"){
			header('Content-type: image');
			header('Content-Disposition: inline; filename="'.$namaawal.'"');
			header('Content-Transfer-Encoding: binary');
			header('Content-Length: ' . filesize($filed));
			header('Accept-Ranges: bytes');
		}else{
			header('Content-type: application/zip');
			header('Content-Disposition: inline; filename="'.$namaawal.'"');
			header('Content-Transfer-Encoding: binary');
			header('Content-Length: ' . filesize($filed));
			header('Accept-Ranges: bytes');
		}
		
		@readfile($filed);
	}
}

?>