Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / forum / user.php
blob5d710027bcd52771bcb4f51744c09add4d72614b
1 <?php // $Id$
3 // Display user activity reports for a course
5 require_once('../../config.php');
6 require_once('lib.php');
7 // Course ID
8 $course = required_param('course', PARAM_INT);
9 // User ID
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
16 require_login();
17 $id = $USER->id;
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);
36 if ($user->deleted) {
37 print_header();
38 print_heading(get_string('userdeleted'));
39 print_footer($course);
40 die;
43 add_to_log($course->id, "forum", "user report",
44 "user.php?course=$course->id&amp;id=$user->id&amp;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));
51 $navlinks = array();
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&amp;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);
64 $currenttab = $mode;
65 $showroles = 1;
66 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
69 switch ($mode) {
70 case 'posts' :
71 $searchterms = array('userid:'.$user->id);
72 $extrasql = '';
73 break;
75 default:
76 $searchterms = array('userid:'.$user->id);
77 $extrasql = 'AND p.parent = 0';
78 break;
81 echo '<div class="user-content">';
83 if ($course->id == SITEID) {
84 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
85 // Search throughout the whole site.
86 $searchcourse = 0;
87 } else {
88 $searchcourse = SITEID;
90 } else {
91 // Search only for posts the user made in this course.
92 $searchcourse = $course->id;
95 // Get the posts.
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&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
102 $discussions = array();
103 $forums = array();
104 $cms = 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;
113 } else {
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;
122 } else {
123 $forum = $forums[$discussion->forum];
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;
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&amp;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);
164 echo "<br />";
167 print_paging_bar($totalcount, $page, $perpage,
168 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
169 } else {
170 if ($mode == 'posts') {
171 print_heading(get_string('noposts', 'forum'));
172 } else {
173 print_heading(get_string('nodiscussionsstartedby', 'forum'));
176 echo '</div>';
177 print_footer($course);