copy_course.php 5.5 KB

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