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(format_string($site->fullname
));
36 if ($CFG->bloglevel
>= 4) {
37 if (has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM
))) {
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 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
);
53 print_heading(format_string($course->fullname
));
55 $toprow[] = new tabobject('participants', $CFG->wwwroot
.'/user/index.php?id='.$filterselect,
56 get_string('participants'));
58 if ($CFG->bloglevel
>= 3) {
59 $toprow[] = new tabobject('blogs', $CFG->wwwroot
.'/blog/index.php?filtertype=course&filterselect='.$filterselect, get_string('blogs','blog'));
62 if (!empty($CFG->enablenotes
) and (has_capability('moodle/notes:manage', $coursecontext) ||
has_capability('moodle/notes:view', $coursecontext))) {
63 $toprow[] = new tabobject('notes', $CFG->wwwroot
.'/notes/index.php?filtertype=course&filterselect=' . $filterselect, get_string('notes', 'notes'));
66 /**************************************
67 * Group Level participation or Blogs *
68 **************************************/
69 } else if ($filtertype == 'group' && $filterselect) {
71 $group_name = groups_get_group_name($filterselect);
72 print_heading($group_name);
74 if ($CFG->bloglevel
>= 2) {
76 $toprow[] = new tabobject('participants', $CFG->wwwroot
.'/user/index.php?id='.$course->id
.'&group='.$filterselect,
77 get_string('participants'));
80 $toprow[] = new tabobject('blogs', $CFG->wwwroot
.'/blog/index.php?filtertype=group&filterselect='.$filterselect, get_string('blogs','blog'));
83 /**************************************
84 * User Level participation or Blogs *
85 **************************************/
88 $user = get_record('user','id', $userid);
90 print_heading(fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE
, $course->id
))));
92 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
93 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
);
94 $personalcontext = get_context_instance(CONTEXT_USER
, $user->id
);
96 if ($user->id
== $USER->id ||
has_capability('moodle/user:viewdetails', $coursecontext) ||
has_capability('moodle/user:viewdetails', $personalcontext) ) {
97 $toprow[] = new tabobject('profile', $CFG->wwwroot
.'/user/view.php?id='.$user->id
.'&course='.$course->id
, get_string('profile'));
101 /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
103 if(empty($CFG->loginhttps
)) {
104 $wwwroot = $CFG->wwwroot
;
106 $wwwroot = str_replace('http:','https:',$CFG->wwwroot
);
110 if (isguestuser($user)) {
111 // guest account can not be edited
113 } else if (is_mnet_remote_user($user)) {
114 // cannot edit remote users
116 } else if (isguestuser() or !isloggedin()) {
117 // guests and not logged in can not edit own profile
119 } else if ($USER->id
== $user->id
) {
120 if (has_capability('moodle/user:update', $systemcontext)) {
121 $edittype = 'advanced';
122 } else if (has_capability('moodle/user:editownprofile', $systemcontext)) {
123 $edittype = 'normal';
127 if (has_capability('moodle/user:update', $systemcontext) and !is_primary_admin($user->id
)){
128 $edittype = 'advanced';
129 } else if (has_capability('moodle/user:editprofile', $personalcontext) and !is_primary_admin($user->id
)){
130 //teachers, parents, etc.
131 $edittype = 'normal';
135 if ($edittype == 'advanced') {
136 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/editadvanced.php?id='.$user->id
.'&course='.$course->id
, get_string('editmyprofile'));
137 } else if ($edittype == 'normal') {
138 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id
.'&course='.$course->id
, get_string('editmyprofile'));
141 /// Everyone can see posts for this user
143 /// add logic to see course read posts permission
144 if (has_capability('moodle/user:readuserposts', $personalcontext) ||
has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
145 $toprow[] = new tabobject('forumposts', $CFG->wwwroot
.'/mod/forum/user.php?id='.$user->id
.'&course='.$course->id
,
146 get_string('forumposts', 'forum'));
148 if (in_array($currenttab, array('posts', 'discussions'))) {
149 $inactive = array('forumposts');
150 $activetwo = array('forumposts');
152 $secondrow = array();
153 $secondrow[] = new tabobject('posts', $CFG->wwwroot
.'/mod/forum/user.php?course='.$course->id
.
154 '&id='.$user->id
.'&mode=posts', get_string('posts', 'forum'));
155 $secondrow[] = new tabobject('discussions', $CFG->wwwroot
.'/mod/forum/user.php?course='.$course->id
.
156 '&id='.$user->id
.'&mode=discussions', get_string('discussions', 'forum'));
161 /// Personal blog entries tab
162 require_once($CFG->dirroot
.'/blog/lib.php');
163 if ($CFG->bloglevel
>= BLOG_USER_LEVEL
and // blogs must be enabled
164 (has_capability('moodle/user:readuserblogs', $personalcontext) // can review posts (parents etc)
165 or has_capability('moodle/blog:manageentries', $systemcontext) // entry manager can see all posts
166 or ($user->id
== $USER->id
and has_capability('moodle/blog:create', $systemcontext)) // viewing self
167 or (has_capability('moodle/blog:view', $systemcontext) or has_capability('moodle/blog:view', $coursecontext))
168 ) // able to read blogs in site or course context
171 $toprow[] = new tabobject('blogs', $CFG->wwwroot
.'/blog/index.php?userid='.$user->id
.'&courseid='.$course->id
, get_string('blog', 'blog'));
174 if (!empty($CFG->enablenotes
) and (has_capability('moodle/notes:manage', $coursecontext) ||
has_capability('moodle/notes:view', $coursecontext))) {
175 $toprow[] = new tabobject('notes', $CFG->wwwroot
.'/notes/index.php?course='.$course->id
. '&user=' . $user->id
, get_string('notes', 'notes'));
178 /// Find out if user allowed to see all reports of this user (usually parent) or individual course reports
180 $myreports = ($course->showreports
and $USER->id
== $user->id
);
181 $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
183 $reportsecondrow = array();
185 if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
186 $reportsecondrow[] = new tabobject('outline', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
187 '&user='.$user->id
.'&mode=outline', get_string('outlinereport'));
190 if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
191 $reportsecondrow[] = new tabobject('complete', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
192 '&user='.$user->id
.'&mode=complete', get_string('completereport'));
195 if ($myreports or $anyreport or has_capability('coursereport/log:viewtoday', $coursecontext)) {
196 $reportsecondrow[] = new tabobject('todaylogs', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
197 '&user='.$user->id
.'&mode=todaylogs', get_string('todaylogs'));
200 if ($myreports or $anyreport or has_capability('coursereport/log:view', $coursecontext)) {
201 $reportsecondrow[] = new tabobject('alllogs', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
202 '&user='.$user->id
.'&mode=alllogs', get_string('alllogs'));
205 if (!empty($CFG->enablestats
)) {
206 if ($myreports or $anyreport or has_capability('coursereport/stats:view', $coursecontext)) {
207 $reportsecondrow[] = new tabobject('stats',$CFG->wwwroot
.'/course/user.php?id='.$course->id
.
208 '&user='.$user->id
.'&mode=stats',get_string('stats'));
212 if (has_capability('moodle/grade:viewall', $coursecontext)) {
213 //ok - can view all course grades
216 } else if ($course->showgrades
and $user->id
== $USER->id
and has_capability('moodle/grade:view', $coursecontext)) {
217 //ok - can view own grades
220 } else if ($course->showgrades
and has_capability('moodle/grade:viewall', $personalcontext)) {
221 // ok - can view grades of this user - parent most probably
224 } else if ($course->showgrades
and $anyreport) {
225 // ok - can view grades of this user - parent most probably
229 $gradeaccess = false;
233 $reportsecondrow[] = new tabobject('grade', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
234 '&user='.$user->id
.'&mode=grade', get_string('grade'));
237 if ($reportsecondrow) {
238 $toprow[] = new tabobject('reports', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
239 '&user='.$user->id
.'&mode=outline', get_string('activityreports'));
240 if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) {
241 $inactive = array('reports');
242 $activetwo = array('reports');
243 $secondrow = $reportsecondrow;
246 } //close last bracket (individual tags)
249 /// this needs permission checkings
252 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
253 $usercontext = get_context_instance(CONTEXT_USER
, $user->id
);
254 if (has_capability('moodle/role:assign',$usercontext)) {
255 $toprow[] = new tabobject('roles', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
256 ,get_string('roles'));
258 if (in_array($currenttab, array('assign', 'override'))) {
259 $inactive = array('roles');
260 $activetwo = array('roles');
262 $secondrow = array();
263 $secondrow[] = new tabobject('assign', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
264 ,get_string('localroles', 'role'));
265 $secondrow[] = new tabobject('override', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/override.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
266 ,get_string('overridepermissions', 'role'));
271 /// Add second row to display if there is one
273 if (!empty($secondrow)) {
274 $tabs = array($toprow, $secondrow);
276 $tabs = array($toprow);
279 if ($currenttab == 'editprofile' && ($user->id
== $USER->id
) && user_not_fully_set_up($USER)) {
280 /// We're being forced here to fix profile
281 notify(get_string('moreprofileinfoneeded'));
283 /// Print out the tabs and continue!
284 print_tabs($tabs, $currenttab, $inactive, $activetwo);