New user tabs from Shane and myself ... these bring together the
[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
5
6 if (empty($currenttab) or empty($user) or empty($course)) {
7 error('You cannot call this script in that way');
8 }
9
10 print_heading(fullname($user, isteacher($course)));
11
12//if (!empty($USER) and (isteacher($course->id) or (($USER->id == $user->id) and !isguest()))) { // tabs are shown
13
14 $inactive = NULL;
15 $toprow = array();
16
17 $toprow[] = new tabobject('profile', $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id,
18 get_string('profile'));
19
20
21
22/// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
23
24 if (($mainadmin = get_admin()) === false) {
25 $mainadmin->id = 0; /// Weird - no primary admin!
26 }
27 if ((!empty($USER->id) and ($USER->id == $user->id) and !isguest()) or
28 (isadmin() and ($user->id != $mainadmin->id)) ) {
29
30 if(empty($CFG->loginhttps)) {
31 $wwwroot = $CFG->wwwroot;
32 } else {
33 $wwwroot = str_replace('http','https',$CFG->wwwroot);
34 }
35 $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id.'&amp;course='.$course->id,
36 get_string('editmyprofile'));
37 }
38
39
40/// Everyone can see posts for this user
41
42 $toprow[] = new tabobject('forumposts', $CFG->wwwroot.'/mod/forum/user.php?id='.$user->id.'&amp;course='.$course->id,
43 get_string('forumposts', 'forum'));
44
45 if (in_array($currenttab, array('posts', 'discussions'))) {
46 $inactive = array('forumposts');
47
48 $secondrow = array();
49 $secondrow[] = new tabobject('posts', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
50 '&amp;id='.$user->id.'&amp;mode=posts', get_string('posts', 'forum'));
51 $secondrow[] = new tabobject('discussions', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
52 '&amp;id='.$user->id.'&amp;mode=discussions', get_string('discussions', 'forum'));
53 }
54
55
56/// Current user must be teacher of the course or the course allows user to view their reports
57 if (isteacher($course->id) or ($course->showreports and $USER->id == $user->id)) {
58
59 $toprow[] = new tabobject('reports', $CFG->wwwroot.'/course/user.php?id='.$course->id.
60 '&amp;user='.$user->id.'&amp;mode=outline', get_string('activityreports'));
61
62 if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs'))) {
63 $inactive = array('reports');
64
65 $secondrow = array();
66 $secondrow[] = new tabobject('outline', $CFG->wwwroot.'/course/user.php?id='.$course->id.
67 '&amp;user='.$user->id.'&amp;mode=outline', get_string('outlinereport'));
68 $secondrow[] = new tabobject('complete', $CFG->wwwroot.'/course/user.php?id='.$course->id.
69 '&amp;user='.$user->id.'&amp;mode=complete', get_string('completereport'));
70 $secondrow[] = new tabobject('todaylogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
71 '&amp;user='.$user->id.'&amp;mode=todaylogs', get_string('todaylogs'));
72 $secondrow[] = new tabobject('alllogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
73 '&amp;user='.$user->id.'&amp;mode=alllogs', get_string('alllogs'));
74 }
75
76 }
77
78
79/// Add second row to display if there is one
80
81 if (!empty($secondrow)) {
82 $tabs = array($toprow, $secondrow);
83 } else {
84 $tabs = array($toprow);
85 }
86
87
88/// Print out the tabs and continue!
89
90 print_tabs($tabs, $currenttab, $inactive);
91
92?>