Commit 00a24fe718e6bb682afbaae5db92c0d657d723c9
1 parent
5faf3fa9
Deletion of documents now lives in the delete action.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4083 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
0 additions
and
281 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/deleteDocumentBL.php deleted
| 1 | -<?php | ||
| 2 | -/** | ||
| 3 | - * $Id$ | ||
| 4 | - * | ||
| 5 | - * Business logic concerned with the deletion of a document. | ||
| 6 | - * Will use deleteDocumentUI for presentation information. | ||
| 7 | - * | ||
| 8 | - * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com | ||
| 9 | - * | ||
| 10 | - * This program is free software; you can redistribute it and/or modify | ||
| 11 | - * it under the terms of the GNU General Public License as published by | ||
| 12 | - * the Free Software Foundation; either version 2 of the License, or | ||
| 13 | - * (at your option) any later version. | ||
| 14 | - * | ||
| 15 | - * This program is distributed in the hope that it will be useful, | ||
| 16 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | - * GNU General Public License for more details. | ||
| 19 | - * | ||
| 20 | - * You should have received a copy of the GNU General Public License | ||
| 21 | - * along with this program; if not, write to the Free Software | ||
| 22 | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 23 | - * | ||
| 24 | - * @version $Revision$ | ||
| 25 | - * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | ||
| 26 | - * @package documentmanagement | ||
| 27 | - */ | ||
| 28 | - | ||
| 29 | -require_once("../../../../config/dmsDefaults.php"); | ||
| 30 | - | ||
| 31 | -KTUtil::extractGPC('fDeleteConfirmed', 'fDocumentIDs', 'fRememberDocumentID'); | ||
| 32 | - | ||
| 33 | -require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 34 | -require_once("$default->fileSystemRoot/lib/users/User.inc"); | ||
| 35 | -require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | ||
| 36 | -require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); | ||
| 37 | -require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); | ||
| 38 | -require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | ||
| 39 | -require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionManager.inc"); | ||
| 40 | - | ||
| 41 | -require_once("$default->fileSystemRoot/presentation/Html.inc"); | ||
| 42 | - | ||
| 43 | -require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | ||
| 44 | - | ||
| 45 | -require_once("deleteDocumentUI.inc"); | ||
| 46 | - | ||
| 47 | -$aNondeletedDocs = array(); | ||
| 48 | - | ||
| 49 | -if (!checkSession()) { | ||
| 50 | - die(); | ||
| 51 | -} | ||
| 52 | - | ||
| 53 | -if (isset($fRememberDocumentID)) { | ||
| 54 | - $fDocumentIDs = $_SESSION['documents'][$fRememberDocumentID]; | ||
| 55 | -} else { | ||
| 56 | - $sUniqueID = KTUtil::randomString(); | ||
| 57 | - $_SESSION["documents"][$sUniqueID] = $fDocumentIDs; | ||
| 58 | - $fRememberDocumentID = $sUniqueID; | ||
| 59 | -} | ||
| 60 | - | ||
| 61 | -if (!isset($fDocumentIDs)) { | ||
| 62 | - //no document selected for deletion | ||
| 63 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 64 | - $oPatternCustom = & new PatternCustom(); | ||
| 65 | - $oPatternCustom->setHtml(renderErrorPage(_("No document currently selected"))); | ||
| 66 | - $main->setCentralPayload($oPatternCustom); | ||
| 67 | - $main->render(); | ||
| 68 | - exit(0); | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | - | ||
| 72 | -// Check permission and collaboration for all documents | ||
| 73 | -for ($i = 0; $i < count($fDocumentIDs); $i++) { | ||
| 74 | - $oDocument = Document::get($fDocumentIDs[$i]); | ||
| 75 | - | ||
| 76 | - if (!Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 77 | - // user does not have permission to delete the document | ||
| 78 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 79 | - $oPatternCustom = & new PatternCustom(); | ||
| 80 | - $oPatternCustom->setHtml(renderErrorPage(_("You do not have, at least, permission to delete one document") . ": " . | ||
| 81 | - $oDocument->getName() . "<br>" . _("Please deselect it and retry."))); | ||
| 82 | - $main->setCentralPayload($oPatternCustom); | ||
| 83 | - $main->render(); | ||
| 84 | - exit(0); | ||
| 85 | - } | ||
| 86 | -} | ||
| 87 | - | ||
| 88 | -if (!isset($fDeleteConfirmed)) { | ||
| 89 | - //get confirmation first | ||
| 90 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 91 | - $oPatternCustom = & new PatternCustom(); | ||
| 92 | - $oPatternCustom->addHtml(getPage($fRememberDocumentID)); | ||
| 93 | - $main->setCentralPayload($oPatternCustom); | ||
| 94 | - $main->render(); | ||
| 95 | - exit(0); | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | - /* Delete all files | ||
| 99 | - If an error occured while deleting a file, then: | ||
| 100 | - - make a rollback of the current file | ||
| 101 | - - insert document object in $aNondeletedDocs array | ||
| 102 | - - delete the other selected file | ||
| 103 | - | ||
| 104 | - At the end check the $aNondeletedDocs array | ||
| 105 | - - if is empty then OK | ||
| 106 | - - if is not empty then show the nondeleted files list | ||
| 107 | - */ | ||
| 108 | - | ||
| 109 | -for ($i = 0; $i < count($fDocumentIDs); $i++) { | ||
| 110 | - $oDocument = Document::get($fDocumentIDs[$i]); | ||
| 111 | - if (!isset($oDocument)) { | ||
| 112 | - // Store the doc with problem | ||
| 113 | - array_push($aNondeletedDocs, array($oDocument, _("Could not load document in database"))); | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - // New transaction | ||
| 117 | - $sDocumentPath = Folder::getFolderPath($oDocument->getFolderID()) . $oDocument->getFileName(); | ||
| 118 | - $oDocumentTransaction = & new DocumentTransaction($fDocumentIDs[$i], "Document deleted", DELETE); | ||
| 119 | - $oDocumentTransaction->create(); | ||
| 120 | - | ||
| 121 | - // flip the status id | ||
| 122 | - $oDocument->setStatusID(DELETED); | ||
| 123 | - | ||
| 124 | - // store | ||
| 125 | - if (!$oDocument->update()) { | ||
| 126 | - //could not update the documents status in the db | ||
| 127 | - $default->log->error("deleteDocumentBL.php DB error deleting document " . | ||
| 128 | - $oDocument->getFileName() . " from folder " . | ||
| 129 | - Folder::getFolderPath($oDocument->getFolderID()) . | ||
| 130 | - " id=" . $oDocument->getFolderID()); | ||
| 131 | - | ||
| 132 | - //get rid of the document transaction | ||
| 133 | - $oDocumentTransaction->delete(); | ||
| 134 | - | ||
| 135 | - // Store the doc with problem | ||
| 136 | - array_push($aNondeletedDocs, array($oDocument, | ||
| 137 | - _("Could not update document in database"))); | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - // now move the document to the delete folder | ||
| 141 | - if (PhysicalDocumentManager::delete($oDocument)) { | ||
| 142 | - //could not delete the document from the file system | ||
| 143 | - $default->log->error("deleteDocumentBL.php Filesystem error deleting document " . | ||
| 144 | - $oDocument->getFileName() . " from folder " . | ||
| 145 | - Folder::getFolderPath($oDocument->getFolderID()) . | ||
| 146 | - " id=" . $oDocument->getFolderID()); | ||
| 147 | - //reverse the document deletion | ||
| 148 | - $oDocument->setStatusID(LIVE); | ||
| 149 | - $oDocument->update(); | ||
| 150 | - //get rid of the document transaction | ||
| 151 | - $oDocumentTransaction->delete(); | ||
| 152 | - | ||
| 153 | - // Store the doc with problem | ||
| 154 | - array_push($aNondeletedDocs, array($oDocument, _("Could not delete document on file system"))); | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - // successfully deleted the document | ||
| 158 | - $default->log->info("deleteDocumentBL.php successfully deleted document " . | ||
| 159 | - $oDocument->getFileName() . " from folder " . | ||
| 160 | - Folder::getFolderPath($oDocument->getFolderID()) . | ||
| 161 | - " id=" . $oDocument->getFolderID()); | ||
| 162 | - | ||
| 163 | - // fire subscription alerts for the deleted document | ||
| 164 | - $count = SubscriptionEngine::fireSubscription($fDocumentIDs[$i], | ||
| 165 | - SubscriptionConstants::subscriptionAlertType("RemoveSubscribedDocument"), | ||
| 166 | - SubscriptionConstants::subscriptionType("DocumentSubscription"), | ||
| 167 | - array( | ||
| 168 | - "folderID" => $oDocument->getFolderID(), | ||
| 169 | - "removedDocumentName" => $oDocument->getName(), | ||
| 170 | - "folderName" => Folder::getFolderDisplayPath($oDocument->getFolderID()), | ||
| 171 | - )); | ||
| 172 | - $default->log->info("deleteDocumentBL.php fired $count subscription alerts for removed document " . $oDocument->getName()); | ||
| 173 | - | ||
| 174 | - // remove all document subscriptions for this document | ||
| 175 | - if (SubscriptionManager::removeSubscriptions($fDocumentIDs[$i], SubscriptionConstants::subscriptionType("DocumentSubscription"))) { | ||
| 176 | - $default->log->info("deleteDocumentBL.php removed all subscriptions for this document"); | ||
| 177 | - } else { | ||
| 178 | - $default->log->error("deleteDocumentBL.php couldn't remove document subscriptions"); | ||
| 179 | - } | ||
| 180 | -} | ||
| 181 | - | ||
| 182 | -// List nondeleted documents | ||
| 183 | -if (!empty($aNondeletedDocs) ) { | ||
| 184 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 185 | - $oPatternCustom = & new PatternCustom(); | ||
| 186 | - | ||
| 187 | - $sError = _("An error occured deleting the following document(s):") . "<br><br>"; | ||
| 188 | - foreach ($aNondeletedDocs as $oDoc) { | ||
| 189 | - $sError .= $oDoc[0]->getDisplayPath() . ": " .$oDoc[1] . "<br>"; | ||
| 190 | - } | ||
| 191 | - $sError .= "<br>" . _("The other documents are been deleted."); | ||
| 192 | - | ||
| 193 | - $oPatternCustom->addHtml(renderErrorPage($sError)); | ||
| 194 | - $main->setCentralPayload($oPatternCustom); | ||
| 195 | - $main->render(); | ||
| 196 | - exit(0); | ||
| 197 | -} | ||
| 198 | - | ||
| 199 | -// redirect to the browse folder page | ||
| 200 | -redirect("$default->rootUrl/control.php?action=browse&fFolderID=" . $oDocument->getFolderID()); | ||
| 201 | -exit(0); | ||
| 202 | -?> |
presentation/lookAndFeel/knowledgeTree/documentmanagement/deleteDocumentUI.inc deleted
| 1 | -<?php | ||
| 2 | -/** | ||
| 3 | - * $Id$ | ||
| 4 | - * | ||
| 5 | - * Presentation information for documentDeleteBL.php. | ||
| 6 | - * | ||
| 7 | - * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com | ||
| 8 | - * | ||
| 9 | - * This program is free software; you can redistribute it and/or modify | ||
| 10 | - * it under the terms of the GNU General Public License as published by | ||
| 11 | - * the Free Software Foundation; either version 2 of the License, or | ||
| 12 | - * (at your option) any later version. | ||
| 13 | - * | ||
| 14 | - * This program is distributed in the hope that it will be useful, | ||
| 15 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | - * GNU General Public License for more details. | ||
| 18 | - * | ||
| 19 | - * You should have received a copy of the GNU General Public License | ||
| 20 | - * along with this program; if not, write to the Free Software | ||
| 21 | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 22 | - * | ||
| 23 | - * @version $Revision$ | ||
| 24 | - * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | ||
| 25 | - * @package documentmanagement | ||
| 26 | - */ | ||
| 27 | -function getPage($sRememberDocumentID) { | ||
| 28 | - global $default; | ||
| 29 | - $aDocumentIDs = $_SESSION['documents'][$sRememberDocumentID]; | ||
| 30 | - $sToRender = renderHeading(_("Delete Document")); | ||
| 31 | - $sToRender .= "<table border=\"0\">\n"; | ||
| 32 | - $sToRender .= "<tr>\n"; | ||
| 33 | - $sToRender .= "<td>" . _("You have chosen to delete the following document(s):") . " <br><br></td>\n"; | ||
| 34 | - | ||
| 35 | - for ($i = 0; $i < count($aDocumentIDs); $i++) { | ||
| 36 | - $oDocument = Document::get($aDocumentIDs[$i]); | ||
| 37 | - $sToRender .= "<tr>\n"; | ||
| 38 | - $sToRender .= "<td> '" . $oDocument->getDisplayPath() . "'</td>\n"; | ||
| 39 | - } | ||
| 40 | - $sQueryString = "fRememberDocumentID=$sRememberDocumentID&"; | ||
| 41 | - $sToRender .= "<tr><tr><tr><tr>\n"; | ||
| 42 | - | ||
| 43 | - $sToRender .= "<td>" . _("Select 'Delete' to confirm the deletion, or 'Cancel' to cancel it") . "</td>\n"; | ||
| 44 | - $sToRender .= "<tr>\n"; | ||
| 45 | - $sToRender .= "<tr>\n"; | ||
| 46 | - $sToRender .= "<td> </td>\n"; | ||
| 47 | - $sToRender .= "<tr>\n"; | ||
| 48 | - $sToRender .= "<td><table><tr><td>"; | ||
| 49 | - $sToRender .= "<a href=\"" . $_SERVER["PHP_SELF"] . "?$sQueryString&fDeleteConfirmed=1\"><img src=\"" . KTHtml::getDeleteButton() . "\" border=\"0\"></a>"; | ||
| 50 | - $sToRender .= "</td> <td>"; | ||
| 51 | - if (KTUtil::arrayGet($_REQUEST, "fReturnFolderID")) { | ||
| 52 | - $sToRender .= generateControllerLink("browse", "fFolderID=" . $_REQUEST['fReturnFolderID'], "<img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>"); | ||
| 53 | - } else if (KTUtil::arrayGet($_REQUEST, "fReturnDocumentID")) { | ||
| 54 | - $sToRender .= generateControllerLink("viewDocument", "fDocumentID=" . $_REQUEST['fReturnDocumentID'], "<img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>"); | ||
| 55 | - } else { | ||
| 56 | - $sToRender .= "<a href=\"javascript:history.go(-1)\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>"; | ||
| 57 | - } | ||
| 58 | - $sToRender .= "</td></tr></table></td>"; | ||
| 59 | - $sToRender .= "</tr>"; | ||
| 60 | - $sToRender .= "</table>\n"; | ||
| 61 | - | ||
| 62 | - return $sToRender; | ||
| 63 | - | ||
| 64 | -} | ||
| 65 | - | ||
| 66 | -function renderErrorPage($sErrorMessage, $iDocumentID = "") { | ||
| 67 | - global $default; | ||
| 68 | - if ($iDocumentID) { | ||
| 69 | - return statusPage("Delete Document", "", $sErrorMessage, "viewDocument", "fDocumentID=$iDocumentID"); | ||
| 70 | - } else { | ||
| 71 | - $sToRender = renderHeading(_("Delete Document")); | ||
| 72 | - $sToRender .= "<table>\n"; | ||
| 73 | - $sToRender .= "<tr><td><p class=\"errorText\">$sErrorMessage</p>\n" . | ||
| 74 | - "<a href=\"javascript:history.go(-2)\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"/></a>\n" . | ||
| 75 | - "</p></td></tr></table>\n"; | ||
| 76 | - return $sToRender; | ||
| 77 | - } | ||
| 78 | -} | ||
| 79 | -?> |