recycle_course.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Delete resources from a course.
  5. *
  6. * @author Bart Mollet <bart.mollet@hogent.be>
  7. * @package chamilo.backup
  8. */
  9. /**
  10. * Code
  11. */
  12. // Language files that need to be included
  13. $language_file = array ('exercice', 'admin', 'course_info', 'coursebackup');
  14. // Including the global initialization file
  15. require_once '../inc/global.inc.php';
  16. $current_course_tool = TOOL_COURSE_MAINTENANCE;
  17. api_protect_course_script(true);
  18. // Check access rights (only teachers are allowed here)
  19. if (!api_is_allowed_to_edit()) {
  20. api_not_allowed(true);
  21. }
  22. // Section for the tabs
  23. $this_section = SECTION_COURSES;
  24. // Breadcrumbs
  25. $interbreadcrumb[] = array('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
  26. // Displaying the header
  27. $nameTools = get_lang('RecycleCourse');
  28. Display::display_header($nameTools);
  29. // Include additional libraries
  30. require_once 'classes/CourseBuilder.class.php';
  31. require_once 'classes/CourseArchiver.class.php';
  32. require_once 'classes/CourseRecycler.class.php';
  33. require_once 'classes/CourseSelectForm.class.php';
  34. // Display the tool title
  35. echo Display::page_header($nameTools);
  36. /* MAIN CODE */
  37. if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['recycle_option']) && $_POST['recycle_option'] == 'full_backup')) {
  38. if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
  39. $course = CourseSelectForm::get_posted_course();
  40. } else {
  41. $cb = new CourseBuilder();
  42. $course = $cb->build();
  43. }
  44. $recycle_type = "";
  45. if (isset($_POST['recycle_option']) && $_POST['recycle_option'] == 'full_backup') {
  46. $recycle_type = 'full_backup';
  47. }
  48. else if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
  49. $recycle_type = 'select_items';
  50. }
  51. $cr = new CourseRecycler($course);
  52. $cr->recycle($recycle_type);
  53. Display::display_confirmation_message(get_lang('RecycleFinished'));
  54. } elseif (isset($_POST['recycle_option']) && $_POST['recycle_option'] == 'select_items') {
  55. $cb = new CourseBuilder();
  56. $course = $cb->build();
  57. CourseSelectForm::display_form($course);
  58. } else {
  59. $cb = new CourseBuilder();
  60. $course = $cb->build();
  61. if (!$course->has_resources()) {
  62. echo get_lang('NoResourcesToRecycle');
  63. } else {
  64. Display::display_warning_message(get_lang('RecycleWarning'), false);
  65. $form = new FormValidator('recycle_course', 'post', 'recycle_course.php?'.api_get_cidreq());
  66. $form->addElement('header', get_lang('SelectOptionForBackup'));
  67. $form->addElement('radio', 'recycle_option', null, get_lang('FullRecycle'), 'full_backup');
  68. $form->addElement('radio', 'recycle_option', null, get_lang('LetMeSelectItems'), 'select_items');
  69. $form->addElement('style_submit_button', 'submit', get_lang('RecycleCourse'), 'class="save"');
  70. $form->setDefaults(array('recycle_option' => 'select_items'));
  71. $form->display();
  72. }
  73. }
  74. // Display the footer
  75. Display::display_footer();