Actualización

This commit is contained in:
Xes
2025-04-10 12:49:05 +02:00
parent 4aff98e77b
commit 1cdd00920f
9151 changed files with 1800913 additions and 0 deletions

View File

@@ -0,0 +1,168 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
/**
* @todo rework file in order to use addFlash
*/
// Setting the global file that gets the general configuration, the databases, the languages, ...
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true);
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
api_set_more_memory_and_time_limits();
// Breadcrumbs
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php?'.api_get_cidreq(),
'name' => get_lang('Maintenance'),
];
// The section (for the tabs)
$this_section = SECTION_COURSES;
// Display the header
Display::display_header(get_lang('CopyCourse'));
echo Display::page_header(get_lang('CopyCourse'));
$action = isset($_POST['action']) ? $_POST['action'] : '';
// If a CourseSelectForm is posted or we should copy all resources, then copy them
if (Security::check_token('post') && (
($action === 'course_select_form') ||
(isset($_POST['copy_option']) && $_POST['copy_option'] === 'full_copy')
)
) {
// Clear token
Security::clear_token();
if ($action === 'course_select_form') {
$cb = new CourseBuilder('partial');
$course = $cb->build(0, null, false, array_keys($_POST['resource']), $_POST['resource']);
$course = CourseSelectForm::get_posted_course(null, 0, '', $course);
} else {
$cb = new CourseBuilder('complete');
$course = $cb->build();
}
// It builds the documents and items related to the LP
$cb->exportToCourseBuildFormat();
// It builds documents added in text (quizzes, assignments)
$cb->restoreDocumentsFromList();
$cr = new CourseRestorer($course);
$cr->set_file_option($_POST['same_file_name_option']);
$cr->restore($_POST['destination_course']);
echo Display::return_message(
get_lang('CopyFinished').': <a href="'.api_get_course_url($_POST['destination_course']).'">'.
Security::remove_XSS($_POST['destination_course']).
'</a>',
'normal',
false
);
} elseif (Security::check_token('post') && (
isset($_POST['copy_option']) &&
$_POST['copy_option'] === 'select_items'
)
) {
// Clear token
Security::clear_token();
$cb = new CourseBuilder();
$course = $cb->build();
$hiddenFields = [];
$hiddenFields['same_file_name_option'] = $_POST['same_file_name_option'];
$hiddenFields['destination_course'] = $_POST['destination_course'];
// Add token to Course select form
$hiddenFields['sec_token'] = Security::get_token();
CourseSelectForm::display_form($course, $hiddenFields, true);
} else {
$course_info = api_get_course_info();
$courseList = CourseManager::getCoursesFollowedByUser(
api_get_user_id(),
COURSEMANAGER,
null,
null,
null,
null,
false,
null,
null,
false,
'ORDER BY c.title'
);
$courses = [];
foreach ($courseList as $courseItem) {
if ($courseItem['real_id'] == $course_info['real_id']) {
continue;
}
$courses[$courseItem['code']] = $courseItem['title'].' ('.$courseItem['code'].')';
}
if (empty($courses)) {
echo Display::return_message(get_lang('NoDestinationCoursesAvailable'), 'normal');
} else {
$form = new FormValidator(
'copy_course',
'post',
api_get_path(WEB_CODE_PATH).'coursecopy/copy_course.php?'.api_get_cidreq()
);
$form->addElement(
'select',
'destination_course',
[
get_lang('SelectDestinationCourse'),
get_lang('YouCanOnlyCopyThisCourseToACourseYouTeach'),
],
$courses
);
$group = [];
$group[] = $form->createElement('radio', 'copy_option', null, get_lang('FullCopy'), 'full_copy');
$group[] = $form->createElement('radio', 'copy_option', null, get_lang('LetMeSelectItems'), 'select_items');
$form->addGroup($group, '', get_lang('SelectOptionForBackup'));
$group = [];
$group[] = $form->createElement(
'radio',
'same_file_name_option',
null,
get_lang('SameFilenameSkip'),
FILE_SKIP
);
$group[] = $form->createElement(
'radio',
'same_file_name_option',
null,
get_lang('SameFilenameRename'),
FILE_RENAME
);
$group[] = $form->createElement(
'radio',
'same_file_name_option',
null,
get_lang('SameFilenameOverwrite'),
FILE_OVERWRITE
);
$form->addGroup($group, '', get_lang('SameFilename'));
$form->addProgress();
$form->addButtonSave(get_lang('CopyCourse'));
$form->setDefaults(['copy_option' => 'select_items', 'same_file_name_option' => FILE_OVERWRITE]);
// Add Security token
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
$form->display();
}
}
Display::display_footer();

View File

@@ -0,0 +1,417 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
use ChamiloSession as Session;
/**
* Copy resources from one course in a session to another one.
*
* @author Christian Fasanando
* @author Julio Montoya <gugli100@gmail.com> Lots of bug fixes/improvements
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_admin_script();
api_protect_limit_for_session_admin();
api_set_more_memory_and_time_limits();
$xajax = new xajax();
$xajax->registerFunction('search_courses');
if (!api_is_allowed_to_edit() && !api_is_session_admin()) {
api_not_allowed(true);
}
$action = isset($_POST['action']) ? $_POST['action'] : '';
$this_section = SECTION_PLATFORM_ADMIN;
$nameTools = get_lang('CopyCourse');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
'name' => get_lang('PlatformAdmin'),
];
// Database Table Definitions
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
/**
* @param string $name
* @param array $sessions
* @param array $attr
*
* @return string
*/
function make_select_session_list($name, $sessions, $attr = [])
{
$attributes = '';
if (count($attr) > 0) {
foreach ($attr as $key => $value) {
$attributes .= ' '.$key.'="'.$value.'"';
}
}
$output = '<select id="session" class="form-control" name="'.$name.'" '.$attributes.'>';
if (count($sessions) == 0) {
$output .= '<option value = "0">'.get_lang('ThereIsNotStillASession').'</option>';
} else {
$output .= '<option value = "0">'.get_lang('SelectASession').'</option>';
}
if (is_array($sessions)) {
foreach ($sessions as $session) {
$categoryName = '';
if (!empty($session['category_name'])) {
$categoryName = ' ('.$session['category_name'].')';
}
$output .= '<option value="'.$session['id'].'">'.
$session['name'].' '.$categoryName.
'</option>';
}
}
$output .= '</select>';
return $output;
}
/**
* @return string
*/
function display_form()
{
$html = '';
$sessions = SessionManager::get_sessions_list([], ['name', 'ASC']);
// Link back to the documents overview
$actionsLeft = '<a href="../admin/index.php">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM).
'</a>';
$html .= Display::toolbarAction('toolbar-copysession', [$actionsLeft]);
$html .= Display::return_message(get_lang('CopyCourseFromSessionToSessionExplanation'), 'warning');
$html .= '<form class="form-horizontal" name="formulaire" method="post" action="'.api_get_self().'" >';
$html .= '<div class="form-group">';
// origin
$html .= '<label class="col-sm-2 control-label">'.get_lang('OriginCoursesFromSession').': </label>';
$html .= '<div class="col-sm-5">';
$html .= make_select_session_list(
'sessions_list_origin',
$sessions,
['onchange' => 'javascript: xajax_search_courses(this.value,\'origin\');']
);
$html .= '</div>';
$html .= '<div class="col-sm-5" id="ajax_list_courses_origin">';
$html .= '<select id="origin" class="form-control" name="SessionCoursesListOrigin[]" ></select>';
$html .= '</div></div>';
//destination
$html .= '<div class="form-group">';
$html .= '<label class="col-sm-2 control-label">'.get_lang('DestinationCoursesFromSession').': </label>';
$html .= '<div class="col-sm-5" id="ajax_sessions_list_destination">';
$html .= '<select class="form-control" name="sessions_list_destination" onchange="javascript: xajax_search_courses(this.value,\'destination\');">';
$html .= '<option value = "0">'.get_lang('ThereIsNotStillASession').'</option></select ></div>';
$html .= '<div class="col-sm-5" id="ajax_list_courses_destination">';
$html .= '<select id="destination" class="form-control" name="SessionCoursesListDestination[]" ></select>';
$html .= '</div></div>';
$options = '<div class="radio"><label><input type="radio" id="copy_option_1" name="copy_option" value="full_copy" checked="checked"/>';
$options .= get_lang('FullCopy').'</label></div>';
/*$options .= '<div class="radio"><label><input type="radio" id="copy_option_2" name="copy_option" value="select_items" disabled="disabled"/>';
$options .= ' '.get_lang('LetMeSelectItems').'</label></div>';*/
$options .= '<div class="checkbox"><label><input type="checkbox" id="copy_base_content_id" name="copy_only_session_items" />'.get_lang('CopyOnlySessionItems').'</label></div>';
$html .= Display::panel($options, get_lang('TypeOfCopy'));
$html .= '<div class="form-group"><div class="col-sm-12">';
$html .= '<button class="btn btn-success" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;"><em class="fa fa-files-o"></em> '.get_lang('CopyCourse').'</button>';
// Add Security token
$html .= '<input type="hidden" value="'.Security::get_token().'" name="sec_token">';
$html .= '</div></div>';
$html .= '</form>';
echo $html;
}
/**
* @param int $id_session
* @param string $type
*
* @return xajaxResponse
*/
function search_courses($id_session, $type)
{
global $tbl_course, $tbl_session_rel_course;
$xajax_response = new xajaxResponse();
$select_destination = '';
$return = null;
if (!empty($type)) {
$id_session = (int) $id_session;
if ($type == 'origin') {
$course_list = SessionManager::get_course_list_by_session_id($id_session);
$temp_course_list = [];
$return .= '<select id="origin" name="SessionCoursesListOrigin[]" class="form-control" onclick="javascript: checkSelected(this.id,\'copy_option_2\',\'title_option2\',\'destination\');">';
foreach ($course_list as $course) {
$temp_course_list[] = "'{$course['code']}'";
$return .= '<option value="'.$course['code'].'" title="'.@htmlspecialchars($course['title'].' ('.$course['visual_code'].')', ENT_QUOTES, api_get_system_encoding()).'">'.$course['title'].' ('.$course['visual_code'].')</option>';
}
$return .= '</select>';
Session::write('course_list', $temp_course_list);
Session::write('session_origin', $id_session);
// Build select for destination sessions where is not included current session from select origin
if (!empty($id_session)) {
$sessions = SessionManager::get_sessions_list([], ['name', 'ASC']);
$select_destination .= '<select name="sessions_list_destination" class="form-control" onchange = "javascript: xajax_search_courses(this.value,\'destination\');">';
$select_destination .= '<option value = "0">-- '.get_lang('SelectASession').' --</option>';
foreach ($sessions as $session) {
if ($id_session == $session['id']) {
continue;
}
if (!empty($session['category_name'])) {
$session['category_name'] = ' ('.$session['category_name'].') ';
}
$select_destination .= '<option value="'.$session['id'].'">'.$session['name'].' '.$session['category_name'].'</option>';
}
$select_destination .= '</select>';
$xajax_response->addAssign('ajax_sessions_list_destination', 'innerHTML', api_utf8_encode($select_destination));
} else {
$select_destination .= '<select name="sessions_list_destination" class="form-control" onchange = "javascript: xajax_search_courses(this.value,\'destination\');">';
$select_destination .= '<option value = "0">'.get_lang('ThereIsNotStillASession').'</option>';
$select_destination .= '</select>';
$xajax_response->addAssign('ajax_sessions_list_destination', 'innerHTML', api_utf8_encode($select_destination));
}
// Select multiple destination empty
$select_multiple_empty = '<select id="destination" name="SessionCoursesListDestination[]" class="form-control"></select>';
// Send response by ajax
$xajax_response->addAssign('ajax_list_courses_origin', 'innerHTML', api_utf8_encode($return));
$xajax_response->addAssign('ajax_list_courses_destination', 'innerHTML', api_utf8_encode($select_multiple_empty));
} else {
// Search courses by id_session where course codes is include en courses list destination
$sql = "SELECT c.code, c.visual_code, c.title, src.session_id
FROM $tbl_course c, $tbl_session_rel_course src
WHERE src.c_id = c.id
AND src.session_id = '".intval($id_session)."'";
//AND c.code IN ($list_courses_origin)";
$rs = Database::query($sql);
$course_list_destination = [];
$return .= '<select id="destination" name="SessionCoursesListDestination[]" class="form-control">';
while ($course = Database::fetch_array($rs)) {
$course_list_destination[] = $course['code'];
$return .= '<option value="'.$course['code'].'" title="'.@htmlspecialchars($course['title'].' ('.$course['visual_code'].')', ENT_QUOTES, api_get_system_encoding()).'">'.$course['title'].' ('.$course['visual_code'].')</option>';
}
$return .= '</select>';
Session::write('course_list_destination', $course_list_destination);
// Send response by ajax
$xajax_response->addAssign(
'ajax_list_courses_destination',
'innerHTML',
api_utf8_encode($return)
);
}
}
return $xajax_response;
}
$xajax->processRequests();
/* HTML head extra */
$htmlHeadXtra[] = $xajax->getJavascript(api_get_path(WEB_LIBRARY_PATH).'xajax/');
$htmlHeadXtra[] = '<script>
function checkSelected(id_select,id_radio,id_title,id_destination) {
var num=0;
obj_origin = document.getElementById(id_select);
obj_destination = document.getElementById(id_destination);
for (x=0;x<obj_origin.options.length;x++) {
if (obj_origin.options[x].selected) {
if (obj_destination.options.length > 0) {
for (y=0;y<obj_destination.options.length;y++) {
if (obj_origin.options[x].value == obj_destination.options[y].value) {
obj_destination.options[y].selected = true;
}
}
}
num++;
} else {
if (obj_destination.options.length > 0) {
for (y=0;y<obj_destination.options.length;y++) {
if (obj_origin.options[x].value == obj_destination.options[y].value) {
obj_destination.options[y].selected = false;
}
}
}
}
}
}
</script>';
Display::display_header($nameTools);
$with_base_content = true;
if (isset($_POST['copy_only_session_items']) && $_POST['copy_only_session_items']) {
$with_base_content = false;
}
/* MAIN CODE */
if (Security::check_token('post') && (
($action === 'course_select_form') || (
isset($_POST['copy_option']) &&
$_POST['copy_option'] == 'full_copy'
)
)
) {
// Clear token
Security::clear_token();
$destination_course = $origin_course = $destination_session = $origin_session = '';
if ($action === 'course_select_form') {
$destination_course = $_POST['destination_course'];
$origin_course = $_POST['origin_course'];
$destination_session = $_POST['destination_session'];
$origin_session = $_POST['origin_session'];
if ($course_code != $origin_course) {
$course = CourseSelectForm::get_posted_course(
'copy_course',
$origin_session,
$origin_course
);
$cr = new CourseRestorer($course);
//$cr->set_file_option($_POST['same_file_name_option']);
$cr->restore($destination_course, $destination_session);
echo Display::return_message(get_lang('CopyFinished'), 'confirmation');
display_form();
} else {
echo Display::return_message(get_lang('PleaseSelectACourse'), 'confirm');
display_form();
}
} else {
$arr_course_origin = [];
$arr_course_destination = [];
$destination_session = '';
$origin_session = '';
if (isset($_POST['SessionCoursesListOrigin'])) {
$arr_course_origin = $_POST['SessionCoursesListOrigin'];
}
if (isset($_POST['SessionCoursesListDestination'])) {
$arr_course_destination = $_POST['SessionCoursesListDestination'];
}
if (isset($_POST['sessions_list_destination'])) {
$destination_session = $_POST['sessions_list_destination'];
}
if (isset($_POST['sessions_list_origin'])) {
$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) {
echo Display::return_message(get_lang('YouMustSelectACourseFromOriginalSession'), 'error');
} else {
//first element of the array
$course_code = $arr_course_origin[0];
$course_destinatination = $arr_course_destination[0];
if ($course_code != $course_destinatination) {
$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);
echo Display::return_message(get_lang('CopyFinished'), 'confirm');
display_form();
} else {
echo Display::return_message(get_lang('PleaseSelectACourse'), 'confirm');
display_form();
}
}
} else {
echo Display::return_message(get_lang('YouMustSelectACourseFromOriginalSession'), 'error');
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') {
echo Display::return_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'), 'normal');
}
$arr_course_origin = [];
$arr_course_destination = [];
$destination_session = '';
$origin_session = '';
if (isset($_POST['SessionCoursesListOrigin'])) {
$arr_course_origin = $_POST['SessionCoursesListOrigin'];
}
if (isset($_POST['SessionCoursesListDestination'])) {
$arr_course_destination = $_POST['SessionCoursesListDestination'];
}
if (isset($_POST['sessions_list_destination'])) {
$destination_session = $_POST['sessions_list_destination'];
}
if (isset($_POST['sessions_list_origin'])) {
$origin_session = $_POST['sessions_list_origin'];
}
if ((is_array($arr_course_origin) && count($arr_course_origin) > 0) && !empty($destination_session)) {
echo Display::return_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'), 'normal');
$course_origin = api_get_course_info($arr_course_origin[0]);
$cb = new CourseBuilder('', $course_origin);
$course = $cb->build($origin_session, $arr_course_origin[0], $with_base_content);
$hiddenFields['destination_course'] = $arr_course_destination[0];
$hiddenFields['origin_course'] = $arr_course_origin[0];
$hiddenFields['destination_session'] = $destination_session;
$hiddenFields['origin_session'] = $origin_session;
// Add token to Course select form
$hiddenFields['sec_token'] = Security::get_token();
CourseSelectForm::display_form($course, $hiddenFields, true);
echo '<div style="float:right"><a href="javascript:window.history.go(-1);">'.
Display::return_icon(
'back.png',
get_lang('Back').' '.get_lang('To').' '.get_lang('PlatformAdmin'),
['style' => 'vertical-align:middle']
).
get_lang('Back').'</a></div>';
} else {
echo Display::return_message(
get_lang('You must select a course from original session and select a destination session'),
'error'
);
display_form();
}
} else {
display_form();
}
Display::display_footer();

View File

@@ -0,0 +1,400 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
use ChamiloSession as Session;
/**
* Copy resources from one course in a session to another one.
*
* @author Christian Fasanando
* @author Julio Montoya <gugli100@gmail.com> Lots of bug fixes/improvements
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com> Code conventions
*
* @package chamilo.backup
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true, true);
api_set_more_memory_and_time_limits();
$xajax = new xajax();
$xajax->registerFunction('searchCourses');
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
if (!api_is_coach()) {
api_not_allowed(true);
}
$action = isset($_POST['action']) ? $_POST['action'] : '';
$courseId = api_get_course_int_id();
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];
$sessionId = api_get_session_id();
if (empty($courseCode) || empty($sessionId)) {
api_not_allowed(true);
}
$this_section = SECTION_COURSES;
$nameTools = get_lang('CopyCourse');
$returnLink = api_get_path(WEB_CODE_PATH).'course_info/maintenance_coach.php?'.api_get_cidreq();
$interbreadcrumb[] = [
'url' => $returnLink,
'name' => get_lang('Maintenance'),
];
/**
* @param string $name
*/
function make_select_session_list($name, $sessions, $attr = [])
{
$attrs = '';
if (count($attr) > 0) {
foreach ($attr as $key => $value) {
$attrs .= ' '.$key.'="'.$value.'"';
}
}
$output = '<select name="'.$name.'" '.$attrs.'>';
if (count($sessions) == 0) {
$output .= '<option value = "0">'.get_lang(
'ThereIsNotStillASession'
).'</option>';
} else {
$output .= '<option value = "0">'.get_lang(
'SelectASession'
).'</option>';
}
if (is_array($sessions)) {
foreach ($sessions as $session) {
$category_name = '';
if (!empty($session['category_name'])) {
$category_name = ' ('.$session['category_name'].')';
}
$output .= '<option value="'.$session['id'].'">'.$session['name'].' '.$category_name.'</option>';
}
}
$output .= '</select>';
return $output;
}
/**
* Show the form to copy courses.
*
* @global string $returnLink
* @global string $courseCode
*/
function displayForm()
{
global $returnLink, $courseCode;
$courseInfo = api_get_course_info();
$sessionId = api_get_session_id();
$userId = api_get_user_id();
$sessions = SessionManager::getSessionsCoachedByUser($userId);
$html = '';
// Actions
$html .= '<div class="actions">';
// Link back to the documents overview
$html .= '<a href="'.$returnLink.'">'.Display::return_icon(
'back.png',
get_lang('BackTo').' '.get_lang('Maintenance'),
'',
ICON_SIZE_MEDIUM
).'</a>';
$html .= '</div>';
$html .= Display::return_message(
get_lang('CopyCourseFromSessionToSessionExplanation')
);
$html .= '<form name="formulaire" method="post" action="'.api_get_self().'?'.api_get_cidreq().'" >';
$html .= '<table border="0" cellpadding="5" cellspacing="0" width="100%">';
// Source
$html .= '<tr><td width="15%"><b>'.get_lang(
'OriginCoursesFromSession'
).':</b></td>';
$html .= '<td width="10%" align="left">'.api_get_session_name(
$sessionId
).'</td>';
$html .= '<td width="50%">';
$html .= "{$courseInfo['title']} ({$courseInfo['code']})".'</td></tr>';
// Destination
$html .= '<tr><td width="15%"><b>'.get_lang(
'DestinationCoursesFromSession'
).':</b></td>';
$html .= '<td width="10%" align="left"><div id="ajax_sessions_list_destination">';
$html .= '<select name="sessions_list_destination" onchange="javascript: xajax_searchCourses(this.value,\'destination\');">';
if (empty($sessions)) {
$html .= '<option value = "0">'.get_lang(
'ThereIsNotStillASession'
).'</option>';
} else {
$html .= '<option value = "0">'.get_lang(
'SelectASession'
).'</option>';
foreach ($sessions as $session) {
if ($session['id'] == $sessionId) {
continue;
}
if (!SessionManager::sessionHasCourse($session['id'], $courseCode)) {
continue;
}
$html .= '<option value="'.$session['id'].'">'.$session['name'].'</option>';
}
}
$html .= '</select ></div></td>';
$html .= '<td width="50%">';
$html .= '<div id="ajax_list_courses_destination">';
$html .= '<select id="destination" name="SessionCoursesListDestination[]" style="width:380px;" ></select></div></td>';
$html .= '</tr></table>';
$html .= "<fieldset>";
$html .= '<legend>'.get_lang('TypeOfCopy').' <small>('.get_lang('CopyOnlySessionItems').')</small></legend>';
$html .= '<label class="radio"><input type="radio" id="copy_option_1" name="copy_option" value="full_copy" checked="checked"/>';
$html .= get_lang('FullCopy').'</label>';
/*$html .= '<label class="radio"><input type="radio" id="copy_option_2" name="copy_option" value="select_items"/>';
$html .= ' '.get_lang('LetMeSelectItems').'</label><br/>';*/
$html .= "</fieldset>";
$html .= '<button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(
api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)
)."'".')) return false;">'.get_lang('CopyCourse').'</button>';
$html .= '</form>';
echo $html;
}
function searchCourses($idSession, $type)
{
$xajaxResponse = new xajaxResponse();
$return = null;
$courseCode = api_get_course_id();
if (!empty($type)) {
$idSession = (int) $idSession;
$courseList = SessionManager::get_course_list_by_session_id($idSession);
$return .= '<select id="destination" name="SessionCoursesListDestination[]" style="width:380px;" >';
foreach ($courseList as $course) {
$course_list_destination[] = $course['code'];
if ($course['code'] != $courseCode) {
continue;
}
$courseTitle = str_replace("'", "\'", $course['title']);
$return .= '<option value="'.$course['code'].'" title="'.@htmlspecialchars(
$course['title'].' ('.$course['visual_code'].')',
ENT_QUOTES,
api_get_system_encoding()
).'">'.
$course['title'].' ('.$course['visual_code'].')</option>';
}
$return .= '</select>';
Session::write('course_list_destination', $course_list_destination);
// Send response by ajax
$xajaxResponse->addAssign(
'ajax_list_courses_destination',
'innerHTML',
api_utf8_encode($return)
);
}
return $xajaxResponse;
}
$xajax->processRequests();
$htmlHeadXtra[] = $xajax->getJavascript(
api_get_path(WEB_LIBRARY_PATH).'xajax/'
);
$htmlHeadXtra[] = '<script>
function checkSelected(id_select,id_radio,id_title,id_destination) {
var num=0;
obj_origin = document.getElementById(id_select);
obj_destination = document.getElementById(id_destination);
for (x=0;x<obj_origin.options.length;x) {
if (obj_origin.options[x].selected) {
if (obj_destination.options.length > 0) {
for (y=0;y<obj_destination.options.length;y) {
if (obj_origin.options[x].value == obj_destination.options[y].value) {
obj_destination.options[y].selected = true;
}
}
}
num;
} else {
if (obj_destination.options.length > 0) {
for (y=0;y<obj_destination.options.length;y) {
if (obj_origin.options[x].value == obj_destination.options[y].value) {
obj_destination.options[y].selected = false;
}
}
}
}
}
if (num == 1) {
document.getElementById(id_radio).disabled = false;
document.getElementById(id_title).style.color = \'#000\';
} else {
document.getElementById(id_radio).disabled = true;
document.getElementById(id_title).style.color = \'#aaa\';
}
}
</script>';
Display::display_header($nameTools);
/* MAIN CODE */
if (($action === 'course_select_form') ||
(isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')
) {
$destinationCourse = $destinationSession = '';
$originCourse = api_get_course_id();
$originSession = api_get_session_id();
if ($action === 'course_select_form') {
$destinationCourse = $_POST['destination_course'];
$destinationSession = $_POST['destination_session'];
$course = CourseSelectForm::get_posted_course(
'copy_course',
$originSession,
$originCourse
);
$cr = new CourseRestorer($course);
$cr->restore($destinationCourse, $destinationSession);
echo Display::return_message(get_lang('CopyFinished'), 'confirmation');
displayForm();
} else {
$arrCourseOrigin = [];
$arrCourseDestination = [];
$destinationSession = '';
if (isset($_POST['SessionCoursesListDestination'])) {
$arrCourseDestination = $_POST['SessionCoursesListDestination'];
if (!empty($arrCourseDestination)) {
$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) {
echo Display::return_message(
get_lang('YouMustSelectACourseFromOriginalSession'),
'error'
);
} else {
$courseDestination = $arrCourseDestination[0];
$cb = new CourseBuilder('', $courseInfo);
$course = $cb->build(
$originSession,
$courseCode
);
$cr = new CourseRestorer($course);
$cr->restore($courseDestination, $destinationSession);
echo Display::return_message(get_lang('CopyFinished'), 'confirmation');
}
displayForm();
} else {
echo Display::return_message(
get_lang('YouMustSelectACourseFromOriginalSession'),
'error'
);
displayForm();
}
}
} elseif (isset($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
// Else, if a CourseSelectForm is requested, show it
if (api_get_setting('show_glossary_in_documents') != 'none') {
echo Display::return_message(
get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'),
'normal'
);
}
$arrCourseDestination = [];
$destinationSession = '';
if (isset($_POST['SessionCoursesListDestination'])) {
$arrCourseDestination = $_POST['SessionCoursesListDestination'];
}
if (isset($_POST['sessions_list_destination'])) {
$destinationSession = $_POST['sessions_list_destination'];
}
if (!empty($destinationSession)) {
echo Display::return_message(
get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'),
'normal'
);
$cb = new CourseBuilder('', $courseInfo);
$course = $cb->build($sessionId, $courseCode);
$hiddenFields['destination_course'] = $arrCourseDestination[0];
$hiddenFields['destination_session'] = $destinationSession;
$hiddenFields['origin_course'] = api_get_course_id();
$hiddenFields['origin_session'] = api_get_session_id();
CourseSelectForm::display_form($course, $hiddenFields, true);
echo '<div style="float:right"><a href="javascript:window.history.go(-1);">'.
Display::return_icon(
'back.png',
get_lang('Back').' '.get_lang('To').' '.get_lang(
'PlatformAdmin'
),
['style' => 'vertical-align:middle']
).
get_lang('Back').'</a></div>';
} else {
echo Display::return_message(
get_lang('You must select a course from original session and select a destination session'),
'error'
);
displayForm();
}
} else {
displayForm();
}
Display::display_footer();

View File

@@ -0,0 +1,119 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
/**
* Create a backup.
*
* @author Bart Mollet <bart.mollet@hogent.be>
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true);
// Check access rights (only teachers are allowed here)
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
api_check_archive_dir();
api_set_more_memory_and_time_limits();
// Section for the tabs
$this_section = SECTION_COURSES;
// Breadcrumbs
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php',
'name' => get_lang('Maintenance'),
];
// Displaying the header
$nameTools = get_lang('CreateBackup');
Display::display_header($nameTools);
// Display the tool title
echo Display::page_header($nameTools);
$action = isset($_POST['action']) ? $_POST['action'] : '';
$backupOption = isset($_POST['backup_option']) ? $_POST['backup_option'] : '';
if (Security::check_token('post') &&
($action === 'course_select_form' || $backupOption === 'full_backup')
) {
// Clear token
Security::clear_token();
if ($action === 'course_select_form') {
$cb = new CourseBuilder('partial');
$course = $cb->build(0, null, false, array_keys($_POST['resource']), $_POST['resource']);
$course = CourseSelectForm::get_posted_course(null, 0, '', $course);
} else {
$cb = new CourseBuilder('complete');
$course = $cb->build();
}
// It builds the documents and items related to the LP
$cb->exportToCourseBuildFormat();
// It builds documents added in text (quizzes, assignments)
$cb->restoreDocumentsFromList();
$zipFile = CourseArchiver::createBackup($course);
echo Display::return_message(get_lang('BackupCreated'), 'confirm');
echo '<br />';
echo Display::url(
get_lang('Download'),
api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.$zipFile.'&'.api_get_cidreq(),
['class' => 'btn btn-primary btn-large']
);
} elseif (Security::check_token('post') && $backupOption === 'select_items') {
// Clear token
Security::clear_token();
$cb = new CourseBuilder('partial');
$course = $cb->build();
if ($course->has_resources()) {
// Add token to Course select form
$hiddenFields['sec_token'] = Security::get_token();
CourseSelectForm::display_form($course, $hiddenFields, false, true);
} else {
echo Display::return_message(get_lang('NoResourcesToBackup'), 'warning');
}
} else {
$form = new FormValidator(
'create_backup_form',
'post',
api_get_self().'?'.api_get_cidreq()
);
$form->addElement('header', get_lang('SelectOptionForBackup'));
$form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
$form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
$form->addButtonSave(get_lang('CreateBackup'));
$form->addProgress();
// When progress bar appears we have to hide the title "Please select a backup-option".
$form->updateAttributes(
[
'onsubmit' => str_replace(
'javascript: ',
'javascript: page_title = getElementById(\'page_title\'); if (page_title) { setTimeout(\'page_title.style.display = \\\'none\\\';\', 2000); } ',
$form->getAttribute('onsubmit')
),
]
);
$values['backup_option'] = 'full_backup';
$form->setDefaults($values);
// Add Security token
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
echo '<div class="row">';
echo '<div class="col-md-12">';
echo '<div class="tool-backup">';
$form->display();
echo '</div>';
echo '</div>';
echo '</div>';
}
Display::display_footer();

View File

@@ -0,0 +1,178 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
use moodleexport\MoodleExport;
/**
* Create a Moodle export.
*/
require_once __DIR__.'/../inc/global.inc.php';
require_once api_get_path(SYS_PATH).'main/work/work.lib.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true);
// Check access rights (only teachers are allowed here)
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
api_check_archive_dir();
api_set_more_memory_and_time_limits();
// Section for the tabs
$this_section = SECTION_COURSES;
// Breadcrumbs
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php',
'name' => get_lang('Maintenance'),
];
// Displaying the header
$nameTools = get_lang('ExportToMoodle');
Display::display_header($nameTools);
// Display the tool title
echo Display::page_header($nameTools);
$action = isset($_POST['action']) ? $_POST['action'] : '';
$exportOption = isset($_POST['export_option']) ? $_POST['export_option'] : '';
// Handle course selection form submission
if ($action === 'course_select_form' && Security::check_token('post')) {
// Handle the selected resources and continue with export
$selectedResources = $_POST['resource'] ?? null;
if (!empty($selectedResources)) {
// Rebuild the course object based on selected resources
$cb = new CourseBuilder('partial');
$course = $cb->build(0, null, false, array_keys($selectedResources), $selectedResources);
// Get admin details
$adminId = (int) $_POST['admin_id'];
$adminUsername = filter_var($_POST['admin_username'], FILTER_SANITIZE_STRING);
if (!preg_match('/^[a-zA-Z0-9_]+$/', $adminUsername)) {
echo Display::return_message(get_lang('PleaseEnterValidLogin'), 'error');
exit();
}
$adminEmail = filter_var($_POST['admin_email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
echo Display::return_message(get_lang('PleaseEnterValidEmail'), 'error');
exit();
}
$exporter = new MoodleExport($course);
$exporter->setAdminUserData($adminId, $adminUsername, $adminEmail);
// Perform export
$courseId = api_get_course_id();
$exportDir = 'moodle_export_'.$courseId;
try {
$moodleVersion = isset($_POST['moodle_version']) ? (int) $_POST['moodle_version'] : 3;
$mbzFile = $exporter->export($courseId, $exportDir, $moodleVersion);
echo Display::return_message(get_lang('MoodleExportCreated'), 'confirm');
echo '<br />';
echo Display::url(
get_lang('Download'),
api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=1&archive='.basename($mbzFile).'&'.api_get_cidreq(),
['class' => 'btn btn-primary btn-large']
);
} catch (Exception $e) {
echo Display::return_message(get_lang('ErrorCreatingExport').': '.$e->getMessage(), 'error');
}
exit();
} else {
echo Display::return_message(get_lang('NoResourcesSelected'), 'warning');
}
} else {
$form = new FormValidator(
'create_export_form',
'post',
api_get_self().'?'.api_get_cidreq()
);
$form->addElement('radio', 'export_option', '', get_lang('CreateFullBackup'), 'full_export');
$form->addElement('radio', 'export_option', '', get_lang('LetMeSelectItems'), 'select_items');
$form->addElement('select', 'moodle_version', get_lang('MoodleVersion'), [
'3' => 'Moodle 3.x',
'4' => 'Moodle 4.x',
]);
$form->addElement('text', 'admin_id', [get_lang('AdminID'), get_lang('MoodleExportAdminIDComment')], ['maxlength' => 10, 'size' => 10]);
$form->addElement('text', 'admin_username', get_lang('AdminLogin'), ['maxlength' => 100, 'size' => 50]);
$form->addElement('text', 'admin_email', get_lang('AdminEmail'), ['maxlength' => 100, 'size' => 50]);
// Add validation rules
$form->addRule('admin_id', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('admin_username', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('admin_email', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('admin_email', get_lang('EnterValidEmail'), 'email');
$values['export_option'] = 'select_items';
$form->setDefaults($values);
// Add buttons
$form->addButtonSave(get_lang('CreateExport'));
$form->addProgress();
if ($form->validate()) {
$values = $form->exportValues();
$adminId = (int) $values['admin_id'];
$adminUsername = $values['admin_username'];
$adminEmail = $values['admin_email'];
if ($values['export_option'] === 'full_export') {
$cb = new CourseBuilder('complete');
$course = $cb->build();
$exporter = new MoodleExport($course);
$exporter->setAdminUserData($adminId, $adminUsername, $adminEmail);
$courseId = api_get_course_id(); // Get course ID
$exportDir = 'moodle_export_'.$courseId;
try {
$moodleVersion = isset($values['moodle_version']) ? $values['moodle_version'] : '3';
$mbzFile = $exporter->export($courseId, $exportDir, $moodleVersion);
echo Display::return_message(get_lang('MoodleExportCreated'), 'confirm');
echo '<br />';
echo Display::url(
get_lang('Download'),
api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=1&archive='.basename($mbzFile).'&'.api_get_cidreq(),
['class' => 'btn btn-primary btn-large']
);
} catch (Exception $e) {
echo Display::return_message(get_lang('ErrorCreatingExport').': '.$e->getMessage(), 'error');
}
} elseif ($values['export_option'] === 'select_items') {
// Partial export - go to the item selection step
$cb = new CourseBuilder('partial');
$course = $cb->build();
if ($course->has_resources()) {
// Add token to Course select form
$hiddenFields['sec_token'] = Security::get_token();
$hiddenFields['admin_id'] = $adminId;
$hiddenFields['admin_username'] = $adminUsername;
$hiddenFields['admin_email'] = $adminEmail;
CourseSelectForm::display_form($course, $hiddenFields, false, true);
} else {
echo Display::return_message(get_lang('NoResourcesToExport'), 'warning');
}
}
} else {
echo '<div class="row">';
echo '<div class="col-md-12">';
echo '<div class="tool-export">';
$form->display();
echo '</div>';
echo '</div>';
}
}
Display::display_footer();

View File

@@ -0,0 +1,275 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
use ChamiloSession as Session;
/**
* Import a backup.
*
* @author Bart Mollet <bart.mollet@hogent.be>
*
* @package chamilo.backup
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true);
// Check access rights (only teachers are allowed here)
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
api_set_more_memory_and_time_limits();
$isPlatformAdmin = api_is_platform_admin();
// Section for the tabs
$this_section = SECTION_COURSES;
// Breadcrumbs
$interbreadcrumb[] = [
'url' => '../course_info/maintenance.php',
'name' => get_lang('Maintenance'),
];
// Displaying the header
$nameTools = get_lang('ImportBackup');
Display::display_header($nameTools);
// Display the tool title
echo Display::page_header($nameTools);
$action = isset($_POST['action']) ? $_POST['action'] : '';
$importOption = isset($_POST['import_option']) ? $_POST['import_option'] : '';
/* MAIN CODE */
$filename = '';
if (Security::check_token('post') && ($action === 'course_select_form' || $importOption === 'full_backup')) {
// Clear token
Security::clear_token();
$error = false;
if ($action === 'course_select_form') {
// Partial backup here we recover the documents posted
$filename = Session::read('backup_file');
$course = CourseArchiver::readCourse($filename, false);
$course = CourseSelectForm::get_posted_course(null, null, null, $course);
} else {
if ($_POST['backup_type'] === 'server') {
$filename = $_POST['backup_server'];
$delete_file = false;
} else {
if ($_FILES['backup']['error'] == 0) {
$filename = CourseArchiver::importUploadedFile($_FILES['backup']['tmp_name']);
if ($filename === false) {
$error = true;
} else {
$delete_file = false;
}
Session::write('backup_file', $filename);
} else {
$error = true;
}
}
if (!$error) {
// Full backup
$course = CourseArchiver::readCourse($filename, $delete_file);
}
}
if (!$error && is_object($course) && $course->has_resources()) {
$cr = new CourseRestorer($course);
$cr->set_file_option($_POST['same_file_name_option']);
$cr->restore();
echo Display::return_message(get_lang('ImportFinished'));
echo '<a class="btn btn-default" href="'.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php">'.
get_lang('CourseHomepage').'</a>';
} else {
if (!$error) {
echo Display::return_message(get_lang('NoResourcesInBackupFile'), 'warning');
echo '<a class="btn btn-default" href="import_backup.php?'.api_get_cidreq().'">'.get_lang('TryAgain').'</a>';
} elseif ($filename === false) {
echo Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'error');
echo '<a class="btn btn-default" href="import_backup.php?'.api_get_cidreq().'">'.get_lang('TryAgain').'</a>';
} else {
if ($filename == '') {
echo Display::return_message(get_lang('SelectBackupFile'), 'error');
echo '<a class="btn btn-default" href="import_backup.php?'.api_get_cidreq().'">'.get_lang('TryAgain').'</a>';
} else {
echo Display::return_message(get_lang('UploadError'), 'error');
echo '<a class="btn btn-default" href="import_backup.php?'.api_get_cidreq().'">'.get_lang('TryAgain').'</a>';
}
}
}
CourseArchiver::cleanBackupDir();
} elseif (Security::check_token('post') && $importOption === 'select_items') {
// Clear token
Security::clear_token();
if ($_POST['backup_type'] === 'server') {
$filename = $_POST['backup_server'];
$delete_file = false;
} else {
$filename = CourseArchiver::importUploadedFile($_FILES['backup']['tmp_name']);
$delete_file = false;
Session::write('backup_file', $filename);
}
$course = CourseArchiver::readCourse($filename, $delete_file);
if ($course->has_resources() && $filename !== false) {
$hiddenFields['same_file_name_option'] = $_POST['same_file_name_option'];
// Add token to Course select form
$hiddenFields['sec_token'] = Security::get_token();
CourseSelectForm::display_form($course, $hiddenFields);
} elseif ($filename === false) {
echo Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'error');
echo '<a class="btn btn-default" href="import_backup.php?'.api_get_cidreq().'">'.get_lang('TryAgain').'</a>';
} else {
echo Display::return_message(get_lang('NoResourcesInBackupFile'), 'warning');
echo '<a class="btn btn-default" href="import_backup.php?'.api_get_cidreq().'">'.get_lang('TryAgain').'</a>';
}
} else {
$user = api_get_user_info();
$backups = CourseArchiver::getAvailableBackups($isPlatformAdmin ? null : $user['user_id']);
$backups_available = count($backups) > 0;
$form = new FormValidator(
'import_backup_form',
'post',
api_get_path(WEB_CODE_PATH).'coursecopy/import_backup.php?'.api_get_cidreq(),
'',
['enctype' => 'multipart/form-data']
);
$form->addElement('header', get_lang('SelectBackupFile'));
$renderer = $form->defaultRenderer();
$renderer->setCustomElementTemplate('<div>{element}</div> ');
$form->addElement('hidden', 'action', 'restore_backup');
$form->addElement(
'radio',
'backup_type',
'',
get_lang('LocalFile'),
'local',
'id="bt_local" class="checkbox" onclick="javascript: document.import_backup_form.backup_server.disabled=true;document.import_backup_form.backup.disabled=false;"'
);
$form->addElement('file', 'backup', '', 'style="margin-left: 50px;"');
$form->addElement('html', '<br />');
if ($backups_available) {
$form->addElement(
'radio',
'backup_type',
'',
get_lang('ServerFile'),
'server',
'id="bt_server" class="checkbox" onclick="javascript: document.import_backup_form.backup_server.disabled=false;document.import_backup_form.backup.disabled=true;"'
);
$options['null'] = '-';
foreach ($backups as $index => $backup) {
$options[$backup['file']] = $backup['course_code'].' ('.$backup['date'].')';
}
$form->addElement(
'select',
'backup_server',
'',
$options,
'style="margin-left: 50px;"'
);
$form->addElement(
'html',
'<script type="text/javascript">document.import_backup_form.backup_server.disabled=true;</script>'
);
} else {
$form->addElement(
'radio',
'',
'',
'<i>'.get_lang('NoBackupsAvailable').'</i>',
'',
'disabled="true"'
);
}
$form->addElement('html', '<br /><br />');
$form->addElement(
'radio',
'import_option',
'',
get_lang('ImportFullBackup'),
'full_backup',
'id="import_option_1" class="checkbox"'
);
$form->addElement(
'radio',
'import_option',
'',
get_lang('LetMeSelectItems'),
'select_items',
'id="import_option_2" class="checkbox"'
);
$form->addElement('html', '<br /><br />');
$form->addElement('html', get_lang('SameFilename'));
$form->addElement('html', '<br /><br />');
$form->addElement(
'radio',
'same_file_name_option',
'',
get_lang('SameFilenameSkip'),
FILE_SKIP,
'id="same_file_name_option_1" class="checkbox"'
);
$form->addElement(
'radio',
'same_file_name_option',
'',
get_lang('SameFilenameRename'),
FILE_RENAME,
'id="same_file_name_option_2" class="checkbox"'
);
$form->addElement(
'radio',
'same_file_name_option',
'',
get_lang('SameFilenameOverwrite'),
FILE_OVERWRITE,
'id="same_file_name_option_3" class="checkbox"'
);
$form->addElement('html', '<br />');
$form->addButtonImport(get_lang('ImportBackup'));
$values['backup_type'] = 'local';
$values['import_option'] = 'full_backup';
$values['same_file_name_option'] = FILE_OVERWRITE;
$form->setDefaults($values);
$form->addProgress();
// When progress bar appears we have to hide the title "Select backup file".
$form->updateAttributes([
'onsubmit' => str_replace(
'javascript: ',
'javascript: page_title = getElementById(\'page_title\'); if (page_title) { setTimeout(\'page_title.style.display = \\\'none\\\';\', 2000); } ',
$form->getAttribute('onsubmit')
),
]);
// Add Security token
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
$form->display();
}
if (!isset($_POST['action'])) {
Session::erase('backup_file');
}
Display::display_footer();

View File

@@ -0,0 +1,63 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Import a backup from moodle system.
*
* @author José Loguercio <jose.loguercio@beeznest.com>
* @author Julio Montoya
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true);
// Check access rights (only teachers are allowed here)
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
api_set_more_memory_and_time_limits();
// Section for the tabs
$this_section = SECTION_COURSES;
// Breadcrumbs
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php?'.api_get_cidreq(),
'name' => get_lang('Maintenance'),
];
$form = new FormValidator('import_moodle', 'post', api_get_self().'?'.api_get_cidreq());
$form->addFile('moodle_file', get_lang('MoodleFile'));
$form->addButtonImport(get_lang('Import'));
if ($form->validate()) {
$file = $_FILES['moodle_file'];
$moodleImport = new MoodleImport();
try {
$responseImport = $moodleImport->import($file);
Display::addFlash(
Display::return_message(
get_lang('MoodleFileImportedSuccessfully'),
'success'
)
);
} catch (Exception $exception) {
Display::addFlash(
Display::return_message($exception->getMessage(), 'error')
);
}
}
$template = new Template(get_lang('ImportFromMoodle'));
$infoMsg = Display::return_message(get_lang('ImportFromMoodleInstructions'), 'normal', false);
$template->assign('info_msg', $infoMsg);
$template->assign('form', $form->returnForm());
$templateName = $template->get_template('coursecopy/import_moodle.tpl');
$content = $template->fetch($templateName);
$template->assign('header', get_lang('ImportFromMoodle'));
$template->assign('content', $content);
$template->display_one_col_template();

View File

@@ -0,0 +1,166 @@
<?php
/* For licensing terms, see /license.txt */
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_admin_script();
api_protect_limit_for_session_admin();
api_set_more_memory_and_time_limits();
$courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0;
$sourceSessionId = isset($_REQUEST['source_session_id']) ? (int) $_REQUEST['source_session_id'] : 0;
$destinationSessionId = isset($_REQUEST['destination_session_id']) ? (int) $_REQUEST['destination_session_id'] : 0;
$page = 1;
if (isset($_GET['page']) && !empty($_GET['page'])) {
$page = (int) $_GET['page'];
}
$courseOptions = [];
$defaults = [];
$courseInfo = [];
if (!empty($courseId)) {
$defaults['course_id'] = $courseId;
$courseInfo = api_get_course_info_by_id($courseId);
$courseOptions[$courseId] = $courseInfo['name'];
}
$currentUrl = api_get_self().'?course_id='.$courseId.
'&source_session_id='.$sourceSessionId.'&destination_session_id='.$destinationSessionId;
$form = new FormValidator('course', 'GET', api_get_self().'?course_id='.$courseId);
$form->addHeader(get_lang('MoveUsersFromCourseToSession'));
$form->addSelectAjax(
'course_id',
get_lang('Course'),
$courseOptions,
[
'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course',
]
);
$form->addHidden('page', $page);
$form->addButtonSearch(get_lang('Search'));
$content = '';
if (!empty($courseId)) {
if (!empty($sourceSessionId) && $sourceSessionId === $destinationSessionId) {
Display::addFlash(Display::return_message(get_lang('CantMoveToTheSameSession')));
api_location(api_get_self());
}
$sessions = SessionManager::get_session_by_course($courseId);
if (!empty($sessions)) {
$sessions = array_column($sessions, 'name', 'id');
$form->addHtml(Display::page_subheader2(get_lang('Sessions')));
$sessionsWithBase = [0 => get_lang('BaseCourse')] + $sessions;
$form->addSelect(
'source_session_id',
get_lang('Source'),
$sessionsWithBase
);
$form->addSelect(
'destination_session_id',
get_lang('Destination'),
$sessions
);
$form->addButtonSearch(get_lang('CompareStats'), 'compare');
$form->addButtonCopy(get_lang('Move'), 'move');
}
if (empty($sourceSessionId)) {
$count = CourseManager::get_user_list_from_course_code($courseInfo['code'], 0, null, null, STUDENT, true);
} else {
$count = CourseManager::get_user_list_from_course_code(
$courseInfo['code'],
$sourceSessionId,
null,
null,
0,
true
);
}
$students = [];
if (isset($_REQUEST['compare']) || isset($_REQUEST['move'])) {
/*$default = 20;
$nro_pages = round($count / $default) + 1;
$begin = $default * ($page - 1);
$end = $default * $page;
if ($count > $default) {
$navigation = "$begin - $end / $count<br />";
if ($page > 1) {
$navigation .= '<a href="'.$currentUrl.'&compare=1&page='.($page - 1).'">'.get_lang('Previous').'</a>';
} else {
$navigation .= get_lang('Previous');
}
$navigation .= '&nbsp;';
if ($page < $nro_pages) {
$page++;
$navigation .= '<a href="'.$currentUrl.'&compare=1&page='.$page.'">'.get_lang('Next').'</a>';
} else {
$navigation .= get_lang('Next');
}
$content .= $navigation;
}*/
//$limit = "LIMIT $begin, $default";
$limit = null;
if (empty($sourceSessionId)) {
$students = CourseManager::get_user_list_from_course_code($courseInfo['code'], 0, $limit, null, STUDENT);
} else {
$students = CourseManager::get_user_list_from_course_code(
$courseInfo['code'],
$sourceSessionId,
$limit,
null,
0
);
}
foreach ($students as $student) {
$studentId = $student['user_id'];
$name = $student['firstname'].' '.$student['lastname'];
$content .= "<h2>$name #$studentId </h2>";
$subscribed = SessionManager::isUserSubscribedAsStudent($destinationSessionId, $studentId);
if ($subscribed) {
$content .= Display::return_message(get_lang('AlreadySubscribed'));
continue;
}
if (isset($_REQUEST['move'])) {
// Registering user to the new session.
SessionManager::subscribeUsersToSession(
$destinationSessionId,
[$studentId],
false,
false
);
}
ob_start();
Tracking::processUserDataMove(
$studentId,
$courseInfo,
$sourceSessionId,
$destinationSessionId,
isset($_REQUEST['move'])
);
$tableResult = ob_get_contents();
ob_get_clean();
$content .= $tableResult;
}
}
}
Display::display_header();
$form->setDefaults($defaults);
$form->display();
echo $content;
Display::display_footer();

View File

@@ -0,0 +1,142 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRecycler;
use Chamilo\CourseBundle\Component\CourseCopy\CourseSelectForm;
/**
* Delete resources from a course.
*
* @author Bart Mollet <bart.mollet@hogent.be>
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true);
$_course = api_get_course_info();
$current_course_code = $_course['official_code'];
// Check access rights (only teachers are allowed here)
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
// Section for the tabs
$this_section = SECTION_COURSES;
// Breadcrumbs
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'course_info/maintenance.php',
'name' => get_lang('Maintenance'),
];
// Displaying the header
$nameTools = get_lang('RecycleCourse');
Display::display_header($nameTools);
// Display the tool title
echo Display::page_header($nameTools);
$action = isset($_POST['action']) ? $_POST['action'] : '';
if (Security::check_token('post') && (
$action === 'course_select_form' ||
(
isset($_POST['recycle_option']) &&
$_POST['recycle_option'] == 'full_backup'
)
)
) {
// Clear token
Security::clear_token();
if (isset($_POST['action']) && $_POST['action'] === 'course_select_form') {
$course = CourseSelectForm::get_posted_course();
} else {
$cb = new CourseBuilder();
$course = $cb->build();
}
$recycle_type = '';
$fullDelete = 0;
$courseCodeConfirmation = '';
if (isset($_POST['course_code_confirmation'])) {
$courseCodeConfirmation = $_POST['course_code_confirmation'];
}
if (isset($_POST['recycle_option']) && $_POST['recycle_option'] === 'full_backup') {
$recycle_type = 'full_backup';
$fullDelete = 1;
} elseif (isset($_POST['action']) && $_POST['action'] === 'course_select_form') {
$recycle_type = 'select_items';
}
$cr = new CourseRecycler($course);
if ($recycle_type === 'full_backup') {
/* to delete, course code confirmation must be equal that current course code */
if ($current_course_code == $courseCodeConfirmation) {
$cr->recycle($recycle_type);
echo Display::return_message(get_lang('RecycleFinished'), 'confirm');
} else {
echo Display::return_message(get_lang('CourseRegistrationCodeIncorrect'), 'error', false);
echo '<p><a class="btn btn-primary" href="'.api_get_self().'?'.api_get_cidreq().'">'.
get_lang('BackToPreviousPage').
'</a></p>';
}
} elseif ($recycle_type === 'select_items') {
$cr->recycle($recycle_type);
echo Display::return_message(get_lang('RecycleFinished'), 'confirm');
}
} elseif (Security::check_token('post') && (
isset($_POST['recycle_option']) &&
$_POST['recycle_option'] === 'select_items'
)
) {
// Clear token
Security::clear_token();
$cb = new CourseBuilder();
$course = $cb->build();
// Add token to Course select form
$hiddenFields['sec_token'] = Security::get_token();
CourseSelectForm::display_form($course, $hiddenFields);
} else {
$cb = new CourseBuilder();
$course = $cb->build();
if (!$course->has_resources()) {
echo get_lang('NoResourcesToRecycle');
} else {
echo Display::return_message(get_lang('RecycleWarning'), 'warning', false);
$form = new FormValidator('recycle_course', 'post', api_get_self().'?'.api_get_cidreq());
$form->addHeader(get_lang('SelectOptionForBackup'));
$form->addElement('radio', 'recycle_option', null, get_lang('FullRecycle'), 'full_backup');
$form->addElement('radio', 'recycle_option', null, get_lang('LetMeSelectItems'), 'select_items');
$form->addHtml('<div class="course-full-delete hidden">');
$form->addText('course_code_confirmation', get_lang('CourseCodeConfirmation'));
$form->addHtml('</div>');
$form->addButtonSave(get_lang('RecycleCourse'));
$form->setDefaults(['recycle_option' => 'select_items']);
// Add Security token
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
$form->display();
/* make recycle_course_course_code_confirmation required to put code course */
echo '
<script>
$(function(){
$(`[type="radio"]`).on(`change`, function (e) {
if ($(this).val() === `full_backup`) {
$(`#recycle_course_course_code_confirmation`).prop(`required`, `required`);
$(`.course-full-delete`).removeClass(`hidden`);
} else {
$(`#recycle_course_course_code_confirmation`).prop(`required`, ``);
$(`.course-full-delete`).addClass(`hidden`);
}
});
})
</script>';
}
}
// Display the footer
Display::display_footer();