echo "\n" . '<td' . $title . ' class="' . $class . '">' . $c . '</td>';
    }
    $padding_p = $max['M'] - $course['possible']['summary']['M'];
    for ($i = 0; $i < $padding_p; $i++) {
        echo "\n" . '<td class="notenrolled">&nbsp;</td>';
    }
    // DISTINCTION
    echo "\n" . '<td class="divider">&nbsp;</td>';
    foreach ($course['possible']['detail']['D'] as $c) {
        $class = 'partial nobox';
        $title = '';
        $desc = get_description($CFG->prefix, $course['course']->id, 'D' . $c);
        if ($desc) {
            $title = ' title="' . $desc . '"';
        }
        if (outcome_achieved($CFG->prefix, $course['course']->id, $student->id, 'D' . $c)) {
            $class = 'achieved';
        }
        //		if (quiz_outcome_achieved($CFG->prefix, $course['course']->id, $student->id, 'D'.$c)) $class = 'achieved';
        //echo "\n".'<td class="'.$class.'">'.$c.'</td>';
        echo "\n" . '<td' . $title . ' class="' . $class . '">' . $c . '</td>';
    }
    $padding_p = $max['D'] - $course['possible']['summary']['D'];
    for ($i = 0; $i < $padding_p; $i++) {
        echo "\n" . '<td class="notenrolled">&nbsp;</td>';
    }
    echo "\n" . '</tr>';
}
if ($points_total > 0) {
    echo '<tr><td class="right"><em>' . get_string('pointstotal', 'block_progress') . '</em></td><td class="total right"><strong>' . $points_total . '</strong></td></tr>';
}
function display_grid($prefix, $courseid, $students, $criteria)
{
    //print_r($criteria);
    $ok = array();
    if (count($criteria['P'])) {
        $ok['P'] = true;
    }
    if (count($criteria['M'])) {
        $ok['M'] = true;
    }
    if (count($criteria['D'])) {
        $ok['D'] = true;
    }
    //print_r($ok);
    $padding = array('P' => 0, 'M' => 0, 'D' => 0);
    $count['P'] = count($criteria['P']);
    $count['M'] = count($criteria['M']);
    $count['D'] = count($criteria['D']);
    if ($count['D'] < 6) {
        $padding['D'] = 6 - $count['D'];
        $count['D'] = 6;
    }
    $data = '<table id="grades" border="1">' . "\n";
    if (array_key_exists('P', $ok) && array_key_exists('M', $ok)) {
        $data .= '<tr><th colspan="3">&nbsp;</th>';
        if ($ok['P']) {
            $data .= '<th class="divider">&nbsp;</th><th class="left small" colspan="' . $count['P'] . '">' . get_string('pass', 'block_progress') . '</th>';
        }
        if ($ok['M']) {
            $data .= '<th class="divider">&nbsp;</th><th class="left small" colspan="' . $count['M'] . '">' . get_string('merit', 'block_progress') . '</th>';
        }
        if ($ok['D']) {
            $data .= '<th class="divider">&nbsp;</th><th class="left small" colspan="' . $count['D'] . '">' . get_string('distinction', 'block_progress') . '</th>';
        }
        $data .= '</tr>' . "\n";
    }
    $data .= '<tr><th colspan="3">&nbsp;</th>';
    foreach ($criteria as $l => $crit) {
        if (array_key_exists($l, $ok)) {
            $data .= '<th class="divider">&nbsp;</th>';
            foreach ($crit as $a => $c) {
                $data .= '<th class="centre small">' . $c . '</th>';
            }
        }
    }
    $data .= '<th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th></tr>';
    foreach ($students as $student) {
        $data .= '<tr><td>' . strtoupper($student->lastname) . '</td><td>' . ucfirst(strtolower($student->firstname)) . '</td></td><td>&nbsp;</td>';
        foreach ($criteria as $letter => $crit) {
            if (array_key_exists($letter, $ok)) {
                $data .= '<td class="divider">&nbsp;</td>';
                foreach ($crit as $a => $c) {
                    $class = 'partial hide';
                    $title = '';
                    $desc = get_description($prefix, $courseid, $letter . $c);
                    if ($desc) {
                        $title = ' title="' . $desc . '"';
                    }
                    if (outcome_achieved($prefix, $courseid, $student->id, $letter . $c)) {
                        $class = 'achieved';
                    }
                    $data .= '<td' . $title . ' class="' . $class . '">' . $letter . $c . '</td>';
                }
            }
        }
        $data .= '</tr>';
    }
    $data .= '</table>' . "\n";
    return $data;
}