MDL-13635 name editing merged from stable

This commit is contained in:
moodler
2008-02-25 06:29:12 +00:00
parent 6e0b112f99
commit 7e6e76a6ce
2 changed files with 44 additions and 10 deletions
+35 -8
View File
@@ -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');
}
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');
}
}
}
//updated related tags
tag_set('tag', $tagnew->id, explode(',', trim($tagnew->relatedtags)));
//var_dump($tagnew); die();
if (empty($errorstring)) { // All is OK, let's save it
$tagnew->timemodified = time();
redirect($CFG->wwwroot.'/tag/index.php?tag='.rawurlencode($tag->name)); // must use $tag here, as the name isn't in the edit form
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()) {
+9 -2
View File
@@ -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'));