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

class ViewJenisKdp extends HtmlResponse {   
   
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/kdp_ref_jenis_kdp/template');
      $this->SetTemplateFile('view_jenis_kdp.html');
   }
   
   function ProcessRequest() {
		$obj = new JenisKdp();
		$paging = Dispatcher::Instance()->Decrypt($_GET['paging']);
   	
      //PENCARIAN (kode_jenis dan nama_jenis)
		if (isset($_POST['kode_jenis'])){ 
			$pkode = $_POST['kode_jenis']; //kode_jenis
			$pnama = $pkode;
		}else{
			if ($paging == '1'){
				$pkode = (string)$_GET['kode_jenis']->StripHtmlTags()->SqlString()->Raw();
				$pnama = $pkode;
			}else{
				$pkode = '';
				$pnama = '';
			}
		} 
		//echo $_GET['paging'];
	  //END PENCARIAN
        
	  //PAGING
		$totalData = $obj->GetCountJenisKdp($pkode, $pnama);
		$itemViewed = 10;
		$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.'&paging='.Dispatcher::Instance()->Encrypt(1).'&kode_jenis='.$pkode);
		Messenger::Instance()->SendToComponent('paging','Paging','view','html','paging_top',
				array($itemViewed,$totalData,$url,$currPage),
				Messenger::CurrentRequest);
	  //END PAGING
	  
	    $data['jenis'] = $obj->GetData($startRec, $itemViewed, $pkode, $pnama);
		 
		$msg = Messenger::Instance()->Receive(__FILE__);
		$data['pesan'] = $msg[0][1];
		$data['css'] = $msg[0][2];
		$data['kodefield'] = $pkode;
		$data['namafield'] = $pnama;
		$data['start'] = $startRec;
		
		return $data;
   }
   
function ParseTemplate($data = NULL) {
	 
	 //PENCARIAN			
     //$cari = $data['search']['nim'].'|'.$data['search']['nama'];
	 $this->mrTemplate->AddVar('content', 'KODE_JENIS', $data['kodefield']);
	 $this->mrTemplate->AddVar('content', 'NAMA_JENIS', $data['namafield']);
	
	 $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('kdp_ref_jenis_kdp', 'JenisKdp', 'view', 'html') );
	//END PENCARIAN
   
     $this->mrTemplate->AddVar('content','URL_ADD', Dispatcher::Instance()->GetUrl('kdp_ref_jenis_kdp','InputJenisKdp','view','html'));
	 
	 //Kirim pesan ke template
	 if ($data['pesan']){
		$this->mrTemplate->SetAttribute('warning-box','visibility','visible');
		$this->mrTemplate->AddVar('warning-box','ISI_PESAN',$data['pesan']);
		$this->mrTemplate->AddVar('warning-box','CLASS_PESAN',$data['css']);
	 }
	 
     if (empty($data['jenis'])){
	    $this->mrTemplate->AddVar('data_jenis_kdp', 'DATA_EMPTY', 'YES');
	 } else {
	    //CONFIRM DELETE BANYAK
		$label = "Jenis KDP";	//Judul Konfirm
		$urlDelete = Dispatcher::Instance()->GetUrl('kdp_ref_jenis_kdp','Delete','do','json');
		$urlReturn = Dispatcher::Instance()->GetUrl('kdp_ref_jenis_kdp','JenisKdp','view','html');  //url jika Tidak
		Messenger::Instance()->Send('confirm','confirmDelete','do','html',array($label,$urlDelete,$urlReturn),Messenger::NextRequest);
		$this->mrTemplate->AddVar('content','URL_DELETE_BANYAK', Dispatcher::Instance()->GetUrl('confirm','confirmDelete','do','html'));	
	    //END CONFIRM DELETE BANYAK
	 
        $this->mrTemplate->AddVar('data_jenis_kdp','DATA_EMPTY','NO');
		$len = sizeof($data['jenis']);
		$no = $data['start'];
	    foreach ($data['jenis'] as $key => $value){
	    	$no++;
	    	$value['no'] = $no;
			
			if($key == 0) $this->mrTemplate->AddVar('content','FIRST_NUMBER',$no); //untuk keperluan checkedall
			if($key == ($len - 1)) $this->mrTemplate->AddVar('content','LAST_NUMBER',$no);
			
			if ($no % 2 != 0){
				$value['class_name'] = 'table-common-even';
			} else {
				$value['class_name'] = '';
			}
			
			//CONFIRM DELETE SATUAN
			$urlAccept = 'kdp_ref_jenis_kdp|Delete|do|json';
           	$urlReturn = 'kdp_ref_jenis_kdp|JenisKdp|view|html';
		   	$label = 'Jenis KDP'; 
			$value['URL_DELETE'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='.$urlAccept.'&urlReturn='.$urlReturn.'&id='.Dispatcher::Instance()->Encrypt($value['ID']).'&label='.$label.'&dataName='.$value['NAMA'];
			//END CONFIRM DELETE SATUAN
			
			$value['URL_EDIT'] = Dispatcher::Instance()->GetUrl('kdp_ref_jenis_kdp','UpdateJenisKdp','view','html').'&id='.Dispatcher::Instance()->Encrypt($value['ID']);
			
			$this->mrTemplate->AddVars('data_jenis_kdp_item',$value, 'KDP_');
			$this->mrTemplate->parseTemplate('data_jenis_kdp_item','a');
		}		
	 }
   }
     
}
?>
