gamekind){
case 'cross';
game_OnExportHTML_cross( $game, $context, $html, $destdir);
break;
case 'hangman':
game_OnExportHTML_hangman( $game, $context, $html, $destdir);
break;
case 'snakes':
game_OnExportHTML_snakes( $game, $html, $destdir, $context);
break;
case 'millionaire':
game_OnExportHTML_millionaire( $game, $context, $html, $destdir);
break;
}
remove_dir( $destdir);
}
function game_OnExportHTML_cross( $game, $context, $html, $destdir){
global $CFG, $DB;
if( $html->filename == ''){
$html->filename = 'cross';
}
$filename = $html->filename . '.htm';
require( "cross/play.php");
$attempt = game_getattempt( $game, $crossrec, true);
if( $crossrec == false){
game_cross_new( $game, $attempt->id, $crossm);
$attempt = game_getattempt( $game, $crossrec);
}
$ret = game_export_printheader( $html->title);
echo "$ret
";
ob_start();
game_cross_play( 0, $game, $attempt, $crossrec, '', true, false, false, false, $html->checkbutton, true, $html->printbutton, false, $context);
$output_string = ob_get_contents();
ob_end_clean();
$course = $DB->get_record( 'course', array( 'id' => $game->course));
$filename = $html->filename . '.htm';
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $output_string);
$filename = game_OnExportHTML_cross_repair_questions( $game, $context, $filename, $destdir);
game_send_stored_file( $filename);
}
function game_OnExportHTML_cross_repair_questions( $game, $context, $filename, $destdir)
{
global $CFG, $DB;
$file_handle = fopen( $destdir.'/'.$filename, "rb");
$found = false;
$files = array();
$contextcourse = false;
$linesbefore = array();
$linesafter = array();
while (!feof($file_handle) ) {
$line = fgets( $file_handle);
if( $found)
{
if( strpos( $line, 'new Array'))
{
$linesafter[] = $line;
break;
}
$array .= $line;
continue;
}
if( strpos( $line, 'Clue = new Array') === false)
{
$linesbefore[] = $line;
continue;
}
$array = $line;
$found = true;
}
while (!feof($file_handle) ) {
$linesafter[] = fgets( $file_handle);
}
fclose($file_handle);
$search = $CFG->wwwroot.'/pluginfile.php';
$pos = 0;
$search = '"'.$CFG->wwwroot.'/pluginfile.php/'.$context->id.'/mod_game/';
$len = strlen( $search);
$start = 0;
$filescopied = false;
for(;;)
{
$pos1 = strpos( $array, $search, $start);
if( $pos1 == false)
break;
$pos2 = strpos( $array, '\"', $pos1+$len);
if( $pos2 == false)
break;
//Have to copy the files
if( $contextcourse === false)
{
mkdir( $destdir.'/images');
if (!$contextcourse = get_context_instance(CONTEXT_COURSE, $game->course)) {
print_error('nocontext');
}
$fs = get_file_storage();
}
$inputs = explode( '/', substr( $array, $pos1+$len, $pos2-$pos1-$len));
$filearea = $inputs[ 0];
$id = $inputs[ 1];
$fileimage = urldecode( $inputs[ 2]);
$component = 'question';
$params = array( 'component' => $component, 'filearea' => $filearea,
'itemid' => $id, 'filename' => $fileimage, 'contextid' => $context, 'contextid' => $contextcourse->id);
$rec = $DB->get_record( 'files', $params);
if( $rec == false)
{
print_r( $params);
break;
}
if (!$file = $fs->get_file_by_hash($rec->pathnamehash) or $file->is_directory())
continue;
$posext = strrpos( $fileimage, '.');
$filenoext = substr( $fileimage, $posext);
$ext = substr( $fileimage, $posext+1);
for($i=0;;$i++)
{
$newfile = $filenoext.$i;
$newfile = md5( $newfile).'.'.$ext;
if( !array_search( $newfile, $files))
break;
}
$file->copy_content_to( $destdir.'/images/'.$newfile);
$filescopied = true;
$array = substr( $array, 0, $pos1+1).'images/'.$newfile.substr( $array, $pos2);
}
if( $filescopied == false)
return $destdir.'/'.$filename;
$linesbefore[] = $array;
foreach( $linesafter as $line)
$linesbefore [] = $line;
file_put_contents( $destdir.'/'.$filename, $linesbefore);
$pos = strrpos( $filename, '.');
if( $pos === false)
$filezip = $filename.'.zip';
else
$filezip = substr( $filename, 0, $pos).'.zip';
$filezip = game_create_zip( $destdir, $game->course, $filezip);
return $filezip;
}
function game_export_printheader( $title, $showbody=true)
{
$ret = ''."\n";
$ret .= ''."\n";
$ret .= "