view.php 5.3 KB

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