123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- <?php
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.');
- }
- require_once($CFG->libdir . '/formslib.php');
- require_once($CFG->dirroot . '/course/moodleform_mod.php');
- require_once($CFG->dirroot . '/mod/iassign/lib.php');
- class mod_ilm_form extends moodleform {
-
- function definition () {
- global $CFG, $COURSE, $USER, $DB;
- global $description;
- $mform = $this->_form;
- if ($CFG->action_ilm != 'import') {
- if ($CFG->action_ilm == 'add') {
-
-
-
- $tmps = $DB->get_records('iassign_ilm', array('parent' => 0));
- }
- else {
-
-
-
- $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 . "',";
- }
- if (!$tmps)
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $CFG->ilm_id));
- else
- $iassign_ilm = $tmps;
- if (!$iassign_ilm) {
- $iassign_ilm = new stdClass();
- $iassign_ilm->parent = 0;
- }
-
- $code_javascript = "\n <script type='text/javascript'>
- //<![CDATA[
- document.getElementById('id_data_file_html').style.display = 'none'
- document.getElementById('id_data_file_jar').classList.remove('collapsed');
- document.getElementById('id_data_ilm').classList.remove('collapsed');
- function search_name (name) {
- var i;
- var names = new Array(";
- if ($names != '')
- $code_javascript .= addslashes($names) . "');\n";
- $code_javascript .= "
- for (i=0;i<names.length;i++) {
- if (names[i].toLowerCase()==name.toLowerCase()) {
- document.forms['mform1'].name.value='';
- confirm('" . get_string('invalid_name_ilm', 'iassign') . " '+names[i]+'!');
- }
- }";
- $code_javascript .= " }
- function search_extension(extensions) {
- var i;
- var ext_inserteds = extensions.split(',');
- var ext_exists = new Array(";
- $code_javascript .= $extensions . "'');" . chr(13);
- $code_javascript .= "
- for (k=0;k<ext_inserteds.length;k++) {
- for (i=0;i<ext_exists.length;i++) {
- if (ext_exists[i].toLowerCase()==ext_inserteds[k].toLowerCase()) {
- document.forms['mform1'].extension.value='';
- confirm('" . get_string('invalid_extension_ilm', 'iassign') . " '+ext_exists[i]+'!');
- }
- }
- }\n";
- $code_javascript .= " }
-
- function search_filejar (fullfilejar) {
- var i;
- var tmp = fullfilejar.split('/');
- var filejar = tmp[tmp.length-1];
- var filejars = new Array(";
- if ($filejars!='')
- $code_javascript .= addslashes($filejars) . "');" . chr(13);
- $code_javascript .= "
- for (i=0;i<filejars.length;i++) {
- if (filejars[i].toLowerCase()==filejar.toLowerCase()) {
- document.forms['mform1'].file_jar[0].value='';
- confirm('" . get_string('invalid_filejar_ilm', 'iassign') . " '+filejars[i]+'!');
- }
- }\n";
- $code_javascript .= " }
- function change_language (lang) {
- if (document.forms['mform1'].description_lang.value != '') {
- descriptions = eval('(' + document.forms['mform1'].description_lang.value + ')');
- descriptions[document.forms['mform1'].set_lang.value] = tinyMCE.activeEditor.getContent();
- document.forms['mform1'].description_lang.value = JSON.stringify(descriptions);
- if (descriptions[lang] != undefined)
- tinyMCE.activeEditor.setContent(descriptions[lang]);
- else
- tinyMCE.activeEditor.setContent('');
- }
- else {
- document.forms['mform1'].description_lang.value = '{ \"' + document.forms['mform1'].set_lang.value + '\" : \"' + tinyMCE.activeEditor.getContent() + '\" }';
- tinyMCE.activeEditor.setContent('');
- }
- document.forms['mform1'].set_lang.value = lang;
- }
- //]]>
- </script>\n";
-
-
- if ($CFG->action_ilm != 'add') {
-
-
-
-
-
-
-
-
- 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);
- }
-
- $mform->addElement('text', 'version', get_string('version_ilm', 'iassign'), array('size' => '55'));
- $mform->setType('version', PARAM_TEXT);
- $mform->addHelpButton('version', 'version_ilm', 'iassign');
-
-
- $mform->addElement('static', 'ilm_type', get_string('type_ilm', 'iassign'));
- $mform->addElement('hidden', 'type');
- $mform->setType('type', PARAM_TEXT);
-
- $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());
-
-
-
-
-
-
-
-
-
-
- $mform->addElement('text', 'description', get_string('description', 'iassign'), array('size' => '80'));
- $mform->setType('description', PARAM_RAW);
-
-
- $mform->addElement('header', 'data_file_jar', get_string('data_file_jar', 'iassign'));
- $mform->addElement('static', 'file_jar_static', get_string('fields_info', 'iassign'));
-
- $mform->addElement('text', 'file_jar', get_string('file_jar_path', 'iassign'), array('size' => '55'));
- $mform->setType('file_jar', PARAM_TEXT);
-
- $mform->addElement('text', 'file_class', get_string('file_class', 'iassign'));
- $mform->setType('file_class', PARAM_TEXT);
-
-
-
-
-
-
-
-
-
- $mform->addElement('text', 'extension', get_string('extension', 'iassign'), array('size' => '30', 'onchange' => 'search_extension(this.value);'));
- $mform->setType('extension', PARAM_TEXT);
-
- $mform->addHelpButton('extension', 'extension', 'iassign');
-
- $mform->addElement('text', 'width', get_string('width', 'iassign'), array('size' => '10'));
- $mform->setType('width', PARAM_TEXT);
-
-
- $mform->addElement('text', 'height', get_string('height', 'iassign'), array('size' => '10'));
- $mform->setType('height', PARAM_TEXT);
-
-
- $mform->addElement('selectyesno', 'evaluate', get_string('auto_evaluate', 'iassign'));
- $mform->setDefault('evaluate', 1);
-
- $mform->addHelpButton('evaluate', 'auto_evaluate', 'iassign');
-
- $mform->addElement('text', 'submissionbehavior', get_string('auto_evaluate', 'iassign'));
- $mform->setType('submissionbehavior', PARAM_INT);
-
- $mform->addElement('header', 'data_file_html', get_string('data_file_html', 'iassign'));
-
- $mform->addElement('static', 'data_file_html_static', get_string('data_file_html_static', 'iassign'));
- }
-
-
-
-
-
- $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');
-
- 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', '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'));
-
- $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();
- }
- }
|