From 05f4b6f4b84fb9ed23561cfa1933a5afd39c640b Mon Sep 17 00:00:00 2001 From: kevin_fourie Date: Fri, 15 Jun 2007 07:59:58 +0000 Subject: [PATCH] Merged in from DEV trunk... --- plugins/ktcore/document/edit.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/plugins/ktcore/document/edit.php b/plugins/ktcore/document/edit.php index 676707c..c954cf7 100644 --- a/plugins/ktcore/document/edit.php +++ b/plugins/ktcore/document/edit.php @@ -283,7 +283,63 @@ class KTDocumentEditAction extends KTDocumentAction { $oForm->handleError(); } - $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. Please note that this change has not yet been saved - please update the metadata below as necessary, and then save the document to make it a permanent change."), $data['type']->getName()), array('new_type' => $data['type']->getId())); + $document_type = $data['type']; + + + $doctypeid = $document_type->getId(); + + + DBUtil::startTransaction(); + $this->oDocument->setDocumentTypeId($doctypeid); + $res = $this->oDocument->update(); + + + if (PEAR::isError($res)) + { + DBUtil::rollback(); + return $res; + } + DBUtil::commit(); + + $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); + + $fs_ids = array(); + + $doctype_fieldsets = KTFieldSet::getForDocumentType($doctypeid); + foreach($doctype_fieldsets as $fieldset) + { + $fs_ids[] = $fieldset->getId(); + } + $MDPack = array(); + foreach ($fieldsets as $oFieldset) + { + if ($oFieldset->getIsGeneric() || in_array($oFieldset->getId(),$fs_ids)) + { + //print $oFieldset->getName() . "
"; + $fields = $oFieldset->getFields(); + $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId()); + foreach ($fields as $oField) + { + $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); + + // FIXME "null" has strange meanings here. + if (!is_null($val)) + { + $MDPack[] = array( + $oField, + $val + ); + } + } + } + + } + + $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack); + + + + $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName())); } } // }}} -- libgit2 0.21.4