You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
8.0 KiB

<?php
class mod_game_exporthtml_form extends moodleform {
public function definition() {
global $CFG, $game;
$mform = $this->_form;
$html = $this->_customdata['html'];
$mform->addElement('header', 'general', get_string('general', 'form'));
if ( $game->gamekind == 'hangman') {
$options = array();
$options[ '0'] = 'Hangman with phrases';
$options[ 'hangmanp'] = 'Hangman with pictures';
$mform->addElement('select', 'type', get_string('javame_type', 'game'), $options);
if ( $html->type == 0) {
$mform->setDefault('type', '0');
} else {
$mform->setDefault('type', 'hangmanp');
}
}
// Input the filename.
$mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30'));
$mform->setDefault('filename', $html->filename);
$mform->setType('filename', PARAM_TEXT);
// Input the html title.
$mform->addElement('text', 'title', get_string('html_title', 'game'), array('size' => '80'));
$mform->setDefault('title', $html->title);
$mform->setType('title', PARAM_TEXT);
// Inputs special fields for hangman.
if ($game->gamekind == 'hangman') {
$mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5'));
$mform->setDefault('maxpicturewidth', $html->maxpicturewidth);
$mform->setType('maxpicturewidth', PARAM_INT);
$mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size' => '5'));
$mform->setDefault('maxpictureheight', $html->maxpictureheight);
$mform->setType('maxpictureheight', PARAM_INT);
}
// Input special fields for crossword.
if ( $game->gamekind == 'cross') {
$mform->addElement('selectyesno', 'checkbutton', get_string('html_hascheckbutton', 'game'));
$mform->setDefault('checkbutton', $html->checkbutton);
$mform->addElement('selectyesno', 'printbutton', get_string('html_hasprintbutton', 'game'));
$mform->setDefault('printbutton', $html->printbutton);
}
$mform->addElement('hidden', 'q', $game->id);
$mform->setType('q', PARAM_INT);
$mform->addElement('hidden', 'target', 'html');
$mform->setType('target', PARAM_TEXT);
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game'));
$mform->closeHeaderBefore('submitbutton');
}
public function validation($data, $files) {
global $CFG, $USER, $DB;
$errors = parent::validation($data, $files);
return $errors;
}
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);
}
}
class mod_game_exportjavame_form extends moodleform {
public function definition() {
global $CFG, $DB, $game;
$mform = $this->_form;
$javame = $this->_customdata['javame'];
$mform->addElement('header', 'general', get_string('general', 'form'));
if ( $game->gamekind == 'hangman') {
$options = array();
$options[ '0'] = 'Hangman with phrases';
$options[ 'hangmanp'] = 'Hangman with pictures';
$mform->addElement('select', 'type', get_string('javame_type', 'game'), $options);
}
$mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30'));
$mform->setDefault('filename', $javame->filename);
$mform->setType('filename', PARAM_TEXT);
$mform->addElement('text', 'icon', get_string('javame_icon', 'game'));
$mform->setDefault('icon', $javame->icon);
$mform->setType('icon', PARAM_TEXT);
$mform->addElement('text', 'createdby', get_string('javame_createdby', 'game'));
$mform->setDefault('createdby', $javame->createdby);
$mform->setType('createdby', PARAM_TEXT);
$mform->addElement('text', 'vendor', get_string('javame_vendor', 'game'));
$mform->setDefault('vendor', $javame->vendor);
$mform->setType('vendor', PARAM_TEXT);
$mform->addElement('text', 'name', get_string('javame_name', 'game'), array('size' => '80'));
$mform->setDefault('name', $javame->name);
$mform->setType('name', PARAM_TEXT);
$mform->addElement('text', 'description', get_string('javame_description', 'game'), array('size' => '80'));
$mform->setDefault('description', $javame->description);
$mform->setType('description', PARAM_TEXT);
$mform->addElement('text', 'version', get_string('javame_version', 'game'), array('size' => '10'));
$mform->setDefault('version', $javame->version);
$mform->setType('version', PARAM_TEXT);
$mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5'));
$mform->setDefault('maxpicturewidth', $javame->maxpicturewidth);
$mform->setType('maxpicturewidth', PARAM_INT);
$mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size' => '5'));
$mform->setDefault('maxpictureheight', $javame->maxpictureheight);
$mform->setType('maxpictureheight', PARAM_INT);
$mform->addElement('hidden', 'q', $game->id);
$mform->setType('q', PARAM_INT);
$mform->addElement('hidden', 'target', 'javame');
$mform->setType('target', PARAM_TEXT);
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game'));
$mform->closeHeaderBefore('submitbutton');
}
public function validation($data, $files) {
global $CFG, $USER, $DB;
$errors = parent::validation($data, $files);
return $errors;
}
public function export() {
global $game, $DB;
$mform = $this->_form;
$javame = $this->_customdata['javame'];
$javame->type = optional_param('type', 0, PARAM_ALPHANUM);
$javame->filename = $mform->getElementValue('filename');
$javame->icon = $mform->getElementValue('icon');
$javame->createdby = $mform->getElementValue('createdby');
$javame->vendor = $mform->getElementValue('vendor');
$javame->name = $mform->getElementValue('name');
$javame->description = $mform->getElementValue('description');
$javame->version = $mform->getElementValue('version');
$javame->maxpicturewidth = $mform->getElementValue('maxpicturewidth');
$javame->maxpictureheight = $mform->getElementValue('maxpictureheight');
if (!($DB->update_record( 'game_export_javame', $javame))) {
print_error("game_export_javame: not updated id=$javame->id");
}
require_once("exportjavame.php");
game_OnExportJavaME( $game, $javame);
}
}