* @author Julio Montoya Lots of bug fixes/improvements * @package chamilo.backup */ $cidReset = true; require_once '../inc/global.inc.php'; $current_course_tool = TOOL_COURSE_MAINTENANCE; api_protect_global_admin_script(); api_protect_limit_for_session_admin(); require_once 'classes/CourseBuilder.class.php'; require_once 'classes/CourseRestorer.class.php'; require_once 'classes/CourseSelectForm.class.php'; $xajax = new xajax(); $xajax->registerFunction('search_courses'); if (!api_is_allowed_to_edit() && !api_is_session_admin()) { 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); } $this_section = SECTION_PLATFORM_ADMIN; $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); /* FUNCTIONS */ function make_select_session_list($name, $sessions, $attr = array()) { $attributes = ''; if (count($attr) > 0) { foreach ($attr as $key => $value) { $attributes .= ' '.$key.'="'.$value.'"'; } } $output = ''; return $output; } function display_form() { $html = ''; $sessions = SessionManager::get_sessions_list(array(), array('name', 'ASC')); // Actions $html .= '
'; // Link back to the documents overview $html .= ''. Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM). ''; $html .= '
'; $html .= Display::return_message(get_lang('CopyCourseFromSessionToSessionExplanation')); $html .= '
'; $html .= ''; // origin $html .= ''; $html .= ''; $html .= ''; //destination $html .= ''; $html .= ''; $html .= ''; $html .= '
'.get_lang('OriginCoursesFromSession').':'.make_select_session_list('sessions_list_origin', $sessions, array('onchange' => 'javascript: xajax_search_courses(this.value,\'origin\');')).'
'; $html .= '
'.get_lang('DestinationCoursesFromSession').':
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '

'.get_lang('TypeOfCopy').'

'; $html .= '
'; $html .= '
'; $html .= '

'; $html .= ''; // Add Security token $html .= ''; $html .= '
'; echo $html; } function search_courses($id_session, $type) { global $tbl_course, $tbl_session_rel_course, $course_list; $xajax_response = new xajaxResponse(); $select_destination = ''; $return = null; 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 .= ''; $_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(array(), array('name', 'ASC')); $select_destination .= ''; $xajax_response -> addAssign('ajax_sessions_list_destination', 'innerHTML', api_utf8_encode($select_destination)); } else { $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.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 = array(); $return .= ''; $_SESSION['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[] = ''; 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') && ( ( isset($_POST['action']) && $_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 (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 ); $cr = new CourseRestorer($course); //$cr->set_file_option($_POST['same_file_name_option']); $cr->restore($destination_course, $destination_session); Display::display_confirmation_message(get_lang('CopyFinished')); display_form(); } else { $arr_course_origin = array(); $arr_course_destination = array(); $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) { 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')); } $arr_course_origin = array(); $arr_course_destination = array(); $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)) { Display::display_normal_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz')); $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['same_file_name_option'] = $_POST['same_file_name_option']; $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 '
'. Display::return_icon( 'back.png', get_lang('Back').' '.get_lang('To').' '.get_lang('PlatformAdmin'), array('style' => 'vertical-align:middle') ). get_lang('Back').'
'; } else { Display::display_error_message( get_lang('You must select a course from original session and select a destination session') ); display_form(); } } else { display_form(); } Display::display_footer();