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

class ViewPengembangan extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/kdp_pengembangan/template');
      $this->SetTemplateFile('view_pengembangan.html');
   }

   function ProcessRequest() {
   	//OBJ
   	$Obj = new KdpPengembangan();
   	
		//GET SESSION DATA
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
		
		//SEARCH FILTER
      $keyword = '';
      if (isset($_POST['keyword']))
      {
         $keyword = $_POST['keyword']->Raw();
      }
      elseif (isset($_GET['cari']))
         list($keyword) = explode('|', Dispatcher::Instance()->Decrypt($_GET['cari']->Raw()));
      $return['cari'] = array
      (
         'keyword' => $keyword
      );   	
		
		$cari = Dispatcher::Instance()->Encrypt(implode('|',$return['cari']));
   	
   	//PAGING
   	$itemViewed = 20;
   	$currPage = 1;
   	$startRec = 0;
   	
   	if(isset ($_GET['page'])){
   		$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
   		$startRec = ($currPage - 1) * $itemViewed;
   	}
   	
   	$return['data'] = $Obj->GetDataKdpPengembangan($keyword, $startRec, $itemViewed);
   	$totalData = $Obj->GetDataKdpPengembanganCount();

   	$url = Dispatcher::Instance()->GetUrl(
   			Dispatcher::Instance()->mModule,
   			Dispatcher::Instance()->mSubModule,
   			Dispatcher::Instance()->mAction,
   			Dispatcher::Instance()->mType);
   	Messenger::Instance()->SendToComponent('paging','Paging','view','html','paging_top',
   			array($itemViewed,$totalData,$url,$currPage),
   			Messenger::CurrentRequest);
   	//END PAGING
   	$return['startRec'] = $startRec;
   	$return['cari'] = $keyword;
   	
   	return $return;
   }

   function ParseTemplate($data = NULL) {
      	
      $urlSearch = Dispatcher::Instance()->GetUrl('kdp_pengembangan', 'Pengembangan', 'view', 'html');			
      $this->mrTemplate->AddVar('content','URL_SEARCH', $urlSearch);
      
		$label = 'Pengembangan KDP';
		$urlAccept = Dispatcher::Instance()->GetUrl('kdp_pengembangan', 'DeleteKdpPengembangan', 'do', 'html');
		$$urlReturn = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html');
		Messenger::Instance()->Send('confirm', 'confirmDelete', 'do', 'html', array($label, $urlAccept, $urlReturn),Messenger::NextRequest);
		$this->mrTemplate->AddVar('content','URL_DELETE_ALL', $$urlReturn);
      $this->mrTemplate->AddVar('content', 'KEYWORD', $data['cari']);
      
      if($this->Pesan)
      {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $this->css);
		}
		
		if (empty($data['data'])){
			return $this->mrTemplate->AddVar('data_jenis_kdp', 'DATA_EMPTY', 'YES');
		} else {
			$this->mrTemplate->AddVar('data_jenis_kdp', 'DATA_EMPTY', 'NO');
		
			
			$urlUpdate = Dispatcher::Instance()->GetUrl('kdp_pengembangan', 'UpdatePengembangan', 'view', 'html');		
			$urlDelete = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').
         "&urlDelete=".Dispatcher::Instance()->Encrypt('kdp_pengembangan|DeleteKdpPengembangan|do|html').
         "&urlReturn=".Dispatcher::Instance()->Encrypt('kdp_pengembangan|Pengembangan|view|html').
         "&label=".Dispatcher::Instance()->Encrypt('Pengembangan KDP');
			
		   $i = $data['startRec']+1;
		   foreach ($data['data'] as $value)
		   {
		      $data = $value;
		      $data['number'] = $i;
		      $data['class_name'] = ($i % 2 == 0) ? '' : 'table-common-even';
		      $data['url_edit'] = $urlUpdate.'&kdpId='.Dispatcher::Instance()->Encrypt($data['KDP_ID']);
		      $data['url_delete'] = $urlDelete."&id=".Dispatcher::Instance()->Encrypt($data['KDP_ID'])."&dataName=".Dispatcher::Instance()->Encrypt($data['KODE_BARANG']);
		      $this->mrTemplate->AddVars('data_jenis_kdp_item', $data, '');
		      $this->mrTemplate->parseTemplate('data_jenis_kdp_item', 'a');
		      $i++;
		   }
		}
		$this->mrTemplate->AddVar('content', 'START', $data['startRec']+1);
		$this->mrTemplate->AddVar('content', 'END', $i-1);
   }
}
?>
