A new, object-oriented, better vesion of μForum
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.

127 lines
3.0 KiB

  1. <?php
  2. require_once('./inc/model.class.php');
  3. class UsersModel extends Model
  4. {
  5. private $user_info = null;
  6. public function nickExists($nick)
  7. {
  8. $out = $this->select(USERS_TABLE, 'nick', '`nick`=\''.$nick.'\'', '', 1);
  9. if (count($out) > 0)
  10. return true;
  11. else
  12. return false;
  13. }
  14. public function createNewUser($nick, $passwd, $email)
  15. {
  16. $this->db->query('call add_user(\''.$nick.'\', \''.$passwd.'\', \''.$email.'\');');
  17. }
  18. public function getUsersNicks()
  19. {
  20. $out = $this->select (USERS_TABLE, 'user_id, nick', '', 'user_id ASC');
  21. if (count($out) > 0)
  22. return $out;
  23. else
  24. return array();
  25. }
  26. public function getUserInformation($user_id, $passwd = false)
  27. {
  28. if ($this->user_info == null)
  29. {
  30. $query = '
  31. SELECT
  32. u.nick as nick, u.email as email, u.rank as rank, u.active as active,
  33. ui.regdate as regdate, ui.lastvisit as lastvisit, ui.avatar as avatar, ui.location as location, ui.signature as signature, pc.post_count as post_count, lu.IP as user_IP ';
  34. if ($passwd)
  35. $query .= ',u.password as password ';
  36. $query .= '
  37. FROM '.USERS_TABLE.' u
  38. LEFT JOIN '.USERS_INFO_TABLE.' ui on ui.user_id = u.user_id
  39. LEFT JOIN '.USERS_PC_VIEW.' pc on pc.user_id = u.user_id
  40. LEFT JOIN '.LOGGED_USERS_VIEW.' lu on lu.user_id = u.user_id
  41. WHERE u.user_id = \''.$user_id.'\'';
  42. $out = $this->select_query($query);
  43. if (count($out) > 0)
  44. $this->user_info = $out[0];
  45. }
  46. return $this->user_info;
  47. }
  48. public function changeUserPassword($user_id, $passwd)
  49. {
  50. $query =
  51. 'UPDATE .'.USERS_TABLE.'
  52. SET `password`=\''.$passwd.'\'
  53. WHERE `user_id` = \''.$user_id.'\'';
  54. $this->db->query($query);
  55. }
  56. public function changeUserRank($user_id, $rank)
  57. {
  58. $query =
  59. 'UPDATE .'.USERS_TABLE.'
  60. SET `rank`=\''.$rank.'\'
  61. WHERE `user_id` = \''.$user_id.'\'';
  62. $this->db->query($query);
  63. }
  64. public function updateUserProfile($user_id, $nick, $email, $location, $signature, $avatar)
  65. {
  66. $query =
  67. 'UPDATE .'.USERS_TABLE.'
  68. SET ';
  69. if ($nick != null)
  70. $query .= '`nick`=\''.$nick.'\',';
  71. $query .= '`email`=\''.$email.'\'
  72. WHERE `user_id` = \''.$user_id.'\'';
  73. $this->db->query($query);
  74. //profile informations
  75. $query =
  76. 'UPDATE .'.USERS_INFO_TABLE.'
  77. SET
  78. `avatar`=\''.$avatar.'\',
  79. `location`=\''.$location.'\',
  80. `signature`=\''.$signature.'\'
  81. WHERE `user_id` = \''.$user_id.'\'';
  82. $this->db->query($query);
  83. }
  84. public function getUsers($stype, $sorder, $rank)
  85. {
  86. $query = '
  87. SELECT
  88. u.user_id as user_id, u.nick as nick, u.rank as rank, ui.regdate as regdate, ui.lastvisit as lastvisit, pc.post_count as post_count
  89. FROM '.USERS_TABLE.' u
  90. LEFT JOIN '.USERS_INFO_TABLE.' ui on ui.user_id = u.user_id
  91. LEFT JOIN '.USERS_PC_VIEW.' pc on pc.user_id = u.user_id ';
  92. if ($rank !== '')
  93. $query .= 'WHERE rank=\''.$rank.'\'';
  94. $query .= '
  95. ORDER BY '.$stype.' '.$sorder;
  96. $out = $this->select_query($query);
  97. return $out;
  98. }
  99. public function deleteUser($user_id)
  100. {
  101. $query =
  102. 'DELETE FROM .'.USERS_TABLE.'
  103. WHERE `user_id` = \''.$user_id.'\'';
  104. $this->db->query($query);
  105. }
  106. }
  107. ?>