create_backup.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // Language files that need to be included
  10. $language_file = array('exercice', 'admin', 'coursebackup');
  11. // Including the global initialization file
  12. require_once '../inc/global.inc.php';
  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. ini_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('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
  26. // Displaying the header
  27. $nameTools = get_lang('CreateBackup');
  28. Display::display_header($nameTools);
  29. // Include additional libraries
  30. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  31. require_once 'classes/CourseBuilder.class.php';
  32. require_once 'classes/CourseArchiver.class.php';
  33. require_once 'classes/CourseRestorer.class.php';
  34. require_once 'classes/CourseSelectForm.class.php';
  35. // Display the tool title
  36. api_display_tool_title($nameTools);
  37. /* MAIN CODE */
  38. if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) {
  39. if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
  40. $course = CourseSelectForm :: get_posted_course();
  41. } else {
  42. $cb = new CourseBuilder();
  43. $course = $cb->build();
  44. }
  45. $zip_file = CourseArchiver :: write_course($course);
  46. Display::display_confirmation_message(get_lang('BackupCreated'));
  47. echo '<br /><a class="a_button orange medium" href="../course_info/download.php?archive='.$zip_file.'">'.get_lang('Download').'</a>';
  48. ?>
  49. <!-- Manual download <script language="JavaScript">
  50. setTimeout('download_backup()',2000);
  51. function download_backup()
  52. {
  53. window.location="../course_info/download.php?archive=<?php echo $zip_file; ?>";
  54. }
  55. </script> //-->
  56. <?php
  57. } elseif (isset($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
  58. $cb = new CourseBuilder('partial');
  59. $course = $cb->build();
  60. CourseSelectForm :: display_form($course);
  61. } else {
  62. $cb = new CourseBuilder();
  63. $course = $cb->build();
  64. if (!$course->has_resources()) {
  65. echo get_lang('NoResourcesToBackup');
  66. } else {
  67. echo '<span id="page_title">'.get_lang('SelectOptionForBackup').'</span><br /><br />';
  68. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  69. $form = new FormValidator('create_backup_form', 'post');
  70. $renderer = $form->defaultRenderer();
  71. $renderer->setElementTemplate('<div>{element}</div> ');
  72. $form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
  73. $form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
  74. $form->addElement('html', '<br />');
  75. $form->addElement('style_submit_button', null, get_lang('CreateBackup'), 'class="save"');
  76. $form->add_progress_bar();
  77. // When progress bar appears we have to hide the title "Please select a backup-option".
  78. $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'))));
  79. $values['backup_option'] = 'full_backup';
  80. $form->setDefaults($values);
  81. $form->display();
  82. }
  83. }
  84. /* FOOTER */
  85. Display::display_footer();