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 &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 changed to boolean $return_output as of 1.5.2.
  36. * @param string $message error message
  37. * @param boolean $return_output When TRUE, output is returned to caller
  38. * instead of being sent to browser (OPTIONAL;
  39. * default = FALSE)
  40. * @since 1.0
  41. */
  42. function plain_error_message($message, $return_output=FALSE) {
  43. return error_box($message, NULL, $return_output);
  44. }
  45. /**
  46. * Displays error when user is logged out
  47. *
  48. * Error strings can be overriden by logout_error hook
  49. * @param string $errString error message
  50. * @param string $errTitle title of page with error message
  51. * @since 1.2.6
  52. */
  53. function logout_error( $errString, $errTitle = '' ) {
  54. global $frame_top, $org_logo, $org_logo_width, $org_logo_height, $org_name,
  55. $hide_sm_attributions, $squirrelmail_language, $oTemplate;
  56. $base_uri = sqm_baseuri();
  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. do_hook('logout_error', $temp=array(&$errString, &$errTitle, &$login_link));
  64. if ( $errTitle == '' ) {
  65. $errTitle = $errString;
  66. }
  67. set_up_language($squirrelmail_language, true);
  68. displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
  69. /* If they don't have a logo, don't bother.. */
  70. $logo_str = '';
  71. if (isset($org_logo) && $org_logo) {
  72. if (isset($org_logo_width) && is_numeric($org_logo_width) &&
  73. $org_logo_width>0) {
  74. $width = $org_logo_width;
  75. } else {
  76. $width = '';
  77. }
  78. if (isset($org_logo_height) && is_numeric($org_logo_height) &&
  79. $org_logo_height>0) {
  80. $height = $org_logo_height;
  81. } else {
  82. $height = '';
  83. }
  84. $logo_str = create_image($org_logo, sprintf(_("%s Logo"), $org_name),
  85. $width, $height, '', 'sqm_loginImage');
  86. }
  87. $sm_attribute_str = '';
  88. if (isset($hide_sm_attributions) && !$hide_sm_attributions) {
  89. $sm_attribute_str = _("SquirrelMail Webmail") . "\n"
  90. . _("By the SquirrelMail Project Team");
  91. }
  92. $oTemplate->assign('logo_str', $logo_str);
  93. $oTemplate->assign('sm_attribute_str', $sm_attribute_str);
  94. $oTemplate->assign('login_link', $login_link);
  95. $oTemplate->assign('errorMessage', $errString);
  96. $oTemplate->display('error_logout.tpl');
  97. $oTemplate->display('footer.tpl');
  98. }
  99. /**
  100. * Displays error message
  101. *
  102. * Since 1.4.1 function checks if page header is already displayed.
  103. *
  104. * Since 1.4.3 and 1.5.1, this function contains the error_box hook.
  105. * Use plain_error_message() and make sure that page header is created,
  106. * if you want compatibility with 1.4.0 and older.
  107. *
  108. * In 1.5.2 second function argument is changed. Older functions used it
  109. * for $color array, new function uses it for optional link data. Function
  110. * will ignore color array and use standard colors instead.
  111. *
  112. * The $return_output argument was added in 1.5.2
  113. *
  114. * @param string $string Error message to be displayed
  115. * @param array $link Optional array containing link details to be displayed.
  116. * Array uses three keys. 'URL' key is required and should contain link URL.
  117. * 'TEXT' key is optional and should contain link name. 'FRAME' key is
  118. * optional and should contain link target attribute.
  119. * @param boolean $return_output When TRUE, output is returned to caller
  120. * instead of being sent to browser (OPTIONAL;
  121. * default = FALSE)
  122. *
  123. * @since 1.3.2
  124. */
  125. function error_box($string, $link=NULL, $return_output=FALSE) {
  126. global $pageheader_sent, $oTemplate, $org_title;
  127. $err = _("ERROR");
  128. do_hook('error_box', $string);
  129. if ( !isset($org_title) ) $org_title = 'SquirrelMail';
  130. // check if the page header has been sent; if not, send it!
  131. //
  132. // (however, if $return_output is turned on, the output of this
  133. // should be being used in some other page, so we don't have
  134. // to worry about page headers in that case)
  135. //
  136. if (!$return_output && empty($pageheader_sent)) {
  137. displayHtmlHeader($org_title . ': '.$err);
  138. $pageheader_sent = TRUE;
  139. echo create_body(); // this is template-safe (see create_body() function)
  140. }
  141. // Double check the link for everything we need
  142. if (!is_null($link)) {
  143. // safety check for older code
  144. if (isset($link['URL'])) {
  145. if (!isset($link['FRAME'])) $link['FRAME'] = '';
  146. if (!isset($link['TEXT'])) $link['TEXT'] = $link['URL'];
  147. } else {
  148. // somebody used older error_box() code
  149. $link=null;
  150. }
  151. }
  152. /** ERROR is pre-translated to avoid multiple translation calls. **/
  153. $oTemplate->assign('error', $err);
  154. $oTemplate->assign('errorMessage', $string);
  155. $oTemplate->assign('link', $link);
  156. $output = $oTemplate->fetch('error_box.tpl');
  157. if ($return_output) return $output;
  158. echo $output;
  159. }
  160. /**
  161. * Adds message that informs about non fatal error that can happen while saving preferences
  162. * @param string $message error message
  163. * @since 1.5.1 and 1.4.5
  164. */
  165. function error_option_save($message) {
  166. global $optpage_save_error;
  167. if (! is_array($optpage_save_error) )
  168. $optpage_save_error=array();
  169. $optpage_save_error=array_merge($optpage_save_error,array($message));
  170. }