GetID(); static::$curRoles = $userId ? CUser::GetUserGroup($userId) : []; } return static::$curRoles; } static public function IsClient() { $roles = static::GetRoles(); return in_array(5, $roles); } static public function IsAccess() { $roles = static::GetRoles(); return (in_array(5, $roles) || in_array(6, $roles) || in_array(7, $roles) || in_array(8, $roles)); } static public function IsEngineer() { $roles = static::GetRoles(); return in_array(6, $roles); } static public function IsMainEngineer() { $roles = static::GetRoles(); return in_array(7, $roles) || in_array(8, $roles); } static public function IsAdminEngineer() { $roles = static::GetRoles(); return in_array(8, $roles); } public static function GetClientList() { $res = []; $rows = CUser::GetList(($by=array("work_company"=>"asc", "last_name"=>"asc", "name"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(5)]); while($row = $rows->GetNext()) { $h = []; $name = $row['NAME'] . ($row['LAST_NAME'] ? ' ' . $row['LAST_NAME'] : ''); $comp = $row['WORK_COMPANY']; $res[$row['ID']] = $comp ? $comp . ' (' . $name . ')' : $name; } return $res; } public static function GetClientFizList() { $res = []; $arSelect = Array("ID", "NAME"); $arFilter = Array("IBLOCK_ID"=>22, "ACTIVE"=>"Y"); $rows = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect); while($row = $rows->GetNext()) { $h = []; $name = $row['NAME']; $res[$row['ID']] = $name; } return $res; } public static function GetEngineerList() { $res = []; $rows = CUser::GetList(($by=array("id"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(6)]); while($row = $rows->GetNext()) { $h = []; $name = $row['NAME'] . ($row['LAST_NAME'] ? ' ' . $row['LAST_NAME'] : ''); $comp = $row['WORK_COMPANY']; $res[$row['ID']] = $comp ? $comp . ' (' . $name . ')' : $name; } return $res; } public static function GetOnlyMainEngineerList() { $res = []; $rows = CUser::GetList(($by=array("id"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(7)]); while($row = $rows->GetNext()) { $roles = CUser::GetUserGroup($row['ID']); //if(in_array(8, $roles)) // continue; $h = []; $res[$row['ID']] = $row['NAME'] . ($row['LAST_NAME'] ? ' ' . $row['LAST_NAME'] : ''); } return $res; } public static function GetMainEngineerList() { $res = []; $rows = CUser::GetList(($by=array("id"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(7)], ['SELECT' => array('*', "UF_*")]); while($row = $rows->fetch()) $res[$row['ID']] = Service::GetEngineerInfo($row); return $res; } public static function array_unique_key($array, $key) { $tmp = $key_array = array(); $i = 0; foreach($array as $val) { if (!in_array($val[$key], $key_array) && !empty($val[$key])) { $key_array[$i] = $val[$key]; $tmp[$val[$key]] = $val; } $i++; } return $tmp; } public static function GetAllEmployeesList() { $res = []; $rows = CUser::GetList(($by=array("id"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(4,6,7,8)], ['SELECT' => array('*', "UF_*")]); while($row = $rows->fetch()){ $data[$row['EMAIL']] = Service::GetEngineerInfo($row); } $res = Service::array_unique_key($data, 'email'); return $res; } static public function GetEngineerStatusList() { if(static::$engi_status) return static::$engi_status; $res = []; $rows = CUserFieldEnum::GetList(Array("SORT"=>"ASC"), Array("USER_FIELD_ID" => 67)); while($row = $rows->GetNext()) $res[$row["ID"]] = $row["VALUE"]; static::$engi_status = $res; return $res; } static public function GetEngineer($id) { $row = CUser::GetList(($by=array("id"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "ID" => $id], ['SELECT' => array('*', "UF_*")])->fetch(); if($row) return Service::GetEngineerInfo($row); return null; } static public function GetEngineerInfo($row) { if($row) { $sList = static::GetEngineerStatusList(); $res['id'] = $row['ID']; $res['email'] = $row['EMAIL']; $res['fullname'] = $row['NAME'] . ($row['LAST_NAME'] ? (' ' . $row['LAST_NAME']) : ''); $res['comment'] = $row['ADMIN_NOTES']; $res['status'] = $row['UF_STATUS']; $res['status_name'] = ''; $res['phone'] = $row["WORK_PHONE"]; $res['tel'] = preg_replace('%([^\+0-9]+)%ui', '', $res['phone']); $res['roles'] = CUser::GetUserGroup($res['id']); if($res['status'] && isset($sList[$res['status']])) $res['status_name'] = $sList[$res['status']]; return $res; } return null; } static public function GetEngineerUserIds($engi_id, $type = 0, $andVacation = 0)//получить всех пользователей, закрепленных к этому инженеру { $engis = []; $res = []; if($type == 3) { $rows = CUser::GetList(($by=array("work_company"=>"asc", "last_name"=>"asc", "name"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(5)], ['SELECT' => array('ID')]); while($row = $rows->fetch()) $res[] = $row['ID']; } else { if($type != 2) { $rows = CUser::GetList(($by=array("work_company"=>"asc", "last_name"=>"asc", "name"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(5), 'UF_ENGINEER' => $engi_id], ['SELECT' => array('ID')]); while($row = $rows->fetch()) $res[] = $row['ID']; } if($type != 1) { $rows = CUser::GetList(($by=array("work_company"=>"asc", "last_name"=>"asc", "name"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(5), 'UF_RESERVE_ENGINEER' => $engi_id], ['SELECT' => array('ID', 'UF_ENGINEER')]); while($row = $rows->fetch()) { $enId = $row['UF_ENGINEER']; if($enId && !$andVacation) { if(!isset($engis[$enId])) { $eng = CUser::GetList(($by=array("id"=>"asc")), ($order='asc'), ["ID" => $enId], ['SELECT' => array('*', "UF_*")])->fetch(); $engis[$enId] = Service::GetEngineerInfo($eng); } if($engis[$enId]['status'] != 9)//если основной инженер не в отпуске, не отображать резервные записи continue; } $res[] = $row['ID']; } } } $res = array_unique($res); return $res; } public static function GetEquipmentList($clientId) { $res = []; $rows = CIBlockElement::GetList(["NAME"=>"ASC"], Array("IBLOCK_ID" => static::$iEquipmentId, "ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y", 'PROPERTY_USER' => $clientId), false, false, ['ID', 'NAME']); while($row = $rows->GetNext()) $res[$row['ID']] = $row['NAME']; return $res; } public static function GetControlFields($vals = null) { $res = []; $rows = CIBlockElement::GetList(["SORT"=>"ASC"], Array("IBLOCK_ID" => static::$iControlId, "ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y"), false, false, ['ID', 'NAME', 'PROPERTY_FULLNAME', 'PROPERTY_VALUE', 'PROPERTY_VALUE2', 'PROPERTY_MARK_GREEN', 'PROPERTY_MARK_GREEN2', 'PROPERTY_CATEGORY', 'PROPERTY_TYPE', 'PROPERTY_WARNING']); while($row = $rows->GetNext()) { $name = trim($row['PROPERTY_FULLNAME_VALUE']); $p = []; $p['id'] = $row['ID']; $p['name'] = $name ? $name : $row['NAME']; // $p['value'] = (string)$row['PROPERTY_VALUE_VALUE']; $p['value'] = $row['PROPERTY_VALUE_VALUE']; $p['value2'] = $row['PROPERTY_VALUE2_VALUE']; $p['mark_green'] = $row['PROPERTY_MARK_GREEN_VALUE']; $p['mark_green2'] = $row['PROPERTY_MARK_GREEN2_VALUE']; $p['category'] = $row['PROPERTY_CATEGORY_VALUE']; if($vals) { foreach($vals as $v) if($v['id'] == $p['id']) { $p['value'] = $v['value']; $p['value2'] = $v['value2']; $p['mark_green'] = $v['mark_green']; $p['mark_green2'] = $v['mark_green2']; // $p['category'] = $v['category']; } } $p['type'] = $row['PROPERTY_TYPE_ENUM_ID']; $p['warning'] = (int)($row['PROPERTY_WARNING_ENUM_ID'] == 67280); $res[] = $p; } return $res; } public static function IsDefaultControl($serialVal) { $c1 = []; $c2 = []; $fields = Service::GetControlFields(); foreach($fields as $field) { $c1[] = ['id' => $field['id'], 'value' => $field['value'], 'value2' => $field['value2'], 'mark_green' => $field['mark_green'], 'mark_green2' => $field['mark_green2'],'category' => $field['category']]; $c2[] = ['id' => $field['id'], 'value' => '']; } if(($serialVal == serialize($c1)) || ($serialVal == serialize($c2))) return 1; return 0; } public static function GetDefaultControl() { $res = []; $fields = Service::GetControlFields(); foreach($fields as $field) $res[] = ['id' => $field['id'], 'value' => $field['value'], 'value2' => $field['value2'], 'mark_green' => $field['mark_green'], 'mark_green2' => $field['mark_green2'], 'category' => $field['category']]; return $res; } static public function GetUserInfo($id, $isRecurse = 0) { $row = CUser::GetByID($id)->Fetch(); if($row) { $res['id'] = $row['ID']; $res['email'] = $row['EMAIL']; $res['dop_emails'] = $row['UF_DOP_EMAILS']; $res['sendsms'] = $row['UF_SEND_SMS']; $res['fullname'] = ($row['LAST_NAME'] ? (' ' . $row['LAST_NAME']) : '') . " " . $row['NAME']; $res['firstname'] = $row['NAME']; $res['lastname'] = $row['LAST_NAME']; $res['surname'] = $row['SECOND_NAME']; $res['title'] = $row["TITLE"]; $res['phone'] = $row["WORK_PHONE"]; $res['tel'] = preg_replace('%([^\+0-9]+)%ui', '', $res['phone']); $res['comment'] = trim($row["ADMIN_NOTES"]); $res['companyname'] = $row['WORK_COMPANY']; $res['contract'] = trim($row['UF_CONTRACT_NUM']); $res['contract_from'] = $row['UF_CONTRACT_FROM']; $res['disk_photo'] = trim($row['UF_DISK_PHOTO']); $res['disk_file'] = trim($row['UF_DISK_FILE']); $res['contract_to'] = $row['UF_CONTRACT_TO']; $res['contract_from_s'] = $row['UF_CONTRACT_FROM'] ? MakeTimeStamp($row['UF_CONTRACT_FROM']) : 0; $res['contract_to_s'] = $row['UF_CONTRACT_FROM'] ? MakeTimeStamp($row['UF_CONTRACT_TO']) : 0; $res['contract_info'] = trim($row['UF_CONTRACT_INFO']); $res['visit'] = $row['LAST_ACTIVITY_DATE']; $res['move_plan'] = $row['UF_MOVE_PLAN']; $res['move_trouble'] = $row['UF_TROUBLE_MOVE']; $res['tarif'] = $row['UF_TARIF']; $res['roles'] = CUser::GetUserGroup($res['id']); $comp = $row['WORK_COMPANY']; $res['client_name'] = $comp ? $comp . ' (' . $res['fullname'] . ')' : $res['fullname']; if(in_array(8, $res['roles'])) $res['title'] = 'руководитель'; else if(in_array(7, $res['roles'])) $res['title'] = 'инженер'; else if(in_array(6, $res['roles'])) $res['title'] = 'сервисный инженер'; else if(in_array(5, $res['roles'])) $res['title'] = 'контрагент'; $cnt = []; for($i = 5; $i <= 8; ++$i) if(in_array($i, $res['roles'])) $cnt[] = $i; if(count($cnt) > 1) $res['title'] = 'пользователь принадлежит к нескольким группам'; if(!$isRecurse) { $res['main_engineer'] = Service::GetUserInfo($row['UF_ENGINEER'], 1); $res['res_engineer'] = Service::GetUserInfo($row['UF_RESERVE_ENGINEER'], 1); } $res['engineer_id'] = $row['UF_ENGINEER']; $res['engineer_rid'] = $row['UF_RESERVE_ENGINEER']; return $res; } return null; } static public function GetEquipInfo($nodeId) { $node = null; if(!$nodeId) return null; $row2 = CIBlockElement::GetList(["SORT"=>"ASC"], Array("IBLOCK_ID" => Service::$iEquipmentId, 'ID' => $nodeId), false, false, ['ID', 'NAME', 'PROPERTY_USER'])->GetNext(); if($row2) { $node['id'] = (int)$row2['ID']; $node['name'] = $row2['NAME']; $node['user_id'] = $row2['PROPERTY_USER_VALUE']; if($node['user_id']) { $user = Service::GetUserInfo($node['user_id']); if($user) { $node['user_name'] = $user['fullname']; $node['user_company'] = $user['companyname']; } } } return $node; } static public function GetEquip($nodeId) { $node = null; $result = null; if(!$nodeId) return null; $res = CIBlockElement::GetList(["SORT"=>"ASC"], Array("IBLOCK_ID" => Service::$iEquipmentId, 'ID' => $nodeId), false, false); while($node = $res->GetNextElement()) { $f = $node->GetFields(); $result = $node->GetProperties(); $result['ID'] = $f['ID']; } return $result; } public static function GetPages($curNum, $onPages, $totalNums, &$totalPages) { $limit = 3; $res = []; $totalPages = (int)($totalNums/$onPages) + ($totalNums%$onPages ? 1 : 0); $r = []; $n = 1; if($curNum <= $limit) { while(count($r) < $limit) { $r[] = $n; ++$n; if($n > $totalPages) break; } if($curNum == $limit && $n > $curNum) { $r[] = $n; ++$n; } if($n == $totalPages) { $r[] = $n; ++$n; } } else $r = [1]; $res[] = $r; $mid = []; if($totalPages - $limit >= $curNum && $curNum > $limit) $mid = [$curNum - 1, $curNum, $curNum + 1]; if($totalPages - $limit <= $curNum && !count($mid)) { if($totalPages - 2 > $n && $totalPages - 2 == $curNum) $tail[] = $totalPages - 3; if($totalPages - 2 > $n) $tail[] = $totalPages - 2; if($totalPages - 1 > $n) $tail[] = $totalPages - 1; if($totalPages > $n) $tail[] = $totalPages; } else if($n < $totalPages) $tail = [$totalPages]; if(count($mid)) $res[] = $mid; if(count($tail)) $res[] = $tail; return $res; } static public function Visit() { global $USER; CUser::SetLastActivityDate($USER->id); } static public function ClientReorder() { $ids = [null]; $eds = []; $users = [];//все, у кого основной инженер отсутствует $engis = Service::GetMainEngineerList(); foreach($engis as $engi) { if(in_array(8, $engi['roles'])) continue; if($engi['status'] != 10)//9 - отсутствует, 10 - работает $ids[] = $engi['id']; else $eds[] = $engi['id']; } $cnt = count($eds); if(!$cnt) return; $res = []; $rows = CUser::GetList(($by=array("id"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(5), 'UF_ENGINEER' => $ids], ['SELECT' => array('*', "UF_*")]); while($row = $rows->fetch()) $users[] = $row['ID']; $n = 0; foreach($users as $user_id) { $user = new CUser; $user->Update($user_id, ['UF_RESERVE_ENGINEER' => $eds[$n]]); echo ' engi: ' . $user_id . '=>' . $eds[$n] . ' '; ++$n; if($n == $cnt) $n = 0; } return $users; } static public function UpdateUser($user_id, $firstname, $lastname, $surname, $address, $engineer_id, $engineer_rid, $contract, $contract_from, $contract_to, $contract_info, $comment, $company, $disk_photo, $disk_file, $move_plan, $tarif, $move_trouble) { echo 'Update user #' . $user_id . ' '; $user = new CUser; $fields = [ 'NAME' => $firstname, 'LAST_NAME' => $lastname, 'SECOND_NAME' => $surname, 'WORK_STREET' => $address, 'WORK_COMPANY' => $company, 'UF_ENGINEER' => $engineer_id, 'UF_RESERVE_ENGINEER' => $engineer_rid, 'UF_CONTRACT_NUM' => $contract, 'UF_CONTRACT_FROM' => ConvertTimeStamp($contract_from, 'FULL'), 'UF_CONTRACT_TO' => ConvertTimeStamp($contract_to, 'FULL'), 'UF_CONTRACT_INFO' => $contract_info, 'ADMIN_NOTES' => $comment, 'UF_DISK_PHOTO' => $disk_photo, 'UF_DISK_FILE' => $disk_file, 'UF_MOVE_PLAN' => $move_plan, 'UF_TROUBLE_MOVE' => $move_trouble, 'UF_TARIF' => $tarif ]; return $user->Update($user_id, $fields); } static public function GetObjects($userId) { $arFilter = Array("IBLOCK_ID" => static::$iEquipmentId, "ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y", 'PROPERTY_USER' => $userId); $rows = CIBlockElement::GetList(["SORT"=>"ASC"], $arFilter, false, false); $res = []; while($ob = $rows->GetNextElement()) { $row = $ob->GetFields(); $props = $ob->GetProperties(); $h = []; $h['id'] = $row['ID']; $h['name'] = $row['NAME']; $h['address'] = $props['ADDRESS']['VALUE']; $h['fio'] = $props['FIO']['VALUE']; $h['map'] = trim($props['MAP']['VALUE']); if(!$h['map']) $h['map'] = 'https://yandex.ru/maps/?mode=search&text=' . $h['address'] . '&z=16'; $h['phone'] = $props['PHONE']['VALUE']; $h['tel'] = preg_replace('%([^\+0-9]+)%ui', '', $h['phone']); $h['email'] = $props['EMAIL']['VALUE']; $cfile = CFile::GetFileArray($row['DETAIL_PICTURE']); $h['img'] = $cfile ? $cfile['SRC'] : SITE_TEMPLATE_PATH . '/images/no_photo.png'; $h['photo_count'] = $cfile ? 1 : 0; $photos = $props['PHOTOS']['VALUE']; if($photos) $h['photo_count'] += count($photos); $h['service_near'] = Register::GetNearService($h['id']); $h['service_near_id'] = Register::GetNearServiceId($h['id']); $h['service_last_id'] = Register::GetLastServiceId($h['id']); $h['service_last'] = Register::GetLastService($h['id']); $res[] = $h; } return $res; } static public function GetObjectTimes($userId) { $arFilter = Array("IBLOCK_ID" => static::$iEquipmentId, "ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y", 'PROPERTY_USER' => $userId); $rows = CIBlockElement::GetList(["SORT"=>"ASC"], $arFilter, false, false); $res = ['counter' => null, 'signal' => null, 'map' => null]; while($ob = $rows->GetNextElement()) { $p = []; $row = $ob->GetFields(); $props = $ob->GetProperties(); $p['id'] = (int)$row['ID']; $p['name'] = $row['NAME']; $p['counter'] = $props['DATE_COUNTER_NEXT']['VALUE']; $p['signal'] = $props['DATE_SIGNAL_NEXT']['VALUE']; $p['map'] = $props['DATE_MAP_NEXT']['VALUE']; $p['counter_stamp'] = $props['DATE_COUNTER_NEXT']['VALUE'] ? MakeTimeStamp($props['DATE_COUNTER_NEXT']['VALUE']) : 0; $p['signal_stamp'] = $props['DATE_SIGNAL_NEXT']['VALUE'] ? MakeTimeStamp($props['DATE_SIGNAL_NEXT']['VALUE']) : 0; $p['map_stamp'] = $props['DATE_MAP_NEXT']['VALUE'] ? MakeTimeStamp($props['DATE_MAP_NEXT']['VALUE']) : 0; $p['counter_style'] = ''; $p['signal_style'] = ''; $p['map_style'] = ''; if($p['counter_stamp'] && ($res['counter'] == null || $res['counter']['counter'] > $p['counter_stamp'])) { if(($p['counter_stamp'] - time()) < 0) $p['counter_style'] = 'cntDanger'; else if(($p['counter_stamp'] - time()) < 24*24*60) $p['counter_style'] = 'cntWarning'; $res['counter'] = $p; } if($p['signal_stamp'] && ($res['signal'] == null || $res['signal']['signal'] > $p['signal_stamp'])) { if(($p['signal_stamp'] - time()) < 0) $p['signal_style'] = 'cntDanger'; else if(($p['signal_stamp'] - time()) < 24*24*60) $p['signal_style'] = 'cntWarning'; $res['signal'] = $p; } if($p['map_stamp'] && ($res['map'] == null || $res['map']['map'] > $p['map_stamp'])) { if(($p['map_stamp'] - time()) < 0) $p['map_style'] = 'cntDanger'; else if(($p['map_stamp'] - time()) < 24*24*60) $p['map_style'] = 'cntWarning'; $res['map'] = $p; } } return $res; } static public function GetEngineerClients($engineer_id) { $res = ['primary' => [], 'secondary' => []]; $rows = CUser::GetList(($by=array("work_company"=>"asc", "last_name"=>"asc", "name"=>"asc")), ($order='asc'), ["ACTIVE" => "Y", "GROUPS_ID" => Array(5)], ['SELECT' => array('ID', 'NAME', 'LAST_NAME', 'WORK_COMPANY', "UF_ENGINEER", "UF_RESERVE_ENGINEER")]); while($row = $rows->GetNext()) { $h = []; $name = $row['NAME'] . ($row['LAST_NAME'] ? ' ' . $row['LAST_NAME'] : ''); $comp = trim($row['WORK_COMPANY']); $c = []; $c['id'] = $row['ID']; $c['name'] = $comp ? $comp . ' (' . $name . ')' : $name; if($row['UF_ENGINEER'] == $engineer_id) $res['primary'][] = $c; if($row['UF_RESERVE_ENGINEER'] == $engineer_id) $res['secondary'][] = $c; } return $res; } };