diff --git a/search/documents/chat_document.php b/search/documents/chat_document.php index dd8962242b062..1296b6a3c3530 100644 --- a/search/documents/chat_document.php +++ b/search/documents/chat_document.php @@ -77,7 +77,7 @@ function chat_make_link($cm_id, $start, $end) { /** * fetches all the records for a given session and assemble them as a unique track * we revamped here the code of report.php for making sessions, but without any output. -* note that we should collect sessions "by groups" if groupmode() is SEPARATEGROUPS. +* note that we should collect sessions "by groups" if $groupmode is SEPARATEGROUPS. * @param int $chat_id the database * @param int $fromtime * @param int $totime @@ -91,7 +91,11 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) { $course = $DB->get_record('course', array('id' => $chat->course)); $coursemodule = $DB->get_field('modules', 'id', array('name' => 'data')); $cm = $DB->get_record('course_modules', array('course' => $course->id, 'module' => $coursemodule, 'instance' => $chat->id)); - $groupmode = groupmode($course, $cm); + if (isset($cm->groupmode) && empty($course->groupmodeforce)) { + $groupmode = $cm->groupmode; + } else { + $groupmode = $course->groupmode; + } $fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : ''; $totimeclause = ($totime) ? "AND timestamp <= {$totime}" : ''; @@ -283,7 +287,12 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c //group consistency check : checks the following situations about groups // trap if user is not same group and groups are separated $course = $DB->get_record('course', array('id' => $chat->course)); - if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){ + if (isset($cm->groupmode) && empty($course->groupmodeforce)) { + $groupmode = $cm->groupmode; + } else { + $groupmode = $course->groupmode; + } + if (($groupmode == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){ if (!empty($CFG->search_access_debug)) echo "search reject : chat element is in separated group "; return false; } diff --git a/search/documents/data_document.php b/search/documents/data_document.php index 8fafd52233f94..236a672f9e80e 100644 --- a/search/documents/data_document.php +++ b/search/documents/data_document.php @@ -371,7 +371,12 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c //group consistency check : checks the following situations about groups // trap if user is not same group and groups are separated $course = $DB->get_record('course', 'id', $data->course); - if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){ + if (isset($cm->groupmode) && empty($course->groupmodeforce)) { + $groupmode = $cm->groupmode; + } else { + $groupmode = $course->groupmode; + } + if (($groupmode == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){ if (!empty($CFG->search_access_debug)) echo "search reject : separated group owned resource "; return false; } diff --git a/search/documents/forum_document.php b/search/documents/forum_document.php index 8e5c939c009e2..adfa6a5f027df 100644 --- a/search/documents/forum_document.php +++ b/search/documents/forum_document.php @@ -177,15 +177,25 @@ function forum_db_names() { * @param int $forum_id a forum identifier * @uses $CFG, $USER, $DB * @return an array of posts -* @todo get rid of old isteacher() call */ function forum_get_discussions_fast($forum_id) { global $CFG, $USER, $DB; $timelimit=''; if (!empty($CFG->forum_enabletimedposts)) { - if (!((has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM)) - && !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) { + + $courseid = $DB->get_field('forum', 'course', array('id'=>$forum_id)); + + if ($courseid) { + $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); + $systemcontext = get_context_instance(CONTEXT_SYSTEM); + } else { + $coursecontext = get_context_instance(CONTEXT_SYSTEM); + $systemcontext = $coursecontext; + } + + if (!((has_capability('moodle/site:doanything', $systemcontext) && !empty($CFG->admineditalways)) + || has_any_capability(array('moodle/legacy:teacher', 'moodle/legacy:editingteacher', 'moodle/legacy:admin'), $coursecontext, $userid, false))) { $now = time(); $timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')"; if (!empty($USER->id)) { @@ -283,7 +293,7 @@ function forum_get_child_posts_fast($parent, $forum_id) { * @return true if access is allowed, false elsewhere */ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){ - global $CFG, $USER, $DB; + global $CFG, $USER, $DB, $SESSION; include_once("{$CFG->dirroot}/{$path}/lib.php"); @@ -307,9 +317,25 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $ } // group check : entries should be in accessible groups - $current_group = get_current_group($discussion->course); + if (isset($SESSION->currentgroup[$discussion->course])) { + $current_group = $SESSION->currentgroup[$discussion->course]; + } else { + $current_group = groups_get_all_groups($discussion->course, $USER->id); + if (is_array($current_group)) { + $current_group = array_shift(array_keys($current_group)); + $SESSION->currentgroup[$discussion->course] = $current_group; + } else { + $current_group = 0; + } + } + $course = $DB->get_record('course', array('id' => $discussion->course)); - if ($group_id >= 0 && (groupmode($course, $cm) == SEPARATEGROUPS) && ($group_id != $current_group) && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)){ + if (isset($cm->groupmode) && empty($course->groupmodeforce)) { + $groupmode = $cm->groupmode; + } else { + $groupmode = $course->groupmode; + } + if ($group_id >= 0 && ($groupmode == SEPARATEGROUPS) && ($group_id != $current_group) && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)){ if (!empty($CFG->search_access_debug)) echo "search reject : separated grouped forum item"; return false; } diff --git a/search/documents/lesson_document.php b/search/documents/lesson_document.php index 54759a942802a..f1c105bbcd760 100644 --- a/search/documents/lesson_document.php +++ b/search/documents/lesson_document.php @@ -203,7 +203,8 @@ function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id, } // the user have it seen yet ? did he tried one time at least - $attempt = get_record('lesson_attempts', 'lessonid', $lesson->id, 'pageid', $page->id, 'userid', $USER->id); + $attempt = $DB->get_record('lesson_attempts', array('lessonid'=>$lesson->id,'pageid'=>$page->id, 'userid'=>$USER->id)); + if (!$attempt && !$lessonsuperuser){ if (!empty($CFG->search_access_debug)) echo "search reject : never tried this lesson "; return false; diff --git a/search/documents/wiki_document.php b/search/documents/wiki_document.php index 5e4f36c169609..02c7628a2393b 100644 --- a/search/documents/wiki_document.php +++ b/search/documents/wiki_document.php @@ -257,7 +257,7 @@ function wiki_db_names() { * @return true if access is allowed, false elsewhere */ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){ - global $CFG, $DB; + global $CFG, $DB, $SESSION; // get the wiki object and all related stuff $page = $DB->get_record('wiki_pages', array('id' => $this_id)); @@ -275,8 +275,24 @@ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c //group consistency check : checks the following situations about groups // trap if user is not same group and groups are separated - $current_group = get_current_group($course->id); - if ((groupmode($course) == SEPARATEGROUPS) && $group_id != $current_group && !has_capability('moodle/site:accessallgroups', $context)) { + if (isset($SESSION->currentgroup[$course->id])) { + $current_group = $SESSION->currentgroup[$course->id]; + } else { + $current_group = groups_get_all_groups($course->id, $USER->id); + if (is_array($current_group)) { + $current_group = array_shift(array_keys($current_group)); + $SESSION->currentgroup[$course->id] = $current_group; + } else { + $current_group = 0; + } + } + + if (isset($cm->groupmode) && empty($course->groupmodeforce)) { + $groupmode = $cm->groupmode; + } else { + $groupmode = $course->groupmode; + } + if (($groupmode == SEPARATEGROUPS) && $group_id != $current_group && !has_capability('moodle/site:accessallgroups', $context)) { if (!empty($CFG->search_access_debug)) echo "search reject : separated group owner wiki "; return false; } diff --git a/search/indexersplash.php b/search/indexersplash.php index 94c8c296202d6..c2715d7031c27 100644 --- a/search/indexersplash.php +++ b/search/indexersplash.php @@ -47,6 +47,7 @@ // print page header $site = get_site(); + $PAGE->set_url(new moodle_url($CFG->wwwroot.'/search/indexersplash.php')); $PAGE->navbar->add($strsearch, new moodle_url($CFG->wwwroot.'/search/index.php')); $PAGE->navbar->add($strquery, new moodle_url($CFG->wwwroot.'/search/stats.php')); $PAGE->navbar->add(get_string('runindexer','search')); diff --git a/search/query.php b/search/query.php index 6182fd169776a..1c95442b34739 100644 --- a/search/query.php +++ b/search/query.php @@ -56,6 +56,15 @@ $advanced = (optional_param('a', '0', PARAM_INT) == '1') ? true : false; $query_string = stripslashes(optional_param('query_string', '', PARAM_CLEAN)); + $url = new moodle_url($CFG->wwwroot.'/search/query.php'); + if ($page_number !== -1) { + $url->param('page', $page_number); + } + if ($advanced) { + $url->param('a', '1'); + } + $PAGE->set_url($url); + /// discard harmfull searches if (!isset($CFG->block_search_utf8dir)){ diff --git a/search/querylib.php b/search/querylib.php index c5f4e318f086b..0899b5ed07e98 100644 --- a/search/querylib.php +++ b/search/querylib.php @@ -402,7 +402,7 @@ private function can_display(&$user, $this_id, $doctype, $course_id, $group_id, $unenroled = !in_array($course_id, array_keys($myCourses)); // if guests are allowed, logged guest can see - $isallowedguest = (isguest()) ? $DB->get_field('course', 'guest', array('id' => $course_id)) : false ; + $isallowedguest = (isguestuser()) ? $DB->get_field('course', 'guest', array('id' => $course_id)) : false ; if ($unenroled && !$isallowedguest){ return false; diff --git a/search/stats.php b/search/stats.php index 88bc62c17c6aa..1f84c950ca554 100644 --- a/search/stats.php +++ b/search/stats.php @@ -46,6 +46,7 @@ $site = get_site(); + $PAGE->set_url($CFG->wwwroot.'/search/stats.php'); $PAGE->navbar->add($strsearch, new moodle_url($CFG->wwwroot.'/search/index.php')); $PAGE->navbar->add($strquery, new moodle_url($CFG->wwwroot.'/search/stats.php')); $PAGE->set_title($strsearch); @@ -125,7 +126,6 @@ echo $OUTPUT->table($admin_table); echo $OUTPUT->spacer($spacer) . '
'; - print_spacer(20); } /// this is the standard summary table for normal users, shows document counts