<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/fakultas/business/AppFakultasToAdmisi.class.php';
class ViewFakultas extends HtmlResponse {
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/fakultas/template');
		$this->SetTemplateFile('view_fakultas.html');
	}
   
   function ProcessRequest(){
      $fakObj=new AppFakultasToAdmisi();
            
      if($_POST || isset($_GET['cari'])) {
         if((isset($_POST['fak_kode']))or(isset($_POST['fak_nama_resmi']))or(isset($_POST['fak_nama_singkat']))){
				$fakKode = $_POST['fak_kode'];
				$fakNamaResmi = $_POST['fak_nama_resmi'];
				$fakNamaSingkat = $_POST['fak_nama_singkat'];
			} elseif((isset($_GET['fak_kode']))or(isset($_GET['fak_nama_resmi']))or(isset($_GET['fak_nama_singkat']))){
				$fakKode = Dispatcher::Instance()->Decrypt($_GET['fak_kode']);
				$fakNamaResmi = Dispatcher::Instance()->Decrypt($_GET['fak_nama_resmi']);
				$fakNamaSingkat = Dispatcher::Instance()->Decrypt($_GET['fak_nama_singkat']);
			} else {
				$fakKode = '';
				$fakNamaResmi = '';
				$fakNamaSingkat = '';
			}
		}
      
      $totalData = $fakObj->GetCountDataFakultas($fakKode, $fakNamaResmi, $fakNamaSingkat);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
      
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
      $dataFakultas=$fakObj->GetDataFakultas($fakKode,
                                             $fakNamaResmi, 
                                             $fakNamaSingkat,
                                             $startRec, 
                                             $itemViewed);

      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
             Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, 
             Dispatcher::Instance()->mType . '&fak_kode=' . Dispatcher::Instance()->Encrypt($fakKode) . 
             '&fak_nama_resmi=' . Dispatcher::Instance()->Encrypt($fakNamaResmi) . 
             '&fak_nama_singkat=' . Dispatcher::Instance()->Encrypt($fakNamaSingkat) . 
             '&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['search']['fakKode']=$fakKode;
      $return['search']['fakNamaResmi']=$fakNamaResmi;
      $return['search']['fakNamaSingkat']=$fakNamaSingkat;
      $return['dataFakultas']=$dataFakultas;
      $return['start'] = $startRec+1;
      return $return;
   }
   
   function ParseTemplate($data=null){
      $search=$data['search'];
      
      $this->mrTemplate->AddVar('content', 'FAK_KODE', $search['fakKode']);
      $this->mrTemplate->AddVar('content', 'FAK_NAMA_RESMI', $search['fakNamaResmi']);
      $this->mrTemplate->AddVar('content', 'FAK_NAMA_SINGKAT', $search['fakNamaSingkat']);
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('fakultas', 'fakultas', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('fakultas', 'inputFakultas', '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['dataFakultas'])) {
			$this->mrTemplate->AddVar('data_fakultas', 'FAKULTAS_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_fakultas', 'FAKULTAS_EMPTY', 'NO');
			$dataFakultas = $data['dataFakultas'];

         $label = "Data Fakultas";
         
			$urlDelete = Dispatcher::Instance()->GetUrl('fakultas', 'deleteFakultas', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('fakultas', 'fakultas', '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($dataFakultas); $i++) {
				$no = $i+$data['start'];
				$dataFakultas[$i]['number'] = $no;
				if ($no % 2 != 0) $dataFakultas[$i]['class_name'] = 'table-common-even';
				else $dataFakultas[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataFakultas)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataFakultas[$i]['fak_kode']);
            $urlAccept = 'fakultas|deleteFakultas|do|html-cari-'.$cari;
            $urlReturn = 'fakultas|fakultas|view|html-cari-'.$cari;

				$dataFakultas[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('fakultas', 'inputFakultas', 'view', 'html') . '&dataId=' . $idEnc. '&page=' . $encPage  ;
            $dataFakultas[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataFakultas[$i]['fak_kode'].'&label='.$label.'&dataName='.$dataFakultas[$i]['fak_nama_resmi'].' ('.$dataFakultas[$i]['fak_nama_singkat'].')';
            
				$this->mrTemplate->AddVars('data_fakultas_item', $dataFakultas[$i], 'FAK_');
				$this->mrTemplate->parseTemplate('data_fakultas_item', 'a');	 
			}
      }
   }
}
?>