view.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
  3. require_once(dirname(__FILE__).'/lib.php');
  4. require_once($CFG->libdir.'/filelib.php');
  5. require_once('locallib.php');
  6. global $DB;
  7. $id = optional_param('id', 0, PARAM_INT); // course_module ID, or
  8. $g = optional_param('g', 0, PARAM_INT); // gradeimporter instance ID, should be named as the first character of the module
  9. $action = optional_param('action', 0, PARAM_INT);
  10. //$cmid = optional_param('cmid', 0, PARAM_INT);
  11. $id = optional_param('id', 0, PARAM_INT);
  12. $fileid = optional_param('fileid', 0, PARAM_INT);
  13. $filename = optional_param('filename', 'a', PARAM_TEXT);
  14. if ($id) {
  15. if (! $cm = get_coursemodule_from_id('gradeimporter', $id)) {
  16. error('Course Module ID was incorrect');
  17. }
  18. if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
  19. error('Course is misconfigured');
  20. }
  21. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id'=> $cm->instance) ) ) {
  22. error('Course module is incorrect');
  23. }
  24. } else if ($g) {
  25. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id'=> $g)) ){
  26. error('Course module is incorrect');
  27. }
  28. if (! $course = $DB->get_record('course', array('id'=> $gradeimporter->course)) ) {
  29. error('Course is misconfigured');
  30. }
  31. if (! $cm = get_coursemodule_from_instance('gradeimporter', $gradeimporter->id, $course->id)) {
  32. error('Course Module ID was incorrect');
  33. }
  34. } else {
  35. error('You must specify a course_module ID or an instance ID');
  36. }
  37. require_login($course, true, $cm);
  38. $context = context_module::instance($cm->id);
  39. if ($action==1 && has_capability('mod/gradeimporter:view', $context)){
  40. //download feedback file
  41. $fs = get_file_storage();
  42. $file = $fs->get_file($context->id, 'mod_gradeimporter', 'gradeimporter_feedback', $fileid, '/', $filename);
  43. if ($file){
  44. send_stored_file($file, 86400, 0, true);
  45. }
  46. } else if ($action == 2 && has_capability('mod/gradeimporter:edit', $context)){
  47. //download students csv with their id
  48. exportCSV($context);
  49. }
  50. /// Print the page header
  51. $PAGE->set_cm($cm);
  52. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $cm->id));
  53. $PAGE->set_title(format_string($gradeimporter->name));
  54. $PAGE->set_heading(format_string($course->fullname));
  55. $PAGE->set_context($context);
  56. $output = $PAGE->get_renderer('mod_folder');
  57. echo $output->header();
  58. $heading = get_string('displayingview', 'gradeimporter', $gradeimporter->name);
  59. echo $output->heading($heading);
  60. //button to add new submission
  61. if (has_capability('mod/gradeimporter:edit', $context)) {
  62. $url = new moodle_url('/mod/gradeimporter/submission.php');
  63. $newbutton = '<form action="'. $url . '">'.
  64. '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
  65. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  66. '<input type="hidden" name="page" value="0" />'.
  67. '<input type="submit" Value="'.get_string('newsubmission', 'gradeimporter').'" />'.
  68. '</form>';
  69. echo $newbutton;
  70. $url = new moodle_url("/mod/gradeimporter/view.php", array('id'=>$id, 'cmid'=>$cm->id, 'action'=>2));
  71. $newbutton = '<form action="'. $url . '">'.
  72. '<input type="hidden" name="id" value="'. $id .'" />'.
  73. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  74. '<input type="hidden" name="action" value="2" />'.
  75. '<input type="submit" Value="'.get_string('downloadconfigcsv', 'gradeimporter').'" />'.
  76. '</form>';
  77. echo $newbutton;
  78. }
  79. //tabela com as notas vem aqui
  80. require_once($CFG->libdir . '/tablelib.php');
  81. require_once(dirname(__FILE__).'/locallib.php');
  82. if (has_capability('mod/gradeimporter:edit', $context)){
  83. //loads teacher view
  84. $enrolledusers = get_enrolled_users ($context, 'mod/gradeimporter:view');
  85. get_teacher_view($cm->id, $gradeimporter->id, $enrolledusers);
  86. } else {
  87. $data = get_comments($cm->id, $id);
  88. //loads student view
  89. $table = new html_table();
  90. $table->attributes['class'] = 'generaltable mod_index';
  91. $table->head = array (get_string('type', 'gradeimporter'), get_string('submission', 'gradeimporter'), get_string('grade', 'gradeimporter'), get_string('comment', 'gradeimporter'), get_string('file', 'gradeimporter'));
  92. $table->align = array ('center', 'center', 'center', 'center', 'center');
  93. if (count($data)) {
  94. $current = "";
  95. foreach ($data as $tipo => $cells) {
  96. if ($current != "" && $current != $tipo) {
  97. $row = new html_table_row();
  98. $cell = new html_table_cell();
  99. $cell->colspan = 5;
  100. $row->cells[] = $cell;
  101. $table->data[] = $row;
  102. }
  103. $current = $tipo;
  104. $row = new html_table_row();
  105. $cell = new html_table_cell($tipo);
  106. $cell->rowspan = count($cells)+1;
  107. $row->cells[] = $cell;
  108. $table->data[] = $row;
  109. foreach ($cells as $cell) {
  110. $row = new html_table_row();
  111. foreach ($cell as $value) {
  112. $cell = new html_table_cell($value);
  113. $row->cells[] = $cell;
  114. }
  115. $table->data[] = $row;
  116. }
  117. }
  118. }
  119. echo html_writer::table($table);
  120. }
  121. /// Finish the page
  122. echo $output->footer();