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
$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
--- /dev/null
+<?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
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
}
}
}
-
-/** 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>';
- }
-}
?>