diff --git a/attempt.php b/attempt.php
index bf31588..971c52d 100755
--- a/attempt.php
+++ b/attempt.php
@@ -1,274 +1,272 @@
-.
+
/**
* This page prints a particular attempt of game
*
* @author bdaloukas
* @version $Id: attempt.php,v 1.22 2012/07/25 23:07:43 bdaloukas Exp $
* @package game
- **/
- require_once( "../../config.php");
- require_once( "lib.php");
- require_once( "locallib.php");
+ **/
+require_once( "../../config.php");
+require_once( "lib.php");
+require_once( "locallib.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");
- require_once( "snakes/play.php");
- require_once( "hiddenpicture/play.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");
+require_once( "snakes/play.php");
+require_once( "hiddenpicture/play.php");
- $action = optional_param('action', "", PARAM_ALPHANUM); // action
-
- game_show_header( $id, $game, $course, $context);
- game_do_attempt( $id, $game, $action, $course, $context);
+$action = optional_param('action', "", PARAM_ALPHANUM); // Is the param action.
- function game_show_header( &$id, &$game, &$course, &$context)
- {
- global $DB, $USER, $PAGE, $OUTPUT;
+game_show_header( $id, $game, $course, $context);
+game_do_attempt( $id, $game, $action, $course, $context);
- $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
- $q = optional_param('q', 0, PARAM_INT); // game ID
+function game_show_header( &$id, &$game, &$course, &$context) {
+ global $DB, $USER, $PAGE, $OUTPUT;
- if ($id) {
- if (! $cm = get_coursemodule_from_id('game', $id)) {
- print_error('invalidcoursemodule');
- }
- if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
- print_error('coursemisconf');
- }
- if (! $game = $DB->get_record('game', array('id' => $cm->instance))) {
- print_error('invalidcoursemodule');
- }
- } else {
- if (! $game = $DB->get_record('game', array('id' => $q))) {
- print_error('invalidgameid', 'game');
- }
- if (! $course = $DB->get_record('course', array('id' => $game->course))) {
- print_error('invalidcourseid');
- }
- if (! $cm = get_coursemodule_from_instance('game', $game->id, $course->id)) {
- print_error('invalidcoursemodule');
- }
- }
+ $id = optional_param('id', 0, PARAM_INT); // It represents Course Module ID.
+ $q = optional_param('q', 0, PARAM_INT); // It represents game id.
- /// Check login and get context.
- require_login($course->id, false, $cm);
- $context = game_get_context_module_instance( $cm->id);
- require_capability('mod/game:view', $context);
+ if ($id) {
+ if (! $cm = get_coursemodule_from_id('game', $id)) {
+ print_error('invalidcoursemodule');
+ }
+ if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
+ print_error('coursemisconf');
+ }
+ if (! $game = $DB->get_record('game', array('id' => $cm->instance))) {
+ print_error('invalidcoursemodule');
+ }
+ } else {
+ if (! $game = $DB->get_record('game', array('id' => $q))) {
+ print_error('invalidgameid', 'game');
+ }
+ if (! $course = $DB->get_record('course', array('id' => $game->course))) {
+ print_error('invalidcourseid');
+ }
+ if (! $cm = get_coursemodule_from_instance('game', $game->id, $course->id)) {
+ print_error('invalidcoursemodule');
+ }
+ }
- /// Cache some other capabilites we use several times.
- $canattempt = has_capability('mod/game:attempt', $context);
- $canreviewmine = has_capability('mod/game:reviewmyattempts', $context);
+ // Check login and get context.
+ require_login($course->id, false, $cm);
+ $context = game_get_context_module_instance( $cm->id);
+ require_capability('mod/game:view', $context);
- /// Create an object to manage all the other (non-roles) access rules.
- $timenow = time();
- //$accessmanager = new game_access_manager(game::create($game->id, $USER->id), $timenow);
+ // Cache some other capabilites we use several times.
+ $canattempt = has_capability('mod/game:attempt', $context);
+ $canreviewmine = has_capability('mod/game:reviewmyattempts', $context);
- /// If no questions have been set up yet redirect to edit.php
- //if (!$game->questions && has_capability('mod/game:manage', $context)) {
- // redirect($CFG->wwwroot . '/mod/game/edit.php?cmid=' . $cm->id);
- //}
+ // Create an object to manage all the other (non-roles) access rules.
+ $timenow = time();
- /// Log this request.
- if( game_use_events())
- {
- require( 'classes/event/game_played.php');
- \mod_game\event\game_played::played($game, $context)->trigger();
- }else
- add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id);
+ // Log this request.
+ if ( game_use_events()) {
+ require( 'classes/event/game_played.php');
+ \mod_game\event\game_played::played($game, $context)->trigger();
+ } else {
+ add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id);
+ }
- /// Initialize $PAGE, compute blocks
- $PAGE->set_url('/mod/game/view.php', array('id' => $cm->id));
+ // Initialize $PAGE, compute blocks.
+ $PAGE->set_url('/mod/game/view.php', array('id' => $cm->id));
- $edit = optional_param('edit', -1, PARAM_BOOL);
- if ($edit != -1 && $PAGE->user_allowed_editing()) {
- $USER->editing = $edit;
- }
+ $edit = optional_param('edit', -1, PARAM_BOOL);
+ if ($edit != -1 && $PAGE->user_allowed_editing()) {
+ $USER->editing = $edit;
+ }
- // Note: MDL-19010 there will be further changes to printing header and blocks.
- // The code will be much nicer than this eventually.
- $title = $course->shortname . ': ' . format_string($game->name);
+ // Note: MDL-19010 there will be further changes to printing header and blocks.
+ // The code will be much nicer than this eventually.
+ $title = $course->shortname . ': ' . format_string($game->name);
- if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
- $buttons = '
';
+ $PAGE->set_button($buttons);
+ }
- $PAGE->set_title($title);
- $PAGE->set_heading($course->fullname);
+ $PAGE->set_title($title);
+ $PAGE->set_heading($course->fullname);
- echo $OUTPUT->header();
- }
+ echo $OUTPUT->header();
+}
- function game_do_attempt( $id, $game, $action, $course, $context)
- {
- global $OUTPUT;
+function game_do_attempt( $id, $game, $action, $course, $context) {
+ global $OUTPUT;
- $forcenew = optional_param('forcenew', false, PARAM_BOOL); // Teacher has requested new preview
- $endofgame = optional_param('endofgame', false, PARAM_BOOL);
- $pos = optional_param('pos', 0, PARAM_INT);
- $num = optional_param('num', 0, PARAM_INT);
- $q = optional_param('q', 0, PARAM_INT);
- $attemptid = optional_param('attemptid', 0, PARAM_INT);
- $g = optional_param('g', '', PARAM_RAW);
- $finishattempt = optional_param('finishattempt', '', PARAM_TEXT);
- $answer = optional_param('answer', '', PARAM_TEXT);
- $continue = false;
+ $forcenew = optional_param('forcenew', false, PARAM_BOOL); // Teacher has requested new preview.
+ $endofgame = optional_param('endofgame', false, PARAM_BOOL);
+ $pos = optional_param('pos', 0, PARAM_INT);
+ $num = optional_param('num', 0, PARAM_INT);
+ $q = optional_param('q', 0, PARAM_INT);
+ $attemptid = optional_param('attemptid', 0, PARAM_INT);
+ $g = optional_param('g', '', PARAM_RAW);
+ $finishattempt = optional_param('finishattempt', '', PARAM_TEXT);
+ $answer = optional_param('answer', '', PARAM_TEXT);
+ $continue = false;
-/// Print the main part of the page
- switch( $action)
- {
- case 'crosscheck':
- $attempt = game_getattempt( $game, $detail);
- $g = game_cross_unpackpuzzle( $g);
- game_cross_continue( $id, $game, $attempt, $detail, $g, $finishattempt, $context);
- break;
- case 'crossprint':
- $attempt = game_getattempt( $game, $detail);
- game_cross_play( $id, $game, $attempt, $detail, '', true, false, false, true, $context);
- break;
- case 'sudokucheck': //the student tries to answer a question
- $attempt = game_getattempt( $game, $detail);
- game_sudoku_check_questions( $id, $game, $attempt, $detail, $finishattempt, $course, $context);
+ // Print the main part of the page.
+ switch ( $action) {
+ case 'crosscheck':
+ $attempt = game_getattempt( $game, $detail);
+ $g = game_cross_unpackpuzzle( $g);
+ game_cross_continue( $id, $game, $attempt, $detail, $g, $finishattempt, $context);
+ break;
+ case 'crossprint':
+ $attempt = game_getattempt( $game, $detail);
+ game_cross_play( $id, $game, $attempt, $detail, '', true, false, false, true, $context);
+ break;
+ case 'sudokucheck': // The student tries to answer a question.
+ $attempt = game_getattempt( $game, $detail);
+ game_sudoku_check_questions( $id, $game, $attempt, $detail, $finishattempt, $course, $context);
$continue = true;
break;
- case 'sudokucheckg': //the student tries to guess a glossaryenry
- $attempt = game_getattempt( $game, $detail);
- $endofgame = array_key_exists( 'endofgame', $_GET);
- $continue = game_sudoku_check_glossaryentries( $id, $game, $attempt, $detail, $endofgame, $course);
+ case 'sudokucheckg': // The student tries to guess a glossaryenry.
+ $attempt = game_getattempt( $game, $detail);
+ $endofgame = array_key_exists( 'endofgame', $_GET);
+ $continue = game_sudoku_check_glossaryentries( $id, $game, $attempt, $detail, $endofgame, $course);
$continue = true;
break;
- case 'sudokucheckn': //the user tries to guess a number
- $attempt = game_getattempt( $game, $detail);
- game_sudoku_check_number( $id, $game, $attempt, $detail, $pos, $num, $context);
+ case 'sudokucheckn': // The user tries to guess a number.
+ $attempt = game_getattempt( $game, $detail);
+ game_sudoku_check_number( $id, $game, $attempt, $detail, $pos, $num, $context);
$continue = false;
break;
- case 'cryptexcheck': //the user tries to guess a question
- $attempt = game_getattempt( $game, $detail);
- game_cryptex_check( $id, $game, $attempt, $detail, $q, $answer, $finishattempt, $context);
+ case 'cryptexcheck': // The user tries to guess a question.
+ $attempt = game_getattempt( $game, $detail);
+ game_cryptex_check( $id, $game, $attempt, $detail, $q, $answer, $finishattempt, $context);
+ break;
+ case 'bookquizcheck': // The student tries to answer a question.
+ $attempt = game_getattempt( $game, $detail);
+ game_bookquiz_check_questions( $id, $game, $attempt, $detail, $context);
break;
- case 'bookquizcheck': //the student tries to answer a question
- $attempt = game_getattempt( $game, $detail);
- game_bookquiz_check_questions( $id, $game, $attempt, $detail, $context);
+ case 'snakescheck': // The student tries to answer a question.
+ $attempt = game_getattempt( $game, $detail);
+ game_snakes_check_questions( $id, $game, $attempt, $detail, $context);
break;
- case 'snakescheck': //the student tries to answer a question
- $attempt = game_getattempt( $game, $detail);
- game_snakes_check_questions( $id, $game, $attempt, $detail, $context);
+ case 'snakescheckg': // The student tries to answer a question from glossary.
+ $attempt = game_getattempt( $game, $detail);
+ game_snakes_check_glossary( $id, $game, $attempt, $detail, $context);
break;
- case 'snakescheckg': //the student tries to answer a question from glossary
- $attempt = game_getattempt( $game, $detail);
- game_snakes_check_glossary( $id, $game, $attempt, $detail, $context);
- break;
- case 'hiddenpicturecheck': //the student tries to answer a question
- $attempt = game_getattempt( $game, $detail);
- $continue = game_hiddenpicture_check_questions( $id, $game, $attempt, $detail, $finishattempt, $context);
+ case 'hiddenpicturecheck': // The student tries to answer a question.
+ $attempt = game_getattempt( $game, $detail);
+ $continue = game_hiddenpicture_check_questions( $id, $game, $attempt, $detail, $finishattempt, $context);
break;
- case 'hiddenpicturecheckg': //the student tries to guess a glossaryenry
- $attempt = game_getattempt( $game, $detail);
- game_hiddenpicture_check_mainquestion( $id, $game, $attempt, $detail, $endofgame, $context);
+ case 'hiddenpicturecheckg': // The student tries to guess a glossaryentry.
+ $attempt = game_getattempt( $game, $detail);
+ game_hiddenpicture_check_mainquestion( $id, $game, $attempt, $detail, $endofgame, $context);
break;
default:
$continue = true;
- break;
- }
- if( $continue){
- game_create( $game, $id, $forcenew, $course, $context);
- }
-/// Finish the page
- echo $OUTPUT->footer();
+ break;
+ }
+ if ($continue) {
+ game_create( $game, $id, $forcenew, $course, $context);
+ }
+ // Finish the page.
+ echo $OUTPUT->footer();
+}
+
+function game_create( $game, $id, $forcenew, $course, $context) {
+ global $USER, $CFG, $DB;
+
+ $attempt = game_getattempt( $game, $detail);
+ $chapterid = optional_param('chapterid', 0, PARAM_INT);
+ $newletter = optional_param('newletter', '', PARAM_ALPHA);
+ $action2 = optional_param('action2', '', PARAM_ALPHA);
+
+ switch ( $game->gamekind) {
+ case 'cross':
+ game_cross_continue( $id, $game, $attempt, $detail, '', $forcenew, $context);
+ break;
+ case 'hangman':
+ game_hangman_continue( $id, $game, $attempt, $detail, $newletter, $action2, $context);
+ break;
+ case 'millionaire':
+ game_millionaire_continue( $id, $game, $attempt, $detail, $context);
+ break;
+ case 'bookquiz':
+ game_bookquiz_continue( $id, $game, $attempt, $detail, $chapterid, $context);
+ break;
+ case 'sudoku':
+ game_sudoku_continue( $id, $game, $attempt, $detail, '', $context);
+ break;
+ case 'cryptex':
+ game_cryptex_continue( $id, $game, $attempt, $detail, $forcenew, $context);
+ break;
+ case 'snakes':
+ game_snakes_continue( $id, $game, $attempt, $detail, $context);
+ break;
+ case 'hiddenpicture':
+ game_hiddenpicture_continue( $id, $game, $attempt, $detail, $context);
+ break;
+ default:
+ print_error( "Game {$game->gamekind} not found");
+ break;
}
+}
+function game_cross_unpackpuzzle( $g) {
+ $ret = "";
+ $len = game_strlen( $g);
+ while ($len) {
+ for ($i = 0; $i < $len; $i++) {
+ $c = game_substr( $g, $i, 1);
+ if ( $c >= '1' and $c <= '9') {
+ if ( $i > 0) {
+ // Found escape character.
+ if (game_substr( $g, $i - 1, 1) == '/') {
+ $g = game_substr( $g, 0, $i - 1).game_substr( $g, $i);
+ $i--;
+ $len--;
+ continue;
+ }
+ }
+ break;
+ }
+ }
- function game_create( $game, $id, $forcenew, $course, $context)
- {
- global $USER, $CFG, $DB;
-
- $attempt = game_getattempt( $game, $detail);
- $chapterid = optional_param('chapterid', 0, PARAM_INT);
- $newletter = optional_param('newletter', '', PARAM_ALPHA);
- $action2 = optional_param('action2', '', PARAM_ALPHA);
+ if ($i < $len) {
+ // Found the start of a number.
+ for ($j = $i + 1; $j < $len; $j++) {
+ $c = game_substr( $g, $j, 1);
+ if ($c < '0' or $c > '9') {
+ break;
+ }
+ }
+ $count = game_substr( $g, $i, $j - $i);
+ $ret .= game_substr( $g, 0, $i) . str_repeat( '_', $count);
- switch( $game->gamekind)
- {
- case 'cross':
- game_cross_continue( $id, $game, $attempt, $detail, '', $forcenew, $context);
- break;
- case 'hangman':
- game_hangman_continue( $id, $game, $attempt, $detail, $newletter, $action2, $context);
- break;
- case 'millionaire':
- game_millionaire_continue( $id, $game, $attempt, $detail, $context);
- break;
- case 'bookquiz':
- game_bookquiz_continue( $id, $game, $attempt, $detail, $chapterid, $context);
- break;
- case 'sudoku':
- game_sudoku_continue( $id, $game, $attempt, $detail, '', $context);
- break;
- case 'cryptex':
- game_cryptex_continue( $id, $game, $attempt, $detail, $forcenew, $context);
- break;
- case 'snakes':
- game_snakes_continue( $id, $game, $attempt, $detail, $context);
- break;
- case 'hiddenpicture':
- game_hiddenpicture_continue( $id, $game, $attempt, $detail, $context);
- break;
- default:
- print_error( "Game {$game->gamekind} not found");
- break;
- }
- }
-
-function game_cross_unpackpuzzle( $g)
-{
- $ret = "";
- $len = game_strlen( $g);
- while( $len)
- {
- for( $i=0; $i < $len; $i++)
- {
- $c = game_substr( $g, $i, 1);
- if( $c >= '1' and $c <= '9'){
- if( $i > 0){
- //found escape character
- if( game_substr( $g, $i-1, 1) == '/'){
- $g = game_substr( $g, 0, $i-1).game_substr( $g, $i);
- $i--;
- $len--;
- continue;
- }
- }
- break;
- }
- }
+ $g = game_substr( $g, $j);
+ $len = game_strlen( $g);
+ } else {
+ $ret .= $g;
+ break;
+ }
+ }
- if( $i < $len){
- //found the start of a number
- for( $j=$i+1; $j < $len; $j++)
- {
- $c = game_substr( $g, $j, 1);
- if( $c < '0' or $c > '9'){
- break;
- }
- }
- $count = game_substr( $g, $i, $j-$i);
- $ret .= game_substr( $g, 0, $i) . str_repeat( '_', $count);
-
- $g = game_substr( $g, $j);
- $len = game_strlen( $g);
-
- }else
- {
- $ret .= $g;
- break;
- }
- }
-
- return $ret;
+ return $ret;
}
diff --git a/export.php b/export.php
index dde2a46..f6d51d5 100755
--- a/export.php
+++ b/export.php
@@ -1,4 +1,19 @@
-.
+
/**
* This page exports a game to another platform e.g. html, jar
*
@@ -10,65 +25,65 @@
require( '../../config.php');
ob_start();
-require_once ($CFG->dirroot.'/lib/formslib.php');
+require_once( $CFG->dirroot.'/lib/formslib.php');
require( 'locallib.php');
require( 'headergame.php');
- $context = game_get_context_module_instance( $cm->id);
- if (!has_capability('mod/game:viewreports', $context))
- return;
+$context = game_get_context_module_instance( $cm->id);
+if (!has_capability('mod/game:viewreports', $context)) {
+ return;
+}
- $target = optional_param('target', "", PARAM_ALPHANUM); // action
+$target = optional_param('target', "", PARAM_ALPHANUM); // The target is HTML or JavaMe.
class mod_game_exporthtml_form extends moodleform {
- function definition() {
+ public function definition() {
global $CFG, $game;
$mform = $this->_form;
$html = $this->_customdata['html'];
-//-------------------------------------------------------------------------------
+
$mform->addElement('header', 'general', get_string('general', 'form'));
- if( $game->gamekind == 'hangman'){
+ if ( $game->gamekind == 'hangman') {
$options = array();
$options[ '0'] = 'Hangman with phrases';
$options[ 'hangmanp'] = 'Hangman with pictures';
$mform->addElement('select', 'type', get_string('javame_type', 'game'), $options);
- if( $html->type == 0)
+ if ( $html->type == 0) {
$mform->setDefault('type', '0');
- else
+ } else {
$mform->setDefault('type', 'hangmanp');
+ }
}
- //filename
- $mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size'=>'30'));
- $mform->setDefault('filename',$html->filename);
+ // Input the filename.
+ $mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30'));
+ $mform->setDefault('filename', $html->filename);
$mform->setType('filename', PARAM_TEXT);
- //html title
- $mform->addElement('text', 'title', get_string('html_title', 'game'), array('size'=>'80'));
- $mform->setDefault('title',$html->title);
+ // Input the html title.
+ $mform->addElement('text', 'title', get_string('html_title', 'game'), array('size' => '80'));
+ $mform->setDefault('title', $html->title);
$mform->setType('title', PARAM_TEXT);
- //fields for hangman
- if( $game->gamekind == 'hangman')
- {
- $mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size'=>'5'));
- $mform->setDefault('maxpicturewidth',$html->maxpicturewidth);
+ // Inputs special fields for hangman.
+ if ($game->gamekind == 'hangman') {
+ $mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5'));
+ $mform->setDefault('maxpicturewidth', $html->maxpicturewidth);
$mform->setType('maxpicturewidth', PARAM_INT);
- $mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size'=>'5'));
- $mform->setDefault('maxpictureheight',$html->maxpictureheight);
+ $mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size' => '5'));
+ $mform->setDefault('maxpictureheight', $html->maxpictureheight);
$mform->setType('maxpictureheight', PARAM_INT);
}
-
- //fiels for cross
- if( $game->gamekind == 'cross')
- {
+
+ // Input special fields for crossword.
+ if ( $game->gamekind == 'cross') {
$mform->addElement('selectyesno', 'checkbutton', get_string('html_hascheckbutton', 'game'));
- $mform->setDefault('checkbutton',$html->checkbutton);
+ $mform->setDefault('checkbutton', $html->checkbutton);
$mform->addElement('selectyesno', 'printbutton', get_string('html_hasprintbutton', 'game'));
- $mform->setDefault('printbutton',$html->printbutton);
+ $mform->setDefault('printbutton', $html->printbutton);
}
$mform->addElement('hidden', 'q', $game->id);
@@ -76,48 +91,45 @@ class mod_game_exporthtml_form extends moodleform {
$mform->addElement('hidden', 'target', 'html');
$mform->setType('target', PARAM_TEXT);
-//-------------------------------------------------------------------------------
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game'));
$mform->closeHeaderBefore('submitbutton');
-//-------------------------------------------------------------------------------
}
- function validation($data, $files) {
+ public function validation($data, $files) {
global $CFG, $USER, $DB;
$errors = parent::validation($data, $files);
-
return $errors;
}
- function export() {
+ public function export() {
global $game, $DB;
$mform = $this->_form;
-
+
$html = new stdClass();
$html->id = $this->_customdata['html']->id;
- $html->type = optional_param('type', 0, PARAM_ALPHANUM);
+ $html->type = optional_param('type', 0, PARAM_ALPHANUM);
$html->filename = $mform->getElementValue('filename');
$html->title = $mform->getElementValue('title');
$html->maxpicturewidth = optional_param('maxpicturewidth', 0, PARAM_INT);
$html->maxpictureheight = optional_param('maxpictureheight', 0, PARAM_INT);
- if( $mform->elementExists( 'checkbutton')){
+ if ( $mform->elementExists( 'checkbutton')) {
$checkbuttonvalue = $mform->getElementValue('checkbutton');
$html->checkbutton = $checkbuttonvalue[ 0];
}
- if( $mform->elementExists( 'printbutton')){
+ if ( $mform->elementExists( 'printbutton')) {
$printbuttonvalue = $mform->getElementValue('printbutton');
$html->printbutton = $printbuttonvalue[ 0];
}
- if (!($DB->update_record( 'game_export_html', $html))){
+ if (!($DB->update_record( 'game_export_html', $html))) {
print_error("game_export_html: not updated id=$html->id");
}
-
+
$cm = get_coursemodule_from_instance('game', $game->id, $game->course);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
+
require_once("exporthtml.php");
game_OnExportHTML( $game, $context, $html);
}
@@ -125,79 +137,73 @@ class mod_game_exporthtml_form extends moodleform {
class mod_game_exportjavame_form extends moodleform {
- function definition() {
+ public function definition() {
global $CFG, $DB, $game;
$mform = $this->_form;
$javame = $this->_customdata['javame'];
-//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
- if( $game->gamekind == 'hangman'){
+ if ( $game->gamekind == 'hangman') {
$options = array();
$options[ '0'] = 'Hangman with phrases';
$options[ 'hangmanp'] = 'Hangman with pictures';
- $mform->addElement('select', 'type', get_string('javame_type', 'game'), $options);
+ $mform->addElement('select', 'type', get_string('javame_type', 'game'), $options);
}
- //filename
- $mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size'=>'30'));
- $mform->setDefault('filename',$javame->filename);
+ $mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30'));
+ $mform->setDefault('filename', $javame->filename);
$mform->setType('filename', PARAM_TEXT);
$mform->addElement('text', 'icon', get_string('javame_icon', 'game'));
- $mform->setDefault('icon',$javame->icon);
- $mform->setType('icon', PARAM_TEXT);
+ $mform->setDefault('icon', $javame->icon);
+ $mform->setType('icon', PARAM_TEXT);
$mform->addElement('text', 'createdby', get_string('javame_createdby', 'game'));
- $mform->setDefault('createdby',$javame->createdby);
+ $mform->setDefault('createdby', $javame->createdby);
$mform->setType('createdby', PARAM_TEXT);
$mform->addElement('text', 'vendor', get_string('javame_vendor', 'game'));
- $mform->setDefault('vendor',$javame->vendor);
+ $mform->setDefault('vendor', $javame->vendor);
$mform->setType('vendor', PARAM_TEXT);
- $mform->addElement('text', 'name', get_string('javame_name', 'game'), array('size'=>'80'));
- $mform->setDefault('name',$javame->name);
+ $mform->addElement('text', 'name', get_string('javame_name', 'game'), array('size' => '80'));
+ $mform->setDefault('name', $javame->name);
$mform->setType('name', PARAM_TEXT);
- $mform->addElement('text', 'description', get_string('javame_description', 'game'), array('size'=>'80'));
- $mform->setDefault('description',$javame->description);
+ $mform->addElement('text', 'description', get_string('javame_description', 'game'), array('size' => '80'));
+ $mform->setDefault('description', $javame->description);
$mform->setType('description', PARAM_TEXT);
- $mform->addElement('text', 'version', get_string('javame_version', 'game'), array('size'=>'10'));
- $mform->setDefault('version',$javame->version);
+ $mform->addElement('text', 'version', get_string('javame_version', 'game'), array('size' => '10'));
+ $mform->setDefault('version', $javame->version);
$mform->setType('version', PARAM_TEXT);
- $mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size'=>'5'));
- $mform->setDefault('maxpicturewidth',$javame->maxpicturewidth);
+ $mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5'));
+ $mform->setDefault('maxpicturewidth', $javame->maxpicturewidth);
$mform->setType('maxpicturewidth', PARAM_INT);
- $mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size'=>'5'));
- $mform->setDefault('maxpictureheight',$javame->maxpictureheight);
+ $mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size' => '5'));
+ $mform->setDefault('maxpictureheight', $javame->maxpictureheight);
$mform->setType('maxpictureheight', PARAM_INT);
-
+
$mform->addElement('hidden', 'q', $game->id);
$mform->setType('q', PARAM_INT);
$mform->addElement('hidden', 'target', 'javame');
$mform->setType('target', PARAM_TEXT);
-//-------------------------------------------------------------------------------
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game'));
$mform->closeHeaderBefore('submitbutton');
-//-------------------------------------------------------------------------------
- //$this->set_data($currententry);
}
- function validation($data, $files) {
+ public function validation($data, $files) {
global $CFG, $USER, $DB;
$errors = parent::validation($data, $files);
-
return $errors;
}
- function export() {
+ public function export() {
global $game, $DB;
$mform = $this->_form;
-
+
$javame = $this->_customdata['javame'];
- $javame->type = optional_param('type', 0, PARAM_ALPHANUM);
+ $javame->type = optional_param('type', 0, PARAM_ALPHANUM);
$javame->filename = $mform->getElementValue('filename');
$javame->icon = $mform->getElementValue('icon');
$javame->createdby = $mform->getElementValue('createdby');
@@ -208,62 +214,59 @@ class mod_game_exportjavame_form extends moodleform {
$javame->maxpicturewidth = $mform->getElementValue('maxpicturewidth');
$javame->maxpictureheight = $mform->getElementValue('maxpictureheight');
- if (!($DB->update_record( 'game_export_javame', $javame))){
+ if (!($DB->update_record( 'game_export_javame', $javame))) {
print_error("game_export_javame: not updated id=$javame->id");
}
-
+
require_once("exportjavame.php");
game_OnExportJavaME( $game, $javame);
}
-}
-
+}
- // create form and set initial data
- if( $target == 'html'){
+// Creates form and set initial data.
+if ($target == 'html') {
+ $html = $DB->get_record( 'game_export_html', array( 'id' => $game->id));
+ if ($html == false) {
+ $html = new stdClass();
+ $html->id = $game->id;
+ $html->checkbutton = 1;
+ $html->printbutton = 1;
+ game_insert_record( 'game_export_html', $html);
$html = $DB->get_record( 'game_export_html', array( 'id' => $game->id));
- if( $html == false){
- $html = new stdClass();
- $html->id = $game->id;
- $html->checkbutton = 1;
- $html->printbutton = 1;
- game_insert_record( 'game_export_html', $html);
- $html = $DB->get_record( 'game_export_html', array( 'id' => $game->id));
- }
- $html->type = 0;
- $mform = new mod_game_exporthtml_form(null, array('id'=>$id, 'html' => $html));
- }else
- {
+ }
+ $html->type = 0;
+ $mform = new mod_game_exporthtml_form(null, array('id' => $id, 'html' => $html));
+} else {
+ $javame = $DB->get_record( 'game_export_javame', array( 'id' => $game->id));
+ if ($javame == false) {
+ $javame = new stdClass();
+ $javame->id = $game->id;
+ $javame->filename = $game->gamekind;
+ game_insert_record( 'game_export_javame', $javame);
$javame = $DB->get_record( 'game_export_javame', array( 'id' => $game->id));
- if( $javame == false){
- $javame = new stdClass();
- $javame->id = $game->id;
- $javame->filename = $game->gamekind;
- game_insert_record( 'game_export_javame', $javame);
- $javame = $DB->get_record( 'game_export_javame', array( 'id' => $game->id));
- }
- $mform = new mod_game_exportjavame_form(null, array('id'=>$id, 'javame' => $javame));
- }
-
- if ($mform->is_cancelled()){
- ob_end_flush();
- if ($id){
- redirect("view.php?id=$cm->id&mode=entry&hook=$id");
- } else {
- redirect("view.php?id=$cm->id");
- }
- } else if ($entry = $mform->get_data()) {
- $mform->export();
- }else
- {
- ob_end_flush();
- if (!empty($id)) {
- $PAGE->navbar->add(get_string('export', 'game'));}
-
- $mform->display();
-// echo $OUTPUT->footer();
}
- $OUTPUT->footer();
+ $mform = new mod_game_exportjavame_form(null, array('id' => $id, 'javame' => $javame));
+}
+
+if ($mform->is_cancelled()) {
+ ob_end_flush();
+ if ($id) {
+ redirect("view.php?id=$cm->id&mode=entry&hook=$id");
+ } else {
+ redirect("view.php?id=$cm->id");
+ }
+} else if ($entry = $mform->get_data()) {
+ $mform->export();
+} else {
+ ob_end_flush();
+ if (!empty($id)) {
+ $PAGE->navbar->add(get_string('export', 'game'));
+ }
+
+ $mform->display();
+}
+$OUTPUT->footer();
function game_send_stored_file($file) {
if (file_exists($file)) {
@@ -279,6 +282,7 @@ function game_send_stored_file($file) {
flush();
readfile($file);
exit;
- }else
+ } else {
print_error("export.php: File does not exists ".$file);
+ }
}
diff --git a/exporthtml.php b/exporthtml.php
index 7ca7f08..1e43e44 100755
--- a/exporthtml.php
+++ b/exporthtml.php
@@ -1,4 +1,19 @@
-.
+
/**
* This page export the game to html for games: cross, hangman
*
@@ -6,413 +21,413 @@
* @version $Id: exporthtml.php,v 1.23 2012/07/25 11:16:03 bdaloukas Exp $
* @package game
**/
-
- require_once( "locallib.php");
- require_once( "exportjavame.php");
-
- function game_OnExportHTML( $game, $context, $html){
- global $CFG;
-
- $destdir = game_export_createtempdir();
-
- switch( $game->gamekind){
+
+require_once( "locallib.php");
+require_once( "exportjavame.php");
+
+function game_onexporthtml( $game, $context, $html) {
+ global $CFG;
+
+ $destdir = game_export_createtempdir();
+
+ switch( $game->gamekind) {
case 'cross';
- game_OnExportHTML_cross( $game, $context, $html, $destdir);
+ game_onexporthtml_cross( $game, $context, $html, $destdir);
break;
case 'hangman':
- game_OnExportHTML_hangman( $game, $context, $html, $destdir);
+ game_onexporthtml_hangman( $game, $context, $html, $destdir);
break;
case 'snakes':
- game_OnExportHTML_snakes( $game, $html, $destdir, $context);
- break;
+ game_onexporthtml_snakes( $game, $html, $destdir, $context);
+ break;
case 'millionaire':
- game_OnExportHTML_millionaire( $game, $context, $html, $destdir);
+ game_onexporthtml_millionaire( $game, $context, $html, $destdir);
break;
- }
+ }
+
+ remove_dir( $destdir);
+}
- 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);
}
-
- function game_OnExportHTML_cross( $game, $context, $html, $destdir){
-
- global $CFG, $DB;
-
- if( $html->filename == ''){
- $html->filename = 'cross';
+
+ $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);
+
+ $outputstring = 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" . $outputstring);
+
+ $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;
+
+ $filehandle = fopen( $destdir.'/'.$filename, "rb");
+
+ $found = false;
+ $files = array();
+ $contextcourse = false;
+ $linesbefore = array();
+ $linesafter = array();
+ while (!feof($filehandle) ) {
+ $line = fgets( $filehandle);
+
+ if ($found) {
+ if ( strpos( $line, 'new Array')) {
+ $linesafter[] = $line;
+ break;
+ }
+ $array .= $line;
+ continue;
}
-
- $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);
+
+ if (strpos( $line, 'Clue = new Array') === false) {
+ $linesbefore[] = $line;
+ continue;
}
-
- $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);
+
+ $array = $line;
+ $found = true;
}
-
- 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;
+ while (!feof($filehandle) ) {
+ $linesafter[] = fgets( $filehandle);
+ }
+
+ fclose($filehandle);
+
+ $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');
}
-
- $array = $line;
- $found = true;
+ $fs = get_file_storage();
}
- while (!feof($file_handle) ) {
- $linesafter[] = fgets( $file_handle);
+
+ $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 {
+ break;
}
- 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;
+ if (!$file = $fs->get_file_by_hash($rec->pathnamehash) or $file->is_directory()) {
+ continue;
+ }
- $pos2 = strpos( $array, '\"', $pos1+$len);
- if( $pos2 == false)
+ $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;
-
- //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();
}
+ }
+ $file->copy_content_to( $destdir.'/images/'.$newfile);
+ $filescopied = true;
- $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;
- }
+ $array = substr( $array, 0, $pos1 + 1).'images/'.$newfile.substr( $array, $pos2);
+ }
- 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;
+ if ($filescopied == false) {
+ return $destdir.'/'.$filename;
}
-
- function game_export_printheader( $title, $showbody=true)
- {
- $ret = ''."\n";
- $ret .= ''."\n";
- $ret .= "\n";
- $ret .= ''."\n";
- $ret .= ''."\n";
- $ret .= "$title\n";
- $ret .= "\n";
- if( $showbody)
- $ret .= "";
-
- return $ret;
- }
-
- function game_OnExportHTML_hangman( $game, $context, $html, $destdir){
-
- global $CFG, $DB;
-
- if( $html->filename == ''){
- $html->filename = 'hangman';
- }
-
- if( $game->param10 <= 0)
- $game->param10 = 6;
-
- $filename = $html->filename . '.htm';
-
- $ret = game_export_printheader( $html->title, false);
- $ret .= "\r\r";
-
- $export_attachment = ( $html->type == 'hangmanp');
-
- $map = game_exmportjavame_getanswers( $game, $context, $export_attachment, $destdir, $files);
- if( $map == false){
- print_error( get_string('no_words', 'game'));
- }
- ob_start();
-
- //Here is the code of hangman
- require_once( "exporthtml_hangman.php");
-
- $output_string = ob_get_contents();
- ob_end_clean();
-
- $courseid = $game->course;
- $course = $DB->get_record( 'course', array( 'id' => $courseid));
-
- $filename = $html->filename . '.htm';
- file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $output_string);
-
- if( $html->type != 'hangmanp')
- {
- //Not copy the standard pictures when we use the "Hangman with pictures"
- $src = $CFG->dirroot.'/mod/game/pix/hangman/1';
- $handle = opendir( $src);
- while (false!==($item = readdir($handle))) {
- if($item != '.' && $item != '..') {
- if(!is_dir($src.'/'.$item)) {
- $itemdest = $item;
-
- if( strpos( $item, '.') === false)
- continue;
-
- copy( $src.'/'.$item, $destdir.'/'.$itemdest);
- }
- }
- }
- }
-
- $filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip');
- game_send_stored_file( $filezip);
+ $linesbefore[] = $array;
+ foreach ($linesafter as $line) {
+ $linesbefore [] = $line;
}
+ file_put_contents( $destdir.'/'.$filename, $linesbefore);
- function game_OnExportHTML_millionaire( $game, $context, $html, $destdir){
-
- global $CFG, $DB;
-
- if( $html->filename == ''){
- $html->filename = 'millionaire';
- }
-
- $filename = $html->filename . '.htm';
-
- $ret = game_export_printheader( $html->title, false);
- $ret .= "\r\r";
-
- //Here is the code of millionaire
- require( "exporthtml_millionaire.php");
-
- $questions = game_millionaire_html_getquestions( $game, $context, $maxanswers, $maxquestions, $retfeedback, $destdir, $files);
- ob_start();
-
- game_millionaire_html_print( $game, $questions, $maxanswers);
-
- //End of millionaire code
- $output_string = ob_get_contents();
- ob_end_clean();
-
- $courseid = $game->course;
- $course = $DB->get_record( 'course', array( 'id' => $courseid));
-
- $filename = $html->filename . '.htm';
-
- file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $output_string);
-
- //Copy the standard pictures of Millionaire
- $src = $CFG->dirroot.'/mod/game/pix/millionaire/1';
+ $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 .= "\n";
+ $ret .= ''."\n";
+ $ret .= ''."\n";
+ $ret .= "$title\n";
+ $ret .= "\n";
+ if ($showbody) {
+ $ret .= "";
+ }
+
+ return $ret;
+}
+
+function game_onexporthtml_hangman( $game, $context, $html, $destdir) {
+
+ global $CFG, $DB;
+
+ if ($html->filename == '') {
+ $html->filename = 'hangman';
+ }
+
+ if ($game->param10 <= 0) {
+ $game->param10 = 6;
+ }
+
+ $filename = $html->filename . '.htm';
+
+ $ret = game_export_printheader( $html->title, false);
+ $ret .= "\r\r";
+
+ $exportattachment = ( $html->type == 'hangmanp');
+
+ $map = game_exmportjavame_getanswers( $game, $context, $exportattachment, $destdir, $files);
+ if ($map == false) {
+ print_error( get_string('no_words', 'game'));
+ }
+
+ ob_start();
+
+ // Here is the code of hangman.
+ require_once( "exporthtml_hangman.php");
+
+ $outputstring = ob_get_contents();
+ ob_end_clean();
+
+ $courseid = $game->course;
+ $course = $DB->get_record( 'course', array( 'id' => $courseid));
+
+ $filename = $html->filename . '.htm';
+ file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring);
+
+ if ($html->type != 'hangmanp') {
+ // Not copy the standard pictures when we use the "Hangman with pictures".
+ $src = $CFG->dirroot.'/mod/game/pix/hangman/1';
$handle = opendir( $src);
- while (false!==($item = readdir($handle))) {
- if($item != '.' && $item != '..') {
- if(!is_dir($src.'/'.$item)) {
+ while (false !== ($item = readdir($handle))) {
+ if ($item != '.' && $item != '..') {
+ if (!is_dir($src.'/'.$item)) {
$itemdest = $item;
- if( strpos( $item, '.') === false)
+ if ( strpos( $item, '.') === false) {
continue;
+ }
- copy( $src.'/'.$item, $destdir.'/'.$itemdest);
+ copy( $src.'/'.$item, $destdir.'/'.$itemdest);
}
- }
- }
-
- $filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip');
- game_send_stored_file($filezip);
- }
-
- function game_OnExportHTML_snakes( $game, $html, $destdir, $context){
- require_once( "exporthtml_millionaire.php");
-
- global $CFG, $DB;
-
- if( $html->filename == ''){
- $html->filename = 'snakes';
- }
-
- $filename = $html->filename . '.htm';
-
- $ret = '';
-
- $board = game_snakes_get_board( $game);
-
- if( ($game->sourcemodule == 'quiz') or ($game->sourcemodule == 'question'))
- $questionsM = game_millionaire_html_getquestions( $game, $context, $maxquestions, $countofquestionsM, $retfeedback, $files);
- else
- {
- $questionsM = array();
- $countofquestionsM = 0;
- $retfeedback = '';
+ }
}
- $questionsS = game_exmportjavame_getanswers( $game, $context, false, $destdir, $files);
-
- ob_start();
-
- //Here is the code of hangman
- require( "exporthtml_snakes.php");
-
- $output_string = ob_get_contents();
- ob_end_clean();
-
- $courseid = $game->course;
- $course = $DB->get_record( 'course', array( 'id' => $courseid));
-
- $filename = $html->filename . '.htm';
-
- file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $output_string);
-
- $src = $CFG->dirroot.'/mod/game/export/html/snakes';
- game_copyfiles( $src, $destdir);
-
- mkdir( $destdir .'/css');
- $src = $CFG->dirroot.'/mod/game/export/html/snakes/css';
- game_copyfiles( $src, $destdir.'/css');
-
- mkdir( $destdir .'/js');
- $src = $CFG->dirroot.'/mod/game/export/html/snakes/js';
- game_copyfiles( $src, $destdir.'/js');
-
- mkdir( $destdir .'/images');
- $destfile = $destdir.'/images/'.$board->fileboard;
- if( $game->param3 != 0)
- {
- //Is a standard board
- copy( $board->imagesrc, $destfile);
- }else
- {
- $cmg = get_coursemodule_from_instance('game', $game->id, $game->course);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cmg->id);
- $fs = get_file_storage();
- $files = $fs->get_area_files($modcontext->id, 'mod_game', 'snakes_board', $game->id);
- foreach ($files as $f) {
- if( $f->is_directory())
+ }
+
+ $filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip');
+ game_send_stored_file( $filezip);
+}
+
+function game_onexporthtml_millionaire( $game, $context, $html, $destdir) {
+
+ global $CFG, $DB;
+
+ if ($html->filename == '') {
+ $html->filename = 'millionaire';
+ }
+
+ $filename = $html->filename . '.htm';
+
+ $ret = game_export_printheader( $html->title, false);
+ $ret .= "\r\r";
+
+ // Here is the code of millionaire.
+ require( "exporthtml_millionaire.php");
+
+ $questions = game_millionaire_html_getquestions( $game, $context, $maxanswers, $maxquestions, $retfeedback, $destdir, $files);
+ ob_start();
+
+ game_millionaire_html_print( $game, $questions, $maxanswers);
+
+ // End of millionaire code.
+ $outputstring = ob_get_contents();
+ ob_end_clean();
+
+ $courseid = $game->course;
+ $course = $DB->get_record( 'course', array( 'id' => $courseid));
+
+ $filename = $html->filename . '.htm';
+
+ file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring);
+
+ // Copy the standard pictures of Millionaire.
+ $src = $CFG->dirroot.'/mod/game/pix/millionaire/1';
+ $handle = opendir( $src);
+ while (false !== ($item = readdir($handle))) {
+ if ($item != '.' && $item != '..') {
+ if (!is_dir($src.'/'.$item)) {
+ $itemdest = $item;
+
+ if (strpos( $item, '.') === false) {
continue;
- break;
+ }
+
+ copy( $src.'/'.$item, $destdir.'/'.$itemdest);
}
- $f->copy_content_to( $destfile);
}
+ }
+
+ $filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip');
+ game_send_stored_file($filezip);
+}
- $a = array( 'player1.png', 'dice1.png', 'dice2.png', 'dice3.png', 'dice4.png', 'dice5.png', 'dice6.png', 'numbers.png');
- foreach( $a as $file)
- copy( $CFG->dirroot.'/mod/game/snakes/1/'.$file, $destdir.'/images/'.$file);
+function game_onexporthtml_snakes( $game, $html, $destdir, $context) {
+ require_once( "exporthtml_millionaire.php");
- $filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip');
- game_send_stored_file($filezip);
+ global $CFG, $DB;
+
+ if ($html->filename == '') {
+ $html->filename = 'snakes';
}
- function game_copyfiles( $src, $destdir)
- {
- $handle = opendir( $src);
- while (($item = readdir($handle)) !== false)
- {
- if( $item == '.' or $item == '..')
- continue;
+ $filename = $html->filename . '.htm';
- if( strpos( $item, '.') === false)
- continue;
-
- if(is_dir($src.'/'.$item))
+ $ret = '';
+
+ $board = game_snakes_get_board( $game);
+
+ if ( ($game->sourcemodule == 'quiz') or ($game->sourcemodule == 'question')) {
+ $questionsm = game_millionaire_html_getquestions( $game, $context, $maxquestions, $countofquestionsm, $retfeedback, $files);
+ } else {
+ $questionsm = array();
+ $countofquestionsm = 0;
+ $retfeedback = '';
+ }
+ $questionss = game_exmportjavame_getanswers( $game, $context, false, $destdir, $files);
+
+ ob_start();
+
+ // Here is the code of hangman.
+ require( "exporthtml_snakes.php");
+
+ $outputstring = ob_get_contents();
+ ob_end_clean();
+
+ $courseid = $game->course;
+ $course = $DB->get_record( 'course', array( 'id' => $courseid));
+
+ $filename = $html->filename . '.htm';
+
+ file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring);
+
+ $src = $CFG->dirroot.'/mod/game/export/html/snakes';
+ game_copyfiles( $src, $destdir);
+
+ mkdir( $destdir .'/css');
+ $src = $CFG->dirroot.'/mod/game/export/html/snakes/css';
+ game_copyfiles( $src, $destdir.'/css');
+
+ mkdir( $destdir .'/js');
+ $src = $CFG->dirroot.'/mod/game/export/html/snakes/js';
+ game_copyfiles( $src, $destdir.'/js');
+
+ mkdir( $destdir .'/images');
+ $destfile = $destdir.'/images/'.$board->fileboard;
+ if ( $game->param3 != 0) {
+ // Is a standard board.
+ copy( $board->imagesrc, $destfile);
+ } else {
+ $cmg = get_coursemodule_from_instance('game', $game->id, $game->course);
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cmg->id);
+ $fs = get_file_storage();
+ $files = $fs->get_area_files($modcontext->id, 'mod_game', 'snakes_board', $game->id);
+ foreach ($files as $f) {
+ if ( $f->is_directory()) {
continue;
+ }
+ break;
+ }
+ $f->copy_content_to( $destfile);
+ }
+
+ $a = array( 'player1.png', 'dice1.png', 'dice2.png', 'dice3.png', 'dice4.png', 'dice5.png', 'dice6.png', 'numbers.png');
+ foreach ($a as $file) {
+ copy( $CFG->dirroot.'/mod/game/snakes/1/'.$file, $destdir.'/images/'.$file);
+ }
+
+ $filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip');
+ game_send_stored_file($filezip);
+}
+
+function game_copyfiles( $src, $destdir) {
+ $handle = opendir( $src);
+ while (($item = readdir($handle)) !== false) {
+ if ( $item == '.' or $item == '..') {
+ continue;
+ }
+
+ if ( strpos( $item, '.') === false) {
+ continue;
+ }
+
+ if (is_dir($src.'/'.$item)) {
+ continue;
+ }
- copy( $src.'/'.$item, $destdir.'/'.$item);
- }
- closedir($handle);
+ copy( $src.'/'.$item, $destdir.'/'.$item);
}
+ closedir($handle);
+}
diff --git a/exporthtml_hangman.php b/exporthtml_hangman.php
index f85c113..6e93913 100755
--- a/exporthtml_hangman.php
+++ b/exporthtml_hangman.php
@@ -1,4 +1,19 @@
-.
+
/**
* This page export the game hangman to html
*
@@ -10,91 +25,102 @@
?>