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.

131 lines
3.2 KiB

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