copy_course.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
  4. use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
  5. use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
  6. /**
  7. * @package chamilo.backup
  8. */
  9. // Setting the global file that gets the general configuration, the databases, the languages, ...
  10. ////require_once '../inc/global.inc.php';
  11. $current_course_tool = TOOL_COURSE_MAINTENANCE;
  12. api_protect_course_script(true);
  13. // Including additional libraries
  14. // Notice for unauthorized people.
  15. if (!api_is_allowed_to_edit()) {
  16. api_not_allowed(true);
  17. }
  18. // Remove memory and time limits as much as possible as this might be a long process...
  19. if (function_exists('ini_set')) {
  20. api_set_memory_limit('256M');
  21. ini_set('max_execution_time', 1800);
  22. //ini_set('post_max_size', "512M");
  23. }
  24. // Breadcrumbs
  25. $interbreadcrumb[] = array(
  26. 'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php?'.api_get_cidreq(),
  27. 'name' => get_lang('Maintenance')
  28. );
  29. // The section (for the tabs)
  30. $this_section = SECTION_COURSES;
  31. // Display the header
  32. Display::display_header(get_lang('CopyCourse'));
  33. echo Display::page_header(get_lang('CopyCourse'));
  34. /* MAIN CODE */
  35. // If a CourseSelectForm is posted or we should copy all resources, then copy them
  36. if (
  37. (
  38. isset($_POST['action']) &&
  39. $_POST['action'] == 'course_select_form') || (
  40. isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy'
  41. )
  42. ) {
  43. // Clear token
  44. Security::clear_token();
  45. if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
  46. $course = CourseSelectForm :: get_posted_course('copy_course');
  47. } else {
  48. $cb = new CourseBuilder();
  49. $course = $cb->build();
  50. }
  51. $cr = new CourseRestorer($course);
  52. $cr->set_file_option($_POST['same_file_name_option']);
  53. $cr->restore($_POST['destination_course']);
  54. Display::display_normal_message(
  55. get_lang('CopyFinished').': <a href="'.api_get_course_url($_POST['destination_course']).'">'.
  56. Security::remove_XSS($_POST['destination_course']).
  57. '</a>',
  58. false
  59. );
  60. } elseif (
  61. isset ($_POST['copy_option']) &&
  62. $_POST['copy_option'] == 'select_items'
  63. ) {
  64. // Clear token
  65. Security::clear_token();
  66. $cb = new CourseBuilder();
  67. $course = $cb->build();
  68. $hiddenFields = array();
  69. $hiddenFields['same_file_name_option'] = $_POST['same_file_name_option'];
  70. $hiddenFields['destination_course'] = $_POST['destination_course'];
  71. // Add token to Course select form
  72. $hiddenFields['sec_token'] = Security::get_token();
  73. CourseSelectForm::display_form($course, $hiddenFields, true);
  74. } else {
  75. $table_c = Database :: get_main_table(TABLE_MAIN_COURSE);
  76. $table_cu = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  77. $user_info = api_get_user_info();
  78. $course_info = api_get_course_info();
  79. $sql = 'SELECT *
  80. FROM '.$table_c.' c, '.$table_cu.' cu
  81. WHERE cu.c_id = c.id';
  82. if (!api_is_platform_admin()) {
  83. $sql .= ' AND cu.status=1 ';
  84. }
  85. $sql .= ' AND
  86. cu.user_id = '.$user_info['user_id'].' AND
  87. c.id != '."'".$course_info['real_id']."'".'
  88. ORDER BY title ASC';
  89. $res = Database::query($sql);
  90. if (Database::num_rows($res) == 0) {
  91. Display::display_normal_message(get_lang('NoDestinationCoursesAvailable'));
  92. } else {
  93. $options = array();
  94. while ($obj = Database::fetch_object($res)) {
  95. $courseInfo = api_get_course_info_by_id($obj->c_id);
  96. $options[$courseInfo['code']] = $obj->title.' ('.$obj->code.')';
  97. }
  98. $form = new FormValidator(
  99. 'copy_course',
  100. 'post',
  101. api_get_path(WEB_CODE_PATH).'coursecopy/copy_course.php?'.api_get_cidreq()
  102. );
  103. $form->addElement('select', 'destination_course', get_lang('SelectDestinationCourse'), $options);
  104. $group = array();
  105. $group[] = $form->createElement('radio', 'copy_option', null, get_lang('FullCopy'), 'full_copy');
  106. $group[] = $form->createElement('radio', 'copy_option', null, get_lang('LetMeSelectItems'), 'select_items');
  107. $form->addGroup($group, '', get_lang('SelectOptionForBackup'));
  108. $group = array();
  109. $group[] = $form->createElement('radio', 'same_file_name_option', null, get_lang('SameFilenameSkip'), FILE_SKIP);
  110. $group[] = $form->createElement('radio', 'same_file_name_option', null, get_lang('SameFilenameRename'), FILE_RENAME);
  111. $group[] = $form->createElement('radio', 'same_file_name_option', null, get_lang('SameFilenameOverwrite'), FILE_OVERWRITE);
  112. $form->addGroup($group, '', get_lang('SameFilename'));
  113. $form->addProgress();
  114. $form->addButtonSave(get_lang('CopyCourse'));
  115. $form->setDefaults(array('copy_option' =>'select_items','same_file_name_option' => FILE_OVERWRITE));
  116. // Add Security token
  117. $token = Security::get_token();
  118. $form->addElement('hidden', 'sec_token');
  119. $form->setConstants(array('sec_token' => $token));
  120. $form->display();
  121. }
  122. }