1
0

readmsg.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /* $Id: readmsg.php 2893 2007-04-14 13:20:30Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // prevent direct invocation
  16. if ((!isset($cfg['user'])) || (isset($_REQUEST['cfg']))) {
  17. @ob_end_clean();
  18. @header("location: ../../index.php");
  19. exit();
  20. }
  21. /******************************************************************************/
  22. // common functions
  23. require_once('inc/functions/functions.common.php');
  24. // delete
  25. if (isset($_REQUEST['delete'])) {
  26. $delete = tfb_getRequestVar('delete');
  27. if (!empty($delete))
  28. DeleteMessage($delete);
  29. @header("location: index.php?iid=readmsg");
  30. exit();
  31. }
  32. // init template-instance
  33. tmplInitializeInstance($cfg["theme"], "page.readmsg.tmpl");
  34. if (isset($_REQUEST['mid'])) {
  35. $mid = tfb_getRequestVar('mid');
  36. list($from_user, $message, $ip, $time, $isnew, $force_read) = GetMessage($mid);
  37. if (!empty($from_user) && $isnew == 1) {
  38. // We have a Message that is being seen
  39. // Mark it as NOT new.
  40. MarkMessageRead($mid);
  41. }
  42. $message = check_html($message, "a");
  43. $message = html_entity_decode($message);
  44. $message = str_replace("\n", "<br>", $message);
  45. if (IsUser($from_user))
  46. $tmpl->setvar('IsUser', 1);
  47. $tmpl->setvar('from_user', $from_user);
  48. $tmpl->setvar('message', $message);
  49. $tmpl->setvar('mid', $mid);
  50. } else {
  51. // read and display all messages in a list.
  52. $inx = 0;
  53. $sql = "SELECT mid, from_user, message, IsNew, ip, time, force_read FROM tf_messages WHERE to_user=".$db->qstr($cfg["user"])." ORDER BY time";
  54. $result = $db->Execute($sql);
  55. if ($db->ErrorNo() != 0) dbError($sql);
  56. $message_list = array();
  57. while (list($mid, $from_user, $message, $new, $ip, $time, $force_read) = $result->FetchRow()) {
  58. $mail_image = ($new == 1)
  59. ? "themes/".$cfg['theme']."/images/new_message.gif"
  60. : "themes/".$cfg['theme']."/images/old_message.gif";
  61. $display_message = check_html($message, "nohtml");
  62. if (strlen($display_message) >= 40)
  63. $display_message = substr($display_message, 0, 39)."...";
  64. // No, let them reply or delete it
  65. array_push($message_list, array (
  66. 'mid' => $mid,
  67. 'mail_image' => $mail_image,
  68. 'from_user' => $from_user,
  69. 'display_message' => $display_message,
  70. 'date2' => date($cfg['_DATETIMEFORMAT'], $time),
  71. 'force_read' => $force_read,
  72. 'IsUser2' => (IsUser($from_user)) ? 1 : 0,
  73. )
  74. );
  75. $inx++;
  76. }
  77. if ($inx == 0) {
  78. $tmpl->setvar('no_inx', 1);
  79. $tmpl->setvar('_NORECORDSFOUND', $cfg['_NORECORDSFOUND']);
  80. } else {
  81. $tmpl->setvar('no_inx', 0);
  82. $tmpl->setloop('message_list', $message_list);
  83. }
  84. $tmpl->setvar('_SENDMESSAGETO', $cfg['_SENDMESSAGETO']);
  85. $tmpl->setvar('_COMPOSE', $cfg['_COMPOSE']);
  86. $userList = array();
  87. for ($inx = 0; $inx < sizeof($cfg['users']); $inx++)
  88. array_push($userList, array('user' => htmlentities($cfg['users'][$inx], ENT_QUOTES)));
  89. $tmpl->setloop('messageList_user', $userList);
  90. }
  91. // set vars
  92. $tmpl->setvar('date1', date($cfg['_DATETIMEFORMAT'], $time));
  93. //
  94. $tmpl->setvar('_FROM', $cfg['_FROM']);
  95. $tmpl->setvar('_REPLY', $cfg['_REPLY']);
  96. $tmpl->setvar('_DELETE', $cfg['_DELETE']);
  97. $tmpl->setvar('_DATE', $cfg['_DATE']);
  98. $tmpl->setvar('_ADMIN', $cfg['_ADMIN']);
  99. $tmpl->setvar('_MESSAGE', $cfg['_MESSAGE']);
  100. $tmpl->setvar('_RETURNTOMESSAGES', $cfg['_RETURNTOMESSAGES']);
  101. //
  102. $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
  103. //
  104. tmplSetTitleBar($cfg["pagetitle"].' - '.$cfg['_MESSAGES']);
  105. tmplSetFoot();
  106. tmplSetIidVars();
  107. // parse template
  108. $tmpl->pparse();
  109. ?>