baseline
[omp.pkp.sfu.ca.git] / pages / manager / PeopleHandler.inc.php
blob1a5bd0b23bfc4292f4ce0e043344a720971c9520
1 <?php
3 /**
4 * @file PeopleHandler.inc.php
6 * Copyright (c) 2003-2008 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9 * @class PeopleHandler
10 * @ingroup pages_manager
12 * @brief Handle requests for people management functions.
15 // $Id: PeopleHandler.inc.php,v 1.18 2009/10/06 21:57:31 asmecher Exp $
17 import('pages.manager.ManagerHandler');
19 class PeopleHandler extends ManagerHandler {
20 /**
21 * Constructor
22 **/
23 function PeopleHandler() {
24 parent::ManagerHandler();
27 /**
28 * Display list of people in the selected role.
29 * @param $args array first parameter is the role ID to display
30 */
31 function people($args) {
32 $this->validate();
33 $this->setupTemplate(true);
35 $roleDao =& DAORegistry::getDAO('RoleDAO');
37 if (Request::getUserVar('roleSymbolic')!=null) $roleSymbolic = Request::getUserVar('roleSymbolic');
38 else $roleSymbolic = isset($args[0])?$args[0]:'all';
40 if ($roleSymbolic != 'all' && String::regexp_match_get('/^(\w+)s$/', $roleSymbolic, $matches)) {
41 $roleId = $roleDao->getRoleIdFromPath($matches[1]);
42 if ($roleId == null) {
43 Request::redirect(null, null, null, 'all');
45 $roleName = $roleDao->getRoleName($roleId, true);
47 } else {
48 $roleId = 0;
49 $roleName = 'manager.people.allUsers';
52 $press =& Request::getPress();
53 $templateMgr =& TemplateManager::getManager();
55 $searchType = null;
56 $searchMatch = null;
57 $search = Request::getUserVar('search');
58 $searchInitial = Request::getUserVar('searchInitial');
59 if (!empty($search)) {
60 $searchType = Request::getUserVar('searchField');
61 $searchMatch = Request::getUserVar('searchMatch');
63 } elseif (!empty($searchInitial)) {
64 $searchInitial = String::strtoupper($searchInitial);
65 $searchType = USER_FIELD_INITIAL;
66 $search = $searchInitial;
69 $rangeInfo = Handler::getRangeInfo('users');
71 if ($roleId) {
72 $users =& $roleDao->getUsersByRoleId($roleId, $press->getId(), $searchType, $search, $searchMatch, $rangeInfo);
73 $templateMgr->assign('roleId', $roleId);
74 switch($roleId) {
75 case ROLE_ID_PRESS_MANAGER:
76 $helpTopicId = 'press.roles.pressManager';
77 break;
78 case ROLE_ID_EDITOR:
79 $helpTopicId = 'press.roles.editor';
80 break;
81 case ROLE_ID_ACQUISITIONS_EDITOR:
82 $helpTopicId = 'press.roles.acquisitionsEditor';
83 break;
84 case ROLE_ID_PRODUCTION_EDITOR:
85 $helpTopicId = 'press.roles.productionEditor';
86 break;
87 case ROLE_ID_DESIGNER:
88 $helpTopicId = 'press.roles.designer';
89 break;
90 case ROLE_ID_REVIEWER:
91 $helpTopicId = 'press.roles.reviewer';
92 break;
93 case ROLE_ID_COPYEDITOR:
94 $helpTopicId = 'press.roles.copyeditor';
95 break;
96 case ROLE_ID_PROOFREADER:
97 $helpTopicId = 'press.roles.proofreader';
98 break;
99 case ROLE_ID_AUTHOR:
100 $helpTopicId = 'press.roles.author';
101 break;
102 case ROLE_ID_READER:
103 $helpTopicId = 'press.roles.reader';
104 break;
105 case ROLE_ID_COMMITTEE_MEMBER:
106 $helpTopicId = 'press.roles.committeeMember';
107 break;
108 case ROLE_ID_DIRECTOR:
109 $helpTopicId = 'press.roles.director';
110 break;
111 case ROLE_ID_INDEXER:
112 $helpTopicId = 'press.roles.indexer';
113 break;
114 default:
115 $helpTopicId = 'press.roles.index';
116 break;
118 } else {
119 $users =& $roleDao->getUsersByPressId($press->getId(), $searchType, $search, $searchMatch, $rangeInfo);
120 $helpTopicId = 'press.users.allUsers';
123 $templateMgr->assign('currentUrl', Request::url(null, null, 'people', 'all'));
124 $templateMgr->assign('roleName', $roleName);
125 $templateMgr->assign_by_ref('users', $users);
126 $templateMgr->assign_by_ref('thisUser', Request::getUser());
127 $templateMgr->assign('isReviewer', $roleId == ROLE_ID_REVIEWER);
129 $templateMgr->assign('searchField', $searchType);
130 $templateMgr->assign('searchMatch', $searchMatch);
131 $templateMgr->assign('search', $search);
132 $templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));
134 if ($roleId == ROLE_ID_REVIEWER) {
135 $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
136 $templateMgr->assign('rateReviewerOnQuality', $press->getSetting('rateReviewerOnQuality'));
137 $templateMgr->assign('qualityRatings', $press->getSetting('rateReviewerOnQuality') ? $reviewAssignmentDao->getAverageQualityRatings($press->getId()) : null);
139 $templateMgr->assign('helpTopicId', $helpTopicId);
140 $fieldOptions = Array(
141 USER_FIELD_FIRSTNAME => 'user.firstName',
142 USER_FIELD_LASTNAME => 'user.lastName',
143 USER_FIELD_USERNAME => 'user.username',
144 USER_FIELD_INTERESTS => 'user.interests',
145 USER_FIELD_EMAIL => 'user.email'
147 if ($roleId == ROLE_ID_REVIEWER) $fieldOptions = array_merge(array(USER_FIELD_INTERESTS => 'user.interests'), $fieldOptions);
148 $templateMgr->assign('fieldOptions', $fieldOptions);
149 $templateMgr->assign('rolePath', $roleDao->getRolePath($roleId));
150 $templateMgr->assign('alphaList', explode(' ', Locale::translate('common.alphaList')));
151 $templateMgr->assign('roleSymbolic', $roleSymbolic);
153 $session =& Request::getSession();
154 $session->setSessionVar('enrolmentReferrer', Request::getRequestedArgs());
156 $templateMgr->display('manager/people/enrollment.tpl');
160 * Search for users to enroll in a specific role.
161 * @param $args array first parameter is the selected role ID
163 function enrollSearch($args) {
164 $this->validate();
166 $roleDao =& DAORegistry::getDAO('RoleDAO');
167 $pressDao =& DAORegistry::getDAO('PressDAO');
168 $userDao =& DAORegistry::getDAO('UserDAO');
170 $roleId = (int)(isset($args[0])?$args[0]:Request::getUserVar('roleId'));
171 $press =& $pressDao->getPressByPath(Request::getRequestedPressPath());
173 $templateMgr =& TemplateManager::getManager();
175 $this->setupTemplate(true);
177 $searchType = null;
178 $searchMatch = null;
179 $search = Request::getUserVar('search');
180 $searchInitial = Request::getUserVar('searchInitial');
181 if (!empty($search)) {
182 $searchType = Request::getUserVar('searchField');
183 $searchMatch = Request::getUserVar('searchMatch');
185 } elseif (!empty($searchInitial)) {
186 $searchInitial = String::strtoupper($searchInitial);
187 $searchType = USER_FIELD_INITIAL;
188 $search = $searchInitial;
191 $rangeInfo = Handler::getRangeInfo('users');
193 $users =& $userDao->getUsersByField($searchType, $searchMatch, $search, true, $rangeInfo);
195 $templateMgr->assign('searchField', $searchType);
196 $templateMgr->assign('searchMatch', $searchMatch);
197 $templateMgr->assign('search', $search);
198 $templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));
200 $templateMgr->assign('roleId', $roleId);
201 $templateMgr->assign('roleName', $roleDao->getRoleName($roleId));
202 $fieldOptions = Array(
203 USER_FIELD_FIRSTNAME => 'user.firstName',
204 USER_FIELD_LASTNAME => 'user.lastName',
205 USER_FIELD_USERNAME => 'user.username',
206 USER_FIELD_EMAIL => 'user.email'
208 if ($roleId == ROLE_ID_REVIEWER) $fieldOptions = array_merge(array(USER_FIELD_INTERESTS => 'user.interests'), $fieldOptions);
209 $templateMgr->assign('fieldOptions', $fieldOptions);
210 $templateMgr->assign_by_ref('users', $users);
211 $templateMgr->assign_by_ref('thisUser', Request::getUser());
212 $templateMgr->assign('alphaList', explode(' ', Locale::translate('common.alphaList')));
213 $templateMgr->assign('helpTopicId', 'press.users.index');
215 $session =& Request::getSession();
216 $referrerUrl = $session->getSessionVar('enrolmentReferrer');
217 $templateMgr->assign('enrolmentReferrerUrl', isset($referrerUrl) ? Request::url(null,'manager','people',$referrerUrl) : Request::url(null,'manager'));
218 $session->unsetSessionVar('enrolmentReferrer');
220 $templateMgr->display('manager/people/searchUsers.tpl');
224 * Show users with no role.
226 function showNoRole() {
227 $this->validate();
229 $userDao =& DAORegistry::getDAO('UserDAO');
231 $templateMgr =& TemplateManager::getManager();
233 parent::setupTemplate(true);
235 $rangeInfo = Handler::getRangeInfo('users');
237 $users =& $userDao->getUsersWithNoRole(true, $rangeInfo);
239 $templateMgr->assign('omitSearch', true);
240 $templateMgr->assign_by_ref('users', $users);
241 $templateMgr->assign_by_ref('thisUser', Request::getUser());
242 $templateMgr->assign('helpTopicId', 'press.users.index');
243 $templateMgr->display('manager/people/searchUsers.tpl');
247 * Enroll a user in a role.
249 function enroll($args) {
250 $this->validate();
251 $roleId = (int)(isset($args[0])?$args[0]:Request::getUserVar('roleId'));
253 // Get a list of users to enroll -- either from the
254 // submitted array 'users', or the single user ID in
255 // 'userId'
256 $users = Request::getUserVar('users');
257 if (!isset($users) && Request::getUserVar('userId') != null) {
258 $users = array(Request::getUserVar('userId'));
261 $pressDao =& DAORegistry::getDAO('PressDAO');
262 $press =& $pressDao->getPressByPath(Request::getRequestedPressPath());
263 $roleDao =& DAORegistry::getDAO('RoleDAO');
264 $rolePath = $roleDao->getRolePath($roleId);
266 if ($users != null && is_array($users) && $rolePath != '' && $rolePath != 'admin') {
267 for ($i=0; $i<count($users); $i++) {
268 if (!$roleDao->roleExists($press->getId(), $users[$i], $roleId)) {
269 $role = new Role();
270 $role->setPressId($press->getId());
271 $role->setUserId($users[$i]);
272 $role->setRoleId($roleId);
274 $roleDao->insertRole($role);
279 Request::redirect(null, null, 'people', (empty($rolePath) ? null : $rolePath . 's'));
283 * Unenroll a user from a role.
285 function unEnroll($args) {
286 $roleId = isset($args[0])?$args[0]:0;
287 $this->validate();
289 $pressDao =& DAORegistry::getDAO('PressDAO');
290 $press =& $pressDao->getPressByPath(Request::getRequestedPressPath());
292 $roleDao =& DAORegistry::getDAO('RoleDAO');
293 if ($roleId != $roleDao->getRoleIdFromPath('admin')) {
294 $roleDao->deleteRoleByUserId(Request::getUserVar('userId'), $press->getId(), $roleId);
297 Request::redirect(null, null, 'people');
301 * Show form to synchronize user enrollment with another press.
303 function enrollSyncSelect($args) {
304 $this->validate();
305 $this->setupTemplate(true);
307 $rolePath = isset($args[0]) ? $args[0] : '';
308 $roleDao =& DAORegistry::getDAO('RoleDAO');
309 $roleId = $roleDao->getRoleIdFromPath($rolePath);
310 if ($roleId) {
311 $roleName = $roleDao->getRoleName($roleId, true);
312 } else {
313 $rolePath = '';
314 $roleName = '';
317 $pressDao =& DAORegistry::getDAO('PressDAO');
318 $pressNames =& $pressDao->getPressNames();
320 $press =& Request::getPress();
321 unset($pressNames[$press->getId()]);
323 $templateMgr =& TemplateManager::getManager();
324 $templateMgr->assign('rolePath', $rolePath);
325 $templateMgr->assign('roleName', $roleName);
326 $templateMgr->assign('pressOptions', $pressNames);
327 $templateMgr->display('manager/people/enrollSync.tpl');
331 * Synchronize user enrollment with another press.
333 function enrollSync($args) {
334 $this->validate();
336 $press =& Request::getPress();
337 $rolePath = Request::getUserVar('rolePath');
338 $syncPress = Request::getUserVar('syncPress');
340 $roleDao =& DAORegistry::getDAO('RoleDAO');
341 $roleId = $roleDao->getRoleIdFromPath($rolePath);
343 if ((!empty($roleId) || $rolePath == 'all') && !empty($syncPress)) {
344 $roles =& $roleDao->getRolesByPressId($syncPress == 'all' ? null : $syncPress, $roleId);
345 while (!$roles->eof()) {
346 $role =& $roles->next();
347 $role->setPressId($press->getId());
348 if ($role->getRolePath() != 'admin' && !$roleDao->roleExists($role->getPressId(), $role->getUserId(), $role->getRoleId())) {
349 $roleDao->insertRole($role);
354 Request::redirect(null, null, 'people', $roleDao->getRolePath($roleId));
358 * Display form to create a new user.
360 function createUser() {
361 $this->editUser();
365 * Get a suggested username, making sure it's not
366 * already used by the system. (Poor-man's AJAX.)
368 function suggestUsername() {
369 $this->validate();
370 $suggestion = Validation::suggestUsername(
371 Request::getUserVar('firstName'),
372 Request::getUserVar('lastName')
374 echo $suggestion;
378 * Display form to create/edit a user profile.
379 * @param $args array optional, if set the first parameter is the ID of the user to edit
381 function editUser($args = array()) {
382 $this->validate();
383 $this->setupTemplate(true);
385 $press =& Request::getPress();
387 $userId = isset($args[0])?$args[0]:null;
389 $templateMgr =& TemplateManager::getManager();
391 if ($userId !== null && !Validation::canAdminister($press->getId(), $userId)) {
392 // We don't have administrative rights
393 // over this user. Display an error.
394 $templateMgr->assign('pageTitle', 'manager.people');
395 $templateMgr->assign('errorMsg', 'manager.people.noAdministrativeRights');
396 $templateMgr->assign('backLink', Request::url(null, null, 'people', 'all'));
397 $templateMgr->assign('backLinkLabel', 'manager.people.allUsers');
398 return $templateMgr->display('common/error.tpl');
401 import('manager.form.UserManagementForm');
403 $templateMgr->assign('currentUrl', Request::url(null, null, 'people', 'all'));
404 if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor
405 $userForm = new UserManagementForm($userId);
406 } else {
407 $userForm =& new UserManagementForm($userId);
409 if ($userForm->isLocaleResubmit()) {
410 $userForm->readInputData();
411 } else {
412 $userForm->initData();
414 $userForm->display();
418 * Allow the Press Manager to merge user accounts, including attributed monographs etc.
420 function mergeUsers($args) {
421 $this->validate();
422 $this->setupTemplate(true);
424 $roleDao =& DAORegistry::getDAO('RoleDAO');
425 $userDao =& DAORegistry::getDAO('UserDAO');
427 $press =& Request::getPress();
428 $pressId = $press->getId();
429 $templateMgr =& TemplateManager::getManager();
431 $oldUserId = Request::getUserVar('oldUserId');
432 $newUserId = Request::getUserVar('newUserId');
434 // Ensure that we have administrative priveleges over the specified user(s).
435 if (
436 (!empty($oldUserId) && !Validation::canAdminister($pressId, $oldUserId)) ||
437 (!empty($newUserId) && !Validation::canAdminister($pressId, $newUserId))
439 $templateMgr->assign('pageTitle', 'manager.people');
440 $templateMgr->assign('errorMsg', 'manager.people.noAdministrativeRights');
441 $templateMgr->assign('backLink', Request::url(null, null, 'people', 'all'));
442 $templateMgr->assign('backLinkLabel', 'manager.people.allUsers');
443 return $templateMgr->display('common/error.tpl');
446 if (!empty($oldUserId) && !empty($newUserId)) {
447 import('user.UserAction');
448 UserAction::mergeUsers($oldUserId, $newUserId);
449 Request::redirect(null, 'manager');
452 if (!empty($oldUserId)) {
453 // Get the old username for the confirm prompt.
454 $oldUser =& $userDao->getUser($oldUserId);
455 $templateMgr->assign('oldUsername', $oldUser->getUsername());
456 unset($oldUser);
459 // The manager must select one or both IDs.
460 if (Request::getUserVar('roleSymbolic')!=null) $roleSymbolic = Request::getUserVar('roleSymbolic');
461 else $roleSymbolic = isset($args[0])?$args[0]:'all';
463 if ($roleSymbolic != 'all' && String::regexp_match_get('/^(\w+)s$/', $roleSymbolic, $matches)) {
464 $roleId = $roleDao->getRoleIdFromPath($matches[1]);
465 if ($roleId == null) {
466 Request::redirect(null, null, null, 'all');
468 $roleName = $roleDao->getRoleName($roleId, true);
469 } else {
470 $roleId = 0;
471 $roleName = 'manager.people.allUsers';
474 $searchType = null;
475 $searchMatch = null;
476 $search = Request::getUserVar('search');
477 $searchInitial = Request::getUserVar('searchInitial');
478 if (!empty($search)) {
479 $searchType = Request::getUserVar('searchField');
480 $searchMatch = Request::getUserVar('searchMatch');
482 } else if (!empty($searchInitial)) {
483 $searchInitial = String::strtoupper($searchInitial);
484 $searchType = USER_FIELD_INITIAL;
485 $search = $searchInitial;
488 $rangeInfo = Handler::getRangeInfo('users');
490 if ($roleId) {
491 $users =& $roleDao->getUsersByRoleId($roleId, $pressId, $searchType, $search, $searchMatch, $rangeInfo);
492 $templateMgr->assign('roleId', $roleId);
493 } else {
494 $users =& $roleDao->getUsersByPressId($pressId, $searchType, $search, $searchMatch, $rangeInfo);
497 $templateMgr->assign('currentUrl', Request::url(null, null, 'people', 'all'));
498 $templateMgr->assign('helpTopicId', 'press.managementPages.mergeUsers');
499 $templateMgr->assign('roleName', $roleName);
500 $templateMgr->assign_by_ref('users', $users);
501 $templateMgr->assign_by_ref('thisUser', Request::getUser());
502 $templateMgr->assign('isReviewer', $roleId == ROLE_ID_REVIEWER);
504 $templateMgr->assign('searchField', $searchType);
505 $templateMgr->assign('searchMatch', $searchMatch);
506 $templateMgr->assign('search', $search);
507 $templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));
509 if ($roleId == ROLE_ID_REVIEWER) {
510 $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
511 $templateMgr->assign('rateReviewerOnQuality', $press->getSetting('rateReviewerOnQuality'));
512 $templateMgr->assign('qualityRatings', $press->getSetting('rateReviewerOnQuality') ? $reviewAssignmentDao->getAverageQualityRatings($pressId) : null);
514 $templateMgr->assign('fieldOptions', Array(
515 USER_FIELD_FIRSTNAME => 'user.firstName',
516 USER_FIELD_LASTNAME => 'user.lastName',
517 USER_FIELD_USERNAME => 'user.username',
518 USER_FIELD_EMAIL => 'user.email',
519 USER_FIELD_INTERESTS => 'user.interests'
521 $templateMgr->assign('alphaList', explode(' ', Locale::translate('common.alphaList')));
522 $templateMgr->assign('oldUserId', $oldUserId);
523 $templateMgr->assign('rolePath', $roleDao->getRolePath($roleId));
524 $templateMgr->assign('roleSymbolic', $roleSymbolic);
525 $templateMgr->display('manager/people/selectMergeUser.tpl');
529 * Disable a user's account.
530 * @param $args array the ID of the user to disable
532 function disableUser($args) {
533 $this->validate();
534 $this->setupTemplate(true);
536 $userId = isset($args[0])?$args[0]:Request::getUserVar('userId');
537 $user =& Request::getUser();
538 $press =& Request::getPress();
540 if ($userId != null && $userId != $user->getId()) {
541 if (!Validation::canAdminister($press->getId(), $userId)) {
542 // We don't have administrative rights
543 // over this user. Display an error.
544 $templateMgr =& TemplateManager::getManager();
545 $templateMgr->assign('pageTitle', 'manager.people');
546 $templateMgr->assign('errorMsg', 'manager.people.noAdministrativeRights');
547 $templateMgr->assign('backLink', Request::url(null, null, 'people', 'all'));
548 $templateMgr->assign('backLinkLabel', 'manager.people.allUsers');
549 return $templateMgr->display('common/error.tpl');
551 $userDao =& DAORegistry::getDAO('UserDAO');
552 $user =& $userDao->getUser($userId);
553 if ($user) {
554 $user->setDisabled(1);
555 $user->setDisabledReason(Request::getUserVar('reason'));
557 $userDao->updateObject($user);
560 Request::redirect(null, null, 'people', 'all');
564 * Enable a user's account.
565 * @param $args array the ID of the user to enable
567 function enableUser($args) {
568 $this->validate();
569 $this->setupTemplate(true);
571 $userId = isset($args[0])?$args[0]:null;
572 $user =& Request::getUser();
574 if ($userId != null && $userId != $user->getId()) {
575 $userDao =& DAORegistry::getDAO('UserDAO');
576 $user =& $userDao->getUser($userId, true);
577 if ($user) {
578 $user->setDisabled(0);
580 $userDao->updateObject($user);
583 Request::redirect(null, null, 'people', 'all');
587 * Remove a user from all roles for the current press.
588 * @param $args array the ID of the user to remove
590 function removeUser($args) {
591 $this->validate();
592 $this->setupTemplate(true);
594 $userId = isset($args[0])?$args[0]:null;
595 $user =& Request::getUser();
596 $press =& Request::getPress();
598 if ($userId != null && $userId != $user->getId()) {
599 $roleDao =& DAORegistry::getDAO('RoleDAO');
600 $roleDao->deleteRoleByUserId($userId, $press->getId());
603 Request::redirect(null, null, 'people', 'all');
607 * Save changes to a user profile.
609 function updateUser() {
610 $this->validate();
611 $press =& Request::getPress();
612 $userId = Request::getUserVar('userId');
614 if (!empty($userId) && !Validation::canAdminister($press->getId(), $userId)) {
615 // We don't have administrative rights
616 // over this user. Display an error.
617 $templateMgr =& TemplateManager::getManager();
618 $templateMgr->assign('pageTitle', 'manager.people');
619 $templateMgr->assign('errorMsg', 'manager.people.noAdministrativeRights');
620 $templateMgr->assign('backLink', Request::url(null, null, 'people', 'all'));
621 $templateMgr->assign('backLinkLabel', 'manager.people.allUsers');
622 return $templateMgr->display('common/error.tpl');
625 import('manager.form.UserManagementForm');
627 if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor
628 $userForm = new UserManagementForm($userId);
629 } else {
630 $userForm =& new UserManagementForm($userId);
632 $userForm->readInputData();
634 if ($userForm->validate()) {
635 $userForm->execute();
637 if (Request::getUserVar('createAnother')) {
638 $this->setupTemplate(true);
639 $templateMgr =& TemplateManager::getManager();
640 $templateMgr->assign('currentUrl', Request::url(null, null, 'people', 'all'));
641 $templateMgr->assign('userCreated', true);
642 if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor
643 $userForm = new UserManagementForm();
644 } else {
645 $userForm =& new UserManagementForm();
647 $userForm->initData();
648 $userForm->display();
650 } else {
651 if ($source = Request::getUserVar('source')) Request::redirectUrl($source);
652 else Request::redirect(null, null, 'people', 'all');
655 } else {
656 $this->setupTemplate(true);
657 $userForm->display();
662 * Display a user's profile.
663 * @param $args array first parameter is the ID or username of the user to display
665 function userProfile($args) {
666 $this->validate();
667 $this->setupTemplate(true);
669 $templateMgr =& TemplateManager::getManager();
670 $templateMgr->assign('currentUrl', Request::url(null, null, 'people', 'all'));
671 $templateMgr->assign('helpTopicId', 'press.users.index');
673 $userDao =& DAORegistry::getDAO('UserDAO');
674 $userId = isset($args[0]) ? $args[0] : 0;
675 if (is_numeric($userId)) {
676 $userId = (int) $userId;
677 $user = $userDao->getUser($userId);
678 } else {
679 $user = $userDao->getUserByUsername($userId);
683 if ($user == null) {
684 // Non-existent user requested
685 $templateMgr->assign('pageTitle', 'manager.people');
686 $templateMgr->assign('errorMsg', 'manager.people.invalidUser');
687 $templateMgr->assign('backLink', Request::url(null, null, 'people', 'all'));
688 $templateMgr->assign('backLinkLabel', 'manager.people.allUsers');
689 $templateMgr->display('common/error.tpl');
691 } else {
692 $site =& Request::getSite();
693 $press =& Request::getPress();
694 $roleDao =& DAORegistry::getDAO('RoleDAO');
695 $roles =& $roleDao->getRolesByUserId($user->getId(), $press->getId());
697 $countryDao =& DAORegistry::getDAO('CountryDAO');
698 $country = null;
699 if ($user->getCountry() != '') {
700 $country = $countryDao->getCountry($user->getCountry());
702 $templateMgr->assign('country', $country);
704 $templateMgr->assign_by_ref('user', $user);
705 $templateMgr->assign_by_ref('userRoles', $roles);
706 $templateMgr->assign('localeNames', Locale::getAllLocales());
707 $templateMgr->display('manager/people/userProfile.tpl');