2010-11-24 15:43:08 +00:00
< ? php
2010-11-30 12:23:46 +00:00
/**
* Implementation of the user object in the document management system
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-11-30 12:23:46 +00:00
* @ license GPL 2
* @ version @ version @
* @ author Uwe Steinmann < uwe @ steinmann . cx >
* @ copyright Copyright ( C ) 2002 - 2005 Markus Westphal , 2006 - 2008 Malcolm Cowe ,
* 2010 Uwe Steinmann
* @ version Release : @ package_version @
*/
/**
* Class to represent a user in the document management system
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-11-30 12:23:46 +00:00
* @ author Markus Westphal , Malcolm Cowe , Uwe Steinmann < uwe @ steinmann . cx >
* @ copyright Copyright ( C ) 2002 - 2005 Markus Westphal , 2006 - 2008 Malcolm Cowe ,
* 2010 Uwe Steinmann
* @ version Release : @ package_version @
*/
2015-07-15 06:20:55 +00:00
class SeedDMS_Core_User { /* {{{ */
2010-12-05 20:29:33 +00:00
/**
* @ var integer id of user
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_id ;
2010-12-05 20:29:33 +00:00
/**
* @ var string login name of user
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_login ;
2010-12-05 20:29:33 +00:00
/**
* @ var string password of user as saved in database ( md5 )
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_pwd ;
2010-12-05 20:29:33 +00:00
2012-08-28 07:31:31 +00:00
/**
* @ var string date when password expires
*
* @ access protected
*/
var $_pwdExpiration ;
2010-12-05 20:29:33 +00:00
/**
* @ var string full human readable name of user
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_fullName ;
2010-12-05 20:29:33 +00:00
/**
* @ var string email address of user
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_email ;
2010-12-05 20:29:33 +00:00
/**
* @ var string prefered language of user
2015-07-15 06:20:55 +00:00
* possible values are subdirectories within the language directory
2010-12-05 20:29:33 +00:00
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_language ;
2010-12-05 20:29:33 +00:00
/**
* @ var string preselected theme of user
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_theme ;
2010-12-05 20:29:33 +00:00
/**
* @ var string comment of user
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_comment ;
2010-12-05 20:29:33 +00:00
/**
2013-02-14 11:10:53 +00:00
* @ var string role of user . Can be one of SeedDMS_Core_User :: role_user ,
* SeedDMS_Core_User :: role_admin , SeedDMS_Core_User :: role_guest
2010-12-05 20:29:33 +00:00
*
* @ access protected
*/
var $_role ;
/**
2012-08-28 07:31:31 +00:00
* @ var boolean true if user shall be hidden
2010-12-05 20:29:33 +00:00
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_isHidden ;
2010-12-05 20:29:33 +00:00
2012-08-28 07:31:31 +00:00
/**
* @ var boolean true if user is disabled
*
* @ access protected
*/
var $_isDisabled ;
/**
* @ var int number of login failures
*
* @ access protected
*/
var $_loginFailures ;
2014-03-26 07:16:53 +00:00
/**
2017-11-08 12:54:49 +00:00
* @ var SeedDMS_Core_Folder home folder
2014-03-26 07:16:53 +00:00
*
* @ access protected
*/
var $_homeFolder ;
2010-12-05 20:29:33 +00:00
/**
2017-11-08 12:54:49 +00:00
* @ var SeedDMS_Core_DMS reference to the dms instance this user belongs to
2010-12-05 20:29:33 +00:00
*
* @ access protected
*/
2010-11-24 15:43:08 +00:00
var $_dms ;
2018-02-08 08:25:45 +00:00
/**
* @ var int
*/
private $_quota ;
2017-11-08 12:54:49 +00:00
2018-02-08 08:25:45 +00:00
/**
* @ var bool
*/
private $_hasImage ;
2017-11-08 12:54:49 +00:00
2010-12-05 20:29:33 +00:00
const role_user = '0' ;
const role_admin = '1' ;
const role_guest = '2' ;
2018-02-08 08:25:45 +00:00
/**
* SeedDMS_Core_User constructor .
* @ param $id
* @ param $login
* @ param $pwd
* @ param $fullName
* @ param $email
* @ param $language
* @ param $theme
* @ param $comment
* @ param $role
* @ param int $isHidden
* @ param int $isDisabled
* @ param string $pwdExpiration
* @ param int $loginFailures
* @ param int $quota
* @ param null $homeFolder
*/
2017-02-20 14:01:58 +00:00
function __construct ( $id , $login , $pwd , $fullName , $email , $language , $theme , $comment , $role , $isHidden = 0 , $isDisabled = 0 , $pwdExpiration = '' , $loginFailures = 0 , $quota = 0 , $homeFolder = null ) {
2010-11-24 15:43:08 +00:00
$this -> _id = $id ;
$this -> _login = $login ;
$this -> _pwd = $pwd ;
$this -> _fullName = $fullName ;
$this -> _email = $email ;
$this -> _language = $language ;
$this -> _theme = $theme ;
$this -> _comment = $comment ;
2010-12-05 20:29:33 +00:00
$this -> _role = $role ;
2010-11-24 15:43:08 +00:00
$this -> _isHidden = $isHidden ;
2012-08-28 07:31:31 +00:00
$this -> _isDisabled = $isDisabled ;
$this -> _pwdExpiration = $pwdExpiration ;
$this -> _loginFailures = $loginFailures ;
2012-12-19 10:24:58 +00:00
$this -> _quota = $quota ;
2014-03-26 07:16:53 +00:00
$this -> _homeFolder = $homeFolder ;
2010-11-24 15:43:08 +00:00
$this -> _dms = null ;
}
2010-10-29 13:19:51 +00:00
2015-04-16 12:11:14 +00:00
/**
* Create an instance of a user object
*
* @ param string | integer $id Id , login name , or email of user , depending
* on the 3 rd parameter .
2017-11-08 12:54:49 +00:00
* @ param SeedDMS_Core_DMS $dms instance of dms
2015-04-16 12:11:14 +00:00
* @ param string $by search by [ name | email ] . If 'name' is passed , the method
* will check for the 4 th paramater and also filter by email . If this
* parameter is left empty , the user will be search by its Id .
* @ param string $email optional email address if searching for name
2018-02-08 08:25:45 +00:00
* @ return SeedDMS_Core_User | bool instance of class SeedDMS_Core_User if user was
* found , null if user was not found , false in case of error
2015-04-16 12:11:14 +00:00
*/
2015-04-14 17:37:06 +00:00
public static function getInstance ( $id , $dms , $by = '' , $email = '' ) { /* {{{ */
$db = $dms -> getDB ();
switch ( $by ) {
case 'name' :
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblUsers` WHERE `login` = " . $db -> qstr ( $id );
2015-04-14 17:37:06 +00:00
if ( $email )
2017-02-10 07:04:19 +00:00
$queryStr .= " AND `email`= " . $db -> qstr ( $email );
2015-04-14 17:37:06 +00:00
break ;
case 'email' :
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblUsers` WHERE `email` = " . $db -> qstr ( $id );
2015-04-14 17:37:06 +00:00
break ;
default :
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblUsers` WHERE `id` = " . ( int ) $id ;
2015-04-14 17:37:06 +00:00
}
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false ) return false ;
2017-12-22 12:02:14 +00:00
if ( count ( $resArr ) != 1 ) return null ;
2015-04-14 17:37:06 +00:00
$resArr = $resArr [ 0 ];
$user = new self ( $resArr [ " id " ], $resArr [ " login " ], $resArr [ " pwd " ], $resArr [ " fullName " ], $resArr [ " email " ], $resArr [ " language " ], $resArr [ " theme " ], $resArr [ " comment " ], $resArr [ " role " ], $resArr [ " hidden " ], $resArr [ " disabled " ], $resArr [ " pwdExpiration " ], $resArr [ " loginfailures " ], $resArr [ " quota " ], $resArr [ " homefolder " ]);
$user -> setDMS ( $dms );
return $user ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ param $orderby
* @ param SeedDMS_Core_DMS $dms
* @ return SeedDMS_Core_User [] | bool
*/
2015-04-14 17:37:06 +00:00
public static function getAllInstances ( $orderby , $dms ) { /* {{{ */
$db = $dms -> getDB ();
if ( $orderby == 'fullname' )
2017-02-11 15:33:48 +00:00
$queryStr = " SELECT * FROM `tblUsers` ORDER BY `fullName` " ;
2015-04-14 17:37:06 +00:00
else
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblUsers` ORDER BY `login` " ;
2015-04-14 17:37:06 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
$users = array ();
for ( $i = 0 ; $i < count ( $resArr ); $i ++ ) {
2017-11-08 12:54:49 +00:00
/** @var SeedDMS_Core_User $user */
2015-04-14 17:37:06 +00:00
$user = new self ( $resArr [ $i ][ " id " ], $resArr [ $i ][ " login " ], $resArr [ $i ][ " pwd " ], $resArr [ $i ][ " fullName " ], $resArr [ $i ][ " email " ], ( isset ( $resArr [ $i ][ " language " ]) ? $resArr [ $i ][ " language " ] : NULL ), ( isset ( $resArr [ $i ][ " theme " ]) ? $resArr [ $i ][ " theme " ] : NULL ), $resArr [ $i ][ " comment " ], $resArr [ $i ][ " role " ], $resArr [ $i ][ " hidden " ], $resArr [ $i ][ " disabled " ], $resArr [ $i ][ " pwdExpiration " ], $resArr [ $i ][ " loginfailures " ], $resArr [ $i ][ " quota " ], $resArr [ $i ][ " homefolder " ]);
$user -> setDMS ( $dms );
$users [ $i ] = $user ;
}
return $users ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ param SeedDMS_Core_DMS $dms
*/
2010-11-15 21:08:07 +00:00
function setDMS ( $dms ) {
$this -> _dms = $dms ;
}
2018-02-08 08:25:45 +00:00
/**
* @ return int
*/
2010-11-24 15:43:08 +00:00
function getID () { return $this -> _id ; }
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2010-11-24 15:43:08 +00:00
function getLogin () { return $this -> _login ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $newLogin
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setLogin ( $newLogin ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `login` = " . $db -> qstr ( $newLogin ) . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
$this -> _login = $newLogin ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2010-11-24 15:43:08 +00:00
function getFullName () { return $this -> _fullName ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $newFullName
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setFullName ( $newFullName ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-11 15:33:48 +00:00
$queryStr = " UPDATE `tblUsers` SET `fullName` = " . $db -> qstr ( $newFullName ) . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
$this -> _fullName = $newFullName ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2010-11-24 15:43:08 +00:00
function getPwd () { return $this -> _pwd ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $newPwd
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setPwd ( $newPwd ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `pwd` = " . $db -> qstr ( $newPwd ) . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
$this -> _pwd = $newPwd ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2012-08-28 07:31:31 +00:00
function getPwdExpiration () { return $this -> _pwdExpiration ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $newPwdExpiration
* @ return bool
*/
2012-08-28 07:31:31 +00:00
function setPwdExpiration ( $newPwdExpiration ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-14 10:31:49 +00:00
if ( trim ( $newPwdExpiration ) == '' || trim ( $newPwdExpiration ) == 'never' ) {
2017-02-20 14:01:58 +00:00
$queryStr = " UPDATE `tblUsers` SET `pwdExpiration` = NULL WHERE `id` = " . $this -> _id ;
2017-02-14 10:31:49 +00:00
} else {
if ( trim ( $newPwdExpiration ) == 'now' )
$newPwdExpiration = date ( 'Y-m-d H:i:s' );
$queryStr = " UPDATE `tblUsers` SET `pwdExpiration` = " . $db -> qstr ( $newPwdExpiration ) . " WHERE `id` = " . $this -> _id ;
}
2012-08-28 07:31:31 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
$this -> _pwdExpiration = $newPwdExpiration ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2010-11-24 15:43:08 +00:00
function getEmail () { return $this -> _email ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $newEmail
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setEmail ( $newEmail ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `email` = " . $db -> qstr ( $newEmail ) . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
$this -> _email = $newEmail ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2010-11-24 15:43:08 +00:00
function getLanguage () { return $this -> _language ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $newLanguage
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setLanguage ( $newLanguage ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `language` = " . $db -> qstr ( $newLanguage ) . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
$this -> _language = $newLanguage ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2010-11-24 15:43:08 +00:00
function getTheme () { return $this -> _theme ; }
2018-02-08 08:25:45 +00:00
/**
* @ param string $newTheme
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setTheme ( $newTheme ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `theme` = " . $db -> qstr ( $newTheme ) . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
$this -> _theme = $newTheme ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2010-11-24 15:43:08 +00:00
function getComment () { return $this -> _comment ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $newComment
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setComment ( $newComment ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `comment` = " . $db -> qstr ( $newComment ) . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
$this -> _comment = $newComment ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return string
*/
2010-12-05 20:29:33 +00:00
function getRole () { return $this -> _role ; }
2018-02-08 08:25:45 +00:00
/**
2018-06-27 16:51:59 +00:00
* @ param integer $newrole
2018-02-08 08:25:45 +00:00
* @ return bool
*/
2010-12-05 20:29:33 +00:00
function setRole ( $newrole ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2018-06-27 16:51:59 +00:00
$newrole = intval ( $newrole );
2010-12-05 20:29:33 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `role` = " . $newrole . " WHERE `id` = " . $this -> _id ;
2010-12-05 20:29:33 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _role = $newrole ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return bool
*/
2013-02-14 11:10:53 +00:00
function isAdmin () { return ( $this -> _role == SeedDMS_Core_User :: role_admin ); }
2010-11-24 15:43:08 +00:00
2018-02-08 08:25:45 +00:00
/**
* @ return bool
*/
function setAdmin () { /* {{{ */
2010-11-24 15:43:08 +00:00
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `role` = " . SeedDMS_Core_User :: role_admin . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
2013-02-14 11:10:53 +00:00
$this -> _role = SeedDMS_Core_User :: role_admin ;
2010-11-24 15:43:08 +00:00
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return bool
*/
2013-02-14 11:10:53 +00:00
function isGuest () { return ( $this -> _role == SeedDMS_Core_User :: role_guest ); }
2010-12-03 07:20:44 +00:00
2018-02-08 08:25:45 +00:00
/**
* @ return bool
*/
function setGuest () { /* {{{ */
2010-12-03 07:20:44 +00:00
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `role` = " . SeedDMS_Core_User :: role_guest . " WHERE `id` = " . $this -> _id ;
2010-12-03 07:20:44 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
2013-02-14 11:10:53 +00:00
$this -> _role = SeedDMS_Core_User :: role_guest ;
2010-12-03 07:20:44 +00:00
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return bool | int
*/
2010-11-24 15:43:08 +00:00
function isHidden () { return $this -> _isHidden ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $isHidden
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setHidden ( $isHidden ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$isHidden = ( $isHidden ) ? " 1 " : " 0 " ;
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `hidden` = " . $isHidden . " WHERE `id` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
2010-12-03 07:20:44 +00:00
$this -> _isHidden = $isHidden ;
2010-11-24 15:43:08 +00:00
return true ;
} /* }}} */
2010-11-05 21:17:41 +00:00
2018-02-08 08:25:45 +00:00
/**
* @ return bool | int
*/
2012-08-28 07:31:31 +00:00
function isDisabled () { return $this -> _isDisabled ; }
2018-02-08 08:25:45 +00:00
/**
* @ param $isDisabled
* @ return bool
*/
2012-08-28 07:31:31 +00:00
function setDisabled ( $isDisabled ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$isDisabled = ( $isDisabled ) ? " 1 " : " 0 " ;
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `disabled` = " . $isDisabled . " WHERE `id` = " . $this -> _id ;
2012-08-28 07:31:31 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _isDisabled = $isDisabled ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return bool | int
*/
2012-08-28 07:31:31 +00:00
function addLoginFailure () { /* {{{ */
$db = $this -> _dms -> getDB ();
$this -> _loginFailures ++ ;
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `loginfailures` = " . $this -> _loginFailures . " WHERE `id` = " . $this -> _id ;
2012-08-28 07:31:31 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
return $this -> _loginFailures ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return bool
*/
2012-08-28 07:31:31 +00:00
function clearLoginFailures () { /* {{{ */
$db = $this -> _dms -> getDB ();
$this -> _loginFailures = 0 ;
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `loginfailures` = " . $this -> _loginFailures . " WHERE `id` = " . $this -> _id ;
2012-08-28 07:31:31 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
return true ;
} /* }}} */
2013-02-06 13:55:05 +00:00
/**
* Calculate the disk space for all documents owned by the user
*
* This is done by using the internal database field storing the
* filesize of a document version .
*
* @ return integer total disk space in Bytes
*/
2012-12-19 10:24:58 +00:00
function getUsedDiskSpace () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT SUM(`fileSize`) sum FROM `tblDocumentContent` a LEFT JOIN `tblDocuments` b ON a.`document`=b.`id` WHERE b.`owner` = " . $this -> _id ;
2012-12-19 10:24:58 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
return $resArr [ 0 ][ 'sum' ];
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return int
*/
2012-12-19 10:24:58 +00:00
function getQuota () { return $this -> _quota ; }
2018-02-08 08:25:45 +00:00
/**
2018-06-27 16:51:59 +00:00
* @ param integer $quota
2018-02-08 08:25:45 +00:00
* @ return bool
*/
2012-12-19 10:24:58 +00:00
function setQuota ( $quota ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$quota = intval ( $quota );
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUsers` SET `quota` = " . $quota . " WHERE `id` = " . $this -> _id ;
2012-12-19 10:24:58 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _quota = $quota ;
return true ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ return null | SeedDMS_Core_Folder
*/
2014-03-26 07:16:53 +00:00
function getHomeFolder () { return $this -> _homeFolder ; }
2018-02-08 08:25:45 +00:00
/**
2018-06-27 16:51:59 +00:00
* @ param integer $homefolder
2018-02-08 08:25:45 +00:00
* @ return bool
*/
2014-03-26 07:16:53 +00:00
function setHomeFolder ( $homefolder ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2018-06-27 16:51:59 +00:00
$homefolder = intval ( $homefolder );
2014-03-26 07:16:53 +00:00
2018-06-27 16:51:59 +00:00
$queryStr = " UPDATE `tblUsers` SET `homefolder` = " . ( $homefolder ? $homefolder : NULL ) . " WHERE `id` = " . $this -> _id ;
2014-03-26 16:29:56 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _homeFolder = $homefolder ;
2014-03-26 07:16:53 +00:00
return true ;
} /* }}} */
2010-11-22 14:53:28 +00:00
/**
2017-07-28 07:35:12 +00:00
* Remove user from all processes
*
2017-07-28 12:56:18 +00:00
* This method adds another log entry to the reviews and approvals
2017-07-31 09:25:33 +00:00
* which indicates the user has been deleted from the process . By default it will
2017-07-28 12:56:18 +00:00
* do so for each review / approval regardless of its current state . So even
* reviews / approvals already processed by the user will be added the log
* entry . Only if the last log entry was a removal already , it will not be
* added a second time .
2017-07-28 07:35:12 +00:00
*
* @ param object $user the user doing the removal ( needed for entry in
* review and approve log ) .
2017-07-28 12:56:18 +00:00
* @ param array $states remove user only from reviews / approvals in one of the states
2017-07-31 09:25:33 +00:00
* If passing array ( 0 ), the method will operate on reviews / approval which
* has not been touched .
2017-07-28 07:35:12 +00:00
* @ return boolean true on success or false in case of an error
*/
2017-07-28 12:56:18 +00:00
private function __removeFromProcesses ( $user , $states = array ()) { /* {{{ */
2017-07-28 07:35:12 +00:00
$db = $this -> _dms -> getDB ();
$reviewStatus = $this -> getReviewStatus ();
foreach ( $reviewStatus [ " indstatus " ] as $ri ) {
2017-07-31 12:17:41 +00:00
if ( $ri [ 'status' ] != - 2 && ( ! isset ( $states [ 'review' ]) || in_array ( $ri [ 'status' ], $states [ 'review' ]))) {
2017-07-28 12:56:18 +00:00
$queryStr = " INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $ri [ " reviewID " ] . " ', '-2', 'Reviewer removed from process', " . $db -> getCurrentDatetime () . " , ' " . $user -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( ! $res ) {
return false ;
}
2017-07-28 07:35:12 +00:00
}
}
$approvalStatus = $this -> getApprovalStatus ();
foreach ( $approvalStatus [ " indstatus " ] as $ai ) {
2017-07-31 12:17:41 +00:00
if ( $ai [ 'status' ] != - 2 && ( ! isset ( $states [ 'approval' ]) || in_array ( $ai [ 'status' ], $states [ 'approval' ]))) {
2017-07-28 12:56:18 +00:00
$queryStr = " INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $ai [ " approveID " ] . " ', '-2', 'Approver removed from process', " . $db -> getCurrentDatetime () . " , ' " . $user -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( ! $res ) {
return false ;
}
2017-07-28 07:35:12 +00:00
}
}
return true ;
} /* }}} */
/**
* Remove user from all processes
*
* This includes review , approval and workflow
*
* @ param object $user the user doing the removal ( needed for entry in
* review and approve log ) .
2017-07-28 12:56:18 +00:00
* @ param array $states remove user only from reviews / approvals in one of the states
2017-07-28 07:35:12 +00:00
* @ return boolean true on success or false in case of an error
*/
2017-07-28 12:56:18 +00:00
public function removeFromProcesses ( $user , $states = array ()) { /* {{{ */
2017-07-28 07:35:12 +00:00
$db = $this -> _dms -> getDB ();
$db -> startTransaction ();
2017-07-28 12:56:18 +00:00
if ( ! $this -> __removeFromProcesses ( $user , $states )) {
2017-07-28 07:35:12 +00:00
$db -> rollbackTransaction ();
return false ;
}
$db -> commitTransaction ();
return true ;
} /* }}} */
2017-07-31 09:25:33 +00:00
/**
* Transfer documents and folders to another user
*
* @ param object $assignToUser the user who is new owner of folders and
* documents which previously were owned by the delete user .
* @ return boolean true on success or false in case of an error
*/
private function __transferDocumentsFolders ( $assignToUser ) { /* {{{ */
$db = $this -> _dms -> getDB ();
if ( ! $assignToUser )
return false ;
/* Assign documents of the removed user to the given user */
$queryStr = " UPDATE `tblFolders` SET `owner` = " . $assignToUser -> getID () . " WHERE `owner` = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr )) {
return false ;
}
$queryStr = " UPDATE `tblDocuments` SET `owner` = " . $assignToUser -> getID () . " WHERE `owner` = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr )) {
return false ;
}
$queryStr = " UPDATE `tblDocumentContent` SET `createdBy` = " . $assignToUser -> getID () . " WHERE `createdBy` = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr )) {
return false ;
}
// ... but keep public links
$queryStr = " UPDATE `tblDocumentLinks` SET `userID` = " . $assignToUser -> getID () . " WHERE `userID` = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr )) {
return false ;
}
// set administrator for deleted user's attachments
$queryStr = " UPDATE `tblDocumentFiles` SET `userID` = " . $assignToUser -> getID () . " WHERE `userID` = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr )) {
return false ;
}
return true ;
} /* }}} */
/**
* Transfer documents and folders to another user
*
* @ param object $assignToUser the user who is new owner of folders and
* documents which previously were owned by the delete user .
* @ return boolean true on success or false in case of an error
*/
public function transferDocumentsFolders ( $assignToUser ) { /* {{{ */
$db = $this -> _dms -> getDB ();
if ( $assignToUser -> getID () == $this -> _id )
return true ;
$db -> startTransaction ();
if ( ! $this -> __transferDocumentsFolders ( $assignToUser )) {
$db -> rollbackTransaction ();
return false ;
}
$db -> commitTransaction ();
return true ;
} /* }}} */
/**
* Transfer events to another user
*
* @ param object $assignToUser the user who is new owner of events
* @ return boolean true on success or false in case of an error
*/
private function __transferEvents ( $assignToUser ) { /* {{{ */
$db = $this -> _dms -> getDB ();
if ( ! $assignToUser )
return false ;
// set new owner of events
$queryStr = " UPDATE `tblEvents` SET `userID` = " . $assignToUser -> getID () . " WHERE `userID` = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr )) {
return false ;
}
return true ;
} /* }}} */
/**
* Transfer events to another user
*
* @ param object $assignToUser the user who is new owner of events
* @ return boolean true on success or false in case of an error
*/
public function transferEvents ( $assignToUser ) { /* {{{ */
$db = $this -> _dms -> getDB ();
if ( $assignToUser -> getID () == $this -> _id )
return true ;
$db -> startTransaction ();
if ( ! $this -> __transferEvents ( $assignToUser )) {
$db -> rollbackTransaction ();
return false ;
}
$db -> commitTransaction ();
return true ;
} /* }}} */
2017-07-28 07:35:12 +00:00
/**
* Remove the user and also remove all its keywords , notifications , etc .
2010-11-22 14:53:28 +00:00
* Do not remove folders and documents of the user , but assign them
* to a different user .
*
2017-11-08 12:54:49 +00:00
* @ param SeedDMS_Core_User $user the user doing the removal ( needed for entry in
2012-09-11 13:16:18 +00:00
* review and approve log ) .
2017-11-08 12:54:49 +00:00
* @ param SeedDMS_Core_User $assignToUser the user who is new owner of folders and
2010-11-22 14:53:28 +00:00
* documents which previously were owned by the delete user .
* @ return boolean true on success or false in case of an error
*/
2010-12-22 19:47:08 +00:00
function remove ( $user , $assignToUser = null ) { /* {{{ */
2010-11-24 15:43:08 +00:00
$db = $this -> _dms -> getDB ();
2010-11-05 21:17:41 +00:00
2010-11-22 14:53:28 +00:00
/* Records like folders and documents that formely have belonged to
* the user will assign to another user . If no such user is set ,
* the function now returns false and will not use the admin user
* anymore .
*/
if ( ! $assignToUser )
2017-11-08 12:54:49 +00:00
return false ;
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUnusedLocalVariableInspection */
$assignTo = $assignToUser -> getID ();
2010-11-22 14:53:28 +00:00
2012-10-22 13:33:30 +00:00
$db -> startTransaction ();
2010-11-22 14:53:28 +00:00
// delete private keyword lists
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT `tblKeywords`.`id` FROM `tblKeywords`, `tblKeywordCategories` WHERE `tblKeywords`.`category` = `tblKeywordCategories`.`id` AND `tblKeywordCategories`.`owner` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$resultArr = $db -> getResultArray ( $queryStr );
if ( count ( $resultArr ) > 0 ) {
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblKeywords` WHERE " ;
2010-11-24 15:43:08 +00:00
for ( $i = 0 ; $i < count ( $resultArr ); $i ++ ) {
$queryStr .= " id = " . $resultArr [ $i ][ " id " ];
if ( $i + 1 < count ( $resultArr ))
$queryStr .= " OR " ;
}
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-10-29 13:19:51 +00:00
}
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblKeywordCategories` WHERE `owner` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
//Benachrichtigungen entfernen
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblNotify` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2011-12-01 21:20:58 +00:00
// Remove private links on documents ...
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblDocumentLinks` WHERE `userID` = " . $this -> _id . " AND `public` = 0 " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2017-07-31 09:25:33 +00:00
/* Assign documents, folders, files, public document links of the removed user to the given user */
if ( ! $this -> __transferDocumentsFolders ( $assignToUser )) {
$db -> rollbackTransaction ();
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-24 15:43:08 +00:00
2016-02-10 09:03:21 +00:00
// unlock documents locked by the user
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblDocumentLocks` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2011-12-01 21:20:58 +00:00
// Delete user from all groups
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblGroupMembers` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2011-12-01 21:20:58 +00:00
// User aus allen ACLs streichen
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblACLs` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2011-12-01 21:20:58 +00:00
// Delete image of user
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblUserImages` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2012-08-28 07:48:59 +00:00
// Delete entries in password history
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblUserPasswordHistory` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2012-08-28 07:48:59 +00:00
// Delete entries in password request
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblUserPasswordRequest` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
// mandatory review/approve
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblMandatoryReviewers` WHERE `reviewerUserID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblMandatoryApprovers` WHERE `approverUserID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblMandatoryReviewers` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblMandatoryApprovers` WHERE `userID` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this -> _id ;
2013-01-24 08:29:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblWorkflowTransitionUsers` WHERE `userid` = " . $this -> _id ;
2013-02-05 09:09:53 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2017-07-31 09:25:33 +00:00
/* Assign events of the removed user to the given user */
if ( ! $this -> __transferEvents ( $assignToUser )) {
$db -> rollbackTransaction ();
return false ;
2012-10-22 13:33:30 +00:00
}
2010-10-29 13:19:51 +00:00
2012-10-22 13:33:30 +00:00
// Delete user itself
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblUsers` WHERE `id` = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-24 15:43:08 +00:00
2010-10-29 13:19:51 +00:00
// TODO : update document status if reviewer/approver has been deleted
2017-02-13 11:47:15 +00:00
// "DELETE FROM `tblDocumentApproveLog` WHERE `userID` = " . $this->_id;
// "DELETE FROM `tblDocumentReviewLog` WHERE `userID` = " . $this->_id;
2010-11-24 15:43:08 +00:00
2017-07-28 07:35:12 +00:00
if ( ! $this -> __removeFromProcesses ( $user )) {
2012-10-22 13:33:30 +00:00
$db -> rollbackTransaction ();
return false ;
2010-11-24 15:43:08 +00:00
}
2012-10-22 13:33:30 +00:00
$db -> commitTransaction ();
2010-11-24 15:43:08 +00:00
return true ;
2010-11-22 14:53:28 +00:00
} /* }}} */
2011-10-10 14:08:52 +00:00
/**
* Make the user a member of a group
2013-02-14 11:10:53 +00:00
* This function uses { @ link SeedDMS_Group :: addUser } but checks before if
2011-10-10 14:08:52 +00:00
* the user is already a member of the group .
*
2017-11-08 12:54:49 +00:00
* @ param SeedDMS_Core_Group $group group to be the member of
2011-10-10 14:08:52 +00:00
* @ return boolean true on success or false in case of an error or the user
* is already a member of the group
*/
2010-11-22 14:53:28 +00:00
function joinGroup ( $group ) { /* {{{ */
2010-11-24 15:43:08 +00:00
if ( $group -> isMember ( $this ))
return false ;
if ( ! $group -> addUser ( $this ))
return false ;
unset ( $this -> _groups );
return true ;
2010-11-22 14:53:28 +00:00
} /* }}} */
2010-11-24 15:43:08 +00:00
2011-10-10 14:08:52 +00:00
/**
* Removes the user from a group
2013-02-14 11:10:53 +00:00
* This function uses { @ link SeedDMS_Group :: removeUser } but checks before if
2011-10-10 14:08:52 +00:00
* the user is a member of the group at all .
*
2017-11-08 12:54:49 +00:00
* @ param SeedDMS_Core_Group $group group to leave
2011-10-10 14:08:52 +00:00
* @ return boolean true on success or false in case of an error or the user
* is not a member of the group
*/
2010-11-22 14:53:28 +00:00
function leaveGroup ( $group ) { /* {{{ */
2010-11-24 15:43:08 +00:00
if ( ! $group -> isMember ( $this ))
return false ;
if ( ! $group -> removeUser ( $this ))
return false ;
unset ( $this -> _groups );
return true ;
2010-11-22 14:53:28 +00:00
} /* }}} */
2010-11-24 15:43:08 +00:00
2011-10-10 14:08:52 +00:00
/**
* Get all groups the user is a member of
*
2017-11-08 12:54:49 +00:00
* @ return SeedDMS_Core_Group [] | bool list of groups
2011-10-10 14:08:52 +00:00
*/
2010-11-22 14:53:28 +00:00
function getGroups () { /* {{{ */
2010-11-24 15:43:08 +00:00
$db = $this -> _dms -> getDB ();
if ( ! isset ( $this -> _groups ))
{
$queryStr = " SELECT `tblGroups`.*, `tblGroupMembers`.`userID` FROM `tblGroups` " .
" LEFT JOIN `tblGroupMembers` ON `tblGroups`.`id` = `tblGroupMembers`.`groupID` " .
" WHERE `tblGroupMembers`.`userID`=' " . $this -> _id . " ' " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
$this -> _groups = array ();
2015-07-15 06:20:55 +00:00
$classname = $this -> _dms -> getClassname ( 'group' );
2010-11-24 15:43:08 +00:00
foreach ( $resArr as $row ) {
2017-11-08 12:54:49 +00:00
/** @var SeedDMS_Core_Group $group */
2015-07-15 06:20:55 +00:00
$group = new $classname ( $row [ " id " ], $row [ " name " ], $row [ " comment " ]);
2012-09-11 12:55:54 +00:00
$group -> setDMS ( $this -> _dms );
2010-11-24 15:43:08 +00:00
array_push ( $this -> _groups , $group );
}
}
return $this -> _groups ;
2010-11-22 14:53:28 +00:00
} /* }}} */
2010-11-24 15:43:08 +00:00
2010-11-22 14:53:28 +00:00
/**
* Checks if user is member of a given group
*
2017-11-08 12:54:49 +00:00
* @ param SeedDMS_Core_Group $group
2010-11-22 14:53:28 +00:00
* @ return boolean true if user is member of the given group otherwise false
*/
function isMemberOfGroup ( $group ) { /* {{{ */
2010-11-24 15:43:08 +00:00
return $group -> isMember ( $this );
2010-11-22 14:53:28 +00:00
} /* }}} */
/**
* Check if user has an image in its profile
*
* @ return boolean true if user has a picture of itself
*/
function hasImage () { /* {{{ */
2010-11-24 15:43:08 +00:00
if ( ! isset ( $this -> _hasImage )) {
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT COUNT(*) AS num FROM `tblUserImages` WHERE `userID` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2012-01-12 17:02:00 +00:00
if ( $resArr === false )
2010-11-24 15:43:08 +00:00
return false ;
if ( $resArr [ 0 ][ " num " ] == 0 ) $this -> _hasImage = false ;
else $this -> _hasImage = true ;
}
return $this -> _hasImage ;
2010-11-22 14:53:28 +00:00
} /* }}} */
2010-11-24 15:43:08 +00:00
2010-12-21 17:39:16 +00:00
/**
* Get the image from the users profile
*
2017-11-08 12:54:49 +00:00
* @ return array | bool image data
2010-12-21 17:39:16 +00:00
*/
function getImage () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblUserImages` WHERE `userID` = " . $this -> _id ;
2010-12-21 17:39:16 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2012-01-12 17:02:00 +00:00
if ( $resArr === false )
2010-12-21 17:39:16 +00:00
return false ;
2012-01-12 17:02:00 +00:00
if ( $resArr )
$resArr = $resArr [ 0 ];
2010-12-21 17:39:16 +00:00
return $resArr ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/**
* @ param $tmpfile
* @ param $mimeType
* @ return bool
*/
2010-11-24 15:43:08 +00:00
function setImage ( $tmpfile , $mimeType ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$fp = fopen ( $tmpfile , " rb " );
if ( ! $fp ) return false ;
$content = fread ( $fp , filesize ( $tmpfile ));
fclose ( $fp );
if ( $this -> hasImage ())
2017-02-10 07:04:19 +00:00
$queryStr = " UPDATE `tblUserImages` SET `image` = ' " . base64_encode ( $content ) . " ', `mimeType` = " . $db -> qstr ( $mimeType ) . " WHERE `userID` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
else
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblUserImages` (`userID`, `image`, `mimeType`) VALUES ( " . $this -> _id . " , ' " . base64_encode ( $content ) . " ', " . $db -> qstr ( $mimeType ) . " ) " ;
2010-11-24 15:43:08 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _hasImage = true ;
return true ;
} /* }}} */
2013-02-05 09:09:53 +00:00
/**
* Returns all documents of a given user
2018-02-08 08:25:45 +00:00
* @ return SeedDMS_Core_Document [] | bool list of documents
2013-02-05 09:09:53 +00:00
*/
function getDocuments () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser` " .
" FROM `tblDocuments` " .
" LEFT JOIN `tblDocumentLocks` ON `tblDocuments`.`id`=`tblDocumentLocks`.`document` " .
" WHERE `tblDocuments`.`owner` = " . $this -> _id . " ORDER BY `sequence` " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$documents = array ();
2015-07-15 06:20:55 +00:00
$classname = $this -> _dms -> getClassname ( 'document' );
2013-02-05 09:09:53 +00:00
foreach ( $resArr as $row ) {
2017-11-08 12:54:49 +00:00
/** @var SeedDMS_Core_Document $document */
2015-07-15 06:20:55 +00:00
$document = new $classname ( $row [ " id " ], $row [ " name " ], $row [ " comment " ], $row [ " date " ], $row [ " expires " ], $row [ " owner " ], $row [ " folder " ], $row [ " inheritAccess " ], $row [ " defaultAccess " ], $row [ " lockUser " ], $row [ " keywords " ], $row [ " sequence " ]);
2013-02-05 09:09:53 +00:00
$document -> setDMS ( $this -> _dms );
$documents [] = $document ;
}
return $documents ;
} /* }}} */
/**
* Returns all documents locked by a given user
*
2017-11-08 12:54:49 +00:00
* @ return bool | SeedDMS_Core_Document [] list of documents
2013-02-05 09:09:53 +00:00
*/
function getDocumentsLocked () { /* {{{ */
$db = $this -> _dms -> getDB ();
2016-02-15 14:14:42 +00:00
$queryStr = " SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser` " .
2013-02-05 09:09:53 +00:00
" FROM `tblDocumentLocks` LEFT JOIN `tblDocuments` ON `tblDocuments`.`id` = `tblDocumentLocks`.`document` " .
" WHERE `tblDocumentLocks`.`userID` = ' " . $this -> _id . " ' " .
" ORDER BY `id` DESC " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$documents = array ();
2015-07-15 06:20:55 +00:00
$classname = $this -> _dms -> getClassname ( 'document' );
2013-02-05 09:09:53 +00:00
foreach ( $resArr as $row ) {
2017-11-08 12:54:49 +00:00
/** @var SeedDMS_Core_Document $document */
2015-07-15 06:20:55 +00:00
$document = new $classname ( $row [ " id " ], $row [ " name " ], $row [ " comment " ], $row [ " date " ], $row [ " expires " ], $row [ " owner " ], $row [ " folder " ], $row [ " inheritAccess " ], $row [ " defaultAccess " ], $row [ " lockUser " ], $row [ " keywords " ], $row [ " sequence " ]);
2013-02-05 09:09:53 +00:00
$document -> setDMS ( $this -> _dms );
$documents [] = $document ;
}
return $documents ;
} /* }}} */
2011-10-12 06:16:44 +00:00
/**
* Get a list of reviews
2017-07-28 12:56:18 +00:00
*
* This function returns a list of all reviews and their latest log entry
* seperated by individuals and groups . If the document id
2015-07-15 06:20:55 +00:00
* is passed , then only this document will be checked for reviews . The
2011-10-12 06:16:44 +00:00
* same is true for the version of a document which limits the list
2017-07-28 12:56:18 +00:00
* further . If you do not limit on a version it will retrieve the status
* for each version , that includes even older versions which has been superseded
* by a new version .
2011-10-12 06:16:44 +00:00
*
2016-02-10 09:03:21 +00:00
* For a detailed description of the result array see
2013-02-14 11:10:53 +00:00
* { link SeedDMS_Core_User :: getApprovalStatus } which does the same for
2013-02-11 07:47:52 +00:00
* approvals .
2011-10-12 06:16:44 +00:00
*
* @ param int $documentID optional document id for which to retrieve the
* reviews
* @ param int $version optional version of the document
2017-11-08 12:54:49 +00:00
* @ return array | bool list of all reviews
2011-10-12 06:16:44 +00:00
*/
2010-11-24 15:43:08 +00:00
function getReviewStatus ( $documentID = null , $version = null ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$status = array ( " indstatus " => array (), " grpstatus " => array ());
// See if the user is assigned as an individual reviewer.
$queryStr = " SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, " .
" `tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, " .
" `tblDocumentReviewLog`.`userID` " .
" FROM `tblDocumentReviewers` " .
" LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) " .
2011-10-12 06:16:44 +00:00
" WHERE `tblDocumentReviewers`.`type`='0' " .
2011-12-01 21:20:58 +00:00
( $documentID == null ? " " : " AND `tblDocumentReviewers`.`documentID` = ' " . ( int ) $documentID . " ' " ) .
( $version == null ? " " : " AND `tblDocumentReviewers`.`version` = ' " . ( int ) $version . " ' " ) .
2011-10-12 06:16:44 +00:00
" AND `tblDocumentReviewers`.`required`=' " . $this -> _id . " ' " .
2013-01-24 08:29:30 +00:00
" ORDER BY `tblDocumentReviewLog`.`reviewLogID` DESC " ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2013-02-06 13:55:05 +00:00
if ( is_bool ( $resArr ) && $resArr === false )
2010-11-24 15:43:08 +00:00
return false ;
if ( count ( $resArr ) > 0 ) {
2013-01-24 08:29:30 +00:00
foreach ( $resArr as $res ) {
if ( isset ( $status [ " indstatus " ][ $res [ 'documentID' ]])) {
if ( $status [ " indstatus " ][ $res [ 'documentID' ]][ 'date' ] < $res [ 'date' ]) {
$status [ " indstatus " ][ $res [ 'documentID' ]] = $res ;
}
} else {
$status [ " indstatus " ][ $res [ 'documentID' ]] = $res ;
}
}
2010-11-24 15:43:08 +00:00
}
// See if the user is the member of a group that has been assigned to
// review the document version.
$queryStr = " SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, " .
" `tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, " .
" `tblDocumentReviewLog`.`userID` " .
" FROM `tblDocumentReviewers` " .
" LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) " .
" LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`groupID` = `tblDocumentReviewers`.`required` " .
2011-10-12 06:16:44 +00:00
" WHERE `tblDocumentReviewers`.`type`='1' " .
2011-12-01 21:20:58 +00:00
( $documentID == null ? " " : " AND `tblDocumentReviewers`.`documentID` = ' " . ( int ) $documentID . " ' " ) .
( $version == null ? " " : " AND `tblDocumentReviewers`.`version` = ' " . ( int ) $version . " ' " ) .
2011-10-12 06:16:44 +00:00
" AND `tblGroupMembers`.`userID`=' " . $this -> _id . " ' " .
2013-01-24 08:29:30 +00:00
" ORDER BY `tblDocumentReviewLog`.`reviewLogID` DESC " ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2013-02-06 13:55:05 +00:00
if ( is_bool ( $resArr ) && $resArr === false )
2010-11-24 15:43:08 +00:00
return false ;
if ( count ( $resArr ) > 0 ) {
2013-01-24 08:29:30 +00:00
foreach ( $resArr as $res ) {
if ( isset ( $status [ " grpstatus " ][ $res [ 'documentID' ]])) {
if ( $status [ " grpstatus " ][ $res [ 'documentID' ]][ 'date' ] < $res [ 'date' ]) {
$status [ " grpstatus " ][ $res [ 'documentID' ]] = $res ;
}
} else {
$status [ " grpstatus " ][ $res [ 'documentID' ]] = $res ;
}
}
2010-11-24 15:43:08 +00:00
}
return $status ;
2010-11-22 14:53:28 +00:00
} /* }}} */
2010-11-24 15:43:08 +00:00
2011-10-12 06:16:44 +00:00
/**
* Get a list of approvals
2017-07-28 12:56:18 +00:00
*
* This function returns a list of all approvals and their latest log entry
* seperated by individuals and groups . If the document id
2011-10-12 06:16:44 +00:00
* is passed , then only this document will be checked for approvals . The
* same is true for the version of a document which limits the list
2017-07-28 12:56:18 +00:00
* further . If you do not limit on a version it will retrieve the status
* for each version , that includes even older versions which has been superseded
* by a new version .
2011-10-12 06:16:44 +00:00
*
* The result array has two elements :
* - indstatus : which contains the approvals by individuals ( users )
* - grpstatus : which contains the approvals by groups
*
2017-07-28 12:56:18 +00:00
* Each element is itself an array of approvals with the following elements
* ( it is a combination of fields from tblDocumentApprovers and tblDocumentApproveLog ) :
2011-10-12 06:16:44 +00:00
* - approveID : unique id of approval
* - documentID : id of document , that needs to be approved
* - version : version of document , that needs to be approved
* - type : 0 for individual approval , 1 for group approval
* - required : id of user who is required to do the approval
* - status : 0 not approved , ....
* - comment : comment given during approval
* - date : date of approval
* - userID : id of user who has done the approval
*
* @ param int $documentID optional document id for which to retrieve the
* approvals
* @ param int $version optional version of the document
2017-11-08 12:54:49 +00:00
* @ return array | bool list of all approvals
2011-10-12 06:16:44 +00:00
*/
2010-11-24 15:43:08 +00:00
function getApprovalStatus ( $documentID = null , $version = null ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$status = array ( " indstatus " => array (), " grpstatus " => array ());
2011-11-29 07:18:19 +00:00
$queryStr =
2018-02-08 08:25:45 +00:00
" SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, " .
2011-10-12 06:16:44 +00:00
" `tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, " .
" `tblDocumentApproveLog`.`userID` " .
" FROM `tblDocumentApprovers` " .
" LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) " .
" WHERE `tblDocumentApprovers`.`type`='0' " .
2011-12-01 21:20:58 +00:00
( $documentID == null ? " " : " AND `tblDocumentApprovers`.`documentID` = ' " . ( int ) $documentID . " ' " ) .
( $version == null ? " " : " AND `tblDocumentApprovers`.`version` = ' " . ( int ) $version . " ' " ) .
2011-10-12 06:16:44 +00:00
" AND `tblDocumentApprovers`.`required`=' " . $this -> _id . " ' " .
2013-01-24 08:29:30 +00:00
" ORDER BY `tblDocumentApproveLog`.`approveLogID` DESC " ;
2011-10-12 06:16:44 +00:00
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) > 0 ) {
2013-01-24 08:29:30 +00:00
foreach ( $resArr as $res ) {
if ( isset ( $status [ " indstatus " ][ $res [ 'documentID' ]])) {
if ( $status [ " indstatus " ][ $res [ 'documentID' ]][ 'date' ] < $res [ 'date' ]) {
$status [ " indstatus " ][ $res [ 'documentID' ]] = $res ;
}
} else {
$status [ " indstatus " ][ $res [ 'documentID' ]] = $res ;
}
}
2010-11-24 15:43:08 +00:00
}
// See if the user is the member of a group that has been assigned to
// approve the document version.
2011-10-12 06:16:44 +00:00
$queryStr =
" SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, " .
" `tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, " .
" `tblDocumentApproveLog`.`userID` " .
" FROM `tblDocumentApprovers` " .
" LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) " .
" LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`groupID` = `tblDocumentApprovers`.`required` " .
" WHERE `tblDocumentApprovers`.`type`='1' " .
2011-12-01 21:20:58 +00:00
( $documentID == null ? " " : " AND `tblDocumentApprovers`.`documentID` = ' " . ( int ) $documentID . " ' " ) .
( $version == null ? " " : " AND `tblDocumentApprovers`.`version` = ' " . ( int ) $version . " ' " ) .
2011-10-12 06:16:44 +00:00
" AND `tblGroupMembers`.`userID`=' " . $this -> _id . " ' " .
2013-01-24 08:29:30 +00:00
" ORDER BY `tblDocumentApproveLog`.`approveLogID` DESC " ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) > 0 ) {
2013-01-24 08:29:30 +00:00
foreach ( $resArr as $res ) {
if ( isset ( $status [ " grpstatus " ][ $res [ 'documentID' ]])) {
if ( $status [ " grpstatus " ][ $res [ 'documentID' ]][ 'date' ] < $res [ 'date' ]) {
$status [ " grpstatus " ][ $res [ 'documentID' ]] = $res ;
}
} else {
$status [ " grpstatus " ][ $res [ 'documentID' ]] = $res ;
}
}
2010-11-24 15:43:08 +00:00
}
return $status ;
} /* }}} */
2013-02-02 16:01:10 +00:00
/**
* Get a list of documents with a workflow
*
* @ param int $documentID optional document id for which to retrieve the
* reviews
* @ param int $version optional version of the document
2017-11-08 12:54:49 +00:00
* @ return array | bool list of all workflows
2013-02-02 16:01:10 +00:00
*/
function getWorkflowStatus ( $documentID = null , $version = null ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = 'SELECT DISTINCT d.*, c.`userid` FROM `tblWorkflowTransitions` a LEFT JOIN `tblWorkflows` b ON a.`workflow`=b.`id` LEFT JOIN `tblWorkflowTransitionUsers` c ON a.`id`=c.`transition` LEFT JOIN `tblWorkflowDocumentContent` d ON b.`id`=d.`workflow` WHERE d.`document` IS NOT NULL AND a.`state`=d.`state` AND c.`userid`=' . $this -> _id ;
2013-02-05 09:09:53 +00:00
if ( $documentID ) {
2017-02-10 07:04:19 +00:00
$queryStr .= ' AND d.`document`=' . ( int ) $documentID ;
2013-02-05 09:09:53 +00:00
if ( $version )
2017-02-10 07:04:19 +00:00
$queryStr .= ' AND d.`version`=' . ( int ) $version ;
2013-02-05 09:09:53 +00:00
}
2013-02-02 16:01:10 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
$result [ 'u' ] = array ();
if ( count ( $resArr ) > 0 ) {
foreach ( $resArr as $res ) {
$result [ 'u' ][] = $res ;
}
}
2017-02-10 07:04:19 +00:00
$queryStr = 'select distinct d.*, c.`groupid` from `tblWorkflowTransitions` a left join `tblWorkflows` b on a.`workflow`=b.`id` left join `tblWorkflowTransitionGroups` c on a.`id`=c.`transition` left join `tblWorkflowDocumentContent` d on b.`id`=d.`workflow` left join `tblGroupMembers` e on c.`groupid` = e.`groupID` where d.`document` is not null and a.`state`=d.`state` and e.`userID`=' . $this -> _id ;
2013-02-05 09:09:53 +00:00
if ( $documentID ) {
2017-02-10 07:04:19 +00:00
$queryStr .= ' AND d.`document`=' . ( int ) $documentID ;
2013-02-05 09:09:53 +00:00
if ( $version )
2017-02-10 07:04:19 +00:00
$queryStr .= ' AND d.`version`=' . ( int ) $version ;
2013-02-05 09:09:53 +00:00
}
2013-02-02 16:01:10 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
$result [ 'g' ] = array ();
if ( count ( $resArr ) > 0 ) {
foreach ( $resArr as $res ) {
$result [ 'g' ][] = $res ;
}
}
return $result ;
} /* }}} */
2017-07-28 07:35:12 +00:00
/**
* Get a list of workflows this user is involved as in individual
*
2017-11-08 12:54:49 +00:00
* @ return array | bool list of all workflows
2017-07-28 07:35:12 +00:00
*/
function getWorkflowsInvolved () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = 'SELECT DISTINCT b.*, c.`userid` FROM `tblWorkflowTransitions` a LEFT JOIN `tblWorkflows` b ON a.`workflow`=b.`id` LEFT JOIN `tblWorkflowTransitionUsers` c ON a.`id`=c.`transition` WHERE c.`userid`=' . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
$result = array ();
if ( count ( $resArr ) > 0 ) {
foreach ( $resArr as $res ) {
$result [] = $this -> _dms -> getWorkflow ( $res [ 'id' ]);
}
}
return $result ;
} /* }}} */
2011-10-12 06:16:44 +00:00
/**
* Get a list of mandatory reviewers
* A user which isn ' t trusted completely may have assigned mandatory
* reviewers ( both users and groups ) .
* Whenever the user inserts a new document the mandatory reviewers are
* filled in as reviewers .
*
* @ return array list of arrays with two elements containing the user id
* ( reviewerUserID ) and group id ( reviewerGroupID ) of the reviewer .
*/
2010-11-24 15:43:08 +00:00
function getMandatoryReviewers () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblMandatoryReviewers` WHERE `userID` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2010-10-29 13:19:51 +00:00
return $resArr ;
2010-11-24 15:43:08 +00:00
} /* }}} */
2011-10-12 06:16:44 +00:00
/**
* Get a list of mandatory approvers
2013-02-14 11:10:53 +00:00
* See { link SeedDMS_Core_User :: getMandatoryReviewers }
2011-10-12 06:16:44 +00:00
*
* @ return array list of arrays with two elements containing the user id
* ( approverUserID ) and group id ( approverGroupID ) of the approver .
*/
2010-11-24 15:43:08 +00:00
function getMandatoryApprovers () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblMandatoryApprovers` WHERE `userID` = " . $this -> _id ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2010-10-29 13:19:51 +00:00
return $resArr ;
2010-11-24 15:43:08 +00:00
} /* }}} */
2017-07-28 16:22:53 +00:00
/**
* Get a list of users this user is a mandatory reviewer of
*
* This method is the reverse function of getMandatoryReviewers () . It returns
* those user where the current user is a mandatory reviewer .
*
2017-11-08 12:54:49 +00:00
* @ return SeedDMS_Core_User [] | bool list of users where this user is a mandatory reviewer .
2017-07-28 16:22:53 +00:00
*/
function isMandatoryReviewerOf () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT * FROM `tblMandatoryReviewers` WHERE `reviewerUserID` = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
$users = array ();
foreach ( $resArr as $res ) {
$users [] = self :: getInstance ( $res [ 'userID' ], $this -> _dms );
}
return $users ;
} /* }}} */
/**
* Get a list of users this user is a mandatory approver of
*
* This method is the reverse function of getMandatoryApprovers () . It returns
* those user where the current user is a mandatory approver .
*
2017-11-08 12:54:49 +00:00
* @ return SeedDMS_Core_User [] | bool list of users where this user is a mandatory approver .
2017-07-28 16:22:53 +00:00
*/
function isMandatoryApproverOf () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT * FROM `tblMandatoryApprovers` WHERE `approverUserID` = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
$users = array ();
foreach ( $resArr as $res ) {
$users [] = self :: getInstance ( $res [ 'userID' ], $this -> _dms );
}
return $users ;
} /* }}} */
2013-01-24 08:29:30 +00:00
/**
* Get the mandatory workflow
* A user which isn ' t trusted completely may have assigned mandatory
* workflow
* Whenever the user inserts a new document the mandatory workflow is
* filled in as the workflow .
*
2017-11-08 12:54:49 +00:00
* @ return SeedDMS_Core_Workflow | bool workflow
2013-01-24 08:29:30 +00:00
*/
function getMandatoryWorkflow () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this -> _id ;
2013-01-24 08:29:30 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
if ( ! $resArr )
return null ;
$workflow = $this -> _dms -> getWorkflow ( $resArr [ 0 ][ 'workflow' ]);
return $workflow ;
} /* }}} */
2016-01-27 15:18:12 +00:00
/**
* Get the mandatory workflows
* A user which isn ' t trusted completely may have assigned mandatory
* workflow
* Whenever the user inserts a new document the mandatory workflow is
* filled in as the workflow .
*
2017-11-08 12:54:49 +00:00
* @ return SeedDMS_Core_Workflow [] | bool workflow
2016-01-27 15:18:12 +00:00
*/
function getMandatoryWorkflows () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this -> _id ;
2016-01-27 15:18:12 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
if ( ! $resArr )
return null ;
$workflows = array ();
foreach ( $resArr as $res ) {
$workflows [] = $this -> _dms -> getWorkflow ( $res [ 'workflow' ]);
}
return $workflows ;
} /* }}} */
2011-10-12 06:16:44 +00:00
/**
* Set a mandatory reviewer
* This function sets a mandatory reviewer if it isn ' t already set .
*
* @ param integer $id id of reviewer
* @ param boolean $isgroup true if $id is a group
* @ return boolean true on success , otherwise false
*/
2010-11-24 15:43:08 +00:00
function setMandatoryReviewer ( $id , $isgroup = false ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2018-06-27 16:51:59 +00:00
$id = ( int ) $id ;
2010-11-24 15:43:08 +00:00
2010-10-29 13:19:51 +00:00
if ( $isgroup ){
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblMandatoryReviewers` WHERE `userID` = " . $this -> _id . " AND `reviewerGroupID` = " . $id ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2011-10-12 06:16:44 +00:00
if ( count ( $resArr ) != 0 ) return true ;
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblMandatoryReviewers` (`userID`, `reviewerGroupID`) VALUES ( " . $this -> _id . " , " . $id . " ) " ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResult ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
2010-10-29 13:19:51 +00:00
} else {
2010-11-24 15:43:08 +00:00
2017-02-14 20:12:50 +00:00
$queryStr = " SELECT * FROM `tblMandatoryReviewers` WHERE `userID` = " . $this -> _id . " AND `reviewerUserID` = " . $id ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2011-10-12 06:16:44 +00:00
if ( count ( $resArr ) != 0 ) return true ;
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblMandatoryReviewers` (`userID`, `reviewerUserID`) VALUES ( " . $this -> _id . " , " . $id . " ) " ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResult ( $queryStr );
2010-10-29 13:19:51 +00:00
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
2010-11-24 15:43:08 +00:00
}
2017-11-08 12:54:49 +00:00
return false ;
2010-11-24 15:43:08 +00:00
} /* }}} */
2011-10-12 06:16:44 +00:00
/**
* Set a mandatory approver
* This function sets a mandatory approver if it isn ' t already set .
*
* @ param integer $id id of approver
* @ param boolean $isgroup true if $id is a group
* @ return boolean true on success , otherwise false
*/
2010-11-24 15:43:08 +00:00
function setMandatoryApprover ( $id , $isgroup = false ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2018-06-27 16:51:59 +00:00
$id = ( int ) $id ;
2010-11-24 15:43:08 +00:00
2010-10-29 13:19:51 +00:00
if ( $isgroup ){
2010-11-24 15:43:08 +00:00
2018-06-27 16:51:59 +00:00
$queryStr = " SELECT * FROM `tblMandatoryApprovers` WHERE `userID` = " . $this -> _id . " AND `approverGroupID` = " . $id ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2017-11-08 12:54:49 +00:00
if ( count ( $resArr ) != 0 ) return true ;
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblMandatoryApprovers` (`userID`, `approverGroupID`) VALUES ( " . $this -> _id . " , " . $id . " ) " ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResult ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
2010-10-29 13:19:51 +00:00
} else {
2010-11-24 15:43:08 +00:00
2018-06-27 16:51:59 +00:00
$queryStr = " SELECT * FROM `tblMandatoryApprovers` WHERE `userID` = " . $this -> _id . " AND `approverUserID` = " . $id ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2017-11-08 12:54:49 +00:00
if ( count ( $resArr ) != 0 ) return true ;
2010-11-24 15:43:08 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblMandatoryApprovers` (`userID`, `approverUserID`) VALUES ( " . $this -> _id . " , " . $id . " ) " ;
2010-11-24 15:43:08 +00:00
$resArr = $db -> getResult ( $queryStr );
2010-10-29 13:19:51 +00:00
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
}
2017-11-08 12:54:49 +00:00
return false ;
2010-11-24 15:43:08 +00:00
} /* }}} */
2013-01-24 08:29:30 +00:00
/**
* Set a mandatory workflow
* This function sets a mandatory workflow if it isn ' t already set .
*
* @ param object $workflow workflow
* @ return boolean true on success , otherwise false
*/
function setMandatoryWorkflow ( $workflow ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this -> _id . " AND `workflow` = " . ( int ) $workflow -> getID ();
2013-01-24 08:29:30 +00:00
$resArr = $db -> getResultArray ( $queryStr );
2017-11-08 12:54:49 +00:00
if ( count ( $resArr ) != 0 ) return true ;
2013-01-24 08:29:30 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblWorkflowMandatoryWorkflow` (`userid`, `workflow`) VALUES ( " . $this -> _id . " , " . $workflow -> getID () . " ) " ;
2013-01-24 08:29:30 +00:00
$resArr = $db -> getResult ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
2017-11-08 12:54:49 +00:00
return false ;
2013-01-24 08:29:30 +00:00
} /* }}} */
2016-01-27 15:18:12 +00:00
/**
* Set a mandatory workflows
* This function sets a list of mandatory workflows .
*
2017-11-08 12:54:49 +00:00
* @ param SeedDMS_Core_Workflow [] $workflows list of workflow objects
2016-01-27 15:18:12 +00:00
* @ return boolean true on success , otherwise false
*/
function setMandatoryWorkflows ( $workflows ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$db -> startTransaction ();
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this -> _id ;
2016-01-27 15:18:12 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
foreach ( $workflows as $workflow ) {
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblWorkflowMandatoryWorkflow` (`userid`, `workflow`) VALUES ( " . $this -> _id . " , " . $workflow -> getID () . " ) " ;
2016-01-27 15:18:12 +00:00
$resArr = $db -> getResult ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) {
$db -> rollbackTransaction ();
return false ;
}
}
$db -> commitTransaction ();
return true ;
} /* }}} */
2013-01-24 08:29:30 +00:00
2011-10-12 06:16:44 +00:00
/**
* Deletes all mandatory reviewers
*
* @ return boolean true on success , otherwise false
*/
2010-11-24 15:43:08 +00:00
function delMandatoryReviewers () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblMandatoryReviewers` WHERE `userID` = " . $this -> _id ;
2010-10-29 13:19:51 +00:00
if ( ! $db -> getResult ( $queryStr )) return false ;
2011-10-12 06:16:44 +00:00
return true ;
2010-11-24 15:43:08 +00:00
} /* }}} */
2011-10-12 06:16:44 +00:00
/**
* Deletes all mandatory approvers
*
* @ return boolean true on success , otherwise false
*/
2010-11-24 15:43:08 +00:00
function delMandatoryApprovers () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblMandatoryApprovers` WHERE `userID` = " . $this -> _id ;
2010-10-29 13:19:51 +00:00
if ( ! $db -> getResult ( $queryStr )) return false ;
2011-10-12 06:16:44 +00:00
return true ;
2010-11-24 15:43:08 +00:00
} /* }}} */
2011-10-10 14:08:52 +00:00
2013-01-24 08:29:30 +00:00
/**
* Deletes the mandatory workflow
*
* @ return boolean true on success , otherwise false
*/
function delMandatoryWorkflow () { /* {{{ */
$db = $this -> _dms -> getDB ();
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this -> _id ;
2013-01-24 08:29:30 +00:00
if ( ! $db -> getResult ( $queryStr )) return false ;
return true ;
} /* }}} */
2016-02-05 15:47:38 +00:00
/**
* Get all notifications of user
*
* @ param integer $type type of item ( T_DOCUMENT or T_FOLDER )
2017-11-08 12:54:49 +00:00
* @ return SeedDMS_Core_Notification [] | bool array of notifications
2016-02-05 15:47:38 +00:00
*/
function getNotifications ( $type = 0 ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT `tblNotify`.* FROM `tblNotify` " .
" WHERE `tblNotify`.`userID` = " . $this -> _id ;
if ( $type ) {
$queryStr .= " AND `tblNotify`.`targetType` = " . ( int ) $type ;
}
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$notifications = array ();
foreach ( $resArr as $row ) {
$not = new SeedDMS_Core_Notification ( $row [ " target " ], $row [ " targetType " ], $row [ " userID " ], $row [ " groupID " ]);
$not -> setDMS ( $this );
array_push ( $notifications , $not );
}
return $notifications ;
} /* }}} */
2017-07-28 07:35:12 +00:00
/**
* Return list of personal keyword categories
*
2017-11-08 12:54:49 +00:00
* @ return SeedDMS_Core_KeywordCategory [] | bool list of categories or false in case of an error
2017-07-28 07:35:12 +00:00
*/
function getKeywordCategories () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT * FROM `tblKeywordCategories` WHERE `owner` = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$categories = array ();
foreach ( $resArr as $row ) {
$cat = new SeedDMS_Core_KeywordCategory ( $row [ " id " ], $row [ " owner " ], $row [ " name " ]);
$cat -> setDMS ( $this -> _dms );
array_push ( $categories , $cat );
}
return $categories ;
} /* }}} */
2015-07-15 06:20:55 +00:00
} /* }}} */