documenting functions
[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, $color;
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 // TODO: load default theme if possible
110 if ( !isset( $color ) ) {
111 $color = array();
112 $color[0] = '#dcdcdc'; /* light gray TitleBar */
113 $color[1] = '#800000'; /* red */
114 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
115 $color[4] = '#ffffff'; /* white Normal Background */
116 $color[7] = '#0000cc'; /* blue Links */
117 $color[8] = '#000000'; /* black Normal text */
118 }
119
120 list($junk, $errString, $errTitle) = do_hook('logout_error', $errString, $errTitle);
121
122 if ( $errTitle == '' ) {
123 $errTitle = $errString;
124 }
125 set_up_language($squirrelmail_language, true);
126
127 displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
128
129 echo '<body text="'.$color[8].'" bgcolor="'.$color[4].'" link="'.$color[7].'" vlink="'.$color[7].'" alink="'.$color[7]."\">\n\n".
130 '<center>';
131
132 if (isset($org_logo) && ($org_logo != '')) {
133 echo '<img src="'.$org_logo.'" alt="'.sprintf(_("%s Logo"), $org_name).
134 "\"$width_and_height /><br />\n";
135 }
136 echo ( $hide_sm_attributions ? '' :
137 '<small>' . _("SquirrelMail Webmail Application") . '<br />'.
138 _("By the SquirrelMail Project Team") . "<br /></small>\n" ).
139 '<table cellspacing="1" cellpadding="0" bgcolor="'.$color[1].'" width="70%">'.
140 '<tr><td>'.
141 '<table width="100%" border="0" bgcolor="'.$color[4].'" align="center">'.
142 '<tr><td bgcolor="'.$color[0].'" align="center">'.
143 '<font color="'.$color[2].'"><b>' . _("ERROR") . '</b></font>'.
144 '</td></tr>'.
145 '<tr><td align="center">' . $errString . '</td></tr>'.
146 '<tr><td bgcolor="'.$color[0].'" align="center">'.
147 '<font color="'.$color[2].'"><b>'.
148 '<a href="'.$base_uri.'src/login.php" target="'.$frame_top.'">'.
149 _("Go to the login page") . '</a></b></font></td></tr>'.
150 '</table></td></tr></table></center></body></html>';
151 }
152
153 /**
154 * Displays error message
155 *
156 * Since 1.4.1 function checks if page header is already displayed.
157 * Since 1.4.3 and 1.5.1 function contains error_box hook.
158 * Use plain_error_message() and make sure that page header is created,
159 * if you want compatibility with 1.4.0 and older.
160 * @param string $string
161 * @param array $color
162 * @since 1.3.2
163 */
164 function error_box($string, $color) {
165 global $pageheader_sent;
166
167 if ( !isset( $color ) ) {
168 $color = array();
169 $color[0] = '#dcdcdc'; /* light gray TitleBar */
170 $color[1] = '#800000'; /* red */
171 $color[2] = '#cc0000'; /* light red Warning/Error Messages */
172 $color[4] = '#ffffff'; /* white Normal Background */
173 $color[7] = '#0000cc'; /* blue Links */
174 $color[8] = '#000000'; /* black Normal text */
175 $color[9] = '#ababab'; /* mid-gray Darker version of #0 */
176 }
177
178 $err = _("ERROR");
179
180 $ret = concat_hook_function('error_box', $string);
181 if($ret != '') {
182 $string = $ret;
183 }
184
185 /* check if the page header has been sent; if not, send it! */
186 if(!isset($pageheader_sent) && !$pageheader_sent) {
187 /* include this just to be sure */
188 include_once( SM_PATH . 'functions/page_header.php' );
189 displayHtmlHeader('SquirrelMail: '.$err);
190 $pageheader_sent = TRUE;
191 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n\n";
192 }
193
194 echo '<table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'.
195 '<tr><td>'.
196 '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'.
197 '<tr><td align="center" bgcolor="'.$color[0].'">'.
198 '<font color="'.$color[2].'"><b>' . $err . ':</b></font>'.
199 '</td></tr><tr><td>'.
200 '<table cellpadding="1" cellspacing="5" align="center" border="0">'.
201 '<tr>' . html_tag( 'td', $string."\n", 'left') . '</tr></table>'.
202 '</td></tr></table></td></tr></table>';
203 }
204
205 /**
206 * Adds message that informs about non fatal error that can happen while saving preferences
207 * @param string $message error message
208 * @since 1.5.1 and 1.4.5
209 */
210 function error_option_save($message) {
211 global $optpage_save_error;
212
213 if (! is_array($optpage_save_error) )
214 $optpage_save_error=array();
215
216 $optpage_save_error=array_merge($optpage_save_error,array($message));
217 }
218 // vim: et ts=4
219 ?>