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