upload.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. require_once '../inc/global.inc.php';
  5. $current_course_tool = TOOL_STUDENTPUBLICATION;
  6. api_protect_course_script(true);
  7. // Including necessary files
  8. require_once 'work.lib.php';
  9. $this_section = SECTION_COURSES;
  10. $work_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
  11. $is_allowed_to_edit = api_is_allowed_to_edit();
  12. $course_id = api_get_course_int_id();
  13. $user_id = api_get_user_id();
  14. $userInfo = api_get_user_info();
  15. $session_id = api_get_session_id();
  16. $course_info = api_get_course_info();
  17. $course_code = $course_info['code'];
  18. $group_id = api_get_group_id();
  19. if (empty($work_id)) {
  20. api_not_allowed(true);
  21. }
  22. protectWork($course_info, $work_id);
  23. $workInfo = get_work_data_by_id($work_id);
  24. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_id, $session_id);
  25. $is_course_member = $is_course_member || api_is_platform_admin();
  26. if ($is_course_member == false || api_is_invitee()) {
  27. api_not_allowed(true);
  28. }
  29. $check = Security::check_token('post');
  30. $token = Security::get_token();
  31. $student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
  32. // @todo add an option to allow/block multiple attempts.
  33. /*
  34. if (!empty($workInfo) && !empty($workInfo['qualification'])) {
  35. $count = get_work_count_by_student($user_id, $work_id);
  36. if ($count >= 1) {
  37. Display::display_header();
  38. if (api_get_course_setting('student_delete_own_publication') == '1') {
  39. Display::display_warning_message(get_lang('CantUploadDeleteYourPaperFirst'));
  40. } else {
  41. Display::display_warning_message(get_lang('YouAlreadySentAPaperYouCantUpload'));
  42. }
  43. Display::display_footer();
  44. exit;
  45. }
  46. }*/
  47. $homework = get_work_assignment_by_id($workInfo['id']);
  48. $validationStatus = getWorkDateValidationStatus($homework);
  49. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications'));
  50. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$work_id, 'name' => $workInfo['title']);
  51. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('UploadADocument'));
  52. $form = new FormValidator('form', 'POST', api_get_self()."?".api_get_cidreq()."&id=".$work_id, '', array('enctype' => "multipart/form-data"));
  53. setWorkUploadForm($form, $workInfo['allow_text_assignment']);
  54. $form->addElement('hidden', 'id', $work_id);
  55. $form->addElement('hidden', 'sec_token', $token);
  56. $error_message = null;
  57. $succeed = false;
  58. if ($form->validate()) {
  59. if ($student_can_edit_in_session && $check) {
  60. $values = $form->getSubmitValues();
  61. // Process work
  62. $error_message = processWorkForm(
  63. $workInfo,
  64. $values,
  65. $course_info,
  66. $session_id,
  67. $group_id,
  68. $user_id
  69. );
  70. $script = 'work_list.php';
  71. if ($is_allowed_to_edit) {
  72. $script = 'work_list_all.php';
  73. }
  74. if (!empty($error_message)) {
  75. Session::write('error_message', $error_message);
  76. }
  77. header('Location: '.api_get_path(WEB_CODE_PATH).'work/'.$script.'?'.api_get_cidreq().'&id='.$work_id);
  78. exit;
  79. } else {
  80. // Bad token or can't add works
  81. $error_message = Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error');
  82. }
  83. }
  84. $htmlHeadXtra[] = to_javascript_work();
  85. Display :: display_header(null);
  86. if (!empty($work_id)) {
  87. echo $validationStatus['message'];
  88. if ($is_allowed_to_edit) {
  89. if (api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION)) {
  90. echo Display::display_warning_message(get_lang('ResourceLockedByGradebook'));
  91. } else {
  92. $form->display();
  93. }
  94. } elseif ($student_can_edit_in_session && $validationStatus['has_ended'] == false) {
  95. $form->display();
  96. } else {
  97. Display::display_error_message(get_lang('ActionNotAllowed'));
  98. }
  99. } else {
  100. Display::display_error_message(get_lang('ActionNotAllowed'));
  101. }
  102. Display :: display_footer();