copy_course.php 4.8 KB

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