From 7e6e76a6ce9f9bbef18e3da2d5427998e5f0e603 Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 25 Feb 2008 06:29:12 +0000 Subject: [PATCH] MDL-13635 name editing merged from stable --- tag/edit.php | 45 ++++++++++++++++++++++++++++++++++++--------- tag/edit_form.php | 11 +++++++++-- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/tag/edit.php b/tag/edit.php index 768bd8c08e..79497dfdbf 100644 --- a/tag/edit.php +++ b/tag/edit.php @@ -41,23 +41,46 @@ if (can_use_html_editor()) { $tag->descriptionformat = FORMAT_HTML; } +$errorstring = ''; + $tagform = new tag_edit_form(); $tagform->set_data($tag); -// if new data has been sent, update the tag record +// If new data has been sent, update the tag record if ($tagnew = $tagform->get_data()) { - $tagnew->timemodified = time(); - if (!update_record('tag', $tagnew)) { - error('Error updating tag record'); - } + if (!has_capability('moodle/tag:manage', $systemcontext)) { + unset($tagnew->name); + unset($tagnew->rawname); + + } else { // They might be trying to change the rawname, make sure it's a change that doesn't affect name + $tagnew->name = array_shift(tag_normalize($tagnew->rawname, TAG_CASE_LOWER)); + + if (!$tagold = tag_get_tag_by_id($tag_id)) { // For doing checks + error('Error updating tag record'); + } - //updated related tags - tag_set('tag', $tagnew->id, explode(',', trim($tagnew->relatedtags))); - //var_dump($tagnew); die(); + if ($tagold->name != $tagnew->name) { // The name has changed, let's make sure it's not another existing tag + if (tag_get_id($tagnew->name)) { // Something exists already, so flag an error + $errorstring = s($tagnew->rawname).': '.get_string('namesalreadybeeingused', 'tag'); + } + } + } - redirect($CFG->wwwroot.'/tag/index.php?tag='.rawurlencode($tag->name)); // must use $tag here, as the name isn't in the edit form + if (empty($errorstring)) { // All is OK, let's save it + $tagnew->timemodified = time(); + + if (!update_record('tag', $tagnew)) { + error('Error updating tag record'); + } + + //updated related tags + tag_set('tag', $tagnew->id, explode(',', trim($tagnew->relatedtags))); + //var_dump($tagnew); die(); + + redirect($CFG->wwwroot.'/tag/index.php?tag='.rawurlencode($tag->name)); // must use $tag here, as the name isn't in the edit form + } } @@ -70,6 +93,10 @@ print_header_simple(get_string('tag', 'tag') . ' - '. $tagname, '', $navigation) print_heading($tagname, '', 2); +if (!empty($errorstring)) { + notify($errorstring); +} + $tagform->display(); if (ajaxenabled()) { diff --git a/tag/edit_form.php b/tag/edit_form.php index e964294394..43c657fbce 100644 --- a/tag/edit_form.php +++ b/tag/edit_form.php @@ -4,14 +4,21 @@ require_once($CFG->dirroot.'/lib/formslib.php'); class tag_edit_form extends moodleform { -function definition () { + function definition () { - $mform =& $this->_form; + $mform =& $this->_form; $mform->addElement('header', 'tag', get_string('description','tag')); $mform->addElement('hidden', 'id'); + $systemcontext = get_context_instance(CONTEXT_SYSTEM); + + if (has_capability('moodle/tag:manage', $systemcontext)) { + $mform->addElement('text', 'rawname', get_string('name', 'tag'), + 'maxlength="'.TAG_MAX_LENGTH.'" size="'.TAG_MAX_LENGTH.'"'); + } + $mform->addElement('htmleditor', 'description', get_string('description', 'tag'), array('rows'=>20)); $mform->addElement('format', 'descriptionformat', get_string('format')); -- 2.39.5