add('Error: Error 1', 'error'); $messageStack->add('Error: Error 2', 'warning'); if ($messageStack->size > 0) echo $messageStack->output(); ---------------------------------------------------------------------- */ /** ensure this file is being included by a parent file */ defined( 'OOS_VALID_MOD' ) or die( 'Direct Access to this location is not allowed.' ); class messageStack { var $size = 0; public function __construct() { $this->errors = array(); if (isset($_SESSION['messageToStack'])) { for ($i = 0, $n = sizeof($_SESSION['messageToStack']); $i < $n; $i++) { $this->add($_SESSION['messageToStack'][$i]['text'], $_SESSION['messageToStack'][$i]['type']); } unset($_SESSION['messageToStack']); } } public function add($message, $type = 'error') { if ($type == 'error') { $this->errors[] = array('params' => 'alert-danger', 'text' => $message); } elseif ($type == 'warning') { $this->errors[] = array('params' => 'alert-warning', 'text' => $message); } elseif ($type == 'success') { $this->errors[] = array('params' => 'alert-success', 'text' => $message); } else { $this->errors[] = array('params' => 'alert-info', 'text' => $message); } $this->size++; } public function add_session($message, $type = 'error') { if (!isset($_SESSION['messageToStack'])) { $_SESSION['messageToStack'] = array(); } $_SESSION['messageToStack'][] = array('text' => $message, 'type' => $type); } public function reset() { $this->errors = array(); $this->size = 0; } public function output() { $sMessageBox = ''; $aContents = $this->errors; for ($i = 0, $n = count($aContents); $i < $n; $i++) { $sMessageBox .= '' . "\n"; } return $sMessageBox; } }