From 5edc0caa81f334900e110041d4838d722ea7bf4e Mon Sep 17 00:00:00 2001
From: bshuttle ' . print_r($field_values, true) . '
';
+ $this->startTransaction();
+ $iPreviousMetadataVersionId = $oDocument->getMetadataVersionId();
+ $oDocument->startNewMetadataVersion($this->oUser);
+ if (PEAR::isError($res)) {
+ $this->errorRedirectToMain('Unable to create a metadata version of the document.');
+ }
+
+ $oDocument->setName($title);
+ $oDocument->setLastModifiedDate(getCurrentDateTime());
+ $oDocument->setModifiedUserId($this->oUser->getId());
+
+ // FIXME refactor this into documentutil.
+ // document type changing semantics
+ if ($newType != null) {
+ $oldType = DocumentType::get($oDocument->getDocumentTypeID());
+ $oDocument->setDocumentTypeID($newType);
+
+ // we need to find fieldsets that _were_ in the old one, and _delete_ those.
+ $for_delete = array();
+
+ $oldFieldsets = KTFieldset::getForDocumentType($oldType);
+ $newFieldsets = KTFieldset::getForDocumentType($newType);
+
+ // prune from MDPack.
+ foreach ($oldFieldsets as $oFieldset) {
+ $old_fields = $oFieldset->getFields();
+ foreach ($old_fields as $oField) {
+ $for_delete[$oField->getId()] = 1;
}
- $field_values = $final_values;
-
- // FIXME handle md versions.
- //return '' . print_r($field_values, true) . '
';
- $this->startTransaction();
- $iPreviousMetadataVersionId = $oDocument->getMetadataVersionId();
- $oDocument->startNewMetadataVersion($this->oUser);
- if (PEAR::isError($res)) {
- $this->errorRedirectToMain('Unable to create a metadata version of the document.');
+ }
+
+ foreach ($newFieldsets as $oFieldset) {
+ $new_fields = $oFieldset->getFields();
+ foreach ($new_fields as $oField) {
+ unset($for_delete[$oField->getId()]);
}
-
- $oDocument->setName($title);
- $oDocument->setLastModifiedDate(getCurrentDateTime());
- $oDocument->setModifiedUserId($this->oUser->getId());
-
- // FIXME refactor this into documentutil.
- // document type changing semantics
- if ($newType != null) {
- $oldType = DocumentType::get($oDocument->getDocumentTypeID());
- $oDocument->setDocumentTypeID($newType);
-
- // we need to find fieldsets that _were_ in the old one, and _delete_ those.
- $for_delete = array();
-
- $oldFieldsets = KTFieldset::getForDocumentType($oldType);
- $newFieldsets = KTFieldset::getForDocumentType($newType);
-
- // prune from MDPack.
- foreach ($oldFieldsets as $oFieldset) {
- $old_fields = $oFieldset->getFields();
- foreach ($old_fields as $oField) {
- $for_delete[$oField->getId()] = 1;
- }
- }
-
- foreach ($newFieldsets as $oFieldset) {
- $new_fields = $oFieldset->getFields();
- foreach ($new_fields as $oField) {
- unset($for_delete[$oField->getId()]);
- }
- }
-
- $newPack = array();
- foreach ($field_values as $MDPack) {
- if (!array_key_exists($MDPack[0]->getId(), $for_delete)) {
- $newPack[] = $MDPack;
- }
- }
- $field_values = $newPack;
-
-
- //var_dump($field_values);
- //exit(0);
+ }
+
+ $newPack = array();
+ foreach ($field_values as $MDPack) {
+ if (!array_key_exists($MDPack[0]->getId(), $for_delete)) {
+ $newPack[] = $MDPack;
}
-
+ }
+ $field_values = $newPack;
+
+
+ //var_dump($field_values);
+ //exit(0);
+ }
+
$oDocumentTransaction = & new DocumentTransaction($oDocument, 'update metadata.', 'ktcore.transactions.update');
$res = $oDocumentTransaction->create();
diff --git a/lib/documentmanagement/DocumentType.inc b/lib/documentmanagement/DocumentType.inc
index 39de6a4..46e8231 100644
--- a/lib/documentmanagement/DocumentType.inc
+++ b/lib/documentmanagement/DocumentType.inc
@@ -112,7 +112,7 @@ class DocumentType extends KTEntity {
function _fieldValues () {
return array(
'name' => $this->sName,
- 'disabled' => $this->bDisabled,
+ 'disabled' => $this->bDisabled,
);
}
@@ -148,6 +148,16 @@ class DocumentType extends KTEntity {
}
return false;
}
+
+ /*
+ Get the fieldsets associated with this document type.
+ Simplifies listing associated fieldsets in doctypes displays.
+ */
+
+ function &getFieldsets() {
+ return KTFieldset::getForDocumentType($this);
+ }
+
/**
* Static function.
diff --git a/lib/metadata/fieldset.inc.php b/lib/metadata/fieldset.inc.php
index 90601fe..af428fc 100644
--- a/lib/metadata/fieldset.inc.php
+++ b/lib/metadata/fieldset.inc.php
@@ -99,23 +99,59 @@ class KTFieldset extends KTEntity {
"bIsSystem" => "is_system",
);
- // returns TRUE if all children are lookup enabled, false otherwise.
- function canBeMadeConditional() {
- if ($this->getIsConditional()) {
- return false;
- }
-
- // DEBUG
- return false;
+ // returns TRUE if all children are lookup enabled, false otherwise.
+ function canBeMadeConditional() {
+ if ($this->getIsConditional()) {
+ return false;
}
+
+ // DEBUG
+ return false;
+ }
function _table () {
return KTUtil::getTableName('fieldsets');
}
+
+
+
+
+ /*
+ * get document types using this field
+ * for listing displays
+ */
+ function &getDocumentTypesUsing($aOptions = null) {
+ $bIds = KTUtil::arrayGet($aOptions, 'ids');
+
+ $sTable = KTUtil::getTableName('document_type_fieldsets');
+
+ $aQuery = array(
+ "SELECT document_type_id FROM $sTable WHERE fieldset_id = ?",
+ array($this->getId()),
+ );
+ $aIds = DBUtil::getResultArrayKey($aQuery, 'document_type_id');
+
+ if ($bIds) {
+ return $aIds;
+ }
+
+ $aRet = array();
+ foreach ($aIds as $iID) {
+ $aRet[] =& call_user_func(array('DocumentType', 'get'), $iID);
+ }
+ return $aRet;
+ }
+
+
+
+
+
+
+
// Static function
function &get($iId) { return KTEntityUtil::get('KTFieldset', $iId); }
- function &getList($sWhereClause = null) { return KTEntityUtil::getList2('KTFieldset', $sWhereClause); }
+ function &getList($sWhereClause = null) { return KTEntityUtil::getList2('KTFieldset', $sWhereClause); }
function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('KTFieldset', $aOptions); }
function &getNonGenericFieldsets($aOptions = null) {
@@ -127,10 +163,11 @@ class KTFieldset extends KTEntity {
), $aOptions);
}
- function &getGenericFieldsets($aOptions = null) {
- $aOptions = KTUtil::meldOptions($aOptions, array(
- 'multi' => true,
- ));
+ function &getGenericFieldsets($aOptions = null) {
+ $aOptions = KTUtil::meldOptions(
+ $aOptions,
+ array('multi' => true,)
+ );
return KTEntityUtil::getByDict('KTFieldset', array(
'is_generic' => true,
), $aOptions);
diff --git a/lib/validation/dispatchervalidation.inc.php b/lib/validation/dispatchervalidation.inc.php
index 32f27dc..069b801 100644
--- a/lib/validation/dispatchervalidation.inc.php
+++ b/lib/validation/dispatchervalidation.inc.php
@@ -210,6 +210,15 @@ class KTDispatcherValidation {
'message', _kt("An empty string was given"));
$this->handleError($aOptions);
}
+
+ $iMaxlen = (int)KTUtil::arrayGet($aOptions, 'max_str_len', false);
+ if($iMaxlen !== false && $iMaxlen !== 0 && strlen($sString) > $iMaxlen) {
+ $aOptions['message'] = KTUtil::arrayGet($aOptions,
+ 'max_str_len_message',
+ _kt("The string is too long: the maximum length in characters is ") . $iMaxlen);
+ $this->handleError($aOptions);
+ }
+
return $sString;
}
@@ -357,8 +366,7 @@ class KTDispatcherValidation {
function validateEntityName($sEntityTypeName, $sName, $aOptions = null) {
$aOptions['message'] = KTUtil::arrayGet($aOptions, 'empty_message', _kt("No name was given for this item"));
- // FIXME BD: don't you mean $sName = $this->validateString ...
- $this->validateString($sName, $aOptions);
+ $sName = $this->validateString($sName, $aOptions);
$aOptions['message'] = KTUtil::arrayGet($aOptions, 'duplicate_message', _kt("An item with this name already exists"));
return $this->validateDuplicateName($sEntityTypeName, $sName, $aOptions);
}
diff --git a/plugins/ktcore/KTFolderActions.php b/plugins/ktcore/KTFolderActions.php
index 2058c92..7b1b305 100644
--- a/plugins/ktcore/KTFolderActions.php
+++ b/plugins/ktcore/KTFolderActions.php
@@ -69,6 +69,11 @@ class KTFolderAddFolderAction extends KTFolderAction {
$sFolderName = KTUtil::arrayGet($_REQUEST, 'name');
$aErrorOptions['defaultmessage'] = _kt("No name given");
$sFolderName = $this->oValidator->validateString($sFolderName, $aErrorOptions);
+
+ if(KTFolderUtil::exists($this->oFolder, $sFolderName)) {
+ $this->errorRedirectToMain(_kt('A folder with that name already exists.'), $aErrorOptions['redirect_to'][1]);
+ exit(0);
+ }
$this->startTransaction();
diff --git a/plugins/ktcore/admin/userManagement.php b/plugins/ktcore/admin/userManagement.php
index b9da91c..ace3a34 100755
--- a/plugins/ktcore/admin/userManagement.php
+++ b/plugins/ktcore/admin/userManagement.php
@@ -89,7 +89,7 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
function do_addUser() {
$this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('User Management'));
$this->oPage->setBreadcrumbDetails(_kt('add a new user'));
- $this->oPage->setTitle(_kt("Modify User Details"));
+ $this->oPage->setTitle(_kt("Add New User"));
$name = KTUtil::arrayGet($_REQUEST, 'name');
$show_all = KTUtil::arrayGet($_REQUEST, 'show_all', false);
@@ -110,7 +110,7 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
}
$add_fields = array();
- $add_fields[] = new KTStringWidget(_kt('Username'), _kt('The username the user will enter to gain access to KnowledgeTree. e.g. jsmith'), 'username', null, $this->oPage, true, null, null, $aOptions);
+ $add_fields[] = new KTStringWidget(_kt('Username'), _kt('The username the user will enter to gain access to KnowledgeTree. e.g. jsmith'), 'newusername', null, $this->oPage, true, null, null, $aOptions);
$add_fields[] = new KTStringWidget(_kt('Name'), _kt('The full name of the user. This is shown in reports and listings. e.g. John Smith'), 'name', null, $this->oPage, true, null, null, $aOptions);
$add_fields[] = new KTStringWidget(_kt('Email Address'), _kt('The email address of the user. Notifications and alerts are mailed to this address if email notifications is set below. e.g. jsmith@acme.com'), 'email_address', null, $this->oPage, false, null, null, $aOptions);
$add_fields[] = new KTCheckboxWidget(_kt('Email Notifications'), _kt("If this is specified then the user will have notifications sent to the email address entered above. If it isn't set, then the user will only see notifications on the Dashboard"), 'email_notifications', true, $this->oPage, false, null, null, $aOptions);
@@ -142,7 +142,7 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
$this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf('action=addUser'), 'name' => _kt('add a new user'));
$oProvider->aBreadcrumbs = $this->aBreadcrumbs;
$oProvider->oPage->setBreadcrumbDetails($oSource->getName());
- $oProvider->oPage->setTitle(_kt("Modify User Details"));
+ $oProvider->oPage->setTitle(_kt("Add New User"));
$oProvider->dispatch();
exit(0);
@@ -164,7 +164,7 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
$this->aBreadcrumbs[] = array('name' => $oUser->getName());
$edit_fields = array();
- $edit_fields[] = new KTStringWidget(_kt('Username'), _kt('The username the user will enter to gain access to KnowledgeTree. e.g. jsmith'), 'username', $oUser->getUsername(), $this->oPage, true);
+ $edit_fields[] = new KTStringWidget(_kt('Username'), _kt('The username the user will enter to gain access to KnowledgeTree. e.g. jsmith'), 'newusername', $oUser->getUsername(), $this->oPage, true);
$edit_fields[] = new KTStringWidget(_kt('Name'), _kt('The full name of the user. This is shown in reports and listings. e.g. John Smith'), 'name', $oUser->getName(), $this->oPage, true);
$edit_fields[] = new KTStringWidget(_kt('Email Address'), _kt('The email address of the user. Notifications and alerts are mailed to this address if email notifications is set below. e.g. jsmith@acme.com'), 'email_address', $oUser->getEmail(), $this->oPage, false);
$edit_fields[] = new KTCheckboxWidget(_kt('Email Notifications'), _kt('If this is specified then the user will have notifications sent to the email address entered above. If it is not set, then the user will only see notifications on the Dashboard'), 'email_notifications', $oUser->getEmailNotification(), $this->oPage, false);
@@ -351,7 +351,7 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
);
$username = $this->oValidator->validateString(
- KTUtil::arrayGet($_REQUEST, 'username'),
+ KTUtil::arrayGet($_REQUEST, 'newusername'),
KTUtil::meldOptions($aErrorOptions, array('message' => _kt("You must provide a username")))
);
@@ -404,7 +404,7 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
$name = KTUtil::arrayGet($_REQUEST, 'name');
if (empty($name)) { $this->errorRedirectTo('addUser', _kt('You must specify a name for the user.')); }
- $username = KTUtil::arrayGet($_REQUEST, 'username');
+ $username = KTUtil::arrayGet($_REQUEST, 'newusername');
if (empty($name)) { $this->errorRedirectTo('addUser', _kt('You must specify a new username.')); }
// FIXME check for non-clashing usernames.
diff --git a/plugins/ktcore/folder/Rename.php b/plugins/ktcore/folder/Rename.php
index 32c0dd3..0f511e7 100644
--- a/plugins/ktcore/folder/Rename.php
+++ b/plugins/ktcore/folder/Rename.php
@@ -64,20 +64,32 @@ class KTFolderRenameAction extends KTFolderAction {
}
function do_rename() {
- $sName = KTUtil::arrayGet($_REQUEST, 'foldername');
- $aOptions = array(
+ $aErrorOptions = array(
'redirect_to' => array('', sprintf('fFolderId=%d', $this->oFolder->getId())),
- 'message' => _kt("No folder name given"),
);
- $this->oValidator->validateString($sName, $aOptions);
+ $sFolderName = KTUtil::arrayGet($_REQUEST, 'foldername');
+ $aErrorOptions['defaultmessage'] = _kt("No folder name given");
+ $sFolderName = $this->oValidator->validateString($sFolderName, $aErrorOptions);
+
+ $oParentFolder =& Folder::get($this->oFolder->iParentID);
+ if(PEAR::isError($oParentFolder)) {
+ $this->errorRedirectToMain(_kt('Unable to retrieve parent folder.'), $aErrorOptions['redirect_to'][1]);
+ exit(0);
+ }
+
+ if(KTFolderUtil::exists($oParentFolder, $sFolderName)) {
+ $this->errorRedirectToMain(_kt('A folder with that name already exists.'), $aErrorOptions['redirect_to'][1]);
+ exit(0);
+ }
+
+ $res = KTFolderUtil::rename($this->oFolder, $sFolderName, $this->oUser);
- $res = KTFolderUtil::rename($this->oFolder, $sName, $this->oUser);
if (PEAR::isError($res)) {
$_SESSION['KTErrorMessage'][] = $res->getMessage();
redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
exit(0);
} else {
- $_SESSION['KTInfoMessage'][] = sprintf(_kt('Folder "%s" renamed to "%s".'), $this->oFolder->getName(), $sName);
+ $_SESSION['KTInfoMessage'][] = sprintf(_kt('Folder "%s" renamed to "%s".'), $this->oFolder->getName(), $sFolderName);
}
$this->commitTransaction();
diff --git a/plugins/ktcore/folder/addDocument.php b/plugins/ktcore/folder/addDocument.php
index 3ef1cfc..1c7afbd 100644
--- a/plugins/ktcore/folder/addDocument.php
+++ b/plugins/ktcore/folder/addDocument.php
@@ -115,6 +115,7 @@ class KTFolderAddDocumentAction extends KTFolderAction {
$aErrorOptions = array(
'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())),
+ 'max_str_len' => 200,
);
$aFile = $this->oValidator->validateFile($_FILES['file'], $aErrorOptions);
diff --git a/templates/ktcore/documenttypes/list.smarty b/templates/ktcore/documenttypes/list.smarty
index dd0b86c..32fac8d 100644
--- a/templates/ktcore/documenttypes/list.smarty
+++ b/templates/ktcore/documenttypes/list.smarty
@@ -31,8 +31,9 @@ system.{/i18n}