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