From ca5d523bef0ebd022b86506a736a44d58f7e3fc3 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Wed, 15 Aug 2007 08:28:40 +0000 Subject: [PATCH] MDL-4384, description for course categories --- course/category.php | 33 ++++++++++++++++---------------- course/category_add_form.php | 37 ++++++++++++++++++++++++++++++++++++ course/index.php | 28 ++++++++------------------- 3 files changed, 61 insertions(+), 37 deletions(-) create mode 100755 course/category_add_form.php diff --git a/course/category.php b/course/category.php index 07a0d3d9ba..cb7b53064f 100644 --- a/course/category.php +++ b/course/category.php @@ -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!"); @@ -51,11 +51,12 @@ $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 )) { @@ -152,6 +153,13 @@ popup_form('category.php?id=', $displaylist, 'switchcategory', $category->id, '', '', '', false, 'self', $strcategories.':'); echo ''; +/// Print current category description + if ($category->description) { + print_box_start(); + print_heading(get_string('description')); + echo $category->description; + print_box_end(); + } /// Editing functions @@ -264,19 +272,10 @@ } /// print option to add a subcategory - if (has_capability('moodle/category:create', $context)) { - $straddsubcategory = get_string('addsubcategory'); - echo '
'; - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - // echo ''; - echo '
'; - echo '
'; - echo '
'; + 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 index 0000000000..b9715f3097 --- /dev/null +++ b/course/category_add_form.php @@ -0,0 +1,37 @@ +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 diff --git a/course/index.php b/course/index.php index 04af05d3fe..5ab89eb36b 100644 --- a/course/index.php +++ b/course/index.php @@ -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); @@ -44,10 +45,12 @@ /// 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) . "'"); @@ -284,7 +287,10 @@ 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 '
'; - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - } -} ?> -- 2.39.5