<?php

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

class ViewCetakRuang extends HtmlResponse {	
	
	function ProcessRequest() {	
		$ruangObj = new Ruang();
		
		$idGedung=Dispatcher::Instance()->Decrypt($_GET['idGedung']);
		$jnsRuangId=Dispatcher::Instance()->Decrypt($_GET['jnsRuangId']);
		$tipeRuangId=Dispatcher::Instance()->Decrypt($_GET['tipeRuangId']);
		$key=Dispatcher::Instance()->Decrypt($_GET['key']);
		$lantaiId=Dispatcher::Instance()->Decrypt($_GET['lantaiId']);
		
		$dataRuang = $ruangObj ->GetDataPrintRuang($idGedung,$jnsRuangId, $tipeRuangId, $key, $lantaiId);	
		
		$contents = file_get_contents(GTFWConfiguration::GetValue( 'application', 'docroot')."doc/template_ruang.rtf");
		$contents = str_replace('[NAMA_COMPANY]',GTFWConfiguration::GetValue('organization', 'company_name'), $contents);
		$contents = str_replace('[HEADER]', 'Data Gedung', $contents);
		$contents = str_replace('[KODE_GEDUNG]', $dataRuang[0]['kode_gedung'], $contents);
		$contents = str_replace('[NAMA_GEDUNG]', $dataRuang[0]['nama_gedung'], $contents);
		
		for ($i=0; $i<sizeof($dataRuang); $i++) {
		$no = $i+1;
		$nomor .=' '. $no.'.' .'\par';
		$kode .= ' '.$dataRuang[$i]['kode'].'\par';
		$nama .= ' '.$dataRuang[$i]['nama'].'\par';
		}
		
		$contents = str_replace('[NOMOR]',$nomor, $contents);
		$contents = str_replace('[NAMA_RUANG]',$nama, $contents);
		$contents = str_replace('[KODE_RUANG]',$kode, $contents);
		
		header("Content-type: application/msword");
		header("Content-disposition: inline; filename=ruang_". (date('d-m-Y')).".rtf");
		header("Content-length: " . strlen($contents));
		print $contents;
      
	}
   
}
?>
