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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. public static function addUser($username, $password, $realname, $mail, $level) {
  61. if (Get::checkExists($username)) { // check if user exists
  62. // ERROR USER EXISTS
  63. return false;
  64. } elseif (strlen($username) < 3) {
  65. return false;
  66. } elseif (strlen($password) < 5) {
  67. return false;
  68. } elseif (strlen($realname) < 5) {
  69. return false;
  70. } elseif (strlen($mail) < 5) {
  71. return false;
  72. } else {
  73. // Now we know everything contains something.
  74. // Time to sanitize!
  75. $username = filter_var($username, FILTER_SANITIZE_STRING);
  76. $realname = filter_var($realname, FILTER_SANITIZE_STRING);
  77. $mail = filter_var($mail, FILTER_SANITIZE_EMAIL);
  78. // Gr8, we are sanitized. We dont sanitize password, as we hash it anyway using argon2
  79. $db = new DBClass();
  80. $sql = "INSERT INTO `users` (`id`, `realname`, `username`, `password`, `email`, `level`) VALUES (NULL, '$realname', '$username', '" . User::hashPass($password) . "', '$mail', '$level');";
  81. return $db->query($sql);
  82. }
  83. }
  84. public static function insertImage($filename, $mime) {
  85. $db = new DBClass();
  86. $time = new DateTime();
  87. $sql = "INSERT INTO `uploads` (`id`, `filename`, `date`, `user`, `mime`) VALUES (NULL, '$filename', '" . $time->getTimestamp() . "', '" . $_SESSION['user'] . "', '" . $mime . "');";
  88. $db->query($sql);
  89. }
  90. }