some code reorganisation

This commit is contained in:
Uwe Steinmann 2015-05-30 07:32:36 +02:00
parent d5e9c7532a
commit 570e0fa782

View File

@ -74,6 +74,7 @@ if ($latestContent->getVersion()!=$version) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version")); UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version"));
} }
$olddocstatus = $content->getStatus();
// verify if document has expired // verify if document has expired
if ($document->hasExpired()){ if ($document->hasExpired()){
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied")); UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied"));
@ -84,6 +85,7 @@ if (!isset($_POST["approvalStatus"]) || !is_numeric($_POST["approvalStatus"]) ||
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_approval_status")); UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_approval_status"));
} }
$controller->setParam('document', $document); $controller->setParam('document', $document);
$controller->setParam('content', $latestContent); $controller->setParam('content', $latestContent);
$controller->setParam('approvalstatus', $_POST["approvalStatus"]); $controller->setParam('approvalstatus', $_POST["approvalStatus"]);
@ -99,20 +101,39 @@ if(!$controller->run()) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText($controller->getErrorMsg())); UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText($controller->getErrorMsg()));
} }
/* //
if ($_POST["approvalType"] == "ind") { // Check to see if the overall status for the document version needs to be
$comment = $_POST["comment"]; // updated.
if(0 > $latestContent->setApprovalByInd($user, $user, $_POST["approvalStatus"], $comment)) { //
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("approval_update_failed"));
/* If document was rejected, set the document status to S_REJECTED right away */
if ($_POST["approvalStatus"]==-1){
if($content->setStatus(S_REJECTED,$comment,$user)) {
} }
} elseif ($_POST["approvalType"] == "grp") { } else {
$comment = $_POST["comment"]; $docApprovalStatus = $content->getApprovalStatus();
$group = $dms->getGroup($_POST['approvalGroup']); if (is_bool($docApprovalStatus) && !$docApprovalStatus) {
if(0 > $latestContent->setApprovalByGrp($group, $user, $_POST["approvalStatus"], $comment)) { UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("cannot_retrieve_approval_snapshot"));
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("approval_update_failed")); }
$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.
$newStatus=S_RELEASED;
if($content->setStatus($newStatus, getMLText("automatic_status_update"), $user)) {
}
} }
} }
*/
if ($_POST["approvalType"] == "ind" || $_POST["approvalType"] == "grp") { if ($_POST["approvalType"] == "ind" || $_POST["approvalType"] == "grp") {
// Send an email notification to the document updater. // Send an email notification to the document updater.
@ -141,44 +162,9 @@ if ($_POST["approvalType"] == "ind" || $_POST["approvalType"] == "grp") {
} }
} }
// /* Send notification about status change only if status has actually changed */
// Check to see if the overall status for the document version needs to be $newdocstatus = $content->getStatus();
// updated. if($olddocstatus['status'] != $newdocstatus['status']) {
//
$sendnotification = false;
/* If document was rejected, set the document status to S_REJECTED right away */
if ($_POST["approvalStatus"]==-1){
if($content->setStatus(S_REJECTED,$comment,$user)) {
$sendnotification = true;
}
} else {
$docApprovalStatus = $content->getApprovalStatus();
if (is_bool($docApprovalStatus) && !$docApprovalStatus) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("cannot_retrieve_approval_snapshot"));
}
$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.
$newStatus=S_RELEASED;
if($content->setStatus($newStatus, getMLText("automatic_status_update"), $user)) {
$sendnotification = true;
}
}
}
if($sendnotification) {
// Send notification to subscribers. // Send notification to subscribers.
if($notifier) { if($notifier) {
$nl=$document->getNotifyList(); $nl=$document->getNotifyList();