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.

calendarview.class.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. class CalendarView
  3. {
  4. private static $Days = array('S', 'M', 'T', 'W', 'T', 'F', 'S');
  5. private static $Headings = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
  6. private static $Events;
  7. public static function render_title($Month, $Year)
  8. {
  9. if (!is_numeric($Month) || !is_numeric($Year)) {
  10. error(404);
  11. }
  12. $NextMonth = $Month % 12 == 0 ? 1 : $Month + 1;
  13. $PreviousMonth = $Month == 1 ? 12 : $Month - 1;
  14. $NextYear = $Year;
  15. if ($NextMonth == 1) {
  16. $NextYear++;
  17. }
  18. $PreviousYear = $Year;
  19. if ($PreviousMonth == 12) {
  20. $PreviousYear--;
  21. } ?>
  22. <h1 class="center">
  23. <a href="tools.php?action=calendar&amp;month=<?=$PreviousMonth?>&amp;year=<?=$PreviousYear?>">&lt;</a>
  24. <?=date("F", mktime(0, 0, 0, $Month, 10)) . " $Year"?>
  25. <a href="tools.php?action=calendar&amp;month=<?=$NextMonth?>&amp;year=<?=$NextYear?>">&gt;</a>
  26. </h1>
  27. <input type="hidden" id="month" value="<?=$Month?>" />
  28. <input type="hidden" id="year" value="<?=$Year?>" />
  29. <?php
  30. }
  31. private static function get_events_on($Day, $Events)
  32. {
  33. // Linear search, Lol.
  34. $Results = [];
  35. foreach ($Events as $Event) {
  36. if ($Event['StartDay'] == $Day || ($Event['StartDay'] <= $Day && $Event['EndDay'] >= $Day)) {
  37. $Results[] = $Event;
  38. }
  39. }
  40. return $Results;
  41. }
  42. private static function render_events_day($Day, $Events)
  43. {
  44. $Events = self::get_events_on($Day, $Events);
  45. foreach ($Events as $Event) {
  46. $Color = Calendar::$Colors[Calendar::$Importances[$Event['Importance']]];
  47. $Category = Calendar::$Categories[$Event['Category']];
  48. $Tooltip = $Event['Title'] . " - " . Calendar::$Categories[$Event['Category']] . " - " . Calendar::$Importances[$Event['Importance']]; ?>
  49. <p><a href="#" class="event_day tooltip" title="<?=$Tooltip?>" data-gazelle-id="<?=$Event['ID']?>" style="color: <?=$Color?>;"><?=Format::cut_string($Event['Title'], 8, true)?></a></p>
  50. <?php
  51. }
  52. }
  53. public static function render_calendar($Month, $Year, $Events)
  54. {
  55. $RunningDay = date('w', mktime(0, 0, 0, $Month, 1, $Year));
  56. $DaysInMonth = date('t', mktime(0, 0, 0, $Month, 1, $Year));
  57. $DaysThisWeek = 1;
  58. $DayCounter = 0;
  59. $DatesArray = []; ?>
  60. <table class="calendar">
  61. <tr>
  62. <?php foreach (self::$Headings as $Heading) { ?>
  63. <td class="calendar-row calendar-heading">
  64. <strong><?=$Heading?></strong>
  65. </td>
  66. <?php } ?>
  67. </tr>
  68. <tr class="calendar-row">
  69. <?php for ($x = 0; $x < $RunningDay; $x++) { ?>
  70. <td class="calendar-day-np"></td>
  71. <?php
  72. $DaysThisWeek++;
  73. }
  74. for ($i = 1; $i <= $DaysInMonth; $i++) {
  75. ?>
  76. <td class="calendar-day">
  77. <div class="day-events">
  78. <?php self::render_events_day($i, $Events); ?>
  79. </div>
  80. <div class="day-number">
  81. <?=$i?>
  82. </div>
  83. </td>
  84. <?php if ($RunningDay == 6) { ?>
  85. </tr>
  86. <?php if (($DayCounter + 1) != $DaysInMonth) { ?>
  87. <tr class="calendar-row">
  88. <?php
  89. }
  90. $RunningDay = -1;
  91. $DaysThisWeek = 0;
  92. }
  93. $DaysThisWeek++;
  94. $RunningDay++;
  95. $DayCounter++;
  96. }
  97. if ($DaysThisWeek < 8) {
  98. for ($x = 1; $x <= (8 - $DaysThisWeek); $x++) {
  99. ?>
  100. <td class="calendar-day-np"></td>
  101. <?php
  102. }
  103. } ?>
  104. </tr>
  105. </table>
  106. <?php
  107. echo $Calendar;
  108. }
  109. }