public static function SetMeetingStatus($userId, $eventId, $status = 'Q', $comment = '') { global $DB; $eventId = intVal($eventId); $userId = intVal($userId); if (!in_array($status, array("Q", "Y", "N"))) { $status = "Q"; } // Select meeting info about event CTimeZone::Disable(); $res = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "DELETED" => "N"), 'fetchMeetings' => true, 'parseRecursion' => false, 'setDefaultLimit' => false)); $Event = $res[0]; if ($Event && $Event['IS_MEETING']) { if ($Event['IS_MEETING']) { $arAffectedSections = array($Event['SECT_ID']); // Try to find this user into attendees for this event $strSql = "SELECT * FROM b_calendar_attendees WHERE USER_KEY={$userId} AND EVENT_ID={$eventId}"; $dbAtt = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $curStatus = "Q"; if ($att = $dbAtt->Fetch()) { $curStatus = $att["STATUS"]; //Set status if ($att["STATUS"] != $status) { $strSql = "UPDATE b_calendar_attendees SET " . $DB->PrepareUpdate("b_calendar_attendees", array("STATUS" => $status, "DESCRIPTION" => $comment)) . " WHERE EVENT_ID=" . $eventId . " AND USER_KEY=" . $userId; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } else { if ($Event['MEETING'] && $Event['MEETING']['OPEN'] && $status == "Y") { //Set status $strSql = "INSERT INTO b_calendar_attendees(EVENT_ID, USER_KEY, USER_ID, STATUS, DESCRIPTION, ACCESSIBILITY) " . "VALUES (" . $eventId . ", '" . $userId . "', " . $userId . ", '" . $status . "', '" . $DB->ForSql($comment) . "','')"; $res = $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); } } if (($status == 'Y' || ($status = 'N')) && CModule::IncludeModule("im")) { CIMNotify::DeleteByTag("CALENDAR|INVITE|" . $eventId . "|" . $userId); } if ($Event['MEETING']['NOTIFY'] && $status != 'Q' && $userId != $Event['CREATED_BY'] && $curStatus != $status) { // Send message to the author CCalendar::SendMessage(array('mode' => $status == "Y" ? 'accept' : 'decline', 'name' => $Event['NAME'], "from" => $Event["DT_FROM"], "to" => $Event["DT_TO"], "location" => CCalendar::GetTextLocation($Event["LOCATION"]), "comment" => $comment, "guestId" => $userId, "eventId" => $eventId, "userId" => $Event['CREATED_BY'])); } $arAffectedSections[] = CCalendar::GetMeetingSection($userId); if (count($arAffectedSections) > 0) { CCalendarSect::UpdateModificationLabel($arAffectedSections); } } } CTimeZone::Enable(); CCalendar::ClearCache(array('attendees_list', 'event_list')); }
public static function SetMeetingStatus($userId, $eventId, $status = 'Q', $comment = '', $parentEventId) { CTimeZone::Disable(); global $DB, $CACHE_MANAGER; $eventId = intVal($eventId); $userId = intVal($userId); if (!in_array($status, array("Q", "Y", "N", "H", "M"))) { $status = "Q"; } $event = CCalendarEvent::GetById($eventId, false); if ($event && $event['IS_MEETING'] && intVal($event['PARENT_ID']) > 0) { $strSql = "UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array("MEETING_STATUS" => $status)) . " WHERE PARENT_ID=" . intVal($event['PARENT_ID']) . " AND OWNER_ID=" . $userId; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); CCalendarSect::UpdateModificationLabel($event['SECT_ID']); // If it's open meeting and our attendee is not on the list if ($event['MEETING'] && $event['MEETING']['OPEN'] && ($status == 'Y' || $status == 'M')) { $arAttendees = self::GetAttendees(array($event['PARENT_ID'])); $arAttendees = $arAttendees[$event['PARENT_ID']]; $attendeeExist = false; foreach ($arAttendees as $attendee) { if ($attendee['USER_ID'] == $userId) { $attendeeExist = true; break; } } if (!$attendeeExist) { // 1. Create another childEvent for new attendee $AllFields = self::GetFields(); $dbFields = array(); foreach ($event as $field => $val) { if (isset($AllFields[$field]) && $field != "ID" && $field != "ATTENDEES_CODES") { $dbFields[$field] = $event[$field]; } } $dbFields['MEETING_STATUS'] = $status; $dbFields['CAL_TYPE'] = 'user'; $dbFields['OWNER_ID'] = $userId; $dbFields['PARENT_ID'] = $event['PARENT_ID']; $dbFields['MEETING'] = serialize($event['MEETING']); $dbFields['REMIND'] = serialize($event['REMIND']); $eventId = CDatabase::Add("b_calendar_event", $dbFields, array('DESCRIPTION', 'MEETING', 'RDATE', 'EXDATE')); $DB->Query("UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array('DAV_XML_ID' => $eventId)) . " WHERE ID=" . IntVal($eventId), false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $sectionId = CCalendarSect::GetLastUsedSection('user', $userId, $userId); if (!$sectionId || !CCalendarSect::GetById($sectionId, false)) { $sectRes = CCalendarSect::GetSectionForOwner('user', $userId); $sectionId = $sectRes['sectionId']; } if ($eventId && $sectionId) { self::ConnectEventToSection($eventId, $sectionId); } // 2. Update ATTENDEES_CODES $attendeesCodes = $event['ATTENDEES_CODES']; $attendeesCodes[] = 'U' . intVal($userId); $attendeesCodes = array_unique($attendeesCodes); $DB->Query("UPDATE b_calendar_event SET " . "ATTENDEES_CODES='" . implode(',', $attendeesCodes) . "'" . " WHERE PARENT_ID=" . intVal($event['PARENT_ID']), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); CCalendarSect::UpdateModificationLabel(array($sectionId)); } } // Notify author of event if ($event['MEETING']['NOTIFY'] && $userId != $event['MEETING_HOST']) { // Send message to the author $fromTo = CCalendarEvent::GetEventFromToForUser($event, $event['MEETING_HOST']); CCalendar::SendMessage(array('mode' => $status == "Y" ? 'accept' : 'decline', 'name' => $event['NAME'], "from" => $fromTo["DATE_FROM"], "to" => $fromTo["DATE_TO"], "location" => CCalendar::GetTextLocation($event["LOCATION"]), "comment" => $comment, "guestId" => $userId, "eventId" => $event['PARENT_ID'], "userId" => $event['MEETING_HOST'])); } CCalendarSect::UpdateModificationLabel(array($event['SECTIONS'][0])); $CACHE_MANAGER->ClearByTag('calendar_user_' . $userId); $CACHE_MANAGER->ClearByTag('calendar_user_' . $event['CREATED_BY']); } CTimeZone::Enable(); CCalendar::ClearCache(array('attendees_list', 'event_list')); }