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