<?php

// message class
// Date: 2012-06-19
//this class regist function to message

class Message
{
	
  protected $method_name;
  protected $obj;
  protected $par0 = -1;
  protected $par1 = -1;
  protected $par2 = -1;
  protected $par3 = -1;
  protected $method;
  protected $key;

  function __construct($method,$key,$obj,$method_name,$par0 = -1,$par1 = -1,$par2 = -1,$par3 = -1)
  {
	  $this->method_name = $method_name;
	  $this->obj = $obj;
	  $this->method = $method;
	  $this->key = $key;

	  if ($this->method == 'post') {
		$arraytest = $_POST;
	  } else $arraytest = $_GET;
	
	  if (isset($arraytest[$par0])) $this->par0 = $arraytest[$par0];
	  if (isset($arraytest[$par1])) $this->par1 = $arraytest[$par1];
	  if (isset($arraytest[$par2])) $this->par2 = $arraytest[$par2];
	  if (isset($arraytest[$par3])) $this->par3 = $arraytest[$par3];
	  
  }

//returns actual page
  function Activate() {
	if ($this->method == 'post') {
		$arraytest = $_POST;
	} else $arraytest = $_GET;
 
	  if (array_key_exists($this->key,$arraytest))  {
		  if ($this->par0 == -1) return call_user_func(array($this->obj,$this->method_name)); 
		  if ($this->par1 == -1) return call_user_func(array($this->obj,$this->method_name),$this->par0); 
		  if ($this->par2 == -1) return call_user_func(array($this->obj,$this->method_name),$this->par0,$this->par1);
		  if ($this->par3 == -1) return call_user_func(array($this->obj,$this->method_name),$this->par0,$this->par1,$this->par2);
		  return call_user_func(array($this->obj,$this->method_name),$this->par0,$this->par1,$this->par2,$this->par3);
	  }
  }

}
?>
