submissiontype.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. require_once('../../config.php');
  3. require_once('locallib.php');
  4. require_once('lib.php');
  5. require_once('submissiontype_form.php');
  6. $cmid = required_param('cmid', PARAM_INT); // Course Module ID
  7. $id = required_param('id' , PARAM_INT); //Gradeimporter id
  8. if (!$cm = get_coursemodule_from_id('gradeimporter', $cmid)){
  9. print_error('invalidcoursemodule');
  10. }
  11. if (!$course = $DB->get_record('course', array('id'=>$cm->course))){
  12. print_error('coursemisconf');
  13. }
  14. $context = context_module::instance($cm->id);
  15. require_capability('mod/gradeimporter:edit', $context);
  16. if (!$gradeimporter = $DB->get_record('gradeimporter', array('id'=>$cm->instance))){
  17. print_error('invalidid', 'gradeimporter');
  18. }
  19. $url = new moodle_url('/mod/gradeimporter/submissiontype.php', array('cmid'=>$cm->id));
  20. if (!empty($id)){
  21. $url->param('id', $id);
  22. }
  23. $PAGE->set_url($url);
  24. require_login($course, false, $cm);
  25. //attempt to get the correct type
  26. $submissiontype = $DB->get_record('gradeimporter_submissiontype', array('gradeimporterid'=>$gradeimporter->id));
  27. if ($submissiontype){
  28. if (isguestuser()){
  29. print_error('guestnoedit', 'gradeimporter', "$CFG->wwwroot/mod/gradeimporter/view.php?id=$cmid");
  30. }
  31. } else {
  32. $submissiontype = new stdClass();
  33. $submissiontype->id = null;
  34. }
  35. $maxfiles = 50;
  36. $maxbytes = $course->maxbytes;
  37. $descriptionoptions = array('trusttext'=>true, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes, 'context'=>$context, 'subdirs'=>file_area_contains_subdirs($context, 'mod_gradeimporter', 'submissiontype', $submissiontype->id));
  38. $submissiontypeoptions = array('subdirs'=>false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
  39. $submissiontype = file_prepare_standard_editor($submissiontype, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'description', $submissiontype->id);
  40. $submissiontype->cmid = $cm->id;
  41. $mform = new mod_gradeimporter_submissiontype_form(null, array('submissiontype' =>$submissiontype, 'cm'=>$cm, 'descriptionoptions'=>$descriptionoptions, 'submissiontypeoptions'=>$submissiontypeoptions));;
  42. if ($mform->is_cancelled()){
  43. if ($id){
  44. redirect("view.php?id=$cm->id&mode=entry&hook=$id");
  45. } else{
  46. redirect("view.php?id=$cm->id");
  47. }
  48. } else if ($submissiontype = $mform->get_data()){
  49. if (empty($submissiontype->id)){
  50. $submissiontype->gradeimporterid = $gradeimporter->id;
  51. $isnewentry = true;
  52. } else{
  53. $isnewentry = false;
  54. }
  55. $submissiontype->description ='';
  56. $submissiontype->descriptionformat = FORMAT_HTML;
  57. $submissiontype->definitiontrust = 0;
  58. if ($isnewentry){
  59. $submissiontype->id = $DB->insert_record('gradeimporter_submissiontype', $submissiontype);
  60. } else{
  61. $DB->update_record('gradeimporter', $submissiontype);
  62. }
  63. $submissiontype = file_postupdate_standard_editor($submissiontype, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'submissiontype', $submissiontype->id);
  64. $DB->update_record('gradeimporter_submissiontype', $submissiontype);
  65. if ($isnewentry){
  66. //update completion state
  67. $completion = new completion_info($course);
  68. if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $gradeimporter->completionentries) {
  69. $completion->update_state($cm, COMPLETION_COMPLETE);
  70. }
  71. }
  72. redirect("submission.php?id=$id&cmid=$cm->id&page=0");
  73. }
  74. if (!empty($id)){
  75. $PAGE->navbar->add(get_string('edit'));
  76. }
  77. $PAGE->set_title($gradeimporter->name);
  78. $PAGE->set_heading($course->fullname);
  79. echo $OUTPUT->header();
  80. echo $OUTPUT->heading(format_string($gradeimporter->name), 2);
  81. if($gradeimporter->intro){
  82. echo $OUTPUT->box(format_module_intro('gradeimporter', $gradeimporter, $cm->id), 'generalbox', 'intro');
  83. }
  84. $mform->display();
  85. echo $OUTPUT->footer();