copy_course.php 4.4 KB

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