예제 #1
0
	public function UpdateListItems($listName, $updates)
	{
		global $USER;

		$arStatusValues = array_flip($this->arStatusValues);
		$arPriorityValues = array_flip($this->arPriorityValues);

		if (!$listName_original = CIntranetUtils::checkGUID($listName))
			return new CSoapFault('Data error', 'Wrong GUID - '.$listName);

		$obResponse = new CXMLCreator('Results');

		$listName = ToUpper(CIntranetUtils::makeGUID($listName_original));
		$arSections = CCalendarSect::GetList(array('arFilter' => array('XML_ID' => $listName_original)));
		if (!$arSections || !is_array($arSections[0]))
			return new CSoapFault(
				'List not found',
				'List with '.$listName.' GUID not found'
			);
		$arSection = $arSections[0];

		$bGroup = $arSection['CAL_TYPE'] == 'group';
		$calType = $arSection['CAL_TYPE'];
		$ownerId = $arSection['OWNER_ID'];

		if ($bGroup)
		{
			CModule::IncludeModule('socialnetwork');
			$arGroupTmp = CSocNetGroup::GetByID($arSection['SOCNET_GROUP_ID']);
			if ($arGroupTmp["CLOSED"] == "Y")
				if (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") != "Y")
					return new CSoapFault('Cannot modify archive group calendar', 'Cannot modify archive group calendar');
		}

		$obBatch = $updates->children[0];
		$atrONERROR = $obBatch->getAttribute('OnError');
		$atrDATEINUTC = $obBatch->getAttribute('DateInUtc');
		$atrPROPERTIES = $obBatch->getAttribute('Properties');

		$arChanges = $obBatch->children;

		$arResultIDs = array();
		$dateStart = ConvertTimeStamp(strtotime('-1 hour'), 'FULL');
		$arResponseRows = array();
		$arReplicationIDs = array();
		$userId = (is_object($USER) && $USER->GetID()) ? $USER->GetID() : 1;

		foreach ($arChanges as $obMethod)
		{
			$arData = array('_command' => $obMethod->getAttribute('Cmd'));

			foreach ($obMethod->children as $obField)
			{
				$name = $obField->getAttribute('Name');
				if ($name == 'MetaInfo')
					$name .= '_'.$obField->getAttribute('Property');

				$arData[$name] = $obField->content;
			}

			if ($arData['_command'] == 'Delete')
			{
				$obRes = new CXMLCreator('Result');
				$obRes->setAttribute('ID', $obMethod->getAttribute('ID').','.$arData['_command']);
				$obRes->setAttribute('List', $listName);
				$obRes->addChild($obNode = new CXMLCreator('ErrorCode'));

				$res = CCalendar::DeleteEvent($arData['ID']);
				if ($res === true)
					$obNode->setData('0x00000000');
				else
					$obNode->setData('0x81020014');

				/*
					0x00000000 - ok
					0x81020015 - data conflict
					0x81020014 - generic error such as invalid value for Field
					0x81020016 - item does not exist
				*/

				$obResponse->addChild($obRes);
			}
			elseif ($arData['_command'] == 'New' || $arData['_command'] == 'Update')
			{
				$q = ToLower($arData['Description']);
				if (($pos = strrpos($q, '</body>')) !== false) $arData['Description'] = substr($arData['Description'], 0, $pos);
				if (($pos = strpos($q, '<body>')) !== false) $arData['Description'] = substr($arData['Description'], $pos + 6);

				$arData['Description'] = str_replace('</DIV>', "\r\n</DIV>", $arData['Description']);
				$arData['Description'] = str_replace(array("&#10;", "&#13;"), "", $arData['Description']);
				$arData['Description'] = preg_replace("/<![^>]*>/", '', $arData['Description']);
				//$arData['Description'] = strip_tags($arData['Description']);
				$arData['Description'] = trim($arData['Description']);

				$arData['Location'] = trim($arData['Location']);

				if (isset($arData['EventDate']))
				{
					$arData['EventDate'] = $this->__makeTS($arData['EventDate']);
					$arData['EndDate'] = $this->__makeTS($arData['EndDate']) + ($arData['fAllDayEvent'] ? -86340 : 0);
					$TZBias = intval(date('Z', $arData['EventDate']));
				}

				$arData['EventType'] = intval($arData['EventType']);

				if ($arData['EventType'] == 2)
					$arData['EventType'] = 0;

				if ($arData['EventType'] > 2 /* || ($arData['EventType'] == 1 && !$arData['RecurrenceData'])*/)
					return new CSoapFault(
						'Unsupported event type',
						'Event type unsupported'
					);

				$arData['fRecurrence'] = intval($arData['fRecurrence']);
				$arData['RRULE'] = '';

				$id = $arData['_command'] == 'New' ? 0 : intVal($arData['ID']);
				if ($arData['RecurrenceData'])
				{
					//$xmlstr = $arData['XMLTZone'];
					//$arData['XMLTZone'] = new CDataXML();
					//$arData['XMLTZone']->LoadString($xmlstr);

					$xmlstr = $arData['RecurrenceData'];
					$obRecurData = new CDataXML();
					$obRecurData->LoadString($xmlstr);

/*
<recurrence>
		<rule>
			<firstDayOfWeek>mo</firstDayOfWeek>
			<repeat>
				<weekly mo='TRUE' tu='TRUE' th='TRUE' sa='TRUE' weekFrequency='1' />
			</repeat>
			<repeatForever>FALSE</repeatForever>
		</rule>
</recurrence>
<deleteExceptions>true</deleteExceptions>
*/

					$obRecurRule = $obRecurData->tree->children[0]->children[0];
					$obRecurRepeat = $obRecurRule->children[1];
					$obNode = $obRecurRepeat->children[0];

					$arData['RRULE'] = array();
					switch($obNode->name)
					{
						case 'daily':
							// hack. we have no "work days" daily recurence
							if ($obNode->getAttribute('weekday') == 'TRUE')
							{
								$arData['RRULE']['FREQ'] = 'WEEKLY';
								$arData['RRULE']['BYDAY'] = 'MO,TU,WE,TH,FR';
								$arData['RRULE']['INTERVAL'] = 1;
							}
							else
							{
								$arData['RRULE']['FREQ'] = 'DAILY';
								$arData['RRULE']['INTERVAL'] = $obNode->getAttribute('dayFrequency');
							}

							$time_end = strtotime(
								date(date('Y-m-d', $arData['EventDate']).' H:i:s', $arData['EndDate'])
							);

							$arData['DT_LENGTH'] = $time_end - $arData['EventDate'];
						break;

						case 'weekly':
							$arData['RRULE']['FREQ'] = 'WEEKLY';
							$arData['RRULE']['BYDAY'] = '';

							$arWeekDays = array('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su');
							foreach ($arWeekDays as $day => $value)
							{
								if ($obNode->getAttribute($value))
									$arData['RRULE']['BYDAY'][] = strtoupper($value);
							}

							$arData['RRULE']['BYDAY'] = implode(',', $arData['RRULE']['BYDAY']);
							$arData['RRULE']['INTERVAL'] = $obNode->getAttribute('weekFrequency');

							$time_end = strtotime(date(date('Y-m-d', $arData['EventDate']).' H:i:s', $arData['EndDate']));

							$arData['DT_LENGTH'] = $time_end - $arData['EventDate'];
						break;

						case 'monthly':
							$arData['RRULE']['FREQ'] = 'MONTHLY';
							$arData['RRULE']['INTERVAL'] = $obNode->getAttribute('monthFrequency');
							$time_end = strtotime(date(date('Y-m', $arData['EventDate']).'-d H:i:s', $arData['EndDate']));

							$arData['DT_LENGTH'] = $time_end - $arData['EventDate'];
						break;

						case 'yearly':
							$arData['RRULE']['FREQ'] = 'YEARLY';
							$arData['RRULE']['INTERVAL'] = $obNode->getAttribute('yearFrequency');

							$time_end = strtotime(date(date('Y', $arData['EventDate']).'-m-d H:i:s', $arData['EndDate']));

							$arData['DT_LENGTH'] = $time_end - $arData['EventDate'];
						break;
					}

					if ($arData['DT_LENGTH'] == 0 && isset($arData['RRULE']['FREQ']))
						$arData['DT_LENGTH'] = 86400;

					$obWhile = $obRecurRule->children[2];
					if ($obWhile->name == 'repeatForever')
					{
						$arData['EndDate'] = MakeTimeStamp('');
					}
					elseif ($obWhile->name == 'windowEnd')
					{
						$arData['EndDate'] = $this->__makeTS($obWhile->textContent());
						$arData['RRULE']['UNTIL'] = ConvertTimeStamp($arData['EndDate'], 'FULL');
					}
				}
				elseif($arData['fRecurrence'] == -1 && $id > 0)
				{
					$arData['RRULE'] = -1;
				}

				if (isset($arData['EventDate']))
				{
					$skipTime = $arData['fAllDayEvent'] ? 'Y' : 'N';
					$TZBias = $arData['fAllDayEvent'] ? 0 : $TZBias;
					$arData['EventDate'] += $TZBias;
					$arData['EndDate'] += $TZBias;

//					$arData["DT_FROM"] = ConvertTimeStamp($arData['EventDate'], 'FULL');
//					$arData["DT_TO"] = ConvertTimeStamp($arData['EndDate'], 'FULL');
				}
				else
				{
					$arData["DT_FROM"] = -1;
					$arData["DT_TO"] = -1;
				}

				// fields
				$arFields = array(
					"ID" => $id,
					'CAL_TYPE' => $calType,
					'OWNER_ID' => $ownerId,
					'CREATED_BY' => $userId,
					'DT_FROM_TS' => $arData['EventDate'],
					'DT_TO_TS' => $arData['EndDate'],
					'DT_SKIP_TIME' => $skipTime,
//					"DT_FROM" => $arData["DT_FROM"],
//					"DT_TO" => $arData["DT_TO"],
					'NAME' => $arData['Title'],
					'DESCRIPTION' => CCalendar::ParseHTMLToBB($arData['Description']),
					'SECTIONS' => array($arSection['ID']),
					'ACCESSIBILITY' => $arStatusValues[$arData['MetaInfo_BusyStatus']],
					'IMPORTANCE' => $arPriorityValues[$arData['MetaInfo_Priority']],
					'RRULE' => $arData['RRULE'],
					'LOCATION' => CCalendar::UnParseTextLocation($arData['Location'])
				);

				if (isset($arData['DT_LENGTH']) && $arData['DT_LENGTH'] > 0)
					$arFields['DT_LENGTH'] = $arData['DT_LENGTH'];

				$EventID = CCalendar::SaveEvent(
					array(
						'arFields' => $arFields,
						'fromWebservice' => true
					)
				);

				if ($EventID)
				{
					// dirty hack
					$arReplicationIDs[$EventID] = $arData['MetaInfo_ReplicationID'];

					$arResponseRows[$EventID] = new CXMLCreator('Result');
					$arResponseRows[$EventID]->setAttribute('ID', $obMethod->getAttribute('ID').','.$arData['_command']);
					$arResponseRows[$EventID]->setAttribute('List', $listName);

					$arResponseRows[$EventID]->addChild($obNode = new CXMLCreator('ErrorCode'));
					$obNode->setData('0x00000000');
					//$arResponseRows[$EventID]->setAttribute('Version', 3);
				}
			}
		}

		$userId = (is_object($USER) && $USER->GetID()) ? $USER->GetID() : 1;
		$fetchMeetings = CCalendar::GetMeetingSection($userId) == $arSection['ID'];
		$arEvents = CCalendarEvent::GetList(
			array(
				'arFilter' => array(
					'CAL_TYPE' => $calType,
					'OWNER_ID' => $ownerId,
					'SECTION' => $arSection['ID'],
					//'INCLUDE_INVITINGS' => 'N'
				),
				'getUserfields' => false,
				'parseRecursion' => false,
				'fetchAttendees' => false,
				'fetchMeetings' => $fetchMeetings,
				'userId' => $userId
			)
		);

		foreach ($arEvents as $key => $event)
		{
			if ($arResponseRows[$event['ID']])
			{
				$obRow = $this->__getRow($event, $listName, $last_change = 0);
				$obRow->setAttribute('xmlns:z', "#RowsetSchema");
				if ($arReplicationIDs[$event['ID']])
					$obRow->setAttribute('MetaInfo_ReplicationID', $arReplicationIDs[$event['ID']]);

				$arResponseRows[$event['ID']]->addChild($obRow);
			}
			$obResponse->addChild($arResponseRows[$event['ID']]);
		}
		return array('UpdateListItemsResult' => $obResponse);
	}
예제 #2
0
 public static function GetMeetingSection($userId, $bCreate = false)
 {
     if (isset(self::$meetingSections[$userId])) {
         return self::$meetingSections[$userId];
     }
     $result = false;
     if ($userId > 0) {
         $set = CCalendar::GetUserSettings($userId);
         $result = $set['meetSection'];
         if ($result && !CCalendarSect::GetById($result, true, true)) {
             $result = false;
         }
         if (!$result) {
             $res = CCalendarSect::GetList(array('arFilter' => array('CAL_TYPE' => 'user', 'OWNER_ID' => $userId)));
             if ($res && count($res) > 0 && $res[0]['ID']) {
                 $result = $res[0]['ID'];
             }
             if (!$result && $bCreate) {
                 $defCalendar = CCalendarSect::CreateDefault(array('type' => 'user', 'ownerId' => $userId));
                 if ($defCalendar && $defCalendar['ID'] > 0) {
                     $result = $defCalendar['ID'];
                 }
             }
             if ($result) {
                 $set['meetSection'] = $result;
                 CCalendar::SetUserSettings($set, $userId);
             }
         }
     }
     self::$meetingSections[$userId] = $result;
     return $result;
 }
예제 #3
0
 public static function ReturnICal($Params)
 {
     $sectId = $Params['sectId'];
     $userId = intVal($Params['userId']);
     $sign = $Params['sign'];
     $type = strtolower($Params['type']);
     $ownerId = intVal($Params['ownerId']);
     $bCache = false;
     $GLOBALS['APPLICATION']->RestartBuffer();
     if (!self::CheckSign($sign, $userId, $sectId)) {
         return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
     }
     $arSections = CCalendarSect::GetList(array('arFilter' => array('ID' => $sectId), 'checkPermissions' => false));
     if ($arSections && $arSections[0] && $arSections[0]['EXPORT'] && $arSections[0]['EXPORT']['ALLOW']) {
         $arSection = $arSections[0];
         $arEvents = CCalendarEvent::GetList(array('arFilter' => array('SECTION' => $arSection['ID']), 'getUserfields' => false, 'parseRecursion' => false, 'fetchAttendees' => false, 'fetchMeetings' => true, 'userId' => $userId));
         $iCalEvents = self::FormatICal($arSection, $arEvents);
     } else {
         return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
     }
     self::ShowICalHeaders();
     echo $iCalEvents;
     exit;
 }
예제 #4
0
 public static function SectionGet($arParams = array(), $nav = null, $server = null)
 {
     $userId = CCalendar::GetCurUserId();
     $methodName = "calendar.section.get";
     if (isset($arParams['type'])) {
         $type = $arParams['type'];
     } else {
         throw new Exception(GetMessage('CAL_REST_PARAM_EXCEPTION', array('#REST_METHOD#' => $methodName, '#PARAM_NAME#' => 'type')));
     }
     if (isset($arParams['ownerId'])) {
         $ownerId = intval($arParams['ownerId']);
     } elseif ($type == 'user') {
         $ownerId = $userId;
     } else {
         throw new Exception(GetMessage('CAL_REST_PARAM_EXCEPTION', array('#REST_METHOD#' => $methodName, '#PARAM_NAME#' => 'ownerId')));
     }
     $arFilter = array('CAL_TYPE' => $type, 'OWNER_ID' => $ownerId, 'ACTIVE' => "Y");
     $res = CCalendarSect::GetList(array('arFilter' => $arFilter));
     foreach ($res as $i => $section) {
         unset($res[$i]['OUTLOOK_JS'], $res[$i]['DAV_EXCH_CAL'], $res[$i]['DAV_EXCH_MOD'], $res[$i]['SORT'], $res[$i]['PARENT_ID'], $res[$i]['IS_EXCHANGE'], $res[$i]['EXTERNAL_ID'], $res[$i]['ACTIVE'], $res[$i]['CAL_DAV_MOD'], $res[$i]['CAL_DAV_CAL'], $res[$i]['XML_ID']);
     }
     return $res;
 }
예제 #5
0
 public static function Edit($Params = array())
 {
     global $DB, $CACHE_MANAGER;
     $arFields = $Params['arFields'];
     $arAffectedSections = array();
     $result = false;
     // Get current user id
     $userId = isset($Params['userId']) && intVal($Params['userId']) > 0 ? intVal($Params['userId']) : CCalendar::GetCurUserId();
     if (!$userId && isset($arFields['CREATED_BY'])) {
         $userId = intVal($arFields['CREATED_BY']);
     }
     $path = !empty($Params['path']) ? $Params['path'] : CCalendar::GetPath($arFields['CAL_TYPE'], $arFields['OWNER_ID'], true);
     $bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0;
     $arFields['TIMESTAMP_X'] = CCalendar::Date(mktime(), true, false);
     if ($bNew) {
         if (!isset($arFields['CREATED_BY'])) {
             $arFields['CREATED_BY'] = $arFields['IS_MEETING'] && $arFields['CAL_TYPE'] == 'user' && $arFields['OWNER_ID'] ? $arFields['OWNER_ID'] : $userId;
         }
         if (!isset($arFields['DATE_CREATE'])) {
             $arFields['DATE_CREATE'] = $arFields['TIMESTAMP_X'];
         }
     }
     if (!isset($arFields['OWNER_ID']) || !$arFields['OWNER_ID']) {
         $arFields['OWNER_ID'] = 0;
     }
     // Current event
     $currentEvent = array();
     if (!$bNew) {
         if (isset($Params['currentEvent'])) {
             $currentEvent = $Params['currentEvent'];
         } else {
             $currentEvent = CCalendarEvent::GetById($arFields['ID']);
         }
         if (!isset($arFields['LOCATION']['OLD']) && $currentEvent) {
             $arFields['LOCATION']['OLD'] = $currentEvent['LOCATION'];
         }
         if ($currentEvent['IS_MEETING'] && !isset($arFields['ATTENDEES']) && $currentEvent['PARENT_ID'] == $currentEvent['ID'] && $arFields['IS_MEETING']) {
             $arFields['ATTENDEES'] = array();
             $attendees = self::GetAttendees($currentEvent['PARENT_ID']);
             if ($attendees[$currentEvent['PARENT_ID']]) {
                 for ($i = 0, $l = count($attendees[$currentEvent['PARENT_ID']]); $i < $l; $i++) {
                     $arFields['ATTENDEES'][] = $attendees[$currentEvent['PARENT_ID']][$i]['USER_ID'];
                 }
             }
         }
         if (($currentEvent['IS_MEETING'] || $arFields['IS_MEETING']) && $currentEvent['PARENT_ID']) {
             $arFields['PARENT_ID'] = $currentEvent['PARENT_ID'];
         }
     }
     if ($userId > 0 && self::CheckFields($arFields, $currentEvent, $userId)) {
         if ($arFields['CAL_TYPE'] == 'user') {
             $CACHE_MANAGER->ClearByTag('calendar_user_' . $arFields['OWNER_ID']);
         }
         $attendees = is_array($arFields['ATTENDEES']) ? $arFields['ATTENDEES'] : array();
         if (!$arFields['PARENT_ID']) {
             $fromTs = $arFields['DATE_FROM_TS_UTC'];
             $toTs = $arFields['DATE_TO_TS_UTC'];
             if ($arFields['DT_SKIP_TIME'] == "Y") {
                 //$toTs += CCalendar::GetDayLen();
             } else {
                 $fromTs += date('Z', $arFields['DATE_FROM_TS_UTC']);
                 $toTs += date('Z', $arFields['DATE_TO_TS_UTC']);
             }
             $arFields['LOCATION'] = CCalendar::SetLocation($arFields['LOCATION']['OLD'], $arFields['LOCATION']['NEW'], array('dateFrom' => CCalendar::Date($fromTs, $arFields['DT_SKIP_TIME'] !== "Y"), 'dateTo' => CCalendar::Date($toTs, $arFields['DT_SKIP_TIME'] !== "Y"), 'name' => $arFields['NAME'], 'persons' => count($attendees), 'attendees' => $attendees, 'bRecreateReserveMeetings' => $arFields['LOCATION']['RE_RESERVE'] !== 'N'));
         } else {
             $arFields['LOCATION'] = CCalendar::GetTextLocation($arFields['LOCATION']['NEW']);
         }
         $bSendInvitations = $Params['bSendInvitations'] !== false;
         if (!isset($arFields['IS_MEETING']) && isset($arFields['ATTENDEES']) && is_array($arFields['ATTENDEES']) && empty($arFields['ATTENDEES'])) {
             $arFields['IS_MEETING'] = false;
         }
         $attendeesCodes = array();
         if ($arFields['IS_MEETING'] && is_array($arFields['MEETING'])) {
             if (!empty($arFields['ATTENDEES_CODES'])) {
                 $attendeesCodes = $arFields['ATTENDEES_CODES'];
                 $arFields['ATTENDEES_CODES'] = implode(',', $arFields['ATTENDEES_CODES']);
             }
             $arFields['~MEETING'] = array('HOST_NAME' => $arFields['MEETING']['HOST_NAME'], 'TEXT' => $arFields['MEETING']['TEXT'], 'OPEN' => $arFields['MEETING']['OPEN'], 'NOTIFY' => $arFields['MEETING']['NOTIFY'], 'REINVITE' => $arFields['MEETING']['REINVITE']);
             $arFields['MEETING'] = serialize($arFields['~MEETING']);
             if (!isset($arFields['MEETING_STATUS'])) {
                 $arFields['MEETING_STATUS'] = 'H';
             }
         }
         $arReminders = array();
         if (is_array($arFields['REMIND'])) {
             foreach ($arFields['REMIND'] as $remind) {
                 if (in_array($remind['type'], array('min', 'hour', 'day'))) {
                     $arReminders[] = array('type' => $remind['type'], 'count' => floatVal($remind['count']));
                 }
             }
         } elseif ($currentEvent['REMIND']) {
             $arReminders = $currentEvent['REMIND'];
         }
         $arFields['REMIND'] = count($arReminders) > 0 ? serialize($arReminders) : '';
         $AllFields = self::GetFields();
         $dbFields = array();
         foreach ($arFields as $field => $val) {
             if (isset($AllFields[$field]) && $field != "ID") {
                 $dbFields[$field] = $arFields[$field];
             }
         }
         CTimeZone::Disable();
         if ($bNew) {
             $eventId = CDatabase::Add("b_calendar_event", $dbFields, array('DESCRIPTION', 'MEETING', 'RDATE', 'EXDATE'));
         } else {
             $eventId = $arFields['ID'];
             $strUpdate = $DB->PrepareUpdate("b_calendar_event", $dbFields);
             $strSql = "UPDATE b_calendar_event SET " . $strUpdate . " WHERE ID=" . IntVal($eventId);
             $DB->QueryBind($strSql, array('DESCRIPTION' => $arFields['DESCRIPTION'], 'MEETING' => $arFields['MEETING'], 'RDATE' => $arFields['RDATE'], 'EXDATE' => $arFields['EXDATE']));
         }
         CTimeZone::Enable();
         if ($bNew && !isset($dbFields['DAV_XML_ID'])) {
             $strSql = "UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array('DAV_XML_ID' => $eventId)) . " WHERE ID=" . IntVal($eventId);
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         // *** Check and update section links ***
         $sectionId = is_array($arFields['SECTIONS']) && $arFields['SECTIONS'][0] ? intVal($arFields['SECTIONS'][0]) : false;
         if ($sectionId && CCalendarSect::GetById($sectionId, false)) {
             if (!$bNew) {
                 $arAffectedSections[] = $currentEvent['SECT_ID'];
             }
             self::ConnectEventToSection($eventId, $sectionId);
         } else {
             // It's new event we have to find section where to put it automatically
             if ($bNew) {
                 if ($arFields['IS_MEETING'] && $arFields['PARENT_ID'] && $arFields['CAL_TYPE'] == 'user') {
                     $sectionId = CCalendar::GetMeetingSection($arFields['OWNER_ID']);
                 } else {
                     $sectionId = CCalendarSect::GetLastUsedSection($arFields['CAL_TYPE'], $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) {
                     $sectRes = CCalendarSect::GetSectionForOwner($arFields['CAL_TYPE'], $arFields['OWNER_ID'], true);
                     $sectionId = $sectRes['sectionId'];
                 }
                 self::ConnectEventToSection($eventId, $sectionId);
             } else {
                 // It's existing event, we take it's section to update modification lables (no db changes in b_calendar_event_sect)
                 $sectionId = $currentEvent['SECT_ID'];
             }
         }
         $arAffectedSections[] = $sectionId;
         if (count($arAffectedSections) > 0) {
             CCalendarSect::UpdateModificationLabel($arAffectedSections);
         }
         $bPull = CModule::IncludeModule("pull");
         if ($arFields['IS_MEETING'] || !$bNew && $currentEvent['IS_MEETING']) {
             if (!$arFields['PARENT_ID']) {
                 $DB->Query("UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array("PARENT_ID" => $eventId)) . " WHERE ID=" . intVal($eventId), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
             }
             if (!$arFields['PARENT_ID'] || $arFields['PARENT_ID'] == $eventId) {
                 self::CreateChildEvents($eventId, $arFields, $Params, $userId);
             }
             if (!$arFields['PARENT_ID']) {
                 $arFields['PARENT_ID'] = intVal($eventId);
             }
         } else {
             if ($bNew && !$arFields['PARENT_ID'] || !$bNew && !$currentEvent['PARENT_ID']) {
                 $DB->Query("UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array("PARENT_ID" => $eventId)) . " WHERE ID=" . intVal($eventId), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
                 if (!$arFields['PARENT_ID']) {
                     $arFields['PARENT_ID'] = intVal($eventId);
                 }
             }
             if ($bPull) {
                 $curUserId = $userId;
                 if ($arFields['PARENT_ID'] && $arFields['PARENT_ID'] !== $arFields['ID']) {
                     $curUserId = $arFields['OWNER_ID'];
                 }
                 CPullStack::AddByUser($curUserId, array('module_id' => 'calendar', 'command' => 'event_update', 'params' => array('EVENT' => CCalendarEvent::OnPullPrepareArFields($arFields), 'ATTENDEES' => array(), 'NEW' => $bNew ? 'Y' : 'N')));
             }
         }
         // Clean old reminders and add new reminders
         self::UpdateReminders(array('id' => $eventId, 'reminders' => $arReminders, 'arFields' => $arFields, 'userId' => $userId, 'path' => $path, 'bNew' => $bNew));
         // Send invitations and notivications
         if ($arFields['IS_MEETING']) {
             if ($bSendInvitations) {
                 if ($arFields['PARENT_ID'] != $eventId) {
                     $CACHE_MANAGER->ClearByTag('calendar_user_' . $arFields['OWNER_ID']);
                     $fromTo = CCalendarEvent::GetEventFromToForUser($arFields, $arFields['OWNER_ID']);
                     CCalendar::SendMessage(array('mode' => 'invite', 'name' => $arFields['NAME'], "from" => $fromTo['DATE_FROM'], "to" => $fromTo['DATE_TO'], "location" => CCalendar::GetTextLocation($arFields["LOCATION"]), "meetingText" => $arFields["~MEETING"]["TEXT"], "guestId" => $arFields['OWNER_ID'], "eventId" => $arFields['PARENT_ID'], "userId" => $userId));
                 }
             } else {
                 if ($arFields['PARENT_ID'] != $eventId && $arFields['MEETING_STATUS'] == "Y") {
                     $CACHE_MANAGER->ClearByTag('calendar_user_' . $arFields['OWNER_ID']);
                     $fromTo = CCalendarEvent::GetEventFromToForUser($arFields, $arFields['OWNER_ID']);
                     CCalendar::SendMessage(array('mode' => 'change_notify', 'name' => $arFields['NAME'], "from" => $fromTo['DATE_FROM'], "to" => $fromTo['DATE_TO'], "location" => CCalendar::GetTextLocation($arFields["LOCATION"]), "meetingText" => $arFields["~MEETING"]["TEXT"], "guestId" => $arFields['OWNER_ID'], "eventId" => $arFields['PARENT_ID'], "userId" => $userId));
                 }
             }
         }
         if ($arFields['CAL_TYPE'] == 'user' && $arFields['IS_MEETING'] && !empty($attendeesCodes) && $arFields['PARENT_ID'] == $eventId) {
             CCalendarLiveFeed::OnEditCalendarEventEntry($eventId, $arFields, $attendeesCodes);
         }
         CCalendar::ClearCache('event_list');
         $result = $eventId;
     }
     return $result;
 }
예제 #6
0
 public static function OnSocNetGroupDelete($groupId)
 {
     $groupId = intVal($groupId);
     if ($groupId > 0) {
         $res = CCalendarSect::GetList(array('arFilter' => array('CAL_TYPE' => 'group', 'OWNER_ID' => $groupId), 'checkPermissions' => false));
         foreach ($res as $sect) {
             CCalendarSect::Delete($sect['ID'], false);
         }
     }
     return true;
 }