edit_work.php 3.7 KB

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