3 * Action for adding an end of cluster page
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 // first get the preceeding page
12 $pageid = required_param('pageid', PARAM_INT
);
16 // the new page is not the first page (end of cluster always comes after an existing page)
17 if (!$page = get_record("lesson_pages", "id", $pageid)) {
18 error("Error: Could not find page");
21 // could put code in here to check if the user really can insert an end of cluster
23 $newpage = new stdClass
;
24 $newpage->lessonid
= $lesson->id
;
25 $newpage->prevpageid
= $pageid;
26 $newpage->nextpageid
= $page->nextpageid
;
27 $newpage->qtype
= LESSON_ENDOFCLUSTER
;
28 $newpage->timecreated
= $timenow;
29 $newpage->title
= get_string("endofclustertitle", "lesson");
30 $newpage->contents
= get_string("endofclustertitle", "lesson");
31 if (!$newpageid = insert_record("lesson_pages", $newpage)) {
32 error("Insert page: end of cluster page not inserted");
34 // update the linked list...
35 if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) {
36 error("Add end of cluster: unable to update link");
38 if ($page->nextpageid
) {
39 // the new page is not the last page
40 if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid
)) {
41 error("Insert end of cluster: unable to update previous link");
44 // ..and the single "answer"
45 $newanswer = new stdClass
;
46 $newanswer->lessonid
= $lesson->id
;
47 $newanswer->pageid
= $newpageid;
48 $newanswer->timecreated
= $timenow;
49 $newanswer->jumpto
= LESSON_NEXTPAGE
;
50 if(!$newanswerid = insert_record("lesson_answers", $newanswer)) {
51 error("Add end of cluster: answer record not inserted");
53 lesson_set_message(get_string('addedendofcluster', 'lesson'), 'notifysuccess');
54 redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id");