Location: PHPKode > scripts > Styled Message Box > styled-message-box/msg.class.php
<?
	class Msg {
		var $css_file ;
		var $icon_file ;
		var $width ;
		var $height ;
		var $mode ;
		var $type ;
		var $msg ;
		var $title ;
		var $ok_msg ;
		var $exit_bg ;
		var $top ;
		var $left ;
		
		// $type = error | warning | confirmation
		// $mode = return | echo
		function Msg($type = 'error', $mode = 'return') {
			$this->return_mode = $type ;
			$this->type = $type ;
		}

		function exitOnBg($bool) {
			$this->exit_bg = $bool ;
		}
		
		function setCss_file($path) {
			$this->css_file = $path ;
		}

		function setIcon_file($icon) {
			$this->icon_file = $icon ;
		}
		
		function setWidth($w) {
			$this->width = $w ;
		}

		function setHeight($h) {
			$this->height = $h ;
		}		
		
		function setMsg($msg) {
			$this->msg = $msg ;
		}

		function setTitle($t) {
			$this->title = $t ;
		}
				
		function setOk_msg($msg) {
			$this->ok_msg = $msg ;
		}
		
		function setTop($p) {
			$this->top = $p ;
		}

		function setLeft($p) {
			$this->left = $p ;
		}		
		
		function generateBox() {
			
			$css = $this->_generateCss($this->css_file) ;
			$js = $this->_generateJs($this->width, $this->height, $this->top, $this->left) ;
			$bg = $this->_generateBackground() ;
			$main_window = $this->_generateMainWindow($this->msg, $this->title, $this->ok_msg, $this->icon_file) ;
			$open = $this->_generateOpener() ;
			
			$result = $css . $js . $bg . $main_window . $open ;
			
			if ($mode == 'echo') {
				echo $result ;
			}
			else {
				return $result ;
			}
		}
		
		function _generateMainWindow($msg, $title, $ok, $icon) {
			$type = $this->type ;
			$type_box = $type . "_box" ;
			$type_text = $type . "_text" ;
			$type_title = $type . "_title" ;
			
			if (isset($icon)) {
				$icon = "<td><img src='$icon' border='0'></td>" ;
			}
			
			$code = "<div id='layer_msg' class='$type_box' style='z-index:15; position:absolute; top:0; left:0;visibility:show; width:0px; height:0px;'>
				<table width='100%' cellpadding='2'>
					<tr>
						$icon
						<td><span class='$type_title'>$title</span></td>
					</tr>	
					<tr>
						<td height='10'></td>
					</tr>
					<form name='bt'>
					<tr>
						<td colspan='2'>
							<span class='$type_text'>$msg</span>
							<p align='center'><input type='button' class='button_ok' name='btok' value='$ok' onclick=\"javascript:fecha_layer('layer_msg');\"></p>
						</td>
					</tr>
					</form>
				</table>
			</div>" ;
			
			return $code ;
		}
		
		function _generateBackground() {
			if ($this->exit_bg) {
				$closeBg =  " onclick=\"javascript:fecha_janelas();\"" ;
			}
			$code = "<div id='layer_fundo' class='bg_layer' $closeBg style='position:absolute; width:0px; height:0px; top:0px; left:0px'></div>" ;
			
			return $code ;
		}
		
		function _generateJs($width, $height, $top, $left) {
			
			if (empty($top)) {
				$half_top = $height / 2 ;
				$top = "(document.body.clientHeight / 2) - " . $half_top ;
			}
			
			if (empty($left)) {
				$half_left = $width / 2 ;
				$left = "(document.body.clientWidth / 2) - " . $half_left ;
			}			
			
			$code = "<script>
			function getObj(name) {
				if (document.getElementById) {
					this.obj = document.getElementById(name);
					this.style = document.getElementById(name).style;
				}
				else if (document.all) {
					this.obj = document.all[name];
					this.style = document.all[name].style;
				}
				else if (document.layers) {
					this.obj = document.layers[name];
					this.style = document.layers[name];
				}
			}

			
			function mostra_msg() {
				window.scrollTo(0,0) ;
				habilita_fundo() ;
				var x = new getObj('layer_msg') ;
				x.style.width = '$width' ;
				x.style.height = '$height' ;
				x.style.top = $top ;
				x.style.left = $left ;				
			}
			
			function fecha_layer(name) {
				desabilita_fundo() ;
				var x = new getObj(name) ;
				x.style.width = 0 ;
				x.style.height = 0 ;
				x.style.visibility = 'hidden' ;
			}
			
			function habilita_fundo() {
				var fundo = new getObj('layer_fundo') ;
				fundo.style.width = document.body.clientWidth ;
				fundo.style.height = document.body.clientHeight ;
			}
			
			function desabilita_fundo() {
				var fundo = new getObj('layer_fundo') ;
				fundo.style.width = 0 ;
				fundo.style.height = 0 ;
			}
			
			function fecha_janelas() {
				fecha_layer('layer_msg') ;
			}
			</script>" ;
			return $code ;
		}
		
		function _generateCss($css_file) {
			$code = "<link href=\"$css_file\" rel=\"stylesheet\" type=\"text/css\">" ;
			return $code ;
		}
		
		function _generateOpener() {
			$code = "<script>mostra_msg();document.forms[\"bt\"].btok.focus() ;</script>" ;
			return $code ;
		}
	
	}
?>
Return current item: Styled Message Box