glossary tabs (when updating a glossary) is not aligned properly MDL-7172 ; merged...
[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();
34 print_heading($site->fullname);
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);
52 print_heading($course->fullname);
f9a0ea69 53
1242eb8f 54 if ($CFG->bloglevel >= 3) {
55
56 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$filterselect.'&amp;group=0',
57 get_string('participants')); //the groupid hack is necessary, otherwise the group in the session willbe used
58
7b07bc55 59 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=course&amp;filterselect='.$filterselect, get_string('blogs','blog'));
f9a0ea69 60 }
f9a0ea69 61
1242eb8f 62 /**************************************
63 * Group Level participation or Blogs *
64 **************************************/
65 } else if ($filtertype == 'group' && $filterselect) {
f9a0ea69 66
1242eb8f 67 $group = get_record('groups','id',$filterselect);
68 print_heading($group->name);
f9a0ea69 69
1242eb8f 70 if ($CFG->bloglevel >= 2) {
f9a0ea69 71
1242eb8f 72 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect,
73 get_string('participants'));
f9a0ea69 74
1242eb8f 75
7b07bc55 76 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=group&amp;filterselect='.$filterselect, get_string('blogs','blog'));
1242eb8f 77 }
f9a0ea69 78
1242eb8f 79 /**************************************
80 * User Level participation or Blogs *
81 **************************************/
82 } else {
83 if (isset($userid)) {
84 $user = get_record('user','id', $userid);
85 }
d02eeded 86 print_heading(fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))));
7077ca83 87
88 $toprow[] = new tabobject('profile', $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id, get_string('profile'));
f9a0ea69 89
e96f2a77 90 $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
91 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
4b10f08b 92 $personalcontext = get_context_instance(CONTEXT_USER, $user->id);
4801fe93 93
1242eb8f 94 /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
95
96 if (($mainadmin = get_admin()) === false) {
97 $mainadmin->id = 0; /// Weird - no primary admin!
98 }
99 if ((!empty($USER->id) and ($USER->id == $user->id) and !isguest()) or
e96f2a77 100 (has_capability('moodle/user:editprofile', $personalcontext) and ($user->id != $mainadmin->id)) ) {
1242eb8f 101
102 if(empty($CFG->loginhttps)) {
103 $wwwroot = $CFG->wwwroot;
104 } else {
2c3432e6 105 $wwwroot = str_replace('http:','https:',$CFG->wwwroot);
f3221af9 106 }
7077ca83 107
108 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id.'&amp;course='.$course->id, get_string('editmyprofile'));
f9a0ea69 109 }
110
1242eb8f 111 /// Everyone can see posts for this user
b3e900ce 112
113 /// add logic to see course read posts permission
d78596d8 114 if (has_capability('moodle/user:readuserposts', $personalcontext) || has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_COURSE, $course->id))) {
b3e900ce 115 $toprow[] = new tabobject('forumposts', $CFG->wwwroot.'/mod/forum/user.php?id='.$user->id.'&amp;course='.$course->id,
116 get_string('forumposts', 'forum'));
1242eb8f 117
b3e900ce 118 if (in_array($currenttab, array('posts', 'discussions'))) {
119 $inactive = array('forumposts');
120 $activetwo = array('forumposts');
1242eb8f 121
b3e900ce 122 $secondrow = array();
123 $secondrow[] = new tabobject('posts', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
1242eb8f 124 '&amp;id='.$user->id.'&amp;mode=posts', get_string('posts', 'forum'));
b3e900ce 125 $secondrow[] = new tabobject('discussions', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
1242eb8f 126 '&amp;id='.$user->id.'&amp;mode=discussions', get_string('discussions', 'forum'));
b3e900ce 127 }
f9a0ea69 128
b3e900ce 129 }
e96f2a77 130
131 /// Personal blog entries tab
132 if ($CFG->bloglevel > 0
133 and (has_capability('moodle/user:readuserblogs', $personalcontext) // can review students posts
134 or has_capability('moodle/blog:manageentries', $sitecontext) // entry manager can see all posts
135 or ($user->id == $USER->id and has_capability('moodle/blog:create', $sitecontext)) // viewing self
136 or ($CFG->bloglevel > 1 and has_capability('moodle/blog:create', $sitecontext, $user->id) and (has_capability('moodle/blog:view', $sitecontext) or has_capability('moodle/blog:view', $coursecontext)))
137 )) {
138
139 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?userid='.$user->id.'&amp;courseid='.$course->id, get_string('blog', 'blog'));
1242eb8f 140 }
1242eb8f 141
142 /// Current user must be teacher of the course or the course allows user to view their reports
7e2d7c92 143
144 //print_object($course);
145 //print_object($user);
b3e900ce 146
147 // add in logic to check course read report
0c05b71f 148 if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) || ($course->showreports and $USER->id == $user->id)) {
1242eb8f 149
150 $toprow[] = new tabobject('reports', $CFG->wwwroot.'/course/user.php?id='.$course->id.
151 '&amp;user='.$user->id.'&amp;mode=outline', get_string('activityreports'));
152
7e2d7c92 153 if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) {
1242eb8f 154 $inactive = array('reports');
155 $activetwo = array('reports');
156
157 $secondrow = array();
158 $secondrow[] = new tabobject('outline', $CFG->wwwroot.'/course/user.php?id='.$course->id.
159 '&amp;user='.$user->id.'&amp;mode=outline', get_string('outlinereport'));
160 $secondrow[] = new tabobject('complete', $CFG->wwwroot.'/course/user.php?id='.$course->id.
161 '&amp;user='.$user->id.'&amp;mode=complete', get_string('completereport'));
162 $secondrow[] = new tabobject('todaylogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
163 '&amp;user='.$user->id.'&amp;mode=todaylogs', get_string('todaylogs'));
164 $secondrow[] = new tabobject('alllogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
165 '&amp;user='.$user->id.'&amp;mode=alllogs', get_string('alllogs'));
166 if (!empty($CFG->enablestats)) {
167 $secondrow[] = new tabobject('stats',$CFG->wwwroot.'/course/user.php?id='.$course->id.
168 '&amp;user='.$user->id.'&amp;mode=stats',get_string('stats'));
169 }
7e2d7c92 170
171 // needs permission checking!!!
172
173 $secondrow[] = new tabobject('grade', $CFG->wwwroot.'/course/user.php?id='.$course->id.
174 '&amp;user='.$user->id.'&amp;mode=grade', get_string('grade'));
175
1242eb8f 176 }
177
178 }
179
180 } //close last bracket (individual tags)
181
7e2d7c92 182
183 /// this needs permission checkings
0a8a95c9 184
e2a305ff 185 $usercontext = get_context_instance(CONTEXT_USER, $user->id);
20374d72 186 if (!empty($showroles) && has_capability('moodle/role:assign',$usercontext)) { // this variable controls whether this roles is showed, or not, so only user/view page should set this flag
6859360c 187 $toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
7e2d7c92 188 ,get_string('roles'));
0a8a95c9 189
190 if (in_array($currenttab, array('assign', 'override'))) {
191 $inactive = array('roles');
192 $activetwo = array('roles');
7e2d7c92 193
0a8a95c9 194 $secondrow = array();
6859360c 195 $secondrow[] = new tabobject('assign', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
b3e900ce 196 ,get_string('assignroles', 'role'));
6859360c 197 $secondrow[] = new tabobject('override', $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
b3e900ce 198 ,get_string('overrideroles', 'role'));
0a8a95c9 199
200 }
201 }
f9a0ea69 202/// Add second row to display if there is one
203
204 if (!empty($secondrow)) {
205 $tabs = array($toprow, $secondrow);
206 } else {
207 $tabs = array($toprow);
208 }
209
f9a0ea69 210/// Print out the tabs and continue!
211
e1ddfa6b 212 print_tabs($tabs, $currenttab, $inactive, $activetwo);
f9a0ea69 213
214?>