student_work.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. require_once '../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_id,
  31. GroupManager::GROUP_TOOL_WORK
  32. );
  33. }
  34. if (!$show_work) {
  35. api_not_allowed();
  36. }
  37. $interbreadcrumb[] = array(
  38. 'url' => '../group/group.php',
  39. 'name' => get_lang('Groups')
  40. );
  41. $interbreadcrumb[] = array(
  42. 'url' => '../group/group_space.php?gidReq='.$group_id,
  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. Session::write('message', $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 Session::read('message');
  88. Session::erase('message');
  89. echo '<div class="actions">';
  90. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'">'.
  91. Display::return_icon('back.png', get_lang('BackToWorksList'), '', ICON_SIZE_MEDIUM).'</a>';
  92. if (api_is_allowed_to_edit()) {
  93. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=export_to_pdf&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  94. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  95. echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=download&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  96. Display::return_icon('save.png', get_lang('Download'), '', ICON_SIZE_MEDIUM).'</a>';
  97. echo '<a
  98. onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;"
  99. href="'.api_get_path(WEB_CODE_PATH).'work/student_work.php?action=delete_all&studentId='.$studentId.'&'.api_get_cidreq().'">'.
  100. Display::return_icon('delete.png', get_lang('DeleteAllFiles'), '', ICON_SIZE_MEDIUM).'</a>';
  101. }
  102. echo '</div>';
  103. $table = new HTML_Table(array('class' => 'data_table'));
  104. $column = 0;
  105. $row = 0;
  106. $headers = array(
  107. get_lang('Title'),
  108. get_lang('HandedOutDate'),
  109. get_lang('HandOutDateLimit'),
  110. get_lang('Feedback'),
  111. get_lang('Actions')
  112. );
  113. foreach ($headers as $header) {
  114. $table->setHeaderContents($row, $column, $header);
  115. $column++;
  116. }
  117. $row++;
  118. $column = 0;
  119. $url = api_get_path(WEB_CODE_PATH).'work/';
  120. foreach ($workPerUser as $work) {
  121. $work = $work['work'];
  122. $scoreWeight = intval($work->qualification) == 0 ? null : $work->qualification;
  123. $workId = $work->id;
  124. $workExtraData = get_work_assignment_by_id($workId);
  125. foreach ($work->user_results as $userResult) {
  126. $itemId = $userResult['id'];
  127. $table->setCellContents($row, $column, $work->title.' ['.trim(strip_tags($userResult['title'])).']');
  128. $table->setCellAttributes($row, $column, array('width' => '300px'));
  129. $column++;
  130. $table->setCellContents($row, $column, $userResult['sent_date']);
  131. $column++;
  132. $dateQualification = !empty($workExtraData['expires_on']) ? api_get_local_time($workExtraData['expires_on']) : '-';
  133. $table->setCellContents($row, $column, $dateQualification);
  134. $column++;
  135. $score = null;
  136. $score = $userResult['qualification'];
  137. $table->setCellContents($row, $column, $score);
  138. $column++;
  139. // Actions
  140. $links = null;
  141. // is a text
  142. $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$itemId;
  143. $links .= Display::url(Display::return_icon('default.png', get_lang('View')), $url);
  144. if (!empty($userResult['url'])) {
  145. $url = api_get_path(WEB_CODE_PATH).'work/download.php?'.api_get_cidreq().'&id='.$itemId;
  146. $links .= Display::url(Display::return_icon('save.png', get_lang('Download')), $url);
  147. }
  148. if (api_is_allowed_to_edit()) {
  149. $url = api_get_path(WEB_CODE_PATH).'work/edit.php?'.api_get_cidreq().'&item_id='.$itemId.'&id='.$workId.'&parent_id='.$workId;
  150. $links .= Display::url(
  151. Display::return_icon('rate_work.png', get_lang('Comment')),
  152. $url
  153. );
  154. }
  155. $table->setCellContents($row, $column, $links);
  156. $row++;
  157. $column = 0;
  158. }
  159. }
  160. echo $table->toHtml();
  161. Display :: display_footer();