create_backup.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  37. require_once 'classes/CourseBuilder.class.php';
  38. require_once 'classes/CourseArchiver.class.php';
  39. require_once 'classes/CourseRestorer.class.php';
  40. require_once 'classes/CourseSelectForm.class.php';
  41. // Display the tool title
  42. echo Display::page_header($nameTools);
  43. /* MAIN CODE */
  44. if ((isset($_POST['action']) &&
  45. $_POST['action'] == 'course_select_form') ||
  46. (isset($_POST['backup_option']) &&
  47. $_POST['backup_option'] == 'full_backup')
  48. ) {
  49. if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
  50. $course = CourseSelectForm::get_posted_course();
  51. } else {
  52. $cb = new CourseBuilder();
  53. $course = $cb->build();
  54. }
  55. $zip_file = CourseArchiver::write_course($course);
  56. Display::display_confirmation_message(get_lang('BackupCreated'));
  57. echo '<br /><a class="btn btn-primary btn-large" href="../course_info/download.php?archive='.$zip_file.'">'.get_lang('Download').'</a>';
  58. } elseif (isset($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
  59. $cb = new CourseBuilder('partial');
  60. $course = $cb->build();
  61. CourseSelectForm::display_form($course);
  62. } else {
  63. $cb = new CourseBuilder();
  64. $course = $cb->build();
  65. if (!$course->has_resources()) {
  66. echo get_lang('NoResourcesToBackup');
  67. } else {
  68. $form = new FormValidator('create_backup_form', 'post', api_get_self().'?'.api_get_cidreq());
  69. $form->addElement('header',get_lang('SelectOptionForBackup'));
  70. $form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
  71. $form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
  72. $form->addElement('style_submit_button', null, get_lang('CreateBackup'), 'class="save"');
  73. $form->add_progress_bar();
  74. // When progress bar appears we have to hide the title "Please select a backup-option".
  75. $form->updateAttributes(
  76. array('onsubmit' => str_replace(
  77. 'javascript: ',
  78. 'javascript: page_title = getElementById(\'page_title\'); if (page_title) { setTimeout(\'page_title.style.display = \\\'none\\\';\', 2000); } ',
  79. $form->getAttribute('onsubmit')
  80. ))
  81. );
  82. $values['backup_option'] = 'full_backup';
  83. $form->setDefaults($values);
  84. $form->display();
  85. }
  86. }
  87. Display::display_footer();