* @author Julio Montoya Lots of bug fixes/improvements * @package chamilo.backup */ /* INIT SECTION */ // Language files that need to be included $language_file = array('coursebackup', 'admin'); $cidReset = true; require_once '../inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php'; 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')) { ini_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()) { $attrs = ''; if (count($attr) > 0) { foreach ($attr as $key => $value) { $attrs .= ' '.$key.'="'.$value.'"'; } } $output = ''; return $output; } function display_form() { $html = ''; $sessions = SessionManager::get_sessions_list(); // Actions $html .= '
'; // Link back to the documents overview $html .= ''.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), array('style' => 'vertical-align:middle')).get_lang('BackTo').' '.get_lang('PlatformAdmin').''; $html .= '
'; $html .= '
'.get_lang('CopyCourse').'
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; // Options configuration //$html .= ''; $html .= '
'.get_lang('OriginCoursesFromSession').': '.get_lang('DestinationCoursesFromSession').':
'.make_select_session_list('sessions_list_origin', $sessions, array('onchange' => 'javascript: xajax_search_courses(this.value,\'origin\');')).' 
'; $html .= '
'; $html .= '
'.get_lang('CopyCourse').'
'; $html .= '
'; $introduction = get_lang('CopyCourseFromSessionToSessionExplanation'); $html .= '
'.$introduction.'
'; $html .= '

'.get_lang('TypeOfCopy').'

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

'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; echo $html; } function search_courses($id_session, $type) { global $tbl_course, $tbl_session_rel_course, $course_list; $xajax_response = new XajaxResponse(); $return_origin = ''; $select_destination = ''; if (!empty($type)) { $id_session = intval($id_session); if ($type == 'origin') { // Search courses by id_session for origin list $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 = '".$id_session."'"; $rs = Database::query($sql); $course_list = array(); $return .= ''; $_SESSION['course_list'] = $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)) { $session_table =Database::get_main_table(TABLE_MAIN_SESSION); $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $sql = " SELECT s.id, s.name, sc.name as category_name FROM $session_table s , $session_category_table sc WHERE s.session_category_id = sc.id AND s.id NOT IN('$id_session')"; $rs_select_destination = Database::query($sql); $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.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 .= ''; $_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 = '';*/ // Send response by ajax //$xajax_response -> addAssign('ajax_list_courses_origin', 'innerHTML', api_utf8_encode($return_option_disabled)); } } return $xajax_response; } $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')) { $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); //print_r($course); $cr = new CourseRestorer($course); //$cr->set_file_option($_POST['same_file_name_option']); $cr->restore($destination_course, $destination_session); Display::display_normal_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')); display_form(); } 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); $cr = new CourseRestorer($course); //$cr->set_file_option($_POST['same_file_name_option']); $cr->restore($course_destinatination, $destination_session); //} } Display::display_normal_message(get_lang('CopyFinished')); display_form(); } else { Display::display_error_message(get_lang('YouMustSelectACourseFromOriginalSession')); display_form(); } } } 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')); } $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]); //$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; //echo '
'; print_r($course);		
				
		CourseSelectForm :: display_form($course, $hidden_fields, 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(); } /* FOOTER */ Display::display_footer();