major grade editing fixes and improvements - grader form now knows if grade is editab...
[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
da5104e6 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);
f9a0ea69 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);
7034b46c 28 $usercontext = get_context_instance(CONTEXT_USER, $id);
29
30 // do not force parents to enrol
31 if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
32 require_course_login($course);
33 }
f9a0ea69 34
bbbf2d40 35 add_to_log($course->id, "forum", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id");
f9a0ea69 36
37 $strforumposts = get_string('forumposts', 'forum');
38 $strparticipants = get_string('participants');
39 $strmode = get_string($mode, 'forum');
951e1073 40 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
f9a0ea69 41
01e38388 42 $navlinks = array();
3b27b0fe 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');
e3f58dfb 47
3b27b0fe 48 $navigation = build_navigation($navlinks);
e3f58dfb 49
50 print_header("$course->shortname: $fullname: $strmode", $course->fullname,$navigation);
51
f9a0ea69 52
53 $currenttab = $mode;
b3e900ce 54 $showroles = 1;
f9a0ea69 55 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
56
fa22fd5f 57
f9a0ea69 58 switch ($mode) {
59 case 'posts' :
60 $searchterms = array('userid:'.$user->id);
61 $extrasql = '';
62 break;
63
64 default:
65 $searchterms = array('userid:'.$user->id);
66 $extrasql = 'AND p.parent = 0';
67 break;
68 }
e1ddfa6b 69
70 echo '<div class="user-content">';
67875aa1 71
67875aa1 72 if ($course->id == SITEID) {
ff406a88 73 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
02cb4f39 74 // Search throughout the whole site.
75 $searchcourse = 0;
76 } else {
77 $searchcourse = SITEID;
78 }
67875aa1 79 } else {
80 // Search only for posts the user made in this course.
81 $searchcourse = $course->id;
82 }
83
84 // Get the posts.
85 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
42fb3c85 86 $totalcount, $extrasql)) {
bbbf2d40 87
f9a0ea69 88 print_paging_bar($totalcount, $page, $perpage,
89 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
67875aa1 90
f9a0ea69 91 foreach ($posts as $post) {
92
93 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
94 error('Discussion ID was incorrect');
95 }
96 if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
97 error("Could not find forum $discussion->forum");
98 }
bbbf2d40 99
3849dae8 100 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 101 if ($forum->type != 'single') {
c78ac798 102 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 103 if ($post->parent != 0) {
17dc3f3c 104 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 105 }
106 }
bbbf2d40 107
108 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
0468976c 109 if ($course->id == SITEID && has_capability('moodle/site:config', $context)) {
a702e657 110 $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
111 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
112 }
bbbf2d40 113
f9a0ea69 114 $post->subject = $fullsubject;
bbbf2d40 115
9de96c06 116 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
f9a0ea69 117 get_string("postincontext", "forum")."</a>";
118
119 forum_print_post($post, $course->id, false, false, false, false, $fulllink);
f9a0ea69 120 echo "<br />";
121 }
122
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 {
aa91a2f2 126 print_heading(get_string('nodiscussionsstartedby', 'forum'));
f9a0ea69 127 }
e1ddfa6b 128 echo '</div>';
f9a0ea69 129 print_footer($course);
130
9de96c06 131?>