require_capability('mod/book:edit', $context); $PAGE->set_url('/mod/book/edit.php', array('cmid' => $cmid, 'id' => $chapterid, 'pagenum' => $pagenum, 'subchapter' => $subchapter)); $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);
error('Incorrect chapter id'); } if ($chapter->bookid != $book->id) { //chapter id not in this book!!!! error('Chapter not part of this book!'); } } else { $chapter = null; } //check all variables unset($cmid); unset($chapterid); // ========================================================================= // security checks END // ========================================================================= $mform = new book_chapter_edit_form(null, $cm); if ($chapter) { $chapter->cmid = $cm->id; $mform->set_data($chapter); } else { $mform->set_data(array('cmid' => $cm->id, 'pagenum' => $pagenum + 1, 'subchapter' => $subchapter)); } /// 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(false)) {