function game_compute_reserve_print($attempt, &$wordrtl, &$reverseprint) { if (function_exists('right_to_left')) { if ($attempt->language != '') { $wordrtl = game_right_to_left($attempt->language); } else { $wordrtl = right_to_left(); } $reverseprint = $wordrtl != right_to_left(); } else { $reverseprint = false; $wordrtl = 'ltr'; } }
function game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, $updateattempt = false, $onlyshow = false, $showsolution = false, $context) { global $DB; global $CFG; 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 = textlib::strlen($mask); //count1 means there is a guested letter //count2 means there is a letter that not guessed $count1 = $count2 = 0; for ($i = 0; $i < $len; $i++) { $c = textlib::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 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 $grade = round(100 * $gradeattempt); echo '<br>' . get_string('grade', 'game') . ' ' . $grade . ' %'; echo "<br><br>"; $i = 0; $else = ''; $contextglossary = false; foreach ($questions as $key => $q) { //print_r( $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 = "{$i}. " . $q->questiontext; $question = game_filterquestion(str_replace('\\"', '"', $question), $q->questionid, $context->id, $game->course); $question2 = strip_tags($question); //ADDED BY DP (AUG 2009) - fixes " breaking the Answer button for this question 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 . ',\'' . $question2 . '\');" />'; } } 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 }
function game_hangman_play($id, $game, $attempt, $hangman, $onlyshow, $showsolution, $context) { global $CFG, $DB, $OUTPUT; $query = $DB->get_record('game_queries', array('id' => $hangman->queryid)); if ($attempt->language != '') { $wordrtl = game_right_to_left($attempt->language); } else { $wordrtl = right_to_left(); } $reverseprint = $wordrtl != right_to_left(); if ($game->toptext != '') { echo $game->toptext . '<br>'; } $max = $game->param10; // Maximum number of wrongs. if ($max <= 0) { $max = 6; } hangman_showpage($done, $correct, $wrong, $max, $wordline, $wordline2, $links, $game, $attempt, $hangman, $query, $onlyshow, $showsolution, $context); if (!$done) { if ($wrong > $max) { $wrong = $max; } if ($game->param3 == 0) { $game->param3 = 1; } echo "\r\n<br/><img src=\"" . $OUTPUT->pix_url('hangman/' . $game->param3 . '/hangman_' . $wrong, 'mod_game') . "\""; $message = sprintf(get_string('hangman_wrongnum', 'game'), $wrong, $max); echo ' ALIGN="MIDDLE" BORDER="0" HEIGHT="100" alt="' . $message . '"/>'; if ($wrong >= $max) { // This word is incorrect. If reach the max number of word I have to finish else continue with next word. hangman_onincorrect($id, $wordline, $query->answertext, $game, $attempt, $hangman, $onlyshow, $showsolution); } else { $i = $max - $wrong; if ($i > 1) { echo ' ' . get_string('hangman_restletters_many', 'game', $i); } else { echo ' ' . get_string('hangman_restletters_one', 'game'); } if ($reverseprint) { echo '<SPAN dir="' . ($wordrtl ? 'rtl' : 'ltr') . '">'; } echo "<br/><font size=\"5\">\n{$wordline}</font>\r\n"; if ($wordline2 != '') { echo "<br/><font size=\"5\">\n{$wordline2}</font>\r\n"; } if ($reverseprint) { echo "</SPAN>"; } if ($hangman->finishedword == false) { echo "<br/><br/><BR/>" . get_string('hangman_letters', 'game') . $links . "\r\n"; } } } else { // This word is correct. If reach the max number of word I have to finish else continue with next word. hangman_oncorrect($id, $wordline, $game, $attempt, $hangman, $query); } echo "<br/><br/>" . get_string('grade', 'game') . ' : ' . round($query->percent * 100) . ' %'; if ($hangman->maxtries > 1) { echo '<br/><br/>' . get_string('hangman_gradeinstance', 'game') . ' : ' . round($hangman->corrects / $hangman->maxtries * 100) . ' %'; } if ($game->bottomtext != '') { echo '<br><br>' . $game->bottomtext; } }
function game_cross_play($id, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution, $endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton) { global $CFG, $DB; $cross = new CrossDB(); $language = $attempt->language; $info = $cross->load($g, $done, $html, $game, $attempt, $crossrec, $onlyshow, $showsolution, $endofgame, $showhtmlsolutions, $attempt->language); if ($language != $attempt->language) { if (!$DB->set_field('game_attempts', 'language', $attempt->language, array('id' => $attempt->id))) { error("game_cross_play: Can't set language"); } } if ($done or $endofgame) { if (!($cm = $DB->get_record('course_modules', array('id' => $id)))) { print_error("Course Module ID was incorrect id={$id}"); } if ($endofgame == false) { echo '<B>' . get_string('cross_win', 'game') . '</B><BR>'; } echo '<br>'; echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id={$id}&forcenew=1\">" . get_string('cross_new', 'game') . '</a> '; //echo "<a href=\"$CFG->wwwroot/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; } else { if ($info != '') { echo "<br>{$info}<br>"; } } 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 = ''; } ?> <style type="text/css"><!-- .answerboxstyle { background-color: #FFFAF0; border-color: #808080; border-style: solid; border-width: 1px; display: block; padding: .75em; width: 240pt; } .box { border-style: solid; border-width: 1pt; cursor: pointer; font-size: .12in; font-weight: bold; height: .18in; overflow: hidden; text-align: center; width: .18in; } .boxcheated_sel { background-color: #FFF1D7; border-color: #C00000; color: #2080D0; } .boxcheated_unsel { background-color: #ffffff; border-color: #606060; color: #2080D0; } .boxerror_sel { background-color: #FFF1D7; border-color: #C00000; color: #BF0000; } .boxerror_unsel { background-color: #FFF0F0; border-color: #606060; color: #BF0000; } .boxnormal_sel { background-color: #FFF1D7; border-color: #C00000; color: #000000; } .boxnormal_unsel { background-color: #ffffff; border-color: #606060; color: #000000; } .button { width: 64pt; } .cluebox { border-bottom-width: 1px; border-color: #c0c0c0; border-left-width: 0px; border-right-width: 0px; border-style: solid; border-top-width: 1px; font-size: 85%; margin-top: 1em; padding-bottom: .5em; padding-left: 0pt; padding-right: 0pt; padding-top: .5em; } .crosswordarea { background-color: #D0D8E0; border-color: #808080; border-style: solid; border-width: 2px; padding: .5em; } a, a:visited { color: #2080d0; text-decoration: none; } a:hover { color: #ff8000; text-decoration: underline; } body { background-color: white; cursor: default; } body, button, input, p, td { font-family: Verdana, Arial, Sans-Serif; font-size: small; } button { cursor: pointer; } h1, h2, h3 { color: #5F78A2; font-family: Franklin Gothic Medium, Arial, Sans-Serif; font-weight: normal; } p { margin-top: 1em; } --></style> </head> <?php if ($print) { echo '<body onload="window.print()">'; } else { echo '<body>'; } if ($game->toptext != '') { echo $game->toptext . '<br>'; } ?> <h1></h1> <div id="waitmessage" class="answerboxstyle"> This interactive crossword puzzle requires JavaScript and a reasonably recent web browser, such as Internet Explorer 5.5 or later, Netscape 7, Mozilla, Firefox, or Safari. If you have disabled web page scripting, please re-enable it and refresh the page. </div> <p><table cellpadding="0" cellspacing="0" border="0"> <?php if ($game->param3 == 2) { echo "<tr>\r\n"; game_cross_show_welcome($game); echo "</tr>\r\n"; echo "<tr><tr><td> </td></tr>\r\n"; } ?> <tr> <td class="crosswordarea"><table id="crossword" cellpadding="3" cellspacing="0" style="display: none; border-collapse: collapse;" <?php echo $textdir; ?> > <script language="JavaScript" type="text/javascript"><!-- // EclipseCrossword and this script block (C) Copyright 2000-2005 Green Eclipse. // Do not remove this copyright notice. You can, however, change the rest of the page. // www.eclipsecrossword.com var BadChars = "`~!@^*()_={[}]\|:;\"',<>?&"; var CrosswordWidth, CrosswordHeight; var TableAcrossWord, TableDownWord; var Words, Word, Clue, WordX, WordY, LastHorizontalWord; var OnlyCheckOnce; var CurrentWord, PrevWordHorizontal, x, y, i, j; var CrosswordFinished, Initialized; // Check the user's browser and then initialize the puzzle. if (document.getElementById("waitmessage") != null) { document.getElementById("waitmessage").innerHTML = "<?php echo get_string('cross_pleasewait', 'game'); ?> "; // Current game variables CurrentWord = -1; PrevWordHorizontal = false; <?php echo $html; ?> OnlyCheckOnce = false; // Create the cell-to-word arrays. TableAcrossWord = new Array(CrosswordWidth); for (var x = 0; x < CrosswordWidth; x++) TableAcrossWord[x] = new Array(CrosswordHeight); TableDownWord = new Array(CrosswordWidth); for (var x = 0; x < CrosswordWidth; x++){ TableDownWord[x] = new Array(CrosswordHeight); } GuessLeter = new Array(CrosswordWidth); for (var x = 0; x < CrosswordWidth; x++) { GuessLeter[x] = new Array(CrosswordHeight); for (var y = 0; y < CrosswordHeight; y++) { GuessLeter[ x][ y] = "_"; } } solu = new Array(CrosswordWidth); for (var x = 0; x < CrosswordWidth; x++) { solu[x] = new Array(CrosswordHeight); for (var y = 0; y < CrosswordHeight; y++) { solu[ x][ y] = ""; } } for (var y = 0; y < CrosswordHeight; y++) for (var x = 0; x < CrosswordWidth; x++) { TableAcrossWord[x][y] = -1; TableDownWord[x][y] = -1; } // First, add the horizontal words to the puzzle. for (var i = 0; i <= LastHorizontalWord; i++) { x = WordX[i]; y = WordY[i]; s = Guess[ i]; so = Solutions[ i]; for (var j = 0; j < WordLength[i]; j++) { TableAcrossWord[x + j][y] = i; if( j < s.length) c = s.substr( j, 1); else c = ''; GuessLeter[ x+ j][ y] = c; if( j < so.length) c = so.substr( j, 1); else c = ''; solu[ x+j][ y] = c; } } // Second, add the vertical words to the puzzle. for (var i = LastHorizontalWord + 1; i < Words; i++) { x = WordX[i]; y = WordY[i]; s = Guess[ i]; so = Solutions[ i]; for (var j = 0; j < WordLength[i]; j++) { TableDownWord[x][y + j] = i; if( j < s.length) c = s.substr( j, 1); else c = ''; GuessLeter[ x][ y+j] = c; if( j < so.length) c = so.substr( j, 1); else c = ''; solu[ x][ y+j] = c; } } document.writeln("<tr><td></td>"); for (var x = 0; x < CrosswordWidth; x++) { document.write("<td align=center>" + (x+1) + " </td>"); //col numbers } // Now, insert the row HTML into the table. for (var y = 0; y < CrosswordHeight; y++) { document.writeln("<tr>"); document.write("<td>" + (y+1)+" </td>"); //line numbers for (var x = 0; x < CrosswordWidth; x++) { if (TableAcrossWord[x][y] >= 0 || TableDownWord[x][y] >= 0) { document.write("<td id=\"c" + PadNumber(x) + PadNumber(y) + "\" class=\"box boxnormal_unsel\" onclick=\"SelectThisWord(event);\">"); if( solu[x][y] != '') document.write( solu[x][y]); else if( GuessLeter[x][y]== "_") document.write( " "); else document.write( GuessLeter[x][y]); document.write("</td>"); }else document.write("<td></td>"); //empty cell } document.writeln("</tr>"); } // Finally, show the crossword and hide the wait message. Initialized = true; document.getElementById("waitmessage").style.display = "none"; document.getElementById("crossword").style.display = "block"; } // ---------- // Event handlers // Raised when a key is pressed in the word entry box. function WordEntryKeyPress(event) { if (CrosswordFinished) return; // Treat an Enter keypress as an OK click. if (CurrentWord >= 0 && event.keyCode == 13) OKClick(); } // ---------- // Helper functions // Returns true if the string passed in contains any characters prone to evil. function ContainsBadChars(theirWord) { for (var i = 0; i < theirWord.length; i++) if (BadChars.indexOf(theirWord.charAt(i)) >= 0) return true; return false; } // Pads a number out to three characters. function PadNumber(number) { if (number < 10) return "00" + number; else if (number < 100) return "0" + number; else return "" + number; } // Returns the table cell at a particular pair of coordinates. function CellAt(x, y) { return document.getElementById("c" + PadNumber(x) + PadNumber(y)); } // Deselects the current word, if there's a word selected. DOES not change the value of CurrentWord. function DeselectCurrentWord() { if (CurrentWord < 0) return; var x, y, i; document.getElementById("answerbox").style.display = "none"; document.getElementById("answerbox2").style.display = "none"; ChangeCurrentWordSelectedStyle(false); CurrentWord = -1; } // Changes the style of the cells in the current word. function ChangeWordStyle(WordNumber, NewStyle) { if (WordNumber< 0) return; var x = WordX[WordNumber]; var y = WordY[WordNumber]; if (WordNumber<= LastHorizontalWord) for (i = 0; i < WordLength[WordNumber]; i++) CellAt(x + i, y).className = NewStyle; else for (i = 0; i < WordLength[WordNumber]; i++) CellAt(x, y + i).className = NewStyle; } // Changes the style of the cells in the current word between the selected/unselected form. function ChangeCurrentWordSelectedStyle(IsSelected) { if (CurrentWord < 0) return; var x = WordX[CurrentWord]; var y = WordY[CurrentWord]; if (CurrentWord <= LastHorizontalWord) for (i = 0; i < WordLength[CurrentWord]; i++) CellAt(x + i, y).className = CellAt(x + i, y).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel"); else for (i = 0; i < WordLength[CurrentWord]; i++) CellAt(x, y + i).className = CellAt(x, y + i).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel"); } // Selects the new word by parsing the name of the TD element referenced by the // event object, and then applying styles as necessary. function SelectThisWord(event) { if (CrosswordFinished) return; var x, y, i, TheirWord, TableCell; // Deselect the previous word if one was selected. document.getElementById("welcomemessage").style.display = "none"; if (CurrentWord >= 0) OKClick(); DeselectCurrentWord(); // Determine the coordinates of the cell they clicked, and then the word that // they clicked. var target = (event.srcElement ? event.srcElement: event.target); x = parseInt(target.id.substring(1, 4), 10); y = parseInt(target.id.substring(4, 7), 10); // If they clicked an intersection, choose the type of word that was NOT selected last time. if (TableAcrossWord[x][y] >= 0 && TableDownWord[x][y] >= 0) CurrentWord = PrevWordHorizontal ? TableDownWord[x][y] : TableAcrossWord[x][y]; else if (TableAcrossWord[x][y] >= 0) CurrentWord = TableAcrossWord[x][y]; else if (TableDownWord[x][y] >= 0) CurrentWord = TableDownWord[x][y]; PrevWordHorizontal = (CurrentWord <= LastHorizontalWord); // Now, change the style of the cells in this word. ChangeCurrentWordSelectedStyle(true); // Then, prepare the answer box. x = WordX[CurrentWord]; y = WordY[CurrentWord]; TheirWord = ""; var TheirWordLength = 0; for (i = 0; i < WordLength[CurrentWord]; i++) { // Find the appropriate table cell. if (CurrentWord <= LastHorizontalWord) TableCell = CellAt(x + i, y); else TableCell = CellAt(x, y + i); // Add its contents to the word we're building. if (TableCell.innerHTML != null && TableCell.innerHTML.length > 0 && TableCell.innerHTML != " " && TableCell.innerHTML.toLowerCase() != " ") { TheirWord += TableCell.innerHTML.toUpperCase(); TheirWordLength++; } else { TheirWord += "•"; } } document.getElementById("wordlabel").innerHTML = TheirWord; <?php $msg = "\"" . get_string('cross_across', 'game') . ", \" : \"" . get_string('cross_down', 'game') . ", \""; $letters = "\" " . get_string('letter', 'game') . ".\" : \" " . get_string('letters', 'game') . ".\""; ?> document.getElementById("wordinfo").innerHTML = ((CurrentWord <= LastHorizontalWord) ? <?php echo $msg; ?> ) + WordLength[CurrentWord] + (WordLength[CurrentWord] == 1 ? <?php echo $letters; ?> ); document.getElementById("wordclue").innerHTML = Clue[CurrentWord]; document.getElementById("worderror").style.display = "none"; //document.getElementById("cheatbutton").style.display = (Word.length == 0) ? "none" : ""; if (TheirWordLength == WordLength[CurrentWord]) document.getElementById("wordentry").value = TheirWord; else document.getElementById("wordentry").value = ""; // Finally, show the answer box. document.getElementById("answerbox").style.display = "block"; document.getElementById("answerbox2").style.display = "block"; try { document.getElementById("wordentry").focus(); document.getElementById("wordentry").select(); } catch (e) { } } // Called when the user clicks the OK link. function OKClick() { var TheirWord, x, y, i, TableCell; if (CrosswordFinished) return; if (document.getElementById("okbutton").disabled) return; // First, validate the entry. TheirWord = document.getElementById("wordentry").value.toUpperCase(); if (TheirWord.length == 0) { DeselectCurrentWord(); return; } if (ContainsBadChars(TheirWord)) { document.getElementById("worderror").innerHTML = "<?php echo get_string('cross_error_containsbadchars', 'game'); ?> "; document.getElementById("worderror").style.display = "block"; return; } if (TheirWord.length < WordLength[CurrentWord]) { document.getElementById("worderror").innerHTML = "<?php echo get_string('cross_error_wordlength1', 'game'); ?> " + WordLength[CurrentWord] + " <?php echo get_string('cross_error_wordlength2', 'game'); ?> "; document.getElementById("worderror").style.display = "block"; return; } if (TheirWord.length > WordLength[CurrentWord]) { document.getElementById("worderror").innerHTML = "<?php echo get_string('cross_error_wordlength1', 'game'); ?> " + WordLength[CurrentWord] + " <?php echo get_string('cross_error_wordlength2', 'game'); ?> ";; document.getElementById("worderror").style.display = "block"; return; } // If we made it this far, they typed an acceptable word, so add these letters to the puzzle and hide the entry box. x = WordX[CurrentWord]; y = WordY[CurrentWord]; for (i = 0; i < TheirWord.length; i++) { TableCell = CellAt(x + (CurrentWord <= LastHorizontalWord ? i : 0), y + (CurrentWord > LastHorizontalWord ? i : 0)); TableCell.innerHTML = TheirWord.substring(i, i + 1); } DeselectCurrentWord(); } <?php if ($showhtmlsolutions == false) { ?> function PackPuzzle( sData) { var i; var s; var s2; var n; var j; s = ""; len = sData.length; for(i=0; i < len; i++) { c = sData.charAt( i); if( (c > "0") && (c <= "9")) { s = s.concat( '/'); } s = s.concat( c); } for(;;) { i = s.indexOf( "__"); if( i == -1) break; len = s.length; for( j=i ; j < len; j++) { if( s.charAt( j) != "_") break; } n = j - i; s2 = s.substr( 0, i); s2 = s2.concat( n); s = s2.concat( s.substr( j)); } return s; } // Called when the "check server" link is clicked. function CheckServerClick( endofgame) { var i, j, x, y, UserEntry, ErrorsFound = 0, EmptyFound = 0, TableCell; if (CrosswordFinished) return; DeselectCurrentWord(); for (y = 0; y < CrosswordHeight; y++) for (x = 0; x < CrosswordWidth; x++) { if (TableAcrossWord[x][y] >= 0 || TableDownWord[x][y] >= 0) { TableCell = CellAt(x, y); if (TableCell.className == "box boxerror_unsel") TableCell.className = "box boxnormal_unsel"; } } sData = ""; for (i = 0; i < Words; i++) { // Get the user's entry for this word. UserEntry = ""; for (j = 0; j < WordLength[i]; j++) { if (i <= LastHorizontalWord) TableCell = CellAt(WordX[i] + j, WordY[i]); else TableCell = CellAt(WordX[i], WordY[i] + j); if (TableCell.innerHTML.length > 0 && TableCell.innerHTML.toLowerCase() != " ") UserEntry += TableCell.innerHTML.toUpperCase(); else if( TableCell.innerHTML.toLowerCase() == " ") UserEntry += " "; else UserEntry += "_"; } sData += UserEntry; } sData = PackPuzzle( sData); if( endofgame) sData += "&finishattempt=1"; <?php if ($onlyshow == false) { global $CFG; $params = 'id=' . $id . '&action=crosscheck&g='; echo "window.location = \"{$CFG->wwwroot}/mod/game/attempt.php?{$params}\"+ sData;\r\n"; } ?> } <?php } ?> function OnPrint() { <?php global $CFG; $params = "id={$id}&gameid={$game->id}"; echo "window.open( \"{$CFG->wwwroot}/mod/game/print.php?{$params}\")"; ?> } <?php if ($showhtmlprintbutton) { ?> function PrintHtmlClick() { document.getElementById("printhtmlbutton").style.display = "none"; <?php if ($showhtmlsolutions) { ?> document.getElementById("checkhtmlbutton").style.display = "none"; <?php } ?> window.print(); <?php if ($showhtmlsolutions) { ?> document.getElementById("checkhtmlbutton").style.display = "block"; <?php } ?> document.getElementById("printhtmlbutton").style.display = "block"; } <?php } ?> <?php if ($showhtmlprintbutton) { ?> /** * * Base64 encode / decode * http://www.webtoolkit.info/ * **/ var Base64 = { // private property _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for decoding decode : function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);bgColor = "Black"; chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 decoding _utf8_decode : function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } } // Called when the "checkhtml" link is clicked. function CheckHtmlClick() { var i, TableCell, UserEntry, sData, solution; sData = ""; for (i = 0; i < Words; i++) { solution = Base64.decode( HtmlSolutions[ i]); // Get the user's entry for this word. UserEntry = ""; for (j = 0; j < WordLength[i]; j++) { if (i <= LastHorizontalWord) TableCell = CellAt(WordX[i] + j, WordY[i]); else TableCell = CellAt(WordX[i], WordY[i] + j); if (TableCell.innerHTML.length > 0 && TableCell.innerHTML.toLowerCase() != " ") UserEntry += TableCell.innerHTML.toUpperCase(); else if( TableCell.innerHTML.toLowerCase() == " ") UserEntry += " "; else UserEntry += "_"; if( UserEntry[ j] != solution[ j]) { TableCell.innerHTML = " "; } } } } <?php } if ($showhtmlsolutions) { ?> function decodeutf8(utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } <?php } ?> //--> </script> </table></td> <?php if ($game->param3 == 2) { echo '<td>     </td>'; game_cross_show_legends($cross); } else { game_cross_show_welcome($game); } ?> </tr></table> <?php if ($onlyshow == false) { echo '<div style="margin-top: 1em;">'; echo '<button id="checkbutton" type="button" onclick="CheckServerClick( 0);" style="display: none;">' . get_string('cross_checkbutton', 'game'); echo '</button>'; echo ' <button id="finishattemptbutton" type="button" onclick="CheckServerClick( 1);" style="display: none;">' . get_string('cross_endofgamebutton', 'game'); echo '</button>'; echo ' <button id="printbutton" type="button" onclick="OnPrint( 0);" style="display: none;">' . get_string('print', 'game'); echo '</button>'; echo "</div>\r\n"; } if ($showhtmlsolutions or $showhtmlprintbutton) { echo '<br>'; } if ($showhtmlsolutions) { echo '<button id="checkhtmlbutton" type="button" onclick="CheckHtmlClick();" visible=true>' . get_string('cross_checkbutton', 'game'); echo '</button>'; } if ($showhtmlprintbutton) { if ($showhtmlsolutions) { echo " "; } echo '<button id="printhtmlbutton" type="button" onclick="PrintHtmlClick( 0);" visible=true>' . get_string('print', 'game'); echo '</button>'; } if ($game->param3 == 2) { echo '<td>     </td>'; game_cross_show_welcome($game); } else { game_cross_show_legends($cross); } if ($game->bottomtext != '') { echo '<br><br>' . $game->bottomtext; } if ($attempt != false) { if ($attempt->timefinish == 0 and $endofgame == 0) { ?> <script language="JavaScript" type="text/javascript"><!-- if (Initialized) { <?php if ($print == false) { echo "document.getElementById(\"welcomemessage\").style.display = \"\";"; } if ($showsolution == false) { ?> document.getElementById("checkbutton").style.display = ""; document.getElementById("finishattemptbutton").style.display = ""; document.getElementById("printbutton").style.display = ""; <?php } ?> } //--> </script> <?php } } ?> </body> <?php }
function game_cross_play($id, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution, $endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton, $showstudentguess, $context) { global $CFG, $DB; $cross = new CrossDB(); $language = $attempt->language; $info = $cross->loadcross($g, $done, $html, $game, $attempt, $crossrec, $onlyshow, $showsolution, $endofgame, $showhtmlsolutions, $attempt->language, $showstudentguess, $context); 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 ($done or $endofgame) { if (!($cm = $DB->get_record('course_modules', array('id' => $id)))) { print_error("Course Module ID was incorrect id={$id}"); } if ($endofgame == false) { echo '<B>' . get_string('win', 'game') . '</B><BR>'; } //echo '<br>'; //echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id&forcenew=1\">".get_string( 'nextgame', 'game').'</a> '; } 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 = ''; } ?> <style type="text/css"> .ui-btn{ width:80% !important; } .ui-btn-active { -moz-box-shadow: 0px 0px 12px #56a788 /*{global-active-background-color}*/; -webkit-box-shadow: 0px 0px 12px #56a788 /*{global-active-background-color}*/; box-shadow: 0px 0px 12px #56a788 /*{global-active-background-color}*/; border: 1px solid #56a788; background: #56a788 /*{global-active-background-color}*/; font-weight: bold; color: #fff /*{global-active-color}*/; cursor: pointer; text-shadow: 0 /*{global-active-shadow-x}*/ 1px /*{global-active-shadow-y}*/ 1px /*{global-active-shadow-radius}*/ #56a788 /*{global-active-shadow-color}*/; text-decoration: none; background-image: -webkit-gradient(linear, left top, left bottom, from( #5393c5 /*{global-active-background-start}*/), to( #56a788 /*{global-active-background-end}*/)); /* Saf4+, Chrome */ background-image: -webkit-linear-gradient( #56a788 /*{global-active-background-start}*/, #56a788 /*{global-active-background-end}*/); /* Chrome 10+, Saf5.1+ */ background-image: -moz-linear-gradient( #56a788 /*{global-active-background-start}*/, #56a788 /*{global-active-background-end}*/); /* FF3.6 */ background-image: -ms-linear-gradient( #56a788 /*{global-active-background-start}*/, #56a788 /*{global-active-background-end}*/); /* IE10 */ background-image: -o-linear-gradient( #56a788 /*{global-active-background-start}*/, #56a788 /*{global-active-background-end}*/); /* Opera 11.10+ */ background-image: linear-gradient( #56a788 /*{global-active-background-start}*/, #56a788 /*{global-active-background-end}*/); font-family: Helvetica, Arial, sans-serif /*{global-font-family}*/; } .table-web{ width:91%; } .legend-web{ position: absolute; top: 93px; left: 75%; } #across-legend{ position: absolute; top: 93px; left: 20px; width: 20% !important; } @media handheld, only screen and (min-width: 1023px) { .heading{ width:180% !important; right:40% !important; } /*#across-legend { position: absolute; top: 93px; left: 5px !important; width: 23% !important; }*/ .answerboxstyle { width: 143pt !important; left:72% !important; } } @media handheld, only screen and (max-device-width : 1024px) { /*#across-legend { position: absolute; top: 93px; left: 2px !important; width: 17% !important; }*/ } @media only screen and (max-width : 1024px) { /*.maintable{ width:70% !important; margin: auto; }*/ } @media handheld, only screen and (max-width: 768px) { .answerboxstyle{ left: 33% !important; } } @media handheld, only screen and (max-width: 360px) { .heading{ width:104% !important; right:2% !important; } .answerboxstyle{ left: 3% !important; } } @media handheld, only screen and (max-width: 640px) { .heading{ width:104% !important; right:2% !important; } .answerboxstyle{ left: 18% !important; } } @media handheld, only screen and (max-width: 320px) { .heading{ width:100% !important; right:2% !important; } .answerboxstyle{ left: 0% !important; } } @media handheld, only screen and (max-width: 548px) { .heading{ width:100% !important; right:2% !important; } .answerboxstyle{ left: 18% !important; } .scroll-wrap{overflow:scroll; width:100%;} } .maintable{ width:100%; } <!-- .welcomemessage{ display:none !important; } .answerboxstyle { text-align:center; border-style: solid; border-width: 4px; display: none; padding: .75em; background-color: #F5F5F5; border-color: #eee; width: 200pt; position: absolute; left: 75%; z-index: 1; } .box { border-style: solid; border-width: 1pt; cursor: pointer; font-size: .12in; height: .18in; font-weight:normal; overflow: hidden; text-align: center; width: 20px !important; height: 25px !important; } .boxcheated_sel { background-color: #FFF1D7; border-color: #C00000; color: #2080D0; } .boxcheated_unsel { background-color: #ffffff; border-color: #606060; color: #2080D0; } .boxerror_sel { background-color: #FFF1D7; border-color: #C00000; color: #BF0000; } .boxerror_unsel { background-color: #FFF0F0; border-color: #606060; color: #BF0000; } .boxnormal_sel { background-color: #8ACFB6; border-color: #fff; color: #fff; } .boxnormal_unsel { background-color: #689987; border-color: #fff; color: #fff; } .filled{ background-color: #fff !important; border-color: #689987 !important; color: #fff !important; } .button { } .cluebox { border-bottom-width: 1px; border-color: #c0c0c0; border-left-width: 0px; border-right-width: 0px; border-style: solid; border-top-width: 1px; font-size: 90%; margin-top: 1em; padding-bottom: 0.5em; padding-left: 0pt; padding-right: 0pt; padding-top: .5em; /* margin-left: 0; */ float: left; margin-bottom: 8px; font-weight: bold; } .crosswordarea { border:1px solid #aaa; padding: .5em; } body { background-color: white; cursor: default; } body, button, input, p, td { font-family: Verdana, Arial, Sans-Serif; font-size: small; } button { cursor: pointer; } h1, h2, h3 { color: gray; font-family: Franklin Gothic Medium, Arial, Sans-Serif; font-weight: normal; } p { margin-top: 1em; } --></style> </head> <?php if ($print) { echo '<body onload="window.print()">'; } else { echo '<body>'; } if ($game->toptext != '') { echo "<h1 class='heading' style='word-wrap: break-word;position: relative;font-family: HelveticaNeue,arial;font-size:20px;color: #989693;width: 200%;font-weight: normal;line-height: 140%;text-align: center;right: 56%;'>" . $game->toptext . '</h1><br>'; } if ($info != '') { echo "<div id='grade-text'> {$info}</div>"; } else { echo "<div id='grade-text'> </br> </div>"; } ?> <div id="waitmessage" class="answerboxstyle"> This interactive crossword puzzle requires JavaScript and a reasonably recent web browser, such as Internet Explorer 5.5 or later, Netscape 7, Mozilla, Firefox, or Safari. If you have disabled web page scripting, please re-enable it and refresh the page. </div> <div class="scroll-wrap" style="border:1px solid #ccc;"> <p> <table cellpadding="0" cellspacing="0" border="0" id="main-table" class="maintable"> <?php /* artf1050487 defect changes start's here */ showlegendNumbers("H", $cross->m_LegendH, get_string('cross_across', 'game')); showlegendNumbers("V", $cross->m_LegendV, get_string('cross_down', 'game')); /* artf1050487 end here */ if ($game->param3 == 2) { echo "<tr>\r\n"; game_cross_show_welcome($game); echo "</tr>\r\n"; echo "<tr><tr><td> </td></tr>\r\n"; echo '<script type="text/javascript">var width = jQuery(window).width();if(width > 360 ){ jQuery("#main-table").addClass("table-web");}</script>'; } ?> <tr> <td class="crosswordarea" style="border:0;"><table id="crossword" cellpadding="3" cellspacing="0" style="display: none; border-collapse: collapse;margin:0 auto auto 28%;width:350px;" <?php echo $textdir; ?> > <script language="JavaScript" type="text/javascript"><!-- // EclipseCrossword and this script block (C) Copyright 2000-2005 Green Eclipse. // Do not remove this copyright notice. You can, however, change the rest of the page. // www.eclipsecrossword.com var BadChars = "`~!@^*()_={[}]\|:;\"',<>?&"; var CrosswordWidth, CrosswordHeight; var TableAcrossWord, TableDownWord; var Words, Word, Clue, WordX, WordY, LastHorizontalWord; var OnlyCheckOnce; var CurrentWord, PrevWordHorizontal, x, y, i, j; var CrosswordFinished, Initialized; // Check the user's browser and then initialize the puzzle. if (document.getElementById("waitmessage") != null) { document.getElementById("waitmessage").innerHTML = "<?php echo get_string('cross_pleasewait', 'game'); ?> "; // Current game variables CurrentWord = -1; PrevWordHorizontal = false; <?php echo $html; ?> OnlyCheckOnce = false; // Create the cell-to-word arrays. TableAcrossWord = new Array(CrosswordWidth); for (var x = 0; x < CrosswordWidth; x++) TableAcrossWord[x] = new Array(CrosswordHeight); TableDownWord = new Array(CrosswordWidth); for (var x = 0; x < CrosswordWidth; x++){ TableDownWord[x] = new Array(CrosswordHeight); } GuessLeter = new Array(CrosswordWidth); for (var x = 0; x < CrosswordWidth; x++) { GuessLeter[x] = new Array(CrosswordHeight); for (var y = 0; y < CrosswordHeight; y++) { GuessLeter[ x][ y] = "_"; } } solu = new Array(CrosswordWidth); for (var x = 0; x < CrosswordWidth; x++) { solu[x] = new Array(CrosswordHeight); for (var y = 0; y < CrosswordHeight; y++) { solu[ x][ y] = ""; } } for (var y = 0; y < CrosswordHeight; y++) for (var x = 0; x < CrosswordWidth; x++) { TableAcrossWord[x][y] = -1; TableDownWord[x][y] = -1; } // First, add the horizontal words to the puzzle. for (var i = 0; i <= LastHorizontalWord; i++) { x = WordX[i]; y = WordY[i]; s = Guess[ i]; so = Solutions[ i]; for (var j = 0; j < WordLength[i]; j++) { TableAcrossWord[x + j][y] = i; if( j < s.length) c = s.substr( j, 1); else c = ''; GuessLeter[ x+ j][ y] = c; if( j < so.length) c = so.substr( j, 1); else c = ''; solu[ x+j][ y] = c; } } // Second, add the vertical words to the puzzle. for (var i = LastHorizontalWord + 1; i < Words; i++) { x = WordX[i]; y = WordY[i]; s = Guess[ i]; so = Solutions[ i]; for (var j = 0; j < WordLength[i]; j++) { TableDownWord[x][y + j] = i; if( j < s.length) c = s.substr( j, 1); else c = ''; GuessLeter[ x][ y+j] = c; if( j < so.length) c = so.substr( j, 1); else c = ''; solu[ x][ y+j] = c; } } document.writeln("<tr><td></td>"); for (var x = 0; x < CrosswordWidth; x++) { //document.write("<td class='vclass' align=center style='background:#fff'>" + (x+1) + " </td>"); document.write("<td class='vclass' align=center style='background:#fff'></td>"); } // Now, insert the row HTML into the table. for (var y = 0; y < CrosswordHeight; y++) { document.writeln("<tr>"); //document.write("<td class='hclass' style='background:#fff'>" + (y+1)+" </td>"); //line numbers //document.write("<td class='hclass' style='background:#fff'> </td>"); //line numbers for (var x = 0; x < CrosswordWidth; x++) { if (TableAcrossWord[x][y] >= 0 || TableDownWord[x][y] >= 0) { document.write("<td id=\"c" + PadNumber(x) + PadNumber(y) + "\" class=\"box boxnormal_unsel\" onclick=\"SelectThisWord(event);\">"); if( solu[x][y] != '') document.write( solu[x][y]); else if( GuessLeter[x][y]== "_") document.write( " "); else document.write( GuessLeter[x][y]); document.write("</td>"); }else document.write("<td></td>"); //empty cell } document.writeln("</tr>"); } var hValue= localStorage.getItem("hcross"); var vValue= localStorage.getItem("vcross"); // vertical row changes jQuery(".hclass").each(function(){ var val = $(this).text(); var elem = $(this); var sample = jQuery.each(JSON.parse(hValue),function(index,value){ if(value == val ){ jQuery(elem).removeClass('hclass').addClass("ok"); } }); }); jQuery(".hclass").each(function(){ jQuery(this).text(""); }); // horizontal row changes jQuery(".vclass").each(function(){ var val = $(this).text(); var elem = $(this); var sample = jQuery.each(JSON.parse(vValue),function(index,value){ if(value == val ){ jQuery(elem).removeClass('vclass').addClass("ok"); } }); }); jQuery(".vclass").each(function(){ jQuery(this).text(""); }); // Finally, show the crossword and hide the wait message. Initialized = true; document.getElementById("waitmessage").style.display = "none"; document.getElementById("crossword").style.display = "block"; } // ---------- // Event handlers // Raised when a key is pressed in the word entry box. function WordEntryKeyPress(event) { if (CrosswordFinished) return; // Treat an Enter keypress as an OK click. if (CurrentWord >= 0 && event.keyCode == 13) OKClick(); } // ---------- // Helper functions // Returns true if the string passed in contains any characters prone to evil. function ContainsBadChars(theirWord) { for (var i = 0; i < theirWord.length; i++) if (BadChars.indexOf(theirWord.charAt(i)) >= 0) return true; return false; } // Pads a number out to three characters. function PadNumber(number) { if (number < 10) return "00" + number; else if (number < 100) return "0" + number; else return "" + number; } // Returns the table cell at a particular pair of coordinates. function CellAt(x, y) { return document.getElementById("c" + PadNumber(x) + PadNumber(y)); } // Deselects the current word, if there's a word selected. DOES not change the value of CurrentWord. function DeselectCurrentWord() { //jQuery(element).parent().addClass("ui-btn-active"); if (CurrentWord < 0) return; var x, y, i; document.getElementById("answerbox").style.display = "none"; document.getElementById("answerbox2").style.display = "none"; ChangeCurrentWordSelectedStyle(false); CurrentWord = -1; } // Changes the style of the cells in the current word. function ChangeWordStyle(WordNumber, NewStyle) { if (WordNumber< 0) return; var x = WordX[WordNumber]; var y = WordY[WordNumber]; if (WordNumber<= LastHorizontalWord) for (i = 0; i < WordLength[WordNumber]; i++) CellAt(x + i, y).className = NewStyle; else for (i = 0; i < WordLength[WordNumber]; i++) CellAt(x, y + i).className = NewStyle; } // Changes the style of the cells in the current word between the selected/unselected form. function ChangeCurrentWordSelectedStyle(IsSelected) { if (CurrentWord < 0) return; var x = WordX[CurrentWord]; var y = WordY[CurrentWord]; if (CurrentWord <= LastHorizontalWord) for (i = 0; i < WordLength[CurrentWord]; i++) CellAt(x + i, y).className = CellAt(x + i, y).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel"); else for (i = 0; i < WordLength[CurrentWord]; i++) CellAt(x, y + i).className = CellAt(x, y + i).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel"); } // Selects the new word by parsing the name of the TD element referenced by the // event object, and then applying styles as necessary. function SelectThisWord(event) { if (CrosswordFinished) return; var x, y, i, TheirWord, TableCell; // Deselect the previous word if one was selected. document.getElementById("welcomemessage").style.display = "none"; if (CurrentWord >= 0) OKClick(); DeselectCurrentWord(); // Determine the coordinates of the cell they clicked, and then the word that // they clicked. var target = (event.srcElement ? event.srcElement: event.target); x = parseInt(target.id.substring(1, 4), 10); y = parseInt(target.id.substring(4, 7), 10); // If they clicked an intersection, choose the type of word that was NOT selected last time. if (TableAcrossWord[x][y] >= 0 && TableDownWord[x][y] >= 0) CurrentWord = PrevWordHorizontal ? TableDownWord[x][y] : TableAcrossWord[x][y]; else if (TableAcrossWord[x][y] >= 0) CurrentWord = TableAcrossWord[x][y]; else if (TableDownWord[x][y] >= 0) CurrentWord = TableDownWord[x][y]; PrevWordHorizontal = (CurrentWord <= LastHorizontalWord); // Now, change the style of the cells in this word. ChangeCurrentWordSelectedStyle(true); // Then, prepare the answer box. x = WordX[CurrentWord]; y = WordY[CurrentWord]; TheirWord = ""; var TheirWordLength = 0; for (i = 0; i < WordLength[CurrentWord]; i++) { // Find the appropriate table cell. if (CurrentWord <= LastHorizontalWord) TableCell = CellAt(x + i, y); else TableCell = CellAt(x, y + i); // Add its contents to the word we're building. if (TableCell.innerHTML != null && TableCell.innerHTML.length > 0 && TableCell.innerHTML != " " && TableCell.innerHTML.toLowerCase() != " ") { TheirWord += TableCell.innerHTML.toUpperCase(); TheirWordLength++; } else { TheirWord += "•"; } } document.getElementById("wordlabel").innerHTML = TheirWord; <?php $msg = "\"" . get_string('cross_across', 'game') . ", \" : \"" . get_string('cross_down', 'game') . ", \""; $letters = "\" " . get_string('letter', 'game') . ".\" : \" " . get_string('letters', 'game') . ".\""; ?> document.getElementById("wordinfo").innerHTML = ((CurrentWord <= LastHorizontalWord) ? <?php echo $msg; ?> ) + WordLength[CurrentWord] + (WordLength[CurrentWord] == 1 ? <?php echo $letters; ?> ); document.getElementById("wordclue").innerHTML = Clue[CurrentWord]; document.getElementById("worderror").style.display = "none"; //document.getElementById("cheatbutton").style.display = (Word.length == 0) ? "none" : ""; if (TheirWordLength == WordLength[CurrentWord]) document.getElementById("wordentry").value = TheirWord; else document.getElementById("wordentry").value = ""; // Finally, show the answer box. document.getElementById("answerbox").style.display = "block"; document.getElementById("answerbox2").style.display = "block"; try { document.getElementById("wordentry").focus(); document.getElementById("wordentry").select(); } catch (e) { } } // Called when the user clicks the OK link. function OKClick(element) { //jQuery(element).parent().addClass("ui-btn-active"); var TheirWord, x, y, i, TableCell; if (CrosswordFinished) return; if (document.getElementById("okbutton").disabled) return; // First, validate the entry. TheirWord = document.getElementById("wordentry").value.toUpperCase(); if (TheirWord.length == 0) { DeselectCurrentWord(); return; } if (ContainsBadChars(TheirWord)) { document.getElementById("worderror").innerHTML = "<?php echo get_string('cross_error_containsbadchars', 'game'); ?> "; document.getElementById("worderror").style.display = "block"; return; } if (TheirWord.length < WordLength[CurrentWord]) { document.getElementById("worderror").innerHTML = "<?php echo get_string('cross_error_wordlength1', 'game'); ?> " + WordLength[CurrentWord] + " <?php echo get_string('cross_error_wordlength2', 'game'); ?> "; document.getElementById("worderror").style.display = "block"; return; } if (TheirWord.length > WordLength[CurrentWord]) { document.getElementById("worderror").innerHTML = "<?php echo get_string('cross_error_wordlength1', 'game'); ?> " + WordLength[CurrentWord] + " <?php echo get_string('cross_error_wordlength2', 'game'); ?> ";; document.getElementById("worderror").style.display = "block"; return; } // If we made it this far, they typed an acceptable word, so add these letters to the puzzle and hide the entry box. x = WordX[CurrentWord]; y = WordY[CurrentWord]; for (i = 0; i < TheirWord.length; i++) { TableCell = CellAt(x + (CurrentWord <= LastHorizontalWord ? i : 0), y + (CurrentWord > LastHorizontalWord ? i : 0)); TableCell.innerHTML = TheirWord.substring(i, i + 1); } DeselectCurrentWord(); } <?php if ($showhtmlsolutions == false) { ?> function PackPuzzle( sData) { var i; var s; var s2; var n; var j; s = ""; len = sData.length; for(i=0; i < len; i++) { c = sData.charAt( i); if( (c > "0") && (c <= "9")) { s = s.concat( '/'); } s = s.concat( c); } for(;;) { i = s.indexOf( "__"); if( i == -1) break; len = s.length; for( j=i ; j < len; j++) { if( s.charAt( j) != "_") break; } n = j - i; s2 = s.substr( 0, i); s2 = s2.concat( n); s = s2.concat( s.substr( j)); } return s; } // Called when the "check server" link is clicked. function CheckServerClick( endofgame, element) { jQuery(element).parent().addClass("ui-btn-active"); var i, j, x, y, UserEntry, ErrorsFound = 0, EmptyFound = 0, TableCell; if (CrosswordFinished) return; DeselectCurrentWord(); for (y = 0; y < CrosswordHeight; y++) for (x = 0; x < CrosswordWidth; x++) { if (TableAcrossWord[x][y] >= 0 || TableDownWord[x][y] >= 0) { TableCell = CellAt(x, y); if (TableCell.className == "box boxerror_unsel") TableCell.className = "box boxnormal_unsel"; } } sData = ""; for (i = 0; i < Words; i++) { // Get the user's entry for this word. UserEntry = ""; for (j = 0; j < WordLength[i]; j++) { if (i <= LastHorizontalWord) TableCell = CellAt(WordX[i] + j, WordY[i]); else TableCell = CellAt(WordX[i], WordY[i] + j); if (TableCell.innerHTML.length > 0 && TableCell.innerHTML.toLowerCase() != " ") UserEntry += TableCell.innerHTML.toUpperCase(); else if( TableCell.innerHTML.toLowerCase() == " ") UserEntry += " "; else UserEntry += "_"; } sData += UserEntry; } sData = PackPuzzle( sData); if( endofgame) sData += "&finishattempt=1"; <?php if ($onlyshow == false) { global $CFG; $params = 'id=' . $id . '&action=crosscheck&g='; echo "window.location = \"{$CFG->wwwroot}/mod/game/attempt.php?{$params}\"+ sData;\r\n"; } ?> } <?php } ?> function OnPrint(sample, element) { jQuery(element).parent().addClass("ui-btn-active"); <?php global $CFG; $params = "id={$id}&gameid={$game->id}"; echo "window.open( \"{$CFG->wwwroot}/mod/game/print.php?{$params}\")"; ?> } <?php if ($showhtmlprintbutton) { ?> function PrintHtmlClick(flag,element) { jQuery(element).parent().addClass("ui-btn-active"); document.getElementById("printhtmlbutton").style.display = "none"; <?php if ($showhtmlsolutions) { ?> document.getElementById("checkhtmlbutton").style.display = "none"; <?php } ?> window.print(); <?php if ($showhtmlsolutions) { ?> document.getElementById("checkhtmlbutton").style.display = "block"; <?php } ?> document.getElementById("printhtmlbutton").style.display = "block"; } <?php } ?> <?php if ($showhtmlprintbutton) { ?> /** * * Base64 encode / decode * http://www.webtoolkit.info/ * **/ var Base64 = { // private property _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for decoding decode : function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);bgColor = "Black"; chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 decoding _utf8_decode : function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } } // Called when the "checkhtml" link is clicked. function CheckHtmlClick(element) { var i, TableCell, UserEntry, sData, solution; jQuery(element).parent().addClass("ui-btn-active"); sData = ""; for (i = 0; i < Words; i++) { solution = Base64.decode( HtmlSolutions[ i]); // Get the user's entry for this word. UserEntry = ""; for (j = 0; j < WordLength[i]; j++) { if (i <= LastHorizontalWord) TableCell = CellAt(WordX[i] + j, WordY[i]); else TableCell = CellAt(WordX[i], WordY[i] + j); if (TableCell.innerHTML.length > 0 && TableCell.innerHTML.toLowerCase() != " ") UserEntry += TableCell.innerHTML.toUpperCase(); else if( TableCell.innerHTML.toLowerCase() == " ") UserEntry += " "; else UserEntry += "_"; if( UserEntry[ j] != solution[ j]) { TableCell.innerHTML = " "; } } } } <?php } if ($showhtmlsolutions) { ?> function decodeutf8(utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } <?php } ?> //--> </script> </table></td> <?php if ($game->param3 == 2) { echo '<td>     </td>'; game_cross_show_legends($cross); } else { game_cross_show_welcome($game); } ?> </tr></table> </div> <?php if ($onlyshow == false) { echo '<div style="margin-top: 1em;width:50%;float:left;">'; echo '<button id="checkbutton" type="button" onclick="CheckServerClick( 0,this);" >' . get_string('cross_checkbutton', 'game'); echo '</button>'; echo "</div>\r\n"; echo '<div style="width:50%;float:left;">'; echo ' <button id="finishattemptbutton" type="button" >' . get_string('cross_endofgamebutton', 'game'); echo '</button>'; //echo ' <button id="printbutton" type="button" onclick="OnPrint( 0);" style="display: none;">'.get_string( 'print', 'game'); //echo '</button>'; echo "</div>\r\n"; } if ($showhtmlsolutions or $showhtmlprintbutton) { echo '<br>'; } if ($showhtmlsolutions) { echo '<button id="checkhtmlbutton" type="button" onclick="CheckHtmlClick(this);" visible=true>' . get_string('cross_checkbutton', 'game'); echo '</button>'; } if ($showhtmlprintbutton) { if ($showhtmlsolutions) { echo " "; } echo '<button id="printhtmlbutton" type="button" onclick="PrintHtmlClick( 0, this);" visible=true>' . get_string('print', 'game'); echo '</button>'; } if ($game->param3 == 2) { echo '<td>     </td>'; game_cross_show_welcome($game); } else { game_cross_show_legends($cross); } if ($game->bottomtext != '') { echo '<br><br>' . $game->bottomtext; } //echo '<script type="text/javascript">var crossobj = '.json_encode($cross->m_LegendH).'</script>'; if ($attempt != false) { if ($attempt->timefinish == 0 and $endofgame == 0) { ?> <script language="JavaScript" type="text/javascript"><!-- if (Initialized) { <?php if ($print == false) { echo "document.getElementById(\"welcomemessage\").style.display = \"\";"; } if ($showsolution == false) { ?> document.getElementById("checkbutton").style.display = ""; document.getElementById("finishattemptbutton").style.display = ""; //document.getElementById("printbutton").style.display = ""; <?php } ?> } //--> </script> <?php } } ?> </body> <?php }