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

class ViewJenisSmta extends HtmlResponse {

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/jenis_smta/template');
		$this->SetTemplateFile('view_jenis_smta.html');
	}
	
	function ProcessRequest() {
		$jenisSmtaObj = new AppJenisSmta();
		
    if($_POST || isset($_GET['cari'])) {
			if(isset($_POST['jenis_smta'])) {
				$jenis_smta = $_POST['jenis_smta'];
			} elseif(isset($_GET['jenis_smta'])) {
				$jenis_smta = Dispatcher::Instance()->Decrypt($_GET['jenis_smta']);
			} else {
				$jenis_smta = '';
			}
		}
		
	//view
		$totalData = $jenisSmtaObj->GetCountDataJenisSmta($jenis_smta);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		$dataJenisSmta = $jenisSmtaObj->getDataJenisSmta($startRec, $itemViewed, $jenis_smta);
#		print_r($dataJenisSmta);
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&jenis_smta=' . Dispatcher::Instance()->Encrypt($jenis_smta) . '&cari=' . Dispatcher::Instance()->Encrypt(1));

		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['siaPesan'] = $msg[1][1];
		$return['siacss'] = $msg[1][2];

		$return['dataJenisSmta'] = $dataJenisSmta;
		$return['start'] = $startRec+1;

		$return['search']['jenis_smta'] = $jenis_smta;
		return $return;
	}
	
	function ParseTemplate($data = NULL) {
		$search = $data['search'];
		$this->mrTemplate->AddVar('content', 'JENIS_SMTA', $search['jenis_smta']);
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('jenis_smta', 'jenisSmta', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('jenis_smta', 'inputJenisSmta', '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($data['siaPesan']) {
			$this->mrTemplate->SetAttribute('warning_connection', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_connection', 'ISI_PESAN', $data['siaPesan']);
			$this->mrTemplate->AddVar('warning_connection', 'CLASS_PESAN', $data['siacss']);
		}

		if (empty($data['dataJenisSmta'])) {
			$this->mrTemplate->AddVar('data_jenis_smta', 'JENIS_SMTA_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_jenis_smta', 'JENIS_SMTA_EMPTY', 'NO');
			$dataJenisSmta = $data['dataJenisSmta'];
		
//mulai bikin tombol delete
			$label = "Data Jenis SMTA";
			$urlDelete = Dispatcher::Instance()->GetUrl('jenis_smta', 'deleteJenisSmta', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('jenis_smta', 'jenisSmta', '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($dataJenisSmta); $i++) {
				$no = $i+$data['start'];
				$dataJenisSmta[$i]['number'] = $no;
				if ($no % 2 != 0) $dataJenisSmta[$i]['class_name'] = 'table-common-even';
				else $dataJenisSmta[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataJenisSmta)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataJenisSmta[$i]['jenis_smta_id']);
               
            $urlAccept = 'jenis_smta|deleteJenisSmta|do|html-cari-'.$cari;
            $urlReturn = 'jenis_smta|jenisSmta|view|html-cari-'.$cari;
            $dataName = $dataJenisSmta[$i]['jenis_smta_nama']; 
				$dataJenisSmta[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('jenis_smta', 'inputJenisSmta', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage . '&cari='.$cari;
            $dataJenisSmta[$i]['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$idEnc.'&label='.$label.'&dataName='.$dataName;
				
            $this->mrTemplate->AddVars('data_jenis_smta_item', $dataJenisSmta[$i], 'JENIS_SMTA_');
				$this->mrTemplate->parseTemplate('data_jenis_smta_item', 'a');	 
			}
		}
	}
}
?>
