iMath) - Computer Science Dep. of IME-USP (Brazil) * * License * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly. */ if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } require_once ($CFG->libdir . '/formslib.php'); require_once ($CFG->dirroot . '/course/moodleform_mod.php'); require_once ($CFG->dirroot . '/mod/iassign/lib.php'); /** * This class create form based moodleform. * @see moodleform */ class mod_ilm_form extends moodleform { /** * Add elements to form */ function definition() { global $CFG, $COURSE, $USER, $DB; $mform = & $this->_form; if ($CFG->action_ilm != 'import') { if ($CFG->action_ilm == 'add') { /* $params = array('parent' => '0'); $tmps = $DB->get_records_sql("SELECT s.id, s.name, s.extension, s.file_jar FROM {iassign_ilm} s WHERE s.parent = :parent", $params); // " - jed/emacs */ $tmps = $DB->get_records('iassign_ilm', array('parent' => 0)); } else { /* $params = array('id' => $CFG->ilm_id); $tmps = $DB->get_records_sql("SELECT s.id, s.name, s.extension, s.file_jar FROM {iassign_ilm} s WHERE s.id != :id AND s.parent = 0", $params); // " - jed/emacs */ $tmps = $DB->get_records('iassign_ilm', array('id' => $CFG->ilm_id)); } $extensions = ""; $names = ""; $versions = ""; $filejars = ""; foreach ($tmps as $tmp) { $exts = explode(",", $tmp->extension); foreach ($exts as $ext) { $extensions .="'" . $ext . "',"; } $names .="'" . $tmp->name . "',"; $filejars .="'" . $tmp->file_jar . "',"; } $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $CFG->ilm_id)); if (!$iassign_ilm) { $iassign_ilm = new stdClass(); $iassign_ilm->parent = 0; } /// @todo Código Javascript, verificar alternativa. $code_javascript = " "; //------------------------------------------------------------------------------- /// Adding the "data_ilm" fieldset, where all the common settings are showed if ($CFG->action_ilm != 'add') { /*$mform->addElement('header', 'type_ilm', get_string('type_ilm', 'iassign')); /// Adding the select option for HTML5 or Java $options = array( 'Java' => 'Java', 'HTML5' => 'HTML5' ); $mform->addElement('select', 'ilm_type', get_string('ilm_type', 'iassign'), $options); $mform->setDefault('ilm_type', PARAM_TEXT); $mform->addHelpButton('ilm_type', 'ilm_type', 'iassign'); $mform->addElement('header', 'data_ilm', get_string('data_ilm', 'iassign')); * */ /// Adding the standard "name" field if ($CFG->action_ilm != 'add') { $mform->addElement('static', 'name_ilm', get_string('name_ilm', 'iassign')); $mform->addElement('hidden', 'name'); $mform->setType('name', PARAM_TEXT); } else { $mform->addElement('text', 'name', get_string('name_ilm', 'iassign'), array('size' => '55', 'onchange' => 'search_name(this.value);')); $mform->setType('name', PARAM_TEXT); } /// Adding the standard "version" field $mform->addElement('text', 'version', get_string('version_ilm', 'iassign'), array('size' => '55')); $mform->setType('version', PARAM_TEXT); $mform->addHelpButton('version', 'version_ilm', 'iassign'); // Adding the type of iLM $mform->addElement('static', 'ilm_type', get_string('type_ilm', 'iassign')); $mform->addElement('hidden', 'type'); $mform->setType('type', PARAM_TEXT); /// Adding the standard "url" field $mform->addElement('text', 'url', get_string('url_ilm', 'iassign'), array('size' => '55')); $mform->setType('url', PARAM_TEXT); $mform->addElement('select', 'lang', get_string('language_label', 'iassign'), get_string_manager()->get_list_of_translations(), array('onChange' => 'change_language(this.value);')); $mform->setDefault('lang', current_language()); /// Adding the standard "description" field $mform->addElement('htmleditor', 'description', get_string('description', 'iassign')); $mform->setType('description', PARAM_RAW); /// Adding the "data_file_jar" fieldset, where all the common settings are showed $mform->addElement('header', 'data_file_jar', get_string('data_file_jar', 'iassign')); $mform->addElement('static', 'file_jar_static', get_string('file_jar', 'iassign')); /// Adding the standard "file_class" field $mform->addElement('text', 'file_class', get_string('file_class', 'iassign'), array('size' => '55')); $mform->setType('file_class', PARAM_TEXT); //$mform->addRule('file_class', get_string('required', 'iassign'), 'required'); /// Adding the standard "extension" field $mform->addElement('text', 'extension', get_string('extension', 'iassign'), array('size' => '30', 'onchange' => 'search_extension(this.value);')); $mform->setType('extension', PARAM_TEXT); //$mform->addRule('extension', get_string('required', 'iassign'), 'required'); $mform->addHelpButton('extension', 'extension', 'iassign'); /// Adding the standard "width" field $mform->addElement('text', 'width', get_string('width', 'iassign'), array('size' => '10')); $mform->setType('width', PARAM_TEXT); //$mform->addRule('width', get_string('required', 'iassign'), 'required'); /// Adding the standard "height" field $mform->addElement('text', 'height', get_string('height', 'iassign'), array('size' => '10')); $mform->setType('height', PARAM_TEXT); //$mform->addRule('height', get_string('required', 'iassign'), 'required'); /// Adding the standard "evaluate" field $mform->addElement('selectyesno', 'evaluate', get_string('auto_evaluate', 'iassign')); $mform->setDefault('evaluate', 1); //$mform->addRule('evaluate', get_string('required', 'iassign'), 'required'); $mform->addHelpButton('evaluate', 'auto_evaluate', 'iassign'); /// Adding the "data_file_jar" fieldset, where all the common settings are showed $mform->addElement('header', 'data_file_html', get_string('data_file_html', 'iassign')); /// Adding static text $mform->addElement('static', 'data_file_html_static', get_string('data_file_html_static', 'iassign')); } /// Upload file ilm /* $mform->addElement('header', 'upload_jar', get_string('upload_jar', 'iassign')); //$mform->setExpanded('upload_jar'); $options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => -1, 'accepted_types' => '*'); $mform->addElement('filemanager', 'file', null, null, $options); * */ $mform->addElement('header', 'upload_jar', get_string('upload_jar', 'iassign')); $options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => 1, 'accepted_types' => array('*')); $mform->addElement('filepicker', 'file', null, null, $options); $mform->addRule('file', get_string('required', 'iassign'), 'required'); if ($CFG->action_ilm == 'add' || $CFG->action_ilm == 'copy' || $CFG->action_ilm == 'new_version') $mform->addRule('file', get_string('required', 'iassign'), 'required'); /// Adding the standard "hidden" field if ($CFG->action_ilm == 'edit') { $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); } $mform->addElement('hidden', 'set_lang'); $mform->setType('set_lang', PARAM_TEXT); $mform->setDefault('set_lang', current_language()); $mform->addElement('hidden', 'description_lang'); $mform->setType('description_lang', PARAM_TEXT); $mform->addElement('hidden', 'file_jar'); $mform->setType('file_jar', PARAM_TEXT); $mform->addElement('hidden', 'author'); $mform->setType('author', PARAM_TEXT); $mform->addElement('hidden', 'action'); $mform->setType('action', PARAM_TEXT); $mform->addElement('hidden', 'timecreated'); $mform->setType('timecreated', PARAM_TEXT); $mform->addElement('hidden', 'timemodified'); $mform->setType('timemodified', PARAM_TEXT); $mform->addElement('hidden', 'parent'); $mform->setType('parent', PARAM_INT); $mform->addElement('hidden', 'enable'); $mform->setType('enable', PARAM_INT); $mform->addElement('html', $code_javascript); } else { $mform->addElement('header', 'upload_ilm', get_string('upload_ilm', 'iassign')); //$mform->setExpanded('upload_ilm'); $options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => 1, 'accepted_types' => array('*')); $mform->addElement('filepicker', 'file', null, null, $options); $mform->addRule('file', get_string('required', 'iassign'), 'required'); $mform->addElement('hidden', 'action'); $mform->setType('action', PARAM_TEXT); } $this->add_action_buttons(); } }