예제 #1
0
 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'));
 }
예제 #2
0
 public static function SaveEvent($Params)
 {
     $arFields = $Params['arFields'];
     if (self::$type && !isset($arFields['CAL_TYPE'])) {
         $arFields['CAL_TYPE'] = self::$type;
     }
     if (self::$bOwner && !isset($arFields['OWNER_ID'])) {
         $arFields['OWNER_ID'] = self::$ownerId;
     }
     if (!isset($arFields['SKIP_TIME']) && isset($arFields['DT_SKIP_TIME'])) {
         $arFields['SKIP_TIME'] = $arFields['DT_SKIP_TIME'] == 'Y';
     }
     $userId = isset($Params['userId']) ? $Params['userId'] : self::GetCurUserId();
     $sectionId = is_array($arFields['SECTIONS']) && count($arFields['SECTIONS']) > 0 ? $arFields['SECTIONS'][0] : 0;
     $bPersonal = self::IsPersonal($arFields['CAL_TYPE'], $arFields['OWNER_ID'], $userId);
     if (!isset($arFields['DATE_FROM']) && !isset($arFields['DATE_TO']) && isset($arFields['DT_FROM']) && isset($arFields['DT_TO'])) {
         $arFields['DATE_FROM'] = $arFields['DT_FROM'];
         $arFields['DATE_TO'] = $arFields['DT_TO'];
     }
     // Fetch current event
     $oCurEvent = false;
     $bNew = !isset($arFields['ID']) || !$arFields['ID'];
     if (!$bNew) {
         $oCurEvent = CCalendarEvent::GetList(array('arFilter' => array("ID" => intVal($arFields['ID']), "DELETED" => "N"), 'parseRecursion' => false, 'fetchAttendees' => $Params['bSilentAccessMeeting'] === true, 'fetchMeetings' => false, 'userId' => $userId));
         if ($oCurEvent) {
             $oCurEvent = $oCurEvent[0];
         }
         $bPersonal = $bPersonal && self::IsPersonal($oCurEvent['CAL_TYPE'], $oCurEvent['OWNER_ID'], $userId);
         $arFields['CAL_TYPE'] = $oCurEvent['CAL_TYPE'];
         $arFields['OWNER_ID'] = $oCurEvent['OWNER_ID'];
         $arFields['CREATED_BY'] = $oCurEvent['CREATED_BY'];
         $arFields['ACTIVE'] = $oCurEvent['ACTIVE'];
         $bChangeMeeting = $arFields['CAL_TYPE'] != 'user' && CCalendarSect::CanDo('calendar_edit', $oCurEvent['SECT_ID'], self::$userId);
         if (!isset($arFields['NAME'])) {
             $arFields['NAME'] = $oCurEvent['NAME'];
         }
         if (!isset($arFields['DESCRIPTION'])) {
             $arFields['DESCRIPTION'] = $oCurEvent['DESCRIPTION'];
         }
         if (!isset($arFields['COLOR']) && $oCurEvent['COLOR']) {
             $arFields['COLOR'] = $oCurEvent['COLOR'];
         }
         if (!isset($arFields['TEXT_COLOR']) && $oCurEvent['TEXT_COLOR']) {
             $arFields['TEXT_COLOR'] = $oCurEvent['TEXT_COLOR'];
         }
         if (!isset($arFields['SECTIONS'])) {
             $arFields['SECTIONS'] = array($oCurEvent['SECT_ID']);
             $sectionId = is_array($arFields['SECTIONS']) && count($arFields['SECTIONS']) > 0 ? $arFields['SECTIONS'][0] : 0;
         }
         if (!isset($arFields['IS_MEETING'])) {
             $arFields['IS_MEETING'] = $oCurEvent['IS_MEETING'];
         }
         if (!isset($arFields['ACTIVE'])) {
             $arFields['ACTIVE'] = $oCurEvent['ACTIVE'];
         }
         if (!isset($arFields['PRIVATE_EVENT'])) {
             $arFields['PRIVATE_EVENT'] = $oCurEvent['PRIVATE_EVENT'];
         }
         if (!isset($arFields['ACCESSIBILITY'])) {
             $arFields['ACCESSIBILITY'] = $oCurEvent['ACCESSIBILITY'];
         }
         if (!isset($arFields['IMPORTANCE'])) {
             $arFields['IMPORTANCE'] = $oCurEvent['IMPORTANCE'];
         }
         if (!isset($arFields['LOCATION']) && $oCurEvent['LOCATION'] != "") {
             $arFields['LOCATION'] = array("OLD" => $oCurEvent['LOCATION'], "NEW" => $oCurEvent['LOCATION']);
         }
         if (!$bPersonal && !$bChangeMeeting) {
             $arFields['IS_MEETING'] = $oCurEvent['IS_MEETING'];
             if ($arFields['IS_MEETING']) {
                 $arFields['SECTIONS'] = array($oCurEvent['SECT_ID']);
             }
         }
         if ($oCurEvent['IS_MEETING']) {
             $arFields['MEETING_HOST'] = $oCurEvent['MEETING_HOST'];
         }
         // If it's attendee and but modifying called from CalDav methods
         if ($Params['bSilentAccessMeeting'] && $oCurEvent['IS_MEETING'] && $oCurEvent['PARENT_ID'] != $oCurEvent['ID']) {
             return true;
             // CalDav will return 204
         }
         if (!$bPersonal && !CCalendarSect::CanDo('calendar_edit', $oCurEvent['SECT_ID'], self::$userId)) {
             return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
         }
         if (!isset($arFields["RRULE"]) && $oCurEvent["RRULE"] != '' && $Params['fromWebservice'] !== true) {
             $arFields["RRULE"] = CCalendarEvent::ParseRRULE($oCurEvent["RRULE"]);
         }
         if ($Params['fromWebservice'] === true) {
             if ($arFields["RRULE"] == -1 && CCalendarEvent::CheckRecurcion($oCurEvent)) {
                 $arFields["RRULE"] = CCalendarEvent::ParseRRULE($oCurEvent['RRULE']);
             }
         }
         if ($oCurEvent) {
             $Params['currentEvent'] = $oCurEvent;
         }
         if (!$bPersonal && !CCalendarSect::CanDo('calendar_edit', $oCurEvent['SECT_ID'], self::$userId)) {
             return GetMessage('EC_ACCESS_DENIED');
         }
     } elseif ($sectionId > 0 && !$bPersonal && !CCalendarSect::CanDo('calendar_add', $sectionId, self::$userId)) {
         return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
     }
     if ($Params['autoDetectSection'] && $sectionId <= 0) {
         $sectionId = false;
         if ($arFields['CAL_TYPE'] == 'user') {
             $sectionId = CCalendarSect::GetLastUsedSection('user', $arFields['OWNER_ID'], $userId);
             if ($sectionId) {
                 $res = CCalendarSect::GetList(array('arFilter' => array('CAL_TYPE' => $arFields['CAL_TYPE'], 'OWNER_ID' => $arFields['OWNER_ID'], 'ID' => $sectionId)));
                 if (!$res || !$res[0]) {
                     $sectionId = false;
                 }
             } else {
                 $sectionId = false;
             }
             if ($sectionId) {
                 $arFields['SECTIONS'] = array($sectionId);
             }
         }
         if (!$sectionId) {
             $sectRes = self::GetSectionForOwner($arFields['CAL_TYPE'], $arFields['OWNER_ID'], $Params['autoCreateSection']);
             if ($sectRes['sectionId'] > 0) {
                 $arFields['SECTIONS'] = array($sectRes['sectionId']);
                 if ($sectRes['autoCreated']) {
                     $Params['bAffectToDav'] = false;
                 }
             } else {
                 return false;
             }
         }
     }
     if (isset($arFields["RRULE"])) {
         $arFields["RRULE"] = CCalendarEvent::CheckRRULE($arFields["RRULE"]);
     }
     // Set version
     if (!isset($arFields['VERSION']) || $arFields['VERSION'] <= $oCurEvent['VERSION']) {
         $arFields['VERSION'] = $oCurEvent['VERSION'] ? $oCurEvent['VERSION'] + 1 : 1;
     }
     if ($Params['autoDetectSection'] && $sectionId <= 0 && $arFields['OWNER_ID'] > 0) {
         $res = CCalendarSect::GetList(array('arFilter' => array('CAL_TYPE' => $arFields['CAL_TYPE'], 'OWNER_ID' => $arFields['OWNER_ID']), 'checkPermissions' => false));
         if ($res && is_array($res) && isset($res[0])) {
             $sectionId = $res[0]['ID'];
         } elseif ($Params['autoCreateSection']) {
             $defCalendar = CCalendarSect::CreateDefault(array('type' => $arFields['CAL_TYPE'], 'ownerId' => $arFields['OWNER_ID']));
             $sectionId = $defCalendar['ID'];
             $Params['bAffectToDav'] = false;
         }
         if ($sectionId > 0) {
             $arFields['SECTIONS'] = array($sectionId);
         } else {
             return false;
         }
     }
     $bExchange = CCalendar::IsExchangeEnabled() && $arFields['CAL_TYPE'] == 'user';
     $bCalDav = CCalendar::IsCalDAVEnabled() && $arFields['CAL_TYPE'] == 'user';
     if ($Params['bAffectToDav'] !== false && ($bExchange || $bCalDav) && $sectionId > 0) {
         $res = CCalendar::DoSaveToDav(array('bCalDav' => $bCalDav, 'bExchange' => $bExchange, 'sectionId' => $sectionId), $arFields, $oCurEvent);
         if ($res !== true) {
             return CCalendar::ThrowError($res);
         }
     }
     $Params['arFields'] = $arFields;
     $Params['userId'] = $userId;
     if (self::$ownerId != $arFields['OWNER_ID'] && self::$type != $arFields['CAL_TYPE']) {
         $Params['path'] = self::GetPath($arFields['CAL_TYPE'], $arFields['OWNER_ID'], 1);
     } else {
         $Params['path'] = self::$path;
     }
     $id = CCalendarEvent::Edit($Params);
     $UFs = $Params['UF'];
     if (isset($UFs) && count($UFs) > 0) {
         CCalendarEvent::UpdateUserFields($id, $UFs);
         if ($arFields['IS_MEETING']) {
             if (!empty($UFs['UF_WEBDAV_CAL_EVENT'])) {
                 $UF = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields("CALENDAR_EVENT", $id, LANGUAGE_ID);
                 CCalendar::UpdateUFRights($UFs['UF_WEBDAV_CAL_EVENT'], $arFields['ATTENDEES_CODES'], $UF['UF_WEBDAV_CAL_EVENT']);
             }
         }
     }
     $arFields['ID'] = $id;
     foreach (GetModuleEvents("calendar", "OnAfterCalendarEventEdit", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array('arFields' => $arFields, 'bNew' => $bNew, 'userId' => $userId));
     }
     return $id;
 }