示例#1
0
function prepareUserData($user)
{
    $user['DETAIL_URL'] = COption::getOptionString('intranet', 'search_user_url', '/user/#ID#/');
    $user['DETAIL_URL'] = str_replace(array('#ID#', '#USER_ID#'), array($user['ID'], $user['ID']), $user['DETAIL_URL']);
    $user['PHOTO_THUMB'] = '<img src="/bitrix/components/bitrix/main.user.link/templates/.default/images/nopic_30x30.gif" border="0" alt="" width="32" height="32">';
    if (intval($user['PERSONAL_PHOTO']) > 0) {
        $imageFile = CFile::getFileArray($user['PERSONAL_PHOTO']);
        if ($imageFile !== false) {
            $arFileTmp = CFile::resizeImageGet($imageFile, array('width' => 42, 'height' => 42), BX_RESIZE_IMAGE_EXACT, false);
            $user['PHOTO_THUMB'] = CFile::showImage($arFileTmp['src'], 32, 32);
        }
    }
    return $user;
}
示例#2
0
 public static function getSrc($avatarId, $width = 21, $height = 21)
 {
     static $cache = array();
     if (empty($avatarId)) {
         return null;
     }
     $avatarId = (int) $avatarId;
     $key = $avatarId . " {$width} {$height}";
     if (!isset($cache[$key])) {
         $src = false;
         if ($avatarId > 0) {
             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
             $imageFile = \CFile::getFileArray($avatarId);
             if ($imageFile !== false) {
                 /** @noinspection PhpDynamicAsStaticMethodCallInspection */
                 $fileTmp = \CFile::resizeImageGet($imageFile, array("width" => $width, "height" => $height), BX_RESIZE_IMAGE_EXACT, false);
                 $src = $fileTmp["src"];
             }
             $cache[$key] = $src;
         }
     }
     return $cache[$key];
 }
示例#3
0
 /**
  * @param $fields
  * @param $params
  * @param $siteId
  * @return string|null
  */
 public static function createAvatar($fields, $params = array(), $siteId = SITE_ID)
 {
     if (!isset($params['AVATAR_SIZE'])) {
         $params['AVATAR_SIZE'] = 30;
     }
     if (CModule::IncludeModule('socialnetwork')) {
         return CSocNetLogTools::FormatEvent_CreateAvatar($fields, $params, '', $siteId);
     }
     static $cachedAvatars = array();
     if (intval($fields['PERSONAL_PHOTO']) > 0) {
         if (empty($cachedAvatars[$params['AVATAR_SIZE']][$fields['PERSONAL_PHOTO']])) {
             $imageFile = CFile::getFileArray($fields['PERSONAL_PHOTO']);
             if ($imageFile !== false) {
                 $file = CFile::resizeImageGet($imageFile, array("width" => $params['AVATAR_SIZE'], "height" => $params['AVATAR_SIZE']), BX_RESIZE_IMAGE_EXACT, false);
                 $avatarPath = $file['src'];
                 $cachedAvatars[$params['AVATAR_SIZE']][$fields['PERSONAL_PHOTO']] = $avatarPath;
             }
         }
     }
     return empty($cachedAvatars[$params['AVATAR_SIZE']][$fields['PERSONAL_PHOTO']]) ? null : $cachedAvatars[$params['AVATAR_SIZE']][$fields['PERSONAL_PHOTO']];
 }
示例#4
0
 protected static function getPropsParams($iblockId)
 {
     $arRes = array();
     $bUseHLIblock = \Bitrix\Main\Loader::includeModule('highloadblock');
     $rsProps = \CIBlockProperty::getList(array('SORT' => 'ASC', 'ID' => 'ASC'), array('IBLOCK_ID' => $iblockId, 'ACTIVE' => 'Y'));
     while ($arProp = $rsProps->fetch()) {
         if ($arProp['PROPERTY_TYPE'] == 'L' || $arProp['PROPERTY_TYPE'] == 'E' || $arProp['PROPERTY_TYPE'] == 'S' && $arProp['USER_TYPE'] == 'directory') {
             if ($arProp['XML_ID'] == 'CML2_LINK') {
                 continue;
             }
             $arValues = array();
             if ($arProp['PROPERTY_TYPE'] == 'L') {
                 $arValues = array();
                 $rsPropEnums = \CIBlockProperty::getPropertyEnum($arProp['ID']);
                 while ($arEnum = $rsPropEnums->fetch()) {
                     $arValues[$arEnum['VALUE']] = array('ID' => $arEnum['ID'], 'NAME' => $arEnum['VALUE'], 'PICT' => false);
                 }
             } elseif ($arProp['PROPERTY_TYPE'] == 'E') {
                 $rsPropEnums = \CIBlockElement::getList(array('SORT' => 'ASC'), array('IBLOCK_ID' => $arProp['LINK_IBLOCK_ID'], 'ACTIVE' => 'Y'), false, false, array('ID', 'NAME', 'PREVIEW_PICTURE'));
                 while ($arEnum = $rsPropEnums->Fetch()) {
                     $arEnum['PREVIEW_PICTURE'] = \CFile::getFileArray($arEnum['PREVIEW_PICTURE']);
                     if (!is_array($arEnum['PREVIEW_PICTURE'])) {
                         $arEnum['PREVIEW_PICTURE'] = false;
                     }
                     if ($arEnum['PREVIEW_PICTURE'] !== false) {
                         $productImg = \CFile::resizeImageGet($arEnum['PREVIEW_PICTURE'], array('width' => 80, 'height' => 80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
                         $arEnum['PREVIEW_PICTURE']['SRC'] = $productImg['src'];
                     }
                     $arValues[$arEnum['NAME']] = array('ID' => $arEnum['ID'], 'NAME' => $arEnum['NAME'], 'SORT' => $arEnum['SORT'], 'PICT' => $arEnum['PREVIEW_PICTURE']);
                 }
             } elseif ($arProp['PROPERTY_TYPE'] == 'S' && $arProp['USER_TYPE'] == 'directory') {
                 if ($bUseHLIblock) {
                     $hlblock = HL\HighloadBlockTable::getList(array("filter" => array("TABLE_NAME" => $arProp["USER_TYPE_SETTINGS"]["TABLE_NAME"])))->fetch();
                     if ($hlblock) {
                         $entity = HL\HighloadBlockTable::compileEntity($hlblock);
                         $entity_data_class = $entity->getDataClass();
                         $rsData = $entity_data_class::getList();
                         while ($arData = $rsData->fetch()) {
                             $arValues[$arData['UF_XML_ID']] = array('ID' => $arData['ID'], 'NAME' => $arData['UF_NAME'], 'SORT' => $arData['UF_SORT'], 'FILE' => $arData['UF_FILE'], 'PICT' => '', 'XML_ID' => $arData['UF_XML_ID']);
                         }
                     }
                 }
             }
             if (!empty($arValues) && is_array($arValues)) {
                 $arRes[$arProp['ID']] = array('ID' => $arProp['ID'], 'CODE' => $arProp['CODE'], 'NAME' => $arProp['NAME'], 'TYPE' => $arProp['PROPERTY_TYPE'], 'ORDER' => array_keys($arValues), 'VALUES' => $arValues, 'SORT' => $arProp['SORT']);
             }
         }
         if ($arProp['PROPERTY_TYPE'] == "S" && is_array($arRes[$arProp['ID']]['VALUES'])) {
             foreach ($arRes[$arProp['ID']]['VALUES'] as $id => $value) {
                 $arTmpFile = \CFile::getFileArray($value["FILE"]);
                 $tmpImg = \CFile::resizeImageGet($arTmpFile, array('width' => 20, 'height' => 20), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
                 $arRes[$arProp['ID']]['VALUES'][$id]['PICT'] = $tmpImg['src'];
             }
         }
     }
     return $arRes;
 }
示例#5
0
 protected function processActionDownload($showFile = false, $runResize = false)
 {
     if ($this->externalLink->hasPassword() && !$this->checkPassword()) {
         $this->showAccessDenied();
         return false;
     }
     $file = $this->externalLink->getFile();
     if (!$file) {
         $this->includeComponentTemplate('error');
         return false;
     }
     if (!$this->externalLink->isAutomatic() && !$this->checkDownloadToken($file, $this->request->getQuery('token'))) {
         $this->includeComponentTemplate('error');
         return false;
     }
     $this->externalLink->incrementDownloadCount();
     if ($this->externalLink->isSpecificVersion()) {
         $version = $file->getVersion($this->externalLink->getVersionId());
         if (!$version) {
             $this->includeComponentTemplate('error');
             return false;
         }
         $fileData = $version->getFile();
     } else {
         $fileData = $file->getFile();
     }
     if (!$fileData) {
         $this->includeComponentTemplate('error');
         return false;
     }
     if ($runResize && TypeFile::isImage($fileData['ORIGINAL_NAME'])) {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $tmpFile = \CFile::resizeImageGet($fileData, array("width" => 255, "height" => 255), BX_RESIZE_IMAGE_EXACT, true, false, true);
         $fileData["FILE_SIZE"] = $tmpFile["size"];
         $fileData["SRC"] = $tmpFile["src"];
     }
     CFile::viewByUser($fileData, array('force_download' => !$showFile, 'attachment_name' => $file->getName()));
 }
示例#6
0
 private function getUserPictureSrc($photoId, $width = 21, $height = 21)
 {
     static $cache = array();
     $photoId = (int) $photoId;
     $key = $photoId . " {$width} {$height}";
     if (isset($cache[$key])) {
         $src = $cache[$key];
     } else {
         $src = false;
         if ($photoId > 0) {
             $imageFile = \CFile::getFileArray($photoId);
             if ($imageFile !== false) {
                 $fileTmp = \CFile::resizeImageGet($imageFile, array("width" => $width, "height" => $height), BX_RESIZE_IMAGE_EXACT, false);
                 $src = $fileTmp["src"];
             }
             $cache[$key] = $src;
         }
     }
     return $src;
 }
示例#7
0
 protected function processActionDownloadFile()
 {
     $this->checkRequiredGetParams(array('attachedId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $fileModel = null;
     list($type, $realValue) = FileUserType::detectType($this->request->getQuery('attachedId'));
     if ($type == FileUserType::TYPE_NEW_OBJECT) {
         /** @var File $fileModel */
         $fileModel = File::loadById((int) $realValue, array('STORAGE'));
         if (!$fileModel) {
             $this->errorCollection->add(array(new Error("Could not find file")));
             $this->sendJsonErrorResponse();
         }
         if (!$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext())) {
             $this->errorCollection->add(array(new Error("Bad permission. Could not read this file")));
             $this->sendJsonErrorResponse();
         }
         $fileName = $fileModel->getName();
         $fileData = $fileModel->getFile();
         if (!$fileData) {
             $this->end();
         }
         $cacheTime = 0;
         $width = $this->request->getQuery('width');
         $height = $this->request->getQuery('height');
         if (TypeFile::isImage($fileData["ORIGINAL_NAME"]) && ($width > 0 || $height > 0)) {
             $signature = $this->request->getQuery('signature');
             if (!$signature) {
                 $this->sendJsonInvalidSignResponse('Empty signature');
             }
             if (!ParameterSigner::validateImageSignature($signature, $fileModel->getId(), $width, $height)) {
                 $this->sendJsonInvalidSignResponse('Invalid signature');
             }
             /** @noinspection PhpDynamicAsStaticMethodCallInspection */
             $tmpFile = \CFile::resizeImageGet($fileData, array("width" => $width, "height" => $height), $this->request->getQuery('exact') == "Y" ? BX_RESIZE_IMAGE_EXACT : BX_RESIZE_IMAGE_PROPORTIONAL, true, false, true);
             $fileData["FILE_SIZE"] = $tmpFile["size"];
             $fileData["SRC"] = $tmpFile["src"];
             $cacheTime = 86400;
         }
         \CFile::viewByUser($fileData, array("force_download" => false, "cache_time" => $cacheTime, 'attachment_name' => $fileName));
     } else {
         $this->errorCollection->add(array(new Error('Could not find attached object')));
         $this->sendJsonErrorResponse();
     }
 }
 protected function processActionShowFile()
 {
     $fileName = $this->file->getName();
     $fileData = $this->file->getFile();
     if (!$fileData) {
         $this->end();
     }
     $isImage = TypeFile::isImage($fileData["ORIGINAL_NAME"]);
     $cacheTime = $isImage ? 86400 : 0;
     $width = $this->request->getQuery('width');
     $height = $this->request->getQuery('height');
     if ($isImage && ($width > 0 || $height > 0)) {
         $signature = $this->request->getQuery('signature');
         if (!$signature) {
             $this->sendJsonInvalidSignResponse('Empty signature');
         }
         if (!ParameterSigner::validateImageSignature($signature, $this->file->getId(), $width, $height)) {
             $this->sendJsonInvalidSignResponse('Invalid signature');
         }
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $tmpFile = \CFile::resizeImageGet($fileData, array("width" => $width, "height" => $height), $this->request->getQuery('exact') == "Y" ? BX_RESIZE_IMAGE_EXACT : BX_RESIZE_IMAGE_PROPORTIONAL, true, false, true);
         $fileData["FILE_SIZE"] = $tmpFile["size"];
         $fileData["SRC"] = $tmpFile["src"];
     }
     \CFile::viewByUser($fileData, array('force_download' => false, 'cache_time' => $cacheTime, 'attachment_name' => $fileName));
 }
示例#9
0
    private function executeManagePage()
    {
        global $USER, $APPLICATION;
        $APPLICATION->setTitle(GetMessage('INTR_MAIL_MANAGE_PAGE_TITLE'));
        CJSCore::Init(array('admin_interface'));
        if (!$USER->isAdmin() && !$USER->canDoOperation('bitrix24_config')) {
            $APPLICATION->AuthForm(GetMessage('ACCESS_DENIED'));
            return;
        }
        $this->arParams['SERVICES'] = array();
        $services = CIntranetMailSetupHelper::getMailServices();
        foreach ($services as $service) {
            if ($service['type'] == 'controller') {
                $crDomains = CControllerClient::ExecuteEvent('OnMailControllerGetDomains', array());
                if (!empty($crDomains['result']) && is_array($crDomains['result'])) {
                    $service['domains'] = $crDomains['result'];
                    $service['users'] = array();
                    foreach ($service['domains'] as $domain) {
                        $service['users'][$domain] = array();
                    }
                    $crUsers = CControllerClient::ExecuteEvent('OnMailControllerGetUsers', array());
                    if (!empty($crUsers['result']) && is_array($crUsers['result'])) {
                        foreach ($crUsers['result'] as $email) {
                            list($login, $domain) = explode('@', $email, 2);
                            if (isset($service['users'][$domain])) {
                                $service['users'][$domain][] = $login;
                            }
                        }
                        $dbMailboxes = CMailbox::getList(array('TIMESTAMP_X' => 'ASC'), array('ACTIVE' => 'Y', '!USER_ID' => 0, 'SERVICE_ID' => $service['id']));
                        while ($mailbox = $dbMailboxes->fetch()) {
                            list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                            if (!empty($service['users'][$domain]) && ($key = array_search($login, $service['users'][$domain])) !== false) {
                                array_splice($service['users'][$domain], $key, 1);
                            }
                        }
                    }
                    $this->arParams['SERVICES'][] = $service;
                }
            }
            if (in_array($service['type'], array('domain', 'crdomain'))) {
                $result = self::checkDomainStatus(array('type' => $service['type'], 'domain' => $service['server'], 'token' => $service['token']), $error);
                if (!empty($result['stage']) && $result['stage'] == 'added') {
                    $service['domains'] = array($service['server']);
                    $service['users'] = array($service['server'] => array());
                    if ($service['type'] == 'domain') {
                        $users = CMailDomain2::getDomainUsers($service['token'], $service['server'], $error);
                        if (!empty($users) && is_array($users)) {
                            $service['users'][$service['server']] = $users;
                        }
                    } else {
                        if ($service['type'] == 'crdomain') {
                            $crUsers = CControllerClient::ExecuteEvent('OnMailControllerGetMemberUsers', array('DOMAIN' => $service['server']));
                            if (!empty($crUsers['result']) && is_array($crUsers['result'])) {
                                $service['users'][$service['server']] = $crUsers['result'];
                            }
                        }
                    }
                    $dbMailboxes = CMailbox::getList(array('TIMESTAMP_X' => 'ASC'), array('ACTIVE' => 'Y', '!USER_ID' => 0, 'SERVICE_ID' => $service['id']));
                    while ($mailbox = $dbMailboxes->fetch()) {
                        list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                        if (!empty($service['users'][$domain]) && ($key = array_search($login, $service['users'][$domain])) !== false) {
                            array_splice($service['users'][$domain], $key, 1);
                        }
                    }
                    $this->arParams['SERVICES'][] = $service;
                }
            }
        }
        $this->arResult['GRID_ID'] = 'manage_domain_grid';
        $gridOptions = new CGridOptions($this->arResult['GRID_ID']);
        $arSort = $gridOptions->getSorting(array('sort' => array('ID' => 'ASC'), 'vars' => array('by' => 'by', 'order' => 'order')));
        $arNav = $gridOptions->getNavParams(array('nPageSize' => 50));
        $arSortArg = each($arSort['sort']);
        $arFilter = array('ACTIVE' => 'Y', '!UF_DEPARTMENT' => false);
        if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'search' && !empty($_REQUEST['FILTER'])) {
            $this->arResult['FILTER'] = $_REQUEST['FILTER'];
            $userIds = array();
            $dbMailboxes = CMailbox::getList(array('TIMESTAMP_X' => 'ASC'), array('LID' => SITE_ID, 'ACTIVE' => 'Y', '!USER_ID' => 0, 'LOGIN' => $_REQUEST['FILTER']));
            while ($mailbox = $dbMailboxes->fetch()) {
                if (in_array($mailbox['SERVER_TYPE'], array('imap', 'controller', 'domain'))) {
                    $userIds[] = $mailbox['USER_ID'];
                }
            }
            $arFilter['ID'] = empty($userIds) ? 0 : join('|', $userIds);
        }
        $dbUsers = CUser::GetList($arSortArg['key'], $arSortArg['value'], $arFilter, array('FIELDS' => array('ID', 'LOGIN', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'PERSONAL_PHOTO', 'WORK_POSITION')));
        $dbUsers->navStart($arNav['nPageSize']);
        $arRows = array();
        while ($user = $dbUsers->fetch()) {
            $user['DETAIL_URL'] = COption::getOptionString('intranet', 'search_user_url', '/user/#ID#/');
            $user['DETAIL_URL'] = str_replace(array('#ID#', '#USER_ID#'), array($user['ID'], $user['ID']), $user['DETAIL_URL']);
            $user['PHOTO_THUMB'] = '<img src="/bitrix/components/bitrix/main.user.link/templates/.default/images/nopic_30x30.gif" border="0" alt="" width="32" height="32">';
            if (intval($user['PERSONAL_PHOTO']) > 0) {
                $imageFile = CFile::getFileArray($user['PERSONAL_PHOTO']);
                if ($imageFile !== false) {
                    $arFileTmp = CFile::resizeImageGet($imageFile, array('width' => 42, 'height' => 42), BX_RESIZE_IMAGE_EXACT, false);
                    $user['PHOTO_THUMB'] = CFile::showImage($arFileTmp['src'], 32, 32);
                }
            }
            $anchor_id = RandString(8);
            $arCols = array('NAME' => '<table id="user_' . $user['ID'] . '" style="border-collapse: collapse; border: none; ">
					<tr>
						<td style="border: none !important; padding: 0px !important; ">
							<div style="width: 32px; height: 32px; margin:2px; padding: 2px; box-shadow:0 0 2px 1px rgba(0, 0, 0, 0.1);">
								<a href="' . $user['DETAIL_URL'] . '">' . $user['PHOTO_THUMB'] . '</a>
							</div>
						</td>
						<td style="border: none !important; padding: 0px 0px 0px 7px !important; vertical-align: top; ">
							<a href="' . $user['DETAIL_URL'] . '"><b>' . CUser::formatName(CSite::getNameFormat(), $user, true, true) . '</b></a><br>
							' . htmlspecialcharsbx($user['WORK_POSITION']) . '
						</td>
					</tr>
				</table>', 'EMAIL' => '', 'ADD' => '', 'DELETE' => '');
            if ($mailbox = CIntranetMailSetupHelper::getUserMailbox($user['ID'])) {
                switch ($mailbox['SERVER_TYPE']) {
                    case 'imap':
                        $arCols['EMAIL'] = $mailbox['LOGIN'];
                        if (strpos($mailbox['LOGIN'], '@') === false) {
                            $arCols['EMAIL'] .= '<br><span style="font-weight: normal; ">imap://' . $mailbox['SERVER'] . ':' . $mailbox['PORT'] . '</span>';
                        }
                        $arCols['ADD'] = '<a href="#" onclick="mb.create(' . $user['ID'] . '); return false; ">' . GetMessage('INTR_MAIL_MANAGE_CHANGE') . '</a>';
                        break;
                    case 'controller':
                    case 'domain':
                    case 'crdomain':
                        $arCols['EMAIL'] = $mailbox['LOGIN'];
                        $arCols['ADD'] = '<a href="#" onclick="mb.create(' . $user['ID'] . '); return false; ">' . GetMessage('INTR_MAIL_MANAGE_CHANGE') . '</a><br><a href="#" onclick="mb.changePassword(' . $user['ID'] . '); return false; ">' . GetMessage('INTR_MAIL_MANAGE_PASSWORD') . '</a>';
                        $arCols['DELETE'] = '<a href="#" onclick="mb.remove(' . $user['ID'] . '); return false; ">' . GetMessage('INTR_MAIL_MANAGE_DELETE') . '</a>';
                        break;
                }
            } else {
                $arCols['ADD'] = '<a href="#" onclick="mb.create(' . $user['ID'] . '); return false; ">' . GetMessage('INTR_MAIL_MANAGE_CREATE') . '</a>';
            }
            if (empty($this->arParams['SERVICES'])) {
                $arCols['ADD'] = '';
                $arCols['DELETE'] = '';
            }
            $arCols['EMAIL'] = '<span id="email_' . $user['ID'] . '" style="font-weight: bold; white-space: nowrap; ">' . $arCols['EMAIL'] . '</span>';
            $arCols['ADD'] = '<span id="create_' . $user['ID'] . '" style="white-space: nowrap; ">' . $arCols['ADD'] . '</span>';
            $arCols['DELETE'] = '<span id="delete_' . $user['ID'] . '" style="white-space: nowrap; ">' . $arCols['DELETE'] . '</span>';
            $arRows[$user['ID']] = array('data' => $user, 'columns' => $arCols);
        }
        $this->arResult['ROWS'] = $arRows;
        $this->arResult['ROWS_COUNT'] = $dbUsers->selectedRowsCount();
        $this->arResult['NAV_OBJECT'] = $dbUsers;
        $this->arResult['NAV_OBJECT']->bShowAll = false;
        $this->includeComponentTemplate('manage');
    }