OK, some massive changes with many files removed or changed.
[moodle.git] / mod / forum / search.php
CommitLineData
501cdbd8 1<?PHP // $Id$
2
3 require("../../config.php");
4 require("lib.php");
5
6 require_variable($id); // course id
7 optional_variable($search, ""); // user id
8
9 $search = strip_tags($search);
10
11 if (! $course = get_record("course", "id", $id)) {
12 error("Course id is incorrect.");
13 }
14
15 require_login($course->id);
16
17 add_to_log($course->id, "course", "search", "search.php?id=$course->id&search=$search", "$search");
18
19 if ($search) {
20 print_header("$course->shortname: Search Results", "$course->fullname",
21 "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
22 <A HREF=\"index.php?id=$course->id\">Forums</A> ->
23 <A HREF=\"search.php?id=$course->id\">Search</A> -> \"$search\"", "search.search");
24 } else {
25 print_header("$course->shortname: Search", "$course->fullname",
26 "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
27 <A HREF=\"index.php?id=$course->id\">Forums</A> -> Search", "search.search");
28 }
29
30 echo "<DIV ALIGN=CENTER>";
31 print_forum_search_form($course, $search);
32 echo "</DIV>";
33
34 if ($search) {
35
36 if (!isteacher($course->id)) {
37 $notteacherforum = "AND f.type <> 'teacher'";
38 } else {
39 $notteacherforum = "";
40 }
41
42 $posts = get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture,u.id as userid
43 FROM forum_posts p, forum_discussions d, user u, forum f
44 WHERE message LIKE '%$search%' AND p.user = u.id
45 AND p.discussion = d.id AND d.course = '$course->id'
46 AND d.forum = f.id $notteacherforum
47 ORDER BY p.modified DESC LIMIT 0, 50 ");
48
49 if (!$posts) {
50 print_heading("<BR>No posts found containing \"$search\"");
51
52 } else {
53 foreach ($posts as $post) {
54 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
55 error("Discussion ID was incorrect");
56 }
57 if (! $forum = get_record("forum", "id", "$discussion->forum")) {
58 error("Could not find forum $discussion->forum");
59 }
60 $post->subject = "<A HREF=\"index.php?id=$course->id&forum=$forum->id\">$forum->name</A> -> ".
61 "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> ".
62 "<A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">$post->subject</A>";
63
64 $post->message = highlight("$search", $post->message);
65
66 $fulllink = "<P ALIGN=right><A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">See this post in context</A></P>";
67 print_post($post, $course->id, false, false, false, false, $fulllink);
68
69 echo "<BR>";
70 }
71 }
72 }
73
74 print_footer($course);
75
76?>
77