public static function GetAbsent($users = false, $Params = array()) { global $DB; // Can be called from agent... So we have to create $USER if it is not exists $tempUser = CCalendar::TempUser(false, true); $curUserId = isset($Params['userId']) ? intVal($Params['userId']) : CCalendar::GetCurUserId(); $arUsers = array(); if ($users !== false && is_array($users)) { foreach ($users as $id) { if ($id > 0) { $arUsers[] = intVal($id); } } } if (!count($arUsers)) { $users = false; } // Part 1: select ordinary events $arFilter = array('CAL_TYPE' => 'user', 'DELETED' => 'N', 'ACCESSIBILITY' => 'absent'); if (isset($Params['fromLimit'])) { $arFilter['FROM_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['fromLimit'], false), true, false); } if (isset($Params['toLimit'])) { $arFilter['TO_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['toLimit'], false), true, false); } $arEvents = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'getUserfields' => false, 'parseRecursion' => true, 'fetchAttendees' => false, 'fetchMeetings' => true, 'userId' => $curUserId, 'checkPermissions' => false, 'preciseLimits' => true)); // Part 2: select attendees CTimeZone::Disable(); if (count($arUsers) > 0) { $userQ = ' AND CA.USER_ID in (' . implode(',', $arUsers) . ')'; } else { $userQ = ''; } $strSql = "\n\t\t\tSELECT\n\t\t\t\tCA.EVENT_ID as ID, CA.USER_ID, CA.STATUS, CA.ACCESSIBILITY,\n\t\t\t\tCE.CAL_TYPE,CE.OWNER_ID,CE.NAME," . $DB->DateToCharFunction("CE.DT_FROM") . " as DT_FROM," . $DB->DateToCharFunction("CE.DT_TO") . " as DT_TO, CE.DT_LENGTH, CE.PRIVATE_EVENT, CE.ACCESSIBILITY, CE.IMPORTANCE, CE.IS_MEETING, CE.MEETING_HOST, CE.MEETING, CE.LOCATION, CE.RRULE, CE.EXRULE, CE.RDATE, CE.EXDATE,\n\t\t\t\tCES.SECT_ID\n\t\t\tFROM b_calendar_attendees CA\n\t\t\tLEFT JOIN\n\t\t\t\tb_calendar_event CE ON(CA.EVENT_ID=CE.ID)\n\t\t\tLEFT JOIN\n\t\t\t\tb_calendar_event_sect CES ON (CA.EVENT_ID=CES.EVENT_ID)\n\t\t\tWHERE\n\t\t\t\t\tCE.ID IS NOT NULL\n\t\t\t\tAND\n\t\t\t\t\tCE.DELETED='N'\n\t\t\t\tAND\n\t\t\t\t\tSTATUS='Y'\n\t\t\t\tAND\n\t\t\t\t\tCA.ACCESSIBILITY='absent'\n\t\t\t\t{$userQ}\n\t\t\t"; if (isset($arFilter['FROM_LIMIT'])) { $strSql .= "AND "; if (strtoupper($DB->type) == "MYSQL") { $strSql .= "CE.DT_TO>=FROM_UNIXTIME('" . MkDateTime(FmtDate($arFilter['FROM_LIMIT'], "D.M.Y"), "d.m.Y") . "')"; } elseif (strtoupper($DB->type) == "MSSQL") { $strSql .= "CE.DT_TO>=" . $DB->CharToDateFunction($arFilter['FROM_LIMIT'], "SHORT"); } elseif (strtoupper($DB->type) == "ORACLE") { $strSql .= "CE.DT_TO>=TO_DATE('" . FmtDate($arFilter['FROM_LIMIT'], "D.M.Y") . " 00:00:00','dd.mm.yyyy hh24:mi:ss')"; } } if ($arFilter['TO_LIMIT']) { $strSql .= "AND "; if (strtoupper($DB->type) == "MYSQL") { $strSql .= "CE.DT_FROM<=FROM_UNIXTIME('" . MkDateTime(FmtDate($arFilter['TO_LIMIT'], "D.M.Y") . " 23:59:59", "d.m.Y H:i:s") . "')"; } elseif (strtoupper($DB->type) == "MSSQL") { $strSql .= "CE.DT_FROM<=dateadd(day, 1, " . $DB->CharToDateFunction($arFilter['TO_LIMIT'], "SHORT") . ")"; } elseif (strtoupper($DB->type) == "ORACLE") { $strSql .= "CE.DT_FROM<=TO_DATE('" . FmtDate($arFilter['TO_LIMIT'], "D.M.Y") . " 23:59:59','dd.mm.yyyy hh24:mi:ss')"; } } $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $arEvents2 = array(); while ($event = $res->Fetch()) { $event = self::PreHandleEvent($event); if ($event['CAL_TYPE'] == 'user' && $event['IS_MEETING'] && $event['OWNER_ID'] == $event['USER_ID']) { continue; } if (self::CheckRecurcion($event)) { self::ParseRecursion($arEvents2, $event, array('fromLimit' => $arFilter["FROM_LIMIT"], 'toLimit' => $arFilter["TO_LIMIT"])); } else { self::HandleEvent($arEvents2, $event); } } CTimeZone::Enable(); $arEvents = array_merge($arEvents, $arEvents2); $bSocNet = CModule::IncludeModule("socialnetwork"); $result = array(); $settings = CCalendar::GetSettings(array('request' => false)); foreach ($arEvents as $event) { $userId = isset($event['USER_ID']) ? $event['USER_ID'] : $event['OWNER_ID']; if ($users !== false && !in_array($userId, $arUsers)) { continue; } if ($bSocNet && !CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $userId, "calendar")) { continue; } if ((!$event['CAL_TYPE'] != 'user' || $curUserId != $event['OWNER_ID']) && $curUserId != $event['CREATED_BY'] && !isset($arUserMeeting[$event['ID']])) { $sectId = $event['SECT_ID']; if (!$event['ACCESSIBILITY']) { $event['ACCESSIBILITY'] = 'busy'; } $private = $event['PRIVATE_EVENT'] && $event['CAL_TYPE'] == 'user'; $bManager = false; if (!$private && CCalendar::IsIntranetEnabled() && CModule::IncludeModule('intranet') && $event['CAL_TYPE'] == 'user' && $settings['dep_manager_sub']) { $bManager = in_array($curUserId, CCalendar::GetUserManagers($event['OWNER_ID'], true)); } if ($private || !CCalendarSect::CanDo('calendar_view_full', $sectId) && !$bManager) { if ($private) { $event['NAME'] = '[' . GetMessage('EC_ACCESSIBILITY_' . strtoupper($event['ACCESSIBILITY'])) . ']'; } else { if (!CCalendarSect::CanDo('calendar_view_title', $sectId)) { $event['NAME'] = '[' . GetMessage('EC_ACCESSIBILITY_' . strtoupper($event['ACCESSIBILITY'])) . ']'; } else { $event['NAME'] = $event['NAME'] . ' [' . GetMessage('EC_ACCESSIBILITY_' . strtoupper($event['ACCESSIBILITY'])) . ']'; } } } } $result[] = array('ID' => $event['ID'], 'NAME' => $event['NAME'], 'DATE_FROM' => $event['DT_FROM'], 'DATE_TO' => $event['DT_TO'], 'DT_FROM_TS' => $event['DT_FROM_TS'], 'DT_TO_TS' => $event['DT_TO_TS'], 'CREATED_BY' => $userId, 'DETAIL_TEXT' => '', 'USER_ID' => $userId); } // Sort by DT_FROM_TS usort($result, array('CCalendar', '_NearestSort')); CCalendar::TempUser($tempUser, false); return $result; }
if (is_array($types)) { foreach ($types as $type) { $arTypes[$type["XML_ID"]] = "[" . $type["XML_ID"] . "] " . $type["NAME"]; } } $arParams = array(); // $arComponentParameters["PARAMETERS"] $arParams["CALENDAR_TYPE"] = array("PARENT" => "BASE", "NAME" => GetMessage("EC_TYPE"), "TYPE" => "LIST", "VALUES" => $arTypes, "REFRESH" => 'Y'); if (!isset($arCurrentValues) && count($arTypes) > 0) { $arCurrentValues["CALENDAR_TYPE"] = each($arTypes); $arCurrentValues["CALENDAR_TYPE"] = $arCurrentValues["CALENDAR_TYPE"]["key"]; } if ($arCurrentValues["CALENDAR_TYPE"] != 'user' && $arCurrentValues["CALENDAR_TYPE"] != 'group') { $Sect = CCalendar::GetSectionList(array('CAL_TYPE' => $arCurrentValues["CALENDAR_TYPE"])); if (count($Sect) > 0) { $arSections = array('0' => '- ' . GetMessage("EC_CALENDAR_SECTION_ALL") . ' -'); foreach ($Sect as $section) { $arSections[$section["ID"]] = "[" . $section["ID"] . "] " . $section["NAME"]; } $arParams["CALENDAR_SECTION_ID"] = array("PARENT" => "BASE", "NAME" => GetMessage("EC_CALENDAR_SECTION"), "TYPE" => "LIST", "VALUES" => $arSections); } } if (CCalendar::IsIntranetEnabled() && $bSocNet) { $arParams["B_CUR_USER_LIST"] = array("PARENT" => "BASE", "NAME" => GetMessage("ECL_P_CUR_USER_EVENT_LIST"), "TYPE" => "CHECKBOX", "DEFAULT" => "N", "REFRESH" => "Y"); } $arParams["INIT_DATE"] = array("PARENT" => "BASE", "NAME" => GetMessage("ECL_P_INIT_DATE"), "DEFAULT" => '-' . GetMessage("ECL_P_SHOW_CUR_DATE") . '-'); $arParams["FUTURE_MONTH_COUNT"] = array("PARENT" => "BASE", "TYPE" => "LIST", "NAME" => GetMessage("ECL_P_FUTURE_MONTH_COUNT"), "VALUES" => array("1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "12" => "12", "24" => "24"), "DEFAULT" => "2"); $arParams["DETAIL_URL"] = array("PARENT" => "BASE", "NAME" => GetMessage("ECL_P_DETAIL_URL"), "DEFAULT" => ""); $arParams["EVENTS_COUNT"] = array("PARENT" => "BASE", "NAME" => GetMessage("ECL_P_EVENTS_COUNT"), "DEFAULT" => "5"); $arParams["CACHE_TIME"] = array("PARENT" => "BASE", "NAME" => GetMessage("ECL_P_CACHE_TIME"), "DEFAULT" => "3600"); $arComponentParameters["PARAMETERS"] = $arParams;
public static function GetAccessibilityForUsers($Params) { $res = CCalendarEvent::GetAccessibilityForUsers(array('users' => $Params['users'], 'from' => $Params['from'], 'to' => $Params['to'], 'curEventId' => $Params['curEventId'])); // Fetch absence from intranet if ($Params['getFromHR'] && CCalendar::IsIntranetEnabled()) { $resHR = CIntranetUtils::GetAbsenceData(array('DATE_START' => $Params['from'], 'DATE_FINISH' => $Params['to'], 'USERS' => $Params['users'], 'PER_USER' => true, 'SELECT' => array('ID', 'DATE_ACTIVE_FROM', 'DATE_ACTIVE_TO')), BX_INTRANET_ABSENCE_HR); foreach ($resHR as $userId => $forUser) { if (!isset($res[$userId]) || !is_array($res[$userId])) { $res[$userId] = array(); } foreach ($forUser as $event) { $res[$userId][] = array('FROM_HR' => true, 'ID' => $event['ID'], 'DT_FROM' => $event['DATE_ACTIVE_FROM'], 'DT_TO' => $event['DATE_ACTIVE_TO'], 'ACCESSIBILITY' => 'absent', 'IMPORTANCE' => 'normal', "FROM" => CCalendar::Timestamp($event['DATE_ACTIVE_FROM']), "TO" => CCalendar::Timestamp($event['DATE_ACTIVE_TO'])); } } } return $res; }
die; } if (!CModule::IncludeModule("calendar")) { return; } $adv_mode = $arCurrentValues["ADVANCED_MODE_SETTINGS"] == 'Y'; $eventListMode = $arCurrentValues["EVENT_LIST_MODE"] == 'Y'; $bSocNet = CModule::IncludeModule("socialnetwork"); if ($bSocNet) { $bSocNet = class_exists('CSocNetUserToGroup') && CBXFeatures::IsFeatureEnabled("Calendar"); } $arTypes = array(); $types = CCalendarType::GetList(); if (is_array($types)) { foreach ($types as $type) { $arTypes[$type["XML_ID"]] = "[" . $type["XML_ID"] . "] " . $type["NAME"]; } } // * * * * * * * * * * * * Groups * * * * * * * * * * * * $arComponentParameters = array(); // $arComponentParameters["GROUPS"] = array( // "BASE_SETTINGS" => array("NAME" => GetMessage("EC_GROUP_BASE_SETTINGS"), "SORT" => "100") // ); //* * * * * * * * * * * Parameters * * * * * * * * * * * $arParams = array(); $arParams["CALENDAR_TYPE"] = array("PARENT" => "BASE", "NAME" => GetMessage("EC_TYPE"), "TYPE" => "LIST", "VALUES" => $arTypes); if (CCalendar::IsIntranetEnabled()) { $arParams["ALLOW_SUPERPOSE"] = array("PARENT" => "BASE", "NAME" => GetMessage("EC_P_ALLOW_SUPERPOSE"), "TYPE" => "CHECKBOX", "DEFAULT" => "Y"); $arParams["ALLOW_RES_MEETING"] = array("PARENT" => "BASE", "NAME" => GetMessage("EC_P_ALLOW_RES_MEETING"), "TYPE" => "CHECKBOX", "DEFAULT" => "Y"); } $arComponentParameters["PARAMETERS"] = $arParams;
public static function GetDefaultAccess($type, $ownerId) { if (CCalendar::IsIntranetEnabled()) { $access = array('G2' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view_time')); } else { $access = array('G2' => CCalendar::GetAccessTasksByName('calendar_section', 'calendar_view')); } if ($type == 'user') { } elseif ($type == 'group' && $ownerId > 0) { $access['SG' . $ownerId . '_A'] = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_access'); $access['SG' . $ownerId . '_E'] = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit'); $access['SG' . $ownerId . '_K'] = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_edit'); } else { } // Creator of the section $access['U' . CCalendar::GetUserId()] = CCalendar::GetAccessTasksByName('calendar_section', 'calendar_access'); $arAccessCodes = array(); foreach ($access as $code => $o) { $arAccessCodes[] = $code; } CCalendar::PushAccessNames($arAccessCodes); return $access; }
public static function GetAbsent($users = false, $Params = array()) { // Can be called from agent... So we have to create $USER if it is not exists $tempUser = CCalendar::TempUser(false, true); $curUserId = isset($Params['userId']) ? intVal($Params['userId']) : CCalendar::GetCurUserId(); $arUsers = array(); if ($users !== false && is_array($users)) { foreach ($users as $id) { if ($id > 0) { $arUsers[] = intVal($id); } } } if (!count($arUsers)) { $users = false; } $arFilter = array('DELETED' => 'N', 'ACCESSIBILITY' => 'absent'); if ($users) { $arFilter['CREATED_BY'] = $users; } if (isset($Params['fromLimit'])) { $arFilter['FROM_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['fromLimit'], false), true, false); } if (isset($Params['toLimit'])) { $arFilter['TO_LIMIT'] = CCalendar::Date(CCalendar::Timestamp($Params['toLimit'], false), true, false); } $arEvents = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'parseRecursion' => true, 'getUserfields' => false, 'userId' => $curUserId, 'preciseLimits' => true, 'checkPermissions' => false, 'skipDeclined' => true)); $bSocNet = CModule::IncludeModule("socialnetwork"); $result = array(); $settings = CCalendar::GetSettings(array('request' => false)); foreach ($arEvents as $event) { $userId = isset($event['USER_ID']) ? $event['USER_ID'] : $event['CREATED_BY']; if ($users !== false && !in_array($userId, $arUsers)) { continue; } if ($bSocNet && !CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $userId, "calendar")) { continue; } if ((!$event['CAL_TYPE'] != 'user' || $curUserId != $event['OWNER_ID']) && $curUserId != $event['CREATED_BY'] && !isset($arUserMeeting[$event['ID']])) { $sectId = $event['SECT_ID']; if (!$event['ACCESSIBILITY']) { $event['ACCESSIBILITY'] = 'busy'; } $private = $event['PRIVATE_EVENT'] && $event['CAL_TYPE'] == 'user'; $bManager = false; if (!$private && CCalendar::IsIntranetEnabled() && CModule::IncludeModule('intranet') && $event['CAL_TYPE'] == 'user' && $settings['dep_manager_sub']) { $bManager = in_array($curUserId, CCalendar::GetUserManagers($event['OWNER_ID'], true)); } if ($private || !CCalendarSect::CanDo('calendar_view_full', $sectId) && !$bManager) { $event = self::ApplyAccessRestrictions($event, $userId); } } $skipTime = $event['DT_SKIP_TIME'] === 'Y'; $fromTs = CCalendar::Timestamp($event['DATE_FROM'], false, !$skipTime); $toTs = CCalendar::Timestamp($event['DATE_TO'], false, !$skipTime); if ($event['DT_SKIP_TIME'] !== 'Y') { $fromTs -= $event['~USER_OFFSET_FROM']; $toTs -= $event['~USER_OFFSET_TO']; } $result[] = array('ID' => $event['ID'], 'NAME' => $event['NAME'], 'DATE_FROM' => CCalendar::Date($fromTs, !$skipTime, false), 'DATE_TO' => CCalendar::Date($toTs, !$skipTime, false), 'DT_FROM_TS' => $fromTs, 'DT_TO_TS' => $toTs, 'CREATED_BY' => $userId, 'DETAIL_TEXT' => '', 'USER_ID' => $userId); } // Sort by DATE_FROM_TS_UTC usort($result, array('CCalendar', '_NearestSort')); CCalendar::TempUser($tempUser, false); return $result; }