Quick Search:

View

Revision:

Diff

Diff from 1498 to:

Annotations

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

Annotated File View

hpdl
1
1 <?php
2 /*
mattice
151
3   $Id: message_stack.php 1498 2007-03-29 14:04:50Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2004 osCommerce
9
hpdl
1498
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
hpdl
1
13 */
14
15   class messageStack {
16     var $messages;
17
18 // class constructor
19     function messageStack() {
20       $this->messages = array();
21     }
22
23 // class methods
24     function add($class, $message, $type = 'error') {
25       $this->messages[] = array('class' => $class, 'type' => $type, 'message' => $message);
26     }
27
28     function add_session($class, $message, $type = 'error') {
hpdl
368
29       if (isset($_SESSION['messageToStack'])) {
30         $messageToStack = $_SESSION['messageToStack'];
hpdl
1
31       } else {
32         $messageToStack = array();
33       }
34
35       $messageToStack[] = array('class' => $class, 'text' => $message, 'type' => $type);
36
hpdl
368
37       $_SESSION['messageToStack'] = $messageToStack;
hpdl
1
38
39       $this->add($class, $message, $type);
40     }
41
42     function reset() {
43       $this->messages = array();
44     }
45
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']) {
51             case 'error':
hpdl
368
52               $bullet_image = DIR_WS_IMAGES . 'icons/error.gif';
hpdl
1
53               break;
54             case 'warning':
hpdl
368
55               $bullet_image = DIR_WS_IMAGES . 'icons/warning.gif';
hpdl
1
56               break;
57             case 'success':
hpdl
368
58               $bullet_image = DIR_WS_IMAGES . 'icons/success.gif';
hpdl
1
59               break;
60             default:
hpdl
368
61               $bullet_image = DIR_WS_IMAGES . 'icons/bullet_default.gif';
hpdl
1
62           }
63
hpdl
757
64           $messages .= '<li style="list-style-image: url(\'' . $bullet_image . '\')">' . osc_output_string($this->messages[$i]['message']) . '</li>';
hpdl
1
65         }
66       }
67       $messages .= '</ul>';
68
69       return '<div class="messageStack">' . $messages . '</div>';
70     }
71
72     function outputPlain($class) {
73       $message = false;
74
75       for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
76         if ($this->messages[$i]['class'] == $class) {
hpdl
757
77           $message = osc_output_string($this->messages[$i]['message']);
hpdl
1
78           break;
79         }
80       }
81
82       return $message;
83     }
84
85     function size($class) {
86       $class_size = 0;
87
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;
95     }
96
97     function loadFromSession() {
hpdl
368
98       if (isset($_SESSION['messageToStack'])) {
99         $messageToStack = $_SESSION['messageToStack'];
hpdl
1
100
101         for ($i=0, $n=sizeof($messageToStack); $i<$n; $i++) {
102           $this->add($messageToStack[$i]['class'], $messageToStack[$i]['text'], $messageToStack[$i]['type']);
103         }
104
hpdl
368
105         unset($_SESSION['messageToStack']);
hpdl
1
106       }
107     }
108   }
109 ?>