Gazelle/classes/calendarview.class.php

117 lines
3.0 KiB
PHP
Raw Normal View History

2013-08-28 23:08:41 +00:00
<?
class CalendarView {
2013-10-13 08:01:01 +00:00
private static $Days = array('S', 'M', 'T', 'W', 'T', 'F', 'S');
private static $Headings = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
2013-08-28 23:08:41 +00:00
private static $Events;
public static function render_title($Month, $Year) {
$NextMonth = $Month % 12 == 0 ? 1 : $Month + 1;
$PreviousMonth = $Month == 1 ? 12 : $Month - 1;
$NextYear = $Year;
if ($NextMonth == 1) {
$NextYear++;
}
$PreviousYear = $Year;
if ($PreviousMonth == 12) {
$PreviousYear--;
}
?>
<h1 class="center">
2013-10-13 08:01:01 +00:00
<a href="tools.php?action=calendar&amp;month=<?=$PreviousMonth?>&amp;year=<?=$PreviousYear?>">&lt;</a>
<?=date("F", mktime(0, 0, 0, $Month, 10)) . " $Year"?>
<a href="tools.php?action=calendar&amp;month=<?=$NextMonth?>&amp;year=<?=$NextYear?>">&gt;</a>
2013-08-28 23:08:41 +00:00
</h1>
2013-10-13 08:01:01 +00:00
<input type="hidden" id="month" value="<?=$Month?>" />
<input type="hidden" id="year" value="<?=$Year?>" />
<?
}
2013-08-28 23:08:41 +00:00
private static function get_events_on($Day, $Events) {
// Linear search, Lol.
$Results = array();
2013-09-20 08:00:56 +00:00
foreach ($Events as $Event) {
2013-08-28 23:08:41 +00:00
if ($Event['StartDay'] == $Day || ($Event['StartDay'] <= $Day && $Event['EndDay'] >= $Day)) {
$Results[] = $Event;
}
}
return $Results;
}
private static function render_events_day($Day, $Events) {
$Events = self::get_events_on($Day, $Events);
foreach ($Events as $Event) {
$Color = Calendar::$Colors[Calendar::$Importances[$Event['Importance']]];
$Category = Calendar::$Categories[$Event['Category']];
$Tooltip = $Event['Title'] . " - " . Calendar::$Categories[$Event['Category']] . " - " . Calendar::$Importances[$Event['Importance']];
?>
<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>
2013-10-13 08:01:01 +00:00
<?
}
2013-08-28 23:08:41 +00:00
}
public static function render_calendar($Month, $Year, $Events) {
$RunningDay = date('w',mktime(0, 0, 0, $Month, 1, $Year));
$DaysInMonth = date('t',mktime(0 ,0 ,0, $Month, 1, $Year));
$DaysThisWeek = 1;
$DayCounter = 0;
$DatesArray = array();
?>
<table class="calendar">
2013-10-13 08:01:01 +00:00
<tr>
<? foreach (self::$Headings as $Heading) { ?>
2013-08-28 23:08:41 +00:00
<td class="calendar-row calendar-heading">
<strong><?=$Heading?></strong>
</td>
2013-10-13 08:01:01 +00:00
<? } ?>
</tr>
2013-08-28 23:08:41 +00:00
<tr class="calendar-row">
2013-10-13 08:01:01 +00:00
<? for ($x = 0; $x < $RunningDay; $x++) { ?>
2013-08-28 23:08:41 +00:00
<td class="calendar-day-np"></td>
2013-10-13 08:01:01 +00:00
<?
$DaysThisWeek++;
}
2013-08-28 23:08:41 +00:00
2013-10-13 08:01:01 +00:00
for ($i = 1; $i <= $DaysInMonth; $i++) {
?>
2013-08-28 23:08:41 +00:00
<td class="calendar-day">
<div class="day-events">
<? self::render_events_day($i, $Events); ?>
</div>
<div class="day-number">
<?=$i?>
</div>
</td>
2013-10-13 08:01:01 +00:00
<? if ($RunningDay == 6) { ?>
</tr>
<? if (($DayCounter + 1) != $DaysInMonth) { ?>
<tr class="calendar-row">
<?
2013-08-28 23:08:41 +00:00
}
2013-10-13 08:01:01 +00:00
$RunningDay = -1;
$DaysThisWeek = 0;
2013-08-28 23:08:41 +00:00
}
2013-10-13 08:01:01 +00:00
$DaysThisWeek++;
$RunningDay++;
$DayCounter++;
}
2013-08-28 23:08:41 +00:00
2013-10-13 08:01:01 +00:00
if ($DaysThisWeek < 8) {
for ($x = 1; $x <= (8 - $DaysThisWeek); $x++) {
?>
<td class="calendar-day-np"></td>
<?
2013-08-28 23:08:41 +00:00
}
2013-10-13 08:01:01 +00:00
}
2013-08-28 23:08:41 +00:00
?>
</tr>
2013-10-13 08:01:01 +00:00
</table>
2013-08-28 23:08:41 +00:00
<?
2013-10-13 08:01:01 +00:00
echo $Calendar;
}
2013-08-28 23:08:41 +00:00
}