diff --git a/inc/inc.ClassGroup.php b/inc/inc.ClassGroup.php index 206c6b842..deef80e98 100644 --- a/inc/inc.ClassGroup.php +++ b/inc/inc.ClassGroup.php @@ -1,269 +1,258 @@ -_id = $id; - $this->_name = $name; - $this->_comment = $comment; - } - function setDMS($dms) { + function LetoDMS_Group($id, $name, $comment) { /* {{{ */ + $this->_id = $id; + $this->_name = $name; + $this->_comment = $comment; + $this->_dms = null; + } /* }}} */ + + function setDMS($dms) { /* {{{ */ $this->_dms = $dms; - } + } /* }}} */ - function getID() { return $this->_id; } - - function getName() { return $this->_name; } - - function setName($newName) - { - global $db; - - $queryStr = "UPDATE tblGroups SET name = '" . $newName . "' WHERE id = " . $this->_id; - if (!$db->getResult($queryStr)) - return false; - - $this->_name = $newName; - return true; - } - - function getComment() { return $this->_comment; } - - function setComment($newComment) - { - global $db; - - $queryStr = "UPDATE tblGroups SET comment = '" . $newComment . "' WHERE id = " . $this->_id; - if (!$db->getResult($queryStr)) - return false; - - $this->_comment = $newComment; - return true; - } - - function getUsers() - { - global $db; - - if (!isset($this->_users)) - { - $queryStr = "SELECT `tblUsers`.* FROM `tblUsers` ". - "LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ". - "WHERE `tblGroupMembers`.`groupID` = '". $this->_id ."'"; - $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && $resArr == false) - return false; - - $this->_users = array(); - - foreach ($resArr as $row) - { - $user = new LetoDMS_User($row["id"], $row["login"], $row["pwd"], $row["fullName"], $row["email"], $row["language"], $row["theme"], $row["comment"], $row["isAdmin"]); - array_push($this->_users, $user); - } - } - return $this->_users; - } - - function addUser($user,$asManager=false) - { - global $db; + function getID() { return $this->_id; } - $queryStr = "INSERT INTO tblGroupMembers (groupID, userID, manager) VALUES (".$this->_id.", ".$user->getID(). ", " . ($asManager?"1":"0") ." )"; + function getName() { return $this->_name; } + + function setName($newName) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblGroups SET name = '" . $newName . "' WHERE id = " . $this->_id; + if (!$db->getResult($queryStr)) + return false; + + $this->_name = $newName; + return true; + } /* }}} */ + + function getComment() { return $this->_comment; } + + function setComment($newComment) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblGroups SET comment = '" . $newComment . "' WHERE id = " . $this->_id; + if (!$db->getResult($queryStr)) + return false; + + $this->_comment = $newComment; + return true; + } /* }}} */ + + function getUsers() { /* {{{ */ + $db = $this->_dms->getDB(); + + if (!isset($this->_users)) { + $queryStr = "SELECT `tblUsers`.* FROM `tblUsers` ". + "LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ". + "WHERE `tblGroupMembers`.`groupID` = '". $this->_id ."'"; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + + $this->_users = array(); + + foreach ($resArr as $row) { + $user = new LetoDMS_User($row["id"], $row["login"], $row["pwd"], $row["fullName"], $row["email"], $row["language"], $row["theme"], $row["comment"], $row["isAdmin"]); + array_push($this->_users, $user); + } + } + return $this->_users; + } /* }}} */ + + function addUser($user,$asManager=false) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "INSERT INTO tblGroupMembers (groupID, userID, manager) VALUES (".$this->_id.", ".$user->getID(). ", " . ($asManager?"1":"0") ." )"; $res = $db->getResult($queryStr); - - if ($res) return false; - - unset($this->_users); - return true; - } - - function removeUser($user) - { - global $db; - - $queryStr = "DELETE FROM tblGroupMembers WHERE groupID = ".$this->_id." AND userID = ".$user->getID(); + + if ($res) return false; + + unset($this->_users); + return true; + } /* }}} */ + + function removeUser($user) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "DELETE FROM tblGroupMembers WHERE groupID = ".$this->_id." AND userID = ".$user->getID(); $res = $db->getResult($queryStr); - - if ($res) return false; - unset($this->_users); - return true; - } + + if ($res) return false; + unset($this->_users); + return true; + } /* }}} */ // $asManager=false: verify if user is in group - // $asManager=true : verify if user is in group as manager - function isMember($user,$asManager=false) - { - if (isset($this->_users)&&!$asManager) - { - foreach ($this->_users as $usr) - if ($usr->getID() == $user->getID()) - return true; - return false; - } - - global $db; - if ($asManager) $queryStr = "SELECT * FROM tblGroupMembers WHERE groupID = " . $this->_id . " AND userID = " . $user->getID() . " AND manager = 1"; + // $asManager=true : verify if user is in group as manager + function isMember($user,$asManager=false) { /* {{{ */ + if (isset($this->_users)&&!$asManager) { + foreach ($this->_users as $usr) + if ($usr->getID() == $user->getID()) + return true; + return false; + } + + $db = $this->_dms->getDB(); + if ($asManager) $queryStr = "SELECT * FROM tblGroupMembers WHERE groupID = " . $this->_id . " AND userID = " . $user->getID() . " AND manager = 1"; else $queryStr = "SELECT * FROM tblGroupMembers WHERE groupID = " . $this->_id . " AND userID = " . $user->getID(); $resArr = $db->getResultArray($queryStr); - - if (is_bool($resArr) && $resArr == false) return false; + + if (is_bool($resArr) && $resArr == false) return false; if (count($resArr) != 1) return false; - - return true; - } - - function toggleManager($user) - { - global $db; - - if (!$this->isMember($user)) return false; - - if ($this->isMember($user,true)) $queryStr = "UPDATE tblGroupMembers SET manager = 0 WHERE groupID = ".$this->_id." AND userID = ".$user->getID(); - else $queryStr = "UPDATE tblGroupMembers SET manager = 1 WHERE groupID = ".$this->_id." AND userID = ".$user->getID(); - - if (!$db->getResult($queryStr)) return false; + return true; - } - - /** - * Entfernt die Gruppe aus dem System. - * Dies ist jedoch nicht mit einem Löschen des entsprechenden Eintrags aus tblGroups geschehen - vielmehr - * muss dafür gesorgt werden, dass die Gruppe nirgendwo mehr auftaucht. D.h. auch die Tabellen tblACLs, - * tblNotify und tblGroupMembers müssen berücksichtigt werden. - */ - function remove() - { - GLOBAl $db, $user; - - $queryStr = "DELETE FROM tblGroups WHERE id = " . $this->_id; - if (!$db->getResult($queryStr)) - return false; - $queryStr = "DELETE FROM tblGroupMembers WHERE groupID = " . $this->_id; - if (!$db->getResult($queryStr)) - return false; - $queryStr = "DELETE FROM tblACLs WHERE groupID = " . $this->_id; - if (!$db->getResult($queryStr)) - return false; - $queryStr = "DELETE FROM tblNotify WHERE groupID = " . $this->_id; - if (!$db->getResult($queryStr)) + } /* }}} */ + + function toggleManager($user) { /* {{{ */ + $db = $this->_dms->getDB(); + + if (!$this->isMember($user)) return false; + + if ($this->isMember($user,true)) $queryStr = "UPDATE tblGroupMembers SET manager = 0 WHERE groupID = ".$this->_id." AND userID = ".$user->getID(); + else $queryStr = "UPDATE tblGroupMembers SET manager = 1 WHERE groupID = ".$this->_id." AND userID = ".$user->getID(); + + if (!$db->getResult($queryStr)) return false; + return true; + } /* }}} */ + + /** + * Entfernt die Gruppe aus dem System. + * Dies ist jedoch nicht mit einem Löschen des entsprechenden Eintrags aus tblGroups geschehen - vielmehr + * muss dafür gesorgt werden, dass die Gruppe nirgendwo mehr auftaucht. D.h. auch die Tabellen tblACLs, + * tblNotify und tblGroupMembers müssen berücksichtigt werden. + */ + function remove() { /* {{{ */ + $db = $this->_dms->getDB(); + $user = $this->_dms->user; + + $queryStr = "DELETE FROM tblGroups WHERE id = " . $this->_id; + if (!$db->getResult($queryStr)) return false; - $queryStr = "DELETE FROM tblMandatoryReviewers WHERE reviewerGroupID = " . $this->_id; - if (!$db->getResult($queryStr)) - return false; - $queryStr = "DELETE FROM tblMandatoryApprovers WHERE approverGroupID = " . $this->_id; - if (!$db->getResult($queryStr)) + $queryStr = "DELETE FROM tblGroupMembers WHERE groupID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; - + $queryStr = "DELETE FROM tblACLs WHERE groupID = " . $this->_id; + if (!$db->getResult($queryStr)) + return false; + $queryStr = "DELETE FROM tblNotify WHERE groupID = " . $this->_id; + if (!$db->getResult($queryStr)) + return false; + $queryStr = "DELETE FROM tblMandatoryReviewers WHERE reviewerGroupID = " . $this->_id; + if (!$db->getResult($queryStr)) + return false; + $queryStr = "DELETE FROM tblMandatoryApprovers WHERE approverGroupID = " . $this->_id; + if (!$db->getResult($queryStr)) + return false; + // TODO : update document status if reviewer/approver has been deleted - - - $reviewStatus = $this->getReviewStatus(); - foreach ($reviewStatus as $r) { - $queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ". - "VALUES ('". $r["reviewID"] ."', '-2', 'Review group removed from process', NOW(), '". $user->getID() ."')"; - $res=$db->getResult($queryStr); - } - - $approvalStatus = $this->getApprovalStatus(); - foreach ($approvalStatus as $a) { - $queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ". - "VALUES ('". $a["approveID"] ."', '-2', 'Approval group removed from process', NOW(), '". $user->getID() ."')"; - $res=$db->getResult($queryStr); - } - - return true; - } - - function getReviewStatus($documentID=null, $version=null) { - global $db; - - if (!$db->createTemporaryTable("ttreviewid")) { - return false; - } - - $status = array(); - - // See if the group is assigned as a reviewer. - $queryStr = "SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, ". - "`tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, ". - "`tblDocumentReviewLog`.`userID` ". - "FROM `tblDocumentReviewers` ". - "LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) ". - "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ". - "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ". - ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". $documentID ."' "). - ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". $version ."' "). - "AND `tblDocumentReviewers`.`type`='1' ". - "AND `tblDocumentReviewers`.`required`='". $this->_id ."' "; - $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && $resArr == false) - return false; - if (count($resArr)>0) { - foreach ($resArr as $res) - $status[] = $res; - } - return $status; - } - - function getApprovalStatus($documentID=null, $version=null) { - global $db; - - if (!$db->createTemporaryTable("ttapproveid")) { - return false; - } - - $status = array(); - - // See if the group is assigned as an approver. - $queryStr = "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ". - "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ". - "`tblDocumentApproveLog`.`userID` ". - "FROM `tblDocumentApprovers` ". - "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ". - "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ". - "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ". - ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". $documentID ."' "). - ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". $version ."' "). - "AND `tblDocumentApprovers`.`type`='1' ". - "AND `tblDocumentApprovers`.`required`='". $this->_id ."' "; - $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && $resArr == false) - return false; - if (count($resArr)>0) { - foreach ($resArr as $res) - $status[] = $res; - } - - return $status; - } -} -?> + + + $reviewStatus = $this->getReviewStatus(); + foreach ($reviewStatus as $r) { + $queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ". + "VALUES ('". $r["reviewID"] ."', '-2', 'Review group removed from process', NOW(), '". $user->getID() ."')"; + $res=$db->getResult($queryStr); + } + + $approvalStatus = $this->getApprovalStatus(); + foreach ($approvalStatus as $a) { + $queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ". + "VALUES ('". $a["approveID"] ."', '-2', 'Approval group removed from process', NOW(), '". $user->getID() ."')"; + $res=$db->getResult($queryStr); + } + + return true; + } /* }}} */ + + function getReviewStatus($documentID=null, $version=null) { /* {{{ */ + $db = $this->_dms->getDB(); + + if (!$db->createTemporaryTable("ttreviewid")) { + return false; + } + + $status = array(); + + // See if the group is assigned as a reviewer. + $queryStr = "SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, ". + "`tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, ". + "`tblDocumentReviewLog`.`userID` ". + "FROM `tblDocumentReviewers` ". + "LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) ". + "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ". + "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ". + ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". $documentID ."' "). + ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". $version ."' "). + "AND `tblDocumentReviewers`.`type`='1' ". + "AND `tblDocumentReviewers`.`required`='". $this->_id ."' "; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + if (count($resArr)>0) { + foreach ($resArr as $res) + $status[] = $res; + } + return $status; + } /* }}} */ + + function getApprovalStatus($documentID=null, $version=null) { /* {{{ */ + $db = $this->_dms->getDB(); + + if (!$db->createTemporaryTable("ttapproveid")) { + return false; + } + + $status = array(); + + // See if the group is assigned as an approver. + $queryStr = "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ". + "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ". + "`tblDocumentApproveLog`.`userID` ". + "FROM `tblDocumentApprovers` ". + "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ". + "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ". + "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ". + ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". $documentID ."' "). + ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". $version ."' "). + "AND `tblDocumentApprovers`.`type`='1' ". + "AND `tblDocumentApprovers`.`required`='". $this->_id ."' "; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + if (count($resArr)>0) { + foreach ($resArr as $res) + $status[] = $res; + } + + return $status; + } /* }}} */ +} +?> diff --git a/inc/inc.ClassUser.php b/inc/inc.ClassUser.php index 833d4be5c..00c4267cc 100644 --- a/inc/inc.ClassUser.php +++ b/inc/inc.ClassUser.php @@ -1,193 +1,185 @@ -_id = $id; - $this->_login = $login; - $this->_pwd = $pwd; - $this->_fullName = $fullName; - $this->_email = $email; - $this->_language = $language; - $this->_theme = $theme; - $this->_comment = $comment; + var $_id; + var $_login; + var $_pwd; + var $_fullName; + var $_email; + var $_language; + var $_theme; + var $_comment; + var $_isAdmin; + var $_isHidden; + var $_dms; + + function LetoDMS_User($id, $login, $pwd, $fullName, $email, $language, $theme, $comment, $isAdmin, $isHidden=0) { + $this->_id = $id; + $this->_login = $login; + $this->_pwd = $pwd; + $this->_fullName = $fullName; + $this->_email = $email; + $this->_language = $language; + $this->_theme = $theme; + $this->_comment = $comment; $this->_isAdmin = $isAdmin; - $this->_isHidden = $isHidden; - } + $this->_isHidden = $isHidden; + $this->_dms = null; + } function setDMS($dms) { $this->_dms = $dms; } - function getID() { return $this->_id; } - - function getLogin() { return $this->_login; } - - function setLogin($newLogin) - { - GLOBAL $db; - - $queryStr = "UPDATE tblUsers SET login ='" . $newLogin . "' WHERE id = " . $this->_id; - $res = $db->getResult($queryStr); - if (!$res) - return false; - - $this->_login = $newLogin; - return true; - } - - function getFullName() { return $this->_fullName; } - - function setFullName($newFullName) - { - GLOBAL $db; - - $queryStr = "UPDATE tblUsers SET fullname = '" . $newFullName . "' WHERE id = " . $this->_id; - $res = $db->getResult($queryStr); - if (!$res) - return false; - - $this->_fullName = $newFullName; - return true; - } - - function getPwd() { return $this->_pwd; } - - function setPwd($newPwd) - { - GLOBAL $db; - - $queryStr = "UPDATE tblUsers SET pwd ='" . $newPwd . "' WHERE id = " . $this->_id; - $res = $db->getResult($queryStr); - if (!$res) - return false; - - $this->_pwd = $newPwd; - return true; - } - - function getEmail() { return $this->_email; } - - function setEmail($newEmail) - { - GLOBAL $db; - - $queryStr = "UPDATE tblUsers SET email ='" . $newEmail . "' WHERE id = " . $this->_id; - $res = $db->getResult($queryStr); - if (!$res) - return false; - - $this->_email = $newEmail; - return true; - } - - function getLanguage() { return $this->_language; } - - function setLanguage($newLanguage) - { - GLOBAL $db; - - $queryStr = "UPDATE tblUsers SET language ='" . $newLanguage . "' WHERE id = " . $this->_id; - $res = $db->getResult($queryStr); - if (!$res) - return false; - - $this->_language = $newLanguage; - return true; - } - - function getTheme() { return $this->_theme; } - - function setTheme($newTheme) - { - GLOBAL $db; - - $queryStr = "UPDATE tblUsers SET theme ='" . $newTheme . "' WHERE id = " . $this->_id; - $res = $db->getResult($queryStr); - if (!$res) - return false; - - $this->_theme = $newTheme; - return true; - } - - function getComment() { return $this->_comment; } - - function setComment($newComment) - { - GLOBAL $db; - - $queryStr = "UPDATE tblUsers SET comment ='" . $newComment . "' WHERE id = " . $this->_id; - $res = $db->getResult($queryStr); - if (!$res) - return false; - - $this->_comment = $newComment; - return true; - } - - function isAdmin() { return $this->_isAdmin; } - - function setAdmin($isAdmin) - { - GLOBAL $db; - - $isAdmin = ($isAdmin) ? "1" : "0"; - $queryStr = "UPDATE tblUsers SET isAdmin = " . $isAdmin . " WHERE id = " . $this->_id; - if (!$db->getResult($queryStr)) - return false; - - $this->_isAdmin = $isAdmin; - return true; - } - - function isHidden() { return $this->_isHidden; } - - function setHidden($isHidden) - { - GLOBAL $db; - - $isHidden = ($isHidden) ? "1" : "0"; - $queryStr = "UPDATE tblUsers SET hidden = " . $isHidden . " WHERE id = " . $this->_id; - if (!$db->getResult($queryStr)) - return false; - - $this->_isHidden = $isAdmin; - return true; - } + function getID() { return $this->_id; } + + function getLogin() { return $this->_login; } + + function setLogin($newLogin) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblUsers SET login ='" . $newLogin . "' WHERE id = " . $this->_id; + $res = $db->getResult($queryStr); + if (!$res) + return false; + + $this->_login = $newLogin; + return true; + } /* }}} */ + + function getFullName() { return $this->_fullName; } + + function setFullName($newFullName) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblUsers SET fullname = '" . $newFullName . "' WHERE id = " . $this->_id; + $res = $db->getResult($queryStr); + if (!$res) + return false; + + $this->_fullName = $newFullName; + return true; + } /* }}} */ + + function getPwd() { return $this->_pwd; } + + function setPwd($newPwd) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblUsers SET pwd ='" . $newPwd . "' WHERE id = " . $this->_id; + $res = $db->getResult($queryStr); + if (!$res) + return false; + + $this->_pwd = $newPwd; + return true; + } /* }}} */ + + function getEmail() { return $this->_email; } + + function setEmail($newEmail) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblUsers SET email ='" . $newEmail . "' WHERE id = " . $this->_id; + $res = $db->getResult($queryStr); + if (!$res) + return false; + + $this->_email = $newEmail; + return true; + } /* }}} */ + + function getLanguage() { return $this->_language; } + + function setLanguage($newLanguage) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblUsers SET language ='" . $newLanguage . "' WHERE id = " . $this->_id; + $res = $db->getResult($queryStr); + if (!$res) + return false; + + $this->_language = $newLanguage; + return true; + } /* }}} */ + + function getTheme() { return $this->_theme; } + + function setTheme($newTheme) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblUsers SET theme ='" . $newTheme . "' WHERE id = " . $this->_id; + $res = $db->getResult($queryStr); + if (!$res) + return false; + + $this->_theme = $newTheme; + return true; + } /* }}} */ + + function getComment() { return $this->_comment; } + + function setComment($newComment) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblUsers SET comment ='" . $newComment . "' WHERE id = " . $this->_id; + $res = $db->getResult($queryStr); + if (!$res) + return false; + + $this->_comment = $newComment; + return true; + } /* }}} */ + + function isAdmin() { return $this->_isAdmin; } + + function setAdmin($isAdmin) { /* {{{ */ + $db = $this->_dms->getDB(); + + $isAdmin = ($isAdmin) ? "1" : "0"; + $queryStr = "UPDATE tblUsers SET isAdmin = " . $isAdmin . " WHERE id = " . $this->_id; + if (!$db->getResult($queryStr)) + return false; + + $this->_isAdmin = $isAdmin; + return true; + } /* }}} */ + + function isHidden() { return $this->_isHidden; } + + function setHidden($isHidden) { /* {{{ */ + $db = $this->_dms->getDB(); + + $isHidden = ($isHidden) ? "1" : "0"; + $queryStr = "UPDATE tblUsers SET hidden = " . $isHidden . " WHERE id = " . $this->_id; + if (!$db->getResult($queryStr)) + return false; + + $this->_isHidden = $isAdmin; + return true; + } /* }}} */ /** * Remove the user and also remove all its keywords, notifies, etc. @@ -199,7 +191,8 @@ class LetoDMS_User { * @return boolean true on success or false in case of an error */ function remove( $assignToUser=null ) { /* {{{ */ - GLOBAL $db, $user; + $db = $this->_dms->getDB(); + $user = $this->_dms->user; /* Records like folders and documents that formely have belonged to * the user will assign to another user. If no such user is set, @@ -211,159 +204,159 @@ class LetoDMS_User { $assignTo = $assignToUser->getID(); // delete private keyword lists - $queryStr = "SELECT tblKeywords.id FROM tblKeywords, tblKeywordCategories WHERE tblKeywords.category = tblKeywordCategories.id AND tblKeywordCategories.owner = " . $this->_id; - $resultArr = $db->getResultArray($queryStr); - if (count($resultArr) > 0) { - $queryStr = "DELETE FROM tblKeywords WHERE "; - for ($i = 0; $i < count($resultArr); $i++) { - $queryStr .= "id = " . $resultArr[$i]["id"]; - if ($i + 1 < count($resultArr)) - $queryStr .= " OR "; - } - if (!$db->getResult($queryStr)) return false; + $queryStr = "SELECT tblKeywords.id FROM tblKeywords, tblKeywordCategories WHERE tblKeywords.category = tblKeywordCategories.id AND tblKeywordCategories.owner = " . $this->_id; + $resultArr = $db->getResultArray($queryStr); + if (count($resultArr) > 0) { + $queryStr = "DELETE FROM tblKeywords WHERE "; + for ($i = 0; $i < count($resultArr); $i++) { + $queryStr .= "id = " . $resultArr[$i]["id"]; + if ($i + 1 < count($resultArr)) + $queryStr .= " OR "; + } + if (!$db->getResult($queryStr)) return false; } - - $queryStr = "DELETE FROM tblKeywordCategories WHERE owner = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - //Benachrichtigungen entfernen - $queryStr = "DELETE FROM tblNotify WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - //Der Besitz von Dokumenten oder Ordnern, deren bisheriger Besitzer der zu löschende war, geht an den Admin über - $queryStr = "UPDATE tblFolders SET owner = " . $assignTo . " WHERE owner = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - $queryStr = "UPDATE tblDocuments SET owner = " . $assignTo . " WHERE owner = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - $queryStr = "UPDATE tblDocumentContent SET createdBy = " . $assignTo . " WHERE createdBy = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - //Verweise auf Dokumente: Private löschen... - $queryStr = "DELETE FROM tblDocumentLinks WHERE userID = " . $this->_id . " AND public = 0"; - if (!$db->getResult($queryStr)) return false; - - //... und öffentliche an Admin übergeben - $queryStr = "UPDATE tblDocumentLinks SET userID = " . $assignTo . " WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - // set administrator for deleted user's attachments - $queryStr = "UPDATE tblDocumentFiles SET userID = " . $assignTo . " WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - //Evtl. von diesem Benutzer gelockte Dokumente werden freigegeben - $queryStr = "DELETE FROM tblDocumentLocks WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - //User aus allen Gruppen löschen - $queryStr = "DELETE FROM tblGroupMembers WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - //User aus allen ACLs streichen - $queryStr = "DELETE FROM tblACLs WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - //Eintrag aus tblUsers löschen - $queryStr = "DELETE FROM tblUserImages WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - //Eintrag aus tblUsers löschen - $queryStr = "DELETE FROM tblUsers WHERE id = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - // mandatory review/approve - $queryStr = "DELETE FROM tblMandatoryReviewers WHERE reviewerUserID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - $queryStr = "DELETE FROM tblMandatoryApprovers WHERE approverUserID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - $queryStr = "DELETE FROM tblMandatoryReviewers WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - $queryStr = "DELETE FROM tblMandatoryApprovers WHERE userID = " . $this->_id; - if (!$db->getResult($queryStr)) return false; - - // set administrator for deleted user's events - $queryStr = "UPDATE tblEvents SET userID = " . $assignTo . " WHERE userID = " . $this->_id; + + $queryStr = "DELETE FROM tblKeywordCategories WHERE owner = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + //Benachrichtigungen entfernen + $queryStr = "DELETE FROM tblNotify WHERE userID = " . $this->_id; if (!$db->getResult($queryStr)) return false; - + //Der Besitz von Dokumenten oder Ordnern, deren bisheriger Besitzer der zu löschende war, geht an den Admin über + $queryStr = "UPDATE tblFolders SET owner = " . $assignTo . " WHERE owner = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + $queryStr = "UPDATE tblDocuments SET owner = " . $assignTo . " WHERE owner = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + $queryStr = "UPDATE tblDocumentContent SET createdBy = " . $assignTo . " WHERE createdBy = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + //Verweise auf Dokumente: Private löschen... + $queryStr = "DELETE FROM tblDocumentLinks WHERE userID = " . $this->_id . " AND public = 0"; + if (!$db->getResult($queryStr)) return false; + + //... und öffentliche an Admin übergeben + $queryStr = "UPDATE tblDocumentLinks SET userID = " . $assignTo . " WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + // set administrator for deleted user's attachments + $queryStr = "UPDATE tblDocumentFiles SET userID = " . $assignTo . " WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + //Evtl. von diesem Benutzer gelockte Dokumente werden freigegeben + $queryStr = "DELETE FROM tblDocumentLocks WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + //User aus allen Gruppen löschen + $queryStr = "DELETE FROM tblGroupMembers WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + //User aus allen ACLs streichen + $queryStr = "DELETE FROM tblACLs WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + //Eintrag aus tblUsers löschen + $queryStr = "DELETE FROM tblUserImages WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + //Eintrag aus tblUsers löschen + $queryStr = "DELETE FROM tblUsers WHERE id = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + // mandatory review/approve + $queryStr = "DELETE FROM tblMandatoryReviewers WHERE reviewerUserID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + $queryStr = "DELETE FROM tblMandatoryApprovers WHERE approverUserID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + $queryStr = "DELETE FROM tblMandatoryReviewers WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + $queryStr = "DELETE FROM tblMandatoryApprovers WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + // set administrator for deleted user's events + $queryStr = "UPDATE tblEvents SET userID = " . $assignTo . " WHERE userID = " . $this->_id; + if (!$db->getResult($queryStr)) return false; + + // TODO : update document status if reviewer/approver has been deleted // "DELETE FROM tblDocumentApproveLog WHERE userID = " . $this->_id; // "DELETE FROM tblDocumentReviewLog WHERE userID = " . $this->_id; - - - $reviewStatus = $this->getReviewStatus(); - foreach ($reviewStatus["indstatus"] as $ri) { - $queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ". - "VALUES ('". $ri["reviewID"] ."', '-2', 'Reviewer removed from process', NOW(), '". $user->getID() ."')"; - $res=$db->getResult($queryStr); - } - - $approvalStatus = $this->getApprovalStatus(); - foreach ($approvalStatus["indstatus"] as $ai) { - $queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ". - "VALUES ('". $ai["approveID"] ."', '-2', 'Approver removed from process', NOW(), '". $user->getID() ."')"; - $res=$db->getResult($queryStr); - } - -// unset($this); - return true; + + + $reviewStatus = $this->getReviewStatus(); + foreach ($reviewStatus["indstatus"] as $ri) { + $queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ". + "VALUES ('". $ri["reviewID"] ."', '-2', 'Reviewer removed from process', NOW(), '". $user->getID() ."')"; + $res=$db->getResult($queryStr); + } + + $approvalStatus = $this->getApprovalStatus(); + foreach ($approvalStatus["indstatus"] as $ai) { + $queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ". + "VALUES ('". $ai["approveID"] ."', '-2', 'Approver removed from process', NOW(), '". $user->getID() ."')"; + $res=$db->getResult($queryStr); + } + +// unset($this); + return true; } /* }}} */ function joinGroup($group) { /* {{{ */ - if ($group->isMember($this)) - return false; - - if (!$group->addUser($this)) - return false; - - unset($this->_groups); - return true; + if ($group->isMember($this)) + return false; + + if (!$group->addUser($this)) + return false; + + unset($this->_groups); + return true; } /* }}} */ - + function leaveGroup($group) { /* {{{ */ - if (!$group->isMember($this)) - return false; - - if (!$group->removeUser($this)) - return false; - - unset($this->_groups); - return true; + if (!$group->isMember($this)) + return false; + + if (!$group->removeUser($this)) + return false; + + unset($this->_groups); + return true; } /* }}} */ - + function getGroups() { /* {{{ */ - GLOBAL $db; - - 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(); - foreach ($resArr as $row) { - $group = new LetoDMS_Group($row["id"], $row["name"], $row["comment"]); - array_push($this->_groups, $group); - } - } - return $this->_groups; + $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(); + foreach ($resArr as $row) { + $group = new LetoDMS_Group($row["id"], $row["name"], $row["comment"]); + array_push($this->_groups, $group); + } + } + return $this->_groups; } /* }}} */ - + /** * Checks if user is member of a given group * - * @param object $group + * @param object $group * @return boolean true if user is member of the given group otherwise false */ function isMemberOfGroup($group) { /* {{{ */ - return $group->isMember($this); + return $group->isMember($this); } /* }}} */ /** @@ -372,244 +365,226 @@ class LetoDMS_User { * @return boolean true if user has a picture of itself */ function hasImage() { /* {{{ */ - if (!isset($this->_hasImage)) - { - GLOBAL $db; - - $queryStr = "SELECT COUNT(*) AS num FROM tblUserImages WHERE userID = " . $this->_id; - $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && $resArr == false) - return false; - - if ($resArr[0]["num"] == 0) $this->_hasImage = false; - else $this->_hasImage = true; - } - - return $this->_hasImage; + if (!isset($this->_hasImage)) { + $db = $this->_dms->getDB(); + + $queryStr = "SELECT COUNT(*) AS num FROM tblUserImages WHERE userID = " . $this->_id; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + + if ($resArr[0]["num"] == 0) $this->_hasImage = false; + else $this->_hasImage = true; + } + + return $this->_hasImage; } /* }}} */ - - /* FIXME: This function should not be a method of the class but rather - * implemented in the calling application - */ - function getImageURL() { /* {{{ */ - GLOBAL $settings; - -// if (!$this->hasImage()) -// return false; - return $settings->_httpRoot . "out/out.UserImage.php?userid=" . $this->_id; + + 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()) + $queryStr = "UPDATE tblUserImages SET image = '".base64_encode($content)."', mimeType = '". $mimeType."' WHERE userID = " . $this->_id; + else + $queryStr = "INSERT INTO tblUserImages (userID, image, mimeType) VALUES (" . $this->_id . ", '".base64_encode($content)."', '".$mimeType."')"; + if (!$db->getResult($queryStr)) + return false; + + $this->_hasImage = true; + return true; } /* }}} */ - - function setImage($tmpfile, $mimeType) - { - GLOBAL $db; - - $fp = fopen($tmpfile, "rb"); - if (!$fp) return false; - $content = fread($fp, filesize($tmpfile)); - fclose($fp); - - if ($this->hasImage()) - $queryStr = "UPDATE tblUserImages SET image = '".base64_encode($content)."', mimeType = '". $mimeType."' WHERE userID = " . $this->_id; - else - $queryStr = "INSERT INTO tblUserImages (userID, image, mimeType) VALUES (" . $this->_id . ", '".base64_encode($content)."', '".$mimeType."')"; - if (!$db->getResult($queryStr)) - return false; - - $this->_hasImage = true; - return true; - } - - function getReviewStatus($documentID=null, $version=null) { - GLOBAL $db; - - if (!$db->createTemporaryTable("ttreviewid")) { - return false; - } - - $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`) ". - "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ". - "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ". - ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". $documentID ."' "). - ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". $version ."' "). - "AND `tblDocumentReviewers`.`type`='0' ". - "AND `tblDocumentReviewers`.`required`='". $this->_id ."' "; - $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && $resArr == false) - return false; - if (count($resArr)>0) { - foreach ($resArr as $res) - $status["indstatus"][] = $res; - } - - // 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` ". - "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ". - "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ". - ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". $documentID ."' "). - ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". $version ."' "). - "AND `tblDocumentReviewers`.`type`='1' ". - "AND `tblGroupMembers`.`userID`='". $this->_id ."'"; - $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && $resArr == false) - return false; - if (count($resArr)>0) { - foreach ($resArr as $res) - $status["grpstatus"][] = $res; - } - return $status; - } - - function getApprovalStatus($documentID=null, $version=null) { - GLOBAL $db; - - if (!$db->createTemporaryTable("ttapproveid")) { - return false; - } - - $status = array("indstatus"=>array(), "grpstatus"=>array()); - - // See if the user is assigned as an individual approver. - $queryStr = "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ". - "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ". - "`tblDocumentApproveLog`.`userID` ". - "FROM `tblDocumentApprovers` ". - "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ". - "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ". - "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ". - ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". $documentID ."' "). - ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". $version ."' "). - "AND `tblDocumentApprovers`.`type`='0' ". - "AND `tblDocumentApprovers`.`required`='". $this->_id ."' "; - $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && $resArr == false) - return false; - if (count($resArr)>0) { - foreach ($resArr as $res) - $status["indstatus"][] = $res; - } - - // See if the user is the member of a group that has been assigned to - // approve the document version. - $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` ". - "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ". - "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ". - ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". $documentID ."' "). - ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". $version ."' "). - "AND `tblDocumentApprovers`.`type`='1' ". - "AND `tblGroupMembers`.`userID`='". $this->_id ."'"; - $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && $resArr == false) - return false; - if (count($resArr)>0) { - foreach ($resArr as $res) - $status["grpstatus"][] = $res; - } - return $status; - } - - function getMandatoryReviewers() - { - GLOBAL $db; - - $queryStr = "SELECT * FROM tblMandatoryReviewers WHERE userID = " . $this->_id; - $resArr = $db->getResultArray($queryStr); + + function getReviewStatus($documentID=null, $version=null) { /* {{{ */ + $db = $this->_dms->getDB(); + + if (!$db->createTemporaryTable("ttreviewid")) { + return false; + } + + $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`) ". + "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ". + "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ". + ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". $documentID ."' "). + ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". $version ."' "). + "AND `tblDocumentReviewers`.`type`='0' ". + "AND `tblDocumentReviewers`.`required`='". $this->_id ."' "; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + if (count($resArr)>0) { + foreach ($resArr as $res) + $status["indstatus"][] = $res; + } + + // 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` ". + "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ". + "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ". + ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". $documentID ."' "). + ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". $version ."' "). + "AND `tblDocumentReviewers`.`type`='1' ". + "AND `tblGroupMembers`.`userID`='". $this->_id ."'"; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + if (count($resArr)>0) { + foreach ($resArr as $res) + $status["grpstatus"][] = $res; + } + return $status; + } /* }}} */ + + function getApprovalStatus($documentID=null, $version=null) { /* {{{ */ + $db = $this->_dms->getDB(); + + if (!$db->createTemporaryTable("ttapproveid")) { + return false; + } + + $status = array("indstatus"=>array(), "grpstatus"=>array()); + + // See if the user is assigned as an individual approver. + $queryStr = "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ". + "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ". + "`tblDocumentApproveLog`.`userID` ". + "FROM `tblDocumentApprovers` ". + "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ". + "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ". + "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ". + ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". $documentID ."' "). + ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". $version ."' "). + "AND `tblDocumentApprovers`.`type`='0' ". + "AND `tblDocumentApprovers`.`required`='". $this->_id ."' "; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + if (count($resArr)>0) { + foreach ($resArr as $res) + $status["indstatus"][] = $res; + } + + // See if the user is the member of a group that has been assigned to + // approve the document version. + $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` ". + "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ". + "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ". + ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". $documentID ."' "). + ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". $version ."' "). + "AND `tblDocumentApprovers`.`type`='1' ". + "AND `tblGroupMembers`.`userID`='". $this->_id ."'"; + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + if (count($resArr)>0) { + foreach ($resArr as $res) + $status["grpstatus"][] = $res; + } + return $status; + } /* }}} */ + + function getMandatoryReviewers() { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "SELECT * FROM tblMandatoryReviewers WHERE userID = " . $this->_id; + $resArr = $db->getResultArray($queryStr); return $resArr; - } - - function getMandatoryApprovers() - { - GLOBAL $db; - - $queryStr = "SELECT * FROM tblMandatoryApprovers WHERE userID = " . $this->_id; - $resArr = $db->getResultArray($queryStr); + } /* }}} */ + + function getMandatoryApprovers() { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "SELECT * FROM tblMandatoryApprovers WHERE userID = " . $this->_id; + $resArr = $db->getResultArray($queryStr); return $resArr; - } - - function setMandatoryReviewer($id, $isgroup=false) - { - GLOBAL $db; - + } /* }}} */ + + function setMandatoryReviewer($id, $isgroup=false) { /* {{{ */ + $db = $this->_dms->getDB(); + if ($isgroup){ - + $queryStr = "SELECT * FROM tblMandatoryReviewers WHERE userID = " . $this->_id . " AND reviewerGroupID = " . $id; - $resArr = $db->getResultArray($queryStr); + $resArr = $db->getResultArray($queryStr); if (count($resArr)!=0) return; - - $queryStr = "INSERT INTO tblMandatoryReviewers (userID, reviewerGroupID) VALUES (" . $this->_id . ", " . $id .")"; - $resArr = $db->getResult($queryStr); - if (is_bool($resArr) && !$resArr) return false; - }else{ - - $queryStr = "SELECT * FROM tblMandatoryReviewers WHERE userID = " . $this->_id . " AND reviewerUserID = " . $id; - $resArr = $db->getResultArray($queryStr); - if (count($resArr)!=0) return; - - $queryStr = "INSERT INTO tblMandatoryReviewers (userID, reviewerUserID) VALUES (" . $this->_id . ", " . $id .")"; - $resArr = $db->getResult($queryStr); + $queryStr = "INSERT INTO tblMandatoryReviewers (userID, reviewerGroupID) VALUES (" . $this->_id . ", " . $id .")"; + $resArr = $db->getResult($queryStr); if (is_bool($resArr) && !$resArr) return false; - } - - } - - function setMandatoryApprover($id, $isgroup=false) - { - GLOBAL $db; - - if ($isgroup){ - - $queryStr = "SELECT * FROM tblMandatoryApprovers WHERE userID = " . $this->_id . " AND approverGroupID = " . $id; - $resArr = $db->getResultArray($queryStr); - if (count($resArr)!=0) return; - - $queryStr = "INSERT INTO tblMandatoryApprovers (userID, approverGroupID) VALUES (" . $this->_id . ", " . $id .")"; - $resArr = $db->getResult($queryStr); - if (is_bool($resArr) && !$resArr) return false; }else{ - - $queryStr = "SELECT * FROM tblMandatoryApprovers WHERE userID = " . $this->_id . " AND approverUserID = " . $id; - $resArr = $db->getResultArray($queryStr); + + $queryStr = "SELECT * FROM tblMandatoryReviewers WHERE userID = " . $this->_id . " AND reviewerUserID = " . $id; + $resArr = $db->getResultArray($queryStr); if (count($resArr)!=0) return; - - $queryStr = "INSERT INTO tblMandatoryApprovers (userID, approverUserID) VALUES (" . $this->_id . ", " . $id .")"; - $resArr = $db->getResult($queryStr); + + $queryStr = "INSERT INTO tblMandatoryReviewers (userID, reviewerUserID) VALUES (" . $this->_id . ", " . $id .")"; + $resArr = $db->getResult($queryStr); if (is_bool($resArr) && !$resArr) return false; } - } - - function delMandatoryReviewers() - { - GLOBAL $db; - $queryStr = "DELETE FROM tblMandatoryReviewers WHERE userID = " . $this->_id; + + } /* }}} */ + + function setMandatoryApprover($id, $isgroup=false) { /* {{{ */ + $db = $this->_dms->getDB(); + + if ($isgroup){ + + $queryStr = "SELECT * FROM tblMandatoryApprovers WHERE userID = " . $this->_id . " AND approverGroupID = " . $id; + $resArr = $db->getResultArray($queryStr); + if (count($resArr)!=0) return; + + $queryStr = "INSERT INTO tblMandatoryApprovers (userID, approverGroupID) VALUES (" . $this->_id . ", " . $id .")"; + $resArr = $db->getResult($queryStr); + if (is_bool($resArr) && !$resArr) return false; + + }else{ + + $queryStr = "SELECT * FROM tblMandatoryApprovers WHERE userID = " . $this->_id . " AND approverUserID = " . $id; + $resArr = $db->getResultArray($queryStr); + if (count($resArr)!=0) return; + + $queryStr = "INSERT INTO tblMandatoryApprovers (userID, approverUserID) VALUES (" . $this->_id . ", " . $id .")"; + $resArr = $db->getResult($queryStr); + if (is_bool($resArr) && !$resArr) return false; + } + } /* }}} */ + + function delMandatoryReviewers() { /* {{{ */ + $db = $this->_dms->getDB(); + $queryStr = "DELETE FROM tblMandatoryReviewers WHERE userID = " . $this->_id; if (!$db->getResult($queryStr)) return false; - } - - function delMandatoryApprovers() - { - GLOBAL $db; - $queryStr = "DELETE FROM tblMandatoryApprovers WHERE userID = " . $this->_id; + } /* }}} */ + + function delMandatoryApprovers() { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "DELETE FROM tblMandatoryApprovers WHERE userID = " . $this->_id; if (!$db->getResult($queryStr)) return false; - } -} -?> + } /* }}} */ +} +?>