diff --git a/lib/dispatcher.inc.php b/lib/dispatcher.inc.php
index ad3ce79..3a768f9 100644
--- a/lib/dispatcher.inc.php
+++ b/lib/dispatcher.inc.php
@@ -180,6 +180,27 @@ class KTDispatcher {
}
$this->redirectTo($event, $sQuery);
}
+
+ function errorRedirectToParent($error_message) {
+ if ($this->bTransactionStarted) {
+ $this->rollbackTransaction();
+ }
+
+ $_SESSION['KTErrorMessage'][] = $error_message;
+ redirect($this->sParentUrl);
+ exit(0);
+ }
+
+ function successRedirectToParent($info_message) {
+ if ($this->bTransactionStarted) {
+ $this->commitTransaction();
+ }
+ if (!empty($info_message)) {
+ $_SESSION['KTInfoMessage'][] = $info_message;
+ }
+ redirect($this->sParentUrl);
+ exit(0);
+ }
function redirectTo($event, $sQuery = "") {
// meld persistant options
diff --git a/lib/widgets/forms.inc.php b/lib/widgets/forms.inc.php
index 73b000b..b17bcbe 100644
--- a/lib/widgets/forms.inc.php
+++ b/lib/widgets/forms.inc.php
@@ -212,6 +212,11 @@ class KTForm {
return $this->renderContaining($sWidgets . ' ' . $sButtons);
}
+ function renderPage($sTitle) {
+ $pageval = $this->render();
+ return sprintf('
%s
%s', $sTitle, $pageval);
+ }
+
function renderWidgets() {
if (empty($this->_widgets)) {
return ' ';
diff --git a/plugins/ktcore/KTValidators.php b/plugins/ktcore/KTValidators.php
index b7cd38b..ebd8e3f 100644
--- a/plugins/ktcore/KTValidators.php
+++ b/plugins/ktcore/KTValidators.php
@@ -22,7 +22,9 @@ class KTStringValidator extends KTValidator {
$this->sMinLengthWarning = KTUtil::arrayGet($aOptions, 'min_length_warning',
sprintf(_kt('You must provide a value which is at least %d characters long.'), $this->iMinLength));
$this->sMaxLengthWarning = KTUtil::arrayGet($aOptions, 'max_length_warning',
- sprintf(_kt('You must provide a value which is at most %d characters long.'), $this->iMaxLength));
+ sprintf(_kt('You must provide a value which is at most %d characters long.'), $this->iMaxLength));
+
+ $this->bTrim = KTUtil::arrayGet($aOptions, 'trim', true, false);
}
function validate($data) {
@@ -33,6 +35,10 @@ class KTStringValidator extends KTValidator {
// otherwise, its ok.
$val = KTUtil::arrayGet($data, $this->sInputVariable);
+ if ($this->bTrim) {
+ $val = trim($val);
+ }
+
$l = strlen($val);
if ($l < $this->iMinLength) {
$errors[$this->sBasename] = $this->sMinLengthWarning;
diff --git a/plugins/ktcore/admin/documentFieldsv2.php b/plugins/ktcore/admin/documentFieldsv2.php
index c10f643..a4133cd 100644
--- a/plugins/ktcore/admin/documentFieldsv2.php
+++ b/plugins/ktcore/admin/documentFieldsv2.php
@@ -267,6 +267,129 @@ class KTDocumentFieldDispatcher extends KTAdminDispatcher {
));
return $oTemplate->render();
}
+
+ function do_delete() {
+ $this->startTransaction();
+ $res = $this->oFieldset->delete();
+ $this->oValidator->notErrorFalse($res, array(
+ 'redirect_to' => array('main', ''),
+ 'message' => _kt('Could not delete fieldset'),
+ ));
+ $this->successRedirectToMain(_kt('Fieldset deleted'));
+ }
+
+ 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' => $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' => $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;
+ }
+
+ function do_editfieldset() {
+ $oForm = $this->form_edit();
+ return $oForm->renderPage(_kt("Edit Fieldset"));
+ }
+
+ 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 = $oFieldset->getAssociatedTypes();
+ foreach ($aTypes as $oType) {
+ $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $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."));
+ }
}
?>
diff --git a/plugins/ktcore/admin/fieldsets/basic.inc.php b/plugins/ktcore/admin/fieldsets/basic.inc.php
index d25f27f..e1af7ac 100644
--- a/plugins/ktcore/admin/fieldsets/basic.inc.php
+++ b/plugins/ktcore/admin/fieldsets/basic.inc.php
@@ -512,31 +512,6 @@ class BasicFieldsetManagementDispatcher extends KTAdminDispatcher {
}
// }}}
- // {{{ do_removeFields
- function do_removeFields() {
- $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']);
- foreach ($_REQUEST['fields'] as $iFieldId) {
- $oField =& DocumentField::get($iFieldId);
- $oField->delete();
- }
- $this->successRedirectTo('edit', _kt('Fields removed'), 'fFieldsetId=' . $oFieldset->getId());
- exit(0);
- }
- // }}}
-
- // {{{ do_delete
- function do_delete() {
- $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
- $res = $oFieldset->delete();
- $this->oValidator->notErrorFalse($res, array(
- 'redirect_to' => array('main', ''),
- 'message' => _kt('Could not delete fieldset'),
- ));
- $this->successRedirectToMain(_kt('Fieldset deleted'));
- }
- // }}}
-
-
// {{{ TREE
// create and display the tree editing form.
function do_managetree() {
@@ -772,6 +747,15 @@ class BasicFieldsetManagementDispatcher extends KTAdminDispatcher {
return $actionStr;
}
+ function do_deletefield() {
+ $res = $this->oField->delete();
+ if (PEAR::isError($res)) {
+ $this->errorRedirectToParent(sprintf(_kt("Unable to delete field: %s"), $res->getMessage()));
+ }
+
+ $this->successRedirectToParent(_kt("Field deleted."));
+ }
+
}
?>
diff --git a/templates/ktcore/metadata/admin/basic_overview.smarty b/templates/ktcore/metadata/admin/basic_overview.smarty
index 5e9ad2d..8227ca1 100644
--- a/templates/ktcore/metadata/admin/basic_overview.smarty
+++ b/templates/ktcore/metadata/admin/basic_overview.smarty
@@ -9,8 +9,8 @@ of related information.{/i18n}
| {i18n}Field Name{/i18n} |
- {i18n}Edit{/i18n} |
- {i18n}Delete{/i18n} |
+ {i18n}Edit{/i18n} |
+ {i18n}Delete{/i18n} |
{i18n}Type Description{/i18n} |
@@ -20,9 +20,12 @@ of related information.{/i18n}
{$oField->getName()|escape}
|
-
+ |
{i18n}edit{/i18n}
|
+
+ {i18n}delete{/i18n}
+ |
{$oField->getTypeDescription()}
|