22abf4fcf93567831a7dfd859e25adc87756a34e
[squirrelmail.git] / functions / display_messages.php
1 <?php
2
3 /**
4 * display_messages.php
5 *
6 * This contains all messages, including information, error, and just
7 * about any other message you can think of.
8 *
9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /** @ignore */
16 if (! defined('SM_PATH')) define('SM_PATH','../');
17
18 /**
19 * including plugin functions
20 */
21 include_once(SM_PATH . 'functions/plugin.php');
22
23 /**
24 * Displays error message and URL to message listing
25 * @param string $message error message
26 * @param string $mailbox mailbox name
27 * @param integer $sort sort order
28 * @param integer $startMessage first message
29 * @param array $color color theme
30 * @since 1.0
31 */
32 function error_message($message, $mailbox, $sort, $startMessage, $color) {
33 $urlMailbox = urlencode($mailbox);
34 $string = '<tr><td align="center">' . $message . '</td></tr>'.
35 '<tr><td align="center">'.
36 '<a href="'.sqm_baseuri()."src/right_main.php?sort=$sort&amp;startMessage=$startMessage&amp;mailbox=$urlMailbox\">".
37 sprintf (_("Click here to return to %s"),
38 strtoupper($mailbox) == 'INBOX' ? _("INBOX") : imap_utf7_decode_local($mailbox)).
39 '</a></td></tr>';
40 error_box($string, $color);
41 }
42
43 /**
44 * Displays error message
45 * @param string $message error message
46 * @param array $color color theme
47 * @since 1.0
48 */
49 function plain_error_message($message, $color) {
50 error_box($message, $color);
51 }
52
53 /**
54 * Displays error when user is logged out
55 *
56 * Error strings can be overriden by logout_error hook
57 * @param string $errString error message
58 * @param string $errTitle title of page with error message
59 * @since 1.2.6
60 */
61 function logout_error( $errString, $errTitle = '' ) {
62 global $frame_top, $org_logo, $org_name, $org_logo_width, $org_logo_height,
63 $hide_sm_attributions, $version, $squirrelmail_language,
64 $color, $theme, $theme_default;
65
66 $base_uri = sqm_baseuri();
67
68 include_once( SM_PATH . 'functions/page_header.php' );
69 if ( !isset( $org_logo ) ) {
70 // Don't know yet why, but in some accesses $org_logo is not set.
71 include( SM_PATH . 'config/config.php' );
72 }
73 /* Display width and height like good little people */
74 $width_and_height = '';
75 if (isset($org_logo_width) && is_numeric($org_logo_width) && $org_logo_width>0) {
76 $width_and_height = " width=\"$org_logo_width\"";
77 }
78 if (isset($org_logo_height) && is_numeric($org_logo_height) && $org_logo_height>0) {
79 $width_and_height .= " height=\"$org_logo_height\"";
80 }
81
82 if (!isset($frame_top) || $frame_top == '' ) {
83 $frame_top = '_top';
84 }
85
86 // load default theme if possible
87 if (!isset($color) && @file_exists($theme[$theme_default]['PATH']))
88 @include ($theme[$theme_default]['PATH']);
89
90 if ( !isset( $color ) ) {
91 $color = array();
92 $color[0] = '#dcdcdc'; /* light gray TitleBar */
93 $color[1] = '#800000'; /* red */
94 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
95 $color[4] = '#ffffff'; /* white Normal Background */
96 $color[7] = '#0000cc'; /* blue Links */
97 $color[8] = '#000000'; /* black Normal text */
98 }
99
100 list($junk, $errString, $errTitle) = do_hook('logout_error', $errString, $errTitle);
101
102 if ( $errTitle == '' ) {
103 $errTitle = $errString;
104 }
105 set_up_language($squirrelmail_language, true);
106
107 displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
108
109 echo '<body text="'.$color[8].'" bgcolor="'.$color[4].'" link="'.$color[7].'" vlink="'.$color[7].'" alink="'.$color[7]."\">\n\n".
110 '<div style="text-align: center;">';
111
112 if (isset($org_logo) && ($org_logo != '')) {
113 echo '<img src="'.$org_logo.'" alt="'.sprintf(_("%s Logo"), $org_name).
114 "\"$width_and_height /><br />\n";
115 }
116 echo ( $hide_sm_attributions ? '' :
117 '<small>' . _("SquirrelMail Webmail Application") . '<br />'.
118 _("By the SquirrelMail Project Team") . "<br /></small>\n" ).
119 '<table cellspacing="1" cellpadding="0" bgcolor="'.$color[1].'" width="70%" align="center">'.
120 '<tr><td>'.
121 '<table width="100%" border="0" bgcolor="'.$color[4].'" align="center">'.
122 '<tr><td bgcolor="'.$color[0].'" align="center">'.
123 '<font color="'.$color[2].'"><b>' . _("ERROR") . '</b></font>'.
124 '</td></tr>'.
125 '<tr><td align="center">' . $errString . '</td></tr>'.
126 '<tr><td bgcolor="'.$color[0].'" align="center">'.
127 '<font color="'.$color[2].'"><b>'.
128 '<a href="'.$base_uri.'src/login.php" target="'.$frame_top.'">'.
129 _("Go to the login page") . '</a></b></font></td></tr>'.
130 '</table></td></tr></table></div></body></html>';
131 }
132
133 /**
134 * Displays error message
135 *
136 * Since 1.4.1 function checks if page header is already displayed.
137 * Since 1.4.3 and 1.5.1 function contains error_box hook.
138 * Use plain_error_message() and make sure that page header is created,
139 * if you want compatibility with 1.4.0 and older.
140 * @param string $string
141 * @param array $color
142 * @since 1.3.2
143 */
144 function error_box($string, $color) {
145 global $pageheader_sent;
146
147 if ( !isset( $color ) ) {
148 $color = array();
149 $color[0] = '#dcdcdc'; /* light gray TitleBar */
150 $color[1] = '#800000'; /* red */
151 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
152 $color[4] = '#ffffff'; /* white Normal Background */
153 $color[7] = '#0000cc'; /* blue Links */
154 $color[8] = '#000000'; /* black Normal text */
155 $color[9] = '#ababab'; /* mid-gray Darker version of #0 */
156 }
157
158 $err = _("ERROR");
159
160 $ret = concat_hook_function('error_box', $string);
161 if($ret != '') {
162 $string = $ret;
163 }
164
165 /* check if the page header has been sent; if not, send it! */
166 if(!isset($pageheader_sent) && !$pageheader_sent) {
167 /* include this just to be sure */
168 include_once( SM_PATH . 'functions/page_header.php' );
169 displayHtmlHeader('SquirrelMail: '.$err);
170 $pageheader_sent = TRUE;
171 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n\n";
172 }
173
174 echo '<table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'.
175 '<tr><td>'.
176 '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'.
177 '<tr><td align="center" bgcolor="'.$color[0].'">'.
178 '<font color="'.$color[2].'"><b>' . $err . ':</b></font>'.
179 '</td></tr><tr><td>'.
180 '<table cellpadding="1" cellspacing="5" align="center" border="0">'.
181 '<tr>' . html_tag( 'td', $string."\n", 'left') . '</tr></table>'.
182 '</td></tr></table></td></tr></table>';
183 }
184
185 /**
186 * Adds message that informs about non fatal error that can happen while saving preferences
187 * @param string $message error message
188 * @since 1.5.1 and 1.4.5
189 */
190 function error_option_save($message) {
191 global $optpage_save_error;
192
193 if (! is_array($optpage_save_error) )
194 $optpage_save_error=array();
195
196 $optpage_save_error=array_merge($optpage_save_error,array($message));
197 }
198 // vim: et ts=4
199 ?>