Fixed some more missing strings
[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
94361e02 15 if ($course->category) {
16 require_login($course->id);
17 }
501cdbd8 18
d7d1f618 19 add_to_log($course->id, "forum", "search", "search.php?id=$course->id&search=$search", "$search");
501cdbd8 20
46217d06 21 $strforums = get_string("modulenameplural", "forum");
22 $strsearch = get_string("search", "forum");
23 $strsearchresults = get_string("searchresults", "forum");
24
501cdbd8 25 if ($search) {
46217d06 26 print_header("$course->shortname: $strsearchresults", "$course->fullname",
501cdbd8 27 "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
46217d06 28 <A HREF=\"index.php?id=$course->id\">$strforums</A> ->
29 <A HREF=\"search.php?id=$course->id\">$strsearch</A> -> \"$search\"", "search.search");
501cdbd8 30 } else {
46217d06 31 print_header("$course->shortname: $strsearch", "$course->fullname",
501cdbd8 32 "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
46217d06 33 <A HREF=\"index.php?id=$course->id\">$strforums</A> -> $strsearch", "search.search");
501cdbd8 34 }
35
36 echo "<DIV ALIGN=CENTER>";
7a12aab4 37 forum_print_search_form($course, $search);
501cdbd8 38 echo "</DIV>";
39
40 if ($search) {
41
42 if (!isteacher($course->id)) {
43 $notteacherforum = "AND f.type <> 'teacher'";
44 } else {
45 $notteacherforum = "";
46 }
47
48 $posts = get_records_sql("SELECT p.*,u.firstname,u.lastname,u.email,u.picture,u.id as userid
49 FROM forum_posts p, forum_discussions d, user u, forum f
50 WHERE message LIKE '%$search%' AND p.user = u.id
51 AND p.discussion = d.id AND d.course = '$course->id'
52 AND d.forum = f.id $notteacherforum
53 ORDER BY p.modified DESC LIMIT 0, 50 ");
54
55 if (!$posts) {
405ea757 56 print_heading("<BR>".get_string("nopostscontaining", "forum", $search));
501cdbd8 57
58 } else {
59 foreach ($posts as $post) {
60 if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
61 error("Discussion ID was incorrect");
62 }
63 if (! $forum = get_record("forum", "id", "$discussion->forum")) {
64 error("Could not find forum $discussion->forum");
65 }
501cdbd8 66
8223d271 67 $fullsubject = "<A HREF=\"view.php?f=$forum->id\">$forum->name</A>";
68 if ($forum->type != "single") {
69 $fullsubject .= " -> <A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A>";
70 if ($post->parent != 0) {
71 $fullsubject .= " -> <A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">$post->subject</A>";
72 }
73 }
74
75 $post->subject = $fullsubject;
501cdbd8 76 $post->message = highlight("$search", $post->message);
77
405ea757 78 $fulllink = "<P ALIGN=right><A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">".get_string("postincontext", "forum")."</A></P>";
11b0c469 79 forum_print_post($post, $course->id, false, false, false, false, $fulllink);
501cdbd8 80
81 echo "<BR>";
82 }
83 }
84 }
85
86 print_footer($course);
87
88?>
89