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