Breadcrumbs: mod/data changes
[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
1936c10e 42 if ($course->id != SITEID) {
6ba65fa0 43 print_header("$course->shortname: $fullname: $strmode", $course->fullname,
f9a0ea69 44 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
45 <a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">$strparticipants</a> ->
46 <a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> ->
47 $strforumposts -> $strmode");
48 } else {
6ba65fa0 49 print_header("$course->shortname: $fullname: $strmode", $course->fullname,
f9a0ea69 50 "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> ->
51 $strforumposts -> $strmode");
52 }
53
54 $currenttab = $mode;
b3e900ce 55 $showroles = 1;
f9a0ea69 56 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
57
fa22fd5f 58
f9a0ea69 59 switch ($mode) {
60 case 'posts' :
61 $searchterms = array('userid:'.$user->id);
62 $extrasql = '';
63 break;
64
65 default:
66 $searchterms = array('userid:'.$user->id);
67 $extrasql = 'AND p.parent = 0';
68 break;
69 }
e1ddfa6b 70
71 echo '<div class="user-content">';
67875aa1 72
67875aa1 73 if ($course->id == SITEID) {
ff406a88 74 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
02cb4f39 75 // Search throughout the whole site.
76 $searchcourse = 0;
77 } else {
78 $searchcourse = SITEID;
79 }
67875aa1 80 } else {
81 // Search only for posts the user made in this course.
82 $searchcourse = $course->id;
83 }
84
85 // Get the posts.
86 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
42fb3c85 87 $totalcount, $extrasql)) {
bbbf2d40 88
f9a0ea69 89 print_paging_bar($totalcount, $page, $perpage,
90 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
67875aa1 91
f9a0ea69 92 foreach ($posts as $post) {
93
94 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
95 error('Discussion ID was incorrect');
96 }
97 if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
98 error("Could not find forum $discussion->forum");
99 }
bbbf2d40 100
3849dae8 101 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 102 if ($forum->type != 'single') {
c78ac798 103 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 104 if ($post->parent != 0) {
17dc3f3c 105 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 106 }
107 }
bbbf2d40 108
109 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
0468976c 110 if ($course->id == SITEID && has_capability('moodle/site:config', $context)) {
a702e657 111 $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
112 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
113 }
bbbf2d40 114
f9a0ea69 115 $post->subject = $fullsubject;
bbbf2d40 116
9de96c06 117 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
f9a0ea69 118 get_string("postincontext", "forum")."</a>";
119
120 forum_print_post($post, $course->id, false, false, false, false, $fulllink);
f9a0ea69 121 echo "<br />";
122 }
123
124 print_paging_bar($totalcount, $page, $perpage,
125 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
126 } else {
aa91a2f2 127 print_heading(get_string('nodiscussionsstartedby', 'forum'));
f9a0ea69 128 }
e1ddfa6b 129 echo '</div>';
f9a0ea69 130 print_footer($course);
131
9de96c06 132?>