Fixing some alignment of categry boxes on front page
[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);
28
f9a0ea69 29 require_course_login($course);
30
31
bbbf2d40 32 add_to_log($course->id, "forum", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id");
f9a0ea69 33
34 $strforumposts = get_string('forumposts', 'forum');
35 $strparticipants = get_string('participants');
36 $strmode = get_string($mode, 'forum');
951e1073 37 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
f9a0ea69 38
1936c10e 39 if ($course->id != SITEID) {
f9a0ea69 40 print_header("$course->shortname: $fullname: $strmode", "$course->fullname",
41 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
42 <a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">$strparticipants</a> ->
43 <a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> ->
44 $strforumposts -> $strmode");
45 } else {
46 print_header("$course->shortname: $fullname: $strmode", "$course->fullname",
47 "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> ->
48 $strforumposts -> $strmode");
49 }
50
51 $currenttab = $mode;
b3e900ce 52 $showroles = 1;
f9a0ea69 53 include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page
54
fa22fd5f 55
f9a0ea69 56 switch ($mode) {
57 case 'posts' :
58 $searchterms = array('userid:'.$user->id);
59 $extrasql = '';
60 break;
61
62 default:
63 $searchterms = array('userid:'.$user->id);
64 $extrasql = 'AND p.parent = 0';
65 break;
66 }
e1ddfa6b 67
68 echo '<div class="user-content">';
67875aa1 69
70
71 if ($course->id == SITEID) {
72 // Search throughout the whole site.
73 $searchcourse = 0;
74 } else {
75 // Search only for posts the user made in this course.
76 $searchcourse = $course->id;
77 }
78
79 // Get the posts.
80 if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage,
42fb3c85 81 $totalcount, $extrasql)) {
bbbf2d40 82
f9a0ea69 83 print_paging_bar($totalcount, $page, $perpage,
84 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
67875aa1 85
f9a0ea69 86 foreach ($posts as $post) {
87
88 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
89 error('Discussion ID was incorrect');
90 }
91 if (! $forum = get_record('forum', 'id', "$discussion->forum")) {
92 error("Could not find forum $discussion->forum");
93 }
bbbf2d40 94
3849dae8 95 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
f9a0ea69 96 if ($forum->type != 'single') {
c78ac798 97 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
f9a0ea69 98 if ($post->parent != 0) {
17dc3f3c 99 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 100 }
101 }
bbbf2d40 102
103 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
0468976c 104 if ($course->id == SITEID && has_capability('moodle/site:config', $context)) {
a702e657 105 $postcoursename = get_field('course', 'shortname', 'id', $forum->course);
106 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
107 }
bbbf2d40 108
f9a0ea69 109 $post->subject = $fullsubject;
bbbf2d40 110
f9a0ea69 111 $fulllink = "<a href=\"discuss.php?d=$post->discussion#$post->id\">".
112 get_string("postincontext", "forum")."</a>";
113
114 forum_print_post($post, $course->id, false, false, false, false, $fulllink);
f9a0ea69 115 echo "<br />";
116 }
117
118 print_paging_bar($totalcount, $page, $perpage,
119 "user.php?id=$user->id&amp;course=$course->id&amp;mode=$mode&amp;perpage=$perpage&amp;");
120 } else {
121 print_heading(get_string('noposts', 'forum'));
122 }
e1ddfa6b 123 echo '</div>';
f9a0ea69 124 print_footer($course);
125
67875aa1 126?>