<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot').
   'module/'.Dispatcher::Instance()->mModule.'/business/MAK.class.php';

//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot').
   'module/label/response/Label.proc.class.php';

class ViewPopUpMak extends HtmlResponse {

	function TemplateBase()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-common-popup.html');
      $this->SetTemplateFile('layout-common-popup.html');
   }
   
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('view_pop_up_mak.html');
   }
	
	function ProcessRequest()
   {
		$Obj = new MAK;
      
      // Inisialisasi Filter
      $filter = array ('program'=>'all', 'jnskeg'=>'all');
      if (isset($_POST['program']))
      {
         $filter['program'] = $_POST['program']->Raw();
         $filter['jnskeg'] = $_POST['jnskeg']->Raw();
      }
		// ---------
      
      // Inisialisasi Combo Box
      $comboProgram = $Obj->ComboProgram();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'program', array('program', $comboProgram, $filter['program'], true, ''), Messenger::CurrentRequest);
      
      $comboJnsKeg = $Obj->ComboJnsKeg();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jnskeg', array('jnskeg', $comboJnsKeg, $filter['jnskeg'], true, ''), Messenger::CurrentRequest);
      // ---------
		
      // Inisialisasi Data Grid
		$data = $Obj->PopUpList($filter, 0, pow(2,30));
      $return['data'] = $data;
      // ---------
      
		return $return;
	}
	
   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 ParseTemplate($data = NULL)
   {
      //set Label
      $this->TemplateLabeling();
	  $search = $data['search'];
   
	  $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('verifikasi_pengadaan', 'PopUpMak', 'view', 'html'));
      
      if (empty($data['data']))
      {
			$this->mrTemplate->AddVar('tabel_mak', 'MAK_EMPTY', 'YES');
         return;
      }
      else $this->mrTemplate->AddVar('tabel_mak', 'MAK_EMPTY', 'NO');
      
      $program = '';
      $subProgram = '';
      foreach ($data['data'] as $value)
      {
         // Program
         if ($program != $value['namaProgram'])
         {
            $tmp = array();
            $tmp['class_name'] = 'table-common-even1';
            $tmp['kode_kegiatan'] = explode('.', $value['kodeKegiatan']);
            $tmp['kode_kegiatan'] = $tmp['kode_kegiatan'][0].".00.00";
            $tmp['nama_kegiatan'] = $value['namaProgram'];
            
            $this->mrTemplate->AddVars('mak_item', $tmp, '');
            $this->mrTemplate->SetAttribute('icon_pilih', 'visibility', 'hidden');
            $this->mrTemplate->parseTemplate('mak_item', 'a');
            
            $this->mrTemplate->SetAttribute('icon_pilih', 'visibility', 'visible');
            $program = $value['namaProgram'];
         }
         
         // Sub Program
         if ($subProgram != $value['namaSubProgram'])
         {
            $tmp = array();
            $tmp['class_name'] = 'table-common-even';
            $tmp['indent'] = '10px';
            $tmp['kode_kegiatan'] = explode('.', $value['kodeKegiatan']);
            $tmp['kode_kegiatan'] = $tmp['kode_kegiatan'][0].".".$tmp['kode_kegiatan'][1].".00";
            $tmp['nama_kegiatan'] = $value['namaSubProgram'].' <i>('.$value['jenisKegiatan'].')</i>';
            
            $this->mrTemplate->AddVars('mak_item', $tmp, '');
            $this->mrTemplate->SetAttribute('icon_pilih', 'visibility', 'hidden');
            $this->mrTemplate->parseTemplate('mak_item', 'a');
            
            $this->mrTemplate->SetAttribute('icon_pilih', 'visibility', 'visible');
            $subProgram = $value['namaSubProgram'];
         }
         
         // Kegiatan
         $tmp = array();
         $tmp['class_name'] = '';
         $tmp['indent'] = '20px';
         $tmp['kode_kegiatan'] = $value['kodeKegiatan'];
         $tmp['nama_kegiatan'] = $value['namaKegiatan'];
         $tmp['nominal'] = number_format($value['nominal_approve'],2,',','.');
         $tmp['nominal_approve'] = $value['nominal_approve'];
         
         $this->mrTemplate->AddVars('mak_item', $tmp, '');
         $this->mrTemplate->AddVars('icon_pilih', $tmp, '');
         $this->mrTemplate->parseTemplate('mak_item', 'a');
      }
	}
}
?>
