view.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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']) ? intval($_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. protectWork(api_get_course_info(), $work['parent_id']);
  24. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  25. api_get_user_id(),
  26. $courseInfo
  27. );
  28. if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_is_coach())) ||
  29. (
  30. $courseInfo['show_score'] == 0 &&
  31. $work['active'] == 1 &&
  32. $work['accepted'] == 1
  33. )
  34. ) {
  35. if ((api_is_allowed_to_edit() || api_is_coach()) || api_is_drh()) {
  36. $url_dir = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?id='.$my_folder_data['id'].'&'.api_get_cidreq();
  37. } else {
  38. $url_dir = api_get_path(WEB_CODE_PATH).'work/work_list.php?id='.$my_folder_data['id'].'&'.api_get_cidreq();
  39. }
  40. $userInfo = api_get_user_info($work['user_id']);
  41. $interbreadcrumb[] = ['url' => $url_dir, 'name' => $my_folder_data['title']];
  42. $interbreadcrumb[] = ['url' => '#', 'name' => $userInfo['complete_name']];
  43. $interbreadcrumb[] = ['url' => '#', 'name' => $work['title']];
  44. if (($courseInfo['show_score'] == 0 &&
  45. $work['active'] == 1 &&
  46. $work['accepted'] == 1
  47. ) ||
  48. (api_is_allowed_to_edit() || api_is_coach()) ||
  49. user_is_author($id) ||
  50. $isDrhOfCourse
  51. ) {
  52. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  53. $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
  54. if ($page == 'edit') {
  55. $url = api_get_path(WEB_CODE_PATH).'work/edit.php?id='.$my_folder_data['id'].'&item_id='.$work['id'].'&'.api_get_cidreq();
  56. } else {
  57. $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();
  58. $allowRedirect = api_get_configuration_value('allow_redirect_to_main_page_after_work_upload');
  59. $urlToRedirect = '';
  60. if ($allowRedirect) {
  61. $url = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
  62. }
  63. }
  64. switch ($action) {
  65. case 'send_comment':
  66. if (isset($_FILES['attachment'])) {
  67. $_POST['attachment'] = $_FILES['attachment'];
  68. }
  69. addWorkComment(
  70. api_get_course_info(),
  71. api_get_user_id(),
  72. $my_folder_data,
  73. $work,
  74. $_POST
  75. );
  76. if (api_is_allowed_to_edit()) {
  77. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  78. $sql = "UPDATE $work_table
  79. SET
  80. qualificator_id = '".api_get_user_id()."',
  81. qualification = '".api_float_val($_POST['qualification'])."',
  82. date_of_qualification = '".api_get_utc_datetime()."'
  83. WHERE c_id = ".$courseInfo['real_id']." AND id = $id";
  84. Database::query($sql);
  85. Display::addFlash(Display::return_message(get_lang('Updated')));
  86. $resultUpload = uploadWork(
  87. $my_folder_data,
  88. $courseInfo,
  89. true,
  90. $work
  91. );
  92. if ($resultUpload) {
  93. $work_table = Database::get_course_table(
  94. TABLE_STUDENT_PUBLICATION
  95. );
  96. if (isset($resultUpload['url']) && !empty($resultUpload['url'])) {
  97. $title = isset($resultUpload['filename']) && !empty($resultUpload['filename']) ? $resultUpload['filename'] : get_lang('Untitled');
  98. $urlToSave = Database::escape_string($resultUpload['url']);
  99. $title = Database::escape_string($title);
  100. $sql = "UPDATE $work_table SET
  101. url_correction = '".$urlToSave."',
  102. title_correction = '".$title."'
  103. WHERE iid = ".$work['iid'];
  104. Database::query($sql);
  105. Display::addFlash(
  106. Display::return_message(get_lang('FileUploadSucces'))
  107. );
  108. }
  109. }
  110. }
  111. header('Location: '.$url);
  112. exit;
  113. break;
  114. case 'delete_attachment':
  115. deleteCommentFile(
  116. $_REQUEST['comment_id'],
  117. api_get_course_info()
  118. );
  119. Display::addFlash(Display::return_message(get_lang('DocDeleted')));
  120. header('Location: '.$url);
  121. exit;
  122. break;
  123. case 'delete_correction':
  124. if (isset($work['url_correction']) && !empty($work['url_correction'])) {
  125. if (api_is_allowed_to_edit()) {
  126. deleteCorrection($courseInfo, $work);
  127. Display::addFlash(
  128. Display::return_message(get_lang('Deleted'))
  129. );
  130. }
  131. }
  132. header('Location: '.$url);
  133. exit;
  134. break;
  135. }
  136. $comments = getWorkComments($work);
  137. $commentForm = getWorkCommentForm($work, $my_folder_data);
  138. $tpl = new Template();
  139. $tpl->assign('work', $work);
  140. $tpl->assign('comments', $comments);
  141. if (isset($work['contains_file'])) {
  142. if (isset($work['download_url'])) {
  143. $actions = Display::url(
  144. Display::return_icon(
  145. 'save.png',
  146. get_lang('Download'),
  147. null,
  148. ICON_SIZE_MEDIUM
  149. ),
  150. $work['download_url']
  151. );
  152. if (!empty($work['url_correction'])) {
  153. $actions .= Display::url(
  154. Display::return_icon(
  155. 'check-circle.png',
  156. get_lang('Correction'),
  157. null,
  158. ICON_SIZE_MEDIUM
  159. ),
  160. $work['download_url'].'&correction=1'
  161. );
  162. if (api_is_allowed_to_edit()) {
  163. $actions .= Display::url(
  164. Display::return_icon(
  165. 'delete.png',
  166. get_lang('Delete').': '.get_lang('Correction'),
  167. null,
  168. ICON_SIZE_MEDIUM
  169. ),
  170. api_get_self().'?action=delete_correction&id='.$id.'&'.api_get_cidreq()
  171. );
  172. }
  173. }
  174. $tpl->assign(
  175. 'actions',
  176. Display::toolbarAction('toolbar', [$actions])
  177. );
  178. }
  179. }
  180. if (api_is_allowed_to_session_edit()) {
  181. $tpl->assign('form', $commentForm);
  182. }
  183. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  184. $template = $tpl->get_template('work/view.tpl');
  185. $content = $tpl->fetch($template);
  186. $tpl->assign('content', $content);
  187. $tpl->display_one_col_template();
  188. } else {
  189. api_not_allowed(true);
  190. }
  191. } else {
  192. api_not_allowed(true);
  193. }