示例#1
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);
     // Fetch current event
     // 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['DT_FROM_TS']) && !isset($arFields['DT_FROM'])) {
             $arFields['DT_FROM_TS'] = $oCurEvent['DT_FROM_TS'];
         }
         if (!isset($arFields['DT_TO_TS']) && !isset($arFields['DT_TO'])) {
             if (isset($arFields['DT_FROM_TS'])) {
                 $arFields['DT_TO_TS'] = $arFields['DT_FROM_TS'] + $oCurEvent['DT_LENGTH'];
                 if ($arFields['SKIP_TIME']) {
                     $arFields['DT_TO_TS'] -= self::GetDayLen();
                 }
             } else {
                 $arFields['DT_TO_TS'] = $oCurEvent['DT_TO_TS'];
             }
         }
         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 (!$bPersonal && !CCalendarSect::CanDo('calendar_edit', $oCurEvent['SECT_ID'], self::$userId)) {
             // If it's attendee but modifying called from CalDav methods
             if ($Params['bSilentAccessMeeting'] && $oCurEvent['IS_MEETING']) {
                 foreach ($oCurEvent['~ATTENDEES'] as $att) {
                     if ($att['USER_ID'] == $userId) {
                         return true;
                     }
                 }
                 // CalDav will return 204
             }
             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 ($arFields['DT_FROM'] == -1) {
                 $arFields['DT_FROM_TS'] = $oCurEvent['DT_FROM_TS'];
                 $arFields['DT_TO_TS'] = $arFields['DT_FROM_TS'] + $oCurEvent['DT_LENGTH'];
                 if ($oCurEvent['DT_SKIP_TIME'] == 'Y') {
                     $arFields['DT_TO_TS'] -= self::GetDayLen();
                 }
             }
         }
         if (self::IsCalDAVEnabled() && $oCurEvent['SECT_ID'] != $sectionId) {
             // Check if it's CalDav section for one or another section
             $calDavCon = CCalendarSect::GetCalDAVConnectionId(array($oCurEvent['SECT_ID'], $sectionId));
             if ($calDavCon[$sectionId] != $calDavCon['SECT_ID']) {
                 // create new
                 $arFieldsNew = $arFields;
                 unset($arFieldsNew['ID']);
                 $newId = self::SaveEvent(array('arFields' => $arFieldsNew));
                 if ($newId) {
                     // Delete
                     self::DeleteEvent($arFields['ID']);
                 }
                 return $newId;
             }
         }
         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) {
         $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;
         }
     }
     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;
     }
     $offset = CCalendar::GetOffset();
     if (!isset($arFields['DT_FROM_TS'])) {
         $arFields['DT_FROM_TS'] = self::Timestamp($arFields['DT_FROM']);
         $arFields['DT_TO_TS'] = self::Timestamp($arFields['DT_TO']);
     }
     if (!isset($arFields['SKIP_TIME'])) {
         $item['DT_SKIP_TIME'] = date('H:i', $arFields['DT_FROM_TS']) == '00:00' && date('H:i', $arFields['DT_TO_TS']) == '00:00';
     }
     if ($Params['bServerTime'] !== true && !$arFields['SKIP_TIME'] && $offset != 0) {
         $arFields['DT_FROM_TS'] -= $offset;
         $arFields['DT_TO_TS'] -= $offset;
     }
     $arFields['DT_FROM'] = self::Date($arFields['DT_FROM_TS']);
     $arFields['DT_TO'] = self::Date($arFields['DT_TO_TS']);
     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;
 }
示例#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::$userId;
     $sectionId = is_array($arFields['SECTIONS']) && count($arFields['SECTIONS']) > 0 ? $arFields['SECTIONS'][0] : 0;
     $bPersonal = self::IsPersonal($arFields['CAL_TYPE'], $arFields['OWNER_ID'], $userId);
     // Fetch current event
     $oCurEvent = false;
     if ($arFields['ID'] > 0) {
         $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];
         }
         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 (!$bPersonal && !CCalendarSect::CanDo('calendar_edit', $oCurEvent['SECT_ID'], self::$userId)) {
             // If it's attendee but modifying called from CalDav methods
             if ($Params['bSilentAccessMeeting'] && $oCurEvent['IS_MEETING']) {
                 foreach ($oCurEvent['~ATTENDEES'] as $att) {
                     if ($att['USER_ID'] == $userId) {
                         return true;
                     }
                 }
                 // CalDav will return 204
             }
             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 ($arFields['DT_FROM'] == -1) {
                 $arFields['DT_FROM_TS'] = $oCurEvent['DT_FROM_TS'];
                 $arFields['DT_TO_TS'] = $arFields['DT_FROM_TS'] + $oCurEvent['DT_LENGTH'];
                 if ($oCurEvent['DT_SKIP_TIME'] == 'Y') {
                     $arFields['DT_TO_TS'] -= self::GetDayLen();
                 }
             }
         }
         if (self::IsCalDAVEnabled() && $oCurEvent['SECT_ID'] != $sectionId) {
             // Check if it's CalDav section for one or another section
             $calDavCon = CCalendarSect::GetCalDAVConnectionId(array($oCurEvent['SECT_ID'], $sectionId));
             if ($calDavCon[$sectionId] != $calDavCon['SECT_ID']) {
                 // create new
                 $arFieldsNew = $arFields;
                 unset($arFieldsNew['ID']);
                 $newId = self::SaveEvent(array('arFields' => $arFieldsNew));
                 if ($newId) {
                     // Delete
                     self::DeleteEvent($arFields['ID']);
                 }
                 return $newId;
             }
         }
     } elseif ($sectionId > 0 && !$bPersonal && !CCalendarSect::CanDo('calendar_add', $sectionId, self::$userId)) {
         return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
     }
     // Set version
     $arFields['VERSION'] = $oCurEvent['VERSION'] ? $oCurEvent['VERSION'] + 1 : 1;
     $offset = CCalendar::GetOffset();
     if (!isset($arFields['DT_FROM_TS'])) {
         $arFields['DT_FROM_TS'] = self::Timestamp($arFields['DT_FROM']);
         $arFields['DT_TO_TS'] = self::Timestamp($arFields['DT_TO']);
     }
     if (!isset($arFields['SKIP_TIME'])) {
         $item['DT_SKIP_TIME'] = date('H:i', $arFields['DT_FROM_TS']) == '00:00' && date('H:i', $arFields['DT_TO_TS']) == '00:00';
     }
     if ($Params['bServerTime'] !== true && !$arFields['SKIP_TIME'] && $offset != 0) {
         $arFields['DT_FROM_TS'] -= $offset;
         $arFields['DT_TO_TS'] -= $offset;
     }
     $arFields['DT_FROM'] = self::Date($arFields['DT_FROM_TS']);
     $arFields['DT_TO'] = self::Date($arFields['DT_TO_TS']);
     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);
     return $id;
 }