/** * Do the scheduling adjustments for a REPLY when an ATTENDEE updates their status. * @param vCalendar $resource The resource that the ATTENDEE is writing to their calendar * @param string $organizer The property which is the event ORGANIZER. */ function do_scheduling_reply(vCalendar $resource, vProperty $organizer) { global $request; $organizer_email = preg_replace('/^mailto:/i', '', $organizer->Value()); $organizer_principal = new Principal('email', $organizer_email); if (!$organizer_principal->Exists()) { dbg_error_log('PUT', 'Organizer "%s" not found - cannot perform scheduling reply.', $organizer); return false; } $sql = 'SELECT caldav_data.dav_name, caldav_data.caldav_data FROM caldav_data JOIN calendar_item USING(dav_id) '; $sql .= 'WHERE caldav_data.collection_id IN (SELECT collection_id FROM collection WHERE is_calendar AND user_no =?) '; $sql .= 'AND uid=? LIMIT 1'; $uids = $resource->GetPropertiesByPath('/VCALENDAR/*/UID'); if (count($uids) == 0) { dbg_error_log('PUT', 'No UID in VCALENDAR - giving up on REPLY.'); return false; } $uid = $uids[0]->Value(); $qry = new AwlQuery($sql, $organizer_principal->user_no(), $uid); if (!$qry->Exec('PUT', __LINE__, __FILE__) || $qry->rows() < 1) { dbg_error_log('PUT', 'Could not find original event from organizer - giving up on REPLY.'); return false; } $row = $qry->Fetch(); $attendees = $resource->GetAttendees(); foreach ($attendees as $v) { $email = preg_replace('/^mailto:/i', '', $v->Value()); if ($email == $request->principal->email()) { $attendee = $v; } } if (empty($attendee)) { dbg_error_log('PUT', 'Could not find ATTENDEE in VEVENT - giving up on REPLY.'); return false; } $schedule_original = new vCalendar($row->caldav_data); $schedule_original->UpdateAttendeeStatus($request->principal->email(), clone $attendee); $collection_path = preg_replace('{/[^/]+$}', '/', $row->dav_name); $segment_name = str_replace($collection_path, '', $row->dav_name); $organizer_calendar = new WritableCollection(array('path' => $collection_path)); $organizer_inbox = new WritableCollection(array('path' => $organizer_principal->internal_url('schedule-inbox'))); $schedule_reply = clone $schedule_original; $schedule_reply->AddProperty('METHOD', 'REPLY'); dbg_error_log('PUT', 'Writing scheduling REPLY from %s to %s', $request->principal->email(), $organizer_principal->email()); $response = '3.7'; // Organizer was not found on server. if (!$organizer_calendar->Exists()) { dbg_error_log('ERROR', 'Default calendar at "%s" does not exist for user "%s"', $organizer_calendar->dav_name(), $schedule_target->username()); $response = '5.2'; // No scheduling support for user } else { if (!$organizer_inbox->HavePrivilegeTo('schedule-deliver-reply')) { $response = '3.8'; // No authority to deliver replies to organizer. } else { if ($organizer_inbox->WriteCalendarMember($schedule_reply, false, false, $request->principal->username() . $segment_name) !== false) { $response = '1.2'; // Scheduling reply delivered successfully if ($organizer_calendar->WriteCalendarMember($schedule_original, false, false, $segment_name) === false) { dbg_error_log('ERROR', 'Could not write updated calendar member to %s', $attendee_calendar->dav_name(), $attendee_calendar->dav_name(), $schedule_target->username()); trace_bug('Failed to write scheduling resource.'); } } } } $schedule_request = clone $schedule_original; $schedule_request->AddProperty('METHOD', 'REQUEST'); dbg_error_log('PUT', 'Status for organizer <%s> set to "%s"', $organizer->Value(), $response); $organizer->SetParameterValue('SCHEDULE-STATUS', $response); $resource->UpdateOrganizerStatus($organizer); $scheduling_actions = true; $calling_attendee = clone $attendee; $attendees = $schedule_original->GetAttendees(); foreach ($attendees as $attendee) { $email = preg_replace('/^mailto:/i', '', $attendee->Value()); if ($email == $request->principal->email() || $email == $organizer_principal->email()) { continue; } $agent = $attendee->GetParameterValue('SCHEDULE-AGENT'); if ($agent && $agent != 'SERVER') { dbg_error_log("PUT", "not delivering to %s, schedule agent set to value other than server", $email); continue; } // an attendee's reply should modify only the PARTSTAT on other attendees' objects // other properties (that might have been adjusted individually by those other // attendees) should remain unmodified. Therefore, we have to make $schedule_original // and $schedule_request be initialized by each attendee's object here. $attendee_principal = new DAVPrincipal(array('email' => $email, 'options' => array('allow_by_email' => true))); if ($attendee_principal == false) { dbg_error_log('PUT', 'Could not find attendee %s', $email); continue; } $sql = 'SELECT caldav_data.dav_name, caldav_data.caldav_data, caldav_data.collection_id FROM caldav_data JOIN calendar_item USING(dav_id) '; $sql .= 'WHERE caldav_data.collection_id IN (SELECT collection_id FROM collection WHERE is_calendar AND user_no =?) '; $sql .= 'AND uid=? LIMIT 1'; $qry = new AwlQuery($sql, $attendee_principal->user_no(), $uid); if (!$qry->Exec('PUT', __LINE__, __FILE__) || $qry->rows() < 1) { dbg_error_log('PUT', "Could not find attendee's event %s", $uid); } $row = $qry->Fetch(); $schedule_original = new vCalendar($row->caldav_data); $schedule_original->UpdateAttendeeStatus($request->principal->email(), clone $calling_attendee); $schedule_request = clone $schedule_original; $schedule_request->AddProperty('METHOD', 'REQUEST'); $schedule_target = new Principal('email', $email); $response = '3.7'; // Attendee was not found on server. if ($schedule_target->Exists()) { // Instead of always writing to schedule-default-calendar, we first try to // find a calendar with an existing instance of the event in any calendar of this attendee. $r = new DAVResource($row); $attendee_calendar = new WritableCollection(array('path' => $r->parent_path())); if ($attendee_calendar->IsCalendar()) { dbg_error_log('XXX', "found the event in attendee's calendar %s", $attendee_calendar->dav_name()); } else { dbg_error_log('XXX', 'could not find the event in any calendar, using schedule-default-calendar'); $attendee_calendar = new WritableCollection(array('path' => $schedule_target->internal_url('schedule-default-calendar'))); } if (!$attendee_calendar->Exists()) { dbg_error_log('ERROR', 'Default calendar at "%s" does not exist for user "%s"', $attendee_calendar->dav_name(), $schedule_target->username()); $response = '5.2'; // No scheduling support for user } else { $attendee_inbox = new WritableCollection(array('path' => $schedule_target->internal_url('schedule-inbox'))); if (!$attendee_inbox->HavePrivilegeTo('schedule-deliver-invite')) { $response = '3.8'; // No authority to deliver invitations to user. } else { if ($attendee_inbox->WriteCalendarMember($schedule_request, false) !== false) { $response = '1.2'; // Scheduling invitation delivered successfully if ($attendee_calendar->WriteCalendarMember($schedule_original, false) === false) { dbg_error_log('ERROR', 'Could not write updated calendar member to %s', $attendee_calendar->dav_name(), $attendee_calendar->dav_name(), $schedule_target->username()); trace_bug('Failed to write scheduling resource.'); } } } } } dbg_error_log('PUT', 'Status for attendee <%s> set to "%s"', $attendee->Value(), $response); $attendee->SetParameterValue('SCHEDULE-STATUS', $response); $scheduling_actions = true; $resource->UpdateAttendeeStatus($email, clone $attendee); } return $scheduling_actions; }
printf("%s\n", $sql); } $qry = new AwlQuery($sql); if ($qry->Exec() && $qry->rows()) { while ($alarm = $qry->Fetch()) { if ($args->debug) { printf("refresh: Processing alarm for '%s' based on '%s','%s', '%s'\n", $alarm->dav_name, $alarm->dtstart, $alarm->rrule, $alarm->trigger); } $ic = new vComponent($alarm->caldav_data); $expanded = expand_event_instances($ic, $earliest, $expand_range_end); $expanded->MaskComponents(array('VEVENT' => 1, 'VTODO' => 1, 'VJOURNAL' => 1)); $instances = $expanded->GetComponents(); $trigger = new vProperty($alarm->trigger); $related = $trigger->GetParameterValue('RELATED'); $first = new RepeatRuleDateTime($alarm->dtstart); $first->modify($trigger->Value()); $next = null; $last = null; foreach ($instances as $k => $component) { $when = new RepeatRuleDateTime($component->GetPValue('DTSTART')); // a UTC value if ($args->debug) { printf("refresh: Looking at event instance on '%s'\n", $when->UTC()); } if ($related == 'END') { $when->modify($component->GetPValue('DURATION')); } $when->modify($trigger->Value()); if ($when > $expand_range_start && $when < $expand_range_end && (!isset($next) || $when < $next)) { $next = clone $when; }
/** * Adds a new property * * @param vProperty $new_property The new property to append to the set, or a string with the name * @param string $value The value of the new property (default: param 1 is an vProperty with everything * @param array $parameters The key/value parameter pairs (default: none, or param 1 is an vProperty with everything) */ function AddProperty($new_property, $value = null, $parameters = null) { if (isset($this->rendered)) { unset($this->rendered); } if (isset($value) && gettype($new_property) == 'string') { $new_prop = new vProperty(); $new_prop->Name($new_property); $new_prop->Value($value); if ($parameters != null) { $new_prop->Parameters($parameters); } dbg_error_log('vComponent', " Adding new property '%s'", $new_prop->Render()); $this->properties[] = $new_prop; } else { if (gettype($new_property)) { $this->properties[] = $new_property; } } }
/** * Delivers the iTIP CANCEL message to an ATTENDEE's Scheduling Inbox Collection. * * This is pretty simple at present, but could be extended in the future to do the sending * of e-mail to a remote attendee. * * @param vCalendar $iTIP * @param vProperty $attendee * @param WritableCollection $attendee_inbox */ function deliverItipCancel(vCalendar $iTIP, vProperty $attendee, WritableCollection $attendee_inbox) { $attendee_inbox->WriteCalendarMember($iTIP, false); header("Debug: Could maybe do the iMIP message dance canceling for attendee: " . $attendee->Value()); }