public function role(array $params) { if (!empty($params['roleId'])) { $par = new ADMIN_UserListParams(); $par->setType('role'); $par->setExtra(array('roleId' => (int) $params['roleId'])); $this->addComponent('userList', new ADMIN_CMP_UserList($par)); $role = BOL_AuthorizationService::getInstance()->getRoleById((int) $params['roleId']); $roleLabel = OW::getLanguage()->text('base', 'authorization_role_' . $role->name); OW::getDocument()->setHeading(OW::getLanguage()->text('admin', 'heading_user_role', array('role' => $roleLabel))); } OW::getDocument()->setHeadingIconClass('ow_ic_user'); $js = UTIL_JsGenerator::newInstance()->newVariable('rolesUrl', OW::getRouter()->urlForRoute('admin_user_roles'))->jQueryEvent('#back-to-roles', 'click', 'document.location.href = rolesUrl'); OW::getDocument()->addOnloadScript($js); }
/** * Constructor. * * @param string $type * @param array $extra */ public function __construct(ADMIN_UserListParams $params) { parent::__construct(); $language = OW::getLanguage(); $userService = BOL_UserService::getInstance(); $authService = BOL_AuthorizationService::getInstance(); $type = $params->getType(); $extra = $params->getExtra(); $formAction = $params->getAction(); $this->assign('action', $formAction); // handle form if (OW::getRequest()->isPost() && !empty($_POST['users'])) { $users = $_POST['users']; if (isset($_POST['suspend'])) { foreach ($users as $id) { // admin user cannot be suspended if ($authService->isActionAuthorizedForUser($id, BOL_AuthorizationService::ADMIN_GROUP_NAME)) { continue; } $userService->suspend($id, $_POST['suspend_message']); } OW::getFeedback()->info($language->text('admin', 'user_feedback_profiles_suspended')); } else { if (isset($_POST['reactivate'])) { foreach ($users as $id) { $userService->unsuspend($id); } OW::getFeedback()->info($language->text('admin', 'user_feedback_profiles_unsuspended')); } else { if (isset($_POST['delete'])) { $deleted = 0; foreach ($users as $id) { // admin user cannot be deleted if ($authService->isActionAuthorizedForUser($id, BOL_AuthorizationService::ADMIN_GROUP_NAME)) { continue; } if ($userService->deleteUser($id, true)) { $deleted++; } } OW::getFeedback()->info($language->text('admin', 'user_delete_msg', array('count' => $deleted))); } else { if (isset($_POST['email_verify'])) { $userDtos = $userService->findUserListByIdList($users); foreach ($userDtos as $dto) { /* @var $dto BOL_User */ $dto->emailVerify = 1; $userService->saveOrUpdate($dto); } OW::getFeedback()->info($language->text('admin', 'user_feedback_email_verified')); } else { if (isset($_POST['email_unverify'])) { $userDtos = $userService->findUserListByIdList($users); foreach ($userDtos as $dto) { // admin user cannot be unverified if ($authService->isActionAuthorizedForUser($dto->id, BOL_AuthorizationService::ADMIN_GROUP_NAME)) { continue; } /* @var $dto BOL_User */ $dto->emailVerify = 0; $userService->saveOrUpdate($dto); } OW::getFeedback()->info($language->text('admin', 'user_feedback_email_unverified')); } else { if (isset($_POST['disapprove'])) { foreach ($users as $id) { // admin user cannot be disapproved if ($authService->isActionAuthorizedForUser($id, BOL_AuthorizationService::ADMIN_GROUP_NAME)) { continue; } $userService->disapprove($id); } OW::getFeedback()->info($language->text('admin', 'user_feedback_profiles_disapproved')); } else { if (isset($_POST['approve'])) { foreach ($users as $id) { if (!$userService->isApproved($id)) { $userService->approve($id); $userService->sendApprovalNotification($id); } } OW::getFeedback()->info($language->text('admin', 'user_feedback_profiles_approved')); } } } } } } } $this->reloadParentPage(); } $onPage = 20; $page = isset($_GET['page']) && (int) $_GET['page'] ? (int) $_GET['page'] : 1; $first = ($page - 1) * $onPage; switch ($type) { case 'recent': $userList = $userService->findRecentlyActiveList($first, $onPage, false); $userCount = $userService->count(false); break; case 'suspended': $userList = $userService->findSuspendedList($first, $onPage); $userCount = $userService->countSuspended(); break; case 'unverified': $userList = $userService->findUnverifiedList($first, $onPage); $userCount = $userService->countUnverified(); break; case 'unapproved': $userList = $userService->findUnapprovedList($first, $onPage); $userCount = $userService->countUnapproved(); break; case 'search': if (isset($extra['question'])) { $search = htmlspecialchars(urldecode($extra['value'])); $this->assign('search', $search); $userList = $userService->findUserListByQuestionValues(array($extra['question'] => $search), $first, $onPage, true); $userCount = $userService->countUsersByQuestionValues(array($extra['question'] => $search), true); } break; case 'role': $roleId = $extra['roleId']; $userList = $userService->findListByRoleId($roleId, $first, $onPage); $userCount = $userService->countByRoleId($roleId); break; } if (!$userList && $page > 1) { OW::getApplication()->redirect(OW::getRequest()->buildUrlQueryString(null, array('page' => $page - 1))); } if ($userList) { $this->assign('users', $userList); $this->assign('total', $userCount); // Paging $pages = (int) ceil($userCount / $onPage); $paging = new BASE_CMP_Paging($page, $pages, $onPage); $this->addComponent('paging', $paging); $userIdList = array(); foreach ($userList as $user) { if (!in_array($user->id, $userIdList)) { array_push($userIdList, $user->id); } } $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($userIdList); $this->assign('avatars', $avatars); $userNameList = $userService->getUserNamesForList($userIdList); $this->assign('userNameList', $userNameList); $questionList = BOL_QuestionService::getInstance()->getQuestionData($userIdList, array('sex', 'birthdate', 'email')); $this->assign('questionList', $questionList); $sexList = array(); foreach ($userIdList as $id) { if (empty($questionList[$id]['sex'])) { continue; } $sex = $questionList[$id]['sex']; if (!empty($sex)) { $sexValue = ''; for ($i = 0; $i < 31; $i++) { $val = pow(2, $i); if ((int) $sex & $val) { $sexValue .= BOL_QuestionService::getInstance()->getQuestionValueLang('sex', $val) . ', '; } } if (!empty($sexValue)) { $sexValue = substr($sexValue, 0, -2); } } $sexList[$id] = $sexValue; } $this->assign('sexList', $sexList); $userSuspendedList = $userService->findSupsendStatusForUserList($userIdList); $this->assign('suspendedList', $userSuspendedList); $userUnverfiedList = $userService->findUnverifiedStatusForUserList($userIdList); $this->assign('unverifiedList', $userUnverfiedList); $userUnapprovedList = $userService->findUnapprovedStatusForUserList($userIdList); $this->assign('unapprovedList', $userUnapprovedList); $onlineStatus = $userService->findOnlineStatusForUserList($userIdList); $this->assign('onlineStatus', $onlineStatus); $moderatorList = $authService->getModeratorList(); $adminList = array(); /* @var $moderator BOL_AuthorizationModerator */ foreach ($moderatorList as $moderator) { $userId = $moderator->getUserId(); if ($userService->findUserById($userId) !== null && $authService->isActionAuthorizedForUser($userId, BOL_AuthorizationService::ADMIN_GROUP_NAME)) { $adminList[] = $userId; } } $this->assign('adminList', $adminList); } else { $this->assign('users', null); } $this->assign('adminId', OW::getUser()->getId()); $this->assign('buttons', $params->getButtons()); $script = '$("#check-all").click(function() { $("#user-list-form input:not(:disabled)[type=checkbox]").attr("checked", $(this).attr("checked") == "checked"); });'; OW::getDocument()->addOnloadScript($script); }