user.inc

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· INC 代码 · 共 532 行 · 第 1/2 页

INC
532
字号
<?php
/**
 * $Id: User.inc 8868 2008-07-29 14:38:13Z kevin_fourie $
 *
 * Represents a user as per the users table in the database.
 *
 * 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 . '/ktentity.inc');
require_once(KT_LIB_DIR . "/util/sanitize.inc");

define('ADMIN_USER_ID', 1);

class User extends KTEntity {
    /** user's login name */
    var $sUserName;
    /** user's name (first and last) */
    var $sName;
    /** user's password */
    var $sPassword;
    /** user's maximum allowed file storage quota in bytes */
    var $iQuotaMax = 1234567890;
    /** user's current file storage quota in bytes */
    var $iQuotaCurrent = 0;
    /** user's email address */
    var $sEmail = "";
    /** user's mobile phone number */
    var $sMobile = "";
    /** notify user by mail status */
    var $bEmailNotification = false;
    /** notify user via sms (mobile phone) status */
    var $bSmsNotification = false;
    /** maxiumum concurrent sessions user may have */
    var $iMaxSessions = 5;
    /** primary key of language preferred by user */
    var $iLanguageID;
    /** internal variable used to determine if the password has changed or not */
    var $bPasswordChanged = false;
    /** authentication source for this user (built-in if null) */
    var $iAuthenticationSourceId = null;
    /** authentication details so that the source knows who this user is */
    var $sAuthenticationDetails = null;
    var $sAuthenticationDetails2 = null;
    var $iAuthenticationDetailsInt1 = null;
    var $iAuthenticationDetailsInt2 = null;
    var $dAuthenticationDetailsDate1 = null;
    var $dAuthenticationDetailsDate2 = null;
    var $bAuthenticationDetailsBool1 = null;
    var $bAuthenticationDetailsBool2 = null;
    var $dLastLogin = null;
    var $bDisabled = false;

    /**
     * The dashboard state for the current user
     * @var string
     */
    var $sDashboardState = '';

    var $_aFieldToSelect = array(
        'iId' => 'id',
        'sUserName' => 'username',
        'sName' => 'name',
        'sPassword' => 'password',
        'iQuotaMax' => 'quota_max',
        'iQuotaCurrent' => 'quota_current',
        'sEmail' => 'email',
        'sMobile' => 'mobile',
        'bEmailNotification' => 'email_notification',
        'bSmsNotification' => 'sms_notification',
        'iMaxSessions' => 'max_sessions',
        'iLanguageID' => 'language_id',
        'iAuthenticationSourceId' => 'authentication_source_id',
        'sAuthenticationDetails' => 'authentication_details_s1',
        'sAuthenticationDetails2' => 'authentication_details_s2',
        'iAuthenticationDetailsInt1' => 'authentication_details_i1',
        'iAuthenticationDetailsInt2' => 'authentication_details_i2',
        'dAuthenticationDetailsDate1' => 'authentication_details_d1',
        'dAuthenticationDetailsDate2' => 'authentication_details_d2',
        'bAuthenticationDetailsBool1' => 'authentication_details_b1',
        'bAuthenticationDetailsBool2' => 'authentication_details_b2',
        'dLastLogin' => 'last_login',
        'bDisabled' => 'disabled',
    );

    var $_bUsePearError = true;

    function _table() {
        return KTUtil::getTableName("users");
    }

    // STATIC
    function _ktentityOptions() {
        return array(
            'orderby' => 'name',
        );
    }


    function getUserName() { return sanitizeForSQLtoHTML($this->sUserName); }
    function setUserName($sNewValue) { $this->sUserName = sanitizeForSQL($sNewValue); }
    function getPassword() { return sanitizeForSQLtoHTML($this->sPassword); }
    function setPassword($sNewValue) { $this->sPassword = sanitizeForSQL($sNewValue); $this->bPasswordChanged = true; }
    function getQuotaMax() { return $this->iQuotaMax; }
    function setQuotaMax($iNewValue) { $this->iQuotaMax = $iNewValue; }
    function setName($sNewValue) { $this->sName = sanitizeForSQL($sNewValue); }
    function getName() { return sanitizeForSQLtoHTML($this->sName); }
    function getQuotaCurrent() { return $this->iQuotaCurrent; }
    function getEmail() { return sanitizeForSQLtoHTML($this->sEmail); }
    function setEmail($sNewValue) { $this->sEmail = sanitizeForSQL($sNewValue); }
    function getMobile() { return sanitizeForSQLtoHTML($this->sMobile); }
    function setMobile($sNewValue) { $this->sMobile = sanitizeForSQL($sNewValue); }
    function getEmailNotification() { return $this->bEmailNotification; }
    function setEmailNotification($bNewValue) { $this->bEmailNotification = KTUtil::anyToBool($bNewValue); }
    function getSmsNotification() { return $this->bSmsNotification; }
    function setSmsNotification($bNewValue) { $this->bSmsNotification = $bNewValue; }
    function getMaxSessions() { return $this->iMaxSessions; }
    function setMaxSessions($iNewValue) { $this->iMaxSessions = $iNewValue; }
    function getLanguageID() { return $this->iLanguageIDID; }
    function setLanguageID($iNewValue) { $this->iLanguageIDID = $iNewValue; }
    function getAuthenticationSourceId() { return $this->iAuthenticationSourceId; }
    function setAuthenticationSourceId($iNewValue) { $this->iAuthenticationSourceId = $iNewValue; }
    function getAuthenticationDetails() { return $this->sAuthenticationDetails; }
    function setAuthenticationDetails($sNewValue) { $this->sAuthenticationDetails = $sNewValue; }
    function getAuthenticationDetails2() { return $this->sAuthenticationDetails2; }
    function setAuthenticationDetails2($sNewValue) { $this->sAuthenticationDetails2 = $sNewValue; }

    function getAuthenticationDetailsInt1() { return $this->iAuthenticationDetailsInt1; }
    function setAuthenticationDetailsInt1($mValue) { $this->iAuthenticationDetailsInt1 = $mValue; }
    function getAuthenticationDetailsInt2() { return $this->iAuthenticationDetailsInt2; }
    function setAuthenticationDetailsInt2($mValue) { $this->iAuthenticationDetailsInt2 = $mValue; }

    function getAuthenticationDetailsDate1() { return $this->dAuthenticationDetailsDate1; }
    function setAuthenticationDetailsDate1($mValue) { $this->dAuthenticationDetailsDate1 = $mValue; }
    function getAuthenticationDetailsDate2() { return $this->dAuthenticationDetailsDate2; }
    function setAuthenticationDetailsDate2($mValue) { $this->dAuthenticationDetailsDate2 = $mValue; }

    function getAuthenticationDetailsBool1() { return $this->bAuthenticationDetailsBool1; }
    function setAuthenticationDetailsBool1($mValue) { $this->bAuthenticationDetailsBool1 = $mValue; }
    function getAuthenticationDetailsBool2() { return $this->bAuthenticationDetailsBool2; }
    function setAuthenticationDetailsBool2($mValue) { $this->bAuthenticationDetailsBool2 = $mValue; }

    function getLastLogin() { return $this->dLastLogin; }
    function setLastLogin($mValue) { $this->dLastLogin = $mValue; }

    function getDisabled() { return $this->bDisabled; }
    function setDisabled($mValue) { $this->bDisabled = $mValue; }

    /* return the key for storing dashboard in system settings */
    function _getDashboardStateKey() {
        return 'dashboard-state-' . $this->getId();
    }

    function getDashboardState() {
        if(empty($this->sDashboardState)){
            $this->sDashboardState = KTUtil::getSystemSetting($this->_getDashboardStateKey());
        }
        return $this->sDashboardState;
    }

    function setDashboardState($mValue) {
        $this->sDashboardState = $mValue;
        KTUtil::setSystemSetting($this->_getDashboardStateKey(), $mValue);
    }

    function refreshDashboadState()
    {
    	require_once(KT_DIR . "/thirdparty/pear/JSON.php");
    	$dashletRegistry = & KTDashletRegistry::getSingleton();

    	$update = false;
    	$knownlist = array();

    	$oJSON = new Services_JSON();
    	$state = $this->getDashboardState();
    	$dashlets = $oJSON->decode($state);

    	if (!isset($dashlets->left)) $dashlets->left = array();
    	if (!isset($dashlets->right)) $dashlets->right = array();
    	$mergedlist = kt_array_merge($dashlets->left,$dashlets->right);

    	foreach($mergedlist as $dashlet)
    	{
    		array_push($knownlist,"'".$dashlet->id."'");
    	}

    	$sKnownlist = implode(',', $knownlist);
    	$aDashlets = $dashletRegistry->getNewDashlets($this, $sKnownlist);

    	if(!empty($aDashlets)){
        	$column=1;
        	foreach($aDashlets as $class)
        	{
        		$column = ($column + 1) %2;
        	    $obj = new stdClass();
        		$obj->id=$class;
        		$obj->state=0;

        		if ($column == 0)
        			array_push($dashlets->left,$obj);
    			else
        			array_push($dashlets->right,$obj);
        		$update=true;
        	}
    	}

    	// Check if the KT Info dashlet is being displayed
    	// If it's not in the top left corner, move it there.
    	if((!(strpos($sKnownlist, 'KTInfoDashlet') === false) && $knownlist[0] != "'KTInfoDashlet'") || empty($knownlist)){
    	    $left = $dashlets->left;
    	    $right = $dashlets->right;

    	    $found = false;
    	    $update = true;
    	    foreach($left as $key => $item){
    	        if($item->id == 'KTInfoDashlet'){
    	            // found the dashlet
    	            $found = 'true';
    	            array_splice($dashlets->left, $key, 1);
    	            array_unshift($dashlets->left, $item);
    	            continue;
    	        }
    	    }
    	    if(!$found){
    	        foreach($right as $key => $item){
        	        if($item->id == 'KTInfoDashlet'){
        	            // found the dashlet
        	            $found = 'true';
    	                array_splice($dashlets->right, $key, 1);
        	            array_unshift($dashlets->left, $item);
        	            continue;
        	        }
        	    }
    	    }
    	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?