edit_work.php 4.0 KB

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