"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

alter.class.php 5.8KB

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