create_backup.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /**
  10. * Code
  11. */
  12. // Language files that need to be included
  13. $language_file = array('exercice', 'admin', '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. api_check_archive_dir();
  19. // Check access rights (only teachers are allowed here)
  20. if (!api_is_allowed_to_edit()) {
  21. api_not_allowed(true);
  22. }
  23. // Remove memory and time limits as much as possible as this might be a long process...
  24. if (function_exists('ini_set')) {
  25. api_set_memory_limit('256M');
  26. ini_set('max_execution_time', 1800);
  27. }
  28. // Section for the tabs
  29. $this_section = SECTION_COURSES;
  30. // Breadcrumbs
  31. $interbreadcrumb[] = array('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
  32. // Displaying the header
  33. $nameTools = get_lang('CreateBackup');
  34. Display::display_header($nameTools);
  35. // Include additional libraries
  36. require_once 'classes/CourseBuilder.class.php';
  37. require_once 'classes/CourseArchiver.class.php';
  38. require_once 'classes/CourseRestorer.class.php';
  39. require_once 'classes/CourseSelectForm.class.php';
  40. // Display the tool title
  41. echo Display::page_header($nameTools);
  42. /* MAIN CODE */
  43. if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) {
  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. $zip_file = CourseArchiver::write_course($course);
  51. Display::display_confirmation_message(get_lang('BackupCreated'));
  52. echo '<br /><a class="btn btn-primary btn-large" href="../course_info/download.php?archive='.$zip_file.'">'.get_lang(
  53. 'Download'
  54. ).'</a>';
  55. } elseif (isset($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
  56. $cb = new CourseBuilder('partial');
  57. $course = $cb->build();
  58. CourseSelectForm::display_form($course);
  59. } else {
  60. $cb = new CourseBuilder();
  61. $course = $cb->build();
  62. if (!$course->has_resources()) {
  63. echo get_lang('NoResourcesToBackup');
  64. } else {
  65. $form = new FormValidator('create_backup_form', 'post', api_get_self().'?'.api_get_cidreq());
  66. $form->addElement('header', get_lang('SelectOptionForBackup'));
  67. $form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
  68. $form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
  69. $form->addElement('style_submit_button', null, get_lang('CreateBackup'), 'class="save"');
  70. $form->add_progress_bar();
  71. // When progress bar appears we have to hide the title "Please select a backup-option".
  72. $form->updateAttributes(
  73. array(
  74. 'onsubmit' => str_replace(
  75. 'javascript: ',
  76. 'javascript: page_title = getElementById(\'page_title\'); if (page_title) { setTimeout(\'page_title.style.display = \\\'none\\\';\', 2000); } ',
  77. $form->getAttribute('onsubmit')
  78. )
  79. )
  80. );
  81. $values['backup_option'] = 'full_backup';
  82. $form->setDefaults($values);
  83. $form->display();
  84. }
  85. }
  86. Display::display_footer();