Commit 1392399079a1e717c2a3ac3d5c8d342fc1b840c0
1 parent
9a5fdf91
initial check in/out functionality
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1145 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
228 additions
and
0 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * $Id$ | ||
| 4 | + * | ||
| 5 | + * Business Logic to check in a document | ||
| 6 | + * | ||
| 7 | + * Expected form variable: | ||
| 8 | + * o $fDocumentID - primary key of document user is checking out | ||
| 9 | + * | ||
| 10 | + * Licensed under the GNU GPL. For full terms see the file COPYING. | ||
| 11 | + * | ||
| 12 | + * @version $Revision$ | ||
| 13 | + * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | ||
| 14 | + * @package presentation.lookAndFeel.knowledgeTree.documentmanagement | ||
| 15 | +*/ | ||
| 16 | + | ||
| 17 | +require_once("../../../../config/dmsDefaults.php"); | ||
| 18 | + | ||
| 19 | +if (checkSession()) { | ||
| 20 | + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | ||
| 21 | + require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 22 | + require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | ||
| 23 | + require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); | ||
| 24 | + require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); | ||
| 25 | + require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | ||
| 26 | + require_once("documentUI.inc"); | ||
| 27 | + | ||
| 28 | + $oPatternCustom = & new PatternCustom(); | ||
| 29 | + | ||
| 30 | + if (isset($fDocumentID)) { | ||
| 31 | + // instantiate the document | ||
| 32 | + $oDocument = & Document::get($fDocumentID); | ||
| 33 | + if ($oDocument) { | ||
| 34 | + // user has permission to check the document in | ||
| 35 | + if (Permission::userHasDocumentWritePermission($fDocumentID)) { | ||
| 36 | + // and the document is checked out | ||
| 37 | + if ($oDocument->getIsCheckedOut()) { | ||
| 38 | + // if we're ready to perform the updates | ||
| 39 | + if ($fForStore) { | ||
| 40 | + // make sure the user actually selected a file first | ||
| 41 | + if (strlen($_FILES['fFile']['name']) > 0) { | ||
| 42 | + | ||
| 43 | + // backup the original document | ||
| 44 | + $sBackupPath = $oDocument->getPath() . ".bk"; | ||
| 45 | + copy($oDocument->getPath(), $sBackupPath); | ||
| 46 | + | ||
| 47 | + // update the document with the uploaded one | ||
| 48 | + if (PhysicalDocumentManager::uploadPhysicalDocument($oDocument, $fFolderID, "", $_FILES['fFile']['tmp_name'])) { | ||
| 49 | + // remove the backup | ||
| 50 | + unlink($sBackupPath); | ||
| 51 | + | ||
| 52 | + // now update the database | ||
| 53 | + // overwrite size | ||
| 54 | + $oDocument->setFileSize($_FILES['fFile']['size']); | ||
| 55 | + // update modified date | ||
| 56 | + $oDocument->setLastModifiedDate(getCurrentDateTime()); | ||
| 57 | + // flip the check out status | ||
| 58 | + $oDocument->setIsCheckedOut(false); | ||
| 59 | + // clear the checked in user id | ||
| 60 | + $oDocument->setCheckedOutUserID(-1); | ||
| 61 | + // bump the version numbers | ||
| 62 | + $default->log->error("fCheckInType=$fCheckInType"); | ||
| 63 | + if ($fCheckInType == "major") { | ||
| 64 | + // major version number rollover | ||
| 65 | + $oDocument->setMajorVersionNumber($oDocument->getMajorVersionNumber()+1); | ||
| 66 | + // reset minor version number | ||
| 67 | + $oDocument->setMinorVersionNumber(0); | ||
| 68 | + } else if ($fCheckInType == "minor") { | ||
| 69 | + $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1); | ||
| 70 | + } | ||
| 71 | + $default->log->error("major=" . $oDocument->getMajorVersionNumber() . ";minor=" . $oDocument->getMinorVersionNumber()); | ||
| 72 | + | ||
| 73 | + // update it | ||
| 74 | + if ($oDocument->update()) { | ||
| 75 | + | ||
| 76 | + // create the document transaction record | ||
| 77 | + $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckInComment, CHECKIN); | ||
| 78 | + // TODO: check transaction creation status? | ||
| 79 | + $oDocumentTransaction->create(); | ||
| 80 | + | ||
| 81 | + // fire subscription alerts for the checked in document | ||
| 82 | + $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckInDocument"), | ||
| 83 | + SubscriptionConstants::subscriptionType("DocumentSubscription"), | ||
| 84 | + array( "modifiedDocumentName" => $oDocument->getName() )); | ||
| 85 | + $default->log->info("checkInDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName()); | ||
| 86 | + | ||
| 87 | + //redirect to the document view page | ||
| 88 | + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); | ||
| 89 | + | ||
| 90 | + } else { | ||
| 91 | + // document update failed | ||
| 92 | + $sErrorMessage = "An error occurred while storing this document in the database"; | ||
| 93 | + } | ||
| 94 | + } else { | ||
| 95 | + // reinstate the backup | ||
| 96 | + copy($sBackupPath, $oDocument->getPath()); | ||
| 97 | + $sErrorMessage = "An error occurred while storing the new file on the filesystem"; | ||
| 98 | + } | ||
| 99 | + } else { | ||
| 100 | + $sErrorMessage = "Please select a document by first clicking on 'Browse'. Then click 'Check-In'"; | ||
| 101 | + } | ||
| 102 | + } else { | ||
| 103 | + // prompt the user for a check in comment and the file | ||
| 104 | + $oPatternCustom->setHtml(renderCheckInPage($oDocument)); | ||
| 105 | + } | ||
| 106 | + } else { | ||
| 107 | + // this document isn't checked out | ||
| 108 | + $oPatternCustom->setHtml("<p class=\"errorText\">You can't check in this document because its not checked out</p>\n"); | ||
| 109 | + } | ||
| 110 | + } else { | ||
| 111 | + // no permission to checkout the document | ||
| 112 | + $oPatternCustom->setHtml("<p class=\"errorText\">Could not check in this document</p>\n"); | ||
| 113 | + } | ||
| 114 | + } else { | ||
| 115 | + // couldn't instantiate the document | ||
| 116 | + $oPatternCustom->setHtml("<p class=\"errorText\">Could not check in this document</p>\n"); | ||
| 117 | + } | ||
| 118 | + } else { | ||
| 119 | + // no document id was set when coming to this page, | ||
| 120 | + $oPatternCustom->setHtml("<p class=\"errorText\">No document is currently selected for check in</p>\n"); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 124 | + $main->setCentralPayload($oPatternCustom); | ||
| 125 | + $main->setFormAction($_SERVER["PHP_SELF"]); | ||
| 126 | + $main->setFormEncType("multipart/form-data"); | ||
| 127 | + if (isset($sErrorMessage)) { | ||
| 128 | + $main->setErrorMessage($sErrorMessage); | ||
| 129 | + } | ||
| 130 | + $oPatternCustom->setHtml(renderCheckInPage($oDocument)); | ||
| 131 | + $main->render(); | ||
| 132 | +} | ||
| 133 | +?> |
presentation/lookAndFeel/knowledgeTree/documentmanagement/checkOutDocumentBL.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * $Id$ | ||
| 4 | + * | ||
| 5 | + * Business Logic to check out a document | ||
| 6 | + * | ||
| 7 | + * Expected form variable: | ||
| 8 | + * o $fDocumentID - primary key of document user is checking out | ||
| 9 | + * | ||
| 10 | + * Licensed under the GNU GPL. For full terms see the file COPYING. | ||
| 11 | + * | ||
| 12 | + * @version $Revision$ | ||
| 13 | + * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | ||
| 14 | + * @package presentation.lookAndFeel.knowledgeTree.documentmanagement | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +require_once("../../../../config/dmsDefaults.php"); | ||
| 18 | + | ||
| 19 | +if (checkSession()) { | ||
| 20 | + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | ||
| 21 | + require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 22 | + require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | ||
| 23 | + require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); | ||
| 24 | + require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); | ||
| 25 | + require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | ||
| 26 | + require_once("documentUI.inc"); | ||
| 27 | + | ||
| 28 | + $oPatternCustom = & new PatternCustom(); | ||
| 29 | + | ||
| 30 | + if (isset($fDocumentID)) { | ||
| 31 | + // instantiate the document | ||
| 32 | + $oDocument = & Document::get($fDocumentID); | ||
| 33 | + if ($oDocument) { | ||
| 34 | + // user has permission to check the document out | ||
| 35 | + if (Permission::userHasDocumentWritePermission($fDocumentID)) { | ||
| 36 | + // and its not checked out already | ||
| 37 | + if (!$oDocument->getIsCheckedOut()) { | ||
| 38 | + // if we're ready to perform the updates | ||
| 39 | + if ($fForStore) { | ||
| 40 | + // flip the checkout status | ||
| 41 | + $oDocument->setIsCheckedOut(true); | ||
| 42 | + // set the user checking the document out | ||
| 43 | + $oDocument->setCheckedOutUserID($_SESSION["userID"]); | ||
| 44 | + // update it | ||
| 45 | + if ($oDocument->update()) { | ||
| 46 | + | ||
| 47 | + //create the document transaction record | ||
| 48 | + $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $fCheckOutComment, CHECKOUT); | ||
| 49 | + // TODO: check transaction creation status? | ||
| 50 | + $oDocumentTransaction->create(); | ||
| 51 | + | ||
| 52 | + // fire subscription alerts for the checked out document | ||
| 53 | + $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("CheckOutDocument"), | ||
| 54 | + SubscriptionConstants::subscriptionType("DocumentSubscription"), | ||
| 55 | + array( "modifiedDocumentName" => $oDocument->getName() )); | ||
| 56 | + $default->log->info("checkOutDocumentBL.php fired $count subscription alerts for checked out document " . $oDocument->getName()); | ||
| 57 | + | ||
| 58 | + //redirect to the document view page | ||
| 59 | + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); | ||
| 60 | + | ||
| 61 | + } else { | ||
| 62 | + // document update failed | ||
| 63 | + $oPatternCustom->setHtml("<p class=\"errorText\">An error occurred while storing this document in the database</p>\n"); | ||
| 64 | + } | ||
| 65 | + } else { | ||
| 66 | + // prompt the user for a checkout comment | ||
| 67 | + $oPatternCustom->setHtml(renderCheckOutPage($oDocument)); | ||
| 68 | + } | ||
| 69 | + } else { | ||
| 70 | + // this document is already checked out | ||
| 71 | + // TODO: for extra credit, tell the user who has this document checked out | ||
| 72 | + $oPatternCustom->setHtml("<p class=\"errorText\">This document is already checked out</p>\n"); | ||
| 73 | + } | ||
| 74 | + } else { | ||
| 75 | + // no permission to checkout the document | ||
| 76 | + $oPatternCustom->setHtml("<p class=\"errorText\">Could not check out this document</p>\n"); | ||
| 77 | + } | ||
| 78 | + } else { | ||
| 79 | + // couldn't instantiate the document | ||
| 80 | + $oPatternCustom->setHtml("<p class=\"errorText\">Could not check out this document</p>\n"); | ||
| 81 | + } | ||
| 82 | + } else { | ||
| 83 | + // no document id was set when coming to this page, | ||
| 84 | + $oPatternCustom->setHtml("<p class=\"errorText\">No document is currently selected for check out</p>\n"); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 88 | + $main->setCentralPayload($oPatternCustom); | ||
| 89 | + $main->setFormAction($_SERVER["PHP_SELF"]); | ||
| 90 | + if (isset($sErrorMessage)) { | ||
| 91 | + $main->setErrorMessage($sErrorMessage); | ||
| 92 | + } | ||
| 93 | + $main->render(); | ||
| 94 | +} | ||
| 95 | +?> |