Commit a503fff2c48457f602ebe8a3e91a4df2f56d2f0c
1 parent
622dfd0a
Bulk import action to import files from the filesystem.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3656 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
189 additions
and
0 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/bulkImport.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +require_once('../../../../config/dmsDefaults.php'); | ||
| 4 | + | ||
| 5 | +require_once(KT_LIB_DIR . '/dispatcher.inc.php'); | ||
| 6 | + | ||
| 7 | +require_once(KT_DIR . "/presentation/webpageTemplate.inc"); | ||
| 8 | +require_once(KT_LIB_DIR . "/documentmanagement/DocumentType.inc"); | ||
| 9 | +require_once(KT_LIB_DIR . "/documentmanagement/DocumentField.inc"); | ||
| 10 | +require_once(KT_LIB_DIR . "/visualpatterns/PatternMetaData.inc"); | ||
| 11 | + | ||
| 12 | +require_once(KT_LIB_DIR . "/import/fsimportstorage.inc.php"); | ||
| 13 | +require_once(KT_LIB_DIR . "/import/bulkimport.inc.php"); | ||
| 14 | + | ||
| 15 | +class KTBulkImportDispatcher extends KTStandardDispatcher { | ||
| 16 | + function do_main() { | ||
| 17 | + $oTemplating =& KTTemplating::getSingleton(); | ||
| 18 | + $oTemplate = $oTemplating->loadTemplate('ktcore/import/fs_import'); | ||
| 19 | + $oFolder = Folder::get($_REQUEST['fFolderID']); | ||
| 20 | + $aFields = array( | ||
| 21 | + 'folder_id' => $oFolder->getID(), | ||
| 22 | + 'folder_path_array' => $oFolder->getPathArray(), | ||
| 23 | + 'document_type_choice' => $this->getDocumentTypeChoice('getMetadataForType(this.value);'), | ||
| 24 | + 'generic_metadata_fields' => $this->getGenericMetadataFields(), | ||
| 25 | + 'type_metadata_fields' => $this->getTypeMetadataFields(1), | ||
| 26 | + ); | ||
| 27 | + return $oTemplate->render($aFields); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + function getDocumentTypeChoice($onchange = "") { | ||
| 31 | + $oTemplating =& KTTemplating::getSingleton(); | ||
| 32 | + $oTemplate = $oTemplating->loadTemplate('ktcore/document/document_type_choice'); | ||
| 33 | + $aFields = array( | ||
| 34 | + 'document_types' => DocumentType::getList(), | ||
| 35 | + 'onchange' => $onchange, | ||
| 36 | + ); | ||
| 37 | + return $oTemplate->render($aFields); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + function getGenericMetadataFields() { | ||
| 41 | + $oTemplating = KTTemplating::getSingleton(); | ||
| 42 | + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields"); | ||
| 43 | + $aTemplateData = array( | ||
| 44 | + 'caption' => _('Generic meta data'), | ||
| 45 | + 'empty_message' => _("No Generic Meta Data"), | ||
| 46 | + 'fields' => DocumentField::getList(array('is_generic = ?', array(true))), | ||
| 47 | + ); | ||
| 48 | + return $oTemplate->render($aTemplateData); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + function getTypeMetadataFields($iDocumentTypeID) { | ||
| 52 | + global $default; | ||
| 53 | + /*ok*/ $sQuery = array("SELECT DF.id AS id " . | ||
| 54 | + "FROM document_fields AS DF LEFT JOIN document_type_fields_link AS DTFL ON DTFL.field_id = DF.id " . | ||
| 55 | + "WHERE DF.is_generic = ? " . | ||
| 56 | + "AND DTFL.document_type_id = ?", array(false, $iDocumentTypeID)); | ||
| 57 | + | ||
| 58 | + $aIDs = DBUtil::getResultArray($sQuery); | ||
| 59 | + | ||
| 60 | + $aFields = array(); | ||
| 61 | + foreach ($aIDs as $iID) { | ||
| 62 | + $aFields[] =& call_user_func(array('DocumentField', 'get'), $iID); | ||
| 63 | + } | ||
| 64 | + $aTemplateData = array( | ||
| 65 | + 'caption' => _('Type specific meta data'), | ||
| 66 | + 'empty_message' => _("No Type Specific Meta Data"), | ||
| 67 | + 'fields' => $aFields, | ||
| 68 | + ); | ||
| 69 | + $oTemplating = KTTemplating::getSingleton(); | ||
| 70 | + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields"); | ||
| 71 | + return $oTemplate->render($aTemplateData); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + function do_import() { | ||
| 75 | + $oFolder =& Folder::get($_REQUEST['fFolderID']); | ||
| 76 | + $matches = array(); | ||
| 77 | + $aFields = array(); | ||
| 78 | + foreach ($_REQUEST as $k => $v) { | ||
| 79 | + if (preg_match('/^emd(\d+)$/', $k, $matches)) { | ||
| 80 | + $aFields[] = array(DocumentField::get($matches[1]), $v); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + $aOptions = array( | ||
| 85 | + 'documenttype' => DocumentType::get($fDocumentTypeID), | ||
| 86 | + 'metadata' => $aFields, | ||
| 87 | + ); | ||
| 88 | + | ||
| 89 | + $fs =& new KTFSImportStorage($_REQUEST['fPath']); | ||
| 90 | + $oUser =& User::get($_SESSION['userID']); | ||
| 91 | + $bm =& new KTBulkImportManager($oFolder, $fs, $oUser, $aOptions); | ||
| 92 | + DBUtil::startTransaction(); | ||
| 93 | + $res = $bm->import(); | ||
| 94 | + if (PEAR::isError($res)) { | ||
| 95 | + DBUtil::rollback(); | ||
| 96 | + $_SESSION["KTErrorMessage"][] = _("Bulk import failed") . ": " . $res->getMessage(); | ||
| 97 | + } else { | ||
| 98 | + DBUtil::commit(); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + controllerRedirect("browse", 'fFolderID=' . $oFolder->getID()); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + function handleOutput($data) { | ||
| 105 | + global $main; | ||
| 106 | + if (empty($data)) { | ||
| 107 | + $data = ""; | ||
| 108 | + } | ||
| 109 | + $main->bFormDisabled = true; | ||
| 110 | + $main->setCentralPayload($data); | ||
| 111 | + $main->render(); | ||
| 112 | + } | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +$d =& new KTBulkImportDispatcher; | ||
| 116 | +$d->dispatch(); | ||
| 117 | + | ||
| 118 | +?> |
templates/ktcore/import/fs_import.smarty
0 → 100644
| 1 | +<script language="javascript" src="/thirdpartyjs/MochiKit/Base.js"> | ||
| 2 | +</script> | ||
| 3 | +<script language="javascript" src="/thirdpartyjs/MochiKit/Async.js"> | ||
| 4 | +</script> | ||
| 5 | +<script language="javascript" src="/thirdpartyjs/MochiKit/DOM.js"> | ||
| 6 | +</script> | ||
| 7 | +{literal} | ||
| 8 | +<script language="javascript"> | ||
| 9 | + | ||
| 10 | +var fetching = null; | ||
| 11 | + | ||
| 12 | +function swapInItem(req) { | ||
| 13 | + var cp = getElement(fetching); | ||
| 14 | + cp.innerHTML = req.responseText; | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +function xmlFailure(err) { | ||
| 18 | + alert('failed'); | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +function swapElementFromRequest(elementId, url) { | ||
| 22 | + var deff = doSimpleXMLHttpRequest(url); | ||
| 23 | + deff.addCallback(swapInItem); | ||
| 24 | + fetching = elementId; | ||
| 25 | + var cp = getElement(fetching); | ||
| 26 | + cp.innerHTML="loading..."; | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +function getMetadataForType(id) { | ||
| 30 | + swapElementFromRequest('type_metadata_fields', | ||
| 31 | + 'http://ktcvs.local/presentation/lookAndFeel/knowledgeTree/documentmanagement/getTypeMetadataFields.php?fDocumentTypeID=' | ||
| 32 | + + id); | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +</script> | ||
| 36 | +{/literal} | ||
| 37 | + | ||
| 38 | +<form method="POST"> | ||
| 39 | + | ||
| 40 | +<input type="hidden" name="fDocumentTypeID" value="1"> | ||
| 41 | +<input type="hidden" name="action" value="import"> | ||
| 42 | + | ||
| 43 | +<h3>Bulk Import</h2> | ||
| 44 | + | ||
| 45 | +<table class="prettysw" cellpadding="0" cellspacing="0"> | ||
| 46 | + <tr> | ||
| 47 | + <th>Folder</th> | ||
| 48 | + <td><input type="hidden" name="fFolderID" value="{$folder_id}">{" > "|join:$folder_path_array}</td> | ||
| 49 | + </tr> | ||
| 50 | + <tr> | ||
| 51 | + <th>Path</th> | ||
| 52 | + <td><input type="text" name="fPath"></td> | ||
| 53 | + </tr> | ||
| 54 | + <tr> | ||
| 55 | + <th>Document Type</th> | ||
| 56 | + <td> | ||
| 57 | +{$document_type_choice} | ||
| 58 | + </td> | ||
| 59 | + </tr> | ||
| 60 | +</table> | ||
| 61 | + | ||
| 62 | +<div id="generic_metadata_fields"> | ||
| 63 | +{$generic_metadata_fields} | ||
| 64 | +</div> | ||
| 65 | + | ||
| 66 | +<div id="type_metadata_fields"> | ||
| 67 | +{$type_metadata_fields} | ||
| 68 | +</div> | ||
| 69 | + | ||
| 70 | +<input type="submit" name="submit" value="Import"> | ||
| 71 | +</form> |