/**
* Print a table data with all session activities 
* 
* @param string $session_id The session identifier
*/
function print_session_activities($session_id)
{
    // Import language strings
    $stractivity = get_string("activity", "jclic");
    $strsolved = get_string("solved", "jclic");
    $stractions = get_string("actions", "jclic");
    $strtime = get_string("time", "jclic");
    $strscore = get_string("score", "jclic");
    $stryes = get_string("yes");
    $strno = get_string("no");
    // Print activities for each session
    $activities = jclic_get_activities($session_id);
    if (sizeof($activities) > 0) {
        echo '<tr><td colspan="7"><div id="' . $session_id . '" style="display:none;visible:hidden">';
        echo '<table class="generaltable" align="center" border="0" cellpadding="5" cellspacing="1" width="80%"><tbody>';
        $subtable_align = array('left', 'center', 'center', 'center', 'center');
        jclic_print_row(array($stractivity, $strsolved, $stractions, $strtime, $strscore), $subtable_align, '', true);
        foreach ($activities as $activity) {
            $subtable_props = array('', 'style="background-color:' . ($activity->activity_solved ? '#DFFFDF' : '#FFDFDF') . '"', '', '', '');
            $act_percent = $activity->num_actions > 0 ? round($activity->score / $activity->num_actions * 100, 0) : 0;
            jclic_print_row(array($activity->activity_name, $activity->activity_solved ? $stryes : $strno, $activity->score . '/' . $activity->num_actions . ' (' . $act_percent . '%)', jclic_time2str($activity->total_time), $activity->qualification . '%'), $subtable_align, $subtable_props);
        }
        echo '</table></div></td></tr>';
    }
}
$stractions = get_string("actions", "jclic");
$strtime = get_string("time", "jclic");
$stryes = get_string("yes");
$strno = get_string("no");
print_header("{$course->shortname}: {$jclic->name}", "{$jclic->name}", "");
$sessions = jclic_get_sessions($jclic->id, $USER->id);
if (sizeof($sessions) > 0) {
    echo "<script language=\"JavaScript\" src=\"../prototype.js\" type=\"text/javascript\"></script>";
    echo '<table class="generaltable" align="center" border="0" cellpadding="5" cellspacing="1" width="95%"><tbody>';
    $general_align = array('center', 'center', 'center', 'center', 'center', 'center');
    // Print header
    jclic_print_row(array($strstarttime, $strscore, $strtotaltime, $strdone, $stractivitysolved, $strattempts), $general_align, '', true);
    // Print session data
    foreach ($sessions as $session) {
        $sessiontime = '<a href="#" onclick="Element.toggle(\'' . $session->session_id . '\')">' . date('d/m/Y H:i', strtotime($session->starttime)) . '</a>';
        $table_data = array($sessiontime, $session->score . '%', $session->totaltime, $session->done, $session->solved, $session->attempts . ($jclic->maxattempts > 0 ? '/' . $jclic->maxattempts : ''));
        jclic_print_row($table_data, $general_align);
        // Print activities for each session
        print_session_activities($session->session_id);
    }
    if (sizeof($sessions) > 1) {
        $sessions_summary = jclic_get_sessions_summary($jclic->id, $USER->id);
        jclic_print_row(array('<b>' . $strtotals . '</b>', '<b>' . $sessions_summary->score . '%</b>', '<b>' . $sessions_summary->totaltime . '</b>', '<b>' . $sessions_summary->done . '</b>', '<b>' . $sessions_summary->solved . '</b>', '<b>' . $sessions_summary->attempts . '</b>'), $general_align);
    }
    echo '</tbody></table><br>';
} else {
    echo '<br><center>' . $strmsgnosessions . '</center>';
}
?>
		
                }
            }
            $sessions_summary = jclic_get_sessions_summary($jclic->id, $student->userid);
            $starttime = array_key_exists('starttime', $sessions_summary) ? $sessions_summary->starttime : '0';
            if ($starttime > 0) {
                $starttime = date('d/m/Y H:i', strtotime($sessions_summary->starttime));
            } else {
                $starttime = '-';
            }
            if (!$showall || sizeof($sessions) <= 0) {
                $table_align = $general_align;
                $student_info = print_user_picture($student, $course->id, NULL, 0, true) . $student->firstname . ' ' . $student->lastname;
                jclic_print_row(array($student_info, !$showall ? $starttime : (sizeof($sessions) <= 0 ? '-' : '<b>' . $strtotals . '</b>'), '<b>' . $sessions_summary->done . '</b>', '<b>' . $sessions_summary->solved . '</b>', '<b>' . $sessions_summary->totaltime . '</b>', '<b>' . $sessions_summary->score . ' %</b>', '<b>' . $sessions_summary->attempts . ($jclic->maxattempts > 0 ? '/' . $jclic->maxattempts : '') . '</b>'), $table_align);
            } else {
                $table_align = array('center', 'center', 'center', 'center', 'center', 'center');
                jclic_print_row(array(!$showall ? $starttime : (sizeof($sessions) <= 0 ? '-' : '<b>' . $strtotals . '</b>'), '<b>' . $sessions_summary->done . '</b>', '<b>' . $sessions_summary->solved . '</b>', '<b>' . $sessions_summary->totaltime . '</b>', '<b>' . $sessions_summary->score . ' %</b>', '<b>' . $sessions_summary->attempts . ($jclic->maxattempts > 0 ? '/' . $jclic->maxattempts : '') . '</b>'), $table_align);
            }
        }
    }
    echo '</tbody></table><br>';
    $delid = optional_param('delete', PARAM_INT);
    if (isset($delid)) {
        jclic_delete_instance($delid);
    }
} else {
    $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https" : "http";
    echo "<script language=\"JavaScript\" src=\"{$CFG->jclic_jclicpluginjs}\" type=\"text/javascript\"></script>";
    echo '<br><A href="#" onclick="window.open(\'action/student_results.php?id=' . $id . '\',\'JClic\',\'navigation=0,toolbar=0,resizable=1,scrollbars=1,width=700,height=400\');" >' . $strshow_results . '</A>';
    $sessions = jclic_get_sessions($jclic->id, $USER->id);
    $attempts = sizeof($sessions);
    if ($jclic->maxattempts < 0 || $attempts < $jclic->maxattempts) {