3 require_once('../config.php');
4 require_once('lib.php');
5 require_once('edit_form.php');
7 require_js(array('yui_dom-event', 'yui_connection', 'yui_animation', 'yui_autocomplete'));
11 if (empty($CFG->usetags
)) {
12 print_error('tagsaredisabled', 'tag');
15 $tag_id = optional_param('id', 0, PARAM_INT
);
16 $tag_name = optional_param('tag', '', PARAM_TAG
);
19 $tag = tag_get('name', $tag_name, '*');
21 $tag = tag_get('id', $tag_id, '*');
25 redirect($CFG->wwwroot
.'/tag/search.php');
28 $tagname = tag_display_name($tag);
30 //Editing a tag requires moodle/tag:edit capability
31 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
32 require_capability('moodle/tag:edit', $systemcontext);
34 // set the relatedtags field of the $tag object that will be passed to the form
35 $tag->relatedtags
= tag_get_related_tags_csv(tag_get_related_tags($tag->id
, TAG_RELATED_MANUAL
), TAG_RETURN_TEXT
);
37 if (can_use_html_editor()) {
38 $options = new object();
39 $options->smiley
= false;
40 $options->filter
= false;
42 // convert and remove any XSS
43 $tag->description
= format_text($tag->description
, $tag->descriptionformat
, $options);
44 $tag->descriptionformat
= FORMAT_HTML
;
49 $tagform = new tag_edit_form();
50 if ( $tag->tagtype
== 'official' ) {
55 $tagform->set_data($tag);
57 // If new data has been sent, update the tag record
58 if ($tagnew = $tagform->get_data()) {
60 tag_description_set($tag_id, stripslashes($tagnew->description
), $tagnew->descriptionformat
);
62 if (has_capability('moodle/tag:manage', $systemcontext)) {
63 if (($tag->tagtype
!= 'default') && (!isset($tagnew->tagtype
) ||
($tagnew->tagtype
!= '1'))) {
64 tag_type_set($tag->id
, 'default');
66 } elseif (($tag->tagtype
!= 'official') && ($tagnew->tagtype
== '1')) {
67 tag_type_set($tag->id
, 'official');
71 if (!has_capability('moodle/tag:manage', $systemcontext) && !has_capability('moodle/tag:edit', $systemcontext)) {
73 unset($tagnew->rawname
);
75 } else { // They might be trying to change the rawname, make sure it's a change that doesn't affect name
76 $tagnew->name
= array_shift(tag_normalize($tagnew->rawname
, TAG_CASE_LOWER
));
78 if ($tag->name
!= $tagnew->name
) { // The name has changed, let's make sure it's not another existing tag
79 if (tag_get_id($tagnew->name
)) { // Something exists already, so flag an error
80 $errorstring = s($tagnew->rawname
).': '.get_string('namesalreadybeeingused', 'tag');
85 if (empty($errorstring)) { // All is OK, let's save it
87 $tagnew->timemodified
= time();
89 if (has_capability('moodle/tag:manage', $systemcontext)) {
91 if(!tag_rename($tag->id
, $tagnew->rawname
)) {
92 error('Error updating tag record');
96 //updated related tags
97 tag_set('tag', $tagnew->id
, explode(',', trim($tagnew->relatedtags
)));
98 //print_object($tagnew); die();
100 redirect($CFG->wwwroot
.'/tag/index.php?tag='.rawurlencode($tag->name
)); // must use $tag here, as the name isn't in the edit form
106 $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
107 $navlinks[] = array('name' => $tagname, 'link' => '', 'type' => '');
109 $navigation = build_navigation($navlinks);
110 print_header_simple(get_string('tag', 'tag') . ' - '. $tagname, '', $navigation);
112 print_heading($tagname, '', 2);
114 if (!empty($errorstring)) {
115 notify($errorstring);
123 <script type
="text/javascript">
126 var myServer
= "./tag_autocomplete.php";
127 var myDataSource
= new YAHOO
.widget
.DS_XHR(myServer
, ["\n", "\t"]);
128 myDataSource
.responseType
= YAHOO
.widget
.DS_XHR
.TYPE_FLAT
;
129 myDataSource
.maxCacheEntries
= 60;
130 myDataSource
.queryMatchSubset
= true;
132 var myAutoComp
= new YAHOO
.widget
.AutoComplete("id_relatedtags","relatedtags-autocomplete", myDataSource
);
133 myAutoComp
.delimChar
= ",";
134 myAutoComp
.maxResultsDisplayed
= 20;
135 myAutoComp
.minQueryLength
= 2;
136 myAutoComp
.allowBrowserAutocomplete
= false;
137 myAutoComp
.formatResult
= function(aResultItem
, sQuery
) {
138 return aResultItem
[1];