]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-4384, description for course categories
authortoyomoyo <toyomoyo>
Wed, 15 Aug 2007 08:28:40 +0000 (08:28 +0000)
committertoyomoyo <toyomoyo>
Wed, 15 Aug 2007 08:28:40 +0000 (08:28 +0000)
course/category.php
course/category_add_form.php [new file with mode: 0755]
course/index.php

index 07a0d3d9ba694285bba4e1f6fbc4fa87965b48b9..cb7b53064fd504ad4593c4043c2ec92efa16920d 100644 (file)
@@ -5,6 +5,7 @@
 
     require_once("../config.php");
     require_once("lib.php");
+    require_once('category_add_form.php');
 
     $id           = required_param('id', PARAM_INT);          // Category id
     $page         = optional_param('page', 0, PARAM_INT);     // which page to show
@@ -18,7 +19,6 @@
     $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!");
         $creatorediting = false;
     }
 
-
+    $mform = new sub_category_add_form();
     if (has_capability('moodle/category:create', $context)) {
-        if (!empty($addsubcategory) and confirm_sesskey()) {
+        if ($form = $mform->get_data()) {
             $subcategory = new stdClass;
-            $subcategory->name = $addsubcategory;
+            $subcategory->name = $form->addcategory;
+            $subcategory->description = $form->description;
             $subcategory->sortorder = 999;
             $subcategory->parent = $id;
             if (!insert_record('course_categories', $subcategory )) {
     popup_form('category.php?id=', $displaylist, 'switchcategory', $category->id, '', '', '', false, 'self', $strcategories.':');
     echo '</div>';
 
+/// Print current category description
+    if ($category->description) {
+        print_box_start();
+        print_heading(get_string('description'));
+        echo $category->description;
+        print_box_end();
+    }
 
 /// Editing functions
 
     }
 
 /// 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>';
+    if (has_capability('moodle/category:create', $context)) {        
+        $cat->id = $id;
+        $mform->set_data($cat);        
+        $mform->display();
     }
 
 /// Print out all the courses
diff --git a/course/category_add_form.php b/course/category_add_form.php
new file mode 100755 (executable)
index 0000000..b9715f3
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+require_once ($CFG->dirroot.'/course/moodleform_mod.php');
+class category_add_form extends moodleform {
+
+    // form definition
+    function definition() {
+        $mform =& $this->_form;
+        $mform->addElement('header', 'general', get_string('addnewcategory')); // TODO: localize
+        $mform->addElement('text', 'addcategory', get_string('categoryname'), array('size'=>'30'));    
+        $mform->addRule('addcategory', get_string('required'), 'required', null);        
+        $mform->addElement('htmleditor', 'description', get_string('description'));
+        $mform->setType('description', PARAM_RAW);
+        $mform->setHelpButton('description', array('writing', 'richtext'), false, 'editorhelpbutton');
+
+        $this->add_action_buttons(false, get_string('submit'));
+    }
+}
+
+class sub_category_add_form extends moodleform {
+
+    // form definition
+    function definition() {
+        $mform =& $this->_form;
+        $mform->addElement('header', 'general', get_string('addsubcategory')); // TODO: localize
+        $mform->addElement('text', 'addcategory', get_string('categoryname'), array('size'=>'30'));    
+        $mform->addRule('addcategory', get_string('required'), 'required', null);        
+        $mform->addElement('htmleditor', 'description', get_string('description'));
+        $mform->setType('description', PARAM_RAW);
+        $mform->addElement('hidden', 'id');
+        $mform->setType('id', PARAM_INT);
+        $mform->setHelpButton('description', array('writing', 'richtext'), false, 'editorhelpbutton');
+        
+        $this->add_action_buttons(false, get_string('submit'));
+    }
+}
+?>
\ No newline at end of file
index 04af05d3fe1da9dd938783082fc5ee826618d5a8..5ab89eb36b7b72a8727ceacf5596a23d01868a0b 100644 (file)
@@ -4,6 +4,7 @@
 
     require_once("../config.php");
     require_once("lib.php");
+    require_once('category_add_form.php');
 
     $categoryedit = optional_param('categoryedit', -1,PARAM_BOOL);
     $delete   = optional_param('delete',0,PARAM_INT);
 
 
 /// If data for a new category was submitted, then add it
-    if ($form = data_submitted() and confirm_sesskey() and has_capability('moodle/category:create', $context)) {
+    $mform = new category_add_form();
+    if ($form = $mform->get_data() and has_capability('moodle/category:create', $context)) {
         if (!empty($form->addcategory)) {
             unset($newcategory);
             $newcategory->name = stripslashes_safe($form->addcategory);
+            $newcategory->description = $form->description;
             $newcategory->sortorder = 999;
             if (!insert_record('course_categories', $newcategory)) {
                 notify("Could not insert the new category '" . format_string($newcategory->name) . "'");
     fix_course_sortorder();
 
 /// Print form for creating new categories
-    print_category_create_form();
+    
+    if (has_capability('moodle/category:create', get_context_instance(CONTEXT_SYSTEM))) {
+        $mform->display();
+    }
 
 /// Print out the categories with all the knobs
 
@@ -421,22 +427,4 @@ function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $
         }
     }
 }
-
-/** prints the add new category text input field and form */
-function print_category_create_form() {
-    
-    $straddnewcategory = get_string('addnewcategory');
-    
-    if (has_capability('moodle/category:create', get_context_instance(CONTEXT_SYSTEM))) {
-        echo '<div class="addcategory">';
-        echo '<form id="addform" action="index.php" method="post">';
-        echo '<fieldset class="invisiblefieldset">';
-        echo '<input type="text" size="30" alt="'.$straddnewcategory.'" name="addcategory" />';
-        echo '<input type="submit" value="'.$straddnewcategory.'" />';
-        echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-        echo '</fieldset>';
-        echo '</form>';
-        echo '</div>';
-    }
-}
 ?>