Commit b54d9edd53db1492e4872bdc294b9d5eb9af4bf1
1 parent
89351bd4
Change modifySpecificMetadata to use the new metadata infrastructure.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3642 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
78 additions
and
51 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/modifySpecificMetaDataBL.php
| ... | ... | @@ -27,35 +27,62 @@ |
| 27 | 27 | |
| 28 | 28 | require_once("../../../../config/dmsDefaults.php"); |
| 29 | 29 | |
| 30 | -KTUtil::extractGPC('fDocumentID', 'fFirstEdit'); | |
| 31 | - | |
| 32 | -if (checkSession()) { | |
| 33 | - require_once("$default->fileSystemRoot/lib/security/Permission.inc"); | |
| 34 | - require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | |
| 35 | - require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | |
| 36 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | |
| 37 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); | |
| 38 | - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMetaData.inc"); | |
| 39 | - require_once("$default->fileSystemRoot/presentation/Html.inc"); | |
| 40 | - require_once("documentUI.inc"); | |
| 41 | - require_once("modifySpecificMetaDataUI.inc"); | |
| 42 | - | |
| 43 | - $oDocument = Document::get($fDocumentID); | |
| 44 | - if (Permission::userHasDocumentWritePermission($oDocument)) { | |
| 45 | - | |
| 46 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 47 | - $oPatternCustom = & new PatternCustom(); | |
| 48 | - $oPatternCustom->setHtml(getPage($fDocumentID, $oDocument->getDocumentTypeID(), $fFirstEdit)); | |
| 49 | - $main->setCentralPayload($oPatternCustom); | |
| 50 | - if (isset($fFirstEdit)) { | |
| 51 | - $_SESSION["pageAccess"][$default->rootUrl . '/presentation/lookAndFeel/knowledgeTree/store.php'] = true; | |
| 52 | - $main->setFormAction("$default->rootUrl/presentation/lookAndFeel/knowledgeTree/store.php?fReturnURL=" . urlencode("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID")); | |
| 53 | - } else { | |
| 54 | - $_SESSION["pageAccess"][$default->rootUrl . '/presentation/lookAndFeel/knowledgeTree/store.php'] = true; | |
| 55 | - $main->setFormAction("$default->rootUrl/presentation/lookAndFeel/knowledgeTree/store.php?fReturnURL=" . urlencode("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID&fShowSection=typeSpecificMetaData")); | |
| 56 | - } | |
| 57 | - $main->setHasRequiredFields(true); | |
| 58 | - $main->render(); | |
| 59 | - } | |
| 30 | +KTUtil::extractGPC('fDocumentID', 'fFirstEdit', 'fForStore'); | |
| 31 | + | |
| 32 | +if (!checkSession()) { | |
| 33 | + die(); | |
| 60 | 34 | } |
| 35 | + | |
| 36 | +require_once("$default->fileSystemRoot/lib/security/Permission.inc"); | |
| 37 | +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | |
| 38 | +require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | |
| 39 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | |
| 40 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); | |
| 41 | +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMetaData.inc"); | |
| 42 | +require_once("$default->fileSystemRoot/presentation/Html.inc"); | |
| 43 | +require_once("documentUI.inc"); | |
| 44 | +require_once("modifySpecificMetaDataUI.inc"); | |
| 45 | + | |
| 46 | +require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | |
| 47 | + | |
| 48 | +$oDocument = Document::get($fDocumentID); | |
| 49 | +if (!Permission::userHasDocumentWritePermission($oDocument)) { | |
| 50 | + die(); | |
| 51 | +} | |
| 52 | + | |
| 53 | +if (empty($fForStore)) { | |
| 54 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 55 | + $oPatternCustom = & new PatternCustom(); | |
| 56 | + $oPatternCustom->setHtml(getPage($fDocumentID, $oDocument->getDocumentTypeID(), $fFirstEdit)); | |
| 57 | + $main->setCentralPayload($oPatternCustom); | |
| 58 | + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForStore=1"); | |
| 59 | + $main->setHasRequiredFields(true); | |
| 60 | + $main->render(); | |
| 61 | + exit(0); | |
| 62 | +} | |
| 63 | + | |
| 64 | +$matches = array(); | |
| 65 | +$aFields = array(); | |
| 66 | +foreach ($_REQUEST as $k => $v) { | |
| 67 | + if (preg_match('/^emd(\d+)$/', $k, $matches)) { | |
| 68 | + $aFields[] = array(DocumentField::get($matches[1]), $v); | |
| 69 | + } | |
| 70 | +} | |
| 71 | + | |
| 72 | +DBUtil::startTransaction(); | |
| 73 | +$res = KTDocumentUtil::saveMetadata($oDocument, $aFields); | |
| 74 | +if (PEAR::isError($res)) { | |
| 75 | + DBUtil::rollback(); | |
| 76 | + $_SESSION['KTErrorMessages'][] = $res->getMessage(); | |
| 77 | + controllerRedirect('modifyDocumentTypeMetaData', "fDocumentID=$fDocumentID"); | |
| 78 | + exit(0); | |
| 79 | +} | |
| 80 | +DBUtil::commit(); | |
| 81 | + | |
| 82 | +if (isset($fFirstEdit)) { | |
| 83 | + controllerRedirect('viewDocument', "fDocumentID=$fDocumentID"); | |
| 84 | +} else { | |
| 85 | + controllerRedirect('viewDocument', "fDocumentID=$fDocumentID&fShowSection=typeSpecificMetaData"); | |
| 86 | +} | |
| 87 | + | |
| 61 | 88 | ?> | ... | ... |
presentation/lookAndFeel/knowledgeTree/documentmanagement/modifySpecificMetaDataUI.inc
| ... | ... | @@ -25,30 +25,30 @@ |
| 25 | 25 | * @package documentmanagement |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | +require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | |
| 29 | +require_once(KT_LIB_DIR . '/documentmanagement/DocumentField.inc'); | |
| 30 | + | |
| 28 | 31 | function getEditableTypeSpecificMetaData($iDocumentID, $iDocumentTypeID) { |
| 29 | - global $default; | |
| 30 | - /*ok*/ $sQuery = array("SELECT DISTINCT $iDocumentID AS document_id, COALESCE(DFL.id, -1) AS id, DF.id AS document_field_id, DFL.value AS value, DF.name AS field_name, DTFL.is_mandatory AS is_mandatory " . | |
| 31 | - "FROM document_type_fields_link AS DTFL INNER JOIN document_fields AS DF ON DTFL.field_id = DF.id " . | |
| 32 | - "LEFT OUTER JOIN document_fields_link AS DFL ON DFL.document_field_id = DTFL.field_id AND DFL.document_id = ? " . | |
| 33 | - "WHERE DF.is_generic = 0 " . | |
| 34 | - "AND DTFL.document_type_id = ?", array($iDocumentID, $iDocumentTypeID)); | |
| 32 | + global $default; | |
| 33 | + /*ok*/ $sQuery = array("SELECT DF.id AS id " . | |
| 34 | + "FROM document_fields AS DF LEFT JOIN document_type_fields_link AS DTFL ON DTFL.field_id = DF.id " . | |
| 35 | + "WHERE DF.is_generic = ? " . | |
| 36 | + "AND DTFL.document_type_id = ?", array(false, $iDocumentTypeID)); | |
| 35 | 37 | |
| 36 | - $aStoreColumnNames = array("document_id", "document_field_id", "value"); | |
| 37 | - $aDisplayColumnNames = array("document_id", "field_name", "value"); | |
| 38 | - $aColumnsEditable = array(0,0,1); | |
| 39 | - $aColumnsVisible = array(0,1,1); | |
| 40 | - $aColumnDisplayTypes = array(1,1,4); | |
| 41 | - $aColumnDatabaseTypes = array(0,0,1); | |
| 42 | - $aMetaDataColumnNames = array(2=>"field_name"); | |
| 38 | + $aIDs = DBUtil::getResultArray($sQuery); | |
| 43 | 39 | |
| 44 | - $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes); | |
| 45 | - $oPatternTableSqlQuery->setTableCaption(_("Type specific meta data")); | |
| 46 | - $oPatternTableSqlQuery->setEmptyTableMessage(_("No Type Specific Meta Data")); | |
| 47 | - $oPatternTableSqlQuery->setUniqueName("tsmd"); | |
| 48 | - $oPatternTableSqlQuery->setMetaDataFields($aMetaDataColumnNames); | |
| 49 | - $oPatternTableSqlQuery->setPreCode(sprintf('require_once(KT_LIB_DIR . "/documentmanagement/documentutil.inc.php"); KTDocumentUtil::createMetadataVersion(%d);', (int)$iDocumentID)); | |
| 50 | - $oPatternTableSqlQuery->setPostCode(sprintf('require_once(KT_LIB_DIR . "/documentmanagement/documentutil.inc.php"); KTDocumentUtil::bumpVersion(%d); KTDocumentUtil::setModifiedDate(%d);', (int)$iDocumentID, (int)$iDocumentID)); | |
| 51 | - return $oPatternTableSqlQuery->render(); | |
| 40 | + $aFields = array(); | |
| 41 | + foreach ($aIDs as $iID) { | |
| 42 | + $aFields[] =& call_user_func(array('DocumentField', 'get'), $iID); | |
| 43 | + } | |
| 44 | + $aTemplateData = array( | |
| 45 | + 'caption' => _('Type specific meta data'), | |
| 46 | + 'empty_message' => _("No Type Specific Meta Data"), | |
| 47 | + 'fields' => $aFields, | |
| 48 | + ); | |
| 49 | + $oTemplating = KTTemplating::getSingleton(); | |
| 50 | + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields"); | |
| 51 | + return $oTemplate->render($aTemplateData); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | function getPage($iDocumentID, $iDocumentTypeID, $bFirstEdit) { | ... | ... |