<?php
/*
	@ClassName : Lantai
	@Copyright : PT Gamatechno Indonesia
	@Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
	@Author By : Dyan Galih <galih@gamatechno.com>
	@Version : 0.1
	@StartDate : 2010-02-02
	@LastUpdate : 2010-02-02
	@Description : 
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/gedung/business/Lantai.class.php';

class ProcLantai {
	var $cssDone = "notebox-done";
	var $cssFail = "notebox-warning";
	var $urlUpdate;
	var $urlReturn;
	
	function __construct() {
		$this->urlUpdate = Dispatcher::Instance()->GetUrl('gedung', 'updateLantai', 'view', 'html');
		$this->urlReturn = Dispatcher::Instance()->GetUrl('gedung', 'listLantai', 'view', 'html');
	}
	
	private function Check()
	{
		if($_POST['kode_lantai']==''){
			Messenger::Instance()->Send('gedung', 'updateLantai', 'view', 'html', array($_POST,'Kode Lantai Tidak Boleh Kosong',$this->cssFail),Messenger::NextRequest); #data to send usualy ARRAY_DATA, MESSAGE, CSS
			return false;
		}
		
		if($_POST['nama_lantai']==''){
			Messenger::Instance()->Send('gedung', 'updateLantai', 'view', 'html', array($_POST,'Nama Lantai Tidak Boleh Kosong',$this->cssFail),Messenger::NextRequest); #data to send usualy ARRAY_DATA, MESSAGE, CSS
			return false;
		}
			
		return true;
	}
	
	public function AddLantai()
	{
		$gedung = Dispatcher::Instance()->Decrypt($_GET['gId']);
		if(isset($_POST['cancel']))
			return $this->urlReturn.'&gId='.$gedung;
			
		if(!$this->Check())
			return $this->urlUpdate.'&gId='.$gedung;
			
		$objLantai = new Lantai();
		
		$gedung = Dispatcher::Instance()->Decrypt($_GET['gId']);
		
		if(!$objLantai->AddLantai($gedung,$_POST['kode_lantai'],$_POST['nama_lantai'])){
			Messenger::Instance()->Send('gedung', 'updateLantai', 'view', 'html', array($_POST,'Ada kesalahan data dalam penyimpanan',$this->cssFail),Messenger::NextRequest); #data to send usualy ARRAY_DATA, MESSAGE, CSS
			return $this->urlUpdate.$idLantai.'&gId='.$gedung;
		}else{
			Messenger::Instance()->Send('gedung', 'listLantai', 'view', 'html', array($_POST,'Penyimpanan Data Berhasil',$this->cssDone),Messenger::NextRequest); #data to send usualy ARRAY_DATA, MESSAGE, CSS
			return $this->urlReturn.$idLantai.'&gId='.$gedung;
		}
	}
	
	public function UpdateLantai()
	{
		$objLantai = new Lantai();
		$idLantai = Dispatcher::Instance()->Decrypt($_GET['lantaiId']);
		$gedung = Dispatcher::Instance()->Decrypt($_GET['gId']);
		
		if(isset($_POST['cancel']))
			return $this->urlReturn.'&lantaiId='.$idLantai.'&gId='.$gedung;
			
		if(!$this->Check())
			return $this->urlUpdate.'&lantaiId='.$idLantai.'&gId='.$gedung;
			
		if(!$objLantai->UpdateLantai($gedung,$_POST['kode_lantai'],$_POST['nama_lantai'],$idLantai)){
			Messenger::Instance()->Send('gedung', 'updateLantai', 'view', 'html', array($_POST,'Ada kesalahan data dalam penyimpanan',$this->cssFail),Messenger::NextRequest); #data to send usualy ARRAY_DATA, MESSAGE, CSS
			return $this->urlUpdate.'&lantaiId='.$idLantai.'&gId='.$gedung;
		}else{
			Messenger::Instance()->Send('gedung', 'listLantai', 'view', 'html', array($_POST,'Penyimpanan Data Berhasil',$this->cssDone),Messenger::NextRequest); #data to send usualy ARRAY_DATA, MESSAGE, CSS
			return $this->urlReturn.'&lantaiId='.$idLantai.'&gId='.$gedung;
		}
	}
	
	public function DeleteLantai(){
		if(isset($_POST['idDelete'])) {
			$objLantai = new Lantai();
		   $idDelete=Dispatcher::Instance()->Decrypt($_POST['idDelete']);
		   $gId=Dispatcher::Instance()->Decrypt($_GET['gId']);
			
		   if(!$objLantai->DeleteLantai($idDelete, $gId)) {
				Messenger::Instance()->Send('gedung', 'listLantai', 'view', 'html', array($_POST,'Ada kesalahan data dalam penghapusan',$this->cssFail),Messenger::NextRequest); #data to send usualy ARRAY_DATA, MESSAGE, CSS
				return $this->urlReturn.'&lantaiId='.$idDelete.'&gId='.$gId;
		   } else {
				Messenger::Instance()->Send('gedung', 'listLantai', 'view', 'html', array($_POST,'Penghapusan Data Berhasil',$this->cssDone),Messenger::NextRequest); #data to send usualy ARRAY_DATA, MESSAGE, CSS
				return $this->urlReturn.'&lantaiId='.$idDelete.'&gId='.$gId;
		   }
		}
	}
}
?>
