示例#1
0
 public static function Edit($Params = array())
 {
     global $DB, $CACHE_MANAGER;
     $arFields = $Params['arFields'];
     // 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);
     if ($userId < 0) {
         return false;
     }
     if (!self::CheckFields($arFields)) {
         return false;
     }
     if ($arFields['CAL_TYPE'] == 'user') {
         $CACHE_MANAGER->ClearByTag('calendar_user_' . $arFields['OWNER_ID']);
     }
     $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'] = $userId;
         }
         if (!isset($arFields['DATE_CREATE'])) {
             $arFields['DATE_CREATE'] = $arFields['TIMESTAMP_X'];
         }
     }
     $attendees = is_array($arFields['ATTENDEES']) ? $arFields['ATTENDEES'] : array();
     if (!isset($arFields['OWNER_ID']) || !$arFields['OWNER_ID']) {
         $arFields['OWNER_ID'] = 0;
     }
     if (!isset($arFields['LOCATION']['OLD']) && !$bNew) {
         // Select meeting info about event
         if (isset($Params['currentEvent'])) {
             $oldEvent = $Params['currentEvent'];
         } else {
             $oldEvent = CCalendarEvent::GetById($arFields['ID']);
         }
         if ($oldEvent) {
             $arFields['LOCATION']['OLD'] = $oldEvent['LOCATION'];
         }
     }
     $offset = CCalendar::GetOffset();
     $arFields['LOCATION'] = CCalendar::SetLocation($arFields['LOCATION']['OLD'], $arFields['LOCATION']['NEW'], array('dateFrom' => CCalendar::Date($arFields['DT_FROM_TS'] + $offset), 'dateTo' => CCalendar::Date($arFields['DT_TO_TS'] + $offset), 'name' => $arFields['NAME'], 'persons' => count($attendees), 'attendees' => $attendees, 'bRecreateReserveMeetings' => $arFields['LOCATION']['RE_RESERVE'] !== 'N'));
     $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']);
         }
         // Organizer
         $bSendInvitations = $Params['bSendInvitations'] !== false;
         $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']);
     }
     $arReminders = array();
     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['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) {
         $ID = CDatabase::Add("b_calendar_event", $dbFields, array('DESCRIPTION', 'MEETING', 'RDATE', 'EXDATE'));
     } else {
         $ID = $arFields['ID'];
         $strUpdate = $DB->PrepareUpdate("b_calendar_event", $dbFields);
         $strSql = "UPDATE b_calendar_event SET " . $strUpdate . " WHERE ID=" . IntVal($arFields['ID']);
         $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' => $ID)) . " WHERE ID=" . IntVal($ID);
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     // Clean links
     // Del link from table
     if (!$bNew) {
         $arAffectedSections = CCalendarEvent::GetCurrentSectionIds($ID);
         $DB->Query("DELETE FROM b_calendar_event_sect WHERE EVENT_ID=" . IntVal($ID), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     } else {
         $arAffectedSections = array();
     }
     $strSections = "0";
     foreach ($arFields['SECTIONS'] as $sect) {
         if (IntVal($sect) > 0) {
             $strSections .= "," . IntVal($sect);
             $arAffectedSections[] = IntVal($sect);
         }
     }
     if (count($arAffectedSections) > 0) {
         CCalendarSect::UpdateModificationLabel($arAffectedSections);
     }
     // We don't have any section for this event
     // and we have to create default one.
     if ($strSections == "0") {
         $defCalendar = CCalendarSect::CreateDefault(array('type' => CCalendar::GetType(), 'ownerId' => CCalendar::GetOwnerId()));
         $strSections .= "," . IntVal($defCalendar['ID']);
     }
     // Add links
     $strSql = "INSERT INTO b_calendar_event_sect(EVENT_ID, SECT_ID) " . "SELECT " . intVal($ID) . ", ID " . "FROM b_calendar_section " . "WHERE ID in (" . $strSections . ")";
     $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     $bPull = CModule::IncludeModule("pull");
     if ($arFields['IS_MEETING']) {
         if (isset($arFields['ATTENDEES'])) {
             self::InviteAttendees($ID, $arFields, $arFields['ATTENDEES'], is_array($Params['attendeesStatuses']) ? $Params['attendeesStatuses'] : array(), $bSendInvitations, $userId);
             if ($bPull) {
                 // TODO: CACHE IT!
                 $attendees = self::GetAttendees($ID);
                 $attendees = $attendees[$ID];
                 foreach ($attendees as $user) {
                     CPullStack::AddByUser($user['USER_ID'], array('module_id' => 'calendar', 'command' => 'event_update', 'params' => array('EVENT' => CCalendarEvent::OnPullPrepareArFields($arFields), 'ATTENDEES' => $attendees, 'NEW' => $bNew ? 'Y' : 'N')));
                 }
             }
         }
     } else {
         if ($bPull) {
             CPullStack::AddByUser($userId, 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' => $ID, 'reminders' => $arReminders, 'arFields' => $arFields, 'userId' => $userId, 'path' => $path, 'bNew' => $bNew));
     if ($arFields['CAL_TYPE'] == 'user' && $arFields['IS_MEETING'] && !empty($attendeesCodes)) {
         CCalendarLiveFeed::OnEditCalendarEventEntry($ID, $arFields, $attendeesCodes);
     }
     CCalendar::ClearCache('event_list');
     return $ID;
 }
示例#2
0
$arParams['OWNER_TYPE'] = 'user';
$arParams['CUR_USER'] = $USER->GetId();
$arResult['USER_FIELDS'] = $USER_FIELD_MANAGER->GetUserFields("CALENDAR_EVENT", $arParams['EVENT_ID'], LANGUAGE_ID);

// Webdaw upload file UF
$arParams["UPLOAD_WEBDAV_ELEMENT"] = $arResult['USER_FIELDS']['UF_WEBDAV_CAL_EVENT'];

$arParams['SECTIONS'] = CCalendar::GetSectionList(array(
	'CAL_TYPE' => $arParams['OWNER_TYPE'],
	'OWNER_ID' => $arParams['CUR_USER']
));

if (empty($arParams['SECTIONS']))
{
	$defCalendar = CCalendarSect::CreateDefault(array(
		'type' => $arParams['OWNER_TYPE'],
		'ownerId' => $arParams['CUR_USER']
	));
	$arParams['SECTIONS'][] = $defCalendar;
	CCalendar::SetCurUserMeetingSection($defCalendar['ID']);
}

$arParams['EVENT'] = CCalendarEvent::GetById($arParams['EVENT_ID']);

$arParams["DESTINATION"] = (is_array($arParams["DESTINATION"]) && IsModuleInstalled("socialnetwork") ? $arParams["DESTINATION"] : array());
$arParams["DESTINATION"] = (array_key_exists("VALUE", $arParams["DESTINATION"]) ? $arParams["DESTINATION"]["VALUE"] : $arParams["DESTINATION"]);


$users = array();
foreach ($arParams["DESTINATION"]['USERS'] as $key => $entry)
{
	if ($entry['isExtranet'] == 'N')
示例#3
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;
 }
示例#4
0
        }
        $Event['~LOCATION'] = $Event['LOCATION'] !== '' ? CCalendar::GetTextLocation($Event["LOCATION"]) : '';
        if ($Event['RRULE'] !== '') {
            $Event['RRULE'] = CCalendarEvent::ParseRRULE($Event['RRULE']);
            if (is_array($Event['RRULE']) && !isset($Event['RRULE']['UNTIL'])) {
                $Event['RRULE']['UNTIL'] = $Event['DT_TO_TS'];
            }
            $Event['DT_TO_TS'] = $Event['DT_FROM_TS'] + intval($Event['DT_LENGTH']);
        }
        $arResult['EVENT'] = $Event;
        $calType = $Event['CAL_TYPE'];
        $ownerId = $Event['OWNER_ID'];
    } else {
        $Event = array();
        // Event is not found
        $arResult['DELETED'] = "Y";
        $arResult['EVENT_ID'] = $eventId;
    }
}
$arResult['CAL_TYPE'] = $calType;
$arResult['OWNER_ID'] = $ownerId;
$arResult['USER_ID'] = $userId;
$arResult['SECTIONS'] = array();
$sections = CCalendar::GetSectionList(array('CAL_TYPE' => $calType, 'OWNER_ID' => $ownerId));
if (empty($sections)) {
    $sections = array(CCalendarSect::CreateDefault(array('type' => $calType, 'ownerId' => $ownerId)));
}
foreach ($sections as $sect) {
    $arResult['SECTIONS'][] = array('ID' => $sect['ID'], 'NAME' => $sect['NAME']);
}
$this->IncludeComponentTemplate();