if ($lessons[$ij]['id'] == $lessonPO) {
        echo '<option selected="true" value="' . $lessons[$ij]['id'] . '">' . $lessons[$ij]['lessonname'] . '</option>';
        $selected_lesson_index = $ij;
    } else {
        echo '<option value="' . $lessons[$ij]['id'] . '">' . $lessons[$ij]['lessonname'] . '</option>';
    }
}
echo '</select>';
if (is_editable_by_me($USER->id, $lessonPO)) {
    echo ' <a onclick="return confirm(\'' . get_string('removeconfirm', 'mootyper') . $lessons[$selected_lesson_index]['lessonname'] . '\')" href="erem.php?id=' . $course->id . '&l=' . $lessons[$selected_lesson_index]['id'] . '">' . get_string('removeall', 'mootyper') . '\'' . $lessons[$selected_lesson_index]['lessonname'] . '\'</a>';
}
echo '</form><br>';
echo '<table style="border: solid;"><tr><td>' . get_string('ename', 'mootyper') . '</td><td>' . get_string('etext', 'mootyper') . '</td><td></td></tr>';
$exercises = get_typerexercisesfull($lessonPO);
foreach ($exercises as $ex) {
    $strToCut = $ex['texttotype'];
    $strToCut = str_replace('\\n', '<br>', $strToCut);
    if (strlen($strToCut) > 65) {
        $strToCut = substr($strToCut, 0, 65) . '...';
    }
    //$jWebDir = $CFG->wwwroot . '/course/view.php?id='.$_POST['rpCourseId'];
    $jlink = '<a href="erem.php?id=' . $course->id . '&r=' . $ex['id'] . '">' . get_string('eremove', 'mootyper') . '</a>';
    $jlink2 = '<a href="eedit.php?id=' . $course->id . '&ex=' . $ex['id'] . '">' . get_string('eeditlabel', 'mootyper') . '</a>';
    echo '<tr style="border-top: solid;"><td>' . $ex['exercisename'] . '</td><td>' . $strToCut . '</td>';
    if (is_editable_by_me($USER->id, $lessonPO)) {
        echo '<td>' . $jlink2 . ' | ' . $jlink . '</td>';
    }
    echo '</tr>';
}
echo '</table>';
echo $OUTPUT->footer();
$PAGE->set_heading(get_string('eheading', 'mootyper'));
//$PAGE->set_context($context);
// other things you may want to set - remove if not needed
$PAGE->set_cacheable(false);
//$PAGE->set_focuscontrol('tb1');
//$PAGE->add_body_class('mootyper-'.$somevar);
// Output starts here
echo $OUTPUT->header();
// action="?id='.$id.'&ins=true"
$lessonsG = get_typerlessons();
if (has_capability('mod/mootyper:editall', context_course::instance($course->id))) {
    $lessons = $lessonsG;
} else {
    $lessons = array();
    foreach ($lessonsG as $lsnG) {
        if (is_editable_by_me($USER->id, $lsnG['id'])) {
            $lessons[] = $lsnG;
        }
    }
}
echo '<form method="POST">';
echo get_string('fnewexercise', 'mootyper') . '&nbsp;';
echo '<select onchange="this.form.submit()" name="lesson">';
echo '<option value="-1">' . get_string('fnewlesson', 'mootyper') . '</option>';
for ($ij = 0; $ij < count($lessons); $ij++) {
    if ($lessons[$ij]['id'] == $lessonPO) {
        echo '<option selected="true" value="' . $lessons[$ij]['id'] . '">' . $lessons[$ij]['lessonname'] . '</option>';
    } else {
        echo '<option value="' . $lessons[$ij]['id'] . '">' . $lessons[$ij]['lessonname'] . '</option>';
    }
}