$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 $data->bookid = $book->id; $data->hidden = 0; $data->timecreated = time(); $data->timemodified = time(); $data->importsrc = ''; $data->content = ''; // updated later
$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)) { if ($data->id) { if (!update_record('book_chapters', addslashes_recursive($data))) { error('Could not update your book'); } 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 $data->bookid = $book->id; $data->hidden = 0; $data->timecreated = time(); $data->timemodified = time(); $data->importsrc = ''; // make room for new page $sql = "UPDATE {$CFG->prefix}book_chapters\n SET pagenum = pagenum + 1\n WHERE bookid = {$book->id} AND pagenum >= {$data->pagenum}";