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

class Process
{
	var $_POST;
	var $Obj;
	var $pageView;
	var $pageInput;
	//css hanya dipake di view
	var $cssDone = "notebox-done";
	var $cssFail = "notebox-warning";

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

	function __construct() {
		$this->Obj = new Kodefikasi;
		$this->_POST = $_POST->AsArray();
		$this->decId = $_GET['id']->Integer()->Raw();
		$this->encId = Dispatcher::Instance()->Encrypt($this->decId);
		$this->pageView = Dispatcher::Instance()->GetUrl('kodefikasi_barang', 'kodefikasi', 'view', 'html');
		$this->pageInput = Dispatcher::Instance()->GetUrl('kodefikasi_barang', 'inputKelompok', 'view', 'html');
	}
   
   function Check ()
   {
      if (isset($this->_POST['btnbalik'])) return $this->pageView;
      if (trim($this->_POST['bidang']) == '' OR trim($this->_POST['kode']) == '' OR trim($this->_POST['nama']) == '')
         $error = 'Isian bertanda bintang tidak boleh kosong!';
      elseif (!is_numeric($this->_POST['kode']))
         $error = 'Kode harus berupa karakter numeris!';
      elseif ($this->Obj->CekKodeKelompok($this->decId, $this->_POST['kode'], $this->_POST['bidang']))
         $error = 'Kode kelompok sudah digunakan';
      
      if (isset($error))
      {
         $msg = array($this->_POST, $error, '');
         Messenger::Instance()->Send('kodefikasi_barang', 'inputKelompok', 'view', 'html', $msg, Messenger::NextRequest);
         
         $return = $this->pageInput;
         if (isset($_GET['id'])) $return .= "&id=".$_GET['id']->Integer()->Raw();
         return $return;
      }
      else return true;
   }
   
   function Update()
   {
      $check = $this->Check();
      if ($check !== true) return $check;
      
      $result = $this->Obj->UpdateKelompok($this->_POST);
      if ($result === 0)
         $msg = array(1=>'Perubahan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Tidak Berhasil Mengubah Data!', $this->cssFail);
      Messenger::Instance()->Send('kodefikasi_barang', 'kodefikasi', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
   
   function Add()
   {
      $check = $this->Check();
      if ($check !== true) return $check;
      
      $result = $this->Obj->AddKelompok($this->_POST);
      if ($result === 0)
         $msg = array(1=>'Penambahan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Proses Penambahan Data Gagal!', $this->cssFail);
      Messenger::Instance()->Send('kodefikasi_barang', 'kodefikasi', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
   
   function Delete()
   {
      $result = $this->Obj->DeleteKelompok($this->_POST['idDelete']);
      if ($result === 0)
         $msg = array(1=>'Penghapusan Data Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Proses Penghapusan Data Gagal!', $this->cssFail);
      Messenger::Instance()->Send('kodefikasi_barang', 'kodefikasi', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
}
?>