PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/GroupCalendar4.5/inc/helper_functions.php

http://wowroster-addons.googlecode.com/
PHP | 153 lines | 113 code | 19 blank | 21 comment | 32 complexity | 5c6681e8a1bef9b2d1ef0e31198e42c2 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Calendar Helper Functions //
  4. ////////////////////////////////////////////////////////////////////////////////
  5. // This file can be included anywhere on your website to draw out information
  6. // from your calendar database.
  7. ////////////////////////////////////////////////////////////////////////////////
  8. if (!isset($gc_database)) include_once("database_info.php");
  9. if (!isset($gc_lang)) include_once("language.php");
  10. ///////////////////////////////////////////////////////////
  11. // Nice Helper functions
  12. ///////////////////////////////////////////////////////////
  13. function Race($code){
  14. global $gc_lang;
  15. return $gc_lang['Race'][$code];
  16. }
  17. function ClassInt($code){
  18. global $gc_lang;
  19. return $gc_lang['Class'][$code];
  20. }
  21. function debug_output($txt) {
  22. global $htmlout;
  23. if ($htmlout) {
  24. $txt = str_replace(" ","&nbsp;",$txt);
  25. $txt = str_replace("\n","<br>\n",$txt);
  26. }
  27. print $txt;
  28. }
  29. function getGCtext($type) {
  30. global $gc_lang;
  31. if (array_key_exists($type,$gc_lang['gcType'])) return $gc_lang['gcType'][$type];
  32. else if ($type != "") return $gc_lang['gcType']['OTHER'] . " ($type)";
  33. else return $gc_lang['gcType']['OTHER'];
  34. }
  35. function getGCimage($type,$path) {
  36. global $roster, $addon;
  37. $base_path = "./";
  38. $filename = $base_path . $path . "Icon-" . $type . ".png";
  39. if (file_exists($filename)) return $path ."Icon-". $type . ".png";
  40. else return $path . "Icon-Unknown.png";
  41. }
  42. function reset_event_names() {
  43. // Items with this Event Type will be ignored, regardless of the "Private" flag
  44. $val = array();
  45. $val[] = "RSAQR";
  46. $val[] = "RSMoon";
  47. $val[] = "RSZG";
  48. $val[] = "RSMC";
  49. $val[] = "RSAQT";
  50. $val[] = "RSSalt";
  51. $val[] = "RSOny";
  52. $val[] = "RSBWL";
  53. $val[] = "RSNaxx";
  54. $val[] = "RSXmut";
  55. $val[] = "RSSnow";
  56. $val[] = "Doctor";
  57. $val[] = "Dentist";
  58. return $val;
  59. }
  60. ///////////////////////////////////////////////////////////
  61. // END Nice Helper functions section
  62. ///////////////////////////////////////////////////////////
  63. ////////////////////////////////////////////////////
  64. // function getUpcomingEvents()
  65. // Returns an array of upcoming events that are not birthdays or resets
  66. // The array will be sorted where the soonest event will be at [0]
  67. function getUpcomingEvents()
  68. {
  69. $right_now = gmdate("Y-m-d H:i:s");
  70. global $gc_database, $roster;
  71. global $gc_user;
  72. global $debuging_flag;
  73. $skipme = reset_event_names();
  74. //Check to see if user specified timezone exists, if not use default
  75. if (!isset($gc_user['user_timezone'])) $gc_user['user_timezone'] = CURR_TIME_OFFSET;
  76. $t_offset = $gc_user['user_timezone'] * 3600;
  77. //////////////////////////////////////////////////////////////////////
  78. // Get Group Calendar Events
  79. //////////////////////////////////////////////////////////////////////
  80. $sql = "SELECT `id`, `title`, `start` AS `start_time`, DATE_ADD(`start`, INTERVAL `duration` MINUTE) AS `end_time`, `type`, `duration`, `description`, `guildonly`, ";
  81. $sql .= "TIME_FORMAT(DATE_ADD(`start`, INTERVAL $t_offset SECOND), '%l:%i%p') AS stime12, ";
  82. $sql .= "TIME_FORMAT(DATE_ADD(DATE_ADD(`start`, INTERVAL $t_offset SECOND), INTERVAL `duration` MINUTE), '%l:%i%p') AS etime12, ";
  83. $sql .= "TIME_FORMAT(DATE_ADD(`start`, INTERVAL $t_offset SECOND), '%H:%i') AS stime24, ";
  84. $sql .= "TIME_FORMAT(DATE_ADD(DATE_ADD(`start`, INTERVAL $t_offset SECOND), INTERVAL `duration` MINUTE), '%H:%i') AS etime24, ";
  85. $sql .= "TIME_FORMAT(start, '%H:%i:%s') AS s_time, ";
  86. $sql .= "TIME_FORMAT(DATE_ADD(`start`, INTERVAL `duration` MINUTE), '%H:%i:%s') AS e_time, ";
  87. $sql .= "DAYOFMONTH(DATE_ADD(`start`, INTERVAL $t_offset SECOND)) AS d, MONTH(DATE_ADD(`start`, INTERVAL $t_offset SECOND)) AS m, YEAR(DATE_ADD(`start`, INTERVAL $t_offset SECOND)) AS y ";
  88. $sql .= "FROM ". CALENDAR_TABLE ." WHERE (`start` > '$right_now' OR DATE_ADD(`start`, INTERVAL `duration` MINUTE) > '$right_now') AND `type` != 'Birth' ORDER BY `start` ASC";
  89. $result = $roster->db->query($sql);// $result = mysql_query($sql,$gc_database['connection']);
  90. if ($result == false && $debuging_flag) print("Error in SQL statement in getUpcomingEvents() function.<br />\nmySQL error: ". mysql_error() ."<br />\nFull SQL string: $sql<br />\n");
  91. $newEvents = array();
  92. while($row = mysql_fetch_array($result)) {
  93. if (in_array($row["type"],$skipme)) continue;
  94. $event = array();
  95. $event['title'] = stripslashes($row["title"]);
  96. if ($event['title']=="") $event['title'] = getGCtext($row['type']);
  97. if (defined("TIME_DISPLAY_FORMAT") && TIME_DISPLAY_FORMAT == "12hr") {
  98. $stime = $row["stime12"];
  99. $etime = $row["etime12"];
  100. } else {
  101. $stime = $row["stime24"];
  102. $etime = $row["etime24"];
  103. }
  104. if (!($row["s_time"] == "00:00:25" && $row["e_time"] == "00:00:25")) {
  105. if ($row["s_time"] == "00:00:25")
  106. $starttime = "- -";
  107. else
  108. $starttime = $stime;
  109. if ($row["e_time"] == "00:00:25" || $row["e_time"] == $row["s_time"])
  110. $endtime = "";
  111. else
  112. $endtime = " - ".$etime;
  113. $timestr = "($starttime$endtime)&nbsp;";
  114. } else {
  115. $timestr = "<br>";
  116. }
  117. $event["id"] = $row["id"];
  118. $event["timestr"] = $timestr;
  119. $event["type"] = $row["type"];
  120. $event["start12"] = $row["stime12"];
  121. $event["end12"] = $row["etime12"];
  122. $event["start24"] = $row["stime24"];
  123. $event["end24"] = $row["etime24"];
  124. $event["duration"] = $row["duration"];
  125. $event["description"] = $row["description"];
  126. $event["guildonly"] = $row["guildonly"];
  127. $event["mday"] = $row["d"];
  128. $event["mon"] = $row["m"];
  129. $event["year"] = $row["y"];
  130. $event["datestr"] = date("l M j", mktime(12,1,1,$row["m"],$row["d"],$row["y"]));
  131. $newEvents[] = $event;
  132. }
  133. return $newEvents;
  134. }