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

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