function getHandler($nsname) { if (!array_key_exists($nsname, $this->fieldset_types)) { // unfortunately, we need to do a bit more spelunking here. // if its conditional, we use a different item. ns is unsufficient. // // FIXME this is slightly wasteful from a performance POV, though DB caching should make it OK. $oFieldset =& KTFieldset::getByNamespace($nsname); if (PEAR::isError($oFieldset)) { global $default; $default->log->error('Could not resolve Fieldset by namespace: ' . $nsname . '. Error: ' . $oFieldset->getMessage()); return 'SimpleFieldsetDisplay'; } if (is_a($oFieldset, 'KTEntityNoObjects')) { global $default; $default->log->error('Could not resolve Fieldset by namespace: ' . $nsname . '. Error: KTEntityNoObjects returned.'); return 'SimpleFieldsetDisplay'; } if ($oFieldset->getIsConditional() && KTMetadataUtil::validateCompleteness($oFieldset)) { return 'ConditionalFieldsetDisplay'; } else { return 'SimpleFieldsetDisplay'; } } else { return $this->fieldset_types[$nsname]; } }
function do_storeRelationship() { // handle the store, and DON'T give a 500 ;) does not act on the information. global $default; $default->log->error(http_build_query($_REQUEST)); $iFieldsetId = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); $parent_field = KTUtil::arrayGet($_REQUEST, 'parent_field'); $parent_lookup = KTUtil::arrayGet($_REQUEST, 'parent_lookup'); $child_lookups = KTUtil::arrayGet($_REQUEST, 'child_lookups'); // child lookups is a nested array. in python it would be: // child_lookups = // { // field_id:[lookup_id, lookup_id], // field_id:[lookup_id, lookup_id], // } $oFieldset =& KTFieldset::get($iFieldsetId); $oFieldset->setIsComplete(false); $oFieldset->update(); $oParentInstance = KTMetadataUtil::getOrCreateValueInstanceForLookup($parent_lookup); $iBehaviourId = $oParentInstance->getBehaviourId(); $oParentMetadata =& MetaData::get($oParentInstance->getFieldValueId()); if (is_null($iBehaviourId)) { $oBehaviour =& KTFieldBehaviour::createFromArray(array('name' => 'autoinstance' . $oParentInstance->getId(), 'humanname' => 'Auto instance' . $oParentMetadata->getName(), 'fieldid' => $oParentInstance->getFieldId())); } else { $oBehaviour =& KTFieldBehaviour::get($iBehaviourId); } if (PEAR::isError($oBehaviour)) { var_dump($oBehaviour); return $oBehaviour; } $iBehaviourId = $oBehaviour->getId(); $oParentInstance->setBehaviourId($iBehaviourId); $oParentInstance->update(); $sTable = KTUtil::getTableName('field_behaviour_options'); $aOptions = array('noid' => true); $aQuery = array("DELETE FROM {$sTable} WHERE behaviour_id = ?", array($iBehaviourId)); $res = DBUtil::runQuery($aQuery); foreach ($child_lookups as $iFieldId => $aLookups) { foreach ($aLookups as $iLookupId) { $oValueInstance =& KTMetadataUtil::getOrCreateValueInstanceForLookup($iLookupId); if (PEAR::isError($oValueInstance)) { var_dump($oValueInstance); return $oValueInstance; } $res = DBUtil::autoInsert($sTable, array('behaviour_id' => $iBehaviourId, 'field_id' => $iFieldId, 'instance_id' => $oValueInstance->getId()), $aOptions); if (PEAR::isError($res)) { var_dump($res); return $res; } } } }
/** * Returns the Metadata Fieldsets for the given DocumentId * @return KTForm * */ function getTypeMetadataFieldsets($iDocumentTypeID) { //Creating the form $oForm = new KTForm(); $oFReg =& KTFieldsetRegistry::getSingleton(); $activesets = KTFieldset::getForDocumentType($iDocumentTypeID); foreach ($activesets 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)); } $oForm->setWidgets($widgets); $oForm->setValidators($validators); return $oForm->renderWidgets(); }
function getTypeMetadataFieldsets($iDocumentTypeID) { $fieldsets = array(); $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton(); $activesets = KTFieldset::getForDocumentType($iDocumentTypeID); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } $aTemplateData = array('fieldsets' => $fieldsets); $oTemplating = KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/editable_metadata_fieldsets"); return $oTemplate->render($aTemplateData); }
function _buildGenericCriteria() { $aFields =& DocumentField::getList(); foreach ($aFields as $oField) { $sNamespace = $oField->getNamespace(); $oFieldset =& KTFieldset::get($oField->getParentFieldset()); if ($oFieldset->getName() == 'Tag Cloud') { continue; } //if(is_null($oFieldset->userinfo)){continue;} $aInitialize = array(sprintf("%s: %s", $oFieldset->getName(), $oField->getName()), 'id', 'id', $oField->getId(), $sNamespace); $this->registerCriterion('GenericMetadataCriterion', $sNamespace, null, $aInitialize); } $this->_bGenericRegistered = true; }
function predispatch() { $this->persistParams(array('fFieldId')); $this->oFieldset = KTFieldset::get(KTUtil::arrayGet($_REQUEST, 'fFieldsetId')); if (PEAR::isError($this->oFieldset)) { $this->oFieldset = null; unset($_REQUEST['fFieldsetId']); // prevent further attacks. } $this->oField = DocumentField::get(KTUtil::arrayGet($_REQUEST, 'fFieldId')); if (PEAR::isError($this->oField)) { $this->oField = null; unset($_REQUEST['fFieldId']); // prevent further attacks. } else { $this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("", "managefield")), 'name' => $this->oField->getName()); } }
function do_main() { $this->oPage->setBreadcrumbDetails(_kt("bulk upload")); $oTemplate =& $this->oValidator->validateTemplate('ktcore/folder/bulkUpload'); $add_fields = array(); $add_fields[] = new KTFileUploadWidget(_kt('Archive file'), _kt('The archive file containing the documents you wish to add to the document management system.'), 'file', "", $this->oPage, true, "file"); $aVocab = array('' => _kt('- Please select a document type -')); foreach (DocumentType::getListForUserAndFolder($this->oUser, $this->oFolder) as $oDocumentType) { if (!$oDocumentType->getDisabled()) { $aVocab[$oDocumentType->getId()] = $oDocumentType->getName(); } } $fieldOptions = array("vocab" => $aVocab); $add_fields[] = new KTLookupWidget(_kt('Document Type'), _kt('Document Types, defined by the administrator, are used to categorise documents. Please select a Document Type from the list below.'), 'fDocumentTypeId', null, $this->oPage, true, "add-document-type", $fieldErrors, $fieldOptions); $fieldsets = array(); $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton(); $activesets = KTFieldset::getGenericFieldsets(); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } // Implement an electronic signature for accessing the admin section, it will appear every 10 minutes global $default; $iFolderId = $this->oFolder->getId(); if ($default->enableESignatures) { $sUrl = KTPluginUtil::getPluginPath('electronic.signatures.plugin', true); $heading = _kt('You are attempting to perform a bulk upload'); $submit['type'] = 'button'; $submit['onclick'] = "javascript: showSignatureForm('{$sUrl}', '{$heading}', 'ktcore.transactions.bulk_upload', 'bulk', 'bulk_upload_form', 'submit', {$iFolderId});"; } else { $submit['type'] = 'submit'; $submit['onclick'] = ''; } $oTemplate->setData(array('context' => &$this, 'submit' => $submit, 'add_fields' => $add_fields, 'generic_fieldsets' => $fieldsets)); return $oTemplate->render(); }
/** * Gets a simple array of document metadata fields * * <code> * $ktapi = new KTAPI(); * $session = $ktapi->start_system_session(); * $document = $ktapi->get_document_by_id($documentid); * $metadata = $document->get_packed_metadata(); * foreach($metadata as $field){ * echo '<br><br>Fieldset: ' . $field[0]->getParentFieldset(); * echo '<br>Field name: ' .$field[0]->getName(); * echo ' Value: ' . $field[1]; * } * </code> * * @author KnowledgeTree Team * @access public * @param array $metadata The full metadata fieldsets and fields * @return array An array of metadata field object and value pairs */ function get_packed_metadata($metadata = null) { global $default; if (is_null($metadata)) { $metadata = $this->get_metadata(); } $packed = array(); foreach ($metadata as $fieldset_metadata) { if (is_array($fieldset_metadata)) { $fieldsetname = $fieldset_metadata['fieldset']; $fields = $fieldset_metadata['fields']; } elseif ($fieldset_metadata instanceof stdClass) { $fieldsetname = $fieldset_metadata->fieldset; $fields = $fieldset_metadata->fields; } else { $default->log->debug("unexpected fieldset type"); continue; } $fieldset = KTFieldset::getByName($fieldsetname); if (is_null($fieldset) || PEAR::isError($fieldset) || $fieldset instanceof KTEntityNoObjects) { $default->log->debug("could not resolve fieldset: {$fieldsetname} for document id: {$this->documentid}"); // exit graciously continue; } foreach ($fields as $fieldinfo) { if (is_array($fieldinfo)) { $fieldname = $fieldinfo['name']; $value = $fieldinfo['value']; } elseif ($fieldinfo instanceof stdClass) { $fieldname = $fieldinfo->name; $value = $fieldinfo->value; } else { $default->log->debug("unexpected fieldinfo type"); continue; } $field = DocumentField::getByFieldsetAndName($fieldset, $fieldname); if (is_null($field) || PEAR::isError($field) || is_a($field, 'KTEntityNoObjects')) { $default->log->debug("Could not resolve field: {$fieldname} on fieldset {$fieldsetname} for document id: {$this->documentid}"); // exit graciously continue; } $packed[] = array($field, $value); } } return $packed; }
function do_viewComparison() { $document_data = array(); $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); if ($document_id === null) { $this->oPage->addError(sprintf(_kt("No document was requested. Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl())); return $this->do_error(); } $document_data['document_id'] = $document_id; $base_version = KTUtil::arrayGet($_REQUEST, 'fBaseVersion'); // try get the document. $oDocument =& Document::get($document_id, $base_version); if (PEAR::isError($oDocument)) { $this->oPage->addError(sprintf(_kt("The base document you attempted to retrieve is invalid. Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl())); return $this->do_error(); } if (!Permission::userHasDocumentReadPermission($oDocument)) { // FIXME inconsistent. $this->oPage->addError(_kt('You are not allowed to view this document')); return $this->permissionDenied(); } $this->oDocument =& $oDocument; $this->oPage->setSecondaryTitle($oDocument->getName()); $aOptions = array('documentaction' => 'viewDocument', 'folderaction' => 'browse'); $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions)); $this->oPage->setBreadcrumbDetails(_kt('compare versions')); $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion'); if ($comparison_version === null) { $this->oPage->addError(sprintf(_kt("No comparison version was requested. Please <a href=\"%s\">select a version</a>."), KTUtil::addQueryStringSelf('action=history&fDocumentId=' . $document_id))); return $this->do_error(); } $oComparison =& Document::get($oDocument->getId(), $comparison_version); if (PEAR::isError($oComparison)) { $this->errorRedirectToMain(_kt('Invalid document to compare against.')); } $comparison_data = array(); $comparison_data['document_id'] = $oComparison->getId(); $document_data['document'] = $oDocument; $comparison_data['document'] = $oComparison; $document_data['document_type'] =& DocumentType::get($oDocument->getDocumentTypeID()); $comparison_data['document_type'] =& DocumentType::get($oComparison->getDocumentTypeID()); // follow twice: once for normal, once for comparison. $is_valid_doctype = true; if (PEAR::isError($document_data['document_type'])) { $this->oPage->addError(_kt('The document you requested has an invalid <strong>document type</strong>. Unfortunately, this means that we cannot effectively display it.')); $is_valid_doctype = false; } // we want to grab all the md for this doc, since its faster that way. $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($base_version))); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } $document_data['field_values'] = $field_values; $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($comparison_version))); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } $comparison_data['field_values'] = $field_values; // Fieldset generation. // // we need to create a set of FieldsetDisplay objects // that adapt the Fieldsets associated with this lot // to the view (i.e. ZX3). Unfortunately, we don't have // any of the plumbing to do it, so we handle this here. $fieldsets = array(); // we always have a generic. array_push($fieldsets, new GenericFieldsetDisplay()); // FIXME can we key this on fieldset namespace? or can we have duplicates? // now we get the other fieldsets, IF there is a valid doctype. if ($is_valid_doctype) { // these are the _actual_ fieldsets. $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton(); // and the generics $activesets = KTFieldset::getGenericFieldsets(); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } $activesets = KTFieldset::getForDocumentType($oDocument->getDocumentTypeID()); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } } // FIXME handle ad-hoc fieldsets. $this->addPortlets(); $oTemplate = $this->oValidator->validateTemplate('ktcore/document/compare'); $aTemplateData = array('context' => $this, 'document_id' => $document_id, 'document' => $oDocument, 'document_data' => $document_data, 'comparison_data' => $comparison_data, 'comparison_document' => $oComparison, 'fieldsets' => $fieldsets); //var_dump($aTemplateData['comparison_data']); return $oTemplate->render($aTemplateData); }
/** * Performs actual import action. | iNET Process * @Return. * @param. */ function do_import() { set_time_limit(0); $aErrorOptions = array('redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId()))); $aErrorOptions['message'] = _kt('Invalid document type provided'); $requestDocumentType = $_REQUEST['fDocumentTypeId']; //Backwards compatibility if ($requestDocumentType == '' || $requestDocumentType == NULL) { $requestDocumentType = $_REQUEST['data']; $requestDocumentType = $requestDocumentType['fDocumentTypeId']; //New elements come through as arrays } $oDocumentType = $this->oValidator->validateDocumentType($requestDocumentType, $aErrorOptions); $aErrorOptions['message'] = _kt('Invalid path provided'); $tmpPath = $_REQUEST['path']; //Backwards compatibility if ($tmpPath == '') { $tmpPath = $_REQUEST['data']; $tmpPath = $tmpPath['path']; } $sPath = $this->oValidator->validateString($tmpPath, $aErrorOptions); /* $matches = array(); $aFields = array(); foreach ($_REQUEST as $k => $v) { if (preg_match('/^metadata_(\d+)$/', $k, $matches)) { // multiselect change start $oDocField = DocumentField::get($matches[1]); if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && $oDocField->getHasInetLookup() && is_array($v)) { $v = join(", ", $v); } $aFields[] = array($oDocField, $v); // previously it was just one line which is commented, just above line // multiselect change end } } $aOptions = array( 'documenttype' => $oDocumentType, 'metadata' => $aFields, 'copy_upload' => 'true', ); */ // Newer metadata form field catcher that works with ktcore form array type fields named like // name='metadata[fieldset][metadata_9]' $aData = $_REQUEST['data']; $data = $aData; /* $oForm = $this->getBulkImportForm(); $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError(); } $data = $res['results']; */ $doctypeid = $requestDocumentType; $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false)); $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); $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()); //Fix for multiselect not submitting data due to the value not being flat. $sVal = ''; if (is_array($val)) { foreach ($val as $v) { $sVal .= $v . ", "; } $sVal = substr($sVal, 0, strlen($sVal) - 2); $val = $sVal; } if ($oFieldset->getIsConditional()) { if ($val == _kt('No selection.')) { $val = null; } } if (!is_null($val)) { $MDPack[] = array($oField, $val); } } } $aOptions = array('documenttype' => $oDocumentType, 'metadata' => $MDPack, 'copy_upload' => 'true'); $po =& new JavascriptObserver($this); $po->start(); $oUploadChannel =& KTUploadChannel::getSingleton(); $oUploadChannel->addObserver($po); $fs =& new KTFSImportStorage($sPath); $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions); if (KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin')) { require_once KT_DIR . "/plugins/foldermetadata/import/bulkimport.inc.php"; $bm =& new KTINETBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions); } else { $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions); } DBUtil::startTransaction(); $res = $bm->import(); if (PEAR::isError($res)) { DBUtil::rollback(); $_SESSION["KTErrorMessage"][] = _kt("Bulk import failed") . ": " . $res->getMessage(); } else { DBUtil::commit(); $this->addInfoMessage(_kt("Bulk import succeeded")); } $po->redirectToFolder($this->oFolder->getId()); exit(0); }
$sFieldName = "synctest"; $sSearch = "(objectClass=organizationalPerson)"; $sAttribute = "cn"; $sRootDN = null; $aAuthenticationSources =& KTAuthenticationSource::getList(); $oSource = null; foreach ($aAuthenticationSources as $oPotentialSource) { if ($oPotentialSource->getName() == $sSourceName) { $oSource =& $oPotentialSource; } } if (empty($oSource)) { printf("No authentication source named %s found\n", $sSourceName); exit(1); } $oFieldset =& KTFieldset::getByNamespace($sFieldsetNamespace); if (PEAR::isError($oFieldset)) { printf("No fieldset named %s found\n", $sFieldsetNamespace); exit(1); } $oField = DocumentField::getByFieldsetAndName($oFieldset, $sFieldName); if (PEAR::isError($oField)) { printf("No field named %s found in fieldset %s\n", $sFieldName, $sFieldsetNamespace); exit(1); } $oAuthenticator =& KTAuthenticationUtil::getAuthenticatorForSource($oSource); $oLdap =& $oAuthenticator->oLdap; $aParams = array('scope' => 'sub', 'attributes' => array($sAttribute)); $aResults = $oLdap->search($sRootDn, $sSearch, $aParams); $aValues = array(); foreach ($aResults->entries() as $oEntry) {
function &getByField($oField) { $oField =& KTUtil::getObject('DocumentField', $oField); $iFieldsetId = $oField->getParentFieldsetId(); return KTFieldset::get($iFieldsetId); }
function configure($aOptions) { $res = parent::configure($aOptions); if (PEAR::isError($res)) { return $res; } $this->sIdMethod = KTUtil::arrayGet($aOptions, 'id_method', 'getId'); $this->sLabelMethod = KTUtil::arrayGet($aOptions, 'label_method'); if (empty($this->sLabelMethod)) { return PEAR::raiseError(_kt('No label method specified.')); } $existing_entities = (array) KTUtil::arrayGet($aOptions, 'existing_entities'); if (empty($this->value)) { $this->value = array(); foreach ($existing_entities as $oEntity) { $this->value[] = call_user_func(array(&$oEntity, $this->sIdMethod)); } } $this->iField = KTUtil::arrayGet($aOptions, 'field'); $this->iMasterId = KTUtil::arrayGet($aOptions, 'masterid'); // if we're the master, we have to build the dependancy array and store it as JSON // also, include the javascript if (KTUtil::arrayGet($aOptions, 'master', false)) { $this->bMaster = true; $this->aJavascript = array('resources/js/conditional_selection.js'); $oFieldset = KTFieldset::get(KTUtil::arrayGet($aOptions, 'fieldset')); $aLookups = array(); $aConnections = array(); foreach ($oFieldset->getFields() as $oField) { $c = array(); foreach ($oField->getEnabledValues() as $oMetadata) { $a = array(); // print '<pre>'; $nvals = KTMetadataUtil::getNextValuesForLookup($oMetadata->getId()); if ($nvals) { foreach ($nvals as $i => $aVals) { $a = array_merge($a, $aVals); foreach ($aVals as $id) { $field = $this->_getFieldIdForMetadataId($id); // print 'id ' . $id . ' is in field ' . $field . "<br/>"; if (!in_array($field, $c)) { $c[] = $field; } } } } $aLookups[$oMetadata->getId()] = $a; } $aConnections[$oField->getId()] = $c; } //exit(0); $oJSON = new Services_JSON(); $this->sLookupsJSON = $oJSON->encode($aLookups); $this->sConnectionsJSON = $oJSON->encode($aConnections); } $new_vocab = array(); foreach ($this->aVocab as $oEntity) { $id = call_user_func(array(&$oEntity, $this->sIdMethod)); $label = call_user_func(array(&$oEntity, $this->sLabelMethod)); $new_vocab[$id] = array($label, $oEntity->getId()); } $this->aVocab = $new_vocab; }
/** * Returns a JSON object containing a list of fields belonging to a generic fieldset * for the given DocumentId * @return JSON Object * */ function getNonGenericFields($iDocumentTypeID) { $oFReg =& KTFieldsetRegistry::getSingleton(); $activesets = KTFieldset::getForDocumentType($iDocumentTypeID); $fields = array(); foreach ($activesets as $oFieldset) { $fieldIds = kt_array_merge($fields, $oFReg->getGenericFields($oFieldset)); } $jsOptions = '{ "htmlId" : {'; foreach ($fieldIds as $fieldId) { $jsOptions .= "'{$fieldId}' : '{$fieldId}',"; } $jsOptions = substr($jsOptions, 0, strlen($jsOptions) - 1); $jsOptions .= '}}'; return $jsOptions; }
/** * This should actually not be in ktapi, but in webservice * This method gets metadata fieldsets based on the document type * * @author KnowledgeTree Team * @access public * @param string $document_type The type of document * @return mixed Error object|SOAP object|Array of fieldsets */ public function get_document_type_metadata($document_type = 'Default') { // now get document type specifc ids $typeid = $this->get_documenttypeid($document_type); if (is_a($typeid, 'KTAPI_DocumentTypeError')) { return $typeid; } if (is_null($typeid) || PEAR::isError($typeid)) { $response['message'] = $typeid->getMessage(); return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response); } $doctype_ids = KTFieldset::getForDocumentType($typeid, array('ids' => false)); if (is_null($doctype_ids) || PEAR::isError($doctype_ids)) { $response['message'] = $generic_ids->getMessage(); return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response); } // first get generic ids $generic_ids = KTFieldset::getGenericFieldsets(array('ids' => false)); if (is_null($generic_ids) || PEAR::isError($generic_ids)) { $response['message'] = $generic_ids->getMessage(); return new SOAP_Value('return', "{urn:{$this->namespace}}kt_metadata_response", $response); } // lets merge the results $fieldsets = kt_array_merge($generic_ids, $doctype_ids); $results = array(); foreach ($fieldsets as $fieldset) { if ($fieldset->getIsConditional()) { /* this is not implemented...*/ continue; } $fields = $fieldset->getFields(); $result = array('fieldset' => $fieldset->getName(), 'description' => $fieldset->getDescription()); $fieldsresult = array(); foreach ($fields as $field) { $value = 'n/a'; //$controltype = 'string'; // Replace with true $controltype = strtolower($field->getDataType()); if ($field->getHasLookup()) { $controltype = 'lookup'; if ($field->getHasLookupTree()) { $controltype = 'tree'; } } $options = array(); if ($field->getInetLookupType() == 'multiwithcheckboxes' || $field->getInetLookupType() == 'multiwithlist') { $controltype = 'multiselect'; } switch ($controltype) { case 'lookup': $selection = KTAPI::get_metadata_lookup($field->getId()); break; case 'tree': $selection = KTAPI::get_metadata_tree($field->getId()); break; case 'large text': $options = array('ishtml' => $field->getIsHTML(), 'maxlength' => $field->getMaxLength()); $selection = array(); break; case 'multiselect': $selection = KTAPI::get_metadata_lookup($field->getId()); $options = array('type' => $field->getInetLookupType()); break; default: $selection = array(); } $fieldsresult[] = array('name' => $field->getName(), 'required' => $field->getIsMandatory(), 'value' => $value, 'description' => $field->getDescription(), 'control_type' => $controltype, 'selection' => $selection, 'options' => $options); } $result['fields'] = $fieldsresult; $results[] = $result; } return $results; }
function getFieldsetsForType($oType) { $aCurrentFieldsets = KTFieldset::getForDocumentType($oType); if (empty($aCurrentFieldsets)) { return _kt('No fieldsets'); } $aNames = array(); foreach ($aCurrentFieldsets as $oFieldset) { if (!PEAR::isError($oFieldset)) { $aNames[] = $oFieldset->getName(); } } return implode(', ', $aNames); }
function validateMetadata(&$oDocument, $aMetadata) { $aFieldsets =& KTFieldset::getGenericFieldsets(); $aFieldsets =& kt_array_merge($aFieldsets, KTFieldset::getForDocumentType($oDocument->getDocumentTypeId())); $aSimpleMetadata = array(); foreach ($aMetadata as $aSingleMetadatum) { list($oField, $sValue) = $aSingleMetadatum; if (is_null($oField)) { continue; } $aSimpleMetadata[$oField->getId()] = $sValue; } $aFailed = array(); foreach ($aFieldsets as $oFieldset) { $aFields =& $oFieldset->getFields(); $aFieldValues = array(); $isRealConditional = $oFieldset->getIsConditional() && KTMetadataUtil::validateCompleteness($oFieldset); foreach ($aFields as $oField) { $v = KTUtil::arrayGet($aSimpleMetadata, $oField->getId()); if ($oField->getIsMandatory() && !$isRealConditional) { if (empty($v)) { // XXX: What I'd do for a setdefault... $aFailed['field'][$oField->getId()] = 1; } } if (!empty($v)) { $aFieldValues[$oField->getId()] = $v; } } if ($isRealConditional) { $res = KTMetadataUtil::getNext($oFieldset, $aFieldValues); if ($res) { foreach ($res as $aMDSet) { if ($aMDSet['field']->getIsMandatory()) { $aFailed['fieldset'][$oFieldset->getId()] = 1; } } } } } if (!empty($aFailed)) { return new KTMetadataValidationError($aFailed); } return $aMetadata; }
function do_editComplexFieldset() { $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id"); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/editcomplex"); /* alright: to "do" this we need at least: * 1. the list of all the columns (id, name) and their available values. * 2. the fieldset_id. * we can then render in/out. Everything "intelligent" happens * in AJAX (doing it with submits sucks arse. * * FIXME we fake it here with nested arrays... */ $oFieldset =& KTFieldset::get($fieldset_id); $aFields =& $oFieldset->getFields(); $this->aBreadcrumbs[] = array('url' => KTUtil::ktLink('admin.php', 'documents/fieldmanagement', 'action=edit&fFieldsetId=' . $oFieldset->getId()), 'name' => $oFieldset->getName()); $this->aBreadcrumbs[] = array('url' => KTUtil::ktLink('admin.php', 'documents/fieldmanagement', 'action=manageConditional&fFieldsetId=' . $oFieldset->getId()), 'name' => _kt('Manage conditional fieldset')); $sTable = KTUtil::getTableName('field_orders'); $aQuery = array("SELECT parent_field_id, child_field_id FROM {$sTable} WHERE fieldset_id = ?", array($oFieldset->getId())); $aFieldOrders = DBUtil::getResultArray($aQuery); $aOrders = array(); foreach ($aFieldOrders as $row) { $aChildren = KTUtil::arrayGet($aOrders, $row['parent_field_id'], array()); $aChildren[] = $row['child_field_id']; $aOrders[$row['parent_field_id']] = $aChildren; } $aKeyedFields = array(); $aOrderedFields = array(); $aStack = array($oFieldset->getMasterFieldId()); // first, key foreach ($aFields as $oField) { $aKeyedFields[$oField->getId()] = $oField; } while (!empty($aStack)) { $iKey = array_shift($aStack); // this shouldn't happen, but avoid it anyway. if (!is_null($aKeyedFields[$iKey])) { $aOrderedFields[] = $aKeyedFields[$iKey]; unset($aKeyedFields[$iKey]); } // add children to stack $aStack = kt_array_merge($aStack, $aOrders[$iKey]); } $this->oPage->setBreadcrumbDetails(_kt('Manage complex conditional')); $aTemplateData = array("context" => &$this, "fieldset_id" => $fieldset_id, "ordering" => $aOrders, "aFields" => $aOrderedFields, "iMasterFieldId" => $oFieldset->getMasterFieldId()); return $oTemplate->render($aTemplateData); }
function do_finalise() { $this->persistParams(array('fFileKey')); $sess_key = $_REQUEST['fFileKey']; $oForm = $this->form_metadata($sess_key); $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError(); } $data = $res['results']; $extra_d = $_SESSION['_add_data'][$sess_key]; $doctypeid = $extra_d['document_type']; $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false)); $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); $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()); if ($oFieldset->getIsConditional()) { if ($val == _kt('No selection.')) { $val = null; } } // ALT.METADATA.LAYER.DIE.DIE.DIE if (!is_null($val)) { $MDPack[] = array($oField, $val); } } } // older code $mpo =& new JavascriptObserver($this); $oUploadChannel =& KTUploadChannel::getSingleton(); $oUploadChannel->addObserver($mpo); require_once KT_LIB_DIR . '/storage/storagemanager.inc.php'; //require_once(KT_LIB_DIR . '/filelike/fsfilelike.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'; $aErrorOptions = array('redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())), 'max_str_len' => 200); $aFile = $this->oValidator->validateFile($extra_d['file'], $aErrorOptions); $sTitle = $extra_d['document_name']; $iFolderId = $this->oFolder->getId(); $aOptions = array('temp_file' => $aFile['tmp_name'], 'documenttype' => DocumentType::get($extra_d['document_type']), 'metadata' => $MDPack, 'description' => $sTitle, 'cleanup_initial_file' => true); $mpo->start(); //$this->startTransaction(); $oDocument =& KTDocumentUtil::add($this->oFolder, $aFile['name'], $this->oUser, $aOptions); if (PEAR::isError($oDocument)) { $message = $oDocument->getMessage(); $this->errorRedirectTo('main', sprintf(_kt("Unexpected failure to add document - %s"), $message), 'fFolderId=' . $this->oFolder->getId()); exit(0); } $this->addInfoMessage(_kt("Document added")); //$this->commitTransaction(); $mpo->redirectToDocument($oDocument->getId()); exit(0); }
/** * function to add fieldset entry to fieldsets table * * @return unknown */ function createFieldset() { // create the fieldsets entry $oFieldset = KTFieldset::createFromArray(array('name' => _kt('Tag Cloud'), 'description' => _kt('The following tags are associated with your document'), 'namespace' => 'tagcloud', 'mandatory' => false, 'isConditional' => false, 'isGeneric' => true, 'isComplete' => false, 'isComplex' => false, 'isSystem' => false)); return $oFieldset; }
function fieldsetsForDocument($oDocument, $iTypeOverride = null) { global $default; $oDocument = KTUtil::getObject('Document', $oDocument); $iMetadataVersionId = $oDocument->getMetadataVersionId(); $iDocumentTypeId = $oDocument->getDocumentTypeId(); if (!is_null($iTypeOverride)) { $iDocumentTypeId = $iTypeOverride; } $sQuery = "SELECT DISTINCT F.id AS fieldset_id " . "FROM {$default->document_metadata_version_table} AS DM INNER JOIN document_fields_link AS DFL ON DM.id = DFL.metadata_version_id " . "INNER JOIN {$default->document_fields_table} AS DF ON DF.ID = DFL.document_field_id " . "INNER JOIN {$default->fieldsets_table} AS F ON F.id = DF.parent_fieldset " . "WHERE DM.id = ?" . "AND F.disabled = false"; $aParam = array($iMetadataVersionId); $aDocumentFieldsetIds = DBUtil::getResultArrayKey(array($sQuery, $aParam), 'fieldset_id'); $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => true)); $aSpecificFieldsetIds = KTFieldset::getForDocumentType($iDocumentTypeId, array('ids' => true)); $aFieldsetIds = kt_array_merge($aDocumentFieldsetIds, $aGenericFieldsetIds, $aSpecificFieldsetIds); $aFieldsetIds = array_unique($aFieldsetIds); sort($aFieldsetIds); $aRet = array(); foreach ($aFieldsetIds as $iID) { $aRet[] = call_user_func(array('KTFieldset', 'get'), $iID); } return $aRet; }
function do_savefieldset() { $oForm = $this->form_edit(); $res = $oForm->validate(); $data = $res['results']; $errors = $res['errors']; $extra_errors = array(); if ($data['name'] != $this->oFieldset->getName()) { $oOldFieldset = KTFieldset::getByName($data['name']); if (!PEAR::isError($oOldFieldset)) { $extra_errors['name'][] = _kt("A fieldset with that name already exists."); } } if (!empty($errors) || !empty($extra_errors)) { return $oForm->handleError(null, $extra_errors); } $this->startTransaction(); $this->oFieldset->setName($data['name']); $this->oFieldset->setDescription($data['description']); $bGeneric = $data['generic']; if ($bGeneric != $this->oFieldset->getIsGeneric() && $bGeneric == true) { // delink it from all doctypes. $aTypes = $this->oFieldset->getAssociatedTypes(); foreach ($aTypes as $oType) { $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $this->oFieldset->getId()); if (PEAR::isError($res)) { $this->errorRedirectTo('edit', _kt('Could not save fieldset changes')); exit(0); } } } $this->oFieldset->setIsGeneric($data['generic']); $res = $this->oFieldset->update(); if (PEAR::isError($res)) { $this->errorRedirectTo('edit', _kt('Could not save fieldset changes')); exit(0); } return $this->successRedirectTo('edit', _kt("Fieldset details updated.")); }
function _upgradeSavedSearch($aSearch) { $aMapping = array('-1' => 'ktcore.criteria.name', '-6' => 'ktcore.criteria.id', '-2' => 'ktcore.criteria.title', '-3' => 'ktcore.criteria.creator', '-4' => 'ktcore.criteria.datecreated', '-5' => 'ktcore.criteria.documenttype', '-7' => 'ktcore.criteria.datemodified', '-8' => 'ktcore.criteria.size', '-9' => 'ktcore.criteria.content', '-10' => 'ktcore.criteria.workflowstate', '-13' => 'ktcore.criteria.discussiontext', '-12' => 'ktcore.criteria.searchabletext', '-11' => 'ktcore.criteria.transactiontext'); $aFieldsets =& KTFieldset::getList('disabled != true'); foreach ($aFieldsets as $oFieldset) { $aFields =& DocumentField::getByFieldset($oFieldset); foreach ($aFields as $oField) { $sNamespace = $oFieldset->getNamespace() . '.' . $oField->getName(); $sId = (string) $oField->getId(); $aMapping[$sId] = $sNamespace; } } foreach (array_keys($aSearch['subgroup']) as $sgkey) { $sg =& $aSearch['subgroup'][$sgkey]; foreach (array_keys($sg['values']) as $vkey) { $item =& $sg['values'][$vkey]; $type = $item['type']; $toreplace = 'bmd' . ((int) $type < 0 ? '_' : '') . abs((int) $type); $item['type'] = $aMapping[$type]; $nData = array(); foreach ($item['data'] as $k => $v) { $k = str_replace($toreplace, $aMapping[$type], $k); $nData[$k] = $v; } $item['data'] = $nData; } } return $aSearch; }
/** * make uploads * @return * * iNET Process */ function do_upload() { set_time_limit(0); global $default; $aErrorOptions = array('redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId()))); $aErrorOptions['message'] = _kt('Invalid document type provided'); $requestDocumentType = $_REQUEST['fDocumentTypeId']; //Backwards compatibility if ($requestDocumentType == '' || $requestDocumentType == NULL) { $requestDocumentType = $_REQUEST['data']; $requestDocumentType = $requestDocumentType['fDocumentTypeId']; //New elements come through as arrays } $oDocumentType = $this->oValidator->validateDocumentType($requestDocumentType, $aErrorOptions); unset($aErrorOptions['message']); $fileData = $_FILES['file']; $fileName = 'file'; if ($fileData == '' || $fileData == NULL) { $fileData = $_FILES['_kt_attempt_unique_file']; //$_FILES['_kt_attempt_unique_file']; $fileName = '_kt_attempt_unique_file'; } $aFile = $this->oValidator->validateFile($fileData, $aErrorOptions); // Lets move the file from the windows temp directory into our own directory $oKTConfig =& KTConfig::getSingleton(); $sBasedir = $oKTConfig->get("urls/tmpDirectory"); $tmpFilename = tempnam($sBasedir, 'kt_storebulk'); $oStorage =& KTStorageManagerUtil::getSingleton(); $res = $oStorage->uploadTmpFile($fileData['tmp_name'], $tmpFilename, array('copy_upload' => 'true')); // Save the new temp filename in the file data array $fileData['tmp_name'] = $tmpFilename; if ($res === false) { $default->log->error('File could not be copied from the system temp directory.'); exit('File could not be copied from the system temp directory.'); } $matches = array(); $aFields = array(); // author: Charl Mert // Older kt3 form field submission used name='metadata_9 etc and the aFields array contained them.' // Should keep open here for backwards compatibility but will close it to "discover" the other // old interfaces. /* foreach ($_REQUEST as $k => $v) { if (preg_match('/^metadata_(\d+)$/', $k, $matches)) { // multiselect change start $oDocField = DocumentField::get($matches[1]); if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin') && $oDocField->getHasInetLookup() && is_array($v)) { $v = join(", ", $v); } $aFields[] = array($oDocField, $v); // previously it was just one line which is commented, just above line // multiselect change end } } */ //Newer metadata form field catcher that works with ktcore form array type fields named like //name='metadata[fieldset][metadata_9]' $aData = $_REQUEST['data']; /* //This validation breaks with ajax loaded form items e.g. a non generic fieldset that submits * //values doesn't pass the check below. $oForm = $this->getBulkUploadForm(); $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError(); } $data = $res['results']; var_dump($data); */ $data = $aData; $doctypeid = $requestDocumentType; $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false)); $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); $MDPack = array(); foreach ($fieldsets as $oFieldset) { $fields = $oFieldset->getFields(); $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId()); //var_dump($values); foreach ($fields as $oField) { //var_dump($oField->getId()); $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); //Fix for multiselect not submitting data due to the value not being flat. $sVal = ''; if (is_array($val)) { foreach ($val as $v) { $sVal .= $v . ", "; } $sVal = substr($sVal, 0, strlen($sVal) - 2); $val = $sVal; } if ($oFieldset->getIsConditional()) { if ($val == _kt('No selection.')) { $val = null; } } if (!is_null($val)) { $MDPack[] = array($oField, $val); } } } $aOptions = array('documenttype' => $oDocumentType, 'metadata' => $MDPack); $fs =& new KTZipImportStorage($fileName, $fileData); if (!$fs->CheckFormat()) { $sFormats = $fs->getFormats(); $this->addErrorMessage(sprintf(_kt("Bulk Upload failed. Archive is not an accepted format. Accepted formats are: .%s"), $sFormats)); controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID()); exit; } if (KTPluginUtil::pluginIsActive('inet.foldermetadata.plugin')) { require_once KT_DIR . "/plugins/foldermetadata/import/bulkimport.inc.php"; $bm =& new KTINETBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions); } else { $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions); } $this->startTransaction(); $res = $bm->import(); $aErrorOptions['message'] = _kt("Bulk Upload failed"); $this->oValidator->notError($res, $aErrorOptions); $this->addInfoMessage(_kt("Bulk Upload successful")); $this->commitTransaction(); controllerRedirect("browse", 'fFolderId=' . $this->oFolder->getID()); exit(0); }