Changes from Nenashev
[moodle.git] / mod / forum / user.php
CommitLineData
f9a0ea69 1<?php // $Id$
2
3// Display user activity reports for a course
4
5 require_once('../../config.php');
6 require_once('lib.php');
7
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);
13
14 if (! $user = get_record("user", "id", $id)) {
15 error("User ID is incorrect");
16 }
17
18 if (! $course = get_record("course", "id", $course)) {
19 error("Course id is incorrect.");
20 }
21
22 require_course_login($course);
23
24
25 add_to_log($course->id, "forum", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id");
26
27 $strforumposts = get_string('forumposts', 'forum');
28 $strparticipants = get_string('participants');
29 $strmode = get_string($mode, 'forum');
30 $fullname = fullname($user, isteacher($course->id));
31
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 }
43
44 $currenttab = $mode;
45 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
46
47 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and
48 $course->groupmodeforce and
49 !isteacheredit($course->id));
50
51 $groupid = $isseparategroups ? get_current_group($course->id) : NULL;
52
53 switch ($mode) {
54 case 'posts' :
55 $searchterms = array('userid:'.$user->id);
56 $extrasql = '';
57 break;
58
59 default:
60 $searchterms = array('userid:'.$user->id);
61 $extrasql = 'AND p.parent = 0';
62 break;
63 }
e1ddfa6b 64
65 echo '<div class="user-content">';
f9a0ea69 66 if ($posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage,
67 $totalcount, $groupid, $extrasql)) {
68 print_paging_bar($totalcount, $page, $perpage,
69 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
70 foreach ($posts as $post) {
71
72 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
73 error('Discussion ID was incorrect');
74 }
75 if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
76 error("Could not find forum $discussion->forum");
77 }
78
3849dae8 79 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 80 if ($forum->type != 'single') {
c78ac798 81 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 82 if ($post->parent != 0) {
17dc3f3c 83 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 84 }
85 }
a702e657 86
87 if (isadmin() && $course->id == SITEID) {
88 $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
89 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
90 }
f9a0ea69 91
92 $post->subject = $fullsubject;
93
f9a0ea69 94 $fulllink = "<a href=\"discuss.php?d=$post->discussion#$post->id\">".
95 get_string("postincontext", "forum")."</a>";
96
97 forum_print_post($post, $course->id, false, false, false, false, $fulllink);
98
99 echo "<br />";
100 }
101
102 print_paging_bar($totalcount, $page, $perpage,
103 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
104 } else {
105 print_heading(get_string('noposts', 'forum'));
106 }
e1ddfa6b 107 echo '</div>';
f9a0ea69 108 print_footer($course);
109
110?>
111