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