student_work.php 6.3 KB

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