<?php
/*
	@ClassName : ViewListLantai
	@Copyright : PT Gamatechno Indonesia
	@Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
	@Author By : Dyan Galih <galih@gamatechno.com>
	@Version : 0.1
	@StartDate : 2010-02-02
	@LastUpdate : 2010-02-02
	@Description : 
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/gedung/business/Lantai.class.php';

class ViewListLantai extends HtmlResponse {
	
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/gedung/template');
		$this->SetTemplateFile('view_list_lantai.html');
	}
	
	function ProcessRequest() {
		$idGedung = Dispatcher::Instance()->Decrypt($_GET['gId']);
		$objLantai = new Lantai();
		
		$msg = Messenger::Instance()->Receive(__FILE__);
		$notebox['msg'] = $msg[0][1];
		$notebox['css'] = $msg[0][2];
      $return['notebox'] = $notebox;
		
		#set default pagging
		$limit = 20;
		$page = 0;
		$offset = 0;
		
		if(isset($_GET['page'])){
			$page = (string) $_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$offset = ($offset - 1) * $limit;
		}
		
		#fetch data
		$return['data'] = $objLantai->GetListLantai($idGedung,$offset,$limit);
		$return['header'] = $objLantai->GetGedungById($idGedung);
		
		#fethc numrows
		$numrows = $objLantai->GetCountLantai($idGedung);// fetch here;
		
		#pagging url
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule,
			Dispatcher::Instance()->mSubModule,
			Dispatcher::Instance()->mAction,
			Dispatcher::Instance()->mType)
			;
		
		$destination_id = "subcontent-element"; # options: {popup-subcontent,subcontent-element}
		
		#send data to pagging component 
		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top',
		array($limit,$numrows, $url, $page, $destination_id),
		Messenger::CurrentRequest);
		
		#send data to parse method
		$return['start'] = $offset+1;
		$return['page'] = $page;
		$return['numrows'] = $numrows;
		$return['gedung_id'] = $idGedung;
		return $return;
	}

	function ParseTemplate($data = NULL) {
		if($data['notebox']['msg']){
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['notebox']['msg']);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $data['notebox']['css']);
		}
		
		$this->mrTemplate->AddVars('content', $data['header'], 'HEADER_');
		$url_back = Dispatcher::Instance()->GetUrl('gedung', 'gedung', 'view', 'html');
		$this->mrTemplate->AddVar('content', 'URL_BACK', $url_back);
		
		if($data['gedung_id'] <> '1'){
			$url_add = Dispatcher::Instance()->GetUrl('gedung', 'updateLantai', 'view', 'html').
					'&gId='.Dispatcher::Instance()->Encrypt($data['gedung_id']);
			$this->mrTemplate->AddVar('content', 'URL_TAMBAH', $url_add);
		}else $this->mrTemplate->AddVar('content', 'DISPLAY_LINK', 'none');
		
		if (empty($data['data'])) {
				$this->mrTemplate->AddVar('data_grid', 'DATA_EMPTY', 'YES');
			} else {
				$this->mrTemplate->AddVar('data_grid', 'DATA_EMPTY', 'NO');
		
				$dataList = $data['data'];

			for ($i=0; $i<sizeof($dataList); $i++) {
				$no = $i+$data['start'];
				$dataList[$i]['number'] = $no;
		
				if ($no % 2 != 0) 
					$dataList[$i]['class_name'] = 'table-common-even';
				else 
					$dataList[$i]['class_name'] = '';
				
					$dataList[$i]['url_ruang'] = Dispatcher::Instance()->GetUrl('gedung', 'listRuang', 'view', 'html').
					'&gId='.Dispatcher::Instance()->Encrypt($data['gedung_id']).
					'&lantaiId='.Dispatcher::Instance()->Encrypt($dataList[$i]['lantaiId'])
					;
				if($dataList[$i]['lantaiId'] <> '1'){	
					$urlAccept = 'gedung|deleteLantai|do|json-gId-'.$data['gedung_id'];
					$urlReturn = 'gedung|searchLantai|view|html-gId-'.$data['gedung_id'];
					$label = 'Lantai';
					$dataName = $dataList[$i]['nama_lantai'];
					$idEnc = $dataList[$i]['lantaiId'];
					$dataList[$i]['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').
					'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$idEnc.'&label='.$label.'&dataName='.$dataName;
	
					$dataList[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('gedung', 'updateLantai', 'view', 'html').
					'&lantaiId='.Dispatcher::Instance()->Encrypt($dataList[$i]['lantaiId']).
					'&gId='.Dispatcher::Instance()->Encrypt($data['gedung_id']);
				}else{
					$dataList[$i]['display_link'] = 'none';
				}
				$this->mrTemplate->AddVars('data_item', $dataList[$i], 'DATA_');
				$this->mrTemplate->parseTemplate('data_item', 'a');
			}	
		}
	}
}
?>
