<?php
#echo 'proc'; exit;
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/fasilitas/business/Fasilitas.class.php';

class ProcessFasilitas {
     
   function Insert() {
      $_POST = $_POST->AsArray();
      $Obj = new Fasilitas();
      if(!empty($_POST['btnbatal'])) {
         $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html');
      }else{
         $nama = $_POST['data']['tambah']['nama'];
         if(empty($nama)){
            $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('null');
         }else{
            $insert = $Obj->DoAdd($_POST['data']['tambah']['nama']);
            if($insert) {
               $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('add');
            }else{
               $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('noadd');
            }
         }
      }
      return $urlRedirect;
   }
   
   function Update() {
      $_POST = $_POST->AsArray();
      $Obj = new Fasilitas();
      if(!empty($_POST['btnbatal'])) {
         $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html');
      }else{
         $nama = $_POST['data']['tambah']['nama'];
         $id_fasilitas = $_POST['data']['tambah']['id_fasilitas'];
         if(empty($nama)){
            $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('null') . '&id_fasilitas=' . Dispatcher::Instance()->Encrypt($id_fasilitas);
         }else{
            $update = $Obj->DoUpdate($_POST['data']['tambah']['nama'], $_POST['data']['tambah']['id_fasilitas']);
            if($update) {
               $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('update');
            }else{
               $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('noupdate');
            }
         }
      }
      return $urlRedirect;
   }
   
   function Delete () {     
      $Obj = new Fasilitas();
      $_POST = $_POST->AsArray();
      #echo 'delet disini';
      #print_r($_POST); exit;
      $delete = $Obj->DoDelete($_POST['idDelete']);
      if($delete) {
         $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('del');
      }else{
         $urlRedirect = Dispatcher::Instance()->GetUrl('fasilitas', 'Fasilitas', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('nodel');
      }
      return $urlRedirect;
   }
}
?>