edit_work.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once '../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. $there_is_a_expire_date = true;
  55. $defaults['enableExpiryDate'] = true;
  56. } else {
  57. $homework['expires_on'] = null;
  58. $there_is_a_expire_date = false;
  59. }
  60. if (!empty($homework['ends_on'])) {
  61. $homework['ends_on'] = api_get_local_time($homework['ends_on']);
  62. $there_is_a_end_date = true;
  63. $defaults['enableEndDate'] = true;
  64. } else {
  65. $homework['ends_on'] = null;
  66. $there_is_a_end_date = false;
  67. }
  68. if ($there_is_a_end_date) {
  69. $defaults['ends_on'] = $homework['ends_on'];
  70. }
  71. if ($there_is_a_expire_date) {
  72. $defaults['expires_on'] = $homework['expires_on'];
  73. }
  74. $defaults['add_to_calendar'] = isset($homework['add_to_calendar']) ? $homework['add_to_calendar'] : null;
  75. $form = getFormWork($form, $defaults);
  76. $form->addElement('hidden', 'work_id', $workId);
  77. $form->addButtonUpdate(get_lang('ModifyDirectory'));
  78. if ($form->validate()) {
  79. $params = $form->getSubmitValues();
  80. $workId = $params['work_id'];
  81. $editCheck = false;
  82. $workData = get_work_data_by_id($workId);
  83. if (!empty($workData)) {
  84. $editCheck = true;
  85. } else {
  86. $editCheck = true;
  87. }
  88. if ($editCheck) {
  89. updateWork($workData['iid'], $params, $courseInfo, $sessionId);
  90. updatePublicationAssignment($workId, $params, $courseInfo, $groupId);
  91. updateDirName($workData, $params['new_dir']);
  92. $currentUrl = api_get_path(WEB_CODE_PATH).'work/edit_work.php?id='.$workId.'&'.api_get_cidreq();
  93. Display::addFlash(Display::return_message(get_lang('FolderEdited'), 'success'));
  94. header('Location: '.$currentUrl);
  95. exit;
  96. } else {
  97. Display::addFlash(Display::return_message(get_lang('FileExists'), 'warning'));
  98. }
  99. }
  100. Display::display_header();
  101. $form->display();
  102. Display :: display_footer();