private function _checkAccess()
 {
     static $access = null;
     if ($access === null) {
         $this->arAccessUsers = CTimeMan::GetAccess();
         if (count($this->arAccessUsers['READ']) > 0) {
             $this->bCanReadAll = in_array('*', $this->arAccessUsers['READ']);
             $this->bCanEditAll = in_array('*', $this->arAccessUsers['WRITE']);
             $access = true;
         } else {
             $access = false;
         }
     }
     return $access;
 }
Example #2
0
                        }
                        /**************************************************************************/
                        break;
                }
                if (!$res) {
                    if ($ex = $APPLICATION->GetException()) {
                        $error = "{error: '" . CUtil::JSEscape($ex->GetString()) . "', error_id:'" . CUtil::JSEscape($ex->GetId()) . "'}";
                    }
                }
                $APPLICATION->RestartBuffer();
                if ($error) {
                    echo $error;
                } elseif ($bReturnRes) {
                    echo CUtil::PhpToJsObject($res);
                } else {
                    $info = CTimeMan::GetRuntimeInfo(true);
                    $info['PLANNER'] = $info['PLANNER']['DATA'];
                    $arReport = $obUser->SetReport('', 0, $info['ID']);
                    if (is_array($arReport)) {
                        $info['REPORT'] = $arReport['REPORT'];
                        $info['REPORT_TS'] = MakeTimeStamp($arReport['TIMESTAMP_X']);
                    }
                    echo CUtil::PhpToJsObject($info);
                }
            }
        }
    }
} else {
    echo GetMessage('main_include_decode_pass_sess');
}
//require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_after.php");
 public static function AddCommentToIM($arFields)
 {
     if (CModule::IncludeModule("im") && intval($arFields["USER_ID"]) > 0) {
         $date_text = "";
         $dbReport = CTimeManReportFull::GetByID($arFields["REPORT_ID"]);
         if ($arReport = $dbReport->Fetch()) {
             $date_from = FormatDate("j F", MakeTimeStamp($arReport["DATE_FROM"], CSite::GetDateFormat("FULL", SITE_ID)));
             $date_to = FormatDate("j F", MakeTimeStamp($arReport["DATE_TO"], CSite::GetDateFormat("FULL", SITE_ID)));
             if ($date_from == $date_to) {
                 $date_text = $date_to;
             } else {
                 $date_text = $date_from . " - " . $date_to;
             }
             $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "FROM_USER_ID" => $arFields["USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "timeman", "NOTIFY_EVENT" => "report_comment", "NOTIFY_TAG" => "TIMEMAN|REPORT|" . $arFields["REPORT_ID"]);
             $arUserIDToSend = array($arReport["USER_ID"]);
             $gender_suffix = "";
             $dbUser = CUser::GetByID($arFields["USER_ID"]);
             if ($arUser = $dbUser->Fetch()) {
                 switch ($arUser["PERSONAL_GENDER"]) {
                     case "M":
                         $gender_suffix = "_M";
                         break;
                     case "F":
                         $gender_suffix = "_F";
                         break;
                     default:
                         $gender_suffix = "";
                 }
             }
             $arManagers = CTimeMan::GetUserManagers($arReport["USER_ID"]);
             if (is_array($arManagers)) {
                 $arUserIDToSend = array_merge($arUserIDToSend, $arManagers);
             }
             $reports_page = COption::GetOptionString("timeman", "WORK_REPORT_PATH", "/company/work_report.php");
             $arUnFollowers = array();
             $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arUserIDToSend, "CODE" => "L" . $arFields["LOG_ID"], "TYPE" => "N"), array("USER_ID"));
             while ($arUnFollower = $rsUnFollower->Fetch()) {
                 $arUnFollowers[] = $arUnFollower["USER_ID"];
             }
             $arUserIDToSend = array_diff($arUserIDToSend, $arUnFollowers);
             foreach ($arUserIDToSend as $user_id) {
                 if ($arFields["USER_ID"] == $user_id) {
                     continue;
                 }
                 $arMessageFields["TO_USER_ID"] = $user_id;
                 $arTmp = CSocNetLogTools::ProcessPath(array("REPORTS_PAGE" => $reports_page), $user_id);
                 $sender_type = $arReport["USER_ID"] == $user_id ? "1" : ($arReport["USER_ID"] == $arFields["USER_ID"] ? "2" : "3");
                 $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("REPORT_FULL_IM_COMMENT_" . $sender_type . $gender_suffix, array("#period#" => "<a href=\"" . $arTmp["URLS"]["REPORTS_PAGE"] . "#user_id=" . $arReport["USER_ID"] . "&report=" . $arReport["ID"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($date_text) . "</a>"));
                 $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("REPORT_FULL_IM_COMMENT_" . $sender_type . $gender_suffix, array("#period#" => htmlspecialcharsbx($date_text))) . " ( " . $arTmp["SERVER_NAME"] . $arTmp["URLS"]["REPORTS_PAGE"] . "#user_id=" . $arReport["USER_ID"] . "&report=" . $arReport["ID"] . " )#BR##BR#" . $arFields["MESSAGE"];
                 CIMNotify::Add($arMessageFields);
             }
         }
     }
 }
Example #4
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (CBXFeatures::IsFeatureEnabled('timeman') && CModule::IncludeModule('timeman') && CTimeMan::CanUse()) {
    if (abs(CTimeZone::GetOffset()) > BX_TIMEMAN_WRONG_DATE_CHECK) {
        $arResult['ERROR'] = 'WRONG_DATE';
        $this->IncludeComponentTemplate('error');
        return true;
    }
    $arResult['TASKS_ENABLED'] = CBXFeatures::IsFeatureEnabled('Tasks') && CModule::IncludeModule('tasks');
    $arResult['START_INFO'] = CTimeMan::GetRuntimeInfo(false);
    $obReportUser = new CUserReportFull();
    $arResult['WORK_REPORT'] = $obReportUser->GetReportData();
    //echo '<pre>'; print_r($arResult['WORK_REPORT']); echo '</pre>';
    CIntranetPlanner::initScripts($arResult['START_INFO']['PLANNER']);
    $arResult['START_INFO']['PLANNER'] = $arResult['START_INFO']['PLANNER']['DATA'];
    CJSCore::Init(array('timeman'));
    $this->IncludeComponentTemplate();
    return true;
} else {
    return false;
}
Example #5
0
 public function Add($arParams)
 {
     global $USER;
     $res = null;
     $calendar_id = $arParams['calendar_id'];
     $calIblock = COption::GetOptionInt('intranet', 'iblock_calendar', null, $arParams['site_id']);
     $calIblockSection = CEventCalendar::GetSectionIDByOwnerId($USER->GetID(), 'USER', $calIblock);
     if (!$calendar_id) {
         $calendar_id = CUserOptions::GetOption('timeman', 'default_calendar', 0);
     }
     if ($calIblockSection > 0) {
         $arCalendars = CEventCalendar::GetCalendarList(array($calIblock, $calIblockSection, 0, 'USER'));
         if (count($arCalendars) == 1) {
             if ($calendar_id && $calendar_id != $arCalendars[0]['ID']) {
                 CUserOptions::DeleteOption('timeman', 'default_calendar');
             }
             $calendar_id = $arCalendars[0]['ID'];
         } else {
             $bCalendarFound = false;
             $arCalsList = array();
             foreach ($arCalendars as $cal) {
                 if ($cal['ID'] == $calendar_id) {
                     $bCalendarFound = true;
                     break;
                 }
                 $arCalsList[] = array('ID' => $cal['ID'], 'NAME' => $cal['NAME'], 'COLOR' => $cal['COLOR']);
             }
             if (!$bCalendarFound) {
                 $bReturnRes = true;
                 $res = array('error_id' => 'CHOOSE_CALENDAR', 'error' => array('TEXT' => GetMessage('TM_CALENDAR_CHOOSE'), 'CALENDARS' => $arCalsList));
             }
         }
     }
     if (!$bReturnRes) {
         if (!$calIblockSection) {
             $calIblockSection = 'none';
         }
         $today = CTimeMan::RemoveHoursTS(time());
         $data = array('DATE_FROM' => $today + CTimeMan::MakeShortTS($arParams['from']), 'DATE_TO' => $today + CTimeMan::MakeShortTS($arParams['to']), 'NAME' => $arParams['name'], 'ABSENCE' => $arParams['absence'] == 'Y');
         $obCalendar = new CEventCalendar();
         $obCalendar->Init(array('ownerType' => 'USER', 'ownerId' => $USER->GetID(), 'bOwner' => true, 'iblockId' => $calIblock, 'bCache' => false));
         $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true));
         $arRes = array('iblockId' => $obCalendar->iblockId, 'ownerType' => $obCalendar->ownerType, 'ownerId' => $obCalendar->ownerId, 'bNew' => true, 'fullUrl' => $obCalendar->fullUrl, 'userId' => $obCalendar->userId, 'pathToUserCalendar' => $obCalendar->pathToUserCalendar, 'pathToGroupCalendar' => $obCalendar->pathToGroupCalendar, 'userIblockId' => $obCalendar->userIblockId, 'calendarId' => $calendar_id, 'sectionId' => $calIblockSection, 'dateFrom' => ConvertTimeStamp($data['DATE_FROM'], 'FULL'), 'dateTo' => ConvertTimeStamp($data['DATE_TO'], 'FULL'), 'name' => $data['NAME'], 'desc' => '', 'prop' => array('ACCESSIBILITY' => $data['ABSENCE'] ? 'absent' : 'busy'), 'notDisplayCalendar' => true);
         if ($GLOBALS['BX_TIMEMAN_RECENTLY_ADDED_EVENT_ID'] = $obCalendar->SaveEvent($arRes)) {
             if ($_REQUEST['cal_set_default'] == 'Y') {
                 CUserOptions::SetOption('timeman', 'default_calendar', $calendar_id);
             }
         }
     }
     return $res;
 }
 protected static function getTimemanCloseDayData($arParams)
 {
     if (CModule::IncludeModule('timeman')) {
         global $USER;
         $arTasks = array();
         $userId = $USER->getId();
         $runningTaskId = null;
         $taskRunTime = null;
         // key features of that info:
         // [REPORT_REQ] => 'A' means that day will be closed right now. other variants - just form show.
         // [INFO][DATE_START] => 1385459336 - unix timestamp of day start
         // [INFO][TIME_START] => 46136 - short timestamp of day start
         // [DURATION]
         // [TIME_LEAKS]
         $arTimemanInfo = CTimeMan::GetRunTimeInfo(true);
         if (!($userId > 0)) {
             foreach ($arTimemanInfo['PLANNER']['DATA']['TASKS'] as $arTask) {
                 $arTask['TIME'] = 0;
                 $arTasks[] = $arTask;
             }
             return array('TASKS' => $arTasks);
         }
         $unixTsDateStart = (int) $arTimemanInfo['INFO']['DATE_START'];
         $oTimer = CTaskTimerManager::getInstance($userId);
         $arTimer = $oTimer->getLastTimer();
         if ($arTimer && $arTimer['TIMER_STARTED_AT'] > 0) {
             $runningTaskId = $arTimer['TASK_ID'];
             if ($arTimer['TIMER_STARTED_AT'] >= $unixTsDateStart) {
                 $taskRunTime = max(0, time() - (int) $arTimer['TIMER_STARTED_AT']);
             } else {
                 $taskRunTime = max(0, time() - $unixTsDateStart);
             }
         }
         $bitrixTimestampDateStart = $unixTsDateStart + CTasksTools::getTimeZoneOffset();
         $dateStartAsString = ConvertTimeStamp($bitrixTimestampDateStart, 'FULL');
         foreach ($arTimemanInfo['PLANNER']['DATA']['TASKS'] as $arTask) {
             $rsElapsedTime = CTaskElapsedTime::getList(array('ID' => 'ASC'), array('TASK_ID' => $arTask['ID'], 'USER_ID' => $userId, '>=CREATED_DATE' => $dateStartAsString), array('skipJoinUsers' => true));
             $arTask['TIME'] = 0;
             while ($arElapsedTime = $rsElapsedTime->fetch()) {
                 $arTask['TIME'] += max(0, $arElapsedTime['SECONDS']);
             }
             if ($runningTaskId && $arTask['ID'] == $runningTaskId) {
                 $arTask['TIME'] += $taskRunTime;
             }
             $arTasks[] = $arTask;
         }
         return array('TASKS' => $arTasks);
     }
 }
Example #7
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CBXFeatures::IsFeatureEnabled('timeman') || !CModule::IncludeModule('timeman')) {
    return;
}
// maybe we should cache GetAccess data?
$arResult['arAccessUsers'] = CTimeMan::GetAccess();
if (count($arResult['arAccessUsers']['READ']) > 0) {
    CUtil::InitJSCore(array('timeman'));
    $arUserFields = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields('USER', 0, LANGUAGE_ID);
    $arResult['UF_DEPARTMENT_field'] = $arUserFields['UF_DEPARTMENT'];
    $arResult['UF_DEPARTMENT_field']['FIELD_NAME'] = 'department';
    $arResult['UF_DEPARTMENT_field']['MULTIPLE'] = 'N';
    $arResult['UF_DEPARTMENT_field']['SETTINGS']['LIST_HEIGHT'] = 1;
    $this->IncludeComponentTemplate();
}
Example #8
0
    if (strlen($Update) > 0 && strlen($_REQUEST["back_url_settings"]) > 0) {
        LocalRedirect($_REQUEST["back_url_settings"]);
    } else {
        LocalRedirect($APPLICATION->GetCurPage() . "?mid=" . urlencode($mid) . "&lang=" . urlencode(LANGUAGE_ID) . "&back_url_settings=" . urlencode($_REQUEST["back_url_settings"]) . "&" . $tabControl->ActiveTabParam());
    }
}
foreach ($arAllModuleOptions as $tab => $arTabOptions) {
    foreach ($arTabOptions as $key => $arOptDef) {
        $value = '';
        switch ($arOptDef[1]) {
            case 'time':
                $value = COption::GetOptionInt($module_id, $key, $arOptDef[2]);
                if ($arOptDef[3] == 'clock') {
                    $value = CTimeMan::FormatTimeOut($value);
                } else {
                    $value = CTimeMan::FormatTime($value, true);
                }
                break;
            case 'int':
                $value = COption::GetOptionInt($module_id, $key, $arOptDef[2]);
                break;
            default:
                $value = COption::GetOptionString($module_id, $key, $arOptDef[2]);
                break;
        }
        $arAllModuleOptions[$tab][$key][0] = $value;
    }
}
$workday_can_edit_current = COption::GetOptionString($module_id, 'workday_can_edit_current', 'Y');
// it's not a mistake!
if (!COption::GetOptionString($module_id, "GROUP_DEFAULT_TASK", "")) {
Example #9
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CBXFeatures::IsFeatureEnabled('timeman') || !CModule::IncludeModule('timeman')) {
    return;
}
// maybe we should cache GetAccess data?
$arResult['arAccessUsers'] = CTimeMan::GetAccess();
$arResult['arAccessUsers2'] = CTimeMan::GetAccessSettings();
$arResult['arDirectUsers'] = CTimeMan::GetDirectAccess();
if (count($arResult['arAccessUsers']['READ']) > 0) {
    CUtil::InitJSCore(array('timeman'));
    $arUserFields = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields('USER', 0, LANGUAGE_ID);
    $arResult['TASKS_ENABLED'] = CBXFeatures::IsFeatureEnabled('Tasks') && CModule::IncludeModule('tasks');
    $arResult['UF_DEPARTMENT_field'] = $arUserFields['UF_DEPARTMENT'];
    $arResult['UF_DEPARTMENT_field']['FIELD_NAME'] = 'department';
    $arResult['UF_DEPARTMENT_field']['MULTIPLE'] = 'N';
    $arResult['UF_DEPARTMENT_field']['SETTINGS']['LIST_HEIGHT'] = 1;
    $arResult['SHOW_ALL'] = "Y";
    $arResult['DEPARTMENT_ID'] = "";
    if ($arResult['arDirectUsers']) {
        $arResult['SHOW_ALL'] = CUserOptions::GetOption("timeman.report.weekly", "show_all", "Y", $USER->GetID());
        $arResult['DEPARTMENT_ID'] = CUserOptions::GetOption("timeman.report.weekly", "department_id", "", $USER->GetID());
    }
    $this->IncludeComponentTemplate();
}
Example #10
0
 public static function Approve($ID, $check_rights = true)
 {
     if ($check_rights) {
         $hasAccess = false;
         $arAccessUsers = CTimeMan::GetAccess();
         if (count($arAccessUsers['WRITE']) > 0) {
             $bCanEditAll = in_array('*', $arAccessUsers['WRITE']);
             $dbRes = CTimeManEntry::GetList(array(), array('ID' => $ID), false, false, array('*'));
             $arRes = $dbRes->Fetch();
             if ($arRes) {
                 $hasAccess = $bCanEditAll || in_array($arRes['USER_ID'], $arAccessUsers['WRITE']);
             }
         }
         if (!$hasAccess) {
             $GLOBALS['APPLICATION']->ThrowException('Access denied');
             return false;
         }
     }
     if (CTimeManEntry::Update($ID, array('ACTIVE' => 'Y'))) {
         CTimeManReport::Approve($ID);
         CTimeManReportDaily::SetActive($ID);
         CTimeManNotify::SendMessage($ID, 'U');
         return true;
     }
     return false;
 }
 /**
  * @param $userId
  * @return bool
  */
 public function canRead($userId)
 {
     if ($this->canRead !== null) {
         return $this->canRead;
     }
     if (($res = $this->getDataToCheck($this->entityId)) && !empty($res)) {
         list($message, $topic) = $res;
         $entityId = null;
         $entityType = null;
         if (!empty($topic["XML_ID"])) {
             $entityId = substr($topic["XML_ID"], strrpos($topic["XML_ID"], "_") + 1);
             $entityType = substr($topic["XML_ID"], 0, strrpos($topic["XML_ID"], "_"));
         }
         switch ($entityType) {
             case "TASK":
                 if (Loader::includeModule("tasks")) {
                     $connector = new TaskConnector($entityId, $this->attachedObject);
                     $this->canRead = $connector->canRead($userId);
                     return $this->canRead;
                 }
                 break;
             case "EVENT":
                 if (Loader::includeModule("calendar")) {
                     $connector = new CalendarEventConnector($entityId, $this->attachedObject);
                     $this->canRead = $connector->canRead($userId);
                     return $this->canRead;
                 }
                 break;
             case "IBLOCK":
                 if ((int) $topic["USER_ID"] > 0 && Loader::includeModule("socialnetwork")) {
                     $codes = array();
                     if (($res = \CSocNetLog::getList(array(), array("SOURCE_ID" => $entityId, "EVENT_ID" => array("photo_photo", "news", "wiki")), false, false, array("ID"))->fetch()) && $res) {
                         $db_res = \CSocNetLogRights::getList(array(), array("LOG_ID" => $res["ID"]));
                         while ($res = $db_res->fetch()) {
                             $codes[] = $res["GROUP_CODE"];
                         }
                     }
                     $this->canRead = $this->canAccess($userId, $codes);
                     return $this->canRead;
                 }
                 $this->canRead = true;
                 return $this->canRead;
             case "MEETING":
                 $this->canRead = (int) $message["FORUM_ID"] == (int) \COption::getOptionInt('meeting', 'comments_forum_id', 0, SITE_ID);
                 return $this->canRead;
             case "TIMEMAN_ENTRY":
                 if (Loader::includeModule("timeman")) {
                     $dbEntry = \CTimeManEntry::getList(array(), array("ID" => $entityId), false, false, array("ID", "USER_ID"));
                     if ($arEntry = $dbEntry->fetch()) {
                         if ($arEntry["USER_ID"] == $userId) {
                             $this->canRead = true;
                             return $this->canRead;
                         } else {
                             $arManagers = \CTimeMan::getUserManagers($arEntry["USER_ID"]);
                             $this->canRead = in_array($userId, $arManagers);
                             return $this->canRead;
                         }
                     }
                 }
                 $this->canRead = false;
                 return $this->canRead;
             case "TIMEMAN_REPORT":
                 if (Loader::includeModule("timeman")) {
                     $dbReport = \CTimeManReportFull::getList(array(), array("ID" => $entityId), array("ID", "USER_ID"));
                     if ($arReport = $dbReport->fetch()) {
                         if ($arReport["USER_ID"] == $userId) {
                             $this->canRead = true;
                             return $this->canRead;
                         } else {
                             $arManagers = \CTimeMan::getUserManagers($arReport["USER_ID"]);
                             $this->canRead = in_array($userId, $arManagers);
                             return $this->canRead;
                         }
                     }
                 }
                 $this->canRead = false;
                 return $this->canRead;
             case "WF":
                 $this->canRead = false;
                 if (Loader::includeModule("bizproc")) {
                     $currentUserId = (int) $this->getUser()->getId();
                     $participants = \CBPTaskService::getWorkflowParticipants($entityId);
                     if (in_array($currentUserId, $participants)) {
                         $this->canRead = true;
                     } else {
                         $state = \CBPStateService::getWorkflowStateInfo($entityId);
                         if ($state && $currentUserId === (int) $state['STARTED_BY']) {
                             $this->canRead = true;
                         }
                     }
                 }
                 return $this->canRead;
         }
         if ((!empty($topic["SOCNET_GROUP_ID"]) || !empty($topic["OWNER_ID"])) && Loader::includeModule("socialnetwork")) {
             if (!empty($topic["SOCNET_GROUP_ID"])) {
                 $this->canRead = \CSocNetFeatures::isActiveFeature(SONET_ENTITY_GROUP, $topic["SOCNET_GROUP_ID"], "forum") && \CSocNetFeaturesPerms::canPerformOperation($userId, SONET_ENTITY_GROUP, $topic["SOCNET_GROUP_ID"], "forum", "view");
                 return $this->canRead;
             } else {
                 $this->canRead = \CSocNetFeatures::isActiveFeature(SONET_ENTITY_USER, $topic["OWNER_ID"], "forum") && \CSocNetFeaturesPerms::canPerformOperation($userId, SONET_ENTITY_USER, $topic["OWNER_ID"], "forum", "view");
                 return $this->canRead;
             }
         }
         if ($message) {
             $user = $this->getUser();
             if ($user && $userId == $user->getId()) {
                 $userGroups = $user->getUserGroupArray();
             } else {
                 $userGroups = array(2);
             }
             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
             if (\CForumUser::isAdmin($userId, $userGroups)) {
                 $this->canRead = true;
                 return $this->canRead;
             }
             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
             $perms = \CForumNew::getUserPermission($message["FORUM_ID"], $userGroups);
             if ($perms >= "Y") {
                 $this->canRead = true;
                 return $this->canRead;
             }
             if ($perms < "E" || $perms < "Q" && $message["APPROVED"] != "Y") {
                 $this->canRead = false;
                 return $this->canRead;
             }
             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
             $forum = \CForumNew::getByID($message["FORUM_ID"]);
             $this->canRead = $forum["ACTIVE"] == "Y";
             return $this->canRead;
         }
     }
     $this->canRead = false;
     return $this->canRead;
 }
Example #12
0
 protected function _GetSettings()
 {
     global $USER_FIELD_MANAGER;
     $arRes = array();
     $arRes = $this->_GetPersonalSettings();
     if ($arRes) {
         if ($arRes['UF_TIMEMAN'] === 'N') {
             return array('UF_TIMEMAN' => false);
         }
         $cnt = 0;
         if ($arRes['UF_TIMEMAN'] !== 'Y') {
             $cnt++;
         }
         foreach ($arRes as $fld => $value) {
             if (!$arRes[$fld] || $arRes[$fld] == '00:00') {
                 $cnt++;
             }
         }
         if ($cnt > 0) {
             if (is_array($this->UF_DEPARTMENT) && count($this->UF_DEPARTMENT) > 0) {
                 $allSet = array('UF_TIMEMAN' => $arRes['UF_TIMEMAN'] ? $arRes['UF_TIMEMAN'] : false, 'UF_TM_MAX_START' => 86401, 'UF_TM_MIN_FINISH' => false, 'UF_TM_MIN_DURATION' => false, 'UF_TM_REPORT_REQ' => false, 'UF_REPORT_PERIOD' => $arRes['UF_REPORT_PERIOD'], 'UF_TM_REPORT_DATE' => $arRes['UF_TM_REPORT_DATE'], 'UF_TM_TIME' => $arRes['UF_TM_TIME'], 'UF_TM_DAY' => $arRes['UF_TM_DAY'], 'UF_TM_REPORT_TPL' => array(), 'UF_TM_FREE' => false, 'UF_TM_ALLOWED_DELTA' => -1);
                 foreach ($this->UF_DEPARTMENT as $dpt) {
                     $dptSet = CTimeMan::GetSectionSettings($dpt);
                     if ($allSet['UF_TIMEMAN'] !== 'Y' && $dptSet['UF_TIMEMAN']) {
                         $allSet['UF_TIMEMAN'] = $dptSet['UF_TIMEMAN'];
                     }
                     if ($dptSet['UF_TM_MAX_START']) {
                         $allSet['UF_TM_MAX_START'] = min($dptSet['UF_TM_MAX_START'], $allSet['UF_TM_MAX_START']);
                     }
                     $allSet['UF_TM_MAX_START'] = min($dptSet['UF_TM_MAX_START'], $allSet['UF_TM_MAX_START']);
                     $allSet['UF_TM_MIN_FINISH'] = max($dptSet['UF_TM_MIN_FINISH'], $allSet['UF_TM_MIN_FINISH']);
                     $allSet['UF_TM_MIN_DURATION'] = max($dptSet['UF_TM_MIN_DURATION'], $allSet['UF_TM_MIN_DURATION']);
                     if ($dptSet['UF_TM_REPORT_REQ']) {
                         $allSet['UF_TM_REPORT_REQ'] = $dptSet['UF_TM_REPORT_REQ'];
                     }
                     if ((!is_array($allSet['UF_TM_REPORT_TPL']) || count($allSet['UF_TM_REPORT_TPL']) <= 0) && $dptSet['UF_TM_REPORT_TPL']) {
                         $allSet['UF_TM_REPORT_TPL'] = $dptSet['UF_TM_REPORT_TPL'];
                     }
                     if ($dptSet['UF_TM_FREE']) {
                         $allSet['UF_TM_FREE'] = $dptSet['UF_TM_FREE'];
                     }
                     if ($dptSet['UF_TM_ALLOWED_DELTA']) {
                         if ($allSet['UF_TM_ALLOWED_DELTA'] == -1 || $dptSet['UF_TM_ALLOWED_DELTA'] < $allSet['UF_TM_ALLOWED_DELTA']) {
                             $allSet['UF_TM_ALLOWED_DELTA'] = $dptSet['UF_TM_ALLOWED_DELTA'];
                         }
                     }
                 }
                 //report fields
                 $allSet["UF_REPORT_PERIOD"] = !$allSet["UF_REPORT_PERIOD"] && $dptSet["UF_REPORT_PERIOD"] ? $dptSet["UF_REPORT_PERIOD"] : $allSet["UF_REPORT_PERIOD"];
                 $allSet["UF_TM_TIME"] = !$allSet["UF_TM_TIME"] && $dptSet["UF_TM_TIME"] ? $dptSet["UF_TM_TIME"] : $allSet["UF_TM_TIME"];
                 $allSet["UF_TM_DAY"] = !$allSet["UF_TM_DAY"] && $dptSet["UF_TM_DAY"] ? $dptSet["UF_TM_DAY"] : $allSet["UF_TM_DAY"];
                 $allSet["UF_TM_REPORT_DATE"] = !$allSet["UF_TM_REPORT_DATE"] && $dptSet["UF_TM_REPORT_DATE"] ? $dptSet["UF_TM_REPORT_DATE"] : $allSet["UF_TM_REPORT_DATE"];
                 if ($arRes['UF_TM_ALLOWED_DELTA'] === '0') {
                     unset($allSet['UF_TM_ALLOWED_DELTA']);
                 }
                 foreach ($allSet as $key => $value) {
                     if (!$arRes[$key] || $arRes[$key] === '00:00') {
                         $arRes[$key] = $value;
                     }
                 }
                 if ($arRes['UF_TIMEMAN'] === 'N') {
                     return $arRes = array('UF_TIMEMAN' => false);
                 }
             } elseif ($arRes['UF_TIMEMAN'] !== 'Y') {
                 // if user is not attached to company structure tm can be allowed only in his own profile
                 return $arRes = array('UF_TIMEMAN' => false);
             }
         }
         //if ($cnt > 0)
         $arRes['UF_TIMEMAN'] = true;
         // it can be only Y|null at this moment
         $arRes['UF_TM_MAX_START'] = $arRes['UF_TM_MAX_START'];
         $arRes['UF_TM_MAX_START'] = $arRes['UF_TM_MAX_START'] > 0 ? $arRes['UF_TM_MAX_START'] : COption::GetOptionInt('timeman', 'workday_max_start', 33300);
         $arRes['UF_TM_MIN_FINISH'] = $arRes['UF_TM_MIN_FINISH'];
         $arRes['UF_TM_MIN_FINISH'] = $arRes['UF_TM_MIN_FINISH'] > 0 ? $arRes['UF_TM_MIN_FINISH'] : COption::GetOptionInt('timeman', 'workday_min_finish', 63900);
         $arRes['UF_TM_MIN_DURATION'] = $arRes['UF_TM_MIN_DURATION'];
         $arRes['UF_TM_MIN_DURATION'] = $arRes['UF_TM_MIN_DURATION'] > 0 ? $arRes['UF_TM_MIN_DURATION'] : COption::GetOptionInt('timeman', 'workday_min_duration', 28800);
         $arRes['UF_TM_REPORT_REQ'] = $arRes['UF_TM_REPORT_REQ'] ? $arRes['UF_TM_REPORT_REQ'] : COption::GetOptionInt('timeman', 'workday_report_required', 'A');
         $arRes['UF_TM_REPORT_TPL'] = $arRes['UF_TM_REPORT_TPL'] ? $arRes['UF_TM_REPORT_TPL'] : array();
         $arRes['UF_TM_FREE'] = $arRes['UF_TM_FREE'] ? $arRes['UF_TM_FREE'] == 'Y' : false;
         $arRes['UF_TM_ALLOWED_DELTA'] = $arRes['UF_TM_ALLOWED_DELTA'] > -1 ? $arRes['UF_TM_ALLOWED_DELTA'] : COption::GetOptionInt('timeman', 'workday_allowed_delta', '900');
     } else {
         return array('UF_TIMEMAN' => false);
     }
     return $arRes;
 }