function game_sudoku_showquestions_glossary($id, $game, $attempt, $sudoku, $offsetentries, $numbers, $correctentries, $onlyshow, $showsolution) { global $CFG; $entries = game_sudoku_getglossaryentries($game, $offsetentries, $questionlist, $numbers); //I will sort with the number of each question $entries2 = array(); foreach ($entries as $q) { $ofs = $numbers[$q->id]; $entries2[$ofs] = $q; } ksort($entries2); if (count($entries2) == 0) { game_sudoku_showquestion_onfinish($id, $game, $attempt, $sudoku); return; } /// Start the form echo "<br><form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; if ($onlyshow) { $hasquestions = false; } else { $hasquestions = count($correctentries) < count($entries2); } if ($hasquestions) { echo "<center><input type=\"submit\" name=\"submit\" value=\"" . get_string('sudoku_submit', 'game') . "\"></center>\n"; } // Add a hidden field with the quiz id echo '<div>'; echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; echo '<input type="hidden" name="action" value="sudokucheckg" />'; /// Print all the questions // Add a hidden field with questionids echo '<input type="hidden" name="questionids" value="' . $questionlist . "\" />\n"; $number = 0; foreach ($entries2 as $entry) { $ofs = $numbers[$entry->id]; if (array_key_exists($ofs, $correctentries)) { continue; //I don't show the correct answers } $query = new StdClass(); $query->glossaryid = $game->glossaryid; $query->glossaryentryid = $entry->id; $s = '<b>A' . $ofs . '.</b> ' . game_show_query($game, $query, $entry->definition, 0) . '<br>'; if ($showsolution) { $s .= get_string('answer') . ': '; $s .= "<input type=\"text\" name=\"resp{$entry->id}\" value=\"{$entry->concept}\"size=30 /><br>"; } else { if ($onlyshow === false) { $s .= get_string('answer') . ': '; $s .= "<input type=\"text\" name=\"resp{$entry->id}\" size=30 /><br>"; } } echo $s . "<hr>\r\n"; } echo "</div>"; // Finish the form if ($hasquestions) { echo "<center><input type=\"submit\" name=\"submit\" value=\"" . get_string('sudoku_submit', 'game') . "\"></center>\n"; } echo "</form>\n"; }
function game_hiddenpicture_showquestion_glossary($game, $id, $query) { global $CFG, $DB; $entry = $DB->get_record('glossary_entries', array('id' => $query->glossaryentryid)); /// Start the form echo '<br>'; echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"" . get_string('hiddenpicture_mainsubmit', 'game') . "\"></center>\n"; // Add a hidden field with the queryid echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; echo '<input type="hidden" name="action" value="hiddenpicturecheckg" />'; echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; // Add a hidden field with glossaryentryid echo '<input type="hidden" name="glossaryentryid" value="' . $query->glossaryentryid . "\" />\n"; $temp = $game->glossaryid; $game->glossaryid = $game->glossaryid2; echo game_show_query($game, $query, $entry->definition); $game->glossaryid = $temp; echo get_string('answer') . ': '; echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; echo "</form><br>\n"; }
function game_showanswers_glossary($game) { 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 ($game->glossaryonlyapproved) { // Only approved glossary entries will be used. $select .= ' AND (ge.approved=1 OR teacherentry=1)'; } $sql = "SELECT ge.id,definition,concept FROM {$table} WHERE {$select} ORDER BY definition"; if (($questions = $DB->get_records_sql($sql)) === false) { return; } // Show repetitions of questions. $table = "{glossary_entries} ge, {game_repetitions} gr"; $select = "glossaryid={$game->glossaryid} AND gr.glossaryentryid=ge.id AND gr.gameid=" . $game->id; $userid = optional_param('userid', 0, PARAM_INT); if ($userid) { $select .= " AND gr.userid={$userid}"; } if ($game->glossarycategoryid) { $select .= " AND gec.entryid = ge.id " . " AND gec.categoryid = {$game->glossarycategoryid}"; $table .= ",{glossary_entries_categories} gec"; } $sql = "SELECT ge.id,SUM(repetitions) as c FROM {$table} WHERE {$select} GROUP BY ge.id"; $reps = $DB->get_records_sql($sql); echo '<table border="1">'; echo '<tr><td></td>'; echo '<td><b>' . get_string('questions', 'quiz') . '</b></td>'; echo '<td><b>' . get_string('answers', 'quiz') . '</b></td>'; if ($reps != false) { echo '<td><b>' . get_string('repetitions', 'game') . '</b></td>'; } echo "</tr>\r\n"; $line = 0; foreach ($questions as $question) { if ($game->param7 == 0) { // Not allowed spaces. if (!(strpos($question->concept, ' ') === false)) { continue; } } if ($game->param8 == 0) { // Not allowed -. if (!(strpos($question->concept, '-') === false)) { continue; } } echo '<tr>'; echo '<td>' . ++$line; echo '</td>'; $query = new StdClass(); $query->glossaryid = $game->glossaryid; $query->glossaryentryid = $question->id; echo '<td>' . game_show_query($game, $query, $question->definition) . '</td>'; echo '<td>' . $question->concept . '</td>'; if ($reps != false) { if (array_key_exists($question->id, $reps)) { $rep = $reps[$question->id]; echo '<td><center>' . $rep->c . '</td>'; } else { echo '<td> </td>'; } } echo "</tr>\r\n"; } echo "</table><br>\r\n\r\n"; }
function game_millionaire_showgrid($game, $millionaire, $id, $query, $aanswer, $info, $context) { global $CFG, $OUTPUT; $question = str_replace(array("\\'", '\\"'), array("'", '"'), $query->questiontext); if ($game->param8 == '') { $color = 408080; } else { $color = substr('000000' . base_convert($game->param8, 10, 16), -6); } $color1 = 'black'; $color2 = 'DarkOrange'; $colorback = "white"; $stylequestion = "background:{$colorback};color:{$color1}"; $stylequestionselected = "background:{$colorback};color:{$color2}"; $state = $millionaire->state; $level = $millionaire->level; $background = "style='background:#{$color}'"; echo '<form name="Form1" method="post" action="attempt.php" id="Form1">'; echo "<table cellpadding=0 cellspacing=0 border=0>\r\n"; echo "<tr {$background}>"; echo '<td rowspan=' . (17 + count($aanswer)) . '> </td>'; echo "<td colspan=6> </td>"; echo '<td rowspan=' . (17 + count($aanswer)) . '> </td>'; echo "</tr>\r\n"; echo "<tr height=10%>"; echo "<td {$background} rowspan=3 colspan=2>"; $dirgif = 'millionaire/1/'; if ($state & 1) { $gif = "5050x"; $disabled = "disabled=1"; } else { $gif = "5050"; $disabled = ""; } echo '<input type="image" ' . $disabled . ' name="Help5050" id="Help5050" Title="50 50" src="' . $OUTPUT->pix_url($dirgif . $gif, 'mod_game') . '" alt="" border="0"> '; if ($state & 2) { $gif = "telephonex"; $disabled = "disabled=1"; } else { $gif = "telephone"; $disabled = ""; } echo '<input type="image" name="HelpTelephone" ' . $disabled . ' id="HelpTelephone" Title="' . get_string('millionaire_telephone', 'game') . '" src="' . $OUTPUT->pix_url($dirgif . $gif, 'mod_game') . '" alt="" border="0"> '; if ($state & 4) { $gif = "peoplex"; $disabled = "disabled=1"; } else { $gif = "people"; $disabled = ""; } echo '<input type="image" name="HelpPeople" ' . $disabled . ' id="HelpPeople" Title="' . get_string('millionaire_helppeople', 'game') . '" src="' . $OUTPUT->pix_url($dirgif . $gif, 'mod_game') . '" alt="" border="0"> '; echo '<input type="image" name="Quit" id="Quit" Title="' . get_string('millionaire_quit', 'game') . '" src="' . $OUTPUT->pix_url($dirgif . 'x', 'mod_game') . '" alt="" border="0"> '; echo "\r\n"; echo "</td>\r\n"; $styletext = ""; if (strpos($question, 'color:') == false and strpos($question, 'background:') == false) { $styletext = "style='{$stylequestion}'"; } $aval = array(100, 200, 300, 400, 500, 1000, 1500, 2000, 4000, 5000, 10000, 20000, 40000, 80000, 150000); for ($i = 15; $i >= 1; $i--) { $btr = false; switch ($i) { case 15: echo "<td rowspan=" . (16 + count($aanswer)) . " {$background}> </td>\r\n"; $btr = true; break; case 14: case 13: echo "<tr>\n"; $btr = true; break; case 12: $question = game_show_query($game, $query, $question); echo "<tr>"; echo "<td rowspan=12 colspan=2 valign=top style=\"{$styletext}\">{$question}</td>\r\n"; $btr = true; break; case 11: case 10: case 9: case 8: case 7: case 6: case 5: case 4: case 3: case 2: case 1: echo "<tr>"; $btr = true; break; default: echo "<tr>"; $btr = true; } if ($i == $level + 1) { $style = "background:{$color1};color:{$color2}"; } else { $style = $stylequestion; } echo "<td style='{$style}' align=right>{$i}</td>"; if ($i < $level + 1) { echo "<td style='{$style}'> * </td>"; } else { if ($i == 15 and $level <= 1) { echo "<td style='{$style}'> </td>"; } else { echo "<td style='{$style}'></td>"; } } echo "<td style='{$style}' align=right>" . sprintf("%10d", $aval[$i - 1]) . "</td>\r\n"; if ($btr) { echo "</tr>\r\n"; } } echo "<tr {$background}><td colspan=10> </td></tr>\r\n"; $bfirst = true; $letters = get_string('lettersall', 'game'); for ($i = 1; $i <= count($aanswer); $i++) { $name = "btAnswer" . $i; $s = game_substr($letters, $i - 1, 1); $disabled = $state == 15 ? "disabled=1" : ""; $style = $stylequestion; if (strpos($aanswer[$i - 1], 'color:') != false or strpos($aanswer[$i - 1], 'background:') != false) { $style = ''; } if ($state == 15 and $i + 1 == $query->correct) { $style = $stylequestionselected; } $button = '<input style="' . $style . '" ' . $disabled . 'type="submit" name="' . $name . '" value="' . $s . '" id="' . $name . "1\"" . " onmouseover=\"this.style.backgroundColor = '{$color2}';{$name}.style.backgroundColor = '{$color2}';\" " . " onmouseout=\"this.style.backgroundColor = '{$colorback}';{$name}.style.backgroundColor = '{$colorback}';\" >"; $text = game_filtertext($aanswer[$i - 1], $game->course); $answer = "<span id={$name} style=\"{$style}\" " . " onmouseover=\"this.style.backgroundColor = '{$color2}';{$name}1.style.backgroundColor = '{$color2}';\" " . " onmouseout=\"this.style.backgroundColor = '{$colorback}';{$name}1.style.backgroundColor = '{$colorback}';\" >" . $text . '</span>'; if ($aanswer[$i - 1] != "") { echo "<tr>\n"; echo "<td style='{$stylequestion}'> {$button}</td>\n"; echo "<td {$style} width=100%> {$answer}</td>"; if ($bfirst) { $bfirst = false; $info = game_filtertext($info, $game->course); echo "<td style=\"{$style}\" rowspan=" . count($aanswer) . " colspan=3>{$info}</td>"; } echo "\r\n</tr>\r\n"; } } echo "<tr><td colspan=10 {$background}> </td></tr>\r\n"; echo "<input type=hidden name=state value=\"{$state}\">\r\n"; echo '<input type=hidden name=id value="' . $id . '">'; echo "<input type=hidden name=buttons value=\"" . count($aanswer) . "\">\r\n"; echo "</table>\r\n"; echo "</form>\r\n"; }
function game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, $updateattempt = false, $onlyshow = false, $showsolution = false, $context, $print = false, $showhtmlprintbutton = true) { global $CFG, $DB; if ($game->toptext != '') { echo $game->toptext . '<br>'; } echo '<br>'; $cryptex = new CryptexDB(); $language = $attempt->language; $questions = $cryptex->loadcryptex($crossm, $mask, $corrects, $attempt->language); if ($language != $attempt->language) { if (!$DB->set_field('game_attempts', 'language', $attempt->language, array('id' => $attempt->id))) { print_error("game_cross_play: Can't set language"); } } if ($attempt->language != '') { $wordrtl = game_right_to_left($attempt->language); } else { $wordrtl = right_to_left(); } $reverseprint = $wordrtl != right_to_left(); if ($reverseprint) { $textdir = 'dir="' . ($wordrtl ? 'rtl' : 'ltr') . '"'; } else { $textdir = ''; } $len = game_strlen($mask); // The count1 means there is a guested letter. // The count2 means there is a letter that not guessed. $count1 = $count2 = 0; for ($i = 0; $i < $len; $i++) { $c = game_substr($mask, $i, 1); if ($c == '1') { $count1++; } else { if ($c == '2') { $count2++; } } } if ($count1 + $count2 == 0) { $gradeattempt = 0; } else { $gradeattempt = $count1 / ($count1 + $count2); } $finished = $count2 == 0; if ($finished === false && $game->param8 > 0) { $found = false; foreach ($questions as $q) { if ($q->tries < $game->param8) { $found = true; } } if ($found == false) { $finished = true; // Rich max tries. } } if ($updateattempt) { game_updateattempts($game, $attempt, $gradeattempt, $finished); } if ($onlyshow == false and $showsolution == false) { if ($finished) { game_cryptex_onfinished($id, $game, $attempt, $cryptexrec); } } ?> <style type="text/css"><!-- .answerboxstyle { background-color: #FFFAF0; border-color: #808080; border-style: solid; border-width: 1px; display: block; padding: .75em; width: 240pt; } --></style> <?php $grade = round(100 * $gradeattempt); echo get_string('grade', 'game') . ' ' . $grade . ' %'; echo '<br>'; echo '<table border=0>'; echo '<tr><td>'; $cryptex->displaycryptex($crossm->cols, $crossm->rows, $cryptexrec->letters, $mask, $showsolution, $textdir); ?> </td> <td width=10%> </td> <td> <form method="get" action="<?php echo $CFG->wwwroot; ?> /mod/game/attempt.php"> <div id="answerbox" class="answerboxstyle" style="display:none;"> <div id="wordclue" name="wordclue" class="cluebox"> </div> <input id="action" name="action" type="hidden" value="cryptexcheck"> <input id="q" name="q" type="hidden" > <input id="id" name="id" value="<?php echo $id; ?> " type="hidden"> <div style="margin-top:1em;"><input id="answer" name="answer" type="text" size="24" style="font-weight: bold; text-transform:uppercase;" autocomplete="off"></div> <table border="0" cellspacing="0" cellpadding="0" width="100%" style="margin-top:1em;"><tr> <td align="right"> <button id="okbutton" type="submit" class="button" style="font-weight: bold;">OK</button> <button id="cancelbutton" type="button" class="button" onclick="DeselectCurrentWord();">Cancel</button> </td></tr></table> </form> </td> </tr> </table> <?php if ($showhtmlprintbutton) { echo '<br><button id="finishattemptbutton" type="button" onclick="OnEndGame();" >' . get_string('finish', 'game'); echo '</button>'; echo '<button id="printbutton" type="button" onclick="OnPrint();" >' . get_string('print', 'game'); echo '</button><br>'; } if ($showhtmlprintbutton) { ?> <script> function PrintHtmlClick() { document.getElementById("printbutton").style.display = "none"; window.print(); document.getElementById("printbutton").style.display = "block"; } function OnPrint() { <?php global $CFG; $params = "id={$id}&gameid={$game->id}"; echo "window.open( \"{$CFG->wwwroot}/mod/game/print.php?{$params}\");"; ?> } function OnEndGame() { <?php global $CFG; $params = 'id=' . $id . '&action=cryptexcheck&g=&finishattempt=1'; echo "window.location = \"{$CFG->wwwroot}/mod/game/attempt.php?{$params}\";\r\n"; ?> } </script> <?php } $i = 0; $else = ''; $contextglossary = false; foreach ($questions as $key => $q) { $i++; if ($showsolution == false) { // When I want to show the solution a want to show the questions to. if (array_key_exists($q->id, $corrects)) { continue; } } $question = game_show_query($game, $q, "{$i}. " . $q->questiontext, $context); $question2 = strip_tags($question); // ADDED BY DP (AUG 2009) - fixes " breaking the Answer button for this question. echo "<script>var msg{$q->id}=" . json_encode($question2) . ';</script>'; if ($onlyshow == false and $showsolution == false) { if ($game->param8 == 0 || $game->param8 > $q->tries) { $question .= ' <input type="submit" value="' . get_string('answer') . '" onclick="OnCheck( ' . $q->id . ",msg{$q->id});\" />"; } } echo $question; if ($showsolution) { echo " {$q->answertext}<B></b>"; } echo '<br>'; } if ($game->bottomtext != '') { echo '<br><br>' . $game->bottomtext; } ?> <script> function OnCheck( id, question) { document.getElementById("q").value = id; document.getElementById("wordclue").innerHTML = question; // Finally, show the answer box. document.getElementById("answerbox").style.display = "block"; try { document.getElementById("answer").focus(); document.getElementById("answer").select(); } catch (e) { } } </script> <?php if ($print) { echo '<body onload="window.print()">'; } else { echo '<body>'; } }