diff --git a/clienttools/.gitignore b/clienttools/.gitignore
new file mode 100644
index 0000000..0bde6cd
--- /dev/null
+++ b/clienttools/.gitignore
@@ -0,0 +1,10 @@
+*~
+bin/luceneserver/lucene.pid
+*.tmproj
+.DS_Store
+.buildpath
+.project
+.settings/
+dummy.php
+var/*
+plugins/commercial
diff --git a/plugins/multiselect/InetWidgets.php b/plugins/multiselect/InetWidgets.php
index 1a687c5..c2eb83c 100644
--- a/plugins/multiselect/InetWidgets.php
+++ b/plugins/multiselect/InetWidgets.php
@@ -1,149 +1,149 @@
-.
- *
- * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
- * California 94120-7775, or email info@knowledgetree.com.
- *
- * The interactive user interfaces in modified source and object code versions
- * of this program must display Appropriate Legal Notices, as required under
- * Section 5 of the GNU General Public License version 3.
- *
- * In accordance with Section 7(b) of the GNU General Public License version 3,
- * these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
- * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
- * Contributor( s): ______________________________________
- *
- */
-
-require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
-require_once(KT_LIB_DIR . '/widgets/basewidget.inc.php');
-require_once(KT_LIB_DIR . '/templating/templating.inc.php');
-require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php');
-
-class InetMultiselectWidget extends KTBaseWidget
-{
- var $sTemplate = "multiselect/selection";
-
-
- /**
- * assign the class variables
- * @return
- * @param $sLabel Object
- * @param $sDescription Object
- * @param $sName Object
- * @param $value Object
- * @param $oPage Object
- * @param $bRequired Object[optional]
- * @param $sId Object[optional]
- * @param $aErrors Object[optional]
- * @param $aOptions Object[optional]
- *
- * iNET Process
- */
- function InetMultiselectWidget($sLabel, $sDescription, $sName, $value, &$oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null)
- {
- $this->sLabel = $sLabel;
- $this->sDescription = $sDescription;
- $this->sName = $sName;
- $this->value = $value;
- $this->oPage =& $oPage;
- $this->bRequired = $bRequired;
- $this->sId = $sId;
- $this->aOptions = $aOptions;
- $this->aErrors = $aErrors;
-
- if (is_null($this->aOptions)) { $this->aOptions = array(); }
- // default to being a bit bigger.
- $this->aOptions['width'] = KTUtil::arrayGet($this->aOptions, 'width', '45');
- if($this->aOptions['lookup_type'] == "multiwithcheckboxes")
- {
- $this->sTemplate = "multiselect/simple_selection";
- }
-
- }
-
-
- /**
- * returns the rendered templates
- * @return
- *
- * iNET Process
- */
- function render() {
- // very simple, general purpose passthrough. Chances are this is sufficient,
- // just override the template being used.
- $bHasErrors = false;
- if (count($this->aErrors) != 0) { $bHasErrors = true; }
-
- $oTemplating =& KTTemplating::getSingleton();
- $oTemplate = $oTemplating->loadTemplate($this->sTemplate);
-
- $aTemplateData = array(
- "context" => $this,
- "label" => $this->sLabel,
- "description" => $this->sDescription,
- "name" => $this->sName,
- "required" => $this->bRequired,
- "page" => $this->oPage,
- "has_id" => ($this->sId !== null),
- "id" => $this->sId,
- "has_value" => ($this->value !== null),
- "value" => $this->value,
- "has_errors" => $bHasErrors,
- "errors" => $this->aErrors,
- "options" => $this->aOptions,
- "vocab" => $this->aOptions['vocab'],
- );
- return $oTemplate->render($aTemplateData);
- }
-
-
- /**
- * returns the selected lookup value
- * @return
- * @param $lookup Object
- *
- * iNET Process
- */
- function selected($lookup) {
- if ($this->bMulti) {
- return $this->_valuesearch[$lookup];
- } else {
- return ($this->value == $lookup);
- }
- }
-
- /**
- *
- * @return array
- * @param $raw_data array
- *
- * iNET Process
- */
- function process($raw_data) {
- return array($this->sBasename => $raw_data[$this->sBasename]);
- }
-}
-
+.
+ *
+ * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
+ * California 94120-7775, or email info@knowledgetree.com.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "Powered by
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
+ * Contributor( s): ______________________________________
+ *
+ */
+
+require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
+require_once(KT_LIB_DIR . '/widgets/basewidget.inc.php');
+require_once(KT_LIB_DIR . '/templating/templating.inc.php');
+require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php');
+
+class InetMultiselectWidget extends KTBaseWidget
+{
+ var $sTemplate = "multiselect/selection";
+
+
+ /**
+ * assign the class variables
+ * @return
+ * @param $sLabel Object
+ * @param $sDescription Object
+ * @param $sName Object
+ * @param $value Object
+ * @param $oPage Object
+ * @param $bRequired Object[optional]
+ * @param $sId Object[optional]
+ * @param $aErrors Object[optional]
+ * @param $aOptions Object[optional]
+ *
+ * iNET Process
+ */
+ function InetMultiselectWidget($sLabel, $sDescription, $sName, $value, &$oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null)
+ {
+ $this->sLabel = $sLabel;
+ $this->sDescription = $sDescription;
+ $this->sName = $sName;
+ $this->value = $value;
+ $this->oPage =& $oPage;
+ $this->bRequired = $bRequired;
+ $this->sId = $sId;
+ $this->aOptions = $aOptions;
+ $this->aErrors = $aErrors;
+
+ if (is_null($this->aOptions)) { $this->aOptions = array(); }
+ // default to being a bit bigger.
+ $this->aOptions['width'] = KTUtil::arrayGet($this->aOptions, 'width', '45');
+ if($this->aOptions['lookup_type'] == "multiwithcheckboxes")
+ {
+ $this->sTemplate = "multiselect/simple_selection";
+ }
+
+ }
+
+
+ /**
+ * returns the rendered templates
+ * @return
+ *
+ * iNET Process
+ */
+ function render() {
+ // very simple, general purpose passthrough. Chances are this is sufficient,
+ // just override the template being used.
+ $bHasErrors = false;
+ if (count($this->aErrors) != 0) { $bHasErrors = true; }
+
+ $oTemplating =& KTTemplating::getSingleton();
+ $oTemplate = $oTemplating->loadTemplate($this->sTemplate);
+
+ $aTemplateData = array(
+ "context" => $this,
+ "label" => $this->sLabel,
+ "description" => $this->sDescription,
+ "name" => $this->sName,
+ "required" => $this->bRequired,
+ "page" => $this->oPage,
+ "has_id" => ($this->sId !== null),
+ "id" => $this->sId,
+ "has_value" => ($this->value !== null),
+ "value" => $this->value,
+ "has_errors" => $bHasErrors,
+ "errors" => $this->aErrors,
+ "options" => $this->aOptions,
+ "vocab" => $this->aOptions['vocab'],
+ );
+ return $oTemplate->render($aTemplateData);
+ }
+
+
+ /**
+ * returns the selected lookup value
+ * @return
+ * @param $lookup Object
+ *
+ * iNET Process
+ */
+ function selected($lookup) {
+ if ($this->bMulti) {
+ return $this->_valuesearch[$lookup];
+ } else {
+ return ($this->value == $lookup);
+ }
+ }
+
+ /**
+ *
+ * @return array
+ * @param $raw_data array
+ *
+ * iNET Process
+ */
+ function process($raw_data) {
+ return array($this->sBasename => $raw_data[$this->sBasename]);
+ }
+}
+
?>
\ No newline at end of file
diff --git a/plugins/multiselect/InetdocumentFieldsv2.php b/plugins/multiselect/InetdocumentFieldsv2.php
index 9b90e96..0d6e149 100644
--- a/plugins/multiselect/InetdocumentFieldsv2.php
+++ b/plugins/multiselect/InetdocumentFieldsv2.php
@@ -1,520 +1,520 @@
-.
- *
- * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
- * California 94120-7775, or email info@knowledgetree.com.
- *
- * The interactive user interfaces in modified source and object code versions
- * of this program must display Appropriate Legal Notices, as required under
- * Section 5 of the GNU General Public License version 3.
- *
- * In accordance with Section 7(b) of the GNU General Public License version 3,
- * these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
- * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
- * Contributor( s): ______________________________________
- *
- */
-
-require_once(KT_LIB_DIR . '/dispatcher.inc.php');
-require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
-require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
-require_once(KT_LIB_DIR . '/plugins/pluginutil.inc.php');
-
-class InetDocumentFieldDispatcher extends KTAdminDispatcher {
- var $bAutomaticTransaction = true;
- var $bHaveConditional = null;
- var $sHelpPage = 'ktcore/admin/document fieldsets.html';
-
- /**
- *
- * @return.
- * @param.
- *
- * iNET Process
- */
- function predispatch() {
- $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Document Field Management'));
- $this->persistParams(array('fFieldsetId'));
-
- $this->oFieldset = KTFieldset::get(KTUtil::arrayGet($_REQUEST, 'fFieldsetId'));
- if (PEAR::isError($this->oFieldset)) {
- $this->oFieldset = null;
- unset($_REQUEST['fFieldset']); // prevent further attacks.
- } else {
- $this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit")), 'name' => $this->oFieldset->getName());
- }
- $this->bHaveConditional = KTPluginUtil::pluginIsActive('ktextra.conditionalmetadata.plugin');
- }
-
- /**
- * create template
- * @Param.
- * @return template.
- *
- * iNET Process
- */
- function do_main () {
- $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/list');
-
- $oTemplate->setData(array(
- 'context' => $this,
- 'fieldsets' => KTFieldset::getList("disabled != true AND namespace != 'tagcloud'"),
- ));
- return $oTemplate;
- }
-
- /**
- * form for creating new fieldset.
- * @Param.
- * @return form.
- *
- * iNET Process
- */
- function form_create() {
- $oForm = new KTForm;
- $oForm->setOptions(array(
- 'identifier' => 'ktcore.fieldsets.create',
- 'label' => _kt("Create New Fieldset"),
- 'submit_label' => _kt('Create Fieldset'),
- 'cancel_action' => 'main',
- 'fail_action' => 'newfieldset',
- 'action' => 'create',
- 'context' => $this,
- ));
-
-
- // construct the widget set.
- // we use a slight variation here, because "type" is only present in certain circumstances.
- $widgets = array(
- array('ktcore.widgets.string',array(
- 'label' => _kt("Fieldset Name"),
- 'name' => 'name',
- 'required' => true,
- 'description' => _kt("Each fieldset needs a unique name."),
- )),
- array('ktcore.widgets.text',array(
- 'label' => _kt("Description"),
- 'name' => 'description',
- 'required' => true,
- 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
- )),
- );
- if ($this->bHaveConditional) {
-
- // FIXME get this from some external source.
- $type_vocab = array(
- 'normal' => _kt("Normal"),
- 'conditional' => _kt("Conditional"),
- );
-
- $widgets[] = array('ktcore.widgets.selection', array(
- 'label' => _kt("Fieldset Type"),
- 'use_simple' => false,
- 'description' => _kt("It is possibler to create different types of fieldsets. The most common kind is a \"normal\" fieldset, which can be configured to have different kinds of fields. The administrator may have installed additional plugins which provide different types of fieldsets."),
- 'important_description' => _kt('Note that it is not possible to convert between different types of fieldsets, so please choose carefully.'),
- 'name' => 'fieldset_type',
- 'required' => true,
- 'value' => 'normal',
- 'vocab' => $type_vocab,
- ));
- }
-
- $widgets[] = array('ktcore.widgets.boolean',array(
- 'label' => _kt("Generic"),
- 'name' => 'generic',
- 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
- ));
-
- $oForm->setWidgets($widgets);
-
- // similarly, we construct validators here.
- $validators = array(
- array('ktcore.validators.string', array(
- 'test' => 'name',
- 'output' => 'name',
- )),
- array('ktcore.validators.string', array(
- 'test' => 'description',
- 'output' => 'description',
- )),
- array('ktcore.validators.boolean', array(
- 'test' => 'generic',
- 'output' => 'generic',
- )),
- );
-
- if ($this->bHaveConditional) {
- $validators[] = array('ktcore.validators.string', array(
- 'test' => 'fieldset_type',
- 'output' => 'fieldset_type',
- ));
- }
-
- $oForm->setValidators($validators);
-
- return $oForm;
- }
- /**
- * Creates a new page
- * @return form
- *
- * iNET Process
- */
- function do_newfieldset() {
- $this->oPage->setBreadcrumbDetails(_kt("Create New Fieldset"));
- $oForm = $this->form_create();
-
- return $oForm->render();
- }
- /**
- * Creates a fieldsets
- * @return
- *
- * iNET Process
- */
- function do_create() {
- $oForm = $this->form_create();
- $res = $oForm->validate();
-
- $data = $res['results'];
- $errors = $res['errors'];
- $extra_errors = array();
-
- if (!empty($data['name'])) {
- $oFieldset = KTFieldset::getByName($data['name']);
- if (!PEAR::isError($oFieldset)) {
- // means we're looking at an existing name
- $extra_errors['name'] = _kt("There is already a fieldset with that name.");
- }
- }
-
- $is_conditional = false;
- // FIXME this is inelegant. get it from somewhere else.
- if ($this->bHaveConditional && ($data['fieldset_type'] == 'conditional')) {
- $is_conditional = true;
- }
-
-
- if (!empty($errors) || !empty($extra_errors)) {
- return $oForm->handleError(null, $extra_errors);
- }
-
- // we also need a namespace.
- $temp_name = $data['name'];
- $namespace = KTUtil::nameToLocalNamespace('fieldsets', $temp_name);
- $oOldFieldset = KTFieldset::getByNamespace($namespace);
-
- while (!PEAR::isError($oOldFieldset)) {
- $temp_name .= '_';
- $namespace = KTUtil::nameToLocalNamespace('fieldsets', $temp_name);
- $oOldFieldset = KTFieldset::getByNamespace($namespace);
- }
-
- // we now know its a non-conflicting one.
- // FIXME handle conditional fieldsets, which should be ... a different object.
- $oFieldset = KTFieldset::createFromArray(array(
- "name" => $data['name'],
- "description" => $data['description'],
- "namespace" => $namespace,
- "mandatory" => false, // FIXME deprecated
- "isConditional" => $is_conditional, // handle this
- "isGeneric" => $data['generic'],
- "isComplete" => false,
- "isComplex" => false,
- "isSystem" => false,
- ));
- if (PEAR::isError($oFieldset)) {
- return $oForm->handleError(sprintf(_kt("Failed to create fieldset: %s"), $oFieldset->getMessage()));
- }
-
- $this->successRedirectTo('edit',_kt("Fieldset created."), sprintf('fFieldsetId=%d', $oFieldset->getId()));
- }
- /**
- * Gets tyoes for fieldsets
- * @return string
- * @param $oFieldset Object
- *
- * iNET Process
- */
- function getTypesForFieldset($oFieldset) {
- global $default;
- if ($oFieldset->getIsGeneric()) {
- return _kt('All types use this generic fieldset.');
- }
-
- $types = $oFieldset->getAssociatedTypes();
- if (PEAR::isError($types)) {
- $default->log->debug('Fieldsets admin: Error retrieving list of associated document types.');
- return _kt('Error retrieving list of types.');
- }
- if (empty($types)) {
- return _kt('None');
- }
-
- $aNames = array();
- foreach ($types as $oType) {
- if (!PEAR::isError($oType)) {
- $aNames[] = $oType->getName();
- }else{
- $default->log->debug('Fieldsets admin: Document type gives error: '.$oType->getMessage());
- }
- }
-
- $list = implode(', ', $aNames);
- $length = mb_strlen($list);
-
- if($length < 50){
- return $list;
- }
- $default->log->debug('Fieldsets admin: wrapping the list of doc types from length '.$length);
-
- // Wrap the list to 50 characters per line
- $wrapList = '';
- $cut = 0;
- while ($length > 50 && $cut !== false){
- $cut = strpos($list, ' ', 50);
- $wrapList .= mb_strcut($list, 0, $cut);
- $wrapList .= '
';
- $list = mb_strcut($list, $cut);
- $length = mb_strlen($list);
- }
- $wrapList .= $list;
-
- return $wrapList;
- }
-
- /**
- * Edits fields
- * @return template
- *
- * iNET Process
- */
- function do_edit() {
-
- // here we engage in some major evil.
- // we check for the subevent var
- // and subdispatch if appropriate.
- //
- // saves a little code-duplication (actually, a lot of code-duplication)
-
- // FIXME this is essentially a stub for the fieldset-delegation code.
- if ($this->oFieldset->getIsConditional()) {
-
- require_once(KT_DIR.'/plugins/ktcore/admin/fieldsets/conditional.inc.php');
- $oSubDispatcher = new ConditionalFieldsetManagementDispatcher;
- } else {
- // multiselect change start
- if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin'))
- {
- require_once(KT_DIR.'/plugins/multiselect/inetbasic.inc.php');
- $oSubDispatcher = new InetBasicFieldsetManagementDispatcher;
- }
- else
- {
-
- require_once(KT_DIR.'/plugins/ktcore/admin/fieldsets/basic.inc.php');
- $oSubDispatcher = new BasicFieldsetManagementDispatcher;
- }
- // multiselect change end
-
-
- }
-
- $subevent_var = 'fieldset_action';
- $subevent = KTUtil::arrayGet($_REQUEST, $subevent_var);
- if (!empty($subevent)) {
- // do nothing, since this will handle everything
- $this_url = KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit"));
- $oSubDispatcher->redispatch($subevent_var, null, $this, $this_url);
- exit(0);
- } else {
- // what we want is the "additional info" section
- $additional = $oSubDispatcher->describe_fieldset($this->oFieldset);
- }
-
- $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/edit');
- $oTemplate->setData(array(
- 'context' => $this,
- 'fieldset_name' => $this->oFieldset->getName(),
- 'additional' => $additional,
- ));
- return $oTemplate->render();
- }
- /**
- * deletes field
- * @return
- *
- * iNET Process
- */
- function do_delete() {
- $this->startTransaction();
-
- // check if fieldset is associated with a document type - remove association
- $types = $this->oFieldset->getAssociatedTypes();
- $sFieldSetId = $this->oFieldset->getId();
- if(!PEAR::isError($types) AND !empty($types)){
- foreach($types as $oType){
- $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $sFieldSetId);
- }
- }
-
- $res = $this->oFieldset->delete('true');
- $this->oValidator->notErrorFalse($res, array(
- 'redirect_to' => array('main', ''),
- 'message' => _kt('Could not delete fieldset'),
- ));
- $this->successRedirectToMain(_kt('Fieldset deleted'));
- }
- /**
- * Form for edit
- * @return form
- *
- * iNET Process
- */
- function form_edit() {
- $oForm = new KTForm;
- $oForm->setOptions(array(
- 'identifier' => 'ktcore.fieldsets.edit',
- 'label' => _kt("Change Fieldset Details"),
- 'submit_label' => _kt('Update Fieldset'),
- 'cancel_action' => 'edit',
- 'fail_action' => 'editfieldset',
- 'action' => 'savefieldset',
- 'context' => $this,
- ));
-
-
- // construct the widget set.
- // we use a slight variation here, because "type" is only present in certain circumstances.
- $widgets = array(
- array('ktcore.widgets.string',array(
- 'label' => _kt("Fieldset Name"),
- 'name' => 'name',
- 'required' => true,
- 'description' => _kt("Each fieldset needs a unique name."),
- 'value' => sanitizeForHTML($this->oFieldset->getName()),
- )),
- array('ktcore.widgets.text',array(
- 'label' => _kt("Description"),
- 'name' => 'description',
- 'required' => true,
- 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
- 'value' => sanitizeForHTML($this->oFieldset->getDescription()),
- )),
- );
-
- $widgets[] = array('ktcore.widgets.boolean',array(
- 'label' => _kt("Generic"),
- 'name' => 'generic',
- 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
- 'value' => $this->oFieldset->getIsGeneric(),
- ));
-
- $oForm->setWidgets($widgets);
-
- // similarly, we construct validators here.
- $validators = array(
- array('ktcore.validators.string', array(
- 'test' => 'name',
- 'output' => 'name',
- )),
- array('ktcore.validators.string', array(
- 'test' => 'description',
- 'output' => 'description',
- )),
- array('ktcore.validators.boolean', array(
- 'test' => 'generic',
- 'output' => 'generic',
- )),
- );
-
- $oForm->setValidators($validators);
-
- return $oForm;
- }
- /**
- * Edits a fieldsets
- * @return form
- *
- * iNET Process
- */
- function do_editfieldset() {
- $oForm = $this->form_edit();
- $this->oPage->setBreadcrumbDetails(_kt('edit fieldset'));
- return $oForm->renderPage(_kt("Edit Fieldset"));
- }
- /**
- * saves a fieldset
- * @return
- *
- * iNET Process
- */
- 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."));
- }
-}
-
+.
+ *
+ * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
+ * California 94120-7775, or email info@knowledgetree.com.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "Powered by
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
+ * Contributor( s): ______________________________________
+ *
+ */
+
+require_once(KT_LIB_DIR . '/dispatcher.inc.php');
+require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
+require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
+require_once(KT_LIB_DIR . '/plugins/pluginutil.inc.php');
+
+class InetDocumentFieldDispatcher extends KTAdminDispatcher {
+ var $bAutomaticTransaction = true;
+ var $bHaveConditional = null;
+ var $sHelpPage = 'ktcore/admin/document fieldsets.html';
+
+ /**
+ *
+ * @return.
+ * @param.
+ *
+ * iNET Process
+ */
+ function predispatch() {
+ $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Document Field Management'));
+ $this->persistParams(array('fFieldsetId'));
+
+ $this->oFieldset = KTFieldset::get(KTUtil::arrayGet($_REQUEST, 'fFieldsetId'));
+ if (PEAR::isError($this->oFieldset)) {
+ $this->oFieldset = null;
+ unset($_REQUEST['fFieldset']); // prevent further attacks.
+ } else {
+ $this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit")), 'name' => $this->oFieldset->getName());
+ }
+ $this->bHaveConditional = KTPluginUtil::pluginIsActive('ktextra.conditionalmetadata.plugin');
+ }
+
+ /**
+ * create template
+ * @Param.
+ * @return template.
+ *
+ * iNET Process
+ */
+ function do_main () {
+ $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/list');
+
+ $oTemplate->setData(array(
+ 'context' => $this,
+ 'fieldsets' => KTFieldset::getList("disabled != true AND namespace != 'tagcloud'"),
+ ));
+ return $oTemplate;
+ }
+
+ /**
+ * form for creating new fieldset.
+ * @Param.
+ * @return form.
+ *
+ * iNET Process
+ */
+ function form_create() {
+ $oForm = new KTForm;
+ $oForm->setOptions(array(
+ 'identifier' => 'ktcore.fieldsets.create',
+ 'label' => _kt("Create New Fieldset"),
+ 'submit_label' => _kt('Create Fieldset'),
+ 'cancel_action' => 'main',
+ 'fail_action' => 'newfieldset',
+ 'action' => 'create',
+ 'context' => $this,
+ ));
+
+
+ // construct the widget set.
+ // we use a slight variation here, because "type" is only present in certain circumstances.
+ $widgets = array(
+ array('ktcore.widgets.string',array(
+ 'label' => _kt("Fieldset Name"),
+ 'name' => 'name',
+ 'required' => true,
+ 'description' => _kt("Each fieldset needs a unique name."),
+ )),
+ array('ktcore.widgets.text',array(
+ 'label' => _kt("Description"),
+ 'name' => 'description',
+ 'required' => true,
+ 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
+ )),
+ );
+ if ($this->bHaveConditional) {
+
+ // FIXME get this from some external source.
+ $type_vocab = array(
+ 'normal' => _kt("Normal"),
+ 'conditional' => _kt("Conditional"),
+ );
+
+ $widgets[] = array('ktcore.widgets.selection', array(
+ 'label' => _kt("Fieldset Type"),
+ 'use_simple' => false,
+ 'description' => _kt("It is possibler to create different types of fieldsets. The most common kind is a \"normal\" fieldset, which can be configured to have different kinds of fields. The administrator may have installed additional plugins which provide different types of fieldsets."),
+ 'important_description' => _kt('Note that it is not possible to convert between different types of fieldsets, so please choose carefully.'),
+ 'name' => 'fieldset_type',
+ 'required' => true,
+ 'value' => 'normal',
+ 'vocab' => $type_vocab,
+ ));
+ }
+
+ $widgets[] = array('ktcore.widgets.boolean',array(
+ 'label' => _kt("Generic"),
+ 'name' => 'generic',
+ 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
+ ));
+
+ $oForm->setWidgets($widgets);
+
+ // similarly, we construct validators here.
+ $validators = array(
+ array('ktcore.validators.string', array(
+ 'test' => 'name',
+ 'output' => 'name',
+ )),
+ array('ktcore.validators.string', array(
+ 'test' => 'description',
+ 'output' => 'description',
+ )),
+ array('ktcore.validators.boolean', array(
+ 'test' => 'generic',
+ 'output' => 'generic',
+ )),
+ );
+
+ if ($this->bHaveConditional) {
+ $validators[] = array('ktcore.validators.string', array(
+ 'test' => 'fieldset_type',
+ 'output' => 'fieldset_type',
+ ));
+ }
+
+ $oForm->setValidators($validators);
+
+ return $oForm;
+ }
+ /**
+ * Creates a new page
+ * @return form
+ *
+ * iNET Process
+ */
+ function do_newfieldset() {
+ $this->oPage->setBreadcrumbDetails(_kt("Create New Fieldset"));
+ $oForm = $this->form_create();
+
+ return $oForm->render();
+ }
+ /**
+ * Creates a fieldsets
+ * @return
+ *
+ * iNET Process
+ */
+ function do_create() {
+ $oForm = $this->form_create();
+ $res = $oForm->validate();
+
+ $data = $res['results'];
+ $errors = $res['errors'];
+ $extra_errors = array();
+
+ if (!empty($data['name'])) {
+ $oFieldset = KTFieldset::getByName($data['name']);
+ if (!PEAR::isError($oFieldset)) {
+ // means we're looking at an existing name
+ $extra_errors['name'] = _kt("There is already a fieldset with that name.");
+ }
+ }
+
+ $is_conditional = false;
+ // FIXME this is inelegant. get it from somewhere else.
+ if ($this->bHaveConditional && ($data['fieldset_type'] == 'conditional')) {
+ $is_conditional = true;
+ }
+
+
+ if (!empty($errors) || !empty($extra_errors)) {
+ return $oForm->handleError(null, $extra_errors);
+ }
+
+ // we also need a namespace.
+ $temp_name = $data['name'];
+ $namespace = KTUtil::nameToLocalNamespace('fieldsets', $temp_name);
+ $oOldFieldset = KTFieldset::getByNamespace($namespace);
+
+ while (!PEAR::isError($oOldFieldset)) {
+ $temp_name .= '_';
+ $namespace = KTUtil::nameToLocalNamespace('fieldsets', $temp_name);
+ $oOldFieldset = KTFieldset::getByNamespace($namespace);
+ }
+
+ // we now know its a non-conflicting one.
+ // FIXME handle conditional fieldsets, which should be ... a different object.
+ $oFieldset = KTFieldset::createFromArray(array(
+ "name" => $data['name'],
+ "description" => $data['description'],
+ "namespace" => $namespace,
+ "mandatory" => false, // FIXME deprecated
+ "isConditional" => $is_conditional, // handle this
+ "isGeneric" => $data['generic'],
+ "isComplete" => false,
+ "isComplex" => false,
+ "isSystem" => false,
+ ));
+ if (PEAR::isError($oFieldset)) {
+ return $oForm->handleError(sprintf(_kt("Failed to create fieldset: %s"), $oFieldset->getMessage()));
+ }
+
+ $this->successRedirectTo('edit',_kt("Fieldset created."), sprintf('fFieldsetId=%d', $oFieldset->getId()));
+ }
+ /**
+ * Gets tyoes for fieldsets
+ * @return string
+ * @param $oFieldset Object
+ *
+ * iNET Process
+ */
+ function getTypesForFieldset($oFieldset) {
+ global $default;
+ if ($oFieldset->getIsGeneric()) {
+ return _kt('All types use this generic fieldset.');
+ }
+
+ $types = $oFieldset->getAssociatedTypes();
+ if (PEAR::isError($types)) {
+ $default->log->debug('Fieldsets admin: Error retrieving list of associated document types.');
+ return _kt('Error retrieving list of types.');
+ }
+ if (empty($types)) {
+ return _kt('None');
+ }
+
+ $aNames = array();
+ foreach ($types as $oType) {
+ if (!PEAR::isError($oType)) {
+ $aNames[] = $oType->getName();
+ }else{
+ $default->log->debug('Fieldsets admin: Document type gives error: '.$oType->getMessage());
+ }
+ }
+
+ $list = implode(', ', $aNames);
+ $length = mb_strlen($list);
+
+ if($length < 50){
+ return $list;
+ }
+ $default->log->debug('Fieldsets admin: wrapping the list of doc types from length '.$length);
+
+ // Wrap the list to 50 characters per line
+ $wrapList = '';
+ $cut = 0;
+ while ($length > 50 && $cut !== false){
+ $cut = strpos($list, ' ', 50);
+ $wrapList .= mb_strcut($list, 0, $cut);
+ $wrapList .= '
';
+ $list = mb_strcut($list, $cut);
+ $length = mb_strlen($list);
+ }
+ $wrapList .= $list;
+
+ return $wrapList;
+ }
+
+ /**
+ * Edits fields
+ * @return template
+ *
+ * iNET Process
+ */
+ function do_edit() {
+
+ // here we engage in some major evil.
+ // we check for the subevent var
+ // and subdispatch if appropriate.
+ //
+ // saves a little code-duplication (actually, a lot of code-duplication)
+
+ // FIXME this is essentially a stub for the fieldset-delegation code.
+ if ($this->oFieldset->getIsConditional()) {
+
+ require_once(KT_DIR.'/plugins/ktcore/admin/fieldsets/conditional.inc.php');
+ $oSubDispatcher = new ConditionalFieldsetManagementDispatcher;
+ } else {
+ // multiselect change start
+ if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin'))
+ {
+ require_once(KT_DIR.'/plugins/multiselect/inetbasic.inc.php');
+ $oSubDispatcher = new InetBasicFieldsetManagementDispatcher;
+ }
+ else
+ {
+
+ require_once(KT_DIR.'/plugins/ktcore/admin/fieldsets/basic.inc.php');
+ $oSubDispatcher = new BasicFieldsetManagementDispatcher;
+ }
+ // multiselect change end
+
+
+ }
+
+ $subevent_var = 'fieldset_action';
+ $subevent = KTUtil::arrayGet($_REQUEST, $subevent_var);
+ if (!empty($subevent)) {
+ // do nothing, since this will handle everything
+ $this_url = KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit"));
+ $oSubDispatcher->redispatch($subevent_var, null, $this, $this_url);
+ exit(0);
+ } else {
+ // what we want is the "additional info" section
+ $additional = $oSubDispatcher->describe_fieldset($this->oFieldset);
+ }
+
+ $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/edit');
+ $oTemplate->setData(array(
+ 'context' => $this,
+ 'fieldset_name' => $this->oFieldset->getName(),
+ 'additional' => $additional,
+ ));
+ return $oTemplate->render();
+ }
+ /**
+ * deletes field
+ * @return
+ *
+ * iNET Process
+ */
+ function do_delete() {
+ $this->startTransaction();
+
+ // check if fieldset is associated with a document type - remove association
+ $types = $this->oFieldset->getAssociatedTypes();
+ $sFieldSetId = $this->oFieldset->getId();
+ if(!PEAR::isError($types) AND !empty($types)){
+ foreach($types as $oType){
+ $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $sFieldSetId);
+ }
+ }
+
+ $res = $this->oFieldset->delete('true');
+ $this->oValidator->notErrorFalse($res, array(
+ 'redirect_to' => array('main', ''),
+ 'message' => _kt('Could not delete fieldset'),
+ ));
+ $this->successRedirectToMain(_kt('Fieldset deleted'));
+ }
+ /**
+ * Form for edit
+ * @return form
+ *
+ * iNET Process
+ */
+ function form_edit() {
+ $oForm = new KTForm;
+ $oForm->setOptions(array(
+ 'identifier' => 'ktcore.fieldsets.edit',
+ 'label' => _kt("Change Fieldset Details"),
+ 'submit_label' => _kt('Update Fieldset'),
+ 'cancel_action' => 'edit',
+ 'fail_action' => 'editfieldset',
+ 'action' => 'savefieldset',
+ 'context' => $this,
+ ));
+
+
+ // construct the widget set.
+ // we use a slight variation here, because "type" is only present in certain circumstances.
+ $widgets = array(
+ array('ktcore.widgets.string',array(
+ 'label' => _kt("Fieldset Name"),
+ 'name' => 'name',
+ 'required' => true,
+ 'description' => _kt("Each fieldset needs a unique name."),
+ 'value' => sanitizeForHTML($this->oFieldset->getName()),
+ )),
+ array('ktcore.widgets.text',array(
+ 'label' => _kt("Description"),
+ 'name' => 'description',
+ 'required' => true,
+ 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
+ 'value' => sanitizeForHTML($this->oFieldset->getDescription()),
+ )),
+ );
+
+ $widgets[] = array('ktcore.widgets.boolean',array(
+ 'label' => _kt("Generic"),
+ 'name' => 'generic',
+ 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
+ 'value' => $this->oFieldset->getIsGeneric(),
+ ));
+
+ $oForm->setWidgets($widgets);
+
+ // similarly, we construct validators here.
+ $validators = array(
+ array('ktcore.validators.string', array(
+ 'test' => 'name',
+ 'output' => 'name',
+ )),
+ array('ktcore.validators.string', array(
+ 'test' => 'description',
+ 'output' => 'description',
+ )),
+ array('ktcore.validators.boolean', array(
+ 'test' => 'generic',
+ 'output' => 'generic',
+ )),
+ );
+
+ $oForm->setValidators($validators);
+
+ return $oForm;
+ }
+ /**
+ * Edits a fieldsets
+ * @return form
+ *
+ * iNET Process
+ */
+ function do_editfieldset() {
+ $oForm = $this->form_edit();
+ $this->oPage->setBreadcrumbDetails(_kt('edit fieldset'));
+ return $oForm->renderPage(_kt("Edit Fieldset"));
+ }
+ /**
+ * saves a fieldset
+ * @return
+ *
+ * iNET Process
+ */
+ 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."));
+ }
+}
+
?>
\ No newline at end of file
diff --git a/plugins/multiselect/MultiSelectPlugin.php b/plugins/multiselect/MultiSelectPlugin.php
index b99ba1c..f2e896f 100644
--- a/plugins/multiselect/MultiSelectPlugin.php
+++ b/plugins/multiselect/MultiSelectPlugin.php
@@ -1,126 +1,126 @@
-.
- *
- * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
- * California 94120-7775, or email info@knowledgetree.com.
- *
- * The interactive user interfaces in modified source and object code versions
- * of this program must display Appropriate Legal Notices, as required under
- * Section 5 of the GNU General Public License version 3.
- *
- * In accordance with Section 7(b) of the GNU General Public License version 3,
- * these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
- * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
- * Contributor( s): ______________________________________
- *
- */
-
-require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
-require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
-
-class MultiSelectPlugin extends KTPlugin {
- var $sNamespace = "inet.multiselect.lookupvalue.plugin";
- var $autoRegister = false;
-
- /**
- * returns plugin name
- * @param string.
- * @return string.
- *
- * iNET Process
- */
- function MultiSelectPlugin($sFilename = null) {
- $res = parent::KTPlugin($sFilename);
- $this->sFriendlyName = _kt('Multi-select Plugin');
- return $res;
- }
-
- /**
- * Register the action, location, call adminsetup function and sql function
- * iNET Process
- */
- function setup() {
- $oTemplating =& KTTemplating::getSingleton();
- $oTemplating->addLocation('Multiselect in metadata Part {lookup Value}', '/plugins/multiselect/templates');
-
- $dir = dirname(__FILE__);
- $this->applySQL(realpath($dir . '/sql/script.sql'));
-
- //For adding documents
- $this->registerAction('folderaction', 'MultiDocumentAddAction', 'inet.multiselect.actions.document.addDocument', 'addDocument.php');
-
- //For bulk upload
- $this->registerAction('folderaction', 'InetBulkUploadFolderAction', 'inet.actions.folder.bulkUpload', 'BulkUpload.php');
- /**
- * Change Starts | iNET Process
- * Code is Added 2009-03-04 :SL
- * Reason : To Register "import from folder location" action for multiselect
- */
- $this->registerAction('folderaction', 'InetBulkImportFolderMultiSelectAction', 'inet.actions.folder.bulkImport.multiselect', 'BulkImport.php');
- /**
- * Change Ends | iNET Process
- */
- $this->setupAdmin();
- }
- /**
- * applies queries to the database
- * @return
- * @param $filename Object
- */
- function applySQL($filename)
- {
- global $default;
- DBUtil::setupAdminDatabase();
- $db = $default->_admindb;
-
- $content = file_get_contents($filename);
- $aQueries = SQLFile::splitSQL($content);
-
- DBUtil::startTransaction();
- foreach($aQueries as $sQuery)
- {
- $res = DBUtil::runQuery($sQuery, $db);
- if (PEAR::isError($res)) {
- continue;
- }
- }
- DBUtil::commit();
- }
- /**
- * Sets up an admin
- * @return
- */
- function setupAdmin()
- {
- $js = "";
- $js .= "";
- $this->registerAdminPage('ratpfieldset', 'InetDocumentFieldDispatcher', 'documents',
- $js._kt('Document Fieldsets'),
- _kt('Manage the different types of information with multiselect functionality that can be associated with classes of documents.'),
- 'InetdocumentFieldsv2.php', null);
- }
-}
-$oPluginRegistry =& KTPluginRegistry::getSingleton();
-$oPluginRegistry->registerPlugin('MultiSelectPlugin', 'inet.multiselect.lookupvalue.plugin', __FILE__);
+.
+ *
+ * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
+ * California 94120-7775, or email info@knowledgetree.com.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "Powered by
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
+ * Contributor( s): ______________________________________
+ *
+ */
+
+require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
+require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
+
+class MultiSelectPlugin extends KTPlugin {
+ var $sNamespace = "inet.multiselect.lookupvalue.plugin";
+ var $autoRegister = false;
+
+ /**
+ * returns plugin name
+ * @param string.
+ * @return string.
+ *
+ * iNET Process
+ */
+ function MultiSelectPlugin($sFilename = null) {
+ $res = parent::KTPlugin($sFilename);
+ $this->sFriendlyName = _kt('Multi-select Plugin');
+ return $res;
+ }
+
+ /**
+ * Register the action, location, call adminsetup function and sql function
+ * iNET Process
+ */
+ function setup() {
+ $oTemplating =& KTTemplating::getSingleton();
+ $oTemplating->addLocation('Multiselect in metadata Part {lookup Value}', '/plugins/multiselect/templates');
+
+ $dir = dirname(__FILE__);
+ $this->applySQL(realpath($dir . '/sql/script.sql'));
+
+ //For adding documents
+ $this->registerAction('folderaction', 'MultiDocumentAddAction', 'inet.multiselect.actions.document.addDocument', 'addDocument.php');
+
+ //For bulk upload
+ $this->registerAction('folderaction', 'InetBulkUploadFolderAction', 'inet.actions.folder.bulkUpload', 'BulkUpload.php');
+ /**
+ * Change Starts | iNET Process
+ * Code is Added 2009-03-04 :SL
+ * Reason : To Register "import from folder location" action for multiselect
+ */
+ $this->registerAction('folderaction', 'InetBulkImportFolderMultiSelectAction', 'inet.actions.folder.bulkImport.multiselect', 'BulkImport.php');
+ /**
+ * Change Ends | iNET Process
+ */
+ $this->setupAdmin();
+ }
+ /**
+ * applies queries to the database
+ * @return
+ * @param $filename Object
+ */
+ function applySQL($filename)
+ {
+ global $default;
+ DBUtil::setupAdminDatabase();
+ $db = $default->_admindb;
+
+ $content = file_get_contents($filename);
+ $aQueries = SQLFile::splitSQL($content);
+
+ DBUtil::startTransaction();
+ foreach($aQueries as $sQuery)
+ {
+ $res = DBUtil::runQuery($sQuery, $db);
+ if (PEAR::isError($res)) {
+ continue;
+ }
+ }
+ DBUtil::commit();
+ }
+ /**
+ * Sets up an admin
+ * @return
+ */
+ function setupAdmin()
+ {
+ $js = "";
+ $js .= "";
+ $this->registerAdminPage('ratpfieldset', 'InetDocumentFieldDispatcher', 'documents',
+ $js._kt('Document Fieldsets'),
+ _kt('Manage the different types of information with multiselect functionality that can be associated with classes of documents.'),
+ 'InetdocumentFieldsv2.php', null);
+ }
+}
+$oPluginRegistry =& KTPluginRegistry::getSingleton();
+$oPluginRegistry->registerPlugin('MultiSelectPlugin', 'inet.multiselect.lookupvalue.plugin', __FILE__);
?>
\ No newline at end of file
diff --git a/plugins/multiselect/inetbasic.inc.php b/plugins/multiselect/inetbasic.inc.php
index e2488e3..8dae27f 100644
--- a/plugins/multiselect/inetbasic.inc.php
+++ b/plugins/multiselect/inetbasic.inc.php
@@ -1,1171 +1,1171 @@
-.
- *
- * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
- * California 94120-7775, or email info@knowledgetree.com.
- *
- * The interactive user interfaces in modified source and object code versions
- * of this program must display Appropriate Legal Notices, as required under
- * Section 5 of the GNU General Public License version 3.
- *
- * In accordance with Section 7(b) of the GNU General Public License version 3,
- * these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
- * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
- * copyright notice.
- * Contributor( s): ______________________________________
- *
- */
-
-require_once(KT_LIB_DIR . '/dispatcher.inc.php');
-require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
-require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
-require_once(KT_LIB_DIR . '/plugins/pluginutil.inc.php');
-require_once(KT_LIB_DIR . "/documentmanagement/MDTree.inc");
-
-class InetBasicFieldsetManagementDispatcher extends KTAdminDispatcher {
- var $bAutomaticTransaction = true;
- var $bHaveConditional = null;
- var $sHelpPage = 'ktcore/admin/document fieldsets.html';
-
- /**
- * @param.
- * @return.
- *
- * iNET Process
- */
- 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());
- }
- }
-
- /**
- * API: this provides information about the fieldset, including which actions are available.
- *
- * @param $oFieldset object.
- * @return template.
- *
- * iNET Process
- */
- function describe_fieldset($oFieldset) {
- $this->persistParams(array('fFieldsetId','action'));
- $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/basic_overview');
- $oTemplate->setData(array(
- 'context' => $this,
- 'fields' => $oFieldset->getFields(),
- ));
- return $oTemplate->render();
- }
- /**
- * Nothing doing
- * iNET Process
- */
- function do_main () {
- return _kt("Something very unexpected happened.");
- }
-
- /**
- * returns array of field type.
- *
- * @param.
- * @return array.
- *
- * iNET Process
- */
- function getFieldTypeVocab() {
- $types = array(
- 'normal' => _kt("Normal (String)"),
- 'lookup' => _kt("Lookup"),
- 'tree' => _kt("Tree"),
- 'Multiselect' => _kt("Multiselect"),
- );
- return $types;
- }
-
-
- /**
- * multiselect change starts
- * @return array
- *
- * iNET Process
- */
- function getLookupFieldTypeVocab() {
- $types = array(
-
- 'multiwithlist' => _kt("Multiselect with a list"),
- 'multiwithcheckboxes' => _kt("Multiselect with checkboxes"),
- );
- return $types;
- }
-
- /**
- * returns lookup type
- * @return string
- *
- * iNET Process
- */
- function getDefaultLookupType() {
- return 'multiwithlist';
-
- }
-
- /**
- * multiselect change end
- * @return
- *
- * iNET Process
- */
- function getDefaultType() {
- return 'normal';
- }
- /**
- * For for displaying new field
- * @return
- *
- * iNET Process
- */
- function form_newfield() {
- $this->oPage->setBreadcrumbDetails(_kt('add field'));
-
- $oForm = new KTForm;
- $oForm->setOptions(array(
- 'identifier' => 'ktcore.fieldsets.basic.field.create',
- 'label' => _kt("Add New Field"),
- 'submit_label' => _kt('Add Field'),
- 'cancel_url' => $this->sParentUrl,
- 'fail_action' => 'newfield',
- 'action' => 'createfield',
- 'context' => $this,
- ));
-
- $type_vocab = $this->getFieldTypeVocab();
-
- $oForm->setWidgets(array(
- array('ktcore.widgets.string',array(
- 'label' => _kt("Field Name"),
- 'name' => 'name',
- 'required' => true,
- 'description' => _kt("Within a given fieldset, each field needs a unique name."),
- )),
- array('ktcore.widgets.text',array(
- 'label' => _kt("Description"),
- 'name' => 'description',
- 'required' => true,
- 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
- )),
- array('ktcore.widgets.selection', array(
- 'label' => _kt('Field Type'),
- 'name' => 'field_type',
- 'vocab' => $this->getFieldTypeVocab(),
- 'description' => _kt("Different types of fields may be available, depending on the system."),
- 'required' => true,
- 'value' => $this->getDefaultType(),
- )),
- array('ktcore.widgets.boolean',array(
- 'label' => _kt("Required"),
- 'name' => 'required',
- 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
- )),
-
- ));
-
- $oForm->setValidators(array(
- array('ktcore.validators.string', array(
- 'test' => 'name',
- 'output' => 'name',
- )),
- array('ktcore.validators.string', array(
- 'test' => 'description',
- 'output' => 'description',
- )),
- array('ktcore.validators.boolean', array(
- 'test' => 'required',
- 'output' => 'required',
- )),
- array('ktcore.validators.string', array(
- 'test' => 'field_type',
- 'output' => 'field_type',
- )),
- ));
-
- return $oForm;
- }
- /**
- * Renders the page for new field
- * @return
- *
- * iNET Process
- */
- function do_newfield() {
- $oForm = $this->form_newfield();
-
- return $oForm->render();
- }
-
- /**
- * Creats a new field->multiselect
- * @return
- *
- *
- * iNET Process
- */
- function do_createfield() {
- $oForm = $this->form_newfield();
- $res = $oForm->validate();
-
- $data = $res['results'];
- $errors = $res['errors'];
- $extra_errors = array();
-
- $oField = DocumentField::getByFieldsetAndName($this->oFieldset, $data['name']);
- if (!PEAR::isError($oField)) {
- $extra_errors['name'] = _kt("A field with that name already exists in this fieldset.");
- }
-
- if (!empty($errors) || !empty($extra_errors)) {
- return $oForm->handleError(null, $extra_errors);
- }
-
- $lookup = false;
- $tree = false;
- // multiselect change start
- $inetlookup = false;
- $inetlookupvalue = '';
- // multiselect change end
-
- if ($data['field_type'] == 'lookup') {
- $lookup = true;
- } else if ($data['field_type'] == 'tree') {
- $lookup = true;
- $tree = true;
- }
- // multiselect change start
- else if($data['field_type'] == 'Multiselect')
- {
- $inetlookup = true;
- $inetlookupvalue = $this->getDefaultLookupType();
- }
- // multiselect change end
-
- $oField = DocumentField::createFromArray(array(
- 'Name' => $data['name'],
- 'Description' => $data['description'],
- 'DataType' => 'STRING',
- 'IsGeneric' => false,
- 'HasLookup' => $lookup,
- 'HasLookupTree' => $tree,
- 'ParentFieldset' => $this->oFieldset->getId(),
- 'IsMandatory' => $data['required'],
- // multiselect change start
- 'HasInetLookup' => $inetlookup,
- 'InetLookupType' => $inetlookupvalue,
- // multiselect change end
- ));
-
- if (PEAR::isError($oField)) {
- return $oForm->handleError(sprintf(_kt("Unable to create field: %s"), $oField->getMessage()));
- }
-
- $this->successRedirectTo('managefield', _kt("Field created."), sprintf('fFieldId=%d', $oField->getId()));
- }
- /**
- * Form for editing a field
- * @return form
- * @param $oField Object
- *
- * iNET Process
- */
- function form_editfield($oField) {
- $oForm = new KTForm;
- $oForm->setOptions(array(
- 'identifier' => 'ktcore.fieldsets.basic.field.edit',
- 'label' => _kt("Edit Field"),
- 'submit_label' => _kt('Update Field'),
- 'cancel_url' => $this->sParentUrl,
- 'fail_action' => 'managefield',
- 'action' => 'updatefield',
- 'context' => $this,
- ));
-
- $field_type = $oField->getType();
- if($field_type == "Multiselect")
- {
- $oForm->setWidgets(array(
- array('ktcore.widgets.string',array(
- 'label' => _kt("Field Name"),
- 'name' => 'name',
- 'value' => sanitizeForHTML($oField->getName()),
- 'required' => true,
- 'description' => _kt("Within a given fieldset, each field needs a unique name."),
- )),
- array('ktcore.widgets.text',array(
- 'label' => _kt("Description"),
- 'name' => 'description',
- 'value' => sanitizeForHTML($oField->getDescription()),
- 'required' => true,
- 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
- )),
- array('ktcore.widgets.boolean',array(
- 'label' => _kt("Required"),
- 'value' => $oField->getIsMandatory(),
- 'name' => 'required',
- 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
- )),
- array('ktcore.widgets.selection', array(
- 'label' => _kt('Type of field'),
- 'name' => 'inetlookup_type',
- 'vocab' => $this->getLookupFieldTypeVocab(),
- 'description' => _kt("Permits to create a multiselect or single select choices."),
- 'required' => true,
- 'value' => $oField->getInetLookupType(),
- 'simple_select' => false,
- )),
- ));
-
- $oForm->setValidators(array(
- array('ktcore.validators.string', array(
- 'test' => 'name',
- 'output' => 'name',
- )),
- array('ktcore.validators.string', array(
- 'test' => 'description',
- 'output' => 'description',
- )),
- array('ktcore.validators.boolean', array(
- 'test' => 'required',
- 'output' => 'required',
- )),
- array('ktcore.validators.string', array(
- 'test' => 'inetlookup_type',
- 'output' => 'inetlookup_type',
- )),
- ));
- }
- else
- {
-
- $oForm->setWidgets(array(
- array('ktcore.widgets.string',array(
- 'label' => _kt("Field Name"),
- 'name' => 'name',
- 'value' => sanitizeForHTML($oField->getName()),
- 'required' => true,
- 'description' => _kt("Within a given fieldset, each field needs a unique name."),
- )),
- array('ktcore.widgets.text',array(
- 'label' => _kt("Description"),
- 'name' => 'description',
- 'value' => sanitizeForHTML($oField->getDescription()),
- 'required' => true,
- 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
- )),
- array('ktcore.widgets.boolean',array(
- 'label' => _kt("Required"),
- 'value' => $oField->getIsMandatory(),
- 'name' => 'required',
- 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
- )),
-
- ));
-
- $oForm->setValidators(array(
- array('ktcore.validators.string', array(
- 'test' => 'name',
- 'output' => 'name',
- )),
- array('ktcore.validators.string', array(
- 'test' => 'description',
- 'output' => 'description',
- )),
- array('ktcore.validators.boolean', array(
- 'test' => 'required',
- 'output' => 'required',
- )),
- ));
- }
- return $oForm;
- }
- /**
- * Manages a field
- * @return template
- *
- *
- * iNET Process
- */
- function do_managefield() {
- $oTemplate = $this->oValidator->validateTemplate('manage_field');
-
- $oTemplate->setData(array(
- 'context' => $this,
- 'field_name' => $this->oField->getName(),
- 'field_id' => $this->oField->getId(),
- 'form' => $this->form_editfield($this->oField),
- 'field' => $this->oField,
- ));
- return $oTemplate->render();
- }
- /**
- * Updates a field
- * @return.
- *
- *
- * iNET Process
- */
- 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 (!PEAR::isError($oOldField)) {
- $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']);
-
- // multiselect change start
- if(isset($data['inetlookup_type']) && $this->oField->getHasInetLookup())
- {
- $this->oField->setInetLookupType($data['inetlookup_type']);
- }
- // multiselect change end
-
- $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."));
- }
- /**
- * Add lookup
- * @return form
- *
- * iNET Process
- */
- function form_addlookups() {
- $oForm = new KTForm;
- $oForm->setOptions(array(
- 'identifier' => 'ktcore.fieldsets.basic.field.addlookup',
- 'label' => _kt("Add Lookup Values"),
- 'submit_label' => _kt('Add Lookups'),
- 'cancel_action' => 'managefield',
- 'fail_action' => 'addlookupvalues',
- 'action' => 'createlookupvalues',
- 'context' => $this,
- ));
-
- $oForm->setWidgets(array(
- array('ktcore.widgets.text',array(
- 'label' => _kt("Lookup Values"),
- 'name' => 'lookups',
- 'required' => true,
- 'description' => _kt("Lookup values are what a user can select from a dropdown. These pre-created lookup values are useful, since they help you keep the metadata in the system organised."),
- 'important_description' => _kt("Please enter the lookup values you wish to add, one per line."),
- )),
- ));
-
- $oForm->setValidators(array(
- array('ktcore.validators.string', array(
- 'test' => 'lookups',
- 'output' => 'lookups',
- 'max_length' => 9999,
- )),
- ));
-
- return $oForm;
- }
-
- /**
- * Add lookup values
- * @return
- *
- * iNET Process
- */
- function do_addlookupvalues() {
- $this->oPage->setBreadcrumbDetails(_kt('add lookup values'));
-
- $oForm = $this->form_addlookups();
- return $oForm->render();
- }
- /**
- * Create lookup values
- * @return
- */
- function do_createlookupvalues() {
- $oForm = $this->form_addlookups();
- $res = $oForm->validate();
- $data = $res['results'];
- $errors = $res['errors'];
- $extra_errors = array();
-
-
- $failed = array();
- $lookups = array();
-
- $raw_lookups = $data['lookups'];
- $lookup_candidates = explode("\n", $raw_lookups);
- foreach ($lookup_candidates as $candidate) {
- $name = trim($candidate);
-
- if (empty($name)) {
- continue;
- }
-
- // check for existing or to-be-created lookups.
- if ($lookups[$name]) {
- $failed[$name] = $name;
- continue;
- }
-
- if ($failed[$name]) {
- continue; // already blown up, fix it.
- }
-
- $oOldLookup = MetaData::getByValueAndDocumentField($name, $this->oField);
- if (!PEAR::isError($oOldLookup)) {
- $failed[$name] = $name;
- continue;
- }
-
- $lookups[$name] = $name;
- }
- if (!empty($failed)) {
- $extra_errors['lookups'][] = sprintf(_kt("The following lookups you specified already exist, or are specified twice: %s"), implode(', ', $failed));
- } else if (empty($lookups)) {
- $extra_errors['lookups'][] = _kt("You must have at least 1 new lookup value.");
- }
-
- if (!empty($errors) || !empty($extra_errors)) {
- return $oForm->handleError(null, $extra_errors);
- }
-
- $data['lookups'] = $lookups;
-
- foreach ($lookups as $value) {
- $oLookup = MetaData::createFromArray(array(
- 'DocFieldId' => $this->oField->getId(),
- 'sName' => $value,
- 'iTreeParent' => null,
- 'bDisabled' => false,
- 'bIsStuck' => false,
- ));
- if (PEAR::isError($oLookup)) {
- return $oForm->handleError(sprintf(_kt("Failed to create lookup: %s"), $oLookup->getMessage()));
- }
- }
-
- $this->successRedirectTo('managefield', sprintf(_kt("%d lookups added."), count($lookups)));
- }
- /**
- * Manages lookups
- * @return template
- *
- * iNET Process
- */
- function do_managelookups() {
- $this->oPage->setBreadcrumbDetails(_kt('manage lookup values'));
-
- // Add javascript to create the edit form
- $sJavaScript = "\nfunction editLookup(id)\n
- {\n
- var div = document.getElementById(id);\n
- var value = div.innerHTML;
-
- \n
- matches = value.match(/\"/g);\n
- var newValue = value;\n
- if(matches){\n
- for(var i = 0; i < matches.length; i++){\n
- newValue = newValue.replace('\"', '"');\n
- }\n
- }\n\n
-
- var inner = '';\n
- inner += '';\n
- inner += '';\n
- inner += '';\n
- div.innerHTML = inner;\n
- document.getElementById('lookup_'+id).focus();\n
- }\n\n
-
- function closeLookupEdit(id)
- {\n
- value = document.getElementById('original_'+id).value;\n
- document.getElementById(id).innerHTML = value;\n
- }\n\n";
-
- $this->oPage->requireJSStandalone($sJavaScript);
-
- $lookups =& MetaData::getByDocumentField($this->oField);
- $args = $this->meldPersistQuery("","metadataMultiAction", true);
-
- $oTemplate =& $this->oValidator->validateTemplate("ktcore/metadata/admin/manage_lookups");
- $oTemplate->setData(array(
- 'context' => $this,
- 'field_name' => $this->oField->getName(),
- 'lookups' => $lookups,
- 'args' => $args,
- ));
- return $oTemplate->render();
- }
-
- // {{{ do_metadataMultiAction
- /**
- * call metadata multiaction methods
- * @param.
- * @return.
- *
- * iNET Process
- */
- function do_metadataMultiAction() {
- $subaction = array_keys(KTUtil::arrayGet($_REQUEST, 'submit', array()));
- $this->oValidator->notEmpty($subaction, array("message" => _kt("No action specified")));
- $subaction = $subaction[0];
- $method = null;
- if (method_exists($this, 'lookup_' . $subaction)) {
- $method = 'lookup_' . $subaction;
- }
- $this->oValidator->notEmpty($method, array("message" => _kt("Unknown action specified")));
- return $this->$method();
- }
- // }}}
-
- // {{{ lookup_remove
- /**
- * remove lookup value.
- * @param
- * @return
- *
- * iNET Process
- */
- function lookup_remove() {
- $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
- $oField =& DocumentField::get($_REQUEST['fFieldId']);
- $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
- if (empty($aMetadata)) {
- $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
- }
- foreach ($_REQUEST['metadata'] as $iMetaDataId) {
- $oMetaData =& MetaData::get($iMetaDataId);
- if (PEAR::isError($oMetaData)) {
- $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
- }
- $oMetaData->delete();
- }
- $this->successRedirectTo('managelookups', _kt('Lookups removed'));
- exit(0);
- }
- // }}}
-
- // {{{ lookup_disable
- /**
- * disable lookup value.
- * @param
- * @return
- *
- * iNET Process
- */
- function lookup_disable() {
- $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
- $oField =& DocumentField::get($_REQUEST['fFieldId']);
- $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
- if (empty($aMetadata)) {
- $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
- }
- foreach ($_REQUEST['metadata'] as $iMetaDataId) {
- $oMetaData =& MetaData::get($iMetaDataId);
- if (PEAR::isError($oMetaData)) {
- $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
- }
- $oMetaData->setDisabled(true);
- $oMetaData->update();
- }
- $this->successRedirectTo('managelookups', _kt('Lookups disabled'));
- exit(0);
- }
- // }}}
-
- /**
- * Save the edited lookup values
- *
- * @param.
- * @return.
- *
- *iNET Process
- */
- function lookup_edit(){
- $aLookupValues = $_REQUEST['lookup'];
-
- if(empty($aLookupValues)){
- $this->errorRedirectTo('managelookups', _kt('No lookups were selected for editing'));
- exit;
- }
-
- foreach ($aLookupValues as $iMetaDataId => $sValue){
- $oMetaData = MetaData::get($iMetaDataId);
- if (PEAR::isError($oMetaData)) {
- $this->addErrorMessage(_kt('Invalid lookup selected').': '.$sValue);
- continue;
-
- }
- if(empty($sValue)){
- $this->addErrorMessage(_kt('Lookup cannot be empty').': '.$oMetaData->getName());
- if(count($aLookupValues) == 1){
- $this->redirectTo('managelookups');
- }
- continue;
- }
- $oMetaData->setName($sValue);
- $oMetaData->update();
- }
-
- $this->successRedirectTo('managelookups', _kt('Lookup values saved'));
- exit(0);
- }
-
- // {{{ lookup_enable
- /**
- * enable lookup value
- * @param
- * @return
- *
- * iNET Process
- */
- function lookup_toggleenabled() {
- $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
- $oField =& DocumentField::get($_REQUEST['fFieldId']);
- $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
- if (empty($aMetadata)) {
- $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
- }
- foreach ($_REQUEST['metadata'] as $iMetaDataId) {
- $oMetaData =& MetaData::get($iMetaDataId);
- if (PEAR::isError($oMetadata)) {
- $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
- }
- $oMetaData->setDisabled(!$oMetaData->getDisabled());
- $oMetaData->update();
- }
- $this->successRedirectTo('managelookups', _kt('Status Toggled'));
- exit(0);
- }
- // }}}
-
- // {{{ lookup_togglestickiness
- /**
- * toggle stickiness of lookup values
- * @param
- * @return
- *
- * iNET Process
- */
- function lookup_togglestickiness() {
- $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
- $oField =& DocumentField::get($_REQUEST['fFieldId']);
- $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
- if (empty($aMetadata)) {
- $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
- }
- foreach ($_REQUEST['metadata'] as $iMetaDataId) {
- $oMetaData =& MetaData::get($iMetaDataId);
- if (PEAR::isError($oMetaData)) {
- $this->errorRedirectTo('managelookups', _kt('Invalid lookups selected'));
- }
- $bStuck = (boolean)$oMetaData->getIsStuck();
- $oMetaData->setIsStuck(!$bStuck);
- $oMetaData->update();
- }
- $this->successRedirectTo('managelookups', _kt('Lookup stickiness toggled'));
- exit(0);
- }
- // }}}
-
-// {{{ TREE
- // create and display the tree editing form.
- /**
- * create and display the tree editing form.
- * @param.
- * @return template
- *
- * iNET Process
- */
- function do_managetree() {
- global $default;
- // extract.
- $iFieldsetId = KTUtil::getId($this->oFieldset);
- $iFieldId = KTUtil::getId($this->oField);
-
- $oFieldset =& $this->oFieldset;
- $oField =& $this->oField;
-
- $this->oPage->setBreadcrumbDetails(_kt('edit lookup tree'));
-
- $field_id = $iFieldId;
- $current_node = KTUtil::arrayGet($_REQUEST, 'current_node', 0);
- $subaction = KTUtil::arrayGet($_REQUEST, 'subaction');
-
- // validate
- if (empty($field_id)) { return $this->errorRedirectToMain(_kt("Must select a field to edit.")); }
- $oField =& DocumentField::get($field_id);
- if (PEAR::isError($oField)) { return $this->errorRedirectToMain(_kt("Invalid field.")); }
-
- $aErrorOptions = array(
- 'redirect_to' => array('editTree', sprintf('field_id=%d', $field_id)),
- );
-
- // under here we do the subaction rendering.
- // we do this so we don't have to do _very_ strange things with multiple actions.
-
- $fieldTree =& new MDTree();
- $fieldTree->buildForField($oField->getId());
-
- if ($subaction !== null) {
- $target = 'managetree';
- $msg = _kt('Changes saved.');
- if ($subaction === "addCategory") {
- $new_category = KTUtil::arrayGet($_REQUEST, 'category_name');
- if (empty($new_category)) {
- return $this->errorRedirectTo("managetree", _kt("Must enter a name for the new category."), array("field_id" => $field_id, "fFieldsetId" => $iFieldsetId));
- } else {
- $this->subact_addCategory($field_id, $current_node, $new_category, $fieldTree);
- }
- $msg = _kt('Category added'). ': ' . $new_category;
- }
- if ($subaction === "deleteCategory") {
- $this->subact_deleteCategory($fieldTree, $current_node);
- $current_node = 0; // clear out, and don't try and render the newly deleted category.
- $msg = _kt('Category removed.');
- }
- if ($subaction === "linkKeywords") {
- $keywords = KTUtil::arrayGet($_REQUEST, 'keywordsToAdd');
- $aErrorOptions['message'] = _kt("No keywords selected");
- $this->oValidator->notEmpty($keywords, $aErrorOptions);
- $this->subact_linkKeywords($fieldTree, $current_node, $keywords);
- $current_node = 0; // clear out, and don't try and render the newly deleted category.
- $msg = _kt('Keywords added to category.');
- }
- if ($subaction === "unlinkKeyword") {
- $keyword = KTUtil::arrayGet($_REQUEST, 'keyword_id');
- $this->subact_unlinkKeyword($fieldTree, $keyword);
- $msg = _kt('Keyword moved to base of tree.');
- }
- // now redirect
- $query = sprintf('field_id=%d&fFieldsetId=%d', $field_id, $iFieldsetId);
- return $this->successRedirectTo($target, $msg, $query);
- }
- if ($fieldTree->root === null) {
- return $this->errorRedirectToMain(_kt("Error building tree. Is this a valid tree-lookup field?"));
- }
-
- // FIXME extract this from MDTree (helper method?)
- $free_metadata = MetaData::getList('document_field_id = '.$oField->getId().' AND (treeorg_parent = 0 OR treeorg_parent IS NULL) AND (disabled = 0)');
-
- // render edit template.
-
- $oTemplate = $this->oValidator->validateTemplate("ktcore/metadata/admin/edit_lookuptree");
- $renderedTree = $this->_evilTreeRenderer($fieldTree);
-
- $this->oPage->setTitle(_kt('Edit Lookup Tree'));
-
- if ($current_node == 0) { $category_name = 'Root'; }
- else {
- $oNode = MDTreeNode::get($current_node);
- $category_name = $oNode->getName();
- }
-
- $aTemplateData = array(
- "context" => $this,
- "args" => $this->meldPersistQuery("","managetree", true),
- "field" => $oField,
- "oFieldset" => $oFieldset,
- "tree" => $fieldTree,
- "renderedTree" => $renderedTree,
- "currentNode" => $current_node,
- 'category_name' => $category_name,
- "freechildren" => $free_metadata,
-
- );
- return $oTemplate->render($aTemplateData);
- }
- /**
- * Adds a category
- * @return
- * @param $field_id Object
- * @param $current_node Object
- * @param $new_category Object
- * @param $constructedTree Object
- *
- * iNET Process
- */
- function subact_addCategory($field_id, $current_node, $new_category, &$constructedTree) {
- $newCategory = MDTreeNode::createFromArray(array (
- "iFieldId" => $field_id,
- "sName" => $new_category,
- "iParentNode" => $current_node,
- ));
- if (PEAR::isError($newCategory))
- {
- return false;
- }
- $constructedTree->addNode($newCategory);
- return true;
- }
- /**
- * Deletes a catagory
- * @return
- * @param $constructedTree Object
- * @param $current_node Object
- */
- function subact_deleteCategory(&$constructedTree, $current_node) {
- $constructedTree->deleteNode($current_node);
- return true;
- }
-
- /**
- *
- * @param $constructedTree object
- * @param $keywords
- * @return true.
- *
- * iNET Process
- */
- function subact_unlinkKeyword(&$constructedTree, $keyword) {
- $oKW = MetaData::get($keyword);
- if (PEAR::isError($oKW)) {
- return true;
- }
- $constructedTree->reparentKeyword($oKW->getId(), 0);
- return true;
- }
-
- /**
- *
- * @param $constructedTree object
- * @param $current_node node id
- * @param $keywords array
- * @return true.
- *
- * iNET Process
- */
- function subact_linkKeywords(&$constructedTree, $current_node, $keywords) {
- foreach ($keywords as $md_id)
- {
- $constructedTree->reparentKeyword($md_id, $current_node);
- }
- return true;
- }
-
- /* ----------------------- EVIL HACK --------------------------
- *
- * This whole thing needs to replaced, as soon as I work out how
- * to non-sucking Smarty recursion.
- */
-
- /**
- * render to subnode of tree
- *
- * @param $subnode node
- * @param $treeToRender object
- * @Return string
- *
- * iNET Process
- */
- function _evilTreeRecursion($subnode, $treeToRender)
- {
- // deliver us from evil....
- $iFieldId = $treeToRender->field_id;
- $oField = DocumentField::get($iFieldId);
- $iFieldsetId = $oField->getParentFieldsetId();
-
- $treeStr = "
{$description}
- {if empty($vocab)} -{$description}
+ {if empty($vocab)} +{$description}
- {if empty($vocab)} -{$description}
+ {if empty($vocab)} +