edit_work.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. api_protect_course_script(true);
  5. $lib_path = api_get_path(LIBRARY_PATH);
  6. /* Libraries */
  7. require_once 'work.lib.php';
  8. // Section (for the tabs)
  9. $this_section = SECTION_COURSES;
  10. if (!api_is_allowed_to_edit()) {
  11. api_not_allowed(true);
  12. }
  13. $blockEdition = api_get_configuration_value('block_student_publication_edition');
  14. if ($blockEdition && !api_is_platform_admin()) {
  15. api_not_allowed(true);
  16. }
  17. $courseInfo = api_get_course_info();
  18. $sessionId = api_get_session_id();
  19. $groupId = api_get_group_id();
  20. $workId = isset($_GET['id']) ? intval($_GET['id']) : null;
  21. $workData = get_work_data_by_id($workId);
  22. $homework = get_work_assignment_by_id($workId);
  23. $locked = api_resource_is_locked_by_gradebook($workId, LINK_STUDENTPUBLICATION);
  24. if (api_is_platform_admin() == false && $locked == true) {
  25. api_not_allowed(true);
  26. }
  27. $htmlHeadXtra[] = to_javascript_work();
  28. $interbreadcrumb[] = [
  29. 'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
  30. 'name' => get_lang('StudentPublications'),
  31. ];
  32. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
  33. $form = new FormValidator(
  34. 'edit_dir',
  35. 'post',
  36. api_get_path(WEB_CODE_PATH).'work/edit_work.php?id='.$workId.'&'.api_get_cidreq()
  37. );
  38. $form->addElement('header', get_lang('Edit'));
  39. $title = !empty($workData['title']) ? $workData['title'] : basename($workData['url']);
  40. $defaults = $workData;
  41. $defaults['new_dir'] = Security::remove_XSS($title);
  42. $there_is_a_end_date = false;
  43. if (Gradebook::is_active()) {
  44. $link_info = GradebookUtils::isResourceInCourseGradebook(
  45. api_get_course_id(),
  46. LINK_STUDENTPUBLICATION,
  47. $workId
  48. );
  49. if (!empty($link_info)) {
  50. $defaults['weight'] = $link_info['weight'];
  51. $defaults['category_id'] = $link_info['category_id'];
  52. $defaults['make_calification'] = 1;
  53. }
  54. } else {
  55. $defaults['category_id'] = '';
  56. }
  57. if (!empty($homework['expires_on'])) {
  58. $homework['expires_on'] = api_get_local_time($homework['expires_on']);
  59. $defaults['enableExpiryDate'] = true;
  60. $defaults['expires_on'] = $homework['expires_on'];
  61. } else {
  62. $homework['expires_on'] = null;
  63. }
  64. if (!empty($homework['ends_on'])) {
  65. $homework['ends_on'] = api_get_local_time($homework['ends_on']);
  66. $defaults['ends_on'] = $homework['ends_on'];
  67. $defaults['enableEndDate'] = true;
  68. } else {
  69. $homework['ends_on'] = null;
  70. $defaults['enableEndDate'] = false;
  71. $defaults['ends_on'] = null;
  72. }
  73. $defaults['add_to_calendar'] = isset($homework['add_to_calendar']) ? $homework['add_to_calendar'] : null;
  74. $form = getFormWork($form, $defaults, $workId);
  75. $form->addElement('hidden', 'work_id', $workId);
  76. $form->addButtonUpdate(get_lang('ModifyDirectory'));
  77. $currentUrl = api_get_path(WEB_CODE_PATH).'work/edit_work.php?id='.$workId.'&'.api_get_cidreq();
  78. if ($form->validate()) {
  79. $params = $form->getSubmitValues();
  80. $params['enableEndDate'] = isset($params['enableEndDate']) ? true : false;
  81. $params['enableExpiryDate'] = isset($params['enableExpiryDate']) ? true : false;
  82. if ($params['enableExpiryDate'] &&
  83. $params['enableEndDate']
  84. ) {
  85. if ($params['expires_on'] > $params['ends_on']) {
  86. Display::addFlash(
  87. Display::return_message(
  88. get_lang('DateExpiredNotBeLessDeadLine'),
  89. 'warning'
  90. )
  91. );
  92. header('Location: '.$currentUrl);
  93. exit;
  94. }
  95. }
  96. $workId = $params['work_id'];
  97. $editCheck = false;
  98. $workData = get_work_data_by_id($workId);
  99. if (!empty($workData)) {
  100. $editCheck = true;
  101. } else {
  102. $editCheck = true;
  103. }
  104. if ($editCheck) {
  105. updateWork($workData['iid'], $params, $courseInfo, $sessionId);
  106. updatePublicationAssignment($workId, $params, $courseInfo, $groupId);
  107. updateDirName($workData, $params['new_dir']);
  108. Skill::saveSkills($form, ITEM_TYPE_STUDENT_PUBLICATION, $workData['iid']);
  109. Display::addFlash(Display::return_message(get_lang('Updated'), 'success'));
  110. header('Location: '.$currentUrl);
  111. exit;
  112. } else {
  113. Display::addFlash(Display::return_message(get_lang('FileExists'), 'warning'));
  114. }
  115. }
  116. Display::display_header();
  117. $form->display();
  118. Display :: display_footer();