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