Lots of bug fixes/improvements * @author Angel Fernando Quiroz Campos 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'), ]; // 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_course = Database::get_main_table(TABLE_MAIN_COURSE); /** * @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 = ''; 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 .= '
'; // Link back to the documents overview $html .= ''.Display::return_icon( 'back.png', get_lang('BackTo').' '.get_lang('Maintenance'), '', ICON_SIZE_MEDIUM ).''; $html .= '
'; $html .= Display::return_message( get_lang('CopyCourseFromSessionToSessionExplanation') ); $html .= '
'; $html .= ''; // Source $html .= ''; $html .= ''; $html .= ''; // Destination $html .= ''; $html .= ''; $html .= ''; $html .= '
'.get_lang( 'OriginCoursesFromSession' ).':'.api_get_session_name( $sessionId ).''; $html .= "{$courseInfo['title']} ({$courseInfo['code']})".'
'.get_lang( 'DestinationCoursesFromSession' ).':
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= "
"; $html .= ''.get_lang('TypeOfCopy').' ('.get_lang('CopyOnlySessionItems').')'; $html .= ''; $html .= '
'; $html .= "
"; $html .= ''; $html .= '
'; 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 .= ''; 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[] = ''; 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 '
'. Display::return_icon( 'back.png', get_lang('Back').' '.get_lang('To').' '.get_lang( 'PlatformAdmin' ), ['style' => 'vertical-align:middle'] ). get_lang('Back').'
'; } 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();