student_work.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. require_once __DIR__.'/../inc/global.inc.php';
  5. $current_course_tool = TOOL_STUDENTPUBLICATION;
  6. api_protect_course_script(true);
  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('StudentPublications');
  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. $show_work = false;
  24. if (api_is_allowed_to_edit(false, true)) {
  25. $show_work = true;
  26. } else {
  27. // you are not a teacher
  28. $show_work = GroupManager::user_has_access(
  29. api_get_user_id(),
  30. $group_properties['iid'],
  31. GroupManager::GROUP_TOOL_WORK
  32. );
  33. }
  34. if (!$show_work) {
  35. api_not_allowed();
  36. }
  37. $interbreadcrumb[] = array(
  38. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  39. 'name' => get_lang('Groups')
  40. );
  41. $interbreadcrumb[] = array(
  42. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  43. 'name' => get_lang('GroupSpace').' '.$group_properties['name']
  44. );
  45. } else {
  46. if (!(api_is_allowed_to_edit() || api_is_coach())) {
  47. api_not_allowed(true);
  48. }
  49. }
  50. $action = isset($_GET['action']) ? $_GET['action'] : null;
  51. switch ($action) {
  52. case 'export_to_pdf':
  53. exportAllWork($studentId, $courseInfo, 'pdf');
  54. exit;
  55. break;
  56. case 'download':
  57. if (api_is_allowed_to_edit()) {
  58. downloadAllFilesPerUser($studentId, $courseInfo);
  59. }
  60. break;
  61. case 'delete_all':
  62. if (api_is_allowed_to_edit()) {
  63. $deletedItems = deleteAllWorkPerUser($studentId, $courseInfo);
  64. if (!empty($deletedItems)) {
  65. $message = get_lang('DocDel').'<br >';
  66. foreach ($deletedItems as $item) {
  67. $message .= $item['title'].'<br />';
  68. }
  69. $message = Display::return_message($message, 'info', false);
  70. Display::addFlash($message);
  71. }
  72. header('Location: '.api_get_self().'?studentId='.$studentId.'&'.api_get_cidreq());
  73. exit;
  74. }
  75. break;
  76. }
  77. $interbreadcrumb[] = array(
  78. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  79. 'name' => get_lang('StudentPublications')
  80. );
  81. $interbreadcrumb[] = array(
  82. 'url' => '#',
  83. 'name' => $userInfo['complete_name']
  84. );
  85. Display :: display_header(null);
  86. $workPerUser = getWorkPerUser($studentId);
  87. echo '<div class="actions">';
  88. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'">'.
  89. Display::return_icon('back.png', get_lang('BackToWorksList'), '', ICON_SIZE_MEDIUM).'</a>';
  90. if (api_is_allowed_to_edit()) {
  91. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=export_to_pdf&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  92. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  93. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=download&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  94. Display::return_icon('save.png', get_lang('Download'), '', ICON_SIZE_MEDIUM).'</a>';
  95. echo '<a
  96. onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;"
  97. href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=delete_all&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  98. Display::return_icon('delete.png', get_lang('DeleteAllFiles'), '', ICON_SIZE_MEDIUM).'</a>';
  99. }
  100. echo '</div>';
  101. $table = new HTML_Table(array('class' => 'data_table'));
  102. $column = 0;
  103. $row = 0;
  104. $headers = array(
  105. get_lang('Title'),
  106. get_lang('HandedOutDate'),
  107. get_lang('HandOutDateLimit'),
  108. get_lang('Feedback'),
  109. get_lang('Actions')
  110. );
  111. foreach ($headers as $header) {
  112. $table->setHeaderContents($row, $column, $header);
  113. $column++;
  114. }
  115. $row++;
  116. $column = 0;
  117. $url = api_get_path(WEB_CODE_PATH).'work/';
  118. foreach ($workPerUser as $work) {
  119. $work = $work['work'];
  120. $scoreWeight = intval($work->qualification) == 0 ? null : $work->qualification;
  121. $workId = $work->id;
  122. $workExtraData = get_work_assignment_by_id($workId);
  123. foreach ($work->user_results as $userResult) {
  124. $itemId = $userResult['id'];
  125. $table->setCellContents($row, $column, $work->title.' ['.trim(strip_tags($userResult['title'])).']');
  126. $table->setCellAttributes($row, $column, array('width' => '300px'));
  127. $column++;
  128. $table->setCellContents($row, $column, $userResult['sent_date']);
  129. $column++;
  130. $dateQualification = !empty($workExtraData['expires_on']) ? api_get_local_time($workExtraData['expires_on']) : '-';
  131. $table->setCellContents($row, $column, $dateQualification);
  132. $column++;
  133. $score = null;
  134. $score = $userResult['qualification'];
  135. $table->setCellContents($row, $column, $score);
  136. $column++;
  137. // Actions
  138. $links = null;
  139. // is a text
  140. $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$itemId;
  141. $links .= Display::url(Display::return_icon('default.png', get_lang('View')), $url);
  142. if (!empty($userResult['url'])) {
  143. $url = api_get_path(WEB_CODE_PATH).'work/download.php?'.api_get_cidreq().'&id='.$itemId;
  144. $links .= Display::url(Display::return_icon('save.png', get_lang('Download')), $url);
  145. }
  146. if (api_is_allowed_to_edit()) {
  147. $url = api_get_path(WEB_CODE_PATH).'work/edit.php?'.api_get_cidreq().'&item_id='.$itemId.'&id='.$workId.'&parent_id='.$workId;
  148. $links .= Display::url(
  149. Display::return_icon('edit.png', get_lang('Comment')),
  150. $url
  151. );
  152. }
  153. $table->setCellContents($row, $column, $links);
  154. $row++;
  155. $column = 0;
  156. }
  157. }
  158. echo Display::page_subheader($userInfo['complete_name']);
  159. echo $table->toHtml();
  160. Display :: display_footer();