question MDL-19820 Replaced deprecated functions
[moodle.git] / course / editsection.php
CommitLineData
24f2b65a 1<?php // $Id$
97c270e9 2 // Edit the introduction of a section
578fdd0a 3
b0e3a925 4 require_once("../config.php");
5 require_once("lib.php");
644d506a 6 require_once($CFG->libdir.'/filelib.php');
7 require_once('editsection_form.php');
578fdd0a 8
644d506a 9 $id = required_param('id',PARAM_INT); // Week/topic ID
578fdd0a 10
579d45b4 11 if (! $section = $DB->get_record("course_sections", array("id"=>$id))) {
ba6018a9 12 print_error("sectionnotexist");
578fdd0a 13 }
14
579d45b4 15 if (! $course = $DB->get_record("course", array("id"=>$section->course))) {
ba6018a9 16 print_error("invalidcourseid");
578fdd0a 17 }
18
644d506a 19 require_login($course);
20 $context = get_context_instance(CONTEXT_COURSE, $course->id);
21 require_capability('moodle/course:update', $context);
2fdcf5e3 22
edc0c493 23 $draftitemid = file_get_submitted_draft_itemid('summary');
a19a06d0 24 $currenttext = file_prepare_draft_area($draftitemid, $context->id, 'course_section', $section->id, array('subdirs'=>true), $section->summary);
644d506a 25
26 $mform = new editsection_form(null, $course);
27 $data = array('id'=>$section->id, 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid'=>$draftitemid));
28 $mform->set_data($data); // set defaults
578fdd0a 29
30/// If data submitted, then process and store.
644d506a 31 if ($mform->is_cancelled()){
32 redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
578fdd0a 33
644d506a 34 } else if ($data = $mform->get_data()) {
578fdd0a 35
a08171c5 36 $text = file_save_draft_area_files($data->summary['itemid'], $context->id, 'course_section', $section->id, array('subdirs'=>true), $data->summary['text']);
644d506a 37 $DB->set_field("course_sections", "summary", $text, array("id"=>$section->id));
578fdd0a 38 add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
578fdd0a 39 redirect("view.php?id=$course->id");
578fdd0a 40 }
41
116ae3b2 42/// Inelegant hack for bug 3408
43 if ($course->format == 'site') {
44 $sectionname = get_string('site');
45 $stredit = get_string('edit', '', " $sectionname");
46 $strsummaryof = get_string('summaryof', '', " $sectionname");
47 } else {
dfd74b5a 48 $sectionname = get_section_name($course->format);
116ae3b2 49 $stredit = get_string('edit', '', " $sectionname $section->section");
644d506a 50 $strsummaryof = get_string('summaryof', '', " $sectionname $section->section");
116ae3b2 51 }
578fdd0a 52
3856ca56 53 $PAGE->set_title($stredit);
54 $PAGE->navbar->add($stredit);
55 $PAGE->set_focuscontrol('theform.summary');
56 echo $OUTPUT->header();
644d506a 57 print_heading_with_help($strsummaryof, 'summaries');
58 $mform->display();
d60c1124 59 echo $OUTPUT->footer();
578fdd0a 60
a19a06d0 61