<?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';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 
   'module/mahasiswa/business/AppMahasiswaSia.class.php';

class ViewInputPhotoMahasiswa extends HtmlResponse{

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

   function ProcessRequest(){
	  $mhsObj = new AppMahasiswa();     
      $mhsObjSia = new AppMahasiswaSia();
      $mhsObjFinansi = new AppMahasiswaToFinansi();
      
      
      if(!$mhsObjFinansi->addConn)
         $return['finansiConn']=false;
      elseif($mhsObjFinansi->addConn)
         $return['finansiConn']=true;  
         
      if(!$mhsObjSia->addConn)
         $return['siaConn']=false;
      elseif($mhsObjSia->addConn)
         $return['siaConn']=true;  
             
      $msg = Messenger::Instance()->Receive(__FILE__);  
      //print_r($msg);
      $idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
      $idMhs = Dispatcher::Instance()->Decrypt($_REQUEST['dataIdMhs']);
      $cari = Dispatcher::Instance()->Decrypt($_REQUEST['cari']);
      $dataMhs =$mhsObj->GetDataMahasiswaById($idDec);
      $dataFoto = $mhsObjSia->GetFoto($idMhs);
      $dataFotoCM =$mhsObj->GetFoto($idDec);  
    // print_r($dataRiwayat);
      
      $return ['cari']=$cari;
      $return['decDataId'] = $idDec;
      $return['pesan']=$msg[0][1];
      $return['data']=$msg[0][0];
      $return['dataMhs'] = $dataMhs;
      $return['dataFoto'] = $dataFoto;
      $return['dataFotoCM'] = $dataFotoCM;   
      $return['dataMhs']=$dataMhs;
      return $return;
   } 
   
   function ParseTemplate($data=NULL){
   
      $photo_path = GTFWConfiguration::GetValue( 'application', 'photo_save_path');
   
      $cari=$data['cari'];
      $finansiConn=$data['finansiConn'];
      $siaConn=$data['siaConn'];


      if($finansiConn==false){
         $this->mrTemplate->AddVar('status_koneksi', 'JUDUL_ERROR', 'Gagal Koneksi');
         $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');
      }

      if($siaConn==false){
         $this->mrTemplate->AddVar('status_koneksi', 'JUDUL_ERROR', 'Gagal Koneksi');
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
         $this->mrTemplate->SetAttribute('sia_conn', 'visibility', 'visible');
         $this->mrTemplate->AddVar('sia_conn', 'ISI_PESAN_SIA', 'Gagal Menghubungi SI Akademik');
      }else{
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
//       print_r($cekPeriodeFinansi);s 
        
      $url_kembali=Dispatcher::Instance()->GetUrl('mahasiswa', 'mahasiswa', 'view', 'html');
      $this->mrTemplate->AddVar('warning', 'URL_KEMBALI',$url_kembali );       
      
      $url_kembali=Dispatcher::Instance()->GetUrl('mahasiswa', 'mahasiswa', 'view', 'html');
      $this->mrTemplate->AddVar('status_koneksi', 'URL_BATAL',$url_kembali ); 
      
      
      if ($data['pesan']) {
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
      }
      
      $dataMhs=$data['dataMhs'];
      $dataMhs=$data['dataMhs'];
      $dataFoto=$data['dataFoto'];
      $dataFotoCM=$data['dataFotoCM'];
      //print_r($dataFoto);
      if ($_REQUEST['dataId']=='')  {
         $url="AddPhotoMahasiswa";
         $tambah="Tambah";
      } else {
         $url="AddPhotoMahasiswa";
         $tambah="Ubah";
      }
         
      $this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
      
      $this->mrTemplate->AddVar('status_koneksi','MHS_NIU',empty($dataMhs[0]['mhs_niu'])
                                                         ?$data['data']['mhs']['mhs_niu']:
                                                         $dataMhs[0]['mhs_niu']);
         
      $this->mrTemplate->AddVar('status_koneksi','MHS_NAMA',empty($dataMhs[0]['mhs_nama'])
                                                          ?$data['data']['mhs']['mhs_nama']:
                                                          $dataMhs[0]['mhs_nama']);
         
      $this->mrTemplate->AddVar('status_koneksi','MHS_NAMA_ANGKATAN',empty($dataMhs[0]['mhs_nama_angkatan'])
                                                                  ?$data['data']['mhs']['mhs_nama_angkatan']:
                                                                  $dataMhs[0]['mhs_nama_angkatan']);
         
      $this->mrTemplate->AddVar('status_koneksi','MHS_NIU_LAMA',empty($dataMhs[0]['mhs_niu_lama'])
                                                               ?$data['data']['mhs']['mhs_niu_lama']:
                                                               $dataMhs[0]['mhs_niu_lama']);
      $this->mrTemplate->AddVar('status_koneksi','MHS_NIU_LAMA',empty($dataMhs[0]['mhs_niu_lama'])
                                                               ?$data['data']['mhs']['mhs_niu_lama']:
                                                               $dataMhs[0]['mhs_niu_lama']);
      if (!empty($dataMhs[0]['mhs_niu'])){
               if (empty($dataFoto[0]['mhs_foto_lama'])) { 
                  //$this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO', 'unknown.gif');
                  $this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO_LABEL', 'Belum ada foto tersimpan');
               }else{
                  $this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO', $dataFoto[0]['mhs_foto_lama']);
                  $this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO_LABEL', $dataFoto[0]['mhs_foto_lama']);
                  $this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO_PATH', $photo_path);
               }   
      }else{
               if (empty($dataFotoCM[0]['mhs_foto_lama'])) { 
                  //$this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO', 'unknown.gif');
                  $this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO_LABEL', 'Belum ada foto tersimpan');
               }else{
                  $this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO', $dataFotoCM[0]['mhs_foto_lama']);
                  $this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO_LABEL', $dataFotoCM[0]['mhs_foto_lama']);
                  $this->mrTemplate->AddVar('status_koneksi', 'MHS_FOTO_PATH', $photo_path);
               }
            }
      
               
      $this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('mahasiswa', $url, 'do', 'html') . 
         "&dataId=" . Dispatcher::Instance()->Encrypt($data['decDataId']));      
      
      $this->mrTemplate->AddVar('status_koneksi','URL_RETURN',Dispatcher::Instance()->GetUrl('mahasiswa', 'mahasiswa', 'view', 'html'));
      
      $this->mrTemplate->AddVar('status_koneksi','CARI',$cari); 
         
      $this->mrTemplate->AddVar('status_koneksi', 'DATAID', Dispatcher::Instance()->Decrypt($_GET['dataId']));

      $this->mrTemplate->AddVar('status_koneksi', 'PAGE', Dispatcher::Instance()->Decrypt($_GET['page']));
      
   }
 }
?>
