copy_course.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.backup
  5. */
  6. /**
  7. * Code
  8. */
  9. // Language files that need to be included
  10. $language_file = array('exercice', 'coursebackup', 'admin');
  11. // Setting the global file that gets the general configuration, the databases, the languages, ...
  12. require_once '../inc/global.inc.php';
  13. // Including additional libraries
  14. require_once 'classes/CourseBuilder.class.php';
  15. require_once 'classes/CourseRestorer.class.php';
  16. require_once 'classes/CourseSelectForm.class.php';
  17. $current_course_tool = TOOL_COURSE_MAINTENANCE;
  18. api_protect_course_script(true);
  19. // Notice for unauthorized people.
  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. //ini_set('post_max_size', "512M");
  28. }
  29. // Breadcrumbs
  30. $interbreadcrumb[] = array('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
  31. // The section (for the tabs)
  32. $this_section = SECTION_COURSES;
  33. // Display the header
  34. Display::display_header(get_lang('CopyCourse'));
  35. echo Display::page_header(get_lang('CopyCourse'));
  36. /* MAIN CODE */
  37. // If a CourseSelectForm is posted or we should copy all resources, then copy them
  38. if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')) {
  39. if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
  40. $course = CourseSelectForm :: get_posted_course('copy_course');
  41. } else {
  42. $cb = new CourseBuilder();
  43. $course = $cb->build();
  44. }
  45. $cr = new CourseRestorer($course);
  46. $cr->set_file_option($_POST['same_file_name_option']);
  47. $cr->restore($_POST['destination_course']);
  48. Display::display_normal_message(
  49. get_lang('CopyFinished').': <a href="'.api_get_course_url(
  50. $_POST['destination_course']
  51. ).'">'.$_POST['destination_course'].'</a>',
  52. false
  53. );
  54. } elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
  55. $cb = new CourseBuilder();
  56. $course = $cb->build();
  57. $hidden_fields = array();
  58. $hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
  59. $hidden_fields['destination_course'] = $_POST['destination_course'];
  60. CourseSelectForm :: display_form($course, $hidden_fields, true);
  61. } else {
  62. $table_c = Database :: get_main_table(TABLE_MAIN_COURSE);
  63. $table_cu = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  64. $user_info = api_get_user_info();
  65. $course_info = api_get_course_info();
  66. $sql = 'SELECT * FROM '.$table_c.' c, '.$table_cu.' cu WHERE cu.c_id = c.id';
  67. if (!api_is_platform_admin()) {
  68. $sql .= ' AND cu.status=1 ';
  69. }
  70. $sql .= ' AND target_course_code IS NULL AND cu.user_id = '.$user_info['user_id'].' AND c.code != '."'".$course_info['sysCode']."'".' ORDER BY title ASC';
  71. $res = Database::query($sql);
  72. if (Database::num_rows($res) == 0) {
  73. Display::display_normal_message(get_lang('NoDestinationCoursesAvailable'));
  74. } else {
  75. $options = array();
  76. while ($obj = Database::fetch_object($res)) {
  77. $options[$obj->code] = $obj->title;
  78. }
  79. $form = new FormValidator('copy_course', 'post', 'copy_course.php?'.api_get_cidreq());
  80. $form->addElement('header', '');
  81. $form->addElement('select', 'destination_course', get_lang('SelectDestinationCourse'), $options);
  82. $group = array();
  83. $group[] = $form->createElement('radio', 'copy_option', null, get_lang('FullCopy'), 'full_copy');
  84. $group[] = $form->createElement('radio', 'copy_option', null, get_lang('LetMeSelectItems'), 'select_items');
  85. $form->addGroup($group, '', get_lang('SelectOptionForBackup'));
  86. $group = array();
  87. $group[] = $form->createElement(
  88. 'radio',
  89. 'same_file_name_option',
  90. null,
  91. get_lang('SameFilenameSkip'),
  92. FILE_SKIP
  93. );
  94. $group[] = $form->createElement(
  95. 'radio',
  96. 'same_file_name_option',
  97. null,
  98. get_lang('SameFilenameRename'),
  99. FILE_RENAME
  100. );
  101. $group[] = $form->createElement(
  102. 'radio',
  103. 'same_file_name_option',
  104. null,
  105. get_lang('SameFilenameOverwrite'),
  106. FILE_OVERWRITE
  107. );
  108. $form->addGroup($group, '', get_lang('SameFilename'));
  109. $form->addElement('style_submit_button', 'submit', get_lang('CopyCourse'), 'class="save"');
  110. $form->setDefaults(array('copy_option' => 'select_items', 'same_file_name_option' => FILE_OVERWRITE));
  111. $form->display();
  112. }
  113. }
  114. /* FOOTER */
  115. Display::display_footer();