Location: PHPKode > scripts > Message Handler > message-handler/class.message.php
<?php 
/*
=======================================================================
SCRIPT:		Class : Message Handler
PROJECT:	Framwork
AUTHOR:		Marco Vögeli
=======================================================================
Methods:	- clear()
			- add(type,text)
			- write()			
            - haserrors() 		return: true/false
			- haswarnings()		return: true/false
=======================================================================
*/ 

class message
{

//--- Class Attributes
var $msgstr;
var $haserror;
var $haswarn;
var $hassome;

//--- Class Constants
var $const_path   = "../images/";
var $const_warn   = "warn.gif";
var $const_error  = "error.gif";
var $const_info   = "info.gif";
var $const_stop   = "stop.gif";
var $const_red    = "#FF0000";
var $const_green  = "#008000";
var $const_yellow = "#FF9900";
var $const_blue   = "#0000FF";


// --------------------------------------------------------------------
//--- Constructor
function  message()
{
// Create global array (Message table)
$this->msgstr = array();
$this->haserror = "";
$this->haswarn = "";
$this->hassome = "";
} 
// --------------------------------------------------------------------
//--- Clear Method
function clear()
{
unset($this->msgstr);
$this->haserror = "";
$this->haswarn = "";
$this->hassome = "";
}
// --------------------------------------------------------------------
//-- Add Method
function add($i_type, $i_text)
{

// Local var
$l_val = "";
$l_img = "";
$l_col = "";
$l_pic = "";

// Fill message type dependent vars
switch ($i_type): 
case "I":
$l_col = $this->const_blue;
$l_img = "info.gif";
    break;

case "W":
$l_col = $this->const_yellow;
$l_img = "warn.gif";
$this->haswarn = "X";
$this->hassome = "X";
    break;
    
case "E":
$l_col = $this->const_red;
$l_img = "error.gif";
$this->haserror = "X";
$this->hassome = "X";
    break;
    
case "D":
$l_col = $this->const_red;
$l_img = "stop.gif";
    break;

case "S":
$l_col = $this->const_green;
$l_img = "succ.gif";
    break;
	    
default:
endswitch; 

$l_pic = $this->const_path;
$l_pic.= $l_img;

// Create String for single message
$l_val = "
<table border=\"2\" width=\"100%\" bordercolor=\"$l_col\" cellspacing=\"0\" cellpadding=\"3\" bordercolordark=\"$l_col\">
  <tr>
    <td width=\"100%\">
	<font face=\"Arial\" size=\"2\" color=\"$l_col\"><b>
	<img src=\"$l_pic\" border=\"0\"> $i_text
	</b></font></td>
  </tr>
</table>";  


// Append to array
array_push($this->msgstr, $l_val);

} 
// --------------------------------------------------------------------
//--- Write Method
function write($l_head)
{

$l_count = count($this->msgstr);  
if ($l_head=="X") {
$this->header($l_count); // Internal Method
} 


for ($i = 0; $i < $l_count; $i++) {
 $l_out = $this->msgstr[$i];
 print "$l_out"; 
}  

$this->footer(); // Internal Method
} 
// --------------------------------------------------------------------

// --------------------------------------------------------------------
//--- Header Method (INTERNAL)
function header($l_count)  
{
print " 
<font face=\"Arial\" size=\"1\">
<center>
( Anzahl Meldungen: $l_count. )
</center>
</font>
"; 
} 
// --------------------------------------------------------------------
//--- Footer Method (INTERNAL)
function footer()
{
print ""; // empty = not needed now
} 
// --------------------------------------------------------------------
//--- HasErrors Method
function haserrors()
{
if ($this->haserror=="X") {
return true;
} else {
return false;
} 
} 
// --------------------------------------------------------------------
//--- HasWarnings Method
function haswarnings()
{
if ($this->haswarn=="X") {
return true;
} else {
return false;
} 
} 
// --------------------------------------------------------------------
} // endclass

 ?> 
Return current item: Message Handler