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