2011-10-16 19:54:57 +00:00
|
|
|
<?php
|
|
|
|
// MyDMS. Document Management System
|
|
|
|
// Copyright (C) 2002-2005 Markus Westphal
|
|
|
|
// Copyright (C) 2006-2008 Malcolm Cowe
|
|
|
|
// Copyright (C) 2010 Matteo Lucarelli
|
2016-08-09 05:34:30 +00:00
|
|
|
// Copyright (C) 2010-2016 Uwe Steinmann
|
2011-10-16 19:54:57 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
include("../inc/inc.Settings.php");
|
|
|
|
include("../inc/inc.Utils.php");
|
2022-11-09 05:40:50 +00:00
|
|
|
include("../inc/inc.LogInit.php");
|
2011-10-16 19:54:57 +00:00
|
|
|
include("../inc/inc.Language.php");
|
2014-12-08 13:47:32 +00:00
|
|
|
include("../inc/inc.Init.php");
|
|
|
|
include("../inc/inc.Extension.php");
|
2015-04-29 18:08:10 +00:00
|
|
|
include("../inc/inc.DBInit.php");
|
2011-10-16 19:54:57 +00:00
|
|
|
include("../inc/inc.Authentication.php");
|
2015-04-29 18:08:10 +00:00
|
|
|
include("../inc/inc.ClassUI.php");
|
2011-10-16 19:54:57 +00:00
|
|
|
|
2016-10-05 14:23:22 +00:00
|
|
|
/* Check if the form data comes from a trusted request */
|
2012-09-11 13:15:59 +00:00
|
|
|
if(!checkFormKey('reviewdocument')) {
|
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_request_token"))),getMLText("invalid_request_token"));
|
|
|
|
}
|
|
|
|
|
2011-10-16 19:54:57 +00:00
|
|
|
if (!isset($_POST["documentid"]) || !is_numeric($_POST["documentid"]) || intval($_POST["documentid"])<1) {
|
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
|
|
|
|
}
|
|
|
|
|
|
|
|
$documentid = $_POST["documentid"];
|
2010-11-12 22:47:41 +00:00
|
|
|
$document = $dms->getDocument($documentid);
|
2011-10-16 19:54:57 +00:00
|
|
|
|
|
|
|
if (!is_object($document)) {
|
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
|
|
|
|
}
|
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
if ($document->getAccessMode($user) < M_READ) {
|
2011-10-16 19:54:57 +00:00
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied"));
|
|
|
|
}
|
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
if (!isset($_POST["version"]) || !is_numeric($_POST["version"]) || intval($_POST["version"])<1) {
|
2011-10-16 19:54:57 +00:00
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version"));
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
2011-10-16 19:54:57 +00:00
|
|
|
|
|
|
|
$version = $_POST["version"];
|
2010-10-29 13:19:51 +00:00
|
|
|
$content = $document->getContentByVersion($version);
|
2011-10-16 19:54:57 +00:00
|
|
|
|
|
|
|
if (!is_object($content)) {
|
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version"));
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
|
|
|
|
2011-10-16 19:54:57 +00:00
|
|
|
// operation is only allowed for the last document version
|
2010-10-29 13:19:51 +00:00
|
|
|
$latestContent = $document->getLatestContent();
|
|
|
|
if ($latestContent->getVersion()!=$version) {
|
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version"));
|
|
|
|
}
|
|
|
|
|
2015-06-15 06:54:33 +00:00
|
|
|
/* Create object for checking access to certain operations */
|
2015-08-07 11:11:50 +00:00
|
|
|
$accessop = new SeedDMS_AccessOperation($dms, $document, $user, $settings);
|
2015-06-15 06:54:33 +00:00
|
|
|
|
|
|
|
// verify if document may be reviewed
|
2015-06-15 12:20:51 +00:00
|
|
|
if (!$accessop->mayReview()){
|
2011-10-16 19:54:57 +00:00
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($_POST["reviewStatus"]) || !is_numeric($_POST["reviewStatus"]) ||
|
2010-10-29 13:19:51 +00:00
|
|
|
(intval($_POST["reviewStatus"])!=1 && intval($_POST["reviewStatus"])!=-1)) {
|
2011-10-16 19:54:57 +00:00
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_review_status"));
|
|
|
|
}
|
|
|
|
|
2015-06-11 19:30:56 +00:00
|
|
|
if($_FILES["reviewfile"]["tmp_name"]) {
|
|
|
|
if (is_uploaded_file($_FILES["reviewfile"]["tmp_name"]) && $_FILES['reviewfile']['error']!=0){
|
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("uploading_failed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
if ($_POST["reviewType"] == "ind") {
|
2011-10-16 19:54:57 +00:00
|
|
|
|
2011-12-02 18:44:42 +00:00
|
|
|
$comment = $_POST["comment"];
|
2015-06-11 19:30:56 +00:00
|
|
|
if($_FILES["reviewfile"]["tmp_name"])
|
|
|
|
$file = $_FILES["reviewfile"]["tmp_name"];
|
|
|
|
else
|
|
|
|
$file = '';
|
|
|
|
$reviewLogID = $latestContent->setReviewByInd($user, $user, $_POST["reviewStatus"], $comment, $file);
|
2021-09-29 15:26:20 +00:00
|
|
|
if($reviewLogID === false || 0 > $reviewLogID) {
|
2011-10-16 19:54:57 +00:00
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("review_update_failed"));
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
2011-10-16 19:54:57 +00:00
|
|
|
else {
|
|
|
|
// Send an email notification to the document updater.
|
2010-12-14 14:14:29 +00:00
|
|
|
if($notifier) {
|
2021-05-19 18:41:50 +00:00
|
|
|
$reviewlog = $latestContent->getReviewLog();
|
|
|
|
$notifier->sendSubmittedReviewMail($latestContent, $user, $reviewlog ? $reviewlog[0] : false);
|
2010-12-14 14:14:29 +00:00
|
|
|
}
|
2011-10-16 19:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($_POST["reviewType"] == "grp") {
|
2011-12-05 08:14:25 +00:00
|
|
|
$comment = $_POST["comment"];
|
2011-10-16 19:54:57 +00:00
|
|
|
$group = $dms->getGroup($_POST['reviewGroup']);
|
2015-06-11 19:30:56 +00:00
|
|
|
if($_FILES["reviewfile"]["tmp_name"])
|
|
|
|
$file = $_FILES["reviewfile"]["tmp_name"];
|
|
|
|
else
|
|
|
|
$file = '';
|
|
|
|
$reviewLogID = $latestContent->setReviewByGrp($group, $user, $_POST["reviewStatus"], $comment, $file);
|
2021-09-29 15:26:20 +00:00
|
|
|
if($reviewLogID === false || 0 > $reviewLogID) {
|
2011-10-16 19:54:57 +00:00
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("review_update_failed"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Send an email notification to the document updater.
|
2010-12-14 14:14:29 +00:00
|
|
|
if($notifier) {
|
2021-05-19 18:41:50 +00:00
|
|
|
$reviewlog = $latestContent->getReviewLog();
|
|
|
|
$notifier->sendSubmittedReviewMail($latestContent, $user, $reviewlog ? $reviewlog[0] : false);
|
2010-12-14 14:14:29 +00:00
|
|
|
}
|
2011-10-16 19:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check to see if the overall status for the document version needs to be
|
|
|
|
// updated.
|
|
|
|
//
|
|
|
|
|
2021-08-30 17:41:26 +00:00
|
|
|
$overallStatus = $content->getStatus();
|
2010-10-29 13:19:51 +00:00
|
|
|
if ($_POST["reviewStatus"]==-1){
|
2010-11-18 13:53:26 +00:00
|
|
|
if($content->setStatus(S_REJECTED,$comment,$user)) {
|
|
|
|
// Send notification to subscribers.
|
|
|
|
if($notifier) {
|
2021-08-30 17:41:26 +00:00
|
|
|
$notifier->sendChangedDocumentStatusMail($content, $user, $overallStatus["status"]);
|
2010-11-18 13:53:26 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-16 19:54:57 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
}else{
|
2011-10-16 19:54:57 +00:00
|
|
|
|
2011-12-05 08:14:25 +00:00
|
|
|
$docReviewStatus = $content->getReviewStatus();
|
2010-10-29 13:19:51 +00:00
|
|
|
if (is_bool($docReviewStatus) && !$docReviewStatus) {
|
2011-10-16 19:54:57 +00:00
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("cannot_retrieve_review_snapshot"));
|
|
|
|
}
|
|
|
|
$reviewCT = 0;
|
|
|
|
$reviewTotal = 0;
|
|
|
|
foreach ($docReviewStatus as $drstat) {
|
|
|
|
if ($drstat["status"] == 1) {
|
|
|
|
$reviewCT++;
|
|
|
|
}
|
|
|
|
if ($drstat["status"] != -2) {
|
|
|
|
$reviewTotal++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If all reviews have been received and there are no rejections, retrieve a
|
|
|
|
// count of the approvals required for this document.
|
|
|
|
if ($reviewCT == $reviewTotal) {
|
2011-12-05 08:14:25 +00:00
|
|
|
$docApprovalStatus = $content->getApprovalStatus();
|
2010-10-29 13:19:51 +00:00
|
|
|
if (is_bool($docApprovalStatus) && !$docApprovalStatus) {
|
2011-10-16 19:54:57 +00:00
|
|
|
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("cannot_retrieve_approval_snapshot"));
|
|
|
|
}
|
|
|
|
$approvalCT = 0;
|
|
|
|
$approvalTotal = 0;
|
|
|
|
foreach ($docApprovalStatus as $dastat) {
|
|
|
|
if ($dastat["status"] == 1) {
|
|
|
|
$approvalCT++;
|
|
|
|
}
|
|
|
|
if ($dastat["status"] != -2) {
|
|
|
|
$approvalTotal++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the approvals received is less than the approvals total, then
|
|
|
|
// change status to pending approval.
|
|
|
|
if ($approvalCT<$approvalTotal) {
|
2013-09-27 06:24:09 +00:00
|
|
|
$newStatus=S_DRAFT_APP;
|
2011-10-16 19:54:57 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Otherwise, change the status to released.
|
2013-09-27 06:24:09 +00:00
|
|
|
$newStatus=S_RELEASED;
|
2011-10-16 19:54:57 +00:00
|
|
|
}
|
2010-10-29 13:19:51 +00:00
|
|
|
if ($content->setStatus($newStatus, getMLText("automatic_status_update"), $user)) {
|
2010-11-18 13:53:26 +00:00
|
|
|
// Send notification to subscribers.
|
|
|
|
if($notifier) {
|
2021-08-30 17:41:26 +00:00
|
|
|
$notifier->sendChangedDocumentStatusMail($content, $user, $overallStatus["status"]);
|
|
|
|
|
|
|
|
// Notify approvers, if necessary.
|
|
|
|
if ($newStatus == S_DRAFT_APP) {
|
|
|
|
$requestUser = $document->getOwner();
|
|
|
|
$notifier->sendApprovalRequestMail($content, $user);
|
2013-03-06 11:53:25 +00:00
|
|
|
}
|
2010-11-18 13:53:26 +00:00
|
|
|
}
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2021-08-30 17:41:26 +00:00
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, 'postReviewDocument')) {
|
|
|
|
$hookObj->postReviewDocument(null, $content, $newStatus);
|
2011-10-16 19:54:57 +00:00
|
|
|
}
|
2010-12-14 14:14:29 +00:00
|
|
|
}
|
2011-10-16 19:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 06:59:25 +00:00
|
|
|
header("Location:../out/out.ViewDocument.php?documentid=".$documentid."¤ttab=revapp");
|
2011-10-16 19:54:57 +00:00
|
|
|
|
|
|
|
?>
|