MDL-13375 fix for duplicate itemnumbers in outcome items; merged from MOODLE_19_STABLE
[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
da5104e6 8 $course = required_param('course', PARAM_INT); // course id
9 $id = optional_param('id', 0, PARAM_INT); // user id
10 $mode = optional_param('mode', 'posts', PARAM_ALPHA);
11 $page = optional_param('page', 0, PARAM_INT);
12 $perpage = optional_param('perpage', 5, PARAM_INT);
f9a0ea69 13
42890783 14 if (empty($id)) { // See your own profile by default
15 require_login();
16 $id = $USER->id;
17 }
18
f9a0ea69 19 if (! $user = get_record("user", "id", $id)) {
20 error("User ID is incorrect");
21 }
22
23 if (! $course = get_record("course", "id", $course)) {
24 error("Course id is incorrect.");
25 }
26
951e1073 27 $syscontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
7034b46c 28 $usercontext = get_context_instance(CONTEXT_USER, $id);
29
30 // do not force parents to enrol
31 if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
32 require_course_login($course);
33 }
f9a0ea69 34
bbbf2d40 35 add_to_log($course->id, "forum", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id");
f9a0ea69 36
37 $strforumposts = get_string('forumposts', 'forum');
38 $strparticipants = get_string('participants');
39 $strmode = get_string($mode, 'forum');
951e1073 40 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
f9a0ea69 41
01e38388 42 $navlinks = array();
b26adbef 43 if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id)) || has_capability('moodle/site:viewparticipants', $syscontext)) {
44 $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'core');
45 }
3b27b0fe 46 $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id", 'type' => 'title');
47 $navlinks[] = array('name' => $strforumposts, 'link' => '', 'type' => 'title');
48 $navlinks[] = array('name' => $strmode, 'link' => '', 'type' => 'title');
e3f58dfb 49
3b27b0fe 50 $navigation = build_navigation($navlinks);
e3f58dfb 51
52 print_header("$course->shortname: $fullname: $strmode", $course->fullname,$navigation);
53
f9a0ea69 54
55 $currenttab = $mode;
b3e900ce 56 $showroles = 1;
f9a0ea69 57 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
58
fa22fd5f 59
f9a0ea69 60 switch ($mode) {
61 case 'posts' :
62 $searchterms = array('userid:'.$user->id);
63 $extrasql = '';
64 break;
65
66 default:
67 $searchterms = array('userid:'.$user->id);
68 $extrasql = 'AND p.parent = 0';
69 break;
70 }
e1ddfa6b 71
72 echo '<div class="user-content">';
67875aa1 73
67875aa1 74 if ($course->id == SITEID) {
ff406a88 75 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
02cb4f39 76 // Search throughout the whole site.
77 $searchcourse = 0;
78 } else {
79 $searchcourse = SITEID;
80 }
67875aa1 81 } else {
82 // Search only for posts the user made in this course.
83 $searchcourse = $course->id;
84 }
85
86 // Get the posts.
87 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
42fb3c85 88 $totalcount, $extrasql)) {
bbbf2d40 89
f9a0ea69 90 print_paging_bar($totalcount, $page, $perpage,
91 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
67875aa1 92
f9a0ea69 93 foreach ($posts as $post) {
94
95 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
96 error('Discussion ID was incorrect');
97 }
98 if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
99 error("Could not find forum $discussion->forum");
100 }
bbbf2d40 101
3849dae8 102 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 103 if ($forum->type != 'single') {
c78ac798 104 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 105 if ($post->parent != 0) {
17dc3f3c 106 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 107 }
108 }
bbbf2d40 109
110 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
0468976c 111 if ($course->id == SITEID && has_capability('moodle/site:config', $context)) {
a702e657 112 $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
113 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
114 }
bbbf2d40 115
f9a0ea69 116 $post->subject = $fullsubject;
bbbf2d40 117
9de96c06 118 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
f9a0ea69 119 get_string("postincontext", "forum")."</a>";
120
121 forum_print_post($post, $course->id, false, false, false, false, $fulllink);
f9a0ea69 122 echo "<br />";
123 }
124
125 print_paging_bar($totalcount, $page, $perpage,
126 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
127 } else {
4d463048 128 if ($mode == 'posts') {
129 print_heading(get_string('noposts', 'forum'));
130 } else {
131 print_heading(get_string('nodiscussionsstartedby', 'forum'));
132 }
f9a0ea69 133 }
e1ddfa6b 134 echo '</div>';
f9a0ea69 135 print_footer($course);
136
9de96c06 137?>