$PAGE->set_pagelayout('admin'); //this is a bloody hack! if ($chapterid) { $chapter = $DB->get_record('book_chapters', array('id' => $chapterid, 'bookid' => $book->id), '*', MUST_EXIST); } else { $chapter = new stdClass(); $chapter->id = null; $chapter->subchapter = $subchapter; $chapter->pagenum = $pagenum + 1; } $chapter->cmid = $cm->id; $options = array('noclean' => true, 'subdirs' => true, 'maxfiles' => -1, 'maxbytes' => 0, 'context' => $context); $chapter = file_prepare_standard_editor($chapter, 'content', $options, $context, 'mod_book', 'chapter', $chapter->id); $mform = new book_chapter_edit_form(null, array('chapter' => $chapter, 'options' => $options)); /// If data submitted, then process and store. if ($mform->is_cancelled()) { if (empty($chapter->id)) { redirect("view.php?id={$cm->id}"); } else { redirect("view.php?id={$cm->id}&chapterid={$chapter->id}"); } } else { if ($data = $mform->get_data()) { if ($data->id) { // store the files $data = file_postupdate_standard_editor($data, 'content', $options, $context, 'mod_book', 'chapter', $data->id); $DB->update_record('book_chapters', $data); add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id=' . $cm->id, 'book ' . $book->id); add_to_log($course->id, 'book', 'update', 'view.php?id=' . $cm->id . '&chapterid=' . $data->id, $book->id, $cm->id); } else { /// adding new chapter