baseline
[omp.pkp.sfu.ca.git] / pages / admin / AdminPeopleHandler.inc.php
blob4c389af2a7f8a9afd7d57cb7e8ec512bd4fbb387
1 <?php
3 /**
4 * @file pages/admin/AdminPeopleHandler.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 AdminPeopleHandler
10 * @ingroup pages_admin
12 * @brief Handle requests for people management functions.
15 // $Id: AdminPeopleHandler.inc.php,v 1.7 2009/07/13 16:35:39 asmecher Exp $
17 import('pages.admin.AdminHandler');
19 class AdminPeopleHandler extends AdminHandler {
20 /**
21 * Constructor
23 function AdminPeopleHandler() {
24 parent::AdminHandler();
27 /**
28 * Allow the Site Administrator to merge user accounts, including attributed monographs etc.
30 function mergeUsers($args) {
31 $this->validate();
32 $this->setupTemplate(true);
34 $roleDao =& DAORegistry::getDAO('RoleDAO');
35 $userDao =& DAORegistry::getDAO('UserDAO');
37 $templateMgr =& TemplateManager::getManager();
39 $oldUserId = Request::getUserVar('oldUserId');
40 $newUserId = Request::getUserVar('newUserId');
42 if (!empty($oldUserId) && !empty($newUserId)) {
43 // Both user IDs have been selected. Merge the accounts.
45 $monographDao =& DAORegistry::getDAO('MonographDAO');
46 foreach ($monographDao->getMonographsByUserId($oldUserId) as $monograph) {
47 $monograph->setUserId($newUserId);
48 $monographDao->updateMonograph($monograph);
49 unset($monograph);
52 $commentDao =& DAORegistry::getDAO('CommentDAO');
53 foreach ($commentDao->getCommentsByUserId($oldUserId) as $comment) {
54 $comment->setUserId($newUserId);
55 $commentDao->updateComment($comment);
56 unset($comment);
59 $monographNoteDao =& DAORegistry::getDAO('MonographNoteDAO');
60 $monographNotes =& $monographNoteDao->getMonographNotesByUserId($oldUserId);
61 while ($monographNote =& $monographNotes->next()) {
62 $monographNote->setUserId($newUserId);
63 $monographNoteDao->updateMonographNote($monographNote);
64 unset($monographNote);
67 $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
68 $editAssignments =& $editAssignmentDao->getByUserId($oldUserId);
69 while ($editAssignment =& $editAssignments->next()) {
70 $editAssignment->setEditorId($newUserId);
71 $editAssignmentDao->updateEditAssignment($editAssignment);
72 unset($editAssignment);
75 $editorSubmissionDao =& DAORegistry::getDAO('EditorSubmissionDAO');
76 $editorSubmissionDao->transferEditorDecisions($oldUserId, $newUserId);
78 $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
79 foreach ($reviewAssignmentDao->getByUserId($oldUserId) as $reviewAssignment) {
80 $reviewAssignment->setReviewerId($newUserId);
81 $reviewAssignmentDao->updateObject($reviewAssignment);
82 unset($reviewAssignment);
85 $copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
86 $copyeditorSubmissions =& $copyeditorSubmissionDao->getCopyeditorSubmissionsByCopyeditorId($oldUserId);
87 while ($copyeditorSubmission =& $copyeditorSubmissions->next()) {
88 $copyeditorSubmission->setCopyeditorId($newUserId);
89 $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
90 unset($copyeditorSubmission);
93 $layoutEditorSubmissionDao =& DAORegistry::getDAO('LayoutEditorSubmissionDAO');
94 $layoutEditorSubmissions =& $layoutEditorSubmissionDao->getSubmissions($oldUserId);
95 while ($layoutEditorSubmission =& $layoutEditorSubmissions->next()) {
96 $layoutAssignment =& $layoutEditorSubmission->getLayoutAssignment();
97 $layoutAssignment->setEditorId($newUserId);
98 $layoutEditorSubmissionDao->updateSubmission($layoutEditorSubmission);
99 unset($layoutAssignment);
100 unset($layoutEditorSubmission);
103 $proofreaderSubmissionDao =& DAORegistry::getDAO('ProofreaderSubmissionDAO');
104 $proofreaderSubmissions =& $proofreaderSubmissionDao->getSubmissions($oldUserId);
105 while ($proofreaderSubmission =& $proofreaderSubmissions->next()) {
106 $proofAssignment =& $proofreaderSubmission->getProofAssignment();
107 $proofAssignment->setProofreaderId($newUserId);
108 $proofreaderSubmissionDao->updateSubmission($proofreaderSubmission);
109 unset($proofAssignment);
110 unset($proofreaderSubmission);
113 $monographEmailLogDao =& DAORegistry::getDAO('MonographEmailLogDAO');
114 $monographEmailLogDao->transferMonographLogEntries($oldUserId, $newUserId);
115 $monographEventLogDao =& DAORegistry::getDAO('MonographEventLogDAO');
116 $monographEventLogDao->transferMonographLogEntries($oldUserId, $newUserId);
118 $monographCommentDao =& DAORegistry::getDAO('MonographCommentDAO');
119 foreach ($monographCommentDao->getMonographCommentsByUserId($oldUserId) as $monographComment) {
120 $monographComment->setAuthorId($newUserId);
121 $monographCommentDao->updateMonographComment($monographComment);
122 unset($monographComment);
125 $accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
126 $accessKeyDao->transferAccessKeys($oldUserId, $newUserId);
128 // Delete the old user and associated info.
129 $sessionDao =& DAORegistry::getDAO('SessionDAO');
130 $sessionDao->deleteSessionsByUserId($oldUserId);
131 $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
132 $temporaryFileDao->deleteTemporaryFilesByUserId($oldUserId);
133 $notificationStatusDao =& DAORegistry::getDAO('NotificationStatusDAO');
134 $notificationStatusDao->deleteNotificationStatusByUserId($oldUserId);
135 $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO');
136 $userSettingsDao->deleteSettings($oldUserId);
137 $groupMembershipDao =& DAORegistry::getDAO('GroupMembershipDAO');
138 $groupMembershipDao->deleteMembershipByUserId($oldUserId);
139 $acquisitionsEditorsDao =& DAORegistry::getDAO('AcquisitionsEditorsDAO');
140 $acquisitionsEditorsDao->deleteEditorsByUserId($oldUserId);
142 // Transfer old user's roles
143 $roles =& $roleDao->getRolesByUserId($oldUserId);
144 foreach ($roles as $role) {
145 if (!$roleDao->roleExists($role->getPressId(), $newUserId, $role->getRoleId())) {
146 $role->setUserId($newUserId);
147 $roleDao->insertRole($role);
150 $roleDao->deleteRoleByUserId($oldUserId);
152 $userDao->deleteUserById($oldUserId);
154 Request::redirect(null, 'admin', 'mergeUsers');
157 if (!empty($oldUserId)) {
158 // Get the old username for the confirm prompt.
159 $oldUser =& $userDao->getUser($oldUserId);
160 $templateMgr->assign('oldUsername', $oldUser->getUsername());
161 unset($oldUser);
164 // The administrator must select one or both IDs.
165 if (Request::getUserVar('roleSymbolic')!=null) $roleSymbolic = Request::getUserVar('roleSymbolic');
166 else $roleSymbolic = isset($args[0])?$args[0]:'all';
168 if ($roleSymbolic != 'all' && String::regexp_match_get('/^(\w+)s$/', $roleSymbolic, $matches)) {
169 $roleId = $roleDao->getRoleIdFromPath($matches[1]);
170 if ($roleId == null) {
171 Request::redirect(null, null, null, 'all');
173 $roleName = $roleDao->getRoleName($roleId, true);
174 } else {
175 $roleId = 0;
176 $roleName = 'admin.mergeUsers.allUsers';
179 $searchType = null;
180 $searchMatch = null;
181 $search = Request::getUserVar('search');
182 $searchInitial = Request::getUserVar('searchInitial');
183 if (!empty($search)) {
184 $searchType = Request::getUserVar('searchField');
185 $searchMatch = Request::getUserVar('searchMatch');
187 } else if (!empty($searchInitial)) {
188 $searchInitial = String::strtoupper($searchInitial);
189 $searchType = USER_FIELD_INITIAL;
190 $search = $searchInitial;
193 $rangeInfo = Handler::getRangeInfo('users');
195 if ($roleId) {
196 $users =& $roleDao->getUsersByRoleId($roleId, null, $searchType, $search, $searchMatch, $rangeInfo);
197 $templateMgr->assign('roleId', $roleId);
198 } else {
199 $users =& $userDao->getUsersByField($searchType, $searchMatch, $search, true, $rangeInfo);
202 $templateMgr->assign('currentUrl', Request::url(null, null, 'mergeUsers'));
203 $templateMgr->assign('helpTopicId', 'site.administrativeFunctions');
204 $templateMgr->assign('roleName', $roleName);
205 $templateMgr->assign_by_ref('users', $users);
206 $templateMgr->assign_by_ref('thisUser', Request::getUser());
207 $templateMgr->assign('isReviewer', $roleId == ROLE_ID_REVIEWER);
209 $templateMgr->assign('searchField', $searchType);
210 $templateMgr->assign('searchMatch', $searchMatch);
211 $templateMgr->assign('search', $search);
212 $templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));
214 if ($roleId == ROLE_ID_REVIEWER) {
215 $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
216 $templateMgr->assign('rateReviewerOnQuality', $press->getSetting('rateReviewerOnQuality'));
217 $templateMgr->assign('qualityRatings', $press->getSetting('rateReviewerOnQuality') ? $reviewAssignmentDao->getAverageQualityRatings($pressId) : null);
219 $templateMgr->assign('fieldOptions', Array(
220 USER_FIELD_FIRSTNAME => 'user.firstName',
221 USER_FIELD_LASTNAME => 'user.lastName',
222 USER_FIELD_USERNAME => 'user.username',
223 USER_FIELD_EMAIL => 'user.email',
224 USER_FIELD_INTERESTS => 'user.interests'
226 $templateMgr->assign('alphaList', explode(' ', Locale::translate('common.alphaList')));
227 $templateMgr->assign('oldUserId', $oldUserId);
228 $templateMgr->assign('rolePath', $roleDao->getRolePath($roleId));
229 $templateMgr->assign('roleSymbolic', $roleSymbolic);
230 $templateMgr->display('admin/selectMergeUser.tpl');