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

class Process
{
	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 Business;
		$this->_POST = $_REQUEST->AsArray();
		$this->decId = $_GET['id']->Integer()->Raw();
		$this->encId = $this->decId;
		$this->pageView = Dispatcher::Instance()->GetUrl('peruntukan_bangunan_ref', 'mainPage', 'view', 'html');
		$this->pageInput = Dispatcher::Instance()->GetUrl('peruntukan_bangunan_ref', 'mainPage', 'view', 'html');
	}
   
   function Check ()
   {
      if (isset($this->_POST['btnbalik'])) return $this->pageView;
      if (trim($this->_POST['nama']) == '')
         $error = 'Tidak ada data yang dimasukan!';
      
      if (isset($error))
      {
         $msg = array($this->_POST, $error, $this->cssAlert);
         Messenger::Instance()->Send('peruntukan_bangunan_ref', 'mainPage', 'view', 'html', $msg, Messenger::NextRequest);
         
         $return = $this->pageInput;
         if (isset($_GET['id'])) $return .= "&id=".$_GET['id']->Integer()->Raw();
         return $return;
      }
      return true;
   }
   
   function Update()
   {
      $check = $this->Check();
      if ($check !== true) return $check;
      
      $result = $this->Obj->Update($this->_POST);
      if ($result)
         $msg = array(1=>'Perubahan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Tidak Berhasil Mengubah Data!', $this->cssFail);
      Messenger::Instance()->Send('peruntukan_bangunan_ref', 'mainPage', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
   
   function Add()
   {
      $check = $this->Check();
      if ($check !== true) return $check;
      
      $result = $this->Obj->Add($this->_POST);
      if ($result)
         $msg = array(1=>'Penambahan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Proses Penambahan Data Gagal!', $this->cssFail);
      Messenger::Instance()->Send('peruntukan_bangunan_ref', 'mainPage', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
   
   function Delete()
   {
      $result = $this->Obj->Delete($this->_POST);
      if ($result)
         $msg = array(1=>'Penghapusan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Proses Penghapusan Data Gagal!', $this->cssFail);
      Messenger::Instance()->Send('peruntukan_bangunan_ref', 'mainPage', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
}
?>