MDL-9628 Fixed sorting
[moodle-pu.git] / tag / edit.php
blob285310ab7b311feb152d9b6243b425b0da357055
1 <?php // $Id$
3 require_once('../config.php');
4 require_once('lib.php');
5 require_once('edit_form.php');
6 require_once($CFG->dirroot.'/lib/weblib.php');
8 require_login();
10 if( empty($CFG->usetags)) {
11 error(get_string('tagsaredisabled', 'tag'));
14 $tagid = required_param('id', PARAM_INT); // user id
15 $tag = tag_by_id($tagid);
16 $tagname = tag_display_name($tag);
18 //Editing a tag requires moodle/tag:edit capability
19 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
20 require_capability('moodle/tag:edit', $systemcontext);
22 // set the relatedtags field of the $tag object that will be passed to the form
23 $tag->relatedtags = tag_names_csv( get_item_tags('tag',$tagid) );
25 $tagform = new tag_edit_form();
26 $tagform->set_data($tag);
28 // if new data has been sent, update the tag record
29 if ($tagnew = $tagform->get_data()) {
31 $tagnew->timemodified = time();
33 if (!update_record('tag', $tagnew)) {
34 error('Error updating tag record');
37 //updated related tags
38 update_item_tags('tag', $tagnew->id, $tagnew->relatedtags);
40 redirect($CFG->wwwroot.'/tag/index.php?id='.$tagnew->id);
44 $navlinks = array();
45 $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
46 $navlinks[] = array('name' => $tagname, 'link' => '', 'type' => '');
48 $navigation = build_navigation($navlinks);
49 print_header_simple(get_string('tag', 'tag') . ' - '. $tagname, '', $navigation);
51 print_heading($tagname, '', 2);
53 $tagform->display();
58 <!-- Dependencies -->
59 <script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/yahoo-dom-event/yahoo-dom-event.js"></script>
61 <!-- OPTIONAL: Connection (required only if using XHR DataSource) -->
62 <script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/connection/connection-min.js"></script>
64 <!-- OPTIONAL: Animation (required only if enabling animation) -->
65 <script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/animation/animation-min.js"></script>
67 <!-- Source file -->
68 <script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/autocomplete/autocomplete-min.js"></script>
70 <script type="text/javascript">
72 // An XHR DataSource
73 var myServer = "./tag_autocomplete.php";
74 var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
75 myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
76 myDataSource.maxCacheEntries = 60;
77 myDataSource.queryMatchSubset = true;
79 var myAutoComp = new YAHOO.widget.AutoComplete("id_relatedtags","relatedtags-autocomplete", myDataSource);
80 myAutoComp.delimChar = ",";
81 myAutoComp.maxResultsDisplayed = 20;
82 myAutoComp.minQueryLength = 2;
83 myAutoComp.allowBrowserAutocomplete = false;
84 </script>
86 <?php
88 print_footer();