<?php
/**
* @package : PopupGedung
* @copyright : Copyright (c) PT Gamatechno Indonesia
* @Analyzed By : Nanang Ruswianto
* @author : Didi Zuliansyah
* @version : 01
* @startDate : 2013-01-01
* @lastUpdate : 2013-01-01
* @description : Class PopupGedung
*/

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

class PopupGedung extends HtmlResponse {

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
		$this->SetTemplateFile('popup_gedung.html');
	}

	function ProcessRequest() {
		$msg = Messenger::Instance()->Receive(__FILE__);
		$obj = new jadwalRuang();
		
		if (isset($_GET['page'])) $post = @$msg[0][0];
		else $post = $_POST->AsArray();
		
		# ----- SEARCH FIELD ----- #
		if(empty($post)) $name = '';
		else{
			Messenger::Instance()->Send(Dispatcher::Instance()->mModule,Dispatcher::Instance()->mSubModule,Dispatcher::Instance()->mAction,Dispatcher::Instance()->mType,array($post),Messenger::UntilFetched);
			$name = $post['name'];
			$return['search'] = $post;
		}
		# ----- END SEARCH FIELD ----- #
		
		$limit = 20;
		$page = 0;
		$offset = 0;
		
		if(isset($_GET['page'])){
			$page = (string) $_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$offset = ($page - 1) * $limit;
		}
		
		$return['data'] = $obj->getListGedung($name,$offset, $limit);
		$numrows = $obj->GetCount();
		
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule,Dispatcher::Instance()->mSubModule,Dispatcher::Instance()->mAction,Dispatcher::Instance()->mType);
		$destination_id = "popup-subcontent";

		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top',array($limit,$numrows, $url, $page, $destination_id),Messenger::CurrentRequest);
		$return['start'] = $offset+1;
		
		return $return;
	}

	function ParseTemplate($data = NULL) {
		$urlSearch = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule,Dispatcher::Instance()->mSubModule,Dispatcher::Instance()->mAction,Dispatcher::Instance()->mType);
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', $urlSearch);
		if(count(@$data['search']) > 0) $this->mrTemplate->AddVars('content', $data['search'], '');
		
		if (empty($data['data'])) {
			$this->mrTemplate->AddVar('data_grid', 'DATA_EMPTY', 'YES');
		}else{
			$this->mrTemplate->AddVar('data_grid', 'DATA_EMPTY', 'NO');
		
			$dataList = $data['data'];$i=0;
			foreach($dataList as $value) {
				$value['nomor'] = $i+$data['start'];
		
				if ($value['nomor'] % 2 != 0) $value['class_name'] = 'table-common-even';
				else $value['class_name'] = '';
		
				$this->mrTemplate->AddVars('data_item', $value, '');
				$this->mrTemplate->parseTemplate('data_item', 'a');
				$i++;
			}
		}
	}
}
?>