view.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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[] = array(
  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[] = array('url' => $url_dir, 'name' => $my_folder_data['title']);
  42. $interbreadcrumb[] = array('url' => '#', 'name' => $userInfo['complete_name']);
  43. $interbreadcrumb[] = array('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. }
  59. switch ($action) {
  60. case 'send_comment':
  61. if (isset($_FILES['attachment'])) {
  62. $_POST['attachment'] = $_FILES['attachment'];
  63. }
  64. addWorkComment(
  65. api_get_course_info(),
  66. api_get_user_id(),
  67. $my_folder_data,
  68. $work,
  69. $_POST
  70. );
  71. if (api_is_allowed_to_edit()) {
  72. $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  73. $sql = "UPDATE $work_table
  74. SET
  75. qualificator_id = '".api_get_user_id()."',
  76. qualification = '".api_float_val($_POST['qualification'])."',
  77. date_of_qualification = '".api_get_utc_datetime()."'
  78. WHERE c_id = ".$courseInfo['real_id']." AND id = $id";
  79. Database::query($sql);
  80. Display::addFlash(Display::return_message(get_lang('Updated')));
  81. $resultUpload = uploadWork(
  82. $my_folder_data,
  83. $courseInfo,
  84. true,
  85. $work
  86. );
  87. if ($resultUpload) {
  88. $work_table = Database::get_course_table(
  89. TABLE_STUDENT_PUBLICATION
  90. );
  91. if (isset($resultUpload['url']) && !empty($resultUpload['url'])) {
  92. $title = isset($resultUpload['filename']) && !empty($resultUpload['filename']) ? $resultUpload['filename'] : get_lang('Untitled');
  93. $urlToSave = Database::escape_string($resultUpload['url']);
  94. $title = Database::escape_string($title);
  95. $sql = "UPDATE $work_table SET
  96. url_correction = '".$urlToSave."',
  97. title_correction = '".$title."'
  98. WHERE iid = ".$work['iid'];
  99. Database::query($sql);
  100. Display::addFlash(
  101. Display::return_message(get_lang('FileUploadSucces'))
  102. );
  103. }
  104. }
  105. }
  106. header('Location: '.$url);
  107. exit;
  108. break;
  109. case 'delete_attachment':
  110. deleteCommentFile(
  111. $_REQUEST['comment_id'],
  112. api_get_course_info()
  113. );
  114. Display::addFlash(Display::return_message(get_lang('DocDeleted')));
  115. header('Location: '.$url);
  116. exit;
  117. break;
  118. case 'delete_correction':
  119. if (isset($work['url_correction']) && !empty($work['url_correction'])) {
  120. if (api_is_allowed_to_edit()) {
  121. deleteCorrection($courseInfo, $work);
  122. Display::addFlash(
  123. Display::return_message(get_lang('Deleted'))
  124. );
  125. }
  126. }
  127. header('Location: '.$url);
  128. exit;
  129. break;
  130. }
  131. $comments = getWorkComments($work);
  132. $commentForm = getWorkCommentForm($work, $my_folder_data);
  133. $tpl = new Template();
  134. $tpl->assign('work', $work);
  135. $tpl->assign('comments', $comments);
  136. if (isset($work['contains_file'])) {
  137. if (isset($work['download_url'])) {
  138. $actions = Display::url(
  139. Display::return_icon(
  140. 'save.png',
  141. get_lang('Download'),
  142. null,
  143. ICON_SIZE_MEDIUM
  144. ),
  145. $work['download_url']
  146. );
  147. if (!empty($work['url_correction'])) {
  148. $actions .= Display::url(
  149. Display::return_icon(
  150. 'check-circle.png',
  151. get_lang('Correction'),
  152. null,
  153. ICON_SIZE_MEDIUM
  154. ),
  155. $work['download_url'].'&correction=1'
  156. );
  157. if (api_is_allowed_to_edit()) {
  158. $actions .= Display::url(
  159. Display::return_icon(
  160. 'delete.png',
  161. get_lang('Delete').': '.get_lang('Correction'),
  162. null,
  163. ICON_SIZE_MEDIUM
  164. ),
  165. api_get_self().'?action=delete_correction&id='.$id.'&'.api_get_cidreq()
  166. );
  167. }
  168. }
  169. $tpl->assign(
  170. 'actions',
  171. Display::toolbarAction('toolbar', [$actions])
  172. );
  173. }
  174. }
  175. if (api_is_allowed_to_session_edit()) {
  176. $tpl->assign('form', $commentForm);
  177. }
  178. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  179. $template = $tpl->get_template('work/view.tpl');
  180. $content = $tpl->fetch($template);
  181. $tpl->assign('content', $content);
  182. $tpl->display_one_col_template();
  183. } else {
  184. api_not_allowed(true);
  185. }
  186. } else {
  187. api_not_allowed(true);
  188. }