Commit | Line | Data |
---|---|---|
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(); |
6ba65fa0 | 34 | print_heading(format_string($site->fullname)); |
1242eb8f | 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&', |
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); |
6ba65fa0 | 52 | print_heading(format_string($course->fullname)); |
f9a0ea69 | 53 | |
1242eb8f | 54 | if ($CFG->bloglevel >= 3) { |
55 | ||
56 | $toprow[] = new tabobject('participants', $CFG->wwwroot.'/user/index.php?id='.$filterselect.'&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&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 | |
f3f7610c ML |
67 | $group_name = groups_get_group_name($filterselect); //TODO: |
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.'&group='.$filterselect, |
73 | get_string('participants')); | |
f9a0ea69 | 74 | |
1242eb8f | 75 | |
7b07bc55 | 76 | $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?filtertype=group&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.'&course='.$course->id, get_string('profile')); | |
f9a0ea69 | 89 | |
b0c90e6e | 90 | $systemcontext = get_context_instance(CONTEXT_SYSTEM); |
e96f2a77 | 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 | ||
ad6226fb | 96 | $mainadmin = get_admin(); |
56f52742 | 97 | |
b0c90e6e | 98 | if(empty($CFG->loginhttps)) { |
99 | $wwwroot = $CFG->wwwroot; | |
100 | } else { | |
101 | $wwwroot = str_replace('http:','https:',$CFG->wwwroot); | |
102 | } | |
103 | ||
104 | $edittype = 'none'; | |
56f52742 | 105 | if (is_mnet_remote_user($user)) { |
106 | // cannot edit remote users | |
1242eb8f | 107 | |
b0c90e6e | 108 | } else if (isguest() or !isloggedin()) { |
109 | // can not edit guest like accounts - TODO: add capability to edit own profile | |
110 | ||
111 | } else if ($USER->id == $user->id) { | |
112 | if (has_capability('moodle/user:update', $systemcontext)) { | |
113 | $edittype = 'advanced'; | |
1242eb8f | 114 | } else { |
b0c90e6e | 115 | $edittype = 'normal'; |
f3221af9 | 116 | } |
b0c90e6e | 117 | |
118 | } else if ($user->id != $mainadmin->id) { | |
119 | //no editing of primary admin! | |
120 | if (has_capability('moodle/user:update', $systemcontext)) { | |
121 | $edittype = 'advanced'; | |
122 | } else if (has_capability('moodle/user:editprofile', $personalcontext)) { | |
123 | //teachers, parents, etc. | |
124 | $edittype = 'normal'; | |
ad6226fb | 125 | } |
f9a0ea69 | 126 | } |
127 | ||
b0c90e6e | 128 | if ($edittype == 'advanced') { |
129 | $toprow[] = new tabobject('editprofile', $wwwroot.'/user/editadvanced.php?id='.$user->id.'&course='.$course->id, get_string('editmyprofile')); | |
130 | } else if ($edittype == 'normal') { | |
131 | $toprow[] = new tabobject('editprofile', $wwwroot.'/user/edit.php?id='.$user->id.'&course='.$course->id, get_string('editmyprofile')); | |
132 | } | |
133 | ||
1242eb8f | 134 | /// Everyone can see posts for this user |
b3e900ce | 135 | |
136 | /// add logic to see course read posts permission | |
d78596d8 | 137 | if (has_capability('moodle/user:readuserposts', $personalcontext) || has_capability('mod/forum:viewdiscussion', get_context_instance(CONTEXT_COURSE, $course->id))) { |
b3e900ce | 138 | $toprow[] = new tabobject('forumposts', $CFG->wwwroot.'/mod/forum/user.php?id='.$user->id.'&course='.$course->id, |
139 | get_string('forumposts', 'forum')); | |
1242eb8f | 140 | |
b3e900ce | 141 | if (in_array($currenttab, array('posts', 'discussions'))) { |
142 | $inactive = array('forumposts'); | |
143 | $activetwo = array('forumposts'); | |
1242eb8f | 144 | |
b3e900ce | 145 | $secondrow = array(); |
146 | $secondrow[] = new tabobject('posts', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id. | |
1242eb8f | 147 | '&id='.$user->id.'&mode=posts', get_string('posts', 'forum')); |
b3e900ce | 148 | $secondrow[] = new tabobject('discussions', $CFG->wwwroot.'/mod/forum/user.php?course='.$course->id. |
aa91a2f2 | 149 | '&id='.$user->id.'&mode=discussions', get_string('discussionsstartedby', 'forum')); |
b3e900ce | 150 | } |
f9a0ea69 | 151 | |
b3e900ce | 152 | } |
e96f2a77 | 153 | |
154 | /// Personal blog entries tab | |
0c939d6c | 155 | require_once($CFG->dirroot.'/blog/lib.php'); |
156 | if ($CFG->bloglevel >= BLOG_USER_LEVEL and // blogs must be enabled | |
157 | (has_capability('moodle/user:readuserblogs', $personalcontext) // can review posts (parents etc) | |
b0c90e6e | 158 | or has_capability('moodle/blog:manageentries', $systemcontext) // entry manager can see all posts |
159 | or ($user->id == $USER->id and has_capability('moodle/blog:create', $systemcontext)) // viewing self | |
160 | or (has_capability('moodle/blog:view', $systemcontext) or has_capability('moodle/blog:view', $coursecontext)) | |
0c939d6c | 161 | ) // able to read blogs in site or course context |
162 | ) { //end if | |
e96f2a77 | 163 | |
164 | $toprow[] = new tabobject('blogs', $CFG->wwwroot.'/blog/index.php?userid='.$user->id.'&courseid='.$course->id, get_string('blog', 'blog')); | |
1242eb8f | 165 | } |
1242eb8f | 166 | |
167 | /// Current user must be teacher of the course or the course allows user to view their reports | |
7e2d7c92 | 168 | |
169 | //print_object($course); | |
170 | //print_object($user); | |
b3e900ce | 171 | |
172 | // add in logic to check course read report | |
1845e470 | 173 | if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) || ($course->showreports and $USER->id == $user->id) || has_capability('moodle/user:viewuseractivitiesreport', $coursecontext)) { |
1242eb8f | 174 | |
175 | $toprow[] = new tabobject('reports', $CFG->wwwroot.'/course/user.php?id='.$course->id. | |
176 | '&user='.$user->id.'&mode=outline', get_string('activityreports')); | |
177 | ||
7e2d7c92 | 178 | if (in_array($currenttab, array('outline', 'complete', 'todaylogs', 'alllogs', 'stats', 'grade'))) { |
1242eb8f | 179 | $inactive = array('reports'); |
180 | $activetwo = array('reports'); | |
181 | ||
182 | $secondrow = array(); | |
183 | $secondrow[] = new tabobject('outline', $CFG->wwwroot.'/course/user.php?id='.$course->id. | |
184 | '&user='.$user->id.'&mode=outline', get_string('outlinereport')); | |
185 | $secondrow[] = new tabobject('complete', $CFG->wwwroot.'/course/user.php?id='.$course->id. | |
186 | '&user='.$user->id.'&mode=complete', get_string('completereport')); | |
187 | $secondrow[] = new tabobject('todaylogs', $CFG->wwwroot.'/course/user.php?id='.$course->id. | |
188 | '&user='.$user->id.'&mode=todaylogs', get_string('todaylogs')); | |
189 | $secondrow[] = new tabobject('alllogs', $CFG->wwwroot.'/course/user.php?id='.$course->id. | |
190 | '&user='.$user->id.'&mode=alllogs', get_string('alllogs')); | |
191 | if (!empty($CFG->enablestats)) { | |
192 | $secondrow[] = new tabobject('stats',$CFG->wwwroot.'/course/user.php?id='.$course->id. | |
193 | '&user='.$user->id.'&mode=stats',get_string('stats')); | |
194 | } | |
7e2d7c92 | 195 | |
f9c471df | 196 | if ($course->showgrades) { |
197 | $secondrow[] = new tabobject('grade', $CFG->wwwroot.'/course/user.php?id='.$course->id. | |
7e2d7c92 | 198 | '&user='.$user->id.'&mode=grade', get_string('grade')); |
f9c471df | 199 | } |
7e2d7c92 | 200 | |
1242eb8f | 201 | } |
202 | ||
203 | } | |
204 | ||
205 | } //close last bracket (individual tags) | |
206 | ||
7e2d7c92 | 207 | |
208 | /// this needs permission checkings | |
0a8a95c9 | 209 | |
fcade7d0 | 210 | |
211 | if (!empty($showroles) and !empty($user)) { // this variable controls whether this roles is showed, or not, so only user/view page should set this flag | |
212 | $usercontext = get_context_instance(CONTEXT_USER, $user->id); | |
213 | if (has_capability('moodle/role:assign',$usercontext)) { | |
214 | $toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$usercontext->id.'&userid='.$user->id.'&courseid='.$course->id | |
215 | ,get_string('roles')); | |
216 | ||
217 | if (in_array($currenttab, array('assign', 'override'))) { | |
218 | $inactive = array('roles'); | |
219 | $activetwo = array('roles'); | |
220 | ||
221 | $secondrow = array(); | |
222 | $secondrow[] = new tabobject('assign', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$usercontext->id.'&userid='.$user->id.'&courseid='.$course->id | |
223 | ,get_string('assignroles', 'role')); | |
224 | $secondrow[] = new tabobject('override', $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$usercontext->id.'&userid='.$user->id.'&courseid='.$course->id | |
225 | ,get_string('overrideroles', 'role')); | |
226 | ||
227 | } | |
0a8a95c9 | 228 | } |
229 | } | |
f9a0ea69 | 230 | /// Add second row to display if there is one |
231 | ||
232 | if (!empty($secondrow)) { | |
233 | $tabs = array($toprow, $secondrow); | |
234 | } else { | |
235 | $tabs = array($toprow); | |
236 | } | |
237 | ||
f9a0ea69 | 238 | /// Print out the tabs and continue! |
239 | ||
e1ddfa6b | 240 | print_tabs($tabs, $currenttab, $inactive, $activetwo); |
f9a0ea69 | 241 | |
242 | ?> |