Happy New Year
[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 *
77a1e3d1 9 * @copyright 1999-2022 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
5e5a1eed 18 *
19 * Fifth argument ($color array) is removed in 1.5.2.
d5f3892b 20 * @param string $message error message
21 * @param string $mailbox mailbox name
22 * @param integer $sort sort order
23 * @param integer $startMessage first message
d5f3892b 24 * @since 1.0
25 */
284a0d8a 26function error_message($message, $mailbox, $sort, $startMessage) {
ec5b189b 27 $urlMailbox = urlencode($mailbox);
5e5a1eed 28 $link = array (
29 'URL' => sqm_baseuri()."src/right_main.php?sort=$sort&amp;startMessage=$startMessage&amp;mailbox=$urlMailbox",
30 'TEXT' => sprintf (_("Click here to return to %s"),
3047e291 31 strtoupper($mailbox) == 'INBOX' ? _("INBOX") : sm_encode_html_special_chars(imap_utf7_decode_local($mailbox)))
5e5a1eed 32 );
284a0d8a 33 error_box($message, $link);
ec5b189b 34}
aa4c3749 35
d5f3892b 36/**
37 * Displays error message
5e5a1eed 38 *
87d2ad51 39 * Second argument ($color array) is changed to boolean $return_output as of 1.5.2.
1f80d9f5 40 *
d5f3892b 41 * @param string $message error message
87d2ad51 42 * @param boolean $return_output When TRUE, output is returned to caller
43 * instead of being sent to browser (OPTIONAL;
44 * default = FALSE)
d5f3892b 45 * @since 1.0
46 */
87d2ad51 47function plain_error_message($message, $return_output=FALSE) {
48 return error_box($message, NULL, $return_output);
ec5b189b 49}
b6d8d08d 50
d5f3892b 51/**
52 * Displays error when user is logged out
284a0d8a 53 *
d5f3892b 54 * Error strings can be overriden by logout_error hook
55 * @param string $errString error message
56 * @param string $errTitle title of page with error message
57 * @since 1.2.6
58 */
9be8198d 59function logout_error( $errString, $errTitle = '' ) {
284a0d8a 60 global $frame_top, $org_logo, $org_logo_width, $org_logo_height, $org_name,
1f80d9f5 61 $hide_sm_attributions, $squirrelmail_language, $oTemplate, $base_uri;
26f9a94a 62
5f882853 63 $login_link = array (
64 'URI' => $base_uri . 'src/login.php',
65 'FRAME' => $frame_top
66 );
67
d849b570 68 /* As of 1.5.2, plugin parameters are combined into one array;
69 plugins on this hook must be updated */
1e5ae210 70 $temp = array(&$errString, &$errTitle, &$login_link);
71 do_hook('logout_error', $temp);
8d42e09a 72
9be8198d 73 if ( $errTitle == '' ) {
c4ea392c 74 $errTitle = $errString;
9be8198d 75 }
76 set_up_language($squirrelmail_language, true);
1f05436e 77
c4ea392c 78 displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
1f05436e 79
284a0d8a 80 /* If they don't have a logo, don't bother.. */
81 $logo_str = '';
82 if (isset($org_logo) && $org_logo) {
8f6e76d2 83
284a0d8a 84 if (isset($org_logo_width) && is_numeric($org_logo_width) &&
85 $org_logo_width>0) {
8f6e76d2 86 $width = $org_logo_width;
87 } else {
88 $width = '';
284a0d8a 89 }
90 if (isset($org_logo_height) && is_numeric($org_logo_height) &&
91 $org_logo_height>0) {
8f6e76d2 92 $height = $org_logo_height;
93 } else {
94 $height = '';
284a0d8a 95 }
8f6e76d2 96
97 $logo_str = create_image($org_logo, sprintf(_("%s Logo"), $org_name),
98 $width, $height, '', 'sqm_loginImage');
99
4cbcaebd 100 }
284a0d8a 101
102 $sm_attribute_str = '';
103 if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
3e6b917e 104 $sm_attribute_str = _("SquirrelMail Webmail") . "\n"
5670da62 105 . _("By the SquirrelMail Project Team");
284a0d8a 106 }
107
284a0d8a 108 $oTemplate->assign('logo_str', $logo_str);
109 $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
110 $oTemplate->assign('login_link', $login_link);
111 $oTemplate->assign('errorMessage', $errString);
112 $oTemplate->display('error_logout.tpl');
113
114 $oTemplate->display('footer.tpl');
9be8198d 115}
116
d5f3892b 117/**
118 * Displays error message
284a0d8a 119 *
d5f3892b 120 * Since 1.4.1 function checks if page header is already displayed.
1b858d86 121 *
d849b570 122 * Since 1.4.3 and 1.5.1, this function contains the error_box hook.
d5f3892b 123 * Use plain_error_message() and make sure that page header is created,
124 * if you want compatibility with 1.4.0 and older.
1b858d86 125 *
126 * In 1.5.2 second function argument is changed. Older functions used it
127 * for $color array, new function uses it for optional link data. Function
128 * will ignore color array and use standard colors instead.
d849b570 129 *
87d2ad51 130 * The $return_output argument was added in 1.5.2
131 *
284a0d8a 132 * @param string $string Error message to be displayed
1b858d86 133 * @param array $link Optional array containing link details to be displayed.
134 * Array uses three keys. 'URL' key is required and should contain link URL.
135 * 'TEXT' key is optional and should contain link name. 'FRAME' key is
136 * optional and should contain link target attribute.
87d2ad51 137 * @param boolean $return_output When TRUE, output is returned to caller
138 * instead of being sent to browser (OPTIONAL;
139 * default = FALSE)
d849b570 140 *
d5f3892b 141 * @since 1.3.2
142 */
87d2ad51 143function error_box($string, $link=NULL, $return_output=FALSE) {
f6b68e06 144 global $pageheader_sent, $oTemplate, $org_title;
a429618b 145
b6c283c4 146 $err = _("ERROR");
d849b570 147 do_hook('error_box', $string);
f6b68e06 148 if ( !isset($org_title) ) $org_title = 'SquirrelMail';
8d42e09a 149
87d2ad51 150 // check if the page header has been sent; if not, send it!
151 //
152 // (however, if $return_output is turned on, the output of this
153 // should be being used in some other page, so we don't have
154 // to worry about page headers in that case)
155 //
156 if (!$return_output && empty($pageheader_sent)) {
f6b68e06 157 displayHtmlHeader($org_title . ': '.$err);
b6c283c4 158 $pageheader_sent = TRUE;
87d2ad51 159 echo create_body(); // this is template-safe (see create_body() function)
b6c283c4 160 }
161
284a0d8a 162 // Double check the link for everything we need
163 if (!is_null($link)) {
1b858d86 164 // safety check for older code
165 if (isset($link['URL'])) {
166 if (!isset($link['FRAME'])) $link['FRAME'] = '';
167 if (!isset($link['TEXT'])) $link['TEXT'] = $link['URL'];
168 } else {
169 // somebody used older error_box() code
170 $link=null;
171 }
284a0d8a 172 }
173
2be6e3fc 174 /** ERROR is pre-translated to avoid multiple translation calls. **/
175 $oTemplate->assign('error', $err);
176 $oTemplate->assign('errorMessage', $string);
284a0d8a 177 $oTemplate->assign('link', $link);
87d2ad51 178 $output = $oTemplate->fetch('error_box.tpl');
179
180 if ($return_output) return $output;
181 echo $output;
fd2611e9 182}
6c92ca88 183
288df1a0 184/**
185 * Adds message that informs about non fatal error that can happen while saving preferences
186 * @param string $message error message
b31af6df 187 * @since 1.5.1 and 1.4.5
288df1a0 188 */
189function error_option_save($message) {
190 global $optpage_save_error;
191
192 if (! is_array($optpage_save_error) )
91e0dccc 193 $optpage_save_error=array();
288df1a0 194
195 $optpage_save_error=array_merge($optpage_save_error,array($message));
284a0d8a 196}