Commit | Line | Data |
---|---|---|
11ade432 AE |
1 | <?php |
2 | namespace wcf\data\user; | |
0dd6ea0c MW |
3 | use wcf\data\object\type\ObjectTypeCache; |
4 | use wcf\data\user\avatar\UserAvatarAction; | |
11ade432 | 5 | use wcf\data\user\group\UserGroup; |
6374f974 | 6 | use wcf\data\user\UserEditor; |
931f6597 | 7 | use wcf\data\AbstractDatabaseObjectAction; |
7918ddba | 8 | use wcf\data\IClipboardAction; |
a427a8c8 | 9 | use wcf\data\ISearchAction; |
7f379ade | 10 | use wcf\system\clipboard\ClipboardHandler; |
11ade432 | 11 | use wcf\system\database\util\PreparedStatementConditionBuilder; |
781fe402 | 12 | use wcf\system\event\EventHandler; |
a79cfb56 | 13 | use wcf\system\exception\PermissionDeniedException; |
3631f7bd | 14 | use wcf\system\exception\UserInputException; |
bae8dd1e | 15 | use wcf\system\request\RequestHandler; |
2bc9f31d | 16 | use wcf\system\WCF; |
2fe45e04 | 17 | use wcf\util\UserRegistrationUtil; |
11ade432 AE |
18 | |
19 | /** | |
20 | * Executes user-related actions. | |
21 | * | |
22 | * @author Alexander Ebert | |
ca4ba303 | 23 | * @copyright 2001-2014 WoltLab GmbH |
11ade432 AE |
24 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
25 | * @package com.woltlab.wcf | |
26 | * @subpackage data.user | |
9f959ced | 27 | * @category Community Framework |
11ade432 | 28 | */ |
7918ddba | 29 | class UserAction extends AbstractDatabaseObjectAction implements IClipboardAction, ISearchAction { |
11ade432 | 30 | /** |
0ad90fc3 | 31 | * @see \wcf\data\AbstractDatabaseObjectAction::$className |
11ade432 AE |
32 | */ |
33 | public $className = 'wcf\data\user\UserEditor'; | |
34 | ||
8eb8876b | 35 | /** |
0ad90fc3 | 36 | * @see \wcf\data\AbstractDatabaseObjectAction::$allowGuestAccess |
8eb8876b MW |
37 | */ |
38 | protected $allowGuestAccess = array('getSearchResultList'); | |
39 | ||
11ade432 | 40 | /** |
0ad90fc3 | 41 | * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsCreate |
11ade432 AE |
42 | */ |
43 | protected $permissionsCreate = array('admin.user.canAddUser'); | |
44 | ||
45 | /** | |
0ad90fc3 | 46 | * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsDelete |
11ade432 AE |
47 | */ |
48 | protected $permissionsDelete = array('admin.user.canDeleteUser'); | |
49 | ||
50 | /** | |
0ad90fc3 | 51 | * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate |
11ade432 AE |
52 | */ |
53 | protected $permissionsUpdate = array('admin.user.canEditUser'); | |
54 | ||
bae8dd1e | 55 | /** |
0ad90fc3 | 56 | * @see \wcf\data\AbstractDatabaseObjectAction::$requireACP |
bae8dd1e | 57 | */ |
57f097e8 | 58 | protected $requireACP = array('create', 'delete', 'disable', 'enable'); |
bae8dd1e | 59 | |
11ade432 AE |
60 | /** |
61 | * Validates permissions and parameters. | |
62 | */ | |
63 | public function validateCreate() { | |
a54f8d8f | 64 | $this->readString('password', false, 'data'); |
11ade432 AE |
65 | } |
66 | ||
67 | /** | |
11cf19be MW |
68 | * Validates accessible groups. |
69 | * | |
70 | * @param boolean $ignoreOwnUser | |
11ade432 | 71 | */ |
11cf19be MW |
72 | protected function __validateAccessibleGroups($ignoreOwnUser = true) { |
73 | if ($ignoreOwnUser) { | |
74 | if (in_array(WCF::getUser()->userID, $this->objectIDs)) { | |
75 | unset($this->objectIDs[array_search(WCF::getUser()->userID, $this->objectIDs)]); | |
76 | if (isset($this->objects[WCF::getUser()->userID])) { | |
77 | unset($this->objects[WCF::getUser()->userID]); | |
78 | } | |
a7fd745e | 79 | } |
48f9369a | 80 | } |
11ade432 | 81 | |
a7fd745e | 82 | // list might be empty because only our own user id was given |
11cf19be | 83 | if (empty($this->objectIDs)) { |
3631f7bd | 84 | throw new UserInputException('objectIDs'); |
a7fd745e AE |
85 | } |
86 | ||
11ade432 AE |
87 | // validate groups |
88 | $conditions = new PreparedStatementConditionBuilder(); | |
11cf19be | 89 | $conditions->add("userID IN (?)", array($this->objectIDs)); |
11ade432 AE |
90 | |
91 | $sql = "SELECT DISTINCT groupID | |
92 | FROM wcf".WCF_N."_user_to_group | |
93 | ".$conditions; | |
94 | $statement = WCF::getDB()->prepareStatement($sql); | |
95 | $statement->execute($conditions->getParameters()); | |
96 | ||
97 | $groupIDs = array(); | |
98 | while ($row = $statement->fetchArray()) { | |
99 | $groupIDs[] = $row['groupID']; | |
100 | } | |
101 | ||
102 | if (!UserGroup::isAccessibleGroup($groupIDs)) { | |
3631f7bd | 103 | throw new PermissionDeniedException(); |
11ade432 AE |
104 | } |
105 | } | |
106 | ||
11cf19be MW |
107 | /** |
108 | * Validates permissions and parameters. | |
109 | */ | |
110 | public function validateDelete() { | |
111 | // read and validate user objects | |
112 | parent::validateDelete(); | |
113 | ||
114 | $this->__validateAccessibleGroups(); | |
115 | } | |
116 | ||
0dd6ea0c | 117 | /** |
0ad90fc3 | 118 | * @see \wcf\data\IDeleteAction::delete() |
0dd6ea0c MW |
119 | */ |
120 | public function delete() { | |
121 | if (empty($this->objects)) { | |
122 | $this->readObjects(); | |
123 | } | |
124 | ||
125 | // delete avatars | |
126 | $avatarIDs = array(); | |
127 | foreach ($this->objects as $user) { | |
128 | if ($user->avatarID) $avatarIDs[] = $user->avatarID; | |
129 | } | |
130 | if (!empty($avatarIDs)) { | |
131 | $action = new UserAvatarAction($avatarIDs, 'delete'); | |
132 | $action->executeAction(); | |
133 | } | |
134 | ||
135 | // delete profile comments | |
136 | if (!empty($this->objectIDs)) { | |
137 | $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.comment.commentableContent', 'com.woltlab.wcf.user.profileComment'); | |
138 | $conditionBuilder = new PreparedStatementConditionBuilder(); | |
139 | $conditionBuilder->add('objectTypeID = ?', array($objectType->objectTypeID)); | |
140 | $conditionBuilder->add('objectID IN (?)', array($this->objectIDs)); | |
141 | ||
142 | $sql = "DELETE FROM wcf".WCF_N."_comment | |
143 | ".$conditionBuilder; | |
144 | $statement = WCF::getDB()->prepareStatement($sql); | |
145 | $statement->execute($conditionBuilder->getParameters()); | |
146 | } | |
147 | ||
148 | $returnValue = parent::delete(); | |
149 | ||
150 | return $returnValue; | |
151 | } | |
152 | ||
11ade432 AE |
153 | /** |
154 | * Validates permissions and parameters. | |
11ade432 AE |
155 | */ |
156 | public function validateUpdate() { | |
a79cfb56 | 157 | // read objects |
15fa2802 | 158 | if (empty($this->objects)) { |
a79cfb56 | 159 | $this->readObjects(); |
15fa2802 MS |
160 | |
161 | if (empty($this->objects)) { | |
3631f7bd | 162 | throw new UserInputException('objectIDs'); |
15fa2802 | 163 | } |
a79cfb56 | 164 | } |
11ade432 | 165 | |
bae8dd1e AE |
166 | // disallow updating of anything except for options outside of ACP |
167 | if (RequestHandler::getInstance()->isACPRequest() && (count($this->parameters) != 1 || !isset($this->parameters['options']))) { | |
168 | throw new PermissionDeniedException(); | |
169 | } | |
170 | ||
a79cfb56 AE |
171 | try { |
172 | WCF::getSession()->checkPermissions($this->permissionsUpdate); | |
173 | } | |
174 | catch (PermissionDeniedException $e) { | |
175 | // check if we're editing ourselves | |
176 | if (count($this->objects) == 1 && ($this->objects[0]->userID == WCF::getUser()->userID)) { | |
67ca3261 AE |
177 | $count = count($this->parameters); |
178 | if ($count > 1 || ($count == 1 && !isset($this->parameters['options']))) { | |
3631f7bd | 179 | throw new PermissionDeniedException(); |
a79cfb56 AE |
180 | } |
181 | } | |
182 | ||
3631f7bd | 183 | throw new PermissionDeniedException(); |
a79cfb56 | 184 | } |
11ade432 AE |
185 | } |
186 | ||
11cf19be MW |
187 | /** |
188 | * Validates the ban action. | |
189 | */ | |
190 | public function validateBan() { | |
191 | WCF::getSession()->checkPermissions(array('admin.user.canBanUser')); | |
192 | ||
193 | $this->__validateAccessibleGroups(); | |
194 | } | |
195 | ||
196 | /** | |
197 | * Validates the unban action. | |
198 | */ | |
199 | public function validateUnban() { | |
200 | $this->validateBan(); | |
201 | } | |
202 | ||
203 | /** | |
204 | * Bans users. | |
205 | */ | |
206 | public function ban() { | |
207 | $conditionBuilder = new PreparedStatementConditionBuilder(); | |
208 | $conditionBuilder->add('userID IN (?)', array($this->objectIDs)); | |
209 | $sql = "UPDATE wcf".WCF_N."_user | |
210 | SET banned = ?, | |
211 | banReason = ? | |
212 | ".$conditionBuilder; | |
213 | $statement = WCF::getDB()->prepareStatement($sql); | |
214 | $statement->execute( | |
57f097e8 | 215 | array_merge(array(1, $this->parameters['banReason']), $conditionBuilder->getParameters()) |
11cf19be | 216 | ); |
bbef7ed8 MW |
217 | |
218 | $this->unmarkItems(); | |
11cf19be MW |
219 | } |
220 | ||
221 | /** | |
222 | * Unbans users. | |
223 | */ | |
224 | public function unban() { | |
225 | $conditionBuilder = new PreparedStatementConditionBuilder(); | |
226 | $conditionBuilder->add('userID IN (?)', array($this->objectIDs)); | |
227 | $sql = "UPDATE wcf".WCF_N."_user | |
228 | SET banned = 0 | |
229 | ".$conditionBuilder; | |
230 | $statement = WCF::getDB()->prepareStatement($sql); | |
231 | $statement->execute($conditionBuilder->getParameters()); | |
232 | } | |
233 | ||
11ade432 AE |
234 | /** |
235 | * Creates a new user. | |
236 | * | |
237 | * @return User | |
238 | */ | |
239 | public function create() { | |
240 | $user = parent::create(); | |
241 | $userEditor = new UserEditor($user); | |
242 | ||
243 | // updates user options | |
244 | if (isset($this->parameters['options'])) { | |
245 | $userEditor->updateUserOptions($this->parameters['options']); | |
246 | } | |
247 | ||
248 | // insert user groups | |
2bb10466 | 249 | $addDefaultGroups = (isset($this->parameters['addDefaultGroups'])) ? $this->parameters['addDefaultGroups'] : true; |
11ade432 | 250 | $groupIDs = (isset($this->parameters['groups'])) ? $this->parameters['groups'] : array(); |
2bb10466 | 251 | $userEditor->addToGroups($groupIDs, false, $addDefaultGroups); |
11ade432 AE |
252 | |
253 | // insert visible languages | |
254 | $languageIDs = (isset($this->parameters['languages'])) ? $this->parameters['languages'] : array(); | |
695780d7 | 255 | $userEditor->addToLanguages($languageIDs, false); |
11ade432 | 256 | |
320f4a6d MW |
257 | if (PACKAGE_ID) { |
258 | // set default notifications | |
259 | $sql = "INSERT INTO wcf".WCF_N."_user_notification_event_to_user | |
260 | (userID, eventID) | |
695780d7 MW |
261 | SELECT ?, eventID |
262 | FROM wcf".WCF_N."_user_notification_event | |
263 | WHERE preset = ?"; | |
320f4a6d | 264 | $statement = WCF::getDB()->prepareStatement($sql); |
695780d7 | 265 | $statement->execute(array($user->userID, 1)); |
c9d91afc MW |
266 | |
267 | // update user rank | |
268 | if (MODULE_USER_RANK) { | |
269 | $action = new UserProfileAction(array($userEditor), 'updateUserRank'); | |
270 | $action->executeAction(); | |
271 | } | |
272 | // update user online marking | |
273 | $action = new UserProfileAction(array($userEditor), 'updateUserOnlineMarking'); | |
274 | $action->executeAction(); | |
320f4a6d MW |
275 | } |
276 | ||
11ade432 AE |
277 | return $user; |
278 | } | |
835fa8c2 AE |
279 | |
280 | /** | |
0ad90fc3 | 281 | * @see \wcf\data\AbstractDatabaseObjectAction::update() |
835fa8c2 AE |
282 | */ |
283 | public function update() { | |
881246d6 AE |
284 | if (isset($this->parameters['data'])) { |
285 | parent::update(); | |
8a3258f5 MS |
286 | |
287 | if (isset($this->parameters['data']['languageID'])) { | |
288 | foreach ($this->objects as $object) { | |
289 | if ($object->userID == WCF::getUser()->userID) { | |
290 | if ($this->parameters['data']['languageID'] != WCF::getUser()->languageID) { | |
291 | WCF::setLanguage($this->parameters['data']['languageID']); | |
292 | } | |
293 | ||
294 | break; | |
295 | } | |
296 | } | |
297 | } | |
881246d6 AE |
298 | } |
299 | else { | |
15fa2802 | 300 | if (empty($this->objects)) { |
881246d6 AE |
301 | $this->readObjects(); |
302 | } | |
303 | } | |
835fa8c2 AE |
304 | |
305 | $groupIDs = (isset($this->parameters['groups'])) ? $this->parameters['groups'] : array(); | |
44adccf6 | 306 | $languageIDs = (isset($this->parameters['languageIDs'])) ? $this->parameters['languageIDs'] : array(); |
835fa8c2 | 307 | $removeGroups = (isset($this->parameters['removeGroups'])) ? $this->parameters['removeGroups'] : array(); |
f277d540 | 308 | $userOptions = (isset($this->parameters['options'])) ? $this->parameters['options'] : array(); |
835fa8c2 | 309 | |
c2000c5d | 310 | if (!empty($groupIDs)) { |
12f80a9d MW |
311 | $action = new UserAction($this->objects, 'addToGroups', array( |
312 | 'groups' => $groupIDs, | |
313 | 'addDefaultGroups' => false | |
314 | )); | |
c2000c5d MW |
315 | $action->executeAction(); |
316 | } | |
317 | ||
835fa8c2 | 318 | foreach ($this->objects as $userEditor) { |
f277d540 | 319 | if (!empty($removeGroups)) { |
835fa8c2 AE |
320 | $userEditor->removeFromGroups($removeGroups); |
321 | } | |
f277d540 AE |
322 | |
323 | if (!empty($userOptions)) { | |
324 | $userEditor->updateUserOptions($userOptions); | |
325 | } | |
44adccf6 AE |
326 | |
327 | if (!empty($languageIDs)) { | |
328 | $userEditor->addToLanguages($languageIDs); | |
329 | } | |
835fa8c2 | 330 | } |
83f2404b AE |
331 | |
332 | // handle user rename | |
333 | if (count($this->objects) == 1 && !empty($this->parameters['data']['username'])) { | |
334 | if ($this->objects[0]->username != $this->parameters['data']['username']) { | |
335 | $userID = $this->objects[0]->userID; | |
336 | $username = $this->parameters['data']['username']; | |
337 | ||
338 | WCF::getDB()->beginTransaction(); | |
339 | ||
340 | // update comments | |
341 | $sql = "UPDATE wcf".WCF_N."_comment | |
342 | SET username = ? | |
343 | WHERE userID = ?"; | |
344 | $statement = WCF::getDB()->prepareStatement($sql); | |
345 | $statement->execute(array($username, $userID)); | |
346 | ||
347 | $sql = "UPDATE wcf".WCF_N."_comment_response | |
348 | SET username = ? | |
349 | WHERE userID = ?"; | |
350 | $statement = WCF::getDB()->prepareStatement($sql); | |
351 | $statement->execute(array($username, $userID)); | |
352 | ||
353 | // modification log | |
354 | $sql = "UPDATE wcf".WCF_N."_modification_log | |
355 | SET username = ? | |
356 | WHERE userID = ?"; | |
357 | $statement = WCF::getDB()->prepareStatement($sql); | |
358 | $statement->execute(array($username, $userID)); | |
359 | ||
360 | WCF::getDB()->commitTransaction(); | |
361 | ||
362 | // fire event to handle other database tables | |
363 | EventHandler::getInstance()->fireAction($this, 'rename'); | |
364 | } | |
365 | } | |
835fa8c2 | 366 | } |
d5cab442 | 367 | |
0dd6ea0c MW |
368 | /** |
369 | * Add users to given groups. | |
370 | */ | |
c2000c5d MW |
371 | public function addToGroups() { |
372 | if (empty($this->objects)) { | |
373 | $this->readObjects(); | |
374 | } | |
375 | ||
376 | $groupIDs = $this->parameters['groups']; | |
377 | $deleteOldGroups = $addDefaultGroups = true; | |
378 | if (isset($this->parameters['deleteOldGroups'])) $deleteOldGroups = $this->parameters['deleteOldGroups']; | |
379 | if (isset($this->parameters['addDefaultGroups'])) $addDefaultGroups = $this->parameters['addDefaultGroups']; | |
380 | ||
381 | foreach ($this->objects as $userEditor) { | |
382 | $userEditor->addToGroups($groupIDs, $deleteOldGroups, $addDefaultGroups); | |
383 | } | |
320f4a6d | 384 | |
6374f974 JR |
385 | //reread objects |
386 | $this->objects = array(); | |
387 | UserEditor::resetCache(); | |
388 | $this->readObjects(); | |
389 | ||
320f4a6d MW |
390 | if (MODULE_USER_RANK) { |
391 | $action = new UserProfileAction($this->objects, 'updateUserRank'); | |
392 | $action->executeAction(); | |
393 | } | |
394 | if (MODULE_USERS_ONLINE) { | |
395 | $action = new UserProfileAction($this->objects, 'updateUserOnlineMarking'); | |
396 | $action->executeAction(); | |
397 | } | |
c2000c5d MW |
398 | } |
399 | ||
a7fd745e | 400 | /** |
0ad90fc3 | 401 | * @see \wcf\data\ISearchAction::validateGetSearchResultList() |
a7fd745e | 402 | */ |
a427a8c8 | 403 | public function validateGetSearchResultList() { |
a54f8d8f AE |
404 | $this->readBoolean('includeUserGroups', false, 'data'); |
405 | $this->readString('searchString', false, 'data'); | |
a7fd745e AE |
406 | |
407 | if (isset($this->parameters['data']['excludedSearchValues']) && !is_array($this->parameters['data']['excludedSearchValues'])) { | |
3631f7bd | 408 | throw new UserInputException('excludedSearchValues'); |
a7fd745e | 409 | } |
d5cab442 AE |
410 | } |
411 | ||
a7fd745e | 412 | /** |
0ad90fc3 | 413 | * @see \wcf\data\ISearchAction::getSearchResultList() |
a7fd745e | 414 | */ |
a427a8c8 | 415 | public function getSearchResultList() { |
d5cab442 | 416 | $searchString = $this->parameters['data']['searchString']; |
c000b08a MS |
417 | $excludedSearchValues = array(); |
418 | if (isset($this->parameters['data']['excludedSearchValues'])) { | |
419 | $excludedSearchValues = $this->parameters['data']['excludedSearchValues']; | |
420 | } | |
d5cab442 | 421 | $list = array(); |
9f959ced | 422 | |
d5cab442 AE |
423 | if ($this->parameters['data']['includeUserGroups']) { |
424 | $accessibleGroups = UserGroup::getAccessibleGroups(); | |
425 | foreach ($accessibleGroups as $group) { | |
18c05238 | 426 | $groupName = $group->getName(); |
c000b08a | 427 | if (!in_array($groupName, $excludedSearchValues)) { |
838e315b | 428 | $pos = mb_strripos($groupName, $searchString); |
c000b08a MS |
429 | if ($pos !== false && $pos == 0) { |
430 | $list[] = array( | |
431 | 'label' => $groupName, | |
432 | 'objectID' => $group->groupID, | |
433 | 'type' => 'group' | |
434 | ); | |
435 | } | |
d5cab442 AE |
436 | } |
437 | } | |
438 | } | |
c000b08a | 439 | |
c2d0b2d6 MS |
440 | // find users |
441 | $userProfileList = new UserProfileList(); | |
442 | $userProfileList->getConditionBuilder()->add("username LIKE ?", array($searchString.'%')); | |
15fa2802 | 443 | if (!empty($excludedSearchValues)) { |
c2d0b2d6 | 444 | $userProfileList->getConditionBuilder()->add("username NOT IN (?)", array($excludedSearchValues)); |
c000b08a | 445 | } |
c2d0b2d6 MS |
446 | $userProfileList->sqlLimit = 10; |
447 | $userProfileList->readObjects(); | |
9f959ced | 448 | |
c2d0b2d6 | 449 | foreach ($userProfileList as $userProfile) { |
d5cab442 | 450 | $list[] = array( |
c2d0b2d6 MS |
451 | 'icon' => $userProfile->getAvatar()->getImageTag(16), |
452 | 'label' => $userProfile->username, | |
453 | 'objectID' => $userProfile->userID, | |
d5cab442 AE |
454 | 'type' => 'user' |
455 | ); | |
456 | } | |
9f959ced | 457 | |
d5cab442 AE |
458 | return $list; |
459 | } | |
49c164a8 AE |
460 | |
461 | /** | |
0ad90fc3 | 462 | * @see \wcf\data\IClipboardAction::validateUnmarkAll() |
49c164a8 | 463 | */ |
fbb077d4 MS |
464 | public function validateUnmarkAll() { |
465 | // does nothing | |
466 | } | |
49c164a8 AE |
467 | |
468 | /** | |
0ad90fc3 | 469 | * @see \wcf\data\IClipboardAction::unmarkAll() |
49c164a8 AE |
470 | */ |
471 | public function unmarkAll() { | |
472 | ClipboardHandler::getInstance()->removeItems(ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user')); | |
473 | } | |
bbef7ed8 MW |
474 | |
475 | /** | |
476 | * Unmarks users. | |
59dc0db6 | 477 | * |
bbef7ed8 MW |
478 | * @param array<integer> $userIDs |
479 | */ | |
480 | protected function unmarkItems(array $userIDs = array()) { | |
481 | if (empty($userIDs)) { | |
482 | $userIDs = $this->objectIDs; | |
483 | } | |
e3369fd2 | 484 | |
bbef7ed8 MW |
485 | if (!empty($userIDs)) { |
486 | ClipboardHandler::getInstance()->unmark($userIDs, ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user')); | |
487 | } | |
488 | } | |
2fe45e04 MW |
489 | |
490 | /** | |
491 | * Validates the enable action. | |
492 | */ | |
493 | public function validateEnable() { | |
494 | WCF::getSession()->checkPermissions(array('admin.user.canEnableUser')); | |
9927f711 MS |
495 | |
496 | $this->__validateAccessibleGroups(); | |
2fe45e04 MW |
497 | } |
498 | ||
499 | /** | |
500 | * Validates the disable action. | |
501 | */ | |
502 | public function validateDisable() { | |
503 | $this->validateEnable(); | |
504 | } | |
505 | ||
506 | /** | |
507 | * Enables users. | |
508 | */ | |
509 | public function enable() { | |
510 | if (empty($this->objects)) $this->readObjects(); | |
9927f711 | 511 | |
2fe45e04 MW |
512 | $action = new UserAction($this->objects, 'update', array( |
513 | 'data' => array( | |
514 | 'activationCode' => 0 | |
515 | ), | |
2818981f | 516 | 'removeGroups' => UserGroup::getGroupIDsByType(array(UserGroup::GUESTS)) |
2fe45e04 MW |
517 | )); |
518 | $action->executeAction(); | |
2818981f MW |
519 | $action = new UserAction($this->objects, 'addToGroups', array( |
520 | 'groups' => UserGroup::getGroupIDsByType(array(UserGroup::USERS)), | |
521 | 'deleteOldGroups' => false, | |
9927f711 | 522 | 'addDefaultGroups' => false |
2818981f | 523 | )); |
2fe45e04 | 524 | $action->executeAction(); |
00ce5cf8 AE |
525 | |
526 | $this->unmarkItems(); | |
2fe45e04 MW |
527 | } |
528 | ||
529 | /** | |
530 | * Disables users. | |
531 | */ | |
532 | public function disable() { | |
533 | if (empty($this->objects)) $this->readObjects(); | |
9927f711 | 534 | |
2fe45e04 MW |
535 | $action = new UserAction($this->objects, 'update', array( |
536 | 'data' => array( | |
537 | 'activationCode' => UserRegistrationUtil::getActivationCode() | |
538 | ), | |
2818981f | 539 | 'removeGroups' => UserGroup::getGroupIDsByType(array(UserGroup::USERS)), |
2fe45e04 MW |
540 | )); |
541 | $action->executeAction(); | |
2818981f MW |
542 | $action = new UserAction($this->objects, 'addToGroups', array( |
543 | 'groups' => UserGroup::getGroupIDsByType(array(UserGroup::GUESTS)), | |
544 | 'deleteOldGroups' => false, | |
545 | 'addDefaultGroups' => false | |
546 | )); | |
2fe45e04 | 547 | $action->executeAction(); |
00ce5cf8 AE |
548 | |
549 | $this->unmarkItems(); | |
2fe45e04 | 550 | } |
2ce24640 MW |
551 | |
552 | /** | |
553 | * @see \wcf\data\AbstractDatabaseObjectAction::readObjects() | |
554 | */ | |
555 | protected function readObjects() { | |
556 | if (empty($this->objectIDs)) { | |
557 | return; | |
558 | } | |
57f097e8 | 559 | |
2ce24640 MW |
560 | // get base class |
561 | $baseClass = call_user_func(array($this->className, 'getBaseClass')); | |
57f097e8 | 562 | |
2ce24640 MW |
563 | // get objects |
564 | $sql = "SELECT user_option_value.*, user_table.* | |
565 | FROM wcf".WCF_N."_user user_table | |
566 | LEFT JOIN wcf".WCF_N."_user_option_value user_option_value | |
567 | ON (user_option_value.userID = user_table.userID) | |
568 | WHERE user_table.userID IN (".str_repeat('?,', count($this->objectIDs) - 1)."?)"; | |
569 | $statement = WCF::getDB()->prepareStatement($sql); | |
570 | $statement->execute($this->objectIDs); | |
571 | while ($object = $statement->fetchObject($baseClass)) { | |
572 | $this->objects[] = new $this->className($object); | |
573 | } | |
574 | } | |
57f097e8 MS |
575 | |
576 | /** | |
577 | * Validates the 'disableSignature' action. | |
578 | */ | |
579 | public function validateDisableSignature() { | |
3696fe93 | 580 | $this->validateEnableSignature(); |
57f097e8 MS |
581 | |
582 | $this->readString('disableSignatureReason', true); | |
583 | } | |
584 | ||
585 | /** | |
586 | * Disables the signature of the handled users. | |
587 | */ | |
588 | public function disableSignature() { | |
589 | if (empty($this->objects)) { | |
590 | $this->readObjects(); | |
591 | } | |
592 | ||
593 | foreach ($this->objects as $userEditor) { | |
594 | $userEditor->update(array( | |
595 | 'disableSignature' => 1, | |
596 | 'disableSignatureReason' => $this->parameters['disableSignatureReason'] | |
597 | )); | |
598 | } | |
599 | } | |
600 | ||
601 | /** | |
602 | * Validates the 'enableSignature' action. | |
603 | */ | |
604 | public function validateEnableSignature() { | |
605 | WCF::getSession()->checkPermissions(array('admin.user.canDisableSignature')); | |
606 | ||
607 | $this->__validateAccessibleGroups(); | |
608 | ||
609 | if (empty($this->objects)) { | |
610 | $this->readObjects(); | |
611 | ||
612 | if (empty($this->objects)) { | |
613 | throw new UserInputException('objectIDs'); | |
614 | } | |
615 | } | |
616 | } | |
617 | ||
618 | /** | |
619 | * Enables the signature of the handled users. | |
620 | */ | |
621 | public function enableSignature() { | |
622 | if (empty($this->objects)) { | |
623 | $this->readObjects(); | |
624 | } | |
625 | ||
626 | foreach ($this->objects as $userEditor) { | |
627 | $userEditor->update(array( | |
628 | 'disableSignature' => 0 | |
629 | )); | |
630 | } | |
631 | } | |
632 | ||
633 | /** | |
634 | * Validates the 'disableAvatar' action. | |
635 | */ | |
636 | public function validateDisableAvatar() { | |
3696fe93 | 637 | $this->validateEnableAvatar(); |
57f097e8 MS |
638 | |
639 | $this->readString('disableAvatarReason', true); | |
640 | } | |
641 | ||
642 | /** | |
643 | * Disables the avatar of the handled users. | |
644 | */ | |
645 | public function disableAvatar() { | |
646 | if (empty($this->objects)) { | |
647 | $this->readObjects(); | |
648 | } | |
649 | ||
650 | foreach ($this->objects as $userEditor) { | |
651 | $userEditor->update(array( | |
652 | 'disableAvatar' => 1, | |
653 | 'disableAvatarReason' => $this->parameters['disableAvatarReason'] | |
654 | )); | |
655 | } | |
656 | } | |
657 | ||
658 | /** | |
659 | * Validates the 'enableAvatar' action. | |
660 | */ | |
661 | public function validateEnableAvatar() { | |
662 | WCF::getSession()->checkPermissions(array('admin.user.canDisableAvatar')); | |
663 | ||
664 | $this->__validateAccessibleGroups(); | |
665 | ||
666 | if (empty($this->objects)) { | |
667 | $this->readObjects(); | |
668 | ||
669 | if (empty($this->objects)) { | |
670 | throw new UserInputException('objectIDs'); | |
671 | } | |
672 | } | |
673 | } | |
674 | ||
675 | /** | |
676 | * Enables the avatar of the handled users. | |
677 | */ | |
678 | public function enableAvatar() { | |
679 | if (empty($this->objects)) { | |
680 | $this->readObjects(); | |
681 | } | |
682 | ||
683 | foreach ($this->objects as $userEditor) { | |
684 | $userEditor->update(array( | |
685 | 'disableAvatar' => 0 | |
686 | )); | |
687 | } | |
688 | } | |
11ade432 | 689 | } |