]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10604:
authorthepurpleblob <thepurpleblob>
Wed, 25 Jul 2007 14:02:27 +0000 (14:02 +0000)
committerthepurpleblob <thepurpleblob>
Wed, 25 Jul 2007 14:02:27 +0000 (14:02 +0000)
Add ability to add sub categories directly from category screens.

Merged from STABLE_18

course/category.php

index 45da9e9647d89a66b24d8637d89a0059a3ea2011..07a0d3d9ba694285bba4e1f6fbc4fa87965b48b9 100644 (file)
@@ -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!");
     }
 
 
+    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()) {
         }
     }
 
+/// print option to add a subcategory
+    if (has_capability('moodle/category:create', $context)) {
+        $straddsubcategory = get_string('addsubcategory');
+        echo '<div class="addcategory">';
+        echo '<form id="addform" action="category.php" method="post">';
+        echo '<fieldset class="invisiblefieldset">';
+        echo '<input type="text" size="30" alt="'.$straddsubcategory.'" name="addsubcategory" />';
+        echo '<input type="submit" value="'.$straddsubcategory.'" />';
+        echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+        echo '<input type="hidden" name="id" value="'.$id.'" />';
+        // echo '<input type="hidden" name="categoryedit" value="'.$categoryedit.'" />';
+        echo '</fieldset>';
+        echo '</form>';
+        echo '</div>';
+    }
 
 /// Print out all the courses
     unset($course);    // To avoid unwanted language effects later