user_stats.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script.
  5. *
  6. * @package chamilo.gradebook
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. api_block_anonymous_users();
  10. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  11. api_get_user_id(),
  12. api_get_course_info()
  13. );
  14. if (!$isDrhOfCourse) {
  15. GradebookUtils::block_students();
  16. }
  17. $interbreadcrumb[] = [
  18. 'url' => Category::getUrl(),
  19. 'name' => get_lang('Gradebook'),
  20. ];
  21. $categoryId = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : 0;
  22. $evaluationId = isset($_GET['selecteval']) ? (int) $_GET['selecteval'] : 0;
  23. $category = Category::load($categoryId);
  24. $userId = Security::remove_XSS($_GET['userid']);
  25. $allevals = $category[0]->get_evaluations($userId, true);
  26. $alllinks = $category[0]->get_links($userId, true);
  27. if (!empty($categoryId)) {
  28. $addparams = [
  29. 'userid' => $userId,
  30. 'selectcat' => $categoryId,
  31. ];
  32. } else {
  33. $addparams = [
  34. 'userid' => $userId,
  35. 'selecteval' => $evaluationId,
  36. ];
  37. }
  38. $user_table = new UserTable($userId, $allevals, $alllinks, $addparams);
  39. if (isset($_GET['exportpdf'])) {
  40. $datagen = new UserDataGenerator($userId, $allevals, $alllinks);
  41. $data_array = $datagen->get_data(
  42. UserDataGenerator::UDG_SORT_NAME,
  43. 0,
  44. null,
  45. true
  46. );
  47. $newarray = [];
  48. $displayscore = ScoreDisplay :: instance();
  49. foreach ($data_array as $data) {
  50. $newarray[] = array_slice($data, 1);
  51. }
  52. $userInfo = api_get_user_info($userId);
  53. $html .= get_lang('Results').' : '.$userInfo['complete_name_with_username'].' ('.api_get_local_time().')';
  54. if ($displayscore->is_custom()) {
  55. $header_names = [
  56. get_lang('Evaluation'),
  57. get_lang('Course'),
  58. get_lang('Category'),
  59. get_lang('EvaluationAverage'),
  60. get_lang('Result'),
  61. get_lang('Display'),
  62. ];
  63. } else {
  64. $header_names = [
  65. get_lang('Evaluation'),
  66. get_lang('Course'),
  67. get_lang('Category'),
  68. get_lang('EvaluationAverage'),
  69. get_lang('Result'),
  70. ];
  71. }
  72. $table = new HTML_Table(['class' => 'data_table']);
  73. $row = 0;
  74. $column = 0;
  75. foreach ($header_names as $item) {
  76. $table->setHeaderContents($row, $column, $item);
  77. $column++;
  78. }
  79. $row = 1;
  80. if (!empty($newarray)) {
  81. foreach ($newarray as $data) {
  82. $column = 0;
  83. $table->setCellContents($row, $column, $data);
  84. $table->updateCellAttributes($row, $column, 'align="center"');
  85. $column++;
  86. $row++;
  87. }
  88. }
  89. $html .= $table->toHtml();
  90. $pdf = new PDF();
  91. $pdf->content_to_pdf($html);
  92. exit;
  93. }
  94. $actions = '<div class="actions">';
  95. if (!empty($categoryId)) {
  96. $interbreadcrumb[] = [
  97. 'url' => 'gradebook_flatview.php?selectcat='.$categoryId.'&'.api_get_cidreq(),
  98. 'name' => get_lang('FlatView'),
  99. ];
  100. $actions .= '<a href=gradebook_flatview.php?selectcat='.$categoryId.'&'.api_get_cidreq().'>'.
  101. Display::return_icon(
  102. 'back.png',
  103. get_lang('BackTo').' '.get_lang('FlatView'),
  104. '',
  105. ICON_SIZE_MEDIUM
  106. ).
  107. '</a>';
  108. }
  109. if (!empty($evaluationId)) {
  110. $interbreadcrumb[] = [
  111. 'url' => 'gradebook_view_result.php?selecteval='.$evaluationId.'&'.api_get_cidreq(),
  112. 'name' => get_lang('ViewResult'),
  113. ];
  114. $actions .= '<a href="gradebook_view_result.php?selecteval='.$evaluationId.'&'.api_get_cidreq().'">
  115. '.Display::return_icon('back.png', get_lang('BackToEvaluation'), '', ICON_SIZE_MEDIUM).'</a>';
  116. }
  117. $actions .= '<a href="'.api_get_self().'?exportpdf=&userid='.$userId.'&selectcat='.$category[0]->get_id().'&'.api_get_cidreq().'" target="_blank">
  118. '.Display::return_icon('pdf.png', get_lang('ExportPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  119. $actions .= '</div>';
  120. Display::display_header(get_lang('ResultsPerUser'));
  121. echo $actions;
  122. DisplayGradebook::display_header_user($_GET['userid'], $category[0]->get_id());
  123. $user_table->display();
  124. Display::display_footer();