"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

get.class.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 `id` DESC LIMIT 5";
  62. return $db->fetchAll($db->query($sql));
  63. }
  64. /* Login and user functions */
  65. public static function checkExists($name) {
  66. // Checks if username already is in db, if not return false, if it exists return true
  67. $db = new DBClass();
  68. $sql = "SELECT * FROM `" . Config::$db_tableusers . "` WHERE `username` = '$name'";
  69. if ($db->numRows($db->query($sql)) != 1) { return false; } else { return true; }
  70. }
  71. /* File/Upload functions */
  72. public static function getImages($limit) {
  73. // Returns all images in database.
  74. $db = new DBClass();
  75. $sql = "SELECT * FROM `uploads` WHERE `mime` LIKE 'image%'";
  76. return $db->fetchAll($db->query($sql));
  77. }
  78. }