[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/classes/ -> message_stack.php (source)

   1  <?php
   2  /*

   3  $Id: message_stack.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax2005 osCMax, 2002 osCommerce

   9  

  10    Released under the GNU General Public License

  11  

  12    Example usage:

  13  

  14    $messageStack = new messageStack();

  15    $messageStack->add('general', 'Error: Error 1', 'error');

  16    $messageStack->add('general', 'Error: Error 2', 'warning');

  17    if ($messageStack->size('general') > 0) echo $messageStack->output('general');

  18  */
  19  
  20    class messageStack extends tableBox {
  21  
  22  // class constructor

  23      function messageStack() {
  24        global $messageToStack;
  25  
  26        $this->messages = array();
  27  
  28        if (tep_session_is_registered('messageToStack')) {
  29          for ($i=0, $n=sizeof($messageToStack); $i<$n; $i++) {
  30            $this->add($messageToStack[$i]['class'], $messageToStack[$i]['text'], $messageToStack[$i]['type']);
  31          }
  32          tep_session_unregister('messageToStack');
  33        }
  34      }
  35  
  36  // class methods

  37      function add($class, $message, $type = 'error') {
  38        if ($type == 'error') {
  39          $this->messages[] = array('params' => 'class="messageStackError"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'error.gif', ICON_ERROR) . '&nbsp;' . $message);
  40        } elseif ($type == 'warning') {
  41          $this->messages[] = array('params' => 'class="messageStackWarning"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . '&nbsp;' . $message);
  42        } elseif ($type == 'success') {
  43          $this->messages[] = array('params' => 'class="messageStackSuccess"', 'class' => $class, 'text' => tep_image(DIR_WS_ICONS . 'success.gif', ICON_SUCCESS) . '&nbsp;' . $message);
  44        } else {
  45          $this->messages[] = array('params' => 'class="messageStackError"', 'class' => $class, 'text' => $message);
  46        }
  47      }
  48  
  49      function add_session($class, $message, $type = 'error') {
  50        global $messageToStack;
  51  
  52        if (!tep_session_is_registered('messageToStack')) {
  53          tep_session_register('messageToStack');
  54          $messageToStack = array();
  55        }
  56  
  57        $messageToStack[] = array('class' => $class, 'text' => $message, 'type' => $type);
  58      }
  59  
  60      function reset() {
  61        $this->messages = array();
  62      }
  63  
  64      function output($class) {
  65        $this->table_data_parameters = 'class="messageBox"';
  66  
  67        $output = array();
  68        for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
  69          if ($this->messages[$i]['class'] == $class) {
  70            $output[] = $this->messages[$i];
  71          }
  72        }
  73  
  74        return $this->tableBox($output);
  75      }
  76  
  77      function size($class) {
  78        $count = 0;
  79  
  80        for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
  81          if ($this->messages[$i]['class'] == $class) {
  82            $count++;
  83          }
  84        }
  85  
  86        return $count;
  87      }
  88    }
  89  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7