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

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

class ViewJenisBidangUsaha extends HtmlResponse {
   
   protected $proc;
   protected $data;
   
   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 ViewJenisBidangUsaha() {
     $this->proc = new ProcJenisBidangUsaha();   
   }
   
   
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.$this->proc->moduleName.'/template');
      $this->SetTemplateFile('view_jenis_bidang_usaha.html');
   }
   
   function ProcessRequest() {  
     //$this->data['tambah']['action']='add'; //inisialisai variable
	 
     if(isset($_POST)) {
	     if(is_object($_POST['data']))
		    $this->data = $_POST['data']->AsArray();
		 else
		    $this->data = $_POST['data'];      
	 }
	 
	 
	   // paging bugfix
      if (!isset($this->data['search']['nama']))
      {
         if (isset($_GET['search']))
            $this->data['search']['nama'] = Dispatcher::Instance()->Decrypt($_GET['search']->Raw());
         else $this->data['search']['nama'] = '';
      }
      // ---------
      // paging bugfix
      $url .= "&search=".Dispatcher::Instance()->Encrypt($this->data['search']['nama']);
      // ---------
	 
	 //aksi buat edit niy..
	 if(isset($_GET['grp'])) { 
	    if(is_object($_GET['grp']))
		   $grp = $_GET['grp']->mrVariable;		   
		else
		   $grp = $_GET['grp'];		
		
	    $data = $this->proc->db->GetDataById(Dispatcher::Instance()->Decrypt($grp));		
		if($data) {
		   $this->data['tambah']['id'] = $grp;
		   $this->data['tambah']['nama'] = $data['nama'];
		   $this->data['tambah']['action'] = 'edit';
		   
		}
	 }
	  
	  
	 
	  
	  
	  
	        
      $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
	  
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();  
         $startRec =($currPage-1) * $itemViewed;
      }
	  
	  
	  
	  $totalData = $this->proc->db->GetCount($this->data['search']);
	  $dataList = $this->proc->db->GetData($startRec,$itemViewed, $this->data['search']);	  
	  
	
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
               Dispatcher::Instance()->mSubModule, 
               Dispatcher::Instance()->mAction, 
               Dispatcher::Instance()->mType
               );
      // paging bugfix
      $url .= "&search=".Dispatcher::Instance()->Encrypt($this->data['search']['nama']);
      // ---------
			   
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', 
         array($itemViewed,$totalData, $url, $currPage), 
         Messenger::CurrentRequest); 

     
        //start menghandle pesan yang diparsing
	    
		$tmp=$this->proc->parsingUrl(__FILE__);		 
		if(isset($tmp['msg']))
		  $return['msg']=$tmp['msg'];  
		//end handle
       
      $return['data'] = $dataList;
      $return['start'] = $startRec+1;
	  $return['search'] = $search;	 	  
	  
	  if(!isset($this->data['tambah']['action']))
	      $this->data['tambah']['action'] ='add';
      
	return $return;
   }
   
   function ParseTemplate($data = NULL) {   
      //set Label
      $this->TemplateLabeling();
      
	  if($this->data['tambah']['action']=='add') {
	     $label_action = 'Tambah';
		 $url_action = $this->proc->moduleAdd;
	  } else {
	     $label_action = 'Edit';
		 $url_action = $this->proc->moduleUpdate;
	  }
	  
	  
	  $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl($this->proc->moduleName, $this->proc->moduleHome, 'view', 'html') );
	  $this->mrTemplate->AddVar('content', 'URL_ACTION', Dispatcher::Instance()->GetUrl($this->proc->moduleName, $url_action , 'do', 'html') );
      
	  
	  $this->mrTemplate->AddVar('content', 'SEARCH_NAMA', $this->data['search']['nama']);
	  $this->mrTemplate->AddVar('content', 'TAMBAH_ID', $this->data['tambah']['id']);
	  $this->mrTemplate->AddVar('content', 'TAMBAH_NAMA', $this->data['tambah']['nama']);
	  $this->mrTemplate->AddVar('content', 'TAMBAH_ACTION', $this->data['tambah']['action']);
	  
	  $this->mrTemplate->AddVar('content', 'LABEL_ACTION', $label_action); 
	  
	  
	  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);
		 
      } 	  	  
      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'];		 
		 $nomor= $data['start'] ;
		//data sudah siap ditampilkan... kirim ke pat-template
		for($j=0;$j < sizeof($dataGrid);$j++) {	
           $dataGrid[$j]['nomor'] = $nomor;
		   $nomor++;
		   if(($j % 2) != 0)
		     $dataGrid[$j]['class_name']='';
		   else
		     $dataGrid[$j]['class_name']='table-common-even';
			 
		   $idEnc= Dispatcher::Instance()->Encrypt($dataGrid[$j]['id']);
		   
		   //==================   start dipake componenet confirm delete =================================
	       $urlAccept = $this->proc->moduleName.'|'.$this->proc->moduleDelete.'|do|html-cari-';
           $urlReturn = $this->proc->moduleName.'|'.$this->proc->moduleHome.'|view|html-cari-';
	       $label = 'Jenis Bidang Usaha';
	       $dataName = $dataGrid[$j]['nama'];				 
           $dataGrid[$j]['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$idEnc.'&label='.$label.'&dataName='.$dataName;               			   
	       //==================   end dipake componenet confirm delete =================================	   
		   
		   $dataGrid[$j]['url_edit'] = Dispatcher::Instance()->GetUrl($this->proc->moduleName, $this->proc->moduleHome, 'view', 'html') .'&grp=' . $idEnc;
		   
		   $this->mrTemplate->AddVars('data_item', $dataGrid[$j], 'DATA_');
           $this->mrTemplate->parseTemplate('data_item', 'a');			   
		}
		
		
	}
	
   }
   
   
  
}
?>
