recycle_course.php 3.3 KB

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