view.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. $interbreadcrumb[] = array ('url' => 'work.php', 'name' => get_lang('StudentPublications'));
  15. $my_folder_data = get_work_data_by_id($work['parent_id']);
  16. $courseInfo = api_get_course_info();
  17. protectWork(api_get_course_info(), $work['parent_id']);
  18. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  19. api_get_user_id(),
  20. $courseInfo
  21. );
  22. if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_is_coach())) ||
  23. (
  24. $courseInfo['show_score'] == 0 &&
  25. $work['active'] == 1 &&
  26. $work['accepted'] == 1
  27. )
  28. ) {
  29. if ((api_is_allowed_to_edit() || api_is_coach()) || api_is_drh()) {
  30. $url_dir = 'work_list_all.php?id='.$my_folder_data['id'];
  31. } else {
  32. $url_dir = 'work_list.php?id='.$my_folder_data['id'];
  33. }
  34. $interbreadcrumb[] = array('url' => $url_dir, 'name' => $my_folder_data['title']);
  35. $interbreadcrumb[] = array('url' => '#','name' => $work['title']);
  36. //|| api_is_drh()
  37. if (($courseInfo['show_score'] == 0 &&
  38. $work['active'] == 1 &&
  39. $work['accepted'] == 1
  40. ) ||
  41. (api_is_allowed_to_edit() || api_is_coach()) ||
  42. user_is_author($id) ||
  43. $isDrhOfCourse
  44. ) {
  45. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  46. $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
  47. if ($page == 'edit') {
  48. $url = api_get_path(WEB_CODE_PATH).'work/edit.php?id='.$my_folder_data['id'].'&item_id='.$work['id'].'&'.api_get_cidreq();
  49. } else {
  50. $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();
  51. }
  52. switch ($action) {
  53. case 'send_comment':
  54. if (isset($_FILES["file"])) {
  55. $_POST['file'] = $_FILES["file"];
  56. }
  57. addWorkComment(
  58. api_get_course_info(),
  59. api_get_user_id(),
  60. $my_folder_data,
  61. $work,
  62. $_POST
  63. );
  64. Display::addFlash(Display::return_message(get_lang('CommentCreated')));
  65. header('Location: '.$url);
  66. exit;
  67. break;
  68. case 'delete_attachment':
  69. deleteCommentFile(
  70. $_REQUEST['comment_id'],
  71. api_get_course_info()
  72. );
  73. Display::addFlash(Display::return_message(get_lang('DocDeleted')));
  74. header('Location: '.$url);
  75. exit;
  76. break;
  77. }
  78. $comments = getWorkComments($work);
  79. $commentForm = getWorkCommentForm($work);
  80. $tpl = new Template();
  81. $tpl->assign('work', $work);
  82. $tpl->assign('comments', $comments);
  83. if (api_is_allowed_to_session_edit()) {
  84. $tpl->assign('form', $commentForm);
  85. }
  86. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  87. $template = $tpl->get_template('work/view.tpl');
  88. $content = $tpl->fetch($template);
  89. $tpl->assign('content', $content);
  90. $tpl->display_one_col_template();
  91. } else {
  92. api_not_allowed(true);
  93. }
  94. } else {
  95. api_not_allowed(true);
  96. }