Commit 90e903ca07d21d5325cfd3b2b98482c09ba135de
1 parent
2303cdf2
Implement document move using the action framework.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4092 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
247 additions
and
12 deletions
plugins/ktcore/KTDocumentActions.php
| @@ -230,6 +230,7 @@ class KTDocumentDeleteAction extends KTDocumentAction { | @@ -230,6 +230,7 @@ class KTDocumentDeleteAction extends KTDocumentAction { | ||
| 230 | } | 230 | } |
| 231 | return true; | 231 | return true; |
| 232 | } | 232 | } |
| 233 | + | ||
| 233 | function do_main() { | 234 | function do_main() { |
| 234 | $this->oPage->setBreadcrumbDetails("delete"); | 235 | $this->oPage->setBreadcrumbDetails("delete"); |
| 235 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/delete'); | 236 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/delete'); |
| @@ -248,6 +249,8 @@ class KTDocumentDeleteAction extends KTDocumentAction { | @@ -248,6 +249,8 @@ class KTDocumentDeleteAction extends KTDocumentAction { | ||
| 248 | $sReason = KTUtil::arrayGet($_REQUEST, 'reason'); | 249 | $sReason = KTUtil::arrayGet($_REQUEST, 'reason'); |
| 249 | $this->oValidator->notEmpty($sReason); | 250 | $this->oValidator->notEmpty($sReason); |
| 250 | 251 | ||
| 252 | + $this->startTransaction(); | ||
| 253 | + | ||
| 251 | // flip the status id | 254 | // flip the status id |
| 252 | $this->oDocument->setStatusID(DELETED); | 255 | $this->oDocument->setStatusID(DELETED); |
| 253 | 256 | ||
| @@ -303,31 +306,203 @@ class KTDocumentDeleteAction extends KTDocumentAction { | @@ -303,31 +306,203 @@ class KTDocumentDeleteAction extends KTDocumentAction { | ||
| 303 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete'); | 306 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete'); |
| 304 | // }}} | 307 | // }}} |
| 305 | 308 | ||
| 306 | -class KTDocumentMoveAction extends KTBuiltInDocumentActionSingle { | 309 | +require_once(KT_LIB_DIR . "/browse/DocumentCollection.inc.php"); |
| 310 | +require_once(KT_LIB_DIR . "/browse/BrowseColumns.inc.php"); | ||
| 311 | +require_once(KT_LIB_DIR . "/browse/PartialQuery.inc.php"); | ||
| 312 | +class KTDocumentMoveColumn extends TitleColumn { | ||
| 313 | + function KTDocumentMoveColumn($sLabel, $sName, $oDocument) { | ||
| 314 | + $this->oDocument = $oDocument; | ||
| 315 | + parent::TitleColumn($sLabel, $sName); | ||
| 316 | + } | ||
| 317 | + function buildFolderLink($aDataRow) { | ||
| 318 | + $baseurl = KTUtil::arrayGet($this->aOptions, "folderurl", ""); | ||
| 319 | + return sprintf('%s?fDocumentId=%d&fFolderId=%d', $baseurl, $this->oDocument->getId(), $aDataRow["folder"]->getId()); | ||
| 320 | + } | ||
| 321 | +} | ||
| 322 | + | ||
| 323 | +// {{{ KTDocumentMoveAction | ||
| 324 | +class KTDocumentMoveAction extends KTDocumentAction { | ||
| 307 | var $sBuiltInAction = 'moveDocument'; | 325 | var $sBuiltInAction = 'moveDocument'; |
| 308 | var $sDisplayName = 'Move'; | 326 | var $sDisplayName = 'Move'; |
| 309 | var $sName = 'ktcore.actions.document.move'; | 327 | var $sName = 'ktcore.actions.document.move'; |
| 310 | 328 | ||
| 311 | - var $_sDisablePermission = "ktcore.permissions.write"; | 329 | + var $_sShowPermission = "ktcore.permissions.write"; |
| 312 | 330 | ||
| 313 | - function _disable() { | ||
| 314 | - if ($this->oDocument->getIsCheckedOut()) { | ||
| 315 | - $this->_sDisabledText = _("This document can't be deleted because its checked out"); | ||
| 316 | - return true; | ||
| 317 | - } | ||
| 318 | - return parent::_disable(); | 331 | + function getInfo() { |
| 332 | + if ($this->oDocument->getIsCheckedOut()) { | ||
| 333 | + return null; | ||
| 334 | + } | ||
| 335 | + return parent::getInfo(); | ||
| 319 | } | 336 | } |
| 320 | 337 | ||
| 338 | + function check() { | ||
| 339 | + $res = parent::check(); | ||
| 340 | + if ($res !== true) { | ||
| 341 | + return $res; | ||
| 342 | + } | ||
| 343 | + if ($this->oDocument->getIsCheckedOut()) { | ||
| 344 | + $_SESSION["KTErrorMessage"][]= _("This document can't be deleted because it is checked out"); | ||
| 345 | + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); | ||
| 346 | + exit(0); | ||
| 347 | + } | ||
| 348 | + $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', $this->oDocument->getFolderId()); | ||
| 349 | + $this->oFolder = $this->oValidator->validateFolder($iFolderId); | ||
| 350 | + $this->oDocumentFolder = $this->oValidator->validateFolder($this->oDocument->getFolderId()); | ||
| 351 | + return true; | ||
| 352 | + } | ||
| 353 | + | ||
| 354 | + /* | ||
| 321 | function getURL() { | 355 | function getURL() { |
| 322 | return sprintf("/control.php?action=%s&fDocumentIDs[]=%d&fReturnDocumentID=%d&fFolderID=%d", $this->sBuiltInAction, $this->oDocument->getID(), $this->oDocument->getID(), $this->oDocument->getFolderID()); | 356 | return sprintf("/control.php?action=%s&fDocumentIDs[]=%d&fReturnDocumentID=%d&fFolderID=%d", $this->sBuiltInAction, $this->oDocument->getID(), $this->oDocument->getID(), $this->oDocument->getFolderID()); |
| 323 | } | 357 | } |
| 358 | + */ | ||
| 359 | + | ||
| 360 | + function do_main() { | ||
| 361 | + $this->oPage->setBreadcrumbDetails("move"); | ||
| 362 | + $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/move'); | ||
| 363 | + $move_fields = array(); | ||
| 364 | + $aNames = $this->oDocumentFolder->getPathArray(); | ||
| 365 | + $aNames[] = $this->oDocument->getName(); | ||
| 366 | + $sDocumentName = join(" » ", $aNames); | ||
| 367 | + $move_fields[] = new KTStaticTextWidget('Document to move', '', 'fDocumentId', $sDocumentName, $this->oPage, false); | ||
| 368 | + | ||
| 369 | + $collection = new DocumentCollection(); | ||
| 370 | + $collection->addColumn(new KTDocumentMoveColumn("Test 1 (title)","title", $this->oDocument)); | ||
| 371 | + $qObj = new FolderBrowseQuery($this->oFolder->getId()); | ||
| 372 | + $collection->setQueryObject($qObj); | ||
| 373 | + | ||
| 374 | + $batchPage = (int) KTUtil::arrayGet($_REQUEST, "page", 0); | ||
| 375 | + $batchSize = 20; | ||
| 376 | + | ||
| 377 | + $resultURL = sprintf("?fDocumentId=%d&fFolderId=%d", $this->oDocument->getId(), $this->oFolder->getId()); | ||
| 378 | + $collection->setBatching($resultURL, $batchPage, $batchSize); | ||
| 379 | + | ||
| 380 | + // ordering. (direction and column) | ||
| 381 | + $displayOrder = KTUtil::arrayGet($_REQUEST, 'sort_order', "asc"); | ||
| 382 | + if ($displayOrder !== "asc") { $displayOrder = "desc"; } | ||
| 383 | + $displayControl = KTUtil::arrayGet($_REQUEST, 'sort_on', "title"); | ||
| 384 | + | ||
| 385 | + $collection->setSorting($displayControl, $displayOrder); | ||
| 386 | + | ||
| 387 | + $collection->getResults(); | ||
| 388 | + | ||
| 389 | + $aBreadcrumbs = array(); | ||
| 390 | + $folder_path_names = $this->oFolder->getPathArray(); | ||
| 391 | + $folder_path_ids = explode(',', $this->oFolder->getParentFolderIds()); | ||
| 392 | + if ($folder_path_ids[0] == 0) { | ||
| 393 | + $folder_path_ids = array(); | ||
| 394 | + } | ||
| 395 | + $folder_path_ids[] = $this->oFolder->getId(); | ||
| 396 | + | ||
| 397 | + foreach (range(0, count($folder_path_ids) - 1) as $index) { | ||
| 398 | + $id = $folder_path_ids[$index]; | ||
| 399 | + $url = sprintf("?fDocumentId=%d&fFolderId=%d", $this->oDocument->getId(), $id); | ||
| 400 | + $aBreadcrumbs[] = array("url" => $url, "name" => $folder_path_names[$index]); | ||
| 401 | + } | ||
| 402 | + | ||
| 403 | + $oTemplate->setData(array( | ||
| 404 | + 'context' => &$this, | ||
| 405 | + 'move_fields' => $move_fields, | ||
| 406 | + 'collection' => $collection, | ||
| 407 | + 'collection_breadcrumbs' => $aBreadcrumbs, | ||
| 408 | + )); | ||
| 409 | + return $oTemplate->render(); | ||
| 410 | + } | ||
| 411 | + | ||
| 412 | + function do_move() { | ||
| 413 | + $this->oPage->setBreadcrumbDetails("move"); | ||
| 414 | + $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/move_final'); | ||
| 415 | + $sFolderPath = join(" » ", $this->oFolder->getPathArray()); | ||
| 416 | + $aNames = $this->oDocumentFolder->getPathArray(); | ||
| 417 | + $aNames[] = $this->oDocument->getName(); | ||
| 418 | + $sDocumentName = join(" » ", $aNames); | ||
| 419 | + $move_fields = array(); | ||
| 420 | + $move_fields[] = new KTStaticTextWidget('Document to move', '', 'fDocumentId', $sDocumentName, $this->oPage, false); | ||
| 421 | + $move_fields[] = new KTStaticTextWidget('Target folder', '', 'fFolderId', $sFolderPath, $this->oPage, false); | ||
| 422 | + $move_fields[] = new KTStringWidget('Reason', 'The reason for this document to be moved.', 'reason', "", $this->oPage, true); | ||
| 423 | + | ||
| 424 | + $oTemplate->setData(array( | ||
| 425 | + 'context' => &$this, | ||
| 426 | + 'move_fields' => $move_fields, | ||
| 427 | + )); | ||
| 428 | + return $oTemplate->render(); | ||
| 429 | + } | ||
| 430 | + | ||
| 431 | + function do_move_final() { | ||
| 432 | + $sReason = KTUtil::arrayGet($_REQUEST, 'reason'); | ||
| 433 | + $aOptions = array( | ||
| 434 | + 'message' => "No reason given", | ||
| 435 | + 'redirect_to' => array('move', sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId())), | ||
| 436 | + ); | ||
| 437 | + $this->oValidator->notEmpty($sReason, $aOptions); | ||
| 438 | + | ||
| 439 | + if (!Permission::userHasFolderWritePermission($this->oFolder)) { | ||
| 440 | + $this->errorRedirectTo("main", "You do not have permission to move a document to this location", sprintf("fDocumentId=%d&fFolderId=%d", $this->oDocument->getId(), $this->oFolder->getId())); | ||
| 441 | + exit(0); | ||
| 442 | + } | ||
| 443 | + | ||
| 444 | + $this->startTransaction(); | ||
| 445 | + | ||
| 446 | + //put the document in the new folder | ||
| 447 | + $this->oDocument->setFolderID($this->oFolder->getId()); | ||
| 448 | + if (!$this->oDocument->update(true)) { | ||
| 449 | + $this->errorRedirectTo("main", "There was a problem updating the document's location in the database", sprintf("fDocumentId=%d&fFolderId=%d", $this->oDocument->getId(), $this->oFolder->getId())); | ||
| 450 | + } | ||
| 451 | + | ||
| 452 | + //move the document on the file system | ||
| 453 | + $oStorage =& KTStorageManagerUtil::getSingleton(); | ||
| 454 | + if (!$oStorage->moveDocument($this->oDocument, $this->oDocumentFolder, $this->oFolder)) { | ||
| 455 | + $this->oDocument->setFolderID($this->oDocumentFolder->getId()); | ||
| 456 | + $this->oDocument->update(true); | ||
| 457 | + errorRedirectTo("move", "There was a problem updating the document's location in the repository storage", sprintf("fDocumentId=%d&fFolderId=%d", $this->oDocument->getId(), $this->oFolder->getId())); | ||
| 458 | + } | ||
| 459 | + $this->oDocument->update(); | ||
| 460 | + | ||
| 461 | + $sMoveMessage = sprintf("Moved from %s/%s to %s/%s: %s", | ||
| 462 | + $this->oDocumentFolder->getFullPath(), | ||
| 463 | + $this->oDocumentFolder->getName(), | ||
| 464 | + $this->oFolder->getFullPath(), | ||
| 465 | + $this->oFolder->getName(), | ||
| 466 | + $sReason); | ||
| 467 | + | ||
| 468 | + // create the document transaction record | ||
| 469 | + $oDocumentTransaction = & new DocumentTransaction($this->oDocument->getID(), $sMoveMessage, MOVE); | ||
| 470 | + $oDocumentTransaction->create(); | ||
| 471 | + | ||
| 472 | + $this->commitTransaction(); | ||
| 473 | + | ||
| 474 | + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | ||
| 475 | + $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate'); | ||
| 476 | + foreach ($aTriggers as $aTrigger) { | ||
| 477 | + $sTrigger = $aTrigger[0]; | ||
| 478 | + $oTrigger = new $sTrigger; | ||
| 479 | + $aInfo = array( | ||
| 480 | + "document" => $this->oDocument, | ||
| 481 | + "old_folder" => $this->oDocumentFolder, | ||
| 482 | + "new_folder" => $this->oFolder, | ||
| 483 | + ); | ||
| 484 | + $oTrigger->setInfo($aInfo); | ||
| 485 | + $ret = $oTrigger->postValidate(); | ||
| 486 | + if (PEAR::isError($ret)) { | ||
| 487 | + $this->oDocument->delete(); | ||
| 488 | + return $ret; | ||
| 489 | + } | ||
| 490 | + } | ||
| 491 | + | ||
| 492 | + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); | ||
| 493 | + exit(0); | ||
| 494 | + } | ||
| 324 | } | 495 | } |
| 325 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentMoveAction', 'ktcore.actions.document.move'); | 496 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentMoveAction', 'ktcore.actions.document.move'); |
| 497 | +// }}} | ||
| 326 | 498 | ||
| 327 | -class KTDocumentHistoryAction extends KTBuiltInDocumentAction { | ||
| 328 | - var $sBuiltInAction = 'viewHistory'; | 499 | +class KTDocumentHistoryAction extends KTDocumentAction { |
| 329 | var $sDisplayName = 'History'; | 500 | var $sDisplayName = 'History'; |
| 330 | var $sName = 'ktcore.actions.document.history'; | 501 | var $sName = 'ktcore.actions.document.history'; |
| 502 | + | ||
| 503 | + function getURL() { | ||
| 504 | + return generateControllerLink("viewDocument", sprintf("action=history&fDocumentId=%d", $this->oDocument->getID())); | ||
| 505 | + } | ||
| 331 | } | 506 | } |
| 332 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentHistoryAction', 'ktcore.actions.document.history'); | 507 | $oKTActionRegistry->registerAction('documentaction', 'KTDocumentHistoryAction', 'ktcore.actions.document.history'); |
| 333 | 508 | ||
| @@ -376,8 +551,7 @@ class KTDocumentPublishAction extends KTDocumentAction { | @@ -376,8 +551,7 @@ class KTDocumentPublishAction extends KTDocumentAction { | ||
| 376 | var $sName = 'ktcore.actions.document.publish'; | 551 | var $sName = 'ktcore.actions.document.publish'; |
| 377 | 552 | ||
| 378 | function _disable() { | 553 | function _disable() { |
| 379 | - $oDocument =& $this->oDocument; | ||
| 380 | - if ($oDocument->getIsCheckedOut()) { | 554 | + if ($this->oDocument->getIsCheckedOut()) { |
| 381 | $this->_sDisabledText = _("This document is checked out and cannot be archived."); | 555 | $this->_sDisabledText = _("This document is checked out and cannot be archived."); |
| 382 | return true; | 556 | return true; |
| 383 | } | 557 | } |
templates/ktcore/action/move.smarty
0 → 100644
| 1 | +<p class="descriptiveText">Moving a document relocates the document | ||
| 2 | +within the document repository.</p> | ||
| 3 | + | ||
| 4 | +{assign var=iDocumentId value=$context->oDocument->getId()} | ||
| 5 | +<p class="descriptiveText">If you do not intend to move this document, you should | ||
| 6 | +<a href="{"viewDocument"|generateControllerUrl:"fDocumentId=$iDocumentId"}">cancel | ||
| 7 | +the move</a>.</p> | ||
| 8 | + | ||
| 9 | +<form method="POST" action="{$smarty.server.PHP_SELF}"> | ||
| 10 | +<fieldset><legend>Move</legend> | ||
| 11 | +<input type="hidden" name="action" value="move" /> | ||
| 12 | +<input type="hidden" name="fDocumentId" value="{$iDocumentId}" /> | ||
| 13 | +{foreach from=$move_fields item=oWidget } | ||
| 14 | + {$oWidget->render()} | ||
| 15 | +{/foreach} | ||
| 16 | + | ||
| 17 | +<div class="field "> | ||
| 18 | +<label for="fFolderId">Target folder</label> | ||
| 19 | +<p class="descriptiveText">The folder given below is where the document | ||
| 20 | +is going to be moved to. Use the folder collection and path below to | ||
| 21 | +browse to the folder you wish to move the documents into.</p> | ||
| 22 | + | ||
| 23 | +<input type="hidden" name="fFolderId" value="{$context->oFolder->getId()}" /> | ||
| 24 | +{foreach from=$collection_breadcrumbs item=breadcrumb name=bc} | ||
| 25 | +<a href="{$breadcrumb.url}">{$breadcrumb.name}</a> | ||
| 26 | +{if !$smarty.foreach.bc.last} | ||
| 27 | +» | ||
| 28 | +{/if} | ||
| 29 | +{/foreach} | ||
| 30 | +{$collection->render()} | ||
| 31 | +</div> | ||
| 32 | + | ||
| 33 | +<div class="form_actions"> | ||
| 34 | +<input type="submit" name="submit[move]" value="Move" /> | ||
| 35 | +<input type="submit" name="submit[cancel]" value="Cancel" /> | ||
| 36 | +</div> | ||
| 37 | +</fieldset> | ||
| 38 | +</form> |
templates/ktcore/action/move_final.smarty
0 → 100644
| 1 | +<p class="descriptiveText">Moving a document relocates the document | ||
| 2 | +within the document repository.</p> | ||
| 3 | + | ||
| 4 | +{assign var=iDocumentId value=$context->oDocument->getId()} | ||
| 5 | +<p class="descriptiveText">If you do not intend to move this document, you should | ||
| 6 | +<a href="{"viewDocument"|generateControllerUrl:"fDocumentId=$iDocumentId"}">cancel | ||
| 7 | +the move</a>.</p> | ||
| 8 | + | ||
| 9 | +<form method="POST" action="{$smarty.server.PHP_SELF}"> | ||
| 10 | +<fieldset><legend>Move</legend> | ||
| 11 | +<input type="hidden" name="action" value="move_final" /> | ||
| 12 | +<input type="hidden" name="fDocumentId" value="{$iDocumentId}" /> | ||
| 13 | +<input type="hidden" name="fFolderId" value="{$context->oFolder->getId()}" /> | ||
| 14 | +{foreach from=$move_fields item=oWidget } | ||
| 15 | + {$oWidget->render()} | ||
| 16 | +{/foreach} | ||
| 17 | + | ||
| 18 | +<div class="form_actions"> | ||
| 19 | +<input type="submit" name="submit[move]" value="Move" /> | ||
| 20 | +<input type="submit" name="submit[cancel]" value="Cancel" /> | ||
| 21 | +</div> | ||
| 22 | +</fieldset> | ||
| 23 | +</form> |