"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.

alter.class.php 5.7KB

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