copy_course.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  15. require_once 'classes/CourseBuilder.class.php';
  16. require_once 'classes/CourseRestorer.class.php';
  17. require_once 'classes/CourseSelectForm.class.php';
  18. // Notice for unauthorized people.
  19. if (!api_is_allowed_to_edit()) {
  20. api_not_allowed(true);
  21. }
  22. // Remove memory and time limits as much as possible as this might be a long process...
  23. if (function_exists('ini_set')) {
  24. ini_set('memory_limit', '256M');
  25. ini_set('max_execution_time', 1800);
  26. //ini_set('post_max_size', "512M");
  27. }
  28. // Breadcrumbs
  29. $interbreadcrumb[] = array ('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
  30. // The section (for the tabs)
  31. $this_section = SECTION_COURSES;
  32. // Display the header
  33. Display::display_header(get_lang('CopyCourse'));
  34. //api_display_tool_title($nameTools);
  35. /* MAIN CODE */
  36. // If a CourseSelectForm is posted or we should copy all resources, then copy them
  37. if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')) {
  38. if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
  39. $course = CourseSelectForm :: get_posted_course('copy_course');
  40. } else {
  41. $cb = new CourseBuilder();
  42. $course = $cb->build();
  43. }
  44. $cr = new CourseRestorer($course);
  45. $cr->set_file_option($_POST['same_file_name_option']);
  46. $cr->restore($_POST['destination_course']);
  47. Display::display_normal_message(get_lang('CopyFinished').': <a href="'.api_get_course_url($_POST['destination_course']).'">'.$_POST['destination_course'].'</a>',false);
  48. } elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
  49. $cb = new CourseBuilder();
  50. $course = $cb->build();
  51. $hidden_fields = array();
  52. $hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
  53. $hidden_fields['destination_course'] = $_POST['destination_course'];
  54. CourseSelectForm :: display_form($course, $hidden_fields, true);
  55. } else {
  56. $table_c = Database :: get_main_table(TABLE_MAIN_COURSE);
  57. $table_cu = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  58. $user_info = api_get_user_info();
  59. $course_info = api_get_course_info();
  60. $sql = 'SELECT * FROM '.$table_c.' c, '.$table_cu.' cu WHERE cu.course_code = c.code';
  61. if (!api_is_platform_admin()) {
  62. $sql .= ' AND cu.status=1 ';
  63. }
  64. $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';
  65. $res = Database::query($sql);
  66. if (Database::num_rows($res) == 0) {
  67. Display::display_normal_message(get_lang('NoDestinationCoursesAvailable'));
  68. } else {
  69. ?>
  70. <form method="post" action="copy_course.php">
  71. <?php
  72. echo get_lang('SelectDestinationCourse');
  73. echo ' <select name="destination_course"/>';
  74. while ($obj = Database::fetch_object($res)) {
  75. echo '<option value="'.$obj->code.'">'.$obj->title.'</option>';
  76. }
  77. echo '</select>';
  78. ?>
  79. <br/>
  80. <br/>
  81. <input type="radio" class="checkbox" id="copy_option_1" name="copy_option" value="full_copy"/>
  82. <label for="copy_option_1"><?php echo get_lang('FullCopy'); ?></label>
  83. <br/>
  84. <input type="radio" class="checkbox" id="copy_option_2" name="copy_option" value="select_items" checked="checked"/>
  85. <label for="copy_option_2"><?php echo get_lang('LetMeSelectItems'); ?></label>
  86. <br/>
  87. <br/>
  88. <?php echo get_lang('SameFilename'); ?>
  89. <blockquote>
  90. <input type="radio" class="checkbox" id="same_file_name_option_1" name="same_file_name_option" value="<?php echo FILE_SKIP; ?>"/>
  91. <label for="same_file_name_option_1"><?php echo get_lang('SameFilenameSkip'); ?></label>
  92. <br/>
  93. <input type="radio" class="checkbox" id="same_file_name_option_2" name="same_file_name_option" value="<?php echo FILE_RENAME; ?>"/>
  94. <label for="same_file_name_option_2"><?php echo get_lang('SameFilenameRename'); ?></label>
  95. <br/>
  96. <input type="radio" class="checkbox" id="same_file_name_option_3" name="same_file_name_option" value="<?php echo FILE_OVERWRITE; ?>" checked="checked"/>
  97. <label for="same_file_name_option_3"><?php echo get_lang('SameFilenameOverwrite'); ?></label>
  98. </blockquote>
  99. <br/>
  100. <button class="save" type="submit"><?php echo get_lang('CopyCourse'); ?></button>
  101. </form>
  102. <?php
  103. }
  104. }
  105. /* FOOTER */
  106. Display::display_footer();