upload.php 4.5 KB

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