"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
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.

get.class.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /*
  3. * Gets various items from the database - Used on basically all pages.
  4. */
  5. class Get {
  6. private function __construct() {
  7. }
  8. public static function NewsArticle($id) {
  9. /* Here we sanitize the userinput. We only allow numbers here.
  10. * - Filter the variable to remove anything but numbers (plusses and minusses)
  11. * However, the filter_var needs us to trim the output first, as we dont want nullbytes.
  12. */
  13. $newsitem = filter_var(trim($id), FILTER_SANITIZE_NUMBER_INT);
  14. $db = new DBClass();
  15. $sql = "SELECT news.*,users.realname FROM `news` JOIN users ON news.author = users.id WHERE news.id = $newsitem";
  16. // Does the newsitem exist? If not, we redirect.
  17. if ($db->numRows($db->query($sql)) != 1) {
  18. header('Location: ' . Config::$sys_url . '?page=error');
  19. die("This newsitem doesnt exist.");
  20. }
  21. // It did, yay! - Lets fetch it, and return it.
  22. return $db->fetchAll($db->query($sql))[0];
  23. }
  24. public static function NewsList() {
  25. // newsadmin
  26. $db = new DBClass();
  27. $sql = "SELECT news.*,users.realname FROM `news` JOIN users ON news.author = users.id ORDER BY `id` DESC";
  28. return $db->fetchAll($db->query($sql));
  29. }
  30. public static function publicNewsList() {
  31. $db = new DBClass();
  32. $sql = "SELECT news.*,users.realname FROM `news` JOIN users ON news.author = users.id ORDER BY `id` DESC LIMIT 5";
  33. return $db->fetchAll($db->query($sql));
  34. }
  35. /* Event functions */
  36. public static function ViewEvent($id) {
  37. /* Here we sanitize the userinput. We only allow numbers here.
  38. * - Filter the variable to remove anything but numbers (plusses and minusses)
  39. * However, the filter_var needs us to trim the output first, as we dont want nullbytes.
  40. */
  41. $eventitem = filter_var(trim($id), FILTER_SANITIZE_NUMBER_INT);
  42. // Get the news
  43. $db = new DBClass();
  44. $sql = "SELECT * FROM `events` WHERE `id` = $eventitem";
  45. // Check if this eventitem exists - If not, we 404
  46. if ($db->numRows($db->query($sql)) != 1) {
  47. header('Location: ' . Config::$sys_url . '?page=error');
  48. die("This newsitem doesnt exist.");
  49. }
  50. // It did, yay! - Lets fetch it, and return it.
  51. return $db->fetchAll($db->query($sql))[0];
  52. }
  53. public static function EventList() {
  54. // eventadmin
  55. $db = new DBClass();
  56. $sql = "SELECT * FROM `events` ORDER BY `id` DESC";
  57. return $db->fetchAll($db->query($sql));
  58. }
  59. public static function publicEventList() {
  60. $db = new DBClass();
  61. $sql = "SELECT * FROM `events` ORDER BY `time` ASC";
  62. return $db->fetchAll($db->query($sql));
  63. }
  64. public static function publicEventListHome($limit) {
  65. $db = new DBClass();
  66. $sql = "SELECT * FROM `events` ORDER BY `time` ASC LIMIT $limit";
  67. return $db->fetchAll($db->query($sql));
  68. }
  69. public static function EventTrackList($limit) {
  70. $db = new DBClass();
  71. $sql = "SELECT * FROM `events` WHERE `type` = '2' ORDER BY `time` ASC LIMIT $limit";
  72. return $db->fetchAll($db->query($sql));
  73. }
  74. /* Login and user functions */
  75. public static function checkExists($name) {
  76. // Checks if username already is in db, if not return false, if it exists return true
  77. $db = new DBClass();
  78. $sql = "SELECT * FROM `" . Config::$db_tableusers . "` WHERE `username` = '$name'";
  79. if ($db->numRows($db->query($sql)) != 1) { return false; } else { return true; }
  80. }
  81. /* File/Upload functions */
  82. public static function getImages($limit) {
  83. // Returns all images in database.
  84. $db = new DBClass();
  85. $sql = "SELECT * FROM `uploads` WHERE `mime` LIKE 'image%'";
  86. return $db->fetchAll($db->query($sql));
  87. }
  88. }