New user tabs from Shane and myself ... these bring together the
[moodle.git] / mod / forum / user.php
1 <?php // $Id$
3 // Display user activity reports for a course
5     require_once('../../config.php');
6     require_once('lib.php');
8     $id      = required_param('id');       // user id
9     $course    = required_param('course');     // course id
10     $mode    = optional_param('mode', 'posts');
11     $page    = optional_param('page', 0);
12     $perpage = optional_param('perpage', 5);
14     if (! $user = get_record("user", "id", $id)) {
15         error("User ID is incorrect");
16     }
18     if (! $course = get_record("course", "id", $course)) {
19         error("Course id is incorrect.");
20     }
22     require_course_login($course);
25     add_to_log($course->id, "forum", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id"); 
27     $strforumposts   = get_string('forumposts', 'forum');
28     $strparticipants = get_string('participants');
29     $strmode         = get_string($mode, 'forum');
30     $fullname        = fullname($user, isteacher($course->id));
32     if ($course->category) {
33         print_header("$course->shortname: $fullname: $strmode", "$course->fullname",
34                  "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
35                   <a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">$strparticipants</a> ->
36                   <a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> -> 
37                   $strforumposts -> $strmode");
38     } else {
39         print_header("$course->shortname: $fullname: $strmode", "$course->fullname",
40                  "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> -> 
41                   $strforumposts -> $strmode");
42     }
44     $currenttab = $mode;
45     include($CFG->dirroot.'/user/tabs.php');   /// Prints out tabs as part of user page
47     $isseparategroups = ($course->groupmode == SEPARATEGROUPS and
48                          $course->groupmodeforce and
49                          !isteacheredit($course->id));
51     $groupid = $isseparategroups ? get_current_group($course->id) : NULL;
53     switch ($mode) {
54         case 'posts' :
55             $searchterms = array('userid:'.$user->id);
56             $extrasql = '';
57             break;
59         default:
60             $searchterms = array('userid:'.$user->id);
61             $extrasql = 'AND p.parent = 0';
62             break;
63     }
65     if ($posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, 
66                                     $totalcount, $groupid, $extrasql)) {
67         print_paging_bar($totalcount, $page, $perpage, 
68                          "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
69         foreach ($posts as $post) {
70     
71             if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
72                 error('Discussion ID was incorrect');
73             }
74             if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
75                 error("Could not find forum $discussion->forum");
76             }
77     
78             $fullsubject = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
79             if ($forum->type != 'single') {
80                 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">$discussion->name</a>";
81                 if ($post->parent != 0) {
82                     $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">$post->subject</a>";
83                 }
84             }
85     
86             $post->subject = $fullsubject;
87     
88             /// Add the forum id to the post object - used by read tracking.
89             $post->forum = $forum->id;
90     
91             $fulllink = "<a href=\"discuss.php?d=$post->discussion#$post->id\">".
92                          get_string("postincontext", "forum")."</a>";
94             forum_print_post($post, $course->id, false, false, false, false, $fulllink);
95     
96             echo "<br />";
97         }
98     
99         print_paging_bar($totalcount, $page, $perpage, 
100                          "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
101     } else {
102         print_heading(get_string('noposts', 'forum'));
103     }
104     print_footer($course);
106 ?>