-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_month_body.inc.php
209 lines (198 loc) · 7.9 KB
/
main_month_body.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
if (!defined('ALLOWINCLUDES')) { exit; } // prohibits direct calling of include files
$ievent = 0;
// read events from the DB
$query = "
SELECT
e.id AS eventid,
e.timebegin,
e.timeend,
e.sponsorid,
e.title,
e.wholedayevent,
e.categoryid,
c.id,
c.name AS category_name
FROM
" . SCHEMANAME . "vtcal_event_public e,
" . SCHEMANAME . "vtcal_category c
WHERE
e.calendarid='" . sqlescape($_SESSION['CALENDAR_ID']) . "'
AND
c.calendarid='" . sqlescape($_SESSION['CALENDAR_ID']) . "'
AND
e.categoryid=c.id
AND
e.timebegin >= '" . sqlescape($monthstart['timestamp']) . "'
AND
e.timeend <= '" . sqlescape($monthend['timestamp']) . "'
";
// Filter by sponsor if necessary
if ($sponsorid != 'all') { $query .= " AND e.sponsorid='" . sqlescape($sponsorid) . "'"; }
// Filter by category filters if necessary
if (isset($CategoryFilter) && count($CategoryFilter) > 0) {
$query .= " AND (";
for ($c=0; $c < count($CategoryFilter); $c++) {
if ($c > 0) { $query .= " OR "; }
$query .= "e.categoryid='" . sqlescape($CategoryFilter[$c]) . "'";
}
$query .= ")";
}
else {
if (isset($categoryid) && $categoryid != 0) {
$query .= " AND e.categoryid='" . sqlescape($categoryid) . "'";
}
}
// Filter the results by a keyword from the search form.
if (!empty($keyword)) {
$query .= " AND (e.title LIKE '%" . sqlescape($keyword) .
"%' OR e.description LIKE '%" . sqlescape($keyword) . "%')";
}
$query .= " ORDER BY e.timebegin ASC, e.wholedayevent DESC";
$result =& DBQuery($query . "\n");
// Output an error message if $result is a string.
if (is_string($result)) { DBErrorBox($result); }
// Otherwise, the query was successful.
else {
echo '
<table id="MonthTable" width="100%" border="0" cellspacing="0" cellpadding="3">
<thead><tr>';
if (WEEK_STARTING_DAY == 0) {
echo '
<th>' . lang('sunday') . '</th>';
}
echo '
<th>' . lang('monday') . '</th>
<th>' . lang('tuesday') . '</th>
<th>' . lang('wednesday') . '</th>
<th>' . lang('thursday') . '</th>
<th>' . lang('friday') . '</th>
<th>' . lang('saturday') . '</th>';
if (WEEK_STARTING_DAY == 1) {
echo '
<th>' . lang('sunday') . '</th>';
}
echo '
</tr></thead>
<tbody>';
// read first event if one exists
if ($ievent < $result->numRows()) {
$event =& $result->fetchRow(DB_FETCHMODE_ASSOC, $ievent);
$event_timebegin = timestamp2datetime($event['timebegin']);
$event_timeend = timestamp2datetime($event['timeend']);
}
// Loop through the 6 possible rows for each week.
// If less rows are necessary,
for ($iweek=1; $iweek <= 6; $iweek++) {
// Determine the first day of the week
$weekstart = Add_Delta_Days($monthstart['month'], $monthstart['day'],
$monthstart['year'], ($iweek - 1) * 7);
$weekstart['timestamp'] = datetime2timestamp($weekstart['year'],
$weekstart['month'], $weekstart['day'], 12, 0, 'am');
// Output only the weeks where the first day is in the current month (excluding the first week)
if ($iweek == 1 || $weekstart['month'] == $month['month']) {
echo '<tr>';
// Output each day for the week.
for ($weekday = 0; $weekday <= 6; $weekday++) {
// Calculate the day's date information.
$iday = Add_Delta_Days($monthstart['month'], $monthstart['day'],
$monthstart['year'], (($iweek - 1) * 7) + $weekday);
$iday['timebegin'] = datetime2timestamp($iday['year'],
$iday['month'], $iday['day'], 0, 0, 'am');
$iday['timeend'] = datetime2timestamp($iday['year'],
$iday['month'], $iday['day'], 11, 59, 'pm');
// Determine the number of days between the day and the current date.
$datediff = Delta_Days($iday['month'], $iday['day'],
$iday['year'], date('m', NOW), date('d', NOW), date('Y', NOW));
// Set the CSS class for how the day should be styled.
$TDclass = '';
if ($month['month'] != $iday['month']) { $TDclass = ' class="MonthDay-OtherMonth"'; }
elseif ($datediff > 0) { $TDclass = ' class="MonthDay-Past"'; }
elseif ($datediff == 0) { $TDclass = ' class="MonthDay-Today"'; }
else { $TDclass = ' class="MonthDay-Future"'; }
echo '
<td' . $TDclass . '>';
// Do not display events that are not in the current month.
// TODO: Change this so the query does not pull the events in the first place.
if (!SHOW_MONTH_OVERLAP && $month['month'] != $iday['month']) {
echo ' ';
}
else {
// Output a table with the day's number.
echo '
<div class="DayNumber">';
// Display an "add event" icon
if (!empty($_SESSION['AUTH_SPONSORID'])) {
echo '
<a class="floatLeft NoPrint" href="addevent.php?calendarid=' . urlencode($_SESSION['CALENDAR_ID']) . '&timebegin_year=' . $iday['year'] . '&timebegin_month=' . $iday['month'] . '&timebegin_day=' . $iday['day'] . '" title="' . lang('add_new_event', false) . '"><img src="images/new.gif" height="16" width="16" alt="' . lang('add_new_event', false) . '" /></a>';
}
echo '
<b><a href="main.php?calendarid=' . urlencode($_SESSION['CALENDAR_ID']) . '&view=day&timebegin=' . urlencode(datetime2timestamp($iday['year'], $iday['month'], $iday['day'], 12, 0, 'am')) . $queryStringExtension . '">' . $iday['day'] . '</a></b></div>';
}
// Output all the events for the day.
while ($ievent < $result->numRows() && $event_timebegin['year'] == $iday['year'] &&
$event_timebegin['month'] == $iday['month'] && $event_timebegin['day'] == $iday['day']) {
// Only display events that are in the current month.
// TODO: Change so the query does not pull the events in the first place.
if (SHOW_MONTH_OVERLAP || $month['month'] == $iday['month']) {
disassemble_timestamp($event);
$event_timebegin_num = timestamp2timenumber($event['timebegin']);
$event_timeend_num = timestamp2timenumber($event['timeend']);
$begintimediff = NOW_AS_TIMENUM - $event_timebegin_num;
$endtimediff = NOW_AS_TIMENUM - (($event_timeend_num == 0)? 1440 : $event_timeend_num);
$event_timelabel = timenumber2timelabel((($event_timeend_num == 0)? 1440 :
$event_timeend_num) - $event_timebegin_num);
$EventHasPassed = ($datediff > 0 || ($datediff == 0 && $endtimediff > 0));
// If the event has passed, use the correct CSS class.
if ($EventHasPassed) { $event['classExtension'] = '-Past'; }
else { $event['classExtension'] = ''; }
// Output the event data.
echo '
<p class="EventItem' . $event['classExtension'] . '"><small>';
if ($event['wholedayevent'] == 0) { // Time of the Event
echo timestring($event_timebegin['hour'], $event_timebegin['min'],
$event_timebegin['ampm']);
if (!($event['timeend_hour'] == DAY_END_H && $event['timeend_min'] == 59) ||
$event_timeend_num == 0) {
echo ' (' . $event_timelabel . ')';
}
}
else { // "All Day" marker
if (!$previousWholeDay ) { echo lang('all_day'); }
$previousWholeDay = true;
}
echo '</small><br />';
if ($event['sponsorid'] != 1) {
echo '
<span class="fromCal">' . lang('calendar') . ': ' . getSponsorCalendarName($event['sponsorid']) . '</span><br />';
}
echo '
<a href="main.php?calendarid=' . urlencode($_SESSION['CALENDAR_ID']) . '&view=event&eventid=' . $event['eventid'] . '&timebegin=' . urlencode(datetime2timestamp($event_timebegin['year'], $event_timebegin['month'], $event_timebegin['day'], 12, 0, 'am')) . '">' . $event['title'] . '</a></p>';
}
// Read the next event
$ievent++;
if ($ievent < $result->numRows()) {
$event =& $result->fetchRow(DB_FETCHMODE_ASSOC, $ievent);
$event_timebegin = timestamp2datetime($event['timebegin']);
$event_timeend = timestamp2datetime($event['timeend']);
}
}
echo '</td>';
}
echo '
</tr>';
}
}
echo '</tbody>
</table><!-- #MonthTable -->';
if (!empty($_SESSION['AUTH_SPONSORID'])) {
echo '
<table class="NoPrint" border="0" cellspacing="0" cellpadding="3">
<tbody><tr>
<td><img src="images/new.gif" height="16" width="16" alt="New" /></td>
<td>= ' . lang('add_new_event') . '</td>
</tr></tbody>
</table>';
}
}
?>