$PAGE->set_context($coursecontext);
    $PAGE->set_url($navurl);
    $PAGE->set_pagelayout('admin');
    $PAGE->set_title(get_string($report, 'local_linkchecker_robot'));
    $sqlfilter = ' AND c.id = ' . $courseid;
} else {
    // If no course then this is an admin only report.
    require_capability('moodle/site:config', context_system::instance());
    admin_externalpage_setup('local_linkchecker_robot_' . $report);
}
echo $OUTPUT->header();
require 'tabs.php';
echo $tabs;
if ($retryid) {
    $robot = new \local_linkchecker_robot\robot\crawler();
    $robot->reset_for_recrawl($retryid);
}
if ($report == 'broken') {
    $sql = " FROM {linkchecker_url}  b\n       LEFT JOIN {linkchecker_edge} l ON l.b = b.id\n       LEFT JOIN {linkchecker_url}  a ON l.a = a.id\n       LEFT JOIN {course} c ON c.id = a.courseid\n           WHERE b.httpcode != ? {$sqlfilter}";
    $opts = array('200');
    $data = $DB->get_records_sql("SELECT concat(b.id, '-', l.id, '-', a.id) AS id,\n                                          b.url target,\n                                          b.httpcode,\n                                          b.httpmsg,\n                                          b.lastcrawled,\n                                          b.id AS toid,\n                                          l.id linkid,\n                                          l.text,\n                                          a.url,\n                                          a.title,\n                                          a.redirect,\n                                          a.courseid,\n                                          c.shortname {$sql}\n                                 ORDER BY httpcode DESC,\n                                          c.shortname ASC", $opts, $start, $perpage);
    $count = $DB->get_field_sql("SELECT count(*) AS count" . $sql, $opts);
    $mdlw = strlen($CFG->wwwroot);
    $table = new html_table();
    $table->head = array('', get_string('lastcrawledtime', 'local_linkchecker_robot'), get_string('response', 'local_linkchecker_robot'), get_string('broken', 'local_linkchecker_robot'), get_string('frompage', 'local_linkchecker_robot'));
    if (!$courseid) {
        array_push($table->head, get_string('course', 'local_linkchecker_robot'));
    }
    $table->data = array();
    foreach ($data as $row) {
        $text = trim($row->text);