work_list.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Entity\CStudentPublication;
  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. $workId = isset($_GET['id']) ? (int) $_GET['id'] : null;
  10. $courseInfo = api_get_course_info();
  11. if (empty($workId) || empty($courseInfo)) {
  12. api_not_allowed(true);
  13. }
  14. // Student publications are saved with the iid in a LP
  15. $origin = api_get_origin();
  16. if ($origin === 'learnpath') {
  17. $em = Database::getManager();
  18. /** @var CStudentPublication $work */
  19. $work = $em->getRepository('ChamiloCourseBundle:CStudentPublication')->findOneBy(
  20. ['iid' => $workId, 'cId' => $courseInfo['real_id']]
  21. );
  22. if ($work) {
  23. $workId = $work->getId();
  24. }
  25. }
  26. protectWork($courseInfo, $workId);
  27. $my_folder_data = get_work_data_by_id($workId);
  28. $work_data = get_work_assignment_by_id($workId);
  29. $tool_name = get_lang('StudentPublications');
  30. $group_id = api_get_group_id();
  31. $htmlHeadXtra[] = api_get_jqgrid_js();
  32. $url_dir = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
  33. if (!empty($group_id)) {
  34. $group_properties = GroupManager :: get_group_properties($group_id);
  35. $interbreadcrumb[] = [
  36. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  37. 'name' => get_lang('Groups'),
  38. ];
  39. $interbreadcrumb[] = [
  40. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  41. 'name' => get_lang('GroupSpace').' '.$group_properties['name'],
  42. ];
  43. }
  44. $interbreadcrumb[] = [
  45. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  46. 'name' => get_lang('StudentPublications'),
  47. ];
  48. $interbreadcrumb[] = [
  49. 'url' => api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$workId,
  50. 'name' => $my_folder_data['title'],
  51. ];
  52. $documentsAddedInWork = getAllDocumentsFromWorkToString($workId, $courseInfo);
  53. $actionsLeft = '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'">'.
  54. Display::return_icon('back.png', get_lang('BackToWorksList'), '', ICON_SIZE_MEDIUM).'</a>';
  55. $actionsRight = '';
  56. $onlyOnePublication = api_get_configuration_value('allow_only_one_student_publication_per_user');
  57. if (api_is_allowed_to_session_edit(false, true) && !empty($workId) && !api_is_invitee()) {
  58. $url = api_get_path(WEB_CODE_PATH).'work/upload.php?'.api_get_cidreq().'&id='.$workId;
  59. $actionsRight = Display::url(
  60. Display::returnFontAwesomeIcon(
  61. ' fa-upload'
  62. ).
  63. get_lang('UploadMyAssignment'),
  64. $url,
  65. ['class' => 'btn btn-primary', 'id' => 'upload_button']
  66. );
  67. }
  68. if ($onlyOnePublication) {
  69. $count = get_work_count_by_student(
  70. api_get_user_id(),
  71. $my_folder_data['id']
  72. );
  73. if (!empty($count) && $count >= 1) {
  74. $actionsRight = '';
  75. }
  76. }
  77. $tpl = new Template('');
  78. $content = Display::toolbarAction('toolbar-work', [$actionsLeft, $actionsRight]);
  79. if (!empty($my_folder_data['title'])) {
  80. $content .= Display::page_subheader($my_folder_data['title']);
  81. }
  82. if (!empty($my_folder_data['description'])) {
  83. $contentWork = Security::remove_XSS($my_folder_data['description']);
  84. $content .= Display::panel($contentWork, get_lang('Description'));
  85. }
  86. $extraFieldWorkData = workGetExtraFieldData($workId);
  87. if (!empty($extraFieldWorkData)) {
  88. $forceDownload = api_get_configuration_value('force_download_doc_before_upload_work');
  89. if ($forceDownload) {
  90. // Force to download documents first.
  91. $downloadDocumentsFirst = addslashes(get_lang('DownloadDocumentsFirst'));
  92. $content .= "<script>
  93. $(function() {
  94. var clicked = 0;
  95. $('#upload_button').on('click', function(e) {
  96. if (clicked == 0) {
  97. alert('$downloadDocumentsFirst');
  98. e.preventDefault();
  99. }
  100. });
  101. $('.download_extra_field').on('click', function(e){
  102. clicked = 1;
  103. });
  104. });
  105. </script>";
  106. }
  107. }
  108. $content .= $extraFieldWorkData;
  109. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  110. $item_id = isset($_REQUEST['item_id']) ? (int) $_REQUEST['item_id'] : null;
  111. switch ($action) {
  112. case 'delete':
  113. $fileDeleted = deleteWorkItem($item_id, $courseInfo);
  114. if (!$fileDeleted) {
  115. Display::addFlash(Display::return_message(get_lang('YouAreNotAllowedToDeleteThisDocument')));
  116. } else {
  117. Display::addFlash(Display::return_message(get_lang('TheDocumentHasBeenDeleted')));
  118. }
  119. break;
  120. }
  121. $result = getWorkDateValidationStatus($work_data);
  122. $content .= $result['message'];
  123. $check_qualification = (int) $my_folder_data['qualification'];
  124. if (!api_is_invitee()) {
  125. if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {
  126. $type = 'simple';
  127. $columns = [
  128. get_lang('Type'),
  129. get_lang('Title'),
  130. get_lang('Qualification'),
  131. get_lang('Date'),
  132. get_lang('Status'),
  133. get_lang('Actions'),
  134. ];
  135. $columnModel = [
  136. [
  137. 'name' => 'type',
  138. 'index' => 'file',
  139. 'width' => '5',
  140. 'align' => 'left',
  141. 'search' => 'false',
  142. 'sortable' => 'false',
  143. ],
  144. [
  145. 'name' => 'title',
  146. 'index' => 'title',
  147. 'width' => '40',
  148. 'align' => 'left',
  149. 'search' => 'false',
  150. 'wrap_cell' => 'true',
  151. ],
  152. [
  153. 'name' => 'qualification',
  154. 'index' => 'qualification',
  155. 'width' => '30',
  156. 'align' => 'center',
  157. 'search' => 'true',
  158. ],
  159. [
  160. 'name' => 'sent_date',
  161. 'index' => 'sent_date',
  162. 'width' => '30',
  163. 'align' => 'left',
  164. 'search' => 'true',
  165. 'wrap_cell' => 'true',
  166. ],
  167. [
  168. 'name' => 'qualificator_id',
  169. 'index' => 'qualificator_id',
  170. 'width' => '20',
  171. 'align' => 'left',
  172. 'search' => 'true',
  173. ],
  174. [
  175. 'name' => 'actions',
  176. 'index' => 'actions',
  177. 'width' => '20',
  178. 'align' => 'left',
  179. 'search' => 'false',
  180. 'sortable' => 'false',
  181. ],
  182. ];
  183. } else {
  184. $type = 'complex';
  185. $columns = [
  186. get_lang('Type'),
  187. get_lang('Title'),
  188. get_lang('Feedback'),
  189. get_lang('Date'),
  190. get_lang('Actions'),
  191. ];
  192. $columnModel = [
  193. [
  194. 'name' => 'type',
  195. 'index' => 'file',
  196. 'width' => '5',
  197. 'align' => 'left',
  198. 'search' => 'false',
  199. 'sortable' => 'false',
  200. ],
  201. [
  202. 'name' => 'title',
  203. 'index' => 'title',
  204. 'width' => '60',
  205. 'align' => 'left',
  206. 'search' => 'false',
  207. 'wrap_cell' => 'true',
  208. ],
  209. [
  210. 'name' => 'qualification',
  211. 'index' => 'qualification',
  212. 'width' => '30',
  213. 'align' => 'center',
  214. 'search' => 'true',
  215. ],
  216. [
  217. 'name' => 'sent_date',
  218. 'index' => 'sent_date',
  219. 'width' => '30',
  220. 'align' => 'left',
  221. 'search' => 'true',
  222. 'wrap_cell' => 'true',
  223. 'sortable' => 'false',
  224. ],
  225. [
  226. 'name' => 'actions',
  227. 'index' => 'actions',
  228. 'width' => '20',
  229. 'align' => 'left',
  230. 'search' => 'false',
  231. 'sortable' => 'false',
  232. ],
  233. ];
  234. }
  235. $extraParams = [
  236. 'autowidth' => 'true',
  237. 'height' => 'auto',
  238. 'sortname' => 'sent_date',
  239. 'sortorder' => 'desc',
  240. ];
  241. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_user_list&work_id='.$workId.'&type='.$type.'&'.api_get_cidreq();
  242. $content .= '
  243. <script>
  244. $(function() {
  245. '.Display::grid_js('results', $url, $columns, $columnModel, $extraParams).'
  246. });
  247. </script>
  248. ';
  249. $documents = getAllDocumentsFromWorkToString($workId, $courseInfo);
  250. $content .= $documents;
  251. $tableWork = Display::grid_html('results');
  252. $content .= Display::panel($tableWork);
  253. }
  254. $tpl->assign('content', $content);
  255. $tpl->display_one_col_template();