view.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once '../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["file"])) {
  61. $_POST['file'] = $_FILES["file"];
  62. }
  63. addWorkComment(
  64. api_get_course_info(),
  65. api_get_user_id(),
  66. $my_folder_data,
  67. $work,
  68. $_POST
  69. );
  70. Display::addFlash(Display::return_message(get_lang('CommentCreated')));
  71. header('Location: '.$url);
  72. exit;
  73. break;
  74. case 'delete_attachment':
  75. deleteCommentFile(
  76. $_REQUEST['comment_id'],
  77. api_get_course_info()
  78. );
  79. Display::addFlash(Display::return_message(get_lang('DocDeleted')));
  80. header('Location: '.$url);
  81. exit;
  82. break;
  83. case 'delete_correction':
  84. if (isset($work['url_correction']) && !empty($work['url_correction'])) {
  85. if (api_is_allowed_to_edit()) {
  86. deleteCorrection($courseInfo, $work);
  87. Display::addFlash(
  88. Display::return_message(get_lang('Deleted'))
  89. );
  90. }
  91. }
  92. header('Location: '.$url);
  93. exit;
  94. break;
  95. }
  96. $comments = getWorkComments($work);
  97. $commentForm = getWorkCommentForm($work);
  98. $tpl = new Template();
  99. $tpl->assign('work', $work);
  100. $tpl->assign('comments', $comments);
  101. $actions = '';
  102. if (isset($work['contains_file'])) {
  103. if (isset($work['download_url'])) {
  104. $actions .= Display::url(
  105. Display::return_icon(
  106. 'save.png',
  107. get_lang('Download'),
  108. null,
  109. ICON_SIZE_MEDIUM
  110. ),
  111. $work['download_url']
  112. );
  113. if (!empty($work['url_correction'])) {
  114. $actions .= Display::url(
  115. Display::return_icon(
  116. 'check.png',
  117. get_lang('Correction'),
  118. null,
  119. ICON_SIZE_MEDIUM
  120. ),
  121. $work['download_url'].'&correction=1'
  122. );
  123. if (api_is_allowed_to_edit()) {
  124. $actions .= Display::url(
  125. Display::return_icon(
  126. 'delete.png',
  127. get_lang('Delete').': '.get_lang('Correction'),
  128. null,
  129. ICON_SIZE_MEDIUM
  130. ),
  131. api_get_self().'?action=delete_correction&id='.$id.'&'.api_get_cidreq()
  132. );
  133. }
  134. }
  135. }
  136. }
  137. $tpl->assign('actions', $actions);
  138. if (api_is_allowed_to_session_edit()) {
  139. $tpl->assign('form', $commentForm);
  140. }
  141. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  142. $template = $tpl->get_template('work/view.tpl');
  143. $content = $tpl->fetch($template);
  144. $tpl->assign('content', $content);
  145. $tpl->display_one_col_template();
  146. } else {
  147. api_not_allowed(true);
  148. }
  149. } else {
  150. api_not_allowed(true);
  151. }