diff --git a/attempt.php b/attempt.php index 6bcc556..f4b0675 100755 --- a/attempt.php +++ b/attempt.php @@ -55,7 +55,7 @@ /// Check login and get context. require_login($course->id, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = game_get_context_module_instance( $cm->id); require_capability('mod/game:view', $context); /// Cache some other capabilites we use several times. diff --git a/bookquiz/play.php b/bookquiz/play.php index 5eebbb7..ca1aba6 100755 --- a/bookquiz/play.php +++ b/bookquiz/play.php @@ -86,6 +86,7 @@ $previd = null; $nextid = null; $found = 0; $scoreattempt = 0; +$lastid = 0; foreach ($chapters as $ch) { $scoreattempt++; if ($found) { @@ -98,6 +99,7 @@ foreach ($chapters as $ch) { if (!$found) { $previd = $ch->id; } + $lastid = $ch->id; } if ($ch == current($chapters)) { $nextid = $ch->id; @@ -132,7 +134,9 @@ if ($nextid) { game_updateattempts_maxgrade( $game, $attempt, 1, 0); $sec = ''; if( !isset( $cm)) - $cm = get_coursemodule_from_id('game', $game->id); + { + $cm = get_coursemodule_from_instance('game', $game->id, $game->course); + } if ($section = $DB->get_record('course_sections', array( 'id' => $cm->section))) { $sec = $section->section; } @@ -140,7 +144,7 @@ if ($nextid) { if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) { print_error("Course Module ID was incorrect id=$id"); } - $chnavigation .= ''.get_string('navexit', 'book').''; + $chnavigation .= 'pix_url('bookquiz/nav_exit', 'mod_game').'" class="bigicon" alt="'.get_string('navexit', 'book').'" />'; } require( 'toc.php'); @@ -188,7 +192,9 @@ $tocwidth = '10%'; $content .= '

'.$currtitle.'
'.$currsubtitle.'

'; } } - $content .= $chapter->content; + $cmbook = get_coursemodule_from_instance( 'book', $game->bookid, $game->course); + $modcontext = game_get_context_module_instance( $cmbook->id); + $content .= game_filterbook( $chapter->content, $chapter->id, $modcontext->id, $game->course); $nocleanoption = new object(); $nocleanoption->noclean = true; @@ -196,7 +202,7 @@ $tocwidth = '10%'; if( $nextbutton != ''){ echo $nextbutton; } - echo format_text($content, FORMAT_HTML, $nocleanoption, $id); + echo format_text($content, FORMAT_HTML, $nocleanoption); if( $nextbutton != ''){ echo $nextbutton; } @@ -221,7 +227,13 @@ function game_bookquiz_play_computelastchapter( $game, &$bookquiz) { global $DB; + if( $game->bookid == 0) + { + print_error( 'Not defined a book on this game'); + } + $pagenum = $DB->get_field( 'book_chapters', 'min(pagenum) as p', array('bookid' => $game->bookid)); + if( $pagenum){ $bookquiz->lastchapterid = $DB->get_field( 'book_chapters', 'id', array('bookid' => $game->bookid, 'pagenum' => $pagenum)); diff --git a/bookquiz/questions.php b/bookquiz/questions.php index 5e9ae70..dc65371 100755 --- a/bookquiz/questions.php +++ b/bookquiz/questions.php @@ -8,7 +8,7 @@ **/ require_once("../../../config.php"); - require_once( "../header.php"); + require_once( "../headergame.php"); require_once("../locallib.php"); $attempt = game_getattempt( $game, $detail); @@ -21,7 +21,7 @@ $ids = explode( ',', $form->ids); game_bookquiz_save( $game->id, $game->bookid, $ids, $form); - redirect("{$CFG->wwwroot}/mod/game/bookquiz/questions.php?id=$cm->id", '', 0); + //redirect("{$CFG->wwwroot}/mod/game/bookquiz/questions.php?id=$cm->id", '', 0); } /// Print upload form @@ -36,7 +36,7 @@ } } - $context = get_context_instance(50, $COURSE->id); + $context = game_get_context_course_instance( $COURSE->id); $select = " contextid in ($context->id)"; $a = array(); @@ -160,7 +160,7 @@ function game_bookquiz_save( $gameid, $bookid, $ids, $form) } }else { - unset( $updrec); + $updrec = new StdClass; $updrec->id = $recids[ $chapterid]; $updrec->questioncategoryid = $categoryid; if (($DB->update_record( 'game_bookquiz_questions', $updrec)) == false) { diff --git a/cross/cross_class.php b/cross/cross_class.php index 16f4c97..352d330 100755 --- a/cross/cross_class.php +++ b/cross/cross_class.php @@ -630,7 +630,7 @@ class Cross if( $game->glossaryid) { $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); - $contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id); + $contextglossary = game_get_context_module_instance( $cmglossary->id); } foreach ($crossd as $rec) { diff --git a/cross/play.php b/cross/play.php index 3ad4823..680dede 100755 --- a/cross/play.php +++ b/cross/play.php @@ -1042,7 +1042,7 @@ if( $attempt != false){ -dirroot.'/lib/formslib.php'); require( 'locallib.php'); require( 'headergame.php'); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = game_get_context_module_instance( $cm->id); if (!has_capability('mod/game:viewreports', $context)) return; @@ -44,18 +44,22 @@ class mod_game_exporthtml_form extends moodleform { //filename $mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size'=>'30')); $mform->setDefault('filename',$html->filename); + $mform->setType('filename', PARAM_TEXT); //html title $mform->addElement('text', 'title', get_string('html_title', 'game'), array('size'=>'80')); $mform->setDefault('title',$html->title); + $mform->setType('title', PARAM_TEXT); //fields for hangman if( $game->gamekind == 'hangman') { $mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size'=>'5')); $mform->setDefault('maxpicturewidth',$html->maxpicturewidth); + $mform->setType('maxpicturewidth', PARAM_INT); $mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size'=>'5')); $mform->setDefault('maxpictureheight',$html->maxpictureheight); + $mform->setType('maxpictureheight', PARAM_INT); } //fiels for cross @@ -68,7 +72,9 @@ class mod_game_exporthtml_form extends moodleform { } $mform->addElement('hidden', 'q', $game->id); + $mform->setType('q', PARAM_INT); $mform->addElement('hidden', 'target', 'html'); + $mform->setType('target', PARAM_TEXT); //------------------------------------------------------------------------------- $mform->addElement('submit', 'submitbutton', get_string( 'export', 'game')); @@ -138,25 +144,36 @@ class mod_game_exportjavame_form extends moodleform { //filename $mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size'=>'30')); $mform->setDefault('filename',$javame->filename); + $mform->setType('filename', PARAM_TEXT); $mform->addElement('text', 'icon', get_string('javame_icon', 'game')); $mform->setDefault('icon',$javame->icon); + $mform->setType('icon', PARAM_TEXT); $mform->addElement('text', 'createdby', get_string('javame_createdby', 'game')); $mform->setDefault('createdby',$javame->createdby); + $mform->setType('createdby', PARAM_TEXT); $mform->addElement('text', 'vendor', get_string('javame_vendor', 'game')); $mform->setDefault('vendor',$javame->vendor); + $mform->setType('vendor', PARAM_TEXT); $mform->addElement('text', 'name', get_string('javame_name', 'game'), array('size'=>'80')); $mform->setDefault('name',$javame->name); + $mform->setType('name', PARAM_TEXT); $mform->addElement('text', 'description', get_string('javame_description', 'game'), array('size'=>'80')); $mform->setDefault('description',$javame->description); + $mform->setType('description', PARAM_TEXT); $mform->addElement('text', 'version', get_string('javame_version', 'game'), array('size'=>'10')); $mform->setDefault('version',$javame->version); + $mform->setType('version', PARAM_TEXT); $mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size'=>'5')); $mform->setDefault('maxpicturewidth',$javame->maxpicturewidth); + $mform->setType('maxpicturewidth', PARAM_INT); $mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size'=>'5')); $mform->setDefault('maxpictureheight',$javame->maxpictureheight); + $mform->setType('maxpictureheight', PARAM_INT); $mform->addElement('hidden', 'q', $game->id); + $mform->setType('q', PARAM_INT); $mform->addElement('hidden', 'target', 'javame'); + $mform->setType('target', PARAM_TEXT); //------------------------------------------------------------------------------- $mform->addElement('submit', 'submitbutton', get_string( 'export', 'game')); diff --git a/hangman/play.php b/hangman/play.php index f162887..67eeff6 100755 --- a/hangman/play.php +++ b/hangman/play.php @@ -302,7 +302,7 @@ function hangman_showpage(&$done, &$correct, &$wrong, $max, &$word_line, &$word_ }else { $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); - $contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id); + $contextglossary = game_get_context_module_instance( $cmglossary->id); $query->questiontext = game_filterglossary(str_replace( '\"', '"', $query->questiontext), $query->glossaryentryid, $contextglossary->id, $game->course); } diff --git a/headergame.php b/headergame.php index 89126fc..fb1c0f0 100755 --- a/headergame.php +++ b/headergame.php @@ -32,7 +32,7 @@ /// Check login and get context. require_login($course->id, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = game_get_context_module_instance( $cm->id); require_capability('mod/game:view', $context); /// Cache some other capabilites we use several times. diff --git a/hiddenpicture/play.php b/hiddenpicture/play.php index 68994d7..aa728b5 100755 --- a/hiddenpicture/play.php +++ b/hiddenpicture/play.php @@ -111,7 +111,7 @@ function game_hiddenpicture_selectglossaryentry( $game, $attempt){ $keys = array(); $fs = get_file_storage(); $cmg = get_coursemodule_from_instance('glossary', $game->glossaryid2, $game->course); - $context = get_context_instance(CONTEXT_MODULE, $cmg->id); + $context = game_get_context_module_instance( $cmg->id); foreach( $recs as $rec){ $files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $rec->id, "timemodified", false); if( $files) diff --git a/locallib.php b/locallib.php index 4f1a83e..e894547 100755 --- a/locallib.php +++ b/locallib.php @@ -1228,6 +1228,35 @@ function game_filterglossary( $text, $entryid, $contextid, $courseid) } +function game_filterbook( $text, $chapterid, $contextid, $courseid) +{ + global $CFG, $DB; + + for(;;) + { + $find='@@PLUGINFILE@@'; + $pos = strpos( $text, $find); + if( $pos === false) + break; + + $pos2 = strpos( $text,'/', $pos); + if( $pos2 === false) + break; + + $pos3 = strpos( $text,'"', $pos); + if( $pos3 === false) + break; + + $file = substr( $text, $pos2+1, $pos3-$pos2-1); + + $new = $CFG->wwwroot."/pluginfile.php/$contextid/mod_book/chapter/$chapterid/$file"; + $text = substr( $text, 0, $pos).$new.substr( $text,$pos3); + } + $questiontext = str_replace( '$$'.'\\'.'\\'.'frac', '$$\\'.'frac', $text); + return game_filtertext( $text, $courseid); + +} + function game_filterquestion( $questiontext, $questionid, $contextid, $courseid) { global $CFG, $DB; @@ -1289,7 +1318,7 @@ function game_filtertext( $text, $courseid){ $formatoptions = new stdClass(); $formatoptions->noclean = true; $formatoptions->filter = 1; - $text = trim( format_text( $text, FORMAT_MOODLE, $formatoptions, $courseid)); + $text = trim( format_text( $text, FORMAT_MOODLE, $formatoptions)); $start = '
'; if( substr( $text, 0, strlen( $start)) == $start){ @@ -1919,12 +1948,17 @@ function game_debug_array( $title, $a) function game_get_version() { - global $DB; + global $CFG, $DB; - if( ($rec = $DB->get_record( 'modules', array( 'name' => 'game'), 'id,version')) === false) + if( ($rec = $DB->get_record( 'modules', array( 'name' => 'game'))) === false) return ''; - - return $rec->version; + + if( isset( $rec->version)) + return $rec->version; + + $module = new StdClass; + require($CFG->dirroot . '/mod/game/version.php'); + return $module->version; } function game_can_start_new_attempt( $game) @@ -1990,3 +2024,37 @@ function game_strpos( $haystack, $needle, $offset = 0) else return textlib_get_instance()->strpos( $haystack, $needle, $offset); } + + +function game_get_context_course_instance( $courseid) +{ + if( class_exists( 'context_course')) + return context_course::instance( $courseid); + + return get_context_instance( 50, $courseid); +} + +function game_get_context_module_instance( $moduleid) +{ + if( class_exists( 'context_module')) + return context_module::instance( $moduleid); + + return get_context_instance( CONTEXT_MODULE, $moduleid); +} + +function game_show_query( $game, $query, $text) +{ + if( $game->glossaryid) + { + $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); + $contextglossary = game_get_context_module_instance( $cmglossary->id); + return game_filterglossary(str_replace( '\"', '"', $text), $query->glossaryentryid, $contextglossary->id, $game->course); + }else if( $query->questionid) + { + $context = game_get_context_module_instance( $game->id); + $text = str_replace( array("\'", '\"'), array("'", '"'), $text); + return game_filterquestion($text, $query->questionid, $context->id, $game->course); + } + + return $text; +} diff --git a/millionaire/play.php b/millionaire/play.php index cabedc5..fb4b1b2 100755 --- a/millionaire/play.php +++ b/millionaire/play.php @@ -176,7 +176,8 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer, $bTR = true; break; case 12: - $question = game_filterquestion($question, $query->questionid, $context->id, $game->course); + //$question = game_filterquestion($question, $query->questionid, $context->id, $game->course); + $question = game_show_query( $game, $query, $question, $context); echo ""; echo "$question\r\n"; $bTR = true; diff --git a/mod_form.php b/mod_form.php index 4bc7cb2..b36b50e 100755 --- a/mod_form.php +++ b/mod_form.php @@ -109,7 +109,7 @@ class mod_game_mod_form extends moodleform_mod { // Question Category - Short Answer if( $gamekind != 'bookquiz'){ - $context = get_context_instance(50, $COURSE->id); + $context = game_get_context_course_instance( $COURSE->id); $select = " contextid in ($context->id)"; $a = array(); @@ -378,7 +378,7 @@ class mod_game_mod_form extends moodleform_mod { if($recs = $DB->get_records('glossary', array( 'course' => $COURSE->id), 'id,name')){ foreach($recs as $rec){ $cmg = get_coursemodule_from_instance('glossary', $rec->id, $COURSE->id); - $context = get_context_instance(CONTEXT_MODULE, $cmg->id); + $context = game_get_context_module_instance( $cmg->id); if( $DB->record_exists( 'files', array( 'contextid' => $context->id))){ $a[$rec->id] = $rec->name; } diff --git a/preview.php b/preview.php index 87f5f0c..46135b8 100755 --- a/preview.php +++ b/preview.php @@ -20,7 +20,7 @@ require_once( "headergame.php"); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = game_get_context_module_instance( $cm->id); if (!has_capability('mod/game:viewreports', $context)){ print_error( get_string( 'only_teachers', 'game')); diff --git a/showanswers.php b/showanswers.php index 5b404e7..f268d78 100755 --- a/showanswers.php +++ b/showanswers.php @@ -53,7 +53,7 @@ function game_showusers($game) $users = array(); - $context = get_context_instance(CONTEXT_COURSE, $game->course); + $context = game_get_context_course_instance( $game->course); if ($courseusers = get_enrolled_users($context)) { foreach ($courseusers as $courseuser) { @@ -377,8 +377,13 @@ function game_showanswers_glossary( $game) echo ''; echo ''.(++$line); echo ''; - - echo ''.$question->definition.''; + + $query = new StdClass; + $query->glossaryid = $game->glossaryid; + $query->glossaryentryid = $question->id; + echo ''.game_show_query( $game, $query, $question->definition).''; + + echo ''.$question->concept.''; if( $reps != false){ if( array_key_exists( $question->id, $reps)) diff --git a/showattempts.php b/showattempts.php index a708aaf..de7da67 100755 --- a/showattempts.php +++ b/showattempts.php @@ -37,7 +37,7 @@ $users = array(); - $context = get_context_instance(CONTEXT_COURSE, $game->course); + $context = game_get_context_course_instance( $game->course); $groupid = optional_param('groupid',0, PARAM_INT); $sql = "SELECT DISTINCT ra.userid,u.lastname,u.firstname FROM {role_assignments} ra, {user} u ". diff --git a/sudoku/play.php b/sudoku/play.php index 842a3a4..3fbb084 100755 --- a/sudoku/play.php +++ b/sudoku/play.php @@ -460,7 +460,10 @@ function game_sudoku_showquestions_glossary( $id, $game, $attempt, $sudoku, $off continue; //I don't show the correct answers } - $s = 'A'.$ofs.'. '.game_filtertext( $entry->definition, 0).'
'; + $query = new StdClass; + $query->glossaryid = $game->glossaryid; + $query->glossaryentryid = $entry->id; + $s = 'A'.$ofs.'. '.game_show_query( $game, $query, $entry->definition, 0).'
'; if( $showsolution){ $s .= get_string( 'answer').': '; $s .= "id}\" value=\"$entry->concept\"size=30 />
"; diff --git a/version.php b/version.php index b337237..739a9c2 100755 --- a/version.php +++ b/version.php @@ -11,7 +11,7 @@ defined('MOODLE_INTERNAL') || die(); $module->component = 'mod_game'; // Full name of the plugin (used for diagnostics) -$module->version = 2013101901; // The current module version (Date: YYYYMMDDXX) +$module->version = 2013120101; // The current module version (Date: YYYYMMDDXX) $module->requires = 2010112400; // Requires Moodle 2.0 $module->cron = 0; // Period for cron to check this module (secs) -$module->release = '3.10.19.1'; +$module->release = '3.12.1.1'; diff --git a/view.php b/view.php index 536f647..4fd0bd5 100755 --- a/view.php +++ b/view.php @@ -20,7 +20,7 @@ /// Check login and get context. require_login($course->id, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = game_get_context_module_instance( $cm->id); require_capability('mod/game:view', $context); $timenow = time();