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

class ProcessInventarisasiTanah
{
	var $_POST;
	var $Obj;
	var $pageView;
	var $pageInput;

	var $cssDone = "notebox-done";
	var $cssAlert = "notebox-alert";
	var $cssFail = "notebox-warning";

	var $return;
	var $decId;
	var $encId;

	function __construct() {
		$this->Obj = new InventarisasiTanah();
		$this->_POST = $_POST->AsArray();
		$this->decId = Dispatcher::Instance()->Decrypt($_REQUEST['id']);
		$this->encId = Dispatcher::Instance()->Encrypt($this->decId);
		$this->pageView = Dispatcher::Instance()->GetUrl('inventarisasi_tanah', 'inventarisasiTanah', 'view', 'html');
		$this->pageInput = Dispatcher::Instance()->GetUrl('inventarisasi_tanah', 'inputInventarisasiTanah', 'view', 'html');
	}
   
   function Check()
   {
      if (isset($this->_POST['btnbalik'])) return $this->pageView;
      if (($this->_POST['invdet']) == '')
      {
         $msg = array($this->_POST, 'Kode Inventarisasi tidak boleh kosong!', $this->cssAlert);
         Messenger::Instance()->Send('inventarisasi_tanah', 'inputInventarisasiTanah', 'view', 'html', $msg, Messenger::NextRequest);
         
         $return = $this->pageInput;
         if (isset($_GET['id'])) $return .= "&id=".$_GET['id'];
         return $return;
      }
      if ($this->_POST['luas'] > $this->_POST['luasHidden']){
      	$msg = array($this->_POST, 'Maksimal luas tanah tidak harus sama dengan data inventarisasi!', $this->cssAlert);
         Messenger::Instance()->Send('inventarisasi_tanah', 'inputInventarisasiTanah', 'view', 'html', $msg, Messenger::NextRequest);
         
         $return = $this->pageInput;
         if (isset($_GET['id'])) $return .= "&id=".$_GET['id'];
         return $return;
      }
         
      return true;
   }
   
   function Update()
   {
     	$check = $this->Check();
    	if ($check !== true) return $check;
	 	
      $result = $this->Obj->UpdateInventarisasiTanah($this->_POST, $this->decId);
      
      if ($result)
         $msg = array(1=>'Perubahan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Tidak Berhasil Mengubah Data!', $this->cssFail);
      Messenger::Instance()->Send('inventarisasi_tanah', 'inventarisasiTanah', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
   
   function Add(){
   	$check = $this->Check();
   	if ($check !== true) return $check;

   	$result = $this->Obj->AddInventarisasiTanah($this->_POST);

      if ($result)
         $msg = array(1=>'Penambahan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Tidak Berhasil Menambah Data!', $this->cssFail);
      Messenger::Instance()->Send('inventarisasi_tanah', 'inventarisasiTanah', 'view', 'html', $msg, Messenger::NextRequest);
      
   	return $this->pageView;
   }
   
   function Delete()
   {
      $result = $this->Obj->DeleteInventarisasiTanah($this->_POST['idDelete']);
      if ($result)
         $msg = array(1=>'Penghapusan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Proses Penghapusan Data Gagal!', $this->cssFail);
      Messenger::Instance()->Send('inventarisasi_tanah', 'inventarisasiTanah', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
}
?>
