Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / CaptchaQuestionEditForm.class.php
CommitLineData
96714cab
MS
1<?php
2namespace wcf\acp\form;
3use wcf\data\captcha\question\CaptchaQuestion;
4use wcf\data\captcha\question\CaptchaQuestionAction;
96714cab
MS
5use wcf\form\AbstractForm;
6use wcf\system\exception\IllegalLinkException;
7use wcf\system\language\I18nHandler;
8use wcf\system\WCF;
9
10/**
11 * Shows the form to edit an existing captcha question.
12 *
13 * @author Matthias Schmidt
c839bd49 14 * @copyright 2001-2018 WoltLab GmbH
96714cab 15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
e71525e4 16 * @package WoltLabSuite\Core\Acp\Form
96714cab
MS
17 */
18class CaptchaQuestionEditForm extends CaptchaQuestionAddForm {
19 /**
0fcfe5f6 20 * @inheritDoc
96714cab 21 */
dccf535f 22 public $activeMenuItem = 'wcf.acp.menu.link.other';
96714cab
MS
23
24 /**
25 * edited captcha question
4e25add7 26 * @var CaptchaQuestion
96714cab
MS
27 */
28 public $captchaQuestion = null;
29
30 /**
31 * id of the edited captcha question
32 * @var integer
33 */
34 public $captchaQuestionID = 0;
35
36 /**
0fcfe5f6 37 * @inheritDoc
96714cab
MS
38 */
39 public function assignVariables() {
40 parent::assignVariables();
41
42 I18nHandler::getInstance()->assignVariables(!empty($_POST));
43
058cbd6a 44 WCF::getTPL()->assign([
96714cab
MS
45 'action' => 'edit',
46 'captchaQuestion' => $this->captchaQuestion
058cbd6a 47 ]);
96714cab
MS
48 }
49
50 /**
0fcfe5f6 51 * @inheritDoc
96714cab
MS
52 */
53 public function readData() {
54 parent::readData();
55
56 if (empty($_POST)) {
57 I18nHandler::getInstance()->setOptions('question', 1, $this->captchaQuestion->question, 'wcf.captcha.question.question.question\d+');
58 I18nHandler::getInstance()->setOptions('answers', 1, $this->captchaQuestion->answers, 'wcf.captcha.question.question.answers\d+');
59
60 $this->isDisabled = $this->captchaQuestion->isDisabled;
61 }
62 }
63
64 /**
0fcfe5f6 65 * @inheritDoc
96714cab
MS
66 */
67 public function readParameters() {
68 parent::readParameters();
69
70 if (isset($_REQUEST['id'])) $this->captchaQuestionID = intval($_REQUEST['id']);
71 $this->captchaQuestion = new CaptchaQuestion($this->captchaQuestionID);
72 if (!$this->captchaQuestion->questionID) {
73 throw new IllegalLinkException();
74 }
75 }
76
77 /**
0fcfe5f6 78 * @inheritDoc
96714cab
MS
79 */
80 public function save() {
81 AbstractForm::save();
82
83 if (I18nHandler::getInstance()->isPlainValue('question')) {
84 if ($this->captchaQuestion->question == 'wcf.captcha.question.question.question'.$this->captchaQuestion->questionID) {
85 I18nHandler::getInstance()->remove($this->captchaQuestion->question);
86 }
87 }
88 else {
89 I18nHandler::getInstance()->save('question', 'wcf.captcha.question.question.question'.$this->captchaQuestion->questionID, 'wcf.captcha.question', 1);
90 }
91
92 if (I18nHandler::getInstance()->isPlainValue('answers')) {
93 if ($this->captchaQuestion->answers == 'wcf.captcha.question.question.answers'.$this->captchaQuestion->questionID) {
94 I18nHandler::getInstance()->remove($this->captchaQuestion->answers);
95 }
96 }
97 else {
98 I18nHandler::getInstance()->save('answers', 'wcf.captcha.question.question.answers'.$this->captchaQuestion->questionID, 'wcf.captcha.question', 1);
99 }
100
058cbd6a
MS
101 $this->objectAction = new CaptchaQuestionAction([$this->captchaQuestion], 'update', [
102 'data' => array_merge($this->additionalFields, [
96714cab
MS
103 'answers' => I18nHandler::getInstance()->isPlainValue('answers') ? I18nHandler::getInstance()->getValue('answers') : 'wcf.captcha.question.question.answers'.$this->captchaQuestion->questionID,
104 'isDisabled' => $this->isDisabled,
105 'question' => I18nHandler::getInstance()->isPlainValue('question') ? I18nHandler::getInstance()->getValue('question') : 'wcf.captcha.question.question.question'.$this->captchaQuestion->questionID
058cbd6a
MS
106 ])
107 ]);
96714cab
MS
108 $this->objectAction->executeAction();
109
110 $this->saved();
111
112 // show success message
113 WCF::getTPL()->assign('success', true);
114 }
115}