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

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/mahasiswa/template');
		$this->SetTemplateFile('view_input_nilai_smta.html');
	}
	
	function ProcessRequest(){
	
      $mhsObj= new AppMahasiswa();
      $idDec = Dispatcher::Instance()->Decrypt($_REQUEST['mhsId']);

      
      $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);
         //print($dataMatPel[$i]['matapelajaran_id']);
      }
      //print_r($dataNilaiMatPel);exit;
      $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['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'];
      $idDec = $data['idDec'];
      $idEnc = Dispatcher::Instance()->Encrypt($idDec);
		$this->mrTemplate->AddVar('content', 'MHSID',$idDec);
		$this->mrTemplate->AddVar('content', 'URL_ACTION',Dispatcher::Instance()->GetUrl('mahasiswa', 'AddNilaiSmta', 'do', 'html').'&mhsId='.$idEnc);
		$this->mrTemplate->AddVar('content', 'URL_BATAL',Dispatcher::Instance()->GetUrl('mahasiswa', 'NilaiSmta', 'view', 'html').'&mhsId='.$idEnc);
		$this->mrTemplate->AddVar('content', 'JUMLAH_SEMESTER',sizeof($dataPeriodeSmta)+1);
         
      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($k=0;$k<=50;$k++){
                  $this->mrTemplate->AddVar('combo_nilai','ID',$dataComboNilai[$k]['ID']);
                  $this->mrTemplate->AddVar('combo_nilai','NAME',$dataComboNilai[$k]['NAME']);
                  $this->mrTemplate->parseTemplate('combo_nilai', 'a'); 
               }
            for($j=0;$j<sizeOf($dataNilaiMatPel[$i]);$j++){            
               if($dataNilaiMatPel[$i][$j]['NILAI']=='0')
                  $dataNilaiMatPel[$i][$j]['NILAI_NAME']='-';
               else
                  $dataNilaiMatPel[$i][$j]['NILAI_NAME']=$dataNilaiMatPel[$i][$j]['NILAI'];
                  
               $dataNilaiMatPel[$i][$j]['NO']=$i;
               $dataNilaiMatPel[$i][$j]['NO_COLS']=$j;
               $this->mrTemplate->AddVar('data_nilai_semester','NO', $dataNilaiMatPel[$i][$j]['NO']);
               $this->mrTemplate->AddVar('data_nilai_semester','PERIODE_ID', $dataNilaiMatPel[$i][$j]['PERIODE_ID']);
               $this->mrTemplate->AddVar('data_nilai_semester','MATAPELAJARAN_ID', $dataMatPel[$i]['matapelajaran_id']);
               $this->mrTemplate->AddVar('data_nilai_semester','MAHASISWA_ID', $idDec);
               $this->mrTemplate->AddVar('data_nilai_semester','NILAI', $dataNilaiMatPel[$i][$j]['NILAI']);
               $this->mrTemplate->AddVar('data_nilai_semester','NILAI_NAME', $dataNilaiMatPel[$i][$j]['NILAI_NAME']);
               $this->mrTemplate->parseTemplate('data_nilai_semester', 'a'); 
            }
            $this->mrTemplate->AddVars('data_item', $dataMatPel[$i]);
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }  
      }
   }
}
?>
