"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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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) {
  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', '');";
  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) {
  17. $db = new DBClass();
  18. $sql = "UPDATE `news` SET `title` = '$title', `content` = '$content' WHERE `news`.`id` = $id;";
  19. $db->query($sql);
  20. header('Location: ' . Config::$sys_url . '?page=newsadmin');
  21. die("Error, please enable browser redirects.");
  22. }
  23. public static function deleteNews($id) {
  24. $db = new DBClass();
  25. $sql = "DELETE FROM `news` WHERE `news`.`id` = $id";
  26. $db->query($sql);
  27. header('Location: ' . Config::$sys_url . '?page=newsadmin');
  28. die("Error, please enable browser redirects.");
  29. }
  30. /* Event functions */
  31. public static function addEvent($title, $content, $type, $eventdate) {
  32. $db = new DBClass();
  33. $sql = "INSERT INTO `events` (`id`, `title`, `img`, `type`, `description`, `time`) VALUES (NULL, '$title', 'image', '$type', '$content', '" . strtotime($eventdate) . "');";
  34. $db->query($sql);
  35. header('Location: ' . Config::$sys_url . '?page=eventadmin');
  36. die("Error, please enable browser-redirects.");
  37. }
  38. public static function editEvent($id, $title, $content, $type, $eventdate) {
  39. $db = new DBClass();
  40. $sql = "UPDATE `events` SET `title` = '$title', `img` = 'images', `type` = '$type', `time` = '" . strtotime($eventdate) . "', `description` = '$content' WHERE `events`.`id` = $id;";
  41. $db->query($sql);
  42. header('Location: ' . Config::$sys_url . '?page=eventadmin');
  43. die("Error, please enable browser redirects.");
  44. }
  45. public static function deleteEvent($id) {
  46. $db = new DBClass();
  47. $sql = "DELETE FROM `events` WHERE `events`.`id` = $id";
  48. $db->query($sql);
  49. header('Location: ' . Config::$sys_url . '?page=eventadmin');
  50. die("Error, please enable browser redirects.");
  51. }
  52. public static function addUser($username, $password, $realname, $mail, $level) {
  53. if (Get::checkExists($username)) { // check if user exists
  54. // ERROR USER EXISTS
  55. die();
  56. }
  57. // lets check the variables
  58. if (strlen($username) < 3) { die(); }
  59. elseif (strlen($password) < 5) { die(); }
  60. elseif (strlen($realname) < 5) { die(); }
  61. elseif (strlen($mail) < 5) { die(); }
  62. // Now we know everything contains something.
  63. // Time to sanitize!
  64. $username = filter_var($username, FILTER_SANITIZE_STRING);
  65. $realname = filter_var($realname, FILTER_SANITIZE_STRING);
  66. $mail = filter_var($mail, FILTER_SANITIZE_EMAIL);
  67. // Gr8, we are sanitized. We dont sanitize password, as we hash it anyway using argon2
  68. $db = new DBClass();
  69. $sql = "INSERT INTO `users` (`id`, `realname`, `username`, `password`, `email`, `level`) VALUES (NULL, '$realname', '$username', '" . User::hashPass($password) . "', '$mail', '$level');";
  70. return $db->query($sql);
  71. }
  72. }