Esempio n. 1
0
 public static function SetMeetingParams($userId, $eventId, $arFields)
 {
     global $DB;
     $eventId = intVal($eventId);
     $userId = intVal($userId);
     // Check $arFields
     if (!in_array($arFields['ACCESSIBILITY'], array('busy', 'quest', 'free', 'absent'))) {
         $arFields['ACCESSIBILITY'] = 'busy';
     }
     $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) : '';
     // Reminding options
     $Event = CCalendarEvent::GetById($eventId);
     if (!$Event) {
         return false;
     }
     $path = CCalendar::GetPath($arFields['CAL_TYPE']);
     $path = CHTTP::urlDeleteParams($path, array("action", "sessid", "bx_event_calendar_request", "EVENT_ID"));
     $viewPath = CHTTP::urlAddParams($path, array('EVENT_ID' => $eventId));
     $remAgentParams = array('eventId' => $eventId, 'userId' => $userId, 'viewPath' => $viewPath, 'calendarType' => $Event["CAL_TYPE"], 'ownerId' => $Event["OWNER_ID"]);
     // 1. clean reminders
     CCalendar::RemoveAgent($remAgentParams);
     // 2. Set new reminders
     foreach ($arReminders as $reminder) {
         $delta = intVal($reminder['count']) * 60;
         //Minute
         if ($reminder['type'] == 'hour') {
             $delta = $delta * 60;
         } elseif ($reminder['type'] == 'day') {
             $delta = $delta * 60 * 24;
         }
         //Day
         if ($Event['DT_FROM_TS'] - $delta >= time() - 60 * 5) {
             // Inaccuracy - 5 min
             CCalendar::AddAgent(CCalendar::Date($Event['DT_FROM_TS'] - $delta), $remAgentParams);
         }
     }
     // Select meeting info about event
     $res = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "DELETED" => "N"), 'parseRecursion' => false));
     if ($Event = $res[0]) {
         if ($Event['IS_MEETING']) {
             // Try to find this user into attendees for this event
             $strSql = "SELECT * FROM b_calendar_attendees WHERE USER_KEY={$userId} AND EVENT_ID={$eventId}";
             $dbAtt = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             if ($att = $dbAtt->Fetch()) {
                 //Set params
                 $strSql = "UPDATE b_calendar_attendees SET " . $DB->PrepareUpdate("b_calendar_attendees", $arFields) . " WHERE EVENT_ID=" . $eventId . " AND USER_KEY=" . $userId;
                 $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             }
         }
     }
     CCalendar::ClearCache('attendees_list');
     return true;
 }
Esempio n. 2
0
 public static function SendMessage($Params)
 {
     if (!CModule::IncludeModule("im")) {
         return false;
     }
     $mode = $Params['mode'];
     // invite|change|cancel|accept|decline
     $Params["meetingText"] = isset($Params["meetingText"]) && is_string($Params["meetingText"]) ? trim($Params["meetingText"]) : '';
     $fromUser = intVal($Params["userId"]);
     $toUser = intVal($Params["guestId"]);
     if (!$fromUser || !$toUser || $toUser == $fromUser) {
         return false;
     }
     $fromTs = CCalendar::Timestamp($Params["from"]);
     $toTs = CCalendar::Timestamp($Params["to"]);
     $fromTs = CCalendar::_fixTimestamp($fromTs);
     $toTs = CCalendar::_fixTimestamp($toTs);
     $arNotifyFields = array('EMAIL_TEMPLATE' => "CALENDAR_INVITATION", 'NOTIFY_MODULE' => "calendar");
     if ($mode == 'accept' || $mode == 'decline') {
         $arNotifyFields['FROM_USER_ID'] = $toUser;
         $arNotifyFields['TO_USER_ID'] = $fromUser;
         if (date('H:i', $fromTs) != '00:00' || date('H:i', $toTs) != '00:00') {
             $Params["from"] = CCalendar::Date($fromTs + CCalendar::GetOffset($fromUser), true, true, true);
             $Params["to"] = CCalendar::Date($toTs + CCalendar::GetOffset($fromUser), true, true, true);
         }
     } else {
         $arNotifyFields['FROM_USER_ID'] = $fromUser;
         $arNotifyFields['TO_USER_ID'] = $toUser;
         if (date('H:i', $fromTs) != '00:00' || date('H:i', $toTs) != '00:00') {
             $Params["from"] = CCalendar::Date($fromTs + CCalendar::GetOffset($toUser), true, true, true);
             $Params["to"] = CCalendar::Date($toTs + CCalendar::GetOffset($toUser), true, true, true);
         }
     }
     $Params["from"] = CCalendar::CutZeroTime($Params["from"]);
     $Params["to"] = CCalendar::CutZeroTime($Params["to"]);
     // If it's event for all day - add one day to timestamp
     if (date("His", $toTs) == '000000') {
         $toTs += self::GetDayLen();
     }
     // Don't send messages for events in the past
     if ($toTs < time()) {
         return false;
     }
     $rs = CUser::GetList($by = "id", $order = "asc", array("ID_EQUAL_EXACT" => $toUser, "ACTIVE" => "Y"));
     if (!$rs->Fetch()) {
         return false;
     }
     $eventId = intVal($Params["eventId"]);
     $calendarUrl = self::GetPathForCalendarEx($arNotifyFields['TO_USER_ID']);
     $calendarUrlEV = $calendarUrl . (strpos($calendarUrl, "?") === false ? '?' : '&') . 'EVENT_ID=' . $eventId;
     $curPath = CCalendar::GetPath();
     $titleWithLink = $Params["name"];
     if ($curPath && $eventId) {
         $curPath = CHTTP::urlDeleteParams($curPath, array("action", "sessid", "bx_event_calendar_request", "EVENT_ID"));
         $curPath = CHTTP::urlAddParams($curPath, array('EVENT_ID' => $eventId));
         $titleWithLink = "[url=" . $curPath . "]" . $Params["name"] . "[/url]";
     }
     $arNotifyFields = array('FROM_USER_ID' => $fromUser, 'TO_USER_ID' => $toUser, 'EMAIL_TEMPLATE' => "CALENDAR_INVITATION", 'NOTIFY_MODULE' => "calendar");
     switch ($mode) {
         case 'invite':
             $arNotifyFields['NOTIFY_EVENT'] = "invite";
             $arNotifyFields['NOTIFY_TYPE'] = IM_NOTIFY_CONFIRM;
             $arNotifyFields['NOTIFY_TAG'] = "CALENDAR|INVITE|" . $eventId . "|" . $toUser;
             $arNotifyFields['NOTIFY_SUB_TAG'] = "CALENDAR|INVITE|" . $eventId;
             $arNotifyFields['MESSAGE'] = GetMessage('EC_MESS_INVITE_SITE', array('#TITLE#' => $Params["name"], '#ACTIVE_FROM#' => $Params["from"]));
             $arNotifyFields['MESSAGE_OUT'] = GetMessage('EC_MESS_INVITE', array('#OWNER_NAME#' => CCalendar::GetUserName($Params['userId']), '#TITLE#' => $Params["name"], '#ACTIVE_FROM#' => $Params["from"]));
             if ($Params['location'] != "") {
                 $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_LOCATION') . ': ' . $Params['location'];
                 $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_LOCATION') . ': ' . $Params['location'];
             }
             if ($Params["meetingText"] != "") {
                 $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_MESS_MEETING_TEXT', array('#MEETING_TEXT#' => $Params["meetingText"]));
                 $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_MEETING_TEXT', array('#MEETING_TEXT#' => $Params["meetingText"]));
             }
             $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_MESS_INVITE_DETAILS_SITE', array('#LINK#' => $calendarUrlEV));
             $arNotifyFields['NOTIFY_BUTTONS'] = array(array('TITLE' => GetMessage('EC_MESS_INVITE_CONF_Y_SITE'), 'VALUE' => 'Y', 'TYPE' => 'accept'), array('TITLE' => GetMessage('EC_MESS_INVITE_CONF_N_SITE'), 'VALUE' => 'N', 'TYPE' => 'cancel'));
             $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_INVITE_CONF_Y', array('#LINK#' => $calendarUrlEV . '&CONFIRM=Y'));
             $arNotifyFields['MESSAGE_OUT'] .= "\n" . GetMessage('EC_MESS_INVITE_CONF_N', array('#LINK#' => $calendarUrlEV . '&CONFIRM=N'));
             $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_INVITE_DETAILS', array('#LINK#' => $calendarUrlEV));
             $arNotifyFields['TITLE'] = GetMessage('EC_MESS_INVITE_TITLE', array('#OWNER_NAME#' => CCalendar::GetUserName($Params['userId']), '#TITLE#' => $Params["name"]));
             break;
         case 'change':
             $arNotifyFields['NOTIFY_EVENT'] = "change";
             $arNotifyFields['NOTIFY_TYPE'] = IM_NOTIFY_CONFIRM;
             $arNotifyFields['NOTIFY_TAG'] = "CALENDAR|INVITE|" . $eventId . "|" . $toUser;
             $arNotifyFields['NOTIFY_SUB_TAG'] = "CALENDAR|INVITE|" . $eventId;
             $arNotifyFields['MESSAGE'] = GetMessage('EC_MESS_INVITE_CHANGED_SITE', array('#TITLE#' => $Params["name"], '#ACTIVE_FROM#' => $Params["from"]));
             $arNotifyFields['MESSAGE_OUT'] = GetMessage('EC_MESS_INVITE_CHANGED', array('#OWNER_NAME#' => CCalendar::GetUserName($Params['userId']), '#TITLE#' => $Params["name"], '#ACTIVE_FROM#' => $Params["from"]));
             if ($Params["meetingText"] != "") {
                 $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_MESS_MEETING_TEXT', array('#MEETING_TEXT#' => $Params["meetingText"]));
                 $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_MEETING_TEXT', array('#MEETING_TEXT#' => $Params["meetingText"]));
             }
             $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_MESS_INVITE_DETAILS_SITE', array('#LINK#' => $calendarUrlEV));
             $arNotifyFields['NOTIFY_BUTTONS'] = array(array('TITLE' => GetMessage('EC_MESS_INVITE_CONF_Y_SITE'), 'VALUE' => 'Y', 'TYPE' => 'accept'), array('TITLE' => GetMessage('EC_MESS_INVITE_CONF_N_SITE'), 'VALUE' => 'N', 'TYPE' => 'cancel'));
             $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_INVITE_CONF_Y', array('#LINK#' => $calendarUrlEV . '&CONFIRM=Y'));
             $arNotifyFields['MESSAGE_OUT'] .= "\n" . GetMessage('EC_MESS_INVITE_CONF_N', array('#LINK#' => $calendarUrlEV . '&CONFIRM=N'));
             $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_INVITE_DETAILS', array('#LINK#' => $calendarUrlEV));
             $arNotifyFields['TITLE'] = GetMessage('EC_MESS_INVITE_CHANGED_TITLE', array('#TITLE#' => $Params["name"]));
             break;
         case 'change_notify':
             $arNotifyFields['NOTIFY_EVENT'] = "change";
             $arNotifyFields['NOTIFY_TAG'] = "CALENDAR|INVITE|" . $eventId . "|" . $toUser;
             $arNotifyFields['NOTIFY_SUB_TAG'] = "CALENDAR|INVITE|" . $eventId;
             $arNotifyFields['MESSAGE'] = GetMessage('EC_MESS_INVITE_CHANGED_SITE', array('#TITLE#' => "[url=" . $calendarUrlEV . "]" . $Params["name"] . "[/url]", '#ACTIVE_FROM#' => $Params["from"]));
             $arNotifyFields['MESSAGE_OUT'] = GetMessage('EC_MESS_INVITE_CHANGED', array('#OWNER_NAME#' => CCalendar::GetUserName($Params['userId']), '#TITLE#' => $Params["name"], '#ACTIVE_FROM#' => $Params["from"]));
             if ($Params["meetingText"] != "") {
                 $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_MESS_MEETING_TEXT', array('#MEETING_TEXT#' => $Params["meetingText"]));
                 $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_MEETING_TEXT', array('#MEETING_TEXT#' => $Params["meetingText"]));
             }
             $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_MESS_INVITE_DETAILS_SITE', array('#LINK#' => $calendarUrlEV));
             $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_INVITE_DETAILS', array('#LINK#' => $calendarUrlEV));
             $arNotifyFields['TITLE'] = GetMessage('EC_MESS_INVITE_CHANGED_TITLE', array('#TITLE#' => $Params["name"]));
             break;
         case 'cancel':
             $arNotifyFields['NOTIFY_EVENT'] = "change";
             $arNotifyFields['NOTIFY_TAG'] = "CALENDAR|INVITE|" . $eventId . "|" . $toUser . "|cancel";
             $arNotifyFields['NOTIFY_SUB_TAG'] = "CALENDAR|INVITE|" . $eventId;
             $arNotifyFields['MESSAGE'] = GetMessage('EC_MESS_INVITE_CANCEL_SITE', array('#TITLE#' => $Params["name"], '#ACTIVE_FROM#' => $Params["from"]));
             $arNotifyFields['MESSAGE_OUT'] = GetMessage('EC_MESS_INVITE_CANCEL', array('#OWNER_NAME#' => CCalendar::GetUserName($Params['userId']), '#TITLE#' => $Params["name"], '#ACTIVE_FROM#' => $Params["from"]));
             $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_MESS_VIEW_OWN_CALENDAR', array('#LINK#' => $calendarUrl));
             $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_VIEW_OWN_CALENDAR_OUT', array('#LINK#' => $calendarUrl));
             $arNotifyFields['TITLE'] = GetMessage('EC_MESS_INVITE_CANCEL_TITLE', array('#TITLE#' => $Params["name"]));
             break;
         case 'accept':
         case 'decline':
             $arNotifyFields['NOTIFY_EVENT'] = "info";
             $arNotifyFields['FROM_USER_ID'] = intVal($Params["guestId"]);
             $arNotifyFields['TO_USER_ID'] = intVal($Params["userId"]);
             $arNotifyFields['NOTIFY_TAG'] = "CALENDAR|INVITE|" . $eventId . "|" . $mode;
             $arNotifyFields['NOTIFY_SUB_TAG'] = "CALENDAR|INVITE|" . $eventId;
             $arNotifyFields['MESSAGE'] = GetMessage($mode == 'accept' ? 'EC_MESS_INVITE_ACCEPTED_SITE' : 'EC_MESS_INVITE_DECLINED_SITE', array('#TITLE#' => "[url=" . $calendarUrlEV . "]" . $Params["name"] . "[/url]", '#ACTIVE_FROM#' => $Params["from"]));
             $arNotifyFields['MESSAGE_OUT'] = GetMessage($mode == 'accept' ? 'EC_MESS_INVITE_ACCEPTED' : 'EC_MESS_INVITE_DECLINED', array('#GUEST_NAME#' => CCalendar::GetUserName($Params['guestId']), '#TITLE#' => $Params["name"], '#ACTIVE_FROM#' => $Params["from"]));
             if ($Params["comment"] != "") {
                 $arNotifyFields['MESSAGE'] .= "\n\n" . GetMessage('EC_MESS_INVITE_ACC_COMMENT', array('#COMMENT#' => $Params["comment"]));
                 $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_INVITE_ACC_COMMENT', array('#COMMENT#' => $Params["comment"]));
             }
             $arNotifyFields['MESSAGE_OUT'] .= "\n\n" . GetMessage('EC_MESS_INVITE_DETAILS', array('#LINK#' => $calendarUrlEV));
             break;
     }
     CIMNotify::Add($arNotifyFields);
     foreach (GetModuleEvents("calendar", "OnSendInvitationMessage", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($Params));
     }
 }
Esempio n. 3
0
 public static function AddComment_Calendar($arFields)
 {
     global $DB;
     if (!CModule::IncludeModule("forum")) {
         return false;
     }
     $ufFileID = array();
     $ufDocID = array();
     $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array("ID", "SOURCE_ID", "SITE_ID"));
     if ($arLog = $dbResult->Fetch()) {
         $arCalendarEvent = CCalendarEvent::GetById($arLog["SOURCE_ID"]);
         if ($arCalendarEvent) {
             $arCalendarSettings = CCalendar::GetSettings();
             $forumID = $arCalendarSettings["forum_id"];
             if ($forumID) {
                 $arFilter = array("FORUM_ID" => $forumID, "XML_ID" => "EVENT_" . $arLog["SOURCE_ID"]);
                 $dbTopic = CForumTopic::GetList(null, $arFilter);
                 if ($dbTopic && ($arTopic = $dbTopic->Fetch())) {
                     $topicID = $arTopic["ID"];
                 } else {
                     $topicID = 0;
                 }
                 $currentUserId = CCalendar::GetCurUserId();
                 $strPermission = $currentUserId == $arCalendarEvent["OWNER_ID"] ? "Y" : "M";
                 $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "PERMISSION_EXTERNAL" => "Q", "PERMISSION" => $strPermission, "APPROVED" => "Y");
                 if ($topicID === 0) {
                     $arFieldsMessage["TITLE"] = "EVENT_" . $arLog["SOURCE_ID"];
                     $arFieldsMessage["TOPIC_XML_ID"] = "EVENT_" . $arLog["SOURCE_ID"];
                 }
                 $arTmp = false;
                 $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp);
                 if (is_array($arTmp)) {
                     if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) {
                         $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"];
                     } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) {
                         $arFieldsMessage["FILES"] = array();
                         foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) {
                             $arFieldsMessage["FILES"][] = array("FILE_ID" => $file_id);
                         }
                     }
                 }
                 $messageID = ForumAddMessage($topicID > 0 ? "REPLY" : "NEW", $forumID, $topicID, 0, $arFieldsMessage, $sError, $sNote);
                 // get UF DOC value and FILE_ID there
                 if ($messageID > 0) {
                     $messageUrl = CCalendar::GetPath("user", $arCalendarEvent["OWNER_ID"]);
                     $messageUrl = $messageUrl . (strpos($messageUrl, "?") === false ? "?" : "&") . "EVENT_ID=" . $arCalendarEvent["ID"] . "&MID=" . $messageID;
                     $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID));
                     while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                         $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                     }
                     $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID);
                 }
             }
         }
     }
     if (!$messageID) {
         $sError = GetMessage("EC_LF_ADD_COMMENT_SOURCE_ERROR");
     }
     return array("SOURCE_ID" => $messageID, "MESSAGE" => $arFieldsMessage ? $arFieldsMessage["POST_MESSAGE"] : false, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $sError, "NOTES" => $sNote, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID), "URL" => $messageUrl);
 }
Esempio n. 4
0
 public static function OnForumCommentIMNotify($entityType, $eventID, $arComment)
 {
     if ($entityType != "EV" || !CModule::IncludeModule("im")) {
         return;
     }
     if (isset($arComment["MESSAGE_ID"]) && intval($arComment["MESSAGE_ID"]) > 0 && ($arCalendarEvent = CCalendarEvent::GetById($eventID))) {
         $arComment["URL"] = CCalendar::GetPath("user", $arCalendarEvent["OWNER_ID"], true);
         $arComment["URL"] .= (strpos($arComment["URL"], "?") === false ? "?" : "&") . "EVENT_ID=" . $arCalendarEvent["ID"] . "&MID=" . intval($arComment["MESSAGE_ID"]);
     }
     CCalendarLiveFeed::NotifyComment($eventID, $arComment);
 }
Esempio n. 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;
 }
Esempio n. 6
0
}
global $USER_FIELD_MANAGER;
$UF = CCalendarEvent::GetEventUserFields($arResult['EVENT']);
$arResult['UF_CRM_CAL_EVENT'] = $UF['UF_CRM_CAL_EVENT'];
if (empty($arResult['UF_CRM_CAL_EVENT']['VALUE'])) {
    $arResult['UF_CRM_CAL_EVENT'] = false;
}
$arResult['UF_WEBDAV_CAL_EVENT'] = $UF['UF_WEBDAV_CAL_EVENT'];
if (empty($arResult['UF_WEBDAV_CAL_EVENT']['VALUE'])) {
    $arResult['UF_WEBDAV_CAL_EVENT'] = false;
}
$arParams['ATTENDEES_SHOWN_COUNT'] = 4;
$arParams['ATTENDEES_SHOWN_COUNT_MAX'] = 8;
$arParams['AVATAR_SIZE'] = 30;
if (!isset($arParams['EVENT_TEMPLATE_URL'])) {
    $editUrl = CCalendar::GetPath('user', '#USER_ID#');
    $arParams['EVENT_TEMPLATE_URL'] = $editUrl . (strpos($editUrl, "?") === false ? '?' : '&') . 'EVENT_ID=#EVENT_ID#';
}
$fromDateTs = CCalendar::Timestamp($arResult['EVENT']['DATE_FROM']);
if ($arResult['EVENT']['DT_SKIP_TIME'] !== "Y") {
    $fromDateTs -= $arResult['EVENT']['~USER_OFFSET_FROM'];
}
$arResult['EVENT']['FROM_WEEK_DAY'] = FormatDate('D', $fromDateTs);
$arResult['EVENT']['FROM_MONTH_DAY'] = FormatDate('j', $fromDateTs);
if ($arResult['EVENT']['IS_MEETING']) {
    $arResult['ATTENDEES_INDEX'] = array();
    $arResult['EVENT']['ACCEPTED_ATTENDEES'] = array();
    $arResult['EVENT']['DECLINED_ATTENDEES'] = array();
    foreach ($arResult['EVENT']['~ATTENDEES'] as $i => $att) {
        $arResult['ATTENDEES_INDEX'][$att["USER_ID"]] = array("STATUS" => $att['STATUS']);
        if ($att['STATUS'] != "Q") {