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];
     }
 }
Example #2
0
 function do_updateFieldset()
 {
     global $main;
     $GLOBALS['default']->log->error(print_r($_REQUEST, true));
     header('Content-Type: application/xml');
     $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fieldset']);
     $matches = array();
     $aFields = array();
     foreach ($_REQUEST as $k => $v) {
         if (preg_match('/^metadata_(\\d+)$/', $k, $matches)) {
             $aValues[$matches[1]] = $v;
         }
     }
     $aNextFieldValues =& KTMetadataUtil::getNext($oFieldset, $aValues);
     $sWidgets = '';
     // convert these into widgets using the ever-evil...
     // function getWidgetForMetadataField($field, $current_value, $page, $errors = null, $vocab = null)
     foreach ($aNextFieldValues as $aFieldInfo) {
         $vocab = array();
         $vocab[''] = 'Unset';
         foreach ($aFieldInfo['values'] as $md_v) {
             $vocab[$md_v->getName()] = $md_v->getName();
         }
         $req = $aFieldInfo['field']->getIsMandatory();
         $oWidget = getWidgetForMetadataField($aFieldInfo['field'], null, $main, null, $vocab, array('required' => $req));
         $sWidgets .= $oWidget->render();
     }
     return $sWidgets;
 }
<?php

require_once '../../config/dmsDefaults.php';
require_once KT_LIB_DIR . '/metadata/metadatautil.inc.php';
$aNewValues = array('zxcv', 'asdfq', 'tgb', 'edrf');
$res = KTMetadataUtil::synchroniseMetadata(4, $aNewValues);
<?php

require_once '../../config/dmsDefaults.php';
require_once KT_LIB_DIR . '/metadata/metadatautil.inc.php';
error_reporting(E_ALL);
var_dump(KTMetadataUtil::checkConditionalFieldsetCompleteness(11));
Example #5
0
 function do_addfieldsets()
 {
     $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']);
     $aFieldsetId = $_REQUEST['fieldsetid'];
     if (!count($aFieldsetId)) {
         $this->errorRedirectTo('edit', _kt('You must select at least one fieldset'), 'fDocumentTypeId=' . $oDocumentType->getId());
         exit(0);
     }
     $res = KTMetadataUtil::addSetsToDocumentType($oDocumentType, $aFieldsetId);
     if (PEAR::isError($res)) {
         var_dump($res);
         $this->errorRedirectTo('edit', _kt('Changes not saved'), 'fDocumentTypeId=' . $oDocumentType->getId());
         exit(0);
     }
     $this->successRedirectTo('edit', _kt('Fieldsets associated.'), 'fDocumentTypeId=' . $oDocumentType->getId());
     exit(0);
 }
 /**
  * Checks whether a conditional fieldset has the necessary
  * relationships set up to be usable - this means that for each
  * field, no matter how it is reached, there is at least one option
  * available to choose.
  */
 function checkConditionalFieldsetCompleteness($oFieldset)
 {
     $oFieldset =& KTUtil::getObject('KTFieldset', $oFieldset);
     if ($oFieldset->getIsConditional() == false) {
         // If we're not conditional, we are fine.
         return true;
     }
     /*
      * First, ensure at least one master field item has a behaviour
      * assigned to it.  That allows at least one item in the master
      * field to be chosen.
      */
     $iMasterFieldId = $oFieldset->getMasterFieldId();
     $sTable = KTUtil::getTableName('field_value_instances');
     $sLookupTable = KTUtil::getTableName('metadata_lookup');
     $aQuery = array("SELECT COUNT(FVI.id) AS cnt FROM {$sTable} AS FVI LEFT JOIN {$sLookupTable} AS ML ON (FVI.field_value_id = ML.id) WHERE FVI.field_id = ? AND ML.disabled = 0", array($iMasterFieldId));
     $iCount = DBUtil::getOneResultKey($aQuery, 'cnt');
     if (PEAR::isError($iCount)) {
         return $iCount;
     }
     $GLOBALS['default']->log->debug("Number of value instances for master field: {$iCount}");
     if ($iCount == 0) {
         $GLOBALS['default']->log->debug("Number of value instances for master field is zero, failing");
         return PEAR::raiseError(_kt("Master field has no values which are assigned to behaviours."));
     }
     $GLOBALS['default']->log->debug("Number of value instances for master field is positive, continuing");
     // fix for KTS-1023
     // check that each master-field value has a valueinstance assigned.
     $sTable = KTUtil::getTableName('metadata_lookup');
     $aQuery = array("SELECT COUNT(id) AS cnt FROM {$sTable} WHERE document_field_id = ? AND disabled = 0 ", array($iMasterFieldId));
     $iValCount = DBUtil::getOneResultKey($aQuery, 'cnt');
     // assumes that there cannot be more than 1 value instance for each master-field-value.
     if ($iValCount != $iCount) {
         return PEAR::raiseError(sprintf(_kt('%d values for the Master Field are not assigned to behaviours.'), $iValCount - $iCount));
     }
     /*
      * Plan: For each behaviour that is assigned on the system,
      * ensure that it allows at least one value instance in each of
      * the fields that it needs to affect.
      */
     $sTable = KTUtil::getTableName('field_value_instances');
     $sFieldTable = KTUtil::getTableName('document_fields');
     $aQuery = array("SELECT DISTINCT FV.behaviour_id AS behaviour_id FROM {$sTable} AS FV INNER JOIN {$sFieldTable} AS F ON FV.field_id = F.id WHERE F.parent_fieldset = ? AND FV.behaviour_id IS NOT NULL", array($oFieldset->getId()));
     $aBehaviourIds = DBUtil::getResultArrayKey($aQuery, 'behaviour_id');
     if (PEAR::isError($aBehaviourIds)) {
         return $aBehaviourIds;
     }
     foreach ($aBehaviourIds as $iBehaviourId) {
         $GLOBALS['default']->log->debug("Checking behaviour id: " . $iBehaviourId);
         $oBehaviour =& KTFieldBehaviour::get($iBehaviourId);
         $sBehaviourName = $oBehaviour->getName();
         $sBehaviourHumanName = $oBehaviour->getHumanName();
         $iParentFieldId = $oBehaviour->getFieldId();
         $GLOBALS['default']->log->debug("   field is " . $iParentFieldId);
         $aNextFields = KTMetadataUtil::getChildFieldIds($iParentFieldId);
         $oParentField =& DocumentField::get($iParentFieldId);
         $sParentFieldName = $oParentField->getName();
         $GLOBALS['default']->log->debug("   next fields must include " . print_r($aNextFields, true));
         $sTable = KTUtil::getTableName('field_behaviour_options');
         $aQuery = array("SELECT DISTINCT field_id FROM {$sTable} WHERE behaviour_id = ?", array($iBehaviourId));
         $aFields = DBUtil::getResultArrayKey($aQuery, 'field_id');
         $GLOBALS['default']->log->debug("   actual fields are " . print_r($aNextFields, true));
         /*
         foreach ($aNextFields as $iFieldId) {
             if (!in_array($iFieldId, $aFields)) {
                 $GLOBALS['default']->log->debug("   field $iFieldId is not included, failing");
                 $oChildField =& DocumentField::get($iFieldId);
                 $sChildFieldName = $oChildField->getName();
                 return PEAR::raiseError("Child field $sChildFieldName of parent field $sParentFieldName has no selectable values in behaviour $sBehaviourHumanName ($sBehaviourName)");
         
         }
         */
     }
     $GLOBALS['default']->log->debug("Got through: passed!");
     return true;
 }
Example #7
0
 function do_trytype()
 {
     $oForm = $this->form_changetype();
     $res = $oForm->validate();
     $data = $res['results'];
     $errors = $res['errors'];
     if (!empty($errors)) {
         $oForm->handleError();
     }
     $document_type = $data['type'];
     $doctypeid = $document_type->getId();
     // Get the current document type, fieldsets and metadata
     $iOldDocTypeID = $this->oDocument->getDocumentTypeID();
     $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $iOldDocTypeID);
     $mdlist = DocumentFieldLink::getByDocument($this->oDocument);
     $field_values = array();
     foreach ($mdlist as $oFieldLink) {
         $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
     }
     DBUtil::startTransaction();
     // Update the document with the new document type id
     $this->oDocument->startNewMetadataVersion($this->oUser);
     $this->oDocument->setDocumentTypeId($doctypeid);
     $res = $this->oDocument->update();
     if (PEAR::isError($res)) {
         DBUtil::rollback();
         return $res;
     }
     // Ensure all values for fieldsets common to both document types are retained
     $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)) {
             $fields = $oFieldset->getFields();
             foreach ($fields as $oField) {
                 $val = isset($field_values[$oField->getId()]) ? $field_values[$oField->getId()] : '';
                 if (!empty($val)) {
                     $MDPack[] = array($oField, $val);
                 }
             }
         }
     }
     $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack, array('novalidate' => true));
     if (PEAR::isError($core_res)) {
         DBUtil::rollback();
         return $core_res;
     }
     DBUtil::commit();
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array("document" => $this->oDocument, "aOptions" => $MDPack);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
     }
     // Check if there are any dynamic conditions / permissions that need to be updated on the document
     // If there are dynamic conditions then update the permissions on the document
     // The dynamic condition test fails unless the changes exists in the DB therefore update permissions after committing the transaction.
     $iPermissionObjectId = $this->oDocument->getPermissionObjectID();
     $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId);
     if (!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)) {
         $res = KTPermissionUtil::updatePermissionLookup($this->oDocument);
     }
     $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName()));
 }
Example #8
0
 function do_main()
 {
     // fix legacy, broken items.
     if (KTUtil::arrayGet($_REQUEST, 'fDocumentID', true) !== true) {
         $_REQUEST['fDocumentId'] = sanitizeForSQL(KTUtil::arrayGet($_REQUEST, 'fDocumentID'));
         unset($_REQUEST['fDocumentID']);
     }
     $document_data = array();
     $document_id = sanitizeForSQL(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();
     }
     // try get the document.
     $oDocument =& Document::get($document_id);
     if (PEAR::isError($oDocument)) {
         $this->oPage->addError(sprintf(_kt("The document you attempted to retrieve is invalid.   Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl()));
         $this->oPage->booleanLink = true;
         return $this->do_error();
     }
     $document_id = $oDocument->getId();
     $document_data['document_id'] = $oDocument->getId();
     if (!KTBrowseUtil::inAdminMode($this->oUser, $oDocument->getFolderId())) {
         if ($oDocument->getStatusID() == ARCHIVED) {
             $this->oPage->addError(_kt('This document has been archived.  Please contact the system administrator to have it restored if it is still needed.'));
             return $this->do_request($oDocument);
         } else {
             if ($oDocument->getStatusID() == DELETED) {
                 $this->oPage->addError(_kt('This document has been deleted.  Please contact the system administrator to have it restored if it is still needed.'));
                 return $this->do_error();
             } else {
                 if (!Permission::userHasDocumentReadPermission($oDocument)) {
                     $this->oPage->addError(_kt('You are not allowed to view this document'));
                     return $this->permissionDenied();
                 }
             }
         }
     }
     if ($oDocument->getStatusID() == ARCHIVED) {
         $this->oPage->addError(_kt('This document has been archived.'));
     } else {
         if ($oDocument->getStatusID() == DELETED) {
             $this->oPage->addError(_kt('This document has been deleted.'));
         }
     }
     $this->oPage->setSecondaryTitle($oDocument->getName());
     $aOptions = array('documentaction' => 'viewDocument', 'folderaction' => 'browse');
     $this->oDocument =& $oDocument;
     //Figure out if we came here by navigating trough a shortcut.
     //If we came here from a shortcut, the breadcrumbspath should be relative
     //to the shortcut folder.
     $iSymLinkFolderId = KTUtil::arrayGet($_REQUEST, 'fShortcutFolder', null);
     if (is_numeric($iSymLinkFolderId)) {
         $oBreadcrumbsFolder = Folder::get($iSymLinkFolderId);
         $aOptions['final'] = false;
         $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForFolder($oBreadcrumbsFolder, $aOptions));
         $this->aBreadcrumbs[] = array('name' => $this->oDocument->getName());
     } else {
         $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions, $iSymLinkFolderId));
     }
     $this->oPage->setBreadcrumbDetails(_kt('document details'));
     $this->addPortlets('Document Details');
     $document_data['document'] = $oDocument;
     $document_data['document_type'] =& DocumentType::get($oDocument->getDocumentTypeID());
     $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::getByDocument($oDocument);
     $field_values = array();
     foreach ($mdlist as $oFieldLink) {
         $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
     }
     //var_dump($field_values);
     $document_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());
     $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
     $aDocFieldsets = KTMetadataUtil::fieldsetsForDocument($oDocument);
     foreach ($aDocFieldsets as $oFieldset) {
         $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
         array_push($fieldsets, new $displayClass($oFieldset));
     }
     $checkout_user = '******';
     if ($oDocument->getIsCheckedOut() == 1) {
         $oCOU = User::get($oDocument->getCheckedOutUserId());
         if (!(PEAR::isError($oCOU) || $oCOU == false)) {
             $checkout_user = $oCOU->getName();
         }
     }
     // is the checkout action active?
     $bCanCheckin = false;
     foreach ($this->actions as $oDocAction) {
         $sActName = $oDocAction->sName;
         if ($sActName == 'ktcore.actions.document.cancelcheckout') {
             if ($oDocAction->getInfo()) {
                 $bCanCheckin = true;
             }
         }
     }
     // viewlets.
     $aViewlets = array();
     $aViewletActions = KTDocumentActionUtil::getDocumentActionsForDocument($this->oDocument, $this->oUser, 'documentviewlet');
     foreach ($aViewletActions as $oAction) {
         $aInfo = $oAction->getInfo();
         if ($aInfo !== null) {
             $aViewlets[] = $oAction->display_viewlet();
             // use the action, since we display_viewlet() later.
         }
     }
     $viewlet_data = implode(' ', $aViewlets);
     $viewlet_data = trim($viewlet_data);
     $content_class = 'view';
     if (!empty($viewlet_data)) {
         $content_class = 'view withviewlets';
     }
     $this->oPage->setContentClass($content_class);
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate('ktcore/document/view');
     $aTemplateData = array('context' => $this, 'sCheckoutUser' => $checkout_user, 'isCheckoutUser' => $this->oUser->getId() == $oDocument->getCheckedOutUserId(), 'canCheckin' => $bCanCheckin, 'document_id' => $document_id, 'document' => $oDocument, 'documentName' => $oDocument->getName(), 'document_data' => $document_data, 'fieldsets' => $fieldsets, 'viewlet_data' => $viewlet_data);
     //return '<pre>' . print_r($aTemplateData, true) . '</pre>';
     return $oTemplate->render($aTemplateData);
 }
 /**
  * This returns all metadata for the document.
  *
  * <code>
  * $ktapi = new KTAPI();
  * $session = $ktapi->start_system_session();
  * $document = $ktapi->get_document_by_id($documentid);
  * $metadata = $document->get_metadata();
  * foreach($metadata as $fieldset){
  *     echo '<br><br>Fieldset: '.$fieldset['fieldset'];
  *
  *     foreach($fieldset['fields'] as $field){
  *         echo '<br>Field name: '.$field['name'] . ' Value: '. $field['value'];
  *     }
  * }
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @return array An array of metadata fieldsets and fields
  */
 function get_metadata()
 {
     $doctypeid = $this->document->getDocumentTypeID();
     $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->document, $doctypeid);
     if (is_null($fieldsets) || PEAR::isError($fieldsets)) {
         return array();
     }
     $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 = '';
             $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field);
             if (!is_null($fieldvalue) && !PEAR::isError($fieldvalue)) {
                 $value = $fieldvalue->getValue();
             }
             $controltype = 'string';
             if ($field->getHasLookup()) {
                 $controltype = 'lookup';
                 if ($field->getHasLookupTree()) {
                     $controltype = 'tree';
                 }
             }
             switch ($controltype) {
                 case 'lookup':
                     $selection = KTAPI::get_metadata_lookup($field->getId());
                     break;
                 case 'tree':
                     $selection = KTAPI::get_metadata_tree($field->getId());
                     break;
                 default:
                     $selection = array();
             }
             $fieldsresult[] = array('name' => $field->getName(), 'required' => $field->getIsMandatory(), 'value' => $value == '' ? 'n/a' : $value, 'blankvalue' => $value == '' ? '1' : '0', 'description' => $field->getDescription(), 'control_type' => $controltype, 'selection' => $selection);
         }
         $result['fields'] = $fieldsresult;
         $results[] = $result;
     }
     return $results;
 }
}
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) {
    // print $oEntry->dn() . "\n";
    $sValue = $oEntry->get_value($sAttribute, 'single');
    // print $sValue . "\n";
    if (!empty($sValue)) {
        $aValues[] = $sValue;
    }
}
$aValues = array_unique($aValues);
KTMetadataUtil::synchroniseMetadata($oField, $aValues);
Example #11
0
 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;
 }
 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 do_updateActiveLookups()
 {
     global $default;
     $default->log->error(http_build_query($_REQUEST));
     $active_field = KTUtil::arrayGet($_REQUEST, 'active_field');
     // field which is "active".
     $selected_lookup = KTUtil::arrayGet($_REQUEST, 'selected_lookup');
     // selected value in said field.
     // REMEMBER TO SET CONTENT-TYPE application/xml
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_lookups');
     $aFieldLookups = KTMetadataUtil::getNextValuesForLookup($selected_lookup);
     $oTemplate->setData(array('aFieldLookups' => $aFieldLookups));
     header("Content-Type: application/xml");
     print $oTemplate->render();
     exit(0);
 }
 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_getActiveFields()
 {
     $GLOBALS['default']->log->error(print_r($_REQUEST, true));
     $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour');
     // $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); //
     $oFieldset =& $this->oValidator->validateFieldset(KTUtil::arrayGet($_REQUEST, 'fieldset_id'));
     if (empty($parent_behaviour)) {
         $aFieldIds = array($oFieldset->getMasterFieldId());
     } else {
         $oBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour);
         $iActiveFieldId = $oBehaviour->getFieldId();
         $aFieldIds = KTMetadataUtil::getChildFieldIds($iActiveFieldId);
     }
     $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/conditional/ajax_complex_get_active_fields');
     $oTemplate->setData(array('aFieldIds' => $aFieldIds));
     $GLOBALS['default']->log->error(print_r(KTMetadataUtil::getChildFieldIds($iActiveFieldId), true));
     header('Content-type: application/xml');
     /// header('Content-type: text/plain');
     return $oTemplate->render();
 }
Example #16
0
 function getIncomplete($oFieldset)
 {
     $res = KTMetadataUtil::checkConditionalFieldsetCompleteness($oFieldset);
     if (PEAR::isError($res)) {
         $sIncomplete = $res->getMessage();
     } else {
         $sIncomplete = null;
     }
     return $sIncomplete;
 }