From d55346ba0f7ba58e3f1928cc0ae1b701161f844f Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 11 Jun 2015 21:28:04 +0200 Subject: [PATCH] manage file uploaded with review or approval --- SeedDMS_Core/Core/inc.ClassDocument.php | 74 +++++++++++++++++++++---- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index f84d5061b..3724e40d8 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -1475,6 +1475,17 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $stList = ""; foreach ($status as $st) { $stList .= (strlen($stList)==0 ? "" : ", "). "'".$st["reviewID"]."'"; + $queryStr = "SELECT * FROM tblDocumentReviewLog WHERE reviewID = " . $st['reviewID']; + $resArr = $db->getResultArray($queryStr); + if ((is_bool($resArr) && !$resArr)) { + $db->rollbackTransaction(); + return false; + } + foreach($resArr as $res) { + $file = $this->_dms->contentDir . $this->getDir().'r'.$res['reviewLogID']; + if(file_exists($file)) + SeedDMS_Core_File::removeFile($file); + } if ($st["status"]==0 && !in_array($st["required"], $emailList)) { $emailList[] = $st["required"]; } @@ -1496,10 +1507,22 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $stList = ""; foreach ($status as $st) { $stList .= (strlen($stList)==0 ? "" : ", "). "'".$st["approveID"]."'"; + $queryStr = "SELECT * FROM tblDocumentApproveLog WHERE approveID = " . $st['approveID']; + $resArr = $db->getResultArray($queryStr); + if ((is_bool($resArr) && !$resArr)) { + $db->rollbackTransaction(); + return false; + } + foreach($resArr as $res) { + $file = $this->_dms->contentDir . $this->getDir().'a'.$res['approveLogID']; + if(file_exists($file)) + SeedDMS_Core_File::removeFile($file); + } if ($st["status"]==0 && !in_array($st["required"], $emailList)) { $emailList[] = $st["required"]; } } + if (strlen($stList)>0) { $queryStr = "DELETE FROM `tblDocumentApproveLog` WHERE `tblDocumentApproveLog`.`approveID` IN (".$stList.")"; if (!$db->getResult($queryStr)) { @@ -2522,6 +2545,13 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ unset($this->_reviewStatus); return false; } + foreach($res as &$t) { + $filename = $this->_dms->contentDir . $this->_document->getDir().'r'.$t['reviewLogID']; + if(file_exists($filename)) + $t['file'] = $filename; + else + $t['file'] = ''; + } $this->_reviewStatus = array_merge($this->_reviewStatus, $res); } } @@ -2557,7 +2587,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ if($recs) { foreach($recs as $rec) { $queryStr= - "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ". + "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`approveLogId`, `tblDocumentApproveLog`.`status`, ". "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ". "`tblDocumentApproveLog`.`userID`, `tblUsers`.`fullName`, `tblGroups`.`name` AS `groupName` ". "FROM `tblDocumentApprovers` ". @@ -2572,6 +2602,13 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ unset($this->_approvalStatus); return false; } + foreach($res as &$t) { + $filename = $this->_dms->contentDir . $this->_document->getDir().'a'.$t['approveLogId']; + if(file_exists($filename)) + $t['file'] = $filename; + else + $t['file'] = ''; + } $this->_approvalStatus = array_merge($this->_approvalStatus, $res); } } @@ -2723,7 +2760,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ * @param string $comment comment for review * @return integer new review log id */ - function setReviewByInd($user, $requestUser, $status, $comment) { /* {{{ */ + function setReviewByInd($user, $requestUser, $status, $comment, $file='') { /* {{{ */ $db = $this->_document->_dms->getDB(); // Check to see if the user can be removed from the review list. @@ -2753,10 +2790,12 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ $res=$db->getResult($queryStr); if (is_bool($res) && !$res) return -1; - else { - $reviewLogID = $db->getInsertID(); - return $reviewLogID; + + $reviewLogID = $db->getInsertID(); + if($file) { + SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'r' . $reviewLogID); } + return $reviewLogID; } /* }}} */ /** @@ -2773,7 +2812,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ * @param string $comment comment for review * @return integer new review log id */ - function setReviewByGrp($group, $requestUser, $status, $comment) { /* {{{ */ + function setReviewByGrp($group, $requestUser, $status, $comment, $file='') { /* {{{ */ $db = $this->_document->_dms->getDB(); // Check to see if the user can be removed from the review list. @@ -2805,6 +2844,9 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ return -1; else { $reviewLogID = $db->getInsertID(); + if($file) { + SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'r' . $reviewLogID); + } return $reviewLogID; } } /* }}} */ @@ -2953,7 +2995,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ * @param string $comment approval comment * @return integer 0 on success, < 0 in case of an error */ - function setApprovalByInd($user, $requestUser, $status, $comment) { /* {{{ */ + function setApprovalByInd($user, $requestUser, $status, $comment, $file='') { /* {{{ */ $db = $this->_document->_dms->getDB(); // Check to see if the user can be removed from the approval list. @@ -2983,8 +3025,12 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ $res=$db->getResult($queryStr); if (is_bool($res) && !$res) return -1; - else - return 0; + + $approveLogID = $db->getInsertID(); + if($file) { + SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'a' . $approveLogID); + } + return $approveLogId; } /* }}} */ /** @@ -2993,7 +3039,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ * {link SeedDMS_Core_DocumentContent::setApprovalByInd} but does it for * group instead of a user */ - function setApprovalByGrp($group, $requestUser, $status, $comment) { /* {{{ */ + function setApprovalByGrp($group, $requestUser, $status, $comment, $file='') { /* {{{ */ $db = $this->_document->_dms->getDB(); // Check to see if the user can be removed from the approval list. @@ -3023,8 +3069,12 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ $res=$db->getResult($queryStr); if (is_bool($res) && !$res) return -1; - else - return 0; + + $approveLogID = $db->getInsertID(); + if($file) { + SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'a' . $approveLogID); + } + return $approveLogId; } /* }}} */ function delIndReviewer($user, $requestUser) { /* {{{ */