documentfieldsv2.php.tmp
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· TMP 代码 · 共 438 行 · 第 1/2 页
TMP
438 行
<?php/** * $Id$ * * 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');class KTDocumentFieldDispatcher extends KTAdminDispatcher { var $bAutomaticTransaction = true; var $bHaveConditional = null; var $sHelpPage = 'ktcore/admin/document fieldsets.html'; 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'); } 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; } 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; } function do_newfieldset() { $this->oPage->setBreadcrumbDetails(_kt("Create New Fieldset")); $oForm = $this->form_create(); return $oForm->render(); } 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()));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?