student_work.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. $current_course_tool = TOOL_STUDENTPUBLICATION;
  5. api_protect_course_script(true);
  6. api_protect_course_group(GroupManager::GROUP_TOOL_WORK);
  7. require_once 'work.lib.php';
  8. $this_section = SECTION_COURSES;
  9. $studentId = isset($_GET['studentId']) ? intval($_GET['studentId']) : null;
  10. if (empty($studentId)) {
  11. api_not_allowed(true);
  12. }
  13. $tool_name = get_lang('Assignments');
  14. $group_id = api_get_group_id();
  15. $userInfo = api_get_user_info($studentId);
  16. $courseInfo = api_get_course_info();
  17. if (empty($userInfo) || empty($courseInfo)) {
  18. api_not_allowed(true);
  19. }
  20. // Only a teachers page.
  21. if (!empty($group_id)) {
  22. $group_properties = GroupManager::get_group_properties($group_id);
  23. $interbreadcrumb[] = [
  24. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  25. 'name' => get_lang('Groups'),
  26. ];
  27. $interbreadcrumb[] = [
  28. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  29. 'name' => get_lang('Group area').' '.$group_properties['name'],
  30. ];
  31. } else {
  32. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  33. api_not_allowed(true);
  34. }
  35. }
  36. $action = isset($_GET['action']) ? $_GET['action'] : null;
  37. switch ($action) {
  38. case 'export_to_pdf':
  39. exportAllWork($studentId, $courseInfo, 'pdf');
  40. exit;
  41. break;
  42. case 'download':
  43. if (api_is_allowed_to_edit()) {
  44. downloadAllFilesPerUser($studentId, $courseInfo);
  45. }
  46. break;
  47. case 'delete_all':
  48. if (api_is_allowed_to_edit()) {
  49. $deletedItems = deleteAllWorkPerUser($studentId, $courseInfo);
  50. if (!empty($deletedItems)) {
  51. $message = get_lang('File deleted').'<br >';
  52. foreach ($deletedItems as $item) {
  53. $message .= $item['title'].'<br />';
  54. }
  55. $message = Display::return_message($message, 'info', false);
  56. Display::addFlash($message);
  57. }
  58. header('Location: '.api_get_self().'?studentId='.$studentId.'&'.api_get_cidreq());
  59. exit;
  60. }
  61. break;
  62. }
  63. $interbreadcrumb[] = [
  64. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  65. 'name' => get_lang('Assignments'),
  66. ];
  67. $interbreadcrumb[] = [
  68. 'url' => '#',
  69. 'name' => $userInfo['complete_name'],
  70. ];
  71. Display :: display_header(null);
  72. $workPerUser = getWorkPerUser($studentId);
  73. echo '<div class="actions">';
  74. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'">'.
  75. Display::return_icon('back.png', get_lang('Back to Assignments list'), '', ICON_SIZE_MEDIUM).'</a>';
  76. if (api_is_allowed_to_edit()) {
  77. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=export_to_pdf&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  78. Display::return_icon('pdf.png', get_lang('Export to PDF'), '', ICON_SIZE_MEDIUM).'</a>';
  79. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=download&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  80. Display::return_icon('save.png', get_lang('Download'), '', ICON_SIZE_MEDIUM).'</a>';
  81. echo '<a
  82. onclick="javascript:if(!confirm(\''.get_lang('Are you sure you want to delete').'\')) return false;"
  83. href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=delete_all&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  84. Display::return_icon('delete.png', get_lang('Delete all papers'), '', ICON_SIZE_MEDIUM).'</a>';
  85. }
  86. echo '</div>';
  87. $table = new HTML_Table(['class' => 'data_table']);
  88. $column = 0;
  89. $row = 0;
  90. $headers = [
  91. get_lang('Title'),
  92. get_lang('Time of reception'),
  93. get_lang('Deadline'),
  94. get_lang('Feedback'),
  95. get_lang('Detail'),
  96. ];
  97. foreach ($headers as $header) {
  98. $table->setHeaderContents($row, $column, $header);
  99. $column++;
  100. }
  101. $row++;
  102. $column = 0;
  103. $url = api_get_path(WEB_CODE_PATH).'work/';
  104. foreach ($workPerUser as $work) {
  105. $work = $work['work'];
  106. $scoreWeight = intval($work->qualification) == 0 ? null : $work->qualification;
  107. $workId = $work->id;
  108. $workExtraData = get_work_assignment_by_id($workId);
  109. foreach ($work->user_results as $userResult) {
  110. $itemId = $userResult['id'];
  111. $table->setCellContents($row, $column, $work->title.' ['.trim(strip_tags($userResult['title'])).']');
  112. $table->setCellAttributes($row, $column, ['width' => '300px']);
  113. $column++;
  114. $table->setCellContents($row, $column, $userResult['sent_date']);
  115. $column++;
  116. $dateQualification = !empty($workExtraData['expires_on']) ? api_get_local_time($workExtraData['expires_on']) : '-';
  117. $table->setCellContents($row, $column, $dateQualification);
  118. $column++;
  119. $score = null;
  120. $score = $userResult['qualification'];
  121. $table->setCellContents($row, $column, $score);
  122. $column++;
  123. // Detail
  124. $links = null;
  125. // is a text
  126. $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$itemId;
  127. $links .= Display::url(Display::return_icon('default.png', get_lang('View')), $url);
  128. if (!empty($userResult['url'])) {
  129. $url = api_get_path(WEB_CODE_PATH).'work/download.php?'.api_get_cidreq().'&id='.$itemId;
  130. $links .= Display::url(Display::return_icon('save.png', get_lang('Download')), $url);
  131. }
  132. if (api_is_allowed_to_edit()) {
  133. $url = api_get_path(WEB_CODE_PATH).'work/edit.php?'.api_get_cidreq().'&item_id='.$itemId.'&id='.$workId.'&parent_id='.$workId;
  134. $links .= Display::url(
  135. Display::return_icon('edit.png', get_lang('Comment')),
  136. $url
  137. );
  138. }
  139. $table->setCellContents($row, $column, $links);
  140. $row++;
  141. $column = 0;
  142. }
  143. }
  144. echo Display::page_subheader($userInfo['complete_name']);
  145. echo $table->toHtml();
  146. Display :: display_footer();