<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/program_studi/business/AppProgramStudiToAdmisi.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/program_studi/business/AppProgramStudiToSia.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/program_studi/business/AppProgramStudiToPortal.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/program_studi/business/AppProgramStudiToFinansi.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/program_studi/business/AppProgramStudiToUm.class.php';

class ViewInputProgramStudi extends HtmlResponse{

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/program_studi/template');
		$this->SetTemplateFile('input_program_studi.html');
	}
	function ProcessRequest() {
      $useUm=GTFWConfiguration::GetValue( 'application', 'use_gtum');
		$idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$prodiObj = new AppProgramStudiToAdmisi();
      $prodiToSia= new AppProgramStudiToSia();
      $prodiToPortal= new AppProgramStudiToPortal();
      $prodiToFinansi= new AppProgramStudiToFinansi();
      $prodiToUm= new AppProgramStudiToUm();
      
      if(!$prodiToSia->addConn)
         $return['siaConn']=false;
      else
         $return['siaConn']=true;      
      
      if(!$prodiToPortal->addConn)
         $return['portalConn']=false;
      else
         $return['portalConn']=true;       

      if(!$prodiToFinansi->addConn)
         $return['finansiConn']=false;
      else
         $return['finansiConn']=true;     

      if(!$prodiToUm->addConn && $useUm==true)
         $return['umConn']=false;
      else
         $return['umConn']=true;    
          
		$msg = Messenger::Instance()->Receive(__FILE__);
		$dataProdi = $prodiObj->GetDataProgramStudiById($idDec);
      $dataComboJenjang=$prodiObj->GetDataJenjangAkademik();
    
      $dataComboJur=$prodiObj->GetJurusan();
  //print_r($dataComboJur);
      if($msg[0][0]){
         $ekstakta=$msg[0][0]['ekstakta'];
         $model=$msg[0][0]['model'];
         $idJenjang=$msg[0][0]['jenjang'];
         $jurusan=$msg[0][0]['jurusan'];
      }else{
         $idJenjang=$dataProdi[0]['jenjang_kode'];
         $ekstakta=$dataProdi[0]['is_ekstakta'];
         $jurusan=$dataProdi[0]['prodi_jur'];
         if($dataProdi[0]['model']!==''){
            $model=$dataProdi[0]['model'];
         }
         if($dataProdi[0]['model']==''){
            $model='1';
         }
      }
      $dataPilihanKelompok=array(array('id'=>'1','name'=>'Kelompok IPA'),array('id'=>'2','name'=>'Kelompok IPS'));
      for($i=0;$i<300;$i++){
         $dataSpma[$i]['id']=$i+1;
         $dataSpma[$i]['name']=$i+1;
         if($i==299){
            $dataSpma[$i]['name']='>'.$i+1;
            }
      }
      
      $dataAdmisi=$prodiToUm->GetDataUm($idDec);
      #print_r($dataAdmisi);
      $return['use_um']=false;
      
      if($useUm==true){
         Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kelompok',
            array('kelompok',$dataPilihanKelompok,$dataAdmisi[0]['KELPIL'],'false',''), Messenger::CurrentRequest) ; 
             
         Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'spma1',
            array('spma1',$dataSpma,$dataAdmisi[0]['SPMA1'],'false',''), Messenger::CurrentRequest) ;     

         Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'spma2',
            array('spma2',$dataSpma,$dataAdmisi[0]['SPMA2'],'false',''), Messenger::CurrentRequest) ;    

         Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'spma3',
            array('spma3',$dataSpma,$dataAdmisi[0]['SPMA3'],'false',''), Messenger::CurrentRequest) ; 

         Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'spma4',
            array('spma4',$dataSpma,$dataAdmisi[0]['SPMA4'],'false',''), Messenger::CurrentRequest) ; 

         Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'spmapbs',
            array('spmapbs',$dataSpma,$dataAdmisi[0]['SPMAPBS'],'false',''), Messenger::CurrentRequest) ; 
        
         Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'spmapbupd',
            array('spmapbupd',$dataSpma,$dataAdmisi[0]['SPMAPBUPD'],'false',''), Messenger::CurrentRequest) ;                    
         $return['use_um']=true;
      }
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jenjang',
         array('jenjang',$dataComboJenjang,$idJenjang,'false',''), Messenger::CurrentRequest) ;     
          
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jurusan',
         array('jurusan',$dataComboJur,$jurusan,'false',''), Messenger::CurrentRequest);    
      
      $dataModel=$prodiObj->GetDataModel();      

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'model',
         array('model',$dataModel,$model,'false',''), Messenger::CurrentRequest);

		$return['decDataId'] = $idDec;
      $return['pesan']=$msg[0][1];
      $return['data']=$msg[0][0];
		$return['dataProdi'] = $dataProdi;

		return $return;

	}
	function ParseTemplate($data = NULL) {
      $siaConn=$data['siaConn'];
      $portalConn=$data['portalConn'];
      $finansiConn=$data['finansiConn'];
      $umConn=$data['umConn'];
      $useUm=$data['use_um'];
      #$dataUm=$data['dataAdmisi'];
      $dataProdi=$data['dataProdi'];
		if ($data['pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
		}
		
		if($useUm==true){
			$this->mrTemplate->SetAttribute('data_admisi', 'visibility', 'visible'); 
      }else{
      	$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'hidden');
      }
      
      if($siaConn==false){
      	$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');
      }elseif($portalConn==false){
      	$this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
         $this->mrTemplate->SetAttribute('portal_conn', 'visibility', 'visible');
			$this->mrTemplate->AddVar('portal_conn', 'ISI_PESAN_PORTAL', 'Gagal Menghubungi SI Portal');
      }elseif($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');
      }elseif($umConn==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 Admisi');
      }else{
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
      
      $url_kembali=Dispatcher::Instance()->GetUrl('program_studi', 'programStudi', 'view', 'html');
      $this->mrTemplate->AddVar('warning', 'URL_KEMBALI',$url_kembali );
		
      #$dataProdi = $data['dataProdi'];
      
		if ($_REQUEST['dataId']=='')  {
			$url="addProgramStudi";
			$tambah="Tambah";
		} else {
			$url="updateProgramStudi";
			$tambah="Ubah";
		}
      
      if(($dataProdi[0]['is_ekstakta']=='1')or ($data['data']['ekstakta']=='1')){
         $checked1='checked';
      }elseif(($dataProdi[0]['is_ekstakta']=='0')or ($data['data']['ekstakta']=='0')){
         $checked2='checked';
      }else{
         $checked1='checked';      
      }
      
		$this->mrTemplate->AddVar('status_koneksi', 'JUDUL', $tambah);
		$this->mrTemplate->AddVar('status_koneksi', 'KODE_PRODI', empty($dataProdi[0]['kode_prodi'])?$data['data']['kode_prodi']:$dataProdi[0]['kode_prodi']);
      $this->mrTemplate->AddVar('status_koneksi', 'KODE_UNIV', empty($dataProdi[0]['kode_univ'])?$data['data']['kode_univ']:$dataProdi[0]['kode_univ']);
      $this->mrTemplate->AddVar('status_koneksi', 'LABEL_NIM', empty($dataProdi[0]['prodi_label_nim'])?$data['data']['label_nim']:$dataProdi[0]['prodi_label_nim']);
      $this->mrTemplate->AddVar('status_koneksi', 'NAMA_PRODI', empty($dataProdi[0]['nama_prodi'])?$data['data']['nama_prodi']:$dataProdi[0]['nama_prodi']);
      $this->mrTemplate->AddVar('status_koneksi','CHECKED1',$checked1);
      $this->mrTemplate->AddVar('status_koneksi','CHECKED2',$checked2);
		$this->mrTemplate->AddVar('status_koneksi', 'URL_ACTION', Dispatcher::Instance()->GetUrl('program_studi', $url, 'do', 'html') . "&dataId=" . Dispatcher::Instance()->Encrypt($data['decDataId']));
		$this->mrTemplate->AddVar('status_koneksi', 'DATAID', Dispatcher::Instance()->Decrypt($_GET['dataId']));
		$this->mrTemplate->AddVar('status_koneksi', 'PAGE', Dispatcher::Instance()->Decrypt($_GET['page']));
	}
}
?>
