create_backup.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Create a backup.
  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. api_check_archive_dir();
  13. // Check access rights (only teachers are allowed here)
  14. if (!api_is_allowed_to_edit()) {
  15. api_not_allowed(true);
  16. }
  17. // Remove memory and time limits as much as possible as this might be a long process...
  18. if (function_exists('ini_set')) {
  19. api_set_memory_limit('256M');
  20. ini_set('max_execution_time', 1800);
  21. }
  22. // Section for the tabs
  23. $this_section = SECTION_COURSES;
  24. // Breadcrumbs
  25. $interbreadcrumb[] = array(
  26. 'url' => '../course_info/maintenance.php',
  27. 'name' => get_lang('Maintenance')
  28. );
  29. // Displaying the header
  30. $nameTools = get_lang('CreateBackup');
  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/CourseRestorer.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 (Security::check_token('post') && (
  41. (
  42. isset($_POST['action']) &&
  43. $_POST['action'] == 'course_select_form'
  44. ) || (
  45. isset($_POST['backup_option']) &&
  46. $_POST['backup_option'] == 'full_backup'
  47. )
  48. )
  49. ) {
  50. // Clear token
  51. Security::clear_token();
  52. if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
  53. $course = CourseSelectForm::get_posted_course();
  54. } else {
  55. $cb = new CourseBuilder();
  56. $course = $cb->build();
  57. }
  58. $zip_file = CourseArchiver::write_course($course);
  59. Display::display_confirmation_message(get_lang('BackupCreated'));
  60. echo '<br /><a class="btn btn-primary btn-large" href="' . api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive=' . $zip_file . '&' . api_get_cidreq() . '">
  61. ' . get_lang('Download') . '</a>';
  62. } elseif (Security::check_token('post') && (
  63. isset($_POST['backup_option']) &&
  64. $_POST['backup_option'] == 'select_items'
  65. )
  66. ) {
  67. // Clear token
  68. Security::clear_token();
  69. $cb = new CourseBuilder('partial');
  70. $course = $cb->build();
  71. // Add token to Course select form
  72. $hiddenFields['sec_token'] = Security::get_token();
  73. CourseSelectForm::display_form($course, $hiddenFields);
  74. } else {
  75. $cb = new CourseBuilder();
  76. $course = $cb->build();
  77. if (!$course->has_resources()) {
  78. echo get_lang('NoResourcesToBackup');
  79. } else {
  80. $form = new FormValidator('create_backup_form', 'post', api_get_self() . '?' . api_get_cidreq());
  81. $form->addElement('header', get_lang('SelectOptionForBackup'));
  82. $form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
  83. $form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
  84. $form->addButtonSave(get_lang('CreateBackup'));
  85. $form->add_progress_bar();
  86. // When progress bar appears we have to hide the title "Please select a backup-option".
  87. $form->updateAttributes(
  88. array(
  89. 'onsubmit' => str_replace(
  90. 'javascript: ',
  91. 'javascript: page_title = getElementById(\'page_title\'); if (page_title) { setTimeout(\'page_title.style.display = \\\'none\\\';\', 2000); } ',
  92. $form->getAttribute('onsubmit')
  93. )
  94. )
  95. );
  96. $values['backup_option'] = 'full_backup';
  97. $form->setDefaults($values);
  98. // Add Security token
  99. $token = Security::get_token();
  100. $form->addElement('hidden', 'sec_token');
  101. $form->setConstants(array('sec_token' => $token));
  102. $form->display();
  103. }
  104. }
  105. Display::display_footer();