<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/verifikasi/business/AppVerifikasi.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/business/AppMahasiswa.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'main/function/date.php';
class ViewVerifikasi extends HtmlResponse{
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/verifikasi/template');
		$this->SetTemplateFile('view_verifikasi.html');
	}
   function ProcessRequest() {
		$verObj = new AppVerifikasi();
		$mhsObj = new AppMahasiswa();
		if($_POST || isset($_GET['cari'])) {
			if((isset($_POST['prodi']))or(isset($_POST['notes_nim']))or(isset($_POST['nama']))
         or(isset($_POST['status_reg']))or(isset($_POST['status_mhs']))or(isset($_POST['status_byr']))){
				$prodi = $_POST['prodi'];
				$notes_nim = $_POST['notes_nim'];
            $nama = $_POST['nama'];
            $status_reg = $_POST['status_reg'];
            $status_mhs = $_POST['status_mhs'];
            $status_byr = $_POST['status_byr'];
            
			} elseif((isset($_POST['prodi']))or(isset($_GET['notes_nim']))or(isset($_GET['nama']))
			or(isset($_GET['status_reg']))or(isset($_GET['status_mhs']))or(isset($_GET['status_byr']))){
				$prodi = Dispatcher::Instance()->Decrypt($_GET['prodi']);
				$notes_nim = Dispatcher::Instance()->Decrypt($_GET['notes_nim']);
            $nama = Dispatcher::Instance()->Decrypt($_GET['nama']);
            $status_reg = Dispatcher::Instance()->Decrypt($_GET['status_reg']);
            $status_mhs = Dispatcher::Instance()->Decrypt($_GET['status_mhs']);
            $status_byr = Dispatcher::Instance()->Decrypt($_GET['status_byr']);
            
			} else {
				$prodi = '';
				$notes_nim = '';
            $nama = '';
            $status_reg = '';
            $status_mhs = '';
            $status_byr = '';
            
			}
		}
		
		if($prodi=='all'){
         $prodi='';
      }      
      
      if($status_reg=='all'){
         $status_reg='';
      }
      
      if($status_mhs=='all'){
         $status_mhs='';
      }
      
      if($status_byr=='all'){
         $status_byr ='';
      }
		
      $totalData = $verObj->GetCountDataMahasiswa($prodi,$notes_nim,$notes_nim,$nama,$status_reg,$status_mhs,$status_byr);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
      if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		$dataMhs=$mhsObj->GetDataDetailMahasiswa($idDec);
      $dataVerifikasi=$verObj->GetDataMahasiswa($prodi,$notes_nim,$notes_nim,$nama,$status_reg,$status_mhs,$status_byr,$startRec,$itemViewed);
		
		
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
             Dispatcher::Instance()->mSubModule, 
             Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . 
             '&prodi=' . Dispatcher::Instance()->Encrypt($prodi) .
             '&notes_nim=' . Dispatcher::Instance()->Encrypt($notes_nim) .
             '&nama=' . Dispatcher::Instance()->Encrypt($nama) . 
             '&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__);
      
      $dataPeriodeAktif = $verObj->GetPeriodeAktif();
      $dataTahunMasuk=$verObj->GetDataTahunMasuk();
      
      //tambahan
		$dataStatusReg=$verObj->GetStatusRegistrasi();
		$dataStatusMhs=$verObj->GetStatusMahasiswa();
		$dataStatusByr=$verObj->GetStatusBayar();
      //end
      
      //ambil setting pembayaran aplikasi
      $dataSettPembayaran = $verObj->getSettPembayaran();
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tahun',
         array('tahun',$dataTahunMasuk,$tahun,'true',''), Messenger::CurrentRequest);
		
		$dataProdi=$verObj->GetDataProdi();

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'prodi',
         array('prodi',$dataProdi,$prodi,'true',''), Messenger::CurrentRequest);
         
      //tambahan
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_reg',
            array('status_reg',$dataStatusReg,$status_reg,'true',''), Messenger::CurrentRequest);
            
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_mhs',
            array('status_mhs',$dataStatusMhs,$status_mhs,'true',''), Messenger::CurrentRequest);
            
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_byr',
            array('status_byr',$dataStatusByr,$status_byr,'true',''), Messenger::CurrentRequest);
      //end
		
      $return['pesan'] = $msg[0][1];
		$return['css'] = $msg[0][2];
		$return['start'] = $startRec+1;
		$return['search']['notes_nim'] = $notes_nim;
      $return['search']['nama'] = $nama;
      $return['search']['prodiKode'] = $dataProdiById[0]['prodi_id'];
      $return['search']['prodiNama'] = $dataProdiById[0]['prodi'];
      $return['dataVerifikasi'] = $dataVerifikasi;
      $return['dataPeriodeAktif'] = $dataPeriodeAktif;
      $return['dataSettPembayaran'] = $dataSettPembayaran;
		return $return;
		
   }

   function ParseTemplate($data = NULL) {
		$search = $data['search'];
		$dataVerifikasi = $data['dataVerifikasi'];
		$dataPeriodeAktif = $data['dataPeriodeAktif'];
		$dataSettPembayaran = $data['dataSettPembayaran'];
		$this->mrTemplate->AddVar('content', 'NOTES_NIM', $search['notes_nim']);
      $this->mrTemplate->AddVar('content', 'NAMA', $search['nama']);
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('verifikasi', 'verifikasi', 'view', 'html'));		
		#print_r($dataVerifikasi);
		
      if($data['pesan']) {
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan'][0]);
         $this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $data['css'][0]);
         
         $this->mrTemplate->SetAttribute('warning_box_2', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box_2', 'ISI_PESAN', $data['pesan'][1]);
         $this->mrTemplate->AddVar('warning_box_2', 'CLASS_PESAN', $data['css'][1]);
		}
		if(!empty($data['dataPeriodeAktif'])){
         $this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
         $this->mrTemplate->AddVars('periode', $data['dataPeriodeAktif'][0], '');
		}
      if (empty($data['dataVerifikasi'])) {
			$this->mrTemplate->AddVar('data_verifikasi', 'VERIFIKASI_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_verifikasi', 'VERIFIKASI_EMPTY', 'NO');
			$dataVerifikasi = $data['dataVerifikasi'];				

         for ($i=0; $i<sizeof($dataVerifikasi); $i++) {
				$no = $i+$data['start'];
				$dataVerifikasi[$i]['number'] = $no;
				if ($no % 2 != 0) $dataVerifikasi[$i]['class_name'] = 'table-common-even';
				else $dataVerifikasi[$i]['class_name'] = '';
				
				$idEnc = Dispatcher::Instance()->Encrypt($dataVerifikasi[$i]['id']);
				$dataVerifikasi[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('verifikasi', 'updateVerifikasi', 'do', 'html') . 
               '&dataId=' . $idEnc; 
               
				if (($dataVerifikasi[$i]['status_mhs'] == '1')) {
               $dataVerifikasi[$i]['STATUS_MHS'] = 'CM';
               $dataVerifikasi[$i]['STATUS_TITLE_MHS'] = 'Calon Mahasiswa';
            } else {
               $dataVerifikasi[$i]['STATUS_MHS'] = 'M';
               $dataVerifikasi[$i]['STATUS_TITLE_MHS'] = 'Mahasiswa';
            }
            
            if ($dataVerifikasi[$i]['status_reg'] == 'S') {
               $dataVerifikasi[$i]['STATUS_TITLE_REG'] = 'Sudah Registrasi';
            } else {
               $dataVerifikasi[$i]['STATUS_TITLE_REG'] = 'Belum Registrasi';
            }
            
            if($dataVerifikasi[$i]['status_byr'] == 'BB'){
               $dataVerifikasi[$i]['STATUS_TITLE_BYR'] = 'Belum Bayar';
            }elseif($dataVerifikasi[$i]['status_byr'] == 'BL'){
               $dataVerifikasi[$i]['STATUS_TITLE_BYR'] = 'Belum Lunas';
            }elseif($dataVerifikasi[$i]['status_byr'] == 'LN'){
               $dataVerifikasi[$i]['status_byr'] = 'L';
               $dataVerifikasi[$i]['STATUS_TITLE_BYR'] = 'Lunas';
            }
            
            //cek dl apakah setting non pembayaran mhs dalam keadaan aktif
            if($dataSettPembayaran == 0){
            	//bypass pembayaran tidak aktif
            	if (($dataVerifikasi[$i]['status_mhs'] == '1') && ($dataVerifikasi[$i]['status_reg'] == 'S')) {
	               $this->mrTemplate->AddVar('aktif', 'IS_SHOW_AKTIFKAN', 'YES');
	               $this->mrTemplate->AddVar('aktif', 'VERIFIKASI_URL_EDIT', $dataVerifikasi[$i]['url_edit']);
	            } else {
	               $this->mrTemplate->AddVar('aktif', 'IS_SHOW_AKTIFKAN', 'NO');
	            }
	            	
            }else{
            	
            	//bypass pembayaran aktif
            	if ($dataVerifikasi[$i]['status_mhs'] == '1'){
	               $this->mrTemplate->AddVar('aktif', 'IS_SHOW_AKTIFKAN', 'YES');
	               $this->mrTemplate->AddVar('aktif', 'VERIFIKASI_URL_EDIT', $dataVerifikasi[$i]['url_edit']);
	            } else {
	               $this->mrTemplate->AddVar('aktif', 'IS_SHOW_AKTIFKAN', 'NO');
	            }
            	
            }                                    
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataVerifikasi)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$dataVerifikasi[$i]['url_detail'] = Dispatcher::Instance()->GetUrl('mahasiswa', 'detailMahasiswa', 'view', 'html') . 
               '&dataId=' . $idEnc;
				$this->mrTemplate->AddVars('data_verifikasi_item', $dataVerifikasi[$i], 'VERIFIKASI_');
				$this->mrTemplate->parseTemplate('data_verifikasi_item', 'a');	 
         }
      }
   }
}
?>
