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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /*
  3. * Alters information in the database. We use this for signup, administration and more.
  4. */
  5. class Alter {
  6. private function __construct() {
  7. }
  8. public static function addNews($author, $title, $content, $image, $type) {
  9. $db = new DBClass();
  10. $time = new DateTime();
  11. // Sanitize number
  12. $type = filter_var(trim($type), FILTER_SANITIZE_NUMBER_INT);
  13. $sql = "INSERT INTO `news` (`id`, `author`, `time`, `title`, `type`, `content`, `img`) VALUES (NULL, '$author', '" . $time->getTimestamp() . "', '$title', '$type', '$content', '$image');";
  14. $db->query($sql);
  15. header('Location: ' . Config::$sys_url . '?page=newsadmin');
  16. die("Error, please enable browser-redirects.");
  17. }
  18. public static function editNews($id, $title, $content, $image, $type) {
  19. $db = new DBClass();
  20. // Sanitize number
  21. $type = filter_var(trim($type), FILTER_SANITIZE_NUMBER_INT);
  22. if ($image != false) {
  23. $sql = "UPDATE `news` SET `title` = '$title', `img` = '$image', `content` = '$content', `type` = '$type' WHERE `news`.`id` = $id;";
  24. } else {
  25. $sql = "UPDATE `news` SET `title` = '$title', `content` = '$content', `type` = '$type' WHERE `news`.`id` = $id;";
  26. }
  27. $db->query($sql);
  28. header('Location: ' . Config::$sys_url . '?page=newsadmin');
  29. die("Error, please enable browser redirects.");
  30. }
  31. public static function deleteNews($id) {
  32. $db = new DBClass();
  33. $sql = "DELETE FROM `news` WHERE `news`.`id` = $id";
  34. $db->query($sql);
  35. header('Location: ' . Config::$sys_url . '?page=newsadmin');
  36. die("Error, please enable browser redirects.");
  37. }
  38. /* Event functions */
  39. public static function addEvent($title, $content, $type, $eventdate, $image) {
  40. $db = new DBClass();
  41. $sql = "INSERT INTO `events` (`id`, `title`, `img`, `type`, `description`, `time`) VALUES (NULL, '$title', '$image', '$type', '$content', '" . strtotime($eventdate) . "');";
  42. $db->query($sql);
  43. header('Location: ' . Config::$sys_url . '?page=eventadmin');
  44. die("Error, please enable browser-redirects.");
  45. }
  46. public static function editEvent($id, $title, $content, $type, $eventdate, $image) {
  47. $db = new DBClass();
  48. if ($image != false) {
  49. $sql = "UPDATE `events` SET `title` = '$title', `img` = '$image', `type` = '$type', `time` = '" . strtotime($eventdate) . "', `description` = '$content' WHERE `events`.`id` = $id;";
  50. } else {
  51. $sql = "UPDATE `events` SET `title` = '$title', `type` = '$type', `time` = '" . strtotime($eventdate) . "', `description` = '$content' WHERE `events`.`id` = $id;";
  52. }
  53. $db->query($sql);
  54. header('Location: ' . Config::$sys_url . '?page=eventadmin');
  55. die("Error, please enable browser redirects.");
  56. }
  57. public static function deleteEvent($id) {
  58. $db = new DBClass();
  59. $sql = "DELETE FROM `events` WHERE `events`.`id` = $id";
  60. $db->query($sql);
  61. header('Location: ' . Config::$sys_url . '?page=eventadmin');
  62. die("Error, please enable browser redirects.");
  63. }
  64. /* Attendee functions */
  65. public static function attentAdd($user, $event) {
  66. // Add user to an event. And sanitize as we only want numbers.
  67. $event = filter_var(trim($event), FILTER_SANITIZE_NUMBER_INT);
  68. if (Get::attentDouble($user, $event) != true) {
  69. $db = new DBClass();
  70. $time = new DateTime();
  71. $sql = "INSERT INTO `attendees` (`id`, `eventid`, `userid`, `time`) VALUES (NULL, '$event', '$user', '" . $time->getTimestamp() . "');";
  72. return $db->query($sql);
  73. }
  74. header('Location: ' . Config::$sys_url . '?page=order&error=1');
  75. die("Error, please enable browser redirects.");
  76. }
  77. public static function attentDel($user, $event) {
  78. // Add user to an event. And sanitize as we only want numbers.
  79. $event = filter_var(trim($event), FILTER_SANITIZE_NUMBER_INT);
  80. if (Get::attentDouble($user, $event) != false) {
  81. $db = new DBClass();
  82. $sql = "DELETE FROM `attendees` WHERE `attendees`.`userid` = $user AND `eventid` = $event";
  83. return $db->query($sql);
  84. }
  85. header('Location: ' . Config::$sys_url . '?page=order&error=2');
  86. die("Error, please enable browser redirects.");
  87. }
  88. /* User functions */
  89. public static function addUser($username, $password, $realname, $mail, $level) {
  90. if (Get::checkExists($username)) { // check if user exists
  91. // ERROR USER EXISTS
  92. return false;
  93. } elseif (strlen($username) < 3) {
  94. return false;
  95. } elseif (strlen($password) < 5) {
  96. return false;
  97. } elseif (strlen($realname) < 5) {
  98. return false;
  99. } elseif (strlen($mail) < 5) {
  100. return false;
  101. } else {
  102. // Now we know everything contains something.
  103. // Time to sanitize!
  104. $username = filter_var($username, FILTER_SANITIZE_STRING);
  105. $realname = filter_var($realname, FILTER_SANITIZE_STRING);
  106. $mail = filter_var($mail, FILTER_SANITIZE_EMAIL);
  107. // Gr8, we are sanitized. We dont sanitize password, as we hash it anyway using argon2
  108. $db = new DBClass();
  109. $sql = "INSERT INTO `users` (`id`, `realname`, `username`, `password`, `email`, `level`) VALUES (NULL, '$realname', '$username', '" . User::hashPass($password) . "', '$mail', '$level');";
  110. return $db->query($sql);
  111. }
  112. }
  113. public static function insertImage($filename, $mime) {
  114. $db = new DBClass();
  115. $time = new DateTime();
  116. $sql = "INSERT INTO `uploads` (`id`, `filename`, `date`, `user`, `mime`) VALUES (NULL, '$filename', '" . $time->getTimestamp() . "', '" . $_SESSION['user'] . "', '" . $mime . "');";
  117. $db->query($sql);
  118. }
  119. }