BioTorrents.de’s version of Gazelle
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.

calendar.class.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. class Calendar
  3. {
  4. public static $Categories = array(1 => "IRC Meeting", "IRC Brainstorm", "Poll Deadline", "Feature Release", "Blog Post", "Announcement", "Featured Album", "Product Release", "Staff Picks", "Forum Brainstorm", "Forum Discussion", "Promotion", "Absence", "Task");
  5. public static $Importances = array(1 => "Critical", "Important", "Average", "Meh");
  6. public static $Colors = array(
  7. "Critical" => "red",
  8. "Important" => "yellow",
  9. "Average" => "green",
  10. "Meh" => "blue"
  11. );
  12. public static $Teams = array(
  13. 0 => "Everyone",
  14. 1 => "Staff"
  15. );
  16. public static function can_view()
  17. {
  18. return check_perms('users_mod');
  19. }
  20. private static function get_teams_query()
  21. {
  22. $Teams = array(0);
  23. $IsMod = check_perms("users_mod");
  24. if ($IsMod) {
  25. $Teams[] = 1;
  26. }
  27. return "Team IN (" . implode(",", $Teams) . ") ";
  28. }
  29. public static function get_events($Month, $Year)
  30. {
  31. if (empty($Month) || empty($Year)) {
  32. $Date = getdate();
  33. $Month = $Date['mon'];
  34. $Year = $Date['year'];
  35. }
  36. $Month = (int)$Month;
  37. $Year = (int)$Year;
  38. $TeamsSQL = self::get_teams_query();
  39. $QueryID = G::$DB->get_query_id();
  40. G::$DB->query("
  41. SELECT
  42. ID, Team, Title, Category, Importance, DAY(StartDate) AS StartDay, DAY(EndDate) AS EndDay
  43. FROM calendar
  44. WHERE
  45. MONTH(StartDate) = '$Month'
  46. AND
  47. YEAR(StartDate) = '$Year'
  48. AND
  49. $TeamsSQL");
  50. $Events = G::$DB->to_array();
  51. G::$DB->set_query_id($QueryID);
  52. return $Events;
  53. }
  54. public static function get_event($ID)
  55. {
  56. $ID = (int)$ID;
  57. if (empty($ID)) {
  58. error("Invalid ID");
  59. }
  60. $TeamsSQL = self::get_teams_query();
  61. $QueryID = G::$DB->get_query_id();
  62. G::$DB->query("
  63. SELECT
  64. ID, Team, Title, Body, Category, Importance, AddedBy, StartDate, EndDate
  65. FROM calendar
  66. WHERE
  67. ID = '$ID'
  68. AND
  69. $TeamsSQL");
  70. $Event = G::$DB->next_record(MYSQLI_ASSOC);
  71. G::$DB->set_query_id($QueryID);
  72. return $Event;
  73. }
  74. public static function create_event($Title, $Body, $Category, $Importance, $Team, $UserID, $StartDate, $EndDate = null)
  75. {
  76. if (empty($Title) || empty($Body) || !is_number($Category) || !is_number($Importance) || !is_number($Team) || empty($StartDate)) {
  77. error("Error adding event");
  78. }
  79. $Title = db_string($Title);
  80. $Body = db_string($Body);
  81. $Category = (int)$Category;
  82. $Importance = (int)$Importance;
  83. $UserID = (int)$UserID;
  84. $Team = (int)$Team;
  85. $StartDate = db_string($StartDate);
  86. $EndDate = db_string($EndDate);
  87. $QueryID = G::$DB->get_query_id();
  88. G::$DB->query("
  89. INSERT INTO calendar
  90. (Title, Body, Category, Importance, Team, StartDate, EndDate, AddedBy)
  91. VALUES
  92. ('$Title', '$Body', '$Category', '$Importance', '$Team', '$StartDate', '$EndDate', '$UserID')");
  93. G::$DB->set_query_id($QueryID);
  94. send_irc("PRIVMSG " . ADMIN_CHAN . " :!mod New calendar event created! Event: $Title; Starts: $StartDate; Ends: $EndDate.");
  95. }
  96. public static function update_event($ID, $Title, $Body, $Category, $Importance, $Team, $StartDate, $EndDate = null)
  97. {
  98. if (!is_number($ID) || empty($Title) || empty($Body) || !is_number($Category) || !is_number($Importance) || !is_number($Team) || empty($StartDate)) {
  99. error("Error updating event");
  100. }
  101. $ID = (int)$ID;
  102. $Title = db_string($Title);
  103. $Body = db_string($Body);
  104. $Category = (int)$Category;
  105. $Importance = (int)$Importance;
  106. $Team = (int)$Team;
  107. $StartDate = db_string($StartDate);
  108. $EndDate = db_string($EndDate);
  109. $QueryID = G::$DB->get_query_id();
  110. G::$DB->query("
  111. UPDATE calendar
  112. SET
  113. Title = '$Title',
  114. Body = '$Body',
  115. Category = '$Category',
  116. Importance = '$Importance',
  117. Team = '$Team',
  118. StartDate = '$StartDate',
  119. EndDate = '$EndDate'
  120. WHERE
  121. ID = '$ID'");
  122. G::$DB->set_query_id($QueryID);
  123. }
  124. public static function remove_event($ID)
  125. {
  126. $ID = (int)$ID;
  127. if (!empty($ID)) {
  128. $QueryID = G::$DB->get_query_id();
  129. G::$DB->query("DELETE FROM calendar WHERE ID = '$ID'");
  130. G::$DB->set_query_id($QueryID);
  131. }
  132. }
  133. }