MDL-13590 - adding locallib.php for HEAD
[moodle.git] / tag / edit.php
CommitLineData
c933a060 1<?php // $Id$
2
3require_once('../config.php');
4require_once('lib.php');
5require_once('edit_form.php');
c933a060 6
9c9d3076 7require_js(array('yui_dom-event', 'yui_connection', 'yui_animation', 'yui_autocomplete'));
8
c933a060 9require_login();
10
9c9d3076 11if (empty($CFG->usetags)) {
c933a060 12 error(get_string('tagsaredisabled', 'tag'));
13}
14
bb062447 15$tagid = required_param('id', PARAM_INT); // user id
16
17$tag = tag_by_id($tagid);
9c9d3076 18$tagname = tag_display_name($tag);
c933a060 19
4f81c51d 20//Editing a tag requires moodle/tag:edit capability
c933a060 21$systemcontext = get_context_instance(CONTEXT_SYSTEM);
4f81c51d 22require_capability('moodle/tag:edit', $systemcontext);
c933a060 23
24// set the relatedtags field of the $tag object that will be passed to the form
bb062447 25$tag->relatedtags = tag_names_csv(get_item_tags('tag',$tagid));
c933a060 26
d4be9d6d 27if (can_use_html_editor()) {
28 $options = new object();
29 $options->smiley = false;
30 $options->filter = false;
31
32 // convert and remove any XSS
33 $tag->description = format_text($tag->description, $tag->descriptionformat, $options);
34 $tag->descriptionformat = FORMAT_HTML;
35}
36
c933a060 37$tagform = new tag_edit_form();
38$tagform->set_data($tag);
39
40// if new data has been sent, update the tag record
41if ($tagnew = $tagform->get_data()) {
d4be9d6d 42
c933a060 43 $tagnew->timemodified = time();
d4be9d6d 44
c933a060 45 if (!update_record('tag', $tagnew)) {
46 error('Error updating tag record');
47 }
48
49 //updated related tags
bb062447 50 update_item_tags('tag', $tagnew->id, $tagnew->relatedtags);
c933a060 51
bb062447 52 redirect($CFG->wwwroot.'/tag/index.php?id='.$tagnew->id);
c933a060 53}
54
55
56$navlinks = array();
57$navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
58$navlinks[] = array('name' => $tagname, 'link' => '', 'type' => '');
59
60$navigation = build_navigation($navlinks);
61print_header_simple(get_string('tag', 'tag') . ' - '. $tagname, '', $navigation);
62
63print_heading($tagname, '', 2);
64
65$tagform->display();
66
9c9d3076 67if (ajaxenabled()) {
9ee998a5 68?>
c933a060 69
70<script type="text/javascript">
71
72// An XHR DataSource
73var myServer = "./tag_autocomplete.php";
74var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
75myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
76myDataSource.maxCacheEntries = 60;
77myDataSource.queryMatchSubset = true;
78
79var myAutoComp = new YAHOO.widget.AutoComplete("id_relatedtags","relatedtags-autocomplete", myDataSource);
80myAutoComp.delimChar = ",";
81myAutoComp.maxResultsDisplayed = 20;
82myAutoComp.minQueryLength = 2;
83myAutoComp.allowBrowserAutocomplete = false;
84</script>
85
86<?php
9c9d3076 87}
c933a060 88print_footer();
89
90?>