$string['nodiscussions'] = "There are no discussion topics yet in this forum";
$string['noguestpost'] = "Sorry, guests are not allowed to post";
$string['nonews'] = "No news has been posted yet";
+$string['nomorepostscontaining'] = "No more posts containing '\$a' were found";
$string['noposts'] = "No posts";
$string['nopostscontaining'] = "No posts containing '\$a' were found";
$string['nosubscribers'] = "There are no subscribers yet for this forum";
$string['repliesone'] = "\$a reply so far";
$string['reply'] = "Reply";
$string['search'] = "Search";
+$string['searcholderposts'] = "Search older posts...";
$string['searchresults'] = "Search results";
$string['searchforums'] = "Search forums";
$string['sendinratings'] = "Send in my latest ratings";
//to allow caseinsensitive search for postgesql
if($CFG->dbtype == "postgres7") {
$LIKE = "ILIKE";
- }else {
+ } else {
$LIKE = "LIKE";
}
+ $messagesearch = "";
+ $subjectsearch = "";
+
+ $searchterms = explode(" ", $search); // Search for words independently
+
+ foreach ($searchterms as $searchterm) {
+ if ($messagesearch) {
+ $messagesearch .= " AND ";
+ }
+ $messagesearch .= " p.message $LIKE '%$searchterm%' ";
+
+ if ($subjectsearch) {
+ $subjectsearch .= " AND ";
+ }
+ $subjectsearch .= " p.subject $LIKE '%$searchterm%' ";
+ }
+
+
return get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture
FROM {$CFG->prefix}forum_posts p,
{$CFG->prefix}forum_discussions d,
{$CFG->prefix}user u,
{$CFG->prefix}forum f
- WHERE (p.message $LIKE '%$search%' OR p.subject $LIKE '%$search%')
+ WHERE ($messagesearch OR $subjectsearch)
AND p.userid = u.id
AND p.discussion = d.id
AND d.course = '$courseid'
require_variable($id); // course id
optional_variable($search, ""); // search string
+ optional_variable($page, "0"); // which page to show
+ optional_variable($perpage, "20"); // which page to show
- $search = strip_tags($search);
+ $search = trim(strip_tags($search));
if (! $course = get_record("course", "id", $id)) {
error("Course id is incorrect.");
}
if ($search) {
-
- if (!$posts = forum_search_posts($search, $course->id)) {
- print_heading(get_string("nopostscontaining", "forum", $search));
+
+ if (!$posts = forum_search_posts($search, $course->id, $page*$perpage, $perpage)) {
+ if ($page) {
+ print_heading(get_string("nomorepostscontaining", "forum", $search));
+ print_continue("search.php?id=$course->id&search=".urlencode($search));
+ } else {
+ print_heading(get_string("nopostscontaining", "forum", $search));
+ }
} else {
+
foreach ($posts as $post) {
+
if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
error("Discussion ID was incorrect");
}
error("Could not find forum $discussion->forum");
}
- $post->subject = highlightfast("$search", $post->subject);
- $discussion->name = highlightfast("$search", $discussion->name);
+ $post->subject = highlight("$search", $post->subject);
+ $discussion->name = highlight("$search", $discussion->name);
$fullsubject = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
if ($forum->type != "single") {
$fulllink = "<p align=\"right\"><a href=\"discuss.php?d=$post->discussion&parent=$post->id\">".get_string("postincontext", "forum")."</a></p>";
forum_print_post($post, $course->id, false, false, false, false, $fulllink, $search);
- echo "<BR>";
+ echo "<br />";
}
}
+
+ if (count($posts) == $perpage) {
+ $options = array();
+ $options["id"] = $course->id;
+ $options["search"] = urlencode($search);
+ $options["page"] = $page+1;
+ $options["perpage"] = $perpage;
+ echo "<center>";
+ print_single_button("search.php", $options, get_string("searcholderposts", "forum"));
+ echo "</center>";
+ }
}
print_footer($course);