Commit bbe5cb78408f4b0a48da9e34b6c42dae90f9ba18
1 parent
5c535e88
Move document implemented as a document action.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4362 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
0 additions
and
321 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentBL.php deleted
| 1 | -<?php | ||
| 2 | -/** | ||
| 3 | - * $Id$ | ||
| 4 | - * | ||
| 5 | - * Move document page. | ||
| 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 Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | ||
| 25 | - * @package documentmanagement | ||
| 26 | - */ | ||
| 27 | - | ||
| 28 | -require_once("../../../../config/dmsDefaults.php"); | ||
| 29 | - | ||
| 30 | -KTUtil::extractGPC('fConfirmed', 'fDocumentIDs', 'fFolderID', 'fForMove', 'fRememberDocumentID'); | ||
| 31 | - | ||
| 32 | -require_once("$default->fileSystemRoot/lib/security/Permission.inc"); | ||
| 33 | -require_once("$default->fileSystemRoot/lib/users/User.inc"); | ||
| 34 | -require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); | ||
| 35 | -require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | ||
| 36 | -require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 37 | - | ||
| 38 | -require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | ||
| 39 | - | ||
| 40 | -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); | ||
| 41 | -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | ||
| 42 | - | ||
| 43 | -require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentUI.inc"); | ||
| 44 | -require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | ||
| 45 | -require_once("$default->fileSystemRoot/presentation/Html.inc"); | ||
| 46 | - | ||
| 47 | -require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); | ||
| 48 | - | ||
| 49 | -$aUnmovedDocs = array(); | ||
| 50 | - | ||
| 51 | -if (!checkSession()) { | ||
| 52 | - die(); | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -if (isset($fRememberDocumentID)) { | ||
| 56 | - $fDocumentIDs = $_SESSION['documents'][$fRememberDocumentID]; | ||
| 57 | -} else { | ||
| 58 | - $sUniqueID = KTUtil::randomString(); | ||
| 59 | - $_SESSION["documents"][$sUniqueID] = $fDocumentIDs; | ||
| 60 | - $fRememberDocumentID = $sUniqueID; | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | - | ||
| 64 | -if (!isset($fDocumentIDs) || !isset($fFolderID)) { | ||
| 65 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 66 | - $oPatternCustom = & new PatternCustom(); | ||
| 67 | - $oPatternCustom->setHtml(""); | ||
| 68 | - $main->setCentralPayload($oPatternCustom); | ||
| 69 | - $main->setErrorMessage(_("No document/folder selected")); | ||
| 70 | - $main->render(); | ||
| 71 | - exit(0); | ||
| 72 | -} | ||
| 73 | - | ||
| 74 | -if (!isset($fForMove)) { | ||
| 75 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 76 | - $oPatternCustom = & new PatternCustom(); | ||
| 77 | - $oPatternCustom->setHtml(getPage($fFolderID, $fRememberDocumentID)); | ||
| 78 | - $main->setCentralPayload($oPatternCustom); | ||
| 79 | - $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fRememberDocumentID=$fRememberDocumentID&fFolderID=$fFolderID"); | ||
| 80 | - $main->render(); | ||
| 81 | - exit(0); | ||
| 82 | -} | ||
| 83 | - | ||
| 84 | -if (!$fConfirmed) { | ||
| 85 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 86 | - $oPatternCustom = & new PatternCustom(); | ||
| 87 | - | ||
| 88 | - // Check for all docs | ||
| 89 | - for ($i = 0; $i < count($fDocumentIDs); $i++) { | ||
| 90 | - $oDocument = Document::get($fDocumentIDs[$i]); | ||
| 91 | - | ||
| 92 | - // check if the selected folder has the same document type as the document we're moving | ||
| 93 | - if (!Folder::folderIsLinkedToDocType($fFolderID, $oDocument->getDocumentTypeID())) { | ||
| 94 | - // the right document type isn't mapped | ||
| 95 | - $oPatternCustom->setHtml(getPage($fFolderID, $fRememberDocumentID, _("You can't move the document to this folder because it cannot store the document type of your document.") . " " . _("Please choose another directory"))); | ||
| 96 | - break; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - // check that there is no filename collision in the destination directory | ||
| 100 | - $sNewDocumentFileSystemPath = Folder::getFolderPath($fFolderID) . $oDocument->getFileName(); | ||
| 101 | - | ||
| 102 | - if (file_exists($sNewDocumentFileSystemPath)) { | ||
| 103 | - // filename collision | ||
| 104 | - $oPatternCustom->setHtml(getPage($fFolderID, $fRememberDocumentID, _("This folder already contains a document of the same name.") . " " . _("Please choose another directory"))); | ||
| 105 | - break; | ||
| 106 | - } | ||
| 107 | - // display confirmation page | ||
| 108 | - $oPatternCustom->setHtml(getConfirmationPage($fFolderID, $fRememberDocumentID)); | ||
| 109 | - } | ||
| 110 | - $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fRememberDocumentID=$fRememberDocumentID&fFolderID=$fFolderID"); | ||
| 111 | - $main->setCentralPayload($oPatternCustom); | ||
| 112 | - $main->render(); | ||
| 113 | - exit(0); | ||
| 114 | -} | ||
| 115 | - | ||
| 116 | -$oStorage =& KTStorageManagerUtil::getSingleton(); | ||
| 117 | - | ||
| 118 | -for ($i = 0; $i < count($fDocumentIDs); $i++) { | ||
| 119 | - | ||
| 120 | - //we're trying to move a document | ||
| 121 | - $oDocument = & Document::get($fDocumentIDs[$i]); | ||
| 122 | - $iOldFolderID = $oDocument->getFolderID(); | ||
| 123 | - $oOldFolder =& Folder::get($iOldFolderID); | ||
| 124 | - $oNewFolder = & Folder::get($fFolderID); | ||
| 125 | - | ||
| 126 | - // check that there is no filename collision in the destination directory | ||
| 127 | - $sNewDocumentFileSystemPath = Folder::getFolderPath($fFolderID) . $oDocument->getFileName(); | ||
| 128 | - | ||
| 129 | - if (file_exists($sNewDocumentFileSystemPath)) { | ||
| 130 | - // Store the doc with problem | ||
| 131 | - array_push($aUnmovedDocs, array($oDocument, _("This folder already contains a document of the same name. Please choose another directory"))); | ||
| 132 | - continue; | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | - if (!Permission::userHasDocumentWritePermission($oDocument) || !Permission::userHasFolderWritePermission($oNewFolder)) { | ||
| 136 | - array_push($aUnmovedDocs, array($oDocument, _("You do not have rights to move this document"))); | ||
| 137 | - continue; | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - //put the document in the new folder | ||
| 141 | - $oDocument->setFolderID($fFolderID); | ||
| 142 | - if (!$oDocument->update(true)) { | ||
| 143 | - //had a problem with the database | ||
| 144 | - array_push($aUnmovedDocs, array($oDocument, _("Could not update document in database"))); | ||
| 145 | - continue; | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - //move the document on the file system | ||
| 149 | - if (!$oStorage->moveDocument($oDocument, $oOldFolder, $oNewFolder)) { | ||
| 150 | - $oDocument->setFolderID($iOldFolderID); | ||
| 151 | - $oDocument->update(true); | ||
| 152 | - | ||
| 153 | - // Store the doc with problem | ||
| 154 | - array_push($aUnmovedDocs, array($oDocument, _("Could not move document on file system"))); | ||
| 155 | - continue; | ||
| 156 | - } | ||
| 157 | - $oDocument->update(); | ||
| 158 | - | ||
| 159 | - $sMoveMessage = sprintf("Moved from %s/%s to %s/%s", | ||
| 160 | - $oOldFolder->getFullPath(), | ||
| 161 | - $oOldFolder->getName(), | ||
| 162 | - $oNewFolder->getFullPath(), | ||
| 163 | - $oNewFolder->getName()); | ||
| 164 | - | ||
| 165 | - // create the document transaction record | ||
| 166 | - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $sMoveMessage, MOVE); | ||
| 167 | - $oDocumentTransaction->create(); | ||
| 168 | - | ||
| 169 | - // fire subscription alerts for the moved document (and the folder its in) | ||
| 170 | - $count = SubscriptionEngine::fireSubscription($fDocumentIDs[$i], SubscriptionConstants::subscriptionAlertType("MovedDocument"), | ||
| 171 | - SubscriptionConstants::subscriptionType("DocumentSubscription"), | ||
| 172 | - array( | ||
| 173 | - "folderID" => $iOldFolderID, | ||
| 174 | - "modifiedDocumentName" => $oDocument->getName(), | ||
| 175 | - "oldFolderName" => Folder::getFolderName($iOldFolderID), | ||
| 176 | - "newFolderName" => Folder::getFolderName($fFolderID), | ||
| 177 | - ) | ||
| 178 | - ); | ||
| 179 | - $default->log->info("moveDocumentBL.php fired $count subscription alerts for moved document " . $oDocument->getName()); | ||
| 180 | - | ||
| 181 | - // fire folder subscriptions for the destination folder | ||
| 182 | - $count = SubscriptionEngine::fireSubscription($fFolderID, SubscriptionConstants::subscriptionAlertType("MovedDocument"), | ||
| 183 | - SubscriptionConstants::subscriptionType("FolderSubscription"), | ||
| 184 | - array( | ||
| 185 | - "folderID" => $iOldFolderID, | ||
| 186 | - "modifiedDocumentName" => $oDocument->getName(), | ||
| 187 | - "oldFolderName" => Folder::getFolderName($iOldFolderID), | ||
| 188 | - "newFolderName" => Folder::getFolderName($fFolderID), | ||
| 189 | - ) | ||
| 190 | - ); | ||
| 191 | - $default->log->info("moveDocumentBL.php fired $count (folderID=$fFolderID) folder subscription alerts for moved document " . $oDocument->getName()); | ||
| 192 | -} | ||
| 193 | - | ||
| 194 | -// Move terminated | ||
| 195 | - | ||
| 196 | -// List undeleted documents | ||
| 197 | -if (!empty($aUnmovedDocs) ) { | ||
| 198 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 199 | - $oPatternCustom = & new PatternCustom(); | ||
| 200 | - | ||
| 201 | - $sError = _("An error occured moving the following document(s):") . " <br><br>"; | ||
| 202 | - foreach ($aUnmovedDocs as $oDoc) { | ||
| 203 | - $sError .= $oDoc[0]->getDisplayPath() . ": " .$oDoc[1] . "<br>"; | ||
| 204 | - } | ||
| 205 | - $sError .= "<br>" . _("The other documents are been moved."); | ||
| 206 | - | ||
| 207 | - $oPatternCustom = & new PatternCustom(); | ||
| 208 | - $oPatternCustom->setHtml(renderErrorPage($sError)); | ||
| 209 | - $main->setCentralPayload($oPatternCustom); | ||
| 210 | - $main->render(); | ||
| 211 | - reset($aUnmovedDocs); | ||
| 212 | - exit(0); | ||
| 213 | -} | ||
| 214 | - | ||
| 215 | -// redirect to the browse folder page | ||
| 216 | -redirect("$default->rootUrl/control.php?action=browse&fFolderID=" . $oDocument->getFolderID()); | ||
| 217 | - | ||
| 218 | -?> |
presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentUI.inc deleted
| 1 | -<?php | ||
| 2 | -/** | ||
| 3 | - * $Id$ | ||
| 4 | - * | ||
| 5 | - * Move document presentation functions. | ||
| 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 Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | ||
| 25 | - * @package documentmanagement | ||
| 26 | - */ | ||
| 27 | - | ||
| 28 | -function getConfirmationPage($iFolderID, $sRememberDocumentID) { | ||
| 29 | - global $default; | ||
| 30 | - $iDocumentIDs = $_SESSION['documents'][$sRememberDocumentID]; | ||
| 31 | - | ||
| 32 | - $sToRender = renderHeading(_("Move Document")); | ||
| 33 | - $sToRender .= "<table>\n"; | ||
| 34 | - $sToRender .= "<tr>\n<td>" . _("Are you sure you want to move") . ": </td></tr>"; | ||
| 35 | - | ||
| 36 | - for ($i = 0; $i < count($iDocumentIDs); $i++) { | ||
| 37 | - | ||
| 38 | - $oDocument = & Document::get($iDocumentIDs[$i]); | ||
| 39 | - | ||
| 40 | - $sToRender .= "<tr><td><strong>" . $oDocument->getDisplayPath() . "</strong> <td> " . _("to") . " </td> </td>\n"; | ||
| 41 | - $sToRender .= "<td><strong>" . Folder::getFolderDisplayPath($iFolderID) . " > " . $oDocument->getFileName() . "</strong></td>\n"; | ||
| 42 | - } | ||
| 43 | - $sQueryString .= "fRememberDocumentID=$sRememberDocumentID&"; | ||
| 44 | - | ||
| 45 | - $sToRender .= "</tr>\n"; | ||
| 46 | - $sToRender .= "<tr><td><a href=\"$default->rootUrl/control.php?action=moveDocument&" . $sQueryString . | ||
| 47 | - "fFolderID=$iFolderID" . | ||
| 48 | - "&fForMove=1&fConfirmed=1\">" . | ||
| 49 | - "<img src=\"" . KTHtml::getMoveButton() . "\" border=\"0\"/>" . | ||
| 50 | - "</a> " . | ||
| 51 | - "<a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$iFolderID\">" . | ||
| 52 | - "<img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a></td></tr>\n"; | ||
| 53 | - $sToRender .= "</table>\n"; | ||
| 54 | - return $sToRender; | ||
| 55 | -} | ||
| 56 | - | ||
| 57 | - | ||
| 58 | -function getPage($iFolderID, $sRememberDocumentID, $sErrorMessage = "") { | ||
| 59 | - global $default; | ||
| 60 | - $iDocumentIDs = $_SESSION['documents'][$sRememberDocumentID]; | ||
| 61 | - | ||
| 62 | - $sToRender = renderHeading(_("Move Document")); | ||
| 63 | - $sToRender .= "<table>\n"; | ||
| 64 | - if ($sErrorMessage) { | ||
| 65 | - $sToRender .= "<tr><td><font color=\"red\">$sErrorMessage</font></td></tr>"; | ||
| 66 | - } | ||
| 67 | - $sToRender .= "<tr><td>" . _("Move document(s)") . ":<br></td>\n"; | ||
| 68 | - | ||
| 69 | - for ($i = 0; $i < count($iDocumentIDs); $i++) { | ||
| 70 | - $sToRender .= "<tr>\n"; | ||
| 71 | - $sToRender .= "<td> '" . Document::getDocumentDisplayPath($iDocumentIDs[$i]) . "'</td>\n"; | ||
| 72 | - } | ||
| 73 | - $sQueryString .= "fRememberDocumentID=$sRememberDocumentID&"; | ||
| 74 | - | ||
| 75 | - $sToRender .= "<tr><td>" . _("To Folder") . ":</td></tr>"; | ||
| 76 | - $sToRender .= "<tr>\n"; | ||
| 77 | - $sToRender .= "<td>" . renderFolderPath($iFolderID, "/control.php?action=moveDocument&" . $sQueryString) . "</td>\n"; | ||
| 78 | - $sToRender .= "</tr>\n"; | ||
| 79 | - $sToRender .= "</table>\n"; | ||
| 80 | - $sToRender .= "<table width=\"100%\">\n"; | ||
| 81 | - $sToRender .= "<tr>\n"; | ||
| 82 | - $sToRender .= "<td>" . renderFolderList($iFolderID, "/control.php?action=moveDocument&" . $sQueryString) . "</td>\n"; | ||
| 83 | - $sToRender .= "</tr>\n"; | ||
| 84 | - $sToRender .= "<td><table><tr><td><a href=\"" . $_SERVER["PHP_SELF"] . "?$sQueryString&fFolderID=$iFolderID&fForMove=1\"><img src=\"" . KTHtml::getMoveHereButton() . "\" border=\"0\"></a></td> <td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$iFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a></td></tr></table></td>"; | ||
| 85 | - | ||
| 86 | - $sToRender .= "</table>\n"; | ||
| 87 | - return $sToRender; | ||
| 88 | -} | ||
| 89 | -function renderErrorPage($sErrorMessage, $iDocumentID = "") { | ||
| 90 | - global $default; | ||
| 91 | - if ($iDocumentID) { | ||
| 92 | - return statusPage(_("Delete Document"), "", $sErrorMessage, "viewDocument", "fDocumentID=$iDocumentID"); | ||
| 93 | - } else { | ||
| 94 | - $sToRender = renderHeading(_("Delete Document")); | ||
| 95 | - $sToRender .= "<table>\n"; | ||
| 96 | - $sToRender .= "<tr><td><p class=\"errorText\">$sErrorMessage</p>\n" . | ||
| 97 | - "<a href=\"javascript:history.go(-2)\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"/></a>\n" . | ||
| 98 | - "</p></td></tr></table>\n"; | ||
| 99 | - return $sToRender; | ||
| 100 | - } | ||
| 101 | -} | ||
| 102 | - | ||
| 103 | -?> |