99 lines
2.8 KiB
PHP
99 lines
2.8 KiB
PHP
<?php // $Id$
|
|
|
|
require_once('../config.php');
|
|
require_once('lib.php');
|
|
require_once('edit_form.php');
|
|
|
|
require_js(array('yui_dom-event', 'yui_connection', 'yui_animation', 'yui_autocomplete'));
|
|
|
|
require_login();
|
|
|
|
if (empty($CFG->usetags)) {
|
|
error(get_string('tagsaredisabled', 'tag'));
|
|
}
|
|
|
|
$tag_id = optional_param('id', 0, PARAM_INT);
|
|
$tag_name = optional_param('tag', '', PARAM_TAG);
|
|
if ($tag_name) {
|
|
$tag = tag_get_id($tag_name, TAG_RETURN_OBJECT);
|
|
} elseif ( $tag_id ) {
|
|
$tag = tag_get_tag_by_id($tag_id);
|
|
} else {
|
|
error('A required parameter was missing');
|
|
}
|
|
$tagname = tag_display_name($tag);
|
|
|
|
//Editing a tag requires moodle/tag:edit capability
|
|
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
|
require_capability('moodle/tag:edit', $systemcontext);
|
|
|
|
// set the relatedtags field of the $tag object that will be passed to the form
|
|
//$tag->relatedtags = tag_names_csv(get_item_tags('tag',$tagid));
|
|
$tag->relatedtags = tag_get_related_tags_csv(tag_get_related_tags($tag->id), TAG_RETURN_TEXT);
|
|
|
|
if (can_use_html_editor()) {
|
|
$options = new object();
|
|
$options->smiley = false;
|
|
$options->filter = false;
|
|
|
|
// convert and remove any XSS
|
|
$tag->description = format_text($tag->description, $tag->descriptionformat, $options);
|
|
$tag->descriptionformat = FORMAT_HTML;
|
|
}
|
|
|
|
$tagform = new tag_edit_form();
|
|
$tagform->set_data($tag);
|
|
|
|
// 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');
|
|
}
|
|
|
|
//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
|
|
}
|
|
|
|
|
|
$navlinks = array();
|
|
$navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
|
|
$navlinks[] = array('name' => $tagname, 'link' => '', 'type' => '');
|
|
|
|
$navigation = build_navigation($navlinks);
|
|
print_header_simple(get_string('tag', 'tag') . ' - '. $tagname, '', $navigation);
|
|
|
|
print_heading($tagname, '', 2);
|
|
|
|
$tagform->display();
|
|
|
|
if (ajaxenabled()) {
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
// An XHR DataSource
|
|
var myServer = "./tag_autocomplete.php";
|
|
var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
|
|
myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
|
|
myDataSource.maxCacheEntries = 60;
|
|
myDataSource.queryMatchSubset = true;
|
|
|
|
var myAutoComp = new YAHOO.widget.AutoComplete("id_relatedtags","relatedtags-autocomplete", myDataSource);
|
|
myAutoComp.delimChar = ",";
|
|
myAutoComp.maxResultsDisplayed = 20;
|
|
myAutoComp.minQueryLength = 2;
|
|
myAutoComp.allowBrowserAutocomplete = false;
|
|
</script>
|
|
|
|
<?php
|
|
}
|
|
print_footer();
|
|
|
|
?>
|