A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.6 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file includes/classes/class_pms.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. if ( !defined('IN_uF') )
  11. {
  12. die('Hacking attempt');
  13. }
  14. class Pms
  15. {
  16. function PMCnt($uid = -1)
  17. {
  18. $uid = ($uid==-1) ? $_SESSION['uid'] : $uid;
  19. //private messages in inbox
  20. $sql = "SELECT COUNT(*) AS `cnt` FROM `".PM_INBOX_TABLE."` WHERE `u_id`='".$uid."'";
  21. $result = DataBase::sql_query($sql, GENERAL, 'Could not obtain count of pms in inbox');
  22. $row = DataBase::fetch($result);
  23. //private messages in sentbox
  24. $sql = "SELECT COUNT(*) AS `cnt` FROM `".PM_SENTBOX_TABLE."` WHERE `u_id`='".$uid."'";
  25. $result = DataBase::sql_query($sql, GENERAL, 'Could not obtain count of pms in sentbox');
  26. $row2 = DataBase::fetch($result);
  27. return array($row['cnt'], $row2['cnt']);
  28. }
  29. function UserName($uid)
  30. {
  31. global $user;
  32. global $forum_config;
  33. $nick = $user[$uid]['nick'];
  34. $rank = $user[$uid]['rank'];
  35. switch($rank)
  36. {
  37. case '0':
  38. {
  39. return $nick;
  40. break;
  41. }
  42. case '1':
  43. {
  44. return '<font color="'.$forum_config['color_mod'].'"><b>'.$nick.'</b></font>';
  45. break;
  46. }
  47. case '2':
  48. {
  49. return '<font color="'.$forum_config['color_admin'].'"><b>'.$nick.'</b></font>';
  50. break;
  51. }
  52. }
  53. }
  54. function SendMessage($text, $name, $nick)
  55. {
  56. //general variables
  57. $u_n_id = $_SESSION['uid'];
  58. $uid = User::UserIdByNick($nick);
  59. //For work!
  60. NewMessage::AddToInbox($text, $name, $u_n_id, $uid);
  61. NewMessage::AddToSentbox($text, $name, $u_n_id, $uid);
  62. }
  63. function DeleteMsgUser($mid)
  64. {
  65. $sql = "DELETE FROM `".PM_INBOX_TABLE."` WHERE `m_id`='$mid'";
  66. DataBase::sql_query($sql,GENERAL,'Could not delete message in inbox');
  67. }
  68. function DeleteMsgAuthor($mid)
  69. {
  70. $sql = "DELETE FROM `".PM_SENTBOX_TABLE."` WHERE `m_id`='$mid'";
  71. DataBase::sql_query($sql,GENERAL,'Could not delete message in sentbox');
  72. }
  73. }
  74. class NewMessage
  75. {
  76. function AddToInbox($text, $name, $unid, $uid)
  77. {
  78. $last = DataBase::new_id(PM_INBOX_TABLE);
  79. $time = time();
  80. $sql = "INSERT INTO `".PM_INBOX_TABLE."` VALUES ('$last', '$uid', '$name', '$text', '$time', '$unid','0')";
  81. DataBase::sql_query($sql,GENERAL,'Could not add new message at inbox');
  82. }
  83. function AddToSentbox($text, $name, $unid, $uid)
  84. {
  85. $last=DataBase::new_id(PM_SENTBOX_TABLE);
  86. $time = time();
  87. $sql = "INSERT INTO `".PM_SENTBOX_TABLE."` VALUES ('$last', '$uid', '$name', '$text', '$time', '$unid')";
  88. DataBase::sql_query($sql,GENERAL,'Could not add new message at inbox');
  89. }
  90. }
  91. ?>