diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 4c5ba137f..9b2f892a4 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -201,7 +201,7 @@ class SeedDMS_Core_DMS { } /* }}} */ /** - * Checks if a list of objects contains a single object + * Checks if a list of objects contains a single object * * This function is only applicable on list containing objects which have * a method getID() because it is used to check if two objects are equal. @@ -728,12 +728,14 @@ class SeedDMS_Core_DMS { * @param string $listtype type of document list, can be 'AppRevByMe', * 'AppRevOwner', 'ReceiptByMe', 'ReviseByMe', 'LockedByMe', 'MyDocs' * @param object $param1 user - * @param string $param2 sort list if listtype='MyDocs', set to true + * @param string $param2 set to true * if 'AppRevByMe', 'ReviseByMe', 'ReceiptByMe' shall return even documents * І have already taken care of. + * @param string $param3 sort list by this field + * @param string $param4 order direction * @return array list of documents */ - function getDocumentList($listtype, $param1=null, $param2='', $param3='') { /* {{{ */ + function getDocumentList($listtype, $param1=null, $param2=false, $param3='', $param4='') { /* {{{ */ /* The following query will get all documents and lots of additional * information. It requires the two temporary tables ttcontentid and * ttstatid. @@ -741,6 +743,9 @@ class SeedDMS_Core_DMS { if (!$this->db->createTemporaryTable("ttstatid") || !$this->db->createTemporaryTable("ttcontentid")) { return false; } + /* The following statement retrieves the status of the last version of all + * documents. It must be restricted by further where clauses. + */ $queryStr = "SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser`, ". "`tblDocumentContent`.`version`, `tblDocumentStatus`.*, `tblDocumentStatusLog`.`status`, ". "`tblDocumentStatusLog`.`comment` AS `statusComment`, `tblDocumentStatusLog`.`date` as `statusDate`, ". @@ -758,12 +763,12 @@ class SeedDMS_Core_DMS { "AND `ttcontentid`.`maxVersion` = `tblDocumentContent`.`version` "; switch($listtype) { - case 'AppRevByMe': // Documents I have to review/approve + case 'AppRevByMe': // Documents I have to review/approve {{{ $user = $param1; // Get document list for the current user. $reviewStatus = $user->getReviewStatus(); $approvalStatus = $user->getApprovalStatus(); - + // Create a comma separated list of all the documentIDs whose information is // required. // Take only those documents into account which hasn't be touched by the user @@ -792,7 +797,7 @@ class SeedDMS_Core_DMS { foreach ($dList as $d) { $docCSV .= (strlen($docCSV)==0 ? "" : ", ")."'".$d."'"; } - + if (strlen($docCSV)>0) { $queryStr .= "AND `tblDocumentStatusLog`.`status` IN (".S_DRAFT_REV.", ".S_DRAFT_APP.", ".S_EXPIRED.") ". "AND `tblDocuments`.`id` IN (" . $docCSV . ") ". @@ -800,14 +805,82 @@ class SeedDMS_Core_DMS { } else { $queryStr = ''; } - break; - case 'ReceiptByMe': // Documents I have to receipt + break; // }}} + case 'ReviewByMe': // Documents I have to review {{{ + $user = $param1; + // Get document list for the current user. + $reviewStatus = $user->getReviewStatus(); + + // Create a comma separated list of all the documentIDs whose information is + // required. + // Take only those documents into account which hasn't be touched by the user + // ($st["status"]==0) + $dList = array(); + foreach ($reviewStatus["indstatus"] as $st) { + if (($st["status"]==0 || $param2) && !in_array($st["documentID"], $dList)) { + $dList[] = $st["documentID"]; + } + } + foreach ($reviewStatus["grpstatus"] as $st) { + if (($st["status"]==0 || $param2) && !in_array($st["documentID"], $dList)) { + $dList[] = $st["documentID"]; + } + } + $docCSV = ""; + foreach ($dList as $d) { + $docCSV .= (strlen($docCSV)==0 ? "" : ", ")."'".$d."'"; + } + + if (strlen($docCSV)>0) { + $queryStr .= "AND `tblDocumentStatusLog`.`status` IN (".S_DRAFT_REV.", ".S_EXPIRED.") ". + "AND `tblDocuments`.`id` IN (" . $docCSV . ") ". + "ORDER BY `statusDate` DESC"; + } else { + $queryStr = ''; + } + break; // }}} + case 'ApproveByMe': // Documents I have to approve {{{ + $user = $param1; + // Get document list for the current user. + $approvalStatus = $user->getApprovalStatus(); + + // Create a comma separated list of all the documentIDs whose information is + // required. + // Take only those documents into account which hasn't be touched by the user + // ($st["status"]==0) + $dList = array(); + foreach ($approvalStatus["indstatus"] as $st) { + if (($st["status"]==0 || $param2) && !in_array($st["documentID"], $dList)) { + $dList[] = $st["documentID"]; + } + } + foreach ($approvalStatus["grpstatus"] as $st) { + if (($st["status"]==0 || $param2) && !in_array($st["documentID"], $dList)) { + $dList[] = $st["documentID"]; + } + } + $docCSV = ""; + foreach ($dList as $d) { + $docCSV .= (strlen($docCSV)==0 ? "" : ", ")."'".$d."'"; + } + + if (strlen($docCSV)>0) { + $queryStr .= "AND `tblDocumentStatusLog`.`status` IN (".S_DRAFT_APP.", ".S_EXPIRED.") ". + "AND `tblDocuments`.`id` IN (" . $docCSV . ") ". + "ORDER BY `statusDate` DESC"; + } else { + $queryStr = ''; + } + break; // }}} + case 'ReceiptByMe': // Documents I have to receipt {{{ $user = $param1; // Get document list for the current user. $receiptStatus = $user->getReceiptStatus(); - + // Create a comma separated list of all the documentIDs whose information is // required. + // Take only those documents into account which hasn't be touched by the user + // ($st["status"]==0) $dList = array(); foreach ($receiptStatus["indstatus"] as $st) { if (($st["status"]==0 || $param2) && !in_array($st["documentID"], $dList)) { @@ -823,19 +896,19 @@ class SeedDMS_Core_DMS { foreach ($dList as $d) { $docCSV .= (strlen($docCSV)==0 ? "" : ", ")."'".$d."'"; } - + if (strlen($docCSV)>0) { $queryStr .= "AND `tblDocuments`.`id` IN (" . $docCSV . ") ". "ORDER BY `statusDate` DESC"; } else { $queryStr = ''; } - break; - case 'ReviseByMe': // Documents I have to receipt + break; // }}} + case 'ReviseByMe': // Documents I have to receipt {{{ $user = $param1; // Get document list for the current user. $revisionStatus = $user->getRevisionStatus(); - + // Create a comma separated list of all the documentIDs whose information is // required. $dList = array(); @@ -853,19 +926,19 @@ class SeedDMS_Core_DMS { foreach ($dList as $d) { $docCSV .= (strlen($docCSV)==0 ? "" : ", ")."'".$d."'"; } - + if (strlen($docCSV)>0) { $queryStr .= "AND `tblDocuments`.`id` IN (" . $docCSV . ") ". "ORDER BY `statusDate` DESC"; } else { $queryStr = ''; } - break; - case 'WorkflowByMe': // Documents I to trigger in Worklflow + break; // }}} + case 'WorkflowByMe': // Documents I to trigger in Worklflow {{{ $user = $param1; // Get document list for the current user. $workflowStatus = $user->getWorkflowStatus(); - + // Create a comma separated list of all the documentIDs whose information is // required. $dList = array(); @@ -883,20 +956,20 @@ class SeedDMS_Core_DMS { foreach ($dList as $d) { $docCSV .= (strlen($docCSV)==0 ? "" : ", ")."'".$d."'"; } - + if (strlen($docCSV)>0) { - $queryStr .= + $queryStr .= //"AND `tblDocumentStatusLog`.`status` IN (".S_IN_WORKFLOW.", ".S_EXPIRED.") ". "AND `tblDocuments`.`id` IN (" . $docCSV . ") ". "ORDER BY `statusDate` DESC"; } else { $queryStr = ''; } - break; - case 'AppRevOwner': // Documents waiting for review/approval I'm owning + break; // }}} + case 'AppRevOwner': // Documents waiting for review/approval I'm owning {{{ $user = $param1; - $orderby = $param2; - if($param3 == 'desc') + $orderby = $param3; + if($param4 == 'desc') $orderdir = 'DESC'; else $orderdir = 'ASC'; @@ -910,28 +983,28 @@ class SeedDMS_Core_DMS { // $queryStr .= "AND `tblDocuments`.`owner` = '".$user->getID()."' ". // "AND `tblDocumentStatusLog`.`status` IN (".S_DRAFT_REV.", ".S_DRAFT_APP.") ". // "ORDER BY `statusDate` DESC"; - break; - case 'RejectOwner': // Documents that has been rejected and I'm owning + break; // }}} + case 'RejectOwner': // Documents that has been rejected and I'm owning {{{ $user = $param1; $queryStr .= "AND `tblDocuments`.`owner` = '".$user->getID()."' ". "AND `tblDocumentStatusLog`.`status` IN (".S_REJECTED.") ". "ORDER BY `statusDate` DESC"; - break; - case 'LockedByMe': // Documents locked by me + break; // }}} + case 'LockedByMe': // Documents locked by me {{{ $user = $param1; $queryStr .= "AND `tblDocumentLocks`.`userID` = '".$user->getID()."' ". "ORDER BY `statusDate` DESC"; - break; - case 'WorkflowOwner': // Documents waiting for workflow trigger I'm owning + break; // }}} + case 'WorkflowOwner': // Documents waiting for workflow trigger I'm owning {{{ $user = $param1; $queryStr .= "AND `tblDocuments`.`owner` = '".$user->getID()."' ". "AND `tblDocumentStatusLog`.`status` IN (".S_IN_WORKFLOW.") ". "ORDER BY `statusDate` DESC"; - break; - case 'MyDocs': // Documents owned by me + break; // }}} + case 'MyDocs': // Documents owned by me {{{ $user = $param1; - $orderby = $param2; - if($param3 == 'desc') + $orderby = $param3; + if($param4 == 'desc') $orderdir = 'DESC'; else $orderdir = 'ASC'; @@ -941,8 +1014,8 @@ class SeedDMS_Core_DMS { else if ($orderby=='s') $queryStr .= "ORDER BY `status`"; else $queryStr .= "ORDER BY `name`"; $queryStr .= " ".$orderdir; - break; - case 'CheckedOutByMe': // Documents I have checked out + break; // }}} + case 'CheckedOutByMe': // Documents I have checked out {{{ $user = $param1; $qs = 'SELECT document FROM tblDocumentCheckOuts WHERE userID='.$user->getID(); @@ -954,14 +1027,14 @@ class SeedDMS_Core_DMS { foreach($ra as $d) { $docs[] = $d['document']; } - + if ($docs) { $queryStr .= "AND `tblDocuments`.`id` IN (" . implode(',', $docs) . ") ". "ORDER BY `statusDate` DESC"; } else { $queryStr = ''; } - break; + break; // }}} } if($queryStr) { @@ -2523,7 +2596,7 @@ class SeedDMS_Core_DMS { $versions[] = $version; } return $versions; - + } /* }}} */ /** @@ -2547,7 +2620,7 @@ class SeedDMS_Core_DMS { $versions[] = $version; } return $versions; - + } /* }}} */ /** @@ -2571,7 +2644,7 @@ class SeedDMS_Core_DMS { $versions[] = $version; } return $versions; - + } /* }}} */ /** @@ -2599,7 +2672,7 @@ class SeedDMS_Core_DMS { $versions[$row['dupid']]['duplicates'][] = $version; } return $versions; - + } /* }}} */ /** @@ -2755,11 +2828,11 @@ class SeedDMS_Core_DMS { foreach ($record as $column) { if (is_numeric($column)) $values .= $column; else $values .= $this->db->qstr($column); - + if ($i<(count($record))) $values .= ","; $i++; } - + fwrite($h, "INSERT INTO `".$table."` VALUES (".$values.");\n"); } }