view.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. $current_course_tool = TOOL_STUDENTPUBLICATION;
  5. require_once 'work.lib.php';
  6. $id = isset($_GET['id']) ? (int) $_GET['id'] : null;
  7. $work = get_work_data_by_id($id);
  8. if (empty($id) || empty($work)) {
  9. api_not_allowed(true);
  10. }
  11. if ($work['active'] != 1) {
  12. api_not_allowed(true);
  13. }
  14. $work['title'] = isset($work['title']) ? Security::remove_XSS($work['title']) : '';
  15. $work['description'] = isset($work['description']) ? Security::remove_XSS($work['description']) : '';
  16. $htmlHeadXtra[] = '<script>'.ExerciseLib::getJsCode().'</script>';
  17. $interbreadcrumb[] = [
  18. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  19. 'name' => get_lang('StudentPublications'),
  20. ];
  21. $my_folder_data = get_work_data_by_id($work['parent_id']);
  22. $courseInfo = api_get_course_info();
  23. $blockScoreEdition = api_get_configuration_value('block_student_publication_score_edition');
  24. if ($blockScoreEdition && !empty($work['qualification']) && !api_is_platform_admin()) {
  25. api_not_allowed(true);
  26. }
  27. protectWork(api_get_course_info(), $work['parent_id']);
  28. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  29. api_get_user_id(),
  30. $courseInfo
  31. );
  32. if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_is_coach())) ||
  33. (
  34. $courseInfo['show_score'] == 0 &&
  35. $work['active'] == 1 &&
  36. $work['accepted'] == 1
  37. )
  38. ) {
  39. if ((api_is_allowed_to_edit() || api_is_coach()) || api_is_drh()) {
  40. $url_dir = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?id='.$my_folder_data['id'].'&'.api_get_cidreq();
  41. } else {
  42. $url_dir = api_get_path(WEB_CODE_PATH).'work/work_list.php?id='.$my_folder_data['id'].'&'.api_get_cidreq();
  43. }
  44. $userInfo = api_get_user_info($work['user_id']);
  45. $interbreadcrumb[] = ['url' => $url_dir, 'name' => $my_folder_data['title']];
  46. $interbreadcrumb[] = ['url' => '#', 'name' => $userInfo['complete_name']];
  47. $interbreadcrumb[] = ['url' => '#', 'name' => $work['title']];
  48. if ((
  49. $courseInfo['show_score'] == 0 &&
  50. $work['active'] == 1 &&
  51. $work['accepted'] == 1
  52. ) ||
  53. (api_is_allowed_to_edit() || api_is_coach()) ||
  54. user_is_author($id) ||
  55. $isDrhOfCourse
  56. ) {
  57. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  58. $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
  59. if ($page == 'edit') {
  60. $url = api_get_path(WEB_CODE_PATH).'work/edit.php?id='.$my_folder_data['id'].'&item_id='.$work['id'].'&'.api_get_cidreq();
  61. } else {
  62. $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();
  63. $allowRedirect = api_get_configuration_value('allow_redirect_to_main_page_after_work_upload');
  64. $urlToRedirect = '';
  65. if ($allowRedirect) {
  66. $url = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
  67. }
  68. }
  69. switch ($action) {
  70. case 'send_comment':
  71. if (isset($_FILES['attachment'])) {
  72. $_POST['attachment'] = $_FILES['attachment'];
  73. }
  74. addWorkComment(
  75. api_get_course_info(),
  76. api_get_user_id(),
  77. $my_folder_data,
  78. $work,
  79. $_POST
  80. );
  81. if (api_is_allowed_to_edit()) {
  82. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  83. $sql = "UPDATE $work_table
  84. SET
  85. qualificator_id = '".api_get_user_id()."',
  86. qualification = '".api_float_val($_POST['qualification'])."',
  87. date_of_qualification = '".api_get_utc_datetime()."'
  88. WHERE c_id = ".$courseInfo['real_id']." AND id = $id";
  89. Database::query($sql);
  90. Display::addFlash(Display::return_message(get_lang('Updated')));
  91. $resultUpload = uploadWork(
  92. $my_folder_data,
  93. $courseInfo,
  94. true,
  95. $work
  96. );
  97. if ($resultUpload) {
  98. $work_table = Database::get_course_table(
  99. TABLE_STUDENT_PUBLICATION
  100. );
  101. if (isset($resultUpload['url']) && !empty($resultUpload['url'])) {
  102. $title = isset($resultUpload['filename']) && !empty($resultUpload['filename']) ? $resultUpload['filename'] : get_lang('Untitled');
  103. $urlToSave = Database::escape_string($resultUpload['url']);
  104. $title = Database::escape_string($title);
  105. $sql = "UPDATE $work_table SET
  106. url_correction = '".$urlToSave."',
  107. title_correction = '".$title."'
  108. WHERE iid = ".$work['iid'];
  109. Database::query($sql);
  110. Display::addFlash(
  111. Display::return_message(get_lang('FileUploadSucces'))
  112. );
  113. }
  114. }
  115. }
  116. $blockScoreEdition = api_get_configuration_value('block_student_publication_score_edition');
  117. if ($blockScoreEdition && !api_is_platform_admin()) {
  118. $url = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$my_folder_data['id'];
  119. }
  120. header('Location: '.$url);
  121. exit;
  122. break;
  123. case 'delete_attachment':
  124. deleteCommentFile(
  125. $_REQUEST['comment_id'],
  126. api_get_course_info()
  127. );
  128. Display::addFlash(Display::return_message(get_lang('DocDeleted')));
  129. header('Location: '.$url);
  130. exit;
  131. break;
  132. case 'delete_correction':
  133. if (isset($work['url_correction']) && !empty($work['url_correction'])) {
  134. if (api_is_allowed_to_edit()) {
  135. deleteCorrection($courseInfo, $work);
  136. Display::addFlash(
  137. Display::return_message(get_lang('Deleted'))
  138. );
  139. }
  140. }
  141. header('Location: '.$url);
  142. exit;
  143. break;
  144. }
  145. $comments = getWorkComments($work);
  146. $commentForm = getWorkCommentForm($work, $my_folder_data);
  147. $tpl = new Template();
  148. $tpl->assign('work', $work);
  149. $tpl->assign('comments', $comments);
  150. $actions = '';
  151. if (isset($work['contains_file']) && !empty($work['contains_file'])) {
  152. if (isset($work['download_url']) && !empty($work['download_url'])) {
  153. $actions = Display::url(
  154. Display::return_icon(
  155. 'back.png',
  156. get_lang('BackToWorksList'),
  157. null,
  158. ICON_SIZE_MEDIUM
  159. ),
  160. api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq()
  161. );
  162. // Check if file can be downloaded
  163. $file = getFileContents($work['id'], $courseInfo, api_get_session_id(), false);
  164. if (!empty($file)) {
  165. $actions .= Display::url(
  166. Display::return_icon(
  167. 'save.png',
  168. get_lang('Download'),
  169. null,
  170. ICON_SIZE_MEDIUM
  171. ),
  172. $work['download_url']
  173. );
  174. }
  175. }
  176. }
  177. if (isset($work['url_correction']) && !empty($work['url_correction']) && !empty($work['download_url'])) {
  178. $actions .= Display::url(
  179. Display::return_icon(
  180. 'check-circle.png',
  181. get_lang('Correction'),
  182. null,
  183. ICON_SIZE_MEDIUM
  184. ),
  185. $work['download_url'].'&correction=1'
  186. );
  187. if (api_is_allowed_to_edit()) {
  188. $actions .= Display::url(
  189. Display::return_icon(
  190. 'delete.png',
  191. get_lang('Delete').': '.get_lang('Correction'),
  192. null,
  193. ICON_SIZE_MEDIUM
  194. ),
  195. api_get_self().'?action=delete_correction&id='.$id.'&'.api_get_cidreq()
  196. );
  197. }
  198. }
  199. if (!empty($actions)) {
  200. $tpl->assign(
  201. 'actions',
  202. Display::toolbarAction('toolbar', [$actions])
  203. );
  204. }
  205. if (api_is_allowed_to_session_edit()) {
  206. $tpl->assign('form', $commentForm);
  207. }
  208. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  209. $template = $tpl->get_template('work/view.tpl');
  210. $content = $tpl->fetch($template);
  211. $tpl->assign('content', $content);
  212. $tpl->display_one_col_template();
  213. } else {
  214. api_not_allowed(true);
  215. }
  216. } else {
  217. api_not_allowed(true);
  218. }