New hooks for managing/catching/logging errors
[squirrelmail.git] / functions / display_messages.php
1 <?php
2
3 /**
4 * display_messages.php
5 *
6 * Copyright (c) 1999-2003 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 * Find out where squirrelmail lives and try to be smart about it.
18 * The only problem would be when squirrelmail lives in directories
19 * called "src", "functions", or "plugins", but people who do that need
20 * to be beaten with a steel pipe anyway.
21 *
22 * @return string the base uri of squirrelmail installation.
23 */
24 function sqm_baseuri(){
25 global $base_uri, $PHP_SELF;
26 /**
27 * If it is in the session, just return it.
28 */
29 if (isset($base_uri)){
30 return $base_uri;
31 }
32 $dirs = array('|src/.*|', '|plugins/.*|', '|functions/.*|');
33 $repl = array('', '', '');
34 $base_uri = preg_replace($dirs, $repl, $PHP_SELF);
35 return $base_uri;
36 }
37
38 function error_message($message, $mailbox, $sort, $startMessage, $color) {
39 $urlMailbox = urlencode($mailbox);
40 if (strtoupper($mailbox) == 'INBOX')
41 $mailbox = _("INBOX");
42 $string = '<tr><td ALIGN="center">' . $message . '</td></tr>'."\n".
43 '<tr><td ALIGN="center">'.
44 '<A HREF="' . sqm_baseuri()
45 . "src/right_main.php?sort=$sort&amp;startMessage=$startMessage"
46 . "&amp;mailbox=$urlMailbox\">" .
47 sprintf (_("Click here to return to %s"), imap_utf7_decode_local($mailbox)) .
48 '</A></td></tr>';
49 error_box($string, $color);
50 }
51
52 function plain_error_message($message, $color) {
53 error_box($message, $color);
54 }
55
56 function logout_error( $errString, $errTitle = '' ) {
57 global $frame_top, $org_logo, $org_name, $org_logo_width, $org_logo_height,
58 $hide_sm_attributions, $version, $squirrelmail_language;
59
60 $base_uri = sqm_baseuri();
61
62 include_once( SM_PATH . 'functions/page_header.php' );
63 if ( !isset( $org_logo ) ) {
64 // Don't know yet why, but in some accesses $org_logo is not set.
65 include( SM_PATH . 'config/config.php' );
66 }
67 /* Display width and height like good little people */
68 $width_and_height = '';
69 if (isset($org_logo_width) && is_numeric($org_logo_width) && $org_logo_width>0) {
70 $width_and_height = " WIDTH=\"$org_logo_width\"";
71 }
72 if (isset($org_logo_height) && is_numeric($org_logo_height) && $org_logo_height>0) {
73 $width_and_height .= " HEIGHT=\"$org_logo_height\"";
74 }
75
76 if (!isset($frame_top) || $frame_top == '' ) {
77 $frame_top = '_top';
78 }
79
80 if ( !isset( $color ) ) {
81 $color = array();
82 $color[0] = '#DCDCDC'; /* light gray TitleBar */
83 $color[1] = '#800000'; /* red */
84 $color[2] = '#CC0000'; /* light red Warning/Error Messages */
85 $color[4] = '#FFFFFF'; /* white Normal Background */
86 $color[7] = '#0000CC'; /* blue Links */
87 $color[8] = '#000000'; /* black Normal text */
88 }
89
90 list($junk, $errString, $errTitle) = do_hook('logout_error', $errString, $errTitle);
91
92 if ( $errTitle == '' ) {
93 $errTitle = $errString;
94 }
95 set_up_language($squirrelmail_language, true);
96
97 displayHtmlHeader( $errTitle, '', false );
98
99 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n\n" .
100 '<CENTER>';
101
102 if (isset($org_logo) && ($org_logo != '')) {
103 echo "<IMG SRC=\"$org_logo\" ALT=\"" . sprintf(_("%s Logo"), $org_name) .
104 "\"$width_and_height><BR>\n";
105 }
106 echo ( $hide_sm_attributions ? '' :
107 '<SMALL>' . sprintf (_("SquirrelMail version %s"), $version) . "<BR>\n".
108 ' ' . _("By the SquirrelMail Development Team") . "<BR></SMALL>\n" ) .
109 "<table cellspacing=1 cellpadding=0 bgcolor=\"$color[1]\" width=\"70%\"><tr><td>".
110 "<TABLE WIDTH=\"100%\" BORDER=\"0\" BGCOLOR=\"$color[4]\" ALIGN=CENTER>".
111 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=\"center\">".
112 "<FONT COLOR=\"$color[2]\"><B>" . _("ERROR") .
113 '</B></FONT></TD></TR>'.
114 '<TR><TD ALIGN="center">' . $errString . '</TD></TR>'.
115 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=\"center\">".
116 "<FONT COLOR=\"$color[2]\"><B>".
117 '<a href="' . $base_uri . 'src/login.php" target="' .
118 $frame_top . '">' .
119 _("Go to the login page") . "</a></B></FONT>".
120 '</TD></TR>'.
121 '</TABLE></td></tr></table></center></body></html>';
122 }
123
124 function error_box($string, $color) {
125 global $pageheader_sent;
126
127 $err = _("ERROR");
128
129 $string = concat_hook_function('error_box', $string);
130
131 /* check if the page header has been sent; if not, send it! */
132 if(!isset($pageheader_sent) && !$pageheader_sent) {
133 /* include this just to be sure */
134 include_once( SM_PATH . 'functions/page_header.php' );
135 displayHtmlHeader('SquirrelMail: '.$err);
136 $pageheader_sent = TRUE;
137 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n\n";
138 }
139
140 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
141 echo ' <tr><td>';
142 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
143 echo ' <tr><td ALIGN="center" bgcolor="'.$color[0].'">';
144 echo ' <font color="' . $color[2].'"><b>' . $err . ':</b></font>';
145 echo ' </td></tr>';
146 echo ' <tr><td>';
147 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
148 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
149 . '</tr>';
150 echo ' </table>';
151 echo ' </td></tr>';
152 echo ' </table></td></tr>';
153 echo ' </table>';
154 }
155 ?>