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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, $image) {
  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, $image) {
  39. $db = new DBClass();
  40. if ($image != false) {
  41. $sql = "UPDATE `events` SET `title` = '$title', `img` = '$image', `type` = '$type', `time` = '" . strtotime($eventdate) . "', `description` = '$content' WHERE `events`.`id` = $id;";
  42. } else {
  43. $sql = "UPDATE `events` SET `title` = '$title', `type` = '$type', `time` = '" . strtotime($eventdate) . "', `description` = '$content' WHERE `events`.`id` = $id;";
  44. }
  45. $db->query($sql);
  46. header('Location: ' . Config::$sys_url . '?page=eventadmin');
  47. die("Error, please enable browser redirects.");
  48. }
  49. public static function deleteEvent($id) {
  50. $db = new DBClass();
  51. $sql = "DELETE FROM `events` WHERE `events`.`id` = $id";
  52. $db->query($sql);
  53. header('Location: ' . Config::$sys_url . '?page=eventadmin');
  54. die("Error, please enable browser redirects.");
  55. }
  56. public static function addUser($username, $password, $realname, $mail, $level) {
  57. if (Get::checkExists($username)) { // check if user exists
  58. // ERROR USER EXISTS
  59. return false;
  60. } elseif (strlen($username) < 3) {
  61. return false;
  62. } elseif (strlen($password) < 5) {
  63. return false;
  64. } elseif (strlen($realname) < 5) {
  65. return false;
  66. } elseif (strlen($mail) < 5) {
  67. return false;
  68. } else {
  69. // Now we know everything contains something.
  70. // Time to sanitize!
  71. $username = filter_var($username, FILTER_SANITIZE_STRING);
  72. $realname = filter_var($realname, FILTER_SANITIZE_STRING);
  73. $mail = filter_var($mail, FILTER_SANITIZE_EMAIL);
  74. // Gr8, we are sanitized. We dont sanitize password, as we hash it anyway using argon2
  75. $db = new DBClass();
  76. $sql = "INSERT INTO `users` (`id`, `realname`, `username`, `password`, `email`, `level`) VALUES (NULL, '$realname', '$username', '" . User::hashPass($password) . "', '$mail', '$level');";
  77. return $db->query($sql);
  78. }
  79. }
  80. public static function insertImage($filename, $mime) {
  81. $db = new DBClass();
  82. $time = new DateTime();
  83. $sql = "INSERT INTO `uploads` (`id`, `filename`, `date`, `user`, `mime`) VALUES (NULL, '$filename', '" . $time->getTimestamp() . "', '" . $_SESSION['user'] . "', '" . $mime . "');";
  84. $db->query($sql);
  85. }
  86. }