You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
4.9 KiB
154 lines
4.9 KiB
![]()
16 years ago
|
<?php
|
||
|
/* For licensing terms, see /license.txt */
|
||
![]()
10 years ago
|
|
||
![]()
9 years ago
|
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
|
||
|
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
|
||
![]()
8 years ago
|
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
|
||
![]()
9 years ago
|
|
||
![]()
14 years ago
|
/**
|
||
![]()
9 years ago
|
* @todo rework file in order to use addFlash
|
||
![]()
14 years ago
|
*/
|
||
![]()
16 years ago
|
|
||
![]()
16 years ago
|
// Setting the global file that gets the general configuration, the databases, the languages, ...
|
||
![]()
9 years ago
|
require_once __DIR__.'/../inc/global.inc.php';
|
||
![]()
9 years ago
|
$current_course_tool = TOOL_COURSE_MAINTENANCE;
|
||
![]()
14 years ago
|
api_protect_course_script(true);
|
||
|
|
||
![]()
16 years ago
|
if (!api_is_allowed_to_edit()) {
|
||
![]()
12 years ago
|
api_not_allowed(true);
|
||
![]()
19 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
api_set_more_memory_and_time_limits();
|
||
![]()
18 years ago
|
|
||
![]()
16 years ago
|
// Breadcrumbs
|
||
![]()
8 years ago
|
$interbreadcrumb[] = [
|
||
![]()
9 years ago
|
'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php?'.api_get_cidreq(),
|
||
![]()
6 years ago
|
'name' => get_lang('Backup'),
|
||
![]()
8 years ago
|
];
|
||
![]()
19 years ago
|
|
||
![]()
16 years ago
|
// The section (for the tabs)
|
||
|
$this_section = SECTION_COURSES;
|
||
![]()
16 years ago
|
|
||
|
// Display the header
|
||
![]()
6 years ago
|
Display::display_header(get_lang('Copy course'));
|
||
|
echo Display::page_header(get_lang('Copy course'));
|
||
![]()
16 years ago
|
|
||
![]()
7 years ago
|
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
||
![]()
16 years ago
|
|
||
![]()
19 years ago
|
// If a CourseSelectForm is posted or we should copy all resources, then copy them
|
||
![]()
11 years ago
|
if (Security::check_token('post') && (
|
||
![]()
6 years ago
|
('course_select_form' === $action) ||
|
||
|
(isset($_POST['copy_option']) && 'full_copy' === $_POST['copy_option'])
|
||
![]()
11 years ago
|
)
|
||
|
) {
|
||
|
// Clear token
|
||
|
Security::clear_token();
|
||
![]()
6 years ago
|
if ('course_select_form' === $action) {
|
||
![]()
9 years ago
|
$course = CourseSelectForm::get_posted_course('copy_course');
|
||
![]()
12 years ago
|
} 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']);
|
||
![]()
8 years ago
|
echo Display::return_message(
|
||
![]()
6 years ago
|
get_lang('Copying is finished').': <a href="'.api_get_course_url($_POST['destination_course']).'">'.
|
||
![]()
9 years ago
|
Security::remove_XSS($_POST['destination_course']).
|
||
|
'</a>',
|
||
![]()
9 years ago
|
'normal',
|
||
![]()
10 years ago
|
false
|
||
![]()
8 years ago
|
);
|
||
![]()
11 years ago
|
} elseif (Security::check_token('post') && (
|
||
![]()
9 years ago
|
isset($_POST['copy_option']) &&
|
||
![]()
6 years ago
|
'select_items' === $_POST['copy_option']
|
||
![]()
11 years ago
|
)
|
||
|
) {
|
||
|
// Clear token
|
||
|
Security::clear_token();
|
||
|
|
||
![]()
12 years ago
|
$cb = new CourseBuilder();
|
||
|
$course = $cb->build();
|
||
![]()
8 years ago
|
$hiddenFields = [];
|
||
![]()
11 years ago
|
$hiddenFields['same_file_name_option'] = $_POST['same_file_name_option'];
|
||
![]()
10 years ago
|
$hiddenFields['destination_course'] = $_POST['destination_course'];
|
||
![]()
11 years ago
|
// Add token to Course select form
|
||
![]()
11 years ago
|
$hiddenFields['sec_token'] = Security::get_token();
|
||
|
CourseSelectForm::display_form($course, $hiddenFields, true);
|
||
![]()
16 years ago
|
} else {
|
||
![]()
12 years ago
|
$course_info = api_get_course_info();
|
||
![]()
9 years ago
|
|
||
![]()
5 years ago
|
$courseList = CourseManager::getCoursesFollowedByUser(
|
||
|
api_get_user_id(),
|
||
|
COURSEMANAGER,
|
||
|
null,
|
||
|
null,
|
||
|
null,
|
||
|
null,
|
||
![]()
9 years ago
|
false,
|
||
![]()
5 years ago
|
null,
|
||
|
null,
|
||
![]()
9 years ago
|
false,
|
||
![]()
5 years ago
|
'ORDER BY c.title'
|
||
![]()
9 years ago
|
);
|
||
|
|
||
![]()
5 years ago
|
$courses = [];
|
||
![]()
5 years ago
|
foreach ($courseList as $courseItem) {
|
||
![]()
5 years ago
|
if ($courseItem['real_id'] == $course_info['real_id']) {
|
||
|
continue;
|
||
|
}
|
||
|
$courses[$courseItem['code']] = $courseItem['title'].' ('.$courseItem['code'].')';
|
||
![]()
5 years ago
|
}
|
||
![]()
13 years ago
|
|
||
![]()
5 years ago
|
if (empty($courses)) {
|
||
|
echo Display::return_message(get_lang('NoDestinationCoursesAvailable'), 'normal');
|
||
|
} else {
|
||
![]()
9 years ago
|
$form = new FormValidator(
|
||
|
'copy_course',
|
||
|
'post',
|
||
![]()
3 years ago
|
api_get_path(WEB_CODE_PATH).'course_copy/copy_course.php?'.api_get_cidreq()
|
||
![]()
9 years ago
|
);
|
||
![]()
4 years ago
|
$form->addSelect('destination_course', get_lang('Select target course'), $courses);
|
||
![]()
13 years ago
|
|
||
![]()
8 years ago
|
$group = [];
|
||
![]()
6 years ago
|
$group[] = $form->createElement('radio', 'copy_option', null, get_lang('Full copy'), 'full_copy');
|
||
|
$group[] = $form->createElement('radio', 'copy_option', null, get_lang('Let me select learning objects'), 'select_items');
|
||
|
$form->addGroup($group, '', get_lang('Please select a backup option'));
|
||
![]()
13 years ago
|
|
||
![]()
8 years ago
|
$group = [];
|
||
![]()
8 years ago
|
$group[] = $form->createElement(
|
||
|
'radio',
|
||
|
'same_file_name_option',
|
||
|
null,
|
||
![]()
6 years ago
|
get_lang('Skip same file name'),
|
||
![]()
8 years ago
|
FILE_SKIP
|
||
|
);
|
||
|
$group[] = $form->createElement(
|
||
|
'radio',
|
||
|
'same_file_name_option',
|
||
|
null,
|
||
![]()
6 years ago
|
get_lang('Rename file (eg file.pdf becomes file_1.pdf)'),
|
||
![]()
8 years ago
|
FILE_RENAME
|
||
|
);
|
||
|
$group[] = $form->createElement(
|
||
|
'radio',
|
||
|
'same_file_name_option',
|
||
|
null,
|
||
![]()
6 years ago
|
get_lang('Overwrite file'),
|
||
![]()
8 years ago
|
FILE_OVERWRITE
|
||
|
);
|
||
![]()
6 years ago
|
$form->addGroup($group, '', get_lang('What should be done with imported files with the same file name as existing files?'));
|
||
![]()
9 years ago
|
$form->addProgress();
|
||
![]()
6 years ago
|
$form->addButtonSave(get_lang('Copy course'));
|
||
![]()
8 years ago
|
$form->setDefaults(['copy_option' => 'select_items', 'same_file_name_option' => FILE_OVERWRITE]);
|
||
![]()
11 years ago
|
|
||
|
// Add Security token
|
||
|
$token = Security::get_token();
|
||
|
$form->addElement('hidden', 'sec_token');
|
||
![]()
8 years ago
|
$form->setConstants(['sec_token' => $token]);
|
||
![]()
14 years ago
|
$form->display();
|
||
![]()
11 years ago
|
}
|
||
![]()
19 years ago
|
}
|
||
![]()
16 years ago
|
|
||
![]()
12 years ago
|
Display::display_footer();
|