prevpageid AND !$thispage->nextpageid) { //This is the only page, no repair needed } elseif (!$thispage->prevpageid) { // this is the first page... if (!$page = get_record("lesson_pages", "id", $thispage->nextpageid)) { error("Delete: next page not found"); } if (!set_field("lesson_pages", "prevpageid", 0, "id", $page->id)) { error("Delete: unable to set prevpage link"); } } elseif (!$thispage->nextpageid) { // this is the last page... if (!$page = get_record("lesson_pages", "id", $thispage->prevpageid)) { error("Delete: prev page not found"); } if (!set_field("lesson_pages", "nextpageid", 0, "id", $page->id)) { error("Delete: unable to set nextpage link"); } } else { // page is in the middle... if (!$prevpage = get_record("lesson_pages", "id", $thispage->prevpageid)) { error("Delete: prev page not found"); } if (!$nextpage = get_record("lesson_pages", "id", $thispage->nextpageid)) { error("Delete: next page not found"); } if (!set_field("lesson_pages", "nextpageid", $nextpage->id, "id", $prevpage->id)) { error("Delete: unable to set next link"); } if (!set_field("lesson_pages", "prevpageid", $prevpage->id, "id", $nextpage->id)) { error("Delete: unable to set prev link"); } } lesson_set_message(get_string('deletedpage', 'lesson').': '.format_string($thispage->title, true), 'notifysuccess'); redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id"); ?>