| [0] | 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear |
|---|
| 7 | # Licensed under the GPL version 2.0 license. |
|---|
| 8 | # See LICENSE file or |
|---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|---|
| 10 | # |
|---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
|---|
| 12 | |
|---|
| 13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
|---|
| 14 | |
|---|
| 15 | dcPage::checkSuper(); |
|---|
| 16 | |
|---|
| 17 | $page_title = __('new user'); |
|---|
| 18 | |
|---|
| 19 | $user_id = ''; |
|---|
| 20 | $user_super = ''; |
|---|
| 21 | $user_pwd = ''; |
|---|
| 22 | $user_change_pwd = ''; |
|---|
| 23 | $user_name = ''; |
|---|
| 24 | $user_firstname = ''; |
|---|
| 25 | $user_displayname = ''; |
|---|
| 26 | $user_email = ''; |
|---|
| 27 | $user_url = ''; |
|---|
| 28 | $user_lang = $core->auth->getInfo('user_lang'); |
|---|
| 29 | $user_tz = $core->auth->getInfo('user_tz'); |
|---|
| 30 | $user_post_status = ''; |
|---|
| 31 | |
|---|
| 32 | $user_options = $core->userDefaults(); |
|---|
| 33 | |
|---|
| 34 | foreach ($core->getFormaters() as $v) { |
|---|
| 35 | $formaters_combo[$v] = $v; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
|---|
| 39 | $status_combo[$v] = $k; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | # Language codes |
|---|
| 43 | $langs = l10n::getISOcodes(1,1); |
|---|
| 44 | foreach ($langs as $k => $v) { |
|---|
| 45 | $lang_avail = $v == 'en' || is_dir(DC_L10N_ROOT.'/'.$v); |
|---|
| 46 | $lang_combo[] = new formSelectOption($k,$v,$lang_avail ? 'avail10n' : ''); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | # Get user if we have an ID |
|---|
| 50 | if (!empty($_REQUEST['id'])) |
|---|
| 51 | { |
|---|
| 52 | try { |
|---|
| 53 | $rs = $core->getUser($_REQUEST['id']); |
|---|
| 54 | |
|---|
| 55 | $user_id = $rs->user_id; |
|---|
| 56 | $user_super = $rs->user_super; |
|---|
| 57 | $user_pwd = $rs->user_pwd; |
|---|
| 58 | $user_change_pwd = $rs->user_change_pwd; |
|---|
| 59 | $user_name = $rs->user_name; |
|---|
| 60 | $user_firstname = $rs->user_firstname; |
|---|
| 61 | $user_displayname = $rs->user_displayname; |
|---|
| 62 | $user_email = $rs->user_email; |
|---|
| 63 | $user_url = $rs->user_url; |
|---|
| 64 | $user_lang = $rs->user_lang; |
|---|
| 65 | $user_tz = $rs->user_tz; |
|---|
| 66 | $user_post_status = $rs->user_post_status; |
|---|
| 67 | |
|---|
| 68 | $user_options = array_merge($user_options,$rs->options()); |
|---|
| 69 | |
|---|
| 70 | $page_title = $user_id; |
|---|
| 71 | } catch (Exception $e) { |
|---|
| 72 | $core->error->add($e->getMessage()); |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | # Add or update user |
|---|
| 77 | if (isset($_POST['user_name'])) |
|---|
| 78 | { |
|---|
| 79 | try |
|---|
| 80 | { |
|---|
| 81 | if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) { |
|---|
| 82 | throw new Exception(__('Password verification failed')); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | $cur = $core->con->openCursor($core->prefix.'user'); |
|---|
| 86 | |
|---|
| 87 | $cur->user_id = $_POST['user_id']; |
|---|
| 88 | $cur->user_super = $user_super = !empty($_POST['user_super']) ? 1 : 0; |
|---|
| 89 | $cur->user_name = $user_name = $_POST['user_name']; |
|---|
| 90 | $cur->user_firstname = $user_firstname = $_POST['user_firstname']; |
|---|
| 91 | $cur->user_displayname = $user_displayname = $_POST['user_displayname']; |
|---|
| 92 | $cur->user_email = $user_email = $_POST['user_email']; |
|---|
| 93 | $cur->user_url = $user_url = $_POST['user_url']; |
|---|
| 94 | $cur->user_lang = $user_lang = $_POST['user_lang']; |
|---|
| 95 | $cur->user_tz = $user_tz = $_POST['user_tz']; |
|---|
| 96 | $cur->user_post_status = $user_post_status = $_POST['user_post_status']; |
|---|
| 97 | |
|---|
| 98 | if ($core->auth->allowPassChange()) { |
|---|
| 99 | $cur->user_change_pwd = !empty($_POST['user_change_pwd']) ? 1 : 0; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | if (!empty($_POST['new_pwd'])) { |
|---|
| 103 | if ($_POST['new_pwd'] != $_POST['new_pwd_c']) { |
|---|
| 104 | throw new Exception(__("Passwords don't match")); |
|---|
| 105 | } else { |
|---|
| 106 | $cur->user_pwd = $_POST['new_pwd']; |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | $user_options['post_format'] = $_POST['user_post_format']; |
|---|
| 111 | $user_options['edit_size'] = (integer) $_POST['user_edit_size']; |
|---|
| 112 | |
|---|
| 113 | if ($user_options['edit_size'] < 1) { |
|---|
| 114 | $user_options['edit_size'] = 10; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | $cur->user_options = new ArrayObject($user_options); |
|---|
| 118 | |
|---|
| 119 | # Udate user |
|---|
| 120 | if ($user_id) |
|---|
| 121 | { |
|---|
| 122 | # --BEHAVIOR-- adminBeforeUserUpdate |
|---|
| 123 | $core->callBehavior('adminBeforeUserUpdate',$cur,$user_id); |
|---|
| 124 | |
|---|
| 125 | $new_id = $core->updUser($user_id,$cur); |
|---|
| 126 | |
|---|
| 127 | # --BEHAVIOR-- adminAfterUserUpdate |
|---|
| 128 | $core->callBehavior('adminAfterUserUpdate',$cur,$new_id); |
|---|
| 129 | |
|---|
| 130 | if ($user_id == $core->auth->userID() && |
|---|
| 131 | $user_id != $new_id) { |
|---|
| 132 | $core->session->destroy(); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | http::redirect('user.php?id='.$new_id.'&upd=1'); |
|---|
| 136 | } |
|---|
| 137 | # Add user |
|---|
| 138 | else |
|---|
| 139 | { |
|---|
| 140 | if ($core->getUsers(array('user_id' => $cur->user_id),true)->f(0) > 0) { |
|---|
| 141 | throw new Exception(sprintf(__('User "%s" already exists.'),html::escapeHTML($cur->user_id))); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | # --BEHAVIOR-- adminBeforeUserCreate |
|---|
| 145 | $core->callBehavior('adminBeforeUserCreate',$cur); |
|---|
| 146 | |
|---|
| 147 | $new_id = $core->addUser($cur); |
|---|
| 148 | |
|---|
| 149 | # --BEHAVIOR-- adminAfterUserCreate |
|---|
| 150 | $core->callBehavior('adminAfterUserCreate',$cur,$new_id); |
|---|
| 151 | |
|---|
| 152 | http::redirect('user.php?id='.$new_id.'&add=1'); |
|---|
| 153 | } |
|---|
| 154 | } |
|---|
| 155 | catch (Exception $e) |
|---|
| 156 | { |
|---|
| 157 | $core->error->add($e->getMessage()); |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /* DISPLAY |
|---|
| 163 | -------------------------------------------------------- */ |
|---|
| 164 | dcPage::open($page_title, |
|---|
| 165 | dcPage::jsConfirmClose('user-form'). |
|---|
| 166 | |
|---|
| 167 | # --BEHAVIOR-- adminUserHeaders |
|---|
| 168 | $core->callBehavior('adminUserHeaders') |
|---|
| 169 | ); |
|---|
| 170 | |
|---|
| 171 | if (!empty($_GET['upd'])) { |
|---|
| 172 | echo '<p class="message">'.__('User has been successfully updated.').'</p>'; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | if (!empty($_GET['add'])) { |
|---|
| 176 | echo '<p class="message">'.__('User has been successfully created.').'</p>'; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | echo '<h2><a href="users.php">'.__('Users').'</a> › '.$page_title.'</h2>'; |
|---|
| 180 | |
|---|
| 181 | if ($user_id == $core->auth->userID()) { |
|---|
| 182 | echo |
|---|
| 183 | '<p class="warning">'.__('Warning:').' '. |
|---|
| 184 | __('If you change your username, you will have to log in again.').'</p>'; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | echo |
|---|
| 188 | '<form action="user.php" method="post"id="user-form">'. |
|---|
| 189 | '<fieldset><legend>'.__('User information').'</legend>'. |
|---|
| 190 | '<div class="two-cols">'. |
|---|
| 191 | '<div class="col">'. |
|---|
| [70] | 192 | '<p><label for="user_id" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Username:').' '. |
|---|
| [0] | 193 | form::field('user_id',20,255,html::escapeHTML($user_id),'',2). |
|---|
| 194 | '</label></p>'. |
|---|
| 195 | '<p class="form-note">'.__('At least 2 characters using letters, numbers or symbols.').'</p>'. |
|---|
| 196 | |
|---|
| [70] | 197 | '<p><label for="new_pwd">'.($user_id!='' ? __('New password:') : __('Password:')).' '. |
|---|
| [0] | 198 | form::password('new_pwd',20,255,'','',3). |
|---|
| 199 | '</label></p>'. |
|---|
| 200 | |
|---|
| [70] | 201 | '<p><label for="new_pwd_c">'.__('Confirm password:').' '. |
|---|
| [0] | 202 | form::password('new_pwd_c',20,255,'','',4). |
|---|
| 203 | '</label></p>'. |
|---|
| 204 | |
|---|
| [70] | 205 | '<p><label for="user_name">'.__('Last Name:').' '. |
|---|
| [0] | 206 | form::field('user_name',20,255,html::escapeHTML($user_name),'',5). |
|---|
| 207 | '</label></p>'. |
|---|
| 208 | |
|---|
| [70] | 209 | '<p><label for="user_firstname">'.__('First Name:').' '. |
|---|
| [0] | 210 | form::field('user_firstname',20,255,html::escapeHTML($user_firstname),'',6). |
|---|
| 211 | '</label></p>'. |
|---|
| 212 | |
|---|
| [70] | 213 | '<p><label for="user_displayname">'.__('Display name:').' '. |
|---|
| [0] | 214 | form::field('user_displayname',20,255,html::escapeHTML($user_displayname),'',7). |
|---|
| 215 | '</label></p>'. |
|---|
| 216 | |
|---|
| [70] | 217 | '<p><label for="user_email">'.__('Email:').' '. |
|---|
| [0] | 218 | form::field('user_email',20,255,html::escapeHTML($user_email),'',8). |
|---|
| 219 | '</label></p>'. |
|---|
| 220 | '</div>'. |
|---|
| 221 | |
|---|
| 222 | '<div class="col">'. |
|---|
| [70] | 223 | '<p><label for="user_url">'.__('URL:').' '. |
|---|
| [0] | 224 | form::field('user_url',30,255,html::escapeHTML($user_url),'',9). |
|---|
| 225 | '</label></p>'. |
|---|
| [70] | 226 | '<p><label for="user_post_format">'.__('Preferred format:').' '. |
|---|
| [0] | 227 | form::combo('user_post_format',$formaters_combo,$user_options['post_format'],'',10). |
|---|
| 228 | '</label></p>'. |
|---|
| 229 | |
|---|
| [70] | 230 | '<p><label for="user_post_status">'.__('Default entry status:').' '. |
|---|
| [0] | 231 | form::combo('user_post_status',$status_combo,$user_post_status,'',11). |
|---|
| 232 | '</label></p>'. |
|---|
| 233 | |
|---|
| 234 | '<p><label>'.__('Entry edit field height:').' '. |
|---|
| 235 | form::field('user_edit_size',5,4,(integer) $user_options['edit_size'],'',12). |
|---|
| 236 | '</label></p>'. |
|---|
| 237 | |
|---|
| [70] | 238 | '<p><label for="user_edit_size">'.__('User language:').' '. |
|---|
| [0] | 239 | form::combo('user_lang',$lang_combo,$user_lang,'l10n',13). |
|---|
| 240 | '</label></p>'. |
|---|
| 241 | |
|---|
| [70] | 242 | '<p><label for="user_tz">'.__('User timezone:').' '. |
|---|
| [0] | 243 | form::combo('user_tz',dt::getZones(true,true),$user_tz,'',14). |
|---|
| 244 | '</label></p>'; |
|---|
| 245 | |
|---|
| 246 | if ($core->auth->allowPassChange()) { |
|---|
| 247 | echo |
|---|
| [70] | 248 | '<p><label for="user_change_pwd" class="classic">'. |
|---|
| [0] | 249 | form::checkbox('user_change_pwd','1',$user_change_pwd,'',15).' '. |
|---|
| 250 | __('Password change required to connect').'</label></p>'; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | echo |
|---|
| [70] | 254 | '<p><label for="user_super" class="classic">'.form::checkbox('user_super','1',$user_super,'',16).' '. |
|---|
| [0] | 255 | __('Super administrator').'</label></p>'. |
|---|
| 256 | '</div>'. |
|---|
| 257 | '</div>'. |
|---|
| 258 | '</fieldset>'; |
|---|
| 259 | |
|---|
| 260 | # --BEHAVIOR-- adminUserForm |
|---|
| 261 | $core->callBehavior('adminUserForm',isset($rs) ? $rs : null); |
|---|
| 262 | |
|---|
| 263 | echo |
|---|
| 264 | '<fieldset>'. |
|---|
| [70] | 265 | '<p><label for="your_pwd">'.__('Your password:'). |
|---|
| [0] | 266 | form::password('your_pwd',20,255,'','',17).'</label></p>'. |
|---|
| 267 | '</fieldset>'. |
|---|
| 268 | '<p class="clear"><input type="submit" accesskey="s" value="'.__('Save').'" tabindex="16" />'. |
|---|
| 269 | ($user_id != '' ? form::hidden('id',$user_id) : ''). |
|---|
| 270 | $core->formNonce(). |
|---|
| 271 | '</p>'. |
|---|
| 272 | |
|---|
| 273 | '</form>'; |
|---|
| 274 | |
|---|
| 275 | if ($user_id) |
|---|
| 276 | { |
|---|
| 277 | echo '<fieldset class="clear"><legend>'.__('Permissions').'</legend>'; |
|---|
| 278 | |
|---|
| 279 | $permissions = $core->getUserPermissions($user_id); |
|---|
| 280 | $perm_types = $core->auth->getPermissionsTypes(); |
|---|
| 281 | |
|---|
| 282 | if (count($permissions) == 0) |
|---|
| 283 | { |
|---|
| 284 | echo '<p>'.__('No permissions.').'</p>'; |
|---|
| 285 | } |
|---|
| 286 | else |
|---|
| 287 | { |
|---|
| 288 | foreach ($permissions as $k => $v) |
|---|
| 289 | { |
|---|
| 290 | if (count($v['p']) > 0) |
|---|
| 291 | { |
|---|
| 292 | echo '<h4><a href="blog.php?id='.html::escapeHTML($k).'">'. |
|---|
| 293 | html::escapeHTML($v['name']).'</a> ('.html::escapeHTML($k).') - '. |
|---|
| 294 | '<a href="permissions.php?blog_id[]='.$k.'&user_id[]='.$user_id.'">' |
|---|
| 295 | .__('change permissions').'</a></h4>'; |
|---|
| 296 | |
|---|
| 297 | echo '<ul>'; |
|---|
| 298 | foreach ($v['p'] as $p => $V) { |
|---|
| 299 | if (isset($perm_types[$p])) { |
|---|
| 300 | echo '<li>'.__($perm_types[$p]).'</li>'; |
|---|
| 301 | } |
|---|
| 302 | } |
|---|
| 303 | echo '</ul>'; |
|---|
| 304 | } |
|---|
| 305 | } |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | echo |
|---|
| 309 | '<p><a href="permissions_blog.php?user_id[]='.$user_id.'">'. |
|---|
| 310 | __('Add new permissions').'</a></p>'. |
|---|
| 311 | '</fieldset>'; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | dcPage::close(); |
|---|
| 315 | ?> |
|---|