<?php

require_once GTFWConfiguration::GetValue( 'application', 'docroot').'module/'.Dispatcher::Instance()->mModule.'/business/AppGedung.class.php';

class ViewCetakGedung extends HtmlResponse {	
	
	function ProcessRequest() {	
		$gedungObj = new AppGedung();
		
		$tahun =Dispatcher::Instance()->Decrypt($_GET['thn']);
		$sbr_dana =Dispatcher::Instance()->Decrypt($_GET['sbr_dana']);
		$kepemilikan =Dispatcher::Instance()->Decrypt($_GET['kepemilikan']);
		$lokasi =Dispatcher::Instance()->Decrypt($_GET['lokasi']);
		$kondisi =Dispatcher::Instance()->Decrypt($_GET['kondisi']);
		$key =Dispatcher::Instance()->Decrypt($_GET['gedung']);
		
		if($tahun=='')$tahun='all';
		if($sbr_dana=='')$sbr_dana='all';
		if($kepemilikan=='')$kepemilikan='all';
		if($lokasi=='')$lokasi='all';
		if($kondisi=='')$kondisi='all';
		
		$dataGedung = $gedungObj->GetDataPrintGedung($tahun, $sbr_dana, $kepemilikan, $lokasi, $kondisi, $key);
		
		$contents = file_get_contents(GTFWConfiguration::GetValue( 'application', 'docroot')."doc/template_gedung.rtf");
		$contents = str_replace('[NAMA_COMPANY]',GTFWConfiguration::GetValue('organization', 'company_name'), $contents);
		$contents = str_replace('[HEADER]', 'Data Gedung', $contents);
		
		for ($i=0; $i<sizeof($dataGedung); $i++) {
		$no = $i+1;
		$nomor .= ' '.$no.'.'.'\par';
		$kode .= ' '.$dataGedung[$i]['gedung_kode'].'\par';
		$nama .= ' '.$dataGedung[$i]['gedung_nama'].'\par';
		}
		
		$contents = str_replace('[NOMOR]',$nomor, $contents);
		$contents = str_replace('[NAMA_GEDUNG]',$nama, $contents);
		$contents = str_replace('[KODE_GEDUNG]',$kode, $contents);
		
		header("Content-type: application/msword");
		header("Content-disposition: inline; filename=gedung_". (date('d-m-Y')).".rtf");
		header("Content-length: " . strlen($contents));
		print $contents;
      
	}
   
}
?>
