view.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. //require_once '../inc/global.inc.php';
  5. $current_course_tool = TOOL_STUDENTPUBLICATION;
  6. require_once 'work.lib.php';
  7. $id = isset($_GET['id']) ? intval($_GET['id']) : null;
  8. $work = get_work_data_by_id($id);
  9. if (empty($id) || empty($work)) {
  10. api_not_allowed(true);
  11. }
  12. if ($work['active'] != 1) {
  13. api_not_allowed(true);
  14. }
  15. $work['title'] = isset($work['title']) ? Security::remove_XSS($work['title']) : '';
  16. $work['description'] = isset($work['description']) ? Security::remove_XSS($work['description']) : '';
  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["file"])) {
  62. $_POST['file'] = $_FILES["file"];
  63. }
  64. addWorkComment(
  65. api_get_course_info(),
  66. api_get_user_id(),
  67. $my_folder_data,
  68. $work,
  69. $_POST
  70. );
  71. Display::addFlash(Display::return_message(get_lang('CommentCreated')));
  72. header('Location: '.$url);
  73. exit;
  74. break;
  75. case 'delete_attachment':
  76. deleteCommentFile(
  77. $_REQUEST['comment_id'],
  78. api_get_course_info()
  79. );
  80. Display::addFlash(Display::return_message(get_lang('DocDeleted')));
  81. header('Location: '.$url);
  82. exit;
  83. break;
  84. }
  85. $comments = getWorkComments($work);
  86. $commentForm = getWorkCommentForm($work);
  87. $tpl = Container::getTwig();
  88. $tpl->addGlobal('work', $work);
  89. $tpl->addGlobal('comments', $comments);
  90. $actions = '';
  91. if (isset($work['contains_file'])) {
  92. if (isset($work['download_url'])) {
  93. $actions .= Display::url(
  94. Display::return_icon(
  95. 'save.png',
  96. get_lang('Download'),
  97. null,
  98. ICON_SIZE_MEDIUM
  99. ),
  100. $work['download_url']
  101. );
  102. if (isset($work['url_correction'])) {
  103. $actions .= Display::url(
  104. Display::return_icon(
  105. 'check.png',
  106. get_lang('Correction'),
  107. null,
  108. ICON_SIZE_MEDIUM
  109. ),
  110. $work['download_url'].'&correction=1'
  111. );
  112. }
  113. }
  114. }
  115. $tpl->addGlobal('actions', $actions);
  116. if (api_is_allowed_to_session_edit()) {
  117. $tpl->addGlobal('form', $commentForm);
  118. }
  119. $tpl->addGlobal('is_allowed_to_edit', api_is_allowed_to_edit());
  120. echo Container::getTwig()->render('@template_style/work/view.html.twig');
  121. } else {
  122. api_not_allowed(true);
  123. }
  124. } else {
  125. api_not_allowed(true);
  126. }