~ubuntu-branches/ubuntu/breezy/moodle/breezy

« back to all changes in this revision

Viewing changes to mod/forum/search.php

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-10-13 02:00:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051013020059-y2qcyo41t7nqppcg
Tags: 1.5.2-1ubuntu1
* Resync with debian (security update)
* changed dependencys to php5
* changed apache dependency to apache2 
* References
  CAN-2005-2247

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?PHP // $Id: search.php,v 1.29 2004/08/22 14:38:41 gustav_delius Exp $
2
 
 
3
 
    require_once("../../config.php");
4
 
    require_once("lib.php");
5
 
 
6
 
    require_variable($id);           // course id
7
 
    optional_variable($search, "");  // search string
8
 
    optional_variable($page, "0");   // which page to show
9
 
    optional_variable($perpage, "20");   // which page to show
10
 
 
11
 
    $search = trim(strip_tags($search));
 
1
<?php // $Id: search.php,v 1.55.2.1 2005/05/29 04:04:31 moodler Exp $
 
2
 
 
3
    require_once('../../config.php');
 
4
    require_once('lib.php');
 
5
 
 
6
    $id = required_param('id', PARAM_INT);                  // course id
 
7
    $search = trim(optional_param('search', '', PARAM_NOTAGS));  // search string
 
8
    $page = optional_param('page', 0, PARAM_INT);   // which page to show
 
9
    $perpage = optional_param('perpage', 10, PARAM_INT);   // how many per page
 
10
    $showform = optional_param('showform', 0, PARAM_INT);   // Just show the form
 
11
 
 
12
    $user    = trim(optional_param('user', '', PARAM_NOTAGS));    // Names to search for
 
13
    $userid  = trim(optional_param('userid', 0, PARAM_INT));      // UserID to search for
 
14
    $forumid = trim(optional_param('forumid', 0, PARAM_INT));      // ForumID to search for
 
15
    $subject = trim(optional_param('subject', '', PARAM_NOTAGS)); // Subject
 
16
    $phrase  = trim(optional_param('phrase', '', PARAM_NOTAGS));  // Phrase
 
17
    $words   = trim(optional_param('words', '', PARAM_NOTAGS));   // Words
 
18
    $fullwords = trim(optional_param('fullwords', '', PARAM_NOTAGS)); // Whole words
 
19
    $notwords = trim(optional_param('notwords', '', PARAM_NOTAGS));   // Words we don't want
 
20
 
 
21
    $timefromrestrict = optional_param('timefromrestrict', 0, PARAM_INT); // Use starting date
 
22
    $fromday = optional_param('fromday', 0, PARAM_INT);      // Starting date
 
23
    $frommonth = optional_param('frommonth', 0, PARAM_INT);      // Starting date
 
24
    $fromyear = optional_param('fromyear', 0, PARAM_INT);      // Starting date
 
25
    $fromhour = optional_param('fromhour', 0, PARAM_INT);      // Starting date
 
26
    $fromminute = optional_param('fromminute', 0, PARAM_INT);      // Starting date
 
27
    if ($timefromrestrict) {
 
28
        $datefrom = make_timestamp($fromyear, $frommonth, $fromday, $fromhour, $fromminute);
 
29
    } else {
 
30
        $datefrom = optional_param('datefrom', 0, PARAM_INT);      // Starting date
 
31
    }
 
32
 
 
33
    $timetorestrict = optional_param('timetorestrict', 0, PARAM_INT); // Use ending date
 
34
    $today = optional_param('today', 0, PARAM_INT);      // Ending date
 
35
    $tomonth = optional_param('tomonth', 0, PARAM_INT);      // Ending date
 
36
    $toyear = optional_param('toyear', 0, PARAM_INT);      // Ending date
 
37
    $tohour = optional_param('tohour', 0, PARAM_INT);      // Ending date
 
38
    $tominute = optional_param('tominute', 0, PARAM_INT);      // Ending date
 
39
    if ($timetorestrict) {
 
40
        $dateto = make_timestamp($toyear, $tomonth, $today, $tohour, $tominute);
 
41
    } else {
 
42
        $dateto = optional_param('datefrom', 0, PARAM_INT);      // Ending date
 
43
    }
 
44
 
 
45
 
 
46
 
 
47
    if (empty($search)) {   // Check the other parameters instead
 
48
        if (!empty($words)) {
 
49
            $search .= ' '.$words;
 
50
        }
 
51
        if (!empty($userid)) {
 
52
            $search .= ' userid:'.$userid;
 
53
        }
 
54
        if (!empty($forumid)) {
 
55
            $search .= ' forumid:'.$forumid;
 
56
        }
 
57
        if (!empty($user)) {
 
58
            $search .= ' '.forum_clean_search_terms($user, 'user:');
 
59
        }
 
60
        if (!empty($subject)) {
 
61
            $search .= ' '.forum_clean_search_terms($subject, 'subject:');
 
62
        }
 
63
        if (!empty($fullwords)) {
 
64
            $search .= ' '.forum_clean_search_terms($fullwords, '+');
 
65
        }
 
66
        if (!empty($notwords)) {
 
67
            $search .= ' '.forum_clean_search_terms($notwords, '-');
 
68
        }
 
69
        if (!empty($phrase)) {
 
70
            $search .= ' "'.$phrase.'"';
 
71
        }
 
72
        if (!empty($datefrom)) {
 
73
            $search .= ' datefrom:'.$datefrom;
 
74
        }
 
75
        if (!empty($dateto)) {
 
76
            $search .= ' dateto:'.$dateto;
 
77
        }
 
78
        $individualparams = true;
 
79
    } else {
 
80
        $individualparams = false;
 
81
    }
12
82
 
13
83
    if ($search) {
14
 
        $searchterms = explode(" ", $search);    // Search for words independently
15
 
        foreach ($searchterms as $key => $searchterm) {
16
 
            if (strlen($searchterm) < 2) {
17
 
                unset($searchterms[$key]);
18
 
            }
19
 
        }
20
 
        $search = s(trim(implode(" ", $searchterms)));
 
84
        $search = forum_clean_search_terms($search);
21
85
    }
22
86
 
23
87
    if (! $course = get_record("course", "id", $id)) {
24
88
        error("Course id is incorrect.");
25
89
    }
26
90
 
27
 
    if ($course->category or $CFG->forcelogin) {
28
 
        require_login($course->id);
29
 
    }
 
91
    require_course_login($course);
30
92
 
31
 
    add_to_log($course->id, "forum", "search", "search.php?id=$course->id&search=".urlencode($search), $search); 
 
93
    add_to_log($course->id, "forum", "search", "search.php?id=$course->id&amp;search=".urlencode($search), $search);
32
94
 
33
95
    $strforums = get_string("modulenameplural", "forum");
34
96
    $strsearch = get_string("search", "forum");
35
97
    $strsearchresults = get_string("searchresults", "forum");
36
98
    $strpage = get_string("page");
37
99
 
38
 
    $searchform = forum_print_search_form($course, $search, true, "plain");
39
 
 
40
 
    if (!$search) {
 
100
    if (!$search || $showform) {
41
101
        print_header_simple("$strsearch", "",
42
 
                 "<A HREF=\"index.php?id=$course->id\">$strforums</A> -> $strsearch", "search.search",
 
102
                 "<a href=\"index.php?id=$course->id\">$strforums</a> -> $strsearch", 'search.words',
43
103
                  "", "", "&nbsp;", navmenu($course));
44
104
 
45
 
        print_simple_box_start("center");
46
 
        echo "<center>";
 
105
        forum_print_big_search_form($course);
 
106
        print_footer($course);
 
107
        exit;
 
108
    }
 
109
 
 
110
/// We need to do a search now and print results
 
111
 
 
112
    $searchterms = str_replace('forumid:', 'instance:', $search);
 
113
    $searchterms = explode(' ', $searchterms);
 
114
 
 
115
    $searchform = forum_search_form($course, $search);
 
116
 
 
117
    if ($group = user_group($course->id, $USER->id)) {
 
118
        $groupid = $group->id;
 
119
    } else {
 
120
        $groupid = 0;
 
121
    }
 
122
 
 
123
    if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount, $groupid)) {
 
124
 
 
125
        print_header_simple("$strsearchresults", "",
 
126
                "<a href=\"index.php?id=$course->id\">$strforums</a> ->
 
127
                <a href=\"search.php?id=$course->id\">$strsearch</a> -> ".s($search), 'search.words',
 
128
                "", "", "&nbsp;", navmenu($course));
 
129
        print_heading(get_string("nopostscontaining", "forum", $search));
 
130
 
 
131
        if (!$individualparams) {
 
132
            $words = $search;
 
133
        }
 
134
 
 
135
        forum_print_big_search_form($course);
 
136
 
 
137
        print_footer($course);
 
138
        exit;
 
139
    }
 
140
 
 
141
    print_header_simple("$strsearchresults", "",
 
142
            "<a href=\"index.php?id=$course->id\">$strforums</a> ->
 
143
            <a href=\"search.php?id=$course->id\">$strsearch</a> -> ".s($search), '',
 
144
            "", "",  $searchform, navmenu($course));
 
145
 
 
146
    echo '<div class="reportlink">';
 
147
    echo '<a href="search.php?id='.$course->id.
 
148
                             '&amp;user='.urlencode($user).
 
149
                             '&amp;userid='.$userid.
 
150
                             '&amp;forumid='.$forumid.
 
151
                             '&amp;subject='.urlencode($subject).
 
152
                             '&amp;phrase='.urlencode($phrase).
 
153
                             '&amp;words='.urlencode($words).
 
154
                             '&amp;fullwords='.urlencode($fullwords).
 
155
                             '&amp;notwords='.urlencode($notwords).
 
156
                             '&amp;dateto='.$dateto.
 
157
                             '&amp;datefrom='.$datefrom.
 
158
                             '&amp;showform=1'.
 
159
                             '">'.get_string('advancedsearch','forum').'...</a>';
 
160
    echo '</div>';
 
161
 
 
162
    print_heading("$strsearchresults: $totalcount");
 
163
 
 
164
    print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&amp;id=$course->id&amp;perpage=$perpage&amp;");
 
165
 
 
166
    //added to implement highlighting of search terms found only in HTML markup
 
167
    //fiedorow - 9/2/2005
 
168
    $strippedsearch = str_replace('user:','',$search);
 
169
    $strippedsearch = str_replace('subject:','',$strippedsearch);
 
170
    $strippedsearch = str_replace('&quot;','',$strippedsearch);
 
171
    $searchterms = explode(' ', $strippedsearch);    // Search for words independently
 
172
    foreach ($searchterms as $key => $searchterm) {
 
173
        if (preg_match('/^\-/',$searchterm)) {
 
174
            unset($searchterms[$key]);
 
175
        } else {
 
176
            $searchterms[$key] = preg_replace('/^\+/','',$searchterm);
 
177
        }
 
178
    }
 
179
    $strippedsearch = implode(' ', $searchterms);    // Rebuild the string
 
180
 
 
181
    foreach ($posts as $post) {
 
182
 
 
183
        if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
 
184
            error('Discussion ID was incorrect');
 
185
        }
 
186
        if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
 
187
            error("Could not find forum $discussion->forum");
 
188
        }
 
189
 
 
190
        $post->subject = highlight($strippedsearch, $post->subject);
 
191
        $discussion->name = highlight($strippedsearch, $discussion->name);
 
192
 
 
193
        $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
 
194
        if ($forum->type != 'single') {
 
195
            $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
 
196
            if ($post->parent != 0) {
 
197
                $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
 
198
            }
 
199
        }
 
200
 
 
201
        $post->subject = $fullsubject;
 
202
 
 
203
        //Indicate search terms only found in HTML markup
 
204
        //Use highlight() with nonsense tags to spot search terms in the
 
205
        //actual text content first.          fiedorow - 9/2/2005
 
206
        $missing_terms = "";
 
207
        $message = highlight($strippedsearch,format_text($post->message, $post->format, NULL, $course->id),
 
208
                0,'<fgw9sdpq4>','</fgw9sdpq4>');
 
209
 
 
210
        foreach ($searchterms as $searchterm) {
 
211
            if (preg_match("/$searchterm/i",$message) && !preg_match('/<fgw9sdpq4>'.$searchterm.'<\/fgw9sdpq4>/i',$message)) {
 
212
                $missing_terms .= " $searchterm";
 
213
            }
 
214
        }
 
215
 
 
216
        $message = str_replace('<fgw9sdpq4>','<span class="highlight">',$message);
 
217
        $message = str_replace('</fgw9sdpq4>','</span>',$message);
 
218
 
 
219
        if ($missing_terms) {
 
220
            $strmissingsearchterms = get_string('missingsearchterms','forum');
 
221
            $post->message = '<p class="highlight2">'.$strmissingsearchterms.' '.$missing_terms.'</p>'.$message;
 
222
        } else {
 
223
            $post->message = $message;
 
224
        }
 
225
 
 
226
        $fulllink = "<a href=\"discuss.php?d=$post->discussion#$post->id\">".get_string("postincontext", "forum")."</a>";
 
227
        //search terms already highlighted - fiedorow - 9/2/2005
 
228
        forum_print_post($post, $course->id, false, false, false, false, $fulllink);
 
229
 
47
230
        echo "<br />";
48
 
        echo $searchform;
49
 
        echo "<br /><p>";
50
 
        print_string("searchhelp");
51
 
        echo "</p>";
52
 
        echo "</center>";
53
 
        print_simple_box_end();
54
 
    }
55
 
 
56
 
    if ($search) {
57
 
 
58
 
        if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount)) {
59
 
 
60
 
 
61
 
            print_header_simple("$strsearchresults", "",
62
 
                     "<a href=\"index.php?id=$course->id\">$strforums</a> -> 
63
 
                      <a href=\"search.php?id=$course->id\">$strsearch</a> -> \"$search\"", "search.search", 
64
 
                      "", "", "&nbsp;", navmenu($course));
65
 
            print_heading(get_string("nopostscontaining", "forum", $search));
66
 
 
67
 
            print_simple_box_start("center");
68
 
            echo "<center>";
69
 
            echo "<br />";
70
 
            echo $searchform;
71
 
            echo "<br /><p>";
72
 
            print_string("searchhelp");
73
 
            echo "</p>";
74
 
            echo "</center>";
75
 
            print_simple_box_end();
76
 
            print_footer($course);
77
 
            exit;
78
 
        }
79
 
 
80
 
        print_header_simple("$strsearchresults", "",
81
 
                 "<a href=\"index.php?id=$course->id\">$strforums</a> -> 
82
 
                  <a href=\"search.php?id=$course->id\">$strsearch</a> -> \"$search\"", "search.search", 
83
 
                  "", "",  $searchform, navmenu($course));
84
 
 
85
 
        print_heading("$strsearchresults: $totalcount");
86
 
 
87
 
        echo "<center>";
88
 
        print_paging_bar($totalcount, $page, $perpage, "search.php?search=$search&id=$course->id&perpage=$perpage&");
89
 
        echo "</center>";
90
 
 
91
 
        foreach ($posts as $post) {
92
 
 
93
 
            if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
94
 
                error("Discussion ID was incorrect");
95
 
            }
96
 
            if (! $forum = get_record("forum", "id", "$discussion->forum")) {
97
 
                error("Could not find forum $discussion->forum");
98
 
            }
99
 
 
100
 
            $post->subject = highlight("$search", $post->subject);
101
 
            $discussion->name = highlight("$search", $discussion->name);
102
 
 
103
 
            $fullsubject = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
104
 
            if ($forum->type != "single") {
105
 
                $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">$discussion->name</a>";
106
 
                if ($post->parent != 0) {
107
 
                    $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&parent=$post->id\">$post->subject</a>";
108
 
                }
109
 
            }
110
 
 
111
 
            $post->subject = $fullsubject;
112
 
 
113
 
            $fulllink = "<p align=\"right\"><a href=\"discuss.php?d=$post->discussion#$post->id\">".get_string("postincontext", "forum")."</a></p>";
114
 
            forum_print_post($post, $course->id, false, false, false, false, $fulllink, $search);
115
 
 
116
 
            echo "<br />";
117
 
        }
118
 
 
119
 
        echo "<center>";
120
 
        print_paging_bar($totalcount, $page, $perpage, "search.php?search=".urlencode($search)."&id=$course->id&perpage=$perpage&");
121
 
        echo "</center>";
122
 
    }
 
231
    }
 
232
 
 
233
    print_paging_bar($totalcount, $page, $perpage, "search.php?search=".urlencode($search)."&amp;id=$course->id&amp;perpage=$perpage&amp;");
123
234
 
124
235
    print_footer($course);
125
236
 
 
237
 
 
238
 
 
239
function forum_print_big_search_form($course) {
 
240
    global $words, $subject, $phrase, $user, $userid, $fullwords, $notwords, $datefrom, $dateto;
 
241
 
 
242
    print_simple_box(get_string('searchforumintro', 'forum'), 'center', '', '', 'searchbox', 'intro');
 
243
 
 
244
    print_simple_box_start("center");
 
245
 
 
246
    echo "<script type=\"text/javascript\" language=\"javascript\">\n";
 
247
    echo "var timefromitems = ['fromday','frommonth','fromyear','fromhour', 'fromminute'];\n";
 
248
    echo "var timetoitems = ['today','tomonth','toyear','tohour','tominute'];\n";
 
249
    echo "</script>\n";
 
250
 
 
251
    echo '<form name="search" action="search.php" method="get">';
 
252
    echo '<input type="hidden" value="'.$course->id.'" name="id" alt="">';
 
253
    echo '<table cellpadding="10" class="searchbox" id="form">';
 
254
 
 
255
    echo '<tr>';
 
256
    echo '<td class="c0">'.get_string('searchwords', 'forum').':</td>';
 
257
    echo '<td class="c1"><input type="text" size="35" name="words" value="'.s($words).'" alt=""></td>';
 
258
    echo '</tr>';
 
259
 
 
260
    echo '<tr>';
 
261
    echo '<td class="c0">'.get_string('searchphrase', 'forum').':</td>';
 
262
    echo '<td class="c1"><input type="text" size="35" name="phrase" value="'.s($phrase).'" alt=""></td>';
 
263
    echo '</tr>';
 
264
 
 
265
    echo '<tr>';
 
266
    echo '<td class="c0">'.get_string('searchnotwords', 'forum').':</td>';
 
267
    echo '<td class="c1"><input type="text" size="35" name="notwords" value="'.s($notwords).'" alt=""></td>';
 
268
    echo '</tr>';
 
269
 
 
270
    echo '<tr>';
 
271
    echo '<td class="c0">'.get_string('searchfullwords', 'forum').':</td>';
 
272
    echo '<td class="c1"><input type="text" size="35" name="fullwords" value="'.s($fullwords).'" alt=""></td>';
 
273
    echo '</tr>';
 
274
 
 
275
    echo '<tr>';
 
276
    echo '<td class="c0">'.get_string('searchdatefrom', 'forum').':</td>';
 
277
    echo '<td class="c1">';
 
278
    echo '<input name="timefromrestrict" type="checkbox" value="1" alt="'.get_string('searchdatefrom', 'forum').'" onclick="return lockoptions(\'search\', \'timefromrestrict\', timefromitems)" /> ';
 
279
    if (empty($dateto)) {
 
280
        $datefrom = make_timestamp(2000, 1, 1, 0, 0, 0);
 
281
    }
 
282
    print_date_selector('fromday', 'frommonth', 'fromyear', $datefrom);
 
283
    print_time_selector('fromhour', 'fromminute', $datefrom);
 
284
 
 
285
    echo '<input type="hidden" name="hfromday" value="0" />';
 
286
    echo '<input type="hidden" name="hfrommonth" value="0" />';
 
287
    echo '<input type="hidden" name="hfromyear" value="0" />';
 
288
    echo '<input type="hidden" name="hfromhour" value="0" />';
 
289
    echo '<input type="hidden" name="hfromminute" value="0" />';
 
290
 
 
291
    echo '</td>';
 
292
    echo '</tr>';
 
293
 
 
294
    echo '<tr>';
 
295
    echo '<td class="c0">'.get_string('searchdateto', 'forum').':</td>';
 
296
    echo '<td class="c1">';
 
297
    echo '<input name="timetorestrict" type="checkbox" value="1" alt="'.get_string('searchdateto', 'forum').'" onclick="return lockoptions(\'search\', \'timetorestrict\', timetoitems)" /> ';
 
298
    if (empty($dateto)) {
 
299
        $dateto = time()+3600;
 
300
    }
 
301
    print_date_selector('today', 'tomonth', 'toyear', $dateto);
 
302
    print_time_selector('tohour', 'tominute', $dateto);
 
303
 
 
304
    echo '<input type="hidden" name="htoday" value="0" />';
 
305
    echo '<input type="hidden" name="htomonth" value="0" />';
 
306
    echo '<input type="hidden" name="htoyear" value="0" />';
 
307
    echo '<input type="hidden" name="htohour" value="0" />';
 
308
    echo '<input type="hidden" name="htominute" value="0" />';
 
309
 
 
310
    echo '</td>';
 
311
    echo '</tr>';
 
312
 
 
313
    echo '<tr>';
 
314
    echo '<td class="c0">'.get_string('searchwhichforums', 'forum').':</td>';
 
315
    echo '<td class="c1">';
 
316
    choose_from_menu(forum_menu_list($course), 'forumid', '', get_string('allforums', 'forum'), '');
 
317
    echo '</td>';
 
318
    echo '</tr>';
 
319
 
 
320
    echo '<tr>';
 
321
    echo '<td class="c0">'.get_string('searchsubject', 'forum').':</td>';
 
322
    echo '<td class="c1"><input type="text" size="35" name="subject" value="'.s($subject).'" alt=""></td>';
 
323
    echo '</tr>';
 
324
 
 
325
    echo '<tr>';
 
326
    echo '<td class="c0">'.get_string('searchuser', 'forum').':</td>';
 
327
    echo '<td class="c1"><input type="text" size="35" name="user" value="'.s($user).'" alt=""></td>';
 
328
    echo '</tr>';
 
329
 
 
330
    echo '<tr>';
 
331
    echo '<td class="submit" colspan="2" align="center">';
 
332
    echo '<input type="submit" value="'.get_string('searchforums', 'forum').'" alt=""></td>';
 
333
    echo '</tr>';
 
334
 
 
335
    echo '</table>';
 
336
    echo '</form>';
 
337
 
 
338
    echo "<script type=\"text/javascript\">";
 
339
    echo "lockoptions('search','timefromrestrict', timefromitems);";
 
340
    echo "lockoptions('search','timetorestrict', timetoitems);";
 
341
    echo "</script>\n";
 
342
 
 
343
    print_simple_box_end();
 
344
}
 
345
 
 
346
 
 
347
function forum_clean_search_terms($words, $prefix='') {
 
348
    $searchterms = explode(' ', $words);
 
349
    foreach ($searchterms as $key => $searchterm) {
 
350
        if (strlen($searchterm) < 2) {
 
351
            unset($searchterms[$key]);
 
352
        } else if ($prefix) {
 
353
            $searchterms[$key] = $prefix.$searchterm;
 
354
        }
 
355
    }
 
356
    return trim(implode(' ', $searchterms));
 
357
}
 
358
 
 
359
function forum_menu_list($course)  {
 
360
 
 
361
    $menu = array();
 
362
 
 
363
    $currentgroup = get_current_group($course->id);
 
364
    $isteacher = isteacher($course->id);
 
365
 
 
366
    if ($isteacher) {   // Add teacher forum
 
367
        if ($forum = forum_get_course_forum($course->id, 'teacher')) {
 
368
            $menu[$forum->id] = format_string($forum->name,true);
 
369
        }
 
370
    }
 
371
 
 
372
    if ($forums = get_all_instances_in_course("forum", $course)) {
 
373
        if ($course->format == 'weeks') {
 
374
            $strsection = get_string('week');
 
375
        } else {
 
376
            $strsection = get_string('topic');
 
377
        }
 
378
 
 
379
        foreach ($forums as $forum) {
 
380
            if (!$isteacher) {   // Non-teachers
 
381
                if ($forum->type == "teacher") {
 
382
                    continue;
 
383
                }
 
384
                if (!isset($forum->visible)) {
 
385
                    if (! instance_is_visible("forum", $forum)) {
 
386
                        continue;
 
387
                    }
 
388
                }
 
389
                if ($cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
 
390
                    $groupmode = groupmode($course, $cm);   // Groups are being used
 
391
                    if (($groupmode == SEPARATEGROUPS) and ($currentgroup === false)) {
 
392
                        continue;
 
393
                    }
 
394
                }
 
395
            }
 
396
 
 
397
            $menu[$forum->id] = format_string($forum->name,true);
 
398
        }
 
399
    }
 
400
 
 
401
    return $menu;
 
402
}
 
403
 
126
404
?>
127
405