Commit 51a456b8bf568aaca1398f5977dae67a2515e9e6

Authored by Brad Shuttleworth
1 parent 75594cb5

fix for KTS-1320: copy or move needs cancel buttons that work.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5975 c91229c3-7414-0410-bfa2-8a42b809f60b
browse.php
@@ -439,7 +439,8 @@ class BrowseDispatcher extends KTStandardDispatcher { @@ -439,7 +439,8 @@ class BrowseDispatcher extends KTStandardDispatcher {
439 array('label' => _kt('Target Folder'), 439 array('label' => _kt('Target Folder'),
440 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to move the documents into.'), 440 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to move the documents into.'),
441 'required' => true, 441 'required' => true,
442 - 'name' => 'browse', 442 + 'name' => 'fFolderId',
  443 + 'broken_name' => true,
443 'folder_id' => $oFolder->getId(), 444 'folder_id' => $oFolder->getId(),
444 'collection' => $collection)); 445 'collection' => $collection));
445 446
@@ -544,7 +545,8 @@ class BrowseDispatcher extends KTStandardDispatcher { @@ -544,7 +545,8 @@ class BrowseDispatcher extends KTStandardDispatcher {
544 'folder' => $target_folder, 545 'folder' => $target_folder,
545 'move_code' => $move_code, 546 'move_code' => $move_code,
546 'folders' => $folderStr, 547 'folders' => $folderStr,
547 - 'documents' => $documentStr, 548 + 'documents' => $documentStr,
  549 +
548 ); 550 );
549 return $oTemplate->render($aTemplateData); 551 return $oTemplate->render($aTemplateData);
550 } 552 }
plugins/ktcore/KTDocumentActions.php
@@ -795,7 +795,7 @@ class KTDocumentMoveAction extends KTDocumentAction { @@ -795,7 +795,7 @@ class KTDocumentMoveAction extends KTDocumentAction {
795 return $res; 795 return $res;
796 } 796 }
797 if ($this->oDocument->getIsCheckedOut()) { 797 if ($this->oDocument->getIsCheckedOut()) {
798 - $_SESSION["KTErrorMessage"][]= _kt("This document can't be deleted because it is checked out"); 798 + $_SESSION["KTErrorMessage"][]= _kt("This document can't be moved because it is checked out");
799 controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); 799 controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
800 exit(0); 800 exit(0);
801 } 801 }
@@ -807,179 +807,163 @@ class KTDocumentMoveAction extends KTDocumentAction { @@ -807,179 +807,163 @@ class KTDocumentMoveAction extends KTDocumentAction {
807 } 807 }
808 808
809 function do_main() { 809 function do_main() {
810 - $this->oPage->setBreadcrumbDetails(_kt("move"));  
811 - $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/move');  
812 - $move_fields = array();  
813 - $aNames = $this->oDocumentFolder->getPathArray();  
814 - $aNames[] = $this->oDocument->getName();  
815 - $sDocumentName = join(" » ", $aNames);  
816 - $move_fields[] = new KTStaticTextWidget(_kt('Document to move'), '', 'fDocumentId', $sDocumentName, $this->oPage, false);  
817 -  
818 - $collection = new AdvancedCollection();  
819 - $oCR =& KTColumnRegistry::getSingleton();  
820 - $col = $oCR->getColumn('ktcore.columns.title');  
821 - $col->setOptions(array('qs_params'=>array('fMoveCode'=>$sMoveCode,  
822 - 'fFolderId'=>$oFolder->getId(),  
823 - 'action'=>'startMove')));  
824 - $collection->addColumn($col);  
825 -  
826 - $qObj = new FolderBrowseQuery($this->oFolder->getId());  
827 - $collection->setQueryObject($qObj);  
828 -  
829 - $aOptions = $collection->getEnvironOptions();  
830 - $collection->setOptions($aOptions);  
831 -  
832 - $oWF =& KTWidgetFactory::getSingleton();  
833 - $oWidget = $oWF->get('ktcore.widgets.collection',  
834 - array('label' => _kt('Target Folder'),  
835 - 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to move the documents into.'),  
836 - 'required' => true,  
837 - 'name' => 'browse',  
838 - 'folder_id' => $oFolder->getId(),  
839 - 'collection' => $collection));  
840 - $move_fields[] = $oWidget;  
841 -  
842 - $oTemplate->setData(array(  
843 - 'context' => &$this,  
844 - 'move_fields' => $move_fields,  
845 - //'collection' => $collection,  
846 - //'collection_breadcrumbs' => $aBreadcrumbs,  
847 - ));  
848 - return $oTemplate->render(); 810 + $oForm = $this->form_move();
  811 + return $oForm->renderPage();
849 } 812 }
850 813
851 function form_move() { 814 function form_move() {
852 $oForm = new KTForm; 815 $oForm = new KTForm;
853 $oForm->setOptions(array( 816 $oForm->setOptions(array(
854 - 'label' => _kt("Move Document"),  
855 - 'action' => 'move_final',  
856 - 'fail_action' => 'move', 817 + 'label' => sprintf(_kt("Move Document \"%s\""), $this->oDocument->getName()),
  818 + 'submit_label' => _kt("Move"),
  819 + 'identifier' => 'ktcore.actions.movedoc',
  820 + 'action' => 'move',
857 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 821 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
858 - 'submit_label' => _kt("Move Document"),  
859 - 'context' => &$this,  
860 - )); 822 + 'fail_action' => 'main',
  823 + 'context' => $this,
  824 + ));
  825 +
  826 + /*
  827 + * This is somewhat more complex than most forms, since the "filename"
  828 + * and title shouldn't appear unless there's a clash.
  829 + *
  830 + * This is still not the most elegant solution.
  831 + */
  832 +
861 $oForm->setWidgets(array( 833 $oForm->setWidgets(array(
  834 + array('ktcore.widgets.foldercollection', array(
  835 + 'label' => _kt('Target Folder'),
  836 + 'description' => _kt('Use the folder collection and path below select the folder into which you wish to move the document.'),
  837 + 'required' => true,
  838 + 'name' => 'browse',
  839 + 'folder_id' => $this->oDocument->getFolderID(),
  840 + )),
862 array('ktcore.widgets.reason', array( 841 array('ktcore.widgets.reason', array(
863 'label' => _kt("Reason"), 842 'label' => _kt("Reason"),
864 - 'description' => _kt("Please specify why you are moving this document. Please bear in mind that you can use a maximum of <strong>250</strong> characters."), 843 + 'description' => _kt("Please specify why you are moving this document. Bear in mind that you can use a maximum of <strong>250</strong> characters."),
865 'name' => 'reason', 844 'name' => 'reason',
866 )), 845 )),
867 )); 846 ));
  847 +
  848 +
868 $oForm->setValidators(array( 849 $oForm->setValidators(array(
869 array('ktcore.validators.string', array( 850 array('ktcore.validators.string', array(
870 'test' => 'reason', 851 'test' => 'reason',
871 'max_length' => 250, 852 'max_length' => 250,
872 'output' => 'reason', 853 'output' => 'reason',
873 )), 854 )),
874 - )); 855 + array('ktcore.validators.entity', array(
  856 + 'class' => 'Folder',
  857 + 'test' => 'browse',
  858 + 'output' => 'browse',
  859 + )),
  860 + ));
  861 +
  862 + // here's the ugly bit.
875 863
876 - return $oForm;  
877 - }  
878 -  
879 - function do_move() {  
880 - $this->persistParams(array('fFolderId'));  
881 -  
882 - $this->oPage->setBreadcrumbDetails(_kt("Move"));  
883 - $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/move_final'); 864 + $err = $oForm->getErrors();
  865 + if (!empty($err['name']) || !empty($err['filename'])) {
  866 + $oForm->addWidget(
  867 + array('ktcore.widgets.string', array(
  868 + 'label' => _kt("Document Title"),
  869 + 'value' => $this->oDocument->getName(),
  870 + 'important_description' => _kt("Please indicate a new title to use to resolve any title conflicts."),
  871 + 'name' => 'name',
  872 + 'required' => true,
  873 + ))
  874 + );
  875 + $oForm->addValidator(
  876 + array('ktcore.validators.string', array(
  877 + 'output' => 'name',
  878 + 'test' => 'name'
  879 + ))
  880 + );
884 881
885 - if($this->oDocument->getFolderId() === $this->oFolder->getId()) {  
886 - $this->errorRedirectTo('main', _kt("The document was already in this folder"), sprintf("fDocumentId=%d&fFolderId=%d", $this->oDocument->getId(), $this->oFolder->getId()));  
887 - exit(0); 882 + $oForm->addWidget(
  883 + array('ktcore.widgets.string', array(
  884 + 'label' => _kt("Filename"),
  885 + 'value' => $this->oDocument->getFilename(),
  886 + 'important_description' => _kt("Please indicate a new filename to use to resolve any conflicts."),
  887 + 'name' => 'filename',
  888 + 'required' => true,
  889 + ))
  890 + );
  891 + $oForm->addValidator(
  892 + array('ktcore.validators.string', array(
  893 + 'output' => 'filename',
  894 + 'test' => 'filename'
  895 + ))
  896 + );
888 } 897 }
  898 + return $oForm;
  899 + }
889 900
  901 + function do_move() {
890 $oForm = $this->form_move(); 902 $oForm = $this->form_move();
891 -  
892 - //$sFolderPath = join(" &raquo; ", $this->oFolder->getPathArray());  
893 - //$aNames = $this->oDocumentFolder->getPathArray();  
894 - //$aNames[] = $this->oDocument->getName();  
895 - //$sDocumentName = join(" &raquo; ", $aNames);  
896 -  
897 - $oTemplate->setData(array(  
898 - 'context' => &$this,  
899 - 'form' => $oForm,  
900 - ));  
901 - return $oTemplate->render();  
902 - }  
903 -  
904 - function do_move_final() {  
905 - $oForm = $this->form_move();  
906 $res = $oForm->validate(); 903 $res = $oForm->validate();
  904 + $errors = $res['errors'];
907 $data = $res['results']; 905 $data = $res['results'];
908 - if (!empty($res['errors'])) {  
909 - return $oForm->handleError(); 906 + $extra_errors = array();
  907 +
  908 + if (!is_null($data['browse'])) {
  909 + if ($data['browse']->getId() == $this->oDocument->getFolderID()) {
  910 + $extra_errors['browse'] = _kt("You cannot move the document within the same folder.");
  911 + } else {
  912 + $bNameClash = KTDocumentUtil::nameExists($data['browse'], $this->oDocument->getName());
  913 + if ($bNameClash && isset($data['name'])) {
  914 + $name = $data['name'];
  915 + $bNameClash = KTDocumentUtil::nameExists($data['browse'], $name);
  916 + } else {
  917 + $name = $this->oDocument->getName();
  918 + }
  919 + if ($bNameClash) {
  920 + $extra_errors['name'] = _kt("A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.");
  921 + }
  922 +
  923 + $bFileClash = KTDocumentUtil::fileExists($this->oFolder, $this->oDocument->getFilename());
  924 + if ($bFileClash && isset($data['filename'])) {
  925 + $filename = $data['filename'];
  926 + $bFileClash = KTDocumentUtil::fileExists($this->oFolder, $filename);
  927 + } else {
  928 + $filename = $this->oDocument->getFilename();
  929 + }
  930 + if ($bFileClash) {
  931 + $extra_errors['filename'] = _kt("A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.");
  932 + }
  933 +
  934 + if (!Permission::userHasFolderWritePermission($data['browse'])) {
  935 + $extra_errors['browse'] = _kt("You do not have permission to create new documents in that folder.");
  936 + }
  937 + }
910 } 938 }
911 939
912 - $sReason = $data['reason'];  
913 -  
914 - if (!Permission::userHasFolderWritePermission($this->oFolder)) {  
915 - $this->errorRedirectToMain(_kt("You do not have permission to move a document to this location"));  
916 - exit(0); 940 + if (!empty($errors) || !empty($extra_errors)) {
  941 + return $oForm->handleError(null, $extra_errors);
917 } 942 }
918 - 943 +
919 $this->startTransaction(); 944 $this->startTransaction();
920 -  
921 - $oOriginalFolder = Folder::get($this->oDocument->getFolderId());  
922 - $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId();  
923 - $iDocumentPermissionObjectId = $this->oDocument->getPermissionObjectId();  
924 -  
925 -  
926 - if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) {  
927 - $this->oDocument->setPermissionObjectId($this->oFolder->getPermissionObjectId()); 945 + // now try update it.
  946 +
  947 + $res = KTDocumentUtil::move($this->oDocument, $data['browse'], $this->oUser, $sReason);
  948 + if (PEAR::isError($oNewDoc)) {
  949 + $this->errorRedirectTo("main", _kt("Failed to move document: ") . $oNewDoc->getMessage());
  950 + exit(0);
928 } 951 }
929 -  
930 - //put the document in the new folder  
931 - $this->oDocument->setFolderID($this->oFolder->getId()); 952 +
  953 + $this->oDocument->setName($name); // if needed.
  954 + $this->oDocument->setFilename($filename); // if needed.
  955 +
932 $res = $this->oDocument->update(); 956 $res = $this->oDocument->update();
933 - if (PEAR::isError($res) || ($res === false)) {  
934 - $this->errorRedirectToMain(_kt("There was a problem updating the document's location in the database"));  
935 - }  
936 -  
937 -  
938 - //move the document on the file system  
939 - $oStorage =& KTStorageManagerUtil::getSingleton();  
940 - $res = $oStorage->moveDocument($this->oDocument, $this->oDocumentFolder, $this->oFolder);  
941 - if (PEAR::isError($res) || ($res === false)) {  
942 - $this->oDocument->setFolderID($oOriginalFolder->getId());  
943 - $this->oDocument->update();  
944 - $this->errorRedirectToMain(_kt("There was a problem updating the document's location in the repository storage")); 957 + if (PEAR::isError($res)) {
  958 + return $this->errorRedirectTo("main", _kt("Failed to move document: ") . $res->getMessage());
945 } 959 }
946 960
947 -  
948 - $sMoveMessage = sprintf("Moved from %s/%s to %s/%s: %s",  
949 - $this->oDocumentFolder->getFullPath(),  
950 - $this->oDocumentFolder->getName(),  
951 - $this->oFolder->getFullPath(),  
952 - $this->oFolder->getName(),  
953 - $sReason);  
954 -  
955 - // create the document transaction record  
956 -  
957 - $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $sMoveMessage, 'ktcore.transactions.move');  
958 - $oDocumentTransaction->create();  
959 -  
960 $this->commitTransaction(); 961 $this->commitTransaction();
961 -  
962 - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();  
963 - $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate');  
964 - foreach ($aTriggers as $aTrigger) {  
965 - $sTrigger = $aTrigger[0];  
966 - $oTrigger = new $sTrigger;  
967 - $aInfo = array(  
968 - "document" => $this->oDocument,  
969 - "old_folder" => $this->oDocumentFolder,  
970 - "new_folder" => $this->oFolder,  
971 - );  
972 - $oTrigger->setInfo($aInfo);  
973 - $ret = $oTrigger->postValidate();  
974 - if (PEAR::isError($ret)) {  
975 - $this->oDocument->delete();  
976 - return $ret;  
977 - }  
978 - }  
979 962
980 - redirect(KTBrowseUtil::getUrlForDocument($this->oDocument));  
981 - exit(0); 963 + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
  964 + exit(0);
982 } 965 }
  966 +
983 } 967 }
984 // }}} 968 // }}}
985 969
@@ -1053,7 +1037,7 @@ class KTDocumentCopyAction extends KTDocumentAction { @@ -1053,7 +1037,7 @@ class KTDocumentCopyAction extends KTDocumentAction {
1053 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to copy the documents into.'), 1037 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to copy the documents into.'),
1054 'required' => true, 1038 'required' => true,
1055 'name' => 'browse', 1039 'name' => 'browse',
1056 - 'folder_id' => $this->oFolder->getId(), 1040 + 'folder_id' => $this->oDocument->getFolderID(),
1057 )), 1041 )),
1058 array('ktcore.widgets.reason', array( 1042 array('ktcore.widgets.reason', array(
1059 'label' => _kt("Reason"), 1043 'label' => _kt("Reason"),
templates/ktcore/action/finalise_mass_move.smarty
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 26
27 <div class="form_actions"> 27 <div class="form_actions">
28 <input type="submit" name="submit[move]" value="{i18n}Move{/i18n}" /> 28 <input type="submit" name="submit[move]" value="{i18n}Move{/i18n}" />
29 -<input type="submit" name="submit[cancel]" value="{i18n}Cancel{/i18n}" /> 29 +<a href="{addQS context=$context}action=main&fFolderId={$folder}{/addQS}" class="form_cancel">Cancel</a>
30 </div> 30 </div>
31 </fieldset> 31 </fieldset>
32 </form> 32 </form>
templates/ktcore/action/mass_move.smarty
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 17
18 <div class="form_actions"> 18 <div class="form_actions">
19 <input type="submit" name="submit[move]" value="{i18n}Move{/i18n}" /> 19 <input type="submit" name="submit[move]" value="{i18n}Move{/i18n}" />
20 -<input type="submit" name="submit[cancel]" value="{i18n}Cancel{/i18n}" /> 20 +<a href="{addQS context=$context}action=main&fFolderId={$folder->getId()}{/addQS}" class="form_cancel">Cancel</a>
21 </div> 21 </div>
22 </fieldset> 22 </fieldset>
23 </form> 23 </form>