├── .gitattributes
├── .gitignore
├── LICENSE.TXT
├── README.md
├── addToCalendar.php
├── common
├── css
│ └── styles.css
├── footer.php
└── header.php
├── doAdd.php
├── error.php
├── home.php
├── loc
└── readme-ja.md
├── logout.php
├── o365
├── ClientReg.php
├── Office365Service.php
└── authorize.php
├── sessionManager.php
└── site-event-list.php
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
38 | # Directories potentially created on remote AFP share
39 | .AppleDB
40 | .AppleDesktop
41 | Network Trash Folder
42 | Temporary Items
43 | .apdisk
44 |
45 | # Project-specific
46 | deploy.bat
47 | *.zip
48 |
--------------------------------------------------------------------------------
/LICENSE.TXT:
--------------------------------------------------------------------------------
1 | php-calendar, https://github.com/jasonjoh/php-calendar
2 |
3 | Copyright (c) Microsoft Corporation
4 | All rights reserved.
5 |
6 | MIT License:
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining
9 | a copy of this software and associated documentation files (the
10 | ""Software""), to deal in the Software without restriction, including
11 | without limitation the rights to use, copy, modify, merge, publish,
12 | distribute, sublicense, and/or sell copies of the Software, and to
13 | permit persons to whom the Software is furnished to do so, subject to
14 | the following conditions:
15 |
16 | The above copyright notice and this permission notice shall be
17 | included in all copies or substantial portions of the Software.
18 |
19 | THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PHP Calendar API Sample #
2 |
3 | [日本 (日本語)](https://github.com/jasonjoh/php-calendar/blob/master/loc/readme-ja.md) (Japanese)
4 |
5 | This sample shows how you can use the [Calendar API](https://msdn.microsoft.com/office/office365/APi/calendar-rest-operations) from PHP. The sample app is an "upcoming shows" app for a fictional community theater's Shakespearean festival. Users can connect their Office 365 account and add events to their calendar for the show times they are attending. The user has the option of inviting friends, which will send a meeting request to each invited friend.
6 |
7 | ## API features used ##
8 |
9 | - Creating events on a user's default calendar
10 | - Adding attachments to events
11 | - Adding attendees to events
12 | - Using a [calendar view](https://msdn.microsoft.com/office/office365/APi/calendar-rest-operations#GetCalendarView) to expand recurring events and display all appointments for a single day.
13 |
14 | ## Required software ##
15 |
16 | - [PHP 5.6](http://php.net/downloads.php)
17 | - A web server capable of serving PHP.
18 |
19 | In my testing I used IIS 8 installed on a Windows 8.1 laptop. I installed PHP 5.6.0 using the [Web Platform Installer](http://www.microsoft.com/web/downloads/platform.aspx) (Windows/IIS only).
20 |
21 | ## Running the sample ##
22 |
23 | It's assumed that you have PHP installed before starting, and that your web server is configured to process and server PHP files.
24 |
25 | 1. Download or fork the sample project.
26 | 1. Create a new directory in your web root directory called `php-calendar`. Copy the files from the repository to this directory.
27 | 1. [Register the app in Azure Active Directory](https://github.com/jasonjoh/office365-azure-guides/blob/master/RegisterAnAppInAzure.md). The app should be registered as a web app with a Sign-on URL of `http://localhost/php-calendar`, and should be given the permission to "Have full access to users' calendars", which is available in the "Delegated Permissions" dropdown.
28 | 1. Edit the `.\o365\ClientReg.php` file.
29 | 1. Copy the client ID for your app obtained during app registration and paste it as the value for the `$clientId` variable.
30 | 1. Copy the key you created during app registration and paste it as the value for the `$clientSecret` variable.
31 | 1. Save the file.
32 | 1. If your PHP installation is not configured with updated CA certificates to verify SSL, requests will fail unless you run Fiddler on the server and set the `$enableFiddler` variable to `true` in `Office365Service.php`. Alternatively, you can insert the following line immediately before any call to `curl_exec`. **However,** it should be noted that doing so disables any SSL verification, which should NOT be done in production.
33 |
34 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
35 | 1. Open a web browser and browse to `http://localhost/php-calendar/home.php`.
36 | 1. You should see a list of upcoming show times for various Shakespearean plays. Click on any of the "Connect my Calendar" buttons to sign in to Office 365.
37 | 1. Once signed in you should be redirected back to the home page, and the buttons should now read "Add to Calendar." Click the button next to a specific show time to add it to your calendar. Events with a "Voucher Required" field of Yes will include the voucher as an attachment on the event.
38 |
39 | ## Copyright ##
40 |
41 | Copyright (c) Microsoft. All rights reserved.
42 |
43 | ----------
44 | Connect with me on Twitter [@JasonJohMSFT](https://twitter.com/JasonJohMSFT)
45 |
46 | Follow the [Exchange Dev Blog](http://blogs.msdn.com/b/exchangedev/)
--------------------------------------------------------------------------------
/addToCalendar.php:
--------------------------------------------------------------------------------
1 | title."' from session.");
23 |
24 | // Get all events on the user's O365 calendar for that day.
25 | $eventsOnThisDay = Office365Service::getEventsForDate($accessToken, $event->startTime);
26 | if (SessionManager::checkResponseAndRefreshToken($eventsOnThisDay)) {
27 | // Pick up new access token
28 | $accessToken = $_SESSION['accessToken'];
29 |
30 | error_log("Retrying get events request");
31 | $eventsOnThisDay = Office365Service::getEventsForDate($accessToken, $event->startTime);
32 | }
33 |
34 | // Build a link URL to the doAdd.php file, which does the actual work to add
35 | // the event to the O365 calendar.
36 | $buttonUrl = "doAdd.php";
37 |
38 | $altRow = false;
39 | ?>
40 |
41 |
42 |
43 |
Add Event To Calendar
44 |
45 |
46 | Show |
47 | title ?> |
48 |
49 |
50 | Location |
51 | location ?> |
52 |
53 |
54 | Date |
55 | startTime, "M j, Y") ?> |
56 |
57 |
58 | Time |
59 | startTime, "g:i a")." - ".date_format($event->endTime, "g:i a") ?> |
60 |
61 |
62 | Voucher required? |
63 | voucherRequired ? "Yes" : "No" ?> |
64 |
65 |
66 |
67 | ";
72 | }
73 | ?>
74 |
75 |
76 | Event |
77 | Start |
78 | End |
79 |
80 |
81 | >
82 |
83 |
91 | |
92 |
93 | setTimeZone(new DateTimeZone(date_default_timezone_get()));
98 | echo date_format($startDate, "g:i a");
99 | ?>
100 | |
101 |
102 | setTimeZone(new DateTimeZone(date_default_timezone_get()));
107 | echo date_format($endDate, "g:i a");
108 | ?>
109 | |
110 |
111 |
112 |
113 | No events found
"; } ?>
114 |
115 |
116 |
117 |
123 |
--------------------------------------------------------------------------------
/common/css/styles.css:
--------------------------------------------------------------------------------
1 | /* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. */
2 | body {
3 | font-family: Tahoma, Geneva, sans-serif;
4 | }
5 |
6 | #info-bar {
7 | width: 100%;
8 | background-color: #2E8B57;
9 | color: #ffffff;
10 | font-size: 1.5em;
11 | text-align: left;
12 | padding: 5px;
13 | margin-bottom: 10px;
14 | }
15 |
16 | #cal-view-title {
17 | width: 100%;
18 | background-color: #2E8B57;
19 | color: #ffffff;
20 | font-size: 1.5em;
21 | text-align: center;
22 | padding: 5px;
23 | }
24 |
25 | #nav-links {
26 | width: auto;
27 | }
28 |
29 | #app-title {
30 | width: auto;
31 | }
32 |
33 | #logout {
34 | float: right;
35 | width: auto;
36 | }
37 |
38 | #table-title {
39 | font-style: bold;
40 | font-size: 2em;
41 | }
42 |
43 | .show-list {
44 | width: 100%;
45 | border-collapse: collapse;
46 | margin-top: 10px;
47 | margin-left: 5px;
48 | }
49 |
50 | .show-list td, .show-list th {
51 | font-size: 1em;
52 | border: 1px solid #2E8B57;
53 | padding: 3px 7px 2px 7px;
54 | }
55 |
56 | .show-list th {
57 | font-size: 1.1em;
58 | text-align: left;
59 | padding-top: 5px;
60 | padding-bottom: 4px;
61 | background-color: #2E8B57;
62 | color: #ffffff;
63 | }
64 |
65 | .show-list th.button, .show-list td.button {
66 | width: 1px;
67 | }
68 |
69 | .show-list tr.alt td {
70 | color: #000000;
71 | background-color: #C1FFC1;
72 | }
73 |
74 | /* Calendar view */
75 | .cal-view {
76 | width: 100%;
77 | border-collapse: collapse;
78 | margin-top: 10px;
79 | margin-bottom: 5px;
80 | }
81 |
82 | .cal-view td, .cal-view th {
83 | font-size: 1em;
84 | border: 1px solid #2E8B57;
85 | padding: 3px 7px 2px 7px;
86 | }
87 |
88 | .cal-view th {
89 | font-size: 1.1em;
90 | text-align: left;
91 | padding-top: 5px;
92 | padding-bottom: 4px;
93 | background-color: #2E8B57;
94 | color: #ffffff;
95 | }
96 |
97 | .cal-view tr.alt td {
98 | color: #000000;
99 | background-color: #C1FFC1;
100 | }
101 |
102 | a.user:link {
103 | color: #ffffff;
104 | }
105 |
106 | a.nav:link, a.nav:visited {
107 | color: #ffffff;
108 | text-decoration: none;
109 | padding-left: 10px;
110 | }
111 |
112 | a.create:link, a.create:visited {
113 | display: block;
114 | width: 200px;
115 | font-weight: bold;
116 | color: #FFFFFF;
117 | background-color: #2E8B57;
118 | text-align: center;
119 | padding: 4px;
120 | text-decoration: none;
121 | text-transform: uppercase;
122 | margin-top: 10px;
123 | margin-bottom: 10px;
124 | }
125 |
126 | a.action:link, a.action:visited {
127 | display: block;
128 | width: 60px;
129 | font-size: .7em;
130 | font-weight: bold;
131 | color: #FFFFFF;
132 | background-color: #2E8B57;
133 | text-align: center;
134 | padding: 4px;
135 | text-decoration: none;
136 | text-transform: uppercase;
137 | float: right;
138 | }
139 |
140 | .add-event {
141 | clear: both;
142 | font-weight: bold;
143 | padding-top: 40px;
144 | }
145 |
146 | input[type=text] {
147 | width: 80%;
148 | }
149 |
150 | input[type=submit] {
151 | display: block;
152 | width: auto;
153 | font-size: .7em;
154 | font-weight: bold;
155 | color: #FFFFFF;
156 | background-color: #2E8B57;
157 | text-align: center;
158 | padding: 4px;
159 | margin-top: 5px;
160 | text-transform: uppercase;
161 | float: left;
162 | }
163 |
164 | #content {
165 | float: left;
166 | width: 750px;
167 | margin:0 auto;
168 | }
169 |
170 | #event-details {
171 | float: left;
172 | width: auto;
173 | text-align: left;
174 | }
175 |
176 | #calendar-sidebar {
177 | display: inline;
178 | float: right;
179 | width: auto;
180 | text-align: left;
181 | border: 1px solid;
182 | margin-top: 20px;
183 | margin-right: 5px;
184 | padding-right: 10px;
185 | clear: right;
186 | }
187 |
188 | .debug-dump {
189 | clear: both;
190 | float: left;
191 | width: 100%;
192 | margin-top: 45px;
193 | word-wrap: break-word;
194 | }
195 |
196 | /*
197 | MIT License:
198 |
199 | Permission is hereby granted, free of charge, to any person obtaining
200 | a copy of this software and associated documentation files (the
201 | ""Software""), to deal in the Software without restriction, including
202 | without limitation the rights to use, copy, modify, merge, publish,
203 | distribute, sublicense, and/or sell copies of the Software, and to
204 | permit persons to whom the Software is furnished to do so, subject to
205 | the following conditions:
206 |
207 | The above copyright notice and this permission notice shall be
208 | included in all copies or substantial portions of the Software.
209 |
210 | THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
211 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
212 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
213 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
214 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
215 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
216 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
217 | */
--------------------------------------------------------------------------------
/common/footer.php:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 | SESSION VARIABLES:
8 | $value)
11 | {
12 | echo " ".$key.": ".$value;
13 | echo "\n";
14 | }
15 | ?>
16 |
17 |