3 namespace wcf\acp\form
;
5 use wcf\data\contact\recipient\ContactRecipient
;
6 use wcf\data\contact\recipient\ContactRecipientAction
;
7 use wcf\data\contact\recipient\ContactRecipientEditor
;
8 use wcf\form\AbstractForm
;
9 use wcf\system\email\Mailbox
;
10 use wcf\system\exception\UserInputException
;
11 use wcf\system\language\I18nHandler
;
12 use wcf\system\request\LinkHandler
;
16 * Shows the form to create a new contact form recipient.
18 * @author Alexander Ebert
19 * @copyright 2001-2019 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22 class ContactRecipientAddForm
extends AbstractForm
27 public $activeMenuItem = 'wcf.acp.menu.link.contact.settings';
32 public $neededModules = ['MODULE_CONTACT_FORM'];
37 public $neededPermissions = ['admin.contact.canManageContactForm'];
52 * 1 if the recipient is disabled
55 public $isDisabled = 0;
58 * order used to the show the recipients
61 public $showOrder = 0;
66 public function readParameters()
68 parent
::readParameters();
70 I18nHandler
::getInstance()->register('email');
71 I18nHandler
::getInstance()->register('name');
77 public function readFormParameters()
79 parent
::readFormParameters();
81 I18nHandler
::getInstance()->readValues();
83 if (I18nHandler
::getInstance()->isPlainValue('email')) {
84 $this->email
= I18nHandler
::getInstance()->getValue('email');
86 if (I18nHandler
::getInstance()->isPlainValue('name')) {
87 $this->name
= I18nHandler
::getInstance()->getValue('name');
90 if (isset($_POST['isDisabled'])) {
91 $this->isDisabled
= \
intval($_POST['isDisabled']);
93 if (isset($_POST['showOrder'])) {
94 $this->showOrder
= \
intval($_POST['showOrder']);
101 public function validate()
105 if (!I18nHandler
::getInstance()->validateValue('email')) {
106 if (I18nHandler
::getInstance()->isPlainValue('email')) {
107 throw new UserInputException('email');
109 throw new UserInputException('email', 'multilingual');
112 foreach (I18nHandler
::getInstance()->getValues('email') as $email) {
115 } catch (\DomainException
$e) {
116 throw new UserInputException('email', 'invalid');
121 if (!I18nHandler
::getInstance()->validateValue('name')) {
122 if (I18nHandler
::getInstance()->isPlainValue('name')) {
123 throw new UserInputException('name');
125 throw new UserInputException('name', 'multilingual');
133 public function save()
137 $this->objectAction
= new ContactRecipientAction([], 'create', [
138 'data' => \array_merge
($this->additionalFields
, [
139 'name' => $this->name
,
140 'email' => $this->email
,
141 'isDisabled' => ($this->isDisabled ?
1 : 0),
142 'showOrder' => $this->showOrder
,
145 /** @var ContactRecipient $recipient */
146 $recipient = $this->objectAction
->executeAction()['returnValues'];
147 $recipientID = $recipient->recipientID
;
150 if (!I18nHandler
::getInstance()->isPlainValue('email')) {
151 I18nHandler
::getInstance()->save('email', 'wcf.contact.recipient.email' . $recipientID, 'wcf.contact', 1);
153 $data['email'] = 'wcf.contact.recipient.email' . $recipientID;
155 if (!I18nHandler
::getInstance()->isPlainValue('name')) {
156 I18nHandler
::getInstance()->save('name', 'wcf.contact.recipient.name' . $recipientID, 'wcf.contact', 1);
158 $data['name'] = 'wcf.contact.recipient.name' . $recipientID;
161 // update i18n values
163 (new ContactRecipientEditor($recipient))->update($data);
168 // show success message
169 WCF
::getTPL()->assign([
171 'objectEditLink' => LinkHandler
::getInstance()->getControllerLink(
172 ContactRecipientEditForm
::class,
173 ['id' => $recipientID]
178 $this->email
= $this->name
= 0;
179 $this->isDisabled
= $this->showOrder
= 0;
181 I18nHandler
::getInstance()->reset();
187 public function assignVariables()
189 parent
::assignVariables();
191 I18nHandler
::getInstance()->assignVariables();
193 WCF
::getTPL()->assign([
195 'email' => $this->email
,
196 'name' => $this->name
,
197 'isDisabled' => $this->isDisabled
,
198 'showOrder' => $this->showOrder
,