Esempio n. 1
2
 public function Execute()
 {
     if (!CModule::IncludeModule("calendar")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $documentService = $this->workflow->GetService("DocumentService");
     $fromTs = CCalendar::Timestamp($this->CalendarFrom);
     $toTs = $this->CalendarTo == '' ? $fromTs : CCalendar::Timestamp($this->CalendarTo);
     $arFields = array("CAL_TYPE" => !$this->CalendarType ? 'user' : $this->CalendarType, "NAME" => trim($this->CalendarName) == '' ? GetMessage('EC_DEFAULT_EVENT_NAME') : $this->CalendarName, "DESCRIPTION" => $this->CalendarDesrc, "SKIP_TIME" => date('H:i', $fromTs) == '00:00' && date('H:i', $toTs) == '00:00', "IS_MEETING" => false, "RRULE" => false);
     if ($fromTs == $toTs && !$arFields["SKIP_TIME"]) {
         $toTs += 3600;
     }
     $arFields['DATE_FROM'] = CCalendar::Date($fromTs);
     $arFields['DATE_TO'] = CCalendar::Date($toTs);
     if ($this->CalendarSection && intVal($this->CalendarSection) > 0) {
         $arFields['SECTIONS'] = array(intVal($this->CalendarSection));
     }
     if ($this->CalendarOwnerId || $arFields["CAL_TYPE"] != "user" && $arFields["CAL_TYPE"] != "group") {
         $arFields["OWNER_ID"] = $this->CalendarOwnerId;
         $eventId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true));
     } else {
         $arCalendarUser = CBPHelper::ExtractUsers($this->CalendarUser, $documentId);
         foreach ($arCalendarUser as $calendarUser) {
             $arFields["CAL_TYPE"] = "user";
             $arFields["OWNER_ID"] = $calendarUser;
             $eventId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true));
         }
     }
     return CBPActivityExecutionStatus::Closed;
 }
Esempio n. 2
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);
	}
Esempio n. 3
0
 protected static function SaveCalendarEvent(&$arFields)
 {
     $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0;
     $typeID = isset($arFields['TYPE_ID']) ? intval($arFields['TYPE_ID']) : CCrmActivityType::Undefined;
     if (!($responsibleID > 0 && ($typeID === CCrmActivityType::Call || $typeID === CCrmActivityType::Meeting))) {
         return false;
     }
     if (!(IsModuleInstalled('calendar') && CModule::IncludeModule('calendar'))) {
         return false;
     }
     $arCalEventFields = array('CAL_TYPE' => 'user', 'OWNER_ID' => $responsibleID, 'NAME' => isset($arFields['SUBJECT']) ? $arFields['SUBJECT'] : '', 'DT_FROM' => isset($arFields['START_TIME']) ? $arFields['START_TIME'] : '', 'DT_TO' => isset($arFields['END_TIME']) ? $arFields['END_TIME'] : '', 'IMPORTANCE' => CCrmActivityPriority::ToCalendarEventImportance(isset($arFields['PRIORITY']) ? intval($arFields['PRIORITY']) : CCrmActivityPriority::Low), 'DESCRIPTION' => isset($arFields['DESCRIPTION']) ? $arFields['DESCRIPTION'] : '');
     $associatedEntityID = isset($arFields['ASSOCIATED_ENTITY_ID']) ? intval($arFields['ASSOCIATED_ENTITY_ID']) : 0;
     if ($associatedEntityID > 0) {
         $arCalEventFields['ID'] = $associatedEntityID;
         $arPresentEventFields = CCalendarEvent::GetById($associatedEntityID, false);
         if (is_array($arPresentEventFields)) {
             if (isset($arPresentEventFields['RRULE']) && $arPresentEventFields['RRULE'] != '') {
                 $arCalEventFields['RRULE'] = CCalendarEvent::ParseRRULE($arPresentEventFields['RRULE']);
             }
             if (isset($arPresentEventFields['DT_LENGTH'])) {
                 $arCalEventFields['DT_LENGTH'] = $arPresentEventFields['DT_LENGTH'];
             }
         }
     }
     if (isset($arFields['NOTIFY_TYPE']) && $arFields['NOTIFY_TYPE'] != CCrmActivityNotifyType::None) {
         $arCalEventFields['REMIND'] = array(array('type' => CCrmActivityNotifyType::ToCalendarEventRemind($arFields['NOTIFY_TYPE']), 'count' => isset($arFields['NOTIFY_VALUE']) ? intval($arFields['NOTIFY_VALUE']) : 15));
     }
     self::$IGNORE_CALENDAR_EVENTS = true;
     // We must initialize CCalendar!
     $calendar = new CCalendar();
     $calendar->Init(array('type' => 'user', 'userId' => $responsibleID, 'ownerId' => $responsibleID));
     $result = $calendar->SaveEvent(array('arFields' => $arCalEventFields, 'userId' => $responsibleID, 'autoDetectSection' => true, 'autoCreateSection' => true));
     $eventID = intval($result);
     $ownerID = intval($arFields['OWNER_ID']);
     $ownerTypeID = intval($arFields['OWNER_TYPE_ID']);
     $arBindings = isset($arFields['BINDINGS']) ? $arFields['BINDINGS'] : array();
     if (empty($arBindings) && $ownerID > 0 && $ownerTypeID > 0) {
         $arBindings[] = array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID);
     }
     if ($eventID > 0 && !empty($arBindings)) {
         $arUserFields = array();
         foreach ($arBindings as &$arBinding) {
             $arUserFields[] = CUserTypeCrm::GetShortEntityType(CCrmOwnerType::ResolveName($arBinding['OWNER_TYPE_ID'])) . '_' . $arBinding['OWNER_ID'];
         }
         unset($arBinding);
         CCalendarEvent::UpdateUserFields($eventID, array('UF_CRM_CAL_EVENT' => $arUserFields));
     }
     self::$IGNORE_CALENDAR_EVENTS = false;
     return $result;
 }
Esempio n. 4
0
 public static function ModifyEvent($calendarId, $arFields)
 {
     list($sectionId, $entityType, $entityId) = $calendarId;
     $userId = $entityType == 'user' ? $entityId : 0;
     self::$silentErrorMode = true;
     CCalendar::SetOffset(false, CCalendar::GetOffset($userId));
     $entityType = strtolower($entityType);
     $eventId = isset($arFields["ID"]) && intval($arFields["ID"]) > 0 ? intval($arFields["ID"]) : 0;
     $arNewFields = array("DAV_XML_ID" => $arFields['XML_ID'], "CAL_DAV_LABEL" => isset($arFields['PROPERTY_BXDAVCD_LABEL']) && strlen($arFields['PROPERTY_BXDAVCD_LABEL']) > 0 ? $arFields['PROPERTY_BXDAVCD_LABEL'] : '', "DAV_EXCH_LABEL" => isset($arFields['PROPERTY_BXDAVEX_LABEL']) && strlen($arFields['PROPERTY_BXDAVEX_LABEL']) > 0 ? $arFields['PROPERTY_BXDAVEX_LABEL'] : '', "ID" => $eventId, 'NAME' => $arFields["NAME"] ? $arFields["NAME"] : GetMessage('EC_NONAME_EVENT'), 'CAL_TYPE' => $entityType, 'OWNER_ID' => $entityId, 'DESCRIPTION' => isset($arFields['DESCRIPTION']) ? $arFields['DESCRIPTION'] : '', 'SECTIONS' => $sectionId, 'ACCESSIBILITY' => isset($arFields['ACCESSIBILITY']) ? $arFields['ACCESSIBILITY'] : 'busy', 'IMPORTANCE' => isset($arFields['IMPORTANCE']) ? $arFields['IMPORTANCE'] : 'normal', "REMIND" => is_array($arFields['REMIND']) ? $arFields['REMIND'] : array(), "RRULE" => is_array($arFields['RRULE']) ? is_array($arFields['RRULE']) : array(), "VERSION" => isset($arFields['VERSION']) ? intVal($arFields['VERSION']) : 1, "PRIVATE_EVENT" => !!$arFields['PRIVATE_EVENT']);
     $bServerTime = false;
     if (isset($arFields['DT_FROM_TS'], $arFields['DT_TO_TS'])) {
         $arNewFields["DT_FROM_TS"] = $arFields['DT_FROM_TS'];
         $arNewFields["DT_TO_TS"] = $arFields['DT_TO_TS'];
         $arNewFields["SKIP_TIME"] = $arFields['SKIP_TIME'];
         $bServerTime = true;
     } elseif (isset($arFields['ACTIVE_FROM'], $arFields['ACTIVE_TO'])) {
         $arNewFields["DT_FROM"] = $arFields['ACTIVE_FROM'];
         $arNewFields["DT_TO"] = $arFields['ACTIVE_TO'];
     }
     if (!empty($arFields['PROPERTY_REMIND_SETTINGS'])) {
         $ar = explode("_", $arFields["PROPERTY_REMIND_SETTINGS"]);
         if (count($ar) == 2) {
             $arNewFields["REMIND"][] = array('type' => $ar[1], 'count' => floatVal($ar[0]));
         }
     }
     if (!empty($arFields['PROPERTY_ACCESSIBILITY'])) {
         $arNewFields["ACCESSIBILITY"] = $arFields['PROPERTY_ACCESSIBILITY'];
     }
     if (!empty($arFields['PROPERTY_IMPORTANCE'])) {
         $arNewFields["IMPORTANCE"] = $arFields['PROPERTY_IMPORTANCE'];
     }
     if (!empty($arFields['PROPERTY_LOCATION'])) {
         $arNewFields["LOCATION"] = CCalendar::UnParseTextLocation($arFields['PROPERTY_LOCATION']);
     }
     if (!empty($arFields['DETAIL_TEXT'])) {
         $arNewFields["DESCRIPTION"] = $arFields['DETAIL_TEXT'];
     }
     $arNewFields["DESCRIPTION"] = CCalendar::ClearExchangeHtml($arNewFields["DESCRIPTION"]);
     if (isset($arFields["PROPERTY_PERIOD_TYPE"]) && in_array($arFields["PROPERTY_PERIOD_TYPE"], array("DAILY", "WEEKLY", "MONTHLY", "YEARLY"))) {
         $arNewFields['RRULE']['FREQ'] = $arFields["PROPERTY_PERIOD_TYPE"];
         $arNewFields['RRULE']['INTERVAL'] = $arFields["PROPERTY_PERIOD_COUNT"];
         if (!isset($arNewFields['DT_LENGTH']) && !empty($arFields['PROPERTY_EVENT_LENGTH'])) {
             $arNewFields['DT_LENGTH'] = intval($arFields['PROPERTY_EVENT_LENGTH']);
         } else {
             $arNewFields['DT_LENGTH'] = $arFields['DT_TO_TS'] - $arFields['DT_FROM_TS'];
             //$arNewFields['DT_LENGTH'] = self::GetDayLen();
         }
         if ($arNewFields['RRULE']['FREQ'] == "WEEKLY" && !empty($arFields['PROPERTY_PERIOD_ADDITIONAL'])) {
             $arNewFields['RRULE']['BYDAY'] = array();
             $bydays = explode(',', $arFields['PROPERTY_PERIOD_ADDITIONAL']);
             foreach ($bydays as $day) {
                 $day = CCalendar::WeekDayByInd($day, false);
                 if ($day !== false) {
                     $arNewFields['RRULE']['BYDAY'][] = $day;
                 }
             }
             $arNewFields['RRULE']['BYDAY'] = implode(',', $arNewFields['RRULE']['BYDAY']);
         }
         if (isset($arFields['ACTIVE_TO'])) {
             $arNewFields['RRULE']['UNTIL'] = $arFields['ACTIVE_TO'];
         } else {
             $arNewFields['RRULE']['UNTIL'] = $arFields['DT_TO_TS'];
         }
     }
     $eventId = CCalendar::SaveEvent(array('arFields' => $arNewFields, 'userId' => $userId, 'bAffectToDav' => false, 'bSilentAccessMeeting' => true, 'bServerTime' => $bServerTime));
     self::$silentErrorMode = false;
     return $eventId;
 }
Esempio n. 5
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule("calendar") || WIZARD_IS_RERUN) {
    return;
}
COption::SetOptionString("intranet", "calendar_2", "Y");
// company calendar calendar type
CCalendarType::Edit(array('NEW' => true, 'arFields' => array('XML_ID' => 'company_calendar', 'NAME' => GetMessage('CAL_TYPE_COMPANY_NAME'), 'DESCRIPTION' => '', 'ACCESS' => array('G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_view')))));
// Sections
$sectId0 = CCalendar::SaveSection(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'ID' => 0, 'NAME' => GetMessage("CAL_COMPANY_SECT_0"), 'DESCRIPTION' => GetMessage("CAL_COMPANY_SECT_DESC_0"), 'COLOR' => '#855CC5', 'TEXT_COLOR' => '', 'OWNER_ID' => '', 'EXPORT' => array('ALLOW' => true, 'SET' => '3_9'), 'ACCESS' => array(), 'IS_EXCHANGE' => false)));
$sectId1 = CCalendar::SaveSection(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'ID' => 0, 'NAME' => GetMessage("CAL_COMPANY_SECT_1"), 'DESCRIPTION' => GetMessage("CAL_COMPANY_SECT_DESC_1"), 'COLOR' => '#7DDEC2', 'TEXT_COLOR' => '', 'OWNER_ID' => '', 'EXPORT' => array('ALLOW' => true, 'SET' => '3_9'), 'ACCESS' => array(), 'IS_EXCHANGE' => false)));
$sectId2 = CCalendar::SaveSection(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'ID' => 0, 'NAME' => GetMessage("CAL_COMPANY_SECT_2"), 'DESCRIPTION' => GetMessage("CAL_COMPANY_SECT_DESC_2"), 'COLOR' => '#F6EA68', 'TEXT_COLOR' => '', 'OWNER_ID' => '', 'EXPORT' => array('ALLOW' => true, 'SET' => '3_9'), 'ACCESS' => array(), 'IS_EXCHANGE' => false)));
// Events for company_calendar
CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_0"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_0"), 'DT_FROM' => GetTime(mktime(9, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(16, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'UNTIL' => GetTime(mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1), "SHORT"), 'BYDAY' => 'TU'), 'SECTIONS' => $sectId0), 'userId' => 1));
CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_1"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_1"), 'DT_FROM' => GetTime(mktime(0, 0, 0, date("m"), date("d") + 2, date("Y")), "SHORT"), 'DT_TO' => GetTime(mktime(0, 0, 0, date("m"), date("d") + 2, date("Y")), "SHORT"), 'RRULE' => array('FREQ' => 'MONTHLY', 'INTERVAL' => 1, 'UNTIL' => GetTime(mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1), "SHORT")), 'SECTIONS' => $sectId0), 'userId' => 1));
CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_2"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_2"), 'DT_FROM' => GetTime(mktime(10, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(12, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'BYDAY' => 'MO'), 'SECTIONS' => $sectId1), 'userId' => 1));
CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_3"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_3"), 'DT_FROM' => GetTime(mktime(9, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(18, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'BYDAY' => 'TU'), 'SECTIONS' => $sectId2), 'userId' => 1));
CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_4"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_4"), 'DT_FROM' => GetTime(mktime(12, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(17, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'BYDAY' => 'FR'), 'SECTIONS' => $sectId2), 'userId' => 1));
CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'company_calendar', 'OWNER_ID' => 1, 'NAME' => GetMessage("CAL_COMP_EVENT_NAME_5"), 'DESCRIPTION' => GetMessage("CAL_COMP_EVENT_DESC_5"), 'DT_FROM' => GetTime(mktime(16, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(21, 0, 0, date("m"), date("d"), date("Y")), "FULL"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 1, 'BYDAY' => 'SA'), 'SECTIONS' => $sectId1), 'userId' => 1));
// User's calendar type
CCalendarType::Edit(array('NEW' => true, 'arFields' => array('XML_ID' => 'user', 'NAME' => GetMessage('CAL_TYPE_USER_NAME'), 'DESCRIPTION' => '', 'ACCESS' => array('G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_edit')))));
// Group's calendar type
CCalendarType::Edit(array('NEW' => true, 'arFields' => array('XML_ID' => 'group', 'NAME' => GetMessage('CAL_TYPE_GROUP_NAME'), 'DESCRIPTION' => '', 'ACCESS' => array('G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_edit')))));
$id = CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'user', 'OWNER_ID' => 1, 'NAME' => GetMessage("W_IB_CALENDAR_EMP_ABS"), 'DT_FROM' => GetTime(mktime(12, 0, 0, date("m"), date("d") + 1, date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(14, 0, 0, date("m"), date("d") + 1, date("Y")), "FULL"), 'DESCRIPTION' => ''), 'userId' => 1, 'autoDetectSection' => true, 'autoCreateSection' => true));
Esempio n. 6
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);
 }
Esempio n. 7
0
 public static function EditCalendarEventEntry($arFields = array(), $arUFFields = array(), $arAccessCodes = array(), $params = array())
 {
     global $DB;
     if ($arFields['SECTION']) {
         $arFields['SECTIONS'] = array($arFields['SECTION']);
     }
     $arFields["OWNER_ID"] = $params["userId"];
     $arFields["CAL_TYPE"] = $params["type"];
     // Add author for new event
     //if (!$arFields["ID"] && !empty($arAccessCodes))
     if (!$arFields["ID"]) {
         $arAccessCodes[] = 'U' . $params["userId"];
     }
     $arAccessCodes = array_unique($arAccessCodes);
     $arAttendees = CCalendar::GetDestinationUsers($arAccessCodes);
     if (trim($arFields["NAME"]) === '') {
         $arFields["NAME"] = GetMessage('EC_DEFAULT_EVENT_NAME');
     }
     $arFields['IS_MEETING'] = !empty($arAttendees) && $arAttendees != array($params["userId"]);
     if (isset($arFields['RRULE']) && !empty($arFields['RRULE'])) {
         if (is_array($arFields['RRULE']['BYDAY'])) {
             $arFields['RRULE']['BYDAY'] = implode(',', $arFields['RRULE']['BYDAY']);
         }
     }
     if ($arFields['IS_MEETING']) {
         $arFields['ATTENDEES_CODES'] = $arAccessCodes;
         $arFields['ATTENDEES'] = $arAttendees;
         $arFields['MEETING_HOST'] = $params["userId"];
         $arFields['MEETING'] = array('HOST_NAME' => CCalendar::GetUserName($params["userId"]), 'TEXT' => '', 'OPEN' => false, 'NOTIFY' => true, 'REINVITE' => false);
     } else {
         $arFields['ATTENDEES'] = false;
     }
     $eventId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true));
     if ($eventId > 0) {
         if (count($arUFFields) > 0) {
             CCalendarEvent::UpdateUserFields($eventId, $arUFFields);
         }
         foreach ($arAccessCodes as $key => $value) {
             if ($value == "UA") {
                 unset($arAccessCodes[$key]);
                 $arAccessCodes[] = "G2";
                 break;
             }
         }
         if ($arFields['IS_MEETING'] && !empty($arUFFields['UF_WEBDAV_CAL_EVENT'])) {
             $UF = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields("CALENDAR_EVENT", $eventId, LANGUAGE_ID);
             CCalendar::UpdateUFRights($arUFFields['UF_WEBDAV_CAL_EVENT'], $arAccessCodes, $UF['UF_WEBDAV_CAL_EVENT']);
         }
         $arSoFields = array("ENTITY_TYPE" => SONET_SUBSCRIBE_ENTITY_USER, "ENTITY_ID" => $params["userId"], "USER_ID" => $params["userId"], "=LOG_DATE" => $DB->CurrentTimeFunction(), "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => $arFields["NAME"], "MESSAGE" => '', "TEXT_MESSAGE" => '');
         $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "calendar", "SOURCE_ID" => $eventId), false, false, array("ID"));
         $arCodes = array();
         foreach ($arAccessCodes as $value) {
             if (substr($value, 0, 2) === 'SG') {
                 $arCodes[] = $value . '_K';
             }
             $arCodes[] = $value;
         }
         $arCodes = array_unique($arCodes);
         if ($arRes = $dbRes->Fetch()) {
             CSocNetLog::Update($arRes["ID"], $arSoFields);
             CSocNetLogRights::DeleteByLogID($arRes["ID"]);
             CSocNetLogRights::Add($arRes["ID"], $arCodes);
         } else {
             $arSoFields = array_merge($arSoFields, array("EVENT_ID" => "calendar", "SITE_ID" => SITE_ID, "SOURCE_ID" => $eventId, "ENABLE_COMMENTS" => "Y", "CALLBACK_FUNC" => false));
             $logID = CSocNetLog::Add($arSoFields, false);
             CSocNetLogRights::Add($logID, $arCodes);
         }
     }
 }
Esempio n. 8
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule("calendar")) {
    return;
}
COption::SetOptionString("intranet", "calendar_2", "Y");
if (WIZARD_FIRST_INSTAL != 'Y') {
    // calendar type
    $arTypes = CCalendarType::GetList(array("arFilter" => array("XML_ID" => 'events_info')));
    if (!$arTypes || count($arTypes) <= 0) {
        CCalendarType::Edit(array('NEW' => true, 'arFields' => array('XML_ID' => 'events_info', 'NAME' => GetMessage('CAL_DEFAULT_TYPE'), 'ACCESS' => array('G2' => CCalendar::GetAccessTasksByName('calendar_type', 'calendar_type_view')))));
    }
    // Sections
    $sectId0 = CCalendar::SaveSection(array('arFields' => array('CAL_TYPE' => 'events_info', 'ID' => 0, 'NAME' => GetMessage("CAL_TYPE_COMPANY_NAME"), 'DESCRIPTION' => "", 'COLOR' => '#855CC5', 'TEXT_COLOR' => '', 'OWNER_ID' => '', 'EXPORT' => array('ALLOW' => true, 'SET' => '3_9'), 'ACCESS' => array(), 'IS_EXCHANGE' => false)));
    // Events for company_calendar
    CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'events_info', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_EVENT_1_NAME"), 'DESCRIPTION' => "", 'DT_FROM' => GetTime(mktime(0, 0, 0, date("m"), date("d") + 4, date("Y")), "FULL"), 'DT_TO' => GetTime(mktime(0, 0, 0, date("m"), date("d") + 4, date("Y")), "FULL"), 'RRULE' => array(), 'SECTIONS' => $sectId0), 'userId' => 1));
    CCalendar::SaveEvent(array('arFields' => array('CAL_TYPE' => 'events', 'OWNER_ID' => 0, 'NAME' => GetMessage("CAL_EVENT_2_NAME"), 'DESCRIPTION' => "", 'COLOR' => '#FFFF80', 'DT_FROM' => GetTime(mktime(0, 0, 0, date("m"), date("d"), date("Y")), "SHORT"), 'DT_TO' => GetTime(mktime(0, 0, 0, date("m"), date("d"), date("Y")), "SHORT"), 'RRULE' => array('FREQ' => 'WEEKLY', 'INTERVAL' => 3, 'BYDAY' => 'SA'), 'SECTIONS' => $sectId0), 'userId' => 1));
}
Esempio n. 9
0
                $arFields['LOCATION']['NEW'] = $loc['NEW'];
            }
        }
        if (isset($_POST['rrule']) && $_POST['rrule'] == '') {
            $arFields['RRULE'] = '';
        }
        if ($arFields['IS_MEETING']) {
            $arFields['ATTENDEES'] = $_POST['attendees'];
            $arFields['ATTENDEES'] = $_POST['attendees'];
            if ($newMeeting && !in_array($ownerId, $arFields['ATTENDEES'])) {
                $arFields['ATTENDEES'][] = $ownerId;
            }
            $arFields['MEETING_HOST'] = $ownerId;
            $arFields['MEETING'] = array('HOST_NAME' => CCalendar::GetUserName($ownerId), 'TEXT' => '', 'OPEN' => false, 'NOTIFY' => true, 'REINVITE' => true);
        }
        $newId = CCalendar::SaveEvent(array('arFields' => $arFields, 'autoDetectSection' => true, 'autoCreateSection' => true));
    } elseif ($_REQUEST['app_calendar_action'] == 'drop_event' && check_bitrix_sessid()) {
        $res = CCalendar::DeleteEvent(intVal($_POST['event_id']));
    }
    die;
}
$calType = 'user';
$ownerId = $userId;
if ($arResult['NEW']) {
} else {
    $Event = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "OWNER_ID" => $userId, "DELETED" => "N"), 'parseRecursion' => false, 'fetchAttendees' => true, 'fetchMeetings' => true, 'checkPermissions' => true, 'setDefaultLimit' => false));
    if ($Event && is_array($Event[0])) {
        $Event = $Event[0];
        if ($Event['IS_MEETING']) {
            foreach ($Event['~ATTENDEES'] as $attendee) {
                $attendee['DISPLAY_NAME'] = CCalendar::GetUserName($attendee);
Esempio n. 10
0
 public function Add($arParams)
 {
     global $USER;
     $today = CTimeMan::RemoveHoursTS(time());
     $data = array('CAL_TYPE' => 'user', 'OWNER_ID' => $USER->GetID(), 'NAME' => $arParams['name'], 'DT_FROM' => ConvertTimeStamp($today + CTimeMan::MakeShortTS($arParams['from']), 'FULL'), 'DT_TO' => ConvertTimeStamp($today + CTimeMan::MakeShortTS($arParams['to']), 'FULL'));
     if ($arParams['absence'] == 'Y') {
         $data['ACCESSIBILITY'] = 'absent';
     }
     return CCalendar::SaveEvent(array('arFields' => $data, 'userId' => $USER->GetID(), 'autoDetectSection' => true, 'autoCreateSection' => true));
 }
Esempio n. 11
0
 public static function EventUpdate($arParams = array(), $nav = null, $server = null)
 {
     $userId = CCalendar::GetCurUserId();
     $methodName = "calendar.event.update";
     $necessaryParams = array('id', 'ownerId', 'type');
     foreach ($necessaryParams as $param) {
         if (!isset($arParams[$param]) || empty($arParams[$param])) {
             throw new Exception(GetMessage('CAL_REST_PARAM_EXCEPTION', array('#PARAM_NAME#' => $param, '#REST_METHOD#' => $methodName)));
         }
     }
     $id = intVal($arParams['id']);
     $type = $arParams['type'];
     $ownerId = intval($arParams['ownerId']);
     $arFields = array("ID" => $id);
     if (isset($arParams['from_ts'])) {
         $arFields["DT_FROM_TS"] = intVal($arParams['from_ts']);
     }
     if (isset($arParams['to_ts'])) {
         $arFields["DT_TO_TS"] = intVal($arParams['to_ts']);
     }
     if (isset($arParams['skip_time'])) {
         $arFields["SKIP_TIME"] = $arParams['skip_time'] == 'Y';
     }
     if (isset($arParams['name'])) {
         $arFields["NAME"] = trim($arParams['name']);
     }
     if (isset($arParams['description'])) {
         $arFields["DESCRIPTION"] = trim($arParams['description']);
     }
     if (isset($arParams['section'])) {
         $sectionId = $arParams['section'];
         $arFields["SECTIONS"] = array($sectionId);
         $res = CCalendarSect::GetList(array('arFilter' => array('CAL_TYPE' => $type, 'OWNER_ID' => $ownerId, 'ID' => $arParams['section'])));
         if ($res && is_array($res) && isset($res[0])) {
             if (!$res[0]['PERM']['edit']) {
                 throw new Exception(GetMessage('CAL_REST_ACCESS_DENIED'));
             }
         } else {
             throw new Exception('CAL_REST_SECTION_ERROR');
         }
     }
     if (isset($arParams['color'])) {
         $color = CCalendar::Color($arParams['color']);
         if ($color) {
             $arFields["COLOR"] = $color;
         }
     }
     if (isset($arParams['text_color'])) {
         $color = CCalendar::Color($arParams['text_color']);
         if ($color) {
             $arFields["TEXT_COLOR"] = $color;
         }
     }
     if (isset($arParams['accessibility'])) {
         $arFields["ACCESSIBILITY"] = $arParams['accessibility'];
     }
     if (isset($arParams['importance'])) {
         $arFields["IMPORTANCE"] = $arParams['importance'];
     }
     if (isset($arParams['private_event'])) {
         $arFields["PRIVATE_EVENT"] = $arParams['private_event'] == "Y";
     }
     if (isset($arParams['rrule'])) {
         $arFields["RRULE"] = $arParams['rrule'];
     }
     if (isset($arParams['is_meeting'])) {
         $arFields["IS_MEETING"] = $arParams['is_meeting'] == "Y";
     }
     if (isset($arParams['location'])) {
         $arFields["LOCATION"] = $arParams['LOCATION'];
     }
     if (isset($arParams['remind'])) {
         $arFields["REMIND"] = $arParams['REMIND'];
     }
     if ($arFields['IS_MEETING']) {
         $arFields['ATTENDEES'] = isset($arParams['attendees']) ? $arParams['attendees'] : false;
         $meeting = isset($arParams['meeting']) ? $arParams['meeting'] : array();
         $arFields['MEETING_HOST'] = isset($arParams['host']) ? intVal($arParams['host']) : $userId;
         $arFields['MEETING'] = array('HOST_NAME' => CCalendar::GetUserName($arFields['MEETING_HOST']), 'TEXT' => $meeting['text'], 'OPEN' => (bool) $meeting['open'], 'NOTIFY' => (bool) $meeting['notify'], 'REINVITE' => (bool) $meeting['reinvite']);
     }
     $newId = CCalendar::SaveEvent(array('arFields' => $arFields));
     if (!$newId) {
         throw new Exception(GetMessage("CAL_REST_EVENT_UPDATE_ERROR"));
     }
     return $newId;
 }
Esempio n. 12
0
 if (!in_array($strPriority, $arPriorityType)) {
     $strPriority = 'normal';
 }
 $arResult['VALUES']['REMIND_LEN'] = $intRemLen;
 $arResult['VALUES']['REMIND_TYPE'] = $strRemType;
 $arResult['VALUES']['PRIORITY'] = $strPriority;
 if (false == $boolError) {
     $strEntityShort = CUserTypeCrm::GetShortEntityType($arResult['ENTITY_TYPE']) . '_';
     foreach ($arID as $intID => $iUserID) {
         $arCrmEvents = array();
         $arCrmEvents[] = $strEntityShort . $intID;
         $arFields = array('CAL_TYPE' => 'user', 'OWNER_ID' => $iUserID, 'NAME' => $arResult['VALUES']['CALENDAR_TOPIC'], 'DT_FROM' => $arResult['VALUES']['CALENDAR_FROM'], 'DT_TO' => $arResult['VALUES']['CALENDAR_TO'], 'DESCRIPTION' => $arResult['VALUES']['CALENDAR_DESC'], 'IMPORTANCE' => $strPriority);
         if ('Y' == $arResult['VALUES']['REMIND_FLAG']) {
             $arFields['REMIND'] = array(array('type' => $strRemType, 'count' => $intRemLen));
         }
         $intEventID = CCalendar::SaveEvent(array('arFields' => $arFields, 'userId' => $iUserID, 'autoDetectSection' => true, 'autoCreateSection' => true));
         if (0 < intval($intEventID)) {
             CCalendarEvent::UpdateUserFields($intEventID, array('UF_CRM_CAL_EVENT' => $arCrmEvents));
         } else {
             $boolError = true;
             $arResult['ERROR_MESSAGE'][] = GetMessage('BX_CRM_CACA_ERR_ADD_FAIL');
         }
     }
 }
 if (true == $boolError) {
     $arKeys = array_keys($arDefResult['VALUES']);
     foreach ($arKeys as $strKey) {
         if (!isset($arResult['VALUES'][$strKey])) {
             $arResult['VALUES'][$strKey] = '';
         }
     }
Esempio n. 13
0
 public static function SetMeetingParams($userId, $eventId, $arFields)
 {
     $eventId = intVal($eventId);
     $userId = intVal($userId);
     // Check $arFields
     if (!in_array($arFields['ACCESSIBILITY'], array('busy', 'quest', 'free', 'absent'))) {
         $arFields['ACCESSIBILITY'] = 'busy';
     }
     $event = CCalendarEvent::GetById($eventId);
     if (!$event) {
         return false;
     }
     $res = CCalendarEvent::GetList(array('arFilter' => array("PARENT_ID" => $eventId, "CREATED_BY" => $userId, "IS_MEETING" => 1, "DELETED" => "N"), 'parseRecursion' => false, 'fetchAttendees' => true, 'fetchMeetings' => true, 'checkPermissions' => true, 'setDefaultLimit' => false));
     if (!$res || !$res[0]) {
         $res = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "CREATED_BY" => $userId, "IS_MEETING" => 1, "DELETED" => "N"), 'parseRecursion' => false, 'fetchAttendees' => true, 'fetchMeetings' => true, 'checkPermissions' => true, 'setDefaultLimit' => false));
     }
     if ($res[0]) {
         $event = $res[0];
         $arReminders = array();
         if (isset($arFields['REMIND'])) {
             if ($arFields['REMIND'] && 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']));
                     }
                 }
             }
         }
         $arFields = array("ID" => $event['ID'], "REMIND" => $arReminders, "ACCESSIBILITY" => $arFields['ACCESSIBILITY']);
         //SaveEvent
         CCalendar::SaveEvent(array('arFields' => $arFields));
     }
     return true;
 }
Esempio n. 14
0
 protected static function plannerActionAdd($arParams)
 {
     global $USER;
     $today = ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT');
     $data = array('CAL_TYPE' => 'user', 'OWNER_ID' => $USER->GetID(), 'NAME' => $arParams['NAME'], 'DT_FROM' => self::MakeDateTime($today, $arParams['FROM']), 'DT_TO' => self::MakeDateTime($today, $arParams['TO']));
     if ($arParams['ABSENCE'] == 'Y') {
         $data['ACCESSIBILITY'] = 'absent';
     }
     CCalendar::SaveEvent(array('arFields' => $data, 'userId' => $USER->GetID(), 'autoDetectSection' => true, 'autoCreateSection' => true));
 }
Esempio n. 15
0
 public static function AddEvent($MEETING_ID, $arFields, $arParams = array())
 {
     global $USER;
     $EventID = false;
     if (self::IsNewCalendar()) {
         $arEventFields = array('ID' => $arFields['EVENT_ID'], 'CAL_TYPE' => 'user', 'OWNER_ID' => $arFields['OWNER_ID'], 'DT_FROM' => $arFields['DATE_START'], 'DT_TO' => ConvertTimeStamp(MakeTimeStamp($arFields['DATE_START']) + $arFields['DURATION'], 'FULL'), 'NAME' => $arFields['TITLE'], 'DESCRIPTION' => CCalendar::ParseHTMLToBB($arFields['DESCRIPTION']), 'IS_MEETING' => true, 'MEETING_HOST' => $arFields['OWNER_ID'], 'MEETING' => array('HOST_NAME' => CCalendar::GetUserName($arFields['OWNER_ID'])), 'ATTENDEES' => array_keys($arFields['USERS']));
         if ($arFields['CURRENT_STATE'] == CMeeting::STATE_CLOSED) {
             $arEventFields['DT_TO'] = MakeTimeStamp($arFields['DATE_FINISH']) > MakeTimeStamp($arFields['DATE_START']) ? $arFields['DATE_FINISH'] : $arEventFields['DT_TO'];
         }
         $matches = array();
         if (preg_match('/^mr_([\\d]+)_([\\d]+)$/', $arFields["PLACE"], $matches)) {
             $arEventFields['LOCATION'] = 'ECMR_' . $matches[2];
             if ($arFields['EVENT_ID'] > 0) {
                 $arCurrentEvent = CCalendarEvent::GetById($arFields['EVENT_ID']);
                 if ($arCurrentEvent['LOCATION']) {
                     $res = CCalendar::ParseLocation($arCurrentEvent['LOCATION']);
                     if ($res['mrevid']) {
                         $arEventFields['LOCATION'] .= '_' . $res['mrevid'];
                     }
                 }
             }
         } else {
             $arEventFields['LOCATION'] = $arFields['PLACE'];
         }
         if (isset($arFields['REINVITE'])) {
             $arEventFields['MEETING']['REINVITE'] = $arFields['REINVITE'];
         } else {
             $arEventFields['MEETING']['REINVITE'] = false;
         }
         if (isset($arFields['NOTIFY'])) {
             $arEventFields['MEETING']['NOTIFY'] = $arFields['NOTIFY'];
         }
         $EventID = CCalendar::SaveEvent(array('arFields' => $arEventFields, 'userId' => $arFields['OWNER_ID'], 'autoDetectSection' => true, 'autoCreateSection' => true));
     } elseif (!$arFields['EVENT_ID']) {
         $iblockId = $arParams['CALENDAR_IBLOCK_ID'] ? $arParams['CALENDAR_IBLOCK_ID'] : COption::GetOptionInt('intranet', 'iblock_calendar', 0, SITE_ID);
         $obCalendar = new CEventCalendar();
         $obCalendar->Init(array('ownerType' => 'USER', 'ownerId' => $USER->GetID(), 'bOwner' => true, 'iblockId' => $iblockId, 'userIblockId' => $iblockId, 'bCache' => false, 'pathToUserCalendar' => '/company/personal/user/#user_id#/calendar/'));
         $guestCalendarId = false;
         $guestSection = $obCalendar->GetSectionIDByOwnerId($USER->GetID(), 'USER', $iblockId);
         $arGuestCalendars = array();
         if (!$guestSection) {
             $guestSection = $obCalendar->CreateSectionForOwner($USER->GetID(), "USER", $iblockId);
         }
         $arGuestCalendars = $obCalendar->GetCalendars(array('sectionId' => $guestSection, 'iblockId' => $iblockId, 'ownerType' => 'USER', 'ownerId' => $USER->GetID(), 'bOwner' => 1, 'forExport' => true, 'bOnlyID' => true));
         if (count($arGuestCalendars) > 0) {
             $arUserSet = $obCalendar->GetUserSettings(array('static' => false, 'userId' => $USER->GetID()));
             if ($arUserSet && isset($arUserSet['MeetCalId']) && in_array($arUserSet['MeetCalId'], $arGuestCalendars)) {
                 $guestCalendarId = intVal($arUserSet['MeetCalId']);
             } else {
                 $guestCalendarId = $arGuestCalendars[0];
             }
         }
         //$bGroup = $arParams['GROUP_ID'] > 0;
         $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true));
         $arEventFields = array('iblockId' => $obCalendar->iblockId, 'ownerType' => $obCalendar->ownerType, 'ownerId' => $obCalendar->ownerId, 'RMiblockId' => self::__getRMIblockID(), 'allowResMeeting' => true, 'bNew' => true, 'fullUrl' => $obCalendar->fullUrl, 'userId' => $obCalendar->userId, 'pathToUserCalendar' => $obCalendar->pathToUserCalendar, 'pathToGroupCalendar' => $obCalendar->pathToGroupCalendar, 'userIblockId' => $obCalendar->iblockId, 'calendarId' => $guestCalendarId, 'sectionId' => $guestSection, 'dateFrom' => $arFields['DATE_START'], 'dateTo' => $arFields['DATE_FINISH'] ? $arFields['DATE_FINISH'] : ConvertTimeStamp(MakeTimeStamp($arFields['DATE_START']) + $arFields['DURATION'], 'FULL'), 'name' => $arFields['TITLE'], 'desc' => $arFields['DESCRIPTION'], 'prop' => array(), 'isMeeting' => true, 'guests' => array_keys($arFields['USERS']), 'notDisplayCalendar' => true);
         if ($EventID = $obCalendar->SaveEvent($arEventFields)) {
             CEventCalendar::ClearCache('/event_calendar/events/' . $arEventFields['iblockId'] . '/');
             CEventCalendar::ClearCache('/event_calendar/events/' . $arEventFields['userIblockId'] . '/');
         }
     }
     if ($EventID) {
         self::Update($MEETING_ID, array('EVENT_ID' => $EventID));
     }
     return $EventID;
 }
	public function Execute()
	{
		if (!CModule::IncludeModule("calendar"))
			return CBPActivityExecutionStatus::Closed;

		$rootActivity = $this->GetRootActivity();
		$documentId = $rootActivity->GetDocumentId();

		$documentService = $this->workflow->GetService("DocumentService");

		$fromTs = CCalendar::Timestamp($this->CalendarFrom);
		$toTs = $this->CalendarTo == '' ? $fromTs : CCalendar::Timestamp($this->CalendarTo);

		$arFields = array(
			"CAL_TYPE" => !$this->CalendarType ? 'user' : $this->CalendarType,
			"NAME" => trim($this->CalendarName) == '' ? GetMessage('EC_DEFAULT_EVENT_NAME') : $this->CalendarName,
			"DESCRIPTION" => $this->CalendarDesrc,
			"SKIP_TIME" => date('H:i', $fromTs) == '00:00' && date('H:i', $toTs) == '00:00',
			"IS_MEETING" => false,
			"RRULE" => false
		);

		if ($fromTs == $toTs && !$arFields["SKIP_TIME"])
			$toTs += 3600 /* HOUR LENGTH*/;

		$arFields['DT_FROM_TS'] = $fromTs;
		$arFields['DT_TO_TS'] = $toTs;

		if ($this->CalendarOwnerId)
		{
			$arFields["OWNER_ID"] = $this->CalendarOwnerId;
			$eventId = CCalendar::SaveEvent(
				array(
					'arFields' => $arFields,
					'autoDetectSection' => true
				)
			);
		}
		else
		{
			$arCalendarUser = array();
			$arCalendarUserTmp = $this->CalendarUser;
			$arCalendarUserTmp = (is_array($arCalendarUserTmp) ? $arCalendarUserTmp : array($arCalendarUserTmp));
			$l = strlen("user_");

			foreach ($arCalendarUserTmp as $user)
			{
				if (substr($user, 0, $l) == "user_")
				{
					$user = intval(substr($user, $l));
					if ($user > 0)
						$arCalendarUser[] = $user;
				}
				else
				{
					$arDSUsers = $documentService->GetUsersFromUserGroup($user, $documentId);
					foreach ($arDSUsers as $v)
					{
						$user = intval($v);
						if ($user > 0)
							$arCalendarUser[] = $user;
					}
				}
			}

			foreach ($arCalendarUser as $calendarUser)
			{
				$arFields["CAL_TYPE"] = "user";
				$arFields["OWNER_ID"] = $calendarUser;
				$eventId = CCalendar::SaveEvent(
					array(
						'arFields' => $arFields,
						'autoDetectSection' => true
					)
				);
			}
		}

		return CBPActivityExecutionStatus::Closed;
	}