Exemplo n.º 1
0
 function do_selectLookup()
 {
     $field = KTUtil::arrayGet($_REQUEST, 'fField', null);
     $oField = DocumentField::get($field);
     if (PEAR::isError($oField) || $oField == false || !$oField->getHasLookup()) {
         $this->errorRedirectToMain('No Field selected.');
         exit(0);
     }
     $_REQUEST['fBrowseMode'] = 'lookup_value';
     $aValues = MetaData::getByDocumentField($oField);
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate('kt3/browse_lookup_value');
     $aTemplateData = array('context' => $this, 'oField' => $oField, 'values' => $aValues);
     return $oTemplate->render($aTemplateData);
 }
Exemplo n.º 2
0
 function do_upload()
 {
     set_time_limit(0);
     $aErrorOptions = array('redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())));
     $aErrorOptions['message'] = _kt('Invalid document type provided');
     $oDocumentType = $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId'], $aErrorOptions);
     unset($aErrorOptions['message']);
     $aFile = $this->oValidator->validateFile($_FILES['file'], $aErrorOptions);
     $matches = array();
     $aFields = array();
     foreach ($_REQUEST as $k => $v) {
         if (preg_match('/^metadata_(\\d+)$/', $k, $matches)) {
             $aFields[] = array(DocumentField::get($matches[1]), $v);
         }
     }
     $aOptions = array('documenttype' => $oDocumentType, 'metadata' => $aFields);
     $fs =& new KTZipImportStorage('file');
     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;
     }
     $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);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 function _evilTreeRecursion($subnode, $treeToRender)
 {
     // deliver us from evil....
     $iFieldId = $treeToRender->field_id;
     $oField = DocumentField::get($iFieldId);
     $iFieldsetId = $oField->getParentFieldsetId();
     $treeStr = "<ul>";
     foreach ($treeToRender->contents[$subnode] as $subnode_id => $subnode_val) {
         if ($subnode_id !== "leaves") {
             $treeStr .= '<li class="treenode active"><a class="pathnode inactive"  onclick="toggleElementClass(\'active\', this.parentNode); toggleElementClass(\'inactive\', this.parentNode);">' . $treeToRender->mapnodes[$subnode_val]->getName() . '</a>';
             $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, false, $subnode_val);
             $treeStr .= $this->_evilTreeRecursion($subnode_val, $treeToRender);
             $treeStr .= '</li>';
         } else {
             foreach ($subnode_val as $leaf) {
                 $treeStr .= '<li class="leafnode">' . $treeToRender->lookups[$leaf]->getName();
                 $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, true, $leaf);
                 $treeStr .= '</li>';
             }
         }
     }
     $treeStr .= '</ul>';
     return $treeStr;
 }
 function widgetsForFieldset($fieldsetOrType, $sContainerName, $oDocument = null)
 {
     // this is likely to be called repeatedly.
     if (is_null($this->oWF)) {
         $this->oWF =& KTWidgetFactory::getSingleton();
     }
     // we're going to create one of two things, here:
     //   - conditional fieldset widget
     //   - a "Fieldset" widget
     // FIXME delegate.
     $oFieldset =& $fieldsetOrType;
     $widgets = array();
     $fields = $oFieldset->getFields();
     if ($oFieldset->getIsConditional()) {
         $iMasterId = $oFieldset->getMasterFieldId();
         $oMasterField = DocumentField::get($iMasterId);
         $newfields = array();
         $newfields[] = $oMasterField;
         foreach ($fields as $oField) {
             if ($oField->getId() != $iMasterId) {
                 $newfields[] = $oField;
             }
         }
         foreach ($newfields as $oField) {
             $fname = 'metadata_' . $oField->getId();
             $value = null;
             if (!is_null($oDocument)) {
                 $oFL = DocumentFieldLink::getByDocumentAndField($oDocument, $oField);
                 if (!is_null($oFL) && !PEAR::isError($oFL)) {
                     $value = $oFL->getValue();
                 }
             }
             $widgets[] = $this->oWF->get('ktcore.widgets.conditionalselection', array('label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 'name' => $fname, 'value' => $value, 'description' => $oField->getDescription(), 'vocab' => MetaData::getEnabledByDocumentField($oField), 'id_method' => 'getName', 'label_method' => 'getName', 'unselected_label' => _kt("No selection."), 'simple_select' => false, 'master' => $oField->getId() == $iMasterId, 'masterid' => $iMasterId, 'fieldset' => $oFieldset->getId(), 'field' => $oField->getId()));
         }
     } else {
         foreach ($fields as $oField) {
             $fname = 'metadata_' . $oField->getId();
             $value = null;
             // check if we had an old value
             if (!is_null($oDocument)) {
                 $oFL = DocumentFieldLink::getByDocumentAndField($oDocument, $oField);
                 if (!is_null($oFL) && !PEAR::isError($oFL)) {
                     $value = $oFL->getValue();
                 }
             }
             // we have to hack in support for the hardcoded types of fields
             // handled by the "generic" widget.
             //
             // we try to make this a little more "sane"
             $type = '';
             if ($oField->getHasLookup()) {
                 if ($oField->getHasLookupTree()) {
                     $type = 'ktcore.fields.tree';
                 } else {
                     $type = 'ktcore.fields.lookup';
                 }
             } else {
                 $type = 'ktcore.fields.string';
             }
             if ($type == 'ktcore.fields.string') {
                 $widgets[] = $this->oWF->get('ktcore.widgets.string', array('label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 'name' => $fname, 'value' => $value, 'description' => $oField->getDescription()));
             } else {
                 if ($type == 'ktcore.fields.lookup') {
                     $widgets[] = $this->oWF->get('ktcore.widgets.entityselection', array('label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 'name' => $fname, 'value' => $value, 'description' => $oField->getDescription(), 'vocab' => MetaData::getEnabledByDocumentField($oField), 'id_method' => 'getName', 'label_method' => 'getName', 'unselected_label' => _kt("No selection."), 'simple_select' => false));
                 } else {
                     if ($type == 'ktcore.fields.tree') {
                         $widgets[] = $this->oWF->get('ktcore.widgets.treemetadata', array('label' => $oField->getName(), 'required' => $oField->getIsMandatory(), 'name' => $fname, 'value' => $value, 'description' => $oField->getDescription(), 'vocab' => MetaData::getEnabledByDocumentField($oField), 'field_id' => $oField->getId()));
                     }
                 }
             }
         }
     }
     return array($this->oWF->get('ktcore.widgets.fieldset', array('label' => $oFieldset->getName(), 'description' => $oFieldset->getDescription(), 'name' => $sContainerName, 'widgets' => $widgets)));
 }
Exemplo n.º 6
0
 function validate($data)
 {
     $results = array();
     $errors = array();
     // very simple if we're required and not present, fail
     // otherwise, its ok.
     $val = KTUtil::arrayGet($data, $this->sInputVariable);
     if (empty($val)) {
         // pass
     } else {
         if ($this->bMulti) {
             $val = (array) $val;
             $failed = array();
             foreach ($val as $k) {
                 if (!$this->aVocab[$k]) {
                     $failed[] = $k;
                 }
             }
             if (!empty($failed)) {
                 $errors[$this->sBasename] = KTUtil::arrayGet($this->aOptions, 'error_message', sprintf(_kt('"%s" are not valid selections.'), implode(', ', $failed)));
             }
         } else {
             $mandatory = true;
             if (substr($this->sInputVariable, 0, 9) == 'metadata_') {
                 $fieldid = substr($this->sInputVariable, 9);
                 $field = DocumentField::get($fieldid);
                 $mandatory = $field->getIsMandatory();
             }
             if (!array_key_exists($val, $this->aVocab) && $mandatory) {
                 $errors[$this->sBasename] = KTUtil::arrayGet($this->aOptions, 'error_message', sprintf(_kt('"%s"is not a valid selection.'), $val));
             }
         }
     }
     if ($this->bProduceOutput) {
         $results[$this->sOutputVariable] = $val;
     }
     return array('errors' => $errors, 'results' => $results);
 }
Exemplo n.º 7
0
 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');
     $oDocumentType = $this->oValidator->validateDocumentType($_REQUEST['fDocumentTypeId'], $aErrorOptions);
     $aErrorOptions['message'] = _kt('Invalid path provided');
     $sPath = $this->oValidator->validateString($_REQUEST['path'], $aErrorOptions);
     $matches = array();
     $aFields = array();
     foreach ($_REQUEST as $k => $v) {
         if (preg_match('/^metadata_(\\d+)$/', $k, $matches)) {
             $aFields[] = array(DocumentField::get($matches[1]), $v);
         }
     }
     $aOptions = array('documenttype' => $oDocumentType, 'metadata' => $aFields, '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);
     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);
 }
Exemplo n.º 8
0
 function do_manageordering()
 {
     $oTemplate =& $this->oValidator->validateTemplate("ktcore/metadata/conditional/manage_ordering");
     $this->oPage->setBreadcrumbDetails(_kt("Manage Field Ordering"));
     $sTable = KTUtil::getTableName('field_orders');
     $aQuery = array("SELECT parent_field_id, child_field_id FROM {$sTable} WHERE fieldset_id = ?", array($this->oFieldset->getId()));
     $aFieldOrders = DBUtil::getResultArray($aQuery);
     $aFields = $this->oFieldset->getFields();
     $aFreeFieldIds = array();
     foreach ($aFields as $oField) {
         $aFreeFieldIds[] = $oField->getId();
     }
     if ($this->oFieldset->getMasterFieldId()) {
         $aParentFieldIds = array($this->oFieldset->getMasterFieldId());
         foreach ($aFieldOrders as $aRow) {
             $aParentFieldIds[] = $aRow['child_field_id'];
         }
         $aParentFields = array();
         foreach (array_unique($aParentFieldIds) as $iId) {
             $aParentFields[] =& DocumentField::get($iId);
         }
         $aFreeFields = array();
         foreach ($aFreeFieldIds as $iId) {
             if (in_array($iId, $aParentFieldIds)) {
                 continue;
             }
             $aFreeFields[] =& DocumentField::get($iId);
         }
     }
     $oTemplate->setData(array('context' => $this, 'parent_fields' => $aParentFields, 'free_fields' => $aFreeFields, 'aFieldOrders' => $aFieldOrders, 'master_form' => $this->form_setmasterfield(), 'orderingargs' => $this->meldPersistQuery("", "orderfields", true)));
     return $oTemplate->render();
 }