submission_form.php 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // This file is part of LInE contributions to Free Education, Private Data
  3. // LInE (Laboratory of Informatics in Education)
  4. // http://www.usp.br/line
  5. //
  6. // Moodle is free software: you can redistribute it or modify it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU General Public License
  13. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  14. defined('MOODLE_INTERNAL') || die();
  15. require_once($CFG->dirroot . "/course/moodleform_mod.php");
  16. require_once($CFG->libdir . "/formslib.php");
  17. require_once("submission_form_functions.php");
  18. class mod_gradeimporter_submission_form extends moodleform {
  19. public function definition () {
  20. global $CFG, $DB;
  21. $mform = $this->_form;
  22. // Custom data
  23. $submission = $this->_customdata['submission']; // Load fields data
  24. $filemanageroptions = $this->_customdata['filemanageroptions'];
  25. $gradeimporterid = $this->_customdata['gradeimporterid'];
  26. $cmid = $this->_customdata['cmid'];
  27. // ----------------------------------------------------------------
  28. // General information
  29. // Header
  30. $mform->addElement('header', 'newsub', get_string('newsubmission', 'gradeimporter'));
  31. // Submission name field
  32. $mform->addElement('text', 'name', get_string('submissionname', 'gradeimporter'), array('maxlength' => '256'));
  33. $mform->setType('name', PARAM_TEXT);
  34. $mform->addRule('name', null, 'required', null, 'client');
  35. $mform->addElement('editor', 'description', get_string('description'));
  36. $mform->setType('description', PARAM_TEXT);
  37. $mform->addElement('filemanager', 'submissionfiles_filemanager', get_string('submissionfiles', 'gradeimporter'), null, $filemanageroptions);
  38. $mform->addHelpButton('submissionfiles_filemanager', 'submissionfiles', 'gradeimporter');
  39. // Add button to open new subtypeform
  40. $subtypeformurl = new moodle_url("/mod/gradeimporter/forms/submissiontype/submissiontype.php", array('cmid' => $cmid, 'id' => $gradeimporterid));
  41. $newsubtypebutton = "<div class=\"col-md-9 form-inline align-items-start felement\">
  42. <button class=\"btn btn-primary\" onclick=\"window.open('" . $subtypeformurl . "','_self')\">New type</button>
  43. </div>\n";
  44. $mform->addElement('html', $newsubtypebutton);
  45. // To edit
  46. $subtypes = get_types_array($gradeimporterid);
  47. if ($subtypes) {
  48. $selectvalues = array();
  49. foreach ($subtypes as $id => $type) {
  50. $selectvalues[$id] = $type->name;
  51. }
  52. }
  53. else {
  54. $selectvalues = array(-1 => 'create new type first');
  55. }
  56. $mform->addElement('select', 'type', get_string('submissiontype', 'gradeimporter'), $selectvalues);
  57. $mform->addElement('selectyesno', 'visibility', get_string('visibility', 'gradeimporter'));
  58. $mform->setDefault('visibility', array('value' => 1));
  59. $mform->addHelpButton('visibility', 'visibility', 'gradeimporter');
  60. $mform->addElement('selectyesno', 'gradebook', get_string('gradebook', 'gradeimporter'));
  61. $mform->setDefault('gradebook', array('value' => 0));
  62. $mform->addHelpButton('gradebook', 'gradebook', 'gradeimporter');
  63. // -----------------------------
  64. // Hidden fields
  65. $mform->addElement('hidden', 'id');
  66. $mform->setType('id', PARAM_INT);
  67. $mform->addElement('hidden', 'cmid');
  68. $mform->setType('cmid', PARAM_INT);
  69. // ------------------------------
  70. // Save and cancel buttons
  71. $this->add_action_buttons();
  72. // ------------------------------
  73. // Sets preloaded data to fields
  74. $this->set_data($submission);
  75. } // public function definition()
  76. } // class mod_gradeimporter_submission_form extends moodleform