display_messages.php 6.7 KB

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