submission_form.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. if (!defined('MOODLE_INTERNAL')) {
  3. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  4. }
  5. require_once($CFG->dirroot.'/lib/formslib.php');
  6. //require_once($CFG->dirroot.'/course/moodleform_mod.php');
  7. //require_once($CFG->dirroot.'/mod/gradeimporter/lib.php');
  8. class mod_gradeimporter_submission_form extends moodleform{
  9. function definition(){
  10. global $CFG, $DB;
  11. $mform =& $this->_form;
  12. $submission = $this->_customdata['submission'];
  13. $cm = $this->_customdata['cm'];
  14. $descriptionoptions = $this->_customdata['descriptionoptions'];
  15. $submissionoptions = $this->_customdata['submissionoptions'];
  16. $gradeimporterid = $this->_customdata['gradeimporterid'];
  17. $context = context_module::instance($cm->id);
  18. $fmtoptions = array('context'=>$context);
  19. //----------------------------------------------------------------------
  20. //form elements start here
  21. $mform->addElement('header', 'general', get_string('general', 'form'));
  22. //submission name
  23. $mform->addElement('text', 'name', get_string('name', 'gradeimporter'), array('size'=>'64'));
  24. $mform->setType('name', PARAM_TEXT);
  25. $mform->addRule('name', get_string('error_nameField', 'gradeimporter'), 'required', null, 'client');
  26. //description
  27. $mform->addElement('editor', 'description_editor', get_string('submissionDescription', 'gradeimporter'), null, $descriptionoptions);
  28. $mform->setType('description_editor', PARAM_RAW);
  29. $mform->addElement('header', 'filehandling', get_string('filehandling', 'gradeimporter'));
  30. $url = new moodle_url('/mod/gradeimporter/submissiontype.php?id='.$gradeimporterid.'&cmid='.$cm->id.'&page=0');
  31. $newSubTypeContent = '<a href='.$url.'>'.get_string('newsubtype', 'gradeimporter').'</a>';
  32. /*$newSubTypeContent = '<form action="'. $url . '">'.
  33. '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
  34. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  35. '<input type="hidden" name="page" value="0" />'.
  36. '<input type="submit" Value="'.get_string('newsubtype', 'gradeimporter').'" />'.
  37. '</form>';*/
  38. $mform->addElement('html', $newSubTypeContent);
  39. //submission type
  40. $submissionTypesRecords = $DB->get_records('gradeimporter_submissiontype', null, 'id', 'id, name, description');
  41. $submissionTypesRecords = array_values($submissionTypesRecords);
  42. $submissionType = array();
  43. foreach (array_keys($submissionTypesRecords) as $key){
  44. $submissionType[$submissionTypesRecords[$key]->id] = $submissionTypesRecords[$key]->name;
  45. }
  46. $mform->addElement('select', 'type', get_string('submissionType', 'gradeimporter'), $submissionType, array('onChange' => 'config_type(this.value);'));
  47. //$mform->setDefault('submissionType', 0); // default submissionType = 3
  48. $mform->addHelpButton('type', 'submissionType', 'gradeimporter');
  49. //receive the files
  50. $mform->addElement('filemanager', 'submission_filemanager', get_string('submissionFiles', 'gradeimporter'), null, $descriptionoptions);
  51. $mform->addHelpButton('submission_filemanager', 'submissionFiles', 'gradeimporter');
  52. //csv delimiter
  53. $csv_delimiter = array();
  54. $csv_delimiter[1] = ',';
  55. /*$csv_delimiter[2] = ';';
  56. $csv_delimiter[3] = ':';
  57. $csv_delimiter[4] = '\t';
  58. */
  59. $mform->addElement('select', 'csv_delimiter', get_string('csvdelimiter', 'gradeimporter'), $csv_delimiter, array('onChange' => 'config_type(this.value);'));
  60. $mform->setDefault('csv_delimiter', 1); // default csv_delimiter = 3
  61. $mform->addHelpButton('csv_delimiter', 'csvdelimiter', 'gradeimporter');
  62. //gradebook Y/N Combobox
  63. $ynarray = array();
  64. $ynarray[0] = get_string('no', 'gradeimporter');
  65. $ynarray[1] = get_string('yes', 'gradeimporter');
  66. $mform->addElement('select', 'gradebook', get_string('gradebookYN', 'gradeimporter'), $ynarray);
  67. //$mform->setDefault('gradebook', 0);
  68. $mform->addHelpButton('gradebook', 'gradebookYN', 'gradeimporter');
  69. //visibility Y/N Combobox
  70. $mform->addElement('select', 'visibility', get_string('visibilityYN', 'gradeimporter'), $ynarray);
  71. //$mform->setDefault('visibility', 0);
  72. $mform->addHelpButton('visibility', 'visibilityYN', 'gradeimporter');
  73. //-----------------------------
  74. //hidden fields
  75. $mform->addElement('hidden', 'id');
  76. $mform->setType('id', PARAM_INT);
  77. $mform->addElement('hidden', 'cmid');
  78. $mform->setType('cmid', PARAM_INT);
  79. //------------------------------
  80. //--------------------------------------------------------------
  81. $this->add_action_buttons();
  82. //--------------------------------------------------------------
  83. $this->set_data($submission);
  84. }
  85. }