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