Exemplo n.º 1
0
 function UpdateListItems($listName, $updates)
 {
     global $USER;
     $arStatusValues = array_flip($this->arStatusValues);
     $arPriorityValues = array_flip($this->arPriorityValues);
     $arWeekDays = array_flip($this->arWeekDays);
     if (!($listName_original = CIntranetUtils::checkGUID($listName))) {
         return new CSoapFault('Data error', 'Wrong GUID - ' . $listName);
     }
     $obResponse = new CXMLCreator('Results');
     $listName = ToUpper(CIntranetUtils::makeGUID($listName_original));
     $obRes = CIBlockSection::GetList(array('SORT' => 'ASC'), array('XML_ID' => $listName_original));
     if (!($arSection = $obRes->Fetch())) {
         return new CSoapFault('List not found', 'List with ' . $listName . ' GUID is not found');
     }
     $bGroup = $arSection['SOCNET_GROUP_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');
             }
         }
     }
     $obCalendar = new CEventCalendar();
     $obCalendar->Init(array('ownerType' => $bGroup ? 'GROUP' : 'USER', 'ownerId' => $bGroup ? $arSection['SOCNET_GROUP_ID'] : (is_object($USER) && $USER->GetID() ? $USER->GetID() : false), 'bOwner' => true, 'iblockId' => $arSection['IBLOCK_ID'], 'bCache' => false));
     // dirty hack
     $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true));
     $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();
     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'));
             if (CECEvent::Delete(array('id' => $arData['ID'], 'ownerType' => $bGroup ? 'GROUP' : 'USER', 'ownerId' => $bGroup ? $arSection['SOCNET_GROUP_ID'] : (is_object($USER) && $USER->GetID() ? $USER->GetID() : false), 'bOwner' => true, 'iblockId' => $arSection['IBLOCK_ID'], 'RMiblockId' => $this->__getRMIblockID(), 'allowResMeeting' => true))) {
                 CEventCalendar::ClearCache('/event_calendar/events/' . $arSection['IBLOCK_ID'] . '/');
                 $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']);
             $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) {
                 return new CSoapFault('Unsupported event type', 'Event type unsupported');
             }
             $arData['fRecurrence'] = intval($arData['fRecurrence']);
             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['RecurrenceData'] = array();
                 switch ($obNode->name) {
                     case 'daily':
                         // hack. we have no "work days" daily recurence
                         if ($obNode->getAttribute('weekday') == 'TRUE') {
                             $arData['RecurrenceData']['PERIOD_TYPE'] = 'WEEKLY';
                             $arData['RecurrenceData']['PERIOD_ADDITIONAL'] = '0,1,2,3,4';
                             $arData['RecurrenceData']['PERIOD_COUNT'] = 1;
                         } else {
                             $arData['RecurrenceData']['PERIOD_TYPE'] = 'DAILY';
                             $arData['RecurrenceData']['PERIOD_COUNT'] = $obNode->getAttribute('dayFrequency');
                         }
                         $time_end = strtotime(date(date('Y-m-d', $arData['EventDate']) . ' H:i:s', $arData['EndDate']));
                         $arData['RecurrenceData']['EVENT_LENGTH'] = $time_end - $arData['EventDate'];
                         break;
                     case 'weekly':
                         $arData['RecurrenceData']['PERIOD_TYPE'] = 'WEEKLY';
                         $arData['RecurrenceData']['PERIOD_ADDITIONAL'] = '';
                         foreach ($arWeekDays as $day => $value) {
                             if ($obNode->getAttribute($day)) {
                                 $arData['RecurrenceData']['PERIOD_ADDITIONAL'] .= ($arData['RecurrenceData']['PERIOD_ADDITIONAL'] == '' ? '' : ',') . $value;
                             }
                         }
                         $arData['RecurrenceData']['PERIOD_COUNT'] = $obNode->getAttribute('weekFrequency');
                         $time_end = strtotime(date(date('Y-m-d', $arData['EventDate']) . ' H:i:s', $arData['EndDate']));
                         $arData['RecurrenceData']['EVENT_LENGTH'] = $time_end - $arData['EventDate'];
                         break;
                     case 'monthly':
                         $arData['RecurrenceData']['PERIOD_TYPE'] = 'MONTHLY';
                         $arData['RecurrenceData']['PERIOD_COUNT'] = $obNode->getAttribute('monthFrequency');
                         $time_end = strtotime(date(date('Y-m', $arData['EventDate']) . '-d H:i:s', $arData['EndDate']));
                         $arData['RecurrenceData']['EVENT_LENGTH'] = $time_end - $arData['EventDate'];
                         break;
                     case 'yearly':
                         $arData['RecurrenceData']['PERIOD_TYPE'] = 'YEARLY';
                         $arData['RecurrenceData']['PERIOD_COUNT'] = $obNode->getAttribute('yearFrequency');
                         $time_end = strtotime(date(date('Y', $arData['EventDate']) . '-m-d H:i:s', $arData['EndDate']));
                         $arData['RecurrenceData']['EVENT_LENGTH'] = $time_end - $arData['EventDate'];
                         break;
                 }
                 $obWhile = $obRule->children[2];
                 if ($obWhile->name == 'repeatForever') {
                     $arData['EndDate'] = MakeTimeStamp('');
                 } elseif ($obWhile->name == 'windowEnd') {
                     $arData['EndDate'] = $this->__makeTS($obWhile->textContent());
                 }
             }
             $TZBias = $arData['fAllDayEvent'] ? 0 : $TZBias;
             $arData['EventDate'] += $TZBias;
             $arData['EndDate'] += $TZBias;
             $arRes = array('iblockId' => $obCalendar->iblockId, 'ownerType' => $obCalendar->ownerType, 'ownerId' => $obCalendar->ownerId, 'RMiblockId' => $this->__getRMIblockID(), 'allowResMeeting' => true, 'bNew' => $arData['_command'] == 'New', 'fullUrl' => $obCalendar->fullUrl, 'userId' => $obCalendar->userId, 'pathToUserCalendar' => $obCalendar->pathToUserCalendar, 'pathToGroupCalendar' => $obCalendar->pathToGroupCalendar, 'userIblockId' => $obCalendar->userIblockId, 'calendarId' => $arSection['ID'], 'sectionId' => $arSection['IBLOCK_SECTION_ID'], 'dateFrom' => ConvertTimeStamp($arData['EventDate'], 'FULL'), 'dateTo' => ConvertTimeStamp($arData['EndDate'], 'FULL'), 'name' => $arData['Title'], 'desc' => $arData['Description'], 'prop' => array('ACCESSIBILITY' => $arStatusValues[$arData['MetaInfo_BusyStatus']], 'IMPORTANCE' => $arPriorityValues[$arData['MetaInfo_Priority']]), 'notDisplayCalendar' => true, 'location' => array('new' => CEventCalendar::ParseLocation($arData['Location'])));
             if ($arData['fRecurrence']) {
                 $arRes['prop']['PERIOD_TYPE'] = $arData['RecurrenceData']['PERIOD_TYPE'];
                 $arRes['prop']['PERIOD_COUNT'] = $arData['RecurrenceData']['PERIOD_COUNT'];
                 $arRes['prop']['EVENT_LENGTH'] = $arData['RecurrenceData']['EVENT_LENGTH'];
                 $arRes['prop']['PERIOD_ADDITIONAL'] = $arData['RecurrenceData']['PERIOD_ADDITIONAL'];
             }
             if ($arData['_command'] == 'New') {
                 $arRes['bNew'] = true;
             } else {
                 $arRes['id'] = $arData['ID'];
             }
             if (!$arRes['bNew']) {
                 if ($arOldEvent = $obCalendar->GetEvents(array('ownerType' => 'USER', 'ownerId' => $arSection['CREATED_BY'], 'bOwner' => true, 'iblockId' => $arSection['IBLOCK_ID'], 'sectionId' => $arSection['ID'], 'eventId' => $arRes['id'], 'arCalendarIds' => array($arSection['ID']), 'forExport' => true))) {
                     $arOldEvent = $arOldEvent[0];
                     $arRes['prop']['VERSION'] = $arOldEvent['VERSION'];
                     if ($arOldEvent['LOCATION']) {
                     }
                     $arRes['location']['old'] = CEventCalendar::ParseLocation($arOldEvent['LOCATION']);
                     if ($arRes['location']['old']['mrid']) {
                         $arRes['location']['new'] = 'ECMR_' . $arRes['location']['old']['mrid'];
                         $arRes['prop']['VERSION']++;
                     }
                     $bMaster = true;
                     if (is_array($arOldEvent['GUESTS']) && count($arOldEvent['GUESTS']) > 0) {
                         $arRes['GUESTS'] = array();
                         foreach ($arOldEvent['GUESTS'] as $arGuest) {
                             $arRes['GUESTS'][] = $arGuest['id'];
                         }
                     }
                     if (is_array($arOldEvent['HOST'])) {
                         $bMaster = false;
                         $arRes['prop']['PARENT'] = $arOldEvent['HOST']['parentId'];
                     }
                     if (!$bMaster) {
                         $arRes['name'] = $arOldEvent['NAME'];
                         $arRes['desc'] = $arOldEvent['DETAIL_TEXT'];
                         $arRes['dateFrom'] = $arOldEvent['DATE_FROM'];
                         $arRes['dateTo'] = $arOldEvent['DATE_TO'];
                         if (is_array($arOldEvent['PERIOD'])) {
                             $arRes['prop']['PERIOD_TYPE'] = $arOldEvent['PERIOD']['TYPE'];
                             $arRes['prop']['PERIOD_COUNT'] = $arOldEvent['PERIOD']['COUNT'];
                             $arRes['prop']['EVENT_LENGTH'] = $arOldEvent['PERIOD']['LENGTH'];
                             $arRes['prop']['PERIOD_ADDITIONAL'] = $arOldEvent['PERIOD']['DAYS'];
                         } else {
                             unset($arRes['prop']['PERIOD_TYPE']);
                             unset($arRes['prop']['PERIOD_COUNT']);
                             unset($arRes['prop']['EVENT_LENGTH']);
                             unset($arRes['prop']['PERIOD_ADDITIONAL']);
                         }
                     } else {
                         if (is_array($arOldEvent['PERIOD']) && !$arData['RecurrenceData'] && $arData['EventType'] == 1) {
                             $arRes['dateFrom'] = $arOldEvent['DATE_FROM'];
                             $arRes['dateTo'] = $arOldEvent['DATE_TO'];
                             $arRes['prop']['PERIOD_TYPE'] = $arOldEvent['PERIOD']['TYPE'];
                             $arRes['prop']['PERIOD_COUNT'] = $arOldEvent['PERIOD']['COUNT'];
                             $arRes['prop']['EVENT_LENGTH'] = $arOldEvent['PERIOD']['LENGTH'];
                             $arRes['prop']['PERIOD_ADDITIONAL'] = $arOldEvent['PERIOD']['DAYS'];
                         }
                     }
                 } else {
                     return new CSoapFault('Event not found', 'Event ' . $arRes['id'] . ' not found on server');
                 }
             }
             if (is_array($arRes['location']['old'])) {
                 $arRes['location']['old'] = $arRes['location']['old']['str'];
             }
             if (is_array($arRes['location']['new'])) {
                 $arRes['location']['new'] = $arRes['location']['new']['str'];
             }
             if ($EventID = $obCalendar->SaveEvent($arRes)) {
                 CEventCalendar::ClearCache('/event_calendar/events/' . $arRes['iblockId'] . '/');
                 // 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);
             }
         }
     }
     $arMethodParams = array('ownerType' => 'USER', 'ownerId' => is_object($USER) && $USER->GetID() ? $USER->GetID() : false, 'iblockId' => $arSection['IBLOCK_ID'], 'sectionId' => $arSection['ID'], 'arCalendarIds' => array($arSection['ID']), 'forExport' => true, 'bLoadAll' => false, 'timestampFrom' => $dateStart);
     $arCalendarEntries = $obCalendar->GetEvents($arMethodParams);
     foreach ($arCalendarEntries as $arEntry) {
         if ($arResponseRows[$arEntry['ID']]) {
             $obRow = $this->__getRow($arEntry, $listName, $last_change = 0);
             $obRow->setAttribute('xmlns:z', "#RowsetSchema");
             if ($arReplicationIDs[$arEntry['ID']]) {
                 $obRow->setAttribute('MetaInfo_ReplicationID', $arReplicationIDs[$arEntry['ID']]);
             }
             $arResponseRows[$arEntry['ID']]->addChild($obRow);
         }
         $obResponse->addChild($arResponseRows[$arEntry['ID']]);
     }
     return array('UpdateListItemsResult' => $obResponse);
 }
Exemplo n.º 2
0
 public function Get($arParams)
 {
     $ID = intval($arParams['ID']);
     $site_id = $arParams['site_id'];
     $calIblock = COption::GetOptionInt('intranet', 'iblock_calendar', null, $site_id);
     $dbRes = CIBlockElement::GetByID($ID);
     if ($arRes = $dbRes->Fetch()) {
         $calIblockSection = $arRes['IBLOCK_SECTION_ID'];
     } else {
         return false;
     }
     CModule::IncludeModule('socialnetwork');
     $obCalendar = new CEventCalendar();
     $obCalendar->Init(array('ownerType' => 'USER', 'ownerId' => $arRes['CREATED_BY'], 'bOwner' => true, 'iblockId' => $calIblock, 'userIblockId' => $calIblock));
     $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true));
     $arEvents = $obCalendar->GetEvents(array('iblockId' => $calIblock, 'sectionId' => $calIblockSection, 'eventId' => $ID, 'bLoadAll' => true, 'ownerType' => 'USER'));
     return $arEvents[0];
 }
Exemplo n.º 3
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();
         }
     }
 }