<?php
class cls_msg
{
	private $arr_msg=array();
	function __construct()
	{
		$this->arr_msg["js"]="";
		$this->arr_msg["html"]="";
	}
	function alert($msg)
	{
		if($msg=="") return;
		$msg=addslashes($msg);
		$this->arr_msg["js"].="alert('".$msg."');";
	}
	function on_history_back()
	{
		$this->arr_msg["js"].="history.back();";
	}
	function go_url($msg_url,$msg_blank="_self"){
		$this->arr_msg["js"].="window.open('".$msg_url."','".$msg_blank."');";
	}
	function js($msg)
	{
		if($msg=="") return;
		if(!isset($this->arr_msg["js"])) $this->arr_msg["js"]="";
		$this->arr_msg["js"].=$msg;
	}
	function html($msg)
	{
		if($msg=="") return;
		if(!isset($this->arr_msg["html"])) $this->arr_msg["html"]="";
		$this->arr_msg["html"].=$msg;
	}
	function __destruct()
	{
		if($this->arr_msg["html"]!=""){
			echo $this->arr_msg["html"];
		}
		if($this->arr_msg["js"]!=""){
			echo "<script>";
			echo $this->arr_msg["js"];
			echo "</script>";
		}
	}
	function json_encode($arr_msg){
		if(!is_array($arr_msg)) return $arr_msg;
		$str_cont="{";
		$arr_item=array();
		foreach($arr_msg as $item=>$key){
			$arr_item[]='"'.$item.'":"'.self::json_encode($key).'"';
		}
		$str_cont.=implode(",",$arr_item)."}";
		return $str_cont;
	}
}
?>