view.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // This file is part of LInE contributions to Free Education, Private Data
  3. // LInE (Laboratory of Informatics in Education)
  4. // www.usp.br/line
  5. //
  6. // Moodle is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // Moodle is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  18. require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
  19. require_once(dirname(__FILE__).'/lib.php');
  20. require_once($CFG->libdir.'/filelib.php');
  21. require_once('locallib.php');
  22. require_once('libs/student_viewlib.php');
  23. require_once('libs/teacher_viewlib.php');
  24. global $DB;
  25. $id = optional_param('id', 0, PARAM_INT); // Course_module ID.
  26. $g = optional_param('g', 0, PARAM_INT); // Gradeimporter instance ID, should be named as the first character of the module.
  27. $action = optional_param('action', 0, PARAM_INT);
  28. $fileid = optional_param('fileid', 0, PARAM_INT);
  29. $filename = optional_param('filename', 'a', PARAM_TEXT);
  30. if ($id) {
  31. if (! $cm = get_coursemodule_from_id('gradeimporter', $id)) {
  32. error('Course Module ID was incorrect');
  33. }
  34. if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
  35. error('Course is misconfigured');
  36. }
  37. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id' => $cm->instance))) {
  38. error('Course module is incorrect');
  39. }
  40. } else if ($g) {
  41. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id' => $g))) {
  42. error('Course module is incorrect');
  43. }
  44. if (! $course = $DB->get_record('course', array('id' => $gradeimporter->course))) {
  45. error('Course is misconfigured');
  46. }
  47. if (! $cm = get_coursemodule_from_instance('gradeimporter', $gradeimporter->id, $course->id)) {
  48. error('Course Module ID was incorrect');
  49. }
  50. } else {
  51. error('You must specify a course_module ID or an instance ID');
  52. }
  53. require_login($course, true, $cm);
  54. $context = context_module::instance($cm->id);
  55. if ($action == 1 && has_capability('mod/gradeimporter:view', $context)) {
  56. // Download feedback file.
  57. $fs = get_file_storage();
  58. $file = $fs->get_file($context->id, 'mod_gradeimporter', 'gradeimporter_feedback', $fileid, '/', $filename);
  59. if ($file) {
  60. send_stored_file($file, 86400, 0, true);
  61. }
  62. } else if ($action == 2 && has_capability('mod/gradeimporter:edit', $context)) {
  63. // Download students csv with their id.
  64. exportCSV($context);
  65. }
  66. // Print the page header.
  67. $PAGE->set_cm($cm);
  68. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $cm->id));
  69. $PAGE->set_title(format_string($gradeimporter->name));
  70. $PAGE->set_heading(format_string($course->fullname));
  71. $PAGE->set_context($context);
  72. $output = $PAGE->get_renderer('mod_folder');
  73. print $output->header();
  74. $heading = get_string('displayingview', 'gradeimporter', $gradeimporter->name);
  75. print $output->heading($heading);
  76. // Button to add new submission.
  77. if (has_capability('mod/gradeimporter:edit', $context)) {
  78. $url = new moodle_url('/mod/gradeimporter/forms/submission/submission.php');
  79. $newbutton = '<form action="'. $url . '">' . "\n" .
  80. '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />' . "\n" .
  81. '<input type="hidden" name="cmid" value="'.$cm->id.'" />' . "\n" .
  82. '<input type="submit" Value="'.get_string('newsubmission', 'gradeimporter').'" />' . "\n" .
  83. '</form>' . "\n";
  84. print $newbutton;
  85. $url = new moodle_url("/mod/gradeimporter/view.php", array('id' => $id, 'cmid' => $cm->id, 'action' => 2));
  86. $newbutton = '<form action="'. $url . '">'. "\n" .
  87. '<input type="hidden" name="id" value="'. $id .'" />' . "\n" .
  88. '<input type="hidden" name="cmid" value="'.$cm->id.'" />' . "\n" .
  89. '<input type="hidden" name="action" value="2" />' . "\n" .
  90. '<input type="submit" Value="' . get_string('downloadconfigcsv', 'gradeimporter') . '" />' . "\n" .
  91. '</form>' . "\n";
  92. print $newbutton;
  93. }
  94. // Tabela com as notas vem aqui.
  95. require_once($CFG->libdir . '/tablelib.php');
  96. require_once(dirname(__FILE__).'/locallib.php');
  97. if (has_capability('mod/gradeimporter:edit', $context)) {
  98. // Loads teacher view.
  99. // get_teacher_view($cm->id, $gradeimporter->id);
  100. $teacherview = new Teacherview($cm->id, $gradeimporter->id);
  101. $teachertable = $teacherview->make_table();
  102. print $teachertable;
  103. }
  104. else {
  105. // Load student view
  106. // Query database to find student feedbacks
  107. $feedbacks = query_feedbacks($cm->id, $gradeimporter->id);
  108. make_feedback_table($feedbacks, $cm->id);
  109. }
  110. // Finishes the page!
  111. print $output->footer();