<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot').
   'module/'.Dispatcher::Instance()->mModule.'/business/Verifikasi.class.php';

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

	var $return;

	function __construct() {
		$this->Obj = new Verifikasi;
		$this->_POST = $_POST->AsArray();
		$this->pageView = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'pengadaanList', 'view', 'html');
		$this->pageInput = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'doVerifikasi', 'view', 'html');
	}
   
   function Check ()
   {
      if (empty($this->_POST)) return $this->pageInput;
      $msg = array();
      
      if (!$this->_POST['pengadaanBAVerifikasi']) $msg[] = "Field BA Pemeriksaan harus diisi.";
      if (!$this->_POST['pengadaanVerifikator']) $msg[] = "Tim Pemeriksa tidak boleh kosong.";
      if (!$this->_POST['pengadaanNoBukti']) $msg[] = "Field Nomor Bukti Pengadaan harus diisi.";
      if (!isset($this->_POST['id'])) $msg[] = "Tidak ada item pengadaan yang dipilih.";
      
      if (count($msg) > 0)
      {
         $msg = array($this->_POST, $msg, 'notebox-alert');
         Messenger::Instance()->Send(Dispatcher::Instance()->mModule, 'doVerifikasi', 'view', 'html', $msg, Messenger::NextRequest);
         
         $return = $this->pageInput;
         if (isset($_GET['id'])) $return .= "&id=".$_GET['id'];
         return $return;
      }
      
      return true;
   }
   
   function Verifikasi()
   {
      $check = $this->Check();
      if ($check !== true) return $check;
      
      $result = $this->Obj->Verifikasi($_GET['id']->Integer()->Raw(), $this->_POST);
      if ($result === 0)
         $msg = array(1=>'Pembatalan Pemeriksaan Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Proses Pembatalan Gagal!'."<span style='display: none'>$result</span>", $this->cssFail);
      Messenger::Instance()->Send(Dispatcher::Instance()->mModule, 'pengadaanList', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
}
?>