1 | <?php |
---|
2 | /** |
---|
3 | * @package Dotclear |
---|
4 | * @subpackage Backend |
---|
5 | * |
---|
6 | * @copyright Olivier Meunier & Association Dotclear |
---|
7 | * @copyright GPL-2.0-only |
---|
8 | */ |
---|
9 | |
---|
10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
---|
11 | |
---|
12 | dcPage::checkSuper(); |
---|
13 | |
---|
14 | $page_title = __('New user'); |
---|
15 | |
---|
16 | $user_id = ''; |
---|
17 | $user_super = ''; |
---|
18 | $user_pwd = ''; |
---|
19 | $user_change_pwd = ''; |
---|
20 | $user_name = ''; |
---|
21 | $user_firstname = ''; |
---|
22 | $user_displayname = ''; |
---|
23 | $user_email = ''; |
---|
24 | $user_url = ''; |
---|
25 | $user_lang = $core->auth->getInfo('user_lang'); |
---|
26 | $user_tz = $core->auth->getInfo('user_tz'); |
---|
27 | $user_post_status = ''; |
---|
28 | |
---|
29 | $user_options = $core->userDefaults(); |
---|
30 | |
---|
31 | # Formaters combo |
---|
32 | $formaters_combo = dcAdminCombos::getFormatersCombo(); |
---|
33 | |
---|
34 | $status_combo = dcAdminCombos::getPostStatusesCombo(); |
---|
35 | |
---|
36 | # Language codes |
---|
37 | $lang_combo = dcAdminCombos::getAdminLangsCombo(); |
---|
38 | |
---|
39 | # Get user if we have an ID |
---|
40 | if (!empty($_REQUEST['id'])) { |
---|
41 | try { |
---|
42 | $rs = $core->getUser($_REQUEST['id']); |
---|
43 | |
---|
44 | $user_id = $rs->user_id; |
---|
45 | $user_super = $rs->user_super; |
---|
46 | $user_pwd = $rs->user_pwd; |
---|
47 | $user_change_pwd = $rs->user_change_pwd; |
---|
48 | $user_name = $rs->user_name; |
---|
49 | $user_firstname = $rs->user_firstname; |
---|
50 | $user_displayname = $rs->user_displayname; |
---|
51 | $user_email = $rs->user_email; |
---|
52 | $user_url = $rs->user_url; |
---|
53 | $user_lang = $rs->user_lang; |
---|
54 | $user_tz = $rs->user_tz; |
---|
55 | $user_post_status = $rs->user_post_status; |
---|
56 | |
---|
57 | $user_options = array_merge($user_options, $rs->options()); |
---|
58 | |
---|
59 | $page_title = $user_id; |
---|
60 | } catch (Exception $e) { |
---|
61 | $core->error->add($e->getMessage()); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | # Add or update user |
---|
66 | if (isset($_POST['user_name'])) { |
---|
67 | try |
---|
68 | { |
---|
69 | if (empty($_POST['your_pwd']) || !$core->auth->checkPassword($_POST['your_pwd'])) { |
---|
70 | throw new Exception(__('Password verification failed')); |
---|
71 | } |
---|
72 | |
---|
73 | $cur = $core->con->openCursor($core->prefix . 'user'); |
---|
74 | |
---|
75 | $cur->user_id = $_POST['user_id']; |
---|
76 | $cur->user_super = $user_super = !empty($_POST['user_super']) ? 1 : 0; |
---|
77 | $cur->user_name = $user_name = html::escapeHTML($_POST['user_name']); |
---|
78 | $cur->user_firstname = $user_firstname = html::escapeHTML($_POST['user_firstname']); |
---|
79 | $cur->user_displayname = $user_displayname = html::escapeHTML($_POST['user_displayname']); |
---|
80 | $cur->user_email = $user_email = html::escapeHTML($_POST['user_email']); |
---|
81 | $cur->user_url = $user_url = html::escapeHTML($_POST['user_url']); |
---|
82 | $cur->user_lang = $user_lang = html::escapeHTML($_POST['user_lang']); |
---|
83 | $cur->user_tz = $user_tz = html::escapeHTML($_POST['user_tz']); |
---|
84 | $cur->user_post_status = $user_post_status = html::escapeHTML($_POST['user_post_status']); |
---|
85 | |
---|
86 | if ($user_id && $cur->user_id == $core->auth->userID() && $core->auth->isSuperAdmin()) { |
---|
87 | // force super_user to true if current user |
---|
88 | $cur->user_super = $user_super = true; |
---|
89 | } |
---|
90 | if ($core->auth->allowPassChange()) { |
---|
91 | $cur->user_change_pwd = !empty($_POST['user_change_pwd']) ? 1 : 0; |
---|
92 | } |
---|
93 | |
---|
94 | if (!empty($_POST['new_pwd'])) { |
---|
95 | if ($_POST['new_pwd'] != $_POST['new_pwd_c']) { |
---|
96 | throw new Exception(__("Passwords don't match")); |
---|
97 | } else { |
---|
98 | $cur->user_pwd = $_POST['new_pwd']; |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | $user_options['post_format'] = html::escapeHTML($_POST['user_post_format']); |
---|
103 | $user_options['edit_size'] = (integer) $_POST['user_edit_size']; |
---|
104 | |
---|
105 | if ($user_options['edit_size'] < 1) { |
---|
106 | $user_options['edit_size'] = 10; |
---|
107 | } |
---|
108 | |
---|
109 | $cur->user_options = new ArrayObject($user_options); |
---|
110 | |
---|
111 | # Udate user |
---|
112 | if ($user_id) { |
---|
113 | # --BEHAVIOR-- adminBeforeUserUpdate |
---|
114 | $core->callBehavior('adminBeforeUserUpdate', $cur, $user_id); |
---|
115 | |
---|
116 | $new_id = $core->updUser($user_id, $cur); |
---|
117 | |
---|
118 | # --BEHAVIOR-- adminAfterUserUpdate |
---|
119 | $core->callBehavior('adminAfterUserUpdate', $cur, $new_id); |
---|
120 | |
---|
121 | if ($user_id == $core->auth->userID() && |
---|
122 | $user_id != $new_id) { |
---|
123 | $core->session->destroy(); |
---|
124 | } |
---|
125 | |
---|
126 | dcPage::addSuccessNotice(__('User has been successfully updated.')); |
---|
127 | $core->adminurl->redirect("admin.user", ['id' => $new_id]); |
---|
128 | } |
---|
129 | # Add user |
---|
130 | else { |
---|
131 | if ($core->getUsers(['user_id' => $cur->user_id], true)->f(0) > 0) { |
---|
132 | throw new Exception(sprintf(__('User "%s" already exists.'), html::escapeHTML($cur->user_id))); |
---|
133 | } |
---|
134 | |
---|
135 | # --BEHAVIOR-- adminBeforeUserCreate |
---|
136 | $core->callBehavior('adminBeforeUserCreate', $cur); |
---|
137 | |
---|
138 | $new_id = $core->addUser($cur); |
---|
139 | |
---|
140 | # --BEHAVIOR-- adminAfterUserCreate |
---|
141 | $core->callBehavior('adminAfterUserCreate', $cur, $new_id); |
---|
142 | |
---|
143 | dcPage::addSuccessNotice(__('User has been successfully created.')); |
---|
144 | dcPage::addWarningNotice(__('User has no permission, he will not be able to login yet. See below to add some.')); |
---|
145 | if (!empty($_POST['saveplus'])) { |
---|
146 | $core->adminurl->redirect("admin.user"); |
---|
147 | } else { |
---|
148 | $core->adminurl->redirect("admin.user", ['id' => $new_id]); |
---|
149 | } |
---|
150 | } |
---|
151 | } catch (Exception $e) { |
---|
152 | $core->error->add($e->getMessage()); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | /* DISPLAY |
---|
157 | -------------------------------------------------------- */ |
---|
158 | dcPage::open($page_title, |
---|
159 | dcPage::jsConfirmClose('user-form') . |
---|
160 | dcPage::jsLoad('js/jquery/jquery.pwstrength.js') . |
---|
161 | dcPage::jsJson('user', [ |
---|
162 | sprintf(__('Password strength: %s'), __('very weak')), |
---|
163 | sprintf(__('Password strength: %s'), __('weak')), |
---|
164 | sprintf(__('Password strength: %s'), __('mediocre')), |
---|
165 | sprintf(__('Password strength: %s'), __('strong')), |
---|
166 | sprintf(__('Password strength: %s'), __('very strong')) |
---|
167 | ]) . |
---|
168 | dcPage::jsLoad('js/_user.js') . |
---|
169 | $core->callBehavior('adminUserHeaders'), |
---|
170 | |
---|
171 | dcPage::breadcrumb( |
---|
172 | [ |
---|
173 | __('System') => '', |
---|
174 | __('Users') => $core->adminurl->get("admin.users"), |
---|
175 | $page_title => '' |
---|
176 | ]) |
---|
177 | ); |
---|
178 | |
---|
179 | if (!empty($_GET['upd'])) { |
---|
180 | dcPage::success(__('User has been successfully updated.')); |
---|
181 | } |
---|
182 | |
---|
183 | if (!empty($_GET['add'])) { |
---|
184 | dcPage::success(__('User has been successfully created.')); |
---|
185 | } |
---|
186 | |
---|
187 | echo |
---|
188 | '<form action="' . $core->adminurl->get("admin.user") . '" method="post" id="user-form">' . |
---|
189 | '<div class="two-cols">' . |
---|
190 | |
---|
191 | '<div class="col">' . |
---|
192 | '<h3>' . __('User profile') . '</h3>' . |
---|
193 | |
---|
194 | '<p><label for="user_id" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('User ID:') . '</label> ' . |
---|
195 | form::field('user_id', 20, 255, [ |
---|
196 | 'default' => html::escapeHTML($user_id), |
---|
197 | 'extra_html' => 'required placeholder="' . __('Login') . '"', |
---|
198 | 'autocomplete' => 'username' |
---|
199 | ]) . |
---|
200 | '</p>' . |
---|
201 | '<p class="form-note info">' . __('At least 2 characters using letters, numbers or symbols.') . '</p>'; |
---|
202 | |
---|
203 | if ($user_id == $core->auth->userID()) { |
---|
204 | echo |
---|
205 | '<p class="warning">' . __('Warning:') . ' ' . |
---|
206 | __('If you change your username, you will have to log in again.') . '</p>'; |
---|
207 | } |
---|
208 | |
---|
209 | echo |
---|
210 | '<div class="pw-table">' . |
---|
211 | '<p class="pw-cell">' . |
---|
212 | '<label for="new_pwd" ' . ($user_id != '' ? '' : 'class="required"') . '>' . |
---|
213 | ($user_id != '' ? '' : '<abbr title="' . __('Required field') . '">*</abbr> ') . |
---|
214 | ($user_id != '' ? __('New password:') : __('Password:')) . '</label>' . |
---|
215 | form::password('new_pwd', 20, 255, |
---|
216 | [ |
---|
217 | 'extra_html' => 'data-indicator="pwindicator"' . |
---|
218 | ($user_id != '' ? '' : ' required placeholder="' . __('Password') . '"'), |
---|
219 | 'autocomplete' => 'new-password'] |
---|
220 | ) . |
---|
221 | '</p>' . |
---|
222 | '<div id="pwindicator">' . |
---|
223 | ' <div class="bar"></div>' . |
---|
224 | ' <p class="label no-margin"></p>' . |
---|
225 | '</div>' . |
---|
226 | '</div>' . |
---|
227 | '<p class="form-note info">' . __('Password must contain at least 6 characters.') . '</p>' . |
---|
228 | |
---|
229 | '<p><label for="new_pwd_c" ' . ($user_id != '' ? '' : 'class="required"') . '>' . |
---|
230 | ($user_id != '' ? '' : '<abbr title="' . __('Required field') . '">*</abbr> ') . __('Confirm password:') . '</label> ' . |
---|
231 | form::password('new_pwd_c', 20, 255, |
---|
232 | [ |
---|
233 | 'extra_html' => ($user_id != '' ? '' : 'required placeholder="' . __('Password') . '"'), |
---|
234 | 'autocomplete' => 'new-password']) . |
---|
235 | '</p>'; |
---|
236 | |
---|
237 | if ($core->auth->allowPassChange()) { |
---|
238 | echo |
---|
239 | '<p><label for="user_change_pwd" class="classic">' . |
---|
240 | form::checkbox('user_change_pwd', '1', $user_change_pwd) . ' ' . |
---|
241 | __('Password change required to connect') . '</label></p>'; |
---|
242 | } |
---|
243 | |
---|
244 | $super_disabled = $user_super && $user_id == $core->auth->userID(); |
---|
245 | |
---|
246 | echo |
---|
247 | '<p><label for="user_super" class="classic">' . |
---|
248 | form::checkbox(($super_disabled ? 'user_super_off' : 'user_super'), '1', |
---|
249 | [ |
---|
250 | 'checked' => $user_super, |
---|
251 | 'disabled' => $super_disabled |
---|
252 | ]) . |
---|
253 | ' ' . __('Super administrator') . '</label></p>' . |
---|
254 | ($super_disabled ? form::hidden(['user_super'], $user_super) : '') . |
---|
255 | |
---|
256 | '<p><label for="user_name">' . __('Last Name:') . '</label> ' . |
---|
257 | form::field('user_name', 20, 255, [ |
---|
258 | 'default' => html::escapeHTML($user_name), |
---|
259 | 'autocomplete' => 'family-name' |
---|
260 | ]) . |
---|
261 | '</p>' . |
---|
262 | |
---|
263 | '<p><label for="user_firstname">' . __('First Name:') . '</label> ' . |
---|
264 | form::field('user_firstname', 20, 255, [ |
---|
265 | 'default' => html::escapeHTML($user_firstname), |
---|
266 | 'autocomplete' => 'given-name' |
---|
267 | ]) . |
---|
268 | '</p>' . |
---|
269 | |
---|
270 | '<p><label for="user_displayname">' . __('Display name:') . '</label> ' . |
---|
271 | form::field('user_displayname', 20, 255, [ |
---|
272 | 'default' => html::escapeHTML($user_displayname), |
---|
273 | 'autocomplete' => 'nickname' |
---|
274 | ]) . |
---|
275 | '</p>' . |
---|
276 | |
---|
277 | '<p><label for="user_email">' . __('Email:') . '</label> ' . |
---|
278 | form::email('user_email', [ |
---|
279 | 'default' => html::escapeHTML($user_email), |
---|
280 | 'autocomplete' => 'email' |
---|
281 | ]) . |
---|
282 | '</p>' . |
---|
283 | '<p class="form-note">' . __('Mandatory for password recovering procedure.') . '</p>' . |
---|
284 | |
---|
285 | '<p><label for="user_url">' . __('URL:') . '</label> ' . |
---|
286 | form::url('user_url', [ |
---|
287 | 'size' => 30, |
---|
288 | 'default' => html::escapeHTML($user_url), |
---|
289 | 'autocomplete' => 'url' |
---|
290 | ]) . |
---|
291 | '</p>' . |
---|
292 | '</div>' . |
---|
293 | |
---|
294 | '<div class="col">' . |
---|
295 | '<h3>' . __('Options') . '</h3>' . |
---|
296 | '<h4>' . __('Interface') . '</h4>' . |
---|
297 | '<p><label for="user_lang">' . __('Language:') . '</label> ' . |
---|
298 | form::combo('user_lang', $lang_combo, $user_lang, 'l10n') . |
---|
299 | '</p>' . |
---|
300 | |
---|
301 | '<p><label for="user_tz">' . __('Timezone:') . '</label> ' . |
---|
302 | form::combo('user_tz', dt::getZones(true, true), $user_tz) . |
---|
303 | '</p>' . |
---|
304 | |
---|
305 | '<h4>' . __('Edition') . '</h4>' . |
---|
306 | '<p><label for="user_post_format">' . __('Preferred format:') . '</label> ' . |
---|
307 | form::combo('user_post_format', $formaters_combo, $user_options['post_format']) . |
---|
308 | '</p>' . |
---|
309 | |
---|
310 | '<p><label for="user_post_status">' . __('Default entry status:') . '</label> ' . |
---|
311 | form::combo('user_post_status', $status_combo, $user_post_status) . |
---|
312 | '</p>' . |
---|
313 | |
---|
314 | '<p><label for="user_edit_size">' . __('Entry edit field height:') . '</label> ' . |
---|
315 | form::number('user_edit_size', 10, 999, (integer) $user_options['edit_size']) . |
---|
316 | '</p>'; |
---|
317 | |
---|
318 | # --BEHAVIOR-- adminUserForm |
---|
319 | $core->callBehavior('adminUserForm', isset($rs) ? $rs : null); |
---|
320 | |
---|
321 | echo |
---|
322 | '</div>' . |
---|
323 | '</div>'; |
---|
324 | |
---|
325 | echo |
---|
326 | '<p class="clear vertical-separator"><label for="your_pwd" class="required">' . |
---|
327 | '<abbr title="' . __('Required field') . '">*</abbr> ' . __('Your password:') . '</label>' . |
---|
328 | form::password('your_pwd', 20, 255, |
---|
329 | [ |
---|
330 | 'extra_html' => 'required placeholder="' . __('Password') . '"', |
---|
331 | 'autocomplete' => 'current-password' |
---|
332 | ] |
---|
333 | ) . '</p>' . |
---|
334 | '<p class="clear"><input type="submit" name="save" accesskey="s" value="' . __('Save') . '" />' . |
---|
335 | ($user_id != '' ? '' : ' <input type="submit" name="saveplus" value="' . __('Save and create another') . '" />') . |
---|
336 | ($user_id != '' ? form::hidden('id', $user_id) : '') . |
---|
337 | $core->formNonce() . |
---|
338 | '</p>' . |
---|
339 | |
---|
340 | '</form>'; |
---|
341 | |
---|
342 | if ($user_id) { |
---|
343 | echo '<div class="clear fieldset">' . |
---|
344 | '<h3>' . __('Permissions') . '</h3>'; |
---|
345 | |
---|
346 | if (!$user_super) { |
---|
347 | echo |
---|
348 | '<form action="' . $core->adminurl->get("admin.user.actions") . '" method="post">' . |
---|
349 | '<p><input type="submit" value="' . __('Add new permissions') . '" />' . |
---|
350 | form::hidden(['redir'], $core->adminurl->get("admin.user", ['id' => $user_id])) . |
---|
351 | form::hidden(['action'], 'blogs') . |
---|
352 | form::hidden(['users[]'], $user_id) . |
---|
353 | $core->formNonce() . |
---|
354 | '</p>' . |
---|
355 | '</form>'; |
---|
356 | |
---|
357 | $permissions = $core->getUserPermissions($user_id); |
---|
358 | $perm_types = $core->auth->getPermissionsTypes(); |
---|
359 | |
---|
360 | if (count($permissions) == 0) { |
---|
361 | echo '<p>' . __('No permissions so far.') . '</p>'; |
---|
362 | } else { |
---|
363 | foreach ($permissions as $k => $v) { |
---|
364 | if (count($v['p']) > 0) { |
---|
365 | echo |
---|
366 | '<form action="' . $core->adminurl->get("admin.user.actions") . '" method="post" class="perm-block">' . |
---|
367 | '<p class="blog-perm">' . __('Blog:') . ' <a href="' . |
---|
368 | $core->adminurl->get("admin.blog", ['id' => html::escapeHTML($k)]) . '">' . |
---|
369 | html::escapeHTML($v['name']) . '</a> (' . html::escapeHTML($k) . ')</p>'; |
---|
370 | |
---|
371 | echo '<ul class="ul-perm">'; |
---|
372 | foreach ($v['p'] as $p => $V) { |
---|
373 | if (isset($perm_types[$p])) { |
---|
374 | echo '<li>' . __($perm_types[$p]) . '</li>'; |
---|
375 | } |
---|
376 | } |
---|
377 | echo |
---|
378 | '</ul>' . |
---|
379 | '<p class="add-perm"><input type="submit" class="reset" value="' . __('Change permissions') . '" />' . |
---|
380 | form::hidden(['redir'], $core->adminurl->get("admin.user", ['id' => $user_id])) . |
---|
381 | form::hidden(['action'], 'perms') . |
---|
382 | form::hidden(['users[]'], $user_id) . |
---|
383 | form::hidden(['blogs[]'], $k) . |
---|
384 | $core->formNonce() . |
---|
385 | '</p>' . |
---|
386 | '</form>'; |
---|
387 | } |
---|
388 | } |
---|
389 | } |
---|
390 | |
---|
391 | } else { |
---|
392 | echo '<p>' . sprintf(__('%s is super admin (all rights on all blogs).'), '<strong>' . $user_id . '</strong>') . '</p>'; |
---|
393 | } |
---|
394 | echo '</div>'; |
---|
395 | } |
---|
396 | |
---|
397 | dcPage::helpBlock('core_user'); |
---|
398 | dcPage::close(); |
---|