view.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file = array('exercice', 'work', 'document', 'admin');
  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. $interbreadcrumb[] = array ('url' => 'work.php', 'name' => get_lang('StudentPublications'));
  16. $my_folder_data = get_work_data_by_id($work['parent_id']);
  17. $courseInfo = api_get_course_info();
  18. allowOnlySubscribedUser(
  19. api_get_user_id(),
  20. $work['parent_id'],
  21. $courseInfo['real_id']
  22. );
  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 = 'work_list_all.php?id='.$my_folder_data['id'];
  36. } else {
  37. $url_dir = 'work_list.php?id='.$my_folder_data['id'];
  38. }
  39. $interbreadcrumb[] = array('url' => $url_dir, 'name' => $my_folder_data['title']);
  40. $interbreadcrumb[] = array('url' => '#','name' => $work['title']);
  41. //|| api_is_drh()
  42. if (($courseInfo['show_score'] == 0 &&
  43. $work['active'] == 1 &&
  44. $work['accepted'] == 1
  45. ) ||
  46. (api_is_allowed_to_edit() || api_is_coach()) ||
  47. user_is_author($id) ||
  48. $isDrhOfCourse
  49. ) {
  50. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  51. switch ($action) {
  52. case 'send_comment':
  53. if (isset($_FILES["file"])) {
  54. $_POST['file'] = $_FILES["file"];
  55. }
  56. addWorkComment(
  57. api_get_course_info(),
  58. api_get_user_id(),
  59. $my_folder_data,
  60. $work,
  61. $_POST
  62. );
  63. $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();
  64. header('Location: '.$url);
  65. exit;
  66. break;
  67. case 'delete_attachment':
  68. deleteCommentFile(
  69. $_REQUEST['comment_id'],
  70. api_get_course_info()
  71. );
  72. $url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();
  73. header('Location: '.$url);
  74. exit;
  75. break;
  76. }
  77. $comments = getWorkComments($work);
  78. $commentForm = getWorkCommentForm($work);
  79. $tpl = new Template();
  80. $tpl->assign('work', $work);
  81. $tpl->assign('work_comment_enabled', ALLOW_USER_COMMENTS);
  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. }