<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/aset_ref_bank/response/ProcessBank.proc.class.php';

class ViewBank extends HtmlResponse {
   
   protected $proc;
   protected $data;
   
   function ViewBank() {
     $this->proc = new ProcessBank();   
   }
   
   
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/aset_ref_bank/template');
      $this->SetTemplateFile('view_bank.html');
   }
   
   function ProcessRequest() { 
      if(isset($_POST['data'])) {
	     if(is_object($_POST['data']))
		    $this->data = $_POST['data']->AsArray();
		 else
		   $this->data = $_POST['data'];		 
	  }
        
	  
	  $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();  
         $startRec =($currPage-1) * $itemViewed;
      }	
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
               Dispatcher::Instance()->mSubModule, 
               Dispatcher::Instance()->mAction, 
               Dispatcher::Instance()->mType
               );
	  
	  $data = $this->proc->Bank->GetData($startRec,$itemViewed,$this->data);
	  $totalData = $this->proc->Bank->GetCount();	   
	  
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', 
         array($itemViewed,$totalData, $url, $currPage), 
         Messenger::CurrentRequest);
		 
	  @$tmp=$this->proc->parsingUrl(__FILE__);
      $return['msg'] = $tmp['msg'];      
	  $return['data'] = $data;
	  $return['start'] = $startRec+1;
      
	return $return;
   }
   
   function ParseTemplate($data = NULL) {   
      
	  $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('aset_ref_bank', 'bank', 'view', 'html') );
      $this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('aset_ref_bank', 'inputBank', 'view', 'html') );
	  $this->mrTemplate->AddVar('content', 'URL_ADD_REKENING', Dispatcher::Instance()->GetUrl('aset_ref_bank', 'inputRekening', 'view', 'html') );	  
	  $this->mrTemplate->AddVar('content', 'SEARCH_BANK_CABANG', $this->data['bank_cabang']);
	  $this->mrTemplate->AddVar('content', 'SEARCH_BANK_ALAMAT', $this->data['bank_alamat']);
	  $this->mrTemplate->AddVar('content', 'SEARCH_BANK_NAMA', $this->data['bank_nama']);
	  
	  if (isset ($data['msg'])) {	     
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['msg']['message']);
		 if($data['msg']['action']=='msg') 
		   $class='notebox-done';
		 else
		   $class = 'notebox-warning';
		 
		 $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['msg']['message']);
         $this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $class);
		 
      }  
	  
	  
      $URLDELETE = Dispatcher::Instance()->GetUrl('aset_ref_bank', 'deleteBank', 'do', 'html');
      
      if (empty($data['data'])) {
         $this->mrTemplate->AddVar('data_grid', 'IS_DATA_EMPTY', 'YES');
      } else {
         $this->mrTemplate->AddVar('data_grid', 'IS_DATA_EMPTY', 'NO');
         $dataGrid = $data['data'];	
         @$no = $i+$data['start'];		 	
		
		for($i=0;$i < sizeof($dataGrid);$i++) {
		   $dataGrid[$i]['nomor'] = $no;
		   if ($no % 2 != 0) $dataGrid[$i]['class_name'] = 'table-common-even';
		   else $dataGrid[$i]['class_name'] = '';
		   $idEnc = Dispatcher::Instance()->Encrypt($dataGrid[$i]['bank_id']);
		   
		   $dataGrid[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('aset_ref_bank', 'inputBank', 'view', 'html').'&grp='.$idEnc;

		   $dataGrid[$i]['url_detail'] = Dispatcher::Instance()->GetUrl('aset_ref_bank', 'detilBank', 'view', 'html').'&grp='.$idEnc;
		   
		   //dipake componenet confirm delete url_delete		   
		   @$urlAccept = 'aset_ref_bank|deleteBank|do|html-cari-'.$cari;
           @$urlReturn = 'aset_ref_bank|bank|view|html-cari-'.$cari;
		   $label = 'Bank';
		   $dataName = $dataGrid[$i]['bank_cabang'];
		   $dataGrid[$i]['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$idEnc.'&label='.$label.'&dataName='.$dataName;               
		   $dataGrid[$i]['urldelete'] = $URLDELETE;
		   $dataGrid[$i]['iddelete'] = $idEnc;
		   $dataGrid[$i]['nama'] = $dataName;
		   $no++;
		   
		   $this->mrTemplate->AddVars('data_item', $dataGrid[$i], 'DATA_');
           $this->mrTemplate->parseTemplate('data_item', 'a');			   
		}
		
		
	}
	
   }
   
   
  
}
?>
