functions.common.message.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /* $Id: functions.common.message.php 2934 2007-04-20 17:35:09Z 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. /**
  16. * Delete Message
  17. *
  18. * @param $mid
  19. */
  20. function DeleteMessage($mid) {
  21. global $cfg, $db;
  22. $sql = "delete from tf_messages where mid=".$db->qstr($mid)." and to_user=".$db->qstr($cfg["user"]);
  23. $result = $db->Execute($sql);
  24. if ($db->ErrorNo() != 0) dbError($sql);
  25. }
  26. /**
  27. * Mark Message as Read
  28. *
  29. * @param $mid
  30. */
  31. function MarkMessageRead($mid) {
  32. global $cfg, $db;
  33. $sql = "select * from tf_messages where mid = ".$db->qstr($mid);
  34. $rs = $db->Execute($sql);
  35. if ($db->ErrorNo() != 0) dbError($sql);
  36. $rec = array('IsNew'=>0, 'force_read'=>0);
  37. $sql = $db->GetUpdateSQL($rs, $rec);
  38. $db->Execute($sql);
  39. if ($db->ErrorNo() != 0) dbError($sql);
  40. }
  41. /**
  42. * Save Message
  43. *
  44. * @param $to_user
  45. * @param $from_user
  46. * @param $message
  47. * @param $to_all
  48. * @param $force_read
  49. */
  50. function SaveMessage($to_user, $from_user, $message, $to_all=0, $force_read=0) {
  51. global $cfg, $db;
  52. $message = str_replace(array("'"), "", $message);
  53. $create_time = time();
  54. $sTable = 'tf_messages';
  55. if ($to_all == 1) {
  56. $message .= "\n\n__________________________________\n*** ".$cfg['_MESSAGETOALL']." ***";
  57. $sql = 'select user_id from tf_users';
  58. $result = $db->Execute($sql);
  59. if ($db->ErrorNo() != 0) dbError($sql);
  60. while ($row = $result->FetchRow()) {
  61. $rec = array(
  62. 'to_user' => strtolower($row['user_id']),
  63. 'from_user' => strtolower($from_user),
  64. 'message' => $message,
  65. 'IsNew' => 1,
  66. 'ip' => $cfg['ip'],
  67. 'time' => $create_time,
  68. 'force_read' => $force_read
  69. );
  70. $sql = $db->GetInsertSql($sTable, $rec);
  71. $result2 = $db->Execute($sql);
  72. if ($db->ErrorNo() != 0) dbError($sql);
  73. }
  74. } else {
  75. // Only Send to one Person
  76. $rec = array(
  77. 'to_user' => strtolower($to_user),
  78. 'from_user' => strtolower($from_user),
  79. 'message' => $message,
  80. 'IsNew' => 1,
  81. 'ip' => $cfg['ip'],
  82. 'time' => $create_time,
  83. 'force_read' => $force_read
  84. );
  85. $sql = $db->GetInsertSql($sTable, $rec);
  86. $result = $db->Execute($sql);
  87. if ($db->ErrorNo() != 0) dbError($sql);
  88. }
  89. }
  90. /**
  91. * Get Message data in an array
  92. *
  93. * @param $mid
  94. * @return array
  95. */
  96. function GetMessage($mid) {
  97. global $cfg, $db;
  98. $sql = "select from_user, message, ip, time, isnew, force_read from tf_messages where mid=".$db->qstr($mid)." and to_user=".$db->qstr($cfg["user"]);
  99. $rtnValue = $db->GetRow($sql);
  100. if ($db->ErrorNo() != 0) dbError($sql);
  101. return $rtnValue;
  102. }
  103. ?>