submission.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. require_once('../../config.php');
  3. require_once('locallib.php');
  4. require_once('lib.php');
  5. require_once('submission_form.php');
  6. echo "pagina submission";
  7. $cmid = required_param('cmid', PARAM_INT); // Course Module ID
  8. $id = required_param('id' , PARAM_INT); //Gradeimporter id
  9. //$delete = optional_param('delete', 0, PARAM_INT);
  10. //$confirm = optional_param('confirm', 0, PARAM_INT);
  11. if (!$cm = get_coursemodule_from_id('gradeimporter', $cmid)){
  12. print_error('invalidcoursemodule');
  13. }
  14. if (!$course = $DB->get_record('course', array('id'=>$cm->course))){
  15. print_error('coursemisconf');
  16. }
  17. $context = context_module::instance($cm->id);
  18. require_capability('mod/gradeimporter:edit', $context);
  19. if (!$gradeimporter = $DB->get_record('gradeimporter', array('id'=>$cm->instance))){
  20. print_error('invalidid', 'gradeimporter');
  21. }
  22. $url = new moodle_url('/mod/gradeimporter/submission.php', array('cmid'=>$cm->id));
  23. if(!empty($id)){
  24. $url->param('id', $id);
  25. }
  26. $PAGE->set_url($url);
  27. require_login($course, false, $cm);
  28. //attempt to get the correct submission
  29. $submission = $DB->get_record('gradeimporter_submission', array('gradeimporterid'=>$gradeimporter->id));
  30. if($submission){
  31. if (isguestuser()){
  32. print_error('guestnoedit', 'gradeimporter', "$CFG->wwwroot/mod/gradeimporter/view.php?id=$cmid");
  33. }
  34. } else{
  35. $submission = new stdClass();
  36. $submission->id = null;
  37. }
  38. $maxfiles = 50;
  39. $maxbytes = $course->maxbytes;
  40. $descriptionoptions = array('trusttext'=>true, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes, 'context'=>$context, 'subdirs'=>file_area_contains_subdirs($context, 'mod_gradeimporter', 'submission', $submission->id));
  41. $submissionoptions = array('subdirs'=>false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
  42. $submission = file_prepare_standard_editor($submission, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'description', $submission->id);
  43. $submission = file_prepare_standard_filemanager($submission, 'submission', $submissionoptions, $context, 'mod_gradeimporter', 'submission', $submission->id);
  44. $submission->cmid = $cm->id;
  45. $mform = new mod_gradeimporter_submission_form(null, array('submission'=>$submission, 'cm'=>$cm, 'descriptionoptions'=>$descriptionoptions, 'submissionoptions'=>$submissionoptions));
  46. if ($mform->is_cancelled()){
  47. if ($id){
  48. redirect("view.php?id=$cm->id&mode=entry&hook=$id");
  49. } else {
  50. redirect("view.php?id=$cm->id");
  51. }
  52. } else if ($submission = $mform->get_data()){
  53. $timenow = time();
  54. if (empty($submission->id)) {
  55. $submission->gradeimporterid = $gradeimporter->id;
  56. $submission->userid = $USER->id;
  57. $submission->timecreated = $timenow;
  58. $isnewentry = true;
  59. } else {
  60. $isnewentry = false;
  61. }
  62. $submission->description = ''; //updated later
  63. $submission->descriptionformat = FORMAT_HTML; //updated later
  64. $submission->definitiontrust = 0;
  65. $submission->timemodified = $timenow;
  66. $submission->position = -1;
  67. if ($isnewentry) {
  68. //add new entry
  69. $submission->id = $DB->insert_record('gradeimporter_submission', $submission);
  70. } else {
  71. //update existing entry
  72. $DB->update_record('gradeimporter', $submission);
  73. }
  74. $submission = file_postupdate_standard_editor($submission, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'description', $submission->id);
  75. $submission = file_postupdate_standard_filemanager($submission, 'submission', $submissionoptions, $context, 'mod_gradeimporter', 'submission', $submission->id);
  76. gradeimporter_check_for_zips($context, $cm, $submission);
  77. //store updated values
  78. $DB->update_record('gradeimporter_submission', $submission);
  79. //refetch complete entry
  80. $submission = $DB->get_record('gradeimporter_submission', array('id'=>$submission->id));
  81. //trigger event and update completion (if entry was created)
  82. $eventparams = array(
  83. 'context'=>$context,
  84. 'objectid'=>$submission->id,
  85. );
  86. if ($isnewentry){
  87. //update completion state
  88. $completion = new completion_info($course);
  89. if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $gradeimporter->completionentries) {
  90. $completion->update_state($cm, COMPLETION_COMPLETE);
  91. }
  92. }
  93. redirect("view.php?id=$cm->id&edition=1");
  94. }
  95. if(!empty($id)) {
  96. $PAGE->navbar->add(get_string('edit'));
  97. }
  98. $PAGE->set_title($gradeimporter->name);
  99. $PAGE->set_heading($course->fullname);
  100. echo $OUTPUT->header();
  101. echo $OUTPUT->heading(format_string($gradeimporter->name), 2);
  102. if ($gradeimporter->intro){
  103. echo $OUTPUT->box(format_module_intro('gradeimporter', $gradeimporter, $cm->id), 'generalbox', 'intro');
  104. }
  105. $mform->display();
  106. echo $OUTPUT->footer();
  107. //codigo antigo
  108. /*if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $id))) {
  109. print_error('invalidgradeimproterdid', 'gradeimporter');
  110. }
  111. list($course, $cm) = get_course_and_cm_from_instance($gradeimporter, 'gradeimporter');
  112. if ($delete && ! $submission = $DB->get_record('gradeimporter_sumbmission', array('gradeimporterid' => $gradeimporter->id, 'id' => $delete))) {
  113. print_error('Invalid comment ID');
  114. }
  115. require_login($course, true, $cm);
  116. $PAGE->set_cm($cm);
  117. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $id));
  118. $PAGE->set_title($gradeimporter->name);
  119. $page->set_heading($course->shortname);
  120. $context = context_module::instance($cm->id);
  121. $gradeimporterurl = $CFG->wwwroot.'mod/gradeimporter/view.php?id='.$cm->id;
  122. if ($delete && has_capability('mod/wavefront:edit', $context)) {
  123. if($confirm && confirm_sesskey()) {
  124. $DB->delete_records('gradeimporter_submission', array('id' => $comment->id));
  125. redirect($gradeimporterurl);
  126. } else {
  127. echo $OUTPUT->header();
  128. $paramyes = array('id' => $gradeimporter->id, 'delete' => $gradeimporter->id, 'sesskey' => sesskey(), 'confirm' => 1);
  129. $paramsno = array('id' => $cm->id);
  130. echo $OUTPUT->confirm(get_string('submissiondelete', 'gradeimporter'),
  131. new moodle_url('/mod/gradeimporter/submission.php', $paramsyes),
  132. new moodle_url('/mod/gradeimporter/view.php', $paramsno));
  133. echo $OUTPUT->footer();
  134. die();
  135. }
  136. }
  137. require_capability('mod/gradeimporter/addsubmission', $context);
  138. if(!$gradeimporter->submission) {
  139. print_error('Submissions disabled', $gradeimporterurl);
  140. }
  141. $mform = new mod_gradeimporter_submission_form(null, $gradeimporter);
  142. if ($mform-is_cancelled()) {
  143. redirect($gradeimporterurl);
  144. } else if ($formdata = $mform->get_data()) {
  145. $newsubmission = new stdClass;
  146. $newsubmission->gradeimporter = $gradeimporter->id;
  147. $newsubmission->type = $formdata->type;
  148. $newsubmission->timemodified = time();
  149. $newsubmission->usermodified = $USER->id;
  150. //$newsubmission->name = $formdata->name;
  151. //$newsubmission->info = $formdata->info;
  152. $newsubmission->position = $formdata->position;
  153. $newsubmission->visibility = $formdata->visibility;
  154. if ($DB->insert_record('gradeimporter_submission', $newsubmission)) {
  155. $params = array($cmid = required_param('cmid', PARAM_INT); // Course Module ID
  156. 'context' => $context,
  157. 'other' => array(
  158. 'gradeimporterid' => $gradeimporter->id
  159. )
  160. );
  161. $event = \mod_gradeimporter\event\gradeimporter_submission_created::create($params);
  162. $event->trigger();
  163. redirect($gradeimporterurl, get_string('submission added', 'gradeimporter'));
  164. } else {
  165. print_error('gradeimporter creation failed');
  166. }
  167. }
  168. echo $OUTPUT->header();
  169. $mform->display();
  170. echo $OUTPUT->footer();*/