<?php

/*
 @ClassName : Print Laporan DIR
 @Copyright : PT Gamatechno Indosnesia
 @Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
 @Designed By : Rosyid <rosyid@gamatechno.com>
 @Author By : Dyan Galih <galih@gamatechno.com>
 @Version : 1.0
 @StartDate : Nov 11, 2008
 @LastUpdate : Nov 11, 2008
 @Description :
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/laporan_dir/business/AppLaporanDir.class.php';
//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';
class printLaporanDir extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/laporan_dir/template');
      $this->SetTemplateFile('print_laporan_dir.html');
   }
   
   function TemplateBase() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-print.html');
      $this->SetTemplateFile('layout-common-print.html');
   }
   
   function TemplateLabeling(){
      $ObjLabel = new GetModuleLabel();
      $arrLabel = $ObjLabel->GetLabel();
      //patTemplate name yang memiliki label2 dinamic
      $arrContent=array("content");
      
      for($i=0;$i<count($arrContent);$i++){
         for($j=0;$j<count($arrLabel);$j++){
            $this->mrTemplate->AddVar($arrContent[$i],$arrLabel[$j]['labelCode'],$arrLabel[$j]['labelName']);
         }
      }
   }
   
   function ProcessRequest() {
      $Obj = new AppLaporanDir();
      $user = $Obj->GetDataUserByUsername($_SESSION['username']);
      $gedung = Dispatcher::Instance()->Decrypt($_GET['gedung']);
      $pj = Dispatcher::Instance()->Decrypt($_GET['pj']);
      $return['data']= $Obj->getDataDir($gedung,$pj);
      
      $return['unit']['unitkerjaNama'] = $user['unitkerjaNama'];
      $return['unit']['unitkerjaKode'] = $user['unitkerjaKode'];
      $return['gedung'] = $gedung;
      $return['pj'] = $pj;
   	return $return;  
   }
   
   function ParseTemplate($data = NULL) {
   	
      $this->TemplateLabeling();
      
      if($data['gedung'] <> 'all' && $data['gedung'] <> '') $gedung = $data['data'][0]['gedungNama'];
      else $gedung = "Semua Gedung";
      if($data['pj'] <> 'all' && $data['pj'] <> '') $ruang = $data['data'][0]['ruangNama'];
      else $ruang = "Semua Ruang";
      if($data['gedung'] == 'all' || $data['gedung']== '' || $data['pj'] == 'all' || $data['pj'] == ''){
          $unitNama = $data['unit']['unitkerjaNama'];
          $unitKode = $data['unit']['unitkerjaKode'];
      }else{
          $unitNama = $data['data'][0]['unitkerjaNama'];
          $unitKode = $data['data'][0]['unitkerjaKode'];
      }
      $this->mrTemplate->AddVar('content','NAMA_GEDUNG',$gedung);
      $this->mrTemplate->AddVar('content','NAMA_RUANG',$ruang);
      $this->mrTemplate->AddVar('content','NAMA_UPB',$unitNama);
      $this->mrTemplate->AddVar('content','KODE_UPB',$unitKode);
      $this->mrTemplate->AddVar('content','TANGGAL',date('d-F-Y'));
      $city = GTFWConfiguration::GetValue('organization', 'city');
		$this->mrTemplate->AddVar('content','CITY',$city);
      
      if(empty($data['data'])){
      	$this->mrTemplate->AddVar('data','DATA_EMPTY','YES');
      	return;
		}else
			$this->mrTemplate->AddVar('data','DATA_EMPTY','NO');
			
			$dataGrid = $data['data'];
			$no = 1;
			
			for($i=0;$i<count($dataGrid);$i++){
				$dataGrid[$i]['no'] = $no+$i;
				
				$this->mrTemplate->AddVars('data_item',$dataGrid[$i],'DIR_');
				$this->mrTemplate->parseTemplate('data_item','a');
			}
			
			if(isset($data['msg'])) {
				if($data['msg'] == 'add') {
					$isiPesan = 'Proses Penambahan Data Berhasil';
					$class = 'notebox-done';
				}
				elseif($data['msg'] == 'noadd') {
					$isiPesan = 'Proses Penambahan Data Gagal';
					$class = 'notebox-warning';
				}elseif($data['msg'] == 'update') {
					$isiPesan = 'Proses Perubahan Data Berhasil';
					$class = 'notebox-done';
				}
				elseif($data['msg'] == 'noupdate') {
					$isiPesan = 'Proses Perubahan Data Gagal';
					$class = 'notebox-warning';
				}elseif($data['msg'] == 'del') {
					$isiPesan = 'Data Berhasil Dihapus';
					$class = 'notebox-done';
				}
				elseif($data['msg'] == 'nodel') {
					$isiPesan = 'Data Gagal Dihapus';
					$class = 'notebox-warning';
				}elseif($data['msg'] == 'null') {
					$isiPesan = 'Nama Jalur Pengadaan Barang Harap Diisi. ';
					$class = 'notebox-warning';
				}
			}
   }
}
?>
