<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/setting/business/Setting.class.php';

class ProcSetting {

   protected $msg;
   protected $data;

   public $db;  //yang berhubungan ke database

    function ProcSetting(){ //constructor
      if(isset($_POST['setting']))
         if(is_object($_POST['setting']))
            $this->data=$_POST['setting']->AsArray();
         else
            $this->data=$_POST['setting'];
      $this->db = new Setting();
    }

	function Update() {
   
		if($this->validation('Perubahan')){
			$update = true;
			for($i=0;$i<count($this->data);$i++){
				$update = $this->db->UpdateSetting($i+1,$this->data[$i]);
			}
			$urlRedirect = Dispatcher::Instance()->GetUrl('setting', 'Setting', 'view', 'html')."&msg=sukses";
		 } else {
		   $urlRedirect = Dispatcher::Instance()->GetUrl('setting', 'Setting', 'view', 'html');
		 }

	   return $urlRedirect;
	}



	function validation($action) {

      if (isset($_POST['btnbatal']))
      {
         $this->msg = '';
         return false;
      }
      
	    $this->msg='';
	    if(!isset($_POST['setting'])) { //kalo gak ada data yang di POST apa yang mau di  validasi
		   $this->msg=$action.' data gagal dilakukan ';
		   return false;
		}

		if($this->msg=='')
   		   return true;
		else
		   return false;
	}
}
?>
