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

class ViewTahapPenerimaan extends HtmlResponse {

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/tahap_penerimaan/template');
		$this->SetTemplateFile('view_tahap_penerimaan.html');
	}
	
	function ProcessRequest() {
		$thpObj = new AppTahapPenerimaan();
		if($_POST || isset($_GET['cari'])) {
			if(isset($_POST['tahap'])) {
				$tahap = $_POST['tahap'];
			} elseif(isset($_GET['tahap'])) {
				$tahap = Dispatcher::Instance()->Decrypt($_GET['tahap']);
			} else {
				$tahap = '';
			}
		}
		
//view
		$totalData = $thpObj->GetCountDataJurusanSmta($tahap);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
	
		$dataTahap = array(
              0=>array('number'=>1,'tahap_kode'=>'1','tahap_nama'=>'Tahap 1','tahap_jenis_tes'=>'Tertulis'),
              1=>array('number'=>2,'tahap_kode'=>'2','tahap_nama'=>'Tahap 2','tahap_jenis_tes'=>'Psikotest'),
              2=>array('number'=>3,'tahap_kode'=>'3','tahap_nama'=>'Tahap 3','tahap_jenis_tes'=>'Kesamaptaan')
      );

		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&jurusan=' . Dispatcher::Instance()->Encrypt($jurusan) . '&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['dataJurusan'] = $dataTahap;
		$return['start'] = $startRec+1;
		$return['search']['tahap'] = $jurusan;
		return $return;
	}
	
	function ParseTemplate($data = NULL) {
		$search = $data['search'];
		$this->mrTemplate->AddVar('content', 'JURUSAN', $search['tahap']);
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('tahap_penerimaan', 'TahapPenerimaan', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('tahap_penerimaan', 'InputTahapPenerimaan', '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['dataJurusan'])) {
			$this->mrTemplate->AddVar('data_jurusan', 'JURUSAN_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_jurusan', 'JURUSAN_EMPTY', 'NO');
			$dataTahap = $data['dataJurusan'];
		
//mulai bikin tombol delete
			$label = "Data Tahap Penerimaan";
			$urlDelete = Dispatcher::Instance()->GetUrl('tahap_penerimaan', 'DeleteTahapPenerimaan', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('tahap_penerimaan', 'TahapPenerimaan', '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($dataTahap); $i++) {
				$no = $i+$data['start'];
				$dataTahap[$i]['number'] = $no;
				if ($no % 2 != 0) $dataTahap[$i]['class_name'] = 'table-common-even';
				else $dataTahap[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataTahap)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataTahap[$i]['jurusan_kode']);
            $urlAccept = 'tahap_penerimaan|deleteTahapPenerimaan|do|html-cari-'.$cari;
            $urlReturn = 'tahap_penerimaan|TahapPenerimaan|view|html-cari-'.$cari;
            
				$dataTahap[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('tahap_penerimaan', 'inputTahapPenerimaan', 'view', 'html') . 
               '&dataId=' . $dataTahap[$i]['number'] . '&page=' . $encPage . '&cari='.$cari;

            $dataTahap[$i]['url_detail'] = Dispatcher::Instance()->GetUrl('tahap_penerimaan', 'detailTahapPenerimaan', 'view', 'html') . 
               '&dataId=' . $idEnc . '&nama=' . $dataTahap[$i]['tahap_nama'] . '&no_daftar=' . $dataTahap[$i]['tahap_kode'] . '&jenis_tes=' . $dataTahap[$i]['tahap_jenis_tes']; 
     
            $dataTahap[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').
               '&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataTahap[$i]['tahap_kode'].
               '&label='.$label.'&dataName='.$dataTahap[$i]['tahap_nama'];    
                
				$this->mrTemplate->AddVars('data_jurusan_item', $dataTahap[$i], 'TAHAP_');
				$this->mrTemplate->parseTemplate('data_jurusan_item', 'a');	 
			}
		}
	}
}
?>
