3 // Display user activity reports for a course
5 require_once('../../config.php');
6 require_once('lib.php');
8 $course = required_param('course', PARAM_INT
);
10 $id = optional_param('id', 0, PARAM_INT
);
11 $mode = optional_param('mode', 'posts', PARAM_ALPHA
);
12 $page = optional_param('page', 0, PARAM_INT
);
13 $perpage = optional_param('perpage', 5, PARAM_INT
);
15 if (empty($id)) { // See your own profile by default
20 if (! $user = get_record("user", "id", $id)) {
21 error("User ID is incorrect");
24 if (! $course = get_record("course", "id", $course)) {
25 error("Course id is incorrect.");
28 $syscontext = get_context_instance(CONTEXT_SYSTEM
);
29 $usercontext = get_context_instance(CONTEXT_USER
, $id);
31 // do not force parents to enrol
32 if (!get_record('role_assignments', 'userid', $USER->id
, 'contextid', $usercontext->id
)) {
33 require_course_login($course);
38 print_heading(get_string('userdeleted'));
39 print_footer($course);
43 add_to_log($course->id
, "forum", "user report",
44 "user.php?course=$course->id&id=$user->id&mode=$mode", "$user->id");
46 $strforumposts = get_string('forumposts', 'forum');
47 $strparticipants = get_string('participants');
48 $strmode = get_string($mode, 'forum');
49 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
52 if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE
, $course->id
)) ||
has_capability('moodle/site:viewparticipants', $syscontext)) {
53 $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'core');
55 $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id", 'type' => 'title');
56 $navlinks[] = array('name' => $strforumposts, 'link' => '', 'type' => 'title');
57 $navlinks[] = array('name' => $strmode, 'link' => '', 'type' => 'title');
59 $navigation = build_navigation($navlinks);
61 print_header("$course->shortname: $fullname: $strmode", $course->fullname
,$navigation);
66 include($CFG->dirroot
.'/user/tabs.php'); /// Prints out tabs as part of user page
71 $searchterms = array('userid:'.$user->id
);
76 $searchterms = array('userid:'.$user->id
);
77 $extrasql = 'AND p.parent = 0';
81 echo '<div class="user-content">';
83 if ($course->id
== SITEID
) {
84 if (empty($CFG->forceloginforprofiles
) ||
isloggedin()) {
85 // Search throughout the whole site.
88 $searchcourse = SITEID
;
91 // Search only for posts the user made in this course.
92 $searchcourse = $course->id
;
96 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
97 $totalcount, $extrasql)) {
99 print_paging_bar($totalcount, $page, $perpage,
100 "user.php?id=$user->id&course=$course->id&mode=$mode&perpage=$perpage&");
102 $discussions = array();
106 foreach ($posts as $post) {
108 if (!isset($discussions[$post->discussion
])) {
109 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion
)) {
110 error('Discussion ID was incorrect');
112 $discussions[$post->discussion
] = $discussion;
114 $discussion = $discussions[$post->discussion
];
117 if (!isset($forums[$discussion->forum
])) {
118 if (! $forum = get_record('forum', 'id', $discussion->forum
)) {
119 error("Could not find forum $discussion->forum");
121 $forums[$discussion->forum
] = $forum;
123 $forum = $forums[$discussion->forum
];
127 if ($forum->assessed
) {
128 if ($scale = make_grades_menu($forum->scale
)) {
129 $ratings =new object();
130 $ratings->scale
= $scale;
131 $ratings->assesstimestart
= $forum->assesstimestart
;
132 $ratings->assesstimefinish
= $forum->assesstimefinish
;
133 $ratings->allow
= false;
137 if (!isset($cms[$forum->id
])) {
138 if (!$cm = get_coursemodule_from_instance('forum', $forum->id
)) {
139 error('Course Module ID was incorrect');
141 $cms[$forum->id
] = $cm;
142 unset($cm); // do not use cm directly, it would break caching
145 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name
,true)."</a>";
146 if ($forum->type
!= 'single') {
147 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name
,true)."</a>";
148 if ($post->parent
!= 0) {
149 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&parent=$post->id\">".format_string($post->subject
,true)."</a>";
153 if ($course->id
== SITEID
&& has_capability('moodle/site:config', $syscontext)) {
154 $postcoursename = get_field('course', 'shortname', 'id', $forum->course
);
155 $fullsubject = '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$forum->course
.'">'.$postcoursename.'</a> -> '. $fullsubject;
158 $post->subject
= $fullsubject;
160 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
161 get_string("postincontext", "forum")."</a>";
163 forum_print_post($post, $discussion, $forum, $cms[$forum->id
], $course, false, false, false, $ratings, $fulllink);
167 print_paging_bar($totalcount, $page, $perpage,
168 "user.php?id=$user->id&course=$course->id&mode=$mode&perpage=$perpage&");
170 if ($mode == 'posts') {
171 print_heading(get_string('noposts', 'forum'));
173 print_heading(get_string('nodiscussionsstartedby', 'forum'));
177 print_footer($course);