quiz MDL-10128 popup checker no longer requests a non-existent file which was causing...
[moodle.git] / mod / forum / user.php
CommitLineData
cd4e6b17 1<?php
f9a0ea69 2
3// Display user activity reports for a course
4
bb8f3759 5require_once('../../config.php');
6require_once('lib.php');
7
8// Course ID
9$course = required_param('course', PARAM_INT);
10// User ID
11$id = optional_param('id', 0, PARAM_INT);
12$mode = optional_param('mode', 'posts', PARAM_ALPHA);
13$page = optional_param('page', 0, PARAM_INT);
14$perpage = optional_param('perpage', 5, PARAM_INT);
15
cd4e6b17 16$url = new moodle_url($CFG->wwwroot.'/mod/forum/user.php', array('course'=>$course));
17if ($id !== 0) {
18 $url->param('id', $id);
19}
20if ($mode !== 'posts') {
21 $url->param('mode', $mode);
22}
23if ($page !== 0) {
24 $url->param('page', $page);
25}
26if ($perpage !== 5) {
27 $url->param('perpage', $perpage);
28}
29$PAGE->set_url($url);
30
bb8f3759 31if (empty($id)) { // See your own profile by default
32 require_login();
33 $id = $USER->id;
34}
35
36if (! $user = $DB->get_record("user", array("id" => $id))) {
37 print_error('invaliduserid');
38}
39
40if (! $course = $DB->get_record("course", array("id" => $course))) {
41 print_error('invalidcourseid');
42}
43
44$syscontext = get_context_instance(CONTEXT_SYSTEM);
45$usercontext = get_context_instance(CONTEXT_USER, $id);
46
47// do not force parents to enrol
48if (!$DB->get_record('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id))) {
49 require_course_login($course);
50}
51
52if ($user->deleted) {
15ca5e5e 53 echo $OUTPUT->header();
f43f1834 54 echo $OUTPUT->heading(get_string('userdeleted'));
396fb912 55 echo $OUTPUT->footer();
bb8f3759 56 die;
57}
f9a0ea69 58
bb8f3759 59add_to_log($course->id, "forum", "user report",
60 "user.php?course=$course->id&amp;id=$user->id&amp;mode=$mode", "$user->id");
f5fc83e8 61
bb8f3759 62$strforumposts = get_string('forumposts', 'forum');
63$strparticipants = get_string('participants');
64$strmode = get_string($mode, 'forum');
65$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
f9a0ea69 66
15ca5e5e 67$link = null;
bb8f3759 68if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id)) || has_capability('moodle/site:viewparticipants', $syscontext)) {
15ca5e5e 69 $link = new moodle_url($CFG->wwwroot.'/user/index.php',array('id'=>$course->id));
bb8f3759 70}
15ca5e5e 71$PAGE->navbar->add($strparticipants, $link);
72$PAGE->navbar->add($fullname, new moodle_url($CFG->wwwroot.'/user/view.php',array('id'=>$user->id,'course'=>$course->id)));
73$PAGE->navbar->add($strforumposts);
74$PAGE->navbar->add($strmode);
75
76$PAGE->set_title("$course->shortname: $fullname: $strmode");
77$PAGE->set_heading($course->fullname);
78echo $OUTPUT->header();
2011a95b 79
bb8f3759 80$currenttab = $mode;
81$showroles = 1;
82require($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
f9a0ea69 83
f9a0ea69 84
bb8f3759 85switch ($mode) {
86 case 'posts' :
87 $searchterms = array('userid:'.$user->id);
88 $extrasql = '';
89 break;
fa22fd5f 90
bb8f3759 91 default:
92 $searchterms = array('userid:'.$user->id);
93 $extrasql = 'AND p.parent = 0';
94 break;
95}
f9a0ea69 96
bb8f3759 97echo '<div class="user-content">';
2011a95b 98
bb8f3759 99if ($course->id == SITEID) {
100 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
101 // Search throughout the whole site.
102 $searchcourse = 0;
67875aa1 103 } else {
bb8f3759 104 $searchcourse = SITEID;
67875aa1 105 }
bb8f3759 106} else {
107 // Search only for posts the user made in this course.
108 $searchcourse = $course->id;
109}
2011a95b 110
bb8f3759 111// Get the posts.
112if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
113 $totalcount, $extrasql)) {
1adbd2c3 114
4e412c45 115 $baseurl = new moodle_url('user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => $mode, 'perpage' => $perpage));
116 echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, $baseurl));
65bcf17b 117
bb8f3759 118 $discussions = array();
119 $forums = array();
120 $cms = array();
2011a95b 121
bb8f3759 122 foreach ($posts as $post) {
65bcf17b 123
bb8f3759 124 if (!isset($discussions[$post->discussion])) {
125 if (! $discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion))) {
126 print_error('invaliddiscussionid', 'forum');
f9a0ea69 127 }
bb8f3759 128 $discussions[$post->discussion] = $discussion;
129 } else {
130 $discussion = $discussions[$post->discussion];
131 }
65bcf17b 132
bb8f3759 133 if (!isset($forums[$discussion->forum])) {
134 if (! $forum = $DB->get_record('forum', array('id' => $discussion->forum))) {
135 print_error('invalidforumid', 'forum');
f9a0ea69 136 }
bb8f3759 137 $forums[$discussion->forum] = $forum;
138 } else {
139 $forum = $forums[$discussion->forum];
140 }
65bcf17b 141
bb8f3759 142 $ratings = null;
143 if ($forum->assessed) {
144 if ($scale = make_grades_menu($forum->scale)) {
145 $ratings =new object();
146 $ratings->scale = $scale;
147 $ratings->assesstimestart = $forum->assesstimestart;
148 $ratings->assesstimefinish = $forum->assesstimefinish;
149 $ratings->allow = false;
2011a95b 150 }
bb8f3759 151 }
2011a95b 152
bb8f3759 153 if (!isset($cms[$forum->id])) {
154 if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
155 print_error('invalidcoursemodule');
65bcf17b 156 }
bb8f3759 157 $cms[$forum->id] = $cm;
158 unset($cm); // do not use cm directly, it would break caching
159 }
65bcf17b 160
bb8f3759 161 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
162 if ($forum->type != 'single') {
163 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
164 if ($post->parent != 0) {
165 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 166 }
bb8f3759 167 }
2011a95b 168
bb8f3759 169 if ($course->id == SITEID && has_capability('moodle/site:config', $syscontext)) {
170 $postcoursename = $DB->get_field('course', array('shortname' => 'id'), $forum->course);
171 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
172 }
bbbf2d40 173
bb8f3759 174 $post->subject = $fullsubject;
bbbf2d40 175
bb8f3759 176 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
177 get_string("postincontext", "forum")."</a>";
f9a0ea69 178
bb8f3759 179 forum_print_post($post, $discussion, $forum, $cms[$forum->id], $course, false, false, false, $ratings, $fulllink);
180 echo "<br />";
181 }
2011a95b 182
4e412c45 183 echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, $baseurl));
bb8f3759 184} else {
185 if ($mode == 'posts') {
f43f1834 186 echo $OUTPUT->heading(get_string('noposts', 'forum'));
f9a0ea69 187 } else {
f43f1834 188 echo $OUTPUT->heading(get_string('nodiscussionsstartedby', 'forum'));
f9a0ea69 189 }
bb8f3759 190}
191echo '</div>';
396fb912 192echo $OUTPUT->footer();
f9a0ea69 193