Browse Source

Fix: Problem when a question contains an apostrophe

MOODLE_20_STABLE
bdaloukas 12 years ago
parent
commit
974d20341e
  1. 3
      cross/play.php
  2. 15
      cryptex/play.php
  3. 3
      hangman/play.php
  4. 7
      locallib.php
  5. 2
      millionaire/play.php
  6. 27
      showanswers.php
  7. 4
      version.php

3
cross/play.php

@ -92,7 +92,10 @@ function showlegend( $legend, $title)
echo "<br><b>$title</b><br>"; echo "<br><b>$title</b><br>";
foreach( $legend as $key => $line) foreach( $legend as $key => $line)
{
$line = game_repairquestion( $line);
echo game_filtertext( "$key: $line<br>", 0); echo game_filtertext( "$key: $line<br>", 0);
}
} }
function game_cross_play( $id, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution, $endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton,$showstudentguess, $context) function game_cross_play( $id, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution, $endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton,$showstudentguess, $context)

15
cryptex/play.php

@ -84,17 +84,6 @@ function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $
return game_cryptex_play( $id, $game, $attempt, $cryptexrec, $crossm, false, false, false, $context); return game_cryptex_play( $id, $game, $attempt, $cryptexrec, $crossm, false, false, false, $context);
} }
function cryptex_showlegend( $legend, $title)
{
if( count( $legend) == 0)
return;
echo "<br><b>$title</b><br>";
foreach( $legend as $key => $line)
echo "$key: $line<br>";
}
//q means game_queries.id //q means game_queries.id
function game_cryptex_check( $id, $game, $attempt, $cryptexrec, $q, $answer, $context) function game_cryptex_check( $id, $game, $attempt, $cryptexrec, $q, $answer, $context)
{ {
@ -268,7 +257,7 @@ width: 240pt;
$i = 0; $i = 0;
$else = ''; $else = '';
$contextglossary = false; $contextglossary = false;
foreach( $questions as $key => $q){//print_r( $q); foreach( $questions as $key => $q){
$i++; $i++;
if( $showsolution == false){ if( $showsolution == false){
//When I want to show the solution a want to show the questions to. //When I want to show the solution a want to show the questions to.
@ -278,7 +267,7 @@ width: 240pt;
} }
$question = "$i. ".$q->questiontext; $question = "$i. ".$q->questiontext;
$question = game_filterquestion(str_replace( '\"', '"', $question), $q->questionid, $context->id, $game->course); $question = game_filterquestion(str_replace( array( "\'", '\"'), array( "'", '"'), $question), $q->questionid, $context->id, $game->course);
$question2 = strip_tags($question); //ADDED BY DP (AUG 2009) - fixes " breaking the Answer button for this question $question2 = strip_tags($question); //ADDED BY DP (AUG 2009) - fixes " breaking the Answer button for this question
if( ($onlyshow == false) and ($showsolution == false)){ if( ($onlyshow == false) and ($showsolution == false)){
if( ($game->param8 == 0) || ($game->param8 > $q->tries)) if( ($game->param8 == 0) || ($game->param8 > $q->tries))

3
hangman/play.php

@ -297,7 +297,8 @@ function hangman_showpage(&$done, &$correct, &$wrong, $max, &$word_line, &$word_
if( $query->questionid) if( $query->questionid)
{ {
$query->questiontext = game_filterquestion(str_replace( '\"', '"', $query->questiontext), $query->questionid, $context->id, $game->course); $questiontext = str_replace( array("\'", '\"'), array("'", '"'), $query->questiontext);
$query->questiontext = game_filterquestion($questiontext, $query->questionid, $context->id, $game->course);
}else }else
{ {
$cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course);

7
locallib.php

@ -416,7 +416,7 @@ function game_questions_selectrandom_detail( $table, $select, $id_field="id", $c
return $a; return $a;
}else }else
{ {
$id = array_rand( $a, $count); $id = array_rand( $a, $count);print_r( $a); echo "count=$count<br>";
return ( $count == 1 ? array( $id) : $id); return ( $count == 1 ? array( $id) : $id);
} }
} }
@ -1321,9 +1321,8 @@ function game_repairquestion( $s){
} }
$s = substr( $s, 0, -6); $s = substr( $s, 0, -6);
} }
$s = str_replace( array("\'", '\"'), array("'", '"'), $s);
$s = str_replace( "\'", "'", $s);
return $s; return $s;
} }

2
millionaire/play.php

@ -86,7 +86,7 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
{ {
global $OUTPUT; global $OUTPUT;
$question = str_replace( '\"', '"', $query->questiontext); $question = str_replace( array("\'", '\"'), array("'", '"'), $query->questiontext);
if( $game->param8 == '') if( $game->param8 == '')
$color = 408080; $color = 408080;

27
showanswers.php

@ -30,7 +30,7 @@
echo '<br><br>'; echo '<br><br>';
$existsbook = ($DB->get_record( 'modules', array( 'name' => 'book'), 'id,id')); $existsbook = ($DB->get_record( 'modules', array( 'name' => 'book'), 'id,id'));
game_showanswers( $game, $existsbook); game_showanswers( $game, $existsbook, $context);
echo $OUTPUT->footer(); echo $OUTPUT->footer();
@ -106,7 +106,7 @@ function game_showusers($game)
echo $output . '</select>' . "\n"; echo $output . '</select>' . "\n";
} }
function game_showanswers( $game, $existsbook) function game_showanswers( $game, $existsbook, $context)
{ {
if( $game->gamekind == 'bookquiz' and $existsbook){ if( $game->gamekind == 'bookquiz' and $existsbook){
game_showanswers_bookquiz( $game); game_showanswers_bookquiz( $game);
@ -115,13 +115,13 @@ function game_showanswers( $game, $existsbook)
switch( $game->sourcemodule){ switch( $game->sourcemodule){
case 'question': case 'question':
game_showanswers_question( $game); game_showanswers_question( $game, $context);
break; break;
case 'glossary': case 'glossary':
game_showanswers_glossary( $game); game_showanswers_glossary( $game);
break; break;
case 'quiz': case 'quiz':
game_showanswers_quiz( $game); game_showanswers_quiz( $game, $context);
break; break;
} }
} }
@ -144,7 +144,7 @@ function game_showanswers_appendselect( $game)
return ''; return '';
} }
function game_showanswers_question( $game) function game_showanswers_question( $game, $context)
{ {
global $DB; global $DB;
@ -159,8 +159,8 @@ function game_showanswers_question( $game)
} }
}else }else
{ {
$context = get_context_instance(50, $COURSE->id); $context2 = get_context_instance(50, $COURSE->id);
$select = " contextid in ($context->id)"; $select = " contextid in ($context2->id)";
$select2 = ''; $select2 = '';
if( $recs = $DB->get_records_select( 'question_categories', $select, null, 'id,id')){ if( $recs = $DB->get_records_select( 'question_categories', $select, null, 'id,id')){
foreach( $recs as $rec){ foreach( $recs as $rec){
@ -175,11 +175,11 @@ function game_showanswers_question( $game)
$showcategories = ($game->gamekind == 'bookquiz'); $showcategories = ($game->gamekind == 'bookquiz');
$order = ($showcategories ? 'category,questiontext' : 'questiontext'); $order = ($showcategories ? 'category,questiontext' : 'questiontext');
game_showanswers_question_select( $game, '{question} q', $select, '*', $order, $showcategories, $game->course); game_showanswers_question_select( $game, '{question} q', $select, '*', $order, $showcategories, $game->course, $context);
} }
function game_showanswers_quiz( $game) function game_showanswers_quiz( $game, $context)
{ {
global $CFG; global $CFG;
@ -189,11 +189,11 @@ function game_showanswers_quiz( $game)
game_showanswers_appendselect( $game); game_showanswers_appendselect( $game);
$table = '{question} q,{quiz_question_instances} qqi'; $table = '{question} q,{quiz_question_instances} qqi';
game_showanswers_question_select( $game, $table, $select, 'q.*', 'category,questiontext', false, $game->course); game_showanswers_question_select( $game, $table, $select, 'q.*', 'category,questiontext', false, $game->course, $context);
} }
function game_showanswers_question_select( $game, $table, $select, $fields='*', $order='questiontext', $showcategoryname=false, $courseid=0) function game_showanswers_question_select( $game, $table, $select, $fields, $order, $showcategoryname, $courseid, $context)
{ {
global $CFG, $DB, $OUTPUT; global $CFG, $DB, $OUTPUT;
@ -219,7 +219,7 @@ function game_showanswers_question_select( $game, $table, $select, $fields='*',
$select = "course=$courseid"; $select = "course=$courseid";
}else{ }else{
$context = get_context_instance(50, $courseid); $context = get_context_instance(50, $courseid);
$select = " contextid in ($context->id)"; $select = " contextid in ($context->id)";
} }
break; break;
} }
@ -260,7 +260,8 @@ function game_showanswers_question_select( $game, $table, $select, $fields='*',
echo '<td>'; echo '<td>';
echo "<a title=\"Edit\" href=\"{$CFG->wwwroot}/question/question.php?inpopup=1&amp;id=$question->id&courseid=$courseid\" target=\"_blank\"><img src=\"".$OUTPUT->pix_url('t/edit')."\" alt=\"Edit\" /></a> "; echo "<a title=\"Edit\" href=\"{$CFG->wwwroot}/question/question.php?inpopup=1&amp;id=$question->id&courseid=$courseid\" target=\"_blank\"><img src=\"".$OUTPUT->pix_url('t/edit')."\" alt=\"Edit\" /></a> ";
echo $question->questiontext.'</td>';
echo game_filterquestion(str_replace( array( "\'", '\"'), array( "'", '"'), $question->questiontext), $question->id, $context->id, $game->course);
switch( $question->qtype){ switch( $question->qtype){
case 'shortanswer': case 'shortanswer':

4
version.php

@ -11,7 +11,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$module->component = 'mod_game'; // Full name of the plugin (used for diagnostics) $module->component = 'mod_game'; // Full name of the plugin (used for diagnostics)
$module->version = 2013072901; // The current module version (Date: YYYYMMDDXX) $module->version = 2013072902; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2010112400; // Requires Moodle 2.0 $module->requires = 2010112400; // Requires Moodle 2.0
$module->cron = 0; // Period for cron to check this module (secs) $module->cron = 0; // Period for cron to check this module (secs)
$module->release = '3.7.29'; $module->release = '3.7.29.2';

Loading…
Cancel
Save