display_messages.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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-2005 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id$
  11. * @package squirrelmail
  12. */
  13. /** @ignore */
  14. if (! defined('SM_PATH')) define('SM_PATH','../');
  15. /**
  16. * including plugin functions
  17. */
  18. include_once(SM_PATH . 'functions/plugin.php');
  19. /**
  20. * Find out where SquirrelMail lives and try to be smart about it.
  21. * The only problem would be when SquirrelMail lives in directories
  22. * called "src", "functions", or "plugins", but people who do that need
  23. * to be beaten with a steel pipe anyway.
  24. *
  25. * @return string the base uri of SquirrelMail installation.
  26. * @since 1.2.6
  27. */
  28. function sqm_baseuri(){
  29. global $base_uri, $PHP_SELF;
  30. /**
  31. * If it is in the session, just return it.
  32. */
  33. if (isset($base_uri)){
  34. return $base_uri;
  35. }
  36. $dirs = array('|src/.*|', '|plugins/.*|', '|functions/.*|');
  37. $repl = array('', '', '');
  38. $base_uri = preg_replace($dirs, $repl, $PHP_SELF);
  39. return $base_uri;
  40. }
  41. /**
  42. * Displays error message and URL to message listing
  43. * @param string $message error message
  44. * @param string $mailbox mailbox name
  45. * @param integer $sort sort order
  46. * @param integer $startMessage first message
  47. * @param array $color color theme
  48. * @since 1.0
  49. */
  50. function error_message($message, $mailbox, $sort, $startMessage, $color) {
  51. $urlMailbox = urlencode($mailbox);
  52. $string = '<tr><td align="center">' . $message . '</td></tr>'.
  53. '<tr><td align="center">'.
  54. '<a href="'.sqm_baseuri()."src/right_main.php?sort=$sort&amp;startMessage=$startMessage&amp;mailbox=$urlMailbox\">".
  55. sprintf (_("Click here to return to %s"),
  56. strtoupper($mailbox) == 'INBOX' ? _("INBOX") : imap_utf7_decode_local($mailbox)).
  57. '</a></td></tr>';
  58. error_box($string, $color);
  59. }
  60. /**
  61. * Displays error message
  62. * @param string $message error message
  63. * @param array $color color theme
  64. * @since 1.0
  65. */
  66. function plain_error_message($message, $color) {
  67. error_box($message, $color);
  68. }
  69. /**
  70. * Displays error when user is logged out
  71. *
  72. * Error strings can be overriden by logout_error hook
  73. * @param string $errString error message
  74. * @param string $errTitle title of page with error message
  75. * @since 1.2.6
  76. */
  77. function logout_error( $errString, $errTitle = '' ) {
  78. global $frame_top, $org_logo, $org_name, $org_logo_width, $org_logo_height,
  79. $hide_sm_attributions, $version, $squirrelmail_language,
  80. $color, $theme, $theme_default;
  81. $base_uri = sqm_baseuri();
  82. include_once( SM_PATH . 'functions/page_header.php' );
  83. if ( !isset( $org_logo ) ) {
  84. // Don't know yet why, but in some accesses $org_logo is not set.
  85. include( SM_PATH . 'config/config.php' );
  86. }
  87. /* Display width and height like good little people */
  88. $width_and_height = '';
  89. if (isset($org_logo_width) && is_numeric($org_logo_width) && $org_logo_width>0) {
  90. $width_and_height = " width=\"$org_logo_width\"";
  91. }
  92. if (isset($org_logo_height) && is_numeric($org_logo_height) && $org_logo_height>0) {
  93. $width_and_height .= " height=\"$org_logo_height\"";
  94. }
  95. if (!isset($frame_top) || $frame_top == '' ) {
  96. $frame_top = '_top';
  97. }
  98. // load default theme if possible
  99. if (!isset($color) && @file_exists($theme[$theme_default]['PATH']))
  100. @include ($theme[$theme_default]['PATH']);
  101. if ( !isset( $color ) ) {
  102. $color = array();
  103. $color[0] = '#dcdcdc'; /* light gray TitleBar */
  104. $color[1] = '#800000'; /* red */
  105. $color[2] = '#cc0000'; /* light red Warning/Error Messages */
  106. $color[4] = '#ffffff'; /* white Normal Background */
  107. $color[7] = '#0000cc'; /* blue Links */
  108. $color[8] = '#000000'; /* black Normal text */
  109. }
  110. list($junk, $errString, $errTitle) = do_hook('logout_error', $errString, $errTitle);
  111. if ( $errTitle == '' ) {
  112. $errTitle = $errString;
  113. }
  114. set_up_language($squirrelmail_language, true);
  115. displayHtmlHeader( $org_name.' - '.$errTitle, '', false );
  116. echo '<body text="'.$color[8].'" bgcolor="'.$color[4].'" link="'.$color[7].'" vlink="'.$color[7].'" alink="'.$color[7]."\">\n\n".
  117. '<center>';
  118. if (isset($org_logo) && ($org_logo != '')) {
  119. echo '<img src="'.$org_logo.'" alt="'.sprintf(_("%s Logo"), $org_name).
  120. "\"$width_and_height /><br />\n";
  121. }
  122. echo ( $hide_sm_attributions ? '' :
  123. '<small>' . _("SquirrelMail Webmail Application") . '<br />'.
  124. _("By the SquirrelMail Project Team") . "<br /></small>\n" ).
  125. '<table cellspacing="1" cellpadding="0" bgcolor="'.$color[1].'" width="70%">'.
  126. '<tr><td>'.
  127. '<table width="100%" border="0" bgcolor="'.$color[4].'" align="center">'.
  128. '<tr><td bgcolor="'.$color[0].'" align="center">'.
  129. '<font color="'.$color[2].'"><b>' . _("ERROR") . '</b></font>'.
  130. '</td></tr>'.
  131. '<tr><td align="center">' . $errString . '</td></tr>'.
  132. '<tr><td bgcolor="'.$color[0].'" align="center">'.
  133. '<font color="'.$color[2].'"><b>'.
  134. '<a href="'.$base_uri.'src/login.php" target="'.$frame_top.'">'.
  135. _("Go to the login page") . '</a></b></font></td></tr>'.
  136. '</table></td></tr></table></center></body></html>';
  137. }
  138. /**
  139. * Displays error message
  140. *
  141. * Since 1.4.1 function checks if page header is already displayed.
  142. * Since 1.4.3 and 1.5.1 function contains error_box hook.
  143. * Use plain_error_message() and make sure that page header is created,
  144. * if you want compatibility with 1.4.0 and older.
  145. * @param string $string
  146. * @param array $color
  147. * @since 1.3.2
  148. */
  149. function error_box($string, $color) {
  150. global $pageheader_sent;
  151. if ( !isset( $color ) ) {
  152. $color = array();
  153. $color[0] = '#dcdcdc'; /* light gray TitleBar */
  154. $color[1] = '#800000'; /* red */
  155. $color[2] = '#cc0000'; /* light red Warning/Error Messages */
  156. $color[4] = '#ffffff'; /* white Normal Background */
  157. $color[7] = '#0000cc'; /* blue Links */
  158. $color[8] = '#000000'; /* black Normal text */
  159. $color[9] = '#ababab'; /* mid-gray Darker version of #0 */
  160. }
  161. $err = _("ERROR");
  162. $ret = concat_hook_function('error_box', $string);
  163. if($ret != '') {
  164. $string = $ret;
  165. }
  166. /* check if the page header has been sent; if not, send it! */
  167. if(!isset($pageheader_sent) && !$pageheader_sent) {
  168. /* include this just to be sure */
  169. include_once( SM_PATH . 'functions/page_header.php' );
  170. displayHtmlHeader('SquirrelMail: '.$err);
  171. $pageheader_sent = TRUE;
  172. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n\n";
  173. }
  174. echo '<table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'.
  175. '<tr><td>'.
  176. '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'.
  177. '<tr><td align="center" bgcolor="'.$color[0].'">'.
  178. '<font color="'.$color[2].'"><b>' . $err . ':</b></font>'.
  179. '</td></tr><tr><td>'.
  180. '<table cellpadding="1" cellspacing="5" align="center" border="0">'.
  181. '<tr>' . html_tag( 'td', $string."\n", 'left') . '</tr></table>'.
  182. '</td></tr></table></td></tr></table>';
  183. }
  184. /**
  185. * Adds message that informs about non fatal error that can happen while saving preferences
  186. * @param string $message error message
  187. * @since 1.5.1 and 1.4.5
  188. */
  189. function error_option_save($message) {
  190. global $optpage_save_error;
  191. if (! is_array($optpage_save_error) )
  192. $optpage_save_error=array();
  193. $optpage_save_error=array_merge($optpage_save_error,array($message));
  194. }
  195. // vim: et ts=4
  196. ?>