MDL-4384, description for course categories

This commit is contained in:
toyomoyo
2007-08-15 08:28:40 +00:00
parent 7d7029f57d
commit ca5d523bef
3 changed files with 61 additions and 37 deletions
+16 -17
View 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!");
@@ -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 '</div>';
/// 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 '<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
+37
View File
@@ -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'));
}
}
?>
+8 -20
View 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);
@@ -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 '<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>';
}
}
?>