copy_course.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. include_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. ==============================================================================
  32. MAIN CODE
  33. ==============================================================================
  34. */
  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'));
  47. } elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
  48. // Else, if a CourseSelectForm is requested, show it
  49. Display::display_normal_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
  50. if (api_get_setting('show_glossary_in_documents') != 'none') {
  51. Display::display_normal_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
  52. }
  53. $cb = new CourseBuilder();
  54. $course = $cb->build();
  55. //echo get_lang('SelectItemsToCopy');
  56. //echo '<br/><br/>';
  57. $hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
  58. $hidden_fields['destination_course'] = $_POST['destination_course'];
  59. CourseSelectForm :: display_form($course, $hidden_fields, true);
  60. } else {
  61. $table_c = Database :: get_main_table(TABLE_MAIN_COURSE);
  62. $table_cu = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  63. $user_info = api_get_user_info();
  64. $course_info = api_get_course_info();
  65. $sql = 'SELECT * FROM '.$table_c.' c, '.$table_cu.' cu WHERE cu.course_code = c.code';
  66. if (!api_is_platform_admin()) {
  67. $sql .= ' AND cu.status=1 ';
  68. }
  69. $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';
  70. $res = Database::query($sql,__FILE__,__LINE__);
  71. if( Database::num_rows($res) == 0) {
  72. Display::display_normal_message(get_lang('NoDestinationCoursesAvailable'));
  73. } else {
  74. ?>
  75. <form method="post" action="copy_course.php">
  76. <?php
  77. echo get_lang('SelectDestinationCourse');
  78. echo ' <select name="destination_course"/>';
  79. while ($obj = Database::fetch_object($res)) {
  80. echo '<option value="'.$obj->code.'">'.$obj->title.'</option>';
  81. }
  82. echo '</select>';
  83. ?>
  84. <br/>
  85. <br/>
  86. <input type="radio" class="checkbox" id="copy_option_1" name="copy_option" value="full_copy"/>
  87. <label for="copy_option_1"><?php echo get_lang('FullCopy') ?></label>
  88. <br/>
  89. <input type="radio" class="checkbox" id="copy_option_2" name="copy_option" value="select_items" checked="checked"/>
  90. <label for="copy_option_2"><?php echo get_lang('LetMeSelectItems') ?></label>
  91. <br/>
  92. <br/>
  93. <?php echo get_lang('SameFilename') ?>
  94. <blockquote>
  95. <input type="radio" class="checkbox" id="same_file_name_option_1" name="same_file_name_option" value="<?php echo FILE_SKIP ?>"/>
  96. <label for="same_file_name_option_1"><?php echo get_lang('SameFilenameSkip') ?></label>
  97. <br/>
  98. <input type="radio" class="checkbox" id="same_file_name_option_2" name="same_file_name_option" value="<?php echo FILE_RENAME ?>"/>
  99. <label for="same_file_name_option_2"><?php echo get_lang('SameFilenameRename') ?></label>
  100. <br/>
  101. <input type="radio" class="checkbox" id="same_file_name_option_3" name="same_file_name_option" value="<?php echo FILE_OVERWRITE ?>" checked="checked"/>
  102. <label for="same_file_name_option_3"><?php echo get_lang('SameFilenameOverwrite') ?></label>
  103. </blockquote>
  104. <br/>
  105. <button class="save" type="submit"><?php echo get_lang('CopyCourse') ?></button>
  106. </form>
  107. <?php
  108. }
  109. }
  110. /*
  111. ==============================================================================
  112. FOOTER
  113. ==============================================================================
  114. */
  115. Display::display_footer();
  116. ?>