edit_work.php 3.8 KB

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