Esempio n. 1
0
 function Delete($arParams)
 {
     global $DB, $USER;
     $iblockId = $arParams['iblockId'];
     $ownerType = $arParams['ownerType'];
     $ownerId = $arParams['ownerId'];
     $ID = $arParams['id'];
     $userId = $arParams['userId'];
     if ($USER) {
         $ownerName = $USER->GetFullName();
     } else {
         $rs = CUser::GetByID($userId);
         if ($arUser = $rs->Fetch()) {
             $name = trim($arUser['NAME'] . ' ' . $arUser['LAST_NAME']);
         }
     }
     $pathToUserCalendar = $arParams['pathToUserCalendar'];
     $arFilter = array("ID" => $ID, "IBLOCK_ID" => $iblockId);
     if ($arParams['bCheckPermissions'] !== false) {
         $arFilter[$ownerType == 'USER' ? "CREATED_BY" : "SOCNET_GROUP_ID"] = $ownerId;
     }
     $rsElement = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID", "XML_ID", "IBLOCK_ID", "PROPERTY_PRIVATE", "PROPERTY_ACCESSIBILITY", "PROPERTY_IMPORTANCE", "PROPERTY_PARENT", "PROPERTY_LOCATION", "NAME", "DETAIL_TEXT", "IBLOCK_SECTION_ID", "ACTIVE_FROM", "ACTIVE_TO", "CREATED_BY", "PROPERTY_BXDAVEX_LABEL", "PROPERTY_BXDAVCD_LABEL"));
     if ($arElement = $rsElement->Fetch()) {
         $DB->StartTransaction();
         // PROPERTY_PARENT_VALUE - id of parent iblock element in meeting
         if (strlen($arElement["PROPERTY_PARENT_VALUE"]) > 0 && $arParams['bJustDel'] !== true) {
             if ($ownerType == 'USER') {
                 $rsHost = CIBlockElement::GetList(array(), array("=ID" => $arElement["PROPERTY_PARENT_VALUE"], "CREATED_BY" => $arElement['CREATED_BY']), false, false, array("ID", "IBLOCK_ID"));
                 // Owner delete mirror of the original event in the personal calendar
                 if ($arHost = $rsHost->Fetch()) {
                     CECEvent::Delete(array('bCheckPermissions' => false, 'id' => intVal($arHost['ID']), 'iblockId' => intVal($arHost['IBLOCK_ID']), 'ownerType' => '', 'ownerId' => 0, 'userId' => $userId, 'pathToUserCalendar' => $arParams['pathToUserCalendar'], 'pathToGroupCalendar' => $arParams['pathToGroupCalendar'], 'userIblockId' => $arParams['userIblockId'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting']));
                     $this->ClearCache($this->cachePath . 'events/' . $arHost['IBLOCK_ID'] . '/');
                     return true;
                 }
             }
             // If no exchange
             CIBlockElement::SetPropertyValues($arElement["ID"], $arElement["IBLOCK_ID"], CEventCalendar::GetConfirmedID($iblockId, "N"), "CONFIRMED");
         } else {
             if ($arParams['bSyncDAV'] !== false) {
                 // Exchange
                 if (CEventCalendar::IsExchangeEnabled() && $ownerType == 'USER' && strlen($arElement['PROPERTY_BXDAVEX_LABEL_VALUE']) > 0) {
                     $eventXmlId = $arElement['XML_ID'];
                     $exchRes = CDavExchangeCalendar::DoDeleteItem($ownerId, $eventXmlId);
                     if ($exchRes !== true) {
                         return CEventCalendar::CollectExchangeErros($exchRes);
                     }
                 }
                 if (CEventCalendar::IsCalDAVEnabled() && $ownerType == 'USER' && strlen($arElement['PROPERTY_BXDAVCD_LABEL_VALUE']) > 0) {
                     $connectionId = CECCalendar::GetCalDAVConnectionId($iblockId, $arElement['IBLOCK_SECTION_ID']);
                     $calendarCalDAVXmlId = CECCalendar::GetCalDAVXmlId($iblockId, $arElement['IBLOCK_SECTION_ID']);
                     $DAVRes = CDavGroupdavClientCalendar::DoDeleteItem($connectionId, $calendarCalDAVXmlId, $arElement['XML_ID']);
                     if ($DAVRes !== true) {
                         return CEventCalendar::CollectCalDAVErros($DAVRes);
                     }
                 }
             }
             if (strlen($arElement["PROPERTY_LOCATION_VALUE"]) > 0) {
                 $loc = CEventCalendar::ParseLocation($arElement["PROPERTY_LOCATION_VALUE"]);
                 if ($loc['mrid'] == $arParams['VMiblockId'] && $loc['mrevid'] > 0) {
                     CEventCalendar::ReleaseVR(array('mrevid' => $loc['mrevid'], 'mrid' => $loc['mrid'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting']));
                 } elseif ($loc['mrid'] > 0 && $loc['mrevid'] > 0) {
                     CEventCalendar::ReleaseMR(array('mrevid' => $loc['mrevid'], 'mrid' => $loc['mrid'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting']));
                 }
             }
             $arGuests = CECEvent::GetGuests($arParams['userIblockId'], $ID);
             $obElement = new CIBlockElement();
             foreach ($arGuests as $guest_id => $arCalendarEvent) {
                 $res = CECEvent::Delete(array('id' => $arCalendarEvent["ID"], 'iblockId' => $arParams['userIblockId'], 'ownerType' => "USER", 'ownerId' => $guest_id, 'userId' => $userId, 'bJustDel' => true));
                 if ($userId == $guest_id) {
                     continue;
                 }
                 if ($arCalendarEvent["PROPERTY_VALUES"]["CONFIRMED"] != "N") {
                     // Send message
                     CEventCalendar::SendInvitationMessage(array('type' => "cancel", 'email' => $arCalendarEvent["CREATED_BY"]["EMAIL"], 'name' => $arCalendarEvent['NAME'], "from" => $arCalendarEvent["ACTIVE_FROM"], "to" => $arCalendarEvent["ACTIVE_TO"], "desc" => $arCalendarEvent['DETAIL_TEXT'], "pathToUserCalendar" => $pathToUserCalendar, "guestId" => $guest_id, "guestName" => $arCalendarEvent["CREATED_BY"]["FULL_NAME"], "userId" => $userId, "ownerName" => $ownerName));
                 }
             }
             if ($ownerType != 'USER') {
                 CEventCalendar::ClearCache('event_calendar/events/' . $arParams['userIblockId'] . '/');
             }
             // Deleting
             if (!CIBlockElement::Delete($ID)) {
                 $DB->Rollback();
                 return '[ECD1]' . GetMessage('EC_EVENT_ERROR_DEL');
             }
         }
         // log changes for socnet
         /*			if($this->bSocNetLog && $ownerType && !$arElement["PROPERTY_PRIVATE_VALUE"] && !$arParams['dontLogEvent'])
         			{
         				CEventCalendar::SocNetLog(
         					array(
         						'target' => 'delete_event',
         						'id' => $ID,
         						'name' => $arElement['NAME'],
         						'desc' => $arElement['DETAIL_TEXT'],
         						'from' => $arElement['ACTIVE_FROM'],
         						'to' => $arElement['ACTIVE_TO'],
         						'calendarId' => $arElement['IBLOCK_SECTION_ID'],
         						'accessibility' => $arElement["PROPERTY_ACCESSIBILITY_VALUE"],
         						'importance' => $arElement["PROPERTY_IMPORTANCE_VALUE"],
         						'pathToGroupCalendar' =>  $arParams["pathToGroupCalendar"],
         						'pathToUserCalendar' =>  $arParams["pathToUserCalendar"],
         						'iblockId' => $iblockId,
         						'ownerType' => $ownerType,
         						'ownerId' => $ownerId
         					)
         				);
         			}*/
         $DB->Commit();
     } else {
         return '[ECD2]' . GetMessage('EC_EVENT_NOT_FOUND');
     }
     return true;
 }
Esempio n. 2
0
 public static function ConvertEntity($ownerType, $ownerId, $sectionId, $iblockId, $createdBy)
 {
     $eventsCount = 0;
     $sectCount = 0;
     $bs = new CIBlockSection();
     $ent_id = "IBLOCK_" . $iblockId . "_SECTION";
     $result = array('eventsCount' => 0, 'sectCount' => 0);
     $bSetAccessFromCalendar = true;
     $Access = array('G2' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_denied'));
     // CONVERT ACCESS:
     if ($ownerType == 'user') {
         if (!CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $ownerId, "calendar")) {
             return $result;
         }
         // Read
         $read = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ownerId, "calendar", 'view');
         $taskId = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view');
         if ($read == 'A') {
             // All users
             $Access['G2'] = $taskId;
         } elseif ($read == 'C') {
             // All autorized
             $Access['AU'] = $taskId;
         } elseif ($read == 'M' || $read == 'E') {
             // Friends
             $Access['SU' . $ownerId . '_F'] = $taskId;
         } elseif ($bSetAccessFromCalendar) {
             $bSetAccessFromCalendar = false;
         }
         // Write - will override read access
         $write = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ownerId, "calendar", 'write');
         $taskId = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit');
         if ($write == 'A') {
             // All users
             $Access['G2'] = $taskId;
         } elseif ($write == 'C') {
             // All autorized
             $Access['AU'] = $taskId;
         } elseif ($write == 'M' || $write == 'E') {
             // Friends
             $Access['SU' . $ownerId . '_F'] = $taskId;
         }
     } elseif ($ownerType == 'group') {
         if (!CSocNetFeatures::IsActiveFeature(SONET_ENTITY_GROUP, $ownerId, "calendar")) {
             return $result;
         }
         // Read
         $read = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $ownerId, "calendar", 'view');
         $taskId = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view');
         if ($read == 'A') {
             // Group owner
             $Access['SG' . $ownerId . '_A'] = $taskId;
         } elseif ($read == 'E') {
             // Group moderator
             $Access['SG' . $ownerId . '_E'] = $taskId;
         } elseif ($read == 'K') {
             // User
             $Access['SG' . $ownerId . '_K'] = $taskId;
         } elseif ($read == 'L') {
             // Authorized
             $Access['AU'] = $taskId;
         } elseif ($read == 'N') {
             // Authorized
             $Access['G2'] = $taskId;
         }
         // Write - will override read access
         $write = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $ownerId, "calendar", 'write');
         $taskId = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit');
         if ($write == 'A') {
             // Group owner
             $Access['SG' . $ownerId . '_A'] = $taskId;
         } elseif ($write == 'E') {
             // Group moderator
             $Access['SG' . $ownerId . '_E'] = $taskId;
         } elseif ($write == 'K') {
             // User
             $Access['SG' . $ownerId . '_K'] = $taskId;
         } elseif ($write == 'L') {
             // Authorized
             $Access['AU'] = $taskId;
         } elseif ($write == 'N') {
             // Authorized
             $Access['G2'] = $taskId;
         }
     } else {
         $arGroupPerm = CIBlock::GetGroupPermissions($iblockId);
         $taskByLetter = array('D' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_denied'), 'R' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view'), 'W' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit'), 'X' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_access'));
         foreach ($arGroupPerm as $groupId => $letter) {
             $Access['G' . $groupId] = $taskByLetter[$letter];
         }
     }
     // 1. Fetch sections
     $arUserSections = CEventCalendar::GetCalendarList(array($iblockId, $sectionId, 0, $ownerType));
     $calendarIndex = array();
     foreach ($arUserSections as $section) {
         $arUF = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields($ent_id, $section['ID']);
         if (isset($arUF["UF_CAL_CONVERTED"]) && strlen($arUF["UF_CAL_CONVERTED"]['VALUE']) > 0) {
             continue;
         }
         $SectionAccess = array();
         if ($bSetAccessFromCalendar && $ownerType == 'user') {
             if ($section['PRIVATE_STATUS'] == 'private') {
                 $deniedTask = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_denied');
                 $SectionAccess['G2'] = $deniedTask;
             } elseif ($section['PRIVATE_STATUS'] == 'time') {
                 $viewTimeTask = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view_time');
                 $SectionAccess['G2'] = $viewTimeTask;
             } elseif ($section['PRIVATE_STATUS'] == 'title') {
                 $viewTitleTask = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view_title');
                 $SectionAccess['G2'] = $viewTitleTask;
             } else {
                 $SectionAccess = $Access;
                 // nested from common access settings from socnet
             }
         } else {
             $SectionAccess = $Access;
             // G2 => denied
         }
         $new_sect_id = CCalendarSect::Edit(array('arFields' => array("CAL_TYPE" => $ownerType, "NAME" => $section['NAME'], "OWNER_ID" => $ownerId, "CREATED_BY" => $createdBy, "DESCRIPTION" => $section['DESCRIPTION'], "COLOR" => $section["COLOR"], "ACCESS" => $SectionAccess)));
         // Set converted property
         $bs->Update($section['ID'], array('UF_CAL_CONVERTED' => 1));
         $calendarIndex[$section['ID']] = $new_sect_id;
         $sectCount++;
     }
     // 2. Create events
     $arEvents = CEventCalendar::GetCalendarEventsList(array($iblockId, $sectionId, 0), array());
     foreach ($arEvents as $event) {
         if (!isset($calendarIndex[$event['IBLOCK_SECTION_ID']]) || $event['PROPERTY_PARENT'] > 0) {
             continue;
         }
         $arFields = array("CAL_TYPE" => $ownerType, "OWNER_ID" => $ownerId, "CREATED_BY" => $event["CREATED_BY"], "DT_FROM" => $event['ACTIVE_FROM'], "DT_TO" => $event['ACTIVE_TO'], 'NAME' => htmlspecialcharsback($event['NAME']), 'DESCRIPTION' => CCalendar::ParseHTMLToBB(htmlspecialcharsback($event['DETAIL_TEXT'])), 'SECTIONS' => array($calendarIndex[$event['IBLOCK_SECTION_ID']]), 'ACCESSIBILITY' => $event['PROPERTY_ACCESSIBILITY'], 'IMPORTANCE' => $event['PROPERTY_IMPORTANCE'], 'PRIVATE_EVENT' => $event['PROPERTY_PRIVATE'] && $event['PROPERTY_PRIVATE'] == 'true' ? '1' : '', 'RRULE' => array(), 'LOCATION' => array('NEW' => $event['PROPERTY_LOCATION'], 'RE_RESERVE' => 'N'), "REMIND" => array(), "IS_MEETING" => $event['PROPERTY_IS_MEETING'] == 'Y');
         if (!empty($event['PROPERTY_REMIND_SETTINGS'])) {
             $ar = explode("_", $event["PROPERTY_REMIND_SETTINGS"]);
             if (count($ar) == 2) {
                 $arFields["REMIND"][] = array('type' => $ar[1], 'count' => floatVal($ar[0]));
             }
         }
         if (isset($event["PROPERTY_PERIOD_TYPE"]) && in_array($event["PROPERTY_PERIOD_TYPE"], array("DAILY", "WEEKLY", "MONTHLY", "YEARLY"))) {
             $arFields['RRULE']['FREQ'] = $event["PROPERTY_PERIOD_TYPE"];
             $arFields['RRULE']['INTERVAL'] = $event["PROPERTY_PERIOD_COUNT"];
             if (!empty($event['PROPERTY_EVENT_LENGTH'])) {
                 $arFields['DT_LENGTH'] = intval($event['PROPERTY_EVENT_LENGTH']);
             }
             if (!$arFields['DT_LENGTH']) {
                 $arFields['DT_LENGTH'] = 86400;
             }
             if ($arFields['RRULE']['FREQ'] == "WEEKLY" && !empty($event['PROPERTY_PERIOD_ADDITIONAL'])) {
                 $arFields['RRULE']['BYDAY'] = array();
                 $bydays = explode(',', $event['PROPERTY_PERIOD_ADDITIONAL']);
                 foreach ($bydays as $day) {
                     $day = CCalendar::WeekDayByInd($day);
                     if ($day !== false) {
                         $arFields['RRULE']['BYDAY'][] = $day;
                     }
                 }
                 $arFields['RRULE']['BYDAY'] = implode(',', $arFields['RRULE']['BYDAY']);
             }
             $arFields['RRULE']['UNTIL'] = $event['ACTIVE_TO'];
         }
         if ($arFields['IS_MEETING']) {
             if ($event['PROPERTY_PARENT'] > 0) {
                 continue;
             }
             $host = intVal($event['CREATED_BY']);
             $arFields['ATTENDEES'] = array();
             if ($event['PROPERTY_HOST_IS_ABSENT'] == 'N') {
                 $arFields['ATTENDEES'][] = $host;
             }
             $arGuests = CECEvent::GetGuests(self::$userIblockId, $event['ID']);
             $attendeesStatuses = array();
             foreach ($arGuests as $userId => $ev) {
                 $attendeesStatuses[$userId] = $ev['PROPERTY_VALUES']['CONFIRMED'];
                 $arFields['ATTENDEES'][] = $userId;
             }
             $arFields['MEETING_HOST'] = $host;
             $arFields['MEETING'] = array('HOST_NAME' => CCalendar::GetUserName($host), 'TEXT' => is_array($event['PROPERTY_MEETING_TEXT']) && is_string($event['PROPERTY_MEETING_TEXT']['TEXT']) ? trim($event['PROPERTY_MEETING_TEXT']['TEXT']) : '', 'OPEN' => false, 'NOTIFY' => false, 'REINVITE' => false);
         }
         $new_event_id = CCalendar::SaveEvent(array('arFields' => $arFields, 'bAffectToDav' => false, 'attendeesStatuses' => $attendeesStatuses, 'bSendInvitations' => false));
         $eventsCount++;
     }
     // 3. Set userfield
     $bs->Update($sectionId, array('UF_CAL_CONVERTED' => 1));
     return array('eventsCount' => $eventsCount, 'sectCount' => $sectCount);
 }