<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/business/AppMahasiswa.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/business/AppMahasiswaToFinansi.class.php';

class ViewImportMahasiswa extends HtmlResponse{

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/template');
		$this->SetTemplateFile('import_mahasiswa.html');
	}

   function ProcessRequest() {
   unset($_SESSION['arrDataMhsFail']);
      $mhsObjAdmisi=new AppMahasiswa();
      $mhsObjFinansi=new AppMahasiswaToFinansi();
      
      if(!$mhsObjFinansi->addConn)
         $return['finansiConn']=false;
      elseif($mhsObjFinansi->addConn)
         $return['finansiConn']=true;  
         
      $msg = Messenger::Instance()->Receive(__FILE__);
      $reset= Dispatcher::Instance()->Decrypt($_REQUEST['reset']);
      $dataTahun=$mhsObjAdmisi->GetTahun(1990);
      //print($reset);

      $pesan=$msg[0][1];
      $data=$msg[0][0];         
      $countMhsExist=$_SESSION['countMhsExist'];
      $countMhsNotExist=$_SESSION['countMhsNotExist'];
      
      if((!empty($countMhsExist) or !empty($countMhsNotExist))and $reset==''){
        $uploaded=true;
      }else{
        $uploaded=false;
        $_SESSION['countMhsExist']="";
        $_SESSION['countMhsNotExist']="";
        }
      
      $tahunMasukDefault=$mhsObjAdmisi->GetTahunPeriodeAktif();
      
      $tahunMasuk=empty($data['tahun_masuk'])?$tahunMasukDefault:$data['tahun_masuk'];
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tahun_masuk',
            array('tahun_masuk',$dataTahun,$tahunMasuk,'false',''), Messenger::CurrentRequest);
      
      $semsMasukDefault=$mhsObjAdmisi->GetPeriodeAktif();
      $dataSemester=$mhsObjAdmisi->GetSemesterMasuk();
      $semesterMasuk=empty($data['sems_masuk'])?$semsMasukDefault:$data['sems_masuk'];
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'mhs_sems_masuk',
         array('sems_masuk',$dataSemester,$semesterMasuk,'false',''), 
         Messenger::CurrentRequest); 
         
      $return['Pesan']=$pesan;
      $return['uploaded']=$uploaded;
      $return['Data']=$data;
      $return['countMhsExist']=$countMhsExist;
      $return['countMhsNotExist']=$countMhsNotExist;
     
		return $return;
	}

   function ParseTemplate($data = NULL) {
      $finansiConn=$data['finansiConn'];
      $uploaded=$data['uploaded'];
      
      if($finansiConn==false){
        $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
        $this->mrTemplate->SetAttribute('finansi_conn', 'visibility', 'visible');
        $this->mrTemplate->AddVar('finansi_conn', 'ISI_PESAN_FINANSI', 'Gagal Menghubungi SI Finansi');
      }else{
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
      
      $url_kembali=Dispatcher::Instance()->GetUrl('mahasiswa', 'mahasiswa', 'view', 'html');
      $this->mrTemplate->AddVar('warning', 'URL_KEMBALI',$url_kembali ); 
      
		if ($data['Pesan']) {
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['Pesan']);
      }
      

      
      if($uploaded==true){
			   $this->mrTemplate->AddVar('uploaded', 'UPLOADED', 'YES');
         $this->mrTemplate->SetAttribute('petunjuk_import', 'visibility', 'visible');
      }else{
			   $this->mrTemplate->AddVar('uploaded', 'UPLOADED', 'NO');
         $this->mrTemplate->SetAttribute('petunjuk_import', 'visibility', 'hidden');
      }
      
      if(empty($data['countMhsNotExist'])){
         $data['countMhsNotExist']=0;
      }
      
      if(empty($data['countMhsExist'])){
         $data['countMhsExist']=0;
      }
      
      $this->mrTemplate->AddVar('uploaded','IS_EXIST',$data['countMhsExist']);
      $this->mrTemplate->AddVar('uploaded','IS_NOT_EXIST',$data['countMhsNotExist']);        
      $this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('mahasiswa', 'importMahasiswa', 'do', 'html') );
      $this->mrTemplate->AddVar('uploaded', 'RESET', Dispatcher::Instance()->GetUrl('mahasiswa', 'importMahasiswa', 'view', 'html').'&reset=1');
      $this->mrTemplate->AddVar('uploaded', 'URL_CONTOH_FILE', 'module/mahasiswa/contoh_file/contoh_file.xls');
      $this->mrTemplate->AddVar('uploaded', 'URL_VIEW_EXIST', Dispatcher::Instance()->GetUrl('mahasiswa', 'hasilImportMahasiswa', 'print', 'html').'&view=exist');     
      $this->mrTemplate->AddVar('uploaded', 'URL_VIEW_NOT_EXIST', Dispatcher::Instance()->GetUrl('mahasiswa', 'hasilImportMahasiswa', 'print', 'html').'&view=not_exist');
	}
}
?>
