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

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

class ViewDetailMitraKerja extends HtmlResponse {
	function TemplateModule()
   {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/mitra_kerja/template');
		$this->SetTemplateFile('view_detail_mitra.html');
	}
   
   function ProcessRequest()
   {
      $Obj = new MitraKerja;
      
      // inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
		@$this->Pesan = $msg[0][1];
		@$this->css = $msg[0][2];
      
      // inisialisasi default value
      if (!isset($_GET['mkId']) OR !($data = $Obj->GetMitraById($_GET['mkId']->Integer()->Raw())))
      {
         $this->RedirectTo(Dispatcher::Instance()->GetUrl('mitra_kerja', 'mitraKerja', 'view', 'html'));
         return NULL;
      }
      $return['data'] = $data;
      
      $bidUsahaList = $Obj->GetBidangUsahaList();
      foreach ($bidUsahaList as $value)
         $BIDUSAHA_LIST[$value['id']] = $value['name'];
      $return['bidUsahaList'] = $BIDUSAHA_LIST;
	  
	   $bankList = $Obj->GetBankList();
      foreach ($bankList as $value)
         $BANK_LIST[$value['id']] = $value['name'];
      $return['bankList'] = $BANK_LIST;
	  
	  $cpList = $Obj->GetMkCpById($_GET['mkId']->Integer()->Raw());
      $return['cpList'] = $cpList;
 
      // inisialisasi link address
      $return['link']['url_back'] = Dispatcher::Instance()->GetUrl('mitra_kerja', 'mitraKerja', 'view', 'html');
      $return['link']['url_edit'] = Dispatcher::Instance()->GetUrl('mitra_kerja', 'inputMitraKerja', 'view', 'html').'&mkId='.$data['mkId'];
      @$return['link']['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').
         "&urlDelete=".Dispatcher::Instance()->Encrypt('mitra_kerja|delete|do|html').
         "&urlReturn=".Dispatcher::Instance()->Encrypt('mitra_kerja|detailMitraKerja|view|html-mkId-'.$data['mkId']).
         "&label=".Dispatcher::Instance()->Encrypt('Mitra Kerja').
         "&id=".Dispatcher::Instance()->Encrypt($data['mkId']).
         "&dataName=".Dispatcher::Instance()->Encrypt($data['mkNama']);
      
      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();
      
      // render message box
      if($this->Pesan)
      {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $this->css);
		}
      // ---------
      
      // render link
      $this->mrTemplate->AddVars('content', $data['link'], '');
      // ---------
      
      // render detail mitra kerja
      $form = $data['data'];
      $mkBidUsaha = $form['mkBidUsaha'];
	  $mkBank = $form['mkBank'];
	  
      unset($form['mkBidUsaha']);
		unset($form['mkBank']);
		$form['doc'] = "document/mitrakerja/".$form['mkdocprofile'];
      $this->mrTemplate->AddVars('content', $form, 'VALUE_');
      
      if(count($mkBidUsaha) > 0)
      {
			$this->mrTemplate->AddVar('bu', 'IS_BU_EMPTY', 'NO');
         foreach ($mkBidUsaha as $value)
         {
            $this->mrTemplate->AddVar('BU_LIST', 'MKBIDUSAHA_LIST_ITEM', $data['bidUsahaList'][$value]);
            $this->mrTemplate->parseTemplate('BU_LIST', 'a');
         }
		}
      else $this->mrTemplate->AddVar('bu', 'IS_BU_EMPTY', 'YES');
      // ---------
	  
	   if(count($mkBank) > 0)
      {
			$this->mrTemplate->AddVar('bank', 'IS_BANK_EMPTY', 'NO');
         foreach ($mkBank as $value)
         {
            $this->mrTemplate->AddVar('BANK_LIST', 'MKBANK_LIST_ITEM', $data['bankList'][$value]);
            $this->mrTemplate->parseTemplate('BANK_LIST', 'a');
         }
		}
      else $this->mrTemplate->AddVar('bank', 'IS_BANK_EMPTY', 'YES');
	  
	  
	  $mkCp = $data['cpList'];
	   if(count($mkCp) > 0)
      {
			$this->mrTemplate->AddVar('cp', 'IS_CP_EMPTY', 'NO');
         for ($i=0;$i<sizeof($mkCp);$i++)
         {
		 
			$mkCp[$i]['foto'] = "document/contactperson/".$mkCp[$i]['foto'];
            $this->mrTemplate->AddVars('cp_list', $mkCp[$i],'CP_' );
            $this->mrTemplate->parseTemplate('cp_list', 'a');
         }
		}
      else $this->mrTemplate->AddVar('cp', 'IS_CP_EMPTY', 'YES');
	  
   }
}
?>