Пример #1
0
<?php 
global $APPLICATION, $USER_FIELD_MANAGER;
$id = $arParams['id'];
$event = $arParams['event'];
$fromTs = CCalendar::Timestamp($event['DATE_FROM']);
$toTs = CCalendar::Timestamp($event['DATE_TO']);
if ($event['DT_SKIP_TIME'] == "Y") {
    $toTs += CCalendar::DAY_LENGTH;
}
if ($event['DT_SKIP_TIME'] !== "Y") {
    $fromTs -= $event['~USER_OFFSET_FROM'];
    $toTs -= $event['~USER_OFFSET_TO'];
}
$UF = CCalendarEvent::GetEventUserFields($event);
if ($event['PARENT_ID']) {
    $attRes = CCalendarEvent::GetAttendees(array($event['PARENT_ID']));
    if ($attRes && isset($attRes[$event['PARENT_ID']])) {
        $event['~ATTENDEES'] = $attRes[$event['PARENT_ID']];
    }
}
$event['UF_CRM_CAL_EVENT'] = $UF['UF_CRM_CAL_EVENT'];
if (empty($event['UF_CRM_CAL_EVENT']['VALUE'])) {
    $event['UF_CRM_CAL_EVENT'] = false;
}
$event['UF_WEBDAV_CAL_EVENT'] = $UF['UF_WEBDAV_CAL_EVENT'];
if (empty($event['UF_WEBDAV_CAL_EVENT']['VALUE'])) {
    $event['UF_WEBDAV_CAL_EVENT'] = false;
}
$event['FROM_WEEK_DAY'] = FormatDate('D', $fromTs);
$event['FROM_MONTH_DAY'] = FormatDate('j', $fromTs);
$event['FROM_MONTH'] = FormatDate('n', $fromTs);
Пример #2
0
 public static function GetEventGuests($eventId, $userId)
 {
     if (self::IsNewCalendar()) {
         $res = array();
         $arAttendees = CCalendarEvent::GetAttendees($eventId);
         if (is_array($arAttendees)) {
             foreach ($arAttendees[$eventId] as $arGuest) {
                 $res[] = array('id' => $arGuest['USER_ID'], 'status' => $arGuest['STATUS']);
             }
         }
         return $res;
     } else {
         $dbRes = CIBlockElement::GetByID($eventId);
         if ($arRes = $dbRes->Fetch()) {
             $calIblockSection = $arRes['IBLOCK_SECTION_ID'];
             $calIblock = $arRes['IBLOCK_ID'];
         }
         CModule::IncludeModule('socialnetwork');
         $obCalendar = new CEventCalendar();
         $obCalendar->Init(array('ownerType' => 'USER', 'ownerId' => $userId, 'bOwner' => true, 'iblockId' => $calIblock, 'userIblockId' => COption::GetOptionInt('intranet', 'iblock_calendar', 0, SITE_ID)));
         $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true));
         $arEvents = $obCalendar->GetEvents(array('iblockId' => $calIblock, 'sectionId' => $calIblockSection, 'eventId' => $eventId, 'bLoadAll' => true, 'ownerType' => 'USER'));
         if ($event = $arEvents[0]) {
             return is_array($event['GUESTS']) ? array_values($event['GUESTS']) : array();
         }
     }
 }
Пример #3
0
 public static function NotifyComment($eventID, $arComment)
 {
     if (!CModule::IncludeModule("im")) {
         return;
     }
     if (intval($eventID) <= 0) {
         return;
     }
     $userId = intval($arComment["USER_ID"]);
     if ($arCalendarEvent = CCalendarEvent::GetById($eventID)) {
         $rsUser = CUser::GetList($by = 'id', $order = 'asc', array('ID_EQUAL_EXACT' => $userId), array('FIELDS' => array('PERSONAL_GENDER')));
         $strMsgAddComment = GetMessage('EC_LF_COMMENT_MESSAGE_ADD');
         $strMsgAddComment_Q = GetMessage('EC_LF_COMMENT_MESSAGE_ADD_Q');
         if ($arUser = $rsUser->fetch()) {
             switch ($arUser['PERSONAL_GENDER']) {
                 case "F":
                 case "M":
                     $strMsgAddComment = GetMessage('EC_LF_COMMENT_MESSAGE_ADD_' . $arUser['PERSONAL_GENDER']);
                     $strMsgAddComment_Q = GetMessage('EC_LF_COMMENT_MESSAGE_ADD_Q_' . $arUser['PERSONAL_GENDER']);
                     break;
                 default:
                     break;
             }
         }
         $url = CCalendar::GetPathForCalendarEx($userId);
         $url = $url . (strpos($url, "?") === false ? '?' : '&') . 'EVENT_ID=' . $eventID . '&EVENT_DATE=' . $arCalendarEvent['DT_FROM'];
         $arMessageFields = array("FROM_USER_ID" => $userId, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "calendar", "NOTIFY_EVENT" => "event_comment");
         $aId = isset($arCalendarEvent['PARENT_ID']) ? $arCalendarEvent['PARENT_ID'] : $arCalendarEvent['ID'];
         $attendees = CCalendarEvent::GetAttendees($aId);
         if (is_array($attendees) && is_array($attendees[$aId])) {
             $attendees = $attendees[$aId];
             foreach ($attendees as $attendee) {
                 if ($attendee["USER_ID"] != $userId && $attendee["STATUS"] != 'N') {
                     $arMessageFields1 = array_merge($arMessageFields, array("TO_USER_ID" => $attendee["USER_ID"]));
                     if ($attendee["STATUS"] == 'Q') {
                         $arMessageFields1["NOTIFY_MESSAGE"] = str_replace(array("#EVENT_TITLE#"), array(strlen($url) > 0 ? "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . $arCalendarEvent["NAME"] . "</a>" : $arCalendarEvent["NAME"]), $strMsgAddComment_Q);
                         $arMessageFields1["NOTIFY_MESSAGE_OUT"] = str_replace(array("#EVENT_TITLE#"), array($arCalendarEvent["NAME"]), $strMsgAddComment_Q) . (strlen($url) > 0 ? " (" . $url . ")" : "") . "#BR##BR#" . $arComment["MESSAGE"];
                     } else {
                         $arMessageFields1["NOTIFY_MESSAGE"] = str_replace(array("#EVENT_TITLE#"), array(strlen($url) > 0 ? "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . $arCalendarEvent["NAME"] . "</a>" : $arCalendarEvent["NAME"]), $strMsgAddComment);
                         $arMessageFields1["NOTIFY_MESSAGE_OUT"] = str_replace(array("#EVENT_TITLE#"), array($arCalendarEvent["NAME"]), $strMsgAddComment) . (strlen($url) > 0 ? " (" . $url . ")" : "") . "#BR##BR#" . $arComment["MESSAGE"];
                     }
                     CIMNotify::Add($arMessageFields1);
                 }
             }
         }
     }
 }
Пример #4
0
 public static function ReminderAgent($eventId = 0, $userId = 0, $viewPath = '', $calendarType = '', $ownerId = 0)
 {
     if ($eventId > 0 && $userId > 0 && $calendarType != '') {
         if (!CModule::IncludeModule("im")) {
             return false;
         }
         $skipReminding = false;
         global $USER;
         // Create tmp user
         if ($bTmpUser = !$USER || !is_object($USER)) {
             $USER = new CUser();
         }
         // We have to use this to set timezone offset to local user's timezone
         self::SetOffset(false, self::GetOffset($userId));
         $arEvents = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "DELETED" => "N", "FROM_LIMIT" => CCalendar::Date(time() - 3600, false), "TO_LIMIT" => CCalendar::Date(CCalendar::GetMaxTimestamp(), false)), 'parseRecursion' => true, 'maxInstanceCount' => 3, 'preciseLimits' => true, 'fetchAttendees' => true, 'checkPermissions' => false, 'setDefaultLimit' => false));
         if ($arEvents && is_array($arEvents[0])) {
             $event = $arEvents[0];
         }
         if ($event && $event['IS_MEETING']) {
             $attendees = CCalendarEvent::GetAttendees($event['PARENT_ID']);
             $attendees = $attendees[$event['PARENT_ID']];
             foreach ($attendees as $attendee) {
                 // If current user is an attendee but his status is 'N' we don't take care about reminding
                 if ($attendee['USER_ID'] == $userId && $attendee['STATUS'] == 'N') {
                     $skipReminding = true;
                     break;
                 }
             }
         }
         if ($event && $event['DELETED'] != 'Y' && !$skipReminding) {
             // Get Calendar Info
             $Section = CCalendarSect::GetById($event['SECT_ID'], false);
             if ($Section) {
                 $arNotifyFields = array('FROM_USER_ID' => $userId, 'TO_USER_ID' => $userId, 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM, 'NOTIFY_MODULE' => "calendar", 'NOTIFY_EVENT' => "reminder", 'NOTIFY_TAG' => "CALENDAR|INVITE|" . $eventId . "|" . $userId . "|REMINDER", 'NOTIFY_SUB_TAG' => "CALENDAR|INVITE|" . $eventId);
                 $fromTs = CCalendar::Timestamp($event['DATE_FROM'], false, $event['DT_SKIP_TIME'] !== 'Y');
                 if ($event['DT_SKIP_TIME'] !== 'Y') {
                     $fromTs -= $event['~USER_OFFSET_FROM'];
                 }
                 $arNotifyFields['MESSAGE'] = GetMessage('EC_EVENT_REMINDER', array('#EVENT_NAME#' => $event["NAME"], '#DATE_FROM#' => CCalendar::Date($fromTs, $event['DT_SKIP_TIME'] !== 'Y')));
                 $sectionName = $Section['NAME'];
                 $ownerName = CCalendar::GetOwnerName($calendarType, $ownerId);
                 if ($calendarType == 'user' && $ownerId == $userId) {
                     $arNotifyFields['MESSAGE'] .= ' ' . GetMessage('EC_EVENT_REMINDER_IN_PERSONAL', array('#CALENDAR_NAME#' => $sectionName));
                 } else {
                     if ($calendarType == 'user') {
                         $arNotifyFields['MESSAGE'] .= ' ' . GetMessage('EC_EVENT_REMINDER_IN_USER', array('#CALENDAR_NAME#' => $sectionName, '#USER_NAME#' => $ownerName));
                     } else {
                         if ($calendarType == 'group') {
                             $arNotifyFields['MESSAGE'] .= ' ' . GetMessage('EC_EVENT_REMINDER_IN_GROUP', array('#CALENDAR_NAME#' => $sectionName, '#GROUP_NAME#' => $ownerName));
                         } else {
                             $arNotifyFields['MESSAGE'] .= ' ' . GetMessage('EC_EVENT_REMINDER_IN_COMMON', array('#CALENDAR_NAME#' => $sectionName, '#IBLOCK_NAME#' => $ownerName));
                         }
                     }
                 }
                 if ($viewPath != '') {
                     $arNotifyFields['MESSAGE'] .= "\n" . GetMessage('EC_EVENT_REMINDER_DETAIL', array('#URL_VIEW#' => $viewPath));
                 }
                 CIMNotify::Add($arNotifyFields);
                 foreach (GetModuleEvents("calendar", "OnRemindEvent", true) as $arEvent) {
                     ExecuteModuleEventEx($arEvent, array(array('eventId' => $eventId, 'userId' => $userId, 'viewPath' => $viewPath, 'calType' => $calendarType, 'ownerId' => $ownerId)));
                 }
                 if (CCalendarEvent::CheckRecurcion($event) && ($nextEvent = $arEvents[1])) {
                     $remAgentParams = array('eventId' => $eventId, 'userId' => $userId, 'viewPath' => $viewPath, 'calendarType' => $calendarType, 'ownerId' => $ownerId);
                     // 1. clean reminders
                     CCalendar::RemoveAgent($remAgentParams);
                     $startTs = CCalendar::Timestamp($nextEvent['DATE_FROM'], false, $event["DT_SKIP_TIME"] !== 'Y');
                     if ($nextEvent["DT_SKIP_TIME"] == 'N' && $nextEvent["TZ_FROM"]) {
                         $startTs = $startTs - CCalendar::GetTimezoneOffset($nextEvent["TZ_FROM"], $startTs);
                         // UTC timestamp
                     }
                     // 2. Set new reminders
                     $reminder = $nextEvent['REMIND'][0];
                     if ($reminder) {
                         $delta = intVal($reminder['count']) * 60;
                         //Minute
                         if ($reminder['type'] == 'hour') {
                             $delta = $delta * 60;
                         } elseif ($reminder['type'] == 'day') {
                             $delta = $delta * 60 * 24;
                         }
                         //Day
                         // $startTs - UTC timestamp;  date("Z", $startTs) - offset of the server
                         $agentTime = $startTs + date("Z", $startTs);
                         if ($agentTime - $delta >= time() - 60 * 5) {
                             // Inaccuracy - 5 min
                             CCalendar::AddAgent(CCalendar::Date($agentTime - $delta), $remAgentParams);
                         }
                     }
                 }
             }
         }
         self::$offset = null;
         if (isset($bTmpUser) && $bTmpUser) {
             unset($USER);
         }
     }
 }