3 require_once('../config.php');
4 require_once('lib.php');
5 require_once($CFG->dirroot
.'/lib/weblib.php');
9 if( empty($CFG->usetags
)) {
10 error(get_string('tagsaredisabled', 'tag'));
13 //managing tags requires moodle/tag:manage capability
14 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
15 require_capability('moodle/tag:manage', $systemcontext);
17 $tagschecked = optional_param('tagschecked', array());
18 $newnames = optional_param('newname', array());
19 $tagtypes = optional_param('tagtypes', array());
20 $action = optional_param('action', '', PARAM_ALPHA
);
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' => '');
26 $navigation = build_navigation($navlinks);
27 print_header_simple(get_string('managetags', 'tag'), '', $navigation);
29 $notice = tag_name_from_string(implode($tagschecked, ', '));
30 $notice = str_replace(',', ', ', $notice);
36 $notice .= ' -- ' . get_string('deleted','tag');
38 tag_delete(implode($tagschecked, ','));
44 $notice .= ' -- ' . get_string('reset','tag');
46 tag_flag_reset(implode($tagschecked, ','));
51 foreach ($tagschecked as $tag_id){
54 $tag = tag_by_id($tag_id);
56 $tag -> tagtype
= $tagtypes[$tag_id];
57 if (update_record('tag', $tag)) {
58 $notice .= ' -- ' . get_string('typechanged','tag');
65 $normalized_new_names_csv = tag_normalize( str_replace(',,','',implode($newnames, ',')) );
67 //tag names entered might already exist
68 $existing_tags = tags_id( $normalized_new_names_csv );
70 //notice to warn that names already exist
72 foreach ($existing_tags as $name => $tag){
73 $err_notice .= $name . ', ';
75 if(!empty($err_notice)){
76 $err_notice .= '-- ' . get_string('namesalreadybeeingused','tag');
80 //update tag names with the names passed in $newnames
81 $tags_names_changed = array();
82 foreach ($tagschecked as $tag_id){
83 $tags_names_changed[$tag_id] = str_replace(',','',$newnames[$tag_id]) ;
86 $tags_names_updated = tag_update_name($tags_names_changed);
88 //notice to inform what tags had their names effectively updated
89 $notice = implode($tags_names_updated, ', ');
91 $notice .= ' -- ' . get_string('updated','tag');
99 notify($err_notice, 'red');
100 notify($notice , 'green');
102 print_tag_management_list();