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. /**
  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. // Check access rights (only teachers are allowed here)
  17. if (!api_is_allowed_to_edit()) {
  18. api_not_allowed(true);
  19. }
  20. // Remove memory and time limits as much as possible as this might be a long process...
  21. if (function_exists('ini_set')) {
  22. ini_set('memory_limit', '256M');
  23. ini_set('max_execution_time', 1800);
  24. }
  25. // Section for the tabs
  26. $this_section = SECTION_COURSES;
  27. // Breadcrumbs
  28. $interbreadcrumb[] = array('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
  29. // Displaying the header
  30. $nameTools = get_lang('CreateBackup');
  31. Display::display_header($nameTools);
  32. // Include additional libraries
  33. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  34. require_once 'classes/CourseBuilder.class.php';
  35. require_once 'classes/CourseArchiver.class.php';
  36. require_once 'classes/CourseRestorer.class.php';
  37. require_once 'classes/CourseSelectForm.class.php';
  38. // Display the tool title
  39. api_display_tool_title($nameTools);
  40. /* MAIN CODE */
  41. if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) {
  42. if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
  43. $course = CourseSelectForm :: get_posted_course();
  44. } else {
  45. $cb = new CourseBuilder();
  46. $course = $cb->build();
  47. }
  48. $zip_file = CourseArchiver :: write_course($course);
  49. Display::display_confirmation_message(get_lang('BackupCreated'));
  50. echo '<br /><a class="a_button orange medium" href="../course_info/download.php?archive='.$zip_file.'">'.get_lang('Download').'</a>';
  51. ?>
  52. <!-- Manual download <script language="JavaScript">
  53. setTimeout('download_backup()',2000);
  54. function download_backup()
  55. {
  56. window.location="../course_info/download.php?archive=<?php echo $zip_file; ?>";
  57. }
  58. </script> //-->
  59. <?php
  60. } elseif (isset($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
  61. $cb = new CourseBuilder('partial');
  62. $course = $cb->build();
  63. CourseSelectForm :: display_form($course);
  64. } else {
  65. $cb = new CourseBuilder();
  66. $course = $cb->build();
  67. if (!$course->has_resources()) {
  68. echo get_lang('NoResourcesToBackup');
  69. } else {
  70. echo '<span id="page_title">'.get_lang('SelectOptionForBackup').'</span><br /><br />';
  71. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  72. $form = new FormValidator('create_backup_form', 'post');
  73. $renderer = $form->defaultRenderer();
  74. $renderer->setElementTemplate('<div>{element}</div> ');
  75. $form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
  76. $form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
  77. $form->addElement('html', '<br />');
  78. $form->addElement('style_submit_button', null, get_lang('CreateBackup'), 'class="save"');
  79. $form->add_progress_bar();
  80. // When progress bar appears we have to hide the title "Please select a backup-option".
  81. $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'))));
  82. $values['backup_option'] = 'full_backup';
  83. $form->setDefaults($values);
  84. $form->display();
  85. }
  86. }
  87. /* FOOTER */
  88. Display::display_footer();