Update for latest functions
[moodle.git] / user / tabs.php
CommitLineData
f9a0ea69 1<?php // $Id$
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
4
1242eb8f 5 if (!isset($filtertype)) {
6 $filtertype = '';
7 }
8 if (!isset($filterselect)) {
9 $filterselect = '';
10 }
f9a0ea69 11
57f2e16c 12 //make sure everything is cleaned properly
13 $filtertype = clean_param($filtertype, PARAM_ALPHA);
14 $filterselect = clean_param($filterselect, PARAM_INT);
15
f9a0ea69 16 if (empty($currenttab) or empty($user) or empty($course)) {
1242eb8f 17 //error('You cannot call this script in that way');
f9a0ea69 18 }
19
1242eb8f 20 if (($filtertype == 'site' && $filterselect) || ($filtertype=='user' && $filterselect)) {
21 $user = get_record('user','id',$filterselect);
22 }
f9a0ea69 23
24 $inactive = NULL;
e1ddfa6b 25 $activetwo = NULL;
f9a0ea69 26 $toprow = array();
27
1242eb8f 28 /**************************************
29 * Site Level participation or Blogs *
30 **************************************/
31 if ($filtertype == 'site') {
f9a0ea69 32
1242eb8f 33 $site = get_site();
6ba65fa0 34 print_heading(format_string($site->fullname));
1242eb8f 35
36 if ($CFG->bloglevel >= 4) {
bd574b2a 37 if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
adc7b679 38 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.SITEID,
39 get_string('participants'));
40 }
f9a0ea69 41
1242eb8f 42 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=site&amp;',
7b07bc55 43 get_string('blogs','blog'));
1242eb8f 44 }
f9a0ea69 45
1242eb8f 46 /**************************************
47 * Course Level participation or Blogs *
48 **************************************/
49 } else if ($filtertype == 'course' && $filterselect) {
f9a0ea69 50
1242eb8f 51 $course = get_record('course','id',$filterselect);
eca3af25 52 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
6ba65fa0 53 print_heading(format_string($course->fullname));
f9a0ea69 54
ffc536af 55 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$filterselect,
56 get_string('participants'));
1242eb8f 57
eca3af25 58 if ($CFG->bloglevel >= 3) {
7b07bc55 59 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=course&amp;filterselect='.$filterselect, get_string('blogs','blog'));
f9a0ea69 60 }
f9a0ea69 61
eca3af25 62 if (has_capability('moodle/notes:manage', $coursecontext) || has_capability('moodle/notes:view', $coursecontext)) {
63 $toprow[] = new tabobject('notes', $CFG->wwwroot.'/notes/index.php?filtertype=course&amp;filterselect=' . $filterselect, get_string('notes', 'notes'));
64 }
65
1242eb8f 66 /**************************************
67 * Group Level participation or Blogs *
68 **************************************/
69 } else if ($filtertype == 'group' && $filterselect) {
f9a0ea69 70
ffc536af 71 $group_name = groups_get_group_name($filterselect);
f3f7610c 72 print_heading($group_name);
f9a0ea69 73
1242eb8f 74 if ($CFG->bloglevel >= 2) {
f9a0ea69 75
1242eb8f 76 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect,
77 get_string('participants'));
f9a0ea69 78
1242eb8f 79
7b07bc55 80 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=group&amp;filterselect='.$filterselect, get_string('blogs','blog'));
1242eb8f 81 }
f9a0ea69 82
1242eb8f 83 /**************************************
84 * User Level participation or Blogs *
85 **************************************/
86 } else {
87 if (isset($userid)) {
88 $user = get_record('user','id', $userid);
89 }
d02eeded 90 print_heading(fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))));
7077ca83 91
92 $toprow[] = new tabobject('profile', $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id, get_string('profile'));
f9a0ea69 93
b0c90e6e 94 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
e96f2a77 95 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
4b10f08b 96 $personalcontext = get_context_instance(CONTEXT_USER, $user->id);
4801fe93 97
1242eb8f 98 /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
99
ad6226fb 100 $mainadmin = get_admin();
56f52742 101
b0c90e6e 102 if(empty($CFG->loginhttps)) {
103 $wwwroot = $CFG->wwwroot;
104 } else {
105 $wwwroot = str_replace('http:','https:',$CFG->wwwroot);
106 }
107
108 $edittype = 'none';
1cb3da36 109 if (isguestuser($user)) {
110 // guest account can not be edited
111
112 } else if (is_mnet_remote_user($user)) {
56f52742 113 // cannot edit remote users
1242eb8f 114
1cb3da36 115 } else if (isguestuser() or !isloggedin()) {
116 // guests and not logged in can not edit own profile
117
b0c90e6e 118 } else if ($USER->id == $user->id) {
119 if (has_capability('moodle/user:update', $systemcontext)) {
120 $edittype = 'advanced';
1cb3da36 121 } else if (has_capability('moodle/user:editownprofile', $systemcontext)) {
b0c90e6e 122 $edittype = 'normal';
f3221af9 123 }
b0c90e6e 124
125 } else if ($user->id != $mainadmin->id) {
126 //no editing of primary admin!
127 if (has_capability('moodle/user:update', $systemcontext)) {
128 $edittype = 'advanced';
129 } else if (has_capability('moodle/user:editprofile', $personalcontext)) {
130 //teachers, parents, etc.
131 $edittype = 'normal';
ad6226fb 132 }
f9a0ea69 133 }
134
b0c90e6e 135 if ($edittype == 'advanced') {
136 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/editadvanced.php?id='.$user->id.'&amp;course='.$course->id, get_string('editmyprofile'));
137 } else if ($edittype == 'normal') {
138 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id.'&amp;course='.$course->id, get_string('editmyprofile'));
139 }
140
1242eb8f 141 /// Everyone can see posts for this user
b3e900ce 142
143 /// add logic to see course read posts permission
d78596d8 144 if (has_capability('moodle/user:readuserposts', $personalcontext) || has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_COURSE, $course->id))) {
b3e900ce 145 $toprow[] = new tabobject('forumposts', $CFG->wwwroot.'/mod/forum/user.php?id='.$user->id.'&amp;course='.$course->id,
146 get_string('forumposts', 'forum'));
1242eb8f 147
b3e900ce 148 if (in_array($currenttab, array('posts', 'discussions'))) {
149 $inactive = array('forumposts');
150 $activetwo = array('forumposts');
1242eb8f 151
b3e900ce 152 $secondrow = array();
153 $secondrow[] = new tabobject('posts', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
1242eb8f 154 '&amp;id='.$user->id.'&amp;mode=posts', get_string('posts', 'forum'));
b3e900ce 155 $secondrow[] = new tabobject('discussions', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
3f7353c5 156 '&amp;id='.$user->id.'&amp;mode=discussions', get_string('discussions', 'forum'));
b3e900ce 157 }
f9a0ea69 158
b3e900ce 159 }
e96f2a77 160
161 /// Personal blog entries tab
0c939d6c 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)
b0c90e6e 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))
0c939d6c 168 ) // able to read blogs in site or course context
169 ) { //end if
e96f2a77 170
171 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?userid='.$user->id.'&amp;courseid='.$course->id, get_string('blog', 'blog'));
1242eb8f 172 }
1242eb8f 173
eca3af25 174 if (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 . '&amp;user=' . $user->id, get_string('notes', 'notes'));
176 }
177
1242eb8f 178 /// Current user must be teacher of the course or the course allows user to view their reports
7e2d7c92 179
180 //print_object($course);
181 //print_object($user);
b3e900ce 182
183 // add in logic to check course read report
1845e470 184 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) || ($course->showreports and $USER->id == $user->id) || has_capability('moodle/user:viewuseractivitiesreport', $coursecontext)) {
1242eb8f 185
186 $toprow[] = new tabobject('reports', $CFG->wwwroot.'/course/user.php?id='.$course->id.
187 '&amp;user='.$user->id.'&amp;mode=outline', get_string('activityreports'));
188
7e2d7c92 189 if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) {
1242eb8f 190 $inactive = array('reports');
191 $activetwo = array('reports');
192
193 $secondrow = array();
194 $secondrow[] = new tabobject('outline', $CFG->wwwroot.'/course/user.php?id='.$course->id.
195 '&amp;user='.$user->id.'&amp;mode=outline', get_string('outlinereport'));
196 $secondrow[] = new tabobject('complete', $CFG->wwwroot.'/course/user.php?id='.$course->id.
197 '&amp;user='.$user->id.'&amp;mode=complete', get_string('completereport'));
198 $secondrow[] = new tabobject('todaylogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
199 '&amp;user='.$user->id.'&amp;mode=todaylogs', get_string('todaylogs'));
200 $secondrow[] = new tabobject('alllogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
201 '&amp;user='.$user->id.'&amp;mode=alllogs', get_string('alllogs'));
202 if (!empty($CFG->enablestats)) {
203 $secondrow[] = new tabobject('stats',$CFG->wwwroot.'/course/user.php?id='.$course->id.
204 '&amp;user='.$user->id.'&amp;mode=stats',get_string('stats'));
205 }
7e2d7c92 206
f9c471df 207 if ($course->showgrades) {
208 $secondrow[] = new tabobject('grade', $CFG->wwwroot.'/course/user.php?id='.$course->id.
7e2d7c92 209 '&amp;user='.$user->id.'&amp;mode=grade', get_string('grade'));
f9c471df 210 }
7e2d7c92 211
1242eb8f 212 }
213
214 }
215
216 } //close last bracket (individual tags)
217
7e2d7c92 218
219 /// this needs permission checkings
0a8a95c9 220
fcade7d0 221
222 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
223 $usercontext = get_context_instance(CONTEXT_USER, $user->id);
224 if (has_capability('moodle/role:assign',$usercontext)) {
225 $toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
226 ,get_string('roles'));
227
228 if (in_array($currenttab, array('assign', 'override'))) {
229 $inactive = array('roles');
230 $activetwo = array('roles');
231
232 $secondrow = array();
233 $secondrow[] = new tabobject('assign', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
234 ,get_string('assignroles', 'role'));
235 $secondrow[] = new tabobject('override', $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
236 ,get_string('overrideroles', 'role'));
237
238 }
0a8a95c9 239 }
240 }
f9a0ea69 241/// Add second row to display if there is one
242
243 if (!empty($secondrow)) {
244 $tabs = array($toprow, $secondrow);
245 } else {
246 $tabs = array($toprow);
247 }
248
f9a0ea69 249/// Print out the tabs and continue!
250
e1ddfa6b 251 print_tabs($tabs, $currenttab, $inactive, $activetwo);
f9a0ea69 252
253?>