Fixing assignment submission visualization for wood.
[moodle.git] / tag / manage.php
CommitLineData
c933a060 1<?php // $Id$
2
3require_once('../config.php');
4require_once('lib.php');
5require_once($CFG->dirroot.'/lib/weblib.php');
6
7require_login();
8
9if( empty($CFG->usetags)) {
10 error(get_string('tagsaredisabled', 'tag'));
11}
12
4f81c51d 13//managing tags requires moodle/tag:manage capability
c933a060 14$systemcontext = get_context_instance(CONTEXT_SYSTEM);
4f81c51d 15require_capability('moodle/tag:manage', $systemcontext);
c933a060 16
17$tagschecked = optional_param('tagschecked', array());
3a597ace 18$newnames = optional_param('newname', array());
79081e87 19$tagtypes = optional_param('tagtypes', array());
c933a060 20$action = optional_param('action', '', PARAM_ALPHA);
21
22$navlinks = array();
23$navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
24$navlinks[] = array('name' => get_string('managetags', 'tag'), 'link' => '', 'type' => '');
25
26$navigation = build_navigation($navlinks);
27print_header_simple(get_string('managetags', 'tag'), '', $navigation);
28
3a597ace 29$notice = tag_name_from_string(implode($tagschecked, ', '));
30$notice = str_replace(',', ', ', $notice);
31
2d7e3f9b 32$err_notice = '';
33
c933a060 34switch($action) {
3a597ace 35
c933a060 36 case 'delete':
3a597ace 37
c933a060 38 $notice .= ' -- ' . get_string('deleted','tag');
3a597ace 39
c933a060 40 tag_delete(implode($tagschecked, ','));
3a597ace 41
c933a060 42 break;
c933a060 43
3a597ace 44 case 'reset':
45
c933a060 46 $notice .= ' -- ' . get_string('reset','tag');
c933a060 47
48 tag_flag_reset(implode($tagschecked, ','));
3a597ace 49
50 break;
79081e87 51 case 'changetype':
3a597ace 52
79081e87 53 foreach ($tagschecked as $tag_id){
54
55 // update tag type;
56 $tag = tag_by_id($tag_id);
57
58 $tag -> tagtype = $tagtypes[$tag_id];
59 if (update_record('tag', $tag)) {
60 $notice .= ' -- ' . get_string('typechanged','tag');
61 }
62 }
63
64 break;
3a597ace 65 case 'changename':
66
67 $normalized_new_names_csv = tag_normalize( str_replace(',,','',implode($newnames, ',')) );
79081e87 68
3a597ace 69 //tag names entered might already exist
70 $existing_tags = tags_id( $normalized_new_names_csv );
71
72 //notice to warn that names already exist
3a597ace 73 foreach ($existing_tags as $name => $tag){
74 $err_notice .= $name . ', ';
75 }
76 if(!empty($err_notice)){
77 $err_notice .= '-- ' . get_string('namesalreadybeeingused','tag');
78 }
79
80
81 //update tag names with the names passed in $newnames
82 $tags_names_changed = array();
83 foreach ($tagschecked as $tag_id){
84 $tags_names_changed[$tag_id] = str_replace(',','',$newnames[$tag_id]) ;
85 }
86
87 $tags_names_updated = tag_update_name($tags_names_changed);
88
89 //notice to inform what tags had their names effectively updated
90 $notice = implode($tags_names_updated, ', ');
91 if(!empty($notice)){
92 $notice .= ' -- ' . get_string('updated','tag');
93 }
94
c933a060 95 break;
96}
97
98echo '<br/>';
99
2d7e3f9b 100if ($err_notice) {
101 notify($err_notice, 'red');
102}
103if ($notice) {
104 notify($notice , 'green');
105}
3a597ace 106
c933a060 107print_tag_management_list();
108
e3ff328b 109
c933a060 110echo '<br/>';
111
112print_footer();
113
114?>