Changeset 3:cf375f1e7b0f for admin/preferences.php
- Timestamp:
- 04/27/11 09:06:30 (14 years ago)
- Branch:
- userprefs
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/preferences.php
r0 r3 15 15 dcPage::check('usage,contentadmin'); 16 16 17 $page_title = __(' Userpreferences');17 $page_title = __('My preferences'); 18 18 19 19 $user_name = $core->auth->getInfo('user_name'); … … 27 27 28 28 $user_options = $core->auth->getOptions(); 29 30 $default_tab = 'user-profile'; 31 32 if (!empty($_GET['append']) || !empty($_GET['removed']) || !empty($_GET['neworder'])) { 33 $default_tab = 'user-favorites'; 34 } 29 35 30 36 foreach ($core->getFormaters() as $v) { … … 104 110 } 105 111 112 # Add selected favorites 113 if (!empty($_POST['appendaction']) && !empty($_POST['append'])) { 114 $ws = $core->auth->user_prefs->addWorkspace('favorites'); 115 $user_favs = $ws->DumpLocalPrefs(); 116 $count = count($user_favs); 117 foreach ($_POST['append'] as $k => $v) 118 { 119 try { 120 $found = false; 121 foreach ($user_favs as $f) { 122 $f = unserialize($f['value']); 123 if ($f['name'] == $v) { 124 $found = true; 125 break; 126 } 127 } 128 if (!$found) { 129 $uid = sprintf("u%03s",$count); 130 $fav = array('name' => $_fav[$v][0],'title' => $_fav[$v][1],'url' => $_fav[$v][2],'small-icon' => $_fav[$v][3], 131 'large-icon' => $_fav[$v][4],'permissions' => $_fav[$v][5],'id' => $_fav[$v][6],'class' => $_fav[$v][7]); 132 $core->auth->user_prefs->favorites->put($uid,serialize($fav),'string'); 133 $count++; 134 } 135 } catch (Exception $e) { 136 $core->error->add($e->getMessage()); 137 break; 138 } 139 } 140 141 if (!$core->error->flag()) { 142 http::redirect('preferences.php?append=1'); 143 } 144 } 145 146 # Delete selected favorites 147 if (!empty($_POST['removeaction']) && !empty($_POST['remove'])) { 148 $ws = $core->auth->user_prefs->addWorkspace('favorites'); 149 foreach ($_POST['remove'] as $k => $v) 150 { 151 try { 152 $core->auth->user_prefs->favorites->drop($v); 153 } catch (Exception $e) { 154 $core->error->add($e->getMessage()); 155 break; 156 } 157 } 158 // Update pref_id values 159 try { 160 $user_favs = $ws->DumpLocalPrefs(); 161 foreach ($user_favs as $k => $v) 162 { 163 $core->auth->user_prefs->favorites->drop($k); 164 } 165 $count = 0; 166 foreach ($user_favs as $k => $v) 167 { 168 $uid = sprintf("u%03s",$count); 169 $f = unserialize($v['value']); 170 $fav = array('name' => $f['name'],'title' => $f['title'],'url' => $f['url'],'small-icon' => $f['small-icon'], 171 'large-icon' => $f['large-icon'],'permissions' => $f['permissions'],'id' => $f['id'],'class' => $f['class']); 172 $core->auth->user_prefs->favorites->put($uid,serialize($fav),'string'); 173 $count++; 174 } 175 } catch (Exception $e) { 176 $core->error->add($e->getMessage()); 177 } 178 179 if (!$core->error->flag()) { 180 http::redirect('preferences.php?removed=1'); 181 } 182 } 183 184 # Order favs 185 $order = array(); 186 if (empty($_POST['favs_order']) && !empty($_POST['order'])) { 187 $order = $_POST['order']; 188 asort($order); 189 $order = array_keys($order); 190 } elseif (!empty($_POST['favs_order'])) { 191 $order = explode(',',$_POST['favs_order']); 192 } 193 194 if (!empty($_POST['saveorder']) && !empty($order)) 195 { 196 try { 197 $user_favs = $ws->DumpLocalPrefs(); 198 foreach ($user_favs as $k => $v) 199 { 200 $core->auth->user_prefs->favorites->drop($k); 201 } 202 $count = 0; 203 foreach ($order as $i => $k) { 204 $uid = sprintf("u%03s",$count); 205 $f = unserialize($user_favs[$k]['value']); 206 $fav = array('name' => $f['name'],'title' => $f['title'],'url' => $f['url'],'small-icon' => $f['small-icon'], 207 'large-icon' => $f['large-icon'],'permissions' => $f['permissions'],'id' => $f['id'],'class' => $f['class']); 208 $core->auth->user_prefs->favorites->put($uid,serialize($fav),'string'); 209 $count++; 210 } 211 } catch (Exception $e) { 212 $core->error->add($e->getMessage()); 213 } 214 215 if (!$core->error->flag()) { 216 http::redirect('preferences.php?&neworder=1'); 217 } 218 } 219 106 220 107 221 /* DISPLAY … … 109 223 dcPage::open($page_title, 110 224 dcPage::jsLoad('js/_preferences.js'). 225 dcPage::jsPageTabs($default_tab). 111 226 dcPage::jsConfirmClose('user-form'). 112 227 … … 121 236 echo '<h2>'.$page_title.'</h2>'; 122 237 238 if (!empty($_GET['append'])) { 239 echo '<p class="message">'.__('Favorites have been successfully added.').'</p>'; 240 } 241 if (!empty($_GET['neworder'])) { 242 echo '<p class="message">'.__('Favorites has been successfully updated.').'</p>'; 243 } 244 if (!empty($_GET['removed'])) { 245 echo '<p class="message">'.__('Favorites have been successfully removed.').'</p>'; 246 } 247 248 # User profile 249 echo '<div class="multi-part" id="user-profile" title="'.__('My profile').'">'; 123 250 124 251 echo 125 252 '<form action="preferences.php" method="post" id="user-form">'. 126 '<fieldset><legend>'.__(' User preferences').'</legend>'.253 '<fieldset><legend>'.__('My profile').'</legend>'. 127 254 '<div class="two-cols">'. 128 255 '<div class="col">'. 129 '<p><label >'.__('Last Name:').256 '<p><label for"user_name">'.__('Last Name:'). 130 257 form::field('user_name',20,255,html::escapeHTML($user_name),'',2).'</label></p>'. 131 258 132 '<p><label >'.__('First Name:').259 '<p><label for="user_firstname">'.__('First Name:'). 133 260 form::field('user_firstname',20,255,html::escapeHTML($user_firstname),'',3).'</label></p>'. 134 261 135 '<p><label >'.__('Display name:').262 '<p><label for="user_displayname">'.__('Display name:'). 136 263 form::field('user_displayname',20,255,html::escapeHTML($user_displayname),'',4).'</label></p>'. 137 264 138 '<p><label >'.__('Email:').265 '<p><label for="user_email">'.__('Email:'). 139 266 form::field('user_email',20,255,html::escapeHTML($user_email),'',5).'</label></p>'. 140 267 141 '<p><label >'.__('URL:').268 '<p><label for="user_url">'.__('URL:'). 142 269 form::field('user_url',30,255,html::escapeHTML($user_url),'',6).'</label></p>'. 143 270 … … 146 273 '<div class="col">'. 147 274 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:'). 275 '<p><label for="user_lang">'.__('User language:'). 158 276 form::combo('user_lang',$lang_combo,$user_lang,'l10n',10).'</label></p>'. 159 277 160 '<p><label >'.__('User timezone:').278 '<p><label for="user_tz">'.__('User timezone:'). 161 279 form::combo('user_tz',dt::getZones(true,true),$user_tz,'',11).'</label></p>'. 162 280 163 '<p><label class="classic">'.164 form::checkbox('user_wysiwyg',1,$user_options['enable_wysiwyg'],'',12).' '.165 __('Enable WYSIWYG mode').'</label></p>'.166 281 '</div>'. 167 282 '</div>'. 168 283 '<br class="clear" />'. //Opera sucks 169 284 '</fieldset>'; 170 171 # --BEHAVIOR-- adminPreferencesForm172 $core->callBehavior('adminPreferencesForm',$core);173 285 174 286 if ($core->auth->allowPassChange()) … … 178 290 '<legend>'.__('Change your password').'</legend>'. 179 291 180 '<p><label >'.__('New password:').292 '<p><label for="new_pwd">'.__('New password:'). 181 293 form::password('new_pwd',20,255,'','',30).'</label></p>'. 182 294 183 '<p><label >'.__('Confirm password:').295 '<p><label for="new_pwd_c">'.__('Confirm password:'). 184 296 form::password('new_pwd_c',20,255,'','',31).'</label></p>'. 185 297 '</fieldset>'. … … 187 299 '<fieldset>'. 188 300 '<p>'.__('If you want to change your email or password you must provide your current password.').'</p>'. 189 '<p><label >'.__('Your password:').301 '<p><label for="cur_pwd">'.__('Your password:'). 190 302 form::password('cur_pwd',20,255,'','',32).'</label></p>'. 191 303 '</fieldset>'; … … 198 310 '</form>'; 199 311 312 echo '</div>'; 313 314 # User options : some from actual user profile, dashboard modules, ... 315 echo '<div class="multi-part" id="user-options" title="'.__('My options').'">'; 316 317 echo 318 '<form action="preferences.php" method="post" id="user-form">'. 319 '<fieldset><legend>'.__('My options').'</legend>'. 320 321 '<p><label for="user_post_format">'.__('Preferred format:'). 322 form::combo('user_post_format',$formaters_combo,$user_options['post_format'],'',7).'</label></p>'. 323 324 '<p><label for="user_post_status">'.__('Default entry status:'). 325 form::combo('user_post_status',$status_combo,$user_post_status,'',8).'</label></p>'. 326 327 '<p><label for="user_edit_size">'.__('Entry edit field height:'). 328 form::field('user_edit_size',5,4,(integer) $user_options['edit_size'],'',9).'</label></p>'. 329 330 '<p><label for="user_wysiwyg" class="classic">'. 331 form::checkbox('user_wysiwyg',1,$user_options['enable_wysiwyg'],'',12).' '. 332 __('Enable WYSIWYG mode').'</label></p>'. 333 '<br class="clear" />'. //Opera sucks 334 '</fieldset>'; 335 336 # --BEHAVIOR-- adminPreferencesForm 337 $core->callBehavior('adminPreferencesForm',$core); 338 339 echo 340 '<p class="clear">'. 341 $core->formNonce(). 342 '<input type="submit" accesskey="s" value="'.__('Save').'" tabindex="33" /></p>'. 343 '</form>'; 344 345 echo '</div>'; 346 347 # User favorites 348 echo '<div class="multi-part" id="user-favorites" title="'.__('My favorites').'">'; 349 $ws = $core->auth->user_prefs->addWorkspace('favorites'); 350 echo '<form action="preferences.php" method="post" id="favs-form">'; 351 echo '<div class="two-cols">'; 352 echo '<div class="col70">'; 353 echo '<fieldset id="my-favs"><legend>'.__('My favorites').'</legend>'; 354 $count = 0; 355 foreach ($ws->dumpPrefs() as $k => $v) { 356 // User favorites only 357 if (!$v['global']) { 358 $fav = unserialize($v['value']); 359 if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) { 360 if ($count == 0) echo '<ul>'; 361 $count++; 362 echo '<li id="fu-'.$k.'">'. 363 '<img src="'.$fav['large-icon'].'" alt="" /> '. 364 '<span>'.form::field(array('order['.$k.']'),2,3,$count).'</span>'. 365 '<label for="fuk-'.$k.'">'.form::checkbox(array('remove[]','fuk-'.$k),$k).$fav['title'].'</label>'. 366 '</li>'; 367 } 368 } 369 } 370 if ($count > 0) echo '</ul>'; 371 if ($count > 0) { 372 echo 373 '<div class="clear">'. 374 '<p class="col">'.form::hidden('favs_order',''). 375 $core->formNonce(). 376 '<input type="submit" name="saveorder" value="'.__('Save order').'"></p>'. 377 378 '<p class="right"><input type="submit" class="delete" name="removeaction"'. 379 'value="'.__('Delete selected favorites').'" '. 380 'onclick="return window.confirm(\''.html::escapeJS( 381 __('Are you sure you want to remove selected favorites?')).'\');" /></p>'. 382 '</div>'; 383 } else { 384 echo 385 '<p>'.__('Currently no personal favorites.').'</p>'; 386 } 387 388 echo '</fieldset>'; 389 390 echo '<div id="default-favs"><h3>'.__('Default favorites').'</h3>'; 391 echo '<p class="form-note clear">'.__('Those favorites are displayed when My Favorites list is empty.').'</p>'; 392 $count = 0; 393 foreach ($ws->dumpPrefs() as $k => $v) { 394 // Global favorites only 395 if ($v['global']) { 396 $fav = unserialize($v['value']); 397 if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) { 398 if ($count == 0) echo '<ul class="fav-list">'; 399 $count++; 400 echo '<li id="fd-'.$k.'">'. 401 '<img src="'.$fav['small-icon'].'" alt="" /> '.$fav['title'].'</li>'; 402 } 403 } 404 } 405 if ($count > 0) echo '</ul>'; 406 echo '</div>'; 407 echo '</div>'; 408 echo '<div class="col30" id="available-favs">'; 409 # Available favorites 410 echo '<fieldset><legend>'.__('Available favorites').'</legend>'; 411 $count = 0; 412 $array = $_fav; 413 function cmp($a,$b) { 414 if ($a[1] == $b[1]) { 415 return 0; 416 } 417 return ($a[1] < $b[1]) ? -1 : 1; 418 } 419 uasort($array,'cmp'); 420 foreach ($array as $k => $fav) { 421 if (($fav[5] == '*') || $core->auth->check($fav[5],$core->blog->id)) { 422 if ($count == 0) echo '<ul class="fav-list">'; 423 $count++; 424 echo '<li id="fa-'.$fav[0].'">'.'<label for="fak-'.$fav[0].'">'. 425 '<span class="minimal">'.form::checkbox(array('append[]','fak-'.$fav[0]),$k).'</span>'. 426 '<img src="'.$fav[3].'" alt="" /> '.'<span class="zoom"><img src="'.$fav[4].'" alt="" /></span>'.$fav[1]. 427 '</label>'.'</li>'; 428 } 429 } 430 if ($count > 0) echo '</ul>'; 431 echo 432 '<p>'. 433 $core->formNonce(). 434 '<input type="submit" name="appendaction" value="'.__('Add to my favorites').'"></p>'; 435 echo '</div>'; 436 echo '</div>'; # Two-cols 437 echo '</form>'; 438 echo '</div>'; # user-favorites 439 200 440 dcPage::helpBlock('core_user_pref'); 201 441 dcPage::close();
Note: See TracChangeset
for help on using the changeset viewer.