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


class ViewDetailStatus extends HtmlResponse {
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/status/template');
		$this->SetTemplateFile('view_detail_status.html');
	}
   
   function ProcessRequest(){
      $statusObj=new AppStatus();
      $idDec = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
      $cari = Dispatcher::Instance()->Decrypt($_REQUEST['cari']);
      
		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);
      $msg = Messenger::Instance()->Receive(__file__);
      
      $dataSemesterAktif = $statusObj->GetSemesterAktif();
      $dataStatus=$statusObj->GetDetailMahasiswa($idDec);
      $dataRiwayatMhs=$statusObj->GetRiwayatMahasiswa($idDec,$idDec);      

      $return['pesan'] = $msg[0][1];
		  $return['css'] = $msg[0][2];  
      $return ['dataStatus']=$dataStatus;
      $return ['dataRiwayatMhs']=$dataRiwayatMhs;
      $return['dataSemesterAktif'] = $dataSemesterAktif;
      $return['start'] = $startRec+1;
      $return ['decId']=$idDec;
      $return ['cari']=$cari;
      return $return;
   }
   function ParseTemplate($data=NULL){

      $cari=$data['cari'];
      $dataStatus=$data['dataStatus'];
      $dataRiwayatMhs = $data['dataRiwayatMhs'];
      $dataSemesterAktif = $data['dataSemesterAktif'];
      
      $URL_RETURN = Dispatcher::Instance()->GetUrl('status', 'status', 'view', 'html');
      $this->mrTemplate->AddVar('content','URL_RETURN',$URL_RETURN);
      $this->mrTemplate->AddVar('content', 'CARI', $cari);
      
      $this->mrTemplate->AddVar('content', 'STATUS_NIM', empty($dataStatus[0]['nim'])?'-':$dataStatus[0]['nim']);
      $this->mrTemplate->AddVar('content', 'STATUS_NAMA', empty($dataStatus[0]['nama'])?'-':$dataStatus[0]['nama']);      
      $this->mrTemplate->AddVar('content', 'STATUS_PRODI', empty($dataStatus[0]['prodi'])?'-':$dataStatus[0]['prodi']);
      $this->mrTemplate->AddVar('content', 'STATUS_ANGKATAN', empty($dataStatus[0]['angkatan'])?'-':$dataStatus[0]['angkatan']);
      #print_r($dataRiwayatMhs);

      $this->mrTemplate->AddVar('semester', $data['dataSemesterAktif'][0], '');
      
		if(!empty($data['dataSemesterAktif'])){
         $this->mrTemplate->SetAttribute('semester', 'visibility', 'visible');
         $this->mrTemplate->AddVar('semester', $data['dataNamaSemester'][0], '');   
      }
      
      if (empty($data['dataRiwayatMhs'])) {
			$this->mrTemplate->AddVar('data_detil', 'DETIL_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_detil', 'DETIL_EMPTY', 'NO');
			$dataRiwayatMhs = $data['dataRiwayatMhs'];

         for ($i=0; $i<sizeof($dataRiwayatMhs); $i++) {
				$no = $i+$data['start'];
				$dataRiwayatMhs[$i]['number'] = $no;
				if ($no % 2 != 0) $dataRiwayatMhs[$i]['class_name'] = 'table-common-even';
				else $dataRiwayatMhs[$i]['class_name'] = '';
				
				if($dataRiwayatMhs[$i]['status'] == 'A'){
               $dataRiwayatMhs[$i]['STATUS_TITLE'] = 'Aktif';
            }elseif($dataRiwayatMhs[$i]['status'] == 'C'){
               $dataRiwayatMhs[$i]['STATUS_TITLE'] = 'Cuti';
            }elseif($dataRiwayatMhs[$i]['status'] == 'L'){
               $dataRiwayatMhs[$i]['STATUS_TITLE'] = 'Lulus';
            }elseif($dataRiwayatMhs[$i]['status'] == 'D'){
               $dataRiwayatMhs[$i]['STATUS_TITLE'] = 'Drop-Out';
            }elseif($dataRiwayatMhs[$i]['status'] == 'K'){
               $dataRiwayatMhs[$i]['STATUS_TITLE'] = 'Keluar';
            }else{
               $dataRiwayatMhs[$i]['STATUS_TITLE'] = 'Non-Aktif';
            }
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataRiwayatMhs)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$this->mrTemplate->AddVars('data_detil_item', $dataRiwayatMhs[$i], 'DETIL_');
				$this->mrTemplate->parseTemplate('data_detil_item', 'a');	 
         }
      }
   }
}

?>