Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
6f025e372d
  1. 108
      attempt.php
  2. 80
      export.php
  3. 195
      exporthtml.php
  4. 79
      exporthtml_hangman.php
  5. 176
      exporthtml_millionaire.php
  6. 103
      exportjavame.php
  7. 42
      index.php
  8. 4
      version.php

108
attempt.php

@ -1,4 +1,19 @@
<?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
*
@ -19,17 +34,16 @@
require_once( "snakes/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)
{
function game_show_header( &$id, &$game, &$course, &$context) {
global $DB, $USER, $PAGE, $OUTPUT;
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$q = optional_param('q', 0, PARAM_INT); // game ID
$id = optional_param('id', 0, PARAM_INT); // It represents Course Module ID.
$q = optional_param('q', 0, PARAM_INT); // It represents game id.
if ($id) {
if (! $cm = get_coursemodule_from_id('game', $id)) {
@ -53,33 +67,27 @@
}
}
/// Check login and get context.
// Check login and get context.
require_login($course->id, false, $cm);
$context = game_get_context_module_instance( $cm->id);
require_capability('mod/game:view', $context);
/// Cache some other capabilites we use several times.
// Cache some other capabilites we use several times.
$canattempt = has_capability('mod/game:attempt', $context);
$canreviewmine = has_capability('mod/game:reviewmyattempts', $context);
/// Create an object to manage all the other (non-roles) access rules.
// Create an object to manage all the other (non-roles) access rules.
$timenow = time();
//$accessmanager = new game_access_manager(game::create($game->id, $USER->id), $timenow);
/// If no questions have been set up yet redirect to edit.php
//if (!$game->questions && has_capability('mod/game:manage', $context)) {
// redirect($CFG->wwwroot . '/mod/game/edit.php?cmid=' . $cm->id);
//}
/// Log this request.
if( game_use_events())
{
// Log this request.
if ( game_use_events()) {
require( 'classes/event/game_played.php');
\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);
}
/// Initialize $PAGE, compute blocks
// Initialize $PAGE, compute blocks.
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id));
$edit = optional_param('edit', -1, PARAM_BOOL);
@ -95,7 +103,8 @@
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<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').
'" /></div></form></td></tr></table>';
$PAGE->set_button($buttons);
}
@ -105,11 +114,10 @@
echo $OUTPUT->header();
}
function game_do_attempt( $id, $game, $action, $course, $context)
{
function game_do_attempt( $id, $game, $action, $course, $context) {
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);
$pos = optional_param('pos', 0, PARAM_INT);
$num = optional_param('num', 0, PARAM_INT);
@ -120,9 +128,8 @@
$answer = optional_param('answer', '', PARAM_TEXT);
$continue = false;
/// Print the main part of the page
switch( $action)
{
// Print the main part of the page.
switch ( $action) {
case 'crosscheck':
$attempt = game_getattempt( $game, $detail);
$g = game_cross_unpackpuzzle( $g);
@ -132,43 +139,43 @@
$attempt = game_getattempt( $game, $detail);
game_cross_play( $id, $game, $attempt, $detail, '', true, false, false, true, $context);
break;
case 'sudokucheck': //the student tries to answer a question
case 'sudokucheck': // The student tries to answer a question.
$attempt = game_getattempt( $game, $detail);
game_sudoku_check_questions( $id, $game, $attempt, $detail, $finishattempt, $course, $context);
$continue = true;
break;
case 'sudokucheckg': //the student tries to guess a glossaryenry
case 'sudokucheckg': // The student tries to guess a glossaryenry.
$attempt = game_getattempt( $game, $detail);
$endofgame = array_key_exists( 'endofgame', $_GET);
$continue = game_sudoku_check_glossaryentries( $id, $game, $attempt, $detail, $endofgame, $course);
$continue = true;
break;
case 'sudokucheckn': //the user tries to guess a number
case 'sudokucheckn': // The user tries to guess a number.
$attempt = game_getattempt( $game, $detail);
game_sudoku_check_number( $id, $game, $attempt, $detail, $pos, $num, $context);
$continue = false;
break;
case 'cryptexcheck': //the user tries to guess a question
case 'cryptexcheck': // The user tries to guess a question.
$attempt = game_getattempt( $game, $detail);
game_cryptex_check( $id, $game, $attempt, $detail, $q, $answer, $finishattempt, $context);
break;
case 'bookquizcheck': //the student tries to answer a question
case 'bookquizcheck': // The student tries to answer a question.
$attempt = game_getattempt( $game, $detail);
game_bookquiz_check_questions( $id, $game, $attempt, $detail, $context);
break;
case 'snakescheck': //the student tries to answer a question
case 'snakescheck': // The student tries to answer a question.
$attempt = game_getattempt( $game, $detail);
game_snakes_check_questions( $id, $game, $attempt, $detail, $context);
break;
case 'snakescheckg': //the student tries to answer a question from glossary
case 'snakescheckg': // The student tries to answer a question from glossary.
$attempt = game_getattempt( $game, $detail);
game_snakes_check_glossary( $id, $game, $attempt, $detail, $context);
break;
case 'hiddenpicturecheck': //the student tries to answer a question
case 'hiddenpicturecheck': // The student tries to answer a question.
$attempt = game_getattempt( $game, $detail);
$continue = game_hiddenpicture_check_questions( $id, $game, $attempt, $detail, $finishattempt, $context);
break;
case 'hiddenpicturecheckg': //the student tries to guess a glossaryenry
case 'hiddenpicturecheckg': // The student tries to guess a glossaryentry.
$attempt = game_getattempt( $game, $detail);
game_hiddenpicture_check_mainquestion( $id, $game, $attempt, $detail, $endofgame, $context);
break;
@ -179,13 +186,11 @@
if ($continue) {
game_create( $game, $id, $forcenew, $course, $context);
}
/// Finish the page
// Finish the page.
echo $OUTPUT->footer();
}
function game_create( $game, $id, $forcenew, $course, $context)
{
function game_create( $game, $id, $forcenew, $course, $context) {
global $USER, $CFG, $DB;
$attempt = game_getattempt( $game, $detail);
@ -193,8 +198,7 @@
$newletter = optional_param('newletter', '', PARAM_ALPHA);
$action2 = optional_param('action2', '', PARAM_ALPHA);
switch( $game->gamekind)
{
switch ( $game->gamekind) {
case 'cross':
game_cross_continue( $id, $game, $attempt, $detail, '', $forcenew, $context);
break;
@ -225,18 +229,15 @@
}
}
function game_cross_unpackpuzzle( $g)
{
function game_cross_unpackpuzzle( $g) {
$ret = "";
$len = game_strlen( $g);
while( $len)
{
for( $i=0; $i < $len; $i++)
{
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
// Found escape character.
if (game_substr( $g, $i - 1, 1) == '/') {
$g = game_substr( $g, 0, $i - 1).game_substr( $g, $i);
$i--;
@ -249,9 +250,8 @@ function game_cross_unpackpuzzle( $g)
}
if ($i < $len) {
//found the start of a number
for( $j=$i+1; $j < $len; $j++)
{
// 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;
@ -262,9 +262,7 @@ function game_cross_unpackpuzzle( $g)
$g = game_substr( $g, $j);
$len = game_strlen( $g);
}else
{
} else {
$ret .= $g;
break;
}

80
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
*
@ -15,19 +30,20 @@ require( 'locallib.php');
require( 'headergame.php');
$context = game_get_context_module_instance( $cm->id);
if (!has_capability('mod/game:viewreports', $context))
if (!has_capability('mod/game:viewreports', $context)) {
return;
}
$target = optional_param('target', "", PARAM_ALPHANUM); // action
$target = optional_param('target', "", PARAM_ALPHANUM); // The target is HTML or JavaMe.
class mod_game_exporthtml_form extends moodleform {
function definition() {
public function definition() {
global $CFG, $game;
$mform = $this->_form;
$html = $this->_customdata['html'];
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
if ( $game->gamekind == 'hangman') {
@ -35,25 +51,25 @@ class mod_game_exporthtml_form extends moodleform {
$options[ '0'] = 'Hangman with phrases';
$options[ 'hangmanp'] = 'Hangman with pictures';
$mform->addElement('select', 'type', get_string('javame_type', 'game'), $options);
if( $html->type == 0)
if ( $html->type == 0) {
$mform->setDefault('type', '0');
else
} else {
$mform->setDefault('type', 'hangmanp');
}
}
//filename
// Input the filename.
$mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30'));
$mform->setDefault('filename', $html->filename);
$mform->setType('filename', PARAM_TEXT);
//html title
// Input the html title.
$mform->addElement('text', 'title', get_string('html_title', 'game'), array('size' => '80'));
$mform->setDefault('title', $html->title);
$mform->setType('title', PARAM_TEXT);
//fields for hangman
if( $game->gamekind == 'hangman')
{
// Inputs special fields for hangman.
if ($game->gamekind == 'hangman') {
$mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5'));
$mform->setDefault('maxpicturewidth', $html->maxpicturewidth);
$mform->setType('maxpicturewidth', PARAM_INT);
@ -62,9 +78,8 @@ class mod_game_exporthtml_form extends moodleform {
$mform->setType('maxpictureheight', PARAM_INT);
}
//fiels for cross
if( $game->gamekind == 'cross')
{
// Input special fields for crossword.
if ( $game->gamekind == 'cross') {
$mform->addElement('selectyesno', 'checkbutton', get_string('html_hascheckbutton', 'game'));
$mform->setDefault('checkbutton', $html->checkbutton);
$mform->addElement('selectyesno', 'printbutton', get_string('html_hasprintbutton', 'game'));
@ -76,21 +91,18 @@ class mod_game_exporthtml_form extends moodleform {
$mform->addElement('hidden', 'target', 'html');
$mform->setType('target', PARAM_TEXT);
//-------------------------------------------------------------------------------
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game'));
$mform->closeHeaderBefore('submitbutton');
//-------------------------------------------------------------------------------
}
function validation($data, $files) {
public function validation($data, $files) {
global $CFG, $USER, $DB;
$errors = parent::validation($data, $files);
return $errors;
}
function export() {
public function export() {
global $game, $DB;
$mform = $this->_form;
@ -125,13 +137,12 @@ class mod_game_exporthtml_form extends moodleform {
class mod_game_exportjavame_form extends moodleform {
function definition() {
public function definition() {
global $CFG, $DB, $game;
$mform = $this->_form;
$javame = $this->_customdata['javame'];
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
if ( $game->gamekind == 'hangman') {
@ -141,7 +152,6 @@ class mod_game_exportjavame_form extends moodleform {
$mform->addElement('select', 'type', get_string('javame_type', 'game'), $options);
}
//filename
$mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30'));
$mform->setDefault('filename', $javame->filename);
$mform->setType('filename', PARAM_TEXT);
@ -175,22 +185,18 @@ class mod_game_exportjavame_form extends moodleform {
$mform->addElement('hidden', 'target', 'javame');
$mform->setType('target', PARAM_TEXT);
//-------------------------------------------------------------------------------
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game'));
$mform->closeHeaderBefore('submitbutton');
//-------------------------------------------------------------------------------
//$this->set_data($currententry);
}
function validation($data, $files) {
public function validation($data, $files) {
global $CFG, $USER, $DB;
$errors = parent::validation($data, $files);
return $errors;
}
function export() {
public function export() {
global $game, $DB;
$mform = $this->_form;
@ -218,8 +224,7 @@ class mod_game_exportjavame_form extends moodleform {
}
// create form and set initial data
// Creates form and set initial data.
if ($target == 'html') {
$html = $DB->get_record( 'game_export_html', array( 'id' => $game->id));
if ($html == false) {
@ -232,8 +237,7 @@ class mod_game_exportjavame_form extends moodleform {
}
$html->type = 0;
$mform = new mod_game_exporthtml_form(null, array('id' => $id, 'html' => $html));
}else
{
} else {
$javame = $DB->get_record( 'game_export_javame', array( 'id' => $game->id));
if ($javame == false) {
$javame = new stdClass();
@ -254,14 +258,13 @@ class mod_game_exportjavame_form extends moodleform {
}
} else if ($entry = $mform->get_data()) {
$mform->export();
}else
{
} else {
ob_end_flush();
if (!empty($id)) {
$PAGE->navbar->add(get_string('export', 'game'));}
$PAGE->navbar->add(get_string('export', 'game'));
}
$mform->display();
// echo $OUTPUT->footer();
}
$OUTPUT->footer();
@ -279,6 +282,7 @@ function game_send_stored_file($file) {
flush();
readfile($file);
exit;
}else
} else {
print_error("export.php: File does not exists ".$file);
}
}

195
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
*
@ -10,30 +25,30 @@
require_once( "locallib.php");
require_once( "exportjavame.php");
function game_OnExportHTML( $game, $context, $html){
function game_onexporthtml( $game, $context, $html) {
global $CFG;
$destdir = game_export_createtempdir();
switch( $game->gamekind) {
case 'cross';
game_OnExportHTML_cross( $game, $context, $html, $destdir);
game_onexporthtml_cross( $game, $context, $html, $destdir);
break;
case 'hangman':
game_OnExportHTML_hangman( $game, $context, $html, $destdir);
game_onexporthtml_hangman( $game, $context, $html, $destdir);
break;
case 'snakes':
game_OnExportHTML_snakes( $game, $html, $destdir, $context);
game_onexporthtml_snakes( $game, $html, $destdir, $context);
break;
case 'millionaire':
game_OnExportHTML_millionaire( $game, $context, $html, $destdir);
game_onexporthtml_millionaire( $game, $context, $html, $destdir);
break;
}
remove_dir( $destdir);
}
function game_OnExportHTML_cross( $game, $context, $html, $destdir){
function game_onexporthtml_cross( $game, $context, $html, $destdir) {
global $CFG, $DB;
@ -55,40 +70,38 @@
ob_start();
game_cross_play( 0, $game, $attempt, $crossrec, '', true, false, false, false, $html->checkbutton, true, $html->printbutton, false, $context);
game_cross_play( 0, $game, $attempt, $crossrec, '', true, false, false, false,
$html->checkbutton, true, $html->printbutton, false, $context);
$output_string = ob_get_contents();
$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" . $output_string);
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring);
$filename = game_OnExportHTML_cross_repair_questions( $game, $context, $filename, $destdir);
$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)
{
function game_onexporthtml_cross_repair_questions( $game, $context, $filename, $destdir) {
global $CFG, $DB;
$file_handle = fopen( $destdir.'/'.$filename, "rb");
$filehandle = fopen( $destdir.'/'.$filename, "rb");
$found = false;
$files = array();
$contextcourse = false;
$linesbefore = array();
$linesafter = array();
while (!feof($file_handle) ) {
$line = fgets( $file_handle);
while (!feof($filehandle) ) {
$line = fgets( $filehandle);
if( $found)
{
if( strpos( $line, 'new Array'))
{
if ($found) {
if ( strpos( $line, 'new Array')) {
$linesafter[] = $line;
break;
}
@ -96,8 +109,7 @@
continue;
}
if( strpos( $line, 'Clue = new Array') === false)
{
if (strpos( $line, 'Clue = new Array') === false) {
$linesbefore[] = $line;
continue;
}
@ -105,11 +117,11 @@
$array = $line;
$found = true;
}
while (!feof($file_handle) ) {
$linesafter[] = fgets( $file_handle);
while (!feof($filehandle) ) {
$linesafter[] = fgets( $filehandle);
}
fclose($file_handle);
fclose($filehandle);
$search = $CFG->wwwroot.'/pluginfile.php';
$pos = 0;
@ -117,20 +129,19 @@
$len = strlen( $search);
$start = 0;
$filescopied = false;
for(;;)
{
for (;;) {
$pos1 = strpos( $array, $search, $start);
if( $pos1 == false)
if ( $pos1 == false) {
break;
}
$pos2 = strpos( $array, '\"', $pos1 + $len);
if( $pos2 == false)
if ( $pos2 == false) {
break;
}
//Have to copy the files
if( $contextcourse === false)
{
// Have to copy the files.
if ($contextcourse === false) {
mkdir( $destdir.'/images');
if (!$contextcourse = get_context_instance(CONTEXT_COURSE, $game->course)) {
print_error('nocontext');
@ -148,52 +159,53 @@
$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);
if ( $rec == false {
break;
}
if (!$file = $fs->get_file_by_hash($rec->pathnamehash) or $file->is_directory())
if (!$file = $fs->get_file_by_hash($rec->pathnamehash) or $file->is_directory()) {
continue;
}
$posext = strrpos( $fileimage, '.');
$filenoext = substr( $fileimage, $posext);
$ext = substr( $fileimage, $posext + 1);
for($i=0;;$i++)
{
for ($i = 0;; $i++) {
$newfile = $filenoext.$i;
$newfile = md5( $newfile).'.'.$ext;
if( !array_search( $newfile, $files))
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)
if ($filescopied == false) {
return $destdir.'/'.$filename;
}
$linesbefore[] = $array;
foreach( $linesafter as $line)
foreach ($linesafter as $line) {
$linesbefore [] = $line;
}
file_put_contents( $destdir.'/'.$filename, $linesbefore);
$pos = strrpos( $filename, '.');
if( $pos === false)
if ($pos === false) {
$filezip = $filename.'.zip';
else
} else {
$filezip = substr( $filename, 0, $pos).'.zip';
}
$filezip = game_create_zip( $destdir, $game->course, $filezip);
return $filezip;
}
function game_export_printheader( $title, $showbody=true)
{
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";
@ -201,13 +213,14 @@
$ret .= '<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">'."\n";
$ret .= "<title>$title</title>\n";
$ret .= "</head>\n";
if( $showbody)
if ($showbody) {
$ret .= "<body>";
}
return $ret;
}
function game_OnExportHTML_hangman( $game, $context, $html, $destdir){
function game_onexporthtml_hangman( $game, $context, $html, $destdir) {
global $CFG, $DB;
@ -215,38 +228,38 @@
$html->filename = 'hangman';
}
if( $game->param10 <= 0)
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');
$exportattachment = ( $html->type == 'hangmanp');
$map = game_exmportjavame_getanswers( $game, $context, $export_attachment, $destdir, $files);
$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
// Here is the code of hangman.
require_once( "exporthtml_hangman.php");
$output_string = ob_get_contents();
$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" . $output_string);
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"
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))) {
@ -254,8 +267,9 @@
if (!is_dir($src.'/'.$item)) {
$itemdest = $item;
if( strpos( $item, '.') === false)
if ( strpos( $item, '.') === false) {
continue;
}
copy( $src.'/'.$item, $destdir.'/'.$itemdest);
}
@ -267,7 +281,7 @@
game_send_stored_file( $filezip);
}
function game_OnExportHTML_millionaire( $game, $context, $html, $destdir){
function game_onexporthtml_millionaire( $game, $context, $html, $destdir) {
global $CFG, $DB;
@ -280,7 +294,7 @@
$ret = game_export_printheader( $html->title, false);
$ret .= "\r<body onload=\"Reset();\">\r";
//Here is the code of millionaire
// Here is the code of millionaire.
require( "exporthtml_millionaire.php");
$questions = game_millionaire_html_getquestions( $game, $context, $maxanswers, $maxquestions, $retfeedback, $destdir, $files);
@ -288,8 +302,8 @@
game_millionaire_html_print( $game, $questions, $maxanswers);
//End of millionaire code
$output_string = ob_get_contents();
// End of millionaire code.
$outputstring = ob_get_contents();
ob_end_clean();
$courseid = $game->course;
@ -297,9 +311,9 @@
$filename = $html->filename . '.htm';
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $output_string);
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring);
//Copy the standard pictures of Millionaire
// Copy the standard pictures of Millionaire.
$src = $CFG->dirroot.'/mod/game/pix/millionaire/1';
$handle = opendir( $src);
while (false !== ($item = readdir($handle))) {
@ -307,8 +321,9 @@
if (!is_dir($src.'/'.$item)) {
$itemdest = $item;
if( strpos( $item, '.') === false)
if (strpos( $item, '.') === false) {
continue;
}
copy( $src.'/'.$item, $destdir.'/'.$itemdest);
}
@ -319,7 +334,7 @@
game_send_stored_file($filezip);
}
function game_OnExportHTML_snakes( $game, $html, $destdir, $context){
function game_onexporthtml_snakes( $game, $html, $destdir, $context) {
require_once( "exporthtml_millionaire.php");
global $CFG, $DB;
@ -334,22 +349,21 @@
$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;
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);
$questionss = game_exmportjavame_getanswers( $game, $context, false, $destdir, $files);
ob_start();
//Here is the code of hangman
// Here is the code of hangman.
require( "exporthtml_snakes.php");
$output_string = ob_get_contents();
$outputstring = ob_get_contents();
ob_end_clean();
$courseid = $game->course;
@ -357,7 +371,7 @@
$filename = $html->filename . '.htm';
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $output_string);
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring);
$src = $CFG->dirroot.'/mod/game/export/html/snakes';
game_copyfiles( $src, $destdir);
@ -372,45 +386,46 @@
mkdir( $destdir .'/images');
$destfile = $destdir.'/images/'.$board->fileboard;
if( $game->param3 != 0)
{
//Is a standard board
if ( $game->param3 != 0) {
// Is a standard board.
copy( $board->imagesrc, $destfile);
}else
{
} 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())
if ( $f->is_directory()) {
continue;
}
break;
}
$f->copy_content_to( $destfile);
}
$a = array( 'player1.png', 'dice1.png', 'dice2.png', 'dice3.png', 'dice4.png', 'dice5.png', 'dice6.png', 'numbers.png');
foreach( $a as $file)
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)
{
function game_copyfiles( $src, $destdir) {
$handle = opendir( $src);
while (($item = readdir($handle)) !== false)
{
if( $item == '.' or $item == '..')
while (($item = readdir($handle)) !== false) {
if ( $item == '.' or $item == '..') {
continue;
}
if( strpos( $item, '.') === false)
if ( strpos( $item, '.') === false) {
continue;
}
if(is_dir($src.'/'.$item))
if (is_dir($src.'/'.$item)) {
continue;
}
copy( $src.'/'.$item, $destdir.'/'.$item);
}

79
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
*
@ -10,15 +25,16 @@
?>
<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/)
var can_play = true;
<?php
$destdir = game_export_createtempdir();
$export_attachment = ( $html->type == 'hangmanp');
$map = game_exmportjavame_getanswers( $game, $context, $export_attachment, $destdir, $files);
$exportattachment = ( $html->type == 'hangmanp');
$map = game_exmportjavame_getanswers( $game, $context, $exportattachment, $destdir, $files);
if ($map == false) {
print_error( 'No Questions');
}
@ -28,49 +44,56 @@ var can_play = true;
$lang = '';
$allletters = '';
$images = '';
foreach( $map as $line)
{
foreach ($map as $line) {
$answer = game_upper( $line->answer);
if ($game->param7) {
//Have to delete space
// Have to delete space.
$answer = str_replace(' ', '', $answer);
}
if ($game->param8) {
//Have to delete -
// Have to deletε -.
$answer = str_replace('-', '', $answer);
}
if ($lang == '') {
$lang = $game->language;
if( $lang == '')
if ($lang == '') {
$lang = game_detectlanguage( $answer);
if( $lang == '')
}
if ($lang == '') {
$lang = current_language();
}
$allletters = game_getallletters( $answer, $lang);
}
if( game_getallletters( $answer, $lang) != $allletters)
if (game_getallletters( $answer, $lang) != $allletters) {
continue;
}
if ($html->type == 'hangmanp') {
$file = $line->attachment;
$pos = strrpos( $file, '.');
if( $pos == false)
if ($pos == false) {
continue;
}
}
if ($html->type == 'hangmanp') {
$src = $line->attachment;
$pos = strrpos( $file, '.');
if( $pos == false)
if ($pos == false) {
continue;
}
}
if( $questions != '')
if ($questions != '') {
$questions .= ', ';
if( $words != '')
}
if ($words != '') {
$words .= ', ';
}
$questions .= '"'.base64_encode( $line->question).'"';
$words .= '"'.base64_encode( $line->answer).'"';
@ -78,8 +101,9 @@ var can_play = true;
$file = $line->id.substr( $file, $pos);
game_export_javame_smartcopyimage( $src, $destdir.'/'.$file, $html->maxpicturewidth, $html->maxpictureheight);
if( $images != '')
if ($images != '') {
$images .= ', ';
}
$images .= '"'.$file.'"';
}
}
@ -87,14 +111,16 @@ var can_play = true;
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')
if ($html->type == 'hangmanp') {
echo "var images = new Array($images);\r";
}
?>
var to_guess = "";
@ -104,10 +130,10 @@ var wrong_guesses = 0;
var used_letters_all = "";
var all_letters = new Array(<?php
$len = game_strlen( $allletters);
for( $i=0; $i < $len; $i++)
{
if( $i > 0)
for ($i = 0; $i < $len; $i++) {
if ($i > 0) {
echo ',';
}
echo '"'.game_substr( $allletters, $i, 1).'"';
}
?>);
@ -162,10 +188,11 @@ function selectLetter(l)
}else
{
wrong_guesses++;
<?php
if ($html->type != 'hangmanp') {
?>eval("document.hm.src=\"hangman_" + wrong_guesses + ".jpg\"");
// incortect letter guess
// Ιncortect letter guess.
eval("document.hm.src=\"hangman_" + wrong_guesses + ".jpg\"");
<?php
}
@ -197,11 +224,13 @@ function reset()
used_letters_all = "";
wrong_guesses = 0;
showallletters();
<?php
if ($html->type != 'hangmanp') {
echo ' document.hm.src="hangman_0.jpg"'."\r";
}
?>
}
function showallletters()
@ -244,10 +273,11 @@ function selectWord()
display_word = masked_word;
<?php
if( $html->type == 'hangmanp')
if ($html->type == 'hangmanp') {
echo " document.hm.src = images[ random_number];\r";
else
} else {
echo " document.getElementById('question').innerHTML=to_question;\r";
}
?>
}
@ -349,7 +379,8 @@ var Base64 = {
</head>
<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">
<div id="displayWord"> </div>
<div id="usedLetters"> </div>

176
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
*
@ -7,8 +22,7 @@
* @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;
$maxanswers = 0;
@ -17,7 +31,8 @@ function game_millionaire_html_getquestions( $game, $context, &$maxanswers, &$co
$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));
print_error( get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string( 'modulename', 'quiz')).
' '.get_string( 'modulename', $game->sourcemodule));
}
if ( $game->sourcemodule == 'quiz') {
@ -27,13 +42,12 @@ function game_millionaire_html_getquestions( $game, $context, &$maxanswers, &$co
$select = "qtype='multichoice' AND quiz='$game->quizid' ".
" AND qqi.question=q.id";
$table = "{question} q,{quiz_question_instances} qqi";
}else
{
} else {
if ( $game->questioncategoryid == 0) {
print_error( get_string( 'must_select_questioncategory', 'game'));
}
//include subcategories
// Include subcategories.
$select = 'category='.$game->questioncategoryid;
if ( $game->subcategories) {
$cats = question_categorylist( $game->questioncategoryid);
@ -57,42 +71,43 @@ function game_millionaire_html_getquestions( $game, $context, &$maxanswers, &$co
$line = $rec->questiontext;
$line = game_export_split_files( $game->course, $context, 'questiontext', $rec->id, $rec->questiontext, $destdir, $files);
$linefeedback = '';
foreach( $recs2 as $rec2)
{
$line .= '#'.str_replace( array( '"', '#'), array( "'", ' '), game_export_split_files( $game->course, $context, 'answer', $rec2->id, $rec2->answer, $destdir, $files));
foreach ($recs2 as $rec2) {
$line .= '#'.str_replace( array( '"', '#'), array( "'", ' '),
game_export_split_files( $game->course, $context, 'answer', $rec2->id, $rec2->answer, $destdir, $files));
$linefeedback .= '#'.str_replace( array( '"', '#'), array( "'", ' '), $rec2->feedback);
}
if( $ret != '')
if ( $ret != '') {
$ret .= ",\r";
}
$ret .= '"'.base64_encode( $line).'"';
if( $retfeedback != '')
if ( $retfeedback != '') {
$retfeedback .= ",\r";
}
$retfeedback .= '"'.base64_encode( $linefeedback).'"';
if( count( $recs2) > $maxanswers)
if ( count( $recs2) > $maxanswers) {
$maxanswers = count( $recs2);
}
$countofquestions++;
}
return $ret;
}
function game_millionaire_html_print( $game, $questions, $maxquestions)
{
function game_millionaire_html_print( $game, $questions, $maxquestions) {
$color1 = 'black';
$color2 = 'DarkOrange';
$colorback = "white";
$stylequestion = "background:$colorback;color:$color1";
$stylequestionselected = "background:$colorback;color:$color2";
?>
<body onload="Reset();">
<script type="text/javascript">
//Millionaire for Moodle by Vasilis Daloukas
// Millionaire for Moodle by Vasilis Daloukas.
<?php echo 'var questions = new Array('.$questions.");\r"; ?>
var current_question = 0;
var level = 0;
@ -104,38 +119,31 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
var countQuestions = 0;
var maxQuestions = <?php echo $maxquestions;?>;
function Highlite( ans)
{
function Highlite( ans) {
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $color2;?>';
}
function Restore( ans)
{
function Restore( ans) {
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $colorback;?>';
}
function OnSelectAnswer( ans)
{
if( posCorrect == ans)
{
if( level+1 > 15)
{
function OnSelectAnswer( ans) {
if ( posCorrect == ans) {
if( level+1 > 15) {
alert( "<?php echo get_string( 'win', 'game');?>");
Reset();
}else
{
} else {
UpdateLevel( level+1);
SelectNextQuestion();
}
}else
{
} else {
OnGameOver( ans);
}
}
function OnGameOver( ans)
{
document.getElementById( "info").innerHTML = "<?php echo get_string( 'millionaire_info_wrong_answer', 'game');?> "+document.getElementById( "lblAnswer" + posCorrect).innerHTML;
function OnGameOver( ans) {
document.getElementById( "info").innerHTML = "<?php echo get_string( 'millionaire_info_wrong_answer', 'game');?> " +
document.getElementById( "lblAnswer" + posCorrect).innerHTML;
Highlite( posCorrect);
Restore( ans);
document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $color2;?>';
@ -148,10 +156,8 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
Reset();
}
function UpdateLevel( newlevel)
{
if( level > 0)
{
function UpdateLevel( newlevel) {
if ( level > 0) {
document.getElementById( "levela" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + 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;?>";
}
function OnHelp5050( ans)
{
if( flag5050)
function OnHelp5050( ans) {
if (flag5050) {
return;
}
document.getElementById( "Help5050").src = "5050x.png";
flag5050 = 1;
for (pos = posCorrect;pos == posCorrect;pos = 1+Math.floor(Math.random()*countQuestions));
for( i=1; i <= countQuestions; i++)
{
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( "btAnswer" + i).style.visibility = 'hidden';
}
}
}
function OnHelpTelephone( ans)
{
if( flagTelephone)
function OnHelpTelephone( ans) {
if( flagTelephone) {
return;
}
flagTelephone = 1;
document.getElementById( "HelpTelephone").src = "telephonex.png";
if (countQuestions < 2) {
wrong = posCorrect;
}else
{
for(;;)
{
} else {
for(;;) {
wrong = 1 + Math.floor(Math.random() * countQuestions);
if( wrong != posCorrect)
if ( wrong != posCorrect) {
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;
else
} else {
pos = wrong;
}
info = "<?php echo get_string( 'millionaire_info_telephone', 'game').'<br><b>';?> ";
info += document.getElementById( "lblAnswer" + pos).innerHTML;
document.getElementById( "info").innerHTML = info;
}
function OnHelpPeople( ans)
{
if( flagPeople)
function OnHelpPeople( ans) {
if( flagPeople) {
return;
}
flagPeople = 1;
document.getElementById( "HelpPeople").src = "peoplex.png";
sum = 0;
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));
aPercent[ i] = percent;
sum += percent;
}
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
max_pos = 0;
for( i=1; i < countQuestions; i++)
{
for( i=1; i < countQuestions; i++) {
if( aPercent[ i] >= aPercent[ max_pos])
max_pos = i;
}
@ -258,15 +260,12 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
document.getElementById( "info").innerHTML = info;
}
function OnQuit( ans)
{
function OnQuit( ans) {
Reset();
}
function Reset()
{
for(i=1; i <= 15; i++)
{
function Reset() {
for(i=1; i <= 15; i++) {
document.getElementById( "levela" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + i).bgColor = "<?php echo $colorback;?>";
@ -288,17 +287,15 @@ function game_millionaire_html_print( $game, $questions, $maxquestions)
SelectNextQuestion();
}
function RandomizeAnswers( elements)
{
function RandomizeAnswers( elements) {
posCorrect = 1;
countQuestions = elements.length-1;
for( i=1; i <= countQuestions; i++)
{
for( i=1; i <= countQuestions; i++) {
pos = 1+Math.floor(Math.random()*countQuestions);
if( posCorrect == i)
if( posCorrect == i) {
posCorrect = pos;
else if( posCorrect == pos)
} else if ( posCorrect == pos)
posCorrect = i;
var temp = elements[ i];
@ -426,9 +423,12 @@ var Base64 = {
<tr height=10%>
<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="HelpTelephone" id="HelpTelephone" Title="<?php echo get_string( 'millionaire_telephone', 'game');?>" src="telephone.png" alt="" border="0" onmousedown="OnHelpTelephone();">&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;
<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="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 rowspan=<?php echo 16 + $maxquestions;?> style='background:#408080'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td id="levela15" align=right>15</td>
@ -444,7 +444,8 @@ var Base64 = {
<td id="levelb13"></td><td id="levelc13" align=right> 400000</td>
</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="levelb12"></td><td id="levelc12" align=right> 200000</td>
</tr>
@ -498,17 +499,18 @@ var Base64 = {
<?php
$letters = get_string( 'lettersall', 'game');
for($i=1 ; $i <= $maxquestions; $i++)
{
for ($i = 1; $i <= $maxquestions; $i++) {
$s = game_substr( $letters, $i - 1, 1);
echo "<tr>\n";
echo "<td style='background:$colorback;color:$color1'>";
echo "<input style=\"background:$colorback;color:$color1;\" type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\"";
echo "<input style=\"background:$colorback;color:$color1;\"
type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\"";
echo " onmouseover=\"Highlite( $i);\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\">";
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";
if( $i == 1)
{
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";
if ( $i == 1) {
echo "<td style='background:#408080' rowspan=".$maxquestions." colspan=3><div id=\"info\"></div></td>\n";
}
echo "</tr>\n";

103
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
*
@ -7,7 +22,7 @@
* @package game
**/
function game_OnExportJavaME( $game, $javame){
function game_onexportjavame( $game, $javame) {
global $CFG, $DB;
$courseid = $game->course;
@ -33,7 +48,7 @@
$itemdest = $item;
if (substr( $item, -5) == '.java') {
continue; //don't copy the java source code files
continue; // Don't copy the java source code files.
}
if (substr( $itemdest, -8) == '-1.class') {
@ -63,7 +78,8 @@
}
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>";
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>";
}
$file = ($filejar != '' ? $filejar : $filezip);
@ -87,13 +103,14 @@
}
$lang = $game->language;
if( $lang == '')
if ($lang == '') {
$lang = current_language();
}
copy( $src. '/lang/'.$lang.'/language.txt', $destdir."/$destmobiledir/language.txt");
$export_attachment = ( $destmobiledir == 'hangmanp');
$exportattachment = ( $destmobiledir == 'hangmanp');
$map = game_exmportjavame_getanswers( $game, $export_attachment, false, $destdir, $files);
$map = game_exmportjavame_getanswers( $game, $exportattachment, false, $destdir, $files);
if ($map == false) {
print_error( 'No Questions');
}
@ -115,8 +132,7 @@
fclose( $fp);
}
function game_exportjavame_exportdata_hangmanp( $src, $destmobiledir, $destdir, $game, $map, $maxwidth, $maxheight)
{
function game_exportjavame_exportdata_hangmanp( $src, $destmobiledir, $destdir, $game, $map, $maxwidth, $maxheight) {
global $CFG;
$fp = fopen( $destdir."/$destmobiledir/$destmobiledir.txt", "w");
@ -128,7 +144,6 @@
$fp = fopen( $destdirphoto.'/photo.txt', "w");
foreach ($map as $line) {
$file = $line->attachment;
$pos = strrpos( $file, '.');
if ($pos != false) {
@ -143,7 +158,7 @@
fclose( $fp);
}
function game_exmportjavame_getanswers( $game, $context, $export_attachment, $dest, &$files){
function game_exmportjavame_getanswers( $game, $context, $exportattachment, $dest, &$files) {
$map = array();
$files = array();
@ -151,7 +166,7 @@
case 'question':
return game_exmportjavame_getanswers_question( $game, $context, $dest, $files);
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':
return game_exmportjavame_getanswers_quiz( $game, $context, $dest, $files);
}
@ -164,11 +179,11 @@
$select .= game_showanswers_appendselect( $game);
return game_exmportjavame_getanswers_question_select( $game, $context, 'question', $select, '*', $game->course, $destdir, $files);
return game_exmportjavame_getanswers_question_select( $game, $context, 'question',
$select, '*', $game->course, $destdir, $files);
}
function game_exmportjavame_getanswers_quiz( $game, $context, $destdir, $files)
{
function game_exmportjavame_getanswers_quiz( $game, $context, $destdir, $files) {
global $CFG;
$select = "quiz='$game->quizid' ".
@ -180,14 +195,13 @@
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)
{
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;
$map = array();
foreach ($questions as $question) {
@ -195,11 +209,13 @@
$ret->qtype = $question->qtype;
$ret->question = $question->questiontext;
$ret->question = str_replace( array( '"', '#'), array( "'", ' '),
game_export_split_files( $game->course, $context, 'questiontext', $question->id, $ret->question, $destdir, $files));
game_export_split_files( $game->course, $context, 'questiontext',
$question->id, $ret->question, $destdir, $files));
switch ($question->qtype) {
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),
'id,answer,feedback');
$ret->answer = $rec->answer;
$ret->feedback = $rec->feedback;
$map[] = $ret;
@ -212,8 +228,7 @@
return $map;
}
function game_exmportjavame_getanswers_glossary( $game, $context, $export_attachment, $destdir, &$files)
{
function game_exmportjavame_getanswers_glossary( $game, $context, $exportattachment, $destdir, &$files) {
global $CFG, $DB;
$table = '{glossary_entries} ge';
@ -224,16 +239,16 @@
$table .= ",{glossary_entries_categories} gec";
}
if( $export_attachment){
if ($exportattachment) {
$select .= " AND attachment <> ''";
}
$fields = 'ge.id,definition,concept';
if( $export_attachment){
if ($exportattachment) {
$fields .= ',attachment';
}
$sql = "SELECT $fields FROM $table WHERE $select ORDER BY definition";
if( ($questions = $DB->get_records_sql( $sql)) === false){
if ($questions = $DB->get_records_sql( $sql)) === false) {
return false;
}
@ -250,11 +265,10 @@
$ret->feedback = '';
$ret->attachment = '';
//Copies the appropriate files from the file storage to destdir
if( $export_attachment){
// Copies the appropriate files from the file storage to destdir.
if ($exportattachment) {
if ($question->attachment != '') {
if( $cmglossary === false)
{
if ($cmglossary === false) {
$cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course);
$contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id);
}
@ -262,17 +276,20 @@
$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())
if ($f->is_directory()) {
continue;
}
$filename = $f->get_filename();
$url = "{$CFG->wwwroot}/pluginfile.php/{$f->get_contextid()}/mod_glossary/attachment}";
$fileurl = $url.$f->get_filepath().$f->get_itemid().'/'.$filename;
$pos = strrpos( $filename, '.');
$ext = substr( $filename, $pos);
$destfile = $ret->id;
if( $i > 0)
if ($i > 0) {
$destfile .= '_'.$i;
}
$destfile = $destdir.'/'.$destfile.$ext;
$f->copy_content_to( $destfile);
$ret->attachment = $destfile;
@ -289,7 +306,6 @@
}
function game_create_manifest_mf( $dir, $javame, $destmobiledir) {
$fp = fopen( $dir.'/MANIFEST.MF', "w");
fputs( $fp, "Manifest-Version: 1.0\r\n");
fputs( $fp, "Ant-Version: Apache Ant 1.7.0\r\n");
@ -328,9 +344,7 @@
return (file_exists( $filejar) ? "{$javame->filename}.jar" : '');
}
function game_showanswers_appendselect( $form)
{
function game_showanswers_appendselect( $form) {
switch( $form->gamekind){
case 'hangman':
case 'cross':
@ -347,8 +361,7 @@ function game_showanswers_appendselect( $form)
return '';
}
function game_export_javame_smartcopyimage( $filename, $dest, $maxwidth)
{
function game_export_javame_smartcopyimage( $filename, $dest, $maxwidth) {
if ($maxwidth == 0) {
copy( $filename, $dest);
return;
@ -369,23 +382,23 @@ function game_export_javame_smartcopyimage( $filename, $dest, $maxwidth)
$mime = $size[ 'mime'];
switch( $mime) {
case 'image/png':
$src_image = imageCreateFromPNG( $filename);
$srcimage = imagecreatefrompng( $filename);
break;
case 'image/jpeg':
$src_image = imagecreatefromjpeg( $filename);
$srcimage = imagecreatefromjpeg( $filename);
break;
case 'image/gif':
$src_image = imageCreateFromGIF( $filename);
$srcimage = imagecreatefromgif( $filename);
break;
default:
die('Aknown mime type $mime');
return false;
}
$dst_w = $size[ 0] * $mul;
$dst_h = $size[ 1] * $mul;
$dst_image = imagecreatetruecolor( $dst_w, $dst_h);
imagecopyresampled( $dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $size[ 0], $size[ 1]);
$dstw = $size[ 0] * $mul;
$dsth = $size[ 1] * $mul;
$dstimage = imagecreatetruecolor( $dstw, $dsth);
imagecopyresampled( $dstimage, $srcimage, 0, 0, 0, 0, $dstw, $dsth, $size[ 0], $size[ 1]);
imagejpeg( $dst_image, $dest);
imagejpeg( $dstimage, $dest);
}

42
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
*
@ -11,7 +26,7 @@
require_once("lib.php");
require_once("locallib.php");
$id = required_param('id', PARAM_INT); // course
$id = required_param('id', PARAM_INT); // It stores the courseid.
if (! $course = $DB->get_record( 'course', array( 'id' => $id))) {
print_error( 'Course ID is incorrect');
@ -19,23 +34,22 @@
require_login($course->id);
/// Get all required strings game
// Get all required strings 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));
$coursecontext = game_get_context_course_instance( $id);
$PAGE->set_pagelayout('incourse');
if( game_use_events())
{
if (game_use_events()) {
require( 'classes/event/course_module_instance_list_viewed.php');
\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", "");
}
// Print the header.
$strgames = get_string("modulenameplural", "game");
@ -46,14 +60,14 @@ $PAGE->set_title($strgames);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
/// Get all the appropriate data
// 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)
// Print the list of instances (your module will probably extend this).
$timenow = time();
$strname = get_string("name");
@ -75,10 +89,10 @@ echo $OUTPUT->header();
foreach ($games as $game) {
if (!$game->visible) {
//Show dimmed if the mod is hidden
// Show dimmed if the mod is hidden.
$link = "<a class=\"dimmed\" href=\"view.php?id=$game->coursemodule\">$game->name</a>";
} else {
//Show normal if the mod is visible
// Show normal if the mod is visible.
$link = "<a href=\"view.php?id=$game->coursemodule\">$game->name</a>";
}
@ -93,8 +107,6 @@ echo $OUTPUT->header();
echo html_writer::table($table);
/// Finish the page
// Finish the page.
echo $OUTPUT->footer($course);
?>

4
version.php

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

Loading…
Cancel
Save