get_record("lesson_pages", array("prevpageid" => 0, "lessonid" => $lesson->id))) { print_error('cannotfindpagerecord', 'lesson'); } } else { if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { print_error('cannotfindpagerecord', 'lesson'); } } $newpage = new stdClass; $newpage->lessonid = $lesson->id; $newpage->prevpageid = $pageid; if ($pageid != 0) { $newpage->nextpageid = $page->nextpageid; } else { $newpage->nextpageid = $page->id; } $newpage->qtype = LESSON_CLUSTER; $newpage->timecreated = $timenow; $newpage->title = get_string("clustertitle", "lesson"); $newpage->contents = get_string("clustertitle", "lesson"); if (!$newpageid = $DB->insert_record("lesson_pages", $newpage)) { print_error('cannotinsertpage', 'lesson'); } // update the linked list... if ($pageid != 0) { if (!$DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid))) { print_error('cannotupdatelink', 'lesson'); } } if ($pageid == 0) { $page->nextpageid = $page->id; } if ($page->nextpageid) { // the new page is not the last page if (!$DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid))) { print_error('cannotupdatelink', 'lesson'); } } // ..and the single "answer" $newanswer = new stdClass; $newanswer->lessonid = $lesson->id; $newanswer->pageid = $newpageid; $newanswer->timecreated = $timenow; $newanswer->jumpto = LESSON_CLUSTERJUMP; if(!$newanswerid = $DB->insert_record("lesson_answers", $newanswer)) { print_error('cannotinsertanswer', 'lesson'); } lesson_set_message(get_string('addedcluster', 'lesson'), 'notifysuccess'); redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id"); ?>