<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/setting_ktm/business/AppSettingKtm.class.php';
class ViewSettingKtm extends HtmlResponse {
	
   function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/setting_ktm/template');
		$this->SetTemplateFile('view_setting_ktm.html');
	}
	
	function ProcessRequest() {
		$sktmObj = new AppSettingKtm();
		$msg = Messenger::Instance()->Receive(__FILE__);
		$return['Pesan'] = $msg[0][1];
		$return['css'] = $msg[0][2];
		#print_r($msg);
		
		
	//view
		$totalData = $sktmObj->GetCountDataSettingKtm($settingKtmId);
      $itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		$dataSettingKtm = $sktmObj->GetDataSettingKtm($startRec, $itemViewed);
		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);
		
		$return['dataSettingKtm'] = $dataSettingKtm;
		$return['start'] = $startRec+1;
		
		return $return;
	}
	
	function ParseTemplate($data = NULL) {
      //print_r($data);
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('setting_ktm', 'inputSettingKtm', '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['dataSettingKtm'])) {
			$this->mrTemplate->AddVar('data_setting_ktm', 'SETTING_KTM_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_setting_ktm', 'SETTING_KTM_EMPTY', 'NO');
			$dataSettingKtm = $data['dataSettingKtm'];
		
         //mulai bikin tombol delete
			$label = "Setting Ktm";
			$urlDelete = Dispatcher::Instance()->GetUrl('setting_ktm', 'deleteSettingKtm', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('setting_ktm', 'settingKtm', '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($dataSettingKtm); $i++) {
				$no = $i+$data['start'];
				$dataSettingKtm[$i]['number'] = $no;
				if ($no % 2 != 0) $dataSettingKtm[$i]['class_name'] = 'table-common-even';
				else $dataSettingKtm[$i]['class_name'] = '';
            $idEnc = Dispatcher::Instance()->Encrypt($dataSettingKtm[$i]['id']);
            $dataSettingKtm[$i]['url_aktif'] = Dispatcher::Instance()->GetUrl('setting_ktm', 'aktifSettingKtm', 'do', 'html') . '&dataId=' . $idEnc;
				
            if ($dataSettingKtm[$i]['is_aktif']=='0'){
               $dataSettingKtm[$i]['is_aktif'] = 'Tidak Aktif';
               $this->mrTemplate->AddVar('aktif','IS_SHOW_AKTIFKAN','YES');
               $this->mrTemplate->AddVar('aktif','SETTING_KTM_URL_AKTIF',$dataSettingKtm[$i]['url_aktif']);
            } else {
               $dataSettingKtm[$i]['is_aktif'] = 'Aktif';
               $dataSettingKtm[$i]['class_name'] = 'active';
               $this->mrTemplate->AddVar('aktif','IS_SHOW_AKTIFKAN','NO');
            }
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataSettingKtm)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
                             
            $urlAccept = 'setting_ktm|deleteSettingKtm|do|html-cari-'.$cari;            
            $urlReturn = 'setting_ktm|SettingKtm|view|html-cari-'.$cari;
                
            $idEnc = Dispatcher::Instance()->Encrypt($dataSettingKtm[$i]['id']);
            
              $dataSettingKtm[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('setting_ktm', 'inputSettingKtm', 'view', 'html') . 
                 '&dataId=' . $idEnc . '&page=' . $encPage . '&cari='.$cari;
                 
              $dataSettingKtm[$i]['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').
                 '&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$idEnc.
                 '&label='.$label.'&dataName='.$dataSettingKtm[$i]['jabatan'].' '.$dataSettingKtm[$i]['nama_pejabat'];
                 
              $dataSettingKtm[$i]['url_detail'] = Dispatcher::Instance()->GetUrl('setting_ktm', 'detailSettingKtm', 'view', 'html') . 
                 '&dataId=' . $idEnc . '&page=' . $encPage . '&cari='.$cari;
                 
              $dataSettingKtm[$i]['url_ttd'] = Dispatcher::Instance()->GetUrl('setting_ktm', 'inputTandaTangan', 'view', 'html') . 
                 '&dataId=' . $idEnc . '&page=' . $encPage . '&cari='.$cari;
               
            $this->mrTemplate->AddVars('data_setting_ktm_item', $dataSettingKtm[$i], 'SETTING_KTM_');
				$this->mrTemplate->parseTemplate('data_setting_ktm_item', 'a');	 
			}
		}
	}
}
?>