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

class ViewPendidikan extends HtmlResponse{
   
   function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/pendidikan/template');
		$this->SetTemplateFile('view_pendidikan.html');
	}
	
	function ProcessRequest() {
	
		$pendObj = new AppPendidikan();
		
		if($_POST || isset($_GET['cari'])) {
			if(isset($_POST['pendidikan'])) {
				$pendidikan = $_POST['pendidikan'];
			} elseif(isset($_GET['pendidikan'])) {
				$pendidikan = Dispatcher::Instance()->Decrypt($_GET['pendidikan']);
			} else {
				$pendidikan = '';
			}
		}
		
		$totalData = $pendObj->GetCountDataPendidikan($pendidikan);
		//print_r($totalData);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0;
		
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		
		//print($pendidikan);
		$dataPendidikan = $pendObj->getDataPendidikan($startRec, $itemViewed, $pendidikan);
		//print_r($dataPendidikan);
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType .'&pendidikan='. Dispatcher::Instance()->Encrypt($pendidikan) . '&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['dataPendidikan'] = $dataPendidikan;
		$return['start'] = $startRec+1;
		$return['search']['pendidikan'] = $pendidikan;
		return $return;		
	}
	
	function ParseTemplate($data = NULL) {
      $search=$data['pendidikan'];
      
      $this->mrTemplate->AddVar('content', 'PENDIDIKAN', $search['pendidikan']);
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('pendidikan', 'pendidikan', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('pendidikan', 'inputPendidikan', '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['dataPendidikan'])) {
			$this->mrTemplate->AddVar('data_pendidikan', 'PENDIDIKAN_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_pendidikan', 'PENDIDIKAN_EMPTY', 'NO');
			$dataPendidikan = $data['dataPendidikan'];
			//print_r($dataPendidikan);
			$label = "Data Pendidikan";
			$urlDelete = Dispatcher::Instance()->GetUrl('pendidikan', 'deletePendidikan', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('pendidikan', 'pendidikan', '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($dataPendidikan); $i++) {
				$no = $i+$data['start'];
				$dataPendidikan[$i]['number'] = $no;
				if ($no % 2 != 0) $dataPendidikan[$i]['class_name'] = 'table-common-even';
				else $dataPendidikan[$i]['class_name'] = '';
				//print_r($dataPendidikan);
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataPendidikan)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataPendidikan[$i]['id_pendidikan']);
            $urlAccept = 'pendidikan|deletePendidikan|do|html-cari-'.$cari;
            $urlReturn = 'pendidikan|pendidikan|view|html-cari-'.$cari;
				$dataPendidikan[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('pendidikan', 'inputPendidikan', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage . '&cari='.$cari;
            $dataPendidikan[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataPendidikan[$i]['id_pendidikan'].'&label='.$label.'&dataName='.$dataPendidikan[$i]['nama_pendidikan'];
				$this->mrTemplate->AddVars('data_pendidikan_item', $dataPendidikan[$i], 'PENDIDIKAN_');
				$this->mrTemplate->parseTemplate('data_pendidikan_item', 'a');	 
			}
   	}
   }
}
?>
