<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jenis_penggunaan_ruang/business/JenisPenggunaanRuang.class.php';
class ProcessJenisPenggunaanRuang {

	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 JenisPenggunaanRuang();
		$this->_POST = $_POST->AsArray();
		$this->decId = Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$this->encId = Dispatcher::Instance()->Encrypt($this->decId);
		$this->pageView = Dispatcher::Instance()->GetUrl('jenis_penggunaan_ruang', 'jenisPenggunaanRuang', 'view', 'html');
		$this->pageInput = Dispatcher::Instance()->GetUrl('jenis_penggunaan_ruang', 'inputJenisPenggunaanRuang', 'view', 'html');
	}

	function Check() {
		//print_r($this->_POST);exit;
		//$_POST['user_nama']=Security::Instance()->mAuthentication->getcurrentuser()->GetUserId();
		if (isset($_POST['btnsimpan'])) 
		{
			if(trim($this->_POST['jenis_nama']) == "" || trim($this->_POST['jenis_kode']) == "")
			{
				return "empty";
			} 
			else {
				return true;
			}
			
		}
		return false;
	}

	function Add() {
		
		$cek = $this->Check();
		if($cek === true) {
			$addPeriode = $this->Obj->DoAddJenis($this->_POST['jenis_kode'], $_POST['jenis_nama'], $_POST['jenis_status']);
			if ($addPeriode === true) {
				Messenger::Instance()->Send('jenis_penggunaan_ruang', 'jenisPenggunaanRuang', 'view', 'html', array($this->_POST,'Penambahan data Berhasil Dilakukan', $this->cssDone),Messenger::NextRequest);
			} else {
				Messenger::Instance()->Send('jenis_penggunaan_ruang', 'jenisPenggunaanRuang', 'view', 'html', array($this->_POST,'Gagal Menambah Data', $this->cssFail),Messenger::NextRequest);
			}
		} elseif($cek == "empty") {
			Messenger::Instance()->Send('jenis_penggunaan_ruang', 'inputJenisPenggunaanRuang', 'view', 'html', array($this->_POST,'Lengkapi Isian Data'),Messenger::NextRequest);
			return $this->pageInput;
		}
		return $this->pageView;
	}

	function Update() {
		$cek = $this->Check();
		if($cek === true) {
			$updatePeriode = $this->Obj->DoUpdateJenis($this->_POST['jenis_kode'], $_POST['jenis_nama'], $_POST['jenis_status'], $this->decId);
				if ($updatePeriode === true) {
				Messenger::Instance()->Send('jenis_penggunaan_ruang', 'jenisPenggunaanRuang', 'view', 'html', array($this->_POST,'Perubahan Data Berhasil Dilakukan', $this->cssDone),Messenger::NextRequest);
			} else {
				Messenger::Instance()->Send('jenis_penggunaan_ruang', 'jenisPenggunaanRuang', 'view', 'html', array($this->_POST,'Perubahan Data Gagal Dilakukan', $this->cssFail),Messenger::NextRequest);
			}
		} elseif($cek == "empty") {
			Messenger::Instance()->Send('jenis_penggunaan_ruang', 'inputJenisPenggunaanRuang', 'view', 'html', array($this->_POST,'Lengkapi Isian Data'),Messenger::NextRequest);
			return $this->pageInput . "&dataId=" . $this->encId;
		}
		return $this->pageView;
	}

	function Delete() {
		$arrId = $this->_POST['idDelete'];
		//print_r($this->_POST);exit;
		$deleteArrData = $this->Obj->DoDeleteJenisByArrayId($arrId);
		if($deleteArrData === true) {
			Messenger::Instance()->Send('jenis_penggunaan_ruang', 'jenisPenggunaanRuang', 'view', 'html', array($this->_POST,'Penghapusan Data Berhasil Dilakukan', $this->cssDone),Messenger::NextRequest);
		} else {
			//jika masuk disini, berarti PASTI ada salah satu atau lebih data yang gagal dihapus
			for($i=0;$i<sizeof($arrId);$i++) {
				$deleteData = false;
				$deleteData = $this->Obj->DoDeleteJenisById($arrId[$i]);
				if($deleteData === true) $sukses += 1;
				else $gagal += 1;
			}
			Messenger::Instance()->Send('jenis_penggunaan_ruang', 'jenisPenggunaanRuang', 'view', 'html', array($this->_POST, $gagal . ' Data Tidak Dapat Dihapus.', $this->cssFail),Messenger::NextRequest);
		}
		return $this->pageView;
	} 
}
?>
