edit_work.php 3.9 KB

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