# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: moodle/course/category.php --- moodle/course/category.php Base (1.119.2.13) +++ moodle/course/category.php Locally Modified (Based On 1.119.2.13) @@ -225,6 +225,10 @@ $options = array('parent' => $category->id); print_single_button($CFG->wwwroot.'/course/editcategory.php', $options, get_string('addsubcategory'), 'get'); + // Print button to delete this category + $options = array('id' => $category->id); + print_single_button($CFG->wwwroot.'/course/deletecategory.php', $options, get_string('deletecategorythis'), 'get'); + echo ''; } Index: moodle/course/deletecategory.php --- moodle/course/deletecategory.php No Base Revision +++ moodle/course/deletecategory.php Locally New @@ -0,0 +1,51 @@ +parent) { + print_error('deletecategoryerrorfirstlevel'); +} +if (!record_exists('course_categories', 'id', $category->parent)) { + error("Unknown parent category $category->parent"); +} +require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $category->id)); +require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $category->parent)); + +$childcat = get_child_categories($category->id); +if (!empty($childcat)){ + print_error('deletecategoryerrornonempty'); +} +$courses = get_courses($category->id); +if (!empty($courses)){ + print_error('deletecategoryerrornonempty'); +} +$containsquestions = question_context_has_any_questions(get_context_instance(CONTEXT_COURSECAT, $category->id)); +if ($containsquestions) { + require_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSECAT, $category->id)); + require_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSECAT, $category->id)); + + $deletequestions = optional_param('deletequestions', 0, PARAM_BOOL); + if (!$deletequestions) { + print_header(); + $optionsyes = array('id' => $category->id, 'deletequestions' => 'yes'); + notice_yesno (get_string('deletecategorycheckhasquestions'), $CFG->wwwroot.'/course/deletecategory.php', 'javascript:history.go(-1);', $optionsyes); + print_footer(); + exit; + } +} +category_delete_full($category, false); +redirect('category.php?id='.$category->parent); + +?> Index: moodle/lang/en_utf8/moodle.php --- moodle/lang/en_utf8/moodle.php Base (1.141.2.75) +++ moodle/lang/en_utf8/moodle.php Locally Modified (Based On 1.141.2.75) @@ -392,9 +392,13 @@ $string['deleteallcomments'] = 'Delete all comments'; $string['deleteallratings'] = 'Delete all ratings'; $string['deletecategory'] = 'Delete category: $a'; +$string['deletecategorythis'] = 'Delete this category'; $string['deletecategorycheck'] = 'Are you absolutely sure you want to completely delete this category \'$a\'?
This will move all courses into the parent category if there is one, or into Miscellaneous.'; $string['deletecategorycheck2'] = 'If you delete this category, you need to choose what to do with the courses and subcategories it contains.'; $string['deletecategoryempty'] = 'This category is empty.'; +$string['deletecategoryerrorfirstlevel'] = 'Only global administrator can delete first level categories'; +$string['deletecategoryerrornonempty'] = 'Cannot delete categoriy which contains courses or sub-categories'; +$string['deletecategorycheckhasquestions'] = 'This category contains questions. If you delete category, theese questions will be deleted too. Do you wish to continue?'; $string['deletecheck'] = 'Delete $a ?'; $string['deletecheckfiles'] = 'Are you absolutely sure you want to delete these files?'; $string['deletecheckfull'] = 'Are you absolutely sure you want to completely delete $a ?';