123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513 |
- <?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_iassign_form extends moodleform {
-
- function definition () {
- global $CFG, $COURSE, $USER, $DB, $OUTPUT;
- $mform = $this->_form;
- $instance = $this->_customdata;
-
- $params = array('name' => '%iGeom%', 'parent' => 0);
- $igeom = $DB->get_records_sql(
- "SELECT s.id, s.name, s.parent FROM {iassign_ilm} s
- WHERE s.name LIKE :name AND s.parent = :parent", $params);
- $id = $COURSE->cm;
- foreach ($igeom as $item)
- $idigeom = $item->id;
- $all_ilm = $DB->get_records('iassign_ilm', array('enable' => 1));
- $iassigns = $DB->get_records('iassign_statement', array('iassignid' => $COURSE->iassignid));
- if ($all_ilm) {
- $ids = "";
- $names = "";
- $evaluates = "";
- foreach ($all_ilm as $one_ilm) {
- $ids .= "'" . $one_ilm->id . "',";
- $names .= "'" . $one_ilm->name . "',";
- $evaluates .= "'" . $one_ilm->evaluate . "',";
- }
- $ids .= "'0'";
- $evaluates .= "'0'";
- }
- $name_iassigns = "";
- if ($iassigns) {
- foreach ($iassigns as $iassign) {
- $name_iassigns .= "'" . $iassign->name . "',";
- }
- }
- $name_iassigns .= "''";
- $error_name = get_string('error_iassign_name', 'iassign');
-
- $code_javascript = "
- <script type='text/javascript'>
- //<![CDATA[
- var i;
- var ids = new Array($ids);
- var evaluates = new Array($evaluates);
- document.forms['mform1'].filename.disabled=1;
- if (document.forms['mform1'].type_iassign.value==1) {
- document.forms['mform1'].grade.style.display='none';
- document.forms['mform1'].max_experiment.style.display='none';
- } else {
- document.forms['mform1'].grade.style.display='block';
- document.forms['mform1'].max_experiment.style.display='block';
- }
- for (i=0;i<ids.length;i++) {
- if (ids[i]==document.forms['mform1'].iassign_ilmid.value && evaluates[i]==0) {
- document.forms['mform1'].automatic_evaluate.style.display='none';
- document.forms['mform1'].show_answer.style.display='none';
- //document.forms['mform1'].automatic_evaluate.disabled=1;
- // document.forms['mform1'].show_answer.disabled=1;
- }
- }
- if (document.forms['mform1'].iassign_ilmid.value==" . $idigeom .") { // iGeom has special parameter 'script'
- document.forms['mform1'].special_param1.style.display='block';
- document.forms['mform1'].special_param1.disabled=0;
- }
- else {
- document.forms['mform1'].special_param1.style.display='none';
- document.forms['mform1'].special_param1.value=0;
- document.forms['mform1'].special_param1.disabled=1;
- }
- function confirm_name (name) {
- var i;
- var names = new Array($name_iassigns);
- for (i=0;i<names.length;i++) {
- if (names[i]==name)
- alert('" . $error_name . "');
- }
- }
- function config_ilm (id) {
- //alert('config_ilm('+id+'): idigeom=$idigeom, ilmid='+document.forms['mform1'].iassign_ilmid.value);
- if (id==$idigeom) {
- document.forms['mform1'].special_param1.style.display='block';
- document.forms['mform1'].special_param1.disabled=0;
- }
- else {
- document.forms['mform1'].special_param1.style.display='none';
- document.forms['mform1'].special_param1.value=0;
- document.forms['mform1'].special_param1.disabled=1;
- }
- var i;
- var ids = new Array($ids);
- var evaluates = new Array($evaluates);
- if (document.forms['mform1'].type_iassign.value==1) {
- document.forms['mform1'].automatic_evaluate.disabled=1;
- document.forms['mform1'].show_answer.disabled=1;
- document.forms['mform1'].automatic_evaluate.value=0;
- document.forms['mform1'].show_answer.value=0;
- }
- else { // if (document.forms['mform1'].type_iassign.value==1)
- for (i=0;i<ids.length;i++) {
- if (ids[i]==id) {
- if (document.forms['mform1'].action.value=='edit') {
- if (evaluates[i]==0){
- document.forms['mform1'].automatic_evaluate.style.display='none';
- document.forms['mform1'].show_answer.style.display='none';
- document.forms['mform1'].automatic_evaluate.disabled=1;
- document.forms['mform1'].show_answer.disabled=1;
- document.forms['mform1'].automatic_evaluate.value=0;
- document.forms['mform1'].show_answer.value=0;
- }
- else {
- document.forms['mform1'].automatic_evaluate.style.display='block';
- document.forms['mform1'].show_answer.style.display='block';
- document.forms['mform1'].automatic_evaluate.disabled=0;
- document.forms['mform1'].show_answer.disabled=0;
- document.forms['mform1'].automatic_evaluate.value=1;
- document.forms['mform1'].show_answer.value=1;
- }
- }
- if (document.forms['mform1'].action.value=='add') {
- if (evaluates[i]==0) {
- document.forms['mform1'].automatic_evaluate.style.display='none';
- document.forms['mform1'].show_answer.style.display='none';
- document.forms['mform1'].automatic_evaluate.disabled=1;
- document.forms['mform1'].show_answer.disabled=1;
- document.forms['mform1'].automatic_evaluate.value=0;
- document.forms['mform1'].show_answer.value=0;
- }
- else {
- document.forms['mform1'].automatic_evaluate.style.display='block';
- document.forms['mform1'].show_answer.style.display='block';
- document.forms['mform1'].automatic_evaluate.disabled=0;
- document.forms['mform1'].show_answer.disabled=0;
- document.forms['mform1'].automatic_evaluate.value=1;
- document.forms['mform1'].show_answer.value=1;
- }
- }
- } // if (ids[i]==id)
- } // for (i=0;i<ids.length;i++)
- } // else if (document.forms['mform1'].type_iassign.value==1)
- } // function config_ilm(id)
- function disable_answer (resp) {
- if (resp==0) {
- document.forms['mform1'].show_answer.value=0;
- document.forms['mform1'].show_answer.disabled=1;
- }
- else {
- document.forms['mform1'].show_answer.disabled=0;
- }
- }
- function view_ilm_manager () {
- document.forms['mform1'].filename.disabled=1;
- open_ilm_manager=window.open('$CFG->wwwroot/mod/iassign/ilm_manager.php?id=$COURSE->id&from=iassign&ilmid='+document.forms['mform1'].iassign_ilmid.value,'','width=1000,height=880,menubar=0,location=0,scrollbars,status,fullscreen,resizable');
- }
- //]]>
- </script>";
-
-
-
- $mform->addElement('header', 'title_type_iassign', get_string('type_iassign', 'iassign'));
- $type_iassign = array();
- $type_iassign[1] = get_string('example', 'iassign');
- $type_iassign[2] = get_string('test', 'iassign');
- $type_iassign[3] = get_string('exercise', 'iassign');
- $mform->addElement('select', 'type_iassign', get_string('choose_type_activity', 'iassign'), $type_iassign, array('onChange' => 'config_type(this.value);'));
- $mform->setDefault('type_iassign', 3);
- $mform->addHelpButton('type_iassign', 'helptypeiassign', 'iassign');
-
-
- $mform->addElement('header', 'data_activity', get_string('data_activity', 'iassign'));
- $mform->addElement('static', 'author', get_string('author_id', 'iassign'));
- $mform->addElement('static', 'author_modified', get_string('author_id_modified', 'iassign'));
-
- $mform->addElement('text', 'name', get_string('iassigntitle', 'iassign'), array('size' => '55', 'onChange' => 'confirm_name(this.value);'));
- $mform->setType('name', PARAM_TEXT);
- $mform->addRule('name', get_string('required', 'iassign'), 'required');
-
-
- $mform->addElement('editor', 'proposition', get_string('proposition', 'iassign'));
- $mform->setType('proposition', PARAM_RAW);
- $mform->addRule('proposition', get_string('required', 'iassign'), 'required');
-
-
- $mform->addElement('header', 'interactivy_learning_module', get_string('interactivy_learning_module', 'iassign'));
-
-
-
-
- $ilms = $all_ilm;
-
-
-
-
-
-
-
-
-
-
-
- $list_html = array(); $list_html_id = array();
- $list_applets = array(); $list_applets_id = array();
- $num_iLM_html = $num_iLM_java = 0;
- foreach ($ilms as $ilm) {
- $type4 = substr($ilm->type, 0,4);
- if (strcasecmp($type4, "HTML") == 0) {
- $list_html[$num_iLM_html] = $ilm->name . ' (' . $ilm->version . ')';
- $list_html_id[$num_iLM_html] = $ilm->id;
- $num_iLM_html++;
- } else {
- $list_applets[$num_iLM_java] = $ilm->name . ' (' . $ilm->version . ')';
- $list_applets_id[$num_iLM_java] = $ilm->id;
- $num_iLM_java++;
- }
- }
-
-
-
- $html_group = get_string("group", "iassign") . " HTML";
- $java_group = get_string("group", "iassign") . " Java";
- $groups_ilm_select = array($html_group => array(), $java_group => array());
- for ($ii=0; $ii<$num_iLM_html; $ii++) {
- $groups_ilm_select[$html_group][$list_html_id[$ii]] = $list_html[$ii];
- }
- for ($ii=0; $ii<$num_iLM_java; $ii++) {
- $groups_ilm_select[$java_group][$list_applets_id[$ii]] = $list_applets[$ii];
- }
-
- $mform->addElement('selectgroups', 'iassign_ilmid', get_string('choose_iLM', 'iassign'), $groups_ilm_select);
- $mform->addHelpButton('iassign_ilmid', 'choose_iLM', 'iassign');
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $fileurl = "";
- $filename = "";
- if (!is_null($COURSE->iassign_file_id)) {
- $mform->addElement('hidden', 'action', 'viewpluginpage');
- $fs = get_file_storage();
- $file = $fs->get_file_by_id($COURSE->iassign_file_id);
- $fileurl = $CFG->wwwroot . "/pluginfile.php/" . $file->get_contextid() . "/mod_iassign/exercise" . '/' . $file->get_itemid() . $file->get_filepath() . $file->get_filename();
- $filename = $file->get_filename();
- }
-
- $html_div = '<br/> <br/><div id="fitem_id_iassign_file_id" class="fitem required fitem_fgroup">';
- $html_div .= '<div class="fitemtitle"><label for="id_iassign_file_id">' . get_string('choose_file', 'iassign');
- $html_div .= '<img class="req" title="' . get_string('requiredelement', 'form') . '" alt="' . get_string('requiredelement', 'form') . '" src="' . $CFG->wwwroot . '/theme/image.php/standard/core/1379534589/req"></label></div>';
- $html_div .= '<div class="felement fselect">';
- $html_div .= '<span id="iassign_file_link" style="color:#000000;"><a href="' . $fileurl . '" target="_blank" title="' . get_string('download_file', 'iassign') . $filename . '">' . $filename . '</a></span>';
- if ($fileurl != "")
- $html_div .= ' ';
- $html_div .= '<input onclick="view_ilm_manager()" name="add_ilm" value="' . get_string('add_ilm', 'iassign') . '" type="button" id="id_add_ilm"/>';
- $html_div .= '</div>';
- $html_div .= '</div>';
- $mform->addElement('html', $html_div);
-
- $mform->addElement('selectyesno', 'special_param1', get_string('special_param', 'iassign'));
- $mform->setDefault('special_param1', 0);
- $mform->addHelpButton('special_param1', 'helpspecial_param', 'iassign');
-
-
- $mform->addElement('header', 'id_automatic_evaluate', get_string('only_automatic_evaluate', 'iassign'));
-
- $mform->addElement('selectyesno', 'automatic_evaluate', get_string('automatic_evaluate', 'iassign'), array('onChange' => 'disable_answer(this.value);'));
- $mform->disabledIf('automatic_evaluate', 'type_iassign', 'eq', 1);
- $mform->setDefault('automatic_evaluate', 0);
-
-
-
- $mform->addElement('selectyesno', 'show_answer', get_string('show_answer', 'iassign'));
- $mform->disabledIf('show_answer', 'type_iassign', 'eq', 1);
-
- $mform->setDefault('show_answer', 0);
-
-
-
- $mform->addElement('header', 'duration_activity', get_string('duration_activity', 'iassign'));
- $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'iassign'));
- $mform->setDefault('timeavailable', time());
- $mform->disabledIf('timeavailable', 'type_iassign', 'eq', 1);
- $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'iassign'));
- $mform->setDefault('timedue', time() + 7 * 24 * 3600);
- $mform->disabledIf('timedue', 'type_iassign', 'eq', 1);
-
- $mform->addElement('selectyesno', 'preventlate', get_string('preventlate', 'iassign'));
- $mform->setDefault('preventlate', 0);
- $mform->addHelpButton('preventlate', 'helppreventlate', 'iassign');
- $mform->disabledIf('preventlate', 'type_iassign', 'eq', 1);
- $mform->disabledIf('preventlate', 'type_iassign', 'eq', 2);
-
- $mform->addElement('selectyesno', 'test', get_string('permission_test', 'iassign'));
- $mform->setDefault('test', 0);
- $mform->addHelpButton('test', 'helptest', 'iassign');
- $mform->disabledIf('test', 'type_iassign', 'eq', 1);
- $mform->disabledIf('test', 'type_iassign', 'eq', 2);
-
- $mform->addElement('header', 'op_val', get_string('op_val', 'iassign'));
- $mform->addElement('modgrade', 'grade', get_string('grade', 'iassign'));
- $mform->setDefault('grade', 100);
- $mform->disabledIf('grade', 'type_iassign', 'eq', 1);
- $mform->disabledIf('grade', 'type_iassign', 'eq', 2);
- $max_experiment_options = array(0 => get_string('ilimit', 'iassign'));
- for ($i = 1; $i <= 20; $i++)
- $max_experiment_options[$i] = $i;
- $mform->addElement('select', 'max_experiment', get_string('experiment', 'iassign'), $max_experiment_options);
- $mform->setDefault('max_experiment', 0);
- $mform->addHelpButton('max_experiment', 'helpexperiment', 'iassign');
- $mform->disabledIf('max_experiment', 'type_iassign', 'eq', 1);
- $mform->disabledIf('max_experiment', 'type_iassign', 'eq', 2);
- if ($COURSE->iassign_list) {
-
- $mform->addElement('header', 'headerdependency', get_string('dependency', 'iassign'));
- $mform->addHelpButton('headerdependency', 'helpdependency', 'iassign');
- foreach ($COURSE->iassign_list as $iassign) {
- $tmp = 'iassign_list[' . $iassign->id . ']';
- if ($iassign->enable == 1)
- $mform->addElement('checkbox', $tmp, $iassign->name);
- }
- }
- $mform->addElement('hidden', 'dependency');
- $mform->setType('dependency', PARAM_RAW);
-
- $mform->addElement('header', 'config', get_string('general', 'iassign'));
- $visibleoptions = array(1 => get_string('show'), 0 => get_string('hide'));
- $mform->addElement('select', 'visible', get_string('visible', 'iassign'), $visibleoptions);
- $mform->setDefault('visible', 0);
-
-
- $mform->addElement('hidden', 'action');
- $mform->setType('action', PARAM_TEXT);
- $mform->addElement('hidden', 'oldname');
- $mform->setType('oldname', PARAM_TEXT);
- $mform->addElement('hidden', 'id');
- $mform->setType('id', PARAM_TEXT);
- $mform->addElement('hidden', 'iassign_id');
- $mform->setType('iassign_id', PARAM_TEXT);
- $mform->addElement('hidden', 'file', '0');
- $mform->setType('file', PARAM_INT);
- $mform->addElement('hidden', 'filename');
- $mform->setType('filename', PARAM_TEXT);
- $mform->addElement('hidden', 'fileold');
- $mform->setType('fileold', PARAM_TEXT);
- $mform->addElement('hidden', 'iassignid');
- $mform->setType('iassignid', PARAM_TEXT);
- $mform->addElement('hidden', 'author_name');
- $mform->setType('author_name', PARAM_TEXT);
- $mform->addElement('hidden', 'author_modified_name');
- $mform->setType('author_modified_name', PARAM_TEXT);
- $mform->addElement('hidden', 'timecreated');
- $mform->setType('timecreated', PARAM_TEXT);
- $mform->addElement('hidden', 'position');
- $mform->setType('position', PARAM_TEXT);
- $mform->addElement('html', $code_javascript);
-
- $this->add_action_buttons();
- }
- function validation ($data, $files) {
- global $COURSE, $DB;
- $errors = parent::validation($data, $files);
- $mform = & $this->_form;
- $errors = array();
- if ($mform->elementExists('name')) {
- $value = trim($data['name']);
- if ($value == '') {
- $errors['name'] = get_string('required', 'iassign');
- }
- }
- if ($mform->elementExists('proposition')) {
-
-
- if (is_array($data['proposition'])) {
-
-
- $aux = $data['proposition'];
- if (isset($aux['text']))
- $value = trim($aux['text']);
- else
- $value = trim($aux[0]);
- }
- else
- $value = trim($data['proposition']);
- if ($value == '') {
- $errors['proposition'] = get_string('required', 'iassign');
- }
- }
-
- if ($mform->elementExists('file')) {
- $value = trim($data['file']);
- if ($value == 0) {
- $errors['iassign_ilmid'] = get_string('required_iassign_file', 'iassign');
- }
- }
- return $errors;
- }
- }
|