From f232aa55876e68cc1cdfdabedf2e887ea3e35106 Mon Sep 17 00:00:00 2001 From: Vadimon Date: Tue, 26 Jan 2010 03:31:10 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=B0=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- course/category.php | 4 +++ course/deletecategory.php | 51 +++++++++++++++++++++++++++++++++++++++++++++ lang/en_utf8/moodle.php | 4 +++ 3 files changed, 59 insertions(+), 0 deletions(-) create mode 100644 course/deletecategory.php diff --git a/course/category.php b/course/category.php index d84d211..6802e08 100644 --- a/course/category.php +++ b/course/category.php @@ -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 ''; } diff --git a/course/deletecategory.php b/course/deletecategory.php new file mode 100644 index 0000000..27f23d4 --- /dev/null +++ b/course/deletecategory.php @@ -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); + +?> diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index ca3ac99..1ae46f6 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -393,9 +393,13 @@ $string['deleteallcannotundo'] = 'Delete all - cannot be undone'; $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 ?'; -- 1.6.5.1.1367.gcd48