copy_course.php 4.5 KB

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