libdir/questionlib.php");
require_once("$CFG->dirroot/question/type/shortanswer/questiontype.php");
require_once("lib.php");
require_once("locallib.php");
require_once( "header.php");
require_once( "hangman/play.php");
require_once( "cross/play.php");
require_once( "cryptex/play.php");
require_once( "millionaire/play.php");
require_once( "sudoku/play.php");
require_once( "bookquiz/play.php");
if( !isteacher( $game->course, $USER->id)){
error( get_string( 'only_teachers', 'game'));
}
$currenttab = required_param('action', PARAM_TEXT);
include('tabs.php');
switch( $currenttab){
case 'showattempts':
echo get_string( 'group').': ';
game_showgroups( $game);
echo get_string('user').': ';
game_showusers($game);
echo '
';
game_showattempts($game);
print_footer();
die;
case 'delete':
if (has_capability('mod/game:deleteattempts', $context))
{
$attemptid = required_param('attemptid', PARAM_INT);
game_ondeleteattempt($game, $attemptid);
print_footer();
}
die;
case 'answers':
showanswers( $game, false);
print_footer();
die;
}
$attemptid = required_param('attemptid', PARAM_INT);
$update = required_param('update', PARAM_INT);
$attempt = get_record_select( 'game_attempts', "id=$attemptid");
$game = get_record_select( 'game', "id=$attempt->gameid");
$detail = get_record_select( 'game_'.$game->gamekind, "id=$attemptid");
$solution = ($currenttab == 'solution');
switch( $game->gamekind)
{
case 'cross':
game_cross_play( $update, $game, $attempt, $detail, '', true, $solution, false, false, false, false, true);
break;
case 'sudoku':
game_sudoku_play( $update, $game, $attempt, $detail, true, $solution);
break;
case 'hangman':
game_hangman_play( $update, $game, $attempt, $detail, true, $solution);
break;
case 'cryptex':
$crossm = get_record_select( 'game_cross', "id=$attemptid");
game_cryptex_play( $update, $game, $attempt, $detail, $crossm, false, true, $solution);
break;
}
function game_showattempts($game){
global $CFG, $USER;
$gamekind = $game->gamekind;
$update = get_coursemodule_from_instance( 'game', $game->id, $game->course)->id;
//Here are user attempts
$table = "game_attempts as ga, {$CFG->prefix}user u, {$CFG->prefix}game as g";
$select = "ga.userid=u.id AND ga.gameid={$game->id} AND g.id={$game->id}";
$fields = "ga.id, u.lastname, u.firstname, ga.attempts,".
"timestart, timefinish, timelastattempt, score, ga.lastip, ga.lastremotehost";
$userid = optional_param('userid',0,PARAM_INT);
if( $userid != 0)
$select .= ' AND ga.userid='.$userid;
$count = count_records_select( $table, $select, 'COUNT( *)');
$maxlines = 20;
$limitfrom = optional_param('limitfrom', 0, PARAM_INT);
$recslimitfrom = $recslimitnum = '';
if( $count > $maxlines){
$recslimitfrom = ( $limitfrom ? $limitfrom * $maxlines : '');
$recslimitnum = $maxlines;
for($i=0; $i*$maxlines < $count; $i++){
if( $i == $limitfrom){
echo ($i+1).' ';
}else
{
echo "wwwroot}/mod/game/preview.php?action=showattempts&update=$update&q={$game->id}&limitfrom=$i&\">".($i+1)."";
echo ' ';
}
}
echo "
";
}
if( ($recs = get_records_select( $table, $select, 'timelastattempt DESC,timestart DESC', $fields, $recslimitfrom, $recslimitnum)) != false){
echo '
'.get_string( 'delete').' | '.get_string('user').' | '; echo ''.get_string('lastip', 'game').' | '; echo ''.get_string('timestart', 'game').' | '; echo ''.get_string('timelastattempt', 'game').' | '; echo ''.get_string('timefinish', 'game').' | '; echo ''.get_string('score', 'game').' | '; echo ''.get_string('attempts', 'game').' | '; echo ''.get_string('preview', 'game').' | '; echo ''.get_string('showsolution', 'game').' | '; echo "