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

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

class ViewPopUpLokasiAset 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/inventarisasi/template');
      $this->SetTemplateFile('pop_up_lokasi_aset.html');
   }
	
	function ProcessRequest()
   {
      $Obj = new PopUpLokasiAset;
      $User = $Obj->GetDataUserByUsername($_SESSION['username']);		
		
      // Inisislisasi filter
      if (isset($_POST['gedungKode']))
      {
         $cari['gedungKode'] = $_POST['gedungKode']->Raw();
         $cari['ruangKode'] = $_POST['ruangKode']->Raw();
         $cari['nama'] = $_POST['nama']->Raw();
      }
      elseif (isset($_GET['cari']))
         $cari = unserialize(base64_decode($_GET['cari']->Raw()));
      else
      {
         $cari['gedungKode'] = '';
         $cari['ruangKode'] = '';
         $cari['nama'] = '';
      }
      
      $return['filter'] = $cari;
      extract($cari);
      $cari = base64_encode(serialize($cari));
      // ---------
      
      // Inisialisasi komponen paging
      $totalData = $Obj->GetCountData($gedungKode, $ruangKode, $nama);
      $itemViewed = 10;
      if (isset($_GET['page'])) $currPage = $_GET['page']->Integer()->Raw();
      if (!isset($currPage) OR $currPage < 1) $currPage = 1;
      $startRec = ($currPage - 1) * $itemViewed;
      
      $url = Dispatcher::Instance()->GetUrl
      (
         Dispatcher::Instance()->mModule,
         Dispatcher::Instance()->mSubModule,
         Dispatcher::Instance()->mAction,
         Dispatcher::Instance()->mType
      ) . "&cari=$cari";
		$dest = "popup-subcontent";
      Messenger::Instance()->SendToComponent('paging', 'paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, $currPage, $dest), Messenger::CurrentRequest);
      $return['start'] = $startRec+1;
      // ---------
      
      // Inisialisasi link URL
      $return['link']['search'] = Dispatcher::Instance()->GetUrl
      (
         Dispatcher::Instance()->mModule->Raw(),
         Dispatcher::Instance()->mSubModule->Raw(),
         Dispatcher::Instance()->mAction->Raw()
        // Dispatcher::Instance()->mType->Raw()
      );
      // ---------
      
      // Generate dataGrid
      $return['data'] = $Obj->GetData($gedungKode, $ruangKode, $nama, $startRec, $itemViewed);
      
      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 filter($string){
		return addslashes($string);
	}
	
	function ParseTemplate($data = NULL)
   {
      //set Label
      $this->TemplateLabeling();
      
      // render filter value
	    $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('inventarisasi','popUpLokasiAset','view', 'html'));
		$this->mrTemplate->AddVars('content', $data['filter'], '');
      
      // render datagrid
		if (empty($data['data']))
      {
         $this->mrTemplate->AddVar('data_unitkerja', 'DATA_EMPTY', 'YES');
         return;
      }
      else $this->mrTemplate->AddVar('data_unitkerja', 'DATA_EMPTY', 'NO');
      
      $i = $data['start'];
      $gedungId = false;
      foreach ($data['data'] as $ruang)
      {
         if ($ruang['gedungId'] !== $gedungId)
         {
            // Gedung
            $data = array();
            $data['class_name'] = 'table-common-even';
            $data['padding'] = '';
            $data['kode'] = $ruang['gedungKode'];
            $data['nama'] = $ruang['gedungNama'];
            $data['gedungId'] = $ruang['gedungId'];
            $data['ruangId'] = 0;
            $data['name'] = $this->filter($ruang['gedungNama']);
            $data['number'] = $i;
				$this->mrTemplate->AddVars('data_item', $data, '');
				$this->mrTemplate->parseTemplate('data_item', 'a');
            
            $gedungId = $ruang['gedungId'];
            $data['class_name'] = '';
            $data['padding'] = '16px';
				$i++;
         }
         
         // Ruang
         $data['number'] = '';
         $data['kode'] = $ruang['ruangKode'];
         $data['nama'] = $ruang['ruangNama'];
         $data['ruangId'] = $ruang['ruangId'];
         $data['name'] = $this->filter($ruang['gedungNama']." &raquo; ".$ruang['ruangNama']);
         
         $this->mrTemplate->AddVars('data_item', $data, '');
         $this->mrTemplate->parseTemplate('data_item', 'a');
         
         
      }
	}
}
?>
