view.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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(dirname(dirname(dirname(__FILE__))).'/config.php');
  17. require_once(dirname(__FILE__).'/lib.php');
  18. require_once($CFG->libdir.'/filelib.php');
  19. require_once('locallib.php');
  20. require_once('libs/viewlib.php');
  21. global $DB;
  22. $id = optional_param('id', 0, PARAM_INT); // Course_module ID.
  23. $g = optional_param('g', 0, PARAM_INT); // Gradeimporter instance ID, should be named as the first character of the module.
  24. $action = optional_param('action', 0, PARAM_INT);
  25. $fileid = optional_param('fileid', 0, PARAM_INT);
  26. $filename = optional_param('filename', 'a', PARAM_TEXT);
  27. if ($id) {
  28. if (! $cm = get_coursemodule_from_id('gradeimporter', $id)) {
  29. error('Course Module ID was incorrect');
  30. }
  31. if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
  32. error('Course is misconfigured');
  33. }
  34. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id' => $cm->instance))) {
  35. error('Course module is incorrect');
  36. }
  37. } else if ($g) {
  38. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id' => $g))) {
  39. error('Course module is incorrect');
  40. }
  41. if (! $course = $DB->get_record('course', array('id' => $gradeimporter->course))) {
  42. error('Course is misconfigured');
  43. }
  44. if (! $cm = get_coursemodule_from_instance('gradeimporter', $gradeimporter->id, $course->id)) {
  45. error('Course Module ID was incorrect');
  46. }
  47. } else {
  48. error('You must specify a course_module ID or an instance ID');
  49. }
  50. require_login($course, true, $cm);
  51. $context = context_module::instance($cm->id);
  52. if ($action == 1 && has_capability('mod/gradeimporter:view', $context)) {
  53. // Download feedback file.
  54. $fs = get_file_storage();
  55. $file = $fs->get_file($context->id, 'mod_gradeimporter', 'gradeimporter_feedback', $fileid, '/', $filename);
  56. if ($file) {
  57. send_stored_file($file, 86400, 0, true);
  58. }
  59. } else if ($action == 2 && has_capability('mod/gradeimporter:edit', $context)) {
  60. // Download students csv with their id.
  61. exportCSV($context);
  62. }
  63. // Print the page header.
  64. $PAGE->set_cm($cm);
  65. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $cm->id));
  66. $PAGE->set_title(format_string($gradeimporter->name));
  67. $PAGE->set_heading(format_string($course->fullname));
  68. $PAGE->set_context($context);
  69. $output = $PAGE->get_renderer('mod_folder');
  70. echo $output->header();
  71. $heading = get_string('displayingview', 'gradeimporter', $gradeimporter->name);
  72. echo $output->heading($heading);
  73. // Button to add new submission.
  74. if (has_capability('mod/gradeimporter:edit', $context)) {
  75. $url = new moodle_url('/mod/gradeimporter/submission.php');
  76. $newbutton = '<form action="'. $url . '">'.
  77. '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
  78. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  79. '<input type="submit" Value="'.get_string('newsubmission', 'gradeimporter').'" />'.
  80. '</form>';
  81. echo $newbutton;
  82. $url = new moodle_url("/mod/gradeimporter/view.php", array('id' => $id, 'cmid' => $cm->id, 'action' => 2));
  83. $newbutton = '<form action="'. $url . '">'.
  84. '<input type="hidden" name="id" value="'. $id .'" />'.
  85. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  86. '<input type="hidden" name="action" value="2" />'.
  87. '<input type="submit" Value="'.get_string('downloadconfigcsv', 'gradeimporter').'" />'.
  88. '</form>';
  89. echo $newbutton;
  90. }
  91. // Tabela com as notas vem aqui.
  92. require_once($CFG->libdir . '/tablelib.php');
  93. require_once(dirname(__FILE__).'/locallib.php');
  94. if (has_capability('mod/gradeimporter:edit', $context)) {
  95. // Loads teacher view.
  96. $enrolledusers = get_enrolled_users($context, 'mod/gradeimporter:view', 0, 'u.id, u.firstname, u.lastname', 'u.firstname, u.lastname');
  97. get_teacher_view($cm->id, $gradeimporter->id, $enrolledusers);
  98. } else {
  99. // Load student view
  100. // Query database to find student feedbacks
  101. $feedbacks = query_feedbacks($cm->id, $gradeimporter->id);
  102. make_feedback_table($feedbacks);
  103. }
  104. // Finishes the page!
  105. echo $output->footer();