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

class ViewValidasi extends HtmlResponse{
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/validasi/template');
		$this->SetTemplateFile('view_validasi.html');
	}
   function ProcessRequest() {
		$valObj = new AppValidasi();
		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']))){
				$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($_POST['notes_nim']))
         or(isset($_GET['nama']))or(isset($_GET['status_reg']))or(isset($_GET['status_mhs']))) {
				$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 = $valObj->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;
		}
      $dataValidasi=$valObj->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__);
		      
      $dataPeriode=$valObj->GetDataPeriode();
      $dataPeriodeAktif=$valObj->GetPeriodeAktif();
      $dataProgramStudi=$valObj->GetDataProgramStudi();
      $dataMahasiswa=$valObj->GetMahasiswa();
		$dataProdi=$valObj->GetDataProdi();
		
		//tambahan
		$dataStatusReg=$valObj->GetStatusRegistrasi();
		$dataStatusMhs=$valObj->GetStatusMahasiswa();
		$dataStatusByr=$valObj->GetStatusBayar();
      //end

      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['dataValidasi'] = $dataValidasi;
		$return['dataMahasiswa'] = $dataMahasiswa;
		$return['dataPeriodeAktif'] = $dataPeriodeAktif;
		$return['dataPeriode'] = $dataPeriode;
		$return['dataProgramStudi'] = $dataProgramStudi;
		$return['start'] = $startRec+1;
		$return['search']['notes_nim'] = $notes_nim;
      $return['search']['nama']=$nama;
		return $return;
		
   }

   function ParseTemplate($data = NULL) {
		$search = $data['search'];
		$dataValidasi = $data['dataValidasi'];
		$dataMahasiswa = $data['dataMahasiswa'];
		$dataPeriodeAktif = $data['dataPeriodeAktif'];
		$dataPeriode = $data['dataPeriode'];
		$dataProgramStudi = $data['dataProgramStudi'];
		$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('validasi', 'validasi', 'view', 'html'));
		$this->mrTemplate->AddVar('empty_periode', 'URL_ADD', Dispatcher::Instance()->GetUrl('periode', 'inputPeriode', 'view', 'html'));
		$this->mrTemplate->AddVar('periode_is_aktif', 'URL_AKTIF', Dispatcher::Instance()->GetUrl('periode', 'periode', 'view', 'html'));
		$this->mrTemplate->AddVar('empty_prodi', 'URL_ADD', Dispatcher::Instance()->GetUrl('periode', 'inputProgramStudi', 'view', 'html'));
		$this->mrTemplate->AddVar('empty_mhs', 'URL_ADD', Dispatcher::Instance()->GetUrl('mahasiswa', 'inputMahasiswa', 'view', 'html'));
      
      if(!empty($data['dataPeriodeAktif'])){
         $this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
         $this->mrTemplate->AddVars('periode', $data['dataPeriodeAktif'][0], '');
		}
      
      if(empty($data['dataPeriode'])){
      $this->mrTemplate->SetAttribute('empty_box', 'visibility', 'visible');
         $this->mrTemplate->SetAttribute('empty_periode', 'visibility', 'visible');
			$this->mrTemplate->AddVar('empty_periode', 'ISI_PESAN_PERIODE', 'Silahkan tambahkan Periode disini');  
      }
      
      if(empty($data['dataPeriodeAktif'])){
      $this->mrTemplate->SetAttribute('empty_box', 'visibility', 'visible');
         $this->mrTemplate->SetAttribute('periode_is_aktif', 'visibility', 'visible');
			$this->mrTemplate->AddVar('periode_is_aktif', 'ISI_PESAN_PERIODE_IS_AKTIF', 'Silahkan Aktifkan Periode disini');
      }

      if(empty($data['dataProgramStudi'])){
      $this->mrTemplate->SetAttribute('empty_box', 'visibility', 'visible');
         $this->mrTemplate->SetAttribute('empty_prodi', 'visibility', 'visible');
			$this->mrTemplate->AddVar('empty_prodi', 'ISI_PESAN_PRODI', 'Silahkan tambahkan Program Studi disini');
      }
      
      if(empty($data['dataMahasiswa'])){
      $this->mrTemplate->SetAttribute('empty_box', 'visibility', 'visible');
         $this->mrTemplate->SetAttribute('empty_mhs', 'visibility', 'visible');
			$this->mrTemplate->AddVar('empty_mhs', 'ISI_PESAN_MHS', 'Silahkan tambahkan Mahasiswa disini');
      }
      
      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['dataValidasi'])) {
			$this->mrTemplate->AddVar('data_validasi', 'VALIDASI_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_validasi', 'VALIDASI_EMPTY', 'NO');
			$dataValidasi = $data['dataValidasi'];

         for ($i=0; $i<sizeof($dataValidasi); $i++) {
				$no = $i+$data['start'];
				$dataValidasi[$i]['number'] = $no;
				if ($no % 2 != 0) $dataValidasi[$i]['class_name'] = 'table-common-even';
				else $dataValidasi[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataValidasi)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				
            $idEnc = Dispatcher::Instance()->Encrypt($dataValidasi[$i]['id']);
				
				if($dataValidasi[$i]['status_reg'] == 'S'){
               $dataValidasi[$i]['STATUS_TITLE_REG'] = 'Sudah Registrasi';
            }else{
               $dataValidasi[$i]['STATUS_TITLE_REG'] = 'Belum Registrasi';
            }
            
            if($dataValidasi[$i]['status_mhs'] == '1'){
               $dataValidasi[$i]['status_mhs'] = 'CM';
               $dataValidasi[$i]['STATUS_TITLE_MHS'] = 'Calon Mahasiswa';
            }else{
               $dataValidasi[$i]['status_mhs'] = 'M';
               $dataValidasi[$i]['STATUS_TITLE_MHS'] = 'Mahasiswa';
				}
				
				if($dataValidasi[$i]['status_byr'] == 'BB'){
               $dataValidasi[$i]['STATUS_TITLE_BYR'] = 'Belum Bayar';
            }elseif($dataValidasi[$i]['status_byr'] == 'BL'){
               $dataValidasi[$i]['STATUS_TITLE_BYR'] = 'Belum Lunas';
            }elseif($dataValidasi[$i]['status_byr'] == 'LN'){
               $dataValidasi[$i]['status_byr'] = 'L';
               $dataValidasi[$i]['STATUS_TITLE_BYR'] = 'Lunas';
            }
				
				if(empty($dataValidasi[$i]['password'])){
               $this->mrTemplate->AddVar('password', 'PASSWORD_EMPTY', 'YES');
               $this->mrTemplate->AddVar('password', 'URL_PASSWORD_EMPTY', Dispatcher::Instance()->GetUrl('validasi', 'addPassword', 'do', 'html') . '&dataId=' . $idEnc);
            }else{
               $this->mrTemplate->AddVar('password', 'PASSWORD_EMPTY', 'NO');
               $this->mrTemplate->AddVar('password', 'URL_PASSWORD', Dispatcher::Instance()->GetUrl('validasi', 'resetPassword', 'do', 'html') . '&dataId=' . $idEnc);
            }
				
				$dataValidasi[$i]['url_password'] = Dispatcher::Instance()->GetUrl('validasi', 'addPassword', 'do', 'html') . '&dataId=' . $idEnc;
            $dataValidasi[$i]['url_detail'] = Dispatcher::Instance()->GetUrl('mahasiswa', 'detailMahasiswa', 'view', 'html') . 
               '&dataId=' . $idEnc; 
				#$dataValidasi[$i]['url_add'] = Dispatcher::Instance()->GetUrl('periode', 'inputPeriode', 'view', 'html');
				$this->mrTemplate->AddVars('data_validasi_item', $dataValidasi[$i], 'VALIDASI_');
				$this->mrTemplate->parseTemplate('data_validasi_item', 'a');	 
         }
      }
   }
}
?>