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. $model = $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. $model->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 //n sei oq faz
  65. $submission->timemodified = $timenow;
  66. if ($isnewentry) {
  67. //add new entry
  68. $submission->id = $DB->insert_record('gradeimporter_submission', $submission);
  69. } else {
  70. //update existing entry
  71. $DB->update_record('gradeimporter', $submission);
  72. }
  73. $submission = file_postupdate_standard_editor($model, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'description', $submission->id);
  74. $submission = file_postupdate_standard_filemanager($submission, 'submission', $submissionoptions, $context, 'mod_gradeimporter', 'submission', $submission->id);
  75. gradeimporter_check_for_zips($context, $cm, $submission);
  76. //store updated values
  77. $DB->update_record('gradeimporter_submission', $submission);
  78. //refetch complete entry
  79. $submission = $DB->get_record('gradeimporter_submission', array('id'=>$submission->id));
  80. //trigger event and update completion (if entry was created)
  81. $eventparams = array(
  82. 'context'=>context,
  83. 'objectid'=>$submission->id,
  84. );
  85. if ($isnewentry){
  86. //update completion state
  87. $completion = new completion_info($course);
  88. if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $gradeimporter->completionentries) {
  89. $completion->update_state($cm, COMPLETION_COMPLETE);
  90. }
  91. }
  92. redirect("view.php?id=$cm->id&edition=1");
  93. }
  94. if(!empty($id)) {
  95. $PAGE->navbar->add(get_string('edit'));
  96. }
  97. $PAGE->set_title($gradeimporter->name);
  98. $PAGE->set_heading($course->fullname);
  99. echo $OUTPUT->header();
  100. echo $OUTPUT->heading(format_string($gradeimporter->name), 2);
  101. if ($gradeimporter->intro){
  102. echo $OUTPUT->box(format_module_intro('gradeimporter', $gradeimporter, $cm->id), 'generalbox', 'intro');
  103. }
  104. $mform->display();
  105. echo $OUTPUT->footer();
  106. //codigo antigo
  107. /*if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $id))) {
  108. print_error('invalidgradeimproterdid', 'gradeimporter');
  109. }
  110. list($course, $cm) = get_course_and_cm_from_instance($gradeimporter, 'gradeimporter');
  111. if ($delete && ! $submission = $DB->get_record('gradeimporter_sumbmission', array('gradeimporterid' => $gradeimporter->id, 'id' => $delete))) {
  112. print_error('Invalid comment ID');
  113. }
  114. require_login($course, true, $cm);
  115. $PAGE->set_cm($cm);
  116. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $id));
  117. $PAGE->set_title($gradeimporter->name);
  118. $page->set_heading($course->shortname);
  119. $context = context_module::instance($cm->id);
  120. $gradeimporterurl = $CFG->wwwroot.'mod/gradeimporter/view.php?id='.$cm->id;
  121. if ($delete && has_capability('mod/wavefront:edit', $context)) {
  122. if($confirm && confirm_sesskey()) {
  123. $DB->delete_records('gradeimporter_submission', array('id' => $comment->id));
  124. redirect($gradeimporterurl);
  125. } else {
  126. echo $OUTPUT->header();
  127. $paramyes = array('id' => $gradeimporter->id, 'delete' => $gradeimporter->id, 'sesskey' => sesskey(), 'confirm' => 1);
  128. $paramsno = array('id' => $cm->id);
  129. echo $OUTPUT->confirm(get_string('submissiondelete', 'gradeimporter'),
  130. new moodle_url('/mod/gradeimporter/submission.php', $paramsyes),
  131. new moodle_url('/mod/gradeimporter/view.php', $paramsno));
  132. echo $OUTPUT->footer();
  133. die();
  134. }
  135. }
  136. require_capability('mod/gradeimporter/addsubmission', $context);
  137. if(!$gradeimporter->submission) {
  138. print_error('Submissions disabled', $gradeimporterurl);
  139. }
  140. $mform = new mod_gradeimporter_submission_form(null, $gradeimporter);
  141. if ($mform-is_cancelled()) {
  142. redirect($gradeimporterurl);
  143. } else if ($formdata = $mform->get_data()) {
  144. $newsubmission = new stdClass;
  145. $newsubmission->gradeimporter = $gradeimporter->id;
  146. $newsubmission->type = $formdata->type;
  147. $newsubmission->timemodified = time();
  148. $newsubmission->usermodified = $USER->id;
  149. //$newsubmission->name = $formdata->name;
  150. //$newsubmission->info = $formdata->info;
  151. $newsubmission->position = $formdata->position;
  152. $newsubmission->visibility = $formdata->visibility;
  153. if ($DB->insert_record('gradeimporter_submission', $newsubmission)) {
  154. $params = array($cmid = required_param('cmid', PARAM_INT); // Course Module ID
  155. 'context' => $context,
  156. 'other' => array(
  157. 'gradeimporterid' => $gradeimporter->id
  158. )
  159. );
  160. $event = \mod_gradeimporter\event\gradeimporter_submission_created::create($params);
  161. $event->trigger();
  162. redirect($gradeimporterurl, get_string('submission added', 'gradeimporter'));
  163. } else {
  164. print_error('gradeimporter creation failed');
  165. }
  166. }
  167. echo $OUTPUT->header();
  168. $mform->display();
  169. echo $OUTPUT->footer();*/