function tasksTaskEditAjaxHandler() { global $DB; if (isset($_POST['NAME_TEMPLATE'])) { $nameTemplate = $_POST['NAME_TEMPLATE']; } else { $nameTemplate = CSite::getNameFormat(false); } if (!check_bitrix_sessid()) { die; } switch ($_POST['action']) { case 'tasks_isUserMemberOfGroup': if (!CModule::IncludeModule('socialnetwork')) { throw new Exception($_POST['action'] . ': socialnetwork module failed to load.'); } if (!isset($_POST['groupId']) || !isset($_POST['userId']) || $_POST['groupId'] < 0 || $_POST['userId'] < 0) { throw new Exception($_POST['action'] . ': invalid userId or groupId'); } $rc = CSocNetUserToGroup::GetUserRole((int) $_POST['userId'], (int) $_POST['groupId']); if ($rc === false || $rc == SONET_ROLES_REQUEST) { echo 'N'; } else { echo 'Y'; } break; case 'getWarnings': if (isset($_POST['TASK']['RESPONSIBLE_ID'])) { $responsibleId = (int) $_POST['TASK']['RESPONSIBLE_ID']; $responsibleName = '#unknown user#'; $rsUser = CUser::GetList($by = 'ID', $order = 'ASC', array('ID' => $responsibleId), array('FIELDS' => array('NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN'))); if ($arUser = $rsUser->fetch()) { $responsibleName = CUser::FormatName($nameTemplate, array("NAME" => $arUser["NAME"], "LAST_NAME" => $arUser["LAST_NAME"], "SECOND_NAME" => $arUser["SECOND_NAME"], "LOGIN" => $arUser["LOGIN"]), true, false); } if (isset($_POST['TASK']['GROUP_ID']) && $_POST['TASK']['GROUP_ID']) { if (CModule::IncludeModule('socialnetwork')) { $rc = CSocNetUserToGroup::GetUserRole($responsibleId, (int) $_POST['TASK']['GROUP_ID']); if ($rc === false || $rc == SONET_ROLES_REQUEST) { $arGroup = CSocNetGroup::GetByID($_POST['TASK']['GROUP_ID']); echo '<div>' . htmlspecialcharsbx(str_replace(array('#FORMATTED_USER_NAME#', '#GROUP_NAME#'), array($responsibleName, $arGroup["NAME"]), GetMessage('TASKS_WARNING_RESPONSIBLE_NOT_IN_TASK_GROUP'))) . "</div>\n"; } } } if (CModule::IncludeModule('intranet')) { $dt = ConvertTimeStamp(false, 'SHORT'); $arAbsenceData = CIntranetUtils::GetAbsenceData(array('USERS' => array($responsibleId), 'DATE_START' => $dt, 'DATE_FINISH' => $dt, 'PER_USER' => false), $MODE = BX_INTRANET_ABSENCE_ALL); $curTs = MakeTimeStamp(ConvertTimeStamp(false, 'FULL')); if (isset($arAbsenceData[0])) { if (array_key_exists('DATE_ACTIVE_FROM', $arAbsenceData[0]) && array_key_exists('DATE_ACTIVE_TO', $arAbsenceData[0])) { $fromTs = MakeTimeStamp($arAbsenceData[0]['DATE_ACTIVE_FROM']); $toTs = MakeTimeStamp($arAbsenceData[0]['DATE_ACTIVE_TO']); } else { $fromTs = MakeTimeStamp($arAbsenceData[0]['DATE_FROM']); $toTs = MakeTimeStamp($arAbsenceData[0]['DATE_TO']); } if ($toTs > $curTs) { $from = FormatDate($DB->DateFormatToPhp(CSite::GetDateFormat(CIntranetUtils::IsDateTime($fromTs) ? 'FULL' : 'SHORT')), $fromTs); $to = FormatDate($DB->DateFormatToPhp(CSite::GetDateFormat(CIntranetUtils::IsDateTime($toTs) ? 'FULL' : 'SHORT')), $toTs); echo '<div>' . htmlspecialcharsbx(str_replace(array('#FORMATTED_USER_NAME#', '#DATE_FROM#', '#DATE_TO#', '#ABSCENCE_REASON#'), array($responsibleName, $from, $to, $arAbsenceData[0]['NAME']), GetMessage('TASKS_WARNING_RESPONSIBLE_IS_ABSENCE'))) . '</div>'; } } } } break; default: throw new Exception('Requested action is unknown!'); break; } }
break; case 'now': default: $date_start = $date_finish = date($format); break; } $arFilter = array('CALENDAR_IBLOCK_ID' => $arParams['CALENDAR_IBLOCK_ID'], 'ABSENCE_IBLOCK_ID' => $arParams['IBLOCK_ID'], 'DATE_START' => $date_start, 'DATE_FINISH' => $date_finish, 'USERS' => $USERS, 'PER_USER' => false); //echo '<pre>'; print_r($arFilter); echo '</pre>'; $arResult['ENTRIES'] = CIntranetUtils::GetAbsenceData($arFilter, BX_INTRANET_ABSENCE_ALL); $arUserIDs = array(); foreach ($arResult['ENTRIES'] as $key => $arEntry) { $arUserIDs[] = $arEntry['USER_ID']; $arResult['ENTRIES'][$key]['DATE_ACTIVE_FROM_TS'] = MakeTimeStamp($arEntry['DATE_FROM'], CSite::GetDateFormat('FULL')); $arResult['ENTRIES'][$key]['DATE_ACTIVE_TO_TS'] = MakeTimeStamp($arEntry['DATE_TO'], CSite::GetDateFormat('FULL')); $arResult['ENTRIES'][$key]['DATE_FROM'] = FormatDate($arParams['DATE' . (CIntranetUtils::IsDateTime($arResult['ENTRIES'][$key]['DATE_ACTIVE_FROM_TS']) ? '_TIME' : '') . '_FORMAT'], $arResult['ENTRIES'][$key]['DATE_ACTIVE_FROM_TS']); $arResult['ENTRIES'][$key]['DATE_TO'] = FormatDate($arParams['DATE' . (CIntranetUtils::IsDateTime($arResult['ENTRIES'][$key]['DATE_ACTIVE_TO_TS']) ? '_TIME' : '') . '_FORMAT'], $arResult['ENTRIES'][$key]['DATE_ACTIVE_TO_TS']); if ($arParams['mode'] == 'now') { $test1 = $arResult['ENTRIES'][$key]['DATE_ACTIVE_FROM_TS']; $test2 = $arResult['ENTRIES'][$key]['DATE_ACTIVE_TO_TS']; if (0 == ($test2 + date('Z')) % 86400) { $test2 += 86399; } if ($test1 > time() || $test2 < time()) { unset($arResult['ENTRIES'][$key]); } } } // foreach ($arResult['ENTRIES'] as $key => $arEntry) // echo $arEntry['DATE_FROM'].' - '.$arEntry['DATE_TO'].'<br />'; usort($arResult['ENTRIES'], array('CIntranetUtils', '__absence_sort')); // echo '<hr />';
} else { $arEvent = CCalendarEvent::GetById($arParams['ID']); $arResult['ENTRY'] = array('ID' => $arEvent['ID'], 'NAME' => $arEvent['NAME'], 'PREVIEW_TEXT' => '', 'DETAIL_TEXT' => $arEvent['DESCRIPTION'], 'DATE_ACTIVE_FROM' => $arEvent['DT_FROM_TS'] + date('Z') - date('Z', $arEvent['DT_FROM_TS']), 'DATE_ACTIVE_TO' => $arEvent['DT_TO_TS'] + date('Z') - date('Z', $arEvent['DT_TO_TS']), 'USER' => $arEvent['CREATED_BY'], 'PROPERTY_PERIOD_TYPE_VALUE' => 'NONE'); if ($arEvent['RRULE']) { $arRRule = array(); $arRRuleStr = explode(';', $arEvent['RRULE']); foreach ($arRRuleStr as $str) { list($param, $value) = explode('=', $str); $arRRule[$param] = $value; } $arResult['ENTRY']['PROPERTY_PERIOD_TYPE_VALUE'] = $arRRule['FREQ']; } } if ($arResult['ENTRY']) { $arResult['ENTRY']['DATE_ACTIVE_FROM'] = FormatDate($DB->DateFormatToPhp(CSite::GetDateFormat(CIntranetUtils::IsDateTime($arResult['ENTRY']['DATE_ACTIVE_FROM']) ? 'FULL' : 'SHORT', $arParams['SITE_ID'], true)), $arResult['ENTRY']['DATE_ACTIVE_FROM']); $arResult['ENTRY']['DATE_ACTIVE_TO'] = FormatDate($DB->DateFormatToPhp(CSite::GetDateFormat(CIntranetUtils::IsDateTime($arResult['ENTRY']['DATE_ACTIVE_TO']) ? 'FULL' : 'SHORT', $arParams['SITE_ID'], true)), $arResult['ENTRY']['DATE_ACTIVE_TO']); if ($arParams['TYPE'] == 1) { $arResult['ENTRY']['TYPE'] = is_array($arResult['ABSENCE_TYPES'][$arResult['ENTRY']['PROPERTY_ABSENCE_TYPE_ENUM_ID']]) ? $arResult['ABSENCE_TYPES'][$arResult['ENTRY']['PROPERTY_ABSENCE_TYPE_ENUM_ID']]['XML_ID'] : ''; $dbRes = CUser::GetByID($arResult['ENTRY']['PROPERTY_USER_VALUE']); } else { $arResult['ENTRY']['TYPE'] = 'PERSONAL'; if (!$arResult['ENTRY']['USER']) { $dbRes = CIBlockSection::GetByID($arResult['ENTRY']['IBLOCK_SECTION_ID']); $arSection = $dbRes->Fetch(); $dbRes = CUser::GetByID($arSection['CREATED_BY']); } else { $dbRes = CUser::GetByID($arResult['ENTRY']['USER']); } } if ($arUser = $dbRes->Fetch()) { if (!is_array($arUser['UF_DEPARTMENT'])) {