Ticket #1173: ref_user_alpha.diff

File ref_user_alpha.diff, 45.1 kB (added by Tamme, 2 years ago)
  • modules/user/classes/RegisterMgr.php

    old new  
    236236 
    237237        $output->template = 'userAdd.html'; 
    238238        $output->user = DB_DataObject::factory($this->conf['table']['user']); 
    239         $output->user->password_confirm = (isset($input->user->password_confirm)) ? 
    240             $input->user->password_confirm : ''; 
     239        $output->user->password_confirm = (isset($input->user->password_confirm)) 
     240            ? $input->user->password_confirm 
     241            : ''; 
    241242    } 
    242243 
    243244    function _cmd_insert(&$input, &$output) 
  • modules/user/classes/DA_User2.php

    old new  
     1<?php 
     2 
     3require_once SGL_MOD_DIR . '/user/classes/DA_UserTemplate.php'; 
     4require_once 'DB/DataObject.php'; 
     5 
     6//  role sync constants 
     7//define('SGL_ROLESYNC_ADD',              1); 
     8//define('SGL_ROLESYNC_REMOVE',           2); 
     9//define('SGL_ROLESYNC_ADDREMOVE',        3); 
     10//define('SGL_ROLESYNC_VIEWONLY',         4); 
     11 
     12class DA_User2 extends DA_UserTemplate 
     13{ 
     14    function DA_User2() 
     15    { 
     16        parent::DA_UserTemplate(); 
     17        $this->dbh = &SGL_DB::singleton(); 
     18    } 
     19     
     20    function &singleton() 
     21    { 
     22        static $instance; 
     23 
     24        // If the instance is not there, create one 
     25        if (!isset($instance)) { 
     26            $instance = new DA_User2(); 
     27        } 
     28        return $instance; 
     29    } 
     30     
     31    function _startTransaction() 
     32    { 
     33        SGL_DB::setConnection(); 
     34        $this->dbh->autocommit(false); 
     35    } 
     36     
     37    function _rollback() 
     38    { 
     39        $this->dbh->rollback(); 
     40    } 
     41     
     42    function _commit() 
     43    { 
     44        $this->dbh->commit(); 
     45    } 
     46     
     47    function _addUser($oUser) 
     48    { 
     49        $userId = $this->dbh->nextId($this->conf['table']['user']); 
     50        if (PEAR::isError($userId)) { 
     51            return $userId; 
     52        } 
     53         
     54        $oUser->usr_id = $userId; 
     55        $ok = $oUser->insert(); 
     56        // according to PEAR Manual 
     57        // insert() throws PEAR_Error on failure 
     58        if (PEAR::isError($ok)) { 
     59            return $ok; 
     60        } 
     61         
     62        //  assign permissions associated with role user belongs to 
     63        //  first get all perms associated with user's role 
     64        $aRolePerms = $this->_getPermsByRoleId($oUser->role_id); 
     65        if (PEAR::isError($aRolePerms)) { 
     66            return $aRolePerms; 
     67        } 
     68 
     69        //  then assign them to the user_permission table 
     70        $ok = $this->_addPermsByUserId($aRolePerms, $oUser->usr_id); 
     71        if (PEAR::isError($ok)) { 
     72            return $ok; 
     73        } 
     74         
     75        //  assign preferences associated with org user belongs to 
     76        //  first get all prefs associated with user's org or default 
     77        //  prefs if orgs are disabled 
     78        $aPrefs = (@$this->conf['OrgMgr']['enabled']) 
     79            ? $this->getUserPrefsByOrgId($oUser->organisation_id, SGL_RET_ID_VALUE) 
     80            : $this->_getMasterPrefs(SGL_RET_ID_VALUE); 
     81 
     82        if (PEAR::isError($aPrefs)) { 
     83            return $aPrefs; 
     84        } 
     85 
     86        //  then assign them to the user_preference table 
     87        $ok = $this->_addPrefsByUserId($aPrefs, $oUser->usr_id); 
     88        if (PEAR::isError($ok)) { 
     89            return $ok; 
     90        } 
     91         
     92        return $userId; 
     93    } 
     94     
     95    function _updateUser($oUser) 
     96    { 
     97        //  get existing user object 
     98        $oUserBackup = $this->_getUserById($oUser->usr_id); 
     99         
     100        $ok = $oUser->update(); 
     101        // according to PEAR Manual 
     102        // update() returns false or throws PEAR_Error on failure 
     103        if ($ok === false) { 
     104            return PEAR::raiseError('Problem updating user DataObject'); 
     105        } elseif (PEAR::isError($ok)) { 
     106            return $ok; 
     107        } 
     108         
     109        //  change perms if role is modified 
     110        if ($oUser->role_id != $oUserBackup->role_id) { 
     111 
     112            //  disallow usr_id(1) admin from changing role 
     113            if ($oUser->usr_id == SGL_ADMIN) { 
     114                return PEAR::raiseError('User with ID = 1 (SGL_ADMIN) cannot change role'); 
     115            } 
     116 
     117            //  first delete old perms 
     118            $aDeleteOptions = array( 
     119                'userId' => $oUser->usr_id 
     120            ); 
     121            $ok = $this->_deleteUserPermissions($aDeleteOptions); 
     122            if (PEAR::isError($ok)) { 
     123                return $ok; 
     124            } 
     125             
     126            //  assign permissions associated with role user has been moved to 
     127            //  first get all perms associated with user's new role 
     128            $aRolePerms = $this->_getPermsByRoleId($oUser->role_id); 
     129            if (PEAR::isError($aRolePerms)) { 
     130                return $aRolePerms; 
     131            } 
     132 
     133            //  then assign them to the user_permission table 
     134            $ok = $this->_addPermsByUserId($aRolePerms, $oUser->usr_id); 
     135            if (PEAR::isError($ok)) { 
     136                return $ok; 
     137            } 
     138        } 
     139 
     140        //  change prefs if org is modified 
     141        if ($oUser->organisation_id  != $oUserBackup->organisation_id) { 
     142 
     143            //  first delete old preferences 
     144            $ok = $this->deletePrefsByUserId($oUser->usr_id); 
     145            if (PEAR::isError($ok)) { 
     146                return $ok; 
     147            } 
     148             
     149            //  assign preferences associated with org user belongs to 
     150            //  first get all prefs associated with user's org 
     151            $aOrgPrefs = $this->getUserPrefsByOrgId($oUser->organisation_id, SGL_RET_ID_VALUE); 
     152            if (PEAR::isError($aOrgPrefs)) { 
     153                return $aOrgPrefs; 
     154            } 
     155 
     156            //  then assign them to the user_preference table 
     157            $ok = $this->addPrefsByUserId($aOrgPrefs, $oUser->usr_id); 
     158            if (PEAR::isError($ok)) { 
     159                return $ok; 
     160            } 
     161        } 
     162 
     163        return true; 
     164    } 
     165     
     166    function _getRoles($bExcludeRoot) 
     167    { 
     168        SGL::logMessage(null, PEAR_LOG_DEBUG); 
     169 
     170        $whereClause = ($bExcludeRoot) ? ' AND role_id <> ' . SGL_ADMIN : ''; 
     171 
     172        $query = " 
     173            SELECT role_id, name 
     174            FROM    " . $this->conf['table']['role'] . " 
     175            WHERE  role_id <> " . SGL_GUEST . " 
     176            AND    role_id <> " . SGL_UNASSIGNED . 
     177            $whereClause; 
     178        $aAllRoles = $this->dbh->getAssoc($query); 
     179 
     180        //  remove roles that have no perms set 
     181        foreach ($aAllRoles as $roleId => $name) { 
     182            if ($roleId === SGL_ADMIN) { 
     183                continue; 
     184            } 
     185            $query = 
     186                'SELECT COUNT(*) FROM ' . $this->conf['table']['role_permission'] . 
     187                ' WHERE role_id =' . $roleId; 
     188            $count = $this->dbh->getOne($query); 
     189            if ($count < 1) { 
     190                unset($aAllRoles[$roleId]); 
     191            } 
     192        } 
     193        return $aAllRoles; 
     194    } 
     195     
     196    function _getUserById($id) 
     197    { 
     198        $oUser = DB_DataObject::factory($this->conf['table']['user']); 
     199        if (!is_null($id)) { 
     200            $oUser->get($id); 
     201        } 
     202         
     203        return $oUser; 
     204    } 
     205     
     206    function _isUniqueUsername($username) 
     207    { 
     208        $oUser = DB_DataObject::factory($this->conf['table']['user']); 
     209        $oUser->whereAdd("username = '$username'"); 
     210        $numRows = $oUser->find(); 
     211 
     212        //  return false if any rows found 
     213        return (boolean) $numRows == 0; 
     214    } 
     215     
     216    function _isUniqueEmail($email) 
     217    { 
     218        $oUser = DB_DataObject::factory($this->conf['table']['user']); 
     219        $oUser->whereAdd("email = '$email'"); 
     220        $numRows = $oUser->find(); 
     221 
     222        //  return false if any rows found 
     223        return (boolean) $numRows == 0; 
     224    } 
     225     
     226    function _getPermsByRoleId($roleId = 0) 
     227    { 
     228        //  no logMessage allowed here 
     229        //  Tamme: WHY??? 
     230        $query = " 
     231            SELECT permission_id 
     232            FROM {$this->conf['table']['role_permission']} 
     233            WHERE role_id = $roleId"; 
     234        $aRolePerms = $this->dbh->getCol($query); 
     235         
     236        return $aRolePerms; 
     237    } 
     238     
     239    function _addPermsByUserId($aRolePerms, $userId) 
     240    { 
     241        SGL::logMessage(null, PEAR_LOG_DEBUG); 
     242         
     243        if (!count($aRolePerms)) { 
     244            return; 
     245        } 
     246 
     247        $query = " 
     248            INSERT INTO {$this->conf['table']['user_permission']} 
     249                (user_permission_id, usr_id, permission_id) 
     250            VALUES (?, ?, ?)"; 
     251        $sth = $this->dbh->prepare($query); 
     252        if (PEAR::isError($sth)) { 
     253            return $sth; 
     254        } 
     255         
     256        foreach ($aRolePerms as $permId) { 
     257            $aParams = array( 
     258                $this->dbh->nextId($this->conf['table']['user_permission']), 
     259                $userId, 
     260                $permId); 
     261             
     262            $result = $this->dbh->execute($sth, $aParams); 
     263            if (PEAR::isError($result)) { 
     264                return $result; 
     265            } 
     266        } 
     267    } 
     268     
     269    function _getMasterPrefs($type = SGL_RET_NAME_VALUE) 
     270    { 
     271        switch ($type) { 
     272            case SGL_RET_ID_VALUE: 
     273                $term = 'preference_id'; 
     274                break; 
     275     
     276            case SGL_RET_NAME_VALUE: 
     277            default: 
     278                $term = 'name'; 
     279        } 
     280         
     281        $query = " 
     282            SELECT $term, default_value 
     283            FROM {$this->conf['table']['preference']}"; 
     284         
     285        $aRes = $this->dbh->getAssoc($query); 
     286        if (PEAR::isError($aRes)) { 
     287            return $aRes; 
     288        } 
     289 
     290        //  set default theme from config 
     291        $key = ($type == SGL_RET_NAME_VALUE) 
     292            ? 'theme'  
     293            : 3; 
     294        $c = &SGL_Config::singleton(); 
     295        $defaultTheme = $c->get(array('site' => 'defaultTheme')); 
     296        $aRes[$key] = $defaultTheme; 
     297 
     298        return $aRes; 
     299    } 
     300 
     301    function _addPrefsByUserId($aPrefs, $userId) 
     302    { 
     303        if (!count($aPrefs)) { 
     304            return true; 
     305        } 
     306 
     307        $query = " 
     308            INSERT INTO {$this->conf['table']['user_preference']} 
     309                (user_preference_id, usr_id, preference_id, value) 
     310            VALUES (?, $userId, ?, ?)"; 
     311         
     312        $sth = $this->dbh->prepare($query); 
     313        if (PEAR::isError($sth)) { 
     314            return $sth; 
     315        } 
     316         
     317        foreach ($aPrefs as $prefId => $prefValue) { 
     318            $aParams = array( 
     319                $this->dbh->nextId($this->conf['table']['user_preference']), 
     320                $prefId, 
     321                $prefValue); 
     322                 
     323            $result = $this->dbh->execute($sth, $aParams); 
     324            if (PEAR::isError($result)) { 
     325                return $result; 
     326            } 
     327        } 
     328             
     329        return true; 
     330    } 
     331     
     332    /** 
     333     * Deletes preferences for a given user. 
     334     * 
     335     * @access public 
     336     * @param integer $userId       The id of the user preferences are being deleted for 
     337     * @return boolean              True on success, PEAR error on failure 
     338     */ 
     339    function _deletePrefsByUserId($userId) 
     340    { 
     341        $query = " 
     342            DELETE FROM {$this->conf['table']['user_preference']} 
     343            WHERE usr_id = $userId"; 
     344        return $this->dbh->query($query); 
     345    } 
     346     
     347    function _deleteUserByIdStatement() 
     348    { 
     349        $query = " 
     350            DELETE FROM {$this->conf['table']['user']} 
     351            WHERE usr_id = ?"; 
     352        $sth = $this->dbh->prepare($query); 
     353         
     354        return $sth; 
     355    } 
     356     
     357    function _deleteUserById($id, $sth = null) 
     358    { 
     359        $aDeleteOptions = array( 
     360            'userId' => $id 
     361        ); 
     362        $result = $this->_deleteUserPermissions($aDeleteOptions); 
     363        if (PEAR::isError($result)) { 
     364            return $result; 
     365        } 
     366         
     367        $result = $this->_deletePrefsByUserId($id); 
     368        if (PEAR::isError($result)) { 
     369            return $result; 
     370        } 
     371         
     372        $result = $this->dbh->execute($sth, $id); 
     373        if (PEAR::isError($result)) { 
     374            return $result; 
     375        } 
     376    } 
     377     
     378    function _getPermsByUserId($userId) 
     379    { 
     380        SGL::logMessage(null, PEAR_LOG_DEBUG); 
     381 
     382        $query = " 
     383            SELECT  permission_id 
     384            FROM    {$this->conf['table']['user_permission']} 
     385            WHERE   usr_id = $userId"; 
     386        $aUserPerms = $this->dbh->getCol($query); 
     387         
     388        return $aUserPerms; 
     389    } 
     390     
     391    /** 
     392     * Returns an assoc array of all perms. 
     393     * 
     394     * @access  public 
     395     * @param   int     $moduleId   only select perms for one module 
     396     * @param   int     $type       return type constant 
     397     * @return  array   $aAllPerms  array of perms returned 
     398     */ 
     399    function _getPermsByModuleId($moduleId, $type) 
     400    { 
     401        switch ($type) { 
     402        case SGL_RET_ARRAY: 
     403            $filter = (!empty($moduleId)) 
     404                ? "AND p.module_id = $moduleId" 
     405                : null; 
     406            $query = " 
     407                SELECT permission_id, p.name, m.name AS module_name, p.module_id 
     408                FROM {$this->conf['table']['permission']} p, 
     409                     {$this->conf['table']['module']} m 
     410                WHERE p.module_id = m.module_id 
     411                $filter 
     412                ORDER BY name"; 
     413            $aAllPerms = $this->dbh->getAll($query, DB_FETCHMODE_ASSOC); 
     414            break; 
     415 
     416        case SGL_RET_ID_VALUE: 
     417        default: 
     418            $filter = (!empty($moduleId)) 
     419                ? "WHERE  module_id = $moduleId" 
     420                : null; 
     421            $query = " 
     422                SELECT permission_id, name 
     423                FROM {$this->conf['table']['permission']} p 
     424                $filter 
     425                ORDER BY name"; 
     426            $aAllPerms = $this->dbh->getAssoc($query); 
     427        } 
     428         
     429        return $aAllPerms; 
     430    } 
     431     
     432    function _deleteUserPermissions($aOptions = null) 
     433    { 
     434        SGL::logMessage(null, PEAR_LOG_DEBUG); 
     435         
     436        if (is_null($aOptions) || !is_array($aOptions) || !count($aOptions)) { 
     437            return SGL::raiseError('no arguments supplied', SGL_ERROR_INVALIDARGS); 
     438        } 
     439         
     440        $wsh = &new WhereStack(); 
     441        foreach ($aOptions as $key => $option) { 
     442            switch ($key) { 
     443            case 'userId': 
     444                $wsh->add('usr_id = ' . (int) $aOptions['userId']); 
     445                break; 
     446                 
     447            case 'permList': 
     448                if (!is_array($option) || !count($option)) { 
     449                    return SGL::raiseError("option 'permList' requires array to operate", 
     450                        SGL_ERROR_INVALIDARGS); 
     451                } 
     452                $strPermList = implode(',', $option); 
     453                $wsh->add("permission_id IN ($strPermList)"); 
     454                break; 
     455                 
     456            default: 
     457                return SGL::raiseError("invalid option '$key'", SGL_ERROR_INVALIDARGS); 
     458            } 
     459        } 
     460 
     461        $query = " 
     462            DELETE FROM {$this->conf['table']['user_permission']} 
     463            {$wsh->getWhere()}"; 
     464        $result = $this->dbh->query($query); 
     465        if (PEAR::isError($result)) { 
     466            return $result; 
     467        } 
     468         
     469        $affected = $this->dbh->affectedRows(); 
     470        if (!PEAR::isError($affected, DB_ERROR_NOT_CAPABLE)) { 
     471            SGL::logMessage("deleted $affected user permissions", PEAR_LOG_DEBUG); 
     472        } 
     473    } 
     474     
     475    function _updateUserPerms($userId, $aNewPerms, $aOptions) 
     476    { 
     477        SGL::logMessage(null, PEAR_LOG_DEBUG); 
     478         
     479        // first get old perms 
     480        $aOldPerms = $this->_getPermsByUserId($userId); 
     481        if (PEAR::isError($aOldPerms)) { 
     482            return $aOldPerms; 
     483        } 
     484         
     485        // delete revoked perms 
     486        $aPermsToRemove = array_diff($aOldPerms, $aNewPerms); 
     487        if (count($aPermsToRemove)) { 
     488            $aDeleteOptions = array( 
     489                'userId' => $userId, 
     490                'permList' => $aPermsToRemove 
     491            ); 
     492            $result = $this->_deleteUserPermissions($aDeleteOptions); 
     493            if (PEAR::isError($result)) { 
     494                return $result; 
     495            } 
     496        } 
     497         
     498        // add missing perms 
     499        $aPermsToAdd = array_diff($aNewPerms, $aOldPerms); 
     500        if (count($aPermsToAdd)) { 
     501            $result = $this->_addPermsByUserId($aPermsToAdd, $userId); 
     502            if (PEAR::isError($result)) { 
     503                return $result; 
     504            } 
     505        } 
     506    } 
     507     
     508    function _deleteUserLogin($aLoginId) 
     509    { 
     510        SGL::logMessage(null, PEAR_LOG_DEBUG); 
     511         
     512        $strLoginId = implode(',', $aLoginId); 
     513         
     514        $query = " 
     515            DELETE FROM {$this->conf['table']['login']} 
     516            WHERE login_id IN ({$strLoginId})"; 
     517        $result = $this->dbh->query($query); 
     518        if (PEAR::isError($result)) { 
     519            return $result; 
     520        } 
     521    } 
     522} 
     523 
     524/** 
     525 * WhereStack 
     526 *  
     527 * @package SGL 
     528 * @author  Marian Seitner <tamme@ups4ever.de> 
     529 */ 
     530class WhereStack 
     531{ 
     532    var $_aStatements = array(); 
     533     
     534    var $_aConnectors; 
     535     
     536    function WhereStack() 
     537    { 
     538        $this->_aConnectors = array( 
     539            'AND', 
     540            'OR' 
     541        ); 
     542    } 
     543     
     544    function add($statement, $connector = 'AND') 
     545    { 
     546        $connector = strtoupper($connector); 
     547        if (!in_array($connector, $this->_aConnectors)) { 
     548            SGL::logMessage("unknown connector $connector", PEAR_LOG_ERR); 
     549            return; 
     550        } 
     551 
     552        $this->_aStatements[] = array( 
     553            $statement, 
     554            $connector 
     555        ); 
     556    } 
     557     
     558    function getWhere() 
     559    { 
     560        $str = "WHERE ({$this->_aStatements[0][0]})"; 
     561        array_shift($this->_aStatements); 
     562         
     563        foreach ($this->_aStatements as $statement) { 
     564            $str .= " {$statement[1]} ({$statement[0]})"; 
     565        } 
     566         
     567        return $str; 
     568    } 
     569} 
     570 
     571define('RC_SUCC', '1'); 
     572define('RC_FAIL', '2'); 
     573define('RC_IGNO', '3'); 
     574 
     575/** 
     576 * ResultCounter 
     577 *  
     578 * @package SGL 
     579 * @author  Marian Seitner <tamme@ups4ever.de> 
     580 */ 
     581class ResultCounter 
     582{ 
     583    var $aResults = array(); 
     584     
     585    function inc($element, $type = RC_SUCC) 
     586    { 
     587        $this->aResults[$type][] = $element; 
     588    } 
     589     
     590    function get($type = null) 
     591    { 
     592        if (is_null($type)) { 
     593            return $this->aResults; 
     594        } 
     595         
     596        return (isset($this->aResults[$type])) 
     597            ? $this->aResults[$type] 
     598            : false; 
     599    } 
     600     
     601    function count($type = null) 
     602    { 
     603        // return overall element count 
     604        if (is_null($type)) { 
     605            $sum = 0; 
     606            foreach ($this->aResults as $aPartialResult) { 
     607                $sum += count($aPartialResult); 
     608            } 
     609             
     610            return $sum; 
     611        } 
     612         
     613        return (isset($this->aResults[$type])) 
     614            ? count($this->aResults[$type]) 
     615            : 0; 
     616    } 
     617     
     618    function merge($oResultCounter) 
     619    { 
     620        $aMergeResults = $oResultCounter->get(); 
     621        foreach ($aMergeResults as $type => $result) { 
     622            $this->aResults[$type][] = $result; 
     623        } 
     624    } 
     625} 
     626 
     627?> 
  • modules/user/classes/DA_UserTemplate.php

    old new  
     1<?php 
     2 
     3class DA_UserTemplate { 
     4 
     5    var $conf = null; 
     6    var $dbh = null; 
     7     
     8    function DA_UserTemplate() 
     9    { 
     10        $c = &SGL_Config::singleton(); 
     11        $this->conf = $c->getAll(); 
     12    } 
     13     
     14    /** 
     15     * @abstract 
     16     */ 
     17    function _startTransaction() {} 
     18     
     19    /** 
     20     * @abstract 
     21     */ 
     22    function _rollback() {} 
     23     
     24    /** 
     25     * @abstract 
     26     */ 
     27    function _commit() {} 
     28 
     29    /** 
     30     * @access public 
     31     * @final 
     32     */ 
     33    function addUser($oUser) 
     34    { 
     35    $this->_startTransaction(); 
     36         
     37        $result = $this->_addUser($oUser); 
     38        if (!PEAR::isError($result)) { 
     39            $this->_commit(); 
     40            return $result; 
     41        } else { 
     42            $this->_rollback(); 
     43            return PEAR::raiseError('Problem encountered adding user'); 
     44        } 
     45    } 
     46     
     47    /** 
     48     * @abstract 
     49     */ 
     50    function _addUser($oUser) {} 
     51     
     52    /** 
     53     * @access public 
     54     * @final 
     55     */ 
     56    function updateUser($oUser) 
     57    { 
     58        $this->_startTransaction(); 
     59         
     60        $result = $this->_updateUser($oUser); 
     61        if (!PEAR::isError($result)) { 
     62            $this->_commit(); 
     63            return true; 
     64        } else { 
     65            $this->_rollback(); 
     66            return PEAR::raiseError('Problem encountered updating user'); 
     67        } 
     68    } 
     69     
     70    /** 
     71     * @abstract 
     72     */ 
     73    function _updateUser($oUser) {} 
     74     
     75    /** 
     76     * @access public 
     77     * @final 
     78     */ 
     79    function getRoles($bExcludeRoot = false) { 
     80        return $this->_getRoles($bExcludeRoot); 
     81    } 
     82     
     83    /** 
     84     * @abstract 
     85     */ 
     86    function _getRoles($bExcludeRoot) {} 
     87     
     88    /** 
     89     * @access public 
     90     * @final 
     91     */ 
     92    function getUserById($id = null) 
     93    { 
     94        return $this->_getUserById($id); 
     95    } 
     96     
     97    /** 
     98     * @abstract 
     99     */ 
     100    function _getUserById($id) {} 
     101     
     102    /** 
     103     * @access public 
     104     * @final 
     105     */ 
     106    function isUniqueUsername($username) 
     107    { 
     108        return $this->_isUniqueUsername($username); 
     109    } 
     110     
     111    /** 
     112     * @abstract 
     113     */ 
     114    function _isUniqueUsername($username) {} 
     115     
     116    /** 
     117     * @access public 
     118     * @final 
     119     */ 
     120    function isUniqueEmail($email) 
     121    { 
     122        return $this->_isUniqueEmail($email); 
     123    } 
     124     
     125    /** 
     126     * @abstract 
     127     */ 
     128    function _isUniqueEmail($email) {} 
     129     
     130    /** 
     131     * Hook 
     132     */ 
     133    function _deleteUserByIdStatement() 
     134    { 
     135        return null; 
     136    } 
     137     
     138    /** 
     139     * @access public 
     140     * @final 
     141     * @todo invoke hook with referenced argument for greater flexibility 
     142     */ 
     143    function deleteUsersById($mId = null) 
     144    { 
     145        if (is_null($mId)) { 
     146            return PEAR::raiseError('invalid argument count'); 
     147        } 
     148         
     149        if (!is_array($mId)) { 
     150            $mId = (array) $mId; 
     151        } 
     152         
     153        if (in_array(SGL_ADMIN, $mId)) { 
     154            return PEAR::raiseError('admin account deletion disallowed'); 
     155        } 
     156         
     157        // invoke hook 
     158        $sth = $this->_deleteUserByIdStatement(); 
     159        if (PEAR::isError($sth)) { 
     160            return $sth; 
     161        } 
     162         
     163        // result counter 
     164        $rch = &new ResultCounter(); 
     165         
     166        foreach ($mId as $id) { 
     167            $this->_startTransaction(); 
     168             
     169            $result = $this->_deleteUserById($id, $sth); 
     170            if (!PEAR::isError($result)) { 
     171                $this->_commit(); 
     172                $rch->inc($id, RC_SUCC); 
     173            } else { 
     174                $this->_rollback(); 
     175                $rch->inc($id, RC_FAIL); 
     176            } 
     177        } 
     178         
     179        return $rch; 
     180    } 
     181     
     182    /** 
     183     * @abstract 
     184     */ 
     185    function _deleteUserById($id) {} 
     186     
     187    /** 
     188     * @access public 
     189     * @final 
     190     */ 
     191    function getPermsByUserId($userId = 0) 
     192    { 
     193        return $this->_getPermsByUserId($userId); 
     194    } 
     195     
     196    /** 
     197     * @abstract 
     198     */ 
     199    function _getPermsByUserId($userId) {} 
     200     
     201    /** 
     202     * @access public 
     203     * @final 
     204     */ 
     205    function getPermsByModuleId($moduleId = null, $type = SGL_RET_ID_VALUE) 
     206    { 
     207        return $this->_getPermsByModuleId($moduleId, $type); 
     208    } 
     209     
     210    /** 
     211     * @abstract 
     212     */ 
     213    function _getPermsByModuleId($moduleId, $type) {} 
     214     
     215    /** 
     216     * @access public 
     217     * @final 
     218     */ 
     219    function updateUserPerms($userId, $aNewPerms, $aOptions = null) 
     220    { 
     221        $this->_startTransaction(); 
     222         
     223        $result = $this->_updateUserPerms($userId, $aNewPerms, $aOptions); 
     224        if (!PEAR::isError($result)) { 
     225            $this->_commit(); 
     226            return true; 
     227        } else { 
     228            $this->_rollback(); 
     229            return PEAR::raiseError('Problem encountered updating user perms'); 
     230        } 
     231    } 
     232     
     233    /** 
     234     * @abstract 
     235     */ 
     236    function _updateUserPerms($userId, $aNewPerms, $aOptions) {} 
     237     
     238    /** 
     239     * @access public 
     240     * @final 
     241     */ 
     242    function deleteUserLogin($aLoginId) 
     243    { 
     244        if (!is_array($aLoginId) || !count($aLoginId)) { 
     245            return SGL::raiseError('Invalid arguments supplied', SGL_ERROR_INVALIDARGS); 
     246        } 
     247         
     248        $this->_startTransaction(); 
     249         
     250        $result = $this->_deleteUserLogin($aLoginId); 
     251        if (!PEAR::isError($result)) { 
     252            $this->_commit(); 
     253            return true; 
     254        } else { 
     255            $this->_rollback(); 
     256            return $result; 
     257        } 
     258    } 
     259     
     260    /** 
     261     * @access private 
     262     * @abstract 
     263     */ 
     264    function _deleteUserLogin($aLoginId) {} 
     265} 
     266 
     267?> 
  • modules/user/classes/UserMgr.php

    old new  
    4040 
    4141require_once SGL_MOD_DIR . '/user/classes/RegisterMgr.php'; 
    4242require_once SGL_MOD_DIR  . '/default/classes/DA_Default.php'; 
    43 require_once SGL_MOD_DIR . '/user/classes/DA_User.php'; 
     43require_once SGL_MOD_DIR . '/user/classes/DA_User2.php'; 
    4444require_once SGL_CORE_DIR . '/Delegator.php'; 
    4545 
    4646require_once 'Validate.php'; 
     
    6464        $this->template = 'userManager.html'; 
    6565        $this->sortBy = 'usr_id'; 
    6666 
    67         $daUser    = &DA_User::singleton(); 
     67        $daUser    = &DA_User2::singleton(); 
    6868        $daDefault = &DA_Default::singleton(); 
    6969        $this->da = new SGL_Delegator(); 
    7070        $this->da->add($daUser); 
    7171        $this->da->add($daDefault); 
    7272 
    7373        $this->_aActionsMapping = array( 
    74             'add'                   => array('add'), 
    75             'insert'                => array('insert', 'redirectToDefault'), 
    76             'edit'                  => array('edit'), 
    77             'update'                => array('update', 'redirectToDefault'), 
    78             'delete'                => array('delete', 'redirectToDefault'), 
    79             'list'                  => array('list'), 
    80             'requestPasswordReset'  => array('requestPasswordReset'), 
    81             'resetPassword'         => array('resetPassword', 'redirectToDefault'), 
    82             'requestChangeUserStatus'  => array('requestChangeUserStatus'), 
    83             'changeUserStatus'      => array('changeUserStatus', 'redirectToDefault'), 
    84             'editPerms'             => array('editPerms'), 
    85             'updatePerms'           => array('updatePerms', 'redirectToDefault'), 
    86             'syncToRole'            => array('syncToRole', 'redirectToDefault'), 
    87             'viewLogin'             => array('viewLogin'), 
    88             'truncateLoginTbl'      => array('truncateLoginTbl', 'redirectToDefault'), 
     74            'add'                       => array('add'), 
     75            'insert'                    => array('insert', 'redirectToDefault'), 
     76            'edit'                      => array('edit'), 
     77            'update'                    => array('update', 'redirectToDefault'), 
     78            'delete'                    => array('delete', 'redirectToDefault'), 
     79            'list'                      => array('list'), 
     80            'requestPasswordReset'      => array('requestPasswordReset'), 
     81            'resetPassword'             => array('resetPassword', 'redirectToDefault'), 
     82            'requestChangeUserStatus'   => array('requestChangeUserStatus'), 
     83            'changeUserStatus'          => array('changeUserStatus', 'redirectToDefault'), 
     84            'editPerms'                 => array('editPerms'), 
     85            'updatePerms'               => array('updatePerms', 'redirectToDefault'), 
     86            'syncToRole'                => array('syncToRole', 'redirectToDefault'), 
     87            'viewLogin'                 => array('viewLogin'), 
     88            'deleteLogin'               => array('deleteLogin', 'redirectToDefault'), 
    8989        ); 
    9090    } 
    9191 
     
    9696        parent::validate($req, $input); 
    9797        $input->action = ($req->get('action')) ? $req->get('action') : 'list'; 
    9898 
    99         //     determine action based on which button was pressed 
     99        //  determine action based on which button was pressed 
    100100        if ($req->get('delete')) { $input->action = 'delete';} 
    101101        if ($req->get('syncToRole')) { $input->action = 'syncToRole';} 
    102102 
    103         $input->masterTemplate  = 'masterMinimal.html'; 
    104         $input->aPerms          = $req->get('frmPerms'); 
    105         $input->moduleId        = $req->get('frmModuleId'); 
    106         $input->from            = ($req->get('pageID'))? $req->get('pageID'):0; 
    107         $input->passwdResetNotify = ($req->get('frmPasswdResetNotify') == 'on') ? 1 : 0; 
    108         $input->changeStatusNotify = ($req->get('frmChangeStatusNotify') == 'on') ? 1 : 0; 
    109         $input->user->is_email_public = (isset($input->user->is_email_public)) ? 1 : 0; 
    110         $input->user->is_acct_active = (isset($input->user->is_acct_active)) ? 1 : 0; 
    111         $input->sortBy      = SGL_Util::getSortBy($req->get('frmSortBy'), SGL_SORTBY_USER); 
    112         $input->sortOrder   = SGL_Util::getSortOrder($req->get('frmSortOrder')); 
     103        $input->masterTemplate          = 'masterMinimal.html'; 
     104        $input->aPerms                  = $req->get('frmPerms'); 
     105        $input->moduleId                = $req->get('frmModuleId'); 
     106        $input->from                    = ($req->get('pageID'))? $req->get('pageID'):0; 
     107        $input->passwdResetNotify       = ($req->get('frmPasswdResetNotify') == 'on') ? 1 : 0; 
     108        $input->changeStatusNotify      = ($req->get('frmChangeStatusNotify') == 'on') ? 1 : 0; 
     109        $input->user->is_email_public   = (isset($input->user->is_email_public)) ? 1 : 0; 
     110        $input->user->is_acct_active    = (isset($input->user->is_acct_active)) ? 1 : 0; 
     111        $input->sortBy                  = SGL_Util::getSortBy($req->get('frmSortBy'), SGL_SORTBY_USER); 
     112        $input->sortOrder               = SGL_Util::getSortOrder($req->get('frmSortOrder')); 
    113113 
    114114        // This will tell HTML_Flexy which key is used to sort data 
    115115        $input->{ 'sort_' . $input->sortBy } = true; 
     
    176176    function _cmd_add(&$input, &$output) 
    177177    { 
    178178        SGL::logMessage(null, PEAR_LOG_DEBUG); 
    179  
    180         parent::_cmd_add($input, $output); 
    181179        $output->pageTitle = $input->pageTitle . ' :: Add'; 
     180         
     181        parent::_cmd_add($input, $output); 
    182182 
    183183        //  get default values for new users 
    184         $defaultRoleId = $this->conf['UserMgr']['defaultRoleId']; 
    185         $output->user->role_id = $defaultRoleId; 
    186         $output->user->username_orig = ''; 
    187         $output->user->email_orig = ''; 
     184        $output->user->role_id = $this->conf['UserMgr']['defaultRoleId']; 
    188185    } 
    189186 
    190187    function _cmd_insert(&$input, &$output) 
     
    201198        $oUser->created_by = $oUser->updated_by = SGL_Session::getUid(); 
    202199        $success = $this->da->addUser($oUser); 
    203200 
    204         //  check for errors 
     201        // show message on success (after redirect) 
    205202        if (!PEAR::isError($success)) { 
    206203            SGL::raiseMsg('user successfully added', true, SGL_MESSAGE_INFO); 
    207         } else { 
    208             SGL::raiseError('There was a problem inserting the record', 
    209                 SGL_ERROR_NOAFFECTEDROWS); 
    210204        } 
    211205    } 
    212206 
    213207    function _cmd_edit(&$input, &$output) 
    214208    { 
    215209        SGL::logMessage(null, PEAR_LOG_DEBUG); 
    216  
    217210        $output->pageTitle = $this->pageTitle . ' :: Edit'; 
    218211        $output->template = 'userAdd.html'; 
     212         
    219213        $oUser =