/usr/share/kopano/php/mapi/class.freebusypublish.php is in php-mapi 8.5.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | <?php
/*
* Copyright 2005 - 2016 Zarafa and its licensors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class FreeBusyPublish {
var $session;
var $calendar;
var $entryid;
var $starttime;
var $length;
var $store;
var $proptags;
/**
* @param mapi_session $session MAPI Session
* @param mapi_folder $calendar Calendar to publish
* @param string $entryid AddressBook Entry ID for the user we're publishing for
*/
function __construct($session, $store, $calendar, $entryid)
{
$properties["entryid"] = PR_ENTRYID;
$properties["parent_entryid"] = PR_PARENT_ENTRYID;
$properties["message_class"] = PR_MESSAGE_CLASS;
$properties["icon_index"] = PR_ICON_INDEX;
$properties["subject"] = PR_SUBJECT;
$properties["display_to"] = PR_DISPLAY_TO;
$properties["importance"] = PR_IMPORTANCE;
$properties["sensitivity"] = PR_SENSITIVITY;
$properties["startdate"] = "PT_SYSTIME:PSETID_Appointment:0x820d";
$properties["duedate"] = "PT_SYSTIME:PSETID_Appointment:0x820e";
$properties["recurring"] = "PT_BOOLEAN:PSETID_Appointment:0x8223";
$properties["recurring_data"] = "PT_BINARY:PSETID_Appointment:0x8216";
$properties["busystatus"] = "PT_LONG:PSETID_Appointment:0x8205";
$properties["label"] = "PT_LONG:PSETID_Appointment:0x8214";
$properties["alldayevent"] = "PT_BOOLEAN:PSETID_Appointment:0x8215";
$properties["private"] = "PT_BOOLEAN:PSETID_Common:0x8506";
$properties["meeting"] = "PT_LONG:PSETID_Appointment:0x8217";
$properties["startdate_recurring"] = "PT_SYSTIME:PSETID_Appointment:0x8235";
$properties["enddate_recurring"] = "PT_SYSTIME:PSETID_Appointment:0x8236";
$properties["location"] = "PT_STRING8:PSETID_Appointment:0x8208";
$properties["duration"] = "PT_LONG:PSETID_Appointment:0x8213";
$properties["responsestatus"] = "PT_LONG:PSETID_Appointment:0x8218";
$properties["reminder"] = "PT_BOOLEAN:PSETID_Common:0x8503";
$properties["reminder_minutes"] = "PT_LONG:PSETID_Common:0x8501";
$properties["contacts"] = "PT_MV_STRING8:PSETID_Common:0x853a";
$properties["contacts_string"] = "PT_STRING8:PSETID_Common:0x8586";
$properties["categories"] = "PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords";
$properties["reminder_time"] = "PT_SYSTIME:PSETID_Common:0x8502";
$properties["commonstart"] = "PT_SYSTIME:PSETID_Common:0x8516";
$properties["commonend"] = "PT_SYSTIME:PSETID_Common:0x8517";
$properties["basedate"] = "PT_SYSTIME:PSETID_Appointment:0x8228";
$properties["timezone_data"] = "PT_BINARY:PSETID_Appointment:0x8233";
$this->proptags = getPropIdsFromStrings($store, $properties);
$this->session = $session;
$this->calendar = $calendar;
$this->entryid = $entryid;
$this->store = $store;
}
/**
* Publishes the infomation
* @paam timestamp $starttime Time from which to publish data (usually now)
* @paam integer $length Amount of seconds from $starttime we should publish
*/
function publishFB($starttime, $length) {
$start = $starttime;
$end = $starttime + $length;
// Get all the items in the calendar that we need
$calendaritems = Array();
$restrict = Array(RES_OR, Array(
// (item[start] >= start && item[start] <= end)
Array(RES_AND, Array(
Array(RES_PROPERTY, Array(RELOP => RELOP_GE, ULPROPTAG => $this->proptags["startdate"], VALUE => $start)),
Array(RES_PROPERTY, Array(RELOP => RELOP_LE, ULPROPTAG => $this->proptags["startdate"], VALUE => $end))
)),
// OR
// (item[end] >= start && item[end] <= end)
Array(RES_AND, Array(
Array(RES_PROPERTY, Array(RELOP => RELOP_GE, ULPROPTAG => $this->proptags["duedate"], VALUE => $start)),
Array(RES_PROPERTY, Array(RELOP => RELOP_LE, ULPROPTAG => $this->proptags["duedate"], VALUE => $end))
)),
// OR
// (item[start] < start && item[end] > end)
Array(RES_AND, Array(
Array(RES_PROPERTY, Array(RELOP => RELOP_LT, ULPROPTAG => $this->proptags["startdate"], VALUE => $start)),
Array(RES_PROPERTY, Array(RELOP => RELOP_GT, ULPROPTAG => $this->proptags["duedate"], VALUE => $end))
)),
// OR
Array(RES_OR, Array(
// OR
// (EXIST(ecurrence_enddate_property) && item[isRecurring] == true && item[end] >= start)
Array(RES_AND, Array(
Array(RES_EXIST, Array(ULPROPTAG => $this->proptags["enddate_recurring"])),
Array(RES_PROPERTY, Array(RELOP => RELOP_EQ, ULPROPTAG => $this->proptags["recurring"], VALUE => true)),
Array(RES_PROPERTY, Array(RELOP => RELOP_GE, ULPROPTAG => $this->proptags["enddate_recurring"], VALUE => $start))
)),
// OR
// (!EXIST(ecurrence_enddate_property) && item[isRecurring] == true && item[start] <= end)
Array(RES_AND, Array(
Array(RES_NOT, Array(
Array(RES_EXIST, Array(ULPROPTAG => $this->proptags["enddate_recurring"]))
)),
Array(RES_PROPERTY, Array(RELOP => RELOP_LE, ULPROPTAG => $this->proptags["startdate"], VALUE => $end)),
Array(RES_PROPERTY, Array(RELOP => RELOP_EQ, ULPROPTAG => $this->proptags["recurring"], VALUE => true))
))
)) // EXISTS OR
)); // global OR
$contents = mapi_folder_getcontentstable($this->calendar);
mapi_table_restrict($contents, $restrict);
while(1) {
$rows = mapi_table_queryrows($contents, array_values($this->proptags), 0, 50);
if(!is_array($rows))
break;
if(empty($rows))
break;
foreach ($rows as $row) {
$occurrences = Array();
if(isset($row[$this->proptags['recurring']]) && $row[$this->proptags['recurring']]) {
$recur = new Recurrence($this->store, $row);
$occurrences = $recur->getItems($starttime, $starttime + $length);
} else {
$occurrences[] = $row;
}
$calendaritems = array_merge($calendaritems, $occurrences);
}
}
// $calendaritems now contains all the calendar items in the specified time
// frame. We now need to merge these into a flat array of begin/end/status
// objects. This also filters out all the 'free' items (status 0)
$freebusy = $this->mergeItemsFB($calendaritems);
// $freebusy now contains the start, end and status of all items, merged.
// Get the FB interface
try {
$fbsupport = mapi_freebusysupport_open($this->session, $this->store);
} catch (MAPIException $e) {
if ($e->getCode() == MAPI_E_NOT_FOUND) {
$e->setHandled();
if (function_exists("dump"))
dump("Error in opening freebusysupport object.");
}
}
// Open updater for this user
if (!isset($fbsupport) || !$fbsupport)
return;
$updaters = mapi_freebusysupport_loadupdate($fbsupport, Array($this->entryid));
$updater = $updaters[0];
// Send the data
mapi_freebusyupdate_reset($updater);
mapi_freebusyupdate_publish($updater, $freebusy);
mapi_freebusyupdate_savechanges($updater, $start-24*60*60, $end);
// We're finished
mapi_freebusysupport_close($fbsupport);
}
/**
* Sorts by timestamp, if equal, then end before start
*/
function cmp($a, $b)
{
if ($a["time"] != $b["time"])
return ($a["time"] > $b["time"] ? 1 : -1);
if ($a["type"] < $b["type"])
return 1;
if ($a["type"] > $b["type"])
return -1;
return 0;
}
/**
* Function mergeItems
* @author Steve Hardy
*/
function mergeItemsFB($items)
{
$merged = Array();
$timestamps = Array();
$csubj = Array();
$cbusy = Array();
$level = 0;
$laststart = null;
foreach($items as $item)
{
$ts["type"] = 0;
$ts["time"] = $item[$this->proptags["startdate"]];
$ts["subject"] = $item[PR_SUBJECT];
$ts["status"] = isset($item[$this->proptags["busystatus"]]) ? $item[$this->proptags["busystatus"]] : 0; // ZP-197
$timestamps[] = $ts;
$ts["type"] = 1;
$ts["time"] = $item[$this->proptags["duedate"]];
$ts["subject"] = $item[PR_SUBJECT];
$ts["status"] = isset($item[$this->proptags["busystatus"]]) ? $item[$this->proptags["busystatus"]] : 0; // ZP-197
$timestamps[] = $ts;
}
usort($timestamps, Array($this, "cmp"));
$laststart = 0;
foreach($timestamps as $ts)
{
switch ($ts["type"])
{
case 0: // Start
if ($level != 0 && $laststart != $ts["time"])
{
$newitem["start"] = $laststart;
$newitem["end"] = $ts["time"];
$newitem["subject"] = join(",", $csubj);
$newitem["status"] = !empty($cbusy) ? max($cbusy) : 0;
if ($newitem["status"] > 0)
$merged[] = $newitem;
}
$level++;
$csubj[] = $ts["subject"];
$cbusy[] = $ts["status"];
$laststart = $ts["time"];
break;
case 1: // End
if ($laststart != $ts["time"])
{
$newitem["start"] = $laststart;
$newitem["end"] = $ts["time"];
$newitem["subject"] = join(",", $csubj);
$newitem["status"] = !empty($cbusy) ? max($cbusy) : 0;
if ($newitem["status"] > 0)
$merged[] = $newitem;
}
$level--;
array_splice($csubj, array_search($ts["subject"], $csubj, 1), 1);
array_splice($cbusy, array_search($ts["status"], $cbusy, 1), 1);
$laststart = $ts["time"];
break;
}
}
return $merged;
}
}
|