recycle_course.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 '../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. /* MAIN CODE */
  32. if (Security::check_token('post') && (
  33. isset($_POST['action']) &&
  34. $_POST['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. } else if (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. Display::display_confirmation_message(get_lang('RecycleFinished'));
  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('NoResourcesToRecycle');
  75. } else {
  76. Display::display_warning_message(get_lang('RecycleWarning'), false);
  77. $form = new FormValidator('recycle_course', 'post', api_get_self().'?'.api_get_cidreq());
  78. $form->addElement('header', get_lang('SelectOptionForBackup'));
  79. $form->addElement('radio', 'recycle_option', null, get_lang('FullRecycle'), 'full_backup');
  80. $form->addElement('radio', 'recycle_option', null, get_lang('LetMeSelectItems'), 'select_items');
  81. $form->addButtonSave(get_lang('RecycleCourse'));
  82. $form->setDefaults(array('recycle_option' => 'select_items'));
  83. // Add Security token
  84. $token = Security::get_token();
  85. $form->addElement('hidden', 'sec_token');
  86. $form->setConstants(array('sec_token' => $token));
  87. $form->display();
  88. }
  89. }
  90. // Display the footer
  91. Display::display_footer();