$searchterm) {
if (strlen($searchterm) < 2) {
unset($searchterms[$key]);
}
}
$search = s(trim(implode(" ", $searchterms)));
}
if (! $course = get_record("course", "id", $id)) {
error("Course id is incorrect.");
}
if ($course->category) {
require_login($course->id);
}
add_to_log($course->id, "forum", "search", "search.php?id=$course->id&search=".urlencode($search), $search);
$strforums = get_string("modulenameplural", "forum");
$strsearch = get_string("search", "forum");
$strsearchresults = get_string("searchresults", "forum");
$strpage = get_string("page");
$searchform = forum_print_search_form($course, $search, true, "plain");
if (!$search) {
print_header("$course->shortname: $strsearch", "$course->fullname",
"id\">$course->shortname ->
id\">$strforums -> $strsearch", "search.search",
"", "", " ", navmenu($course));
print_simple_box_start("center");
echo "
";
echo "
";
echo $searchform;
echo "
";
print_string("searchhelp");
echo "
";
echo "";
print_simple_box_end();
}
if ($search) {
if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount)) {
print_header("$course->shortname: $strsearchresults", "$course->fullname",
"id\">$course->shortname ->
id\">$strforums ->
id\">$strsearch -> \"$search\"", "search.search",
"", "", " ", navmenu($course));
print_heading(get_string("nopostscontaining", "forum", $search));
print_simple_box_start("center");
echo "";
echo "
";
echo $searchform;
echo "
";
print_string("searchhelp");
echo "
";
echo "";
print_simple_box_end();
print_footer($course);
exit;
}
print_header("$course->shortname: $strsearchresults", "$course->fullname",
"id\">$course->shortname ->
id\">$strforums ->
id\">$strsearch -> \"$search\"", "search.search",
"", "", $searchform, navmenu($course));
print_heading("$strsearchresults: $totalcount");
echo "";
print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&id=$course->id&perpage=$perpage&");
echo "";
foreach ($posts as $post) {
if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
error("Discussion ID was incorrect");
}
if (! $forum = get_record("forum", "id", "$discussion->forum")) {
error("Could not find forum $discussion->forum");
}
$post->subject = highlight("$search", $post->subject);
$discussion->name = highlight("$search", $discussion->name);
$fullsubject = "id\">$forum->name";
if ($forum->type != "single") {
$fullsubject .= " -> id\">$discussion->name";
if ($post->parent != 0) {
$fullsubject .= " -> discussion&parent=$post->id\">$post->subject";
}
}
$post->subject = $fullsubject;
$fulllink = "discussion#$post->id\">".get_string("postincontext", "forum")."
";
forum_print_post($post, $course->id, false, false, false, false, $fulllink, $search);
echo "
";
}
echo "";
print_paging_bar($totalcount, $page, $perpage, "search.php?search=".urlencode($search)."&id=$course->id&perpage=$perpage&");
echo "";
}
print_footer($course);
?>