📄 basic.inc.php
字号:
<?php
/**
* $Id: basic.inc.php 8387 2008-04-22 16:36:04Z kevin_fourie $
*
* KnowledgeTree Community Edition
* Document Management Made Simple
* Copyright (C) 2008 KnowledgeTree Inc.
* Portions copyright The Jam Warehouse Software (Pty) Limited
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 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 BasicFieldsetManagementDispatcher extends KTAdminDispatcher {
var $bAutomaticTransaction = true;
var $bHaveConditional = null;
var $sHelpPage = 'ktcore/admin/document fieldsets.html';
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.
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();
}
function do_main () {
return _kt("Something very unexpected happened.");
}
function getFieldTypeVocab() {
$types = array(
'normal' => _kt("Normal (String)"),
'lookup' => _kt("Lookup"),
'tree' => _kt("Tree"),
);
return $types;
}
function getDefaultType() {
return 'normal';
}
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;
}
function do_newfield() {
$oForm = $this->form_newfield();
return $oForm->render();
}
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;
if ($data['field_type'] == 'lookup') {
$lookup = true;
} else if ($data['field_type'] == 'tree') {
$lookup = true;
$tree = true;
}
$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'],
));
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()));
}
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,
));
$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;
}
function do_managefield() {
$oTemplate = $this->oValidator->validateTemplate('ktcore/metadata/admin/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();
}
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)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -