display_messages.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 &copy; 1999-2007 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") : htmlspecialchars(imap_utf7_decode_local($mailbox)))
  29. );
  30. error_box($message, $link);
  31. }
  32. /**
  33. * Displays error message
  34. *
  35. * Second argument ($color array) is removed in 1.5.2.
  36. * @param string $message error message
  37. * @since 1.0
  38. */
  39. function plain_error_message($message) {
  40. error_box($message);
  41. }
  42. /**
  43. * Displays error when user is logged out
  44. *
  45. * Error strings can be overriden by logout_error hook
  46. * @param string $errString error message
  47. * @param string $errTitle title of page with error message
  48. * @since 1.2.6
  49. */
  50. function logout_error( $errString, $errTitle = '' ) {
  51. global $frame_top, $org_logo, $org_logo_width, $org_logo_height, $org_name,
  52. $hide_sm_attributions, $squirrelmail_language, $oTemplate;
  53. $base_uri = sqm_baseuri();
  54. $login_link = array (
  55. 'URI' => $base_uri . 'src/login.php',
  56. 'FRAME' => $frame_top
  57. );
  58. /* As of 1.5.2, plugin parameters are combined into one array;
  59. plugins on this hook must be updated */
  60. do_hook('logout_error', $temp=array(&$errString, &$errTitle, &$login_link));
  61. if ( $errTitle == '' ) {
  62. $errTitle = $errString;
  63. }
  64. set_up_language($squirrelmail_language, true);
  65. displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
  66. /* If they don't have a logo, don't bother.. */
  67. $logo_str = '';
  68. if (isset($org_logo) && $org_logo) {
  69. if (isset($org_logo_width) && is_numeric($org_logo_width) &&
  70. $org_logo_width>0) {
  71. $width = $org_logo_width;
  72. } else {
  73. $width = '';
  74. }
  75. if (isset($org_logo_height) && is_numeric($org_logo_height) &&
  76. $org_logo_height>0) {
  77. $height = $org_logo_height;
  78. } else {
  79. $height = '';
  80. }
  81. $logo_str = create_image($org_logo, sprintf(_("%s Logo"), $org_name),
  82. $width, $height, '', 'sqm_loginImage');
  83. }
  84. $sm_attribute_str = '';
  85. if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
  86. $sm_attribute_str = _("SquirrelMail Webmail Application") . "\n"
  87. . _("By the SquirrelMail Project Team");
  88. }
  89. $oTemplate->assign('logo_str', $logo_str);
  90. $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
  91. $oTemplate->assign('login_link', $login_link);
  92. $oTemplate->assign('errorMessage', $errString);
  93. $oTemplate->display('error_logout.tpl');
  94. $oTemplate->display('footer.tpl');
  95. }
  96. /**
  97. * Displays error message
  98. *
  99. * Since 1.4.1 function checks if page header is already displayed.
  100. *
  101. * Since 1.4.3 and 1.5.1, this function contains the error_box hook.
  102. * Use plain_error_message() and make sure that page header is created,
  103. * if you want compatibility with 1.4.0 and older.
  104. *
  105. * In 1.5.2 second function argument is changed. Older functions used it
  106. * for $color array, new function uses it for optional link data. Function
  107. * will ignore color array and use standard colors instead.
  108. *
  109. * @param string $string Error message to be displayed
  110. * @param array $link Optional array containing link details to be displayed.
  111. * Array uses three keys. 'URL' key is required and should contain link URL.
  112. * 'TEXT' key is optional and should contain link name. 'FRAME' key is
  113. * optional and should contain link target attribute.
  114. *
  115. * @since 1.3.2
  116. */
  117. function error_box($string, $link=NULL) {
  118. global $pageheader_sent, $oTemplate;
  119. $err = _("ERROR");
  120. do_hook('error_box', $string);
  121. /* check if the page header has been sent; if not, send it! */
  122. if (!isset($pageheader_sent) && !$pageheader_sent) {
  123. displayHtmlHeader('SquirrelMail: '.$err);
  124. $pageheader_sent = TRUE;
  125. echo "<body>\n\n";
  126. }
  127. // Double check the link for everything we need
  128. if (!is_null($link)) {
  129. // safety check for older code
  130. if (isset($link['URL'])) {
  131. if (!isset($link['FRAME'])) $link['FRAME'] = '';
  132. if (!isset($link['TEXT'])) $link['TEXT'] = $link['URL'];
  133. } else {
  134. // somebody used older error_box() code
  135. $link=null;
  136. }
  137. }
  138. /** ERROR is pre-translated to avoid multiple translation calls. **/
  139. $oTemplate->assign('error', $err);
  140. $oTemplate->assign('errorMessage', $string);
  141. $oTemplate->assign('link', $link);
  142. $oTemplate->display('error_box.tpl');
  143. }
  144. /**
  145. * Adds message that informs about non fatal error that can happen while saving preferences
  146. * @param string $message error message
  147. * @since 1.5.1 and 1.4.5
  148. */
  149. function error_option_save($message) {
  150. global $optpage_save_error;
  151. if (! is_array($optpage_save_error) )
  152. $optpage_save_error=array();
  153. $optpage_save_error=array_merge($optpage_save_error,array($message));
  154. }