/** * 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(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)))), 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)))), 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)))), array(RES_OR, array(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)))), 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)))))))); // 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) { $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); } else { ZLog::Write(LOGLEVEL_WARN, "FreeBusyPublish is not available"); } }
/** * Function which checks whether received meeting request is either conflicting with other appointments or not. * @return mixed(boolean/integer) true if normal meeting is conflicting or an integer which specifies no of instances * conflict of recurring meeting and false if meeting is not conflicting. * @param MAPIMessage $message meeting request item that should be checked for conflicts in calendar * @param MAPIStore $userStore store containing calendar folder that will be used for confilict checking * @param MAPIFolder $calFolder calendar folder for conflict checking * @return Mixed if boolean then true/false for indicating confict, if number then items that are conflicting with the message. */ function isMeetingConflicting($message = false, $userStore = false, $calFolder = false) { $returnValue = false; $noOfInstances = 0; if ($message === false) { $message = $this->message; } $messageProps = mapi_getprops($message, array(PR_MESSAGE_CLASS, $this->proptags['goid'], $this->proptags['goid2'], $this->proptags['startdate'], $this->proptags['duedate'], $this->proptags['recurring'], $this->proptags['clipstart'], $this->proptags['clipend'], PR_RCVD_REPRESENTING_NAME)); if ($userStore === false) { $userStore = $this->store; // check if delegate is processing the response if (isset($messageProps[PR_RCVD_REPRESENTING_NAME])) { $delegatorStore = $this->getDelegatorStore($messageProps[PR_RCVD_REPRESENTING_NAME], array(PR_IPM_APPOINTMENT_ENTRYID)); $userStore = $delegatorStore['store']; $calFolder = $delegatorStore[PR_IPM_APPOINTMENT_ENTRYID]; } } if ($calFolder === false) { $calFolder = $this->openDefaultCalendar($userStore); } if ($calFolder) { // Meeting request is recurring, so get all occurrence and check for each occurrence whether it conflicts with other appointments in Calendar. if (isset($messageProps[$this->proptags['recurring']]) && $messageProps[$this->proptags['recurring']] === true) { // Apply recurrence class and retrieve all occurrences(max: 30 occurrence because recurrence can also be set as 'no end date') $recurr = new Recurrence($userStore, $message); $items = $recurr->getItems($messageProps[$this->proptags['clipstart']], $messageProps[$this->proptags['clipend']] * (24 * 24 * 60), 30); foreach ($items as $item) { // Get all items in the timeframe that we want to book, and get the goid and busystatus for each item $calendarItems = $recurr->getCalendarItems($userStore, $calFolder, $item[$this->proptags['startdate']], $item[$this->proptags['duedate']], array($this->proptags['goid'], $this->proptags['busystatus'])); foreach ($calendarItems as $calendarItem) { if ($calendarItem[$this->proptags['busystatus']] !== fbFree) { /** * Only meeting requests have globalID, normal appointments do not have globalID * so if any normal appointment if found then it is assumed to be conflict. */ if (isset($calendarItem[$this->proptags['goid']])) { if ($calendarItem[$this->proptags['goid']] !== $messageProps[$this->proptags['goid']]) { $noOfInstances++; break; } } else { $noOfInstances++; break; } } } } if ($noOfInstances > 0) { $returnValue = $noOfInstances; } } else { // Get all items in the timeframe that we want to book, and get the goid and busystatus for each item $items = getCalendarItems($userStore, $calFolder, $messageProps[$this->proptags['startdate']], $messageProps[$this->proptags['duedate']], array($this->proptags['goid'], $this->proptags['busystatus'])); foreach ($items as $item) { if ($item[$this->proptags['busystatus']] !== fbFree) { if (isset($item[$this->proptags['goid']])) { if ($item[$this->proptags['goid']] !== $messageProps[$this->proptags['goid']] && $item[$this->proptags['goid']] !== $messageProps[$this->proptags['goid2']]) { $returnValue = true; break; } } else { $returnValue = true; break; } } } } } return $returnValue; }
/** * Function which checks whether received meeting request is either conflicting with other appointments or not. *@return mixed(boolean/integer) true if normal meeting is conflicting or an integer which specifies no of instances * conflict of recurring meeting and false if meeting is not conflicting. */ function isMeetingConflicting($message = false, $userStore = false, $calFolder = false, $msgprops = false) { $returnValue = false; $conflicting = false; $noOfInstances = 0; if (!$message) { $message = $this->message; } if (!$userStore) { $userStore = $this->store; } if (!$calFolder) { $root = mapi_msgstore_openentry($userStore); $rootprops = mapi_getprops($root, array(PR_STORE_ENTRYID, PR_IPM_APPOINTMENT_ENTRYID, PR_FREEBUSY_ENTRYIDS)); if (!isset($rootprops[PR_IPM_APPOINTMENT_ENTRYID])) { return; } $calFolder = mapi_msgstore_openentry($userStore, $rootprops[PR_IPM_APPOINTMENT_ENTRYID]); } if (!$msgprops) { $msgprops = mapi_getprops($message, array($this->proptags['goid'], $this->proptags['goid2'], $this->proptags['startdate'], $this->proptags['duedate'], $this->proptags['recurring'], $this->proptags['clipstart'], $this->proptags['clipend'])); } if ($calFolder) { // Meeting request is recurring, so get all occurrence and check for each occurrence whether it conflicts with other appointments in Calendar. if (isset($msgprops[$this->proptags['recurring']]) && $msgprops[$this->proptags['recurring']]) { // Apply recurrence class and retrieve all occurrences(max: 30 occurrence because recurrence can also be set as 'no end date') $recurr = new Recurrence($userStore, $message); $items = $recurr->getItems($msgprops[$this->proptags['clipstart']], $msgprops[$this->proptags['clipend']] * (24 * 24 * 60), 30); foreach ($items as $item) { // Get all items in the timeframe that we want to book, and get the goid and busystatus for each item $calendarItems = $recurr->getCalendarItems($userStore, $calFolder, $item[$this->proptags['startdate']], $item[$this->proptags['duedate']], array($this->proptags['goid'], $this->proptags['busystatus'], PR_OWNER_APPT_ID)); foreach ($calendarItems as $calendarItem) { if ($calendarItem[$this->proptags['busystatus']] != fbFree) { /** * Only meeting requests have globalID, normal appointments do not have globalID * so if any normal appointment if found then it is assumed to be conflict. */ if (isset($calendarItem[$this->proptags['goid']])) { if ($calendarItem[$this->proptags['goid']] !== $msgprops[$this->proptags['goid']]) { $noOfInstances++; break; } } else { $noOfInstances++; break; } } } } $returnValue = $noOfInstances; } else { // Get all items in the timeframe that we want to book, and get the goid and busystatus for each item $items = getCalendarItems($userStore, $calFolder, $msgprops[$this->proptags['startdate']], $msgprops[$this->proptags['duedate']], array($this->proptags['goid'], $this->proptags['busystatus'], PR_OWNER_APPT_ID)); foreach ($items as $item) { if ($item[$this->proptags['busystatus']] != fbFree) { if (isset($item[$this->proptags['goid']])) { if ($item[$this->proptags['goid']] !== $msgprops[$this->proptags['goid']] && $item[$this->proptags['goid']] !== $msgprops[$this->proptags['goid2']]) { $conflicting = true; break; } } else { $conflicting = true; break; } } } if ($conflicting) { $returnValue = true; } } } return $returnValue; }
/** * Note: Static function, more like a utility function. * * Gets all the items (including recurring items) in the specified calendar in the given timeframe. Items are * included as a whole if they overlap the interval <$start, $end> (non-inclusive). This means that if the interval * is <08:00 - 14:00>, the item [6:00 - 8:00> is NOT included, nor is the item [14:00 - 16:00>. However, the item * [7:00 - 9:00> is included as a whole, and is NOT capped to [8:00 - 9:00>. * * @param $store resource The store in which the calendar resides * @param $calendar resource The calendar to get the items from * @param $viewstart int Timestamp of beginning of view window * @param $viewend int Timestamp of end of view window * @param $propsrequested array Array of properties to return * @param $rows array Array of rowdata as if they were returned directly from mapi_table_queryrows. Each recurring item is * expanded so that it seems that there are only many single appointments in the table. */ function getCalendarItems($store, $calendar, $viewstart, $viewend, $propsrequested) { $result = array(); $properties = getPropIdsFromStrings($store, array("duedate" => "PT_SYSTIME:PSETID_Appointment:0x820e", "startdate" => "PT_SYSTIME:PSETID_Appointment:0x820d", "enddate_recurring" => "PT_SYSTIME:PSETID_Appointment:0x8236", "recurring" => "PT_BOOLEAN:PSETID_Appointment:0x8223", "recurring_data" => "PT_BINARY:PSETID_Appointment:0x8216", "timezone_data" => "PT_BINARY:PSETID_Appointment:0x8233", "label" => "PT_LONG:PSETID_Appointment:0x8214")); // Create a restriction that will discard rows of appointments that are definitely not in our // requested time frame $table = mapi_folder_getcontentstable($calendar); $restriction = array(RES_OR, array(array(RES_AND, array(array(RES_PROPERTY, array(RELOP => RELOP_GT, ULPROPTAG => $properties["duedate"], VALUE => $viewstart)), array(RES_PROPERTY, array(RELOP => RELOP_LT, ULPROPTAG => $properties["startdate"], VALUE => $viewend)))), array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => $properties["recurring"], VALUE => true)))); // global OR // Get requested properties, plus whatever we need $proplist = array(PR_ENTRYID, $properties["recurring"], $properties["recurring_data"], $properties["timezone_data"]); $proplist = array_merge($proplist, $propsrequested); $propslist = array_unique($proplist); $rows = mapi_table_queryallrows($table, $proplist, $restriction); // $rows now contains all the items that MAY be in the window; a recurring item needs expansion before including in the output. foreach ($rows as $row) { $items = array(); if (isset($row[$properties["recurring"]]) && $row[$properties["recurring"]]) { // Recurring item $rec = new Recurrence($store, $row); // GetItems guarantees that the item overlaps the interval <$viewstart, $viewend> $occurrences = $rec->getItems($viewstart, $viewend); foreach ($occurrences as $occurrence) { // The occurrence takes all properties from the main row, but overrides some properties (like start and end obviously) $item = $occurrence + $row; array_push($items, $item); } } else { // Normal item, it matched the search criteria and therefore overlaps the interval <$viewstart, $viewend> array_push($items, $row); } $result = array_merge($result, $items); } // All items are guaranteed to overlap the interval <$viewstart, $viewend>. Note that we may be returning a few extra // properties that the caller did not request (recurring, etc). This shouldn't be a problem though. return $result; }