basic.inc.php.svn-base

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 869 行 · 第 1/3 页

SVN-BASE
869
字号
                $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']);        $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."));    }    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;    }    function do_addlookupvalues() {        $this->oPage->setBreadcrumbDetails(_kt('add lookup values'));        $oForm = $this->form_addlookups();        return $oForm->render();    }    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)));    }    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;                <!-- Replace all double quotes with &#34; -->\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('\"', '&#34;');\n                    }\n                }\n\n                var inner = '<input type=\"text\" name=\"lookup['+id+']\" id=\"lookup_'+id+'\" value=\"'+newValue+'\" />';\n                inner += '<input type=\"hidden\" id=\"original_'+id+'\" value=\"'+newValue+'\" />';\n                inner += '<input type=\"submit\" name=\"submit[edit]\" value=\""._kt('Save')."\" />';\n                inner += '<input type=\"button\" onclick=\"javascript: closeLookupEdit('+id+');\" name=\"cancel\" value=\""._kt('Cancel')."\" />';\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    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    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    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     *     */    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;                //$this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));            }            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    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    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'));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?