<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/hubungan_biaya/business/AppHubunganBiaya.class.php';


class ViewHubunganBiaya extends HtmlResponse {

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/hubungan_biaya/template');
		$this->SetTemplateFile('view_hubungan_biaya.html');
	}
	
	function ProcessRequest() {
		$hubObj = new AppHubunganBiaya();
      if($_POST || isset($_GET['cari'])) {
			if(isset($_POST['hubungan_biaya'])) {
				$hubBiaya = $_POST['hubungan_biaya'];

			} elseif(isset($_GET['hubungan_biaya'])) {
				$hubBiaya = Dispatcher::Instance()->Decrypt($_GET['hubungan_biaya']);
			} else {
				$hubBiaya = '';
			}
		}
	//view
		$totalData = $hubObj->GetCountDataHubunganBiaya($hubBiaya);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		$dataHubunganBiaya = $hubObj->GetDataHubunganBiaya($startRec, $itemViewed,$hubBiaya);
	//print_r($dataHubunganBiaya);
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&hubungan_biaya=' . Dispatcher::Instance()->Encrypt($hubBiaya));

		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);

		$msg = Messenger::Instance()->Receive(__FILE__);
		$return['pesan']=$msg[0][1];
		$return['css']=$msg[0][2];
      $return['search']['hubBiaya']=$hubBiaya;
		$return['dataHubunganBiaya'] = $dataHubunganBiaya;
		$return['start'] = $startRec+1;
   
		return $return;
	}
	
	function ParseTemplate($data = NULL) {
      $search=$data['search'];
      $this->mrTemplate->AddVar('content', 'HUBUNGAN_BIAYA', $search['hubBiaya']);
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('hubungan_biaya', 'inputHubunganBiaya', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('hubungan_biaya', 'hubunganBiaya', 'view', 'html'));
		if($data['pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $data['css']);
		}

		if (empty($data['dataHubunganBiaya'])) {
			$this->mrTemplate->AddVar('data_hubungan_biaya', 'HUBUNGANBIAYA_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_hubungan_biaya', 'HUBUNGANBIAYA_EMPTY', 'NO');
			$dataHubunganBiaya = $data['dataHubunganBiaya'];
		
//mulai bikin tombol delete
			$label = "Data Hubungan Biaya";
			$urlDelete = Dispatcher::Instance()->GetUrl('hubungan_biaya', 'deleteHubunganBiaya', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('hubungan_biaya', 'hubunganBiaya', 'view', 'html');
			Messenger::Instance()->Send('confirm', 'confirmDelete', 'do', 'html', array($label, $urlDelete, $urlReturn),Messenger::NextRequest);
			$this->mrTemplate->AddVar('content', 'URL_DELETE', Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html'));

			for ($i=0; $i<sizeof($dataHubunganBiaya); $i++) {
				$no = $i+$data['start'];
				$dataHubunganBiaya[$i]['number'] = $no;
				//print_r($dataHubunganBiaya);
				if ($no % 2 != 0) $dataHubunganBiaya[$i]['class_name'] = 'table-common-even';
				else $dataHubunganBiaya[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataHubunganBiaya)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataHubunganBiaya[$i]['biaya_id']);
            $urlAccept = 'hubungan_biaya|deleteHubunganBiaya|do|html-cari-'.$cari;
            $urlReturn = 'hubungan_biaya|hubunganBiaya|view|html-cari-'.$cari;
				$dataHubunganBiaya[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('hubungan_biaya', 'inputHubunganBiaya', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage ;
            $dataHubunganBiaya[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataHubunganBiaya[$i]['biaya_id'].'&label='.$label.'&dataName='.$dataHubunganBiaya[$i]['biaya_nama'];
				$this->mrTemplate->AddVars('data_hubungan_biaya_item', $dataHubunganBiaya[$i], 'BIAYA_');
				$this->mrTemplate->parseTemplate('data_hubungan_biaya_item', 'a');	 
			}
		}
	}
}
?>
