Create template for errors when not logged in.
[squirrelmail.git] / functions / display_messages.php
... / ...
CommitLineData
1<?php
2
3/**
4 * display_messages.php
5 *
6 * This contains all messages, including information, error, and just
7 * about any other message you can think of.
8 *
9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15
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 */
25function error_message($message, $mailbox, $sort, $startMessage) {
26 $urlMailbox = urlencode($mailbox);
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);
32}
33
34/**
35 * Displays error message
36 * @param string $message error message
37 * @param array $color color theme
38 * @since 1.0
39 */
40function plain_error_message($message) {
41 error_box($message);
42}
43
44/**
45 * Displays error when user is logged out
46 *
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 */
52function logout_error( $errString, $errTitle = '' ) {
53 global $frame_top, $org_logo, $org_logo_width, $org_logo_height, $org_name,
54 $hide_sm_attributions, $squirrelmail_language, $oTemplate;
55
56 $base_uri = sqm_baseuri();
57
58 list($junk, $errString, $errTitle) = do_hook('logout_error', $errString, $errTitle);
59
60 if ( $errTitle == '' ) {
61 $errTitle = $errString;
62 }
63 set_up_language($squirrelmail_language, true);
64
65 displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
66
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";
86 }
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');
106}
107
108/**
109 * Displays error message
110 *
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.
115 * @param string $string Error message to be displayed
116 * @param mixed $link Optional array containing link details to be displayed
117 * @since 1.3.2
118 */
119function error_box($string, $link=NULL) {
120 global $pageheader_sent, $oTemplate;
121
122 $err = _("ERROR");
123 $ret = concat_hook_function('error_box', $string);
124 if($ret != '') {
125 $string = $ret;
126 }
127
128 /* check if the page header has been sent; if not, send it! */
129 if(!isset($pageheader_sent) && !$pageheader_sent) {
130 displayHtmlHeader('SquirrelMail: '.$err);
131 $pageheader_sent = TRUE;
132 echo "<body>\n\n";
133 }
134
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
143 /** ERROR is pre-translated to avoid multiple translation calls. **/
144 $oTemplate->assign('error', $err);
145 $oTemplate->assign('errorMessage', $string);
146 $oTemplate->assign('link', $link);
147 $oTemplate->display('error_box.tpl');
148}
149
150/**
151 * Adds message that informs about non fatal error that can happen while saving preferences
152 * @param string $message error message
153 * @since 1.5.1 and 1.4.5
154 */
155function error_option_save($message) {
156 global $optpage_save_error;
157
158 if (! is_array($optpage_save_error) )
159 $optpage_save_error=array();
160
161 $optpage_save_error=array_merge($optpage_save_error,array($message));
162}