예제 #1
0
 public static function CanDo($operation, $xmlId = 0, $userId = false)
 {
     global $USER;
     if ($USER->CanDoOperation('edit_php')) {
         return true;
     }
     if (($xmlId == 'group' || $xmlId == 'user') && CCalendar::IsSocNet() && CCalendar::IsSocnetAdmin()) {
         return true;
     }
     return in_array($operation, self::GetOperations($xmlId, $userId));
 }
예제 #2
0
 public static function CanDo($operation, $sectId = 0, $userId = false)
 {
     global $USER;
     if (!isset($USER) || !$sectId) {
         return false;
     }
     if ($USER->CanDoOperation('edit_php')) {
         return true;
     }
     if ((CCalendar::GetType() == 'group' || CCalendar::GetType() == 'user') && CCalendar::IsSocNet() && CCalendar::IsSocnetAdmin()) {
         return true;
     }
     $res = in_array($operation, self::GetOperations($sectId, $userId));
     self::$bClearOperationCache = false;
     return $res;
 }
예제 #3
0
 public static function GetList($Params = array())
 {
     global $DB, $USER_FIELD_MANAGER;
     $getUF = $Params['getUserfields'] !== false;
     $checkPermissions = $Params['checkPermissions'] !== false;
     $bCache = CCalendar::CacheTime() > 0;
     $Params['setDefaultLimit'] = $Params['setDefaultLimit'] === true;
     $userId = isset($Params['userId']) ? intVal($Params['userId']) : CCalendar::GetCurUserId();
     CTimeZone::Disable();
     if ($bCache) {
         $cache = new CPHPCache();
         $cacheId = 'event_list_' . md5(serialize($Params));
         if ($checkPermissions) {
             $cacheId .= 'chper' . CCalendar::GetCurUserId() . '|';
         }
         if (CCalendar::IsSocNet() && CCalendar::IsSocnetAdmin()) {
             $cacheId .= 'socnetAdmin|';
         }
         $cacheId .= CCalendar::GetOffset();
         $cachePath = CCalendar::CachePath() . 'event_list';
         if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath)) {
             $res = $cache->GetVars();
             $arResult = $res["arResult"];
             $arAttendees = $res["arAttendees"];
         }
     }
     if (!$bCache || !isset($arResult)) {
         $arFilter = $Params['arFilter'];
         if ($getUF) {
             $obUserFieldsSql = new CUserTypeSQL();
             $obUserFieldsSql->SetEntity("CALENDAR_EVENT", "CE.ID");
             $obUserFieldsSql->SetSelect(array("UF_*"));
             $obUserFieldsSql->SetFilter($arFilter);
         }
         $fetchMeetings = $Params['fetchMeetings'];
         $Params['fetchAttendees'] = $Params['fetchAttendees'] !== false;
         $skipDeclined = $Params['skipDeclined'] === true;
         if ($Params['setDefaultLimit'] !== false) {
             if (!isset($arFilter["FROM_LIMIT"])) {
                 // default 3 month back
                 $arFilter["FROM_LIMIT"] = CCalendar::Date(time() - 31 * 3 * 24 * 3600, false);
             }
             if (!isset($arFilter["TO_LIMIT"])) {
                 // default one year into the future
                 $arFilter["TO_LIMIT"] = CCalendar::Date(time() + 365 * 24 * 3600, false);
             }
         }
         $arOrder = isset($Params['arOrder']) ? $Params['arOrder'] : array('SORT' => 'asc');
         $arFields = self::GetFields();
         if ($arFilter["DELETED"] === false) {
             unset($arFilter["DELETED"]);
         } elseif (!isset($arFilter["DELETED"])) {
             $arFilter["DELETED"] = "N";
         }
         $ownerId = isset($arFilter['OWNER_ID']) ? $arFilter['OWNER_ID'] : CCalendar::GetOwnerId();
         $arSqlSearch = array();
         if (is_array($arFilter)) {
             $filter_keys = array_keys($arFilter);
             for ($i = 0, $l = count($filter_keys); $i < $l; $i++) {
                 $n = strtoupper($filter_keys[$i]);
                 $val = $arFilter[$filter_keys[$i]];
                 if (is_string($val) && strlen($val) <= 0 || strval($val) == "NOT_REF") {
                     continue;
                 }
                 if ($n == 'FROM_LIMIT') {
                     $ts = CCalendar::Timestamp($val, false);
                     if ($ts > 0) {
                         $arSqlSearch[] = "CE.DATE_TO_TS_UTC>=" . $ts;
                     }
                 } elseif ($n == 'TO_LIMIT') {
                     $ts = CCalendar::Timestamp($val, false);
                     if ($ts > 0) {
                         $arSqlSearch[] = "CE.DATE_FROM_TS_UTC<=" . ($ts + 86399);
                     }
                 } elseif ($n == 'OWNER_ID' && intVal($val) > 0) {
                     $arSqlSearch[] = "CE.OWNER_ID=" . intVal($val);
                 }
                 if ($n == 'NAME') {
                     $arSqlSearch[] = "CE.NAME='" . CDatabase::ForSql($val) . "'";
                 } elseif ($n == 'CREATED_BY') {
                     if (is_array($val)) {
                         $val = array_map(intVal, $val);
                         $arSqlSearch[] = 'CE.CREATED_BY IN (\'' . implode('\',\'', $val) . '\')';
                     } else {
                         if (intVal($val) > 0) {
                             $arSqlSearch[] = "CE.CREATED_BY=" . intVal($val);
                         }
                     }
                 } elseif ($n == 'SECTION') {
                     if (!is_array($val)) {
                         $val = array($val);
                     }
                     $q = "";
                     if (is_array($val)) {
                         $sval = '';
                         foreach ($val as $sectid) {
                             if (intVal($sectid) > 0) {
                                 $sval .= intVal($sectid) . ',';
                             }
                         }
                         $sval = trim($sval, ' ,');
                         if ($sval != '') {
                             $q = 'CES.SECT_ID in (' . $sval . ')';
                         }
                     }
                     if ($q != "") {
                         $arSqlSearch[] = $q;
                     }
                 } elseif ($n == 'DAV_XML_ID' && is_array($val)) {
                     array_walk($val, array($DB, 'ForSql'));
                     $arSqlSearch[] = 'CE.DAV_XML_ID IN (\'' . implode('\',\'', $val) . '\')';
                 } elseif (isset($arFields[$n])) {
                     $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val, 'N');
                 }
             }
         }
         if ($getUF) {
             $r = $obUserFieldsSql->GetFilter();
             if (strlen($r) > 0) {
                 $arSqlSearch[] = "(" . $r . ")";
             }
         }
         if ($skipDeclined) {
             //$arSqlSearch[] = "(CE.IS_MEETING<>1 OR CE.MEETING_STATUS<>'N')";
         }
         $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
         $strOrderBy = '';
         foreach ($arOrder as $by => $order) {
             if (isset($arFields[strtoupper($by)])) {
                 $strOrderBy .= $arFields[strtoupper($by)]["FIELD_NAME"] . ' ' . (strtolower($order) == 'desc' ? 'desc' . (strtoupper($DB->type) == "ORACLE" ? " NULLS LAST" : "") : 'asc' . (strtoupper($DB->type) == "ORACLE" ? " NULLS FIRST" : "")) . ',';
             }
         }
         if (strlen($strOrderBy) > 0) {
             $strOrderBy = "ORDER BY " . rtrim($strOrderBy, ",");
         }
         $selectList = "";
         foreach ($arFields as $field) {
             $selectList .= $field['FIELD_NAME'] . ", ";
         }
         $strSql = "\n\t\t\t\tSELECT " . $selectList . "CES.SECT_ID, CES.REL\n\t\t\t\t\t" . ($getUF ? $obUserFieldsSql->GetSelect() : '') . "\n\t\t\t\tFROM\n\t\t\t\t\tb_calendar_event CE\n\t\t\t\tLEFT JOIN b_calendar_event_sect CES ON (CE.ID=CES.EVENT_ID)\n\t\t\t\t" . ($getUF ? $obUserFieldsSql->GetJoin("CE.ID") : '') . "\n\t\t\t\tWHERE\n\t\t\t\t\t{$strSqlSearch}\n\t\t\t\t{$strOrderBy}";
         $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($getUF) {
             $res->SetUserFields($USER_FIELD_MANAGER->GetUserFields("CALENDAR_EVENT"));
         }
         $arResult = array();
         $arMeetingIds = array();
         $arEvents = array();
         $bIntranet = CCalendar::IsIntranetEnabled();
         $defaultMeetingSection = false;
         while ($event = $res->Fetch()) {
             $event['IS_MEETING'] = intVal($event['IS_MEETING']) > 0;
             if ($event['IS_MEETING'] && $event['CAL_TYPE'] == 'user' && $event['OWNER_ID'] == $userId && !$event['SECT_ID']) {
                 if (!$defaultMeetingSection) {
                     $defaultMeetingSection = CCalendar::GetMeetingSection($userId);
                     if (!$defaultMeetingSection || !CCalendarSect::GetById($defaultMeetingSection, false)) {
                         $sectRes = CCalendarSect::GetSectionForOwner($event['CAL_TYPE'], $userId);
                         $defaultMeetingSection = $sectRes['sectionId'];
                     }
                 }
                 self::ConnectEventToSection($event['ID'], $defaultMeetingSection);
                 $event['SECT_ID'] = $defaultMeetingSection;
             }
             $arEvents[] = $event;
             if ($bIntranet && $event['IS_MEETING']) {
                 $arMeetingIds[] = $event['ID'];
             }
         }
         if ($Params['fetchAttendees'] && count($arMeetingIds) > 0) {
             $arAttendees = self::GetAttendees($arMeetingIds);
         } else {
             $arAttendees = array();
         }
         foreach ($arEvents as $event) {
             $event["ACCESSIBILITY"] = trim($event["ACCESSIBILITY"]);
             if ($bIntranet && $event['IS_MEETING']) {
                 if (isset($event['MEETING']) && $event['MEETING'] != "") {
                     $event['MEETING'] = unserialize($event['MEETING']);
                     if (!is_array($event['MEETING'])) {
                         $event['MEETING'] = array();
                     }
                 }
                 //					if ($arUserMeeting[$event['ID']])
                 //					{
                 //						$status = $arUserMeeting[$event['ID']]['STATUS'];
                 //						if ($skipDeclined && $status == "N")
                 //							continue;
                 //
                 //						if ($status == "Y" || $userId == $ownerId)
                 //						{
                 //							$event['USER_MEETING'] = array(
                 //								'ATTENDEE_ID' => $ownerId,
                 //								'ACCESSIBILITY' => $arUserMeeting[$event['ID']]['ACCESSIBILITY'],
                 //								'COLOR' => $arUserMeeting[$event['ID']]['COLOR'],
                 //								'TEXT_COLOR' => $arUserMeeting[$event['ID']]['TEXT_COLOR'],
                 //								'DESCRIPTION' => $arUserMeeting[$event['ID']]['DESCRIPTION'],
                 //								'STATUS' => $status,
                 //								'REMIND' => array()
                 //							);
                 //
                 //							if (isset($arUserMeeting[$event['ID']]['REMIND']) && $arUserMeeting[$event['ID']]['REMIND'] != "")
                 //							{
                 //								$event['USER_MEETING']['REMIND'] = unserialize($arUserMeeting[$event['ID']]['REMIND']);
                 //								if (!is_array($event['USER_MEETING']['REMIND']))
                 //									$event['USER_MEETING']['REMIND'] = array();
                 //							}
                 //						}
                 //						else if (is_array($arFilter['SECTION']) && !in_array($event['SECT_ID'], $arFilter['SECTION']))
                 //						{
                 //							continue;
                 //						}
                 //					}
             }
             if (isset($event['REMIND']) && $event['REMIND'] != "") {
                 $event['REMIND'] = unserialize($event['REMIND']);
                 if (!is_array($event['REMIND'])) {
                     $event['REMIND'] = array();
                 }
             }
             if ($bIntranet && $event['IS_MEETING'] && isset($arAttendees[$event['ID']]) && count($arAttendees[$event['ID']]) > 0) {
                 $event['~ATTENDEES'] = $arAttendees[$event['ID']];
             }
             $checkPermissionsForEvent = $userId != $event['CREATED_BY'];
             // It's creator
             // It's event in user's calendar
             if ($checkPermissionsForEvent && $event['CAL_TYPE'] == 'user' && $userId == $event['OWNER_ID']) {
                 $checkPermissionsForEvent = false;
             }
             if ($checkPermissionsForEvent && $event['IS_MEETING'] && $event['USER_MEETING'] && $event['USER_MEETING']['ATTENDEE_ID'] == $userId) {
                 $checkPermissionsForEvent = false;
             }
             if ($checkPermissionsForEvent && $event['IS_MEETING'] && is_array($event['~ATTENDEES'])) {
                 foreach ($event['~ATTENDEES'] as $att) {
                     if ($att['USER_ID'] == $userId) {
                         $checkPermissionsForEvent = false;
                         break;
                     }
                 }
             }
             if ($checkPermissions && $checkPermissionsForEvent) {
                 $event = self::ApplyAccessRestrictions($event, $userId);
             }
             if ($event === false) {
                 continue;
             }
             $event = self::PreHandleEvent($event);
             if ($Params['parseRecursion'] && self::CheckRecurcion($event)) {
                 self::ParseRecursion($arResult, $event, array('fromLimit' => $arFilter["FROM_LIMIT"], 'toLimit' => $arFilter["TO_LIMIT"], 'instanceCount' => isset($Params['maxInstanceCount']) ? $Params['maxInstanceCount'] : false, 'preciseLimits' => isset($Params['preciseLimits']) ? $Params['preciseLimits'] : false));
             } else {
                 self::HandleEvent($arResult, $event);
             }
         }
         if ($bCache) {
             $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath);
             $cache->EndDataCache(array("arResult" => $arResult, "arAttendees" => $arAttendees));
         }
     }
     CTimeZone::Enable();
     //self::$lastAttendeesList = $arAttendees;
     if (!is_array(self::$lastAttendeesList)) {
         self::$lastAttendeesList = $arAttendees;
     } elseif (is_array($arAttendees)) {
         foreach ($arAttendees as $eventId => $att) {
             self::$lastAttendeesList[$eventId] = $att;
         }
     }
     return $arResult;
 }