Browse Source

New: Print button on Cryptex Game

MOODLE_20_STABLE
Vasilis Daloukas 10 years ago
parent
commit
0eb760cdd1
  1. 47
      cryptex/play.php
  2. 34
      print.php
  3. 4
      version.php

47
cryptex/play.php

@ -127,7 +127,7 @@ function game_cryptex_check( $id, $game, $attempt, $cryptexrec, $q, $answer, $co
game_cryptex_play( $id, $game, $attempt, $cryptexrec, $crossm, true, $onlyshow, $showsolution, $context);
}
function game_cryptex_play( $id, $game, $attempt, $cryptexrec, $crossm, $updateattempt=false, $onlyshow=false, $showsolution=false, $context)
function game_cryptex_play( $id, $game, $attempt, $cryptexrec, $crossm, $updateattempt=false, $onlyshow=false, $showsolution=false, $context, $print=false, $showhtmlprintbutton=true)
{
global $DB;
@ -219,6 +219,11 @@ width: 240pt;
--></style>
<?php
$grade = round( 100 * $gradeattempt);
echo get_string( 'grade', 'game').' '.$grade.' %';
echo '<br>';
echo '<table border=0>';
echo '<tr><td>';
$cryptex->displaycryptex( $crossm->cols, $crossm->rows, $cryptexrec->letters, $mask, $showsolution, $textdir);
@ -239,7 +244,7 @@ width: 240pt;
style="font-weight: bold; text-transform:uppercase;" autocomplete="off"></div>
<table border="0" cellspacing="0" cellpadding="0" width="100%" style="margin-top:1em;"><tr>
<td align="right">
<td align="right">print
<button id="okbutton" type="submit" class="button" style="font-weight: bold;">OK</button> &nbsp;
<button id="cancelbutton" type="button" class="button" onclick="DeselectCurrentWord();">Cancel</button>
</td></tr></table>
@ -248,12 +253,37 @@ width: 240pt;
</tr>
</table>
<?php
if( $showhtmlprintbutton){
echo ' &nbsp;&nbsp;&nbsp;&nbsp;<button id="printbutton" type="button" onclick="OnPrint();" style="display: block;">'.get_string( 'print', 'game');
echo '</button>';
}
if( $showhtmlprintbutton){
?>
<script>
function PrintHtmlClick()
{
document.getElementById("printbutton").style.display = "none";
window.print();
document.getElementById("printbutton").style.display = "block";
}
function OnPrint()
{
<?php
$grade = round( 100 * $gradeattempt);
echo '<br>'.get_string( 'grade', 'game').' '.$grade.' %';
global $CFG;
$params = "id=$id&gameid=$game->id";
echo "window.open( \"{$CFG->wwwroot}/mod/game/print.php?$params\")";
?>
}
</script>
<?php
}
echo "<br><br>";
$i = 0;
$else = '';
$contextglossary = false;
@ -305,8 +335,15 @@ width: 240pt;
}
</script>
<?php
if( $print){
echo '<body onload="window.print()">';
}else{
echo '<body>';
}
}
function game_cryptex_onfinished( $id, $game, $attempt, $cryptexrec)
{
global $CFG, $DB;

34
print.php

@ -17,16 +17,17 @@
require_login( $game->course);
$context = get_context_instance(CONTEXT_MODULE, $id);
$context = game_get_context_module_instance( $id);
require_capability('mod/game:view', $context);
game_print( $game, $id, $context);
function game_print( $game, $update, $context){
if( $game->gamekind == 'cross'){
if( $game->gamekind == 'cross')
game_print_cross( $game, $update, $context);
}
else if( $game->gamekind == 'cryptex')
game_print_cryptex( $game, $update, $context);
}
function game_print_cross( $game, $update, $context)
@ -53,5 +54,32 @@
<?php
game_cross_play( $update, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution, $endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton,$showstudentguess, $context);
}
function game_print_cryptex( $game, $update, $context)
{
global $DB;
require( 'cross/cross_class.php');
require( 'cross/crossdb_class.php');
require( "cryptex/play.php");
$attempt = game_getattempt( $game, $crossrec);
$updateattempt = false;
$onlyshow = true;
$showsolution = false;
$showhtmlprintbutton = false;
$print = true;
$crossm = $DB->get_record_select( 'game_cross', "id=$attempt->id");
?>
<html dir="ltr" lang="el" xml:lang="el" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Print</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
game_cryptex_play( $update, $game, $attempt, $crossrec, $crossm, $updateattempt, $onlyshow, $showsolution, $context, $print, $showhtmlprintbutton);
}

4
version.php

@ -22,10 +22,10 @@ if( !isset( $plugin))
$useplugin = 2;
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2015071203; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2015071204; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2010112400; // Requires Moodle 2.0
$plugin->cron = 0; // Period for cron to check this module (secs)
$plugin->release = '3.30.12.3';
$plugin->release = '3.30.12.4';
if( $useplugin != 2)
$module = $plugin;

Loading…
Cancel
Save