mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
271fea974f
(all the module was using them, please change your editor settings to 4 spaces)
67 lines
2.6 KiB
PHP
67 lines
2.6 KiB
PHP
<?php
|
|
|
|
/************** add end of branch ************************************/
|
|
|
|
if (!isteacher($course->id)) {
|
|
error("Only teachers can look at this page");
|
|
}
|
|
|
|
confirm_sesskey();
|
|
|
|
// first get the preceeding page
|
|
$pageid = required_param('pageid', PARAM_INT);
|
|
|
|
$timenow = time();
|
|
|
|
// the new page is not the first page (end of branch always comes after an existing page)
|
|
if (!$page = get_record("lesson_pages", "id", $pageid)) {
|
|
error("Add end of branch: page record not found");
|
|
}
|
|
// chain back up to find the (nearest branch table)
|
|
$btpageid = $pageid;
|
|
if (!$btpage = get_record("lesson_pages", "id", $btpageid)) {
|
|
error("Add end of branch: btpage record not found");
|
|
}
|
|
while (($btpage->qtype != LESSON_BRANCHTABLE) AND ($btpage->prevpageid > 0)) {
|
|
$btpageid = $btpage->prevpageid;
|
|
if (!$btpage = get_record("lesson_pages", "id", $btpageid)) {
|
|
error("Add end of branch: btpage record not found");
|
|
}
|
|
}
|
|
if ($btpage->qtype == LESSON_BRANCHTABLE) {
|
|
$newpage = new stdClass;
|
|
$newpage->lessonid = $lesson->id;
|
|
$newpage->prevpageid = $pageid;
|
|
$newpage->nextpageid = $page->nextpageid;
|
|
$newpage->qtype = LESSON_ENDOFBRANCH;
|
|
$newpage->timecreated = $timenow;
|
|
$newpage->title = get_string("endofbranch", "lesson");
|
|
$newpage->contents = get_string("endofbranch", "lesson");
|
|
if (!$newpageid = insert_record("lesson_pages", $newpage)) {
|
|
error("Insert page: new page not inserted");
|
|
}
|
|
// update the linked list...
|
|
if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) {
|
|
error("Add end of branch: unable to update link");
|
|
}
|
|
if ($page->nextpageid) {
|
|
// the new page is not the last page
|
|
if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) {
|
|
error("Insert page: unable to update previous link");
|
|
}
|
|
}
|
|
// ..and the single "answer"
|
|
$newanswer = new stdClass;
|
|
$newanswer->lessonid = $lesson->id;
|
|
$newanswer->pageid = $newpageid;
|
|
$newanswer->timecreated = $timenow;
|
|
$newanswer->jumpto = $btpageid;
|
|
if(!$newanswerid = insert_record("lesson_answers", $newanswer)) {
|
|
error("Add end of branch: answer record not inserted");
|
|
}
|
|
redirect("view.php?id=$cm->id", get_string('addedanendofbranch', 'lesson'));
|
|
} else {
|
|
notice(get_string("nobranchtablefound", "lesson"), "view.php?id=$cm->id");
|
|
}
|
|
?>
|