Commit c6ee5f7ebdc7485f8b4e96aca9f6e4e70b4c455e
1 parent
91e0ef20
Move add document action into a separate file, and move control over UI
to a document addition observer. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4408 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
118 additions
and
101 deletions
plugins/ktcore/KTFolderActions.php
| ... | ... | @@ -14,107 +14,7 @@ require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); |
| 14 | 14 | $oRegistry =& KTPluginRegistry::getSingleton(); |
| 15 | 15 | $oPlugin =& $oRegistry->getPlugin('ktcore.plugin'); |
| 16 | 16 | |
| 17 | -class KTFolderAddDocumentAction extends KTFolderAction { | |
| 18 | - var $sDisplayName = 'Add Document'; | |
| 19 | - var $sName = 'ktcore.actions.folder.addDocument'; | |
| 20 | - | |
| 21 | - var $_sShowPermission = "ktcore.permissions.write"; | |
| 22 | - | |
| 23 | - function do_main() { | |
| 24 | - $this->oPage->setBreadcrumbDetails(_("add document")); | |
| 25 | - $this->oPage->setTitle(_('Add a document')); | |
| 26 | - $oTemplate =& $this->oValidator->validateTemplate('ktcore/document/add'); | |
| 27 | - $add_fields = array(); | |
| 28 | - $add_fields[] = new KTFileUploadWidget(_('File'), _('The contents of the document to be added to the document management system.'), 'file', "", $this->oPage, true); | |
| 29 | - $add_fields[] = new KTStringWidget(_('Title'), _('Describe the changes made to the document.'), 'title', "", $this->oPage, true); | |
| 30 | - | |
| 31 | - | |
| 32 | - | |
| 33 | - $aVocab = array(); | |
| 34 | - foreach (DocumentType::getList() as $oDocumentType) { | |
| 35 | - $aVocab[$oDocumentType->getId()] = $oDocumentType->getName(); | |
| 36 | - } | |
| 37 | - $fieldOptions = array("vocab" => $aVocab); | |
| 38 | - $add_fields[] = new KTLookupWidget(_('Document Type'), 'FIXME', 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions); | |
| 39 | - | |
| 40 | - $fieldsets = array(); | |
| 41 | - $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton(); | |
| 42 | - $activesets = KTFieldset::getGenericFieldsets(); | |
| 43 | - foreach ($activesets as $oFieldset) { | |
| 44 | - $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); | |
| 45 | - array_push($fieldsets, new $displayClass($oFieldset)); | |
| 46 | - } | |
| 47 | - | |
| 48 | - $oTemplate->setData(array( | |
| 49 | - 'context' => &$this, | |
| 50 | - 'add_fields' => $add_fields, | |
| 51 | - 'generic_fieldsets' => $fieldsets, | |
| 52 | - )); | |
| 53 | - return $oTemplate->render(); | |
| 54 | - } | |
| 55 | - | |
| 56 | - function do_upload() { | |
| 57 | - require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); | |
| 58 | - require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 59 | - require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc'); | |
| 60 | - require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); | |
| 61 | - require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | |
| 62 | - | |
| 63 | - // make sure the user actually selected a file first | |
| 64 | - // and that something was uploaded | |
| 65 | - if (!((strlen($_FILES['file']['name']) > 0) && $_FILES['file']['size'] > 0)) { | |
| 66 | - // no uploaded file | |
| 67 | - $message = _("You did not select a valid document to upload"); | |
| 68 | - | |
| 69 | - $errors = array( | |
| 70 | - 1 => _("The uploaded file is larger than the PHP upload_max_filesize setting"), | |
| 71 | - 2 => _("The uploaded file is larger than the MAX_FILE_SIZE directive that was specified in the HTML form"), | |
| 72 | - 3 => _("The uploaded file was not fully uploaded to KnowledgeTree"), | |
| 73 | - 4 => _("No file was selected to be uploaded to KnowledgeTree"), | |
| 74 | - 6 => _("An internal error occurred receiving the uploaded document"), | |
| 75 | - ); | |
| 76 | - $message = KTUtil::arrayGet($errors, $_FILES['file']['error'], $message); | |
| 77 | - | |
| 78 | - if (@ini_get("file_uploads") == false) { | |
| 79 | - $message = _("File uploads are disabled in your PHP configuration"); | |
| 80 | - } | |
| 81 | - | |
| 82 | - $this->errorRedirectToMain($message, 'fFolderId=' . $this->oFolder->getId()); | |
| 83 | - exit(0); | |
| 84 | - } | |
| 85 | - | |
| 86 | - $matches = array(); | |
| 87 | - $aFields = array(); | |
| 88 | - foreach ($_REQUEST as $k => $v) { | |
| 89 | - if (preg_match('/^metadata_(\d+)$/', $k, $matches)) { | |
| 90 | - $aFields[] = array(DocumentField::get($matches[1]), $v); | |
| 91 | - } | |
| 92 | - } | |
| 93 | - | |
| 94 | - $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId']); | |
| 95 | - | |
| 96 | - $aOptions = array( | |
| 97 | - 'contents' => new KTFSFileLike($_FILES['file']['tmp_name']), | |
| 98 | - 'documenttype' => $this->oDocumentType, | |
| 99 | - 'metadata' => $aFields, | |
| 100 | - 'description' => $_REQUEST['fName'], | |
| 101 | - ); | |
| 102 | - | |
| 103 | - $this->startTransaction(); | |
| 104 | - $oDocument =& KTDocumentUtil::add($this->oFolder, basename($_FILES['file']['name']), $this->oUser, $aOptions); | |
| 105 | - if (PEAR::isError($oDocument)) { | |
| 106 | - $message = $oDocument->getMessage(); | |
| 107 | - $this->errorRedirectToMain($message, 'fFolderId=' . $this->oFolder->getId()); | |
| 108 | - exit(0); | |
| 109 | - } | |
| 110 | - | |
| 111 | - $this->commitTransaction(); | |
| 112 | - //redirect to the document details page | |
| 113 | - controllerRedirect("viewDocument", "fDocumentId=" . $oDocument->getID()); | |
| 114 | - } | |
| 115 | - | |
| 116 | -} | |
| 117 | -$oPlugin->registerAction('folderaction', 'KTFolderAddDocumentAction', 'ktcore.actions.folder.addDocument'); | |
| 17 | +$oPlugin->registerAction('folderaction', 'KTFolderAddDocumentAction', 'ktcore.actions.folder.addDocument', 'folder/addDocument.php'); | |
| 118 | 18 | |
| 119 | 19 | class KTFolderAddFolderAction extends KTFolderAction { |
| 120 | 20 | var $sDisplayName = 'Add a Folder'; | ... | ... |
plugins/ktcore/folder/addDocument.php
0 โ 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once(KT_LIB_DIR . '/actions/folderaction.inc.php'); | |
| 4 | + | |
| 5 | +require_once(KT_LIB_DIR . "/widgets/fieldsetDisplay.inc.php"); | |
| 6 | +require_once(KT_LIB_DIR . "/widgets/FieldsetDisplayRegistry.inc.php"); | |
| 7 | +require_once(KT_LIB_DIR . "/foldermanagement/folderutil.inc.php"); | |
| 8 | +require_once(KT_LIB_DIR . "/documentmanagement/observers.inc.php"); | |
| 9 | + | |
| 10 | +class KTFolderAddDocumentAction extends KTFolderAction { | |
| 11 | + var $sDisplayName = 'Add Document'; | |
| 12 | + var $sName = 'ktcore.actions.folder.addDocument'; | |
| 13 | + | |
| 14 | + var $_sShowPermission = "ktcore.permissions.write"; | |
| 15 | + | |
| 16 | + function do_main() { | |
| 17 | + $this->oPage->setBreadcrumbDetails(_("add document")); | |
| 18 | + $this->oPage->setTitle(_('Add a document')); | |
| 19 | + $oTemplate =& $this->oValidator->validateTemplate('ktcore/document/add'); | |
| 20 | + $add_fields = array(); | |
| 21 | + $add_fields[] = new KTFileUploadWidget(_('File'), _('The contents of the document to be added to the document management system.'), 'file', "", $this->oPage, true); | |
| 22 | + $add_fields[] = new KTStringWidget(_('Title'), _('Describe the changes made to the document.'), 'title', "", $this->oPage, true); | |
| 23 | + | |
| 24 | + $aVocab = array(); | |
| 25 | + foreach (DocumentType::getList() as $oDocumentType) { | |
| 26 | + $aVocab[$oDocumentType->getId()] = $oDocumentType->getName(); | |
| 27 | + } | |
| 28 | + $fieldOptions = array("vocab" => $aVocab); | |
| 29 | + $add_fields[] = new KTLookupWidget(_('Document Type'), 'FIXME', 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions); | |
| 30 | + | |
| 31 | + $fieldsets = array(); | |
| 32 | + $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton(); | |
| 33 | + $activesets = KTFieldset::getGenericFieldsets(); | |
| 34 | + foreach ($activesets as $oFieldset) { | |
| 35 | + $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); | |
| 36 | + array_push($fieldsets, new $displayClass($oFieldset)); | |
| 37 | + } | |
| 38 | + | |
| 39 | + $oTemplate->setData(array( | |
| 40 | + 'context' => &$this, | |
| 41 | + 'add_fields' => $add_fields, | |
| 42 | + 'generic_fieldsets' => $fieldsets, | |
| 43 | + )); | |
| 44 | + return $oTemplate->render(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + function do_upload() { | |
| 48 | + $this->oPage->setBreadcrumbDetails(_("add document")); | |
| 49 | + $this->oPage->setTitle(_('Add a document')); | |
| 50 | + $mpo =& new JavascriptObserver(&$this); | |
| 51 | + // $mpo =& new KTSinglePageObserver(&$this); | |
| 52 | + $oUploadChannel =& KTUploadChannel::getSingleton(); | |
| 53 | + $oUploadChannel->addObserver($mpo); | |
| 54 | + | |
| 55 | + require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); | |
| 56 | + require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); | |
| 57 | + require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc'); | |
| 58 | + require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); | |
| 59 | + require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | |
| 60 | + | |
| 61 | + // make sure the user actually selected a file first | |
| 62 | + // and that something was uploaded | |
| 63 | + if (!((strlen($_FILES['file']['name']) > 0) && $_FILES['file']['size'] > 0)) { | |
| 64 | + // no uploaded file | |
| 65 | + $message = _("You did not select a valid document to upload"); | |
| 66 | + | |
| 67 | + $errors = array( | |
| 68 | + 1 => _("The uploaded file is larger than the PHP upload_max_filesize setting"), | |
| 69 | + 2 => _("The uploaded file is larger than the MAX_FILE_SIZE directive that was specified in the HTML form"), | |
| 70 | + 3 => _("The uploaded file was not fully uploaded to KnowledgeTree"), | |
| 71 | + 4 => _("No file was selected to be uploaded to KnowledgeTree"), | |
| 72 | + 6 => _("An internal error occurred receiving the uploaded document"), | |
| 73 | + ); | |
| 74 | + $message = KTUtil::arrayGet($errors, $_FILES['file']['error'], $message); | |
| 75 | + | |
| 76 | + if (@ini_get("file_uploads") == false) { | |
| 77 | + $message = _("File uploads are disabled in your PHP configuration"); | |
| 78 | + } | |
| 79 | + | |
| 80 | + $this->errorRedirectToMain($message, 'fFolderId=' . $this->oFolder->getId()); | |
| 81 | + exit(0); | |
| 82 | + } | |
| 83 | + | |
| 84 | + $matches = array(); | |
| 85 | + $aFields = array(); | |
| 86 | + foreach ($_REQUEST as $k => $v) { | |
| 87 | + if (preg_match('/^metadata_(\d+)$/', $k, $matches)) { | |
| 88 | + $aFields[] = array(DocumentField::get($matches[1]), $v); | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId']); | |
| 93 | + | |
| 94 | + $aOptions = array( | |
| 95 | + 'contents' => new KTFSFileLike($_FILES['file']['tmp_name']), | |
| 96 | + 'documenttype' => $this->oDocumentType, | |
| 97 | + 'metadata' => $aFields, | |
| 98 | + 'description' => $_REQUEST['fName'], | |
| 99 | + ); | |
| 100 | + | |
| 101 | + $mpo->start(); | |
| 102 | + $this->startTransaction(); | |
| 103 | + $oDocument =& KTDocumentUtil::add($this->oFolder, basename($_FILES['file']['name']), $this->oUser, $aOptions); | |
| 104 | + if (PEAR::isError($oDocument)) { | |
| 105 | + $message = $oDocument->getMessage(); | |
| 106 | + $this->errorRedirectToMain($message, 'fFolderId=' . $this->oFolder->getId()); | |
| 107 | + exit(0); | |
| 108 | + } | |
| 109 | + | |
| 110 | + $mpo->redirectToDocument($oDocument->getId()); | |
| 111 | + $this->commitTransaction(); | |
| 112 | + exit(0); | |
| 113 | + } | |
| 114 | + | |
| 115 | +} | |
| 116 | + | |
| 117 | +?> | ... | ... |