Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / UserRankEditForm.class.php
1 <?php
2 namespace wcf\acp\form;
3 use wcf\data\user\rank\UserRank;
4 use wcf\data\user\rank\UserRankAction;
5 use wcf\form\AbstractForm;
6 use wcf\system\exception\IllegalLinkException;
7 use wcf\system\language\I18nHandler;
8 use wcf\system\WCF;
9
10 /**
11 * Shows the user rank edit form.
12 *
13 * @author Marcel Werk
14 * @copyright 2001-2014 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf
17 * @subpackage acp.form
18 * @category Community Framework
19 */
20 class UserRankEditForm extends UserRankAddForm {
21 /**
22 * @see \wcf\page\AbstractPage::$activeMenuItem
23 */
24 public $activeMenuItem = 'wcf.acp.menu.link.user.rank.list';
25
26 /**
27 * rank id
28 * @var integer
29 */
30 public $rankID = 0;
31
32 /**
33 * rank object
34 * @var \wcf\data\user\rank\UserRank
35 */
36 public $rank = null;
37
38 /**
39 * @see \wcf\page\IPage::readParameters()
40 */
41 public function readParameters() {
42 parent::readParameters();
43
44 if (isset($_REQUEST['id'])) $this->rankID = intval($_REQUEST['id']);
45 $this->rank = new UserRank($this->rankID);
46 if (!$this->rank->rankID) {
47 throw new IllegalLinkException();
48 }
49 }
50
51 /**
52 * @see \wcf\form\IForm::save()
53 */
54 public function save() {
55 AbstractForm::save();
56
57 $this->rankTitle = 'wcf.user.rank.userRank'.$this->rank->rankID;
58 if (I18nHandler::getInstance()->isPlainValue('rankTitle')) {
59 I18nHandler::getInstance()->remove($this->rankTitle);
60 $this->rankTitle = I18nHandler::getInstance()->getValue('rankTitle');
61 }
62 else {
63 I18nHandler::getInstance()->save('rankTitle', $this->rankTitle, 'wcf.user', 1);
64 }
65
66 // update label
67 $this->objectAction = new UserRankAction(array($this->rank), 'update', array('data' => array_merge($this->additionalFields, array(
68 'rankTitle' => $this->rankTitle,
69 'cssClassName' => ($this->cssClassName == 'custom' ? $this->customCssClassName : $this->cssClassName),
70 'groupID' => $this->groupID,
71 'requiredPoints' => $this->requiredPoints,
72 'rankImage' => $this->rankImage,
73 'repeatImage' => $this->repeatImage,
74 'requiredGender' => $this->requiredGender
75 ))));
76 $this->objectAction->executeAction();
77 $this->saved();
78
79 // reset values if non-custom value was choosen
80 if ($this->cssClassName != 'custom') $this->customCssClassName = '';
81
82 // show success
83 WCF::getTPL()->assign(array(
84 'success' => true
85 ));
86 }
87
88 /**
89 * @see \wcf\page\IPage::readData()
90 */
91 public function readData() {
92 parent::readData();
93
94 if (empty($_POST)) {
95 I18nHandler::getInstance()->setOptions('rankTitle', 1, $this->rank->rankTitle, 'wcf.user.rank.userRank\d+');
96 $this->rankTitle = $this->rank->rankTitle;
97 $this->cssClassName = $this->rank->cssClassName;
98 if (!in_array($this->cssClassName, $this->availableCssClassNames)) {
99 $this->customCssClassName = $this->cssClassName;
100 $this->cssClassName = 'custom';
101 }
102 $this->groupID = $this->rank->groupID;
103 $this->requiredPoints = $this->rank->requiredPoints;
104 $this->requiredGender = $this->rank->requiredGender;
105 $this->repeatImage = $this->rank->repeatImage;
106 $this->rankImage = $this->rank->rankImage;
107 }
108 }
109
110 /**
111 * @see \wcf\page\IPage::assignVariables()
112 */
113 public function assignVariables() {
114 parent::assignVariables();
115
116 I18nHandler::getInstance()->assignVariables(!empty($_POST));
117
118 WCF::getTPL()->assign(array(
119 'rankID' => $this->rankID,
120 'rank' => $this->rank,
121 'action' => 'edit'
122 ));
123 }
124 }