diff --git a/course/category.php b/course/category.php index 45da9e9647d..07a0d3d9ba6 100644 --- a/course/category.php +++ b/course/category.php @@ -18,6 +18,7 @@ $rename = optional_param('rename', '', PARAM_NOTAGS); $resort = optional_param('resort', 0, PARAM_BOOL); $categorytheme= optional_param('categorytheme', false, PARAM_CLEAN); + $addsubcategory=optional_param('addsubcategory', '', PARAM_NOTAGS); if (!$site = get_site()) { error("Site isn't defined!"); @@ -51,6 +52,18 @@ } + if (has_capability('moodle/category:create', $context)) { + if (!empty($addsubcategory) and confirm_sesskey()) { + $subcategory = new stdClass; + $subcategory->name = $addsubcategory; + $subcategory->sortorder = 999; + $subcategory->parent = $id; + if (!insert_record('course_categories', $subcategory )) { + notify( "Could not insert the new subcategory '$addsubcategory' " ); + } + } + } + if (has_capability('moodle/category:update', $context)) { /// Rename the category if requested if (!empty($rename) and confirm_sesskey()) { @@ -250,6 +263,21 @@ } } +/// print option to add a subcategory + if (has_capability('moodle/category:create', $context)) { + $straddsubcategory = get_string('addsubcategory'); + echo '