create_backup.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. // $Id: create_backup.php 13315 2007-09-27 08:17:12Z yannoo $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Bart Mollet (bart.mollet@hogent.be)
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. * ==============================================================================
  23. * Create a backup.
  24. *
  25. * @author Bart Mollet <bart.mollet@hogent.be>
  26. * @package dokeos.backup
  27. * ==============================================================================
  28. */
  29. // name of the language file that needs to be included
  30. $language_file = array ('admin','coursebackup');
  31. // including the global file
  32. include ('../inc/global.inc.php');
  33. // Check access rights (only teachers are allowed here)
  34. if (!api_is_allowed_to_edit())
  35. {
  36. api_not_allowed(true);
  37. }
  38. //remove memory and time limits as much as possible as this might be a long process...
  39. if(function_exists('ini_set'))
  40. {
  41. ini_set('memory_limit','256M');
  42. ini_set('max_execution_time',1800);
  43. }
  44. // section for the tabs
  45. $this_section=SECTION_COURSES;
  46. // breadcrumbs
  47. $interbreadcrumb[] = array ("url" => "../course_info/maintenance.php", "name" => get_lang('Maintenance'));
  48. // Displaying the header
  49. $nameTools = get_lang('CreateBackup');
  50. Display::display_header($nameTools);
  51. // include additional libraries
  52. include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
  53. require_once ('classes/CourseBuilder.class.php');
  54. require_once ('classes/CourseArchiver.class.php');
  55. require_once ('classes/CourseRestorer.class.php');
  56. require_once ('classes/CourseSelectForm.class.php');
  57. // Display the tool title
  58. api_display_tool_title($nameTools);
  59. /*
  60. ==============================================================================
  61. MAIN CODE
  62. ==============================================================================
  63. */
  64. if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup'))
  65. {
  66. if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form')
  67. {
  68. $course = CourseSelectForm :: get_posted_course();
  69. }
  70. else
  71. {
  72. $cb = new CourseBuilder();
  73. $course = $cb->build();
  74. }
  75. $zip_file = CourseArchiver :: write_course($course);
  76. Display::display_confirmation_message(get_lang('BackupCreated').'<br/><br/><a href="../course_info/download.php?archive='.$zip_file.'">'.$zip_file.'</a>', false);
  77. echo '<p><a href="../course_home/course_home.php">&lt;&lt; '.get_lang('CourseHomepage').'</a></p>';
  78. ?>
  79. <!-- Manual download <script language="JavaScript">
  80. setTimeout('download_backup()',2000);
  81. function download_backup()
  82. {
  83. window.location="../course_info/download.php?archive=<?php echo $zip_file ?>";
  84. }
  85. </script> //-->
  86. <?php
  87. }
  88. elseif (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'select_items')
  89. {
  90. $cb = new CourseBuilder();
  91. $course = $cb->build();
  92. CourseSelectForm :: display_form($course);
  93. }
  94. else
  95. {
  96. $cb = new CourseBuilder();
  97. $course = $cb->build();
  98. if (!$course->has_resources())
  99. {
  100. echo get_lang('NoResourcesToBackup');
  101. }
  102. else
  103. {
  104. echo get_lang('SelectOptionForBackup');
  105. include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  106. $form = new FormValidator('create_backup_form','POST');
  107. $renderer = $form->defaultRenderer();
  108. $renderer->setElementTemplate('<div>{element}</div> ');
  109. $form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
  110. $form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
  111. $form->addElement('html','<br/>');
  112. $form->addElement('submit', null, get_lang('CreateBackup'));
  113. $form->add_progress_bar();
  114. $values['backup_option'] = 'full_backup';
  115. $form->setDefaults($values);
  116. $form->display();
  117. }
  118. }
  119. /*
  120. ==============================================================================
  121. FOOTER
  122. ==============================================================================
  123. */
  124. Display::display_footer();
  125. ?>