"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. $time = new DateTime();
  62. $sql = "SELECT * FROM `events` WHERE `time` > ".$time->getTimestamp()." ORDER BY `time` ASC";
  63. return $db->fetchAll($db->query($sql));
  64. }
  65. public static function publicOldEventList() {
  66. $db = new DBClass();
  67. $time = new DateTime();
  68. $sql = "SELECT * FROM `events` WHERE `time` < ".$time->getTimestamp()." ORDER BY `time` ASC";
  69. return $db->fetchAll($db->query($sql));
  70. }
  71. public static function publicEventListHome($limit) {
  72. $db = new DBClass();
  73. $time = new DateTime();
  74. $sql = "SELECT * FROM `events` WHERE `time` > ".$time->getTimestamp()." ORDER BY `time` ASC LIMIT $limit";
  75. return $db->fetchAll($db->query($sql));
  76. }
  77. public static function EventTrackList($limit) {
  78. $db = new DBClass();
  79. $sql = "SELECT * FROM `events` WHERE `type` = '2' ORDER BY `time` ASC LIMIT $limit";
  80. return $db->fetchAll($db->query($sql));
  81. }
  82. /* Attend functions */
  83. public static function attentEventList() {
  84. // Get list of events that havent already started
  85. $db = new DBClass();
  86. $time = new DateTime();
  87. $sql = "SELECT * FROM `events` WHERE `time` > ".$time->getTimestamp()." AND `type` = 1 ORDER BY `time` ASC";
  88. return $db->fetchAll($db->query($sql));
  89. }
  90. public static function attentDouble($user,$event) {
  91. // Checks if username already is in db, if not return false, if it exists return true
  92. $db = new DBClass();
  93. $sql = "SELECT * FROM `attendees` WHERE `userid` = $user AND `eventid` = $event";
  94. if ($db->numRows($db->query($sql)) != 1) { return false; } else { return true; }
  95. }
  96. public static function attendees($event) {
  97. // Checks if username already is in db, if not return false, if it exists return true
  98. $db = new DBClass();
  99. $sql = "SELECT * FROM `attendees` WHERE `eventid` = $event";
  100. return $db->numRows($db->query($sql));
  101. }
  102. /* Login and user functions */
  103. public static function checkExists($name) {
  104. // Checks if username already is in db, if not return false, if it exists return true
  105. $db = new DBClass();
  106. $sql = "SELECT * FROM `" . Config::$db_tableusers . "` WHERE `username` = '$name'";
  107. if ($db->numRows($db->query($sql)) != 1) { return false; } else { return true; }
  108. }
  109. /* File/Upload functions */
  110. public static function getImages($limit) {
  111. // Returns all images in database.
  112. $db = new DBClass();
  113. $sql = "SELECT * FROM `uploads` WHERE `mime` LIKE 'image%'";
  114. return $db->fetchAll($db->query($sql));
  115. }
  116. }