global $CFG, $DB, $PAGE, $OUTPUT;
require_once $CFG->dirroot . '/mod/attendance/locallib.php';
require_once $CFG->dirroot . '/mod/attendance/tempedit_form.php';
$id = required_param('id', PARAM_INT);
$userid = required_param('userid', PARAM_INT);
$action = optional_param('action', null, PARAM_ALPHA);
$cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
$tempuser = $DB->get_record('attendance_tempusers', array('id' => $userid), '*', MUST_EXIST);
$att = new attendance($att, $cm, $course);
$params = array('userid' => $tempuser->id);
if ($action) {
    $params['action'] = $action;
}
$PAGE->set_url($att->url_tempedit($params));
require_login($course, true, $cm);
$att->perm->require_managetemp_capability();
$PAGE->set_title($course->shortname . ": " . $att->name . ' - ' . get_string('tempusersedit', 'attendance'));
$PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true);
$PAGE->navbar->add(get_string('tempusersedit', 'attendance'));
/** @var mod_attendance_renderer $output */
$output = $PAGE->get_renderer('mod_attendance');
if ($action == 'delete') {
    if (optional_param('confirm', false, PARAM_BOOL)) {
        require_sesskey();
        // Remove the user from the grades table, the attendance log and the tempusers table.
        $DB->delete_records('grade_grades', array('userid' => $tempuser->studentid));
        $DB->delete_records('attendance_log', array('studentid' => $tempuser->studentid));
        $DB->delete_records('attendance_tempusers', array('id' => $tempuser->id));
function print_tempusers($tempusers, attendance $att)
{
    echo '<p></p>';
    echo '<table border="1" bordercolor="#EEEEEE" style="background-color:#fff" cellpadding="2" align="center"' . 'width="80%" summary="' . get_string('temptable', 'attendance') . '"><tr>';
    echo '<th class="header">' . get_string('tusername', 'attendance') . '</th>';
    echo '<th class="header">' . get_string('tuseremail', 'attendance') . '</th>';
    echo '<th class="header">' . get_string('tcreated', 'attendance') . '</th>';
    echo '<th class="header">' . get_string('tactions', 'attendance') . '</th>';
    echo '</tr>';
    $even = false;
    // Used to colour rows.
    foreach ($tempusers as $tempuser) {
        if ($even) {
            echo '<tr style="background-color: #FCFCFC">';
        } else {
            echo '<tr>';
        }
        $even = !$even;
        echo '<td>' . format_string($tempuser->fullname) . '</td>';
        echo '<td>' . format_string($tempuser->email) . '</td>';
        echo '<td>' . userdate($tempuser->created, get_string('strftimedatetime')) . '</td>';
        $params = array('userid' => $tempuser->id);
        $editlink = html_writer::link($att->url_tempedit($params), get_string('edituser', 'attendance'));
        $deletelink = html_writer::link($att->url_tempdelete($params), get_string('deleteuser', 'attendance'));
        $mergelink = html_writer::link($att->url_tempmerge($params), get_string('mergeuser', 'attendance'));
        echo '<td>' . $editlink . ' | ' . $deletelink . ' | ' . $mergelink . '</td>';
        echo '</tr>';
    }
    echo '</table>';
}