| [860] | 1 | <?php | 
|---|
| [3731] | 2 | /** | 
|---|
|  | 3 | * @package Dotclear | 
|---|
|  | 4 | * @subpackage Backend | 
|---|
|  | 5 | * | 
|---|
|  | 6 | * @copyright Olivier Meunier & Association Dotclear | 
|---|
|  | 7 | * @copyright GPL-2.0-only | 
|---|
|  | 8 | */ | 
|---|
| [860] | 9 |  | 
|---|
| [3699] | 10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; | 
|---|
| [860] | 11 |  | 
|---|
|  | 12 | dcPage::checkSuper(); | 
|---|
|  | 13 |  | 
|---|
| [3874] | 14 | $users = []; | 
|---|
| [3699] | 15 | if (!empty($_POST['users']) && is_array($_POST['users'])) { | 
|---|
|  | 16 | foreach ($_POST['users'] as $u) { | 
|---|
|  | 17 | if ($core->userExists($u)) { | 
|---|
|  | 18 | $users[] = $u; | 
|---|
|  | 19 | } | 
|---|
|  | 20 | } | 
|---|
| [860] | 21 | } | 
|---|
|  | 22 |  | 
|---|
| [3874] | 23 | $blogs = []; | 
|---|
| [3699] | 24 | if (!empty($_POST['blogs']) && is_array($_POST['blogs'])) { | 
|---|
|  | 25 | foreach ($_POST['blogs'] as $b) { | 
|---|
|  | 26 | if ($core->blogExists($b)) { | 
|---|
|  | 27 | $blogs[] = $b; | 
|---|
|  | 28 | } | 
|---|
|  | 29 | } | 
|---|
| [860] | 30 | } | 
|---|
|  | 31 |  | 
|---|
|  | 32 | /* Actions | 
|---|
|  | 33 | -------------------------------------------------------- */ | 
|---|
| [3699] | 34 | if (!empty($_POST['action']) && !empty($_POST['users'])) { | 
|---|
|  | 35 | $action = $_POST['action']; | 
|---|
| [2566] | 36 |  | 
|---|
| [3699] | 37 | if (isset($_POST['redir']) && strpos($_POST['redir'], '://') === false) { | 
|---|
|  | 38 | $redir = $_POST['redir']; | 
|---|
|  | 39 | } else { | 
|---|
| [3874] | 40 | $redir = $core->adminurl->get("admin.users", [ | 
|---|
| [3699] | 41 | 'q'      => $_POST['q'], | 
|---|
|  | 42 | 'sortby' => $_POST['sortby'], | 
|---|
|  | 43 | 'order'  => $_POST['order'], | 
|---|
|  | 44 | 'page'   => $_POST['page'], | 
|---|
|  | 45 | 'nb'     => $_POST['nb'] | 
|---|
| [3874] | 46 | ]); | 
|---|
| [3699] | 47 | } | 
|---|
| [2566] | 48 |  | 
|---|
| [3699] | 49 | if (empty($users)) { | 
|---|
|  | 50 | $core->error->add(__('No blog or user given.')); | 
|---|
|  | 51 | } | 
|---|
| [2566] | 52 |  | 
|---|
| [3699] | 53 | # --BEHAVIOR-- adminUsersActions | 
|---|
|  | 54 | $core->callBehavior('adminUsersActions', $core, $users, $blogs, $action, $redir); | 
|---|
| [2566] | 55 |  | 
|---|
| [3699] | 56 | # Delete users | 
|---|
|  | 57 | if ($action == 'deleteuser' && !empty($users)) { | 
|---|
|  | 58 | foreach ($users as $u) { | 
|---|
|  | 59 | try | 
|---|
|  | 60 | { | 
|---|
|  | 61 | if ($u == $core->auth->userID()) { | 
|---|
|  | 62 | throw new Exception(__('You cannot delete yourself.')); | 
|---|
|  | 63 | } | 
|---|
| [2566] | 64 |  | 
|---|
| [3699] | 65 | # --BEHAVIOR-- adminBeforeUserDelete | 
|---|
|  | 66 | $core->callBehavior('adminBeforeUserDelete', $u); | 
|---|
| [2566] | 67 |  | 
|---|
| [3699] | 68 | $core->delUser($u); | 
|---|
|  | 69 | } catch (Exception $e) { | 
|---|
|  | 70 | $core->error->add($e->getMessage()); | 
|---|
|  | 71 | } | 
|---|
|  | 72 | } | 
|---|
|  | 73 | if (!$core->error->flag()) { | 
|---|
|  | 74 | dcPage::addSuccessNotice(__('User has been successfully deleted.')); | 
|---|
|  | 75 | http::redirect($redir); | 
|---|
|  | 76 | } | 
|---|
|  | 77 | } | 
|---|
| [2566] | 78 |  | 
|---|
| [3699] | 79 | # Update users perms | 
|---|
|  | 80 | if ($action == 'updateperm' && !empty($users) && !empty($blogs)) { | 
|---|
|  | 81 | try | 
|---|
|  | 82 | { | 
|---|
|  | 83 | if (empty($_POST['your_pwd']) || !$core->auth->checkPassword($_POST['your_pwd'])) { | 
|---|
|  | 84 | throw new Exception(__('Password verification failed')); | 
|---|
|  | 85 | } | 
|---|
| [2566] | 86 |  | 
|---|
| [3699] | 87 | foreach ($users as $u) { | 
|---|
|  | 88 | foreach ($blogs as $b) { | 
|---|
| [3874] | 89 | $set_perms = []; | 
|---|
| [2566] | 90 |  | 
|---|
| [3699] | 91 | if (!empty($_POST['perm'][$b])) { | 
|---|
|  | 92 | foreach ($_POST['perm'][$b] as $perm_id => $v) { | 
|---|
|  | 93 | if ($v) { | 
|---|
|  | 94 | $set_perms[$perm_id] = true; | 
|---|
|  | 95 | } | 
|---|
|  | 96 | } | 
|---|
|  | 97 | } | 
|---|
| [2566] | 98 |  | 
|---|
| [3699] | 99 | $core->setUserBlogPermissions($u, $b, $set_perms, true); | 
|---|
|  | 100 | } | 
|---|
|  | 101 | } | 
|---|
|  | 102 | } catch (Exception $e) { | 
|---|
|  | 103 | $core->error->add($e->getMessage()); | 
|---|
|  | 104 | } | 
|---|
|  | 105 | if (!$core->error->flag()) { | 
|---|
|  | 106 | dcPage::addSuccessNotice(__('User has been successfully updated.')); | 
|---|
|  | 107 | http::redirect($redir); | 
|---|
|  | 108 | } | 
|---|
|  | 109 | } | 
|---|
| [860] | 110 | } | 
|---|
|  | 111 |  | 
|---|
|  | 112 | /* DISPLAY | 
|---|
|  | 113 | -------------------------------------------------------- */ | 
|---|
| [1358] | 114 | if (!empty($users) && empty($blogs) && $action == 'blogs') { | 
|---|
| [3699] | 115 | $breadcrumb = dcPage::breadcrumb( | 
|---|
| [3874] | 116 | [ | 
|---|
| [3699] | 117 | __('System')      => '', | 
|---|
|  | 118 | __('Users')       => $core->adminurl->get("admin.users"), | 
|---|
|  | 119 | __('Permissions') => '' | 
|---|
| [3874] | 120 | ]); | 
|---|
| [1358] | 121 | } else { | 
|---|
| [3699] | 122 | $breadcrumb = dcPage::breadcrumb( | 
|---|
| [3874] | 123 | [ | 
|---|
| [3699] | 124 | __('System')  => '', | 
|---|
|  | 125 | __('Users')   => $core->adminurl->get("admin.users"), | 
|---|
|  | 126 | __('Actions') => '' | 
|---|
| [3874] | 127 | ]); | 
|---|
| [1358] | 128 | } | 
|---|
|  | 129 |  | 
|---|
| [860] | 130 | dcPage::open( | 
|---|
| [3699] | 131 | __('Users'), | 
|---|
|  | 132 | dcPage::jsLoad('js/_users_actions.js') . | 
|---|
|  | 133 | # --BEHAVIOR-- adminUsersActionsHeaders | 
|---|
|  | 134 | $core->callBehavior('adminUsersActionsHeaders'), | 
|---|
|  | 135 | $breadcrumb | 
|---|
| [860] | 136 | ); | 
|---|
|  | 137 |  | 
|---|
|  | 138 | if (!isset($action)) { | 
|---|
| [3699] | 139 | dcPage::close(); | 
|---|
|  | 140 | exit; | 
|---|
| [860] | 141 | } | 
|---|
|  | 142 |  | 
|---|
|  | 143 | $hidden_fields = ''; | 
|---|
| [3699] | 144 | foreach ($users as $u) { | 
|---|
| [3874] | 145 | $hidden_fields .= form::hidden(['users[]'], $u); | 
|---|
| [860] | 146 | } | 
|---|
|  | 147 |  | 
|---|
| [3699] | 148 | if (isset($_POST['redir']) && strpos($_POST['redir'], '://') === false) { | 
|---|
| [3874] | 149 | $hidden_fields .= form::hidden(['redir'], html::escapeURL($_POST['redir'])); | 
|---|
| [3699] | 150 | } else { | 
|---|
|  | 151 | $hidden_fields .= | 
|---|
| [3874] | 152 | form::hidden(['q'], html::escapeHTML($_POST['q'])) . | 
|---|
|  | 153 | form::hidden(['sortby'], $_POST['sortby']) . | 
|---|
|  | 154 | form::hidden(['order'], $_POST['order']) . | 
|---|
|  | 155 | form::hidden(['page'], $_POST['page']) . | 
|---|
|  | 156 | form::hidden(['nb'], $_POST['nb']); | 
|---|
| [860] | 157 | } | 
|---|
|  | 158 |  | 
|---|
| [3699] | 159 | echo '<p><a class="back" href="' . html::escapeURL($redir) . '">' . __('Back to user profile') . '</a></p>'; | 
|---|
| [1499] | 160 |  | 
|---|
| [860] | 161 | # --BEHAVIOR-- adminUsersActionsContent | 
|---|
| [3699] | 162 | $core->callBehavior('adminUsersActionsContent', $core, $action, $hidden_fields); | 
|---|
| [860] | 163 |  | 
|---|
|  | 164 | # Blog list where to set permissions | 
|---|
| [3699] | 165 | if (!empty($users) && empty($blogs) && $action == 'blogs') { | 
|---|
|  | 166 | try { | 
|---|
|  | 167 | $rs      = $core->getBlogs(); | 
|---|
|  | 168 | $nb_blog = $rs->count(); | 
|---|
|  | 169 | } catch (Exception $e) {} | 
|---|
| [2566] | 170 |  | 
|---|
| [3699] | 171 | foreach ($users as $u) { | 
|---|
| [3874] | 172 | $user_list[] = '<a href="' . $core->adminurl->get("admin.user", ['id' => $u]) . '">' . $u . '</a>'; | 
|---|
| [3699] | 173 | } | 
|---|
| [2566] | 174 |  | 
|---|
| [3699] | 175 | echo | 
|---|
|  | 176 | '<p>' . sprintf( | 
|---|
|  | 177 | __('Choose one or more blogs to which you want to give permissions to users %s.'), | 
|---|
|  | 178 | implode(', ', $user_list) | 
|---|
|  | 179 | ) . '</p>'; | 
|---|
| [2566] | 180 |  | 
|---|
| [3699] | 181 | if ($nb_blog == 0) { | 
|---|
|  | 182 | echo '<p><strong>' . __('No blog') . '</strong></p>'; | 
|---|
|  | 183 | } else { | 
|---|
|  | 184 | echo | 
|---|
|  | 185 | '<form action="' . $core->adminurl->get("admin.user.actions") . '" method="post" id="form-blogs">' . | 
|---|
|  | 186 | '<div class="table-outer clear">' . | 
|---|
|  | 187 | '<table><tr>' . | 
|---|
|  | 188 | '<th class="nowrap" colspan="2">' . __('Blog ID') . '</th>' . | 
|---|
|  | 189 | '<th class="nowrap">' . __('Blog name') . '</th>' . | 
|---|
|  | 190 | '<th class="nowrap">' . __('URL') . '</th>' . | 
|---|
|  | 191 | '<th class="nowrap">' . __('Entries') . '</th>' . | 
|---|
|  | 192 | '<th class="nowrap">' . __('Status') . '</th>' . | 
|---|
|  | 193 | '</tr>'; | 
|---|
| [2566] | 194 |  | 
|---|
| [3699] | 195 | while ($rs->fetch()) { | 
|---|
|  | 196 | $img_status = $rs->blog_status == 1 ? 'check-on' : ($rs->blog_status == 0 ? 'check-off' : 'check-wrn'); | 
|---|
|  | 197 | $txt_status = $core->getBlogStatus($rs->blog_status); | 
|---|
|  | 198 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />', $img_status, $txt_status); | 
|---|
| [2566] | 199 |  | 
|---|
| [3699] | 200 | echo | 
|---|
|  | 201 | '<tr class="line">' . | 
|---|
|  | 202 | '<td class="nowrap">' . | 
|---|
| [3874] | 203 | form::checkbox(['blogs[]'], $rs->blog_id, | 
|---|
|  | 204 | [ | 
|---|
| [3707] | 205 | 'extra_html' => 'title="' . __('select') . ' ' . $rs->blog_id . '"' | 
|---|
| [3874] | 206 | ]) . | 
|---|
| [3707] | 207 | '</td>' . | 
|---|
| [3699] | 208 | '<td class="nowrap">' . $rs->blog_id . '</td>' . | 
|---|
|  | 209 | '<td class="maximal">' . html::escapeHTML($rs->blog_name) . '</td>' . | 
|---|
|  | 210 | '<td class="nowrap"><a class="outgoing" href="' . html::escapeHTML($rs->blog_url) . '">' . html::escapeHTML($rs->blog_url) . | 
|---|
| [3771] | 211 | ' <img src="images/outgoing-link.svg" alt="" /></a></td>' . | 
|---|
| [3699] | 212 | '<td class="nowrap">' . $core->countBlogPosts($rs->blog_id) . '</td>' . | 
|---|
|  | 213 | '<td class="status">' . $img_status . '</td>' . | 
|---|
|  | 214 | '</tr>'; | 
|---|
|  | 215 | } | 
|---|
| [2566] | 216 |  | 
|---|
| [3699] | 217 | echo | 
|---|
|  | 218 | '</table></div>' . | 
|---|
|  | 219 | '<p class="checkboxes-helpers"></p>' . | 
|---|
|  | 220 | '<p><input id="do-action" type="submit" value="' . __('Set permissions') . '" />' . | 
|---|
|  | 221 | $hidden_fields . | 
|---|
| [3874] | 222 | form::hidden(['action'], 'perms') . | 
|---|
| [3699] | 223 | $core->formNonce() . '</p>' . | 
|---|
|  | 224 | '</form>'; | 
|---|
|  | 225 | } | 
|---|
| [860] | 226 | } | 
|---|
|  | 227 | # Permissions list for each selected blogs | 
|---|
| [3699] | 228 | elseif (!empty($blogs) && !empty($users) && $action == 'perms') { | 
|---|
| [3874] | 229 | $user_perm = []; | 
|---|
| [3699] | 230 | if (count($users) == 1) { | 
|---|
|  | 231 | $user_perm = $core->getUserPermissions($users[0]); | 
|---|
|  | 232 | } | 
|---|
| [2566] | 233 |  | 
|---|
| [3699] | 234 | foreach ($users as $u) { | 
|---|
| [3874] | 235 | $user_list[] = '<a href="' . $core->adminurl->get("admin.user", ['id' => $u]) . '">' . $u . '</a>'; | 
|---|
| [3699] | 236 | } | 
|---|
| [2566] | 237 |  | 
|---|
| [3699] | 238 | echo | 
|---|
|  | 239 | '<p>' . sprintf( | 
|---|
|  | 240 | __('You are about to change permissions on the following blogs for users %s.'), | 
|---|
|  | 241 | implode(', ', $user_list) | 
|---|
|  | 242 | ) . '</p>' . | 
|---|
|  | 243 | '<form id="permissions-form" action="' . $core->adminurl->get("admin.user.actions") . '" method="post">'; | 
|---|
| [2566] | 244 |  | 
|---|
| [3699] | 245 | foreach ($blogs as $b) { | 
|---|
| [3874] | 246 | echo '<h3>' . ('Blog:') . ' <a href="' . $core->adminurl->get("admin.blog", ['id' => html::escapeHTML($b)]) . '">' . html::escapeHTML($b) . '</a>' . | 
|---|
|  | 247 | form::hidden(['blogs[]'], $b) . '</h3>'; | 
|---|
| [3699] | 248 | $unknown_perms = $user_perm; | 
|---|
|  | 249 | foreach ($core->auth->getPermissionsTypes() as $perm_id => $perm) { | 
|---|
|  | 250 | $checked = false; | 
|---|
| [2566] | 251 |  | 
|---|
| [3699] | 252 | if (count($users) == 1) { | 
|---|
|  | 253 | $checked = isset($user_perm[$b]['p'][$perm_id]) && $user_perm[$b]['p'][$perm_id]; | 
|---|
|  | 254 | } | 
|---|
|  | 255 | if (isset($unknown_perms[$b]['p'][$perm_id])) { | 
|---|
|  | 256 | unset($unknown_perms[$b]['p'][$perm_id]); | 
|---|
|  | 257 | } | 
|---|
| [2566] | 258 |  | 
|---|
| [3699] | 259 | echo | 
|---|
|  | 260 | '<p><label for="perm' . html::escapeHTML($b) . html::escapeHTML($perm_id) . '" class="classic">' . | 
|---|
| [3874] | 261 | form::checkbox(['perm[' . html::escapeHTML($b) . '][' . html::escapeHTML($perm_id) . ']', 'perm' . html::escapeHTML($b) . html::escapeHTML($perm_id)], | 
|---|
| [3699] | 262 | 1, $checked) . ' ' . | 
|---|
|  | 263 | __($perm) . '</label></p>'; | 
|---|
|  | 264 | } | 
|---|
|  | 265 | if (isset($unknown_perms[$b])) { | 
|---|
| [2566] | 266 |  | 
|---|
| [3699] | 267 | foreach ($unknown_perms[$b]['p'] as $perm_id => $v) { | 
|---|
|  | 268 | $checked = isset($user_perm[$b]['p'][$perm_id]) && $user_perm[$b]['p'][$perm_id]; | 
|---|
|  | 269 | echo | 
|---|
|  | 270 | '<p><label for="perm' . html::escapeHTML($b) . html::escapeHTML($perm_id) . '" class="classic">' . | 
|---|
|  | 271 | form::checkbox( | 
|---|
| [3874] | 272 | ['perm[' . html::escapeHTML($b) . '][' . html::escapeHTML($perm_id) . ']', | 
|---|
|  | 273 | 'perm' . html::escapeHTML($b) . html::escapeHTML($perm_id)], | 
|---|
| [3699] | 274 | 1, $checked) . ' ' . | 
|---|
|  | 275 | sprintf(__('[%s] (unreferenced permission)'), $perm_id) . '</label></p>'; | 
|---|
|  | 276 | } | 
|---|
|  | 277 | } | 
|---|
|  | 278 | } | 
|---|
| [2566] | 279 |  | 
|---|
| [3699] | 280 | echo | 
|---|
|  | 281 | '<p class="checkboxes-helpers"></p>' . | 
|---|
|  | 282 | '<div class="fieldset">' . | 
|---|
|  | 283 | '<h3>' . __('Validate permissions') . '</h3>' . | 
|---|
|  | 284 | '<p><label for="your_pwd" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Your password:') . '</label>' . | 
|---|
|  | 285 | form::password('your_pwd', 20, 255, | 
|---|
| [3874] | 286 | [ | 
|---|
| [3699] | 287 | 'extra_html'   => 'required placeholder="' . __('Password') . '"', | 
|---|
|  | 288 | 'autocomplete' => 'current-password' | 
|---|
| [3874] | 289 | ] | 
|---|
| [3699] | 290 | ) . '</p>' . | 
|---|
|  | 291 | '<p><input type="submit" accesskey="s" value="' . __('Save') . '" />' . | 
|---|
|  | 292 | $hidden_fields . | 
|---|
| [3874] | 293 | form::hidden(['action'], 'updateperm') . | 
|---|
| [3699] | 294 | $core->formNonce() . '</p>' . | 
|---|
|  | 295 | '</div>' . | 
|---|
|  | 296 | '</form>'; | 
|---|
| [860] | 297 | } | 
|---|
|  | 298 |  | 
|---|
| [2436] | 299 | dcPage::helpBlock('core_users'); | 
|---|
| [860] | 300 | dcPage::close(); | 
|---|