/** * Create the dummy course */ function create_dummy_course($course_code) { $this->default_property['insert_user_id'] = '1'; $this->default_property['insert_date'] = date('Y-m-d H:i:s'); $this->default_property['lastedit_date'] = date('Y-m-d H:i:s'); $this->default_property['lastedit_user_id'] = '1'; $this->default_property['to_group_id'] = '0'; $this->default_property['to_user_id'] = null; $this->default_property['visibility'] = '1'; $this->default_property['start_visible'] = '0000-00-00 00:00:00'; $this->default_property['end_visible'] = '0000-00-00 00:00:00'; $course = Database::get_course_info($course_code); $this->course = new Course(); $tmp_path = api_get_path(SYS_COURSE_PATH) . $course['directory'] . '/document/tmp_' . uniqid(''); @mkdir($tmp_path, api_get_permissions_for_new_directories(), true); $this->course->backup_path = $tmp_path; $this->create_dummy_links(); $this->create_dummy_events(); $this->create_dummy_forums(); $this->create_dummy_announcements(); $this->create_dummy_documents(); $this->create_dummy_learnpaths(); $cr = new CourseRestorer($this->course); $cr->set_file_option(FILE_OVERWRITE); $cr->restore($course_code); rmdirr($tmp_path); }
function copy() { $main_path = api_get_path(SYS_CODE_PATH); require_once $main_path . 'coursecopy/classes/CourseBuilder.class.php'; require_once $main_path . 'coursecopy/classes/CourseArchiver.class.php'; require_once $main_path . 'coursecopy/classes/CourseRestorer.class.php'; require_once $main_path . 'coursecopy/classes/CourseSelectForm.class.php'; //Course builder $cb = new CourseBuilder(); //Setting tools that will be copied $cb->set_tools_to_build(array('learnpaths')); //Setting elements that will be copied $cb->set_tools_specific_id_list(array('learnpaths' => array($this->lp_id))); $course = $cb->build(); //Course restorer $course_restorer = new CourseRestorer($course); $course_restorer->set_add_text_in_items(true); $course_restorer->set_tool_copy_settings(array('learnpaths' => array('reset_dates' => true))); $course_restorer->restore(api_get_course_id(), api_get_session_id(), false, false); }
/** * * @param string source course code * @param int source session id * @param string destination course code * @param int destination session id * @return bool */ public static function copy_course($source_course_code, $source_session_id, $destination_course_code, $destination_session_id, $params = array()) { require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseBuilder.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseRestorer.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseSelectForm.class.php'; $course_info = api_get_course_info($source_course_code); if (!empty($course_info)) { $cb = new CourseBuilder('', $course_info); $course = $cb->build($source_session_id, $source_course_code, true); $course_restorer = new CourseRestorer($course); $course_restorer->skip_content = $params; $course_restorer->restore($destination_course_code, $destination_session_id, true, true); return true; } return false; }
} else { $delete_file = true; } } else { $error = true; } } if (!$error) { // Full backup $course = CourseArchiver::read_course($filename, $delete_file); } } if (!$error && $course->has_resources()) { $cr = new CourseRestorer($course); $cr->set_file_option($_POST['same_file_name_option']); $cr->restore(); Display::display_normal_message(get_lang('ImportFinished')); echo '<a class="btn" href="' . api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/index.php">' . get_lang('CourseHomepage') . '</a>'; } else { if (!$error) { Display::display_warning_message(get_lang('NoResourcesInBackupFile')); echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>'; } elseif ($filename === false) { Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin')); echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>'; } else { if ($filename == '') { Display::display_error_message(get_lang('SelectBackupFile')); echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>'; } else { Display::display_error_message(get_lang('UploadError'));
$origin_session = $_POST['sessions_list_origin']; } if (is_array($arr_course_origin) && count($arr_course_origin) > 0 && !empty($destination_session)) { //We need only one value if (count($arr_course_origin) > 1 || count($arr_course_destination) > 1) { Display::display_error_message(get_lang('YouMustSelectACourseFromOriginalSession')); } else { //foreach ($arr_course_origin as $course_origin) { //first element of the array $course_code = $arr_course_origin[0]; $course_destinatination = $arr_course_destination[0]; $course_origin = api_get_course_info($course_code); $cb = new CourseBuilder('', $course_origin); $course = $cb->build($origin_session, $course_code, $with_base_content); $cr = new CourseRestorer($course); $cr->restore($course_destinatination, $destination_session); } Display::display_confirmation_message(get_lang('CopyFinished')); display_form(); } else { Display::display_error_message(get_lang('YouMustSelectACourseFromOriginalSession')); display_form(); } } } elseif (Security::check_token('post') && (isset($_POST['copy_option']) && $_POST['copy_option'] == 'select_items')) { // Clear token Security::clear_token(); // Else, if a CourseSelectForm is requested, show it if (api_get_setting('show_glossary_in_documents') != 'none') { Display::display_normal_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary')); }
$this_section = SECTION_COURSES; // Display the header Display::display_header(get_lang('CopyCourse')); echo Display::page_header(get_lang('CopyCourse')); /* MAIN CODE */ // If a CourseSelectForm is posted or we should copy all resources, then copy them if (isset($_POST['action']) && $_POST['action'] == 'course_select_form' || isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy') { if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') { $course = CourseSelectForm::get_posted_course('copy_course'); } else { $cb = new CourseBuilder(); $course = $cb->build(); } $cr = new CourseRestorer($course); $cr->set_file_option($_POST['same_file_name_option']); $cr->restore($_POST['destination_course']); Display::display_normal_message(get_lang('CopyFinished') . ': <a href="' . api_get_course_url($_POST['destination_course']) . '">' . $_POST['destination_course'] . '</a>', false); } elseif (isset($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') { $cb = new CourseBuilder(); $course = $cb->build(); $hidden_fields = array(); $hidden_fields['same_file_name_option'] = $_POST['same_file_name_option']; $hidden_fields['destination_course'] = $_POST['destination_course']; CourseSelectForm::display_form($course, $hidden_fields, true); } else { $table_c = Database::get_main_table(TABLE_MAIN_COURSE); $table_cu = Database::get_main_table(TABLE_MAIN_COURSE_USER); $user_info = api_get_user_info(); $course_info = api_get_course_info(); $sql = 'SELECT * FROM ' . $table_c . ' c, ' . $table_cu . ' cu WHERE cu.c_id = c.id'; if (!api_is_platform_admin()) {
$arrCourseOrigin = SessionManager::get_course_list_by_session_id(api_get_session_id(), $courseInfo['title']); } } if (isset($_POST['sessions_list_destination'])) { $destinationSession = $_POST['sessions_list_destination']; } if (is_array($arrCourseOrigin) && count($arrCourseOrigin) > 0 && !empty($destinationSession)) { //We need only one value if (count($arrCourseOrigin) > 1 || count($arrCourseDestination) > 1) { Display::display_error_message(get_lang('YouMustSelectACourseFromOriginalSession')); } else { $courseDestination = $arrCourseDestination[0]; $cb = new CourseBuilder('', $courseInfo); $course = $cb->build($originSession, $courseCode); $cr = new CourseRestorer($course); $cr->restore($courseDestination, $destinationSession); Display::display_confirmation_message(get_lang('CopyFinished')); } displayForm(); } else { Display::display_error_message(get_lang('YouMustSelectACourseFromOriginalSession')); displayForm(); } } } elseif (isset($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') { // Else, if a CourseSelectForm is requested, show it if (api_get_setting('document.show_glossary_in_documents') != 'none') { Display::display_normal_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary')); } $arrCourseDestination = array(); $destinationSession = '';