<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/nim_formula/business/AppNimFormula.class.php';
class ViewSettingNimFormulaFormat extends HtmlResponse {
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/nim_formula/template');
		$this->SetTemplateFile('setting_nim_formula_format.html');
	}
   
   function ProcessRequest(){
      $nimObj=new AppNimFormula();
      
      $msg = Messenger::Instance()->Receive(__FILE__);
      $formula=$_SESSION['formula'];
      $dataId=$msg[0][0]['dataId'];

      $formulaKomp=explode('&',$formula);
      $dataNimKomponen=$nimObj->GetNimKomponen();
      $nimFormulaById=$nimObj->GetNimFormulaById($dataId);
      $formatFormula=str_replace(array('.','/','-'),'',$nimFormulaById[0]['formula_format']);
      $format=explode('&',$formatFormula);
      #$formula = str_replace('&', '', $nimFormulaById[0]['formula']);
      $formula = str_replace('&', '', $formula);

      for($k=0;$k<sizeof($format);$k++){
         $komp[$k]=substr($format[$k], 0, 5);
      }
      
      for($i=0;$i<sizeof($komp);$i++){  
         if($komp[$i]=='[001]' ){
            $dataSf=explode(':',$format[$i]);
            $k001=$dataSf[1];
         }elseif($komp[$i]=='[003]' ){
            $dataSf=explode(':',$format[$i]);
            $k003=$dataSf[1];
         }elseif($komp[$i]=='[004]' ){
            $dataSf=explode(':',$format[$i]);
            $k004=$dataSf[1];
         }elseif($komp[$i]=='[005]' ){
            $dataSf=explode(':',$format[$i]);
            $k005=$dataSf[1];
         }elseif($komp[$i]=='[006]' ){
            $dataSf=explode(':',$format[$i]);
            $k006=$dataSf[1];
         }elseif($komp[$i]=='[007]' ){
            $dataSf=explode(':',$format[$i]);
            $k007=$dataSf[1];
         }elseif($komp[$i]=='[008]' ){
            $data008=explode(':',$format[$i]);
            $value=explode('|',$data008[1]);
            $k008_jml_digit=$value[0];
            $k008_tipe=$value[1];
            $k008_thn_mulai=$value[2];
            $k008_nim_mulai=$value[3];
         }elseif($komp[$i]=='[009]' ){
            $dataSf=explode(':',$format[$i]);
            $k009=$dataSf[1];
         }
      }
      

      
      $valueFormat001[0]['id']=2;
      $valueFormat001[0]['name']=2;
      $valueFormat001[1]['id']=4;
      $valueFormat001[1]['name']=4;
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k001',
         array('k001',$valueFormat001,$k001,'false',''), 
         Messenger::CurrentRequest);
         
      for($i=3;$i<=6;$i++){
            $dataK001[$i]['id']=$i;
            $dataK001[$i]['name']=$i;
      }
      
      $valueFormat3_6=array_values($dataK001);
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k003',
         array('k003',$valueFormat3_6,$k003,'false',''), 
         Messenger::CurrentRequest);      
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k004',
         array('k004',$valueFormat3_6,$k004,'false',''), 
         Messenger::CurrentRequest);      
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k005',
         array('k005',$valueFormat3_6,$k005,'false',''), 
         Messenger::CurrentRequest);      
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k006',
         array('k006',$valueFormat3_6,$k006,'false',''), 
         Messenger::CurrentRequest);      
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k007',
         array('k007',$valueFormat3_6,$k007,'false',''), 
         Messenger::CurrentRequest);      
      

      
      for($i=2;$i<=4;$i++){
            $data[$i]['id']=$i;
            $data[$i]['name']=$i;
      }
      
      $valueFormat2_4=array_values($data); 
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k008_jml_digit',
         array('k008_jml_digit',$valueFormat2_4,$k008_jml_digit,'false',''), 
         Messenger::CurrentRequest);
         
      $valueFormatTipe[0]['id']="Angka";
      $valueFormatTipe[0]['name']="Angka";
      $valueFormatTipe[1]['id']="Abjad";
      $valueFormatTipe[1]['name']="Abjad";

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k008_tipe',
         array('k008_tipe',$valueFormatTipe,$k008_tipe,'false',''), 
         Messenger::CurrentRequest);
         
      $tahunMulai=$nimObj->GetTahun(1950);
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k008_thn_mulai',
         array('k008_thn_mulai',$tahunMulai,$k008_thn_mulai,'false',''), 
         Messenger::CurrentRequest);      
      
    
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html','k009',
         array('k009',$valueFormat3_6,$k009,'false',''), 
         Messenger::CurrentRequest);      
      
      $return['k008_nim_mulai']=$k008_nim_mulai;
      $return['pesan']=$msg[0][1];
      $return['dataNimKomponen']=$dataNimKomponen;
      $return['formulaKomp']=$formulaKomp;
      $return['dataId']=$dataId;
      $return['formula']=$formula;
      return $return;
   }
   
   function ParseTemplate($data=NULL){
      $k008_nim_mulai=$data['k008_nim_mulai'];
      $dataNimKomponen=$data['dataNimKomponen'];
      $formulaKomp=$data['formulaKomp'];
      $dataId=$data['dataId'];
		
      if ($data['pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
		}
      
      if($dataId==''){
         $url='addNimFormula';
      }else{
         $url='updateNimFormula';
      }
      
      $url_action=Dispatcher::Instance()->GetUrl('nim_formula',$url,'do','html');
      $url_back=Dispatcher::Instance()->GetUrl('nim_formula','settingNimFormula','view','html').'&dataId='.$dataId;
      $this->mrTemplate->AddVar('content','URL_ACTION',$url_action);
      $this->mrTemplate->AddVar('content','URL_BACK',$url_back);
      $this->mrTemplate->AddVar('content','DATA_ID',$dataId);
      $this->mrTemplate->AddVar('content','FORMULA_NIM',$data['formula']);

      $this->mrTemplate->AddVar('k008','KOO8_NIM_MULAI',$k008_nim_mulai);


      for($i=0;$i<sizeOf($dataNimKomponen);$i++){
         for($j=0;$j<sizeOf($formulaKomp);$j++){
            if($formulaKomp[$j]==='['.$dataNimKomponen[$i]['komp_kode'].']'){           
               $this->mrTemplate->SetAttribute('k'.$dataNimKomponen[$i]['komp_kode'], 'visibility', 'visible');
            }
         }
      }
   }
}

?>