submission.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
  3. require_once(dirname(__FILE__).'/locallib.php');
  4. require_once(dirname(__FILE__).'/comment_form.php');
  5. $id = required_param('id', PARAM_INT);
  6. $delete = optional_param('delete', 0, PARAM_INT);
  7. $confirm = optional_param('confirm', 0, PARAM_INT);
  8. if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $id))) {
  9. print_error('invalidgradeimproterdid', 'gradeimporter');
  10. }
  11. list($course, $cm) = get_course_and_cm_from_instance($gradeimporter, 'gradeimporter');
  12. if ($delete && ! $submission = $DB->get_record('gradeimporter_sumbmission', array('gradeimporterid' => $gradeimporter->id, 'id' => $delete))) {
  13. print_error('Invalid comment ID');
  14. }
  15. require_login($course, true, $cm);
  16. $PAGE->set_cm($cm);
  17. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $id));
  18. $PAGE->set_title($gradeimporter->name);
  19. $page->set_heading($course->shortname);
  20. $context = context_module::instance($cm->id);
  21. $gradeimporterurl = $CFG->wwwroot.'mod/gradeimporter/view.php?id='.$cm->id;
  22. if ($delete && has_capability('mod/wavefront:edit', $context)) {
  23. if($confirm && confirm_sesskey()) {
  24. $DB->delete_records('gradeimporter_submission', array('id' => $comment->id));
  25. redirect($gradeimporterurl);
  26. } else {
  27. echo $OUTPUT->header();
  28. $paramyes = array('id' => $gradeimporter->id, 'delete' => $gradeimporter->id, 'sesskey' => sesskey(), 'confirm' => 1);
  29. $paramsno = array('id' => $cm->id);
  30. echo $OUTPUT->confirm(get_string('submissiondelete', 'gradeimporter'),
  31. new moodle_url('/mod/gradeimporter/submission.php', $paramsyes),
  32. new moodle_url('/mod/gradeimporter/view.php', $paramsno));
  33. echo $OUTPUT->footer();
  34. die();
  35. }
  36. }
  37. require_capability('mod/gradeimporter/addsubmission', $context);
  38. if(!$gradeimporter->submission) {
  39. print_error('Submissions disabled', $gradeimporterurl);
  40. }
  41. $mform = new mod_gradeimporter_submission_form(null, $gradeimporter);
  42. if ($mform-is_cancelled()) {
  43. redirect($gradeimporterurl);
  44. } else if ($formdata = $mform->get_data()) {
  45. $newsubmission = new stdClass;
  46. $newsubmission->gradeimporter = $gradeimporter->id;
  47. $newsubmission->type = $formdata->type;
  48. $newsubmission->timemodified = time();
  49. $newsubmission->usermodified = $USER->id;
  50. //$newsubmission->name = $formdata->name;
  51. //$newsubmission->info = $formdata->info;
  52. $newsubmission->position = $formdata->position;
  53. $newsubmission->visibility = $formdata->visibility;
  54. if ($DB->insert_record('gradeimporter_submission', $newsubmission)) {
  55. $params = array(
  56. 'context' => $context,
  57. 'other' => array(
  58. 'gradeimporterid' => $gradeimporter->id
  59. )
  60. );
  61. $event = \mod_gradeimporter\event\gradeimporter_submission_created::create($params);
  62. $event->trigger();
  63. redirect($gradeimporterurl, get_string('submission added', 'gradeimporter'));
  64. } else {
  65. print_error('gradeimporter creation failed');
  66. }
  67. }
  68. echo $OUTPUT->header();
  69. $mform->display();
  70. echo $OUTPUT->footer();