-
Notifications
You must be signed in to change notification settings - Fork 40
/
addToCalendar.php
147 lines (134 loc) · 5.37 KB
/
addToCalendar.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
<?php
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
// create an array to set page-level variables
$page = array();
$page['title'] = 'Add to Calendar';
// include the page header
include('common/header.php');
require_once('o365/Office365Service.php');
require_once('sessionManager.php');
// Get the index of the show from the query parameters
$showIndex = $_GET['showIndex'];
error_log("addToCalendar.php called.");
error_log("showIndex parameter: ".$showIndex);
// Get access token from the session.
$accessToken = $_SESSION['accessToken'];
// Get the event from the array of events in the session.
$event = $_SESSION['events'][$showIndex];
error_log("Retrieved event '".$event->title."' from session.");
// Get all events on the user's O365 calendar for that day.
$eventsOnThisDay = Office365Service::getEventsForDate($accessToken, $event->startTime);
if (SessionManager::checkResponseAndRefreshToken($eventsOnThisDay)) {
// Pick up new access token
$accessToken = $_SESSION['accessToken'];
error_log("Retrying get events request");
$eventsOnThisDay = Office365Service::getEventsForDate($accessToken, $event->startTime);
}
// Build a link URL to the doAdd.php file, which does the actual work to add
// the event to the O365 calendar.
$buttonUrl = "doAdd.php";
$altRow = false;
?>
<div id="content">
<div id="event-details">
<h1>Add Event To Calendar</h1>
<table>
<tr>
<td>Show</td>
<td><?php echo $event->title ?></td>
</tr>
<tr>
<td>Location</td>
<td><?php echo $event->location ?></td>
</tr>
<tr>
<td>Date</td>
<td><?php echo date_format($event->startTime, "M j, Y") ?></td>
</tr>
<tr>
<td>Time</td>
<td><?php echo date_format($event->startTime, "g:i a")." - ".date_format($event->endTime, "g:i a") ?></td>
</tr>
<tr>
<td>Voucher required?</td>
<td><?php echo $event->voucherRequired ? "Yes" : "No" ?></td>
</tr>
</table>
</div>
<div id="calendar-sidebar">
<div id="cal-view-title">Your calendar for <?php echo date_format($event->startTime, "m/d/Y") ?></div>
<?php
if ($eventsOnThisDay['error']) {
echo "<div text-align=\"center\">ERROR: ".$eventsOnThisDay['error']."</div>";
}
?>
<table class="cal-view">
<tr>
<th>Event</th>
<th>Start</th>
<th>End</th>
</tr>
<?php foreach($eventsOnThisDay['value'] as $event) { ?>
<tr title="<?php echo $event['Subject'] ?>"<?php echo $altRow ? 'class="alt"' : "" ?>>
<td>
<?php
if (strlen($event['Subject']) <= 25) {
echo $event['Subject'];
}
else {
echo substr($event['Subject'], 0, 22)."...";
}
?>
</td>
<td>
<?php
// Since date/time values are in UTC when they are returned by
// Exchange, convert them to the local time zone before displaying.
$startDate = new DateTime($event['Start'], new DateTimeZone("UTC"));
$startDate->setTimeZone(new DateTimeZone(date_default_timezone_get()));
echo date_format($startDate, "g:i a");
?>
</td>
<td>
<?php
// Since date/time values are in UTC when they are returned by
// Exchange, convert them to the local time zone before displaying.
$endDate = new DateTime($event['End'], new DateTimeZone("UTC"));
$endDate->setTimeZone(new DateTimeZone(date_default_timezone_get()));
echo date_format($endDate, "g:i a");
?>
</td>
</tr>
<?php } ?>
</table>
<?php if (sizeof($eventsOnThisDay['value']) <= 0) { echo "<div text-align=\"center\">No events found</div>"; } ?>
</div>
</div>
<form class="add-event" action="<?php echo $buttonUrl ?>" method="post">
<input type="hidden" name="showIndex" id="showIndex" value="<?php echo $showIndex ?>"/>
<label for="attendees">Enter email addresses (separated by ';') to invite friends!</label><br>
<input type="text" name="attendees" id="attendees"/><br>
<input type="submit" value="Add to my calendar"</input>
</form>
<?php
include('common/footer.php');
/*
MIT License:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
""Software""), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
?>