Fixes for capability checks.
[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
42890783 8 $course = required_param('course'); // course id
9 $id = optional_param('id'); // user id
f9a0ea69 10 $mode = optional_param('mode', 'posts');
11 $page = optional_param('page', 0);
12 $perpage = optional_param('perpage', 5);
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
27 require_course_login($course);
28
29
bbbf2d40 30 add_to_log($course->id, "forum", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id");
f9a0ea69 31
32 $strforumposts = get_string('forumposts', 'forum');
33 $strparticipants = get_string('participants');
34 $strmode = get_string($mode, 'forum');
35 $fullname = fullname($user, isteacher($course->id));
36
37 if ($course->category) {
38 print_header("$course->shortname: $fullname: $strmode", "$course->fullname",
39 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
40 <a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">$strparticipants</a> ->
41 <a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> ->
42 $strforumposts -> $strmode");
43 } else {
44 print_header("$course->shortname: $fullname: $strmode", "$course->fullname",
45 "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> ->
46 $strforumposts -> $strmode");
47 }
48
49 $currenttab = $mode;
50 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
51
bbbf2d40 52 $isseparategroups = /*(($course->groupmode == SEPARATEGROUPS and
53 $course->groupmodeforce and
54 !isteacheredit($course->id))*/forum_get_separate_modules($course->id);
55
56 /*
57 //editting teacher can view everything so do not pass in groupid
58 if (isteacheredit ($course->id)){
59 $isseparategroups = false;
fa22fd5f 60 }
bbbf2d40 61 */
62
63 $groupid = $isseparategroups ? /*get_current_group*/mygroupid($course->id) : NULL;
fa22fd5f 64
f9a0ea69 65 switch ($mode) {
66 case 'posts' :
67 $searchterms = array('userid:'.$user->id);
68 $extrasql = '';
69 break;
70
71 default:
72 $searchterms = array('userid:'.$user->id);
73 $extrasql = 'AND p.parent = 0';
74 break;
75 }
e1ddfa6b 76
77 echo '<div class="user-content">';
bbbf2d40 78 // Get the posts regardless of group first.
f9a0ea69 79 if ($posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage,
bbbf2d40 80 $totalcount, $groupid, $extrasql)) {
81
f9a0ea69 82 print_paging_bar($totalcount, $page, $perpage,
83 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
84 foreach ($posts as $post) {
85
86 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
87 error('Discussion ID was incorrect');
88 }
89 if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
90 error("Could not find forum $discussion->forum");
91 }
bbbf2d40 92
3849dae8 93 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 94 if ($forum->type != 'single') {
c78ac798 95 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 96 if ($post->parent != 0) {
17dc3f3c 97 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 98 }
99 }
bbbf2d40 100
101 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
0468976c 102 if ($course->id == SITEID && has_capability('moodle/site:config', $context)) {
a702e657 103 $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
104 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
105 }
bbbf2d40 106
f9a0ea69 107 $post->subject = $fullsubject;
bbbf2d40 108
f9a0ea69 109 $fulllink = "<a href=\"discuss.php?d=$post->discussion#$post->id\">".
110 get_string("postincontext", "forum")."</a>";
111
112 forum_print_post($post, $course->id, false, false, false, false, $fulllink);
bbbf2d40 113
f9a0ea69 114 echo "<br />";
115 }
116
117 print_paging_bar($totalcount, $page, $perpage,
118 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
119 } else {
120 print_heading(get_string('noposts', 'forum'));
121 }
e1ddfa6b 122 echo '</div>';
f9a0ea69 123 print_footer($course);
124
125?>
126