|
ZenCart_Documentation
1.5.0
http://www.collinsharper.com
|
00001 <?php 00009 if (!defined('IS_ADMIN_FLAG')) { 00010 die('Illegal Access'); 00011 } 00012 00013 /* 00014 Example usage: 00015 00016 $messageStack = new messageStack(); 00017 $messageStack->add('Error: Error 1', 'error'); 00018 $messageStack->add('Error: Error 2', 'warning'); 00019 if ($messageStack->size > 0) echo $messageStack->output(); 00020 */ 00021 00022 class messageStack extends tableBlock { 00023 var $size = 0; 00024 00025 function messageStack() { 00026 00027 $this->errors = array(); 00028 00029 if (isset($_SESSION['messageToStack']) && is_array($_SESSION['messageToStack'])) { 00030 for ($i = 0, $n = sizeof($_SESSION['messageToStack']); $i < $n; $i++) { 00031 $this->add($_SESSION['messageToStack'][$i]['text'], $_SESSION['messageToStack'][$i]['type']); 00032 } 00033 $_SESSION['messageToStack'] = ''; 00034 } 00035 } 00036 00037 function add($message, $type = 'error') { 00038 if ($type == 'error') { 00039 $this->errors[] = array('params' => 'class="messageStackError"', 'text' => zen_image(DIR_WS_ICONS . 'error.gif', ICON_ERROR) . ' ' . $message); 00040 } elseif ($type == 'warning') { 00041 $this->errors[] = array('params' => 'class="messageStackWarning"', 'text' => zen_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . ' ' . $message); 00042 } elseif ($type == 'success') { 00043 $this->errors[] = array('params' => 'class="messageStackSuccess"', 'text' => zen_image(DIR_WS_ICONS . 'success.gif', ICON_SUCCESS) . ' ' . $message); 00044 } elseif ($type == 'caution') { 00045 $this->errors[] = array('params' => 'class="messageStackCaution"', 'text' => zen_image(DIR_WS_ICONS . 'warning.gif', ICON_WARNING) . ' ' . $message); 00046 } else { 00047 $this->errors[] = array('params' => 'class="messageStackError"', 'text' => $message); 00048 } 00049 00050 00051 $this->size++; 00052 } 00053 00054 function add_session($message, $type = 'error') { 00055 00056 if (!$_SESSION['messageToStack']) { 00057 $_SESSION['messageToStack'] = array(); 00058 } 00059 00060 $_SESSION['messageToStack'][] = array('text' => $message, 'type' => $type); 00061 } 00062 00063 function reset() { 00064 $this->errors = array(); 00065 $this->size = 0; 00066 } 00067 00068 function output() { 00069 $this->table_data_parameters = 'class="messageBox"'; 00070 return $this->tableBlock($this->errors); 00071 } 00072 }