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


class ViewJalurMasuk extends HtmlResponse {
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/jalur_masuk/template');
		$this->SetTemplateFile('view_jalur_masuk.html');
	}
	
	function ProcessRequest() {
		$jalurObj = new AppJalurMasukToAdmisi();
      if($_POST || isset($_GET['cari'])) {
			if((isset($_POST['jalur_kode']))or(isset($_POST['jalur_nama']))) {
				$jalurKode = $_POST['jalur_kode'];
				$jalurNama = $_POST['jalur_nama'];
			} elseif((isset($_GET['jalur_kode'])) or (isset($_GET['jalur_nama']))) {
				$jalurKode = Dispatcher::Instance()->Decrypt($_GET['jalur_kode']);
			} else {
				$jalurKode = '';
				$jalurNama = '';
			}
		}
      $totalData = $jalurObj->GetCountDataJalurMasuk($jalurKode,$jalurNama);

		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		$dataJalur = $jalurObj->GetDataJalurMasuk($startRec, $itemViewed,$jalurKode,$jalurNama);
		//print_r($dataJalur);
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&jalur_kode=' . Dispatcher::Instance()->Encrypt($jalurKode) . '&jalur_nama=' . Dispatcher::Instance()->Encrypt($jalurNama). '&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['dataJalur'] = $dataJalur;
		$return['start'] = $startRec+1;

		$return['search']['jalurNama'] = $jalurNama;
		$return['search']['jalurKode'] = $jalurKode;
		return $return;
	}
	
	function ParseTemplate($data = NULL) {
      $search=$data['search'];
      $this->mrTemplate->AddVar('content', 'JALUR_KODE', $search['jalurKode']);
      $this->mrTemplate->AddVar('content', 'JALUR_NAMA', $search['jalurNama']);
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('jalur_masuk', 'inputJalurMasuk', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('jalur_masuk', 'jalurMasuk', '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']);
		}
      //print_r($data['dataJalur']);
		if (empty($data['dataJalur'])) {
			$this->mrTemplate->AddVar('data_jalur', 'JALUR_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_jalur', 'JALUR_EMPTY', 'NO');
			$dataJalur = $data['dataJalur'];
		   // print_r($dataJalur);
//mulai bikin tombol delete
			$label = "Data Jalur Masuk";
			$urlDelete = Dispatcher::Instance()->GetUrl('jalur_masuk', 'deleteJalurMasuk', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('jalur_masuk', 'jalurMasuk', '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($dataJalur); $i++) {
				$no = $i+$data['start'];
				$dataJalur[$i]['number'] = $no;
				//print_r($dataJalur);
				if ($no % 2 != 0) $dataJalur[$i]['class_name'] = 'table-common-even';
				else $dataJalur[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataJalur)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataJalur[$i]['kode_jalur']);
            $urlAccept = 'jalur_masuk|deleteJalurMasuk|do|html-cari-'.$cari;
            $urlReturn = 'jalur_masuk|jalurMasuk|view|html-cari-'.$cari;
				$dataJalur[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('jalur_masuk', 'inputJalurMasuk', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage ;
            $dataJalur[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataJalur[$i]['kode_jalur'].'&label='.$label.'&dataName='.$dataJalur[$i]['nama_jalur'];  
				$this->mrTemplate->AddVars('data_jalur_item', $dataJalur[$i], 'JALUR_');
				$this->mrTemplate->parseTemplate('data_jalur_item', 'a');	 
			}
		}
	}
}
?>
