コード例 #1
0
$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) {
    // print $oEntry->dn() . "\n";
    $sValue = $oEntry->get_value($sAttribute, 'single');
    // print $sValue . "\n";
    if (!empty($sValue)) {
        $aValues[] = $sValue;
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: basic.inc.php プロジェクト: jpbauer/knowledgetree
 function do_updatefield()
 {
     $oForm = $this->form_editfield($this->oField);
     $res = $oForm->validate();
     $data = $res['results'];
     $errors = $res['errors'];
     $extra_errors = array();
     // check that the field name either hasn't changed, or doesn't exist.
     if ($data['name'] != $this->oField->getName()) {
         $oOldField = DocumentField::getByFieldsetAndName($this->oFieldset, $data['name']);
         // If the field exists throw an error. Mysql doesn't distinguish between é and e so check the names are different in php.
         if (!PEAR::isError($oOldField) && $oOldField->getName() == $data['name']) {
             $extra_errors['name'] = _kt("That name is already in use in this fieldset.  Please specify a unique name.");
         }
     }
     if (!empty($errors) || !empty($extra_errors)) {
         return $oForm->handleError(null, $extra_errors);
     }
     $this->oField->setName($data['name']);
     $this->oField->setDescription($data['description']);
     $this->oField->setIsMandatory($data['required']);
     $res = $this->oField->update();
     if (PEAR::isError($res)) {
         return $oForm->handleError(sprintf(_kt("Failed to update field: %s"), $res->getMessage()));
     }
     $this->successRedirectTo('managefield', _kt("Field updated."));
 }