MDL-13811 Completed the required changes. Also added a "Cancel email change" link...
[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
db1b15ce 36 add_to_log($course->id, "forum", "user report",
4e445355 37 "user.php?course=$course->id&amp;id=$user->id&amp;mode=$mode", "$user->id");
f9a0ea69 38
39 $strforumposts = get_string('forumposts', 'forum');
40 $strparticipants = get_string('participants');
41 $strmode = get_string($mode, 'forum');
951e1073 42 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
f9a0ea69 43
01e38388 44 $navlinks = array();
b26adbef 45 if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id)) || has_capability('moodle/site:viewparticipants', $syscontext)) {
46 $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'core');
47 }
3b27b0fe 48 $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id", 'type' => 'title');
49 $navlinks[] = array('name' => $strforumposts, 'link' => '', 'type' => 'title');
50 $navlinks[] = array('name' => $strmode, 'link' => '', 'type' => 'title');
2011a95b 51
3b27b0fe 52 $navigation = build_navigation($navlinks);
2011a95b 53
e3f58dfb 54 print_header("$course->shortname: $fullname: $strmode", $course->fullname,$navigation);
2011a95b 55
f9a0ea69 56
57 $currenttab = $mode;
b3e900ce 58 $showroles = 1;
f9a0ea69 59 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
60
fa22fd5f 61
f9a0ea69 62 switch ($mode) {
63 case 'posts' :
64 $searchterms = array('userid:'.$user->id);
65 $extrasql = '';
66 break;
67
68 default:
69 $searchterms = array('userid:'.$user->id);
70 $extrasql = 'AND p.parent = 0';
71 break;
72 }
2011a95b 73
e1ddfa6b 74 echo '<div class="user-content">';
2011a95b 75
67875aa1 76 if ($course->id == SITEID) {
ff406a88 77 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
02cb4f39 78 // Search throughout the whole site.
79 $searchcourse = 0;
80 } else {
81 $searchcourse = SITEID;
82 }
67875aa1 83 } else {
84 // Search only for posts the user made in this course.
85 $searchcourse = $course->id;
86 }
2011a95b 87
67875aa1 88 // Get the posts.
2011a95b 89 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
42fb3c85 90 $totalcount, $extrasql)) {
2011a95b 91
92 print_paging_bar($totalcount, $page, $perpage,
f9a0ea69 93 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
65bcf17b 94
95 $discussions = array();
96 $forums = array();
97 $cms = array();
2011a95b 98
f9a0ea69 99 foreach ($posts as $post) {
65bcf17b 100
101 if (!isset($discussions[$post->discussion])) {
4e445355 102 if (! $discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion))) {
2011a95b 103 error('Discussion ID was incorrect');
65bcf17b 104 }
105 $discussions[$post->discussion] = $discussion;
106 } else {
107 $discussion = $discussions[$post->discussion];
f9a0ea69 108 }
65bcf17b 109
110 if (!isset($forums[$discussion->forum])) {
4e445355 111 if (! $forum = $DB->get_record('forum', array('id' => $discussion->forum))) {
2011a95b 112 error("Could not find forum $discussion->forum");
65bcf17b 113 }
114 $forums[$discussion->forum] = $forum;
115 } else {
116 $forum = $forums[$discussion->forum];
f9a0ea69 117 }
65bcf17b 118
2011a95b 119 $ratings = null;
120 if ($forum->assessed) {
121 if ($scale = make_grades_menu($forum->scale)) {
122 $ratings =new object();
123 $ratings->scale = $scale;
124 $ratings->assesstimestart = $forum->assesstimestart;
125 $ratings->assesstimefinish = $forum->assesstimefinish;
126 $ratings->allow = false;
127 }
128 }
129
65bcf17b 130 if (!isset($cms[$forum->id])) {
131 if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
2011a95b 132 error('Course Module ID was incorrect');
65bcf17b 133 }
134 $cms[$forum->id] = $cm;
135 unset($cm); // do not use cm directly, it would break caching
136 }
137
3849dae8 138 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 139 if ($forum->type != 'single') {
c78ac798 140 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 141 if ($post->parent != 0) {
17dc3f3c 142 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 143 }
144 }
2011a95b 145
65bcf17b 146 if ($course->id == SITEID && has_capability('moodle/site:config', $syscontext)) {
4e445355 147 $postcoursename = $DB->get_field('course', array('shortname' => 'id'), $forum->course);
a702e657 148 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
149 }
bbbf2d40 150
f9a0ea69 151 $post->subject = $fullsubject;
bbbf2d40 152
9de96c06 153 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
f9a0ea69 154 get_string("postincontext", "forum")."</a>";
155
2011a95b 156 forum_print_post($post, $discussion, $forum, $cms[$forum->id], $course, false, false, false, $ratings, $fulllink);
f9a0ea69 157 echo "<br />";
158 }
2011a95b 159
160 print_paging_bar($totalcount, $page, $perpage,
f9a0ea69 161 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
162 } else {
4d463048 163 if ($mode == 'posts') {
164 print_heading(get_string('noposts', 'forum'));
165 } else {
166 print_heading(get_string('nodiscussionsstartedby', 'forum'));
167 }
f9a0ea69 168 }
e1ddfa6b 169 echo '</div>';
f9a0ea69 170 print_footer($course);
171
9de96c06 172?>