XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
EditUserAction.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_MODULE_PATH . '/user/class/AbstractEditAction.class.php';
13require_once XOOPS_MODULE_PATH . '/user/forms/EditUserForm.class.php';
14
15define('USER_COOKIE_KEEP_TIME', 31_536_000);
16
17/***
18 * @internal
19 */
21{
25 public $mUserCookie = '';
26
27 public $mSelfDelete = false;
28
29 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
30 {
31 parent::prepare($controller, $xoopsUser, $moduleConfig);
32 $this->mUserCookie = $moduleConfig['usercookie'];
33 }
34
35 public function _getId()
36 {
37 $root =& XCube_Root::getSingleton();
38 $uid = is_object($root->mContext->mXoopsUser) ? $root->mContext->mXoopsUser->get('uid') : 0;
39
40 return isset($_REQUEST['uid']) ? (int)xoops_getrequest('uid') : $uid;
41 }
42
43 public function &_getHandler()
44 {
45 $handler =& xoops_getmodulehandler('users', 'user');
46 return $handler;
47 }
48
55 public function _setupActionForm()
56 {
57 $this->mActionForm =new User_EditUserForm($this->mConfig);
58 $this->mActionForm->prepare();
59 }
60
68 protected function _getPagetitle()
69 {
70 return Legacy_Utils::getUserName($this->_getId());
71 }
72
73 public function isEnableCreate()
74 {
75 return false;
76 }
77
78 public function isSecure()
79 {
80 return true;
81 }
82
93 public function hasPermission(&$controller, &$xoopsUser, $moduleConfig)
94 {
95 if (!is_object($this->mObject)) {
96 return false;
97 }
98
99 if ($controller->mRoot->mContext->mUser->isInRole('Module.user.Admin')) {
100 return true;
101 }
102
103 return ($this->mObject->get('uid') == $xoopsUser->get('uid'));
104 }
105
106 public function _doExecute()
107 {
108 if ($this->mObjectHandler->insert($this->mObject)) {
109 if ($this->mActionForm->get('usercookie')) {
110 setcookie($this->mUserCookie, $this->mObject->getShow('uname'), ['expires' => time() + USER_COOKIE_KEEP_TIME]);
111 } else {
112 setcookie($this->mUserCookie);
113 }
114 $ret = false;
115 XCube_DelegateUtils::call('Legacy_Profile.SaveProfile', new XCube_Ref($ret), $this->mActionForm);
116 return $ret;
117 } else {
118 return false;
119 }
120 }
121
122 public function executeViewInput(&$controller, &$xoopsUser, &$render)
123 {
124 $render->setTemplateName('user_edituser.html');
125 $render->setAttribute('actionForm', $this->mActionForm);
126 $render->setAttribute('thisUser', $this->mObject);
127 $render->setAttribute('currentUser', $xoopsUser);
128 $render->setAttribute('allow_chgmail', $this->mConfig['allow_chgmail']);
129
130 $handler =& xoops_gethandler('timezone');
131 $timezoneArr =& $handler->getObjects();
132 $render->setAttribute('timezones', $timezoneArr);
133
134 //
135 // set flags.
136 //
137 $user_ownpage = (is_object($xoopsUser) && $xoopsUser->get('uid') == $this->mObject->get('uid'));
138 $render->setAttribute('user_ownpage', $user_ownpage);
139 //
140 // About 'SELF DELETE'
141 //
142 $render->setAttribute('self_delete', $this->mSelfDelete);
143 if ($user_ownpage && $this->mSelfDelete) {
144 $render->setAttribute('enableSelfDelete', true);
145 } else {
146 $render->setAttribute('enableSelfDelete', false);
147 }
148
149 //
150 // umode option
151 //
152 $umodeOptions = ['nest' => _NESTED, 'flat' => _FLAT, 'thread' => _THREADED];
153 $render->setAttribute('umodeOptions', $umodeOptions);
154
155 //
156 // uorder option
157 //
158 $uorderOptions = [0 => _OLDESTFIRST, 1 => _NEWESTFIRST];
159 $render->setAttribute('uorderOptions', $uorderOptions);
160
161 //
162 // notify option
163 //
164
165 //
166 // TODO Because abstract message catalog style is not decided, we load directly.
167 //
168 $root =& XCube_Root::getSingleton();
169 $root->mLanguageManager->loadPageTypeMessageCatalog('notification');
170 require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
171
172 // Check the PM service has been installed.
173 $root =& XCube_Root::getSingleton();
174 $service =& $root->mServiceManager->getService('privateMessage');
175
176 $methodOptions = [];
177 $methodOptions[XOOPS_NOTIFICATION_METHOD_DISABLE] = _NOT_METHOD_DISABLE;
178 if (null != $service) {
179 $methodOptions[XOOPS_NOTIFICATION_METHOD_PM] = _NOT_METHOD_PM;
180 }
181 $methodOptions[XOOPS_NOTIFICATION_METHOD_EMAIL] = _NOT_METHOD_EMAIL;
182
183 $render->setAttribute('notify_methodOptions', $methodOptions);
184
185 $modeOptions = [
186 XOOPS_NOTIFICATION_MODE_SENDALWAYS => _NOT_MODE_SENDALWAYS,
187 XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE => _NOT_MODE_SENDONCE,
188 XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT => _NOT_MODE_SENDONCEPERLOGIN
189 ];
190
191 $render->setAttribute('notify_modeOptions', $modeOptions);
192 $this->_setDatepicker();
193 }
194
195 protected function _setDatepicker()
196 {
197 $headerScript = XCube_Root::getSingleton()->mContext->getAttribute('headerScript');
198 $headerScript->addScript('$(".datepicker").each(function(){$(this).datepicker({dateFormat: "'._JSDATEPICKSTRING.'"});});');
199 }
200
201 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
202 {
203 $redirect = xoops_getrequest('xoops_redirect');
204 $controller->executeForward(($redirect && '/' === $redirect[0])? $redirect : (XOOPS_URL . '/userinfo.php?uid=' . $this->mObject->getShow('uid')));
205 }
206
207 public function executeViewError(&$controller, &$xoopsUser, &$render)
208 {
209 $controller->executeRedirect(XOOPS_URL . '/', 1, _MD_USER_ERROR_DBUPDATE_FAILED);
210 }
211}
static getUserName( $uid)
hasPermission(&$controller, &$xoopsUser, $moduleConfig)