<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/predikat_lulus/business/AppPredikatLulus.class.php';
class ViewPredikatLulus extends HtmlResponse {

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/predikat_lulus/template');
		$this->SetTemplateFile('view_predikat_lulus.html');
	}
	
	function ProcessRequest() {
      $predikatObj=new AppPredikatLulus();
 
		if($_POST || isset($_GET['cari'])) {
			if((isset($_POST['nama_lokal']))or (isset($_POST['nama_asing']))) {
				$namaLokal = $_POST['nama_lokal'];
				$namaAsing = $_POST['nama_asing'];
			} elseif((isset($_GET['nama_lokal'])) or (isset($_GET['nama_asing']))) {
				$namaLokal = Dispatcher::Instance()->Decrypt($_GET['nama_lokal']);
				$namaAsing = Dispatcher::Instance()->Decrypt($_GET['nama_asing']);
			} else {
				$namaLokal='';
				$namaAsing='';
			}
		}
      $totalData = $predikatObj->GetCountDataPredikatLulus($namaLokal,$namaAsing);
    //print($totalData);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
    
		$dataPredikat = $predikatObj->GetDataPredikatLulus($startRec,$itemViewed,$namaLokal,$namaAsing);
	//print_r($dataPredikat);
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&nama_lokal=' . Dispatcher::Instance()->Encrypt($namaLokal) . '&nama_lokal=' . Dispatcher::Instance()->Encrypt($namaAsing) . '&cari=' . Dispatcher::Instance()->Encrypt(1));

		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);
    //print_r($dataKota);
		$msg = Messenger::Instance()->Receive(__FILE__);
		
      $return['pesan']=$msg[0][1];
      $return['css']=$msg[0][2];
		$return['dataPredikat'] = $dataPredikat;
		$return['search']['namaLokal']=$namaLokal;
		$return['search']['namaAsing']=$namaAsing;
	   $return['start'] = $startRec+1;
		return $return;
	}
	
	function ParseTemplate($data = NULL) {
      $search=$data[$search];
      $this->mrTemplate->AddVar('content', 'NAMA_LOKAL', $search['namaLokal']);
      $this->mrTemplate->AddVar('content', 'NAMA_ASING', $search['namaAsing']);
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('predikat_lulus', 'predikatLulus', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('predikat_lulus', 'inputPredikatLulus', '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['dataPredikat'])) {
			$this->mrTemplate->AddVar('data_predikat', 'PREDIKAT_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_predikat', 'PREDIKAT_EMPTY', 'NO');
			$dataPredikat = $data['dataPredikat'];
		
//mulai bikin tombol delete
			$label = "Data Predikat lulus";
			$urlDelete = Dispatcher::Instance()->GetUrl('predikat_lulus', 'deletePredikatLulus', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('predikat_lulus', 'predikatLulus', '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($dataPredikat); $i++) {
				$no = $i+$data['start'];
				$dataPredikat[$i]['number'] = $no;
				//print_r($dataPredikat);
				if ($no % 2 != 0) $dataPredikat[$i]['class_name'] = 'table-common-even';
				else $dataPredikat[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataPredikat)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataPredikat[$i]['predikat_id']);
            $urlAccept = 'predikat_lulus|deletePredikatLulus|do|html-cari-'.$cari;
            $urlReturn = 'predikat_lulus|predikatLulus|view|html-cari-'.$cari;
				$dataPredikat[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('predikat_lulus', 'inputPredikatLulus', 'view', 'html') . '&dataId=' . $idEnc. '&page=' . $encPage  ;
            $dataPredikat[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataPredikat[$i]['predikat_id'].'&label='.$label.'&dataName='.$dataPredikat[$i]['predikat_nama'];
				$this->mrTemplate->AddVars('data_predikat_item', $dataPredikat[$i], 'PREDIKAT_');
				$this->mrTemplate->parseTemplate('data_predikat_item', 'a');	 
			}
		}
	}
}
?>
