Quick Search:

View

Revision:

Diff

Diff from 725 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/message_stack.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
153
3   $Id: message_stack.php 725 2006-08-18 12:51:04Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2004 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class messageStack {
14     var $messages;
15
16 // class constructor
17     function messageStack() {
18       $this->messages = array();
19     }
20
21 // class methods
22     function add($class, $message, $type = 'error') {
23       $this->messages[] = array('class' => $class, 'type' => $type, 'message' => $message);
24     }
25
26     function add_session($class, $message, $type = 'error') {
hpdl
199
27       if (isset($_SESSION['messageToStack'])) {
28         $messageToStack = $_SESSION['messageToStack'];
hpdl
1
29       } else {
30         $messageToStack = array();
31       }
32
33       $messageToStack[] = array('class' => $class, 'text' => $message, 'type' => $type);
34
hpdl
199
35       $_SESSION['messageToStack'] = $messageToStack;
hpdl
1
36
37       $this->add($class, $message, $type);
38     }
39
40     function reset() {
41       $this->messages = array();
42     }
43
44     function output($class) {
45       $messages = '<ul>';
46       for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
47         if ($this->messages[$i]['class'] == $class) {
48           switch ($this->messages[$i]['type']) {
49             case 'error':
hpdl
273
50               $bullet_image = DIR_WS_IMAGES . 'icons/error.gif';
hpdl
1
51               break;
52             case 'warning':
hpdl
273
53               $bullet_image = DIR_WS_IMAGES . 'icons/warning.gif';
hpdl
1
54               break;
55             case 'success':
hpdl
273
56               $bullet_image = DIR_WS_IMAGES . 'icons/success.gif';
hpdl
1
57               break;
58             default:
hpdl
273
59               $bullet_image = DIR_WS_IMAGES . 'icons/bullet_default.gif';
hpdl
1
60           }
61
hpdl
725
62           $messages .= '<li style="list-style-image: url(\'' . $bullet_image . '\')">' . osc_output_string($this->messages[$i]['message']) . '</li>';
hpdl
1
63         }
64       }
65       $messages .= '</ul>';
66
67       return '<div class="messageStack">' . $messages . '</div>';
68     }
69
70     function outputPlain($class) {
71       $message = false;
72
73       for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
74         if ($this->messages[$i]['class'] == $class) {
hpdl
725
75           $message = osc_output_string($this->messages[$i]['message']);
hpdl
1
76           break;
77         }
78       }
79
80       return $message;
81     }
82
83     function size($class) {
84       $class_size = 0;
85
86       for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
87         if ($this->messages[$i]['class'] == $class) {
88           $class_size++;
89         }
90       }
91
92       return $class_size;
93     }
94
95     function loadFromSession() {
hpdl
199
96       if (isset($_SESSION['messageToStack'])) {
97         $messageToStack = $_SESSION['messageToStack'];
hpdl
1
98
99         for ($i=0, $n=sizeof($messageToStack); $i<$n; $i++) {
100           $this->add($messageToStack[$i]['class'], $messageToStack[$i]['text'], $messageToStack[$i]['type']);
101         }
102
hpdl
199
103         unset($_SESSION['messageToStack']);
hpdl
1
104       }
105     }
106   }
107 ?>