recycle_course.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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(
  26. 'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php',
  27. 'name' => get_lang('Maintenance')
  28. );
  29. // Displaying the header
  30. $nameTools = get_lang('RecycleCourse');
  31. Display::display_header($nameTools);
  32. // Include additional libraries
  33. require_once 'classes/CourseBuilder.class.php';
  34. require_once 'classes/CourseArchiver.class.php';
  35. require_once 'classes/CourseRecycler.class.php';
  36. require_once 'classes/CourseSelectForm.class.php';
  37. // Display the tool title
  38. echo Display::page_header($nameTools);
  39. /* MAIN CODE */
  40. if ((isset($_POST['action']) &&
  41. $_POST['action'] == 'course_select_form') ||
  42. (isset($_POST['recycle_option']) &&
  43. $_POST['recycle_option'] == 'full_backup')
  44. ) {
  45. if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
  46. $course = CourseSelectForm::get_posted_course();
  47. } else {
  48. $cb = new CourseBuilder();
  49. $course = $cb->build();
  50. }
  51. $recycle_type = "";
  52. if (isset($_POST['recycle_option']) && $_POST['recycle_option'] == 'full_backup') {
  53. $recycle_type = 'full_backup';
  54. } else if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
  55. $recycle_type = 'select_items';
  56. }
  57. $cr = new CourseRecycler($course);
  58. $cr->recycle($recycle_type);
  59. Display::display_confirmation_message(get_lang('RecycleFinished'));
  60. } elseif (isset($_POST['recycle_option']) && $_POST['recycle_option'] == 'select_items') {
  61. $cb = new CourseBuilder();
  62. $course = $cb->build();
  63. CourseSelectForm::display_form($course);
  64. } else {
  65. $cb = new CourseBuilder();
  66. $course = $cb->build();
  67. if (!$course->has_resources()) {
  68. echo get_lang('NoResourcesToRecycle');
  69. } else {
  70. Display::display_warning_message(get_lang('RecycleWarning'), false);
  71. $form = new FormValidator('recycle_course', 'post', api_get_self().'?'.api_get_cidreq());
  72. $form->addElement('header', get_lang('SelectOptionForBackup'));
  73. $form->addElement('radio', 'recycle_option', null, get_lang('FullRecycle'), 'full_backup');
  74. $form->addElement('radio', 'recycle_option', null, get_lang('LetMeSelectItems'), 'select_items');
  75. $form->addElement('style_submit_button', 'submit', get_lang('RecycleCourse'), 'class="save"');
  76. $form->setDefaults(array('recycle_option' => 'select_items'));
  77. $form->display();
  78. }
  79. }
  80. // Display the footer
  81. Display::display_footer();