view.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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($my_folder_data, $courseInfo, true, $work);
  81. if ($resultUpload) {
  82. $work_table = Database:: get_course_table(
  83. TABLE_STUDENT_PUBLICATION
  84. );
  85. if (isset($resultUpload['url']) && !empty($resultUpload['url'])) {
  86. $title = isset($resultUpload['filename']) && !empty($resultUpload['filename']) ? $resultUpload['filename'] : get_lang(
  87. 'Untitled'
  88. );
  89. $urlToSave = Database::escape_string($resultUpload['url']);
  90. $title = Database::escape_string($title);
  91. $sql = "UPDATE $work_table SET
  92. url_correction = '".$urlToSave."',
  93. title_correction = '".$title."'
  94. WHERE iid = ".$work['iid'];
  95. Database::query($sql);
  96. Display::addFlash(
  97. Display::return_message(get_lang('FileUploadSucces'))
  98. );
  99. }
  100. }
  101. }
  102. header('Location: '.$url);
  103. exit;
  104. break;
  105. case 'delete_attachment':
  106. deleteCommentFile(
  107. $_REQUEST['comment_id'],
  108. api_get_course_info()
  109. );
  110. Display::addFlash(Display::return_message(get_lang('DocDeleted')));
  111. header('Location: '.$url);
  112. exit;
  113. break;
  114. case 'delete_correction':
  115. if (isset($work['url_correction']) && !empty($work['url_correction'])) {
  116. if (api_is_allowed_to_edit()) {
  117. deleteCorrection($courseInfo, $work);
  118. Display::addFlash(
  119. Display::return_message(get_lang('Deleted'))
  120. );
  121. }
  122. }
  123. header('Location: '.$url);
  124. exit;
  125. break;
  126. }
  127. $comments = getWorkComments($work);
  128. $commentForm = getWorkCommentForm($work, $my_folder_data);
  129. $tpl = new Template();
  130. $tpl->assign('work', $work);
  131. $tpl->assign('comments', $comments);
  132. $actions = '';
  133. if (isset($work['contains_file'])) {
  134. if (isset($work['download_url'])) {
  135. $actions .= Display::url(
  136. Display::return_icon(
  137. 'save.png',
  138. get_lang('Download'),
  139. null,
  140. ICON_SIZE_MEDIUM
  141. ),
  142. $work['download_url']
  143. );
  144. if (!empty($work['url_correction'])) {
  145. $actions .= Display::url(
  146. Display::return_icon(
  147. 'check-circle.png',
  148. get_lang('Correction'),
  149. null,
  150. ICON_SIZE_MEDIUM
  151. ),
  152. $work['download_url'].'&correction=1'
  153. );
  154. if (api_is_allowed_to_edit()) {
  155. $actions .= Display::url(
  156. Display::return_icon(
  157. 'delete.png',
  158. get_lang('Delete').': '.get_lang('Correction'),
  159. null,
  160. ICON_SIZE_MEDIUM
  161. ),
  162. api_get_self().'?action=delete_correction&id='.$id.'&'.api_get_cidreq()
  163. );
  164. }
  165. }
  166. }
  167. }
  168. $tpl->assign('actions', $actions);
  169. if (api_is_allowed_to_session_edit()) {
  170. $tpl->assign('form', $commentForm);
  171. }
  172. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  173. $template = $tpl->get_template('work/view.tpl');
  174. $content = $tpl->fetch($template);
  175. $tpl->assign('content', $content);
  176. $tpl->display_one_col_template();
  177. } else {
  178. api_not_allowed(true);
  179. }
  180. } else {
  181. api_not_allowed(true);
  182. }