2 rcs_id('$Id: UserPreferences.php,v 1.5 2002-08-23 21:54:30 rurban Exp $');
4 * Plugin to allow any user to adjust his own preferences.
5 * This must be used in the page "UserPreferences" or in a subpage of a
6 * user called like HomePage/Preferences.
8 class WikiPlugin_UserPreferences
14 return _("UserPreferences");
17 function getDefaultArguments() {
19 $pagename = $request->getArg('pagename');
20 $user = $request->getUser();
21 // for a UserPage/Prefences plugin default to this userid
22 if (isSubPage($pagename)) {
23 $pages = explode(SUBPAGE_SEPARATOR,$pagename);
27 $userid = $user->_userid;
29 return array('userid' => $userid, // current or the one from the SubPage
30 'changePass' => $user->mayChangePassword(),
33 'notifyPages' => true,
34 'editAreaSize' => true,
36 'relativeDates' => true
40 function run($dbi, $argstr, $request) {
41 $args = $this->getArgs($argstr, $request);
42 $user = &$request->getUser();
43 if (! $request->isActionPage($request->getArg('pagename'))) {
44 $no_args = $this->getDefaultArguments();
45 foreach ($no_args as $key => $value) {
46 $no_args[$value] = false;
48 $no_args['errmsg'] = _("Error: The page with the UserPreferences plugin must be valid WikiWord or a Preferences subpage of the users HomePage. Sorry, UserPreferences cannot be saved.");
49 return Template('userprefs', $no_args);
51 if ($user->isAuthenticated() and $args['userid'] == $user->_userid) {
52 if ($request->isPost()) {
54 $pref = $request->_prefs;
55 else // hmm. already handled somewhere else...
56 $pref = new UserPreferences($request->getArg('pref'));
57 // Fixme: How to update the Theme? Correct update?
58 $request->_user->SetPreferences($pref);
59 $args['errmsg'] = _("Preferences successfully updated.");
61 $available_themes = array();
62 $dir_root = PHPWIKI_DIR . '/themes/';
63 $dir = dir($dir_root);
65 while($entry = $dir->read()) {
66 if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.') and
68 array_push($available_themes,$entry);
73 $args['available_themes'] = $available_themes;
75 $available_languages = array('en');
76 $dir_root = PHPWIKI_DIR . '/locale/';
77 $dir = dir($dir_root);
79 while($entry = $dir->read()) {
80 if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.') and
81 $entry != 'po' and $entry != 'CVS') {
82 array_push($available_languages,$entry);
87 $args['available_languages'] = $available_languages;
89 return Template('userprefs', $args);
91 return $user->PrintLoginForm (&$request, $args, false, false);
101 // c-hanging-comment-ender-p: nil
102 // indent-tabs-mode: nil