copy_course.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. // $Id: copy_course.php 12219 2007-05-01 18:46:59Z yannoo $
  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('coursebackup','admin');
  36. include ('../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. $nameTools = get_lang('CopyCourse');
  46. $interbreadcrumb[] = array ("url" => "../course_info/maintenance.php", "name" => get_lang('Maintenance'));
  47. Display::display_header($nameTools);
  48. //api_display_tool_title($nameTools);
  49. /*
  50. ==============================================================================
  51. MAIN CODE
  52. ==============================================================================
  53. */
  54. // If a CourseSelectForm is posted or we should copy all resources, then copy them
  55. if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy'))
  56. {
  57. if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form')
  58. {
  59. $course = CourseSelectForm :: get_posted_course();
  60. }
  61. else
  62. {
  63. $cb = new CourseBuilder();
  64. $course = $cb->build();
  65. }
  66. $cr = new CourseRestorer($course);
  67. $cr->set_file_option($_POST['same_file_name_option']);
  68. $cr->restore($_POST['destination_course']);
  69. Display::display_normal_message(get_lang('CopyFinished'));
  70. }
  71. // Else, if a CourseSelectForm is requested, show it
  72. elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items')
  73. {
  74. $cb = new CourseBuilder();
  75. $course = $cb->build();
  76. echo get_lang('SelectItemsToCopy');
  77. echo '<br/><br/>';
  78. $hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
  79. $hidden_fields['destination_course'] = $_POST['destination_course'];
  80. CourseSelectForm :: display_form($course, $hidden_fields);
  81. }
  82. // Else, show the default page
  83. else
  84. {
  85. $table_c = Database :: get_main_table(TABLE_MAIN_COURSE);
  86. $table_cu = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  87. $user_info = api_get_user_info();
  88. $course_info = api_get_course_info();
  89. $sql = 'SELECT * FROM '.$table_c.' c, '.$table_cu.' cu WHERE cu.course_code = c.code';
  90. if( ! api_is_platform_admin())
  91. {
  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']."'".' ';
  95. $res = api_sql_query($sql,__FILE__,__LINE__);
  96. if( mysql_num_rows($res) == 0)
  97. {
  98. Display::display_normal_message(get_lang('NoDestinationCoursesAvailable'));
  99. }
  100. else
  101. {
  102. ?>
  103. <form method="post" action="copy_course.php">
  104. <?php
  105. echo get_lang('SelectDestinationCourse');
  106. echo ' <select name="destination_course"/>';
  107. while ($obj = mysql_fetch_object($res))
  108. {
  109. echo '<option value="'.$obj->code.'">'.$obj->title.'</option>';
  110. }
  111. echo '</select>';
  112. ?>
  113. <br/>
  114. <br/>
  115. <input type="radio" class="checkbox" id="copy_option_1" name="copy_option" value="full_copy" checked="checked"/>
  116. <label for="copy_option_1"><?php echo get_lang('FullCopy') ?></label>
  117. <br/>
  118. <input type="radio" class="checkbox" id="copy_option_2" name="copy_option" value="select_items"/>
  119. <label for="copy_option_2"><?php echo get_lang('LetMeSelectItems') ?></label>
  120. <br/>
  121. <br/>
  122. <?php echo get_lang('SameFilename') ?>
  123. <blockquote>
  124. <input type="radio" class="checkbox" id="same_file_name_option_1" name="same_file_name_option" value="<?php echo FILE_SKIP ?>"/>
  125. <label for="same_file_name_option_1"><?php echo get_lang('SameFilenameSkip') ?></label>
  126. <br/>
  127. <input type="radio" class="checkbox" id="same_file_name_option_2" name="same_file_name_option" value="<?php echo FILE_RENAME ?>"/>
  128. <label for="same_file_name_option_2"><?php echo get_lang('SameFilenameRename') ?></label>
  129. <br/>
  130. <input type="radio" class="checkbox" id="same_file_name_option_3" name="same_file_name_option" value="<?php echo FILE_OVERWRITE ?>" checked="checked"/>
  131. <label for="same_file_name_option_3"><?php echo get_lang('SameFilenameOverwrite') ?></label>
  132. </blockquote>
  133. <br/>
  134. <input type="submit" value="<?php echo get_lang('CopyCourse') ?>"/>
  135. </form>
  136. <?php
  137. }
  138. }
  139. /*
  140. ==============================================================================
  141. FOOTER
  142. ==============================================================================
  143. */
  144. Display::display_footer();
  145. ?>