upload.php 4.5 KB

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