weekly release 1.9.15+
[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');
3f5636b5 7 // Course ID
8 $course = required_param('course', PARAM_INT);
9 // User ID
d3397f06 10 $id = optional_param('id', 0, PARAM_INT);
da5104e6 11 $mode = optional_param('mode', 'posts', PARAM_ALPHA);
12 $page = optional_param('page', 0, PARAM_INT);
13 $perpage = optional_param('perpage', 5, PARAM_INT);
f9a0ea69 14
42890783 15 if (empty($id)) { // See your own profile by default
16 require_login();
17 $id = $USER->id;
18 }
19
f9a0ea69 20 if (! $user = get_record("user", "id", $id)) {
21 error("User ID is incorrect");
22 }
23
24 if (! $course = get_record("course", "id", $course)) {
25 error("Course id is incorrect.");
26 }
27
5623276d 28 $syscontext = get_context_instance(CONTEXT_SYSTEM);
7034b46c 29 $usercontext = get_context_instance(CONTEXT_USER, $id);
1de384c3 30
7034b46c 31 // do not force parents to enrol
32 if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
33 require_course_login($course);
34 }
f9a0ea69 35
3e779c59 36 if ($user->deleted) {
37 print_header();
38 print_heading(get_string('userdeleted'));
39 print_footer($course);
40 die;
41 }
42
9bdb39c7 43 add_to_log($course->id, "forum", "user report",
44 "user.php?course=$course->id&amp;id=$user->id&amp;mode=$mode", "$user->id");
f9a0ea69 45
46 $strforumposts = get_string('forumposts', 'forum');
47 $strparticipants = get_string('participants');
48 $strmode = get_string($mode, 'forum');
951e1073 49 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
f9a0ea69 50
01e38388 51 $navlinks = array();
33d2459c 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');
54 }
3b27b0fe 55 $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id", 'type' => 'title');
56 $navlinks[] = array('name' => $strforumposts, 'link' => '', 'type' => 'title');
57 $navlinks[] = array('name' => $strmode, 'link' => '', 'type' => 'title');
1de384c3 58
3b27b0fe 59 $navigation = build_navigation($navlinks);
1de384c3 60
e3f58dfb 61 print_header("$course->shortname: $fullname: $strmode", $course->fullname,$navigation);
1de384c3 62
f9a0ea69 63
64 $currenttab = $mode;
b3e900ce 65 $showroles = 1;
f9a0ea69 66 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
67
fa22fd5f 68
f9a0ea69 69 switch ($mode) {
70 case 'posts' :
71 $searchterms = array('userid:'.$user->id);
72 $extrasql = '';
73 break;
74
75 default:
76 $searchterms = array('userid:'.$user->id);
77 $extrasql = 'AND p.parent = 0';
78 break;
79 }
1de384c3 80
e1ddfa6b 81 echo '<div class="user-content">';
1de384c3 82
67875aa1 83 if ($course->id == SITEID) {
ff406a88 84 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
02cb4f39 85 // Search throughout the whole site.
86 $searchcourse = 0;
87 } else {
88 $searchcourse = SITEID;
89 }
67875aa1 90 } else {
91 // Search only for posts the user made in this course.
92 $searchcourse = $course->id;
93 }
1de384c3 94
67875aa1 95 // Get the posts.
1de384c3 96 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
42fb3c85 97 $totalcount, $extrasql)) {
1de384c3 98
99 print_paging_bar($totalcount, $page, $perpage,
f9a0ea69 100 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
5623276d 101
102 $discussions = array();
103 $forums = array();
104 $cms = array();
1de384c3 105
f9a0ea69 106 foreach ($posts as $post) {
5623276d 107
108 if (!isset($discussions[$post->discussion])) {
109 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
110 error('Discussion ID was incorrect');
111 }
112 $discussions[$post->discussion] = $discussion;
113 } else {
114 $discussion = $discussions[$post->discussion];
f9a0ea69 115 }
5623276d 116
117 if (!isset($forums[$discussion->forum])) {
118 if (! $forum = get_record('forum', 'id', $discussion->forum)) {
119 error("Could not find forum $discussion->forum");
120 }
121 $forums[$discussion->forum] = $forum;
122 } else {
123 $forum = $forums[$discussion->forum];
f9a0ea69 124 }
5623276d 125
1de384c3 126 $ratings = null;
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;
134 }
135 }
136
5623276d 137 if (!isset($cms[$forum->id])) {
138 if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
139 error('Course Module ID was incorrect');
140 }
141 $cms[$forum->id] = $cm;
142 unset($cm); // do not use cm directly, it would break caching
143 }
144
3849dae8 145 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 146 if ($forum->type != 'single') {
c78ac798 147 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 148 if ($post->parent != 0) {
17dc3f3c 149 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 150 }
151 }
1de384c3 152
5623276d 153 if ($course->id == SITEID && has_capability('moodle/site:config', $syscontext)) {
a702e657 154 $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
155 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
156 }
bbbf2d40 157
f9a0ea69 158 $post->subject = $fullsubject;
bbbf2d40 159
9de96c06 160 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
f9a0ea69 161 get_string("postincontext", "forum")."</a>";
162
1de384c3 163 forum_print_post($post, $discussion, $forum, $cms[$forum->id], $course, false, false, false, $ratings, $fulllink);
f9a0ea69 164 echo "<br />";
165 }
1de384c3 166
167 print_paging_bar($totalcount, $page, $perpage,
f9a0ea69 168 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
169 } else {
4d463048 170 if ($mode == 'posts') {
171 print_heading(get_string('noposts', 'forum'));
172 } else {
173 print_heading(get_string('nodiscussionsstartedby', 'forum'));
174 }
f9a0ea69 175 }
e1ddfa6b 176 echo '</div>';
f9a0ea69 177 print_footer($course);
178
9de96c06 179?>