view.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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:edit', $context)){
  40. //download feedback file
  41. $fs = get_file_storage();
  42. echo 'file storage';
  43. $file = $fs->get_file($context->id, 'mod_gradeimporter', 'gradeimporter_feedback', $fileid, '/', $filename);
  44. if ($file){
  45. echo 'found file';
  46. send_stored_file($file, 86400, 0, true);
  47. }
  48. } else if ($action == 2 && has_capability('mod/gradeimporter:edit', $context)){
  49. exportCSV($context);
  50. }
  51. /// Print the page header
  52. $PAGE->set_cm($cm);
  53. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $cm->id));
  54. $PAGE->set_title(format_string($gradeimporter->name));
  55. $PAGE->set_heading(format_string($course->fullname));
  56. $PAGE->set_context($context);
  57. /*$button = '';
  58. if (has_capability('mod/gradeimporter:edit', $context)) {
  59. $urlparams = array('id'=>$id, 'page'=>$page, 'editing'=>$editing ? '0' : '1');
  60. $url = new moodle_url('/mod/gradeimporter/view.php', $urlparams);
  61. $strediting = get_string('turnediting'.($editing ? 'off' : 'on'));
  62. $button = $OUTPUT->single_button($url, $strediting, 'get'). ' ';
  63. }
  64. $PAGE->set_button($button);*/
  65. /// Print the main part of the page
  66. $output = $PAGE->get_renderer('mod_folder');
  67. echo $output->header();
  68. $heading = get_string('displayingview', 'gradeimporter', $gradeimporter->name);
  69. echo $output->heading($heading);
  70. //button to add new submission
  71. if (has_capability('mod/gradeimporter:edit', $context)) {
  72. $url = new moodle_url('/mod/gradeimporter/submission.php');
  73. $newbutton = '<form action="'. $url . '">'.
  74. '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
  75. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  76. '<input type="hidden" name="page" value="0" />'.
  77. '<input type="submit" Value="'.get_string('newsubmission', 'gradeimporter').'" />'.
  78. '</form>';
  79. echo $newbutton;
  80. $url = new moodle_url("/mod/gradeimporter/view.php", array('id'=>$id, 'cmid'=>$cm->id, 'action'=>2));
  81. $newbutton = '<form action="'. $url . '">'.
  82. '<input type="hidden" name="id" value="'. $id .'" />'.
  83. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  84. '<input type="hidden" name="action" value="2" />'.
  85. '<input type="submit" Value="'.get_string('downloadconfigcsv', 'gradeimporter').'" />'.
  86. '</form>';
  87. echo $newbutton;
  88. }
  89. //tabela com as notas vem aqui
  90. require_once($CFG->libdir . '/tablelib.php');
  91. require_once(dirname(__FILE__).'/locallib.php');
  92. use \gradeimporter\feedback;
  93. // $data = array();
  94. // $data["Prova"] = array();
  95. // $data["Prova"][] = array("P1", "7", "fulanoP1.pdf");
  96. // $data["Prova"][] = array("P2", "7", "fulanoP2.pdf");
  97. // $data["Prova"][] = array("P3", "7", "fulanoP3.pdf");
  98. // $data["Exercicio"][] = array("E1", "-", "fulanoE1.pdf.pdf");
  99. // $data["Exercicio"][] = array("E2", "-", "fulanoE2.pdf.pdf");
  100. // $data["teste"][] = array("E1", "-", "fulanoE1.pdf.pdf");
  101. // $data["teste"][] = array("E2", "-", "fulanoE2.pdf.pdf");
  102. $data = feedback::get_comments($cm->id, $id);
  103. $table = new html_table();
  104. $table->attributes['class'] = 'generaltable mod_index';
  105. $table->head = array ("Tipo", "Nome", "Nota", "Arquivos");
  106. $table->align = array ('center', 'center', 'center', 'center');
  107. if (count($data)) {
  108. $current = "";
  109. foreach ($data as $tipo => $cells) {
  110. if ($current != "" && $current != $tipo) {
  111. $row = new html_table_row();
  112. $cell = new html_table_cell();
  113. $cell->colspan = 5;
  114. $row->cells[] = $cell;
  115. $table->data[] = $row;
  116. }
  117. $current = $tipo;
  118. $row = new html_table_row();
  119. $cell = new html_table_cell($tipo);
  120. $cell->rowspan = count($cells)+1;
  121. $row->cells[] = $cell;
  122. $table->data[] = $row;
  123. foreach ($cells as $cell) {
  124. $row = new html_table_row();
  125. foreach ($cell as $value) {
  126. $cell = new html_table_cell($value);
  127. $row->cells[] = $cell;
  128. }
  129. $table->data[] = $row;
  130. }
  131. }
  132. }
  133. echo html_writer::table($table);
  134. /// Finish the page
  135. echo $output->footer();