2 rcs_id('$Id: UserPreferences.php,v 1.9 2003-09-13 21:53:41 carstenklapp Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Plugin to allow any user to adjust his own preferences.
25 * This must be used in the page "UserPreferences" or in a subpage of a
26 * user called like HomePage/Preferences.
28 class WikiPlugin_UserPreferences
34 return _("UserPreferences");
37 function getVersion() {
38 return preg_replace("/[Revision: $]/", '',
42 function getDefaultArguments() {
44 $pagename = $request->getArg('pagename');
45 $user = $request->getUser();
46 // for a UserPage/Prefences plugin default to this userid
47 if (isSubPage($pagename)) {
48 $pages = explode(SUBPAGE_SEPARATOR,$pagename);
52 $userid = $user->_userid;
54 return array('userid' => $userid, // current or the one from the SubPage
55 'changePass' => $user->mayChangePassword(),
58 'notifyPages' => true,
59 'editAreaSize' => true,
62 'lang' => DEFAULT_LANGUAGE,
63 'relativeDates' => true
67 function run($dbi, $argstr, $request) {
68 $args = $this->getArgs($argstr, $request);
69 $user = &$request->getUser();
70 if (! $request->isActionPage($request->getArg('pagename'))) {
71 $no_args = $this->getDefaultArguments();
72 foreach ($no_args as $key => $value) {
73 $no_args[$value] = false;
75 $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()));
76 $no_args['isForm'] = false;
77 return Template('userprefs', $no_args);
79 if ($user->isAuthenticated() and $args['userid'] == $user->_userid) {
80 if ($request->isPost()) {
81 if ($request->_prefs) {
82 $pref = $request->_prefs;
83 } else { // hmm. already handled somewhere else...
84 $pref = new UserPreferences($request->getArg('pref'));
86 // Fixme: How to update the Theme? Correct update?
87 $num = $request->_user->SetPreferences($pref);
89 $errmsg = _("No changes.");
91 $errmsg = fmt("%d UserPreferences fields successfully updated.", $num);
93 $args['errmsg'] = HTML(HTML::h2($errmsg),HTML::hr());
95 $available_themes = array();
96 $dir_root = 'themes/';
97 if (defined('PHPWIKI_DIR'))
98 $dir_root = PHPWIKI_DIR . "/$dir_root";
99 $dir = dir($dir_root);
101 while($entry = $dir->read()) {
102 if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.') and
104 array_push($available_themes,$entry);
109 $args['available_themes'] = $available_themes;
111 $available_languages = array('en');
112 $dir_root = 'locale/';
113 if (defined('PHPWIKI_DIR'))
114 $dir_root = PHPWIKI_DIR . "/$dir_root";
115 $dir = dir($dir_root);
117 while($entry = $dir->read()) {
118 if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.') and
119 $entry != 'po' and $entry != 'CVS') {
120 array_push($available_languages,$entry);
125 $args['available_languages'] = $available_languages;
127 return Template('userprefs', $args);
129 return $user->PrintLoginForm ($request, $args, false, false);
134 // $Log: not supported by cvs2svn $
141 // c-hanging-comment-ender-p: nil
142 // indent-tabs-mode: nil