<?php
/**
* @package DoAddUsulanBarang
* @copyright Copyright (c) PT Gamatechno Indonesia
* @author Dyan Galih <galih@gamatechno.com>
* @version 0.1
* @startDate 2011-01-21
* @lastUpdate 2011-01-21
* @description Do Add Usulan Barang
*/

require_once GTFWConfiguration::GetValue('application', 'docroot') . 'module/pb_usulan/response/UsulanBarang.proc.class.php';

class DoAddUsulanBarang extends JsonResponse {

   function ProcessRequest() {
	
		$objPengRuan = new UsulanBarangProc;
		
		$urlRedirect = Dispatcher::Instance()->GetUrl('pb_usulan', 'usulanBarang', 'view', 'html', true);
	
		if(isset($_POST['cancel'])){
			return array(
				'exec' => 'GtfwAjax.replaceContentWithUrl("subcontent-element","'.$urlRedirect.'&ascomponent=1");'
			); #failed
			exit;
		}
		
		if($_POST['usulanId']->Raw()==''){
			$result = $objPengRuan->Add();
		} else {
			$result = $objPengRuan->Update();
		}
		
		if ($result['status']==true)
			return array(
				'exec' => 'alert("'.$result['message'].'");GtfwAjax.replaceContentWithUrl("subcontent-element","'.$urlRedirect.'&ascomponent=1");'
			); #success
			else
				return array(
				'exec' => 'alert("'.$result['message'].'");'
				); #failed
	}
}
?>