コード例 #1
0
function game_hiddenpicture_selectglossaryentry($game, $attempt)
{
    global $CFG, $DB, $USER;
    srand((double) microtime() * 1000000);
    if ($game->glossaryid2 == 0) {
        print_error(get_string('must_select_glossary', 'game'));
    }
    $select = "ge.glossaryid={$game->glossaryid2}";
    $table = '{glossary_entries} ge';
    if ($game->glossarycategoryid2) {
        $table .= ",{glossary_entries_categories} gec";
        $select .= " AND gec.entryid = ge.id AND gec.categoryid = {$game->glossarycategoryid2}";
    }
    if ($game->param7 == 0) {
        //Allow spaces
        $select .= " AND concept NOT LIKE '% %'";
    }
    $sql = "SELECT ge.id,attachment FROM {$table} WHERE {$select}";
    if (($recs = $DB->get_records_sql($sql)) == false) {
        $a->name = "'" . $DB->get_field('glossary', 'name', array('id' => $game->glossaryid2)) . "'";
        print_error(get_string('hiddenpicture_nomainquestion', 'game', $a));
        return false;
    }
    $ids = array();
    $keys = array();
    $fs = get_file_storage();
    $cmg = get_coursemodule_from_instance('glossary', $game->glossaryid2, $game->course);
    $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) {
            foreach ($files as $key => $file) {
                $s = strtoupper($file->get_filename());
                $s = substr($s, -4);
                if ($s == '.GIF' or $s == '.JPG' or $s == '.PNG') {
                    $ids[] = $rec->id;
                    $keys[] = $file->get_pathnamehash();
                }
            }
        }
    }
    if (count($ids) == 0) {
        $a->name = "'" . $DB->get_field('glossary', 'name', array('id' => $game->glossaryid2)) . "'";
        print_error(get_string('hiddenpicture_nomainquestion', 'game', $a));
        return false;
    }
    //Have to select randomly one glossaryentry
    $poss = array();
    for ($i = 0; $i < count($ids); $i++) {
        $poss[] = $i;
    }
    shuffle($poss);
    $min_num = 0;
    $attachement = '';
    for ($i = 0; $i < count($ids); $i++) {
        $pos = $poss[$i];
        $tempid = $ids[$pos];
        $a = array('gameid' => $game->id, 'userid' => $USER->id, 'questionid' => 0, 'glossaryentryid' => $tempid);
        if (($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions r')) != false) {
            if ($rec2->r < $min_num or $min_num == 0) {
                $min_num = $rec2->r;
                $glossaryentryid = $tempid;
                $attachement = $keys[$pos];
            }
        } else {
            $glossaryentryid = $tempid;
            $attachement = $keys[$pos];
            break;
        }
    }
    $sql = 'SELECT id, concept as answertext, definition as questiontext, id as glossaryentryid, 0 as questionid, glossaryid, attachment' . ' FROM {glossary_entries} WHERE id = ' . $glossaryentryid;
    if (($rec = $DB->get_record_sql($sql)) == false) {
        return false;
    }
    $query = new stdClass();
    $query->attemptid = $attempt->id;
    $query->gamekind = $game->gamekind;
    $query->gameid = $game->id;
    $query->userid = $USER->id;
    $query->col = 0;
    $query->sourcemodule = 'glossary';
    $query->questionid = 0;
    $query->glossaryentryid = $rec->glossaryentryid;
    $query->attachment = $attachement;
    $query->questiontext = $rec->questiontext;
    $query->answertext = $rec->answertext;
    $query->score = 0;
    if (($query->id = $DB->insert_record('game_queries', $query)) == 0) {
        print_error('Error inserting in game_queries');
    }
    $newrec = new stdClass();
    $newrec->id = $attempt->id;
    $newrec->correct = 0;
    if (!game_insert_record('game_hiddenpicture', $newrec)) {
        print_error('Error inserting in game_hiddenpicture');
    }
    game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid);
    return $newrec;
}
コード例 #2
0
/**
 * This page export the game to html
 * 
 * @author  bdaloukas
 * @version $Id: print.php,v 1.7 2012/07/25 11:16:04 bdaloukas Exp $
 * @package game
 **/
require_once "../../config.php";
require_once "lib.php";
require_once "locallib.php";
$id = required_param('id', PARAM_INT);
// Course Module ID.
$gameid = required_param('gameid', PARAM_INT);
$game = $DB->get_record('game', array('id' => $gameid));
require_login($game->course);
$context = game_get_context_module_instance($id);
require_capability('mod/game:view', $context);
game_print($game, $id, $context);
function game_print($game, $update, $context)
{
    if ($game->gamekind == 'cross') {
        game_print_cross($game, $update, $context);
    } else {
        if ($game->gamekind == 'cryptex') {
            game_print_cryptex($game, $update, $context);
        }
    }
}
function game_print_cross($game, $update, $context)
{
    require "cross/play.php";
コード例 #3
0
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) {
            $cmgame = get_coursemodule_from_instance('game', $game->id, $game->course);
            $context = game_get_context_module_instance($cmgame->id);
            $text = str_replace(array("\\'", '\\"'), array("'", '"'), $text);
            return game_filterquestion($text, $query->questionid, $context->id, $game->course);
        }
    }
    return $text;
}
コード例 #4
0
 public function showhtml_base($crossm, $crossd, $showsolution, $showhtmlsolutions, $showstudentguess, $context, $game)
 {
     $this->mLegendh = array();
     $this->mLegendv = array();
     $sret = "CrosswordWidth  = {$crossm->cols};\n";
     $sret .= "CrosswordHeight = {$crossm->rows};\n";
     $sret .= "Words=" . count($crossd) . ";\n";
     $swordlength = "";
     $sguess = "";
     $ssolutions = '';
     $shtmlsolutions = '';
     $swordx = "";
     $swordy = "";
     $sclue = "";
     $lasthorizontalword = -1;
     $i = -1;
     $legendv = array();
     $legendh = array();
     if ($game->glossaryid) {
         $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course);
         $contextglossary = game_get_context_module_instance($cmglossary->id);
     }
     foreach ($crossd as $rec) {
         if ($rec->horizontal == false and $lasthorizontalword == -1) {
             $lasthorizontalword = $i;
         }
         $i++;
         $swordlength .= "," . game_strlen($rec->answertext);
         if ($rec->questionid != 0) {
             $q = game_filterquestion(str_replace('\\"', '"', $rec->questiontext), $rec->questionid, $context->id, $game->course);
             $rec->questiontext = game_repairquestion($q);
         } else {
             // Glossary.
             $q = game_filterglossary(str_replace('\\"', '"', $rec->questiontext), $rec->glossaryentryid, $contextglossary->id, $game->course);
             $rec->questiontext = game_repairquestion($q);
         }
         $sclue .= ',"' . game_tojavascriptstring(game_filtertext($rec->questiontext, 0)) . "\"\r\n";
         if ($showstudentguess) {
             $sguess .= ',"' . $rec->studentanswer . '"';
         } else {
             $sguess .= ",''";
         }
         $swordx .= "," . ($rec->col - 1);
         $swordy .= "," . ($rec->row - 1);
         if ($showsolution) {
             $ssolutions .= ',"' . $rec->answertext . '"';
         } else {
             $ssolutions .= ',""';
         }
         if ($showhtmlsolutions) {
             $shtmlsolutions .= ',"' . base64_encode($rec->answertext) . '"';
         }
         $attachment = '';
         $s = $rec->questiontext . $attachment;
         if ($rec->horizontal) {
             if (array_key_exists($rec->row, $legendh)) {
                 $legendh[$rec->row][] = $s;
             } else {
                 $legendh[$rec->row] = array($s);
             }
         } else {
             if (array_key_exists($rec->col, $legendv)) {
                 $legendv[$rec->col][] = $s;
             } else {
                 $legendv[$rec->col] = array($s);
             }
         }
     }
     $letters = get_string('lettersall', 'game');
     $this->mlegendh = array();
     foreach ($legendh as $key => $value) {
         if (count($value) == 1) {
             $this->mlegendh[$key] = $value[0];
         } else {
             for ($i = 0; $i < count($value); $i++) {
                 $this->mlegendh[$key . game_substr($letters, $i, 1)] = $value[$i];
             }
         }
     }
     $this->mlegendv = array();
     foreach ($legendv as $key => $value) {
         if (count($value) == 1) {
             $this->mlegendv[$key] = $value[0];
         } else {
             for ($i = 0; $i < count($value); $i++) {
                 $this->mlegendv[$key . game_substr($letters, $i, 1)] = $value[$i];
             }
         }
     }
     ksort($this->mlegendh);
     ksort($this->mlegendv);
     $sret .= "WordLength = new Array( " . game_substr($swordlength, 1) . ");\n";
     $sret .= "Clue = new Array( " . game_substr($sclue, 1) . ");\n";
     $sguess = str_replace(' ', '_', $sguess);
     $sret .= "Guess = new Array( " . game_substr($sguess, 1) . ");\n";
     $sret .= "Solutions = new Array( " . game_substr($ssolutions, 1) . ");\n";
     if ($showhtmlsolutions) {
         $sret .= "HtmlSolutions = new Array( " . game_substr($shtmlsolutions, 1) . ");\n";
     }
     $sret .= "WordX = new Array( " . game_substr($swordx, 1) . ");\n";
     $sret .= "WordY = new Array( " . game_substr($swordy, 1) . ");\n";
     $sret .= "LastHorizontalWord = {$lasthorizontalword};\n";
     return $sret;
 }
コード例 #5
0
function game_snakes_showquestion_glossary($id, $snakes, $query, $game)
{
    global $CFG, $DB;
    $entry = $DB->get_record('glossary_entries', array('id' => $query->glossaryentryid));
    // Start the form.
    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('sudoku_submit', '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="snakescheckg" />';
    echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n";
    // Print all the questions.
    // Add a hidden field with glossaryentryid.
    echo '<input type="hidden" name="glossaryentryid" value="' . $query->glossaryentryid . "\" />\n";
    $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course);
    $contextglossary = game_get_context_module_instance($cmglossary->id);
    $s = game_filterglossary(str_replace('\\"', '"', $entry->definition), $query->glossaryentryid, $contextglossary->id, $game->course);
    echo $s . '<br>';
    echo get_string('answer') . ': ';
    echo "<input type=\"text\" name=\"answer\" size=30 /><br>";
    echo "</form>\n";
}
コード例 #6
0
/**
 * Actual implementation of the reset course functionality, delete all the
 * Game responses for course $data->courseid.
 *
 * @global object
 * @param $data the data submitted from the reset course.
 * @return array status array
 */
function game_reset_userdata($data)
{
    global $DB;
    $componentstr = get_string('modulenameplural', 'game');
    $status = array();
    $fs = get_file_storage();
    for ($i = 1; $i <= 2; $i++) {
        if ($i == 1) {
            if (empty($data->reset_game_all)) {
                continue;
            }
            $allgamessql = 'SELECT g.id FROM {game} g WHERE g.course = ' . $data->courseid;
            $allattemptssql = 'SELECT ga.id FROM {game} g LEFT JOIN {game_attempts} ga ON g.id = ga.gameid WHERE g.course = ' . $data->courseid;
            $newstatus = array('component' => $componentstr, 'item' => get_string('reset_game_all', 'game'), 'error' => false);
        } else {
            if ($i == 2) {
                if (empty($data->reset_game_deleted_course)) {
                    continue;
                }
                $allgamessql = 'SELECT g.id FROM {game} g WHERE NOT EXISTS( SELECT * FROM {course} c WHERE c.id = g.course)';
                $allattemptssql = 'SELECT ga.id FROM {game_attempts} ga ' . 'WHERE NOT EXISTS( SELECT * FROM {game} g WHERE ga.gameid = g.id)';
                $newstatus = array('component' => $componentstr, 'item' => get_string('reset_game_deleted_course', 'game'), 'error' => false);
            }
        }
        $recs = $DB->get_recordset_sql($allgamessql);
        if ($recs->valid()) {
            foreach ($recs as $rec) {
                if (!($cm = get_coursemodule_from_instance('game', $rec->id))) {
                    continue;
                }
                $context = game_get_context_module_instance($cm->id);
                $fs->delete_area_files($context->id, 'mod_game', 'gnakes_file');
                $fs->delete_area_files($context->id, 'mod_game', 'gnakes_board');
                // Reset grades.
                $game = $DB->get_record_select('game', 'id=' . $rec->id, null, 'id,name,course ');
                $grades = null;
                $params = array('itemname' => $game->name, 'idnumber' => 0);
                $params['reset'] = true;
                grade_update('mod/game', $game->course, 'mod', 'game', $game->id, 0, $grades, $params);
            }
        }
        $DB->delete_records_select('game_bookquiz', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_bookquiz_chapters', "attemptid IN ({$allattemptssql})");
        $DB->delete_records_select('game_bookquiz_questions', "gameid IN ({$allgamessql})");
        $DB->delete_records_select('game_cross', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_cryptex', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_export_html', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_export_javame', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_grades', "gameid IN ({$allgamessql})");
        $DB->delete_records_select('game_hangman', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_hiddenpicture', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_millionaire', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_queries', "gameid IN ({$allgamessql})");
        $DB->delete_records_select('game_repetitions', "gameid IN ({$allgamessql})");
        $DB->delete_records_select('game_snakes', "id IN ({$allgamessql})");
        $DB->delete_records_select('game_sudoku', "id IN ({$allgamessql})");
        if ($i == 2) {
            $DB->delete_records_select('game_attempts', "NOT EXISTS (SELECT * FROM {game} g WHERE {game_attempts}.gameid=g.id)");
        } else {
            $DB->delete_records_select('game_attempts', "gameid IN ({$allgamessql})");
        }
        $status[] = $newstatus;
    }
    if (empty($data->reset_game_deleted_course)) {
        return $status;
    }
    // Delete data from deleted games.
    $a = array('bookquiz', 'cross', 'cryptex', 'grades', 'bookquiz_questions', 'export_html', 'export_javame', 'hangman', 'hiddenpicture', 'millionaire', 'snakes', 'sudoku');
    foreach ($a as $table) {
        $DB->delete_records_select('game_' . $table, "NOT EXISTS( SELECT * FROM {game} g WHERE {game_{$table}}.id=g.id)");
    }
    $a = array('grades', 'queries', 'repetitions');
    foreach ($a as $table) {
        $DB->delete_records_select('game_' . $table, "NOT EXISTS( SELECT * FROM {game} g WHERE {game_{$table}}.gameid=g.id)");
    }
    $a = array('bookquiz_chapters');
    foreach ($a as $table) {
        $DB->delete_records_select('game_' . $table, "NOT EXISTS( SELECT * FROM {game_attempts} ga WHERE {game_{$table}}.attemptid=ga.id)");
    }
    return $status;
}
コード例 #7
0
 public function export()
 {
     global $game, $DB;
     $mform = $this->_form;
     $html = new stdClass();
     $html->id = $this->_customdata['html']->id;
     $html->type = optional_param('type', 0, PARAM_ALPHANUM);
     $html->filename = $mform->getElementValue('filename');
     $html->title = $mform->getElementValue('title');
     $html->maxpicturewidth = optional_param('maxpicturewidth', 0, PARAM_INT);
     $html->maxpictureheight = optional_param('maxpictureheight', 0, PARAM_INT);
     if ($mform->elementExists('checkbutton')) {
         $checkbuttonvalue = $mform->getElementValue('checkbutton');
         $html->checkbutton = $checkbuttonvalue[0];
     }
     if ($mform->elementExists('printbutton')) {
         $printbuttonvalue = $mform->getElementValue('printbutton');
         $html->printbutton = $printbuttonvalue[0];
     }
     if (!$DB->update_record('game_export_html', $html)) {
         print_error("game_export_html: not updated id={$html->id}");
     }
     $cm = get_coursemodule_from_instance('game', $game->id, $game->course);
     $context = game_get_context_module_instance($cm->id);
     require_once "exporthtml.php";
     game_OnExportHTML($game, $context, $html);
 }
コード例 #8
0
function game_show_header(&$id, &$game, &$course, &$context)
{
    global $DB, $USER, $PAGE, $OUTPUT;
    $id = optional_param('id', 0, PARAM_INT);
    // Course Module ID, or
    $q = optional_param('q', 0, PARAM_INT);
    // game ID
    if ($id) {
        if (!($cm = get_coursemodule_from_id('game', $id))) {
            print_error('invalidcoursemodule');
        }
        if (!($course = $DB->get_record('course', array('id' => $cm->course)))) {
            print_error('coursemisconf');
        }
        if (!($game = $DB->get_record('game', array('id' => $cm->instance)))) {
            print_error('invalidcoursemodule');
        }
    } else {
        if (!($game = $DB->get_record('game', array('id' => $q)))) {
            print_error('invalidgameid', 'game');
        }
        if (!($course = $DB->get_record('course', array('id' => $game->course)))) {
            print_error('invalidcourseid');
        }
        if (!($cm = get_coursemodule_from_instance('game', $game->id, $course->id))) {
            print_error('invalidcoursemodule');
        }
    }
    /// Check login and get context.
    require_login($course->id, false, $cm);
    $context = game_get_context_module_instance($cm->id);
    require_capability('mod/game:view', $context);
    /// Cache some other capabilites we use several times.
    $canattempt = has_capability('mod/game:attempt', $context);
    $canreviewmine = has_capability('mod/game:reviewmyattempts', $context);
    /// Create an object to manage all the other (non-roles) access rules.
    $timenow = time();
    //$accessmanager = new game_access_manager(game::create($game->id, $USER->id), $timenow);
    /// If no questions have been set up yet redirect to edit.php
    //if (!$game->questions && has_capability('mod/game:manage', $context)) {
    //    redirect($CFG->wwwroot . '/mod/game/edit.php?cmid=' . $cm->id);
    //}
    /// Log this request.
    if (game_use_events()) {
        require 'classes/event/game_played.php';
        \mod_game\event\game_played::played($game, $context)->trigger();
    } else {
        add_to_log($course->id, 'game', 'view', "view.php?id={$cm->id}", $game->id, $cm->id);
    }
    /// Initialize $PAGE, compute blocks
    $PAGE->set_url('/mod/game/view.php', array('id' => $cm->id));
    $edit = optional_param('edit', -1, PARAM_BOOL);
    if ($edit != -1 && $PAGE->user_allowed_editing()) {
        $USER->editing = $edit;
    }
    // Note: MDL-19010 there will be further changes to printing header and blocks.
    // The code will be much nicer than this eventually.
    $title = $course->shortname . ': ' . format_string($game->name);
    if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
        $buttons = '<table><tr><td><form method="get" action="view.php"><div>' . '<input type="hidden" name="id" value="' . $cm->id . '" />' . '<input type="hidden" name="edit" value="' . ($PAGE->user_is_editing() ? 'off' : 'on') . '" />' . '<input type="submit" value="' . get_string($PAGE->user_is_editing() ? 'blockseditoff' : 'blocksediton') . '" /></div></form></td></tr></table>';
        $PAGE->set_button($buttons);
    }
    $PAGE->set_title($title);
    $PAGE->set_heading($course->fullname);
    echo $OUTPUT->header();
}
コード例 #9
0
function game_bookquiz_play($id, $game, $attempt, $bookquiz, $chapterid, $context)
{
    global $DB, $OUTPUT, $cm;
    if ($bookquiz->lastchapterid == 0) {
        game_bookquiz_play_computelastchapter($game, $bookquiz);
        if ($bookquiz->lastchapterid == 0) {
            print_error(get_string('bookquiz_empty', 'game'));
        }
    }
    if ($chapterid == 0) {
        $chapterid = $bookquiz->lastchapterid;
    } else {
        if ($DB->set_field('game_bookquiz', 'lastchapterid', $chapterid, array('id' => $bookquiz->id)) == false) {
            print_error("Can't update table game_bookquiz with lastchapterid to {$chapterid}");
        }
    }
    $book = $DB->get_record('book', array('id' => $game->bookid));
    if (!($chapter = $DB->get_record('book_chapters', array('id' => $chapterid)))) {
        print_error('Error reading book chapters.');
    }
    $select = "bookid = {$game->bookid} AND hidden = 0";
    $chapters = $DB->get_records_select('book_chapters', $select, null, 'pagenum', 'id, pagenum, subchapter, title, hidden');
    $okchapters = array();
    if (($recs = $DB->get_records('game_bookquiz_chapters', array('attemptid' => $attempt->id))) != false) {
        foreach ($recs as $rec) {
            //1 means correct answer
            $okchapters[$rec->chapterid] = 1;
        }
    }
    //2 means current
    //$okchapters[ $chapterid] =  2;
    $showquestions = false;
    $a = array('gameid' => $game->id, 'chapterid' => $chapterid);
    if (($questions = $DB->get_records('game_bookquiz_questions', $a)) === false) {
        if (!array_key_exists($chapterid, $okchapters)) {
            $okchapters[$chapterid] = 1;
            $newrec = new stdClass();
            $newrec->attemptid = $attempt->id;
            $newrec->chapterid = $chapterid;
            if (!$DB->insert_record('game_bookquiz_chapters', $newrec)) {
                print_error("Can't insert to table game_bookquiz_chapters");
            }
        }
    } else {
        //Have to select random one question
        $questionid = game_bookquiz_selectrandomquestion($questions);
        if ($questionid != 0) {
            $showquestions = true;
        }
    }
    /// prepare chapter navigation icons
    $previd = null;
    $nextid = null;
    $found = 0;
    $scoreattempt = 0;
    $lastid = 0;
    foreach ($chapters as $ch) {
        $scoreattempt++;
        if ($found) {
            $nextid = $ch->id;
            break;
        }
        if ($ch->id == $chapter->id) {
            $found = 1;
        }
        if (!$found) {
            $previd = $ch->id;
        }
        $lastid = $ch->id;
    }
    if ($ch == current($chapters)) {
        $nextid = $ch->id;
    }
    if (count($chapters)) {
        $scoreattempt = ($scoreattempt - 1) / count($chapters);
    }
    $chnavigation = '';
    if ($previd) {
        $chnavigation .= '<a title="' . get_string('navprev', 'book') . '" href="attempt.php?id=' . $id . '&chapterid=' . $previd . '"><img src="' . $OUTPUT->pix_url('bookquiz/nav_prev', 'mod_game') . '" class="bigicon" alt="' . get_string('navprev', 'book') . '"/></a>';
    } else {
        $chnavigation .= '<img src="' . $OUTPUT->pix_url('bookquiz/nav_prev_dis', 'mod_game') . '" class="bigicon" alt="" />';
    }
    $nextbutton = '';
    if ($nextid) {
        if (!$showquestions) {
            $chnavigation .= '<a title="' . get_string('navnext', 'book') . '" href="attempt.php?id=' . $id . '&chapterid=' . $nextid . '"><img src="' . $OUTPUT->pix_url('bookquiz/nav_next', 'mod_game') . '" class="bigicon" alt="' . get_string('navnext', 'book') . '" ></a>';
            $nextbutton = '<center>';
            $nextbutton .= '<form name="form" method="get" action="attempt.php">';
            $nextbutton .= '<input type="hidden" name="id" value="' . $id . '" >' . "\r\n";
            $nextbutton .= '<input type="hidden" name="chapterid" value="' . $nextid . '" >' . "\r\n";
            $nextbutton .= '<input type="submit" value="' . get_string('continue') . '">';
            $nextbutton .= '</center>';
            $showquestions = false;
            game_updateattempts_maxgrade($game, $attempt, $scoreattempt, 0);
        }
    } else {
        game_updateattempts_maxgrade($game, $attempt, 1, 0);
        $sec = '';
        if (!isset($cm)) {
            $cm = get_coursemodule_from_instance('game', $game->id, $game->course);
        }
        if ($section = $DB->get_record('course_sections', array('id' => $cm->section))) {
            $sec = $section->section;
        }
        if (!($cm = $DB->get_record('course_modules', array('id' => $id)))) {
            print_error("Course Module ID was incorrect id={$id}");
        }
        $chnavigation .= '<a title="' . get_string('navexit', 'book') . '" href="attempt.php?id=' . $id . '&chapterid=' . $lastid . '><img src="' . $OUTPUT->pix_url('bookquiz/nav_exit', 'mod_game') . '" class="bigicon" alt="' . get_string('navexit', 'book') . '" /></a>';
    }
    require 'toc.php';
    $tocwidth = '10%';
    if ($showquestions) {
        if ($game->param3 == 0) {
            game_bookquiz_showquestions($id, $questionid, $chapter->id, $nextid, $scoreattempt, $game, $context);
        }
    }
    ?>
<table border="0" cellspacing="0" width="100%" valign="top" cellpadding="2">

<!-- subchapter title and upper navigation row //-->
<tr>
    <td width="<?php 
    echo 10;
    ?>
" valign="bottom">
    </td>
    <td valign="top">
        <table border="0" cellspacing="0" width="100%" valign="top" cellpadding="0">
        <tr>
            <td align="right"><?php 
    echo $chnavigation;
    ?>
</td>
        </tr>
        </table>
    </td>
</tr>

<!-- toc and chapter row //-->
<tr>
    <td width="<?php 
    echo $tocwidth;
    ?>
" valign="top" align="left">
        <?php 
    echo $OUTPUT->box_start('generalbox');
    echo $toc;
    echo $OUTPUT->box_end();
    ?>
    </td>
    <td valign="top" align="left">
        <?php 
    echo $OUTPUT->box_start('generalbox');
    $content = '';
    if (!$book->customtitles) {
        if ($currsubtitle == '&nbsp;') {
            $content .= '<p class="book_chapter_title">' . $currtitle . '</p>';
        } else {
            $content .= '<p class="book_chapter_title">' . $currtitle . '<br />' . $currsubtitle . '</p>';
        }
    }
    $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;
    echo '<div>';
    if ($nextbutton != '') {
        echo $nextbutton;
    }
    echo format_text($content, FORMAT_HTML, $nocleanoption);
    if ($nextbutton != '') {
        echo $nextbutton;
    }
    echo '</div>';
    echo $OUTPUT->box_end();
    /// lower navigation
    echo '<p align="right">' . $chnavigation . '</p>';
    ?>
    </td>
</tr>
</table>

<?php 
    if ($showquestions) {
        if ($game->param3 != 0) {
            game_bookquiz_showquestions($id, $questionid, $chapter->id, $nextid, $scoreattempt, $game, $context);
        }
    }
}
コード例 #10
0
function hangman_showpage(&$done, &$correct, &$wrong, $max, &$wordline, &$wordline2, &$links, $game, &$attempt, &$hangman, &$query, $onlyshow, $showsolution, $context)
{
    global $USER, $CFG, $DB;
    $id = optional_param('id', 0, PARAM_INT);
    // Course Module ID.
    $word = $query->answertext;
    $newletter = optional_param('newletter', "", PARAM_TEXT);
    if ($newletter == '_') {
        $newletter = ' ';
    }
    if ($newletter == 'A') {
        $letters = $hangman->letters;
        if ($newletter != null) {
            if (game_strpos($letters, $newletter) === false) {
                $letters .= $newletter;
            }
            if (game_strpos($letters, 'Ã') === false) {
                $letters .= 'Ã';
            }
        }
    } elseif ($newletter == 'C') {
        $letters = $hangman->letters;
        if ($newletter != null) {
            if (game_strpos($letters, $newletter) === false) {
                $letters .= $newletter;
            }
            if (game_strpos($letters, 'Ç') === false) {
                $letters .= 'Ç';
            }
        }
    } else {
        $letters = $hangman->letters;
        if ($newletter != null) {
            if (game_strpos($letters, $newletter) === false) {
                $letters .= $newletter;
            }
        }
    }
    $links = "";
    $alpha = $hangman->allletters;
    $wrong = 0;
    if ($query->questionid) {
        $questiontext = str_replace(array("\\'", '\\"'), array("'", '"'), $query->questiontext);
        $query->questiontext = game_filterquestion($questiontext, $query->questionid, $context->id, $game->course);
    } else {
        $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course);
        $contextglossary = game_get_context_module_instance($cmglossary->id);
        $query->questiontext = game_filterglossary(str_replace('\\"', '"', $query->questiontext), $query->glossaryentryid, $contextglossary->id, $game->course);
    }
    if ($game->param5) {
        $s = trim(game_filtertext($query->questiontext, $game->course));
        if ($s != '.' and $s != '') {
            echo "<br/><b>" . $s . '</b>';
        }
        if ($query->attachment != '') {
            $file = "{$CFG->wwwroot}/file.php/{$game->course}/moddata/{$query->attachment}";
            echo "<img src=\"{$file}\" />";
        }
        echo "<br/><br/>";
    }
    $wordline = $wordline2 = "";
    $len = game_strlen($word);
    $done = 1;
    $answer = '';
    $correct = 0;
    for ($x = 0; $x < $len; $x++) {
        $char = game_substr($word, $x, 1);
        if ($showsolution) {
            $wordline2 .= $char == " " ? '&nbsp; ' : $char;
            $done = 0;
        }
        if (game_strpos($letters, $char) === false) {
            $wordline .= "_<font size=\"1\">&nbsp;</font>\r\n";
            $done = 0;
            $answer .= '_';
        } else {
            $wordline .= $char == " " ? '&nbsp; ' : $char;
            $answer .= $char;
            $correct++;
        }
    }
    $lenalpha = game_strlen($alpha);
    $fontsize = 5;
    for ($c = 0; $c < $lenalpha; $c++) {
        $char = game_substr($alpha, $c, 1);
        if (game_strpos($letters, $char) === false) {
            // User doesn't select this character.
            $params = 'id=' . $id . '&amp;newletter=' . urlencode($char);
            if ($onlyshow or $showsolution) {
                $links .= $char;
            } else {
                $links .= "<font size=\"{$fontsize}\"><a href=\"attempt.php?{$params}\">{$char}</a></font>\r\n";
            }
            continue;
        }
        if ($char == 'A') {
            if (game_strpos($word, $char) === false and game_strpos($word, 'Ã') === false) {
                $links .= "\r\n<font size=\"{$fontsize}\" color=\"red\">{$char} </font>";
                $wrong++;
            } else {
                $links .= "\r\n<B><font size=\"{$fontsize}\">{$char} </font></B> ";
            }
        } elseif ($char == 'C') {
            if (game_strpos($word, $char) === false and game_strpos($word, 'Ç') === false) {
                $links .= "\r\n<font size=\"{$fontsize}\" color=\"red\">{$char} </font>";
                $wrong++;
            } else {
                $links .= "\r\n<B><font size=\"{$fontsize}\">{$char} </font></B> ";
            }
        } elseif (game_strpos($word, $char) === false) {
            $links .= "\r\n<font size=\"{$fontsize}\" color=\"red\">{$char} </font>";
            $wrong++;
        } else {
            $links .= "\r\n<B><font size=\"{$fontsize}\">{$char} </font></B> ";
        }
    }
    $finishedword = ($done or $wrong >= $max);
    $finished = false;
    $updrec = new stdClass();
    $updrec->id = $hangman->id;
    $updrec->letters = $letters;
    if ($finishedword) {
        if ($hangman->finishedword == 0) {
            // Only one time per word increace the variable try.
            $hangman->try = $hangman->try + 1;
            if ($hangman->try > $hangman->maxtries) {
                $finished = true;
            }
            if ($done) {
                $hangman->corrects = $hangman->corrects + 1;
                $updrec->corrects = $hangman->corrects;
            }
        }
        $updrec->try = $hangman->try;
        $updrec->finishedword = 1;
    }
    $query->percent = ($correct - $wrong / $max) / game_strlen($word);
    if ($query->percent < 0) {
        $query->percent = 0;
    }
    if ($onlyshow or $showsolution) {
        return;
    }
    if (!$DB->update_record('game_hangman', $updrec)) {
        print_error("hangman_showpage: Can't update game_hangman id={$updrec->id}");
    }
    if ($done) {
        $score = 1;
    } else {
        if ($wrong >= $max) {
            $score = 0;
        } else {
            $score = -1;
        }
    }
    game_updateattempts($game, $attempt, $score, $finished);
    game_update_queries($game, $attempt, $query, $score, $answer);
}
コード例 #11
0
 function definition()
 {
     global $CFG, $DB, $COURSE;
     $config = get_config('game');
     $mform =& $this->_form;
     $id = $this->_instance;
     if (!empty($this->_instance)) {
         if ($g = $DB->get_record('game', array('id' => $id))) {
             $gamekind = $g->gamekind;
         } else {
             print_error('incorrect game');
         }
     } else {
         $gamekind = required_param('type', PARAM_ALPHA);
     }
     //Hidden elements
     $mform->addElement('hidden', 'gamekind', $gamekind);
     $mform->setDefault('gamekind', $gamekind);
     $mform->setType('gamekind', PARAM_ALPHA);
     $mform->addElement('hidden', 'type', $gamekind);
     $mform->setDefault('type', $gamekind);
     $mform->setType('type', PARAM_ALPHA);
     $mform->addElement('hidden', 'gameversion', game_get_version());
     $mform->setType('gameversion', PARAM_INT);
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', 'Name', array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEAN);
     }
     if (!isset($g)) {
         $mform->setDefault('name', get_string('game_' . $gamekind, 'game'));
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $hasglossary = $gamekind == 'hangman' || $gamekind == 'cross' || $gamekind == 'cryptex' || $gamekind == 'sudoku' || $gamekind == 'hiddenpicture' || $gamekind == 'snakes';
     $questionsourceoptions = array();
     if ($hasglossary) {
         $questionsourceoptions['glossary'] = get_string('modulename', 'glossary');
     }
     //if( $gamekind != 'snakes' && $gamekind != 'sudoku' &&
     //    $gamekind != 'hiddenpicture') {
     $questionsourceoptions['question'] = get_string('sourcemodule_question', 'game');
     //}
     if ($gamekind != 'bookquiz') {
         $questionsourceoptions['quiz'] = get_string('modulename', 'quiz');
     }
     $mform->addElement('select', 'sourcemodule', get_string('sourcemodule', 'game'), $questionsourceoptions);
     if ($hasglossary) {
         $a = array();
         if ($recs = $DB->get_records('glossary', array('course' => $COURSE->id), 'id,name')) {
             foreach ($recs as $rec) {
                 $a[$rec->id] = $rec->name;
             }
         }
         $mform->addElement('select', 'glossaryid', get_string('sourcemodule_glossary', 'game'), $a);
         $mform->disabledIf('glossaryid', 'sourcemodule', 'neq', 'glossary');
         if (count($a) == 0) {
             $select = 'glossaryid=-1';
         } else {
             if (count($a) == 1) {
                 $select = 'glossaryid=' . $rec->id;
             } else {
                 $select = '';
                 foreach ($recs as $rec) {
                     $select .= ',' . $rec->id;
                 }
                 $select = 'g.id IN (' . substr($select, 1) . ')';
             }
         }
         $select .= ' AND g.id=gc.glossaryid';
         $table = "{glossary} g, {glossary_categories} gc";
         $a = array();
         $a[] = '';
         $sql = "SELECT gc.id,gc.name,g.name as name2 FROM {$table} WHERE {$select} ORDER BY g.name,gc.name";
         if ($recs = $DB->get_records_sql($sql)) {
             foreach ($recs as $rec) {
                 $a[$rec->id] = $rec->name2 . ' -> ' . $rec->name;
             }
         }
         $mform->addElement('select', 'glossarycategoryid', get_string('sourcemodule_glossarycategory', 'game'), $a);
         $mform->disabledIf('glossarycategoryid', 'sourcemodule', 'neq', 'glossary');
     }
     //*********************
     // Question Category - Short Answer
     if ($gamekind != 'bookquiz') {
         $context = game_get_context_course_instance($COURSE->id);
         $select = " contextid in ({$context->id})";
         $a = array();
         if ($recs = $DB->get_records_select('question_categories', $select, null, 'id,name')) {
             foreach ($recs as $rec) {
                 $s = $rec->name;
                 if (($count = $DB->count_records('question', array('category' => $rec->id))) != 0) {
                     $s .= " ({$count})";
                 }
                 $a[$rec->id] = $s;
             }
         }
         $mform->addElement('select', 'questioncategoryid', get_string('sourcemodule_questioncategory', 'game'), $a);
         $mform->disabledIf('questioncategoryid', 'sourcemodule', 'neq', 'question');
         //subcategories
         $mform->addElement('selectyesno', 'subcategories', get_string('sourcemodule_include_subcategories', 'game'));
         $mform->disabledIf('subcategories', 'sourcemodule', 'neq', 'question');
     }
     //***********************
     // Quiz Category
     if ($gamekind != 'bookquiz') {
         $a = array();
         if ($recs = $DB->get_records('quiz', array('course' => $COURSE->id), 'id,name')) {
             foreach ($recs as $rec) {
                 $a[$rec->id] = $rec->name;
             }
         }
         $mform->addElement('select', 'quizid', get_string('sourcemodule_quiz', 'game'), $a);
         $mform->disabledIf('quizid', 'sourcemodule', 'neq', 'quiz');
     }
     //***********************
     // Book
     if ($gamekind == 'bookquiz') {
         $a = array();
         if ($recs = $DB->get_records('book', array('course' => $COURSE->id), 'id,name')) {
             foreach ($recs as $rec) {
                 $a[$rec->id] = $rec->name;
             }
         }
         $mform->addElement('select', 'bookid', get_string('sourcemodule_book', 'game'), $a);
     }
     //Common settings to all games
     $mform->addElement('text', 'maxattempts', get_string('cross_max_attempts', 'game'));
     $mform->setType('maxattempts', PARAM_INT);
     //---------------------------------------------------------------------------
     // Grade options
     $mform->addElement('header', 'gradeoptions', get_string('grades', 'grades'));
     $mform->addElement('text', 'grade', get_string('grademax', 'grades'), array('size' => 4));
     $mform->setType('grade', PARAM_INT);
     $gradingtypeoptions = array();
     $gradingtypeoptions[GAME_GRADEHIGHEST] = get_string('gradehighest', 'game');
     $gradingtypeoptions[GAME_GRADEAVERAGE] = get_string('gradeaverage', 'game');
     $gradingtypeoptions[GAME_ATTEMPTFIRST] = get_string('attemptfirst', 'game');
     $gradingtypeoptions[GAME_ATTEMPTLAST] = get_string('attemptlast', 'game');
     $mform->addElement('select', 'grademethod', get_string('grademethod', 'game'), $gradingtypeoptions);
     // Open and close dates.
     $mform->addElement('date_time_selector', 'timeopen', get_string('gameopen', 'game'), array('optional' => true, 'step' => 1));
     $mform->addHelpButton('timeopen', 'gameopenclose', 'game');
     $mform->addElement('date_time_selector', 'timeclose', get_string('gameclose', 'game'), array('optional' => true, 'step' => 1));
     //---------------------------------------------------------------------------
     // Bookquiz options
     if ($gamekind == 'bookquiz') {
         $mform->addElement('header', 'bookquiz', get_string('bookquiz_options', 'game'));
         $bookquizlayoutoptions = array();
         $bookquizlayoutoptions[0] = get_string('bookquiz_layout0', 'game');
         $bookquizlayoutoptions[1] = get_string('bookquiz_layout1', 'game');
         $mform->addElement('select', 'param3', get_string('bookquiz_layout', 'game'), $bookquizlayoutoptions);
     }
     //---------------------------------------------------------------------------
     // Hangman options
     if ($gamekind == 'hangman') {
         $mform->addElement('header', 'hangman', get_string('hangman_options', 'game'));
         $mform->addElement('text', 'param4', get_string('hangman_maxtries', 'game'), array('size' => 4));
         $mform->setType('param4', PARAM_INT);
         $mform->addElement('selectyesno', 'param1', get_string('hangman_showfirst', 'game'));
         $mform->addElement('selectyesno', 'param2', get_string('hangman_showlast', 'game'));
         $mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces', 'game'));
         $mform->addElement('selectyesno', 'param8', get_string('hangman_allowsub', 'game'));
         $mform->addElement('text', 'param10', get_string('hangman_maximum_number_of_errors', 'game'), array('size' => 4));
         $mform->setType('param10', PARAM_INT);
         if (!isset($config->hangmanimagesets)) {
             $number = 1;
         } else {
             $number = $config->hangmanimagesets;
         }
         if ($number > 1) {
             $a = array();
             for ($i = 1; $i <= $number; $i++) {
                 $a[$i] = $i;
             }
             $mform->addElement('select', 'param3', get_string('hangman_imageset', 'game'), $a);
         }
         $mform->addElement('selectyesno', 'param5', get_string('hangman_showquestion', 'game'));
         $mform->setDefault('param5', 1);
         $mform->addElement('selectyesno', 'param6', get_string('hangman_showcorrectanswer', 'game'));
         $a = array();
         $a = get_string_manager()->get_list_of_translations();
         $a[''] = '----------';
         ksort($a);
         $mform->addElement('select', 'language', get_string('hangman_language', 'game'), $a);
     }
     //---------------------------------------------------------------------------
     // Crossword options
     if ($gamekind == 'cross') {
         $mform->addElement('header', 'cross', get_string('cross_options', 'game'));
         $mform->addElement('text', 'param1', get_string('cross_maxcols', 'game'));
         $mform->setType('param1', PARAM_INT);
         $mform->addElement('text', 'param4', get_string('cross_minwords', 'game'));
         $mform->setType('param4', PARAM_INT);
         $mform->addElement('text', 'param2', get_string('cross_maxwords', 'game'));
         $mform->setType('param2', PARAM_INT);
         $mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces', 'game'));
         $crosslayoutoptions = array();
         $crosslayoutoptions[0] = get_string('cross_layout0', 'game');
         $crosslayoutoptions[1] = get_string('cross_layout1', 'game');
         $mform->addElement('select', 'param3', get_string('cross_layout', 'game'), $crosslayoutoptions);
         $mform->setType('param5', PARAM_INT);
         $mform->addElement('selectyesno', 'param6', get_string('cross_disabletransformuppercase', 'game'));
     }
     //---------------------------------------------------------------------------
     // Cryptex options
     if ($gamekind == 'cryptex') {
         $mform->addElement('header', 'cryptex', get_string('cryptex_options', 'game'));
         $mform->addElement('text', 'param1', get_string('cross_maxcols', 'game'));
         $mform->setType('param1', PARAM_INT);
         $mform->addElement('text', 'param4', get_string('cross_minwords', 'game'));
         $mform->setType('param4', PARAM_INT);
         $mform->addElement('text', 'param2', get_string('cross_maxwords', 'game'));
         $mform->setType('param2', PARAM_INT);
         $mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces', 'game'));
         $mform->addElement('text', 'param8', get_string('cryptex_maxtries', 'game'));
         $mform->setType('param8', PARAM_INT);
     }
     //---------------------------------------------------------------------------
     // Millionaire options
     if ($gamekind == 'millionaire') {
         global $OUTPUT, $PAGE;
         $mform->addElement('header', 'millionaire', get_string('millionaire_options', 'game'));
         $mform->addElement('text', 'param8', get_string('millionaire_background', 'game'));
         $mform->setDefault('param8', '#408080');
         $mform->setType('param8', PARAM_TEXT);
         //$mform->addElement('colorpicker', 'param8', get_string('millionaire_background', 'game'));
         //$mform->registerRule('color','regex','/^#([a-fA-F0-9]{6})$/');
         //$mform->addRule('config_bgcolor','Enter a valid RGB color - # and then 6 characters','color');
         $mform->addElement('selectyesno', 'shuffle', get_string('millionaire_shuffle', 'game'));
     }
     //---------------------------------------------------------------------------
     // Sudoku options
     if ($gamekind == 'sudoku') {
         $mform->addElement('header', 'sudoku', get_string('sudoku_options', 'game'));
         $mform->addElement('text', 'param2', get_string('sudoku_maxquestions', 'game'));
         $mform->setType('param2', PARAM_INT);
     }
     //---------------------------------------------------------------------------
     // Snakes and Ladders options
     if ($gamekind == 'snakes') {
         $mform->addElement('header', 'snakes', get_string('snakes_options', 'game'));
         $snakesandladdersbackground = array();
         if ($recs = $DB->get_records('game_snakes_database', null, 'id,name')) {
             foreach ($recs as $rec) {
                 $snakesandladdersbackground[$rec->id] = $rec->name;
             }
         }
         $snakeslayoutoptions = array();
         $snakeslayoutoptions[0] = get_string('snakes_layout0', 'game');
         $snakeslayoutoptions[1] = get_string('snakes_layout1', 'game');
         $mform->addElement('select', 'param8', get_string('bookquiz_layout', 'game'), $snakeslayoutoptions);
         if (count($snakesandladdersbackground) == 0) {
             require "{$CFG->dirroot}/mod/game/db/importsnakes.php";
             if ($recs = $DB->get_records('game_snakes_database', null, 'id,name')) {
                 foreach ($recs as $rec) {
                     $snakesandladdersbackground[$rec->id] = $rec->name;
                 }
             }
         }
         $snakesandladdersbackground[0] = get_string('userdefined', 'game');
         ksort($snakesandladdersbackground);
         $mform->addElement('select', 'param3', get_string('snakes_background', 'game'), $snakesandladdersbackground);
         //param3 = background
         //param4 = itemid for file_storage
         //param5 (=1 means dirty file and and have to be computed again)
         //param6 = width of autogenerated picture
         //param7 = height of autogenerated picture
         //param8 = layout
         $attachmentoptions = array('subdirs' => false, 'maxfiles' => 1);
         $mform->addElement('filepicker', 'param4', get_string('snakes_file', 'game'), $attachmentoptions);
         $mform->disabledIf('param4', 'param3', 'neq', '0');
         $mform->addElement('textarea', 'snakes_data', get_string('snakes_data', 'game'), 'rows="2" cols="70"');
         $mform->disabledIf('snakes_data', 'param3', 'neq', '0');
         $mform->addElement('text', 'snakes_cols', get_string('snakes_cols', 'game'), array('size' => 4));
         $mform->disabledIf('snakes_cols', 'param3', 'neq', '0');
         $mform->setType('snakes_cols', PARAM_INT);
         $mform->addElement('text', 'snakes_rows', get_string('snakes_rows', 'game'), array('size' => 4));
         $mform->disabledIf('snakes_rows', 'param3', 'neq', '0');
         $mform->setType('snakes_rows', PARAM_INT);
         $mform->addElement('text', 'snakes_headerx', get_string('snakes_headerx', 'game'), array('size' => 4));
         $mform->disabledIf('snakes_headerx', 'param3', 'neq', '0');
         $mform->setType('snakes_headerx', PARAM_INT);
         $mform->addElement('text', 'snakes_headery', get_string('snakes_headery', 'game'), array('size' => 4));
         $mform->disabledIf('snakes_headery', 'param3', 'neq', '0');
         $mform->setType('snakes_headery', PARAM_INT);
         $mform->addElement('text', 'snakes_footerx', get_string('snakes_footerx', 'game'), array('size' => 4));
         $mform->disabledIf('snakes_footerx', 'param3', 'neq', '0');
         $mform->setType('snakes_footerx', PARAM_INT);
         $mform->addElement('text', 'snakes_footery', get_string('snakes_footery', 'game'), array('size' => 4));
         $mform->disabledIf('snakes_footery', 'param3', 'neq', '0');
         $mform->setType('snakes_footery', PARAM_INT);
         $mform->addElement('text', 'snakes_width', get_string('hiddenpicture_width', 'game'), array('size' => 6));
         $mform->setType('snakes_width', PARAM_INT);
         $mform->addELement('text', 'snakes_height', get_string('hiddenpicture_height', 'game'), array('size' => 6));
         $mform->setType('snakes_height', PARAM_INT);
     }
     //---------------------------------------------------------------------------
     // Hidden Picture options
     if ($gamekind == 'hiddenpicture') {
         $mform->addElement('header', 'hiddenpicture', get_string('hiddenpicture_options', 'game'));
         $mform->addElement('text', 'param1', get_string('hiddenpicture_across', 'game'));
         $mform->setType('param1', PARAM_INT);
         $mform->setDefault('param1', 3);
         $mform->addElement('text', 'param2', get_string('hiddenpicture_down', 'game'));
         $mform->setType('param2', PARAM_INT);
         $mform->setDefault('param2', 3);
         $a = array();
         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 = game_get_context_module_instance($cmg->id);
                 if ($DB->record_exists('files', array('contextid' => $context->id))) {
                     $a[$rec->id] = $rec->name;
                 }
             }
         }
         $mform->addElement('select', 'glossaryid2', get_string('hiddenpicture_pictureglossary', 'game'), $a);
         $mform->addElement('text', 'param4', get_string('hiddenpicture_width', 'game'));
         $mform->setType('param4', PARAM_INT);
         $mform->addELement('text', 'param5', get_string('hiddenpicture_height', 'game'));
         $mform->setType('param5', PARAM_INT);
         $mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces', 'game'));
     }
     //---------------------------------------------------------------------------
     // Header/Footer options
     $mform->addElement('header', 'headerfooteroptions', 'Header/Footer Options');
     $mform->addElement('htmleditor', 'toptext', get_string('toptext', 'game'));
     $mform->addElement('htmleditor', 'bottomtext', get_string('bottomtext', 'game'));
     //---------------------------------------------------------------------------
     $features = new stdClass();
     $this->standard_coursemodule_elements($features);
     //---------------------------------------------------------------------------
     // buttons
     $this->add_action_buttons();
 }