-
Notifications
You must be signed in to change notification settings - Fork 4
/
exchange.php
executable file
·92 lines (73 loc) · 3.35 KB
/
exchange.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
<?php
/*
* This file is intended to check an exchange calendar via ews
*
*/
$today = date('Y-m-d');
if ($force == TRUE) {
$time = 'T'.date('H:i:sP');
} else {
$time = 'T00:00:01'.date('P');
}
$ews = new ExchangeWebServices($mailserver, $r['logon_name'], $r['pass']);
// Set init class
$request = new EWSType_FindItemType();
// Use this to search only the items in the parent directory in question or use ::SOFT_DELETED
// to identify "soft deleted" items, i.e. not visible and not in the trash can.
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
// This identifies the set of properties to return in an item or folder response
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;
// Define the timeframe to load calendar items
$request->CalendarView = new EWSType_CalendarViewType();
$request->CalendarView->StartDate = $today . $time; // an ISO8601 date e.g. 2012-06-12T15:18:34+03:00
$request->CalendarView->EndDate = $today . 'T23:59:59'.date('P');// an ISO8601 date later than the above
// Only look in the "calendars folder"
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
// Send request
$response = $ews->FindItem($request);
// Loop through each item if event(s) were found in the timeframe specified
if ($response->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView > 0){
$events = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items;
$events2 = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
foreach ($events as $event){
$start = date('Y-m-d H:i:s',strtotime($event->Start));
$end = date('Y-m-d H:i:s',strtotime($event->End));
$subject = $event->Subject;
//room resource delegation fix
$subject = str_replace("FW: ", "", $subject);
$subject = str_replace("\n", "", $subject);
$subject = trim($subject);
if ($subject != "") {
//assuming still connected to database
$query = "INSERT INTO events (EventName, Start, End, Room, Grp, Bldg) VALUES (?,?,?,?,?,?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, "ssssss", $subject, $start, $end, $r['name'], $r['group'], $r['bldg']);
/* Execute the statement */
mysqli_stmt_execute($stmt);
}
}
foreach ($events2 as $event2){
$start = date('Y-m-d H:i:s',strtotime($event2->Start));
$end = date('Y-m-d H:i:s',strtotime($event2->End));
$subject = $event2->Subject;
//room resource delegation fix
$subject = str_replace("FW: ", "", $subject);
$subject = str_replace("\n", "", $subject);
$subject = trim($subject);
if ($subject != "") {
//assuming still connected to database
$query = "INSERT INTO events (EventName, Start, End, Room, Grp, Bldg) VALUES (?,?,?,?,?,?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, "ssssss", $subject, $start, $end, $r['name'], $r['group'], $r['bldg']);
/* Execute the statement */
mysqli_stmt_execute($stmt);
}
}
}
else {
// No items returned
}
?>