XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
UserSearchListAction.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_MODULE_PATH . '/user/class/AbstractListAction.class.php';
13require_once XOOPS_MODULE_PATH . '/user/admin/forms/UserSearchFilterForm.class.php';
14require_once XOOPS_MODULE_PATH . '/user/admin/forms/UserSearchListForm.class.php';
15
16// @todo @gigamaster !Fix WARNING:
17// Declaration of User_UserSearchListAction::prepare(&$controller, &$xoopsUser)
18// should be compatible with
19// User_Action::prepare(&$controller, &$xoopsUser, $moduleConfig)
21{
22 public $mUserObjects = [];
23 public $mActionForm = null;
24 public $mpageArr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 0];
25 public $mExtraURL = '';
26
27 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
28 {
29 $this->mActionForm =new User_UserSearchListForm();
30 $this->mActionForm->prepare();
31 }
32
33 public function &_getHandler()
34 {
35 $handler =& xoops_getmodulehandler('users_search');
36 return $handler;
37 }
38
39 public function &_getFilterForm()
40 {
41 $filter =new User_UserSearchFilterForm($this->_getPageNavi(), $this->_getHandler());
42 return $filter;
43 }
44
45 public function &_getPageNavi()
46 {
47 $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
48 if (isset($_REQUEST[$navi->mPrefix.'perpage']) && 0 == (int)$_REQUEST[$navi->mPrefix . 'perpage']) {
49 $navi->setPerpage(0);
50 }
51 return $navi;
52 }
53
54 public function _getBaseUrl()
55 {
56 return './index.php?action=UserSearchList';
57 }
58
59 public function execute(&$controller, &$xoopsUser)
60 {
61 //in case of result of user-search
62 if (!isset($_REQUEST['batchjob'])) {
63 return $this->getDefaultView($controller, $xoopsUser);
64 }
65
66 //To return user to proper-url with search condition
67 $this->mFilter =& $this->_getFilterForm();
68 $this->mFilter->fetch();
69 //
70 if (null != xoops_getrequest('_form_control_cancel')) {
71 return USER_FRAME_VIEW_CANCEL;
72 }
73
74 $this->mActionForm->fetch();
75 $this->mActionForm->validate();
76
77 if ($this->mActionForm->hasError()) {
78 return $this->_processConfirm($controller, $xoopsUser);
79 } else {
80 return $this->_processSave($controller, $xoopsUser);
81 }
82 }
83
84 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
85 {
86 $controller->mRoot->mDelegateManager->add('Legacy.Event.Explaceholder.Get.UserPagenaviOtherUrl', 'User_UserSearchListAction::renderOtherUrlControl');
87 $controller->mRoot->mDelegateManager->add('Legacy.Event.Explaceholder.Get.UserSearchPagenaviHidden', 'User_UserSearchListAction::renderHiddenControl');
88
89 $render->setTemplateName('user_search_list.html');
90 $render->setAttribute('objects', $this->mObjects);
91 $render->setAttribute('pageNavi', $this->mFilter->mNavi);
92 $render->setAttribute('actionForm', $this->mActionForm);
93 $render->setAttribute('filterForm', $this->mFilter);
94 $render->setAttribute('pageArr', $this->mpageArr);
95 }
96
97 public function _processConfirm(&$controller, &$xoopsUser)
98 {
99 $levelArr = $this->mActionForm->get('level');
100 $userHandler =& xoops_getmodulehandler('users');
101 //
102 // Do mapping.
103 //
104 foreach (array_keys($levelArr) as $uid) {
105 $user =& $userHandler->get($uid);
106 if (is_object($user)) {
107 $this->mUserObjects[$uid] =& $user;
108 }
109 unset($user);
110 }
111
112 return USER_FRAME_VIEW_INPUT;
113 }
114
115 public function _processSave(&$controller, &$xoopsUser)
116 {
117 $levelArr = $this->mActionForm->get('level');
118 $userHandler =& xoops_gethandler('user');
119
120 foreach (array_keys($levelArr) as $uid) {
121 if (1 != $uid) {
122 $user =& $userHandler->get($uid);
123 if (is_object($user)) {
124 $olddata['level'] = $user->get('level');
125 $olddata['posts'] = $user->get('posts');
126 $newdata['level'] = $this->mActionForm->get('level', $uid);
127 $newdata['posts'] = $this->mActionForm->get('posts', $uid);
128 if (count(array_diff_assoc($olddata, $newdata)) > 0) {
129 $user->set('level', $this->mActionForm->get('level', $uid));
130 $user->set('posts', $this->mActionForm->get('posts', $uid));
131 if (!$userHandler->insert($user)) {
132 return USER_FRAME_VIEW_ERROR;
133 }
134 }//count if
135 }//object if
136 }//if
137 }//foreach
138
139 foreach (array_keys($levelArr) as $uid) {
140 if ((1 == $this->mActionForm->get('delete', $uid)) && (1 != $uid)) {
141 $user =& $userHandler->get($uid);
142 if (is_object($user)) {
143 XCube_DelegateUtils::call('Legacy.Admin.Event.UserDelete', new XCube_Ref($user));
144 $memberhandler =& xoops_gethandler('member');
145 if ($memberhandler->delete($user)) {
146 XCube_DelegateUtils::call('Legacy.Admin.Event.UserDelete.Success', new XCube_Ref($user));
147 } else {
148 XCube_DelegateUtils::call('Legacy.Admin.Event.UserDelete.Fail', new XCube_Ref($user));
149 return USER_FRAME_VIEW_ERROR;
150 }
151 }//object
152 }//delete == 1
153 }//foreach
154
155 return USER_FRAME_VIEW_SUCCESS;
156 }
157
164 public function executeViewInput(&$controller, &$xoopsUser, &$render)
165 {
166 $render->setTemplateName('user_search_list_confirm.html');
167 $render->setAttribute('userObjects', $this->mUserObjects);
168 $render->setAttribute('actionForm', $this->mActionForm);
169
170 //
171 // To support a template writer, this send the list of mid that
172 // actionForm kept.
173 //
174 $t_arr = $this->mActionForm->get('level');
175 $render->setAttribute('uids', array_keys($t_arr));
176 //To return user to proper-url with search condition
177 $controller->mRoot->mDelegateManager->add('Legacy.Event.Explaceholder.Get.UserSearchPagenaviHidden', 'User_UserSearchListAction::renderHiddenControl');
178 $render->setAttribute('pageNavi', $this->mFilter->mNavi);
179 }
180
181// @todo @gigamaster Check change $render to $renderer
182 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
183 {
184 $controller->executeForward('./index.php?action=UserSearchList'.$this->getExtraURL());
185 }
186
187 public function executeViewError(&$controller, &$xoopsUser, &$renderer)
188 {
189 $controller->executeRedirect('./index.php?action=UserSearchList'.$this->getExtraURL(), 1, _MD_USER_ERROR_DBUPDATE_FAILED);
190 }
191
192 public function executeViewCancel(&$controller, &$xoopsUser, &$renderer)
193 {
194 $controller->executeForward('./index.php?action=UserSearchList'.$this->getExtraURL());
195 }
196
197
198 public function getExtraURL()
199 {
200 $extraurl = '';
201 if ((is_countable($this->mFilter->mNavi->mExtra) ? count($this->mFilter->mNavi->mExtra) : 0) > 0) {
202 $t_arr = [];
203 foreach ($this->mFilter->mNavi->mExtra as $key => $value) {
204 $t_arr[] = $key . '=' . urlencode($value);
205 }
206 $extraurl = '&' . implode('&', $t_arr);
207 }
208 return $extraurl;
209 }
210
211 public static function renderOtherUrlControl(&$buf, $params)
212 {
213 if (isset($params['pagenavi']) && is_object($params['pagenavi'])) {
214 $navi =& $params['pagenavi'];
215 $url = $params['url'];
216 if ((is_countable($navi->mExtra) ? count($navi->mExtra) : 0) > 0) {
217 $t_arr = [];
218
219 foreach ($navi->mExtra as $key => $value) {
220 $t_arr[] = $key . '=' . urlencode($value);
221 }
222
223 if (0 == count($t_arr)) {
224 $buf = $url;
225 return;
226 }
227
228 if (false !== strpos($url, '?')) {
229 $buf = $url . '&amp;' . implode('&amp;', $t_arr);
230 } else {
231 $buf = $url . '?' . implode('&amp;', $t_arr);
232 }
233 }
234 }
235 }
236
237 public static function renderHiddenControl(&$buf, $params)
238 {
239 if (isset($params['pagenavi']) && is_object($params['pagenavi'])) {
240 $navi =& $params['pagenavi'];
241 $mask = isset($params['mask']) ? explode('+', $params['mask']) : [];
242 foreach ($navi->mExtra as $key => $value) {
243 if (!in_array($key, $mask)) {
244 $value = htmlspecialchars($value, ENT_QUOTES);
245 $buf .= "<input type=\"hidden\" name=\"{$key}\" value=\"{$value}\" />";
246 }
247 }
248 }
249 }
250}
executeViewInput(&$controller, &$xoopsUser, &$render)