Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

1497
 
1845
 
1845
 
message_stack.php
_> 11 <?php
  22 /*
<> 3 -  $Id: message_stack.php 1497 2007-03-29 13:40:05Z hpdl $
   3+  $Id: message_stack.php 1845 2009-02-27 00:19:37Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
  77 
<> 8 -  Copyright (c) 2004 osCommerce
   8+  Copyright (c) 2009 osCommerce
99 
  1010   This program is free software; you can redistribute it and/or modify
  1111   it under the terms of the GNU General Public License v2 (1991)
  1212   as published by the Free Software Foundation.
  1313 */
  1414 
<> 15 -  class messageStack {
  16 -    var $messages;
   15+/**
   16+ * The osC_MessageStack class manages information messages to be displayed.
   17+ * Messages that are shown are automatically removed from the stack.
   18+ */
1719 
<> 18 -// class constructor
  19 -    function messageStack() {
  20 -      $this->messages = array();
   20+  class osC_MessageStack {
   21+
   22+/**
   23+ * A reference to the messages stored in the session messageToStack variable
   24+ *
   25+ * @var array
   26+ * @access private
   27+ */
   28+
   29+    private $_data = array();
   30+
   31+/**
   32+ * Constructor, references the session data to the private $_data variable
   33+ *
   34+ * @access public
   35+ */
   36+
   37+    public function __construct() {
   38+      if ( !isset($_SESSION['messageToStack']) ) {
   39+        $_SESSION['messageToStack'] = array();
   40+      }
   41+
   42+      $this->_data =& $_SESSION['messageToStack'];
2143     }
  2244 
<> 23 -// class methods
  24 -    function add($class, $message, $type = 'error') {
  25 -      $this->messages[] = array('class' => $class, 'type' => $type, 'message' => $message);
   45+/**
   46+ * Add a message to the stack
   47+ *
   48+ * @param string $group The group the message belongs to
   49+ * @param string $message The message information text
   50+ * @param string $type The type of message: error, warning, success
   51+ * @access public
   52+ */
   53+
   54+    public function add($group, $message, $type = 'error') {
   55+      $this->_data[$group][] = array('text' => $message,
   56+                                     'type' => $type);
2657     }
  2758 
<> 28 -    function add_session($class, $message, $type = 'error') {
  29 -      if (isset($_SESSION['messageToStack'])) {
  30 -        $messageToStack = $_SESSION['messageToStack'];
  31 -      } else {
  32 -        $messageToStack = array();
  33 -      }
   59+/**
   60+ * Reset the message stack
   61+ *
   62+ * @access public
   63+ */
3464 
<> 35 -      $messageToStack[] = array('class' => $class, 'text' => $message, 'type' => $type);
   65+    public function reset() {
   66+      $this->_data = array();
   67+    }
3668 
<> 37 -      $_SESSION['messageToStack'] = $messageToStack;
   69+/**
   70+ * Checks to see if a group in the stack contains messages
   71+ *
   72+ * @param string $group The name of the group to check
   73+ * @access public
   74+ */
3875 
<> 39 -      $this->add($class, $message, $type);
   76+    public function exists($group) {
   77+      return ( isset($this->_data[$group]) && !empty($this->_data[$group]) );
4078     }
  4179 
<> 42 -    function reset() {
  43 -      $this->messages = array();
   80+/**
   81+ * Checks to see if the message stack contains messages
   82+ *
   83+ * @access public
   84+ */
   85+
   86+    public function hasContent() {
   87+      return !empty($this->_data);
4488     }
  4589 
<> 46 -    function output($class) {
  47 -      $messages = '<ul>';
  48 -      for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
  49 -        if ($this->messages[$i]['class'] == $class) {
  50 -          switch ($this->messages[$i]['type']) {
   90+/**
   91+ * Get the messages belonging to a group. The messages are placed into an
   92+ * unsorted list wrapped in a DIV element with the "messageStack" style sheet
   93+ * class.
   94+ *
   95+ * @param string $group The name of the group to get the messages from
   96+ * @access public
   97+ */
   98+
   99+    public function get($group) {
   100+      $result = false;
   101+
   102+      if ( $this->exists($group) ) {
   103+        $result = '<div class="messageStack"><ul>';
   104+
   105+        foreach ( $this->_data[$group] as $message ) {
   106+          switch ( $message['type'] ) {
51107             case 'error':
<> 52 -              $bullet_image = DIR_WS_IMAGES . 'icons/error.gif';
   108+              $bullet_image = 'error.gif';
53109               break;
<>  110+
54111             case 'warning':
<> 55 -              $bullet_image = DIR_WS_IMAGES . 'icons/warning.gif';
   112+              $bullet_image = 'warning.gif';
56113               break;
<>  114+
57115             case 'success':
<> 58 -              $bullet_image = DIR_WS_IMAGES . 'icons/success.gif';
   116+              $bullet_image = 'success.gif';
59117               break;
<>  118+
60119             default:
<> 61 -              $bullet_image = DIR_WS_IMAGES . 'icons/bullet_default.gif';
   120+              $bullet_image = 'bullet_default.gif';
62121           }
  63122 
<> 64 -          $messages .= '<li style="list-style-image: url(\'' . $bullet_image . '\')">' . osc_output_string($this->messages[$i]['message']) . '</li>';
   123+          $result .= '<li style="list-style-image: url(\'' . DIR_WS_IMAGES . 'icons/' . $bullet_image . '\')">' . osc_output_string($message['text']) . '</li>';
65124         }
<>  125+
   126+        $result .= '</ul></div>';
   127+
   128+        unset($this->_data[$group]);
66129       }
<> 67 -      $messages .= '</ul>';
68130 
<> 69 -      return '<div class="messageStack">' . $messages . '</div>';
   131+      return $result;
70132     }
  71133 
<> 72 -    function outputPlain($class) {
  73 -      $message = false;
   134+/**
   135+ * Get the messages belonging to a group. The messages are separated by a new
   136+ * line character.
   137+ *
   138+ * @param string $group The name of the group to get the messages from
   139+ * @access public
   140+ */
74141 
<> 75 -      for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
  76 -        if ($this->messages[$i]['class'] == $class) {
  77 -          $message = osc_output_string($this->messages[$i]['message']);
  78 -          break;
   142+    public function getRaw($group) {
   143+      $result = false;
   144+
   145+      if ( $this->exists($group) ) {
   146+        $result = '';
   147+
   148+        foreach ( $this->_data[$group] as $message ) {
   149+          $result .= osc_output_string($message['text']) . "\n";
79150         }
<>  151+
   152+        unset($this->_data[$group]);
80153       }
  81154 
<> 82 -      return $message;
   155+      return $result;
83156     }
  84157 
<> 85 -    function size($class) {
  86 -      $class_size = 0;
   158+/**
   159+ * Get the message stack array data set
   160+ *
   161+ * @access public
   162+ */
87163 
<> 88 -      for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
  89 -        if ($this->messages[$i]['class'] == $class) {
  90 -          $class_size++;
  91 -        }
  92 -      }
  93 -
  94 -      return $class_size;
   164+    public function getAll() {
   165+      return $this->_data;
95166     }
  96167 
<> 97 -    function loadFromSession() {
  98 -      if (isset($_SESSION['messageToStack'])) {
  99 -        $messageToStack = $_SESSION['messageToStack'];
   168+/**
   169+ * Get the number of messages belonging to a group
   170+ *
   171+ * @param string $group The name of the group to check
   172+ * @access public
   173+ */
100174 
<> 101 -        for ($i=0, $n=sizeof($messageToStack); $i<$n; $i++) {
  102 -          $this->add($messageToStack[$i]['class'], $messageToStack[$i]['text'], $messageToStack[$i]['type']);
  103 -        }
   175+    public function size($group) {
   176+      $size = 0;
104177 
<> 105 -        unset($_SESSION['messageToStack']);
   178+      if ( $this->exists($group) ) {
   179+        $size = sizeof($this->_data[$group]);
106180       }
<>  181+
   182+      return $size;
<_ 107183     }
  108184   }
  109185 ?>