copy_course.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // $Id: copy_course.php 22204 2009-07-17 20:31:35Z iflorespaz $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Bart Mollet (bart.mollet@hogent.be)
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. * ==============================================================================
  23. * Copy resources from one course to another one.
  24. *
  25. * @author Bart Mollet <bart.mollet@hogent.be>
  26. * @package dokeos.backup
  27. * ==============================================================================
  28. */
  29. /*
  30. ==============================================================================
  31. INIT SECTION
  32. ==============================================================================
  33. */
  34. // name of the language file that needs to be included
  35. $language_file = array('exercice', 'coursebackup', 'admin');
  36. require_once '../inc/global.inc.php';
  37. include_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
  38. require_once 'classes/CourseBuilder.class.php';
  39. require_once 'classes/CourseRestorer.class.php';
  40. require_once 'classes/CourseSelectForm.class.php';
  41. if (!api_is_allowed_to_edit())
  42. {
  43. api_not_allowed(true);
  44. }
  45. //remove memory and time limits as much as possible as this might be a long process...
  46. if(function_exists('ini_set'))
  47. {
  48. ini_set('memory_limit','256M');
  49. ini_set('max_execution_time',1800);
  50. }
  51. $nameTools = get_lang('CopyCourse');
  52. $interbreadcrumb[] = array ("url" => "../course_info/maintenance.php", "name" => get_lang('Maintenance'));
  53. Display::display_header($nameTools);
  54. //api_display_tool_title($nameTools);
  55. /*
  56. ==============================================================================
  57. MAIN CODE
  58. ==============================================================================
  59. */
  60. // If a CourseSelectForm is posted or we should copy all resources, then copy them
  61. if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')) {
  62. if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
  63. $course = CourseSelectForm :: get_posted_course('copy_course');
  64. } else {
  65. $cb = new CourseBuilder();
  66. $course = $cb->build();
  67. }
  68. $cr = new CourseRestorer($course);
  69. $cr->set_file_option($_POST['same_file_name_option']);
  70. $cr->restore($_POST['destination_course']);
  71. Display::display_normal_message(get_lang('CopyFinished'));
  72. } elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
  73. // Else, if a CourseSelectForm is requested, show it
  74. Display::display_normal_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
  75. if (api_get_setting('show_glossary_in_documents') != 'none') {
  76. Display::display_normal_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
  77. }
  78. $cb = new CourseBuilder();
  79. $course = $cb->build();
  80. //echo get_lang('SelectItemsToCopy');
  81. //echo '<br/><br/>';
  82. $hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
  83. $hidden_fields['destination_course'] = $_POST['destination_course'];
  84. CourseSelectForm :: display_form($course, $hidden_fields, true);
  85. } else {
  86. $table_c = Database :: get_main_table(TABLE_MAIN_COURSE);
  87. $table_cu = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  88. $user_info = api_get_user_info();
  89. $course_info = api_get_course_info();
  90. $sql = 'SELECT * FROM '.$table_c.' c, '.$table_cu.' cu WHERE cu.course_code = c.code';
  91. if (!api_is_platform_admin()) {
  92. $sql .= ' AND cu.status=1 ';
  93. }
  94. $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';
  95. $res = Database::query($sql,__FILE__,__LINE__);
  96. if( Database::num_rows($res) == 0) {
  97. Display::display_normal_message(get_lang('NoDestinationCoursesAvailable'));
  98. } else {
  99. ?>
  100. <form method="post" action="copy_course.php">
  101. <?php
  102. echo get_lang('SelectDestinationCourse');
  103. echo ' <select name="destination_course"/>';
  104. while ($obj = Database::fetch_object($res)) {
  105. echo '<option value="'.$obj->code.'">'.$obj->title.'</option>';
  106. }
  107. echo '</select>';
  108. ?>
  109. <br/>
  110. <br/>
  111. <input type="radio" class="checkbox" id="copy_option_1" name="copy_option" value="full_copy"/>
  112. <label for="copy_option_1"><?php echo get_lang('FullCopy') ?></label>
  113. <br/>
  114. <input type="radio" class="checkbox" id="copy_option_2" name="copy_option" value="select_items" checked="checked"/>
  115. <label for="copy_option_2"><?php echo get_lang('LetMeSelectItems') ?></label>
  116. <br/>
  117. <br/>
  118. <?php echo get_lang('SameFilename') ?>
  119. <blockquote>
  120. <input type="radio" class="checkbox" id="same_file_name_option_1" name="same_file_name_option" value="<?php echo FILE_SKIP ?>"/>
  121. <label for="same_file_name_option_1"><?php echo get_lang('SameFilenameSkip') ?></label>
  122. <br/>
  123. <input type="radio" class="checkbox" id="same_file_name_option_2" name="same_file_name_option" value="<?php echo FILE_RENAME ?>"/>
  124. <label for="same_file_name_option_2"><?php echo get_lang('SameFilenameRename') ?></label>
  125. <br/>
  126. <input type="radio" class="checkbox" id="same_file_name_option_3" name="same_file_name_option" value="<?php echo FILE_OVERWRITE ?>" checked="checked"/>
  127. <label for="same_file_name_option_3"><?php echo get_lang('SameFilenameOverwrite') ?></label>
  128. </blockquote>
  129. <br/>
  130. <button class="save" type="submit"><?php echo get_lang('CopyCourse') ?></button>
  131. </form>
  132. <?php
  133. }
  134. }
  135. /*
  136. ==============================================================================
  137. FOOTER
  138. ==============================================================================
  139. */
  140. Display::display_footer();
  141. ?>