2 /// This file to be included so we can assume config.php has already been included.
3 /// We also assume that $user, $course, $currenttab have been set
5 if (!isset($filtertype)) {
8 if (!isset($filterselect)) {
12 //make sure everything is cleaned properly
13 $filtertype = clean_param($filtertype, PARAM_ALPHA
);
14 $filterselect = clean_param($filterselect, PARAM_INT
);
16 if (empty($currenttab) or empty($user) or empty($course)) {
17 //error('You cannot call this script in that way');
20 if (($filtertype == 'site' && $filterselect) ||
($filtertype=='user' && $filterselect)) {
21 $user = get_record('user','id',$filterselect);
28 /**************************************
29 * Site Level participation or Blogs *
30 **************************************/
31 if ($filtertype == 'site') {
34 print_heading($site->fullname
);
36 if ($CFG->bloglevel
>= 4) {
37 if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
38 $toprow[] = new tabobject('participants', $CFG->wwwroot
.'/user/index.php?id='.SITEID
,
39 get_string('participants'));
42 $toprow[] = new tabobject('blogs', $CFG->wwwroot
.'/blog/index.php?filtertype=site&',
43 get_string('blogs','blog'));
46 /**************************************
47 * Course Level participation or Blogs *
48 **************************************/
49 } else if ($filtertype == 'course' && $filterselect) {
51 $course = get_record('course','id',$filterselect);
52 print_heading($course->fullname
);
54 if ($CFG->bloglevel
>= 3) {
56 $toprow[] = new tabobject('participants', $CFG->wwwroot
.'/user/index.php?id='.$filterselect.'&group=0',
57 get_string('participants')); //the groupid hack is necessary, otherwise the group in the session willbe used
59 $toprow[] = new tabobject('blogs', $CFG->wwwroot
.'/blog/index.php?filtertype=course&filterselect='.$filterselect, get_string('blogs','blog'));
62 /**************************************
63 * Group Level participation or Blogs *
64 **************************************/
65 } else if ($filtertype == 'group' && $filterselect) {
67 $group_name = groups_get_group_name($filterselect); //TODO:
68 print_heading($group_name);
70 if ($CFG->bloglevel
>= 2) {
72 $toprow[] = new tabobject('participants', $CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$filterselect,
73 get_string('participants'));
76 $toprow[] = new tabobject('blogs', $CFG->wwwroot
.'/blog/index.php?filtertype=group&filterselect='.$filterselect, get_string('blogs','blog'));
79 /**************************************
80 * User Level participation or Blogs *
81 **************************************/
84 $user = get_record('user','id', $userid);
86 print_heading(fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE
, $course->id
))));
88 $toprow[] = new tabobject('profile', $CFG->wwwroot
.'/user/view.php?id='.$user->id
.'&course='.$course->id
, get_string('profile'));
90 $sitecontext = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
91 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
);
92 $personalcontext = get_context_instance(CONTEXT_USER
, $user->id
);
94 /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
96 if (($mainadmin = get_admin()) === false) {
97 $mainadmin->id
= 0; /// Weird - no primary admin!
100 if (is_mnet_remote_user($user)) {
101 // cannot edit remote users
103 else if ((!empty($USER->id
) and ($USER->id
== $user->id
) and !isguest()) or
104 (has_capability('moodle/user:editprofile', $personalcontext) and ($user->id
!= $mainadmin->id
)) ) {
106 if(empty($CFG->loginhttps
)) {
107 $wwwroot = $CFG->wwwroot
;
109 $wwwroot = str_replace('http:','https:',$CFG->wwwroot
);
112 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id
.'&course='.$course->id
, get_string('editmyprofile'));
115 /// Everyone can see posts for this user
117 /// add logic to see course read posts permission
118 if (has_capability('moodle/user:readuserposts', $personalcontext) ||
has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
119 $toprow[] = new tabobject('forumposts', $CFG->wwwroot
.'/mod/forum/user.php?id='.$user->id
.'&course='.$course->id
,
120 get_string('forumposts', 'forum'));
122 if (in_array($currenttab, array('posts', 'discussions'))) {
123 $inactive = array('forumposts');
124 $activetwo = array('forumposts');
126 $secondrow = array();
127 $secondrow[] = new tabobject('posts', $CFG->wwwroot
.'/mod/forum/user.php?course='.$course->id
.
128 '&id='.$user->id
.'&mode=posts', get_string('posts', 'forum'));
129 $secondrow[] = new tabobject('discussions', $CFG->wwwroot
.'/mod/forum/user.php?course='.$course->id
.
130 '&id='.$user->id
.'&mode=discussions', get_string('discussions', 'forum'));
135 /// Personal blog entries tab
136 require_once($CFG->dirroot
.'/blog/lib.php');
137 if ($CFG->bloglevel
>= BLOG_USER_LEVEL
and // blogs must be enabled
138 (has_capability('moodle/user:readuserblogs', $personalcontext) // can review posts (parents etc)
139 or has_capability('moodle/blog:manageentries', $sitecontext) // entry manager can see all posts
140 or ($user->id
== $USER->id
and has_capability('moodle/blog:create', $sitecontext)) // viewing self
141 or (has_capability('moodle/blog:view', $sitecontext) or has_capability('moodle/blog:view', $coursecontext))
142 ) // able to read blogs in site or course context
145 $toprow[] = new tabobject('blogs', $CFG->wwwroot
.'/blog/index.php?userid='.$user->id
.'&courseid='.$course->id
, get_string('blog', 'blog'));
148 /// Current user must be teacher of the course or the course allows user to view their reports
150 //print_object($course);
151 //print_object($user);
153 // add in logic to check course read report
154 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) ||
($course->showreports
and $USER->id
== $user->id
)) {
156 $toprow[] = new tabobject('reports', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
157 '&user='.$user->id
.'&mode=outline', get_string('activityreports'));
159 if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) {
160 $inactive = array('reports');
161 $activetwo = array('reports');
163 $secondrow = array();
164 $secondrow[] = new tabobject('outline', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
165 '&user='.$user->id
.'&mode=outline', get_string('outlinereport'));
166 $secondrow[] = new tabobject('complete', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
167 '&user='.$user->id
.'&mode=complete', get_string('completereport'));
168 $secondrow[] = new tabobject('todaylogs', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
169 '&user='.$user->id
.'&mode=todaylogs', get_string('todaylogs'));
170 $secondrow[] = new tabobject('alllogs', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
171 '&user='.$user->id
.'&mode=alllogs', get_string('alllogs'));
172 if (!empty($CFG->enablestats
)) {
173 $secondrow[] = new tabobject('stats',$CFG->wwwroot
.'/course/user.php?id='.$course->id
.
174 '&user='.$user->id
.'&mode=stats',get_string('stats'));
177 if ($course->showgrades
) {
178 $secondrow[] = new tabobject('grade', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
179 '&user='.$user->id
.'&mode=grade', get_string('grade'));
186 } //close last bracket (individual tags)
189 /// this needs permission checkings
192 if (!empty($showroles) and !empty($user)) { // this variable controls whether this roles is showed, or not, so only user/view page should set this flag
193 $usercontext = get_context_instance(CONTEXT_USER
, $user->id
);
194 if (has_capability('moodle/role:assign',$usercontext)) {
195 $toprow[] = new tabobject('roles', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
196 ,get_string('roles'));
198 if (in_array($currenttab, array('assign', 'override'))) {
199 $inactive = array('roles');
200 $activetwo = array('roles');
202 $secondrow = array();
203 $secondrow[] = new tabobject('assign', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
204 ,get_string('assignroles', 'role'));
205 $secondrow[] = new tabobject('override', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/override.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
206 ,get_string('overrideroles', 'role'));
211 /// Add second row to display if there is one
213 if (!empty($secondrow)) {
214 $tabs = array($toprow, $secondrow);
216 $tabs = array($toprow);
219 /// Print out the tabs and continue!
221 print_tabs($tabs, $currenttab, $inactive, $activetwo);