Oppaitime'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.8KB

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