. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * */ require_once(KT_LIB_DIR . '/documentmanagement/Document.inc'); require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc'); require_once(KT_LIB_DIR . '/foldermanagement/Folder.inc'); require_once(KT_LIB_DIR . '/documentmanagement/DocumentLink.inc'); require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); require_once(KT_LIB_DIR . '/documentmanagement/DocumentType.inc'); require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php'); require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); require_once(KT_LIB_DIR . '/triggers/triggerregistry.inc.php'); require_once(KT_LIB_DIR . '/permissions/permission.inc.php'); require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); require_once(KT_LIB_DIR . "/widgets/forms.inc.php"); require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php"); require_once(KT_LIB_DIR . "/util/sanitize.inc"); require_once(KT_LIB_DIR.'/permissions/permissiondynamiccondition.inc.php'); // {{{ KTDocumentEditAction class KTDocumentEditAction extends KTDocumentAction { var $sName = 'ktcore.actions.document.edit'; var $_sShowPermission = "ktcore.permissions.write"; var $_bMutator = true; var $sIconClass = 'edit_metadata'; function getInfo() { if ($this->oDocument->getIsCheckedOut()) { return null; } return parent::getInfo(); } function getDisplayName() { return _kt('Edit Metadata'); } function predispatch() { $this->persistParams(array('new_type')); } function form_edit() { $oForm = new KTForm; $oForm->setOptions(array( 'label' => _kt('Edit Metadata'), 'submit_label' => _kt('Update Document'), 'action' => 'update', 'fail_action' => 'main', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'context' => &$this, 'extraargs' => $this->meldPersistQuery("","",true), )); $oFReg =& KTFieldsetRegistry::getSingleton(); $doctypeid = $this->oDocument->getDocumentTypeID(); if ($_REQUEST['new_type']) { $oTestType = DocumentType::get($_REQUEST['new_type']); if (!PEAR::isError($oTestType)) { $doctypeid = $oTestType->getId(); } } $widgets = array( array('ktcore.widgets.string', array( 'label' => _kt("Document Title"), 'description' => sprintf(_kt("The document title is used as the main name of a document throughout %s."), APP_NAME), 'name' => 'document_title', 'required' => true, 'value' => sanitizeForHTML($this->oDocument->getName()), )), ); $validators = array( array('ktcore.validators.string', array( 'test' => 'document_title', 'output' => 'document_title', )), ); $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); foreach ($fieldsets as $oFieldset) { $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); $validators = kt_array_merge($validators, $oFReg->validatorsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); } // Electronic Signature if enabled global $default; if($default->enableESignatures){ $widgets[] = array('ktcore.widgets.info', array( 'label' => _kt('This action requires authentication'), 'description' => _kt('Please provide your user credentials as confirmation of this action.'), 'name' => 'info' )); $widgets[] = array('ktcore.widgets.string', array( 'label' => _kt('Username'), 'name' => 'sign_username', 'required' => true )); $widgets[] = array('ktcore.widgets.password', array( 'label' => _kt('Password'), 'name' => 'sign_password', 'required' => true )); $widgets[] = array('ktcore.widgets.reason', array( 'label' => _kt('Reason'), 'name' => 'reason', 'required' => true )); $validators[] = array('electonic.signatures.validators.authenticate', array( 'object_id' => $this->oDocument->iId, 'type' => 'document', 'action' => 'ktcore.transactions.edit_metadata', 'test' => 'info', 'output' => 'info' )); } $oForm->setWidgets($widgets); $oForm->setValidators($validators); return $oForm; } function do_main() { $this->oPage->setBreadcrumbDetails(_kt("Edit Metadata")); $oTemplate = $this->oValidator->validateTemplate('ktcore/document/edit'); $doctypeid = $this->oDocument->getDocumentTypeID(); $type = DocumentType::get($doctypeid); $oForm = $this->form_edit(); $oTemplate->setData(array( 'context' => $this, 'form' => $oForm, 'document' => $this->oDocument, 'type_name' => $type->getName(), )); return $oTemplate->render(); } function do_update() { $oForm = $this->form_edit(); $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError(); } $data = $res['results']; // we need to format these in MDPack format // which is a little archaic: // // array( // array($oField, $sValue), // array($oField, $sValue), // array($oField, $sValue), // ); // // we do this the "easy" way. $doctypeid = $this->oDocument->getDocumentTypeId(); if ($_REQUEST['new_type']) { $oTestType = DocumentType::get($_REQUEST['new_type']); if (!PEAR::isError($oTestType)) { $doctypeid = $oTestType->getId(); } } $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); $MDPack = array(); foreach ($fieldsets as $oFieldset) { $fields = $oFieldset->getFields(); $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId()); foreach ($fields as $oField) { $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); // for html fields we want to do some stripping :) if ($oField->getIsHTML()) { // NOTE this works great...once the text is saved a first time // but the first time the