0299c007e8ff2d5b9745d890d61b391688259e25
[moodle.git] / user / tabs.php
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
5     if (!isset($filtertype)) {
6         $filtertype = '';
7     }
8     if (!isset($filterselect)) {
9         $filterselect = '';
10     }
12     //make sure everything is cleaned properly
13     $filtertype   = clean_param($filtertype, PARAM_ALPHA);
14     $filterselect = clean_param($filterselect, PARAM_INT);
16     if (empty($currenttab) or empty($user) or empty($course)) {
17         //error('You cannot call this script in that way');
18     }
20     if (($filtertype == 'site' && $filterselect) || ($filtertype=='user' && $filterselect)) {
21         $user = get_record('user','id',$filterselect);
22     }
24     $inactive = NULL;
25     $activetwo = NULL;
26     $toprow = array();
28     /**************************************
29      * Site Level participation or Blogs  *
30      **************************************/
31     if ($filtertype == 'site') {
33         $site = get_site();
34         print_heading($site->fullname);
35         
36         if ($CFG->bloglevel >= 4) {
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             }
44             $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=site&amp;',
45                 get_string('blogs','blog'));
46         }
48     /**************************************
49      * Course Level participation or Blogs  *
50      **************************************/
51     } else if ($filtertype == 'course' && $filterselect) {
53         $course = get_record('course','id',$filterselect);
54         print_heading($course->fullname);
56         if ($CFG->bloglevel >= 3) {
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         
61             $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=course&amp;filterselect='.$filterselect, get_string('blogs','blog'));
62         }
64     /**************************************
65      * Group Level participation or Blogs  *
66      **************************************/
67     } else if ($filtertype == 'group' && $filterselect) {
69         $group = get_record('groups','id',$filterselect);
70         print_heading($group->name);
72         if ($CFG->bloglevel >= 2) {
74             $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$filterselect,
75                 get_string('participants'));
77         
78             $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=group&amp;filterselect='.$filterselect, get_string('blogs','blog'));
79         }
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, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))));
90         $toprow[] = new tabobject('profile', $CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id, get_string('profile'));
92         $personalcontext = get_context_instance(CONTEXT_USERID, $user->id);
93     /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin
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)) ) {
101             if(empty($CFG->loginhttps)) {
102                 $wwwroot = $CFG->wwwroot;
103             } else {
104                 $wwwroot = str_replace('http:','https:',$CFG->wwwroot);
105             }
107             $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id.'&amp;course='.$course->id, get_string('editmyprofile'));
108         }
110     /// Everyone can see posts for this user
111     
112     /// add logic to see course read posts permission
113         if (has_capability('moodle/user:readuserposts', $personalcontext) || has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_COURSE, $courseid))) {
114             $toprow[] = new tabobject('forumposts', $CFG->wwwroot.'/mod/forum/user.php?id='.$user->id.'&amp;course='.$course->id,
115                         get_string('forumposts', 'forum'));
117             if (in_array($currenttab, array('posts', 'discussions'))) {
118                 $inactive = array('forumposts');
119                 $activetwo = array('forumposts');
121                 $secondrow = array();
122                 $secondrow[] = new tabobject('posts', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
123                                       '&amp;id='.$user->id.'&amp;mode=posts', get_string('posts', 'forum'));
124                 $secondrow[] = new tabobject('discussions', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id.
125                                       '&amp;id='.$user->id.'&amp;mode=discussions', get_string('discussions', 'forum'));
126             }
128         }
129     /// Blog entry, everyone can view
130         if ($CFG->bloglevel > 0 && has_capability('moodle/user:readuserblogs')) { // only if blog is enabled. Permission check kicks in when display list
131             $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?userid='.$user->id.'&amp;courseid='.$course->id, get_string('blogs', 'blog'));
132         }
133         
135     /// Current user must be teacher of the course or the course allows user to view their reports
136     
137     //print_object($course);
138     //print_object($user);
139     
140         // add in logic to check course read report
141         if (has_capability('moodle/user:viewactivitiesreport', $personalcontext) || ($course->showreports and $USER->id == $user->id)) {
143             $toprow[] = new tabobject('reports', $CFG->wwwroot.'/course/user.php?id='.$course->id.
144                                       '&amp;user='.$user->id.'&amp;mode=outline', get_string('activityreports'));
146             if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) {
147                 $inactive = array('reports');
148                 $activetwo = array('reports');
150                 $secondrow = array();
151                 $secondrow[] = new tabobject('outline', $CFG->wwwroot.'/course/user.php?id='.$course->id.
152                                           '&amp;user='.$user->id.'&amp;mode=outline', get_string('outlinereport'));
153                 $secondrow[] = new tabobject('complete', $CFG->wwwroot.'/course/user.php?id='.$course->id.
154                                           '&amp;user='.$user->id.'&amp;mode=complete', get_string('completereport'));
155                 $secondrow[] = new tabobject('todaylogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
156                                           '&amp;user='.$user->id.'&amp;mode=todaylogs', get_string('todaylogs'));
157                 $secondrow[] = new tabobject('alllogs', $CFG->wwwroot.'/course/user.php?id='.$course->id.
158                                           '&amp;user='.$user->id.'&amp;mode=alllogs', get_string('alllogs'));
159                 if (!empty($CFG->enablestats)) {
160                     $secondrow[] = new tabobject('stats',$CFG->wwwroot.'/course/user.php?id='.$course->id.
161                                                  '&amp;user='.$user->id.'&amp;mode=stats',get_string('stats'));
162                 }
163                 
164                 // needs permission checking!!!
165                 
166                 $secondrow[] = new tabobject('grade', $CFG->wwwroot.'/course/user.php?id='.$course->id.
167                                           '&amp;user='.$user->id.'&amp;mode=grade', get_string('grade'));
168                                 
169             }
171         }
173     }    //close last bracket (individual tags)
176     /// this needs permission checkings
178     if (!empty($showroles)) { // this variable controls whether this roles is showed, or not, so only user/view page should set this flag
179         $usercontext = get_context_instance(CONTEXT_USERID, $user->id);
180         $toprow[] = new tabobject('roles', $CFG->wwwroot.'/admin/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
181                               ,get_string('roles'));
182                               
183         if (in_array($currenttab, array('assign', 'override'))) {
184             $inactive = array('roles');
185             $activetwo = array('roles');
187             $secondrow = array();
188             $secondrow[] = new tabobject('assign', $CFG->wwwroot.'/admin/roles/assign.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
189                               ,get_string('assignroles', 'role'));
190             $secondrow[] = new tabobject('override', $CFG->wwwroot.'/admin/roles/override.php?contextid='.$usercontext->id.'&amp;userid='.$user->id.'&amp;courseid='.$course->id
191                               ,get_string('overrideroles', 'role'));
192                                 
193         }                                                                                                       
194     }
195 /// Add second row to display if there is one
197     if (!empty($secondrow)) {
198         $tabs = array($toprow, $secondrow);
199     } else {
200         $tabs = array($toprow);
201     }
203 /// Print out the tabs and continue!
205     print_tabs($tabs, $currenttab, $inactive, $activetwo);
207 ?>