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 // need to use html_entity_decode because formslib does it for us later on.
36 $tag->relatedtags
= html_entity_decode(tag_get_related_tags_csv(tag_get_related_tags($tag->id
, TAG_RELATED_MANUAL
), TAG_RETURN_TEXT
));
38 if (can_use_html_editor()) {
39 $options = new object();
40 $options->smiley
= false;
41 $options->filter
= false;
43 // convert and remove any XSS
44 $tag->description
= format_text($tag->description
, $tag->descriptionformat
, $options);
45 $tag->descriptionformat
= FORMAT_HTML
;
50 $tagform = new tag_edit_form();
51 if ( $tag->tagtype
== 'official' ) {
56 $tagform->set_data($tag);
58 // If new data has been sent, update the tag record
59 if ($tagnew = $tagform->get_data()) {
61 tag_description_set($tag_id, stripslashes($tagnew->description
), $tagnew->descriptionformat
);
63 if (has_capability('moodle/tag:manage', $systemcontext)) {
64 if (($tag->tagtype
!= 'default') && (!isset($tagnew->tagtype
) ||
($tagnew->tagtype
!= '1'))) {
65 tag_type_set($tag->id
, 'default');
67 } elseif (($tag->tagtype
!= 'official') && ($tagnew->tagtype
== '1')) {
68 tag_type_set($tag->id
, 'official');
72 if (!has_capability('moodle/tag:manage', $systemcontext) && !has_capability('moodle/tag:edit', $systemcontext)) {
74 unset($tagnew->rawname
);
76 } else { // They might be trying to change the rawname, make sure it's a change that doesn't affect name
77 $tagnew->name
= array_shift(tag_normalize($tagnew->rawname
, TAG_CASE_LOWER
));
79 if ($tag->name
!= $tagnew->name
) { // The name has changed, let's make sure it's not another existing tag
80 if (tag_get_id($tagnew->name
)) { // Something exists already, so flag an error
81 $errorstring = s($tagnew->rawname
).': '.get_string('namesalreadybeeingused', 'tag');
86 if (empty($errorstring)) { // All is OK, let's save it
88 $tagnew->timemodified
= time();
90 if (has_capability('moodle/tag:manage', $systemcontext)) {
92 if(!tag_rename($tag->id
, $tagnew->rawname
)) {
93 error('Error updating tag record');
97 //updated related tags
98 tag_set('tag', $tagnew->id
, explode(',', trim($tagnew->relatedtags
)));
99 //print_object($tagnew); die();
101 redirect($CFG->wwwroot
.'/tag/index.php?tag='.rawurlencode($tag->name
)); // must use $tag here, as the name isn't in the edit form
107 $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
108 $navlinks[] = array('name' => $tagname, 'link' => '', 'type' => '');
110 $navigation = build_navigation($navlinks);
111 print_header_simple(get_string('tag', 'tag') . ' - '. $tagname, '', $navigation);
113 print_heading($tagname, '', 2);
115 if (!empty($errorstring)) {
116 notify($errorstring);
124 <script type
="text/javascript">
127 var myServer
= "./tag_autocomplete.php";
128 var myDataSource
= new YAHOO
.widget
.DS_XHR(myServer
, ["\n", "\t"]);
129 myDataSource
.responseType
= YAHOO
.widget
.DS_XHR
.TYPE_FLAT
;
130 myDataSource
.maxCacheEntries
= 60;
131 myDataSource
.queryMatchSubset
= true;
133 var myAutoComp
= new YAHOO
.widget
.AutoComplete("id_relatedtags","relatedtags-autocomplete", myDataSource
);
134 myAutoComp
.delimChar
= ",";
135 myAutoComp
.maxResultsDisplayed
= 20;
136 myAutoComp
.minQueryLength
= 2;
137 myAutoComp
.allowBrowserAutocomplete
= false;
138 myAutoComp
.formatResult
= function(aResultItem
, sQuery
) {
139 return aResultItem
[1];