Updated the HEAD build version to 20081212
[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');
95bc81eb 7 // Course ID
8 $course = required_param('course', PARAM_INT);
9 // User ID
846fb679 10 $id = optional_param('id', 0, PARAM_INT);
da5104e6 11 $mode = optional_param('mode', 'posts', PARAM_ALPHA);
12 $page = optional_param('page', 0, PARAM_INT);
13 $perpage = optional_param('perpage', 5, PARAM_INT);
f9a0ea69 14
42890783 15 if (empty($id)) { // See your own profile by default
16 require_login();
17 $id = $USER->id;
18 }
19
4e445355 20 if (! $user = $DB->get_record("user", array("id" => $id))) {
2011a95b 21 error("User ID is incorrect");
f9a0ea69 22 }
23
4e445355 24 if (! $course = $DB->get_record("course", array("id" => $course))) {
2011a95b 25 error("Course id is incorrect.");
f9a0ea69 26 }
27
65bcf17b 28 $syscontext = get_context_instance(CONTEXT_SYSTEM);
7034b46c 29 $usercontext = get_context_instance(CONTEXT_USER, $id);
2011a95b 30
7034b46c 31 // do not force parents to enrol
4e445355 32 if (!$DB->get_record('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id))) {
7034b46c 33 require_course_login($course);
34 }
f9a0ea69 35
f5fc83e8 36 if ($user->deleted) {
37 print_header();
38 print_heading(get_string('userdeleted'));
39 print_footer($course);
40 die;
41 }
42
db1b15ce 43 add_to_log($course->id, "forum", "user report",
4e445355 44 "user.php?course=$course->id&amp;id=$user->id&amp;mode=$mode", "$user->id");
f9a0ea69 45
46 $strforumposts = get_string('forumposts', 'forum');
47 $strparticipants = get_string('participants');
48 $strmode = get_string($mode, 'forum');
951e1073 49 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
f9a0ea69 50
01e38388 51 $navlinks = array();
b26adbef 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');
54 }
3b27b0fe 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');
2011a95b 58
3b27b0fe 59 $navigation = build_navigation($navlinks);
2011a95b 60
e3f58dfb 61 print_header("$course->shortname: $fullname: $strmode", $course->fullname,$navigation);
2011a95b 62
f9a0ea69 63
64 $currenttab = $mode;
b3e900ce 65 $showroles = 1;
f9a0ea69 66 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
67
fa22fd5f 68
f9a0ea69 69 switch ($mode) {
70 case 'posts' :
71 $searchterms = array('userid:'.$user->id);
72 $extrasql = '';
73 break;
74
75 default:
76 $searchterms = array('userid:'.$user->id);
77 $extrasql = 'AND p.parent = 0';
78 break;
79 }
2011a95b 80
e1ddfa6b 81 echo '<div class="user-content">';
2011a95b 82
67875aa1 83 if ($course->id == SITEID) {
ff406a88 84 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
02cb4f39 85 // Search throughout the whole site.
86 $searchcourse = 0;
87 } else {
88 $searchcourse = SITEID;
89 }
67875aa1 90 } else {
91 // Search only for posts the user made in this course.
92 $searchcourse = $course->id;
93 }
2011a95b 94
67875aa1 95 // Get the posts.
2011a95b 96 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
42fb3c85 97 $totalcount, $extrasql)) {
2011a95b 98
99 print_paging_bar($totalcount, $page, $perpage,
f9a0ea69 100 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
65bcf17b 101
102 $discussions = array();
103 $forums = array();
104 $cms = array();
2011a95b 105
f9a0ea69 106 foreach ($posts as $post) {
65bcf17b 107
108 if (!isset($discussions[$post->discussion])) {
4e445355 109 if (! $discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion))) {
2011a95b 110 error('Discussion ID was incorrect');
65bcf17b 111 }
112 $discussions[$post->discussion] = $discussion;
113 } else {
114 $discussion = $discussions[$post->discussion];
f9a0ea69 115 }
65bcf17b 116
117 if (!isset($forums[$discussion->forum])) {
4e445355 118 if (! $forum = $DB->get_record('forum', array('id' => $discussion->forum))) {
2011a95b 119 error("Could not find forum $discussion->forum");
65bcf17b 120 }
121 $forums[$discussion->forum] = $forum;
122 } else {
123 $forum = $forums[$discussion->forum];
f9a0ea69 124 }
65bcf17b 125
2011a95b 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;
134 }
135 }
136
65bcf17b 137 if (!isset($cms[$forum->id])) {
138 if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
2011a95b 139 error('Course Module ID was incorrect');
65bcf17b 140 }
141 $cms[$forum->id] = $cm;
142 unset($cm); // do not use cm directly, it would break caching
143 }
144
3849dae8 145 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 146 if ($forum->type != 'single') {
c78ac798 147 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 148 if ($post->parent != 0) {
17dc3f3c 149 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 150 }
151 }
2011a95b 152
65bcf17b 153 if ($course->id == SITEID && has_capability('moodle/site:config', $syscontext)) {
4e445355 154 $postcoursename = $DB->get_field('course', array('shortname' => 'id'), $forum->course);
a702e657 155 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
156 }
bbbf2d40 157
f9a0ea69 158 $post->subject = $fullsubject;
bbbf2d40 159
9de96c06 160 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
f9a0ea69 161 get_string("postincontext", "forum")."</a>";
162
2011a95b 163 forum_print_post($post, $discussion, $forum, $cms[$forum->id], $course, false, false, false, $ratings, $fulllink);
f9a0ea69 164 echo "<br />";
165 }
2011a95b 166
167 print_paging_bar($totalcount, $page, $perpage,
f9a0ea69 168 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
169 } else {
4d463048 170 if ($mode == 'posts') {
171 print_heading(get_string('noposts', 'forum'));
172 } else {
173 print_heading(get_string('nodiscussionsstartedby', 'forum'));
174 }
f9a0ea69 175 }
e1ddfa6b 176 echo '</div>';
f9a0ea69 177 print_footer($course);
178
9de96c06 179?>