* @author Julio Montoya Lots of bug fixes/improvements * @author Angel Fernando Quiroz Campos Code conventions * @package chamilo.backup */ require_once '../inc/global.inc.php'; $current_course_tool = TOOL_COURSE_MAINTENANCE; api_protect_course_script(true, true); $xajax = new xajax(); $xajax->registerFunction('searchCourses'); if (!api_is_allowed_to_edit()) { api_not_allowed(true); } if (!api_is_coach()) { api_not_allowed(true); } $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) OR empty($sessionId)) { 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')) { ini_set('memory_limit', '256M'); ini_set('max_execution_time', 1800); } $this_section = SECTION_COURSES; $nameTools = get_lang('CopyCourse'); $returnLink = api_get_path(WEB_CODE_PATH) . 'course_info/maintenance_coach.php?' . api_get_cidreq(); $interbreadcrumb[] = array( '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_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 */ /** * @param string $name */ function make_select_session_list($name, $sessions, $attr = array()) { $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 .= ''; $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 = intval($idSession); $courseList = SessionManager::get_course_list_by_session_id($idSession); $return .= ''; $_SESSION['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(); /* HTML head extra */ $htmlHeadXtra[] = $xajax->getJavascript( api_get_path(WEB_LIBRARY_PATH) . 'xajax/' ); $htmlHeadXtra[] = ''; Display::display_header($nameTools); /* MAIN CODE */ if ((isset($_POST['action']) && $_POST['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 (isset($_POST['action']) && $_POST['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); Display::display_confirmation_message(get_lang('CopyFinished')); displayForm(); } else { $arrCourseOrigin = array(); $arrCourseDestination = array(); $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) { Display::display_error_message( get_lang('YouMustSelectACourseFromOriginalSession') ); } else { $courseDestination = $arrCourseDestination[0]; $cb = new CourseBuilder('', $courseInfo); $course = $cb->build( $originSession, $courseCode ); $cr = new CourseRestorer($course); $cr->restore($courseDestination, $destinationSession); Display::display_confirmation_message(get_lang('CopyFinished')); } displayForm(); } else { Display::display_error_message( get_lang('YouMustSelectACourseFromOriginalSession') ); 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') { Display::display_normal_message( get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary') ); } $arrCourseDestination = array(); $destinationSession = ''; if (isset($_POST['SessionCoursesListDestination'])) { $arrCourseDestination = $_POST['SessionCoursesListDestination']; } if (isset($_POST['sessions_list_destination'])) { $destinationSession = $_POST['sessions_list_destination']; } if (!empty($destinationSession)) { Display::display_normal_message( get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz') ); $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' ), 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') ); displayForm(); } } else { displayForm(); } Display::display_footer();