create_backup.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // Check access rights (only teachers are allowed here)
  19. if (!api_is_allowed_to_edit()) {
  20. api_not_allowed(true);
  21. }
  22. // Remove memory and time limits as much as possible as this might be a long process...
  23. if (function_exists('ini_set')) {
  24. ini_set('memory_limit', '256M');
  25. ini_set('max_execution_time', 1800);
  26. }
  27. // Section for the tabs
  28. $this_section = SECTION_COURSES;
  29. // Breadcrumbs
  30. $interbreadcrumb[] = array('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
  31. // Displaying the header
  32. $nameTools = get_lang('CreateBackup');
  33. Display::display_header($nameTools);
  34. // Include additional libraries
  35. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  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('Download').'</a>';
  53. } elseif (isset($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
  54. $cb = new CourseBuilder('partial');
  55. $course = $cb->build();
  56. CourseSelectForm :: display_form($course);
  57. } else {
  58. $cb = new CourseBuilder();
  59. $course = $cb->build();
  60. if (!$course->has_resources()) {
  61. echo get_lang('NoResourcesToBackup');
  62. } else {
  63. $form = new FormValidator('create_backup_form', 'post');
  64. $form->addElement('header',get_lang('SelectOptionForBackup'));
  65. $form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
  66. $form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
  67. $form->addElement('style_submit_button', null, get_lang('CreateBackup'), 'class="save"');
  68. $form->add_progress_bar();
  69. // When progress bar appears we have to hide the title "Please select a backup-option".
  70. $form->updateAttributes(array('onsubmit' => str_replace('javascript: ', 'javascript: page_title = getElementById(\'page_title\'); if (page_title) { setTimeout(\'page_title.style.display = \\\'none\\\';\', 2000); } ', $form->getAttribute('onsubmit'))));
  71. $values['backup_option'] = 'full_backup';
  72. $form->setDefaults($values);
  73. $form->display();
  74. }
  75. }
  76. /* FOOTER */
  77. Display::display_footer();