-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathget_events.php
156 lines (130 loc) · 4.12 KB
/
get_events.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
<?php
/**
* Description:
* Web Service functionality to get events.
* Uses XML (but not SOAP at this point since that would be
* overkill and require extra packages to install).
*
* Comments:
* Client apps must use the same authentication as the web browser. If
* WebCalendar is setup to use web-based authentication, then the login.php
* found in this directory should be used to obtain a session cookie.
*
* Developer Notes:
* If you enable the WS_DEBUG option below,
* all data will be written to a debug file in /tmp also.
*/
$WS_DEBUG = false;
require_once 'ws.php';
// Initialize...
ws_init();
// header ( 'Content-type: text/xml' );
header ( 'Content-type: text/plain' );
echo '<?xml version="1.0" encoding="UTF-8"?' . ">\n";
$out = '
<events>';
// If login is public user, make sure public can view others...
if ( $login == '__public__' && $login != $user ) {
if ( $PUBLIC_ACCESS_OTHERS != 'Y' ) {
$out .= '
<error>' . translate ( 'Not authorized' ) . '</error>
</events>
';
exit;
}
// $out .= '<!-- Allowing public user to view other users calendar -->';
}
if ( empty ( $user ) )
$user = $login;
// If viewing different user then yourself...
if ( $login != $user ) {
if ( $ALLOW_VIEW_OTHER != 'Y' ) {
$out .= '
<error>' . translate ( 'Not authorized' ) . '</error>
</events>
';
exit;
}
// $out .= '<!-- Allowing user to view other users calendar -->';
}
$startdate = getValue ( 'startdate' );
$enddate = getValue ( 'enddate' );
if ( empty ( $startdate ) )
$startdate = date ( 'Ymd' );
if ( empty ( $enddate ) )
$enddate = $startdate;
// Now read all the repeating events (for all users).
$repeated_events = query_events ( $user, true,
'AND ( wer.cal_end > ' . $startdate . ' OR wer.cal_end IS NULL )' );
// Read non-repeating events (for all users).
if ( $WS_DEBUG )
$out .= '
<!-- ' . str_replace ( ['XXX', 'YYY', 'ZZZ'],
[$user, $startdate, $enddate],
translate ( 'Checking for events for XXX from date YYY to date ZZZ.' ) )
. ' -->
';
$events = read_events ( $user, date_to_epoch ( $startdate ),
date_to_epoch ( $enddate ) );
if ( $WS_DEBUG )
$out .= '
<!-- ' . str_replace ( 'XXX', count ( $events ),
translate ( 'Found XXX events in time range.' ) ) . ' -->
';
/* Process an event for a single day. Check to see if it has a reminder,
* when it needs to be sent and when the last time it was sent.
*/
function process_event ( $id, $name, $event_date, $event_time ) {
global $out, $WS_DEBUG;
if ( $WS_DEBUG )
ws_log_message ( str_replace ( ['XXX', 'YYY', 'ZZZ', 'AAA'],
[$id, $name, $event_time, $event_date],
translate ( 'Event id=XXX YYY at ZZZ on AAA.' ) ) );
return ws_print_event_xml ( $id, $event_date );
}
// $out .= '<!-- events for user "'.$user.'", login "'.$login.'" -->
// <!-- date range: '."$startdate - $enddate -->\n";
$starttime = mktime ( 0, 0, 0,
substr ( $startdate, 4, 2 ),
substr ( $startdate, 6, 2 ),
substr ( $startdate, 0, 4 ) );
$endtime = mktime ( 0, 0, 0,
substr ( $enddate, 4, 2 ),
substr ( $enddate, 6, 2 ),
substr ( $enddate, 0, 4 ) );
for ( $d = $starttime; $d <= $endtime; $d += 86400 ) {
$completed_ids = [];
$date = date ( 'Ymd', $d );
// $out .= "Date: $date\n";
// Get non-repeating events for this date.
// An event will be included one time for each participant.
$ev = get_entries ( $date );
// Keep track of duplicates.
$completed_ids = [];
for ( $i = 0, $evCnt = count ( $ev ); $i < $evCnt; $i++ ) {
$id = $ev[$i]->getID();
if ( ! empty ( $completed_ids[$id] ) )
continue;
$completed_ids[$id] = 1;
$out .= process_event( $id, $ev[$i]->getName(), $date,
$ev[$i]->getTime() );
}
$rep = get_repeating_entries ( $user, $date );
for ( $i = 0, $repCnt = count ( $rep ); $i < $repCnt; $i++ ) {
$id = $rep[$i]->getID();
if ( ! empty ( $completed_ids[$id] ) )
continue;
$completed_ids[$id] = 1;
$out .= process_event( $id, $rep[$i]->getName(), $date,
$rep[$i]->getTime() );
}
}
$out .= '
</events>
';
// If web service debugging is on...
if ( ! empty ( $WS_DEBUG ) && $WS_DEBUG )
ws_log_message ( $out );
// Send output now...
echo $out;
?>