From 6cb5dec1a9d8fd9c1756f837e8834bcf4e908818 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 22 Nov 2016 17:58:28 +0100 Subject: [PATCH] fix search for documents with reception acknowledgement --- SeedDMS_Core/Core/inc.ClassDMS.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 23e5f37ea..4834542f1 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -1422,9 +1422,14 @@ class SeedDMS_Core_DMS { // Construct the SQL query that will be used to search the database. // - if (!$this->db->createTemporaryTable("ttcontentid") || !$this->db->createTemporaryTable("ttstatid") || !$this->db->createTemporaryTable("ttreceiptid")) { + if (!$this->db->createTemporaryTable("ttcontentid") || !$this->db->createTemporaryTable("ttstatid")) { return false; } + if($reception) { + if (!$this->db->createTemporaryTable("ttreceiptid")) { + return false; + } + } $searchQuery = "FROM `tblDocumentContent` ". "LEFT JOIN `tblDocuments` ON `tblDocuments`.`id` = `tblDocumentContent`.`document` ". @@ -1470,8 +1475,26 @@ class SeedDMS_Core_DMS { $searchQuery .= " AND `tblDocumentStatusLog`.`status` IN (".implode(',', $status).")"; } - if($reception) - $searchQuery .= " AND `tblDocumentReceiptLog`.`status` IN (".implode(',', $reception).")"; + if($reception) { + $searchReception = array(); + /* still waiting for users/groups to acknownledge reception */ + if(in_array("missingaction", $reception)) + $searchReception[] = "b.`status` IN (0)"; + /* document has not been acknowledeged by at least one user/group */ + if(in_array("hasrejection", $reception)) + $searchReception[] = "b.`status` IN (-1)"; + /* document has been acknowledeged by at least one user/group */ + if(in_array("hasacknowledge", $reception)) + $searchReception[] = "b.`status` IN (1)"; + /* document has been acknowledeged by all users/groups !!! not working !!! */ + if(in_array("completeacknowledge", $reception)) + $searchReception[] = "b.`status` NOT IN (-1, 0)"; + if($searchReception) { + $searchQuery .= " AND EXISTS (SELECT NULL FROM `tblDocumentRecipients` a LEFT JOIN `tblDocumentReceiptLog` b ON a.`receiptID`=b.`receiptID` LEFT JOIN `ttreceiptid` c ON c.`maxLogID` = b.`receiptLogID` WHERE "; + $searchQuery .= "c.`maxLogID`=b.`receiptLogID` AND `tblDocuments`.`id` = a.`documentID` "; + $searchQuery .= "AND (".implode(' OR ', $searchReception)."))"; + } + } if($searchKey || $searchOwner || $searchCategories || $searchCreateDate || $searchExpirationDate || $searchAttributes || $status || $reception) { // Count the number of rows that the search will produce.