diff --git a/main/coursecopy/copy_course_session.php b/main/coursecopy/copy_course_session.php
index 0ab062dc30..2c9f07a6f0 100755
--- a/main/coursecopy/copy_course_session.php
+++ b/main/coursecopy/copy_course_session.php
@@ -31,13 +31,13 @@ $xajax = new xajax();
$xajax->registerFunction('search_courses');
if (!api_is_allowed_to_edit() && !api_is_session_admin()) {
- api_not_allowed(true);
+ api_not_allowed(true);
}
// Remove memory and time limits as much as possible as this might be a long process...
if (function_exists('ini_set')) {
- api_set_memory_limit('256M');
- ini_set('max_execution_time', 1800);
+ api_set_memory_limit('256M');
+ ini_set('max_execution_time', 1800);
}
$this_section = SECTION_PLATFORM_ADMIN;
@@ -46,247 +46,223 @@ $nameTools = get_lang('CopyCourse');
$interbreadcrumb[] = array('url' => '../admin/index.php', 'name' => get_lang('PlatformAdmin'));
// Database Table Definitions
-$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
-$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
-$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
-$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
+$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
+$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
+$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
/* FUNCTIONS */
-function make_select_session_list($name, $sessions, $attr = array()) {
-
- $attrs = '';
- if (count($attr) > 0) {
- foreach ($attr as $key => $value) {
- $attrs .= ' '.$key.'="'.$value.'"';
- }
- }
- $output = '';
-
- if (count($sessions) == 0) {
- $output .= ''.get_lang('ThereIsNotStillASession').' ';
- } else {
- $output .= ''.get_lang('SelectASession').' ';
- }
-
- if (is_array($sessions)) {
- foreach ($sessions as $session) {
- $category_name = '';
+function make_select_session_list($name, $sessions, $attr = array())
+{
+ $attrs = '';
+ if (count($attr) > 0) {
+ foreach ($attr as $key => $value) {
+ $attrs .= ' '.$key.'="'.$value.'"';
+ }
+ }
+ $output = '';
+
+ if (count($sessions) == 0) {
+ $output .= ''.get_lang('ThereIsNotStillASession').' ';
+ } else {
+ $output .= ''.get_lang('SelectASession').' ';
+ }
+
+ if (is_array($sessions)) {
+ foreach ($sessions as $session) {
+ $categoryName = '';
if (!empty($session['category_name'])) {
- $category_name = ' ('.$session['category_name'].')';
+ $categoryName = ' ('.$session['category_name'].')';
}
-
- $output .= ''.$session['name'].' '.$category_name.' ';
- }
- }
- $output .= ' ';
- return $output;
+
+ $output .= ''.
+ $session['name'].' '.$categoryName.
+ ' ';
+ }
+ }
+ $output .= ' ';
+
+ return $output;
}
-function display_form() {
- $html = '';
- $sessions = SessionManager::get_sessions_list(null, array('name ASC'));
-
- // Actions
- $html .= '
';
+function display_form()
+{
+ $html = '';
+ $sessions = SessionManager::get_sessions_list(null, array('name ASC'));
+
+ // Actions
+ $html .= '';
$html .= Display::return_message(get_lang('CopyCourseFromSessionToSessionExplanation'));
-
- $html .= '';
- echo $html;
-}
-function search_courses($id_session, $type) {
- global $tbl_course, $tbl_session_rel_course, $course_list;
- $xajax_response = new XajaxResponse();
- $select_destination = '';
- if (!empty($type)) {
+ echo $html;
+}
- $id_session = intval($id_session);
+function search_courses($id_session, $type)
+{
+ global $tbl_course, $tbl_session_rel_course, $course_list;
+ $xajax_response = new XajaxResponse();
+ $select_destination = '';
+ $return = null;
- if ($type == 'origin') {
-
+ if (!empty($type)) {
+ $id_session = intval($id_session);
+ if ($type == 'origin') {
$course_list = SessionManager::get_course_list_by_session_id($id_session);
-
- $temp_course_list = array();
- $return .= '';
-
- foreach ($course_list as $course) {
- $temp_course_list[] = "'{$course['code']}'";
- $course_title=str_replace("'","\'",$course_title);
- $return .= ''.$course['title'].' ('.$course['visual_code'].') ';
- }
+ $temp_course_list = array();
+ $return .= '';
- $return .= ' ';
- $_SESSION['course_list'] = $temp_course_list;
- $_SESSION['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(null, array('name ASC'));
-
- $select_destination .= '';
- $select_destination .= '-- '.get_lang('SelectASession').' -- ';
- foreach ($sessions as $session) {
- if ($id_session == $session['id']) { continue; };
- if (!empty($session['category_name'])) {
- $session['category_name'] = ' ('.$session['category_name'].') ';
- }
- $select_destination .= ''.$session['name'].' '.$session['category_name'].' ';
- }
- $select_destination .= ' ';
- $xajax_response -> addAssign('ajax_sessions_list_destination', 'innerHTML', api_utf8_encode($select_destination));
- } else {
- $select_destination .= '';
- $select_destination .= ''.get_lang('ThereIsNotStillASession').' ';
- $select_destination .= ' ';
- $xajax_response -> addAssign('ajax_sessions_list_destination', 'innerHTML', api_utf8_encode($select_destination));
- }
+ foreach ($course_list as $course) {
+ $temp_course_list[] = "'{$course['code']}'";
+ $return .= ''.$course['title'].' ('.$course['visual_code'].') ';
+ }
- // Select multiple destination empty
- $select_multiple_empty = ' ';
+ $return .= ' ';
+ $_SESSION['course_list'] = $temp_course_list;
+ $_SESSION['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(null, array('name ASC'));
+
+ $select_destination .= '';
+ $select_destination .= '-- '.get_lang('SelectASession').' -- ';
+ foreach ($sessions as $session) {
+ if ($id_session == $session['id']) { continue; };
+ if (!empty($session['category_name'])) {
+ $session['category_name'] = ' ('.$session['category_name'].') ';
+ }
+ $select_destination .= ''.$session['name'].' '.$session['category_name'].' ';
+ }
+ $select_destination .= ' ';
+ $xajax_response -> addAssign('ajax_sessions_list_destination', 'innerHTML', api_utf8_encode($select_destination));
+ } else {
+ $select_destination .= '';
+ $select_destination .= ''.get_lang('ThereIsNotStillASession').' ';
+ $select_destination .= ' ';
+ $xajax_response -> addAssign('ajax_sessions_list_destination', 'innerHTML', api_utf8_encode($select_destination));
+ }
+
+ // Select multiple destination empty
+ $select_multiple_empty = ' ';
+
+ // 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 {
+ //Left Select - Destination
+ $list_courses_origin = implode(',', $_SESSION['course_list']);
+ $session_origin = $_SESSION['session_origin'];
+
+ // Search courses by id_session where course codes is include en courses list destination
+ $sql = "SELECT c.code, c.visual_code, c.title, src.id_session
+ FROM $tbl_course c, $tbl_session_rel_course src
+ WHERE src.course_code = c.code
+ AND src.id_session = '".intval($id_session)."'";
+ //AND c.code IN ($list_courses_origin)";
+ $rs = Database::query($sql);
+
+ $course_list_destination = array();
+ $return .= '';
+ while ($course = Database :: fetch_array($rs)) {
+ $course_list_destination[] = $course['code'];
+ $return .= ''.$course['title'].' ('.$course['visual_code'].') ';
+ }
+ $return .= ' ';
+ $_SESSION['course_list_destination'] = $course_list_destination;
+
+ // Send response by ajax
+ $xajax_response->addAssign(
+ 'ajax_list_courses_destination',
+ 'innerHTML',
+ api_utf8_encode($return)
+ );
+ }
+ }
- // 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 {
- //Left Select - Destination
-
- $list_courses_origin = implode(',', $_SESSION['course_list']);
- $session_origin = $_SESSION['session_origin'];
-
- // Search courses by id_session where course codes is include en courses list destination
- $sql = "SELECT c.code, c.visual_code, c.title, src.id_session
- FROM $tbl_course c, $tbl_session_rel_course src
- WHERE src.course_code = c.code
- AND src.id_session = '".intval($id_session)."'";
- //AND c.code IN ($list_courses_origin)";
- $rs = Database::query($sql);
-
- $course_list_destination = array();
- //onmouseover="javascript: this.disabled=true;" onmouseout="javascript: this.disabled=false;"
- $return .= '';
- while ($course = Database :: fetch_array($rs)) {
- $course_list_destination[] = $course['code'];
- $course_title = str_replace("'", "\'", $course_title);
- $return .= ''.$course['title'].' ('.$course['visual_code'].') ';
- }
- $return .= ' ';
- $_SESSION['course_list_destination'] = $course_list_destination;
-
- // Send response by ajax
- $xajax_response -> addAssign('ajax_list_courses_destination', 'innerHTML', api_utf8_encode($return));
-/*
- // Disable option from session courses list origin where if no the same con the destination
- $sql = "SELECT c.code, c.visual_code, c.title, src.id_session
- FROM $tbl_course c, $tbl_session_rel_course src
- WHERE src.course_code = c.code
- AND src.id_session = '".intval($session_origin)."'";
- $result = Database::query($sql);
-
- $return_option_disabled = '';
- while ($cours = Database :: fetch_array($result)) {
- $course_title=str_replace("'", "\'", $course_title);
- if (count($course_list_destination) > 0) {
- if (!in_array($cours['code'], $course_list_destination)) {
- $return_option_disabled .= ''.$cours['title'].' ('.$cours['visual_code'].') ';
- } else {
- $return_option_disabled .= ''.$cours['title'].' ('.$cours['visual_code'].') ';
- }
- } else {
- if (empty($id_session)) {
- $return_option_disabled .= ''.$cours['title'].' ('.$cours['visual_code'].') ';
- } else {
- $return_option_disabled .= ''.$cours['title'].' ('.$cours['visual_code'].') ';
- }
- }
- }
- $return_option_disabled .= ' ';*/
- // Send response by ajax
- //$xajax_response -> addAssign('ajax_list_courses_origin', 'innerHTML', api_utf8_encode($return_option_disabled));
- }
- }
return $xajax_response;
}
-$xajax -> processRequests();
+$xajax->processRequests();
/* HTML head extra */
$htmlHeadXtra[] = $xajax->getJavascript( api_get_path(WEB_LIBRARY_PATH).'xajax/');
$htmlHeadXtra[] = '';
-
Display::display_header($nameTools);
$with_base_content = true;
@@ -294,22 +270,26 @@ if (isset($_POST['copy_only_session_items']) && $_POST['copy_only_session_items'
$with_base_content = false;
}
-
/* MAIN CODE */
-
-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') ||
+ (isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')
+) {
$destination_course = $origin_course = $destination_session = $origin_session = '';
if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
-
+
$destination_course = $_POST['destination_course'];
$origin_course = $_POST['origin_course'];
$destination_session = $_POST['destination_session'];
$origin_session = $_POST['origin_session'];
-
- $course = CourseSelectForm :: get_posted_course('copy_course', $origin_session, $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);
@@ -334,23 +314,23 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
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
+ //We need only one value
if (count($arr_course_origin) > 1 || count($arr_course_destination) > 1) {
- Display::display_error_message(get_lang('YouMustSelectACourseFromOriginalSession'));
+ 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);
+
+ $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 = new CourseRestorer($course);
$cr->restore($course_destinatination, $destination_session);
-
+
}
Display::display_confirmation_message(get_lang('CopyFinished'));
display_form();
@@ -386,19 +366,27 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
if ((is_array($arr_course_origin) && count($arr_course_origin) > 0) && !empty($destination_session)) {
Display::display_normal_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
- $course_origin = api_get_course_info($arr_course_origin[0]);
+ $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);
//$hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
$hidden_fields['destination_course'] = $arr_course_destination[0];
$hidden_fields['origin_course'] = $arr_course_origin[0];
$hidden_fields['destination_session'] = $destination_session;
- $hidden_fields['origin_session'] = $origin_session;
-
+ $hidden_fields['origin_session'] = $origin_session;
+
CourseSelectForm :: display_form($course, $hidden_fields, true);
- echo '';
+ echo '';
} else {
- Display::display_error_message(get_lang('You must select a course from original session and select a destination session'));
+ Display::display_error_message(
+ get_lang('You must select a course from original session and select a destination session')
+ );
display_form();
}
} else {