]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/UserPreferences.php
LANG still broken, working on better locale handling.
[SourceForge/phpwiki.git] / lib / plugin / UserPreferences.php
1 <?php // -*-php-*-
2 rcs_id('$Id: UserPreferences.php,v 1.6 2002-08-27 21:51:31 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                      'appearance'       => 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'] = HTML(HTML::h2(_("Error: The page with the UserPreferences plugin must be valid WikiWord or a Preferences subpage of the users HomePage. Sorry, UserPreferences cannot be saved."),HTML::hr()));
49             $no_args['isForm'] = false;
50             return Template('userprefs', $no_args);
51         }
52         if ($user->isAuthenticated() and $args['userid'] == $user->_userid) {
53             if ($request->isPost()) {
54                 if ($request->_prefs) {
55                   $pref = $request->_prefs;
56                 } else { // hmm. already handled somewhere else...
57                   $pref = new UserPreferences($request->getArg('pref'));
58                 }
59                 // Fixme: How to update the Theme? Correct update?
60                 $num = $request->_user->SetPreferences($pref);
61                 if (!$num) {
62                     $errmsg = _("No changes.");
63                 } else {
64                     $errmsg = fmt("%d UserPreferences fields successfully updated.", $num);
65                 }
66                 $args['errmsg'] = HTML(HTML::h2($errmsg),HTML::hr());
67             }
68             $available_themes = array(); 
69             $dir_root = PHPWIKI_DIR . '/themes/'; 
70             $dir = dir($dir_root);
71             if ($dir) {
72                 while($entry = $dir->read()) {
73                     if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.') and 
74                         $entry!='CVS') {
75                         array_push($available_themes,$entry);
76                     }
77                 }
78                 $dir->close();
79             }
80             $args['available_themes'] = $available_themes;
81
82             $available_languages = array('en');
83             $dir_root = PHPWIKI_DIR . '/locale/'; 
84             $dir = dir($dir_root);
85             if ($dir) {
86                 while($entry = $dir->read()) {
87                     if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.') and 
88                         $entry != 'po' and $entry != 'CVS') {
89                         array_push($available_languages,$entry);
90                     }
91                 }
92                 $dir->close();
93             }
94             $args['available_languages'] = $available_languages;
95
96             return Template('userprefs', $args);
97         } else {
98             return $user->PrintLoginForm (&$request, $args, false, false);
99         }
100     }
101 };
102
103 // For emacs users
104 // Local Variables:
105 // mode: php
106 // tab-width: 8
107 // c-basic-offset: 4
108 // c-hanging-comment-ender-p: nil
109 // indent-tabs-mode: nil
110 // End:
111 ?>