Updated to use new Roles System. Plus some fixes.
[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) {
adc7b679 37 if (isteacher(SITEID) ||
38 ($CFG->showsiteparticipants == 1 && isteacherinanycourse()) ||
39 ($CFG->showsiteparticipantslist == 2)) {
40 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.SITEID,
41 get_string('participants'));
42 }
f9a0ea69 43
1242eb8f 44 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=site&amp;',
7b07bc55 45 get_string('blogs','blog'));
1242eb8f 46 }
f9a0ea69 47
1242eb8f 48 /**************************************
49 * Course Level participation or Blogs *
50 **************************************/
51 } else if ($filtertype == 'course' && $filterselect) {
f9a0ea69 52
1242eb8f 53 $course = get_record('course','id',$filterselect);
54 print_heading($course->fullname);
f9a0ea69 55
1242eb8f 56 if ($CFG->bloglevel >= 3) {
57
58 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$filterselect.'&amp;group=0',
59 get_string('participants')); //the groupid hack is necessary, otherwise the group in the session willbe used
60
7b07bc55 61 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=course&amp;filterselect='.$filterselect, get_string('blogs','blog'));
f9a0ea69 62 }
f9a0ea69 63
1242eb8f 64 /**************************************
65 * Group Level participation or Blogs *
66 **************************************/
67 } else if ($filtertype == 'group' && $filterselect) {
f9a0ea69 68
1242eb8f 69 $group = get_record('groups','id',$filterselect);
70 print_heading($group->name);
f9a0ea69 71
1242eb8f 72 if ($CFG->bloglevel >= 2) {
f9a0ea69 73
1242eb8f 74 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect,
75 get_string('participants'));
f9a0ea69 76
1242eb8f 77
7b07bc55 78 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=group&amp;filterselect='.$filterselect, get_string('blogs','blog'));
1242eb8f 79 }
f9a0ea69 80
1242eb8f 81 /**************************************
82 * User Level participation or Blogs *
83 **************************************/
84 } else {
85 if (isset($userid)) {
86 $user = get_record('user','id', $userid);
87 }
88 print_heading(fullname($user, isteacher($course->id)));
7077ca83 89
90 $toprow[] = new tabobject('profile', $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id, get_string('profile'));
f9a0ea69 91
f9a0ea69 92
1242eb8f 93 /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
94
95 if (($mainadmin = get_admin()) === false) {
96 $mainadmin->id = 0; /// Weird - no primary admin!
97 }
98 if ((!empty($USER->id) and ($USER->id == $user->id) and !isguest()) or
99 (isadmin() and ($user->id != $mainadmin->id)) ) {
100
101 if(empty($CFG->loginhttps)) {
102 $wwwroot = $CFG->wwwroot;
103 } else {
2c3432e6 104 $wwwroot = str_replace('http:','https:',$CFG->wwwroot);
f3221af9 105 }
7077ca83 106
107 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id.'&amp;course='.$course->id, get_string('editmyprofile'));
f9a0ea69 108 }
109
1242eb8f 110
111 /// Everyone can see posts for this user
112
113 $toprow[] = new tabobject('forumposts', $CFG->wwwroot.'/mod/forum/user.php?id='.$user->id.'&amp;course='.$course->id,
114 get_string('forumposts', 'forum'));
115
116 if (in_array($currenttab, array('posts', 'discussions'))) {
117 $inactive = array('forumposts');
118 $activetwo = array('forumposts');
119
120 $secondrow = array();
121 $secondrow[] = new tabobject('posts', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
122 '&amp;id='.$user->id.'&amp;mode=posts', get_string('posts', 'forum'));
123 $secondrow[] = new tabobject('discussions', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
124 '&amp;id='.$user->id.'&amp;mode=discussions', get_string('discussions', 'forum'));
125 }
f9a0ea69 126
127
1242eb8f 128 /// Blog entry, everyone can view
cc841d67 129 if ($CFG->bloglevel > 0) { // only if blog is enabled. Permission check kicks in when display list
1242eb8f 130 $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?userid='.$user->id.'&amp;courseid='.$course->id, get_string('blogs', 'blog'));
131 }
132
133
134 /// Current user must be teacher of the course or the course allows user to view their reports
7e2d7c92 135
136 //print_object($course);
137 //print_object($user);
1242eb8f 138 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
139
140 $toprow[] = new tabobject('reports', $CFG->wwwroot.'/course/user.php?id='.$course->id.
141 '&amp;user='.$user->id.'&amp;mode=outline', get_string('activityreports'));
142
7e2d7c92 143 if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) {
1242eb8f 144 $inactive = array('reports');
145 $activetwo = array('reports');
146
147 $secondrow = array();
148 $secondrow[] = new tabobject('outline', $CFG->wwwroot.'/course/user.php?id='.$course->id.
149 '&amp;user='.$user->id.'&amp;mode=outline', get_string('outlinereport'));
150 $secondrow[] = new tabobject('complete', $CFG->wwwroot.'/course/user.php?id='.$course->id.
151 '&amp;user='.$user->id.'&amp;mode=complete', get_string('completereport'));
152 $secondrow[] = new tabobject('todaylogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
153 '&amp;user='.$user->id.'&amp;mode=todaylogs', get_string('todaylogs'));
154 $secondrow[] = new tabobject('alllogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
155 '&amp;user='.$user->id.'&amp;mode=alllogs', get_string('alllogs'));
156 if (!empty($CFG->enablestats)) {
157 $secondrow[] = new tabobject('stats',$CFG->wwwroot.'/course/user.php?id='.$course->id.
158 '&amp;user='.$user->id.'&amp;mode=stats',get_string('stats'));
159 }
7e2d7c92 160
161 // needs permission checking!!!
162
163 $secondrow[] = new tabobject('grade', $CFG->wwwroot.'/course/user.php?id='.$course->id.
164 '&amp;user='.$user->id.'&amp;mode=grade', get_string('grade'));
165
1242eb8f 166 }
167
168 }
169
170 } //close last bracket (individual tags)
171
7e2d7c92 172
173 /// this needs permission checkings
0a8a95c9 174
175 if (!empty($showroles)) { // this variable controls whether this roles is showed, or not, so only user/view page should set this flag
176 $usercontext = get_context_instance(CONTEXT_USERID, $user->id);
177 $toprow[] = new tabobject('roles', $CFG->wwwroot.'/admin/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
7e2d7c92 178 ,get_string('roles'));
0a8a95c9 179
180 if (in_array($currenttab, array('assign', 'override'))) {
181 $inactive = array('roles');
182 $activetwo = array('roles');
7e2d7c92 183
0a8a95c9 184 $secondrow = array();
185 $secondrow[] = new tabobject('assign', $CFG->wwwroot.'/admin/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
186 ,get_string('assign'));
187 $secondrow[] = new tabobject('override', $CFG->wwwroot.'/admin/roles/override.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
188 ,get_string('override'));
189
190 }
191 }
f9a0ea69 192/// Add second row to display if there is one
193
194 if (!empty($secondrow)) {
195 $tabs = array($toprow, $secondrow);
196 } else {
197 $tabs = array($toprow);
198 }
199
f9a0ea69 200/// Print out the tabs and continue!
201
e1ddfa6b 202 print_tabs($tabs, $currenttab, $inactive, $activetwo);
f9a0ea69 203
204?>