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::check('usage,contentadmin'); |
---|
16 | |
---|
17 | $page_title = __('User preferences'); |
---|
18 | |
---|
19 | $user_name = $core->auth->getInfo('user_name'); |
---|
20 | $user_firstname = $core->auth->getInfo('user_firstname'); |
---|
21 | $user_displayname = $core->auth->getInfo('user_displayname'); |
---|
22 | $user_email = $core->auth->getInfo('user_email'); |
---|
23 | $user_url = $core->auth->getInfo('user_url'); |
---|
24 | $user_lang = $core->auth->getInfo('user_lang'); |
---|
25 | $user_tz = $core->auth->getInfo('user_tz'); |
---|
26 | $user_post_status = $core->auth->getInfo('user_post_status'); |
---|
27 | |
---|
28 | $user_options = $core->auth->getOptions(); |
---|
29 | |
---|
30 | foreach ($core->getFormaters() as $v) { |
---|
31 | $formaters_combo[$v] = $v; |
---|
32 | } |
---|
33 | |
---|
34 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
---|
35 | $status_combo[$v] = $k; |
---|
36 | } |
---|
37 | |
---|
38 | # Language codes |
---|
39 | $langs = l10n::getISOcodes(1,1); |
---|
40 | foreach ($langs as $k => $v) { |
---|
41 | $lang_avail = $v == 'en' || is_dir(DC_L10N_ROOT.'/'.$v); |
---|
42 | $lang_combo[] = new formSelectOption($k,$v,$lang_avail ? 'avail10n' : ''); |
---|
43 | } |
---|
44 | |
---|
45 | # Add or update user |
---|
46 | if (isset($_POST['user_name'])) |
---|
47 | { |
---|
48 | try |
---|
49 | { |
---|
50 | $pwd_check = !empty($_POST['cur_pwd']) && $core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['cur_pwd'])); |
---|
51 | |
---|
52 | if ($core->auth->allowPassChange() && !$pwd_check && $user_email != $_POST['user_email']) { |
---|
53 | throw new Exception(__('If you want to change your email or password you must provide your current password.')); |
---|
54 | } |
---|
55 | |
---|
56 | $cur = $core->con->openCursor($core->prefix.'user'); |
---|
57 | |
---|
58 | $cur->user_name = $user_name = $_POST['user_name']; |
---|
59 | $cur->user_firstname = $user_firstname = $_POST['user_firstname']; |
---|
60 | $cur->user_displayname = $user_displayname = $_POST['user_displayname']; |
---|
61 | $cur->user_email = $user_email = $_POST['user_email']; |
---|
62 | $cur->user_url = $user_url = $_POST['user_url']; |
---|
63 | $cur->user_lang = $user_lang = $_POST['user_lang']; |
---|
64 | $cur->user_tz = $user_tz = $_POST['user_tz']; |
---|
65 | $cur->user_post_status = $user_post_status = $_POST['user_post_status']; |
---|
66 | |
---|
67 | $user_options['edit_size'] = (integer) $_POST['user_edit_size']; |
---|
68 | if ($user_options['edit_size'] < 1) { |
---|
69 | $user_options['edit_size'] = 10; |
---|
70 | } |
---|
71 | $user_options['post_format'] = $_POST['user_post_format']; |
---|
72 | $user_options['enable_wysiwyg'] = !empty($_POST['user_wysiwyg']); |
---|
73 | |
---|
74 | $cur->user_options = new ArrayObject($user_options); |
---|
75 | |
---|
76 | if ($core->auth->allowPassChange() && !empty($_POST['new_pwd'])) |
---|
77 | { |
---|
78 | if (!$pwd_check) { |
---|
79 | throw new Exception(__('If you want to change your email or password you must provide your current password.')); |
---|
80 | } |
---|
81 | |
---|
82 | if ($_POST['new_pwd'] != $_POST['new_pwd_c']) { |
---|
83 | throw new Exception(__("Passwords don't match")); |
---|
84 | } |
---|
85 | |
---|
86 | $cur->user_pwd = $_POST['new_pwd']; |
---|
87 | } |
---|
88 | |
---|
89 | # --BEHAVIOR-- adminBeforeUserUpdate |
---|
90 | $core->callBehavior('adminBeforeUserUpdate',$cur,$core->auth->userID()); |
---|
91 | |
---|
92 | # Udate user |
---|
93 | $core->updUser($core->auth->userID(),$cur); |
---|
94 | |
---|
95 | # --BEHAVIOR-- adminAfterUserUpdate |
---|
96 | $core->callBehavior('adminAfterUserUpdate',$cur,$core->auth->userID()); |
---|
97 | |
---|
98 | http::redirect('preferences.php?upd=1'); |
---|
99 | } |
---|
100 | catch (Exception $e) |
---|
101 | { |
---|
102 | $core->error->add($e->getMessage()); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | /* DISPLAY |
---|
108 | -------------------------------------------------------- */ |
---|
109 | dcPage::open($page_title, |
---|
110 | dcPage::jsLoad('js/_preferences.js'). |
---|
111 | dcPage::jsConfirmClose('user-form'). |
---|
112 | |
---|
113 | # --BEHAVIOR-- adminPreferencesHeaders |
---|
114 | $core->callBehavior('adminPreferencesHeaders') |
---|
115 | ); |
---|
116 | |
---|
117 | if (!empty($_GET['upd'])) { |
---|
118 | echo '<p class="message">'.__('Personal information has been successfully updated.').'</p>'; |
---|
119 | } |
---|
120 | |
---|
121 | echo '<h2>'.$page_title.'</h2>'; |
---|
122 | |
---|
123 | |
---|
124 | echo |
---|
125 | '<form action="preferences.php" method="post" id="user-form">'. |
---|
126 | '<fieldset><legend>'.__('User preferences').'</legend>'. |
---|
127 | '<div class="two-cols">'. |
---|
128 | '<div class="col">'. |
---|
129 | '<p><label>'.__('Last Name:'). |
---|
130 | form::field('user_name',20,255,html::escapeHTML($user_name),'',2).'</label></p>'. |
---|
131 | |
---|
132 | '<p><label>'.__('First Name:'). |
---|
133 | form::field('user_firstname',20,255,html::escapeHTML($user_firstname),'',3).'</label></p>'. |
---|
134 | |
---|
135 | '<p><label>'.__('Display name:'). |
---|
136 | form::field('user_displayname',20,255,html::escapeHTML($user_displayname),'',4).'</label></p>'. |
---|
137 | |
---|
138 | '<p><label>'.__('Email:'). |
---|
139 | form::field('user_email',20,255,html::escapeHTML($user_email),'',5).'</label></p>'. |
---|
140 | |
---|
141 | '<p><label>'.__('URL:'). |
---|
142 | form::field('user_url',30,255,html::escapeHTML($user_url),'',6).'</label></p>'. |
---|
143 | |
---|
144 | '</div>'. |
---|
145 | |
---|
146 | '<div class="col">'. |
---|
147 | |
---|
148 | '<p><label>'.__('Preferred format:'). |
---|
149 | form::combo('user_post_format',$formaters_combo,$user_options['post_format'],'',7).'</label></p>'. |
---|
150 | |
---|
151 | '<p><label>'.__('Default entry status:'). |
---|
152 | form::combo('user_post_status',$status_combo,$user_post_status,'',8).'</label></p>'. |
---|
153 | |
---|
154 | '<p><label>'.__('Entry edit field height:'). |
---|
155 | form::field('user_edit_size',5,4,(integer) $user_options['edit_size'],'',9).'</label></p>'. |
---|
156 | |
---|
157 | '<p><label>'.__('User language:'). |
---|
158 | form::combo('user_lang',$lang_combo,$user_lang,'l10n',10).'</label></p>'. |
---|
159 | |
---|
160 | '<p><label>'.__('User timezone:'). |
---|
161 | form::combo('user_tz',dt::getZones(true,true),$user_tz,'',11).'</label></p>'. |
---|
162 | |
---|
163 | '<p><label class="classic">'. |
---|
164 | form::checkbox('user_wysiwyg',1,$user_options['enable_wysiwyg'],'',12).' '. |
---|
165 | __('Enable WYSIWYG mode').'</label></p>'. |
---|
166 | '</div>'. |
---|
167 | '</div>'. |
---|
168 | '<br class="clear" />'. //Opera sucks |
---|
169 | '</fieldset>'; |
---|
170 | |
---|
171 | # --BEHAVIOR-- adminPreferencesForm |
---|
172 | $core->callBehavior('adminPreferencesForm',$core); |
---|
173 | |
---|
174 | if ($core->auth->allowPassChange()) |
---|
175 | { |
---|
176 | echo |
---|
177 | '<fieldset>'. |
---|
178 | '<legend>'.__('Change your password').'</legend>'. |
---|
179 | |
---|
180 | '<p><label>'.__('New password:'). |
---|
181 | form::password('new_pwd',20,255,'','',30).'</label></p>'. |
---|
182 | |
---|
183 | '<p><label>'.__('Confirm password:'). |
---|
184 | form::password('new_pwd_c',20,255,'','',31).'</label></p>'. |
---|
185 | '</fieldset>'. |
---|
186 | |
---|
187 | '<fieldset>'. |
---|
188 | '<p>'.__('If you want to change your email or password you must provide your current password.').'</p>'. |
---|
189 | '<p><label>'.__('Your password:'). |
---|
190 | form::password('cur_pwd',20,255,'','',32).'</label></p>'. |
---|
191 | '</fieldset>'; |
---|
192 | } |
---|
193 | |
---|
194 | echo |
---|
195 | '<p class="clear">'. |
---|
196 | $core->formNonce(). |
---|
197 | '<input type="submit" accesskey="s" value="'.__('Save').'" tabindex="33" /></p>'. |
---|
198 | '</form>'; |
---|
199 | |
---|
200 | dcPage::helpBlock('core_user_pref'); |
---|
201 | dcPage::close(); |
---|
202 | ?> |
---|