From 09eb215121eba818f6c9c918f7bcdb0c36ff213b Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 10 Jun 2010 18:25:06 +0000 Subject: [PATCH] MDL-22729 Course sections can be re-edited again By the way, the current style of creating course_sections is ugly. We should probably have something like make_sure_that_at_least_default_section_exists($courseid, $sectionid=null) and not to insert it into database at many places as we do now. --- course/editsection.php | 15 ++++++--------- course/editsection_form.php | 5 +++-- course/lib.php | 5 +++-- course/view.php | 1 + enrol/database/enrol.php | 1 + enrol/imsenterprise/enrol.php | 1 + enrol/ldap/enrol.php | 1 + index.php | 2 +- 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/course/editsection.php b/course/editsection.php index bde6b8994c6..37a2590c0b4 100644 --- a/course/editsection.php +++ b/course/editsection.php @@ -32,13 +32,8 @@ $id = required_param('id',PARAM_INT); // Week/topic ID $PAGE->set_url('/course/editsection.php', array('id'=>$id)); -if (! $section = $DB->get_record("course_sections", array("id"=>$id))) { - print_error("sectionnotexist"); -} - -if (! $course = $DB->get_record("course", array("id"=>$section->course))) { - print_error("invalidcourseid"); -} +$section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST); +$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST); require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); @@ -48,7 +43,7 @@ $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->m $section = file_prepare_standard_editor($section, 'summary', $editoroptions, $context, 'course_section', $section->id); $section->usedefaultname = (is_null($section->name)); $mform = new editsection_form(null, array('course'=>$course, 'editoroptions'=>$editoroptions)); -$mform->set_data($section); // set defaults +$mform->set_data($section); // set current value /// If data submitted, then process and store. if ($mform->is_cancelled()){ @@ -60,7 +55,9 @@ if ($mform->is_cancelled()){ } else { $section->name = null; } - $section->summary = file_save_draft_area_files($data->summary['itemid'], $context->id, 'course_section', $section->id, array('subdirs'=>true), $data->summary['text']); + $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course_section', $section->id); + $section->summary = $data->summary; + $section->summaryformat = $data->summaryformat; $DB->update_record('course_sections', $section); add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section"); redirect("view.php?id=$course->id"); diff --git a/course/editsection_form.php b/course/editsection_form.php index 5d036628a8f..3c39ff03421 100644 --- a/course/editsection_form.php +++ b/course/editsection_form.php @@ -22,8 +22,9 @@ class editsection_form extends moodleform { $mform->disabledIf('name','usedefaultname','checked'); /// Prepare course and the editor - - $mform->addElement('editor', 'summary', get_string('summary'), null, $this->_customdata['editoroptions']); + + $mform->addElement('editor', 'summary_editor', get_string('summary'), null, $this->_customdata['editoroptions']); + $mform->setType('summary_editor', PARAM_RAW); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); diff --git a/course/lib.php b/course/lib.php index 8ed00f612c0..7c8f5444e91 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2515,7 +2515,7 @@ function get_course_section($section, $courseid) { $cw->course = $courseid; $cw->section = $section; $cw->summary = ""; - $cw->summaryformat = FORMAT_MOODLE; + $cw->summaryformat = FORMAT_HTML; $cw->sequence = ""; $id = $DB->insert_record("course_sections", $cw); return $DB->get_record("course_sections", array("id"=>$id)); @@ -2563,7 +2563,7 @@ function add_mod_to_section($mod, $beforemod=NULL) { $section->course = $mod->course; $section->section = $mod->section; $section->summary = ""; - $section->summaryformat = FORMAT_MOODLE; + $section->summaryformat = FORMAT_HTML; $section->sequence = $mod->coursemodule; return $DB->insert_record("course_sections", $section); } @@ -3451,6 +3451,7 @@ function create_course($data) { $section = new object(); $section->course = $course->id; // Create a default section. $section->section = 0; + $section->summaryformat = FORMAT_HTML; $section->id = $DB->insert_record('course_sections', $section); fix_course_sortorder(); diff --git a/course/view.php b/course/view.php index 15b9554b4bd..6fe94fef6da 100644 --- a/course/view.php +++ b/course/view.php @@ -229,6 +229,7 @@ $section->course = $course->id; // Create a default section. $section->section = 0; $section->visible = 1; + $section->summaryformat = FORMAT_HTML; $section->id = $DB->insert_record('course_sections', $section); } if (! $sections = get_all_sections($course->id) ) { // Try again diff --git a/enrol/database/enrol.php b/enrol/database/enrol.php index 55f1099e3e4..594f82d44cc 100644 --- a/enrol/database/enrol.php +++ b/enrol/database/enrol.php @@ -608,6 +608,7 @@ function create_course ($course,$skip_fix_course_sortorder=0){ $section = new object(); $section->course = $newcourseid; // Create a default section. $section->section = 0; + $section->summaryformat = FORMAT_HTML; $section->id = $DB->insert_record("course_sections", $section); $course = $DB->get_record('course', array('id' => $newcourseid)); blocks_add_default_course_blocks($course); diff --git a/enrol/imsenterprise/enrol.php b/enrol/imsenterprise/enrol.php index 479be871a2a..316c77444b6 100644 --- a/enrol/imsenterprise/enrol.php +++ b/enrol/imsenterprise/enrol.php @@ -545,6 +545,7 @@ function process_group_tag($tagcontents){ $section = new object(); $section->course = $course->id; // Create a default section. $section->section = 0; + $section->summaryformat = FORMAT_HTML; $section->id = $DB->insert_record("course_sections", $section); add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)"); diff --git a/enrol/ldap/enrol.php b/enrol/ldap/enrol.php index a4fa75dbdf9..9f1827c39c0 100755 --- a/enrol/ldap/enrol.php +++ b/enrol/ldap/enrol.php @@ -597,6 +597,7 @@ function create_course ($course_ext,$skip_fix_course_sortorder=0){ $section = new object(); $section->course = $newcourseid; // Create a default section. $section->section = 0; + $section->summaryformat = FORMAT_HTML; $section->id = $DB->insert_record("course_sections", $section); $course = $DB->get_record('course', array('id' => $newcourseid)); blocks_add_default_course_blocks($course); diff --git a/index.php b/index.php index de079800518..1c60a4f39d0 100644 --- a/index.php +++ b/index.php @@ -98,7 +98,7 @@ $section->course = $SITE->id; $section->section = 1; $section->summary = ''; - $section->summaryformat = '0'; + $section->summaryformat = FORMAT_HTML; $section->sequence = ''; $section->visible = 1; $section->id = $DB->insert_record('course_sections', $section);