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

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

class ViewCetakKib2 extends HtmlResponse
{
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/inventarisasi/template');
		//print_r($_GET['size']->raw());
		$size = $_GET['size']->raw();
		if($size==10){
			$this->SetTemplateFile('view_cetak_kib2.html');
		} else {
			$this->SetTemplateFile('view_cetak_kib2_5cm.html');
		}
	}
   
    function TemplateBase()
    {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      //$this->SetTemplateFile('document-print.html');
      //$this->SetTemplateFile('layout-common-print.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new AppInventarisasi();
      
      if (!isset($_GET['id']) or $_GET['id'] == '')
         $return['data'] = array();
      else $return['data'] = $Obj->GetCetakKib2($_GET['id']->Raw());
	  $return['size'] = $_GET['size']->raw();
      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)
   {
      $keys = implode('|', array_keys($data));
     
      //set Label
      $this->TemplateLabeling();
 
      if (empty($data['data']))
      {
			$this->mrTemplate->SetAttribute('empty', 'visibility', 'visible');
         return;
      }
      else $this->mrTemplate->SetAttribute('kib', 'visibility', 'visible');
      
      foreach ($data['data'] as $value)
      {
         list($tmp['kode_a'], $tmp['kode_b']) = explode('|', $value);
         if ($data['size'] == 10) $tmp['kode_a'] = str_replace('#','',$tmp['kode_a']);
         else $tmp['kode_a'] = str_replace('#','<br>',$tmp['kode_a']);
         $tmp['barcode'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule,'barcode','view','img')."&text=".$tmp['kode_b'];
         $this->mrTemplate->AddVars('kib', $tmp, '');
         $this->mrTemplate->parseTemplate('kib', 'a');
      }
   }
   
}
?>