Source for file preferences.php
Documentation is available at preferences.php
* @copyright (c) 2004-15 bitweaver.org
require_once( '../kernel/setup_inc.php' );
// User preferences screen
$gBitSystem->verifyFeature( 'users_preferences' );
$gBitUser->verifyRegistered();
// set up the user we're editing
if( !empty( $_REQUEST["view_user"] ) && $_REQUEST["view_user"] <> $gBitUser->mUserId ) {
$userClass = $gBitSystem->getConfig( 'user_class', (defined('ROLE_MODEL') ) ? 'RolePermUser' : 'BitPermUser' );
$editUser = new $userClass( $_REQUEST["view_user"] );
$gBitSmarty->assign('view_user', $_REQUEST["view_user"]);
$watches = $editUser->getWatches();
$gBitSmarty->assign('watches', $watches );
$gQueryUserId = &$editUser->mUserId;
$parsedUrl = parse_url( $_SERVER["REQUEST_URI"] );
// settings only applicable when the wiki package is active
if( $gBitSystem->isPackageActive( 'wiki' )) {
include_once( WIKI_PKG_PATH. 'BitPage.php' );
$parsedUrl1 = str_replace( USERS_PKG_URL. "user_preferences", WIKI_PKG_URL. "edit", $parsedUrl["path"] );
$parsedUrl2 = str_replace( USERS_PKG_URL. "user_preferences", WIKI_PKG_URL. "index", $parsedUrl["path"] );
$gBitSmarty->assign( 'url_edit', httpPrefix(). $parsedUrl1 );
$gBitSmarty->assign( 'url_visit', httpPrefix(). $parsedUrl2 );
$gBitSmarty->assign('customFields', $customFields );
// include preferences settings from other packages - these will be included as individual tabs
$includeFiles = $gBitSystem->getIncludeFiles( 'user_preferences_inc.php', 'user_preferences_inc.tpl' );
foreach( $includeFiles as $file ) {
require_once( $file['php'] );
$gBitSmarty->assign( 'includFiles', $includeFiles );
// fetch available languages
$gBitLanguage->mLanguage = $editUser->getPreference( 'bitlanguage', $gBitLanguage->mLanguage );
$gBitSmarty->assign( 'gBitLanguage', $gBitLanguage );
// allow users to set their preferred site style - this option is only available when users can set the site-wide theme
if( $gBitSystem->getConfig( 'users_themes' ) == 'y' ) {
if( !empty( $_REQUEST['prefs'] )) {
if( !empty( $_REQUEST['style'] ) && $_REQUEST['style'] != $gBitSystem->getConfig( 'style' ) ) {
$editUser->storePreference( 'theme', $_REQUEST["style"] );
$editUser->storePreference( 'theme', NULL );
$assignStyle = $_REQUEST["style"];
$styles = $gBitThemes->getStyles( NULL, TRUE, TRUE );
$gBitSmarty->assign_by_ref( 'styles', $styles );
if( !isset ( $_REQUEST["style"] )) {
$assignStyle = $editUser->getPreference( 'theme' );
$gBitSmarty->assign( 'assignStyle', $assignStyle );
// process the preferences form
if( isset ( $_REQUEST["prefs"] )) {
if ( !$editUser->store( $_REQUEST ) ) {
$feedback['error'] = $editUser->mErrors;
'users_homepage' => NULL,
'site_display_utc' => 'Local',
'site_display_timezone' => 'UTC',
'users_information' => 'public',
'users_email_display' => 'n',
if( $_REQUEST['site_display_utc'] != 'Fixed' ) {
unset ( $_REQUEST['site_display_timezone'] );
$editUser->storePreference( 'site_display_timezone', NULL, USERS_PKG_NAME );
$editUser->storePreference( 'site_display_timezone', $_REQUEST['site_display_timezone'], USERS_PKG_NAME );
// we don't have to store http:// in the db
if( empty( $_REQUEST['users_homepage'] ) || $_REQUEST['users_homepage'] == 'http://' ) {
unset ( $_REQUEST['users_homepage'] );
} elseif( !preg_match( '/^http:\/\//', $_REQUEST['users_homepage'] )) {
$_REQUEST['users_homepage'] = 'http://'. $_REQUEST['users_homepage'];
foreach( $prefs as $pref => $default ) {
if( !empty( $_REQUEST[$pref] ) && $_REQUEST[$pref] != $default ) {
//vd( "storePreference( $pref, $_REQUEST[$pref], USERS_PKG_NAME )" );
$editUser->storePreference( $pref, $_REQUEST[$pref], USERS_PKG_NAME );
$editUser->storePreference( $pref, NULL, USERS_PKG_NAME );
$editUser->storePreference( 'bitlanguage', ( $_REQUEST['bitlanguage'] != $gBitLanguage->mLanguage ) ? $_REQUEST['bitlanguage'] : NULL, LANGUAGES_PKG_NAME );
'users_double_click' => USERS_PKG_NAME,
foreach( $toggles as $toggle => $package ) {
if( isset ( $_REQUEST[$toggle] )) {
$editUser->storePreference( $toggle, 'y', $package );
$editUser->storePreference( $toggle, NULL, $package );
if( isset ( $customFields ) && is_array( $customFields )) {
foreach( $customFields as $f ) {
if( isset ( $_REQUEST['CUSTOM'][$f] )) {
$editUser->storePreference( trim( $f ), trim( $_REQUEST['CUSTOM'][$f] ), USERS_PKG_NAME );
// we need to reload the page for all the included user preferences
if( isset ( $_REQUEST['view_user'] )) {
bit_redirect ( USERS_PKG_URL. "preferences.php?view_user=$editUser->mUserId" );
if( isset ( $_REQUEST['chgemail'] )) {
if( !$gBitUser->hasPermission( 'p_users_admin' ) && !$editUser->validate( $editUser->mUsername, $_REQUEST['pass'], '', '' )) {
$gBitSystem->fatalError( tra("Invalid password. Your current password is required to change your email address." ));
$org_email = $editUser->getField( 'email' );
if( $editUser->changeUserEmail( $editUser->mUserId, $_REQUEST['email'] )) {
$feedback['success'] = tra( 'Your email address was updated successfully' );
/* this file really needs a once over
we need to call services when various preferences are stored
for now my need is when the email address is changed. when the
need expands to more we can look at cleaning up this file
into something more sane. happy to help out at that time -wjames5
$paramHash['org_email'] = $org_email;
$editUser->invokeServices( 'content_store_function', $_REQUEST );
$feedback['error'] = $editUser->mErrors;
if( isset ( $_REQUEST["chgpswd"] )) {
if( $_REQUEST["pass1"] != $_REQUEST["pass2"] ) {
$gBitSystem->fatalError( tra("The passwords didn't match" ));
if( !$gBitUser->hasPermission( 'p_users_admin' ) && !$editUser->validate( $editUser->getField( 'email' ), $_REQUEST["old"], '', '' )) {
$gBitSystem->fatalError( tra( "Invalid old password" ));
$users_min_pass_length = $gBitSystem->getConfig( 'users_min_pass_length', 4 );
if( strlen( $_REQUEST["pass1"] ) < $users_min_pass_length ) {
$gBitSystem->fatalError( tra( "Password should be at least" ). ' '. $users_min_pass_length. ' '. tra( "characters long" ));
$gBitSystem->fatalError( tra( "Password must contain both letters and numbers" ));
if( $editUser->storePassword( $_REQUEST["pass1"] )) {
$feedback['success'] = tra( 'The password was updated successfully' );
// this should go in tidbits
if( isset ( $_REQUEST['tasksprefs'] )) {
$editUser->storePreference( 'tasks_max_records', $_REQUEST['tasks_max_records'], 'users' );
if( isset ( $_REQUEST['tasks_use_dates'] ) && $_REQUEST['tasks_use_dates'] == 'on' ) {
$editUser->storePreference( 'tasks_use_dates', 'y', 'users' );
$editUser->storePreference( 'tasks_use_dates', 'n', 'users' );
// get available languages
$languages = $gBitLanguage->listLanguages();
$gBitSmarty->assign_by_ref( 'languages', $languages );
if( strstr( $file, ".gif" )) {
$gBitSmarty->assign( 'flags', $flags );
$editUser->mInfo['users_homepage'] = $editUser->getPreference( 'users_homepage', '' );
$gBitSmarty->assign( 'editUser', $editUser );
$gBitSmarty->assign( 'gContent', $editUser ); // also assign to gContent to make services happy
$gBitSmarty->assign( 'feedback', $feedback );
/* This should come from BitDate->get_timezone_list but that seems to rely on a global from PEAR that does not exist. */
$user_timezones = DateTimeZone::listIdentifiers();
for($i=- 12;$i<= 12;$i++ ) {
$user_timezones[$i * 60 * 60] = $i; // Stored offset needs to be in seconds.
$gBitSmarty->assign( 'userTimezones', $user_timezones);
// email scrambling methods
$scramblingMethods = array( "n", "strtr", "unicode", "x" );
$gBitSmarty->assign_by_ref( 'scramblingMethods', $scramblingMethods );
$scramblingEmails = array(
$gBitSmarty->assign_by_ref( 'scramblingEmails', $scramblingEmails );
$editUser->invokeServices( 'content_edit_function' );
$gBitSystem->display( 'bitpackage:users/user_preferences.tpl', 'Edit User Preferences' , array( 'display_mode' => 'display' ));
|