90fbca7c76fe4652bdcf8914f819d0c93b48e7ce
[squirrelmail.git] / functions / display_messages.php
1 <?php
2
3 /**
4 * display_messages.php
5 *
6 * Copyright (c) 1999-2004 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 * $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>'."\n".
46 '<tr><td ALIGN="center">'.
47 '<A HREF="' . sqm_baseuri()
48 . "src/right_main.php?sort=$sort&amp;startMessage=$startMessage"
49 . "&amp;mailbox=$urlMailbox\">" .
50 sprintf (_("Click here to return to %s"), strtoupper($mailbox) == 'INBOX' ? _("INBOX") : imap_utf7_decode_local($mailbox)) .
51 '</A></td></tr>';
52 error_box($string, $color);
53 }
54
55 function plain_error_message($message, $color) {
56 error_box($message, $color);
57 }
58
59 function logout_error( $errString, $errTitle = '' ) {
60 global $frame_top, $org_logo, $org_name, $org_logo_width, $org_logo_height,
61 $hide_sm_attributions, $version, $squirrelmail_language;
62
63 $base_uri = sqm_baseuri();
64
65 include_once( SM_PATH . 'functions/page_header.php' );
66 if ( !isset( $org_logo ) ) {
67 // Don't know yet why, but in some accesses $org_logo is not set.
68 include( SM_PATH . 'config/config.php' );
69 }
70 /* Display width and height like good little people */
71 $width_and_height = '';
72 if (isset($org_logo_width) && is_numeric($org_logo_width) && $org_logo_width>0) {
73 $width_and_height = " WIDTH=\"$org_logo_width\"";
74 }
75 if (isset($org_logo_height) && is_numeric($org_logo_height) && $org_logo_height>0) {
76 $width_and_height .= " HEIGHT=\"$org_logo_height\"";
77 }
78
79 if (!isset($frame_top) || $frame_top == '' ) {
80 $frame_top = '_top';
81 }
82
83 if ( !isset( $color ) ) {
84 $color = array();
85 $color[0] = '#DCDCDC'; /* light gray TitleBar */
86 $color[1] = '#800000'; /* red */
87 $color[2] = '#CC0000'; /* light red Warning/Error Messages */
88 $color[4] = '#FFFFFF'; /* white Normal Background */
89 $color[7] = '#0000CC'; /* blue Links */
90 $color[8] = '#000000'; /* black Normal text */
91 }
92
93 list($junk, $errString, $errTitle) = do_hook('logout_error', $errString, $errTitle);
94
95 if ( $errTitle == '' ) {
96 $errTitle = $errString;
97 }
98 set_up_language($squirrelmail_language, true);
99
100 displayHtmlHeader( $errTitle, '', false );
101
102 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n\n" .
103 '<CENTER>';
104
105 if (isset($org_logo) && ($org_logo != '')) {
106 echo "<IMG SRC=\"$org_logo\" ALT=\"" . sprintf(_("%s Logo"), $org_name) .
107 "\"$width_and_height><BR>\n";
108 }
109 echo ( $hide_sm_attributions ? '' :
110 '<SMALL>' . sprintf (_("SquirrelMail version %s"), $version) . "<BR>\n".
111 ' ' . _("By the SquirrelMail Development Team") . "<BR></SMALL>\n" ) .
112 "<table cellspacing=1 cellpadding=0 bgcolor=\"$color[1]\" width=\"70%\"><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") .
116 '</B></FONT></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="' .
121 $frame_top . '">' .
122 _("Go to the login page") . "</a></B></FONT>".
123 '</TD></TR>'.
124 '</TABLE></td></tr></table></center></body></html>';
125 }
126
127 function error_box($string, $color) {
128 global $pageheader_sent;
129
130 if ( !isset( $color ) ) {
131 $color = array();
132 $color[0] = '#DCDCDC'; /* light gray TitleBar */
133 $color[1] = '#800000'; /* red */
134 $color[2] = '#CC0000'; /* light red Warning/Error Messages */
135 $color[4] = '#FFFFFF'; /* white Normal Background */
136 $color[7] = '#0000CC'; /* blue Links */
137 $color[8] = '#000000'; /* black Normal text */
138 }
139
140 $err = _("ERROR");
141
142 $ret = concat_hook_function('error_box', $string);
143 if($ret != '') {
144 $string = $ret;
145 }
146
147 /* check if the page header has been sent; if not, send it! */
148 if(!isset($pageheader_sent) && !$pageheader_sent) {
149 /* include this just to be sure */
150 include_once( SM_PATH . 'functions/page_header.php' );
151 displayHtmlHeader('SquirrelMail: '.$err);
152 $pageheader_sent = TRUE;
153 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n\n";
154 }
155
156 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
157 echo ' <tr><td>';
158 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
159 echo ' <tr><td ALIGN="center" bgcolor="'.$color[0].'">';
160 echo ' <font color="' . $color[2].'"><b>' . $err . ':</b></font>';
161 echo ' </td></tr>';
162 echo ' <tr><td>';
163 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
164 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
165 . '</tr>';
166 echo ' </table>';
167 echo ' </td></tr>';
168 echo ' </table></td></tr>';
169 echo ' </table>';
170 }
171 ?>