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

class ViewJenjangAkademik extends HtmlResponse{
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/jenjang_akademik/template');
		$this->SetTemplateFile('view_jenjang_akademik.html');
	}
   function ProcessRequest() {
		$jjObj = new AppJenjangAkademikToAdmisi();
		if($_POST || isset($_GET['cari'])) {
			if((isset($_POST['jenjang_kode']))or(isset($_POST['jenjang_kode_dikti']))or(isset($_POST['jenjang_nama']))){
				$jenjangKode = $_POST['jenjang_kode'];
            $jenjangKodeDikti=$_POST['jenjang_kode_dikti'];
            $jenjangNama=$_POST['jenjang_nama'];
			} elseif((isset($_GET['jenjang_kode']))or(isset($_GET['jenjang_kode_dikti']))or(isset($_GET['jenjang_nama']))) {
				$jenjangKode = Dispatcher::Instance()->Decrypt($_GET['jenjang_kode']);
            $jenjangKodeDikti=Dispatcher::Instance()->Decrypt($_GET['jenjang_kode_dikti']);
            $jenjangNama=Dispatcher::Instance()->Decrypt($_GET['jenjang_nama']);
			} else {
				$jenjangKode = '';
            $jenjangKodeDikti='';
            $jenjangNama='';
			}
		}
      $totalData = $jjObj->GetCountDataJenjangAkademik($jenjangKode,$jenjangKodeDikti,$jenjangNama);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
      if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
      $dataJenjangAkademik=$jjObj->GetDataJenjangAkademik($jenjangKode,$jenjangKodeDikti,$jenjangNama,$startRec,$itemViewed);
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&jenjang_kode=' . Dispatcher::Instance()->Encrypt($jenjangKode) . '&jenjang_kode_dikti=' . Dispatcher::Instance()->Encrypt($jenjangKodeDikti) . '&jenjang_nama=' . Dispatcher::Instance()->Encrypt($jenjangNama) . '&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['dataJenjangAkademik'] = $dataJenjangAkademik;
		$return['start'] = $startRec+1;
		$return['search']['jenjang_kode'] = $jenjangKode;
      $return['search']['jenjang_kode_dikti']=$jenjangKodeDikti;
      $return['search']['jenjang_nama']=$jenjangNama;
		return $return;
   }

   function ParseTemplate($data = NULL) {
		$search = $data['search'];
		$this->mrTemplate->AddVar('content', 'JENJANG_KODE', $search['jenjang_kode']);
      $this->mrTemplate->AddVar('content', 'JENJANG_KODE_DIKTI', $search['jenjang_kode_dikti']);
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('jenjang_akademik', 'jenjangAkademik', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('jenjang_akademik', 'inputJenjangAkademik', '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['dataJenjangAkademik'])) {
			$this->mrTemplate->AddVar('data_jenjang_akademik', 'JENJANG_AKADEMIK_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_jenjang_akademik', 'JENJANG_AKADEMIK_EMPTY', 'NO');
			$dataJenjangAkademik = $data['dataJenjangAkademik'];
        
         $label = "Data Jenjang Akademik";
			$urlDelete = Dispatcher::Instance()->GetUrl('jenjang_akademik', 'deleteJenjangAkademik', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('jenjang_akademik', 'jenjangAkademik', '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($dataJenjangAkademik); $i++) {
				$no = $i+$data['start'];
				$dataJenjangAkademik[$i]['number'] = $no;
				if ($no % 2 != 0) $dataJenjangAkademik[$i]['class_name'] = 'table-common-even';
				else $dataJenjangAkademik[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataJenjangAkademik)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataJenjangAkademik[$i]['jenjang_kode']);
            $urlAccept = 'jenjang_akademik|deleteJenjangAkademik|do|html-cari-'.$cari;
            $urlReturn = 'jenjang_akademik|jenjangAkademik|view|html-cari-'.$cari;
				$dataJenjangAkademik[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('jenjang_akademik', 'inputJenjangAkademik', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage . '&cari='.$cari;
            $dataJenjangAkademik[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataJenjangAkademik[$i]['jenjang_kode'].'&label='.$label.'&dataName='.$dataJenjangAkademik[$i]['jenjang_nama'];     
				$this->mrTemplate->AddVars('data_jenjang_akademik_item', $dataJenjangAkademik[$i], 'JENJANG_');
				$this->mrTemplate->parseTemplate('data_jenjang_akademik_item', 'a');	 
			}
		}
   }
}
?>
