recycle_course.php 3.3 KB

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