From 0440ff150cefe9088c8aa126e646f901c69a7793 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 25 Jan 2006 01:07:31 +0100 Subject: user manager plugin darcs-hash:20060125000731-9b6ab-f42d90c270edd795038b814516a1da90c0824e71.gz --- lib/plugins/usermanager/admin.php | 420 +++++++++++++++++++++++++++ lib/plugins/usermanager/images/search.png | Bin 0 -> 733 bytes lib/plugins/usermanager/images/user_edit.png | Bin 0 -> 1058 bytes lib/plugins/usermanager/lang/de/add.txt | 1 + lib/plugins/usermanager/lang/de/delete.txt | 1 + lib/plugins/usermanager/lang/de/edit.txt | 1 + lib/plugins/usermanager/lang/de/intro.txt | 1 + lib/plugins/usermanager/lang/de/lang.php | 48 +++ lib/plugins/usermanager/lang/de/list.txt | 1 + lib/plugins/usermanager/lang/en/add.txt | 1 + lib/plugins/usermanager/lang/en/delete.txt | 1 + lib/plugins/usermanager/lang/en/edit.txt | 1 + lib/plugins/usermanager/lang/en/intro.txt | 1 + lib/plugins/usermanager/lang/en/lang.php | 49 ++++ lib/plugins/usermanager/lang/en/list.txt | 1 + lib/plugins/usermanager/lang/fr/add.txt | 1 + lib/plugins/usermanager/lang/fr/delete.txt | 1 + lib/plugins/usermanager/lang/fr/edit.txt | 1 + lib/plugins/usermanager/lang/fr/intro.txt | 1 + lib/plugins/usermanager/lang/fr/lang.php | 25 ++ lib/plugins/usermanager/lang/fr/list.txt | 2 + 21 files changed, 558 insertions(+) create mode 100644 lib/plugins/usermanager/admin.php create mode 100644 lib/plugins/usermanager/images/search.png create mode 100644 lib/plugins/usermanager/images/user_edit.png create mode 100644 lib/plugins/usermanager/lang/de/add.txt create mode 100644 lib/plugins/usermanager/lang/de/delete.txt create mode 100644 lib/plugins/usermanager/lang/de/edit.txt create mode 100644 lib/plugins/usermanager/lang/de/intro.txt create mode 100644 lib/plugins/usermanager/lang/de/lang.php create mode 100644 lib/plugins/usermanager/lang/de/list.txt create mode 100644 lib/plugins/usermanager/lang/en/add.txt create mode 100644 lib/plugins/usermanager/lang/en/delete.txt create mode 100644 lib/plugins/usermanager/lang/en/edit.txt create mode 100644 lib/plugins/usermanager/lang/en/intro.txt create mode 100644 lib/plugins/usermanager/lang/en/lang.php create mode 100644 lib/plugins/usermanager/lang/en/list.txt create mode 100644 lib/plugins/usermanager/lang/fr/add.txt create mode 100644 lib/plugins/usermanager/lang/fr/delete.txt create mode 100644 lib/plugins/usermanager/lang/fr/edit.txt create mode 100644 lib/plugins/usermanager/lang/fr/intro.txt create mode 100644 lib/plugins/usermanager/lang/fr/lang.php create mode 100644 lib/plugins/usermanager/lang/fr/list.txt (limited to 'lib') diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php new file mode 100644 index 000000000..6952a6cf2 --- /dev/null +++ b/lib/plugins/usermanager/admin.php @@ -0,0 +1,420 @@ + + * @author Chris Smith + */ +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +if(!defined('DOKU_PLUGIN_IMAGES')) define('DOKU_PLUGIN_IMAGES',DOKU_BASE.'lib/plugins/usermanager/images/'); +require_once(DOKU_PLUGIN.'admin.php'); + +/** + * All DokuWiki plugins to extend the admin function + * need to inherit from this class + */ +class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { + + var $_auth = null; // auth object + var $_user_total = 0; // number of registered users + var $_filter = array(); // user selection filter(s) + var $_start = 0; // index of first user to be displayed + var $_last = 0; // index of the last user to be displayed + var $_pagesize = 20; // number of users to list on one page + var $_user_edit = null; // set to user selected for editing + + /** + * Constructor + */ + function admin_plugin_usermanager(){ + global $auth; + + $this->setupLocale(); + if (isset($auth)) $this->_auth = & $auth; + } + + /** + * return some info + */ + function getInfo(){ + $disabled = is_null($this->_auth) ? '(disabled)' : ''; + + return array( + 'author' => 'Chris Smith', + 'email' => 'chris@jalakai.co.uk', + 'date' => '2005-11-24', + 'name' => 'User Manager', + 'desc' => 'Manage users '.$disabled, + 'url' => 'http://wiki.splitbrain.org/plugin:user_manager', + ); + } + /** + * return prompt for admin menu + */ + function getMenuText($language) { + + if (!is_null($this->_auth)) + return parent::getMenuText($language); + + return $this->getLang["menu"]." (objectified auth only)"; + } + + /** + * return sort order for position in admin menu + */ + function getMenuSort() { + return 2; + } + + /** + * handle user request + */ + function handle() { + global $ID; + + if (is_null($this->_auth)) return false; + + // extract the command and any specific parameters + // submit button name is of the form - fn[cmd][param(s)] + $fn = $_REQUEST['fn']; + + if (is_array($fn)) { + $cmd = key($fn); + $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null; + } else { + $cmd = $fn; + $param = null; + } + + if ($cmd != "search") { + $this->_start = $_REQUEST['start']; + $this->_filter = $this->_retrieveFilter(); + } + + switch($cmd){ + case "add" : $this->_addUser(); break; + case "delete" : $this->_deleteUser(); break; + case "modify" : $this->_modifyUser(); break; + case "edit" : $this->_edit_user = $param; break; // no extra handling required - only html + case "search" : $this->_setFilter($param); + $this->_start = 0; + break; + } + + $this->_user_total = $this->_auth->getUserCount($this->_filter); + + // page handling + switch($cmd){ + case 'start' : $this->_start = 0; break; + case 'prev' : $this->_start -= $this->_pagesize; break; + case 'next' : $this->_start += $this->_pagesize; break; + case 'last' : $this->_start = $this->_user_total; break; + } + $this->_validatePagination(); + } + + /** + * output appropriate html + */ + function html() { + global $ID; + + if(is_null($this->_auth)) { + print $this->lang['badauth']; + return false; + } + + $user_list = $this->_auth->retrieveUsers($this->_start, $this->_pagesize, $this->_filter); + $users = array_keys($user_list); + + $page_buttons = $this->_pagination(); + $edit_disable = $this->_auth->canDo('modifyUser') ? '' : 'disabled="disabled"'; + $delete_disable = $this->_auth->canDo('deleteUsers') ? '' : 'disabled="disabled"'; + + print $this->locale_xhtml('intro'); + print $this->locale_xhtml('list'); + + ptln("
"); + + if ($this->_user_total) { + ptln("

".sprintf($this->lang['summary'],$this->_start+1,$this->_last,$this->_user_total,$this->_auth->getUserCount())."

"); + } else { + ptln("

".sprintf($this->lang['nonefound'],$this->_auth->getUserCount())."

"); + } + ptln("
"); + ptln(" "); + ptln(" "); + ptln(" "); + ptln(" "); + ptln(" "); + + ptln(" "); +// ptln(" "); + ptln(" "); + ptln(" "); + ptln(" "); + ptln(" "); + ptln(" "); + ptln(" "); + ptln(" "); + + if ($this->_user_total) { + ptln(" "); + foreach ($user_list as $user => $userinfo) { + extract($userinfo); + $groups = join(', ',$grps); + ptln(" "); + ptln(" "); +// ptln(" "); + ptln(" "); + ptln(" "); + ptln(" "); + } + ptln(" "); + } + + ptln(" "); + ptln(" "); + ptln(" "); + ptln("
 ".$this->lang["user_id"]."".$this->lang["user_name"]."".$this->lang["user_mail"]."".$this->lang["user_groups"]."
lang['search']."\" />lang['search_prompt']."\" alt=\"".$this->lang['search']."\" />_htmlFilter('user')."\" />_htmlFilter('name')."\" />_htmlFilter('mail')."\" />_htmlFilter('grps')."\" />
lang['edit']."\"/>lang['edit_prompt']."\" alt=\"".$this->lang['edit']."\"/>".hsc($user)."".hsc($name)."".hsc($mail)."".hsc($groups)."
"); + ptln(" "); + ptln(" lang['delete_selected']."\"/>"); + ptln(" "); + ptln(" "); + ptln(" lang['start']."\" />"); + ptln(" lang['prev']."\" />"); + ptln(" lang['next']."\" />"); + ptln(" lang['last']."\" />"); + ptln(" "); + ptln(" lang['clear']."\" />"); + ptln("
"); + ptln(" "); + ptln(" "); + + $this->_htmlFilterSettings(2); + + ptln("
"); + ptln("
"); + + $style = $this->_edit_user ? " style=\"width: 46%; float: left;\"" : ""; + + if ($this->_auth->canDo('createUser')) { + ptln(""); + print $this->locale_xhtml('add'); + ptln("
"); + + $this->_htmlUserForm('add',null,4); + + ptln("
"); + ptln(""); + } + + if($this->_edit_user && $this->_auth->canDo('modifyUser')){ + ptln(""); + print $this->locale_xhtml('edit'); + ptln("
"); + + $this->_htmlUserForm('modify',$this->_edit_user,4); + + ptln("
"); + ptln(""); + } + } + + function _htmlUserForm($cmd,$user=null,$indent=0) { + + if ($user) { + extract($this->_auth->getUserData($user)); + $groups = join(',',$grps); + } else { + $user = $name = $mail = $groups = ''; + } + + ptln("
",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + ptln("
".$this->lang["field"]."".$this->lang["value"]."
",$indent); + ptln(" ",$indent); + ptln(" ",$indent); + + // save current $user, we need this to access details if the name is changed + if ($user) + ptln(" ",$indent); + + $this->_htmlFilterSettings($indent+10); + + ptln(" lang[$cmd]."\" />",$indent); + ptln("
",$indent); + ptln("
",$indent); + } + + function _htmlFilter($key) { + if (empty($this->_filter)) return ''; + return (isset($this->_filter[$key]) ? hsc($this->_filter[$key]) : ''); + } + + function _htmlFilterSettings($indent=0) { + + ptln("_start."\" />",$indent); + + foreach ($this->_filter as $key => $filter) { + ptln("",$indent); + } + } + + function _addUser(){ + + if (!$this->_auth->canDo('createUser')) return false; + + list($user,$pass,$name,$mail,$grps) = $this->_retrieveUser(); + if (empty($user)) return false; + + return $this->_auth->createUser($user,$pass,$name,$mail,$grps); + } + + /** + * Delete user + */ + function _deleteUser(){ + + if (!$this->_auth->canDo('deleteUsers')) return false; + + $selected = $_REQUEST['delete']; + if (!is_array($selected) || empty($selected)) return false; + $selected = array_keys($selected); + + $count = $this->_auth->deleteUsers($selected); + if ($count == count($selected)) { + $text = str_replace('%d', $count, $this->lang['delete_ok']); + msg("$text.", 1); + } else { + $part1 = str_replace('%d', $count, $this->lang['delete_ok']); + $part2 = str_replace('%d', (count($selected)-$count), $this->lang['delete_fail']); + msg("$part1, $part2",-1); + } + } + + /** + * Modify user + */ + function _modifyUser(){ + if (!$this->_auth->canDo('modifyUser')) return false; + + list($user,$pass,$name,$mail,$grps) = $this->_retrieveUser(); + if (empty($user)) return false; + + $changes = array(); + $user_old = cleanID(preg_replace('/.*:/','',$_REQUEST['userid_old'])); + if ($user != $user_old) { + // check $user doesn't already exist + if ($this->_auth->getUserData($user)) { + msg(sprintf($this->lang['update_exists'],$user),-1); + $this->_edit_user = $user = $user_old; + } else { + $changes['user'] = $user; + $user = $user_old; + } + } + + if (!empty($pass)) $changes['pass'] = $pass; + if (!empty($name)) $changes['name'] = $name; + if (!empty($mail)) $changes['mail'] = $mail; + if (!empty($grps)) $changes['grps'] = $grps; + + if ($this->_auth->modifyUser($user, $changes)) { + msg($this->lang['update_ok'],1); + } else { + msg($this->lang['update_fail'],-1); + } + } + + /* + * retrieve & clean user data from the form + * return an array(user, password, full name, email, array(groups)) + */ + function _retrieveUser($clean=true) { + + $user[0] = ($clean) ? cleanID(preg_replace('/.*:/','',$_REQUEST['userid'])) : $_REQUEST['userid']; + $user[1] = $_REQUEST['userpass']; + $user[2] = $_REQUEST['username']; + $user[3] = $_REQUEST['usermail']; + $user[4] = preg_split('/\s*,\s*/',$_REQUEST['usergroups'],-1,PREG_SPLIT_NO_EMPTY); + + if (is_array($user[4]) && (count($user[4]) == 1) && (trim($user[4][0]) == '')) { + $user[4] = null; + } + + return $user; + } + + function _setFilter($op) { + + $this->_filter = array(); + + if ($op == 'new') { + list($user,$pass,$name,$mail,$grps) = $this->_retrieveUser(false); + + if (!empty($user)) $this->_filter['user'] = $user; + if (!empty($name)) $this->_filter['name'] = $name; + if (!empty($mail)) $this->_filter['mail'] = $mail; + if (!empty($grps)) $this->_filter['grps'] = join('|',$grps); + } + } + + function _retrieveFilter() { + + $t_filter = $_REQUEST['filter']; + if (!is_array($t_filter)) return array(); + + // messy, but this way we ensure we aren't getting any additional crap from malicious users + $filter = array(); + + if (isset($t_filter['user'])) $filter['user'] = $t_filter['user']; + if (isset($t_filter['name'])) $filter['name'] = $t_filter['name']; + if (isset($t_filter['mail'])) $filter['mail'] = $t_filter['mail']; + if (isset($t_filter['grps'])) $filter['grps'] = $t_filter['grps']; + + return $filter; + } + + function _validatePagination() { + + if ($this->_start >= $this->_user_total) { + $this->_start = $this->_user_total - $this->_pagesize; + } + if ($this->_start < 0) $this->_start = 0; + + $this->_last = min($this->_user_total, $this->_start + $this->_pagesize); + } + + /* + * return an array of strings to enable/disable pagination buttons + */ + function _pagination() { + + $buttons['start'] = $buttons['prev'] = ($this->_start == 0) ? 'disabled="disabled"' : ''; + $buttons['last'] = $buttons['next'] = (($this->_start + $this->_pagesize) >= $this->_user_total) ? 'disabled="disabled"' : ''; + + return $buttons; + } +} diff --git a/lib/plugins/usermanager/images/search.png b/lib/plugins/usermanager/images/search.png new file mode 100644 index 000000000..1aa445f03 Binary files /dev/null and b/lib/plugins/usermanager/images/search.png differ diff --git a/lib/plugins/usermanager/images/user_edit.png b/lib/plugins/usermanager/images/user_edit.png new file mode 100644 index 000000000..8ca490eaf Binary files /dev/null and b/lib/plugins/usermanager/images/user_edit.png differ diff --git a/lib/plugins/usermanager/lang/de/add.txt b/lib/plugins/usermanager/lang/de/add.txt new file mode 100644 index 000000000..925fa5042 --- /dev/null +++ b/lib/plugins/usermanager/lang/de/add.txt @@ -0,0 +1 @@ +===== Benutzer hinzufügen ===== diff --git a/lib/plugins/usermanager/lang/de/delete.txt b/lib/plugins/usermanager/lang/de/delete.txt new file mode 100644 index 000000000..4f3bbbd03 --- /dev/null +++ b/lib/plugins/usermanager/lang/de/delete.txt @@ -0,0 +1 @@ +===== Benutzer löschen ===== diff --git a/lib/plugins/usermanager/lang/de/edit.txt b/lib/plugins/usermanager/lang/de/edit.txt new file mode 100644 index 000000000..9419200dd --- /dev/null +++ b/lib/plugins/usermanager/lang/de/edit.txt @@ -0,0 +1 @@ +===== Benutzer ändern ===== diff --git a/lib/plugins/usermanager/lang/de/intro.txt b/lib/plugins/usermanager/lang/de/intro.txt new file mode 100644 index 000000000..dab4d2a06 --- /dev/null +++ b/lib/plugins/usermanager/lang/de/intro.txt @@ -0,0 +1 @@ +====== Benutzer pflegen... ====== diff --git a/lib/plugins/usermanager/lang/de/lang.php b/lib/plugins/usermanager/lang/de/lang.php new file mode 100644 index 000000000..4ce96bc81 --- /dev/null +++ b/lib/plugins/usermanager/lang/de/lang.php @@ -0,0 +1,48 @@ + diff --git a/lib/plugins/usermanager/lang/de/list.txt b/lib/plugins/usermanager/lang/de/list.txt new file mode 100644 index 000000000..8d6d5fb46 --- /dev/null +++ b/lib/plugins/usermanager/lang/de/list.txt @@ -0,0 +1 @@ +===== Benutzerliste ===== diff --git a/lib/plugins/usermanager/lang/en/add.txt b/lib/plugins/usermanager/lang/en/add.txt new file mode 100644 index 000000000..9afecb5cd --- /dev/null +++ b/lib/plugins/usermanager/lang/en/add.txt @@ -0,0 +1 @@ +===== Add user ===== diff --git a/lib/plugins/usermanager/lang/en/delete.txt b/lib/plugins/usermanager/lang/en/delete.txt new file mode 100644 index 000000000..c3ca90dbb --- /dev/null +++ b/lib/plugins/usermanager/lang/en/delete.txt @@ -0,0 +1 @@ +===== Delete user ===== diff --git a/lib/plugins/usermanager/lang/en/edit.txt b/lib/plugins/usermanager/lang/en/edit.txt new file mode 100644 index 000000000..4d02dfddc --- /dev/null +++ b/lib/plugins/usermanager/lang/en/edit.txt @@ -0,0 +1 @@ +===== Edit user ===== diff --git a/lib/plugins/usermanager/lang/en/intro.txt b/lib/plugins/usermanager/lang/en/intro.txt new file mode 100644 index 000000000..73bf55613 --- /dev/null +++ b/lib/plugins/usermanager/lang/en/intro.txt @@ -0,0 +1 @@ +====== User Manager ====== diff --git a/lib/plugins/usermanager/lang/en/lang.php b/lib/plugins/usermanager/lang/en/lang.php new file mode 100644 index 000000000..e76357872 --- /dev/null +++ b/lib/plugins/usermanager/lang/en/lang.php @@ -0,0 +1,49 @@ + diff --git a/lib/plugins/usermanager/lang/en/list.txt b/lib/plugins/usermanager/lang/en/list.txt new file mode 100644 index 000000000..54c45caf7 --- /dev/null +++ b/lib/plugins/usermanager/lang/en/list.txt @@ -0,0 +1 @@ +===== User List ===== diff --git a/lib/plugins/usermanager/lang/fr/add.txt b/lib/plugins/usermanager/lang/fr/add.txt new file mode 100644 index 000000000..e60b8b894 --- /dev/null +++ b/lib/plugins/usermanager/lang/fr/add.txt @@ -0,0 +1 @@ +===== Ajouter un utilisateur ===== diff --git a/lib/plugins/usermanager/lang/fr/delete.txt b/lib/plugins/usermanager/lang/fr/delete.txt new file mode 100644 index 000000000..778f44192 --- /dev/null +++ b/lib/plugins/usermanager/lang/fr/delete.txt @@ -0,0 +1 @@ +===== Supprimer un utilisateur ===== diff --git a/lib/plugins/usermanager/lang/fr/edit.txt b/lib/plugins/usermanager/lang/fr/edit.txt new file mode 100644 index 000000000..ec193eb5a --- /dev/null +++ b/lib/plugins/usermanager/lang/fr/edit.txt @@ -0,0 +1 @@ +===== Modifier les informations d'un utilisateur ===== diff --git a/lib/plugins/usermanager/lang/fr/intro.txt b/lib/plugins/usermanager/lang/fr/intro.txt new file mode 100644 index 000000000..84987b0bf --- /dev/null +++ b/lib/plugins/usermanager/lang/fr/intro.txt @@ -0,0 +1 @@ +====== Gestion des utilisateurs ====== diff --git a/lib/plugins/usermanager/lang/fr/lang.php b/lib/plugins/usermanager/lang/fr/lang.php new file mode 100644 index 000000000..5f64cc962 --- /dev/null +++ b/lib/plugins/usermanager/lang/fr/lang.php @@ -0,0 +1,25 @@ +