From b8763822d0c1936478ca60e9f376b4b2fdebeb24 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 28 Sep 2021 16:19:25 +0200 Subject: [PATCH 1/2] init possible values of attribute in getStatistic() --- SeedDMS_Core/Core/inc.ClassAttribute.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SeedDMS_Core/Core/inc.ClassAttribute.php b/SeedDMS_Core/Core/inc.ClassAttribute.php index fb97e3b93..a51d6c81f 100644 --- a/SeedDMS_Core/Core/inc.ClassAttribute.php +++ b/SeedDMS_Core/Core/inc.ClassAttribute.php @@ -936,6 +936,11 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ } } } + $valueset = $this->getValueSetAsArray(); + $possiblevalues = array(); + foreach($valueset as $value) { + $possiblevalues[md5($value)] = array('value'=>$value, 'c'=>0); + } $queryStr = "SELECT count(*) c, `value` FROM `tblDocumentAttributes` WHERE `attrdef`=".$this->_id." GROUP BY `value` ORDER BY c DESC"; $resArr = $db->getResultArray($queryStr); if($resArr) { @@ -1052,7 +1057,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ * @param integer $limit limit number of documents/folders * @return array array containing list of documents and folders */ - public function getObjects($attrvalue, $limit='') { /* {{{ */ + public function getObjects($attrvalue, $limit=0) { /* {{{ */ $db = $this->_dms->getDB(); $result = array('docs'=>array(), 'folders'=>array(), 'contents'=>array()); From 007e3faa0a029e0dd46710ef925255ee2262d6c4 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 28 Sep 2021 16:20:33 +0200 Subject: [PATCH 2/2] various minor changes ported back from SeedDMS 6 --- SeedDMS_Core/Core/inc.ClassDMS.php | 28 ++++++++++++++----------- SeedDMS_Core/Core/inc.ClassDocument.php | 28 ++++++++++++++++++++----- SeedDMS_Core/Core/inc.ClassFolder.php | 10 ++++----- SeedDMS_Core/Core/inc.DBAccessPDO.php | 10 ++++++--- 4 files changed, 50 insertions(+), 26 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 8637f4b82..96ae4b0c7 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -347,9 +347,11 @@ class SeedDMS_Core_DMS { */ static function filterDocumentFiles($user, $files) { /* {{{ */ $tmp = array(); - foreach ($files as $file) - if ($file->isPublic() || ($file->getUser()->getID() == $user->getID()) || $user->isAdmin() || ($file->getDocument()->getOwner()->getID() == $user->getID())) - array_push($tmp, $file); + if($files) { + foreach ($files as $file) + if ($file->isPublic() || ($file->getUser()->getID() == $user->getID()) || $user->isAdmin() || ($file->getDocument()->getOwner()->getID() == $user->getID())) + array_push($tmp, $file); + } return $tmp; } /* }}} */ @@ -374,6 +376,7 @@ class SeedDMS_Core_DMS { $this->forceRename = false; $this->checkWithinRootDir = false; $this->noReadForStatus = array(); + $this->user = null; $this->classnames = array(); $this->classnames['folder'] = 'SeedDMS_Core_Folder'; $this->classnames['document'] = 'SeedDMS_Core_Document'; @@ -589,8 +592,9 @@ class SeedDMS_Core_DMS { /** * Set the logged in user * - * If user authentication was done externally, this function can - * be used to tell the dms who is currently logged in. + * This method tells SeeDMS_Core_DMS the currently logged in user. It must be + * called right after instanciating the class, because some methods in + * SeedDMS_Core_Document() require the currently logged in user. * * @param object $user this muss not be empty and an instance of SeedDMS_Core_User * @return bool|object returns the old user object or null on success, otherwise false @@ -613,8 +617,7 @@ class SeedDMS_Core_DMS { /** * Get the logged in user * - * If user authentication was done externally, this function can - * be used to tell the dms who is currently logged in. + * Returns the currently logged in user, as set by setUser() * * @return SeedDMS_Core_User $user * @@ -685,7 +688,7 @@ class SeedDMS_Core_DMS { if (!$db->createTemporaryTable("ttstatid") || !$db->createTemporaryTable("ttcontentid")) { return false; } - + $tsnow = mktime(0, 0, 0); /* Start of today */ if(is_int($date)) { $ts = $tsnow + $date * 86400; @@ -1041,7 +1044,7 @@ class SeedDMS_Core_DMS { $queryStr .= " AND `tblDocumentReviewLog`.`status` = 0 "; if ($orderby=='e') $queryStr .= "ORDER BY `expires`"; else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`"; - else if ($orderby=='s') $queryStr .= "ORDER BY `status`"; + else if ($orderby=='s') $queryStr .= "ORDER BY `tblDocumentStatusLog`.`status`"; else $queryStr .= "ORDER BY `name`"; $queryStr .= " ".$orderdir; } else { @@ -1123,7 +1126,7 @@ class SeedDMS_Core_DMS { $queryStr .= " AND `tblDocumentApproveLog`.`status` = 0 "; if ($orderby=='e') $queryStr .= "ORDER BY `expires`"; else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`"; - else if ($orderby=='s') $queryStr .= "ORDER BY `status`"; + else if ($orderby=='s') $queryStr .= "ORDER BY `tblDocumentStatusLog`.`status`"; else $queryStr .= "ORDER BY `name`"; $queryStr .= " ".$orderdir; } else { @@ -1197,6 +1200,7 @@ class SeedDMS_Core_DMS { $queryStr .= "OR `tblWorkflowTransitionGroups`.`groupid` IN (".implode(',', $groups).")"; $queryStr .= ") "; } + $queryStr .= "AND `tblDocumentStatusLog`.`status` = ".S_IN_WORKFLOW." "; // echo 'SELECT '.$selectStr." ".$queryStr; if ($orderby=='e') $queryStr .= "ORDER BY `expires`"; else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`"; @@ -1264,8 +1268,8 @@ class SeedDMS_Core_DMS { $orderdir = 'DESC'; else $orderdir = 'ASC'; - $queryStr .= "AND `tblDocuments`.`owner` = '".$user->getID()."' ". - "AND `tblDocumentStatusLog`.`status` IN (".S_REJECTED.") "; + $queryStr .= "AND `tblDocuments`.`owner` = '".$user->getID()."' "; + $queryStr .= "AND `tblDocumentStatusLog`.`status` IN (".S_REJECTED.") "; //$queryStr .= "ORDER BY `statusDate` DESC"; if ($orderby=='e') $queryStr .= "ORDER BY `expires`"; else if ($orderby=='u') $queryStr .= "ORDER BY `statusDate`"; diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index 3d7df7a0d..0dc0a994a 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -58,6 +58,12 @@ define("S_OBSOLETE", -2); */ define("S_EXPIRED", -3); +/* + * Lowest and highest status that may be set + */ +define("S_LOWEST_STATUS", -3); +define("S_HIGHEST_STATUS", 3); + /** * The different states a workflow log can be in. This is used in * all tables tblDocumentXXXLog @@ -2939,7 +2945,8 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ * * This method may not be called after a negative approval or review to * recalculated the status, because - * it doesn't take a defeating approval or review into account. It will + * it doesn't take a defeating approval or review into account. This method + * does not set the status to S_REJECTED! It will * just check for a pending workflow, approval or review and set the status * accordingly, e.g. after the list of reviewers or appovers has been * modified. If there is not pending workflow, approval or review the @@ -2966,6 +2973,8 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ /* $pendingReview will be set when there are still open reviews */ $pendingReview=false; + /* $hasReview will be set if there is at least one positiv review */ + $hasReview=false; unset($this->_reviewStatus); // force to be reloaded from DB $reviewStatus=$this->getReviewStatus(); if (is_array($reviewStatus) && count($reviewStatus)>0) { @@ -2973,12 +2982,16 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ if ($r["status"]==0){ $pendingReview=true; break; + } elseif($r["status"]==1){ + $hasReview=true; } } } /* $pendingApproval will be set when there are still open approvals */ $pendingApproval=false; + /* $hasApproval will be set if there is at least one positiv review */ + $hasApproval=false; unset($this->_approvalStatus); // force to be reloaded from DB $approvalStatus=$this->getApprovalStatus(); if (is_array($approvalStatus) && count($approvalStatus)>0) { @@ -2986,6 +2999,8 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ if ($a["status"]==0){ $pendingApproval=true; break; + } elseif($a["status"]==1){ + $hasApproval=true; } } } @@ -3233,7 +3248,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ // If the supplied value lies outside of the accepted range, return an // error. - if ($status < -3 || $status > 3) { + if ($status < S_LOWEST_STATUS || $status > S_HIGHEST_STATUS) { return false; } @@ -4524,6 +4539,9 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ $db = $this->_document->getDMS()->getDB(); $this->getWorkflow(); + if($this->_workflow) + return false; + if($workflow && is_object($workflow)) { $db->startTransaction(); $initstate = $workflow->getInitState(); @@ -4540,14 +4558,14 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ $db->commitTransaction(); return true; } - return true; + return false; } /* }}} */ /** * Get workflow assigned to the document content * * The method returns the last workflow if one was assigned. - * If a the document version is in a sub workflow, it will have + * If the document version is in a sub workflow, it will have * a never date and therefore will be found first. * * @return object/boolean an object of class SeedDMS_Core_Workflow @@ -4601,7 +4619,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ $db->rollbackTransaction(); return false; } - $queryStr = "INSERT INTO `tblWorkflowLog` (`document`, `version`, `workflow`, `transition`, `comment`, `date`, `userid`) ". + $queryStr = "INSERT INTO `tblWorkflowLog` (`document`, `version`, `workflow`, `transition`, `comment`, `date`, `userid`) ". "VALUES ('".$this->_document->getID() ."', '".(int) $this->_version."', '".(int) $log['workflow']->getID()."', '".(int) $log['transition']->getID()."', ".$db->qstr($log['comment']) .", ".$db->qstr($log['date']).", ".$log['user']->getID().")"; if (!$db->getResult($queryStr)) { $db->rollbackTransaction(); diff --git a/SeedDMS_Core/Core/inc.ClassFolder.php b/SeedDMS_Core/Core/inc.ClassFolder.php index 1be3964ca..c7863347d 100644 --- a/SeedDMS_Core/Core/inc.ClassFolder.php +++ b/SeedDMS_Core/Core/inc.ClassFolder.php @@ -1051,9 +1051,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { $document = $this->_dms->getDocument($db->getInsertID('tblDocuments')); -// if ($version_comment!="") - $res = $document->addContent($version_comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers, $reqversion, $version_attributes, $workflow); -// else $res = $document->addContent($comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers,$reqversion, $version_attributes, $workflow); + $res = $document->addContent($version_comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers, $reqversion, $version_attributes, $workflow); if (is_bool($res) && !$res) { $db->rollbackTransaction(); @@ -1296,9 +1294,9 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { * has no access list the returned array contains the two elements * 'users' and 'groups' which are than empty. The methode returns false * if the function fails. - * - * @param int $mode access mode (defaults to M_ANY) - * @param int|string $op operation (defaults to O_EQ) + * + * @param integer $mode access mode (defaults to M_ANY) + * @param integer $op operation (defaults to O_EQ) * @return bool|SeedDMS_Core_GroupAccess|SeedDMS_Core_UserAccess */ function getAccessList($mode = M_ANY, $op = O_EQ) { /* {{{ */ diff --git a/SeedDMS_Core/Core/inc.DBAccessPDO.php b/SeedDMS_Core/Core/inc.DBAccessPDO.php index f7d09680b..5c0ade558 100644 --- a/SeedDMS_Core/Core/inc.DBAccessPDO.php +++ b/SeedDMS_Core/Core/inc.DBAccessPDO.php @@ -232,7 +232,7 @@ class SeedDMS_Core_DatabaseAccess { $this->_ttapproveid = false; $this->_ttstatid = false; $this->_ttcontentid = false; - $this->_useviews = false; + $this->_useviews = false; // turn off views, because they are much slower then temp. tables $this->_debug = false; } /* }}} */ @@ -401,8 +401,10 @@ class SeedDMS_Core_DatabaseAccess { } $res = $this->_conn->query($queryStr); if ($res === false) { - if($this->_debug) + if($this->_debug) { echo "error: ".$queryStr."
"; + print_r($this->_conn->errorInfo()); + } return false; } $resArr = $res->fetchAll(PDO::FETCH_ASSOC); @@ -429,8 +431,10 @@ class SeedDMS_Core_DatabaseAccess { } $res = $this->_conn->exec($queryStr); if($res === false) { - if($this->_debug) + if($this->_debug) { echo "error: ".$queryStr."
"; + print_r($this->_conn->errorInfo()); + } return false; } else return true;