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

class ViewPencarianMahasiswa extends HtmlResponse{
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/pencarian_mahasiswa/template');
		$this->SetTemplateFile('view_pencarian.html');
	}
   
   function ProcessRequest(){
   
      $pencarianObj=new AppPencarianMahasiswa();
      $msg = Messenger::Instance()->Receive(__FILE__, $this->mComponentName);
      
      $field=explode("-",$msg[0][1]);
      //field = nama - status - periode -prodi -nim 
      $periodeShow=false;
      $prodiShow=false;
      $nimShow=false;
      $namaShow=false;
      $statusShow=false;
      $periode=$msg[0][3][0];
      $prodiFak=$msg[0][3][1];
      $nim=$msg[0][3][2];
      $nama=$msg[0][3][3];
      $status=$msg[0][3][4];
      $reset=$msg[0][2];
      //print_r($periode);
      for ($i=0;$i<sizeOf($field);$i++){
         
         if ($field[$i]=="periode"){
            $dataTahun=$pencarianObj->GetTahun(1900);
            $tahunMasukAwal=$periode['tahun']['awal'];
            $semesterAwal=$periode['semester']['awal'];
            $tahunMasukAkhir=$periode['tahun']['akhir'];
            $semesterAkhir=$periode['semester']['akhir'];
            
            Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tahun_masuk_awal',
               array('tahun_masuk_awal',$dataTahun,$tahunMasukAwal,'true',''), Messenger::CurrentRequest); 
               
            Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tahun_masuk_akhir',
               array('tahun_masuk_akhir',$dataTahun,$tahunMasukAkhir,'true',''), Messenger::CurrentRequest); 
               
            $dataSemester=$pencarianObj->GetSemesterMasuk();
            Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'sems_masuk_awal',
               array('sems_masuk_awal',$dataSemester,$semesterAwal,'true',''), Messenger::CurrentRequest);
            
            Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'sems_masuk_akhir',
               array('sems_masuk_akhir',$dataSemester,$semesterAkhir,'true',''), Messenger::CurrentRequest);
            
            $periodeShow=True;
         }elseif($field[$i]=="prodi"){      
            //print_r($prodiFak);
            $prodi=$prodiFak['prodi'];
            $fakultas=$prodiFak['fakProdi'];
            $dataProdi=$pencarianObj->GetDataProdi();
            $dataFakultas=$pencarianObj->GetFakultas();
            
            foreach($dataProdi as $value ){
               if (isset($dataProdi[0])) $dataProdi = array();
               $dataProdi[$value['fakKode']][] = array($value['id'],$value['name']);
               
               if ($value['fakKode'] == $fakultas)
                  $arrProdi[] = array('id'=>$value['id'], 'name'=>$value['name']);
            }
            $return['json']['prodi']=json_encode($dataProdi);
            Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'program_studi',
               array('program_studi',$arrProdi,$prodi,'true','id="comboProdi"'), Messenger::CurrentRequest);

            
            Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'fakultas',
               array('fakultas',$dataFakultas,$fakultas,'true','onchange="updateProdi();" '), Messenger::CurrentRequest);
               
            $prodiShow=True;
            
         }elseif($field[$i]=="nim"){
            $nimShow=true;
         }elseif($field[$i]=="nama"){
            $namaShow=True;
         }elseif($field[$i]=="status"){         
            $dataStatus=$pencarianObj->GetStatusMahasiswa();
            Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_mahasiswa',
                  array('is_calon',$dataStatus,$status,'true',''), Messenger::CurrentRequest);  
            $statusShow=TRUE;
         }
         
      }

      $return['show']['periodeShow']=$periodeShow;
      $return['show']['prodiShow']=$prodiShow;
      $return['show']['nimShow']=$nimShow;
      $return['show']['namaShow']=$namaShow;
      $return['show']['statusShow']=$statusShow;
      $return['show']['reset']=$reset;
      $return['data']['nim']=$nim;
      $return['data']['nama']=$nama;
      $return['urlSearch']=$msg[0][0];
      return $return;
   }
   
   function Parsetemplate($data=null){
      $urlSearch=$data['urlSearch'];
      
      $nim=$data['data']['nim'];
      $nama=$data['data']['nama'];
		$this->mrTemplate->AddVars('content', $data['json'], 'JSON_');
      $this->mrTemplate->AddVar('content','URL_SEARCH',$urlSearch);
      $show=$data['show'];

      if($show['periodeShow']==true){
         $this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
      }   
      
      if($show['prodiShow']==true){
         $this->mrTemplate->SetAttribute('prodi', 'visibility', 'visible');
      }  

      if($show['nimShow']==true){
         $this->mrTemplate->SetAttribute('nim', 'visibility', 'visible');
         $this->mrTemplate->AddVar('nim', 'NOTES_NIM', $nim);
      }   
      
      if($show['namaShow']==true){
         $this->mrTemplate->SetAttribute('nama', 'visibility', 'visible');
         $this->mrTemplate->AddVar('nama', 'NAMA', $nama);
      }
         
      if($show['statusShow']==true){
         $this->mrTemplate->SetAttribute('status', 'visibility', 'visible');
      }
      if($show['reset']==true){
         $this->mrTemplate->SetAttribute('reset', 'visibility', 'visible');
      }
   }

}
?>