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.

63 lines
1.4 KiB

  1. <?php
  2. require_once('./inc/model.class.php');
  3. class BansModel extends Model
  4. {
  5. private $ban_info = null;
  6. public function getBans()
  7. {
  8. $query = 'SELECT b.ban_id as ban_id, b.user_id as user_id, u.nick as nick, b.reason as reason
  9. FROM '.BANLIST_TABLE.' b
  10. LEFT JOIN '.USERS_TABLE.' u ON u.user_id = b.user_id';
  11. return $this->select_query($query);
  12. }
  13. public function getBan($ban_id)
  14. {
  15. if ($this->ban_info == null)
  16. {
  17. $query = 'SELECT b.ban_id as ban_id, b.user_id as user_id, u.nick as nick, b.reason as reason
  18. FROM '.BANLIST_TABLE.' b
  19. LEFT JOIN '.USERS_TABLE.' u ON u.user_id = b.user_id
  20. WHERE `ban_id`=\''.$ban_id.'\'';
  21. $out = $this->select_query($query);
  22. if (count($out) > 0)
  23. $this->ban_info = $out[0];
  24. }
  25. return $this->ban_info;
  26. }
  27. public function getUserBan($user_id)
  28. {
  29. $out = $this->select(BANLIST_TABLE, '*', 'user_id=\''.$user_id.'\'');
  30. if (count($out) > 0)
  31. return $out[0];
  32. else
  33. return null;
  34. }
  35. public function addBan($user_id, $reason)
  36. {
  37. $query = 'INSERT INTO '.BANLIST_TABLE.'
  38. (`ban_id`, `user_id`, `reason`)
  39. VALUES (NULL, \''.$user_id.'\', \''.$reason.'\')';
  40. $this->db->query($query);
  41. $query = 'DELETE FROM '.SESSIONS_TABLE.' WHERE `user_id`=\''.$user_id.'\'';
  42. $this->db->query($query);
  43. }
  44. public function deleteBan($ban_id)
  45. {
  46. $query = 'DELETE FROM '.BANLIST_TABLE.' WHERE `ban_id`=\''.$ban_id.'\'';
  47. $this->db->query($query);
  48. }
  49. }
  50. ?>