display_messages.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. list($junk, $errString, $errTitle) = do_hook('logout_error', $errString, $errTitle);
  55. if ( $errTitle == '' ) {
  56. $errTitle = $errString;
  57. }
  58. set_up_language($squirrelmail_language, true);
  59. displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
  60. /* If they don't have a logo, don't bother.. */
  61. $logo_str = '';
  62. if (isset($org_logo) && $org_logo) {
  63. /* Display width and height like good little people */
  64. $width_and_height = '';
  65. if (isset($org_logo_width) && is_numeric($org_logo_width) &&
  66. $org_logo_width>0) {
  67. $width_and_height = " width=\"$org_logo_width\"";
  68. }
  69. if (isset($org_logo_height) && is_numeric($org_logo_height) &&
  70. $org_logo_height>0) {
  71. $width_and_height .= " height=\"$org_logo_height\"";
  72. }
  73. $logo_str = '<img src="'.$org_logo.'" ' .
  74. 'alt="'. sprintf(_("%s Logo"), $org_name).'" ' .
  75. $width_and_height .
  76. 'class="sqm_loginImage" ' .
  77. ' /><br />'."\n";
  78. }
  79. $sm_attribute_str = '';
  80. if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
  81. $sm_attribute_str = _("SquirrelMail Webmail Application")."<br />\n" .
  82. _("By the SquirrelMail Project Team")."<br />\n";
  83. }
  84. $login_link = array (
  85. 'URL' => $base_uri . 'src/login.php',
  86. 'FRAME' => $frame_top
  87. );
  88. $oTemplate->assign('logo_str', $logo_str);
  89. $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
  90. $oTemplate->assign('login_link', $login_link);
  91. $oTemplate->assign('errorMessage', $errString);
  92. $oTemplate->display('error_logout.tpl');
  93. $oTemplate->display('footer.tpl');
  94. }
  95. /**
  96. * Displays error message
  97. *
  98. * Since 1.4.1 function checks if page header is already displayed.
  99. *
  100. * Since 1.4.3 and 1.5.1 function contains error_box hook.
  101. * Use plain_error_message() and make sure that page header is created,
  102. * if you want compatibility with 1.4.0 and older.
  103. *
  104. * In 1.5.2 second function argument is changed. Older functions used it
  105. * for $color array, new function uses it for optional link data. Function
  106. * will ignore color array and use standard colors instead.
  107. * @param string $string Error message to be displayed
  108. * @param array $link Optional array containing link details to be displayed.
  109. * Array uses three keys. 'URL' key is required and should contain link URL.
  110. * 'TEXT' key is optional and should contain link name. 'FRAME' key is
  111. * optional and should contain link target attribute.
  112. * @since 1.3.2
  113. */
  114. function error_box($string, $link=NULL) {
  115. global $pageheader_sent, $oTemplate;
  116. $err = _("ERROR");
  117. $ret = concat_hook_function('error_box', $string);
  118. if($ret != '') {
  119. $string = $ret;
  120. }
  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. }