<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/integrasi_data/business/AppIntegrasiDataAdmisi.class.php';
class ViewIntegrasiData extends HtmlResponse{

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/integrasi_data/template');
		$this->SetTemplateFile('view_integrasi_data.html');
	}
	
	function ProcessRequest(){
      #search Begin
      if($_POST || isset($_GET['cari'])) {
			if((isset($_POST['mhs_prodi']))or(isset($_POST['mhs_nama']))or(isset($_POST['mhs_status_reg']))or(isset($_POST['mhs_status']))or(isset($_POST['mhs_nim']))) {
            $mhsProdi=$_POST['mhs_prodi'];
            $mhsNama=$_POST['mhs_nama'];
            $mhsStatusReg=$_POST['mhs_status_reg'];
            $mhsStatus=$_POST['mhs_status'];
            $mhsNim=$_POST['mhs_nim'];
            $mhsNoTes=$_POST['mhs_no_tes'];
			} elseif((isset($_GET['mhs_prodi'])) or (isset($_GET['mhs_nama']))or (isset($_GET['mhs_status_reg']))or (isset($_GET['mhs_status']))or (isset($_GET['mhs_nim']))or (isset($_GET['mhs_no_tes']))) {
				$mhsProdi=Dispatcher::Instance()->Decrypt($_GET['mhs_prodi']);
            $mhsNama=Dispatcher::Instance()->Decrypt($_GET['mhs_nama']);
            $mhsStatusReg=Dispatcher::Instance()->Decrypt($_GET['mhs_status_reg']);
            $mhsStatus=Dispatcher::Instance()->Decrypt($_GET['mhs_status']);
            $mhsNim=Dispatcher::Instance()->Decrypt($_GET['mhs_nim']);
            $mhsNoTes=Dispatcher::Instance()->Decrypt($_GET['mhs_no_tes']);
			} else {
				$mhsProdi='';
            $mhsNama='';
            $mhsStatusReg='';
            $mhsStatus='';
            $mhsNim='';
            $mhsNoTes='';
			}
			$mhsProdi=($mhsProdi=='all')?'':$mhsProdi;
         $mhsNama=($mhsNama=='all')?'':$mhsNama;
         $mhsStatusReg=($mhsStatusReg=='all')?'':$mhsStatusReg;
         $mhsStatus=($mhsStatus=='all')?'':$mhsStatus;
         $mhsNim=($mhsNim=='all')?'':$mhsNim;
         $mhsNoTes=($mhsNoTes=='all')?'':$mhsNoTes;
			
         $search['mhs_prodi']= $mhsProdi;
         $search['mhs_nama']= $mhsNama;
         $search['mhs_status_reg']= $mhsStatusReg;
         $search['mhs_status']= $mhsStatus;
         $search['mhs_nim']= $mhsNim;
         $search['mhs_no_tes']= $mhsNoTes;
		}
		#search End
		
      #Get Data Begin		
      $integrasiData=new AppIntegrasiDataAdmisi();
      
      $totalData=$integrasiData->GetCountListData($mhsProdi,
                                                  $mhsNama,
                                                  $mhsStatusReg,
                                                  $mhsStatus,
                                                  $mhsNim,
                                                  $mhsNoTes);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		
		$listData=$integrasiData->GetListData($mhsProdi,
                                            $mhsNama,
                                            $mhsStatusReg,
                                            $mhsStatus,
                                            $mhsNim,
                                            $mhsNoTes,
                                            $startRec,
                                            $itemViewed);
      
      $dataProdi=$integrasiData->GetDataProdi();
      $dataPeriode=$integrasiData->GetPeriodeAktif();
      $dataStatusReg=$integrasiData->GetStatusReg();
      $dataStatusMhs=$integrasiData->GetStatusMhs();                              
      #Get Data End
            
      #Show Paging Begin                                  
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
                                            Dispatcher::Instance()->mSubModule, 
                                            Dispatcher::Instance()->mAction, 
                                            Dispatcher::Instance()->mType .
                                            '&mhs_prodi=' . Dispatcher::Instance()->Encrypt($mhsProdi) . 
                                            '&mhs_nama=' . Dispatcher::Instance()->Encrypt($mhsNama).
                                            '&mhs_status_reg=' . Dispatcher::Instance()->Encrypt($mhsStatusReg).
                                            '&mhs_status=' . Dispatcher::Instance()->Encrypt($mhsStatus).
                                            '&mhs_nim=' . Dispatcher::Instance()->Encrypt($mhsNim).
                                            '&mhs_no_tes=' . Dispatcher::Instance()->Encrypt($mhsNoTes).
                                            '&cari=' . Dispatcher::Instance()->Encrypt(1));

		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);
      #Show Paging End

      #Show Combo Box Begin
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'prodi',
         array('mhs_prodi',$dataProdi,$mhsProdi,'true',''), Messenger::CurrentRequest);
         
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_reg',
            array('mhs_status_reg',$dataStatusReg,$mhsStatusReg,'true',''), Messenger::CurrentRequest);
            
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_mhs',
            array('mhs_status',$dataStatusMhs,$mhsStatus,'true',''), Messenger::CurrentRequest);
            
      #Show Combo Box End
                   
      #Get MSG Begin
 		$msg = Messenger::Instance()->Receive(__FILE__);
		$pesan = $msg[0][1];
		$css = $msg[0][2];      
      #Get MSG End      
      
      #return Begin
      $return['pesan']=$pesan;
      $return['css']=$css;
      $return['listData']=$listData;
      $return['start']=$startRec+1;
      $return['search']=$search;
      $return['dataPeriode']=$dataPeriode;
      return $return;
      #return end     
   }
   
   function ParseTemplate($data=null){
      #Begin Get Data From return
      $pesan=$data['pesan'];
      $css=$data['css'];
      $listData=$data['listData'];
      $dataPeriode=$data['dataPeriode'];
      $start=$data['start'];
      $search=$data['search'];
      # end Get Data    
         
      # begin Show Periode        
		if(!empty($dataPeriode)){
         $this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
         $this->mrTemplate->AddVar('periode', 'PERIODE',$dataPeriode[0]['periode']);
		}
		#end Show Periode
				
      #Begin Parse To Filter
      $this->mrTemplate->AddVar('content', 'MHS_NIM', $search['mhs_nim']);
      $this->mrTemplate->AddVar('content', 'MHS_NAMA', $search['mhs_nama']);
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', 
         Dispatcher::Instance()->GetUrl('integrasi_data', 'integrasiData', 'view', 'html'));
      #End Parse To Filter             
      
      #Begin Parse Alert
      if($pesan!='') {
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $pesan[0]);
         $this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $css[0]);
         
         $this->mrTemplate->SetAttribute('warning_box_2', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box_2', 'ISI_PESAN', $pesan[1]);
         $this->mrTemplate->AddVar('warning_box_2', 'CLASS_PESAN', $css[1]);
		}
      #End Parse Alert             
      
      #Begin Parse List Data              
      if(empty($listData)){
			$this->mrTemplate->AddVar('list_data', 'DATA_EMPTY', 'YES');
      }else{
			$this->mrTemplate->AddVar('list_data', 'DATA_EMPTY', 'NO'); 
         $decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
         $encPage = Dispatcher::Instance()->Encrypt($decPage);
         for($i=0;$i<sizeof($listData);$i++){
				$no = $i+$start;
				$listData[$i]['number'] = $no;
				
			   if ($no % 2 != 0) 
               $listData[$i]['class_name'] = 'table-common-even';
				else 
               $listData[$i]['class_name'] = '';
				
				$idEnc = Dispatcher::Instance()->Encrypt($listData[$i]['mhs_id']);
				$listData[$i]['url_send'] = Dispatcher::Instance()->GetUrl('integrasi_data', 'integrasiData', 'do', 'html') . 
               '&dataId=' . $idEnc; 
               
				if($i == 0) 
               $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($listData)-1) 
               $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				
				if (($listData[$i]['status_mhs'] == 'CM')) {
               $listData[$i]['status_mhs_title'] = 'Calon Mahasiswa';
            } else {
               $listData[$i]['status_mhs_title'] = 'Mahasiswa';
            }
            
            if ($listData[$i]['status_reg'] == 'S') {
               $listData[$i]['status_reg_title'] = 'Sudah Registrasi';
            } else {
               $listData[$i]['status_reg_title'] = 'Belum Registrasi';
            }
            
            $this->mrTemplate->AddVars('list_data_item', $listData[$i], '');
				$this->mrTemplate->parseTemplate('list_data_item', 'a');	 
            
         }
      }
      #End Parse List Data                  
   }
}
