"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

get.class.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. }