Example #1
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;
 }
Example #2
0
 public static function SetMeetingStatus($userId, $eventId, $status = 'Q', $comment = '', $parentEventId)
 {
     CTimeZone::Disable();
     global $DB, $CACHE_MANAGER;
     $eventId = intVal($eventId);
     $userId = intVal($userId);
     if (!in_array($status, array("Q", "Y", "N", "H", "M"))) {
         $status = "Q";
     }
     $event = CCalendarEvent::GetById($eventId, false);
     if ($event && $event['IS_MEETING'] && intVal($event['PARENT_ID']) > 0) {
         $strSql = "UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array("MEETING_STATUS" => $status)) . " WHERE PARENT_ID=" . intVal($event['PARENT_ID']) . " AND OWNER_ID=" . $userId;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         CCalendarSect::UpdateModificationLabel($event['SECT_ID']);
         // If it's open meeting and our attendee is not on the list
         if ($event['MEETING'] && $event['MEETING']['OPEN'] && ($status == 'Y' || $status == 'M')) {
             $arAttendees = self::GetAttendees(array($event['PARENT_ID']));
             $arAttendees = $arAttendees[$event['PARENT_ID']];
             $attendeeExist = false;
             foreach ($arAttendees as $attendee) {
                 if ($attendee['USER_ID'] == $userId) {
                     $attendeeExist = true;
                     break;
                 }
             }
             if (!$attendeeExist) {
                 // 1. Create another childEvent for new attendee
                 $AllFields = self::GetFields();
                 $dbFields = array();
                 foreach ($event as $field => $val) {
                     if (isset($AllFields[$field]) && $field != "ID" && $field != "ATTENDEES_CODES") {
                         $dbFields[$field] = $event[$field];
                     }
                 }
                 $dbFields['MEETING_STATUS'] = $status;
                 $dbFields['CAL_TYPE'] = 'user';
                 $dbFields['OWNER_ID'] = $userId;
                 $dbFields['PARENT_ID'] = $event['PARENT_ID'];
                 $dbFields['MEETING'] = serialize($event['MEETING']);
                 $dbFields['REMIND'] = serialize($event['REMIND']);
                 $eventId = CDatabase::Add("b_calendar_event", $dbFields, array('DESCRIPTION', 'MEETING', 'RDATE', 'EXDATE'));
                 $DB->Query("UPDATE b_calendar_event SET " . $DB->PrepareUpdate("b_calendar_event", array('DAV_XML_ID' => $eventId)) . " WHERE ID=" . IntVal($eventId), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 $sectionId = CCalendarSect::GetLastUsedSection('user', $userId, $userId);
                 if (!$sectionId || !CCalendarSect::GetById($sectionId, false)) {
                     $sectRes = CCalendarSect::GetSectionForOwner('user', $userId);
                     $sectionId = $sectRes['sectionId'];
                 }
                 if ($eventId && $sectionId) {
                     self::ConnectEventToSection($eventId, $sectionId);
                 }
                 // 2. Update ATTENDEES_CODES
                 $attendeesCodes = $event['ATTENDEES_CODES'];
                 $attendeesCodes[] = 'U' . intVal($userId);
                 $attendeesCodes = array_unique($attendeesCodes);
                 $DB->Query("UPDATE b_calendar_event SET " . "ATTENDEES_CODES='" . implode(',', $attendeesCodes) . "'" . " WHERE PARENT_ID=" . intVal($event['PARENT_ID']), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
                 CCalendarSect::UpdateModificationLabel(array($sectionId));
             }
         }
         // Notify author of event
         if ($event['MEETING']['NOTIFY'] && $userId != $event['MEETING_HOST']) {
             // Send message to the author
             $fromTo = CCalendarEvent::GetEventFromToForUser($event, $event['MEETING_HOST']);
             CCalendar::SendMessage(array('mode' => $status == "Y" ? 'accept' : 'decline', 'name' => $event['NAME'], "from" => $fromTo["DATE_FROM"], "to" => $fromTo["DATE_TO"], "location" => CCalendar::GetTextLocation($event["LOCATION"]), "comment" => $comment, "guestId" => $userId, "eventId" => $event['PARENT_ID'], "userId" => $event['MEETING_HOST']));
         }
         CCalendarSect::UpdateModificationLabel(array($event['SECTIONS'][0]));
         $CACHE_MANAGER->ClearByTag('calendar_user_' . $userId);
         $CACHE_MANAGER->ClearByTag('calendar_user_' . $event['CREATED_BY']);
     }
     CTimeZone::Enable();
     CCalendar::ClearCache(array('attendees_list', 'event_list'));
 }