// We are in teacherview here $_SESSION['studentview'] = 'teacherview'; } } if (isset($_cid)) { $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $time = api_get_utc_datetime(); $sql = "UPDATE {$tbl_course} SET last_visit = '{$time}' WHERE code='{$_cid}'"; Database::query($sql); } // direct login to course if (isset($cas_login) && $cas_login && exist_firstpage_parameter() || $logging_in && exist_firstpage_parameter()) { $redirectCourseDir = api_get_firstpage_parameter(); api_delete_firstpage_parameter(); // delete the cookie if (!isset($_SESSION['request_uri'])) { if (CourseManager::get_course_id_from_path($redirectCourseDir)) { $_SESSION['noredirection'] = false; $_SESSION['request_uri'] = api_get_path(WEB_COURSE_PATH) . $redirectCourseDir . '/'; } } } elseif (api_user_is_login() && exist_firstpage_parameter()) { $redirectCourseDir = api_get_firstpage_parameter(); api_delete_firstpage_parameter(); // delete the cookie if (CourseManager::get_course_id_from_path($redirectCourseDir)) { $_SESSION['noredirection'] = false; $_SESSION['request_uri'] = api_get_path(WEB_COURSE_PATH) . $redirectCourseDir . '/'; } } Redirect::session_request_uri($logging_in, $user_id);
/** * Replace urls inside content html from a copy course * @param string $content_html * @param string $origin_course_code * @param string $destination_course_directory * @param string $origin_course_path_from_zip * @param string $origin_course_info_path * * @return string new content html with replaced urls or return false if content is not a string */ static function replace_urls_inside_content_html_from_copy_course($content_html, $origin_course_code, $destination_course_directory, $origin_course_path_from_zip = null, $origin_course_info_path = null) { if (empty($content_html)) { return false; } $orig_source_html = DocumentManager::get_resources_from_source_html($content_html); $orig_course_info = api_get_course_info($origin_course_code); // Course does not exist in the current DB probably this came from a zip file? if (empty($orig_course_info)) { if (!empty($origin_course_path_from_zip)) { $orig_course_path = $origin_course_path_from_zip . '/'; $orig_course_info_path = $origin_course_info_path; } } else { $orig_course_path = api_get_path(SYS_COURSE_PATH) . $orig_course_info['path'] . '/'; $orig_course_info_path = $orig_course_info['path']; } $destination_course_code = CourseManager::get_course_id_from_path($destination_course_directory); $destination_course_info = api_get_course_info($destination_course_code); $dest_course_path = api_get_path(SYS_COURSE_PATH) . $destination_course_directory . '/'; $dest_course_path_rel = api_get_path(REL_COURSE_PATH) . $destination_course_directory . '/'; $user_id = api_get_user_id(); if (!empty($orig_source_html)) { foreach ($orig_source_html as $source) { // Get information about source url $real_orig_url = $source[0]; // url $scope_url = $source[1]; // scope (local, remote) $type_url = $source[2]; // type (rel, abs, url) // Get path and query from origin url $orig_parse_url = parse_url($real_orig_url); $real_orig_path = isset($orig_parse_url['path']) ? $orig_parse_url['path'] : null; $real_orig_query = isset($orig_parse_url['query']) ? $orig_parse_url['query'] : null; // Replace origin course code by destination course code from origin url query $dest_url_query = ''; if (!empty($real_orig_query)) { $dest_url_query = '?' . $real_orig_query; if (strpos($dest_url_query, $origin_course_code) !== false) { $dest_url_query = str_replace($origin_course_code, $destination_course_code, $dest_url_query); } } if ($scope_url == 'local') { if ($type_url == 'abs' || $type_url == 'rel') { $document_file = strstr($real_orig_path, 'document'); if (strpos($real_orig_path, $document_file) !== false) { $origin_filepath = $orig_course_path . $document_file; $destination_filepath = $dest_course_path . $document_file; // copy origin file inside destination course if (file_exists($origin_filepath)) { $filepath_dir = dirname($destination_filepath); if (!is_dir($filepath_dir)) { $perm = api_get_permissions_for_new_directories(); $result = @mkdir($filepath_dir, $perm, true); if ($result) { $filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $filepath_dir); //Add to item properties to the new folder $doc_id = add_document($destination_course_info, $filepath_to_add, 'folder', 0, basename($filepath_to_add)); api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null); } } if (!file_exists($destination_filepath)) { $result = @copy($origin_filepath, $destination_filepath); if ($result) { $filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $destination_filepath); $size = filesize($destination_filepath); // Add to item properties to the file $doc_id = add_document($destination_course_info, $filepath_to_add, 'file', $size, basename($filepath_to_add)); api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null); } } } // Replace origin course path by destination course path. if (strpos($content_html, $real_orig_url) !== false) { $url_course_path = str_replace($orig_course_info_path . '/' . $document_file, '', $real_orig_path); //$destination_url = $url_course_path . $destination_course_directory . '/' . $document_file . $dest_url_query; // See BT#7780 $destination_url = $dest_course_path_rel . $document_file . $dest_url_query; // If the course code doesn't exist in the path? what we do? Nothing! see BT#1985 if (strpos($real_orig_path, $origin_course_code) === false) { $url_course_path = $real_orig_path; $destination_url = $real_orig_path; } $content_html = str_replace($real_orig_url, $destination_url, $content_html); } } // replace origin course code by destination course code from origin url if (strpos($real_orig_url, '?') === 0) { $dest_url = str_replace($origin_course_code, $destination_course_code, $real_orig_url); $content_html = str_replace($real_orig_url, $dest_url, $content_html); } } } } } return $content_html; }
/** * Gets language of the requested type for the current user. Types are : * user_profil_lang : profile language of current user * user_select_lang : language selected by user at login * course_lang : language of the current course * platform_lang : default platform language * @param string $lang_type * @return string **/ function api_get_language_from_type($lang_type) { $return = false; switch ($lang_type) { case 'platform_lang': $temp_lang = api_get_setting('platformLanguage'); if (!empty($temp_lang)) { $return = $temp_lang; } break; case 'user_profil_lang': $_user = api_get_user_info(); if (isset($_user['language']) && !empty($_user['language'])) { $return = $_user['language']; } break; case 'user_selected_lang': if (isset($_SESSION['user_language_choice']) && !empty($_SESSION['user_language_choice'])) { $return = $_SESSION['user_language_choice']; } break; case 'course_lang': global $_course; $cidReq = null; if (empty($_course)) { // Code modified because the local.inc.php file it's declarated after this work // causing the function api_get_course_info() returns a null value $cidReq = isset($_GET["cidReq"]) ? Database::escape_string($_GET["cidReq"]) : null; $cDir = !empty($_GET['cDir']) ? $_GET['cDir'] : null; if (empty($cidReq) && !empty($cDir)) { $c = CourseManager::get_course_id_from_path($cDir); if ($c) { $cidReq = $c; } } } $_course = api_get_course_info($cidReq); if (isset($_course['language']) && !empty($_course['language'])) { $return = $_course['language']; } break; default: $return = false; break; } return $return; }