-
Notifications
You must be signed in to change notification settings - Fork 2
/
preferences.php
268 lines (232 loc) · 9.49 KB
/
preferences.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
/**
* user preferences
*
* @copyright (c) 2004-15 bitweaver.org
*
* @package users
* @subpackage functions
*/
/**
* required setup
*/
require_once( '../kernel/includes/setup_inc.php' );
// User preferences screen
$gBitSystem->verifyFeature( 'users_preferences' );
$gBitUser->verifyRegistered();
$feedback = array();
// set up the user we're editing
if( !empty( $_REQUEST["view_user"] ) && $_REQUEST["view_user"] <> $gBitUser->mUserId ) {
$gBitSystem->verifyPermission( 'p_users_admin' );
$userClass = $gBitSystem->getConfig( 'user_class', (defined('ROLE_MODEL') ) ? 'RolePermUser' : 'BitPermUser' );
$editUser = new $userClass( $_REQUEST["view_user"] );
$editUser->load( TRUE );
$gBitSmarty->assign('view_user', $_REQUEST["view_user"]);
$watches = $editUser->getWatches();
$gBitSmarty->assign('watches', $watches );
} else {
$gBitUser->load( TRUE );
$editUser = &$gBitUser;
}
global $gQueryUserId;
$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_CLASS_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 );
}
// custom user fields
if( $gBitSystem->isFeatureActive( 'custom_user_fields' )) {
$customFields= explode( ',', $gBitSystem->getConfig( 'custom_user_fields' ) );
$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 ) {
if( !empty( $file['php'] ) && is_file( $file['php'] ) ) {
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"] );
} else {
$editUser->storePreference( 'theme', NULL );
}
$assignStyle = $_REQUEST["style"];
}
$styles = $gBitThemes->getStyles( NULL, TRUE, TRUE );
$gBitSmarty->assignByRef( '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;
} else {
// preferences
$prefs = array(
'users_homepage' => NULL,
'site_display_utc' => 'Local',
'site_display_timezone' => 'UTC',
'users_country' => NULL,
'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 );
} else {
$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 ) {
$editUser->storePreference( $pref, $_REQUEST[$pref], USERS_PKG_NAME );
} else {
$editUser->storePreference( $pref, NULL, USERS_PKG_NAME );
}
}
if( $gBitSystem->isFeatureActive( 'users_change_language' )) {
$editUser->storePreference( 'bitlanguage', ( $_REQUEST['bitlanguage'] != $gBitLanguage->mLanguage ) ? $_REQUEST['bitlanguage'] : NULL, LANGUAGES_PKG_NAME );
}
/*/ toggles
$toggles = array(
);
foreach( $toggles as $toggle => $package ) {
if( isset( $_REQUEST[$toggle] )) {
$editUser->storePreference( $toggle, 'y', $package );
} else {
$editUser->storePreference( $toggle, NULL, $package );
}
}
*/
// process custom fields
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" );
} else {
bit_redirect ( USERS_PKG_URL."preferences.php" );
}
}
}
// change email address
if( isset( $_REQUEST['chgemail'] )) {
// check user's password
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 = $_REQUEST;
$paramHash['org_email'] = $org_email;
$editUser->invokeServices( 'content_store_function', $_REQUEST );
} else {
$feedback['error'] = $editUser->mErrors;
}
}
// change user password
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" ));
}
//Validate password here
$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" ));
}
// Check this code
if( $gBitSystem->isFeatureActive( 'users_pass_chr_num' )) {
if (!preg_match_all("/[0-9]+/", $_REQUEST["pass1"], $parsedUrl ) || !preg_match_all("/[A-Za-z]+/", $_REQUEST["pass1"], $parsedUrl )) {
$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' );
} else {
$editUser->storePreference( 'tasks_use_dates', 'n', 'users' );
}
}
// get available languages
$languages = array();
$languages = $gBitLanguage->listLanguages();
$gBitSmarty->assignByRef( 'languages', $languages );
// Get flags
$flags = array();
$h = opendir( USERS_PKG_PATH.'icons/flags/' );
while( $file = readdir( $h )) {
if( strstr( $file, ".gif" )) {
$flags[] = preg_replace( "/\.gif/", "", $file );
}
}
closedir( $h );
sort( $flags );
$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. */
if ( version_compare( phpversion(), "5.2.0", ">=" ) ) {
$user_timezones = DateTimeZone::listIdentifiers();
} else {
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->assignByRef( 'scramblingMethods', $scramblingMethods );
$scramblingEmails = array(
tra( "no" ),
scramble_email( $editUser->mInfo['email'], 'strtr' ),
scramble_email( $editUser->mInfo['email'], 'unicode' )."-".tra( "unicode" ),
scramble_email( $editUser->mInfo['email'], 'x' )
);
$gBitSmarty->assignByRef( 'scramblingEmails', $scramblingEmails );
// edit services
$editUser->invokeServices( 'content_edit_function' );
$gBitSystem->display( 'bitpackage:users/user_preferences.tpl', 'Edit User Preferences' , array( 'display_mode' => 'display' ));