recycle_course.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
  4. use Chamilo\CourseBundle\Component\CourseCopy\CourseRecycler;
  5. use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
  6. /**
  7. * Delete resources from a course.
  8. *
  9. * @author Bart Mollet <bart.mollet@hogent.be>
  10. *
  11. * @package chamilo.backup
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. $current_course_tool = TOOL_COURSE_MAINTENANCE;
  15. api_protect_course_script(true);
  16. // Check access rights (only teachers are allowed here)
  17. if (!api_is_allowed_to_edit()) {
  18. api_not_allowed(true);
  19. }
  20. // Section for the tabs
  21. $this_section = SECTION_COURSES;
  22. // Breadcrumbs
  23. $interbreadcrumb[] = [
  24. 'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php',
  25. 'name' => get_lang('Backup'),
  26. ];
  27. // Displaying the header
  28. $nameTools = get_lang('Empty this course');
  29. Display::display_header($nameTools);
  30. // Display the tool title
  31. echo Display::page_header($nameTools);
  32. $action = isset($_POST['action']) ? $_POST['action'] : '';
  33. if (Security::check_token('post') && (
  34. $action === 'course_select_form' ||
  35. (
  36. isset($_POST['recycle_option']) &&
  37. $_POST['recycle_option'] == 'full_backup'
  38. )
  39. )
  40. ) {
  41. // Clear token
  42. Security::clear_token();
  43. if (isset($_POST['action']) && $_POST['action'] === 'course_select_form') {
  44. $course = CourseSelectForm::get_posted_course();
  45. } else {
  46. $cb = new CourseBuilder();
  47. $course = $cb->build();
  48. }
  49. $recycle_type = '';
  50. if (isset($_POST['recycle_option']) && $_POST['recycle_option'] === 'full_backup') {
  51. $recycle_type = 'full_backup';
  52. } elseif (isset($_POST['action']) && $_POST['action'] === 'course_select_form') {
  53. $recycle_type = 'select_items';
  54. }
  55. $cr = new CourseRecycler($course);
  56. $cr->recycle($recycle_type);
  57. echo Display::return_message(get_lang('Recycle is finished'), 'confirm');
  58. } elseif (Security::check_token('post') && (
  59. isset($_POST['recycle_option']) &&
  60. $_POST['recycle_option'] === 'select_items'
  61. )
  62. ) {
  63. // Clear token
  64. Security::clear_token();
  65. $cb = new CourseBuilder();
  66. $course = $cb->build();
  67. // Add token to Course select form
  68. $hiddenFields['sec_token'] = Security::get_token();
  69. CourseSelectForm::display_form($course, $hiddenFields);
  70. } else {
  71. $cb = new CourseBuilder();
  72. $course = $cb->build();
  73. if (!$course->has_resources()) {
  74. echo get_lang('No resource to recycle');
  75. } else {
  76. echo Display::return_message(get_lang('Warning: using this tool, you will delete learning objects in your course. There is no UNDO possible. We advise you to create a <a href="create_backup.php">backup</a> before.'), 'warning', false);
  77. $form = new FormValidator('recycle_course', 'post', api_get_self().'?'.api_get_cidreq());
  78. $form->addElement('header', get_lang('Please select a backup option'));
  79. $form->addElement('radio', 'recycle_option', null, get_lang('Delete everything'), 'full_backup');
  80. $form->addElement('radio', 'recycle_option', null, get_lang('Let me select learning objects'), 'select_items');
  81. $form->addButtonSave(get_lang('Empty this course'));
  82. $form->setDefaults(['recycle_option' => 'select_items']);
  83. // Add Security token
  84. $token = Security::get_token();
  85. $form->addElement('hidden', 'sec_token');
  86. $form->setConstants(['sec_token' => $token]);
  87. $form->display();
  88. }
  89. }
  90. // Display the footer
  91. Display::display_footer();