MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / forum / user.php
blob39b537a53efd90e491cc29f50c80b29411f18529
1 <?php // $Id$
3 // Display user activity reports for a course
5 require_once('../../config.php');
6 require_once('lib.php');
8 $course = required_param('course', PARAM_INT); // course id
9 $id = optional_param('id', 0, PARAM_INT); // user id
10 $mode = optional_param('mode', 'posts', PARAM_ALPHA);
11 $page = optional_param('page', 0, PARAM_INT);
12 $perpage = optional_param('perpage', 5, PARAM_INT);
14 if (empty($id)) { // See your own profile by default
15 require_login();
16 $id = $USER->id;
19 if (! $user = get_record("user", "id", $id)) {
20 error("User ID is incorrect");
23 if (! $course = get_record("course", "id", $course)) {
24 error("Course id is incorrect.");
27 $syscontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
28 $usercontext = get_context_instance(CONTEXT_USER, $id);
30 // do not force parents to enrol
31 if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
32 require_course_login($course);
35 add_to_log($course->id, "forum", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id");
37 $strforumposts = get_string('forumposts', 'forum');
38 $strparticipants = get_string('participants');
39 $strmode = get_string($mode, 'forum');
40 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
42 $navlinks = array();
43 $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$course->id", 'type' => 'core');
44 $navlinks[] = array('name' => $fullname, 'link' => "$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id", 'type' => 'title');
45 $navlinks[] = array('name' => $strforumposts, 'link' => '', 'type' => 'title');
46 $navlinks[] = array('name' => $strmode, 'link' => '', 'type' => 'title');
48 $navigation = build_navigation($navlinks);
50 print_header("$course->shortname: $fullname: $strmode", $course->fullname,$navigation);
53 $currenttab = $mode;
54 $showroles = 1;
55 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
58 switch ($mode) {
59 case 'posts' :
60 $searchterms = array('userid:'.$user->id);
61 $extrasql = '';
62 break;
64 default:
65 $searchterms = array('userid:'.$user->id);
66 $extrasql = 'AND p.parent = 0';
67 break;
70 echo '<div class="user-content">';
72 if ($course->id == SITEID) {
73 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
74 // Search throughout the whole site.
75 $searchcourse = 0;
76 } else {
77 $searchcourse = SITEID;
79 } else {
80 // Search only for posts the user made in this course.
81 $searchcourse = $course->id;
84 // Get the posts.
85 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
86 $totalcount, $extrasql)) {
88 print_paging_bar($totalcount, $page, $perpage,
89 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
91 foreach ($posts as $post) {
93 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
94 error('Discussion ID was incorrect');
96 if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
97 error("Could not find forum $discussion->forum");
100 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
101 if ($forum->type != 'single') {
102 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
103 if ($post->parent != 0) {
104 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
108 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
109 if ($course->id == SITEID && has_capability('moodle/site:config', $context)) {
110 $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
111 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
114 $post->subject = $fullsubject;
116 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
117 get_string("postincontext", "forum")."</a>";
119 forum_print_post($post, $course->id, false, false, false, false, $fulllink);
120 echo "<br />";
123 print_paging_bar($totalcount, $page, $perpage,
124 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
125 } else {
126 if ($mode == 'posts') {
127 print_heading(get_string('noposts', 'forum'));
128 } else {
129 print_heading(get_string('nodiscussionsstartedby', 'forum'));
132 echo '</div>';
133 print_footer($course);