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

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/mahasiswa/template');
		$this->SetTemplateFile('view_nilai_smta.html');
	}
	
	function ProcessRequest(){
	   $msg = Messenger::Instance()->Receive(__FILE__);
      $mhsObj= new AppMahasiswa();
      if(isset($_REQUEST['mhsId'])){
         $idDec = Dispatcher::Instance()->Decrypt($_REQUEST['mhsId']);
      }else{
         $idDec = $msg[0][0];
         
      }
      $pesan=$msg[0][1];
      $css=$msg[0][2];
//print_r($msg);
      
      $infoMahasiswa = $mhsObj -> GetInfoMahasiswa($idDec); 
      $totalMatPel = $mhsObj -> GetCountMataPelajaran();
      $dataMatPel = $mhsObj -> GetMataPelajaranSmta();
      $dataPeriodeSmta = $mhsObj -> GetPeriodeSmta();
      $dataComboNilai = $mhsObj -> GetDataForComboNilai();
      
      for($i=0;$i<$totalMatPel;$i++){
         $dataNilaiMatPel[]=$mhsObj->GetNilaiMataPelajaranSmta($dataMatPel[$i]['matapelajaran_id'],$idDec);
      }
      
      $itemViewed = $totalMatPel;
		$currPage = 1;
		$startRec = 0 ;
		
      if(!empty($dataMatPel)){
      
         $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
                Dispatcher::Instance()->mSubModule, 
                Dispatcher::Instance()->mAction, 
                Dispatcher::Instance()->mType);
                
         Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top',
            array($itemViewed,$totalData, $url, $currPage), 
            Messenger::CurrentRequest); 
      }

      
      $result['pesan']=$pesan;
      $result['css']=$css;
      $result['infoMahasiswa'] = $infoMahasiswa;
      $result['dataMatPel']=$dataMatPel;
      $result['dataPeriodeSmta']=$dataPeriodeSmta;
      $result['dataNilaiMatPel']=$dataNilaiMatPel;
      $result['idDec']=$idDec;
      $result['dataComboNilai']=$dataComboNilai;
      return $result;
   }
   
   function ParseTemplate($data=NULL){
      $infoMahasiswa = $data['infoMahasiswa'];
      $dataMatPel = $data['dataMatPel'];
      $dataPeriodeSmta = $data['dataPeriodeSmta'];
      $dataNilaiMatPel = $data['dataNilaiMatPel'];
      $dataComboNilai = $data['dataComboNilai'];
      $pesan = $data['pesan'];
      $css = $data['css'];
      $idDec = $data['idDec'];
      $idEnc = Dispatcher::Instance()->Encrypt($idDec);
		$this->mrTemplate->AddVar('content', 'URL_UBAH',Dispatcher::Instance()->GetUrl('mahasiswa', 'InputNilaiSmta', 'view', 'html').'&mhsId='.$idEnc);
		$this->mrTemplate->AddVar('content', 'URL_KEMBALI',Dispatcher::Instance()->GetUrl('mahasiswa', 'detailMahasiswa', 'view', 'html').'&dataId='.$idEnc);
     
      if($pesan) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $pesan);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $css);
		}
		
      if(!empty($infoMahasiswa)){
         $len=sizeOf($infoMahasiswa);
         for($i=0;$i<$len;$i++){
            $this->mrTemplate->AddVars('info_mhs', $infoMahasiswa[$i]);
            $this->mrTemplate->parseTemplate('info_mhs', 'a');
         }
      }
      
      if(!empty($dataPeriodeSmta)){
         $len=sizeOf($dataPeriodeSmta);
         for($i=0;$i<$len;$i++){
            $this->mrTemplate->AddVars('header_semester', $dataPeriodeSmta[$i]);
            $this->mrTemplate->parseTemplate('header_semester', 'a'); 
         }
      }
      if(!empty($dataMatPel)){
         $len=sizeOf($dataMatPel);
         //print_r($dataComboNilai);
         for($i=0;$i<$len;$i++){
            $dataMatPel[$i]['NO']=$i+1;
            $this->mrTemplate->clearTemplate('data_nilai_semester');
            $this->mrTemplate->clearTemplate('combo_nilai');
            for($j=0;$j<sizeOf($dataNilaiMatPel[$i]);$j++){            
               if($dataNilaiMatPel[$i][$j]['NILAI']==0)
                  $dataNilaiMatPel[$i][$j]['NILAI']='-';
               $this->mrTemplate->AddVar('data_nilai_semester','MATAPELAJARAN_ID', $dataMatPel[$i]['matapelajaran_id']);
               $this->mrTemplate->AddVar('data_nilai_semester','NILAI', $dataNilaiMatPel[$i][$j]['NILAI']);
               $this->mrTemplate->parseTemplate('data_nilai_semester', 'a'); 
            }
            $this->mrTemplate->AddVars('data_item', $dataMatPel[$i]);
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }  
      }
   }
}
?>
