usermanagement.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 763 行 · 第 1/3 页
PHP
763 行
<?php
/**
* $Id: userManagement.php 8387 2008-04-22 16:36:04Z kevin_fourie $
*
* KnowledgeTree Community Edition
* Document Management Made Simple
* Copyright (C) 2008 KnowledgeTree Inc.
* Portions copyright The Jam Warehouse Software (Pty) Limited
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
* California 94120-7775, or email info@knowledgetree.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by KnowledgeTree" and retain the original
* copyright notice.
* Contributor( s): ______________________________________
*
*/
require_once(KT_LIB_DIR . '/database/dbutil.inc');
require_once(KT_LIB_DIR . '/users/User.inc');
require_once(KT_LIB_DIR . '/groups/GroupUtil.php');
require_once(KT_LIB_DIR . '/groups/Group.inc');
require_once(KT_LIB_DIR . "/templating/templating.inc.php");
require_once(KT_LIB_DIR . "/dispatcher.inc.php");
require_once(KT_LIB_DIR . "/templating/kt3template.inc.php");
require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php");
require_once(KT_LIB_DIR . "/authentication/authenticationsource.inc.php");
require_once(KT_LIB_DIR . "/authentication/authenticationproviderregistry.inc.php");
require_once(KT_LIB_DIR . "/authentication/builtinauthenticationprovider.inc.php");
class KTUserAdminDispatcher extends KTAdminDispatcher {
var $sHelpPage = 'ktcore/admin/manage users.html';
function do_main() {
$this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('User Management'));
$this->oPage->setBreadcrumbDetails(_kt('select a user'));
$this->oPage->setTitle(_kt("User Management"));
$KTConfig =& KTConfig::getSingleton();
$alwaysAll = $KTConfig->get("alwaysShowAll");
$name = KTUtil::arrayGet($_REQUEST, 'search_name', KTUtil::arrayGet($_REQUEST, 'old_search'));
$show_all = KTUtil::arrayGet($_REQUEST, 'show_all', $alwaysAll);
$user_id = KTUtil::arrayGet($_REQUEST, 'user_id');
$no_search = true;
if (KTUtil::arrayGet($_REQUEST, 'do_search', false) != false) {
$no_search = false;
}
if ($name == '*') {
$show_all = true;
$name = '';
}
$search_fields = array();
$search_fields[] = new KTStringWidget(_kt('Username'), _kt("Enter part of the person's username. e.g. <strong>ra</strong> will match <strong>brad</strong>."), 'search_name', $name, $this->oPage, true);
// FIXME handle group search stuff.
$search_results = null;
if (!empty($name)) {
$search_results =& User::getList('WHERE username LIKE \'%' . DBUtil::escapeSimple($name) . '%\' AND id > 0');
} else if ($show_all !== false) {
$search_results =& User::getList('id > 0');
$no_search = false;
$name = '*';
}
$aAuthenticationSources =& KTAuthenticationSource::getList();
$bCanAdd = true;
if (KTPluginUtil::pluginIsActive('ktdms.wintools')) {
require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php');
$bCanAdd = BaobabKeyUtil::canAddUser();
if (PEAR::isError($bCanAdd)) {
$bCanAdd = false;
}
}
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/principals/useradmin");
$aTemplateData = array(
"context" => $this,
"search_fields" => $search_fields,
"search_results" => $search_results,
"no_search" => $no_search,
"authentication_sources" => $aAuthenticationSources,
"old_search" => $name,
"can_add" => $bCanAdd,
);
return $oTemplate->render($aTemplateData);
}
function do_addUser() {
$this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('User Management'));
$this->oPage->setBreadcrumbDetails(_kt('add a new user'));
$this->oPage->setTitle(_kt("Add New User"));
// Get persisted params
$name = KTUtil::arrayGet($_REQUEST, 'name');
$username = KTUtil::arrayGet($_REQUEST, 'newusername');
$emailAddress = KTUtil::arrayGet($_REQUEST, 'email_address');
$mobileNum = KTUtil::arrayGet($_REQUEST, 'mobile_number');
$maxSessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', '3');
// Check if parameters are being persisted before checking for the email notification parameter - otherwise it will always be true
if(isset($_REQUEST['name']) || isset($_REQUEST['newusername'])){
$emailNotification = (KTUtil::arrayGet($_REQUEST, 'email_notification') == 'on') ? true : false;
}else{
$emailNotification = true;
}
$show_all = KTUtil::arrayGet($_REQUEST, 'show_all', false);
$add_user = KTUtil::arrayGet($_REQUEST, 'add_user', false);
if ($add_user !== false) { $add_user = true; }
$edit_user = KTUtil::arrayGet($_REQUEST, 'edit_user', false);
$aOptions = array('autocomplete' => false);
// sometimes even admin is restricted in what they can do.
$KTConfig =& KTConfig::getSingleton();
$minLength = ((int) $KTConfig->get('user_prefs/passwordLength', 6));
$restrictAdmin = ((bool) $KTConfig->get('user_prefs/restrictAdminPasswords', false));
$passwordAddRequirement = '';
if ($restrictAdmin) {
$passwordAddRequirement = ' ' . sprintf('Password must be at least %d characters long.', $minLength);
}
$add_fields = array();
$add_fields[] = new KTStringWidget(_kt('Username'), sprintf(_kt('The username the user will enter to gain access to %s. e.g. <strong>jsmith</strong>'), APP_NAME), 'newusername', $username, $this->oPage, true, null, null, $aOptions);
$add_fields[] = new KTStringWidget(_kt('Name'), _kt('The full name of the user. This is shown in reports and listings. e.g. <strong>John Smith</strong>'), 'name', $name, $this->oPage, true, null, null, $aOptions);
$add_fields[] = new KTStringWidget(_kt('Email Address'), _kt('The email address of the user. Notifications and alerts are mailed to this address if <strong>email notifications</strong> is set below. e.g. <strong>jsmith@acme.com</strong>'), 'email_address', $emailAddress, $this->oPage, false, null, null, $aOptions);
$add_fields[] = new KTCheckboxWidget(_kt('Email Notifications'), _kt("If this is specified then the user will have notifications sent to the email address entered above. If it isn't set, then the user will only see notifications on the <strong>Dashboard</strong>"), 'email_notifications', $emailNotification, $this->oPage, false, null, null, $aOptions);
$add_fields[] = new KTPasswordWidget(_kt('Password'), _kt('Specify an initial password for the user.') . $passwordAddRequirement, 'new_password', null, $this->oPage, true, null, null, $aOptions);
$add_fields[] = new KTPasswordWidget(_kt('Confirm Password'), _kt('Confirm the password specified above.'), 'confirm_password', null, $this->oPage, true, null, null, $aOptions);
// nice, easy bits.
$add_fields[] = new KTStringWidget(_kt('Mobile Number'), _kt("The mobile phone number of the user. e.g. <strong>999 9999 999</strong>"), 'mobile_number', $mobileNum, $this->oPage, false, null, null, $aOptions);
$add_fields[] = new KTStringWidget(_kt('Maximum Sessions'), _kt('As a safety precaution, it is useful to limit the number of times a given account can log in, before logging out. This prevents a single account being used by many different people.'), 'max_sessions', $maxSessions, $this->oPage, true, null, null, $aOptions);
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/principals/adduser");
$aTemplateData = array(
"context" => $this,
"add_fields" => $add_fields,
);
return $oTemplate->render($aTemplateData);
}
function do_addUserFromSource() {
$oSource =& KTAuthenticationSource::get($_REQUEST['source_id']);
$sProvider = $oSource->getAuthenticationProvider();
$oRegistry =& KTAuthenticationProviderRegistry::getSingleton();
$oProvider =& $oRegistry->getAuthenticationProvider($sProvider);
$this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('User Management'));
$this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf('action=addUser'), 'name' => _kt('add a new user'));
$oProvider->aBreadcrumbs = $this->aBreadcrumbs;
$oProvider->oPage->setBreadcrumbDetails($oSource->getName());
$oProvider->oPage->setTitle(_kt("Add New User"));
$oProvider->dispatch();
exit(0);
}
function do_editUser() {
$this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('User Management'));
$this->oPage->setBreadcrumbDetails(_kt('modify user details'));
$this->oPage->setTitle(_kt("Modify User Details"));
$user_id = KTUtil::arrayGet($_REQUEST, 'user_id');
$oUser =& User::get($user_id);
$old_search = KTUtil::arrayGet($_REQUEST, 'old_search');
if (PEAR::isError($oUser) || $oUser == false) {
$this->errorRedirectToMain(_kt('Please select a user first.'));
exit(0);
}
$name = KTUtil::arrayGet($_REQUEST, 'name', $oUser->getName());
$username = KTUtil::arrayGet($_REQUEST, 'newusername', $oUser->getUsername());
$emailAddress = KTUtil::arrayGet($_REQUEST, 'email_address', $oUser->getEmail());
$mobileNum = KTUtil::arrayGet($_REQUEST, 'mobile_number', $oUser->getMobile());
$maxSessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', $oUser->getMaxSessions());
if(isset($_REQUEST['name']) || isset($_REQUEST['newusername'])){
$emailNotification = (KTUtil::arrayGet($_REQUEST, 'email_notification') == 'on') ? true : false;
}else{
$emailNotification = $oUser->getEmailNotification();
}
$this->aBreadcrumbs[] = array('name' => $oUser->getName());
$edit_fields = array();
$edit_fields[] = new KTStringWidget(_kt('Username'), sprintf(_kt('The username the user will enter to gain access to %s. e.g. <strong>jsmith</strong>'), APP_NAME), 'newusername', $username, $this->oPage, true);
$edit_fields[] = new KTStringWidget(_kt('Name'), _kt('The full name of the user. This is shown in reports and listings. e.g. <strong>John Smith</strong>'), 'name', $name, $this->oPage, true);
$edit_fields[] = new KTStringWidget(_kt('Email Address'), _kt('The email address of the user. Notifications and alerts are mailed to this address if <strong>email notifications</strong> is set below. e.g. <strong>jsmith@acme.com</strong>'), 'email_address', $emailAddress, $this->oPage, false);
$edit_fields[] = new KTCheckboxWidget(_kt('Email Notifications'), _kt('If this is specified then the user will have notifications sent to the email address entered above. If it is not set, then the user will only see notifications on the <strong>Dashboard</strong>'), 'email_notifications', $emailNotification, $this->oPage, false);
$edit_fields[] = new KTStringWidget(_kt('Mobile Number'), _kt("The mobile phone number of the user. e.g. <strong>999 9999 999</strong>"), 'mobile_number', $mobileNum, $this->oPage, false);
$edit_fields[] = new KTStringWidget(_kt('Maximum Sessions'), _kt('As a safety precaution, it is useful to limit the number of times a given account can log in, before logging out. This prevents a single account being used by many different people.'), 'max_sessions', $maxSessions, $this->oPage, true);
$oAuthenticationSource = KTAuthenticationSource::getForUser($oUser);
if (is_null($oAuthenticationSource)) {
$oProvider =& new KTBuiltinAuthenticationProvider;
} else {
$sProvider = $oAuthenticationSource->getAuthenticationProvider();
$oRegistry =& KTAuthenticationProviderRegistry::getSingleton();
$oProvider = $oRegistry->getAuthenticationProvider($sProvider);
}
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/principals/edituser");
$aTemplateData = array(
"context" => $this,
"edit_fields" => $edit_fields,
"edit_user" => $oUser,
"provider" => $oProvider,
"source" => $oAuthenticationSource,
'old_search' => $old_search,
);
return $oTemplate->render($aTemplateData);
}
function do_setPassword() {
$this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('User Management'));
$this->oPage->setBreadcrumbDetails(_kt('change user password'));
$this->oPage->setTitle(_kt("Change User Password"));
$old_search = KTUtil::arrayGet($_REQUEST, 'old_search');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?