Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / clipboard / action / UserClipboardAction.class.php
1 <?php
2 namespace wcf\system\clipboard\action;
3 use wcf\data\clipboard\action\ClipboardAction;
4 use wcf\data\user\group\UserGroup;
5 use wcf\system\database\util\PreparedStatementConditionBuilder;
6 use wcf\system\request\LinkHandler;
7 use wcf\system\WCF;
8
9 /**
10 * Prepares clipboard editor items for user objects.
11 *
12 * @author Alexander Ebert
13 * @copyright 2001-2014 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.clipboard.action
17 * @category Community Framework
18 */
19 class UserClipboardAction extends AbstractClipboardAction {
20 /**
21 * @see \wcf\system\clipboard\action\AbstractClipboardAction::$actionClassActions
22 */
23 protected $actionClassActions = array('delete');
24
25 /**
26 * @see \wcf\system\clipboard\action\AbstractClipboardAction::$supportedActions
27 */
28 protected $supportedActions = array('assignToGroup', 'ban', 'delete', 'exportMailAddress', 'sendMail');
29
30 /**
31 * @see \wcf\system\clipboard\action\IClipboardAction::execute()
32 */
33 public function execute(array $objects, ClipboardAction $action) {
34 $item = parent::execute($objects, $action);
35
36 if ($item === null) {
37 return null;
38 }
39
40 // handle actions
41 switch ($action->actionName) {
42 case 'assignToGroup':
43 $item->setURL(LinkHandler::getInstance()->getLink('UserAssignToGroup'));
44 break;
45
46 case 'delete':
47 $item->addInternalData('confirmMessage', WCF::getLanguage()->getDynamicVariable('wcf.clipboard.item.com.woltlab.wcf.user.delete.confirmMessage', array(
48 'count' => $item->getCount()
49 )));
50 break;
51
52 case 'exportMailAddress':
53 $item->setURL(LinkHandler::getInstance()->getLink('UserEmailAddressExport'));
54 break;
55
56 case 'sendMail':
57 $item->setURL(LinkHandler::getInstance()->getLink('UserMail'));
58 break;
59 }
60
61 return $item;
62 }
63
64 /**
65 * @see \wcf\system\clipboard\action\IClipboardAction::getClassName()
66 */
67 public function getClassName() {
68 return 'wcf\data\user\UserAction';
69 }
70
71 /**
72 * @see \wcf\system\clipboard\action\IClipboardAction::getTypeName()
73 */
74 public function getTypeName() {
75 return 'com.woltlab.wcf.user';
76 }
77
78 /**
79 * Returns the ids of the users which can be deleted.
80 *
81 * @return array<integer>
82 */
83 protected function validateDelete() {
84 // check permissions
85 if (!WCF::getSession()->getPermission('admin.user.canDeleteUser')) {
86 return array();
87 }
88
89 return $this->__validateAccessibleGroups(array_keys($this->objects));
90 }
91
92 /**
93 * Returns the ids of the users which can be banned.
94 *
95 * @return array<integer>
96 */
97 protected function validateBan() {
98 // check permissions
99 if (!WCF::getSession()->getPermission('admin.user.canBanUser')) {
100 return array();
101 }
102
103 return $this->__validateAccessibleGroups(array_keys($this->objects));
104 }
105
106 /**
107 * Validates accessible groups.
108 *
109 * @return array<integer>
110 */
111 protected function __validateAccessibleGroups(array $userIDs, $ignoreOwnUser = true) {
112 if ($ignoreOwnUser) {
113 foreach ($userIDs as $index => $userID) {
114 if ($userID == WCF::getUser()->userID) {
115 unset($userIDs[$index]);
116 }
117 }
118 }
119
120 // no valid users found
121 if (empty($userIDs)) return array();
122
123 // fetch user to group associations
124 $conditions = new PreparedStatementConditionBuilder();
125 $conditions->add("userID IN (?)", array($userIDs));
126
127 $sql = "SELECT userID, groupID
128 FROM wcf".WCF_N."_user_to_group
129 ".$conditions;
130 $statement = WCF::getDB()->prepareStatement($sql);
131 $statement->execute($conditions->getParameters());
132
133 $userToGroup = array();
134 while ($row = $statement->fetchArray()) {
135 if (!isset($userToGroup[$row['userID']])) {
136 $userToGroup[$row['userID']] = array();
137 }
138
139 $userToGroup[$row['userID']][] = $row['groupID'];
140 }
141
142 // validate if user's group is accessible for current user
143 foreach ($userIDs as $userID) {
144 if (!isset($userToGroup[$userID]) || !UserGroup::isAccessibleGroup($userToGroup[$userID])) {
145 unset($userIDs[$userID]);
146 }
147 }
148
149 return $userIDs;
150 }
151 }