submission_form.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // This file is part of
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. defined('MOODLE_INTERNAL') || die();
  17. require_once($CFG->dirroot.'/lib/formslib.php');
  18. // require_once($CFG->dirroot.'/course/moodleform_mod.php');
  19. // require_once($CFG->dirroot.'/mod/gradeimporter/lib.php');
  20. class mod_gradeimporter_submission_form extends moodleform {
  21. public function definition() {
  22. global $CFG, $DB;
  23. $mform =& $this->_form;
  24. $submission = $this->_customdata['submission'];
  25. $cm = $this->_customdata['cm'];
  26. $descriptionoptions = $this->_customdata['descriptionoptions'];
  27. $submissionoptions = $this->_customdata['submissionoptions'];
  28. $gradeimporterid = $this->_customdata['gradeimporterid'];
  29. $context = context_module::instance($cm->id);
  30. $fmtoptions = array('context' => $context);
  31. // ----------------------------------------------------------------------
  32. // Form elements start here
  33. $mform->addElement('header', 'general', get_string('general', 'form'));
  34. // Submission name
  35. $mform->addElement('text', 'name', get_string('name', 'gradeimporter'), array('size' => '64'));
  36. $mform->setType('name', PARAM_TEXT);
  37. $mform->addRule('name', get_string('error_nameField', 'gradeimporter'), 'required', null, 'client');
  38. // Description
  39. $mform->addElement('editor', 'descriptioneditor',
  40. get_string('submissionDescription', 'gradeimporter'),
  41. null, $descriptionoptions,
  42. );
  43. $mform->setType('descriptioneditor', PARAM_RAW);
  44. $mform->addElement('header', 'filehandling', get_string('filehandling', 'gradeimporter'));
  45. $url = new moodle_url('/mod/gradeimporter/submissiontype.php?id='.$gradeimporterid.'&cmid='.$cm->id.'&page=0');
  46. $newsubtypecontent = '<a href='.$url.'>'.get_string('newsubtype', 'gradeimporter').'</a>';
  47. /*$newsubtypecontent = '<form action="'. $url . '">'.
  48. '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
  49. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  50. '<input type="hidden" name="page" value="0" />'.
  51. '<input type="submit" Value="'.get_string('newsubtype', 'gradeimporter').'" />'.
  52. '</form>';*/
  53. $mform->addElement('html', $newsubtypecontent);
  54. // Submission type
  55. $submissiontyperecords = $DB->get_records('gradeimporter_submissiontype', null, 'id', 'id, name, description');
  56. $submissiontyperecords = array_values($submissiontyperecords);
  57. $submissiontype = array();
  58. foreach (array_keys($submissiontyperecords) as $key) {
  59. $submissiontype[$submissiontyperecords[$key]->id] = $submissiontyperecords[$key]->name;
  60. }
  61. $mform->addElement('select', 'type',
  62. get_string('submissiontype', 'gradeimporter'),
  63. $submissiontype,
  64. array('onChange' => 'config_type(this.value);')
  65. );
  66. // $mform->setDefault('submissiontype', 0); // default submissiontype = 3
  67. $mform->addHelpButton('type', 'submissiontype', 'gradeimporter');
  68. // Receive the files
  69. $mform->addElement('filemanager', 'submission_filemanager',
  70. get_string('submissionFiles', 'gradeimporter'),
  71. null, $descriptionoptions
  72. );
  73. $mform->addHelpButton('submission_filemanager', 'submissionFiles', 'gradeimporter');
  74. // Csv delimiter
  75. $csvdelimiter = array();
  76. $csvdelimiter[1] = ',';
  77. /*$csvdelimiter[2] = ';';
  78. $csvdelimiter[3] = ':';
  79. $csvdelimiter[4] = '\t';
  80. */
  81. $mform->addElement('select', 'csvdelimiter',
  82. get_string('csvdelimiter', 'gradeimporter'),
  83. $csvdelimiter,
  84. array('onChange' => 'config_type(this.value);')
  85. );
  86. $mform->setDefault('csvdelimiter', 1); // Default csvdelimiter = 3
  87. $mform->addHelpButton('csvdelimiter', 'csvdelimiter', 'gradeimporter');
  88. // Gradebook Y/N Combobox
  89. $ynarray = array();
  90. $ynarray[0] = get_string('no', 'gradeimporter');
  91. $ynarray[1] = get_string('yes', 'gradeimporter');
  92. $mform->addElement('select', 'gradebook', get_string('gradebookYN', 'gradeimporter'), $ynarray);
  93. // $mform->setDefault('gradebook', 0);
  94. $mform->addHelpButton('gradebook', 'gradebookYN', 'gradeimporter');
  95. // Visibility Y/N Combobox
  96. $mform->addElement('select', 'visibility', get_string('visibilityYN', 'gradeimporter'), $ynarray);
  97. // $mform->setDefault('visibility', 0);
  98. $mform->addHelpButton('visibility', 'visibilityYN', 'gradeimporter');
  99. // -----------------------------
  100. // Hidden fields
  101. $mform->addElement('hidden', 'id');
  102. $mform->setType('id', PARAM_INT);
  103. $mform->addElement('hidden', 'cmid');
  104. $mform->setType('cmid', PARAM_INT);
  105. // ------------------------------
  106. // --------------------------------------------------------------
  107. $this->add_action_buttons();
  108. // --------------------------------------------------------------
  109. $this->set_data($submission);
  110. }
  111. }