move most of the code in op/* into new controller

This commit is contained in:
Uwe Steinmann 2023-06-18 13:59:23 +02:00
parent 0be0f90881
commit b7d029475d
4 changed files with 290 additions and 1 deletions

View File

@ -0,0 +1,101 @@
<?php
/**
* Implementation of ApproveDocument controller
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2023 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Class which does the busines logic for approving a document
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2023 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_Controller_ApproveDocument extends SeedDMS_Controller_Common {
public $oldstatus;
public $newstatus;
public function run() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$settings = $this->params['settings'];
$content = $this->params['content'];
$approvaltype = $this->params['type'];
$approvalstatus = $this->params['status'];
$approvalcomment = $this->params['comment'];
$approvalfile = $this->params['file'];
$approvalgroup = $this->params['group'];
$overallStatus = $content->getStatus();
$this->oldstatus = $overallStatus['status'];
$this->newstatus = $this->oldstatus;
if ($approvaltype == "ind") {
$approvalLogID = $content->setApprovalByInd($user, $user, $approvalstatus, $approvalcomment, $approvalfile);
} elseif ($approvaltype == "grp") {
$approvalLogID = $content->setApprovalByGrp($approvalgroup, $user, $approvalstatus, $approvalcomment, $approvalfile);
} else {
$this->errormsg = "approval_wrong_type";
return false;
}
if($approvalLogID === false || 0 > $approvalLogID) {
$this->errormsg = "approval_update_failed";
return false;
}
if($approvalstatus == -1) {
$this->newstatus = S_REJECTED;
if($content->setStatus(S_REJECTED, $approvalcomment, $user)) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['approveDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['approveDocument'] as $hookObj) {
if (method_exists($hookObj, 'postApproveDocument')) {
$hookObj->postApproveDocument(null, $content, S_REJECTED);
}
}
}
}
} else {
$docApprovalStatus = $content->getApprovalStatus();
if (is_bool($docApprovalStatus) && !$docApprovalStatus) {
$this->errormsg = "cannot_retrieve_approval_snapshot";
return false;
}
$approvalCT = 0;
$approvalTotal = 0;
foreach ($docApprovalStatus as $drstat) {
if ($drstat["status"] == 1) {
$approvalCT++;
}
if ($drstat["status"] != -2) {
$approvalTotal++;
}
}
// If all approvals have been received and there are no rejections, retrieve a
// count of the approvals required for this document.
if ($approvalCT == $approvalTotal) {
// Change the status to released.
$this->newstatus=S_RELEASED;
if($content->setStatus($this->newstatus, getMLText("automatic_status_update"), $user)) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['approveDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['approveDocument'] as $hookObj) {
if (method_exists($hookObj, 'postApproveDocument')) {
$hookObj->postApproveDocument(null, $content, S_RELEASED);
}
}
}
}
}
}
return true;
} /* }}} */
}

View File

@ -0,0 +1,118 @@
<?php
/**
* Implementation of ReviewDocument controller
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2023 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Class which does the busines logic for reviewing a document
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2023 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_Controller_ReviewDocument extends SeedDMS_Controller_Common {
public function run() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$settings = $this->params['settings'];
$content = $this->params['content'];
$reviewtype = $this->params['type'];
$reviewstatus = $this->params['status'];
$reviewcomment = $this->params['comment'];
$reviewfile = $this->params['file'];
$reviewgroup = $this->params['group'];
$overallStatus = $content->getStatus();
$this->oldstatus = $overallStatus['status'];
$this->newstatus = $this->oldstatus;
if ($reviewtype == "ind") {
$reviewLogID = $content->setReviewByInd($user, $user, $reviewstatus, $reviewcomment, $reviewfile);
} elseif($reviewtype == "grp") {
$reviewLogID = $content->setReviewByGrp($reviewgroup, $user, $reviewstatus, $reviewcomment, $reviewfile);
} else {
$this->errormsg = "review_wrong_type";
return false;
}
if($reviewLogID === false || 0 > $reviewLogID) {
$this->errormsg = "review_update_failed";
return false;
}
if($reviewstatus == -1) {
$this->newstatus = S_REJECTED;
if($content->setStatus(S_REJECTED, $reviewcomment, $user)) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'] as $hookObj) {
if (method_exists($hookObj, 'postReviewDocument')) {
$hookObj->postReviewDocument(null, $content, S_REJECTED);
}
}
}
}
} else {
$docReviewStatus = $content->getReviewStatus();
if (is_bool($docReviewStatus) && !$docReviewStatus) {
$this->errormsg = "cannot_retrieve_review_snapshot";
return false;
}
$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) {
$docApprovalStatus = $content->getApprovalStatus();
if (is_bool($docApprovalStatus) && !$docApprovalStatus) {
$this->errormsg = "cannot_retrieve_approval_snapshot";
return false;
}
$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) {
$this->newstatus = S_DRAFT_APP;
} else {
// Otherwise, change the status to released.
$this->newstatus = S_RELEASED;
}
if($content->setStatus($this->newstatus, getMLText("automatic_status_update"), $user)) {
if(isset($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'] as $hookObj) {
if (method_exists($hookObj, 'postReviewDocument')) {
$hookObj->postReviewDocument(null, $content, $this->newstatus);
}
}
}
}
}
}
return true;
} /* }}} */
}

View File

@ -28,6 +28,10 @@ include("../inc/inc.Extension.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.Authentication.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassController.php");
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
/* Check if the form data comes from a trusted request */
if(!checkFormKey('approvedocument')) {
@ -87,6 +91,32 @@ if($_FILES["approvalfile"]["tmp_name"]) {
}
}
$controller->setParam('comment', $_POST['comment']);
$controller->setParam('type', $_POST['approvalType']);
$controller->setParam('status', $_POST['approvalStatus']);
$controller->setParam('content', $latestContent);
$controller->setParam('file', !empty($_FILES["approvalfile"]["tmp_name"]) ? $_FILES["approvalfile"]["tmp_name"] : '');
$controller->setParam('group', !empty($_POST['approvalGroup']) ? $dms->getGroup($_POST['approvalGroup']) : null);
if(!$controller()) {
$err = $controller->getErrorMsg();
if(is_string($err))
$errmsg = getMLText($err);
elseif(is_array($err)) {
$errmsg = getMLText($err[0], $err[1]);
} else {
$errmsg = $err;
}
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),$errmsg);
} else {
if($notifier) {
$approvelog = $latestContent->getApproveLog();
$notifier->sendSubmittedApprovalMail($latestContent, $user, $approvelog ? $approvelog[0] : false);
if($controller->oldstatus != $controller->newstatus)
$notifier->sendChangedDocumentStatusMail($latestContent, $user, $controller->oldstatus);
}
}
if(0) {
if ($_POST["approvalType"] == "ind") {
$comment = $_POST["comment"];
@ -125,12 +155,14 @@ else if ($_POST["approvalType"] == "grp") {
}
}
}
}
//
// Check to see if the overall status for the document version needs to be
// updated.
//
if(0) {
$overallStatus = $content->getStatus();
if ($_POST["approvalStatus"]==-1){
if($content->setStatus(S_REJECTED,$comment,$user)) {
@ -184,7 +216,7 @@ if ($_POST["approvalStatus"]==-1){
}
}
}
}
add_log_line("?documentid=".$_POST['documentid']."&version=".$_POST['version']."&approvalType=".$_POST['approvalType']."&approvalStatus=".$_POST['approvalStatus']);
header("Location:../out/out.ViewDocument.php?documentid=".$documentid."&currenttab=revapp");

View File

@ -28,6 +28,10 @@ include("../inc/inc.Extension.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.Authentication.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassController.php");
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
/* Check if the form data comes from a trusted request */
if(!checkFormKey('reviewdocument')) {
@ -85,6 +89,37 @@ if($_FILES["reviewfile"]["tmp_name"]) {
}
}
$controller->setParam('comment', $_POST['comment']);
$controller->setParam('type', $_POST['reviewType']);
$controller->setParam('status', $_POST['reviewStatus']);
$controller->setParam('content', $latestContent);
$controller->setParam('file', !empty($_FILES["reviewfile"]["tmp_name"]) ? $_FILES["reviewfile"]["tmp_name"] : '');
$controller->setParam('group', !empty($_POST['reviewGroup']) ? $dms->getGroup($_POST['reviewGroup']) : null);
if(!$controller()) {
$err = $controller->getErrorMsg();
if(is_string($err))
$errmsg = getMLText($err);
elseif(is_array($err)) {
$errmsg = getMLText($err[0], $err[1]);
} else {
$errmsg = $err;
}
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),$errmsg);
} else {
if($notifier) {
$reviewlog = $latestContent->getReviewLog();
$notifier->sendSubmittedReviewMail($latestContent, $user, $reviewlog ? $reviewlog[0] : false);
if($controller->oldstatus != $controller->newstatus)
$notifier->sendChangedDocumentStatusMail($latestContent, $user, $controller->oldstatus);
// Notify approvers, if necessary.
if ($controller->newstatus == S_DRAFT_APP) {
$notifier->sendApprovalRequestMail($latestContent, $user);
}
}
}
if(0) {
if ($_POST["reviewType"] == "ind") {
$comment = $_POST["comment"];
@ -123,12 +158,14 @@ else if ($_POST["reviewType"] == "grp") {
}
}
}
}
//
// Check to see if the overall status for the document version needs to be
// updated.
//
if(0) {
$overallStatus = $content->getStatus();
if ($_POST["reviewStatus"]==-1){
if($content->setStatus(S_REJECTED,$comment,$user)) {
@ -202,6 +239,7 @@ if ($_POST["reviewStatus"]==-1){
}
}
}
}
header("Location:../out/out.ViewDocument.php?documentid=".$documentid."&currenttab=revapp");