if (!$seplment->can_view_submission($userid)) {
    print_error('nopermission');
}
if ($action == 'loadallpages') {
    $draft = true;
    if (!has_capability('mod/sepl:grade', $context)) {
        $draft = false;
        $readonly = true;
        // A student always sees the readonly version.
        require_capability('mod/sepl:submit', $context);
    }
    // Whoever is viewing the readonly version should not use the drafts, but the actual annotations.
    if ($readonly) {
        $draft = false;
    }
    $pages = document_services::get_page_images_for_attempt($seplment, $userid, $attemptnumber, $readonly);
    $response = new stdClass();
    $response->pagecount = count($pages);
    $response->pages = array();
    $grade = $seplment->get_user_grade($userid, true);
    // The readonly files are stored in a different file area.
    $filearea = document_services::PAGE_IMAGE_FILEAREA;
    if ($readonly) {
        $filearea = document_services::PAGE_IMAGE_READONLY_FILEAREA;
    }
    foreach ($pages as $id => $pagefile) {
        $index = count($response->pages);
        $page = new stdClass();
        $comments = page_editor::get_comments($grade->id, $index, $draft);
        $page->url = moodle_url::make_pluginfile_url($context->id, 'seplfeedback_editpdf', $filearea, $grade->id, '/', $pagefile->get_filename())->out();
        $page->comments = $comments;