Commit | Line | Data |
---|---|---|
158bd3ca TD |
1 | <?php |
2 | namespace wcf\acp\form; | |
158bd3ca TD |
3 | use wcf\data\user\group\UserGroup; |
4 | use wcf\data\user\group\UserGroupAction; | |
5 | use wcf\data\user\group\UserGroupEditor; | |
6 | use wcf\form\AbstractForm; | |
7 | use wcf\system\exception\IllegalLinkException; | |
8 | use wcf\system\exception\PermissionDeniedException; | |
2b4d2743 | 9 | use wcf\system\language\I18nHandler; |
158bd3ca TD |
10 | use wcf\system\WCF; |
11 | ||
12 | /** | |
13 | * Shows the group edit form. | |
6e048dca | 14 | * |
158bd3ca | 15 | * @author Marcel Werk |
c839bd49 | 16 | * @copyright 2001-2018 WoltLab GmbH |
158bd3ca | 17 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
e71525e4 | 18 | * @package WoltLabSuite\Core\Acp\Form |
158bd3ca TD |
19 | */ |
20 | class UserGroupEditForm extends UserGroupAddForm { | |
21 | /** | |
734662c9 | 22 | * @inheritDoc |
158bd3ca | 23 | */ |
906091f5 | 24 | public $activeMenuItem = 'wcf.acp.menu.link.group'; |
158bd3ca TD |
25 | |
26 | /** | |
734662c9 | 27 | * @inheritDoc |
158bd3ca | 28 | */ |
734662c9 | 29 | public $neededPermissions = ['admin.user.canEditGroup']; |
158bd3ca TD |
30 | |
31 | /** | |
9f959ced MS |
32 | * id of the edited user group |
33 | * @var integer | |
158bd3ca TD |
34 | */ |
35 | public $groupID = 0; | |
36 | ||
37 | /** | |
9f959ced | 38 | * user group editor object |
734662c9 | 39 | * @var UserGroupEditor |
158bd3ca | 40 | */ |
eec1d83c | 41 | public $group; |
158bd3ca TD |
42 | |
43 | /** | |
734662c9 | 44 | * @inheritDoc |
158bd3ca TD |
45 | */ |
46 | public function readParameters() { | |
47 | parent::readParameters(); | |
48 | ||
49 | // get group | |
08d76680 | 50 | if (isset($_REQUEST['id'])) $this->groupID = intval($_REQUEST['id']); |
158bd3ca TD |
51 | $group = new UserGroup($this->groupID); |
52 | if (!$group->groupID) { | |
53 | throw new IllegalLinkException(); | |
54 | } | |
55 | if (!$group->isAccessible()) { | |
56 | throw new PermissionDeniedException(); | |
57 | } | |
58 | ||
59 | $this->group = new UserGroupEditor($group); | |
ae6b590f | 60 | |
e4499881 | 61 | /** @noinspection PhpUndefinedMethodInspection */ |
60c22b37 | 62 | $this->optionHandler->setUserGroup($group); |
e4499881 | 63 | /** @noinspection PhpUndefinedMethodInspection */ |
ae6b590f MS |
64 | $this->optionHandler->init(); |
65 | } | |
66 | ||
67 | /** | |
734662c9 | 68 | * @inheritDoc |
ae6b590f MS |
69 | */ |
70 | protected function initOptionHandler() { | |
71 | // does nothing, we call OptionHandler::init() after we set the | |
72 | // user group | |
158bd3ca TD |
73 | } |
74 | ||
75 | /** | |
734662c9 | 76 | * @inheritDoc |
158bd3ca TD |
77 | */ |
78 | public function readData() { | |
15fa2802 | 79 | if (empty($_POST)) { |
3b13a539 | 80 | I18nHandler::getInstance()->setOptions('groupName', 1, $this->group->groupName, 'wcf.acp.group.group\d+'); |
005f6926 | 81 | I18nHandler::getInstance()->setOptions('groupDescription', 1, $this->group->groupDescription, 'wcf.acp.group.groupDescription\d+'); |
158bd3ca | 82 | $this->groupName = $this->group->groupName; |
005f6926 | 83 | $this->groupDescription = $this->group->groupDescription; |
320f4a6d MW |
84 | $this->priority = $this->group->priority; |
85 | $this->userOnlineMarking = $this->group->userOnlineMarking; | |
86 | $this->showOnTeamPage = $this->group->showOnTeamPage; | |
158bd3ca TD |
87 | } |
88 | ||
89 | parent::readData(); | |
90 | } | |
91 | ||
92 | /** | |
734662c9 | 93 | * @inheritDoc |
158bd3ca TD |
94 | */ |
95 | public function assignVariables() { | |
96 | parent::assignVariables(); | |
97 | ||
15fa2802 | 98 | I18nHandler::getInstance()->assignVariables(!empty($_POST)); |
2b4d2743 | 99 | |
734662c9 | 100 | WCF::getTPL()->assign([ |
158bd3ca | 101 | 'groupID' => $this->group->groupID, |
edadd7c1 | 102 | 'group' => $this->group, |
848f7022 | 103 | 'action' => 'edit', |
eec1d83c | 104 | 'availableUserGroups' => UserGroup::getAccessibleGroups(), |
3d9f265d AE |
105 | 'groupIsEveryone' => $this->group->groupType == UserGroup::EVERYONE, |
106 | 'groupIsGuest' => $this->group->groupType == UserGroup::GUESTS, | |
107 | 'groupIsUsers' => $this->group->groupType == UserGroup::USERS | |
734662c9 | 108 | ]); |
158bd3ca TD |
109 | |
110 | // add warning when the initiator is in the group | |
79a8c2e8 | 111 | if ($this->group->isMember()) { |
158bd3ca TD |
112 | WCF::getTPL()->assign('warningSelfEdit', true); |
113 | } | |
114 | } | |
115 | ||
116 | /** | |
734662c9 | 117 | * @inheritDoc |
158bd3ca TD |
118 | */ |
119 | public function save() { | |
120 | AbstractForm::save(); | |
121 | ||
122 | // save group | |
efc3c01a | 123 | $optionValues = $this->optionHandler->save(); |
2b4d2743 AE |
124 | $this->groupName = 'wcf.acp.group.group'.$this->group->groupID; |
125 | if (I18nHandler::getInstance()->isPlainValue('groupName')) { | |
e118b677 | 126 | I18nHandler::getInstance()->remove($this->groupName); |
2b4d2743 | 127 | $this->groupName = I18nHandler::getInstance()->getValue('groupName'); |
62ef44d1 MS |
128 | |
129 | UserGroup::getGroupByID($this->groupID)->setName($this->groupName); | |
2b4d2743 AE |
130 | } |
131 | else { | |
132 | I18nHandler::getInstance()->save('groupName', $this->groupName, 'wcf.acp.group', 1); | |
62ef44d1 MS |
133 | |
134 | $groupNames = I18nHandler::getInstance()->getValues('groupName'); | |
135 | UserGroup::getGroupByID($this->groupID)->setName($groupNames[WCF::getLanguage()->languageID]); | |
2b4d2743 | 136 | } |
005f6926 MW |
137 | $this->groupDescription = 'wcf.acp.group.groupDescription'.$this->group->groupID; |
138 | if (I18nHandler::getInstance()->isPlainValue('groupDescription')) { | |
139 | I18nHandler::getInstance()->remove($this->groupDescription); | |
140 | $this->groupDescription = I18nHandler::getInstance()->getValue('groupDescription'); | |
141 | } | |
142 | else { | |
143 | I18nHandler::getInstance()->save('groupDescription', $this->groupDescription, 'wcf.acp.group', 1); | |
144 | } | |
2b4d2743 | 145 | |
734662c9 MS |
146 | $this->objectAction = new UserGroupAction([$this->groupID], 'update', [ |
147 | 'data' => array_merge($this->additionalFields, [ | |
320f4a6d | 148 | 'groupName' => $this->groupName, |
005f6926 | 149 | 'groupDescription' => $this->groupDescription, |
320f4a6d MW |
150 | 'priority' => $this->priority, |
151 | 'userOnlineMarking' => $this->userOnlineMarking, | |
152 | 'showOnTeamPage' => $this->showOnTeamPage | |
734662c9 | 153 | ]), |
53506605 | 154 | 'options' => $optionValues |
734662c9 | 155 | ]); |
635dd8c4 | 156 | $this->objectAction->executeAction(); |
158bd3ca TD |
157 | $this->saved(); |
158 | ||
dd30d576 AE |
159 | // reset user group cache |
160 | UserGroupEditor::resetCache(); | |
161 | ||
158bd3ca TD |
162 | // show success message |
163 | WCF::getTPL()->assign('success', true); | |
164 | } | |
165 | } |