[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 18 /** 19 * @package core_tag 20 * @category tag 21 * @copyright 2007 Luiz Cruz <[email protected]> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once('../config.php'); 26 require_once ('lib.php'); 27 require_once ('edit_form.php'); 28 29 $tag_id = optional_param('id', 0, PARAM_INT); 30 $tag_name = optional_param('tag', '', PARAM_TAG); 31 32 require_login(); 33 34 if (empty($CFG->usetags)) { 35 print_error('tagsaredisabled', 'tag'); 36 } 37 38 //Editing a tag requires moodle/tag:edit capability 39 $systemcontext = context_system::instance(); 40 require_capability('moodle/tag:edit', $systemcontext); 41 42 if ($tag_name) { 43 $tag = tag_get('name', $tag_name, '*'); 44 } else if ($tag_id) { 45 $tag = tag_get('id', $tag_id, '*'); 46 } 47 48 if (empty($tag)) { 49 redirect($CFG->wwwroot.'/tag/search.php'); 50 } 51 52 $PAGE->set_url('/tag/index.php', array('id' => $tag->id)); 53 $PAGE->set_subpage($tag->id); 54 $PAGE->set_context($systemcontext); 55 $PAGE->set_blocks_editing_capability('moodle/tag:editblocks'); 56 $PAGE->set_pagelayout('base'); 57 58 $tagname = tag_display_name($tag); 59 60 // set the relatedtags field of the $tag object that will be passed to the form 61 $tag->relatedtags = tag_get_related_tags_csv(tag_get_related_tags($tag->id, TAG_RELATED_MANUAL), TAG_RETURN_TEXT); 62 63 $options = new stdClass(); 64 $options->smiley = false; 65 $options->filter = false; 66 67 // convert and remove any XSS 68 $tag->description = format_text($tag->description, $tag->descriptionformat, $options); 69 $tag->descriptionformat = FORMAT_HTML; 70 71 $errorstring = ''; 72 73 $editoroptions = array( 74 'maxfiles' => EDITOR_UNLIMITED_FILES, 75 'maxbytes' => $CFG->maxbytes, 76 'trusttext' => false, 77 'context' => $systemcontext, 78 'subdirs' => file_area_contains_subdirs($systemcontext, 'tag', 'description', $tag->id), 79 ); 80 $tag = file_prepare_standard_editor($tag, 'description', $editoroptions, $systemcontext, 'tag', 'description', $tag->id); 81 82 $tagform = new tag_edit_form(null, compact('editoroptions')); 83 if ( $tag->tagtype == 'official' ) { 84 $tag->tagtype = '1'; 85 } else { 86 $tag->tagtype = '0'; 87 } 88 89 $tagform->set_data($tag); 90 91 // If new data has been sent, update the tag record 92 if ($tagnew = $tagform->get_data()) { 93 94 if (has_capability('moodle/tag:manage', $systemcontext)) { 95 if (($tag->tagtype != 'default') && (!isset($tagnew->tagtype) || ($tagnew->tagtype != '1'))) { 96 tag_type_set($tag->id, 'default'); 97 98 } elseif (($tag->tagtype != 'official') && ($tagnew->tagtype == '1')) { 99 tag_type_set($tag->id, 'official'); 100 } 101 } 102 103 if (!has_capability('moodle/tag:manage', $systemcontext)) { 104 unset($tagnew->name); 105 unset($tagnew->rawname); 106 107 } else { // They might be trying to change the rawname, make sure it's a change that doesn't affect name 108 $norm = tag_normalize($tagnew->rawname, TAG_CASE_LOWER); 109 $tagnew->name = array_shift($norm); 110 111 if ($tag->name != $tagnew->name) { // The name has changed, let's make sure it's not another existing tag 112 if (tag_get_id($tagnew->name)) { // Something exists already, so flag an error 113 $errorstring = s($tagnew->rawname).': '.get_string('namesalreadybeeingused', 'tag'); 114 } 115 } 116 } 117 118 if (empty($errorstring)) { // All is OK, let's save it 119 120 $tagnew = file_postupdate_standard_editor($tagnew, 'description', $editoroptions, $systemcontext, 'tag', 'description', $tag->id); 121 122 if ($tag->description != $tagnew->description) { 123 tag_description_set($tag_id, $tagnew->description, $tagnew->descriptionformat); 124 } 125 126 $tagnew->timemodified = time(); 127 128 if (has_capability('moodle/tag:manage', $systemcontext)) { 129 // Check if we need to rename the tag. 130 if (isset($tagnew->name) && ($tag->name != $tagnew->name)) { 131 // Rename the tag. 132 if (!tag_rename($tag->id, $tagnew->rawname)) { 133 print_error('errorupdatingrecord', 'tag'); 134 } 135 } 136 } 137 138 //updated related tags 139 tag_set('tag', $tagnew->id, explode(',', trim($tagnew->relatedtags)), 'core', $systemcontext->id); 140 //print_object($tagnew); die(); 141 142 redirect($CFG->wwwroot.'/tag/index.php?tag='.rawurlencode($tag->name)); // must use $tag here, as the name isn't in the edit form 143 } 144 } 145 146 $PAGE->navbar->add(get_string('tags', 'tag'), new moodle_url('/tag/search.php')); 147 $PAGE->navbar->add($tagname); 148 $PAGE->navbar->add(get_string('edit')); 149 $PAGE->set_title(get_string('tag', 'tag') . ' - '. $tagname); 150 $PAGE->set_heading($COURSE->fullname); 151 echo $OUTPUT->header(); 152 echo $OUTPUT->heading($tagname, 2); 153 154 if (!empty($errorstring)) { 155 echo $OUTPUT->notification($errorstring); 156 } 157 158 $tagform->display(); 159 160 $PAGE->requires->js('/tag/tag.js'); 161 $PAGE->requires->js_function_call('init_tag_autocomplete', null, true); 162 163 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |