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/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(format_string($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 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
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 $mainadmin = get_admin();
98 if(empty($CFG->loginhttps
)) {
99 $wwwroot = $CFG->wwwroot
;
101 $wwwroot = str_replace('http:','https:',$CFG->wwwroot
);
105 if (is_mnet_remote_user($user)) {
106 // cannot edit remote users
108 } else if (isguest() or !isloggedin()) {
109 // can not edit guest like accounts - TODO: add capability to edit own profile
111 } else if ($USER->id
== $user->id
) {
112 if (has_capability('moodle/user:update', $systemcontext)) {
113 $edittype = 'advanced';
115 $edittype = 'normal';
118 } else if ($user->id
!= $mainadmin->id
) {
119 //no editing of primary admin!
120 if (has_capability('moodle/user:update', $systemcontext)) {
121 $edittype = 'advanced';
122 } else if (has_capability('moodle/user:editprofile', $personalcontext)) {
123 //teachers, parents, etc.
124 $edittype = 'normal';
128 if ($edittype == 'advanced') {
129 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/editadvanced.php?id='.$user->id
.'&course='.$course->id
, get_string('editmyprofile'));
130 } else if ($edittype == 'normal') {
131 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id
.'&course='.$course->id
, get_string('editmyprofile'));
134 /// Everyone can see posts for this user
136 /// add logic to see course read posts permission
137 if (has_capability('moodle/user:readuserposts', $personalcontext) ||
has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
138 $toprow[] = new tabobject('forumposts', $CFG->wwwroot
.'/mod/forum/user.php?id='.$user->id
.'&course='.$course->id
,
139 get_string('forumposts', 'forum'));
141 if (in_array($currenttab, array('posts', 'discussions'))) {
142 $inactive = array('forumposts');
143 $activetwo = array('forumposts');
145 $secondrow = array();
146 $secondrow[] = new tabobject('posts', $CFG->wwwroot
.'/mod/forum/user.php?course='.$course->id
.
147 '&id='.$user->id
.'&mode=posts', get_string('posts', 'forum'));
148 $secondrow[] = new tabobject('discussions', $CFG->wwwroot
.'/mod/forum/user.php?course='.$course->id
.
149 '&id='.$user->id
.'&mode=discussions', get_string('discussions', 'forum'));
154 /// Personal blog entries tab
155 require_once($CFG->dirroot
.'/blog/lib.php');
156 if ($CFG->bloglevel
>= BLOG_USER_LEVEL
and // blogs must be enabled
157 (has_capability('moodle/user:readuserblogs', $personalcontext) // can review posts (parents etc)
158 or has_capability('moodle/blog:manageentries', $systemcontext) // entry manager can see all posts
159 or ($user->id
== $USER->id
and has_capability('moodle/blog:create', $systemcontext)) // viewing self
160 or (has_capability('moodle/blog:view', $systemcontext) or has_capability('moodle/blog:view', $coursecontext))
161 ) // able to read blogs in site or course context
164 $toprow[] = new tabobject('blogs', $CFG->wwwroot
.'/blog/index.php?userid='.$user->id
.'&courseid='.$course->id
, get_string('blog', 'blog'));
167 /// Current user must be teacher of the course or the course allows user to view their reports
169 //print_object($course);
170 //print_object($user);
172 // add in logic to check course read report
173 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) ||
($course->showreports
and $USER->id
== $user->id
) ||
has_capability('moodle/user:viewuseractivitiesreport', $coursecontext)) {
175 $toprow[] = new tabobject('reports', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
176 '&user='.$user->id
.'&mode=outline', get_string('activityreports'));
178 if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) {
179 $inactive = array('reports');
180 $activetwo = array('reports');
182 $secondrow = array();
183 $secondrow[] = new tabobject('outline', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
184 '&user='.$user->id
.'&mode=outline', get_string('outlinereport'));
185 $secondrow[] = new tabobject('complete', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
186 '&user='.$user->id
.'&mode=complete', get_string('completereport'));
187 $secondrow[] = new tabobject('todaylogs', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
188 '&user='.$user->id
.'&mode=todaylogs', get_string('todaylogs'));
189 $secondrow[] = new tabobject('alllogs', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
190 '&user='.$user->id
.'&mode=alllogs', get_string('alllogs'));
191 if (!empty($CFG->enablestats
)) {
192 $secondrow[] = new tabobject('stats',$CFG->wwwroot
.'/course/user.php?id='.$course->id
.
193 '&user='.$user->id
.'&mode=stats',get_string('stats'));
196 if ($course->showgrades
) {
197 $secondrow[] = new tabobject('grade', $CFG->wwwroot
.'/course/user.php?id='.$course->id
.
198 '&user='.$user->id
.'&mode=grade', get_string('grade'));
205 } //close last bracket (individual tags)
208 /// this needs permission checkings
211 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
212 $usercontext = get_context_instance(CONTEXT_USER
, $user->id
);
213 if (has_capability('moodle/role:assign',$usercontext)) {
214 $toprow[] = new tabobject('roles', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
215 ,get_string('roles'));
217 if (in_array($currenttab, array('assign', 'override'))) {
218 $inactive = array('roles');
219 $activetwo = array('roles');
221 $secondrow = array();
222 $secondrow[] = new tabobject('assign', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
223 ,get_string('assignroles', 'role'));
224 $secondrow[] = new tabobject('override', $CFG->wwwroot
.'/'.$CFG->admin
.'/roles/override.php?contextid='.$usercontext->id
.'&userid='.$user->id
.'&courseid='.$course->id
225 ,get_string('overrideroles', 'role'));
230 /// Add second row to display if there is one
232 if (!empty($secondrow)) {
233 $tabs = array($toprow, $secondrow);
235 $tabs = array($toprow);
238 /// Print out the tabs and continue!
240 print_tabs($tabs, $currenttab, $inactive, $activetwo);