First checkin of tag system from GSOC student Luiz Cruz
[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
8require_login();
9
10if( empty($CFG->usetags)) {
11 error(get_string('tagsaredisabled', 'tag'));
12}
13
14$tagid = required_param('id', PARAM_INT); // user id
15$tag = tag_by_id($tagid);
16$tagname = /*ucwords*/($tag->name);
17
18//Editing a tag requires moodle/tag:edittags capability
19$systemcontext = get_context_instance(CONTEXT_SYSTEM);
20require_capability('moodle/tag:edittags', $systemcontext);
21
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) );
24
25$tagform = new tag_edit_form();
26$tagform->set_data($tag);
27
28// if new data has been sent, update the tag record
29if ($tagnew = $tagform->get_data()) {
30
31 $tagnew->timemodified = time();
32
33 if (!update_record('tag', $tagnew)) {
34 error('Error updating tag record');
35 }
36
37 //updated related tags
38 update_item_tags('tag', $tagnew->id, $tagnew->relatedtags);
39
40 redirect($CFG->wwwroot.'/tag/index.php?id='.$tagnew->id);
41}
42
43
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' => '');
47
48$navigation = build_navigation($navlinks);
49print_header_simple(get_string('tag', 'tag') . ' - '. $tagname, '', $navigation);
50
51print_heading($tagname, '', 2);
52
53$tagform->display();
54
55
56?>
57
58<!-- Dependencies -->
59<script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/yahoo-dom-event/yahoo-dom-event.js"></script>
60
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>
63
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>
66
67<!-- Source file -->
68<script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/autocomplete/autocomplete-min.js"></script>
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
87
88print_footer();
89
90?>