submissiontype.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. require_once('../../config.php');
  17. require_once('locallib.php');
  18. require_once('lib.php');
  19. require_once('submissiontype_form.php');
  20. $cmid = required_param('cmid', PARAM_INT); // Course Module ID
  21. $id = required_param('id' , PARAM_INT); // Gradeimporter id
  22. if (!$cm = get_coursemodule_from_id('gradeimporter', $cmid)) {
  23. throw new moodle_exception('invalidcoursemodule');
  24. }
  25. if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
  26. throw new moodle_exception('coursemisconf');
  27. }
  28. $context = context_module::instance($cm->id);
  29. require_capability('mod/gradeimporter:edit', $context);
  30. if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $cm->instance))) {
  31. throw new moodle_exception('invalidid', 'gradeimporter');
  32. }
  33. $url = new moodle_url('/mod/gradeimporter/submissiontype.php', array('cmid' => $cm->id));
  34. if (!empty($id)) {
  35. $url->param('id', $id);
  36. }
  37. $PAGE->set_url($url);
  38. require_login($course, false, $cm);
  39. if ($submissiontype) {
  40. if (isguestuser()) {
  41. throw new moodle_exception('guestnoedit', 'gradeimporter', "$CFG->wwwroot/mod/gradeimporter/view.php?id=$cmid");
  42. }
  43. } else {
  44. $submissiontype = new stdClass();
  45. $submissiontype->id = null;
  46. }
  47. $maxfiles = 50;
  48. $maxbytes = $course->maxbytes;
  49. $descriptionoptions = array('trusttext' => true, 'maxfiles' => $maxfiles,
  50. 'maxbytes' => $maxbytes, 'context' => $context,
  51. 'subdirs' => file_area_contains_subdirs($context, 'mod_gradeimporter',
  52. 'submissiontype', $submissiontype->id));
  53. $submissiontypeoptions = array('subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
  54. $submissiontype = file_prepare_standard_editor($submissiontype, 'description', $descriptionoptions,
  55. $context, 'mod_gradeimporter', 'description', $submissiontype->id);
  56. $submissiontype->cmid = $cm->id;
  57. $mform = new mod_gradeimporter_submissiontype_form(null, array('submissiontype' => $submissiontype,
  58. 'cm' => $cm,
  59. 'descriptionoptions' => $descriptionoptions,
  60. 'submissiontypeoptions' => $submissiontypeoptions
  61. )
  62. );
  63. if ($mform->is_cancelled()) {
  64. if ($id) {
  65. redirect("view.php?id=$cm->id&mode=entry&hook=$id");
  66. } else {
  67. redirect("view.php?id=$cm->id");
  68. }
  69. } else if ($submissiontype = $mform->get_data()) {
  70. if (empty($submissiontype->id)) {
  71. $submissiontype->gradeimporterid = $gradeimporter->id;
  72. $isnewentry = true;
  73. } else {
  74. $isnewentry = false;
  75. }
  76. $submissiontype->description = '';
  77. $submissiontype->descriptionformat = FORMAT_HTML;
  78. $submissiontype->definitiontrust = 0;
  79. if ($isnewentry) {
  80. $submissiontype->id = $DB->insert_record('gradeimporter_submissiontype', $submissiontype);
  81. } else {
  82. $DB->update_record('gradeimporter', $submissiontype);
  83. }
  84. $submissiontype = file_postupdate_standard_editor($submissiontype, 'description',
  85. $descriptionoptions, $context, 'mod_gradeimporter',
  86. 'submissiontype', $submissiontype->id);
  87. $DB->update_record('gradeimporter_submissiontype', $submissiontype);
  88. if ($isnewentry) {
  89. // Update completion state
  90. $completion = new completion_info($course);
  91. if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $gradeimporter->completionentries) {
  92. $completion->update_state($cm, COMPLETION_COMPLETE);
  93. }
  94. }
  95. redirect("submission.php?id=$id&cmid=$cm->id&page=0");
  96. }
  97. if (!empty($id)) {
  98. $PAGE->navbar->add(get_string('edit'));
  99. }
  100. $PAGE->set_title($gradeimporter->name);
  101. $PAGE->set_heading($course->fullname);
  102. echo $OUTPUT->header();
  103. echo $OUTPUT->heading(format_string($gradeimporter->name), 2);
  104. if ($gradeimporter->intro) {
  105. echo $OUTPUT->box(format_module_intro('gradeimporter', $gradeimporter, $cm->id), 'generalbox', 'intro');
  106. }
  107. $mform->display();
  108. echo $OUTPUT->footer();