Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
6f025e372d
  1. 456
      attempt.php
  2. 242
      export.php
  3. 751
      exporthtml.php
  4. 217
      exporthtml_hangman.php
  5. 320
      exporthtml_millionaire.php
  6. 673
      exportjavame.php
  7. 136
      index.php
  8. 4
      version.php

456
attempt.php

@ -1,274 +1,272 @@
<?php // $Id: attempt.php,v 1.22 2012/07/25 23:07:43 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This page prints a particular attempt of game * This page prints a particular attempt of game
* *
* @author bdaloukas * @author bdaloukas
* @version $Id: attempt.php,v 1.22 2012/07/25 23:07:43 bdaloukas Exp $ * @version $Id: attempt.php,v 1.22 2012/07/25 23:07:43 bdaloukas Exp $
* @package game * @package game
**/ **/
require_once( "../../config.php"); require_once( "../../config.php");
require_once( "lib.php"); require_once( "lib.php");
require_once( "locallib.php"); require_once( "locallib.php");
require_once( "hangman/play.php"); require_once( "hangman/play.php");
require_once( "cross/play.php"); require_once( "cross/play.php");
require_once( "cryptex/play.php"); require_once( "cryptex/play.php");
require_once( "millionaire/play.php"); require_once( "millionaire/play.php");
require_once( "sudoku/play.php"); require_once( "sudoku/play.php");
require_once( "bookquiz/play.php"); require_once( "bookquiz/play.php");
require_once( "snakes/play.php"); require_once( "snakes/play.php");
require_once( "hiddenpicture/play.php"); require_once( "hiddenpicture/play.php");
$action = optional_param('action', "", PARAM_ALPHANUM); // action $action = optional_param('action', "", PARAM_ALPHANUM); // Is the param action.
game_show_header( $id, $game, $course, $context);
game_do_attempt( $id, $game, $action, $course, $context);
function game_show_header( &$id, &$game, &$course, &$context) game_show_header( $id, $game, $course, $context);
{ game_do_attempt( $id, $game, $action, $course, $context);
global $DB, $USER, $PAGE, $OUTPUT;
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or function game_show_header( &$id, &$game, &$course, &$context) {
$q = optional_param('q', 0, PARAM_INT); // game ID global $DB, $USER, $PAGE, $OUTPUT;
if ($id) { $id = optional_param('id', 0, PARAM_INT); // It represents Course Module ID.
if (! $cm = get_coursemodule_from_id('game', $id)) { $q = optional_param('q', 0, PARAM_INT); // It represents 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');
}
}
/// Check login and get context. if ($id) {
require_login($course->id, false, $cm); if (! $cm = get_coursemodule_from_id('game', $id)) {
$context = game_get_context_module_instance( $cm->id); print_error('invalidcoursemodule');
require_capability('mod/game:view', $context); }
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. // Check login and get context.
$canattempt = has_capability('mod/game:attempt', $context); require_login($course->id, false, $cm);
$canreviewmine = has_capability('mod/game:reviewmyattempts', $context); $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. // Cache some other capabilites we use several times.
$timenow = time(); $canattempt = has_capability('mod/game:attempt', $context);
//$accessmanager = new game_access_manager(game::create($game->id, $USER->id), $timenow); $canreviewmine = has_capability('mod/game:reviewmyattempts', $context);
/// If no questions have been set up yet redirect to edit.php // Create an object to manage all the other (non-roles) access rules.
//if (!$game->questions && has_capability('mod/game:manage', $context)) { $timenow = time();
// redirect($CFG->wwwroot . '/mod/game/edit.php?cmid=' . $cm->id);
//}
/// Log this request. // Log this request.
if( game_use_events()) if ( game_use_events()) {
{ require( 'classes/event/game_played.php');
require( 'classes/event/game_played.php'); \mod_game\event\game_played::played($game, $context)->trigger();
\mod_game\event\game_played::played($game, $context)->trigger(); } else {
}else add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id);
add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id); }
/// Initialize $PAGE, compute blocks // Initialize $PAGE, compute blocks.
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id)); $PAGE->set_url('/mod/game/view.php', array('id' => $cm->id));
$edit = optional_param('edit', -1, PARAM_BOOL); $edit = optional_param('edit', -1, PARAM_BOOL);
if ($edit != -1 && $PAGE->user_allowed_editing()) { if ($edit != -1 && $PAGE->user_allowed_editing()) {
$USER->editing = $edit; $USER->editing = $edit;
} }
// Note: MDL-19010 there will be further changes to printing header and blocks. // Note: MDL-19010 there will be further changes to printing header and blocks.
// The code will be much nicer than this eventually. // The code will be much nicer than this eventually.
$title = $course->shortname . ': ' . format_string($game->name); $title = $course->shortname . ': ' . format_string($game->name);
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. $buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'. '<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'. '<input type="hidden" name="edit" value="'.($PAGE->user_is_editing() ? 'off' : 'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>'; '<input type="submit" value="'.get_string($PAGE->user_is_editing() ? 'blockseditoff' : 'blocksediton').
$PAGE->set_button($buttons); '" /></div></form></td></tr></table>';
} $PAGE->set_button($buttons);
}
$PAGE->set_title($title); $PAGE->set_title($title);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
echo $OUTPUT->header(); echo $OUTPUT->header();
} }
function game_do_attempt( $id, $game, $action, $course, $context) function game_do_attempt( $id, $game, $action, $course, $context) {
{ global $OUTPUT;
global $OUTPUT;
$forcenew = optional_param('forcenew', false, PARAM_BOOL); // Teacher has requested new preview $forcenew = optional_param('forcenew', false, PARAM_BOOL); // Teacher has requested new preview.
$endofgame = optional_param('endofgame', false, PARAM_BOOL); $endofgame = optional_param('endofgame', false, PARAM_BOOL);
$pos = optional_param('pos', 0, PARAM_INT); $pos = optional_param('pos', 0, PARAM_INT);
$num = optional_param('num', 0, PARAM_INT); $num = optional_param('num', 0, PARAM_INT);
$q = optional_param('q', 0, PARAM_INT); $q = optional_param('q', 0, PARAM_INT);
$attemptid = optional_param('attemptid', 0, PARAM_INT); $attemptid = optional_param('attemptid', 0, PARAM_INT);
$g = optional_param('g', '', PARAM_RAW); $g = optional_param('g', '', PARAM_RAW);
$finishattempt = optional_param('finishattempt', '', PARAM_TEXT); $finishattempt = optional_param('finishattempt', '', PARAM_TEXT);
$answer = optional_param('answer', '', PARAM_TEXT); $answer = optional_param('answer', '', PARAM_TEXT);
$continue = false; $continue = false;
/// Print the main part of the page // Print the main part of the page.
switch( $action) switch ( $action) {
{ case 'crosscheck':
case 'crosscheck': $attempt = game_getattempt( $game, $detail);
$attempt = game_getattempt( $game, $detail); $g = game_cross_unpackpuzzle( $g);
$g = game_cross_unpackpuzzle( $g); game_cross_continue( $id, $game, $attempt, $detail, $g, $finishattempt, $context);
game_cross_continue( $id, $game, $attempt, $detail, $g, $finishattempt, $context); break;
break; case 'crossprint':
case 'crossprint': $attempt = game_getattempt( $game, $detail);
$attempt = game_getattempt( $game, $detail); game_cross_play( $id, $game, $attempt, $detail, '', true, false, false, true, $context);
game_cross_play( $id, $game, $attempt, $detail, '', true, false, false, true, $context); break;
break; case 'sudokucheck': // The student tries to answer a question.
case 'sudokucheck': //the student tries to answer a question $attempt = game_getattempt( $game, $detail);
$attempt = game_getattempt( $game, $detail); game_sudoku_check_questions( $id, $game, $attempt, $detail, $finishattempt, $course, $context);
game_sudoku_check_questions( $id, $game, $attempt, $detail, $finishattempt, $course, $context);
$continue = true; $continue = true;
break; break;
case 'sudokucheckg': //the student tries to guess a glossaryenry case 'sudokucheckg': // The student tries to guess a glossaryenry.
$attempt = game_getattempt( $game, $detail); $attempt = game_getattempt( $game, $detail);
$endofgame = array_key_exists( 'endofgame', $_GET); $endofgame = array_key_exists( 'endofgame', $_GET);
$continue = game_sudoku_check_glossaryentries( $id, $game, $attempt, $detail, $endofgame, $course); $continue = game_sudoku_check_glossaryentries( $id, $game, $attempt, $detail, $endofgame, $course);
$continue = true; $continue = true;
break; break;
case 'sudokucheckn': //the user tries to guess a number case 'sudokucheckn': // The user tries to guess a number.
$attempt = game_getattempt( $game, $detail); $attempt = game_getattempt( $game, $detail);
game_sudoku_check_number( $id, $game, $attempt, $detail, $pos, $num, $context); game_sudoku_check_number( $id, $game, $attempt, $detail, $pos, $num, $context);
$continue = false; $continue = false;
break; break;
case 'cryptexcheck': //the user tries to guess a question case 'cryptexcheck': // The user tries to guess a question.
$attempt = game_getattempt( $game, $detail); $attempt = game_getattempt( $game, $detail);
game_cryptex_check( $id, $game, $attempt, $detail, $q, $answer, $finishattempt, $context); 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; break;
case 'bookquizcheck': //the student tries to answer a question case 'snakescheck': // The student tries to answer a question.
$attempt = game_getattempt( $game, $detail); $attempt = game_getattempt( $game, $detail);
game_bookquiz_check_questions( $id, $game, $attempt, $detail, $context); game_snakes_check_questions( $id, $game, $attempt, $detail, $context);
break; break;
case 'snakescheck': //the student tries to answer a question case 'snakescheckg': // The student tries to answer a question from glossary.
$attempt = game_getattempt( $game, $detail); $attempt = game_getattempt( $game, $detail);
game_snakes_check_questions( $id, $game, $attempt, $detail, $context); game_snakes_check_glossary( $id, $game, $attempt, $detail, $context);
break; break;
case 'snakescheckg': //the student tries to answer a question from glossary case 'hiddenpicturecheck': // The student tries to answer a question.
$attempt = game_getattempt( $game, $detail); $attempt = game_getattempt( $game, $detail);
game_snakes_check_glossary( $id, $game, $attempt, $detail, $context); $continue = game_hiddenpicture_check_questions( $id, $game, $attempt, $detail, $finishattempt, $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);
break; break;
case 'hiddenpicturecheckg': //the student tries to guess a glossaryenry case 'hiddenpicturecheckg': // The student tries to guess a glossaryentry.
$attempt = game_getattempt( $game, $detail); $attempt = game_getattempt( $game, $detail);
game_hiddenpicture_check_mainquestion( $id, $game, $attempt, $detail, $endofgame, $context); game_hiddenpicture_check_mainquestion( $id, $game, $attempt, $detail, $endofgame, $context);
break; break;
default: default:
$continue = true; $continue = true;
break; break;
} }
if( $continue){ if ($continue) {
game_create( $game, $id, $forcenew, $course, $context); game_create( $game, $id, $forcenew, $course, $context);
} }
/// Finish the page // Finish the page.
echo $OUTPUT->footer(); 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) if ($i < $len) {
{ // Found the start of a number.
global $USER, $CFG, $DB; for ($j = $i + 1; $j < $len; $j++) {
$c = game_substr( $g, $j, 1);
$attempt = game_getattempt( $game, $detail); if ($c < '0' or $c > '9') {
$chapterid = optional_param('chapterid', 0, PARAM_INT); break;
$newletter = optional_param('newletter', '', PARAM_ALPHA); }
$action2 = optional_param('action2', '', PARAM_ALPHA); }
$count = game_substr( $g, $i, $j - $i);
$ret .= game_substr( $g, 0, $i) . str_repeat( '_', $count);
switch( $game->gamekind) $g = game_substr( $g, $j);
{ $len = game_strlen( $g);
case 'cross': } else {
game_cross_continue( $id, $game, $attempt, $detail, '', $forcenew, $context); $ret .= $g;
break; 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;
}
}
if( $i < $len){ return $ret;
//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;
} }

242
export.php

@ -1,4 +1,19 @@
<?php // $Id: export.php,v 1.22 2012/07/25 11:16:03 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This page exports a game to another platform e.g. html, jar * This page exports a game to another platform e.g. html, jar
* *
@ -10,65 +25,65 @@
require( '../../config.php'); require( '../../config.php');
ob_start(); ob_start();
require_once ($CFG->dirroot.'/lib/formslib.php'); require_once( $CFG->dirroot.'/lib/formslib.php');
require( 'locallib.php'); require( 'locallib.php');
require( 'headergame.php'); require( 'headergame.php');
$context = game_get_context_module_instance( $cm->id); $context = game_get_context_module_instance( $cm->id);
if (!has_capability('mod/game:viewreports', $context)) if (!has_capability('mod/game:viewreports', $context)) {
return; 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 { class mod_game_exporthtml_form extends moodleform {
function definition() { public function definition() {
global $CFG, $game; global $CFG, $game;
$mform = $this->_form; $mform = $this->_form;
$html = $this->_customdata['html']; $html = $this->_customdata['html'];
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('header', 'general', get_string('general', 'form'));
if( $game->gamekind == 'hangman'){ if ( $game->gamekind == 'hangman') {
$options = array(); $options = array();
$options[ '0'] = 'Hangman with phrases'; $options[ '0'] = 'Hangman with phrases';
$options[ 'hangmanp'] = 'Hangman with pictures'; $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);
if( $html->type == 0) if ( $html->type == 0) {
$mform->setDefault('type', '0'); $mform->setDefault('type', '0');
else } else {
$mform->setDefault('type', 'hangmanp'); $mform->setDefault('type', 'hangmanp');
}
} }
//filename // Input the filename.
$mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size'=>'30')); $mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30'));
$mform->setDefault('filename',$html->filename); $mform->setDefault('filename', $html->filename);
$mform->setType('filename', PARAM_TEXT); $mform->setType('filename', PARAM_TEXT);
//html title // Input the html title.
$mform->addElement('text', 'title', get_string('html_title', 'game'), array('size'=>'80')); $mform->addElement('text', 'title', get_string('html_title', 'game'), array('size' => '80'));
$mform->setDefault('title',$html->title); $mform->setDefault('title', $html->title);
$mform->setType('title', PARAM_TEXT); $mform->setType('title', PARAM_TEXT);
//fields for hangman // Inputs special fields for hangman.
if( $game->gamekind == 'hangman') if ($game->gamekind == 'hangman') {
{ $mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5'));
$mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size'=>'5')); $mform->setDefault('maxpicturewidth', $html->maxpicturewidth);
$mform->setDefault('maxpicturewidth',$html->maxpicturewidth);
$mform->setType('maxpicturewidth', PARAM_INT); $mform->setType('maxpicturewidth', PARAM_INT);
$mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size'=>'5')); $mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size' => '5'));
$mform->setDefault('maxpictureheight',$html->maxpictureheight); $mform->setDefault('maxpictureheight', $html->maxpictureheight);
$mform->setType('maxpictureheight', PARAM_INT); $mform->setType('maxpictureheight', PARAM_INT);
} }
//fiels for cross // Input special fields for crossword.
if( $game->gamekind == 'cross') if ( $game->gamekind == 'cross') {
{
$mform->addElement('selectyesno', 'checkbutton', get_string('html_hascheckbutton', 'game')); $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->addElement('selectyesno', 'printbutton', get_string('html_hasprintbutton', 'game'));
$mform->setDefault('printbutton',$html->printbutton); $mform->setDefault('printbutton', $html->printbutton);
} }
$mform->addElement('hidden', 'q', $game->id); $mform->addElement('hidden', 'q', $game->id);
@ -76,48 +91,45 @@ class mod_game_exporthtml_form extends moodleform {
$mform->addElement('hidden', 'target', 'html'); $mform->addElement('hidden', 'target', 'html');
$mform->setType('target', PARAM_TEXT); $mform->setType('target', PARAM_TEXT);
//-------------------------------------------------------------------------------
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game')); $mform->addElement('submit', 'submitbutton', get_string( 'export', 'game'));
$mform->closeHeaderBefore('submitbutton'); $mform->closeHeaderBefore('submitbutton');
//-------------------------------------------------------------------------------
} }
function validation($data, $files) { public function validation($data, $files) {
global $CFG, $USER, $DB; global $CFG, $USER, $DB;
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
return $errors; return $errors;
} }
function export() { public function export() {
global $game, $DB; global $game, $DB;
$mform = $this->_form; $mform = $this->_form;
$html = new stdClass(); $html = new stdClass();
$html->id = $this->_customdata['html']->id; $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->filename = $mform->getElementValue('filename');
$html->title = $mform->getElementValue('title'); $html->title = $mform->getElementValue('title');
$html->maxpicturewidth = optional_param('maxpicturewidth', 0, PARAM_INT); $html->maxpicturewidth = optional_param('maxpicturewidth', 0, PARAM_INT);
$html->maxpictureheight = optional_param('maxpictureheight', 0, PARAM_INT); $html->maxpictureheight = optional_param('maxpictureheight', 0, PARAM_INT);
if( $mform->elementExists( 'checkbutton')){ if ( $mform->elementExists( 'checkbutton')) {
$checkbuttonvalue = $mform->getElementValue('checkbutton'); $checkbuttonvalue = $mform->getElementValue('checkbutton');
$html->checkbutton = $checkbuttonvalue[ 0]; $html->checkbutton = $checkbuttonvalue[ 0];
} }
if( $mform->elementExists( 'printbutton')){ if ( $mform->elementExists( 'printbutton')) {
$printbuttonvalue = $mform->getElementValue('printbutton'); $printbuttonvalue = $mform->getElementValue('printbutton');
$html->printbutton = $printbuttonvalue[ 0]; $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"); print_error("game_export_html: not updated id=$html->id");
} }
$cm = get_coursemodule_from_instance('game', $game->id, $game->course); $cm = get_coursemodule_from_instance('game', $game->id, $game->course);
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_once("exporthtml.php"); require_once("exporthtml.php");
game_OnExportHTML( $game, $context, $html); game_OnExportHTML( $game, $context, $html);
} }
@ -125,79 +137,73 @@ class mod_game_exporthtml_form extends moodleform {
class mod_game_exportjavame_form extends moodleform { class mod_game_exportjavame_form extends moodleform {
function definition() { public function definition() {
global $CFG, $DB, $game; global $CFG, $DB, $game;
$mform = $this->_form; $mform = $this->_form;
$javame = $this->_customdata['javame']; $javame = $this->_customdata['javame'];
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('header', 'general', get_string('general', 'form'));
if( $game->gamekind == 'hangman'){ if ( $game->gamekind == 'hangman') {
$options = array(); $options = array();
$options[ '0'] = 'Hangman with phrases'; $options[ '0'] = 'Hangman with phrases';
$options[ 'hangmanp'] = 'Hangman with pictures'; $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->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size'=>'30')); $mform->setDefault('filename', $javame->filename);
$mform->setDefault('filename',$javame->filename);
$mform->setType('filename', PARAM_TEXT); $mform->setType('filename', PARAM_TEXT);
$mform->addElement('text', 'icon', get_string('javame_icon', 'game')); $mform->addElement('text', 'icon', get_string('javame_icon', 'game'));
$mform->setDefault('icon',$javame->icon); $mform->setDefault('icon', $javame->icon);
$mform->setType('icon', PARAM_TEXT); $mform->setType('icon', PARAM_TEXT);
$mform->addElement('text', 'createdby', get_string('javame_createdby', 'game')); $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->setType('createdby', PARAM_TEXT);
$mform->addElement('text', 'vendor', get_string('javame_vendor', 'game')); $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->setType('vendor', PARAM_TEXT);
$mform->addElement('text', 'name', get_string('javame_name', 'game'), array('size'=>'80')); $mform->addElement('text', 'name', get_string('javame_name', 'game'), array('size' => '80'));
$mform->setDefault('name',$javame->name); $mform->setDefault('name', $javame->name);
$mform->setType('name', PARAM_TEXT); $mform->setType('name', PARAM_TEXT);
$mform->addElement('text', 'description', get_string('javame_description', 'game'), array('size'=>'80')); $mform->addElement('text', 'description', get_string('javame_description', 'game'), array('size' => '80'));
$mform->setDefault('description',$javame->description); $mform->setDefault('description', $javame->description);
$mform->setType('description', PARAM_TEXT); $mform->setType('description', PARAM_TEXT);
$mform->addElement('text', 'version', get_string('javame_version', 'game'), array('size'=>'10')); $mform->addElement('text', 'version', get_string('javame_version', 'game'), array('size' => '10'));
$mform->setDefault('version',$javame->version); $mform->setDefault('version', $javame->version);
$mform->setType('version', PARAM_TEXT); $mform->setType('version', PARAM_TEXT);
$mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size'=>'5')); $mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5'));
$mform->setDefault('maxpicturewidth',$javame->maxpicturewidth); $mform->setDefault('maxpicturewidth', $javame->maxpicturewidth);
$mform->setType('maxpicturewidth', PARAM_INT); $mform->setType('maxpicturewidth', PARAM_INT);
$mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size'=>'5')); $mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size' => '5'));
$mform->setDefault('maxpictureheight',$javame->maxpictureheight); $mform->setDefault('maxpictureheight', $javame->maxpictureheight);
$mform->setType('maxpictureheight', PARAM_INT); $mform->setType('maxpictureheight', PARAM_INT);
$mform->addElement('hidden', 'q', $game->id); $mform->addElement('hidden', 'q', $game->id);
$mform->setType('q', PARAM_INT); $mform->setType('q', PARAM_INT);
$mform->addElement('hidden', 'target', 'javame'); $mform->addElement('hidden', 'target', 'javame');
$mform->setType('target', PARAM_TEXT); $mform->setType('target', PARAM_TEXT);
//-------------------------------------------------------------------------------
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game')); $mform->addElement('submit', 'submitbutton', get_string( 'export', 'game'));
$mform->closeHeaderBefore('submitbutton'); $mform->closeHeaderBefore('submitbutton');
//-------------------------------------------------------------------------------
//$this->set_data($currententry);
} }
function validation($data, $files) { public function validation($data, $files) {
global $CFG, $USER, $DB; global $CFG, $USER, $DB;
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
return $errors; return $errors;
} }
function export() { public function export() {
global $game, $DB; global $game, $DB;
$mform = $this->_form; $mform = $this->_form;
$javame = $this->_customdata['javame']; $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->filename = $mform->getElementValue('filename');
$javame->icon = $mform->getElementValue('icon'); $javame->icon = $mform->getElementValue('icon');
$javame->createdby = $mform->getElementValue('createdby'); $javame->createdby = $mform->getElementValue('createdby');
@ -208,62 +214,59 @@ class mod_game_exportjavame_form extends moodleform {
$javame->maxpicturewidth = $mform->getElementValue('maxpicturewidth'); $javame->maxpicturewidth = $mform->getElementValue('maxpicturewidth');
$javame->maxpictureheight = $mform->getElementValue('maxpictureheight'); $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"); print_error("game_export_javame: not updated id=$javame->id");
} }
require_once("exportjavame.php"); require_once("exportjavame.php");
game_OnExportJavaME( $game, $javame); game_OnExportJavaME( $game, $javame);
} }
} }
// create form and set initial data // Creates form and set initial data.
if( $target == 'html'){ 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)); $html = $DB->get_record( 'game_export_html', array( 'id' => $game->id));
if( $html == false){ }
$html = new stdClass(); $html->type = 0;
$html->id = $game->id; $mform = new mod_game_exporthtml_form(null, array('id' => $id, 'html' => $html));
$html->checkbutton = 1; } else {
$html->printbutton = 1; $javame = $DB->get_record( 'game_export_javame', array( 'id' => $game->id));
game_insert_record( 'game_export_html', $html); if ($javame == false) {
$html = $DB->get_record( 'game_export_html', array( 'id' => $game->id)); $javame = new stdClass();
} $javame->id = $game->id;
$html->type = 0; $javame->filename = $game->gamekind;
$mform = new mod_game_exporthtml_form(null, array('id'=>$id, 'html' => $html)); game_insert_record( 'game_export_javame', $javame);
}else
{
$javame = $DB->get_record( 'game_export_javame', array( 'id' => $game->id)); $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&amp;mode=entry&amp;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&amp;mode=entry&amp;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) { function game_send_stored_file($file) {
if (file_exists($file)) { if (file_exists($file)) {
@ -279,6 +282,7 @@ function game_send_stored_file($file) {
flush(); flush();
readfile($file); readfile($file);
exit; exit;
}else } else {
print_error("export.php: File does not exists ".$file); print_error("export.php: File does not exists ".$file);
}
} }

751
exporthtml.php

@ -1,4 +1,19 @@
<?php // $Id: exporthtml.php,v 1.23 2012/07/25 11:16:03 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This page export the game to html for games: cross, hangman * 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 $ * @version $Id: exporthtml.php,v 1.23 2012/07/25 11:16:03 bdaloukas Exp $
* @package game * @package game
**/ **/
require_once( "locallib.php"); require_once( "locallib.php");
require_once( "exportjavame.php"); require_once( "exportjavame.php");
function game_OnExportHTML( $game, $context, $html){ function game_onexporthtml( $game, $context, $html) {
global $CFG; global $CFG;
$destdir = game_export_createtempdir(); $destdir = game_export_createtempdir();
switch( $game->gamekind){ switch( $game->gamekind) {
case 'cross'; case 'cross';
game_OnExportHTML_cross( $game, $context, $html, $destdir); game_onexporthtml_cross( $game, $context, $html, $destdir);
break; break;
case 'hangman': case 'hangman':
game_OnExportHTML_hangman( $game, $context, $html, $destdir); game_onexporthtml_hangman( $game, $context, $html, $destdir);
break; break;
case 'snakes': case 'snakes':
game_OnExportHTML_snakes( $game, $html, $destdir, $context); game_onexporthtml_snakes( $game, $html, $destdir, $context);
break; break;
case 'millionaire': case 'millionaire':
game_OnExportHTML_millionaire( $game, $context, $html, $destdir); game_onexporthtml_millionaire( $game, $context, $html, $destdir);
break; 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){ $ret = game_export_printheader( $html->title);
echo "$ret<br>";
global $CFG, $DB;
ob_start();
if( $html->filename == ''){
$html->filename = 'cross'; 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'; if (strpos( $line, 'Clue = new Array') === false) {
$linesbefore[] = $line;
require( "cross/play.php"); continue;
$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); $array = $line;
echo "$ret<br>"; $found = true;
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);
} }
while (!feof($filehandle) ) {
function game_OnExportHTML_cross_repair_questions( $game, $context, $filename, $destdir) $linesafter[] = fgets( $filehandle);
{ }
global $CFG, $DB;
fclose($filehandle);
$file_handle = fopen( $destdir.'/'.$filename, "rb");
$search = $CFG->wwwroot.'/pluginfile.php';
$found = false; $pos = 0;
$files = array(); $search = '"'.$CFG->wwwroot.'/pluginfile.php/'.$context->id.'/mod_game/';
$contextcourse = false; $len = strlen( $search);
$linesbefore = array(); $start = 0;
$linesafter = array(); $filescopied = false;
while (!feof($file_handle) ) { for (;;) {
$line = fgets( $file_handle); $pos1 = strpos( $array, $search, $start);
if ( $pos1 == false) {
if( $found) break;
{ }
if( strpos( $line, 'new Array'))
{ $pos2 = strpos( $array, '\"', $pos1 + $len);
$linesafter[] = $line; if ( $pos2 == false) {
break; break;
} }
$array .= $line;
continue; // Have to copy the files.
} if ($contextcourse === false) {
mkdir( $destdir.'/images');
if( strpos( $line, 'Clue = new Array') === false) if (!$contextcourse = get_context_instance(CONTEXT_COURSE, $game->course)) {
{ print_error('nocontext');
$linesbefore[] = $line;
continue;
} }
$fs = get_file_storage();
$array = $line;
$found = true;
} }
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); if (!$file = $fs->get_file_by_hash($rec->pathnamehash) or $file->is_directory()) {
continue;
$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); $posext = strrpos( $fileimage, '.');
if( $pos2 == false) $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; 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)); $array = substr( $array, 0, $pos1 + 1).'images/'.$newfile.substr( $array, $pos2);
}
$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()) if ($filescopied == false) {
continue; return $destdir.'/'.$filename;
$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 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
$ret .= '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="el" xml:lang="el">'."\n";
$ret .= "<head>\n";
$ret .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
$ret .= '<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">'."\n";
$ret .= "<title>$title</title>\n";
$ret .= "</head>\n";
if( $showbody)
$ret .= "<body>";
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<body onload=\"reset()\">\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(); $linesbefore[] = $array;
foreach ($linesafter as $line) {
//Here is the code of hangman $linesbefore [] = $line;
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);
} }
file_put_contents( $destdir.'/'.$filename, $linesbefore);
function game_OnExportHTML_millionaire( $game, $context, $html, $destdir){ $pos = strrpos( $filename, '.');
if ($pos === false) {
global $CFG, $DB; $filezip = $filename.'.zip';
} else {
if( $html->filename == ''){ $filezip = substr( $filename, 0, $pos).'.zip';
$html->filename = 'millionaire'; }
}
$filezip = game_create_zip( $destdir, $game->course, $filezip);
$filename = $html->filename . '.htm';
return $filezip;
$ret = game_export_printheader( $html->title, false); }
$ret .= "\r<body onload=\"Reset();\">\r";
function game_export_printheader( $title, $showbody=true) {
//Here is the code of millionaire $ret = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
require( "exporthtml_millionaire.php"); $ret .= '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="el" xml:lang="el">'."\n";
$ret .= "<head>\n";
$questions = game_millionaire_html_getquestions( $game, $context, $maxanswers, $maxquestions, $retfeedback, $destdir, $files); $ret .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
ob_start(); $ret .= '<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">'."\n";
$ret .= "<title>$title</title>\n";
game_millionaire_html_print( $game, $questions, $maxanswers); $ret .= "</head>\n";
if ($showbody) {
//End of millionaire code $ret .= "<body>";
$output_string = ob_get_contents(); }
ob_end_clean();
return $ret;
$courseid = $game->course; }
$course = $DB->get_record( 'course', array( 'id' => $courseid));
function game_onexporthtml_hangman( $game, $context, $html, $destdir) {
$filename = $html->filename . '.htm';
global $CFG, $DB;
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $output_string);
if ($html->filename == '') {
//Copy the standard pictures of Millionaire $html->filename = 'hangman';
$src = $CFG->dirroot.'/mod/game/pix/millionaire/1'; }
if ($game->param10 <= 0) {
$game->param10 = 6;
}
$filename = $html->filename . '.htm';
$ret = game_export_printheader( $html->title, false);
$ret .= "\r<body onload=\"reset()\">\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); $handle = opendir( $src);
while (false!==($item = readdir($handle))) { while (false !== ($item = readdir($handle))) {
if($item != '.' && $item != '..') { if ($item != '.' && $item != '..') {
if(!is_dir($src.'/'.$item)) { if (!is_dir($src.'/'.$item)) {
$itemdest = $item; $itemdest = $item;
if( strpos( $item, '.') === false) if ( strpos( $item, '.') === false) {
continue; 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(); $filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip');
game_send_stored_file( $filezip);
//Here is the code of hangman }
require( "exporthtml_snakes.php");
function game_onexporthtml_millionaire( $game, $context, $html, $destdir) {
$output_string = ob_get_contents();
ob_end_clean(); global $CFG, $DB;
$courseid = $game->course; if ($html->filename == '') {
$course = $DB->get_record( 'course', array( 'id' => $courseid)); $html->filename = 'millionaire';
}
$filename = $html->filename . '.htm';
$filename = $html->filename . '.htm';
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $output_string);
$ret = game_export_printheader( $html->title, false);
$src = $CFG->dirroot.'/mod/game/export/html/snakes'; $ret .= "\r<body onload=\"Reset();\">\r";
game_copyfiles( $src, $destdir);
// Here is the code of millionaire.
mkdir( $destdir .'/css'); require( "exporthtml_millionaire.php");
$src = $CFG->dirroot.'/mod/game/export/html/snakes/css';
game_copyfiles( $src, $destdir.'/css'); $questions = game_millionaire_html_getquestions( $game, $context, $maxanswers, $maxquestions, $retfeedback, $destdir, $files);
ob_start();
mkdir( $destdir .'/js');
$src = $CFG->dirroot.'/mod/game/export/html/snakes/js'; game_millionaire_html_print( $game, $questions, $maxanswers);
game_copyfiles( $src, $destdir.'/js');
// End of millionaire code.
mkdir( $destdir .'/images'); $outputstring = ob_get_contents();
$destfile = $destdir.'/images/'.$board->fileboard; ob_end_clean();
if( $game->param3 != 0)
{ $courseid = $game->course;
//Is a standard board $course = $DB->get_record( 'course', array( 'id' => $courseid));
copy( $board->imagesrc, $destfile);
}else $filename = $html->filename . '.htm';
{
$cmg = get_coursemodule_from_instance('game', $game->id, $game->course); file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring);
$modcontext = get_context_instance(CONTEXT_MODULE, $cmg->id);
$fs = get_file_storage(); // Copy the standard pictures of Millionaire.
$files = $fs->get_area_files($modcontext->id, 'mod_game', 'snakes_board', $game->id); $src = $CFG->dirroot.'/mod/game/pix/millionaire/1';
foreach ($files as $f) { $handle = opendir( $src);
if( $f->is_directory()) while (false !== ($item = readdir($handle))) {
if ($item != '.' && $item != '..') {
if (!is_dir($src.'/'.$item)) {
$itemdest = $item;
if (strpos( $item, '.') === false) {
continue; 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'); function game_onexporthtml_snakes( $game, $html, $destdir, $context) {
foreach( $a as $file) require_once( "exporthtml_millionaire.php");
copy( $CFG->dirroot.'/mod/game/snakes/1/'.$file, $destdir.'/images/'.$file);
$filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip'); global $CFG, $DB;
game_send_stored_file($filezip);
if ($html->filename == '') {
$html->filename = 'snakes';
} }
function game_copyfiles( $src, $destdir) $filename = $html->filename . '.htm';
{
$handle = opendir( $src);
while (($item = readdir($handle)) !== false)
{
if( $item == '.' or $item == '..')
continue;
if( strpos( $item, '.') === false) $ret = '';
continue;
$board = game_snakes_get_board( $game);
if(is_dir($src.'/'.$item))
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; 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); copy( $src.'/'.$item, $destdir.'/'.$item);
}
closedir($handle);
} }
closedir($handle);
}

217
exporthtml_hangman.php

@ -1,4 +1,19 @@
<?php // $Id: exporthtml_hangman.php,v 1.10 2012/07/25 11:16:03 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This page export the game hangman to html * This page export the game hangman to html
* *
@ -10,91 +25,102 @@
?> ?>
<script type="text/javascript"> <script type="text/javascript">
// Hangman for Moodle by Vasilis Daloukas // Hangman for Moodle by Vasilis Daloukas.
// The script is based on HangMan II script- By Chris Fortey (http://www.c-g-f.net/) // The script is based on HangMan II script- By Chris Fortey (http://www.c-g-f.net/)
var can_play = true; var can_play = true;
<?php <?php
$destdir = game_export_createtempdir();
$export_attachment = ( $html->type == 'hangmanp'); $destdir = game_export_createtempdir();
$map = game_exmportjavame_getanswers( $game, $context, $export_attachment, $destdir, $files);
if( $map == false){ $exportattachment = ( $html->type == 'hangmanp');
print_error( 'No Questions'); $map = game_exmportjavame_getanswers( $game, $context, $exportattachment, $destdir, $files);
if ($map == false) {
print_error( 'No Questions');
}
$questions = '';
$words = '';
$lang = '';
$allletters = '';
$images = '';
foreach ($map as $line) {
$answer = game_upper( $line->answer);
if ($game->param7) {
// Have to delete space.
$answer = str_replace(' ', '', $answer);
}
if ($game->param8) {
// Have to deletε -.
$answer = str_replace('-', '', $answer);
}
if ($lang == '') {
$lang = $game->language;
if ($lang == '') {
$lang = game_detectlanguage( $answer);
} }
if ($lang == '') {
$questions = ''; $lang = current_language();
$words = '';
$lang = '';
$allletters = '';
$images = '';
foreach( $map as $line)
{
$answer = game_upper( $line->answer);
if( $game->param7){
//Have to delete space
$answer = str_replace(' ', '', $answer);
}
if( $game->param8){
//Have to delete -
$answer = str_replace('-', '', $answer);
}
if( $lang == ''){
$lang = $game->language;
if( $lang == '')
$lang = game_detectlanguage( $answer);
if( $lang == '')
$lang = current_language();
$allletters = game_getallletters( $answer, $lang);
}
if( game_getallletters( $answer, $lang) != $allletters)
continue;
if( $html->type == 'hangmanp'){
$file = $line->attachment;
$pos = strrpos( $file, '.');
if( $pos == false)
continue;
}
if( $html->type == 'hangmanp'){
$src = $line->attachment;
$pos = strrpos( $file, '.');
if( $pos == false)
continue;
}
if( $questions != '')
$questions .= ', ';
if( $words != '')
$words .= ', ';
$questions .= '"'.base64_encode( $line->question).'"';
$words .= '"'.base64_encode( $line->answer).'"';
if( $html->type == 'hangmanp'){
$file = $line->id.substr( $file, $pos);
game_export_javame_smartcopyimage( $src, $destdir.'/'.$file, $html->maxpicturewidth, $html->maxpictureheight);
if( $images != '')
$images .= ', ';
$images .= '"'.$file.'"';
}
} }
$allletters = game_getallletters( $answer, $lang);
}
if (game_getallletters( $answer, $lang) != $allletters) {
continue;
}
if($game->param7){ if ($html->type == 'hangmanp') {
$allletters .= '_'; $file = $line->attachment;
} $pos = strrpos( $file, '.');
if($game->param8){ if ($pos == false) {
$allletters .= '-'; continue;
} }
}
echo "var questions = new Array($questions);\r";
echo "var words = new Array($words);\r"; if ($html->type == 'hangmanp') {
if( $html->type == 'hangmanp') $src = $line->attachment;
echo "var images = new Array($images);\r"; $pos = strrpos( $file, '.');
if ($pos == false) {
continue;
}
}
if ($questions != '') {
$questions .= ', ';
}
if ($words != '') {
$words .= ', ';
}
$questions .= '"'.base64_encode( $line->question).'"';
$words .= '"'.base64_encode( $line->answer).'"';
if ($html->type == 'hangmanp') {
$file = $line->id.substr( $file, $pos);
game_export_javame_smartcopyimage( $src, $destdir.'/'.$file, $html->maxpicturewidth, $html->maxpictureheight);
if ($images != '') {
$images .= ', ';
}
$images .= '"'.$file.'"';
}
}
if ($game->param7) {
$allletters .= '_';
}
if ($game->param8) {
$allletters .= '-';
}
echo "var questions = new Array($questions);\r";
echo "var words = new Array($words);\r";
if ($html->type == 'hangmanp') {
echo "var images = new Array($images);\r";
}
?> ?>
var to_guess = ""; var to_guess = "";
@ -104,10 +130,10 @@ var wrong_guesses = 0;
var used_letters_all = ""; var used_letters_all = "";
var all_letters = new Array(<?php var all_letters = new Array(<?php
$len = game_strlen( $allletters); $len = game_strlen( $allletters);
for( $i=0; $i < $len; $i++) for ($i = 0; $i < $len; $i++) {
{ if ($i > 0) {
if( $i > 0)
echo ','; echo ',';
}
echo '"'.game_substr( $allletters, $i, 1).'"'; echo '"'.game_substr( $allletters, $i, 1).'"';
} }
?>); ?>);
@ -162,13 +188,14 @@ function selectLetter(l)
}else }else
{ {
wrong_guesses++; wrong_guesses++;
<?php <?php
if( $html->type != 'hangmanp'){ if ($html->type != 'hangmanp') {
?>eval("document.hm.src=\"hangman_" + wrong_guesses + ".jpg\""); ?>eval("document.hm.src=\"hangman_" + wrong_guesses + ".jpg\"");
// incortect letter guess // Ιncortect letter guess.
eval("document.hm.src=\"hangman_" + wrong_guesses + ".jpg\""); eval("document.hm.src=\"hangman_" + wrong_guesses + ".jpg\"");
<?php <?php
} }
?> ?>
if (wrong_guesses == <?php echo $game->param10 + 1;?>) if (wrong_guesses == <?php echo $game->param10 + 1;?>)
{ {
@ -197,11 +224,13 @@ function reset()
used_letters_all = ""; used_letters_all = "";
wrong_guesses = 0; wrong_guesses = 0;
showallletters(); showallletters();
<?php <?php
if( $html->type != 'hangmanp'){ if ($html->type != 'hangmanp') {
echo ' document.hm.src="hangman_0.jpg"'."\r"; echo ' document.hm.src="hangman_0.jpg"'."\r";
} }
?> ?>
} }
function showallletters() function showallletters()
@ -244,10 +273,11 @@ function selectWord()
display_word = masked_word; display_word = masked_word;
<?php <?php
if( $html->type == 'hangmanp') if ($html->type == 'hangmanp') {
echo " document.hm.src = images[ random_number];\r"; echo " document.hm.src = images[ random_number];\r";
else } else {
echo " document.getElementById('question').innerHTML=to_question;\r"; echo " document.getElementById('question').innerHTML=to_question;\r";
}
?> ?>
} }
@ -349,7 +379,8 @@ var Base64 = {
</head> </head>
<div id="question"></div> <div id="question"></div>
<img src="<?php echo ($html->type == 'hangmanp' ? '' : 'hangman_0.jpg');?>" name="hm"> <a href="javascript:reset();"><?php echo game_get_string_lang( 'html_hangman_new', 'game', $lang); ?></a> <img src="<?php echo ($html->type == 'hangmanp' ? '' : 'hangman_0.jpg');?>" name="hm">
<a href="javascript:reset();"><?php echo game_get_string_lang( 'html_hangman_new', 'game', $lang); ?></a>
<form name="game"> <form name="game">
<div id="displayWord"> </div> <div id="displayWord"> </div>
<div id="usedLetters"> </div> <div id="usedLetters"> </div>

320
exporthtml_millionaire.php

@ -1,4 +1,19 @@
<?php // $Id: exporthtml_millionaire.php,v 1.14 2012/07/25 11:16:03 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This page export the game millionaire to html * This page export the game millionaire to html
* *
@ -6,93 +21,93 @@
* @version $Id: exporthtml_millionaire.php,v 1.14 2012/07/25 11:16:03 bdaloukas Exp $ * @version $Id: exporthtml_millionaire.php,v 1.14 2012/07/25 11:16:03 bdaloukas Exp $
* @package game * @package game
**/ **/
function game_millionaire_html_getquestions( $game, $context, &$maxanswers, &$countofquestions, &$retfeedback, $destdir, &$files) function game_millionaire_html_getquestions( $game, $context, &$maxanswers, &$countofquestions, &$retfeedback, $destdir, &$files) {
{ global $CFG, $DB, $USER;
global $CFG, $DB, $USER;
$maxanswers = 0;
$maxanswers = 0;
$countofquestions = 0; $countofquestions = 0;
$files = array(); $files = array();
if( ($game->sourcemodule != 'quiz') and ($game->sourcemodule != 'question')){
print_error( get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string( 'modulename', 'quiz')).' '.get_string( 'modulename', $game->sourcemodule));
}
if( $game->sourcemodule == 'quiz'){
if( $game->quizid == 0){
print_error( get_string( 'must_select_quiz', 'game'));
}
$select = "qtype='multichoice' AND quiz='$game->quizid' ".
" AND qqi.question=q.id";
$table = "{question} q,{quiz_question_instances} qqi";
}else
{
if( $game->questioncategoryid == 0){
print_error( get_string( 'must_select_questioncategory', 'game'));
}
//include subcategories if ( ($game->sourcemodule != 'quiz') and ($game->sourcemodule != 'question')) {
$select = 'category='.$game->questioncategoryid; print_error( get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string( 'modulename', 'quiz')).
if( $game->subcategories){ ' '.get_string( 'modulename', $game->sourcemodule));
}
if ( $game->sourcemodule == 'quiz') {
if ( $game->quizid == 0) {
print_error( get_string( 'must_select_quiz', 'game'));
}
$select = "qtype='multichoice' AND quiz='$game->quizid' ".
" AND qqi.question=q.id";
$table = "{question} q,{quiz_question_instances} qqi";
} else {
if ( $game->questioncategoryid == 0) {
print_error( get_string( 'must_select_questioncategory', 'game'));
}
// Include subcategories.
$select = 'category='.$game->questioncategoryid;
if ( $game->subcategories) {
$cats = question_categorylist( $game->questioncategoryid); $cats = question_categorylist( $game->questioncategoryid);
if( strpos( $cats, ',') > 0){ if (strpos( $cats, ',') > 0) {
$select = 'category in ('.$cats.')'; $select = 'category in ('.$cats.')';
} }
} }
$select .= " AND qtype='multichoice'"; $select .= " AND qtype='multichoice'";
$table = "{question} q"; $table = "{question} q";
} }
$select .= " AND q.hidden=0"; $select .= " AND q.hidden=0";
$sql = "SELECT q.id as id, q.questiontext FROM $table WHERE $select"; $sql = "SELECT q.id as id, q.questiontext FROM $table WHERE $select";
$recs = $DB->get_records_sql( $sql); $recs = $DB->get_records_sql( $sql);
$ret = ''; $ret = '';
$retfeedback = ''; $retfeedback = '';
foreach( $recs as $rec){ foreach ($recs as $rec) {
$recs2 = $DB->get_records( 'question_answers', array( 'question' => $rec->id), 'fraction DESC', 'id,answer,feedback'); $recs2 = $DB->get_records( 'question_answers', array( 'question' => $rec->id), 'fraction DESC', 'id,answer,feedback');
//Must parse the questiontext and get the name of files. // Must parse the questiontext and get the name of files.
$line = $rec->questiontext; $line = $rec->questiontext;
$line = game_export_split_files( $game->course, $context, 'questiontext', $rec->id, $rec->questiontext, $destdir, $files); $line = game_export_split_files( $game->course, $context, 'questiontext', $rec->id, $rec->questiontext, $destdir, $files);
$linefeedback = ''; $linefeedback = '';
foreach( $recs2 as $rec2) foreach ($recs2 as $rec2) {
{ $line .= '#'.str_replace( array( '"', '#'), array( "'", ' '),
$line .= '#'.str_replace( array( '"', '#'), array( "'", ' '), game_export_split_files( $game->course, $context, 'answer', $rec2->id, $rec2->answer, $destdir, $files)); game_export_split_files( $game->course, $context, 'answer', $rec2->id, $rec2->answer, $destdir, $files));
$linefeedback .= '#'.str_replace( array( '"', '#'), array( "'", ' '), $rec2->feedback); $linefeedback .= '#'.str_replace( array( '"', '#'), array( "'", ' '), $rec2->feedback);
} }
if( $ret != '') if ( $ret != '') {
$ret .= ",\r"; $ret .= ",\r";
$ret .= '"'.base64_encode( $line).'"'; }
$ret .= '"'.base64_encode( $line).'"';
if( $retfeedback != '')
$retfeedback .= ",\r"; if ( $retfeedback != '') {
$retfeedback .= '"'.base64_encode( $linefeedback).'"'; $retfeedback .= ",\r";
}
$retfeedback .= '"'.base64_encode( $linefeedback).'"';
if( count( $recs2) > $maxanswers) if ( count( $recs2) > $maxanswers) {
$maxanswers = count( $recs2); $maxanswers = count( $recs2);
}
$countofquestions++; $countofquestions++;
} }
return $ret; return $ret;
} }
function game_millionaire_html_print( $game, $questions, $maxquestions) function game_millionaire_html_print( $game, $questions, $maxquestions) {
{ $color1 = 'black';
$color1 = 'black'; $color2 = 'DarkOrange';
$color2 = 'DarkOrange'; $colorback = "white";
$colorback="white"; $stylequestion = "background:$colorback;color:$color1";
$stylequestion = "background:$colorback;color:$color1"; $stylequestionselected = "background:$colorback;color:$color2";
$stylequestionselected = "background:$colorback;color:$color2";
?> ?>
<body onload="Reset();"> <body onload="Reset();">
<script type="text/javascript"> <script type="text/javascript">
//Millionaire for Moodle by Vasilis Daloukas // Millionaire for Moodle by Vasilis Daloukas.
<?php echo 'var questions = new Array('.$questions.");\r"; ?> <?php echo 'var questions = new Array('.$questions.");\r"; ?>
var current_question = 0; var current_question = 0;
var level = 0; var level = 0;
@ -104,38 +119,31 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
var countQuestions = 0; var countQuestions = 0;
var maxQuestions = <?php echo $maxquestions;?>; var maxQuestions = <?php echo $maxquestions;?>;
function Highlite( ans) function Highlite( ans) {
{
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $color2;?>'; document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $color2;?>';
} }
function Restore( ans) function Restore( ans) {
{
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $colorback;?>'; document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $colorback;?>';
} }
function OnSelectAnswer( ans) function OnSelectAnswer( ans) {
{ if ( posCorrect == ans) {
if( posCorrect == ans) if( level+1 > 15) {
{
if( level+1 > 15)
{
alert( "<?php echo get_string( 'win', 'game');?>"); alert( "<?php echo get_string( 'win', 'game');?>");
Reset(); Reset();
}else } else {
{
UpdateLevel( level+1); UpdateLevel( level+1);
SelectNextQuestion(); SelectNextQuestion();
} }
}else } else {
{
OnGameOver( ans); OnGameOver( ans);
} }
} }
function OnGameOver( ans) function OnGameOver( ans) {
{ document.getElementById( "info").innerHTML = "<?php echo get_string( 'millionaire_info_wrong_answer', 'game');?> " +
document.getElementById( "info").innerHTML = "<?php echo get_string( 'millionaire_info_wrong_answer', 'game');?> "+document.getElementById( "lblAnswer" + posCorrect).innerHTML; document.getElementById( "lblAnswer" + posCorrect).innerHTML;
Highlite( posCorrect); Highlite( posCorrect);
Restore( ans); Restore( ans);
document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $color2;?>'; document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $color2;?>';
@ -148,10 +156,8 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
Reset(); Reset();
} }
function UpdateLevel( newlevel) function UpdateLevel( newlevel) {
{ if ( level > 0) {
if( level > 0)
{
document.getElementById( "levela" + level).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levela" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + level).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levelb" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + level).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levelc" + level).bgColor = "<?php echo $colorback;?>";
@ -170,77 +176,73 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
document.getElementById( "levelc" + level).style.color = "<?php echo $colorback;?>"; document.getElementById( "levelc" + level).style.color = "<?php echo $colorback;?>";
} }
function OnHelp5050( ans) function OnHelp5050( ans) {
{ if (flag5050) {
if( flag5050)
return; return;
}
document.getElementById( "Help5050").src = "5050x.png"; document.getElementById( "Help5050").src = "5050x.png";
flag5050 = 1; flag5050 = 1;
for(pos = posCorrect;pos == posCorrect;pos = 1+Math.floor(Math.random()*countQuestions));
for( i=1; i <= countQuestions; i++) for (pos = posCorrect;pos == posCorrect;pos = 1+Math.floor(Math.random()*countQuestions));
{
if( (i != pos) && (i != posCorrect)) for (i=1; i <= countQuestions; i++) {
{ if( (i != pos) && (i != posCorrect)) {
document.getElementById( "lblAnswer" + i).style.visibility = 'hidden'; document.getElementById( "lblAnswer" + i).style.visibility = 'hidden';
document.getElementById( "btAnswer" + i).style.visibility = 'hidden'; document.getElementById( "btAnswer" + i).style.visibility = 'hidden';
} }
} }
} }
function OnHelpTelephone( ans) function OnHelpTelephone( ans) {
{ if( flagTelephone) {
if( flagTelephone)
return; return;
}
flagTelephone = 1; flagTelephone = 1;
document.getElementById( "HelpTelephone").src = "telephonex.png"; document.getElementById( "HelpTelephone").src = "telephonex.png";
if( countQuestions < 2){ if (countQuestions < 2) {
wrong = posCorrect; wrong = posCorrect;
}else } else {
{ for(;;) {
for(;;) wrong = 1 + Math.floor(Math.random() * countQuestions);
{ if ( wrong != posCorrect) {
wrong = 1+Math.floor(Math.random()*countQuestions);
if( wrong != posCorrect)
break; break;
}
} }
} }
//with 80% gives the correct answer
if( Math.random() <= 0.8) // With 80% gives the correct answer.
if (Math.random() <= 0.8) {
pos = posCorrect; pos = posCorrect;
else } else {
pos = wrong; pos = wrong;
}
info = "<?php echo get_string( 'millionaire_info_telephone','game').'<br><b>';?> "; info = "<?php echo get_string( 'millionaire_info_telephone', 'game').'<br><b>';?> ";
info += document.getElementById( "lblAnswer" + pos).innerHTML; info += document.getElementById( "lblAnswer" + pos).innerHTML;
document.getElementById( "info").innerHTML = info; document.getElementById( "info").innerHTML = info;
} }
function OnHelpPeople( ans) function OnHelpPeople( ans) {
{ if( flagPeople) {
if( flagPeople)
return; return;
}
flagPeople = 1; flagPeople = 1;
document.getElementById( "HelpPeople").src = "peoplex.png"; document.getElementById( "HelpPeople").src = "peoplex.png";
sum = 0; sum = 0;
var aPercent = new Array(); var aPercent = new Array();
for( i = 0; i < countQuestions-1; i++) for( i = 0; i < countQuestions-1; i++) {
{
percent = Math.floor(Math.random()*(100-sum)); percent = Math.floor(Math.random()*(100-sum));
aPercent[ i] = percent; aPercent[ i] = percent;
sum += percent; sum += percent;
} }
aPercent[ countQuestions - 1] = 100 - sum; aPercent[ countQuestions - 1] = 100 - sum;
if( Math.random() <= 0.8) if( Math.random() <= 0.8) {
{
//with percent 80% sets in the correct answer the biggest percent //with percent 80% sets in the correct answer the biggest percent
max_pos = 0; max_pos = 0;
for( i=1; i < countQuestions; i++) for( i=1; i < countQuestions; i++) {
{
if( aPercent[ i] >= aPercent[ max_pos]) if( aPercent[ i] >= aPercent[ max_pos])
max_pos = i; max_pos = i;
} }
@ -251,22 +253,19 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
var letters = "<?php echo get_string( 'lettersall', 'game');?>"; var letters = "<?php echo get_string( 'lettersall', 'game');?>";
info = "<?php echo '<br>'.get_string( 'millionaire_info_people', 'game').':<br>';?>"; info = "<?php echo '<br>'.get_string( 'millionaire_info_people', 'game').':<br>';?>";
for( i=0; i < countQuestions; i++){ for( i=0; i < countQuestions; i++) {
info += "<br>" + letters.charAt( i) + " : " + aPercent[ i] + " %"; info += "<br>" + letters.charAt( i) + " : " + aPercent[ i] + " %";
} }
document.getElementById( "info").innerHTML = info; document.getElementById( "info").innerHTML = info;
} }
function OnQuit( ans) function OnQuit( ans) {
{
Reset(); Reset();
} }
function Reset() function Reset() {
{ for(i=1; i <= 15; i++) {
for(i=1; i <= 15; i++)
{
document.getElementById( "levela" + i).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levela" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + i).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levelb" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + i).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levelc" + i).bgColor = "<?php echo $colorback;?>";
@ -274,11 +273,11 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
document.getElementById( "levelb" + i).style.color = "<?php echo $color1;?>"; document.getElementById( "levelb" + i).style.color = "<?php echo $color1;?>";
document.getElementById( "levelc" + i).style.color = "<?php echo $color1;?>"; document.getElementById( "levelc" + i).style.color = "<?php echo $color1;?>";
} }
flag5050 = 0; flag5050 = 0;
flagTelephone = 0; flagTelephone = 0;
flagPeople = 0; flagPeople = 0;
document.getElementById( "Help5050").src = "5050.png"; document.getElementById( "Help5050").src = "5050.png";
document.getElementById( "HelpPeople").src = "people.png"; document.getElementById( "HelpPeople").src = "people.png";
document.getElementById( "HelpTelephone").src = "telephone.png"; document.getElementById( "HelpTelephone").src = "telephone.png";
@ -288,17 +287,15 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
SelectNextQuestion(); SelectNextQuestion();
} }
function RandomizeAnswers( elements) function RandomizeAnswers( elements) {
{
posCorrect = 1; posCorrect = 1;
countQuestions = elements.length-1; countQuestions = elements.length-1;
for( i=1; i <= countQuestions; i++) for( i=1; i <= countQuestions; i++) {
{
pos = 1+Math.floor(Math.random()*countQuestions); pos = 1+Math.floor(Math.random()*countQuestions);
if( posCorrect == i) if( posCorrect == i) {
posCorrect = pos; posCorrect = pos;
else if( posCorrect == pos) } else if ( posCorrect == pos)
posCorrect = i; posCorrect = i;
var temp = elements[ i]; var temp = elements[ i];
@ -418,19 +415,22 @@ var Base64 = {
<table cellpadding=0 cellspacing=0 border=0> <table cellpadding=0 cellspacing=0 border=0>
<tr style='background:#408080'> <tr style='background:#408080'>
<td rowspan=<?php echo 17+$maxquestions;?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td rowspan=<?php echo 17 + $maxquestions;?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td colspan=6>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td colspan=6>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td rowspan=<?php echo 17+$maxquestions;?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td rowspan=<?php echo 17 + $maxquestions;?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr> </tr>
<tr height=10%> <tr height=10%>
<td style='background:#408080' rowspan=3 colspan=2> <td style='background:#408080' rowspan=3 colspan=2>
<input type="image" name="Help5050" id="Help5050" Title="50 50" src="5050.png" alt="" border="0" onmousedown=OnHelp5050();>&nbsp; <input type="image" name="Help5050" id="Help5050" Title="50 50" src="5050.png" alt="" border="0" onmousedown=OnHelp5050();>&nbsp;
<input type="image" name="HelpTelephone" id="HelpTelephone" Title="<?php echo get_string( 'millionaire_telephone', 'game');?>" src="telephone.png" alt="" border="0" onmousedown="OnHelpTelephone();">&nbsp; <input type="image" name="HelpTelephone" id="HelpTelephone" Title="<?php echo get_string( 'millionaire_telephone', 'game');?>"
<input type="image" name="HelpPeople" id="HelpPeople" Title="<?php echo get_string( 'millionaire_helppeople', 'game');?>" src="people.png" alt="" border="0" onmousedown="OnHelpPeople();">&nbsp; src="telephone.png" alt="" border="0" onmousedown="OnHelpTelephone();">&nbsp;
<input type="image" name="Quit" id="Quit" Title="<?php echo get_string( 'millionaire_quit', 'game');?>" src="x.png" alt="" border="0" onmousedown=OnQuit();>&nbsp; <input type="image" name="HelpPeople" id="HelpPeople" Title="<?php echo get_string( 'millionaire_helppeople', 'game');?>"
src="people.png" alt="" border="0" onmousedown="OnHelpPeople();">&nbsp;
<input type="image" name="Quit" id="Quit" Title="<?php echo get_string( 'millionaire_quit', 'game');?>"
src="x.png" alt="" border="0" onmousedown=OnQuit();>&nbsp;
</td> </td>
<td rowspan=<?php echo 16+$maxquestions;?> style='background:#408080'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td rowspan=<?php echo 16 + $maxquestions;?> style='background:#408080'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td id="levela15" align=right>15</td> <td id="levela15" align=right>15</td>
<td id="levelb15">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td id="levelb15">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td id="levelc15" align=right> 150000</td> <td id="levelc15" align=right> 150000</td>
@ -444,7 +444,8 @@ var Base64 = {
<td id="levelb13"></td><td id="levelc13" align=right> 400000</td> <td id="levelb13"></td><td id="levelc13" align=right> 400000</td>
</tr> </tr>
<tr><td rowspan=12 colspan=2 valign=top style='background:<?php echo $colorback;?>;color:<?php echo $color1;?>'><div id="question">aa</div></td> <tr><td rowspan=12 colspan=2 valign=top style='background:<?php echo $colorback;?>;color:<?php echo $color1;?>'>
<div id="question">aa</div></td>
<td id="levela12" align=r0ight>12</div></td> <td id="levela12" align=r0ight>12</div></td>
<td id="levelb12"></td><td id="levelc12" align=right> 200000</td> <td id="levelb12"></td><td id="levelc12" align=right> 200000</td>
</tr> </tr>
@ -497,22 +498,23 @@ var Base64 = {
</tr> </tr>
<?php <?php
$letters = get_string( 'lettersall', 'game'); $letters = get_string( 'lettersall', 'game');
for($i=1 ; $i <= $maxquestions; $i++) for ($i = 1; $i <= $maxquestions; $i++) {
{ $s = game_substr( $letters, $i - 1, 1);
$s = game_substr( $letters, $i-1, 1); echo "<tr>\n";
echo "<tr>\n"; echo "<td style='background:$colorback;color:$color1'>";
echo "<td style='background:$colorback;color:$color1'>"; echo "<input style=\"background:$colorback;color:$color1;\"
echo "<input style=\"background:$colorback;color:$color1;\" type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\""; type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\"";
echo " onmouseover=\"Highlite( $i);\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\">"; echo " onmouseover=\"Highlite( $i);\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\">";
echo "</td>\n"; echo "</td>\n";
echo "<td style=\"background:$colorback;color:$color1;\" width=100%> &nbsp; <span id=lblAnswer$i style=\"background:$colorback;color:$color1\" onmouseover=\"Highlite($i);\r \n\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\"></span></td>\n"; echo "<td style=\"background:$colorback;color:$color1;\" width=100%> &nbsp; <span id=lblAnswer$i
if( $i == 1) style=\"background:$colorback;color:$color1\"
{ onmouseover=\"Highlite($i);\r \n\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\"></span></td>\n";
echo "<td style='background:#408080' rowspan=".$maxquestions." colspan=3><div id=\"info\"></div></td>\n"; if ( $i == 1) {
echo "<td style='background:#408080' rowspan=".$maxquestions." colspan=3><div id=\"info\"></div></td>\n";
}
echo "</tr>\n";
} }
echo "</tr>\n";
}
?> ?>
<tr><td colspan=10 style='background:#408080'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr> <tr><td colspan=10 style='background:#408080'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>

673
exportjavame.php

@ -1,4 +1,19 @@
<?php // $Id: exportjavame.php,v 1.18 2012/07/25 11:16:03 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This page export the game to javame for mobile phones * This page export the game to javame for mobile phones
* *
@ -6,386 +21,384 @@
* @version $Id: exportjavame.php,v 1.18 2012/07/25 11:16:03 bdaloukas Exp $ * @version $Id: exportjavame.php,v 1.18 2012/07/25 11:16:03 bdaloukas Exp $
* @package game * @package game
**/ **/
function game_OnExportJavaME( $game, $javame){
global $CFG, $DB;
$courseid = $game->course;
$course = $DB->get_record( 'course', array( 'id' => $courseid));
$destdir = game_export_createtempdir();
if( $javame->type == 'hangmanp'){
$destmobiledir = 'hangmanp';
}else{
$destmobiledir = 'hangman';
}
$src = $CFG->dirroot.'/mod/game/export/javame/'.$destmobiledir.'/simple';
if( $javame->filename == ''){
$javame->filename = 'moodle'.$destmobiledir;
}
$handle = opendir( $src);
while (false!==($item = readdir($handle))) {
if($item != '.' && $item != '..') {
if(!is_dir($src.'/'.$item)) {
$itemdest = $item;
if( substr( $item, -5) == '.java'){
continue; //don't copy the java source code files
}
if( substr( $itemdest, -8) == '-1.class'){
$itemdest = substr( $itemdest, 0, -8).'$1.class';
}
copy( $src.'/'.$item, $destdir.'/'.$itemdest);
}
}
}
mkdir( $destdir.'/META-INF');
game_exportjavame_exportdata( $src, $destmobiledir, $destdir, $game, $javame->maxpicturewidth, $javame->maxpictureheight);
game_create_manifest_mf( $destdir.'/META-INF', $javame, $destmobiledir);
$filejar = game_create_jar( $destdir, $course, $javame);
if( $filejar == ''){
$filezip = game_create_zip( $destdir, $course->id, $javame->filename.'.zip');
}else{
$filezip = '';
}
if( $destdir != ''){ function game_onexportjavame( $game, $javame) {
remove_dir( $destdir); global $CFG, $DB;
}
$courseid = $game->course;
if( $filezip != ''){ $course = $DB->get_record( 'course', array( 'id' => $courseid));
echo "unzip the $filezip in a directory and when you are in this directory use the command <br><b>jar cvfm {$javame->filename}.jar META-INF/MANIFEST.MF<br></b> to produce the jar files<br><br>";
} $destdir = game_export_createtempdir();
$file = ($filejar != '' ? $filejar : $filezip); if ( $javame->type == 'hangmanp') {
game_send_stored_file( $file); $destmobiledir = 'hangmanp';
} else {
$destmobiledir = 'hangman';
} }
$src = $CFG->dirroot.'/mod/game/export/javame/'.$destmobiledir.'/simple';
function game_exportjavame_exportdata( $src, $destmobiledir, $destdir, $game, $maxwidth, $maxheight){
global $CFG; if ( $javame->filename == '') {
$javame->filename = 'moodle'.$destmobiledir;
mkdir( $destdir.'/'.$destmobiledir); }
$handle = opendir( $src); $handle = opendir( $src);
while (false!==($item = readdir($handle))) { while (false !== ($item = readdir($handle))) {
if($item != '.' && $item != '..') { if ($item != '.' && $item != '..') {
if(!is_dir($src.'/'.$item)) { if (!is_dir($src.'/'.$item)) {
if( substr( $item, -4) == '.jpg'){ $itemdest = $item;
copy( $src.'/'.$item, $destdir."/$destmobiledir/".$item);
} if (substr( $item, -5) == '.java') {
} continue; // Don't copy the java source code files.
} }
}
if (substr( $itemdest, -8) == '-1.class') {
$lang = $game->language; $itemdest = substr( $itemdest, 0, -8).'$1.class';
if( $lang == '') }
$lang = current_language();
copy( $src. '/lang/'.$lang.'/language.txt', $destdir."/$destmobiledir/language.txt"); copy( $src.'/'.$item, $destdir.'/'.$itemdest);
$export_attachment = ( $destmobiledir == 'hangmanp');
$map = game_exmportjavame_getanswers( $game, $export_attachment, false, $destdir, $files);
if( $map == false){
print_error( 'No Questions');
}
if( $destmobiledir == 'hangmanp'){
game_exportjavame_exportdata_hangmanp( $src, $destmobiledir, $destdir, $game, $map, $maxwidth, $maxheight);
return;
}
$fp = fopen( $destdir."/$destmobiledir/hangman.txt","w");
fputs( $fp, "1.txt=$destmobiledir\r\n");
fclose( $fp);
$fp = fopen( $destdir."/$destmobiledir/1.txt","w");
foreach( $map as $line){
$s = game_upper( $line->answer) . '=' . $line->question;
fputs( $fp, "$s\r\n");
} }
fclose( $fp); }
}
mkdir( $destdir.'/META-INF');
game_exportjavame_exportdata( $src, $destmobiledir, $destdir, $game, $javame->maxpicturewidth, $javame->maxpictureheight);
game_create_manifest_mf( $destdir.'/META-INF', $javame, $destmobiledir);
$filejar = game_create_jar( $destdir, $course, $javame);
if ($filejar == '') {
$filezip = game_create_zip( $destdir, $course->id, $javame->filename.'.zip');
} else {
$filezip = '';
}
if ($destdir != '') {
remove_dir( $destdir);
}
if ($filezip != '') {
echo "unzip the $filezip in a directory and when you are in this directory use the command <br><b>jar ".
"cvfm {$javame->filename}.jar META-INF/MANIFEST.MF<br></b> to produce the jar files<br><br>";
} }
function game_exportjavame_exportdata_hangmanp( $src, $destmobiledir, $destdir, $game, $map, $maxwidth, $maxheight) $file = ($filejar != '' ? $filejar : $filezip);
{ game_send_stored_file( $file);
global $CFG; }
$fp = fopen( $destdir."/$destmobiledir/$destmobiledir.txt","w"); function game_exportjavame_exportdata( $src, $destmobiledir, $destdir, $game, $maxwidth, $maxheight) {
fputs( $fp, "01=01\r\n"); global $CFG;
fclose( $fp);
mkdir( $destdir.'/'.$destmobiledir);
$destdirphoto = $destdir.'/'.$destmobiledir.'/01';
mkdir( $destdirphoto); $handle = opendir( $src);
while (false !== ($item = readdir($handle))) {
$fp = fopen( $destdirphoto.'/photo.txt',"w"); if ($item != '.' && $item != '..') {
foreach( $map as $line){ if (!is_dir($src.'/'.$item)) {
if (substr( $item, -4) == '.jpg') {
$file = $line->attachment; copy( $src.'/'.$item, $destdir."/$destmobiledir/".$item);
$pos = strrpos( $file, '.');
if( $pos != false){
$file = $line->id.substr( $file, $pos);
$src = $CFG->dataroot.'/'.$game->course.'/moddata/'.$line->attachment;
game_export_javame_smartcopyimage( $src, $destdirphoto.'/'.$file, $maxwidth, $maxheight);
$s = $file . '=' . game_upper( $line->answer);
fputs( $fp, "$s\r\n");
} }
} }
fclose( $fp); }
}
$lang = $game->language;
if ($lang == '') {
$lang = current_language();
} }
copy( $src. '/lang/'.$lang.'/language.txt', $destdir."/$destmobiledir/language.txt");
function game_exmportjavame_getanswers( $game, $context, $export_attachment, $dest, &$files){
$map = array(); $exportattachment = ( $destmobiledir == 'hangmanp');
$files = array();
$map = game_exmportjavame_getanswers( $game, $exportattachment, false, $destdir, $files);
switch( $game->sourcemodule){ if ($map == false) {
print_error( 'No Questions');
}
if ($destmobiledir == 'hangmanp') {
game_exportjavame_exportdata_hangmanp( $src, $destmobiledir, $destdir, $game, $map, $maxwidth, $maxheight);
return;
}
$fp = fopen( $destdir."/$destmobiledir/hangman.txt", "w");
fputs( $fp, "1.txt=$destmobiledir\r\n");
fclose( $fp);
$fp = fopen( $destdir."/$destmobiledir/1.txt", "w");
foreach ($map as $line) {
$s = game_upper( $line->answer) . '=' . $line->question;
fputs( $fp, "$s\r\n");
}
fclose( $fp);
}
function game_exportjavame_exportdata_hangmanp( $src, $destmobiledir, $destdir, $game, $map, $maxwidth, $maxheight) {
global $CFG;
$fp = fopen( $destdir."/$destmobiledir/$destmobiledir.txt", "w");
fputs( $fp, "01=01\r\n");
fclose( $fp);
$destdirphoto = $destdir.'/'.$destmobiledir.'/01';
mkdir( $destdirphoto);
$fp = fopen( $destdirphoto.'/photo.txt', "w");
foreach ($map as $line) {
$file = $line->attachment;
$pos = strrpos( $file, '.');
if ($pos != false) {
$file = $line->id.substr( $file, $pos);
$src = $CFG->dataroot.'/'.$game->course.'/moddata/'.$line->attachment;
game_export_javame_smartcopyimage( $src, $destdirphoto.'/'.$file, $maxwidth, $maxheight);
$s = $file . '=' . game_upper( $line->answer);
fputs( $fp, "$s\r\n");
}
}
fclose( $fp);
}
function game_exmportjavame_getanswers( $game, $context, $exportattachment, $dest, &$files) {
$map = array();
$files = array();
switch ($game->sourcemodule) {
case 'question': case 'question':
return game_exmportjavame_getanswers_question( $game, $context, $dest, $files); return game_exmportjavame_getanswers_question( $game, $context, $dest, $files);
case 'glossary': case 'glossary':
return game_exmportjavame_getanswers_glossary( $game, $context, $export_attachment, $dest, $files); return game_exmportjavame_getanswers_glossary( $game, $context, $exportattachment, $dest, $files);
case 'quiz': case 'quiz':
return game_exmportjavame_getanswers_quiz( $game, $context, $dest, $files); return game_exmportjavame_getanswers_quiz( $game, $context, $dest, $files);
}
return false;
}
function game_exmportjavame_getanswers_question( $game, $context, $destdir, &$files){
$select = 'hidden = 0 AND category='.$game->questioncategoryid;
$select .= game_showanswers_appendselect( $game);
return game_exmportjavame_getanswers_question_select( $game, $context, 'question', $select, '*', $game->course, $destdir, $files);
} }
function game_exmportjavame_getanswers_quiz( $game, $context, $destdir, $files) return false;
{ }
global $CFG;
function game_exmportjavame_getanswers_question( $game, $context, $destdir, &$files) {
$select = "quiz='$game->quizid' ". $select = 'hidden = 0 AND category='.$game->questioncategoryid;
" AND qqi.question=q.id".
" AND q.hidden=0". $select .= game_showanswers_appendselect( $game);
game_showanswers_appendselect( $game);
$table = "{question} q,{quiz_question_instances} qqi"; return game_exmportjavame_getanswers_question_select( $game, $context, 'question',
$select, '*', $game->course, $destdir, $files);
return game_exmportjavame_getanswers_question_select( $game, $context, $table, $select, "q.*", $game->course, $destdir, $files); }
function game_exmportjavame_getanswers_quiz( $game, $context, $destdir, $files) {
global $CFG;
$select = "quiz='$game->quizid' ".
" AND qqi.question=q.id".
" AND q.hidden=0".
game_showanswers_appendselect( $game);
$table = "{question} q,{quiz_question_instances} qqi";
return game_exmportjavame_getanswers_question_select( $game, $context, $table, $select, "q.*", $game->course, $destdir, $files);
}
function game_exmportjavame_getanswers_question_select( $game, $context, $table, $select, $fields, $courseid, $destdir, &$files) {
global $CFG, $DB;
if (($questions = $DB->get_records_select( $table, $select, null, '', $fields)) === false) {
return;
} }
function game_exmportjavame_getanswers_question_select( $game, $context, $table, $select, $fields, $courseid, $destdir, &$files)
{
global $CFG, $DB;
if( ($questions = $DB->get_records_select( $table, $select, null, '', $fields)) === false){
return;
}
$line = 0;
$line = 0; $map = array();
$map = array(); foreach ($questions as $question) {
foreach( $questions as $question){ unset( $ret);
unset( $ret); $ret->qtype = $question->qtype;
$ret->qtype = $question->qtype; $ret->question = $question->questiontext;
$ret->question = $question->questiontext; $ret->question = str_replace( array( '"', '#'), array( "'", ' '),
$ret->question = str_replace( array( '"', '#'), array( "'", ' '), game_export_split_files( $game->course, $context, 'questiontext',
game_export_split_files( $game->course, $context, 'questiontext', $question->id, $ret->question, $destdir, $files)); $question->id, $ret->question, $destdir, $files));
switch( $question->qtype){ switch ($question->qtype) {
case 'shortanswer': case 'shortanswer':
$rec = $DB->get_record( 'question_answers', array( 'question' => $question->id), 'id,answer,feedback'); $rec = $DB->get_record( 'question_answers', array( 'question' => $question->id),
$ret->answer = $rec->answer; 'id,answer,feedback');
$ret->feedback = $rec->feedback; $ret->answer = $rec->answer;
$map[] = $ret; $ret->feedback = $rec->feedback;
$map[] = $ret;
break; break;
default: default:
break; break;
}
} }
return $map;
} }
function game_exmportjavame_getanswers_glossary( $game, $context, $export_attachment, $destdir, &$files)
{
global $CFG, $DB;
$table = '{glossary_entries} ge';
$select = "glossaryid={$game->glossaryid}";
if( $game->glossarycategoryid){
$select .= " AND gec.entryid = ge.id ".
" AND gec.categoryid = {$game->glossarycategoryid}";
$table .= ",{glossary_entries_categories} gec";
}
if( $export_attachment){
$select .= " AND attachment <> ''";
}
$fields = 'ge.id,definition,concept';
if( $export_attachment){
$fields .= ',attachment';
}
$sql = "SELECT $fields FROM $table WHERE $select ORDER BY definition";
if( ($questions = $DB->get_records_sql( $sql)) === false){
return false;
}
$fs = get_file_storage(); return $map;
$map = array(); }
$cmglossary = false;
function game_exmportjavame_getanswers_glossary( $game, $context, $exportattachment, $destdir, &$files) {
foreach( $questions as $question){ global $CFG, $DB;
$ret = new stdClass();
$ret->id = $question->id; $table = '{glossary_entries} ge';
$ret->qtype = 'shortanswer'; $select = "glossaryid={$game->glossaryid}";
$ret->question = strip_tags( $question->definition); if ($game->glossarycategoryid) {
$ret->answer = $question->concept; $select .= " AND gec.entryid = ge.id ".
$ret->feedback = ''; " AND gec.categoryid = {$game->glossarycategoryid}";
$ret->attachment = ''; $table .= ",{glossary_entries_categories} gec";
}
//Copies the appropriate files from the file storage to destdir
if( $export_attachment){ if ($exportattachment) {
if( $question->attachment != ''){ $select .= " AND attachment <> ''";
if( $cmglossary === false) }
{
$cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $fields = 'ge.id,definition,concept';
$contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id); if ($exportattachment) {
$fields .= ',attachment';
}
$sql = "SELECT $fields FROM $table WHERE $select ORDER BY definition";
if ($questions = $DB->get_records_sql( $sql)) === false) {
return false;
}
$fs = get_file_storage();
$map = array();
$cmglossary = false;
foreach ($questions as $question) {
$ret = new stdClass();
$ret->id = $question->id;
$ret->qtype = 'shortanswer';
$ret->question = strip_tags( $question->definition);
$ret->answer = $question->concept;
$ret->feedback = '';
$ret->attachment = '';
// Copies the appropriate files from the file storage to destdir.
if ($exportattachment) {
if ($question->attachment != '') {
if ($cmglossary === false) {
$cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course);
$contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id);
}
$ret->attachment = "glossary/{$game->glossaryid}/$question->id/$question->attachment";
$myfiles = $fs->get_area_files( $contextglossary->id, 'mod_glossary', 'attachment', $ret->id);
$i = 0;
foreach ($myfiles as $f) {
if ($f->is_directory()) {
continue;
} }
$filename = $f->get_filename();
$ret->attachment = "glossary/{$game->glossaryid}/$question->id/$question->attachment"; $url = "{$CFG->wwwroot}/pluginfile.php/{$f->get_contextid()}/mod_glossary/attachment}";
$myfiles = $fs->get_area_files( $contextglossary->id, 'mod_glossary', 'attachment', $ret->id); $fileurl = $url.$f->get_filepath().$f->get_itemid().'/'.$filename;
$i=0; $pos = strrpos( $filename, '.');
foreach ($myfiles as $f) { $ext = substr( $filename, $pos);
if( $f->is_directory()) $destfile = $ret->id;
continue; if ($i > 0) {
$filename = $f->get_filename(); $destfile .= '_'.$i;
$url = "{$CFG->wwwroot}/pluginfile.php/{$f->get_contextid()}/mod_glossary/attachment}"; }
$fileurl = $url.$f->get_filepath().$f->get_itemid().'/'.$filename; $destfile = $destdir.'/'.$destfile.$ext;
$pos = strrpos( $filename, '.'); $f->copy_content_to( $destfile);
$ext = substr( $filename, $pos); $ret->attachment = $destfile;
$destfile = $ret->id; $i++;
if( $i > 0) $files[] = $destfile;
$destfile .= '_'.$i;
$destfile = $destdir.'/'.$destfile.$ext;
$f->copy_content_to( $destfile);
$ret->attachment = $destfile;
$i++;
$files[] = $destfile;
}
} }
} }
$map[] = $ret;
} }
return $map; $map[] = $ret;
} }
function game_create_manifest_mf( $dir, $javame, $destmobiledir){ return $map;
}
$fp = fopen( $dir.'/MANIFEST.MF',"w");
fputs( $fp, "Manifest-Version: 1.0\r\n"); function game_create_manifest_mf( $dir, $javame, $destmobiledir) {
fputs( $fp, "Ant-Version: Apache Ant 1.7.0\r\n"); $fp = fopen( $dir.'/MANIFEST.MF', "w");
fputs( $fp, "Created-By: {$javame->createdby}\r\n"); fputs( $fp, "Manifest-Version: 1.0\r\n");
fputs( $fp, "MIDlet-1: MoodleHangman,,$destmobiledir\r\n"); fputs( $fp, "Ant-Version: Apache Ant 1.7.0\r\n");
fputs( $fp, "MIDlet-Vendor: {$javame->vendor}\r\n"); fputs( $fp, "Created-By: {$javame->createdby}\r\n");
fputs( $fp, "MIDlet-Name: {$javame->vendor}\r\n"); fputs( $fp, "MIDlet-1: MoodleHangman,,$destmobiledir\r\n");
fputs( $fp, "MIDlet-Description: {$javame->description}\r\n"); fputs( $fp, "MIDlet-Vendor: {$javame->vendor}\r\n");
fputs( $fp, "MIDlet-Version: {$javame->version}\r\n"); fputs( $fp, "MIDlet-Name: {$javame->vendor}\r\n");
fputs( $fp, "MicroEdition-Configuration: CLDC-1.0\r\n"); fputs( $fp, "MIDlet-Description: {$javame->description}\r\n");
fputs( $fp, "MicroEdition-Profile: MIDP-1.0\r\n"); fputs( $fp, "MIDlet-Version: {$javame->version}\r\n");
fputs( $fp, "MicroEdition-Configuration: CLDC-1.0\r\n");
fclose( $fp); fputs( $fp, "MicroEdition-Profile: MIDP-1.0\r\n");
fclose( $fp);
}
function game_create_jar( $srcdir, $course, $javame) {
global $CFG;
$dir = $CFG->dataroot . '/' . $course->id;
$filejar = $dir . "/export/{$javame->filename}.jar";
if (!file_exists( $dir)) {
mkdir( $dir);
} }
function game_create_jar( $srcdir, $course, $javame){
global $CFG;
$dir = $CFG->dataroot . '/' . $course->id;
$filejar = $dir . "/export/{$javame->filename}.jar";
if (!file_exists( $dir)){
mkdir( $dir);
}
if (!file_exists( $dir.'/export')){ if (!file_exists( $dir.'/export')) {
mkdir( $dir.'/export'); mkdir( $dir.'/export');
} }
if (file_exists( $filejar)){ if (file_exists( $filejar)) {
unlink( $filejar); unlink( $filejar);
} }
$cmd = "cd $srcdir;jar cvfm $filejar META-INF/MANIFEST.MF *"; $cmd = "cd $srcdir;jar cvfm $filejar META-INF/MANIFEST.MF *";
exec( $cmd); exec( $cmd);
return (file_exists( $filejar) ? "{$javame->filename}.jar" : ''); return (file_exists( $filejar) ? "{$javame->filename}.jar" : '');
} }
function game_showanswers_appendselect( $form) function game_showanswers_appendselect( $form) {
{
switch( $form->gamekind){ switch( $form->gamekind){
case 'hangman': case 'hangman':
case 'cross': case 'cross':
case 'crypto': case 'crypto':
return " AND qtype='shortanswer'"; return " AND qtype='shortanswer'";
case 'millionaire': case 'millionaire':
return " AND qtype = 'multichoice'"; return " AND qtype = 'multichoice'";
case 'sudoku': case 'sudoku':
case 'bookquiz': case 'bookquiz':
case 'snakes': case 'snakes':
return " AND qtype in ('shortanswer', 'truefalse', 'multichoice')"; return " AND qtype in ('shortanswer', 'truefalse', 'multichoice')";
} }
return ''; return '';
} }
function game_export_javame_smartcopyimage( $filename, $dest, $maxwidth) function game_export_javame_smartcopyimage( $filename, $dest, $maxwidth) {
{ if ($maxwidth == 0) {
if( $maxwidth == 0){
copy( $filename, $dest); copy( $filename, $dest);
return; return;
} }
$size = getimagesize( $filename); $size = getimagesize( $filename);
if( $size == false){ if ($size == false) {
copy( $filename, $dest); copy( $filename, $dest);
return; return;
} }
$mul = $maxwidth / $size[ 0]; $mul = $maxwidth / $size[ 0];
if( $mul > 1){ if ($mul > 1) {
copy( $filename, $dest); copy( $filename, $dest);
return; return;
} }
$mime = $size[ 'mime']; $mime = $size[ 'mime'];
switch( $mime){ switch( $mime) {
case 'image/png': case 'image/png':
$src_image = imageCreateFromPNG( $filename); $srcimage = imagecreatefrompng( $filename);
break; break;
case 'image/jpeg': case 'image/jpeg':
$src_image = imagecreatefromjpeg( $filename); $srcimage = imagecreatefromjpeg( $filename);
break; break;
case 'image/gif': case 'image/gif':
$src_image = imageCreateFromGIF( $filename); $srcimage = imagecreatefromgif( $filename);
break; break;
default: default:
die('Aknown mime type $mime'); die('Aknown mime type $mime');
return false; return false;
} }
$dst_w = $size[ 0] * $mul; $dstw = $size[ 0] * $mul;
$dst_h = $size[ 1] * $mul; $dsth = $size[ 1] * $mul;
$dst_image = imagecreatetruecolor( $dst_w, $dst_h); $dstimage = imagecreatetruecolor( $dstw, $dsth);
imagecopyresampled( $dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $size[ 0], $size[ 1]); imagecopyresampled( $dstimage, $srcimage, 0, 0, 0, 0, $dstw, $dsth, $size[ 0], $size[ 1]);
imagejpeg( $dst_image, $dest); imagejpeg( $dstimage, $dest);
} }

136
index.php

@ -1,4 +1,19 @@
<?php // $Id: index.php,v 1.8 2012/08/29 20:55:25 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This page lists all the instances of game module in a particular course * This page lists all the instances of game module in a particular course
* *
@ -7,35 +22,34 @@
* @package game * @package game
**/ **/
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once("locallib.php"); require_once("locallib.php");
$id = required_param('id', PARAM_INT); // course
if (! $course = $DB->get_record( 'course', array( 'id' => $id))) { $id = required_param('id', PARAM_INT); // It stores the courseid.
print_error( 'Course ID is incorrect');
}
require_login($course->id); if (! $course = $DB->get_record( 'course', array( 'id' => $id))) {
print_error( 'Course ID is incorrect');
}
/// Get all required strings game require_login($course->id);
$strgames = get_string( 'modulenameplural', 'game'); // Get all required strings game.
$strgame = get_string('modulename', 'game');
$strgames = get_string( 'modulenameplural', 'game');
$strgame = get_string('modulename', 'game');
/// Print the header // Print the header.
$PAGE->set_url('/mod/game/index.php', array('id'=>$id)); $PAGE->set_url('/mod/game/index.php', array('id' => $id));
$coursecontext = game_get_context_course_instance( $id); $coursecontext = game_get_context_course_instance( $id);
$PAGE->set_pagelayout('incourse'); $PAGE->set_pagelayout('incourse');
if( game_use_events()) if (game_use_events()) {
{
require( 'classes/event/course_module_instance_list_viewed.php'); require( 'classes/event/course_module_instance_list_viewed.php');
\mod_game\event\course_module_instance_list_viewed::create_from_course($course)->trigger(); \mod_game\event\course_module_instance_list_viewed::create_from_course($course)->trigger();
}else } else {
add_to_log($course->id, "game", "view all", "index.php?id=$course->id", ""); add_to_log($course->id, "game", "view all", "index.php?id=$course->id", "");
}
// Print the header. // Print the header.
$strgames = get_string("modulenameplural", "game"); $strgames = get_string("modulenameplural", "game");
@ -45,56 +59,54 @@ $PAGE->navbar->add($strgames);
$PAGE->set_title($strgames); $PAGE->set_title($strgames);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
echo $OUTPUT->header(); echo $OUTPUT->header();
/// Get all the appropriate data
if (! $games = get_all_instances_in_course("game", $course)) {
notice("There are no games", "../../course/view.php?id=$course->id");
die;
}
/// Print the list of instances (your module will probably extend this) // Get all the appropriate data.
$timenow = time(); if (! $games = get_all_instances_in_course("game", $course)) {
$strname = get_string("name"); notice("There are no games", "../../course/view.php?id=$course->id");
$strweek = get_string("week"); die;
$strtopic = get_string("topic"); }
$table = new html_table(); // Print the list of instances (your module will probably extend this).
if ($course->format == "weeks") { $timenow = time();
$table->head = array ($strweek, $strname); $strname = get_string("name");
$table->align = array ("center", "left"); $strweek = get_string("week");
} else if ($course->format == "topics") { $strtopic = get_string("topic");
$table->head = array ($strtopic, $strname);
$table->align = array ("center", "left", "left", "left"); $table = new html_table();
if ($course->format == "weeks") {
$table->head = array ($strweek, $strname);
$table->align = array ("center", "left");
} else if ($course->format == "topics") {
$table->head = array ($strtopic, $strname);
$table->align = array ("center", "left", "left", "left");
} else {
$table->head = array ($strname);
$table->align = array ("left", "left", "left");
}
foreach ($games as $game) {
if (!$game->visible) {
// Show dimmed if the mod is hidden.
$link = "<a class=\"dimmed\" href=\"view.php?id=$game->coursemodule\">$game->name</a>";
} else { } else {
$table->head = array ($strname); // Show normal if the mod is visible.
$table->align = array ("left", "left", "left"); $link = "<a href=\"view.php?id=$game->coursemodule\">$game->name</a>";
} }
foreach ($games as $game) { if ($course->format == "weeks" or $course->format == "topics") {
if (!$game->visible) { $table->data[] = array ($game->section, $link);
//Show dimmed if the mod is hidden } else {
$link = "<a class=\"dimmed\" href=\"view.php?id=$game->coursemodule\">$game->name</a>"; $table->data[] = array ($link);
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$game->coursemodule\">$game->name</a>";
}
if ($course->format == "weeks" or $course->format == "topics") {
$table->data[] = array ($game->section, $link);
} else {
$table->data[] = array ($link);
}
} }
}
echo "<br />"; echo "<br />";
echo html_writer::table($table);
/// Finish the page echo html_writer::table($table);
echo $OUTPUT->footer($course); // Finish the page.
?> echo $OUTPUT->footer($course);

4
version.php

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

Loading…
Cancel
Save