display_messages.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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-2006 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. /* Display width and height like good little people */
  70. $width_and_height = '';
  71. if (isset($org_logo_width) && is_numeric($org_logo_width) &&
  72. $org_logo_width>0) {
  73. $width_and_height = " width=\"$org_logo_width\"";
  74. }
  75. if (isset($org_logo_height) && is_numeric($org_logo_height) &&
  76. $org_logo_height>0) {
  77. $width_and_height .= " height=\"$org_logo_height\"";
  78. }
  79. $logo_str = '<img src="'.$org_logo.'" ' .
  80. 'alt="'. sprintf(_("%s Logo"), $org_name).'" ' .
  81. $width_and_height .
  82. 'class="sqm_loginImage" ' .
  83. ' /><br />'."\n";
  84. }
  85. $sm_attribute_str = '';
  86. if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
  87. $sm_attribute_str = _("SquirrelMail Webmail Application")."<br />\n" .
  88. _("By the SquirrelMail Project Team")."<br />\n";
  89. }
  90. $oTemplate->assign('logo_str', $logo_str);
  91. $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
  92. $oTemplate->assign('login_link', $login_link);
  93. $oTemplate->assign('errorMessage', $errString);
  94. $oTemplate->display('error_logout.tpl');
  95. $oTemplate->display('footer.tpl');
  96. }
  97. /**
  98. * Displays error message
  99. *
  100. * Since 1.4.1 function checks if page header is already displayed.
  101. *
  102. * Since 1.4.3 and 1.5.1, this function contains the error_box hook.
  103. * Use plain_error_message() and make sure that page header is created,
  104. * if you want compatibility with 1.4.0 and older.
  105. *
  106. * In 1.5.2 second function argument is changed. Older functions used it
  107. * for $color array, new function uses it for optional link data. Function
  108. * will ignore color array and use standard colors instead.
  109. *
  110. * @param string $string Error message to be displayed
  111. * @param array $link Optional array containing link details to be displayed.
  112. * Array uses three keys. 'URL' key is required and should contain link URL.
  113. * 'TEXT' key is optional and should contain link name. 'FRAME' key is
  114. * optional and should contain link target attribute.
  115. *
  116. * @since 1.3.2
  117. */
  118. function error_box($string, $link=NULL) {
  119. global $pageheader_sent, $oTemplate;
  120. $err = _("ERROR");
  121. do_hook('error_box', $string);
  122. /* check if the page header has been sent; if not, send it! */
  123. if (!isset($pageheader_sent) && !$pageheader_sent) {
  124. displayHtmlHeader('SquirrelMail: '.$err);
  125. $pageheader_sent = TRUE;
  126. echo "<body>\n\n";
  127. }
  128. // Double check the link for everything we need
  129. if (!is_null($link)) {
  130. // safety check for older code
  131. if (isset($link['URL'])) {
  132. if (!isset($link['FRAME'])) $link['FRAME'] = '';
  133. if (!isset($link['TEXT'])) $link['TEXT'] = $link['URL'];
  134. } else {
  135. // somebody used older error_box() code
  136. $link=null;
  137. }
  138. }
  139. /** ERROR is pre-translated to avoid multiple translation calls. **/
  140. $oTemplate->assign('error', $err);
  141. $oTemplate->assign('errorMessage', $string);
  142. $oTemplate->assign('link', $link);
  143. $oTemplate->display('error_box.tpl');
  144. }
  145. /**
  146. * Adds message that informs about non fatal error that can happen while saving preferences
  147. * @param string $message error message
  148. * @since 1.5.1 and 1.4.5
  149. */
  150. function error_option_save($message) {
  151. global $optpage_save_error;
  152. if (! is_array($optpage_save_error) )
  153. $optpage_save_error=array();
  154. $optpage_save_error=array_merge($optpage_save_error,array($message));
  155. }