]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/UserPreferences.php
oops. some missing plugin changes
[SourceForge/phpwiki.git] / lib / plugin / UserPreferences.php
1 <?php // -*-php-*-
2 rcs_id('$Id: UserPreferences.php,v 1.3 2002-08-22 23:32:33 rurban Exp $');
3 /**
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.
7  */
8 class WikiPlugin_UserPreferences
9 extends WikiPlugin
10 {
11     var $bool_args;
12
13     function getName () {
14         return _("UserPreferences");
15     }
16
17     function getDefaultArguments() {
18         global $request;
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);
24             $userid = $pages[0];
25         } else {
26             // take current user
27             $userid = $user->_userid;
28         }
29         return array('userid'           => $userid, // current or the one from the SubPage
30                      'changePass'       => $user->mayChangePassword(),
31                      'changeTheme'      => true,
32                      'email'            => true,
33                      'notifyPages'      => true,
34                      'editAreaSize'     => true,
35                      'timeOffset'       => true,
36                      'relativeDates'    => true
37                      );
38     }
39    
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;
47             }
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);
50         }
51         if ($user->isAuthenticated() and $args['userid'] == $user->_userid) {
52             if ($request->isPost()) {
53                 if ($request->_prefs) 
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.');
60             } 
61             $available_themes = array();
62             $dir_root = PHPWIKI_DIR . '/themes/'; 
63             $dir = dir($dir_root);
64             if ($dir) {
65                     while($entry = $dir->read()) {
66                         if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.')) {
67                             array_push($available_themes,$entry);
68                         }
69                     }
70                     $dir->close();
71             }
72             $args['available_themes'] = $available_themes;
73             return Template('userprefs', $args);
74         } else {
75             return $user->PrintLoginForm (&$request, $args, false, false);
76         }
77     }
78 };
79
80 // For emacs users
81 // Local Variables:
82 // mode: php
83 // tab-width: 8
84 // c-basic-offset: 4
85 // c-hanging-comment-ender-p: nil
86 // indent-tabs-mode: nil
87 // End:
88 ?>