Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
76.53% covered (warning)
76.53%
613 / 801
67.09% covered (warning)
67.09%
53 / 79
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeedDMS_Core_User
76.53% covered (warning)
76.53%
613 / 801
67.09% covered (warning)
67.09%
53 / 79
1681.27
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
 getInstance
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
8
 getAllInstances
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
7
 isType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getID
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLogin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLogin
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
 getFullName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFullName
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 getPwd
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setPwd
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 getPwdExpiration
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setPwdExpiration
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
5
 getEmail
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEmail
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 getLanguage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLanguage
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 getTheme
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTheme
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 getComment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setComment
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 getRole
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRole
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 isAdmin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAdmin
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 isGuest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setGuest
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 isHidden
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHidden
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 isDisabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDisabled
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 addLoginFailure
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 clearLoginFailures
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 getUsedDiskSpace
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getQuota
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setQuota
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
4
 getHomeFolder
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHomeFolder
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 __removeFromProcesses
18.52% covered (danger)
18.52%
10 / 54
0.00% covered (danger)
0.00%
0 / 1
861.82
 removeFromProcesses
71.43% covered (warning)
71.43%
5 / 7
0.00% covered (danger)
0.00%
0 / 1
2.09
 __transferDocumentsFolders
68.42% covered (warning)
68.42%
13 / 19
0.00% covered (danger)
0.00%
0 / 1
8.54
 transferDocumentsFolders
77.78% covered (warning)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
3.10
 __transferEvents
71.43% covered (warning)
71.43%
5 / 7
0.00% covered (danger)
0.00%
0 / 1
3.21
 transferEvents
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
 remove
49.45% covered (danger)
49.45%
45 / 91
0.00% covered (danger)
0.00%
0 / 1
105.73
 joinGroup
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
 leaveGroup
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
 getGroups
93.33% covered (success)
93.33%
14 / 15
0.00% covered (danger)
0.00%
0 / 1
5.01
 isMemberOfGroup
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasImage
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
4.02
 getImage
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 setImage
83.33% covered (warning)
83.33%
10 / 12
0.00% covered (danger)
0.00%
0 / 1
4.07
 getDocuments
73.33% covered (warning)
73.33%
11 / 15
0.00% covered (danger)
0.00%
0 / 1
4.30
 getDocumentsLocked
73.33% covered (warning)
73.33%
11 / 15
0.00% covered (danger)
0.00%
0 / 1
4.30
 getDocumentLinks
64.29% covered (warning)
64.29%
9 / 14
0.00% covered (danger)
0.00%
0 / 1
4.73
 getDocumentFiles
69.23% covered (warning)
69.23%
9 / 13
0.00% covered (danger)
0.00%
0 / 1
4.47
 getDocumentContents
66.67% covered (warning)
66.67%
8 / 12
0.00% covered (danger)
0.00%
0 / 1
4.59
 getFolders
92.31% covered (success)
92.31%
12 / 13
0.00% covered (danger)
0.00%
0 / 1
4.01
 getReviewStatus
79.17% covered (warning)
79.17%
38 / 48
0.00% covered (danger)
0.00%
0 / 1
20.93
 getApprovalStatus
80.00% covered (warning)
80.00%
40 / 50
0.00% covered (danger)
0.00%
0 / 1
20.59
 getWorkflowStatus
53.85% covered (warning)
53.85%
14 / 26
0.00% covered (danger)
0.00%
0 / 1
29.62
 getWorkflowsInvolved
70.00% covered (warning)
70.00%
7 / 10
0.00% covered (danger)
0.00%
0 / 1
5.68
 getMandatoryReviewers
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getMandatoryApprovers
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 isMandatoryReviewerOf
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 isMandatoryApproverOf
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 getMandatoryWorkflow
75.00% covered (warning)
75.00%
6 / 8
0.00% covered (danger)
0.00%
0 / 1
4.25
 getMandatoryWorkflows
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
5
 setMandatoryReviewer
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
8
 setMandatoryApprover
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
8
 setMandatoryWorkflow
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 setMandatoryWorkflows
71.43% covered (warning)
71.43%
10 / 14
0.00% covered (danger)
0.00%
0 / 1
5.58
 delMandatoryReviewers
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 delMandatoryApprovers
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 delMandatoryWorkflow
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getNotifications
71.43% covered (warning)
71.43%
10 / 14
0.00% covered (danger)
0.00%
0 / 1
5.58
 getKeywordCategories
63.64% covered (warning)
63.64%
7 / 11
0.00% covered (danger)
0.00%
0 / 1
4.77
1<?php
2/**
3 * Implementation of the user object in the document management system
4 *
5 * @category   DMS
6 * @package    SeedDMS_Core
7 * @license    GPL 2
8 * @version    @version@
9 * @author     Uwe Steinmann <uwe@steinmann.cx>
10 * @copyright  Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe,
11 *             2010 Uwe Steinmann
12 * @version    Release: @package_version@
13 */
14
15/**
16 * Class to represent a user in the document management system
17 *
18 * @category   DMS
19 * @package    SeedDMS_Core
20 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
21 * @copyright  Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe,
22 *             2010 Uwe Steinmann
23 * @version    Release: @package_version@
24 */
25class SeedDMS_Core_User { /* {{{ */
26    /**
27     * @var integer id of user
28     *
29     * @access protected
30     */
31    protected $_id;
32
33    /**
34     * @var string login name of user
35     *
36     * @access protected
37     */
38    protected $_login;
39
40    /**
41     * @var string password of user as saved in database (md5)
42     *
43     * @access protected
44     */
45    protected $_pwd;
46
47    /**
48     * @var string date when password expires
49     *
50     * @access protected
51     */
52    protected $_pwdExpiration;
53
54    /**
55     * @var string full human readable name of user
56     *
57     * @access protected
58     */
59    protected $_fullName;
60
61    /**
62     * @var string email address of user
63     *
64     * @access protected
65     */
66    protected $_email;
67
68    /**
69     * @var string prefered language of user
70     *      possible values are subdirectories within the language directory
71     *
72     * @access protected
73     */
74    protected $_language;
75
76    /**
77     * @var string preselected theme of user
78     *
79     * @access protected
80     */
81    protected $_theme;
82
83    /**
84     * @var string comment of user
85     *
86     * @access protected
87     */
88    protected $_comment;
89
90    /**
91     * @var string role of user. Can be one of SeedDMS_Core_User::role_user,
92     *      SeedDMS_Core_User::role_admin, SeedDMS_Core_User::role_guest
93     *
94     * @access protected
95     */
96    protected $_role;
97
98    /**
99     * @var boolean true if user shall be hidden
100     *
101     * @access protected
102     */
103    protected $_isHidden;
104
105    /**
106     * @var boolean true if user is disabled
107     *
108     * @access protected
109     */
110    protected $_isDisabled;
111
112    /**
113     * @var int number of login failures
114     *
115     * @access protected
116     */
117    protected $_loginFailures;
118
119    /**
120     * @var SeedDMS_Core_Folder home folder
121     *
122     * @access protected
123     */
124    protected $_homeFolder;
125
126    /**
127     * @var array list of groups
128     *
129     * @access protected
130     */
131    protected $_groups;
132
133    /**
134     * @var SeedDMS_Core_DMS reference to the dms instance this user belongs to
135     *
136     * @access protected
137     */
138    protected $_dms;
139
140    /**
141     * @var int
142     *
143     * @access protected
144     */
145    protected $_quota;
146
147    /**
148     * @var bool
149     *
150     * @access protected
151     */
152    protected $_hasImage;
153
154    const role_user = '0';
155    const role_admin = '1';
156    const role_guest = '2';
157
158    /**
159     * SeedDMS_Core_User constructor.
160     * @param $id
161     * @param $login
162     * @param $pwd
163     * @param $fullName
164     * @param $email
165     * @param $language
166     * @param $theme
167     * @param $comment
168     * @param $role
169     * @param int $isHidden
170     * @param int $isDisabled
171     * @param string $pwdExpiration
172     * @param int $loginFailures
173     * @param int $quota
174     * @param null $homeFolder
175     */
176    function __construct($id, $login, $pwd, $fullName, $email, $language, $theme, $comment, $role, $isHidden=0, $isDisabled=0, $pwdExpiration='', $loginFailures=0, $quota=0, $homeFolder=null) {
177        $this->_id = $id;
178        $this->_login = $login;
179        $this->_pwd = $pwd;
180        $this->_fullName = $fullName;
181        $this->_email = $email;
182        $this->_language = $language;
183        $this->_theme = $theme;
184        $this->_comment = $comment;
185        $this->_role = $role;
186        $this->_isHidden = (bool) $isHidden;
187        $this->_isDisabled = (bool) $isDisabled;
188        $this->_pwdExpiration = $pwdExpiration;
189        $this->_loginFailures = $loginFailures;
190        $this->_quota = $quota;
191        $this->_homeFolder = $homeFolder;
192        $this->_dms = null;
193    }
194
195    /**
196     * Create an instance of a user object
197     *
198     * @param string|integer $id Id, login name, or email of user, depending
199     * on the 3rd parameter.
200     * @param SeedDMS_Core_DMS $dms instance of dms
201     * @param string $by search by [name|email]. If 'name' is passed, the method
202     * will check for the 4th paramater and also filter by email. If this
203     * parameter is left empty, the user will be search by its Id.
204     * @param string $email optional email address if searching for name
205     * @return SeedDMS_Core_User|bool instance of class SeedDMS_Core_User if user was
206     * found, null if user was not found, false in case of error
207     */
208    public static function getInstance($id, $dms, $by='', $email='') { /* {{{ */
209        $db = $dms->getDB();
210
211        switch($by) {
212        case 'name':
213            $queryStr = "SELECT * FROM `tblUsers` WHERE `login` = ".$db->qstr($id);
214            if($email)
215                $queryStr .= " AND `email`=".$db->qstr($email);
216            break;
217        case 'email':
218            $queryStr = "SELECT * FROM `tblUsers` WHERE `email` = ".$db->qstr($id);
219            break;
220        default:
221            $queryStr = "SELECT * FROM `tblUsers` WHERE `id` = " . (int) $id;
222        }
223        $resArr = $db->getResultArray($queryStr);
224
225        if (is_bool($resArr) && $resArr == false) return false;
226        if (count($resArr) != 1) return null;
227
228        $resArr = $resArr[0];
229
230        $user = new self((int) $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"]);
231        $user->setDMS($dms);
232        return $user;
233    } /* }}} */
234
235    /**
236     * @param $orderby
237     * @param SeedDMS_Core_DMS $dms
238     * @return SeedDMS_Core_User[]|bool
239     */
240    public static function getAllInstances($orderby, $dms) { /* {{{ */
241        $db = $dms->getDB();
242
243        if($orderby == 'fullname')
244            $queryStr = "SELECT * FROM `tblUsers` ORDER BY `fullName`";
245        else
246            $queryStr = "SELECT * FROM `tblUsers` ORDER BY `login`";
247        $resArr = $db->getResultArray($queryStr);
248
249        if (is_bool($resArr) && $resArr == false)
250            return false;
251
252        $users = array();
253
254        for ($i = 0; $i < count($resArr); $i++) {
255            /** @var SeedDMS_Core_User $user */
256            $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"]);
257            $user->setDMS($dms);
258            $users[$i] = $user;
259        }
260
261        return $users;
262} /* }}} */
263
264    /**
265     * Check if this object is of type 'user'.
266     *
267     * @param string $type type of object
268     */
269    public function isType($type) { /* {{{ */
270        return $type == 'user';
271    } /* }}} */
272
273    /**
274     * @param SeedDMS_Core_DMS $dms
275     */
276    function setDMS($dms) {
277        $this->_dms = $dms;
278    }
279
280    /**
281     * @return SeedDMS_Core_DMS $dms
282     */
283    function getDMS() {
284        return $this->_dms;
285    }
286
287    /**
288     * @return int
289     */
290    function getID() { return $this->_id; }
291
292    /**
293     * @return string
294     */
295    function getLogin() { return $this->_login; }
296
297    /**
298     * @param $newLogin
299     * @return bool
300     */
301    function setLogin($newLogin) { /* {{{ */
302        $newLogin = trim($newLogin);
303        if(!$newLogin)
304            return false;
305
306        $db = $this->_dms->getDB();
307
308        $queryStr = "UPDATE `tblUsers` SET `login` =".$db->qstr($newLogin)." WHERE `id` = " . $this->_id;
309        $res = $db->getResult($queryStr);
310        if (!$res)
311            return false;
312
313        $this->_login = $newLogin;
314        return true;
315    } /* }}} */
316
317    /**
318     * @return string
319     */
320    function getFullName() { return $this->_fullName; }
321
322    /**
323     * @param $newFullName
324     * @return bool
325     */
326    function setFullName($newFullName) { /* {{{ */
327        $db = $this->_dms->getDB();
328
329        $queryStr = "UPDATE `tblUsers` SET `fullName` = ".$db->qstr($newFullName)." WHERE `id` = " . $this->_id;
330        $res = $db->getResult($queryStr);
331        if (!$res)
332            return false;
333
334        $this->_fullName = $newFullName;
335        return true;
336    } /* }}} */
337
338    /**
339     * @return string
340     */
341    function getPwd() { return $this->_pwd; }
342
343    /**
344     * @param $newPwd
345     * @return bool
346     */
347    function setPwd($newPwd) { /* {{{ */
348        $db = $this->_dms->getDB();
349
350        $queryStr = "UPDATE `tblUsers` SET `pwd` =".$db->qstr($newPwd)." WHERE `id` = " . $this->_id;
351        $res = $db->getResult($queryStr);
352        if (!$res)
353            return false;
354
355        $this->_pwd = $newPwd;
356        return true;
357    } /* }}} */
358
359    /**
360     * @return string
361     */
362    function getPwdExpiration() { return $this->_pwdExpiration; }
363
364    /**
365     * @param $newPwdExpiration
366     * @return bool
367     */
368    function setPwdExpiration($newPwdExpiration) { /* {{{ */
369        $db = $this->_dms->getDB();
370
371        if(trim($newPwdExpiration) == '' || trim($newPwdExpiration) == 'never') {
372            $newPwdExpiration = null;
373            $queryStr = "UPDATE `tblUsers` SET `pwdExpiration` = NULL WHERE `id` = " . $this->_id;
374        } else {
375            if(trim($newPwdExpiration) == 'now')
376                $newPwdExpiration = date('Y-m-d H:i:s');
377            $queryStr = "UPDATE `tblUsers` SET `pwdExpiration` =".$db->qstr($newPwdExpiration)." WHERE `id` = " . $this->_id;
378        }
379        $res = $db->getResult($queryStr);
380        if (!$res)
381            return false;
382
383        $this->_pwdExpiration = $newPwdExpiration;
384        return true;
385    } /* }}} */
386
387    /**
388     * @return string
389     */
390    function getEmail() { return $this->_email; }
391
392    /**
393     * @param $newEmail
394     * @return bool
395     */
396    function setEmail($newEmail) { /* {{{ */
397        $db = $this->_dms->getDB();
398
399        $queryStr = "UPDATE `tblUsers` SET `email` =".$db->qstr(trim($newEmail))." WHERE `id` = " . $this->_id;
400        $res = $db->getResult($queryStr);
401        if (!$res)
402            return false;
403
404        $this->_email = $newEmail;
405        return true;
406    } /* }}} */
407
408    /**
409     * @return string
410     */
411    function getLanguage() { return $this->_language; }
412
413    /**
414     * @param $newLanguage
415     * @return bool
416     */
417    function setLanguage($newLanguage) { /* {{{ */
418        $db = $this->_dms->getDB();
419
420        $queryStr = "UPDATE `tblUsers` SET `language` =".$db->qstr(trim($newLanguage))." WHERE `id` = " . $this->_id;
421        $res = $db->getResult($queryStr);
422        if (!$res)
423            return false;
424
425        $this->_language = $newLanguage;
426        return true;
427    } /* }}} */
428
429    /**
430     * @return string
431     */
432    function getTheme() { return $this->_theme; }
433
434    /**
435     * @param string $newTheme
436     * @return bool
437     */
438    function setTheme($newTheme) { /* {{{ */
439        $db = $this->_dms->getDB();
440
441        $queryStr = "UPDATE `tblUsers` SET `theme` =".$db->qstr(trim($newTheme))." WHERE `id` = " . $this->_id;
442        $res = $db->getResult($queryStr);
443        if (!$res)
444            return false;
445
446        $this->_theme = $newTheme;
447        return true;
448    } /* }}} */
449
450    /**
451     * @return string
452     */
453    function getComment() { return $this->_comment; }
454
455    /**
456     * @param $newComment
457     * @return bool
458     */
459    function setComment($newComment) { /* {{{ */
460        $db = $this->_dms->getDB();
461
462        $queryStr = "UPDATE `tblUsers` SET `comment` =".$db->qstr(trim($newComment))." WHERE `id` = " . $this->_id;
463        $res = $db->getResult($queryStr);
464        if (!$res)
465            return false;
466
467        $this->_comment = $newComment;
468        return true;
469    } /* }}} */
470
471    /**
472     * @return string
473     */
474    function getRole() { return $this->_role; }
475
476    /**
477     * @param integer $newrole
478     * @return bool
479     */
480    function setRole($newrole) { /* {{{ */
481        $db = $this->_dms->getDB();
482        if(!in_array($newrole, array(SeedDMS_Core_User::role_admin, SeedDMS_Core_User::role_guest, SeedDMS_Core_User::role_user), true))
483            return false;
484
485        $queryStr = "UPDATE `tblUsers` SET `role` = " . $newrole . " WHERE `id` = " . $this->_id;
486        if (!$db->getResult($queryStr))
487            return false;
488
489        $this->_role = $newrole;
490        return true;
491    } /* }}} */
492
493    /**
494     * @return bool
495     */
496    function isAdmin() { return ($this->_role == SeedDMS_Core_User::role_admin); }
497
498    /**
499     * @return bool
500     */
501    function setAdmin() { /* {{{ */
502        $db = $this->_dms->getDB();
503
504        $queryStr = "UPDATE `tblUsers` SET `role` = " . SeedDMS_Core_User::role_admin . " WHERE `id` = " . $this->_id;
505        if (!$db->getResult($queryStr))
506            return false;
507
508        $this->_role = SeedDMS_Core_User::role_admin;
509        return true;
510    } /* }}} */
511
512    /**
513     * @return bool
514     */
515    function isGuest() { return ($this->_role == SeedDMS_Core_User::role_guest); }
516
517    /**
518     * @return bool
519     */
520    function setGuest() { /* {{{ */
521        $db = $this->_dms->getDB();
522
523        $queryStr = "UPDATE `tblUsers` SET `role` = " . SeedDMS_Core_User::role_guest . " WHERE `id` = " . $this->_id;
524        if (!$db->getResult($queryStr))
525            return false;
526
527        $this->_role = SeedDMS_Core_User::role_guest;
528        return true;
529    } /* }}} */
530
531    /**
532     * @return bool
533     */
534    function isHidden() { return $this->_isHidden; }
535
536    /**
537     * @param $isHidden
538     * @return bool
539     */
540    function setHidden($isHidden) { /* {{{ */
541        $db = $this->_dms->getDB();
542
543        $isHidden = ($isHidden) ? "1" : "0";
544        $queryStr = "UPDATE `tblUsers` SET `hidden` = " . intval($isHidden) . " WHERE `id` = " . $this->_id;
545        if (!$db->getResult($queryStr))
546            return false;
547
548        $this->_isHidden = (bool) $isHidden;
549        return true;
550    }     /* }}} */
551
552    /**
553     * @return bool|int
554     */
555    function isDisabled() { return $this->_isDisabled; }
556
557    /**
558     * @param $isDisabled
559     * @return bool
560     */
561    function setDisabled($isDisabled) { /* {{{ */
562        $db = $this->_dms->getDB();
563
564        $isDisabled = ($isDisabled) ? "1" : "0";
565        $queryStr = "UPDATE `tblUsers` SET `disabled` = " . intval($isDisabled) . " WHERE `id` = " . $this->_id;
566        if (!$db->getResult($queryStr))
567            return false;
568
569        $this->_isDisabled = (bool) $isDisabled;
570        return true;
571    }     /* }}} */
572
573    /**
574     * @return bool|int
575     */
576    function addLoginFailure() { /* {{{ */
577        $db = $this->_dms->getDB();
578
579        $this->_loginFailures++;
580        $queryStr = "UPDATE `tblUsers` SET `loginfailures` = " . $this->_loginFailures . " WHERE `id` = " . $this->_id;
581        if (!$db->getResult($queryStr))
582            return false;
583
584        return $this->_loginFailures;
585    } /* }}} */
586
587    /**
588     * @return bool
589     */
590    function clearLoginFailures() { /* {{{ */
591        $db = $this->_dms->getDB();
592
593        $this->_loginFailures = 0;
594        $queryStr = "UPDATE `tblUsers` SET `loginfailures` = " . $this->_loginFailures . " WHERE `id` = " . $this->_id;
595        if (!$db->getResult($queryStr))
596            return false;
597
598        return true;
599    } /* }}} */
600
601    /**
602     * Calculate the disk space for all documents owned by the user
603     * 
604     * This is done by using the internal database field storing the
605     * filesize of a document version.
606     *
607     * @return integer total disk space in Bytes
608     */
609    function getUsedDiskSpace() { /* {{{ */
610        $db = $this->_dms->getDB();
611
612        $queryStr = "SELECT SUM(`fileSize`) sum FROM `tblDocumentContent` a LEFT JOIN `tblDocuments` b ON a.`document`=b.`id` WHERE b.`owner` = " . $this->_id;
613        $resArr = $db->getResultArray($queryStr);
614        if (is_bool($resArr) && $resArr == false)
615            return false;
616
617        return $resArr[0]['sum'];
618    } /* }}} */
619
620    /**
621     * @return int
622     */
623    function getQuota() { return $this->_quota; }
624
625    /**
626     * @param integer $quota
627     * @return bool
628     */
629    function setQuota($quota) { /* {{{ */
630        if (!is_numeric($quota))
631            return false;
632        if($quota < 0)
633            return false;
634
635        $db = $this->_dms->getDB();
636
637        $quota = intval($quota);
638        $queryStr = "UPDATE `tblUsers` SET `quota` = " . $quota . " WHERE `id` = " . $this->_id;
639        if (!$db->getResult($queryStr))
640            return false;
641
642        $this->_quota = $quota;
643        return true;
644    }     /* }}} */
645
646    /**
647     * @return null|SeedDMS_Core_Folder
648     */
649    function getHomeFolder() { return $this->_homeFolder; }
650
651    /**
652     * @param integer $homefolder
653     * @return bool
654     */
655    function setHomeFolder($homefolder) { /* {{{ */
656        $db = $this->_dms->getDB();
657        $homefolder = intval($homefolder);
658
659        $queryStr = "UPDATE `tblUsers` SET `homefolder` = " . ($homefolder ? $homefolder : 'NULL') . " WHERE `id` = " . $this->_id;
660        if (!$db->getResult($queryStr))
661            return false;
662
663        $this->_homeFolder = $homefolder;
664        return true;
665    }     /* }}} */
666
667    /**
668     * Remove user from all processes
669     *
670     * This method adds another log entry to the reviews and approvals
671     * which indicates the user has been deleted from the process. By default it will
672     * do so for each review/approval regardless of its current state unles
673     * the user has been removed already (status=-2). So even
674     * reviews/approvals already processed by the user will be added the log
675     * entry. Only, if the last log entry was a removal already, it will not be
676     * added a second time.
677     *
678     * This removal from processes will also take place for older versions of a document.
679     *
680     * This methode was initialy added to remove a user (which is going to be deleted
681     * afterwards) from all processes he or she is still involved in.
682     *
683     * If a new user is passed, then this user will be added as a new reviewer, approver, etc.
684     * Hence, this method does not replace the old user but actually deletes the old user and
685     * adds a new one. Adding the new reviewer, approver, etc. will also be done for old versions
686     * of a document. The same operation could be archieved by first calling
687     * SeedDMS_Core_DocumentVersion::delIndReviewer() followed by SeedDMS_Core_DocumentVersion::addIndReviewer()
688     * but this would require to do for each version of a document and the operation would not
689     * be in a single transaction.
690     *
691     * A new user is only added if the process (review, approval, etc.) is still in its initial
692     * state (have not been reviewed/approved or rejected). Unlike the removal of the user (see above).
693     *
694     * If a new user is given but has no read access on the document the transfer for that
695     * particular document will be skipped. Not even the removal of the user will take place.
696     * 
697     * @param object $user the user doing the removal (needed for entry in
698     *        review and approve log).
699     * @param array $states remove user only from reviews/approvals in one of the states
700     *        e.g. if passing array('review'=>array(0)), the method will operate on
701     *        reviews which has not been touched yet.
702     * @param object $newuser user who takes over the processes
703     * @param array $docs remove only processes from docs with the given document ids
704     * @return boolean true on success or false in case of an error
705     */
706    private function __removeFromProcesses($user, $states = array(), $newuser=null, $docs=null) { /* {{{ */
707        $db = $this->_dms->getDB();
708
709        /* Get a list of all reviews, even those of older document versions */
710        $reviewStatus = $this->getReviewStatus();
711        $db->startTransaction();
712        foreach ($reviewStatus["indstatus"] as $ri) {
713            if(!($doc = $this->_dms->getDocument($ri['documentID'])))
714                continue;
715            if($docs) {
716                if(!in_array($doc->getID(), $docs))
717                    continue;
718                if(!$doc->isLatestContent($ri['version']))
719                    continue;
720            }
721            if($newuser && $doc->getAccessMode($newuser) < M_READ)
722                continue;
723            if($ri['status'] != -2 && (!isset($states['review']) || in_array($ri['status'], $states['review']))) {
724                $queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ".
725                    "VALUES ('". $ri["reviewID"] ."', '-2', '".(($newuser && $ri['status'] == 0) ? 'Reviewer replaced by '.$newuser->getLogin() : 'Reviewer removed from process')."', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
726                $res=$db->getResult($queryStr);
727                if(!$res) {
728                    $db->rollbackTransaction();
729                    return false;
730                }
731                /* Only reviews not done already can be transferred to a new user */
732                if($newuser && $ri['status'] == 0) {
733                    if($version = $doc->getContentByVersion($ri['version'])) {
734                        $ret = $version->addIndReviewer($newuser, $user);
735                        /* returns -3 if the user is already a reviewer */ 
736                        if($ret === false || ($ret < 0 && $ret != -3)) {
737                            $db->rollbackTransaction();
738                            return false;
739                        }
740                    }
741                }
742            }
743        }
744        $db->commitTransaction();
745
746        /* Get a list of all approvals, even those of older document versions */
747        $approvalStatus = $this->getApprovalStatus();
748        $db->startTransaction();
749        foreach ($approvalStatus["indstatus"] as $ai) {
750            if(!($doc = $this->_dms->getDocument($ai['documentID'])))
751                continue;
752            if($docs) {
753                if(!in_array($doc->getID(), $docs))
754                    continue;
755                if(!$doc->isLatestContent($ai['version']))
756                    continue;
757            }
758            if($newuser && $doc->getAccessMode($newuser) < M_READ)
759                continue;
760            if($ai['status'] != -2 && (!isset($states['approval']) || in_array($ai['status'], $states['approval']))) {
761                $queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ".
762                    "VALUES ('". $ai["approveID"] ."', '-2', '".(($newuser && $ai['status'] == 0)? 'Approver replaced by '.$newuser->getLogin() : 'Approver removed from process')."', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
763                $res=$db->getResult($queryStr);
764                if(!$res) {
765                    $db->rollbackTransaction();
766                    return false;
767                }
768                /* Only approvals not done already can be transferred to a new user */
769                if($newuser && $ai['status'] == 0) {
770                    if($version = $doc->getContentByVersion($ai['version'])) {
771                        $ret = $version->addIndReviewer($newuser, $user);
772                        /* returns -3 if the user is already a reviewer */ 
773                        if($ret === false || ($ret < 0 && $ret != -3)) {
774                            $db->rollbackTransaction();
775                            return false;
776                        }
777                    }
778                }
779            }
780        }
781        $db->commitTransaction();
782
783        return true;
784    } /* }}} */
785
786    /**
787     * Remove user from all processes
788     *
789     * This includes review, approval and workflow
790     *
791     * @param object $user the user doing the removal (needed for entry in
792     *        review and approve log).
793     * @param array $states remove user only from reviews/approvals in one of the states
794     * @param object $newuser user who takes over the processes
795     * @return boolean true on success or false in case of an error
796     */
797    public function removeFromProcesses($user, $states=array(), $newuser=null, $docs=null) { /* {{{ */
798        $db = $this->_dms->getDB();
799
800        $db->startTransaction();
801        if(!$this->__removeFromProcesses($user, $states, $newuser, $docs)) {
802            $db->rollbackTransaction();
803            return false;
804        }
805        $db->commitTransaction();
806        return true;
807    } /* }}} */
808
809    /**
810     * Transfer documents and folders to another user
811     *
812     * @param object $assignToUser the user who is new owner of folders and
813     *        documents which previously were owned by the delete user.
814     * @return boolean true on success or false in case of an error
815     */
816    private function __transferDocumentsFolders($assignToUser) { /* {{{ */
817        $db = $this->_dms->getDB();
818
819        if(!$assignToUser)
820            return false;
821
822        /* Assign documents of the removed user to the given user */
823        $queryStr = "UPDATE `tblFolders` SET `owner` = " . $assignToUser->getID() . " WHERE `owner` = " . $this->_id;
824        if (!$db->getResult($queryStr)) {
825            return false;
826        }
827
828        $queryStr = "UPDATE `tblDocuments` SET `owner` = " . $assignToUser->getID() . " WHERE `owner` = " . $this->_id;
829        if (!$db->getResult($queryStr)) {
830            return false;
831        }
832
833        $queryStr = "UPDATE `tblDocumentContent` SET `createdBy` = " . $assignToUser->getID() . " WHERE `createdBy` = " . $this->_id;
834        if (!$db->getResult($queryStr)) {
835            return false;
836        }
837
838        // ... but keep public links
839        $queryStr = "UPDATE `tblDocumentLinks` SET `userID` = " . $assignToUser->getID() . " WHERE `userID` = " . $this->_id;
840        if (!$db->getResult($queryStr)) {
841            return false;
842        }
843
844        // set administrator for deleted user's attachments
845        $queryStr = "UPDATE `tblDocumentFiles` SET `userID` = " . $assignToUser->getID() . " WHERE `userID` = " . $this->_id;
846        if (!$db->getResult($queryStr)) {
847            return false;
848        }
849
850        return true;
851    } /* }}} */
852
853    /**
854     * Transfer documents and folders to another user
855     *
856     * @param object $assignToUser the user who is new owner of folders and
857     *        documents which previously were owned by the delete user.
858     * @return boolean true on success or false in case of an error
859     */
860    public function transferDocumentsFolders($assignToUser) { /* {{{ */
861        $db = $this->_dms->getDB();
862
863        if($assignToUser->getID() == $this->_id)
864            return true;
865
866        $db->startTransaction();
867        if(!$this->__transferDocumentsFolders($assignToUser)) {
868            $db->rollbackTransaction();
869            return false;
870        }
871        $db->commitTransaction();
872        return true;
873    } /* }}} */
874
875    /**
876     * Transfer events to another user
877     *
878     * @param object $assignToUser the user who is new owner of events
879     * @return boolean true on success or false in case of an error
880     */
881    private function __transferEvents($assignToUser) { /* {{{ */
882        $db = $this->_dms->getDB();
883
884        if(!$assignToUser)
885            return false;
886
887        // set new owner of events
888        $queryStr = "UPDATE `tblEvents` SET `userID` = " . $assignToUser->getID() . " WHERE `userID` = " . $this->_id;
889        if (!$db->getResult($queryStr)) {
890            return false;
891        }
892
893        return true;
894    } /* }}} */
895
896    /**
897     * Transfer events to another user
898     *
899     * @param object $assignToUser the user who is new owner of events
900     * @return boolean true on success or false in case of an error
901     */
902    public function transferEvents($assignToUser) { /* {{{ */
903        $db = $this->_dms->getDB();
904
905        if($assignToUser->getID() == $this->_id)
906            return true;
907
908        $db->startTransaction();
909        if(!$this->__transferEvents($assignToUser)) {
910            $db->rollbackTransaction();
911            return false;
912        }
913        $db->commitTransaction();
914        return true;
915    } /* }}} */
916
917    /**
918     * Remove the user and also remove all its keywords, notifications, etc.
919     * Do not remove folders and documents of the user, but assign them
920     * to a different user.
921     *
922     * @param SeedDMS_Core_User $user the user doing the removal (needed for entry in
923     *        review and approve log).
924     * @param SeedDMS_Core_User $assignToUser the user who is new owner of folders and
925     *        documents which previously were owned by the delete user.
926     * @return boolean true on success or false in case of an error
927     */
928    function remove($user, $assignToUser=null) { /* {{{ */
929        $db = $this->_dms->getDB();
930
931        /* Records like folders and documents that formely have belonged to
932         * the user will assign to another user. If no such user is set,
933         * the function now returns false and will not use the admin user
934         * anymore.
935         */
936        if(!$assignToUser)
937            return false;
938            /** @noinspection PhpUnusedLocalVariableInspection */
939            $assignTo = $assignToUser->getID();
940
941        $db->startTransaction();
942
943        // delete private keyword lists
944        $queryStr = "SELECT `tblKeywords`.`id` FROM `tblKeywords`, `tblKeywordCategories` WHERE `tblKeywords`.`category` = `tblKeywordCategories`.`id` AND `tblKeywordCategories`.`owner` = " . $this->_id;
945        $resultArr = $db->getResultArray($queryStr);
946        if (count($resultArr) > 0) {
947            $queryStr = "DELETE FROM `tblKeywords` WHERE ";
948            for ($i = 0; $i < count($resultArr); $i++) {
949                $queryStr .= "id = " . $resultArr[$i]["id"];
950                if ($i + 1 < count($resultArr))
951                    $queryStr .= " OR ";
952            }
953            if (!$db->getResult($queryStr)) {
954                $db->rollbackTransaction();
955                return false;
956            }
957        }
958
959        $queryStr = "DELETE FROM `tblKeywordCategories` WHERE `owner` = " . $this->_id;
960        if (!$db->getResult($queryStr)) {
961            $db->rollbackTransaction();
962            return false;
963        }
964
965        //Benachrichtigungen entfernen
966        $queryStr = "DELETE FROM `tblNotify` WHERE `userID` = " . $this->_id;
967        if (!$db->getResult($queryStr)) {
968            $db->rollbackTransaction();
969            return false;
970        }
971
972        // Remove private links on documents ...
973        $queryStr = "DELETE FROM `tblDocumentLinks` WHERE `userID` = " . $this->_id . " AND `public` = 0";
974        if (!$db->getResult($queryStr)) {
975            $db->rollbackTransaction();
976            return false;
977        }
978
979        /* Assign documents, folders, files, public document links of the removed user to the given user */
980        if(!$this->__transferDocumentsFolders($assignToUser)) {
981                $db->rollbackTransaction();
982                return false;
983        }
984
985        // unlock documents locked by the user
986        $queryStr = "DELETE FROM `tblDocumentLocks` WHERE `userID` = " . $this->_id;
987        if (!$db->getResult($queryStr)) {
988            $db->rollbackTransaction();
989            return false;
990        }
991
992        // Delete user from all groups
993        $queryStr = "DELETE FROM `tblGroupMembers` WHERE `userID` = " . $this->_id;
994        if (!$db->getResult($queryStr)) {
995            $db->rollbackTransaction();
996            return false;
997        }
998
999        // User aus allen ACLs streichen
1000        $queryStr = "DELETE FROM `tblACLs` WHERE `userID` = " . $this->_id;
1001        if (!$db->getResult($queryStr)) {
1002            $db->rollbackTransaction();
1003            return false;
1004        }
1005
1006        // Delete image of user
1007        $queryStr = "DELETE FROM `tblUserImages` WHERE `userID` = " . $this->_id;
1008        if (!$db->getResult($queryStr)) {
1009            $db->rollbackTransaction();
1010            return false;
1011        }
1012
1013        // Delete entries in password history
1014        $queryStr = "DELETE FROM `tblUserPasswordHistory` WHERE `userID` = " . $this->_id;
1015        if (!$db->getResult($queryStr)) {
1016            $db->rollbackTransaction();
1017            return false;
1018        }
1019
1020        // Delete entries in password request
1021        $queryStr = "DELETE FROM `tblUserPasswordRequest` WHERE `userID` = " . $this->_id;
1022        if (!$db->getResult($queryStr)) {
1023            $db->rollbackTransaction();
1024            return false;
1025        }
1026
1027        // mandatory review/approve
1028        $queryStr = "DELETE FROM `tblMandatoryReviewers` WHERE `reviewerUserID` = " . $this->_id;
1029        if (!$db->getResult($queryStr)) {
1030            $db->rollbackTransaction();
1031            return false;
1032        }
1033
1034        $queryStr = "DELETE FROM `tblMandatoryApprovers` WHERE `approverUserID` = " . $this->_id;
1035        if (!$db->getResult($queryStr)) {
1036            $db->rollbackTransaction();
1037            return false;
1038        }
1039
1040        $queryStr = "DELETE FROM `tblMandatoryReviewers` WHERE `userID` = " . $this->_id;
1041        if (!$db->getResult($queryStr)) {
1042            $db->rollbackTransaction();
1043            return false;
1044        }
1045
1046        $queryStr = "DELETE FROM `tblMandatoryApprovers` WHERE `userID` = " . $this->_id;
1047        if (!$db->getResult($queryStr)) {
1048            $db->rollbackTransaction();
1049            return false;
1050        }
1051
1052        $queryStr = "DELETE FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this->_id;
1053        if (!$db->getResult($queryStr)) {
1054            $db->rollbackTransaction();
1055            return false;
1056        }
1057
1058        $queryStr = "DELETE FROM `tblWorkflowTransitionUsers` WHERE `userid` = " . $this->_id;
1059        if (!$db->getResult($queryStr)) {
1060            $db->rollbackTransaction();
1061            return false;
1062        }
1063
1064        /* Assign events of the removed user to the given user */
1065        if(!$this->__transferEvents($assignToUser)) {
1066                $db->rollbackTransaction();
1067                return false;
1068        }
1069
1070        // Delete user itself
1071        $queryStr = "DELETE FROM `tblUsers` WHERE `id` = " . $this->_id;
1072        if (!$db->getResult($queryStr)) {
1073            $db->rollbackTransaction();
1074            return false;
1075        }
1076
1077        // TODO : update document status if reviewer/approver has been deleted
1078        // "DELETE FROM `tblDocumentApproveLog` WHERE `userID` = " . $this->_id;
1079        // "DELETE FROM `tblDocumentReviewLog` WHERE `userID` = " . $this->_id;
1080
1081        if(!$this->__removeFromProcesses($user)) {
1082                $db->rollbackTransaction();
1083                return false;
1084        }
1085
1086        $db->commitTransaction();
1087        return true;
1088    } /* }}} */
1089
1090    /**
1091     * Make the user a member of a group
1092     * This function uses {@link SeedDMS_Group::addUser} but checks before if
1093     * the user is already a member of the group.
1094     *
1095     * @param SeedDMS_Core_Group $group group to be the member of
1096     * @return boolean true on success or false in case of an error or the user
1097     *        is already a member of the group
1098     */
1099    function joinGroup($group) { /* {{{ */
1100        if ($group->isMember($this))
1101            return false;
1102
1103        if (!$group->addUser($this))
1104            return false;
1105
1106        unset($this->_groups);
1107        return true;
1108    } /* }}} */
1109
1110    /**
1111     * Removes the user from a group
1112     * This function uses {@link SeedDMS_Group::removeUser} but checks before if
1113     * the user is a member of the group at all.
1114     *
1115     * @param SeedDMS_Core_Group $group group to leave
1116     * @return boolean true on success or false in case of an error or the user
1117     *        is not a member of the group
1118     */
1119    function leaveGroup($group) { /* {{{ */
1120        if (!$group->isMember($this))
1121            return false;
1122
1123        if (!$group->removeUser($this))
1124            return false;
1125
1126        unset($this->_groups);
1127        return true;
1128    } /* }}} */
1129
1130    /**
1131     * Get all groups the user is a member of
1132     *
1133     * @return SeedDMS_Core_Group[]|bool list of groups
1134     */
1135    function getGroups() { /* {{{ */
1136        $db = $this->_dms->getDB();
1137
1138        if (!isset($this->_groups))
1139        {
1140            $queryStr = "SELECT `tblGroups`.*, `tblGroupMembers`.`userID` FROM `tblGroups` ".
1141                "LEFT JOIN `tblGroupMembers` ON `tblGroups`.`id` = `tblGroupMembers`.`groupID` ".
1142                "WHERE `tblGroupMembers`.`userID`='". $this->_id ."'";
1143            $resArr = $db->getResultArray($queryStr);
1144            if (is_bool($resArr) && $resArr == false)
1145                return false;
1146
1147            $this->_groups = array();
1148            $classname = $this->_dms->getClassname('group');
1149            foreach ($resArr as $row) {
1150                /** @var SeedDMS_Core_Group $group */
1151                $group = new $classname((int) $row["id"], $row["name"], $row["comment"]);
1152                $group->setDMS($this->_dms);
1153                array_push($this->_groups, $group);
1154            }
1155        }
1156        return $this->_groups;
1157    } /* }}} */
1158
1159    /**
1160     * Checks if user is member of a given group
1161     *
1162     * @param SeedDMS_Core_Group $group
1163     * @return boolean true if user is member of the given group otherwise false
1164     */
1165    function isMemberOfGroup($group) { /* {{{ */
1166        return $group->isMember($this);
1167    } /* }}} */
1168
1169    /**
1170     * Check if user has an image in its profile
1171     *
1172     * @return boolean true if user has a picture of itself
1173     */
1174    function hasImage() { /* {{{ */
1175        if (!isset($this->_hasImage)) {
1176            $db = $this->_dms->getDB();
1177
1178            $queryStr = "SELECT COUNT(*) AS num FROM `tblUserImages` WHERE `userID` = " . $this->_id;
1179            $resArr = $db->getResultArray($queryStr);
1180            if ($resArr === false)
1181                return false;
1182
1183            if ($resArr[0]["num"] == 0)    $this->_hasImage = false;
1184            else $this->_hasImage = true;
1185        }
1186
1187        return $this->_hasImage;
1188    } /* }}} */
1189
1190    /**
1191     * Get the image from the users profile
1192     *
1193     * @return string|null|bool image data as a string or null if no image is set or
1194     * false in case of an error
1195     */
1196    function getImage() { /* {{{ */
1197        $db = $this->_dms->getDB();
1198
1199        $queryStr = "SELECT * FROM `tblUserImages` WHERE `userID` = " . $this->_id;
1200        $resArr = $db->getResultArray($queryStr);
1201        if ($resArr === false)
1202            return false;
1203
1204        if($resArr)
1205            return $resArr[0];
1206        else
1207            return null;
1208    } /* }}} */
1209
1210    /**
1211     * @param $tmpfile
1212     * @param $mimeType
1213     * @return bool
1214     */
1215    function setImage($tmpfile, $mimeType) { /* {{{ */
1216        $db = $this->_dms->getDB();
1217
1218        $fp = fopen($tmpfile, "rb");
1219        if (!$fp) return false;
1220        $content = fread($fp, filesize($tmpfile));
1221        fclose($fp);
1222
1223        if ($this->hasImage())
1224            $queryStr = "UPDATE `tblUserImages` SET `image` = '".base64_encode($content)."', `mimeType` = ".$db->qstr($mimeType)." WHERE `userID` = " . $this->_id;
1225        else
1226            $queryStr = "INSERT INTO `tblUserImages` (`userID`, `image`, `mimeType`) VALUES (" . $this->_id . ", '".base64_encode($content)."', ".$db->qstr($mimeType).")";
1227        if (!$db->getResult($queryStr))
1228            return false;
1229
1230        $this->_hasImage = true;
1231        return true;
1232    } /* }}} */
1233
1234    /**
1235     * Returns all documents of a given user
1236     * @return SeedDMS_Core_Document[]|bool list of documents
1237     */
1238    function getDocuments() { /* {{{ */
1239        $db = $this->_dms->getDB();
1240
1241        $queryStr = "SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser` ".
1242            "FROM `tblDocuments` ".
1243            "LEFT JOIN `tblDocumentLocks` ON `tblDocuments`.`id`=`tblDocumentLocks`.`document` ".
1244            "WHERE `tblDocuments`.`owner` = " . $this->_id . " ORDER BY `sequence`";
1245
1246        $resArr = $db->getResultArray($queryStr);
1247        if (is_bool($resArr) && !$resArr)
1248            return false;
1249
1250        $documents = array();
1251        $classname = $this->_dms->getClassname('document');
1252        foreach ($resArr as $row) {
1253            /** @var SeedDMS_Core_Document $document */
1254            $document = new $classname((int) $row["id"], $row["name"], $row["comment"], $row["date"], $row["expires"], $row["owner"], $row["folder"], $row["inheritAccess"], $row["defaultAccess"], $row["lockUser"], $row["keywords"], $row["sequence"]);
1255            $document->setDMS($this->_dms);
1256            $documents[] = $document;
1257        }
1258        return $documents;
1259    } /* }}} */
1260
1261    /**
1262     * Returns all documents locked by a given user
1263     *
1264     * @return bool|SeedDMS_Core_Document[] list of documents
1265     */
1266    function getDocumentsLocked() { /* {{{ */
1267        $db = $this->_dms->getDB();
1268
1269        $queryStr = "SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser` ".
1270            "FROM `tblDocumentLocks` LEFT JOIN `tblDocuments` ON `tblDocuments`.`id` = `tblDocumentLocks`.`document` ".
1271            "WHERE `tblDocumentLocks`.`userID` = '".$this->_id."' ".
1272            "ORDER BY `id` DESC";
1273
1274        $resArr = $db->getResultArray($queryStr);
1275        if (is_bool($resArr) && !$resArr)
1276            return false;
1277
1278        $documents = array();
1279        $classname = $this->_dms->getClassname('document');
1280        foreach ($resArr as $row) {
1281            /** @var SeedDMS_Core_Document $document */
1282            $document = new $classname((int) $row["id"], $row["name"], $row["comment"], $row["date"], $row["expires"], $row["owner"], $row["folder"], $row["inheritAccess"], $row["defaultAccess"], $row["lockUser"], $row["keywords"], $row["sequence"]);
1283            $document->setDMS($this->_dms);
1284            $documents[] = $document;
1285        }
1286        return $documents;
1287    } /* }}} */
1288
1289    /**
1290     * Returns all document links of a given user
1291     * @return SeedDMS_Core_DocumentLink[]|bool list of document links
1292     */
1293    function getDocumentLinks() { /* {{{ */
1294        $db = $this->_dms->getDB();
1295
1296        $queryStr = "SELECT * FROM `tblDocumentLinks` ".
1297            "WHERE `userID` = " . $this->_id;
1298
1299        $resArr = $db->getResultArray($queryStr);
1300        if (is_bool($resArr) && !$resArr)
1301            return false;
1302
1303        $links = array();
1304        $classname = 'SeedDMS_Core_DocumentLink';
1305        foreach ($resArr as $row) {
1306            $document = $this->_dms->getDocument($row["document"]);
1307            $target = $this->_dms->getDocument($row["target"]);
1308            /** @var SeedDMS_Core_Document $document */
1309            $link = new $classname((int) $row["id"], $document, $target, $row["userID"], $row["public"]);
1310            $links[] = $link;
1311        }
1312        return $links;
1313    } /* }}} */
1314
1315    /**
1316     * Returns all document files of a given user
1317     * @return SeedDMS_Core_DocumentFile[]|bool list of document files
1318     */
1319    function getDocumentFiles() { /* {{{ */
1320        $db = $this->_dms->getDB();
1321
1322        $queryStr = "SELECT * FROM `tblDocumentFiles` ".
1323            "WHERE `userID` = " . $this->_id;
1324
1325        $resArr = $db->getResultArray($queryStr);
1326        if (is_bool($resArr) && !$resArr)
1327            return false;
1328
1329        $files = array();
1330        $classname = 'SeedDMS_Core_DocumentFile';
1331        foreach ($resArr as $row) {
1332            $document = $this->_dms->getDocument($row["document"]);
1333            /** @var SeedDMS_Core_DocumentFile $file */
1334            $file = new $classname((int) $row["id"], $document, $row["userID"], $row["comment"], $row["date"], $row["dir"], $row["fileType"], $row["mimeType"], $row["orgFileName"], $row["name"],$row["version"],$row["public"]);
1335            $files[] = $file;
1336        }
1337        return $files;
1338    } /* }}} */
1339
1340    /**
1341     * Returns all document contents of a given user
1342     * @return SeedDMS_Core_DocumentContent[]|bool list of document contents
1343     */
1344    function getDocumentContents() { /* {{{ */
1345        $db = $this->_dms->getDB();
1346
1347        $queryStr = "SELECT * FROM `tblDocumentContent` WHERE `createdBy` = " . $this->_id;
1348
1349        $resArr = $db->getResultArray($queryStr);
1350        if (is_bool($resArr) && !$resArr)
1351            return false;
1352
1353        $contents = array();
1354        $classname = $this->_dms->getClassname('documentcontent');
1355        foreach ($resArr as $row) {
1356            $document = $this->_dms->getDocument($row["document"]);
1357            /** @var SeedDMS_Core_DocumentContent $content */
1358            $content = new $classname((int) $row["id"], $document, $row["version"], $row["comment"], $row["date"], $row["createdBy"], $row["dir"], $row["orgFileName"], $row["fileType"], $row["mimeType"], $row['fileSize'], $row['checksum']);
1359            $contents[] = $content;
1360        }
1361        return $contents;
1362    } /* }}} */
1363
1364    /**
1365     * Returns all folders of a given user
1366     * @return SeedDMS_Core_Folder[]|bool list of folders
1367     */
1368    function getFolders() { /* {{{ */
1369        $db = $this->_dms->getDB();
1370
1371        $queryStr = "SELECT * FROM `tblFolders` ".
1372            "WHERE `owner` = " . $this->_id . " ORDER BY `sequence`";
1373
1374        $resArr = $db->getResultArray($queryStr);
1375        if (is_bool($resArr) && !$resArr)
1376            return false;
1377
1378        $folders = array();
1379        $classname = $this->_dms->getClassname('folder');
1380        foreach ($resArr as $row) {
1381            /** @var SeedDMS_Core_Folder $folder */
1382            $folder = new $classname((int) $row["id"], $row["name"], $row['parent'], $row["comment"], $row["date"], $row["owner"], $row["inheritAccess"], $row["defaultAccess"], $row["sequence"]);
1383            $folder->setDMS($this->_dms);
1384            $folders[] = $folder;
1385        }
1386        return $folders;
1387    } /* }}} */
1388
1389    /**
1390     * Get a list of reviews
1391     *
1392     * This function returns a list of all reviews and their latest log entry
1393     * seperated by individuals and groups. If the document id
1394     * is passed, then only this document will be checked for reviews. The
1395     * same is true for the version of a document which limits the list
1396     * further. If you do not limit on a version it will retrieve the status
1397     * for each version, that includes even older versions which has been superseded
1398     * by a new version.
1399     *
1400     * For a detailed description of the result array see
1401     * {link SeedDMS_Core_User::getApprovalStatus} which does the same for
1402     * approvals.
1403     *
1404     * @param int $documentID optional document id for which to retrieve the
1405     *        reviews
1406     * @param int $version optional version of the document
1407     * @return array|bool list of all reviews
1408     */
1409    function getReviewStatus($documentID=null, $version=null) { /* {{{ */
1410        $db = $this->_dms->getDB();
1411
1412        if (!$db->createTemporaryTable("ttreviewid", true)) {
1413            return false;
1414        }
1415
1416        $status = array("indstatus"=>array(), "grpstatus"=>array());
1417
1418        // See if the user is assigned as an individual reviewer.
1419        // Attention: this method didn't use ttreviewid to filter out the latest
1420        // log entry. This was added 2021-09-29 because $group->getReviewStatus()
1421        // does it as well. The check below if the date is larger than the date
1422        // of a previos entry is still required to just take the latest version
1423        // of a document into account.
1424        $queryStr = "SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, ".
1425            "`tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, ".
1426            "`tblDocumentReviewLog`.`userID` ".
1427            "FROM `tblDocumentReviewers` ".
1428            "LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) ".
1429            "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ".
1430            "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ".
1431            ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". (int) $documentID ."' ").
1432            ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". (int) $version ."' ").
1433            "AND `tblDocumentReviewers`.`type`='0' ".
1434            "AND `tblDocumentReviewers`.`required`='". $this->_id ."' ".
1435            "ORDER BY `tblDocumentReviewLog`.`reviewLogID` DESC";
1436        $resArr = $db->getResultArray($queryStr);
1437        if (is_bool($resArr) && $resArr === false)
1438            return false;
1439        if (count($resArr)>0) {
1440            foreach ($resArr as $res) {
1441                if(isset($status["indstatus"][$res['documentID']])) {
1442                    if($status["indstatus"][$res['documentID']]['date'] < $res['date']) {
1443                        $status["indstatus"][$res['documentID']] = $res;
1444                    }
1445                } else {
1446                    $status["indstatus"][$res['documentID']] = $res;
1447                }
1448            }
1449        }
1450
1451        // See if the user is the member of a group that has been assigned to
1452        // review the document version.
1453        $queryStr = "SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, ".
1454            "`tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, ".
1455            "`tblDocumentReviewLog`.`userID` ".
1456            "FROM `tblDocumentReviewers` ".
1457            "LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) ".
1458            "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ".
1459            "LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`groupID` = `tblDocumentReviewers`.`required` ".
1460            "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ".
1461            ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". (int) $documentID ."' ").
1462            ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". (int) $version ."' ").
1463            "AND `tblDocumentReviewers`.`type`='1' ".
1464            "AND `tblGroupMembers`.`userID`='". $this->_id ."' ".
1465            "ORDER BY `tblDocumentReviewLog`.`reviewLogID` DESC";
1466        $resArr = $db->getResultArray($queryStr);
1467        if (is_bool($resArr) && $resArr === false)
1468            return false;
1469        if (count($resArr)>0) {
1470            foreach ($resArr as $res) {
1471                if(isset($status["grpstatus"][$res['documentID']])) {
1472                    if($status["grpstatus"][$res['documentID']]['date'] < $res['date']) {
1473                        $status["grpstatus"][$res['documentID']] = $res;
1474                    }
1475                } else {
1476                    $status["grpstatus"][$res['documentID']] = $res;
1477                }
1478            }
1479        }
1480        return $status;
1481    } /* }}} */
1482
1483    /**
1484     * Get a list of approvals
1485     *
1486     * This function returns a list of all approvals and their latest log entry
1487     * seperated by individuals and groups. If the document id
1488     * is passed, then only this document will be checked for approvals. The
1489     * same is true for the version of a document which limits the list
1490     * further. If you do not limit on a version it will retrieve the status
1491     * for each version, that includes even older versions which has been superseded
1492     * by a new version.
1493     *
1494     * The result array has two elements:
1495     * - indstatus: which contains the approvals by individuals (users)
1496     * - grpstatus: which contains the approvals by groups
1497     *
1498     * Each element is itself an array of approvals with the following elements
1499     * (it is a combination of fields from tblDocumentApprovers and tblDocumentApproveLog):
1500     * - approveID: unique id of approval
1501     * - documentID: id of document, that needs to be approved
1502     * - version: version of document, that needs to be approved
1503     * - type: 0 for individual approval, 1 for group approval
1504     * - required: id of user who is required to do the approval
1505     * - status: 0 not approved, ....
1506     * - comment: comment given during approval
1507     * - date: date of approval
1508     * - userID: id of user who has done the approval
1509     *
1510     * @param int $documentID optional document id for which to retrieve the
1511     *        approvals
1512     * @param int $version optional version of the document
1513     * @return array|bool list of all approvals
1514     */
1515    function getApprovalStatus($documentID=null, $version=null) { /* {{{ */
1516        $db = $this->_dms->getDB();
1517
1518        if (!$db->createTemporaryTable("ttapproveid")) {
1519            return false;
1520        }
1521
1522        $status = array("indstatus"=>array(), "grpstatus"=>array());
1523
1524        // See if the user is assigned as an individual approver.
1525        // Attention: this method didn't use ttapproveid to filter out the latest
1526        // log entry. This was added 2021-09-29 because $group->getApprovalStatus()
1527        // does it as well. The check below if the date is larger than the date
1528        // of a previos entry is still required to just take the latest version
1529        // of a document into account.
1530        $queryStr =
1531            "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ".
1532            "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ".
1533            "`tblDocumentApproveLog`.`userID` ".
1534            "FROM `tblDocumentApprovers` ".
1535            "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ".
1536            "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ".
1537            "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ".
1538            ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". (int) $documentID ."' ").
1539            ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". (int) $version ."' ").
1540            "AND `tblDocumentApprovers`.`type`='0' ".
1541            "AND `tblDocumentApprovers`.`required`='". $this->_id ."' ".
1542            "ORDER BY `tblDocumentApproveLog`.`approveLogID` DESC";
1543
1544        $resArr = $db->getResultArray($queryStr);
1545        if (is_bool($resArr) && $resArr == false)
1546            return false;
1547        if (count($resArr)>0) {
1548            foreach ($resArr as $res) {
1549                if(isset($status["indstatus"][$res['documentID']])) {
1550                    if($status["indstatus"][$res['documentID']]['date'] < $res['date']) {
1551                        $status["indstatus"][$res['documentID']] = $res;
1552                    }
1553                } else {
1554                    $status["indstatus"][$res['documentID']] = $res;
1555                }
1556            }
1557        }
1558
1559        // See if the user is the member of a group that has been assigned to
1560        // approve the document version.
1561        $queryStr =
1562            "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ".
1563            "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ".
1564            "`tblDocumentApproveLog`.`userID` ".
1565            "FROM `tblDocumentApprovers` ".
1566            "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ".
1567            "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ".
1568            "LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`groupID` = `tblDocumentApprovers`.`required` ".
1569            "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ".
1570            ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". (int) $documentID ."' ").
1571            ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". (int) $version ."' ").
1572            "AND `tblDocumentApprovers`.`type`='1' ".
1573            "AND `tblGroupMembers`.`userID`='". $this->_id ."' ".
1574            "ORDER BY `tblDocumentApproveLog`.`approveLogID` DESC";
1575        $resArr = $db->getResultArray($queryStr);
1576        if (is_bool($resArr) && $resArr == false)
1577            return false;
1578        if (count($resArr)>0) {
1579            foreach ($resArr as $res) {
1580                if(isset($status["grpstatus"][$res['documentID']])) {
1581                    if($status["grpstatus"][$res['documentID']]['date'] < $res['date']) {
1582                        $status["grpstatus"][$res['documentID']] = $res;
1583                    }
1584                } else {
1585                    $status["grpstatus"][$res['documentID']] = $res;
1586                }
1587            }
1588        }
1589        return $status;
1590    } /* }}} */
1591
1592    /**
1593     * Get a list of documents with a workflow
1594     *
1595     * @param int $documentID optional document id for which to retrieve the
1596     *        reviews
1597     * @param int $version optional version of the document
1598     * @return array|bool list of all workflows
1599     */
1600    function getWorkflowStatus($documentID=null, $version=null) { /* {{{ */
1601        $db = $this->_dms->getDB();
1602
1603        $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;
1604        if($documentID) {
1605            $queryStr .= ' AND d.`document`='.(int) $documentID;
1606            if($version)
1607                $queryStr .= ' AND d.`version`='.(int) $version;
1608        }
1609        $resArr = $db->getResultArray($queryStr);
1610        if (is_bool($resArr) && $resArr == false)
1611            return false;
1612        $result['u'] = array();
1613        if (count($resArr)>0) {
1614            foreach ($resArr as $res) {
1615                $result['u'][] = $res;
1616            }
1617        }
1618
1619        $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;
1620        if($documentID) {
1621            $queryStr .= ' AND d.`document`='.(int) $documentID;
1622            if($version)
1623                $queryStr .= ' AND d.`version`='.(int) $version;
1624        }
1625        $resArr = $db->getResultArray($queryStr);
1626        if (is_bool($resArr) && $resArr == false)
1627            return false;
1628        $result['g'] = array();
1629        if (count($resArr)>0) {
1630            foreach ($resArr as $res) {
1631                $result['g'][] = $res;
1632            }
1633        }
1634        return $result;
1635    } /* }}} */
1636
1637    /**
1638     * Get a list of workflows this user is involved as in individual
1639     *
1640     * @return array|bool list of all workflows
1641     */
1642    function getWorkflowsInvolved() { /* {{{ */
1643        $db = $this->_dms->getDB();
1644
1645        $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;
1646        $resArr = $db->getResultArray($queryStr);
1647        if (is_bool($resArr) && $resArr == false)
1648            return false;
1649        $result = array();
1650        if (count($resArr)>0) {
1651            foreach ($resArr as $res) {
1652                $result[] = $this->_dms->getWorkflow((int) $res['id']);
1653            }
1654        }
1655
1656        return $result;
1657    } /* }}} */
1658
1659    /**
1660     * Get a list of mandatory reviewers
1661     * A user which isn't trusted completely may have assigned mandatory
1662     * reviewers (both users and groups).
1663     * Whenever the user inserts a new document the mandatory reviewers are
1664     * filled in as reviewers.
1665     *
1666     * @return array list of arrays with two elements containing the user id
1667     *         (reviewerUserID) and group id (reviewerGroupID) of the reviewer.
1668     */
1669    function getMandatoryReviewers() { /* {{{ */
1670        $db = $this->_dms->getDB();
1671
1672        $queryStr = "SELECT * FROM `tblMandatoryReviewers` WHERE `userID` = " . $this->_id;
1673        $resArr = $db->getResultArray($queryStr);
1674
1675        return $resArr;
1676    } /* }}} */
1677
1678    /**
1679     * Get a list of mandatory approvers
1680     * See {link SeedDMS_Core_User::getMandatoryReviewers}
1681     *
1682     * @return array list of arrays with two elements containing the user id
1683     *         (approverUserID) and group id (approverGroupID) of the approver.
1684     */
1685    function getMandatoryApprovers() { /* {{{ */
1686        $db = $this->_dms->getDB();
1687
1688        $queryStr = "SELECT * FROM `tblMandatoryApprovers` WHERE `userID` = " . $this->_id;
1689        $resArr = $db->getResultArray($queryStr);
1690
1691        return $resArr;
1692    } /* }}} */
1693
1694    /**
1695     * Get a list of users this user is a mandatory reviewer of
1696     *
1697     * This method is the reverse function of getMandatoryReviewers(). It returns
1698     * those user where the current user is a mandatory reviewer.
1699     *
1700     * @return SeedDMS_Core_User[]|bool list of users where this user is a mandatory reviewer.
1701     */
1702    function isMandatoryReviewerOf() { /* {{{ */
1703        $db = $this->_dms->getDB();
1704
1705        $queryStr = "SELECT * FROM `tblMandatoryReviewers` WHERE `reviewerUserID` = " . $this->_id;
1706        $resArr = $db->getResultArray($queryStr);
1707        if (is_bool($resArr) && !$resArr) return false;
1708
1709        $users = array();
1710        foreach($resArr as $res) {
1711            $users[] = self::getInstance($res['userID'], $this->_dms);
1712        }
1713
1714        return $users;
1715    } /* }}} */
1716
1717    /**
1718     * Get a list of users this user is a mandatory approver of
1719     *
1720     * This method is the reverse function of getMandatoryApprovers(). It returns
1721     * those user where the current user is a mandatory approver.
1722     *
1723     * @return SeedDMS_Core_User[]|bool list of users where this user is a mandatory approver.
1724     */
1725    function isMandatoryApproverOf() { /* {{{ */
1726        $db = $this->_dms->getDB();
1727
1728        $queryStr = "SELECT * FROM `tblMandatoryApprovers` WHERE `approverUserID` = " . $this->_id;
1729        $resArr = $db->getResultArray($queryStr);
1730        if (is_bool($resArr) && !$resArr) return false;
1731
1732        $users = array();
1733        foreach($resArr as $res) {
1734            $users[] = self::getInstance($res['userID'], $this->_dms);
1735        }
1736
1737        return $users;
1738    } /* }}} */
1739
1740    /**
1741     * Get the mandatory workflow
1742     * A user which isn't trusted completely may have assigned mandatory
1743     * workflow
1744     * Whenever the user inserts a new document the mandatory workflow is
1745     * filled in as the workflow.
1746     *
1747     * @return SeedDMS_Core_Workflow|bool workflow
1748     */
1749    function getMandatoryWorkflow() { /* {{{ */
1750        $db = $this->_dms->getDB();
1751
1752        $queryStr = "SELECT * FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this->_id;
1753        $resArr = $db->getResultArray($queryStr);
1754        if (is_bool($resArr) && !$resArr) return false;
1755
1756        if(!$resArr)
1757            return null;
1758
1759        $workflow = $this->_dms->getWorkflow($resArr[0]['workflow']);
1760        return $workflow;
1761    } /* }}} */
1762
1763    /**
1764     * Get the mandatory workflows
1765     * A user which isn't trusted completely may have assigned mandatory
1766     * workflow
1767     * Whenever the user inserts a new document the mandatory workflow is
1768     * filled in as the workflow.
1769     *
1770     * @return SeedDMS_Core_Workflow[]|bool workflow
1771     */
1772    function getMandatoryWorkflows() { /* {{{ */
1773        $db = $this->_dms->getDB();
1774
1775        $queryStr = "SELECT * FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this->_id;
1776        $resArr = $db->getResultArray($queryStr);
1777        if (is_bool($resArr) && !$resArr) return false;
1778
1779        if(!$resArr)
1780            return null;
1781
1782        $workflows = array();
1783        foreach($resArr as $res) {
1784            $workflows[] = $this->_dms->getWorkflow($res['workflow']);
1785        }
1786        return $workflows;
1787    } /* }}} */
1788
1789    /**
1790     * Set a mandatory reviewer
1791     * This function sets a mandatory reviewer if it isn't already set.
1792     *
1793     * @param integer $id id of reviewer
1794     * @param boolean $isgroup true if $id is a group
1795     * @return boolean true on success, otherwise false
1796     */
1797    function setMandatoryReviewer($id, $isgroup=false) { /* {{{ */
1798        $db = $this->_dms->getDB();
1799        $id = (int) $id;
1800
1801        if ($isgroup){
1802
1803            $queryStr = "SELECT * FROM `tblMandatoryReviewers` WHERE `userID` = " . $this->_id . " AND `reviewerGroupID` = " . $id;
1804            $resArr = $db->getResultArray($queryStr);
1805            if (count($resArr)!=0) return true;
1806
1807            $queryStr = "INSERT INTO `tblMandatoryReviewers` (`userID`, `reviewerGroupID`) VALUES (" . $this->_id . ", " . $id .")";
1808            $resArr = $db->getResult($queryStr);
1809            if (is_bool($resArr) && !$resArr) return false;
1810
1811        }else{
1812
1813            $queryStr = "SELECT * FROM `tblMandatoryReviewers` WHERE `userID` = " . $this->_id . " AND `reviewerUserID` = " . $id;
1814            $resArr = $db->getResultArray($queryStr);
1815            if (count($resArr)!=0) return true;
1816
1817            $queryStr = "INSERT INTO `tblMandatoryReviewers` (`userID`, `reviewerUserID`) VALUES (" . $this->_id . ", " . $id .")";
1818            $resArr = $db->getResult($queryStr);
1819            if (is_bool($resArr) && !$resArr) return false;
1820        }
1821
1822        return true;
1823    } /* }}} */
1824
1825    /**
1826     * Set a mandatory approver
1827     * This function sets a mandatory approver if it isn't already set.
1828     *
1829     * @param integer $id id of approver
1830     * @param boolean $isgroup true if $id is a group
1831     * @return boolean true on success, otherwise false
1832     */
1833    function setMandatoryApprover($id, $isgroup=false) { /* {{{ */
1834        $db = $this->_dms->getDB();
1835        $id = (int) $id;
1836
1837        if ($isgroup){
1838
1839            $queryStr = "SELECT * FROM `tblMandatoryApprovers` WHERE `userID` = " . $this->_id . " AND `approverGroupID` = " . $id;
1840            $resArr = $db->getResultArray($queryStr);
1841            if (count($resArr)!=0) return true;
1842
1843            $queryStr = "INSERT INTO `tblMandatoryApprovers` (`userID`, `approverGroupID`) VALUES (" . $this->_id . ", " . $id .")";
1844            $resArr = $db->getResult($queryStr);
1845            if (is_bool($resArr) && !$resArr) return false;
1846
1847        }else{
1848
1849            $queryStr = "SELECT * FROM `tblMandatoryApprovers` WHERE `userID` = " . $this->_id . " AND `approverUserID` = " . $id;
1850            $resArr = $db->getResultArray($queryStr);
1851            if (count($resArr)!=0) return true;
1852
1853            $queryStr = "INSERT INTO `tblMandatoryApprovers` (`userID`, `approverUserID`) VALUES (" . $this->_id . ", " . $id .")";
1854            $resArr = $db->getResult($queryStr);
1855            if (is_bool($resArr) && !$resArr) return false;
1856        }
1857
1858        return true;
1859    } /* }}} */
1860
1861    /**
1862     * Set a mandatory workflow
1863     * This function sets a mandatory workflow if it isn't already set.
1864     *
1865     * @param object $workflow workflow
1866     * @return boolean true on success, otherwise false
1867     */
1868    function setMandatoryWorkflow($workflow) { /* {{{ */
1869        $db = $this->_dms->getDB();
1870
1871        $queryStr = "SELECT * FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this->_id . " AND `workflow` = " . (int) $workflow->getID();
1872        $resArr = $db->getResultArray($queryStr);
1873        if (count($resArr)!=0) return true;
1874
1875        $queryStr = "INSERT INTO `tblWorkflowMandatoryWorkflow` (`userid`, `workflow`) VALUES (" . $this->_id . ", " . $workflow->getID() .")";
1876        $resArr = $db->getResult($queryStr);
1877        if (is_bool($resArr) && !$resArr) return false;
1878
1879        return true;
1880    } /* }}} */
1881
1882    /**
1883     * Set a mandatory workflows
1884     * This function sets a list of mandatory workflows.
1885     *
1886     * @param SeedDMS_Core_Workflow[] $workflows list of workflow objects
1887     * @return boolean true on success, otherwise false
1888     */
1889    function setMandatoryWorkflows($workflows) { /* {{{ */
1890        $db = $this->_dms->getDB();
1891
1892        $db->startTransaction();
1893        $queryStr = "DELETE FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this->_id;
1894        if (!$db->getResult($queryStr)) {
1895            $db->rollbackTransaction();
1896            return false;
1897        }
1898
1899        foreach($workflows as $workflow) {
1900            $queryStr = "INSERT INTO `tblWorkflowMandatoryWorkflow` (`userid`, `workflow`) VALUES (" . $this->_id . ", " . $workflow->getID() .")";
1901            $resArr = $db->getResult($queryStr);
1902            if (is_bool($resArr) && !$resArr) {
1903                $db->rollbackTransaction();
1904                return false;
1905            }
1906        }
1907
1908        $db->commitTransaction();
1909        return true;
1910    } /* }}} */
1911
1912    /**
1913     * Deletes all mandatory reviewers
1914     *
1915     * @return boolean true on success, otherwise false
1916     */
1917    function delMandatoryReviewers() { /* {{{ */
1918        $db = $this->_dms->getDB();
1919        $queryStr = "DELETE FROM `tblMandatoryReviewers` WHERE `userID` = " . $this->_id;
1920        if (!$db->getResult($queryStr)) return false;
1921        return true;
1922    } /* }}} */
1923
1924    /**
1925     * Deletes all mandatory approvers
1926     *
1927     * @return boolean true on success, otherwise false
1928     */
1929    function delMandatoryApprovers() { /* {{{ */
1930        $db = $this->_dms->getDB();
1931
1932        $queryStr = "DELETE FROM `tblMandatoryApprovers` WHERE `userID` = " . $this->_id;
1933        if (!$db->getResult($queryStr)) return false;
1934        return true;
1935    } /* }}} */
1936
1937    /**
1938     * Deletes the  mandatory workflow
1939     *
1940     * @return boolean true on success, otherwise false
1941     */
1942    function delMandatoryWorkflow() { /* {{{ */
1943        $db = $this->_dms->getDB();
1944        $queryStr = "DELETE FROM `tblWorkflowMandatoryWorkflow` WHERE `userid` = " . $this->_id;
1945        if (!$db->getResult($queryStr)) return false;
1946        return true;
1947    } /* }}} */
1948
1949    /**
1950     * Get all notifications of user
1951     *
1952     * @param integer $type type of item (T_DOCUMENT or T_FOLDER)
1953     * @return SeedDMS_Core_Notification[]|bool array of notifications
1954     */
1955    function getNotifications($type=0) { /* {{{ */
1956        $db = $this->_dms->getDB();
1957        $queryStr = "SELECT `tblNotify`.* FROM `tblNotify` ".
1958         "WHERE `tblNotify`.`userID` = ". $this->_id;
1959        if($type) {
1960            $queryStr .= " AND `tblNotify`.`targetType` = ". (int) $type;
1961        }
1962
1963        $resArr = $db->getResultArray($queryStr);
1964        if (is_bool($resArr) && !$resArr)
1965            return false;
1966
1967        $notifications = array();
1968        foreach ($resArr as $row) {
1969            $not = new SeedDMS_Core_Notification($row["target"], $row["targetType"], $row["userID"], $row["groupID"]);
1970            $not->setDMS($this);
1971            array_push($notifications, $not);
1972        }
1973
1974        return $notifications;
1975    } /* }}} */
1976
1977    /**
1978     * Return list of personal keyword categories
1979     *
1980     * @return SeedDMS_Core_KeywordCategory[]|bool list of categories or false in case of an error
1981     */
1982    function getKeywordCategories() { /* {{{ */
1983        $db = $this->_dms->getDB();
1984
1985        $queryStr = "SELECT * FROM `tblKeywordCategories` WHERE `owner` = ".$this->_id;
1986
1987        $resArr = $db->getResultArray($queryStr);
1988        if (is_bool($resArr) && !$resArr)
1989            return false;
1990
1991        $categories = array();
1992        foreach ($resArr as $row) {
1993            $cat = new SeedDMS_Core_KeywordCategory((int) $row["id"], $row["owner"], $row["name"]);
1994            $cat->setDMS($this->_dms);
1995            array_push($categories, $cat);
1996        }
1997
1998        return $categories;
1999    } /* }}} */
2000
2001} /* }}} */