handle DB.php load errors inside preference class and don't worry about
[squirrelmail.git] / functions / display_messages.php
CommitLineData
59177427 1<?php
2ba13803 2
35586184 3/**
4 * display_messages.php
5 *
35586184 6 * This contains all messages, including information, error, and just
7 * about any other message you can think of.
8 *
47ccfad4 9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
31841a9e 11 * @version $Id$
d6c32258 12 * @package squirrelmail
35586184 13 */
3302d0d4 14
ebb9eaaf 15
d5f3892b 16/**
17 * Displays error message and URL to message listing
18 * @param string $message error message
19 * @param string $mailbox mailbox name
20 * @param integer $sort sort order
21 * @param integer $startMessage first message
22 * @param array $color color theme
23 * @since 1.0
24 */
284a0d8a 25function error_message($message, $mailbox, $sort, $startMessage) {
ec5b189b 26 $urlMailbox = urlencode($mailbox);
284a0d8a 27 $link = array (
28 'URL' => sqm_baseuri()."src/right_main.php?sort=$sort&amp;startMessage=$startMessage&amp;mailbox=$urlMailbox",
29 'TEXT' => sprintf (_("Click here to return to %s"), strtoupper($mailbox) == 'INBOX' ? _("INBOX") : imap_utf7_decode_local($mailbox))
30 );
31 error_box($message, $link);
ec5b189b 32}
aa4c3749 33
d5f3892b 34/**
35 * Displays error message
36 * @param string $message error message
37 * @param array $color color theme
38 * @since 1.0
39 */
284a0d8a 40function plain_error_message($message) {
41 error_box($message);
ec5b189b 42}
b6d8d08d 43
d5f3892b 44/**
45 * Displays error when user is logged out
284a0d8a 46 *
d5f3892b 47 * Error strings can be overriden by logout_error hook
48 * @param string $errString error message
49 * @param string $errTitle title of page with error message
50 * @since 1.2.6
51 */
9be8198d 52function logout_error( $errString, $errTitle = '' ) {
284a0d8a 53 global $frame_top, $org_logo, $org_logo_width, $org_logo_height, $org_name,
54 $hide_sm_attributions, $squirrelmail_language, $oTemplate;
35185c82 55
399846ea 56 $base_uri = sqm_baseuri();
26f9a94a 57
8d42e09a 58 list($junk, $errString, $errTitle) = do_hook('logout_error', $errString, $errTitle);
59
9be8198d 60 if ( $errTitle == '' ) {
c4ea392c 61 $errTitle = $errString;
9be8198d 62 }
63 set_up_language($squirrelmail_language, true);
1f05436e 64
c4ea392c 65 displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
1f05436e 66
284a0d8a 67 /* If they don't have a logo, don't bother.. */
68 $logo_str = '';
69 if (isset($org_logo) && $org_logo) {
70 /* Display width and height like good little people */
71 $width_and_height = '';
72 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
73 $org_logo_width>0) {
74 $width_and_height = " width=\"$org_logo_width\"";
75 }
76 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
77 $org_logo_height>0) {
78 $width_and_height .= " height=\"$org_logo_height\"";
79 }
80
81 $logo_str = '<img src="'.$org_logo.'" ' .
82 'alt="'. sprintf(_("%s Logo"), $org_name).'" ' .
83 $width_and_height .
84 'class="sqm_loginImage" ' .
85 ' /><br />'."\n";
4cbcaebd 86 }
284a0d8a 87
88 $sm_attribute_str = '';
89 if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
90 $sm_attribute_str = _("SquirrelMail Webmail Application")."<br />\n" .
91 _("By the SquirrelMail Project Team")."<br />\n";
92 }
93
94 $login_link = array (
95 'URL' => $base_uri . 'src/login.php',
96 'FRAME' => $frame_top
97 );
98
99 $oTemplate->assign('logo_str', $logo_str);
100 $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
101 $oTemplate->assign('login_link', $login_link);
102 $oTemplate->assign('errorMessage', $errString);
103 $oTemplate->display('error_logout.tpl');
104
105 $oTemplate->display('footer.tpl');
9be8198d 106}
107
d5f3892b 108/**
109 * Displays error message
284a0d8a 110 *
d5f3892b 111 * Since 1.4.1 function checks if page header is already displayed.
112 * Since 1.4.3 and 1.5.1 function contains error_box hook.
113 * Use plain_error_message() and make sure that page header is created,
114 * if you want compatibility with 1.4.0 and older.
284a0d8a 115 * @param string $string Error message to be displayed
116 * @param mixed $link Optional array containing link details to be displayed
d5f3892b 117 * @since 1.3.2
118 */
284a0d8a 119function error_box($string, $link=NULL) {
2be6e3fc 120 global $pageheader_sent, $oTemplate;
a429618b 121
b6c283c4 122 $err = _("ERROR");
7753dac4 123 $ret = concat_hook_function('error_box', $string);
124 if($ret != '') {
125 $string = $ret;
126 }
8d42e09a 127
b6c283c4 128 /* check if the page header has been sent; if not, send it! */
129 if(!isset($pageheader_sent) && !$pageheader_sent) {
b6c283c4 130 displayHtmlHeader('SquirrelMail: '.$err);
131 $pageheader_sent = TRUE;
2be6e3fc 132 echo "<body>\n\n";
b6c283c4 133 }
134
284a0d8a 135 // Double check the link for everything we need
136 if (!is_null($link)) {
137 if (!isset($link['FRAME']))
138 $link['FRAME'] = '';
139 if (!isset($link['TEXT']))
140 $link['TEXT'] = $link['URL'];
141 }
142
2be6e3fc 143 /** ERROR is pre-translated to avoid multiple translation calls. **/
144 $oTemplate->assign('error', $err);
145 $oTemplate->assign('errorMessage', $string);
284a0d8a 146 $oTemplate->assign('link', $link);
2be6e3fc 147 $oTemplate->display('error_box.tpl');
fd2611e9 148}
6c92ca88 149
288df1a0 150/**
151 * Adds message that informs about non fatal error that can happen while saving preferences
152 * @param string $message error message
b31af6df 153 * @since 1.5.1 and 1.4.5
288df1a0 154 */
155function error_option_save($message) {
156 global $optpage_save_error;
157
158 if (! is_array($optpage_save_error) )
91e0dccc 159 $optpage_save_error=array();
288df1a0 160
161 $optpage_save_error=array_merge($optpage_save_error,array($message));
284a0d8a 162}