MDL-19676 MDL-14408 MDL-8776 Blog improvements
[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
214b1cf7 5 require_once($CFG->libdir . '/portfoliolib.php');
6
1242eb8f 7 if (!isset($filtertype)) {
8 $filtertype = '';
9 }
10 if (!isset($filterselect)) {
11 $filterselect = '';
12 }
f9a0ea69 13
57f2e16c 14 //make sure everything is cleaned properly
15 $filtertype = clean_param($filtertype, PARAM_ALPHA);
16 $filterselect = clean_param($filterselect, PARAM_INT);
17
f9a0ea69 18 if (empty($currenttab) or empty($user) or empty($course)) {
4e244ba8 19 //print_error('cannotcallscript');
f9a0ea69 20 }
21
1242eb8f 22 if (($filtertype == 'site' && $filterselect) || ($filtertype=='user' && $filterselect)) {
ce8c75ee 23 $user = $DB->get_record('user', array('id'=>$filterselect));
1242eb8f 24 }
f9a0ea69 25
26 $inactive = NULL;
e1ddfa6b 27 $activetwo = NULL;
f9a0ea69 28 $toprow = array();
565b14d2 29 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
f9a0ea69 30
1c7b8b93
NC
31 /****************************
32 * Site Level participation *
33 ****************************/
1242eb8f 34 if ($filtertype == 'site') {
f9a0ea69 35
1242eb8f 36 $site = get_site();
8fa89bfd 37 echo $OUTPUT->heading(format_string($site->fullname));
2f6c662f 38
1c7b8b93
NC
39 /******************************
40 * Course Level participation *
41 ******************************/
1242eb8f 42 } else if ($filtertype == 'course' && $filterselect) {
f9a0ea69 43
ce8c75ee 44 $course = $DB->get_record('course', array('id'=>$filterselect));
eca3af25 45 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
8fa89bfd 46 echo $OUTPUT->heading(format_string($course->fullname));
f9a0ea69 47
ffc536af 48 $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$filterselect,
49 get_string('participants'));
2f6c662f 50
90658eef 51 if (!empty($CFG->enablenotes) and (has_capability('moodle/notes:manage', $coursecontext) || has_capability('moodle/notes:view', $coursecontext))) {
eca3af25 52 $toprow[] = new tabobject('notes', $CFG->wwwroot.'/notes/index.php?filtertype=course&amp;filterselect=' . $filterselect, get_string('notes', 'notes'));
53 }
54
1c7b8b93
NC
55 /*****************************
56 * Group Level participation *
57 *****************************/
1242eb8f 58 } else if ($filtertype == 'group' && $filterselect) {
f9a0ea69 59
ffc536af 60 $group_name = groups_get_group_name($filterselect);
8fa89bfd 61 echo $OUTPUT->heading($group_name);
f9a0ea69 62
f9a0ea69 63
1c7b8b93
NC
64 /****************************
65 * User Level participation *
66 ****************************/
1242eb8f 67 } else {
68 if (isset($userid)) {
ce8c75ee 69 $user = $DB->get_record('user', array('id'=>$userid));
1242eb8f 70 }
8fa89bfd 71 echo $OUTPUT->heading(fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))));
7077ca83 72
e96f2a77 73 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
4b10f08b 74 $personalcontext = get_context_instance(CONTEXT_USER, $user->id);
4801fe93 75
95a5e161 76 if ($user->id == $USER->id || has_capability('moodle/user:viewdetails', $coursecontext) || has_capability('moodle/user:viewdetails', $personalcontext) ) {
31759089 77 $toprow[] = new tabobject('profile', $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id, get_string('viewprofile'));
62193086 78 }
79
1242eb8f 80
fc4b2dec 81 /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
56f52742 82
b0c90e6e 83 if(empty($CFG->loginhttps)) {
84 $wwwroot = $CFG->wwwroot;
85 } else {
86 $wwwroot = str_replace('http:','https:',$CFG->wwwroot);
87 }
88
1242eb8f 89 /// Everyone can see posts for this user
2f6c662f 90
b3e900ce 91 /// add logic to see course read posts permission
d78596d8 92 if (has_capability('moodle/user:readuserposts', $personalcontext) || has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_COURSE, $course->id))) {
b3e900ce 93 $toprow[] = new tabobject('forumposts', $CFG->wwwroot.'/mod/forum/user.php?id='.$user->id.'&amp;course='.$course->id,
94 get_string('forumposts', 'forum'));
1242eb8f 95
b3e900ce 96 if (in_array($currenttab, array('posts', 'discussions'))) {
97 $inactive = array('forumposts');
98 $activetwo = array('forumposts');
1242eb8f 99
b3e900ce 100 $secondrow = array();
101 $secondrow[] = new tabobject('posts', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
1242eb8f 102 '&amp;id='.$user->id.'&amp;mode=posts', get_string('posts', 'forum'));
b3e900ce 103 $secondrow[] = new tabobject('discussions', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
3f7353c5 104 '&amp;id='.$user->id.'&amp;mode=discussions', get_string('discussions', 'forum'));
b3e900ce 105 }
f9a0ea69 106
b3e900ce 107 }
e96f2a77 108
90658eef 109 if (!empty($CFG->enablenotes) and (has_capability('moodle/notes:manage', $coursecontext) || has_capability('moodle/notes:view', $coursecontext))) {
eca3af25 110 $toprow[] = new tabobject('notes', $CFG->wwwroot.'/notes/index.php?course='.$course->id . '&amp;user=' . $user->id, get_string('notes', 'notes'));
111 }
112
358e2a0b 113 /// Find out if user allowed to see all reports of this user (usually parent) or individual course reports
2f6c662f 114
358e2a0b 115 $myreports = ($course->showreports and $USER->id == $user->id);
116 $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
2f6c662f 117
595a6f22 118 $reportsecondrow = array();
1242eb8f 119
358e2a0b 120 if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
595a6f22 121 $reportsecondrow[] = new tabobject('outline', $CFG->wwwroot.'/course/user.php?id='.$course->id.
358e2a0b 122 '&amp;user='.$user->id.'&amp;mode=outline', get_string('outlinereport'));
123 }
1242eb8f 124
358e2a0b 125 if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
595a6f22 126 $reportsecondrow[] = new tabobject('complete', $CFG->wwwroot.'/course/user.php?id='.$course->id.
358e2a0b 127 '&amp;user='.$user->id.'&amp;mode=complete', get_string('completereport'));
128 }
1242eb8f 129
358e2a0b 130 if ($myreports or $anyreport or has_capability('coursereport/log:viewtoday', $coursecontext)) {
595a6f22 131 $reportsecondrow[] = new tabobject('todaylogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
358e2a0b 132 '&amp;user='.$user->id.'&amp;mode=todaylogs', get_string('todaylogs'));
133 }
134
135 if ($myreports or $anyreport or has_capability('coursereport/log:view', $coursecontext)) {
595a6f22 136 $reportsecondrow[] = new tabobject('alllogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
358e2a0b 137 '&amp;user='.$user->id.'&amp;mode=alllogs', get_string('alllogs'));
138 }
2f6c662f 139
358e2a0b 140 if (!empty($CFG->enablestats)) {
141 if ($myreports or $anyreport or has_capability('coursereport/stats:view', $coursecontext)) {
595a6f22 142 $reportsecondrow[] = new tabobject('stats',$CFG->wwwroot.'/course/user.php?id='.$course->id.
358e2a0b 143 '&amp;user='.$user->id.'&amp;mode=stats',get_string('stats'));
1242eb8f 144 }
358e2a0b 145 }
146
147 if (has_capability('moodle/grade:viewall', $coursecontext)) {
148 //ok - can view all course grades
149 $gradeaccess = true;
1242eb8f 150
358e2a0b 151 } else if ($course->showgrades and $user->id == $USER->id and has_capability('moodle/grade:view', $coursecontext)) {
152 //ok - can view own grades
153 $gradeaccess = true;
154
155 } else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) {
156 // ok - can view grades of this user - parent most probably
157 $gradeaccess = true;
158
3c7da16d 159 } else if ($course->showgrades and $anyreport) {
160 // ok - can view grades of this user - parent most probably
161 $gradeaccess = true;
162
358e2a0b 163 } else {
164 $gradeaccess = false;
1242eb8f 165 }
166
358e2a0b 167 if ($gradeaccess) {
595a6f22 168 $reportsecondrow[] = new tabobject('grade', $CFG->wwwroot.'/course/user.php?id='.$course->id.
358e2a0b 169 '&amp;user='.$user->id.'&amp;mode=grade', get_string('grade'));
170 }
171
595a6f22 172 if ($reportsecondrow) {
358e2a0b 173 $toprow[] = new tabobject('reports', $CFG->wwwroot.'/course/user.php?id='.$course->id.
174 '&amp;user='.$user->id.'&amp;mode=outline', get_string('activityreports'));
175 if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) {
176 $inactive = array('reports');
177 $activetwo = array('reports');
595a6f22 178 $secondrow = $reportsecondrow;
358e2a0b 179 }
180 }
1242eb8f 181 } //close last bracket (individual tags)
182
19add4c0 183 // Repository Tab
8bde1611 184 if (!empty($user) and $user->id == $USER->id) {
19add4c0 185 require_once($CFG->dirroot . '/repository/lib.php');
12c79bfd 186 $usercontext = get_context_instance(CONTEXT_USER,$user->id);
dbc01944 187 $editabletypes = repository::get_editable_types($usercontext);
8bde1611 188 if (!empty($usercontext) && $usercontext->contextlevel == CONTEXT_USER && !empty($editabletypes)) {
12c79bfd 189 $toprow[] = new tabobject('repositories', $CFG->wwwroot .'/repository/manage_instances.php?contextid='.$usercontext->id, get_string('repositories', 'repository'));
6c91ce49 190 }
95a5e161 191
3b120e46 192 }
193
f9a0ea69 194/// Add second row to display if there is one
195
196 if (!empty($secondrow)) {
197 $tabs = array($toprow, $secondrow);
198 } else {
199 $tabs = array($toprow);
200 }
201
95a5e161 202 if ($currenttab == 'editprofile' && ($user->id == $USER->id) && user_not_fully_set_up($USER)) {
f2dcd845 203 /// We're being forced here to fix profile
3aac07d8 204 echo $OUTPUT->notification(get_string('moreprofileinfoneeded'));
f2dcd845 205 } else {
206 /// Print out the tabs and continue!
207 print_tabs($tabs, $currenttab, $inactive, $activetwo);
208 }
f9a0ea69 209
210?>