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.

calendarview.class.php 3.6KB

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