Commit | Line | Data |
---|---|---|
ce221eb5 | 1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * Display profile for a particular user | |
20 | * | |
21 | * @copyright 1999 Martin Dougiamas http://dougiamas.com | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | * @package user | |
24 | */ | |
25 | ||
26 | require_once("../config.php"); | |
27 | require_once($CFG->dirroot.'/user/profile/lib.php'); | |
28 | require_once($CFG->dirroot.'/tag/lib.php'); | |
29 | ||
30 | $id = optional_param('id', 0, PARAM_INT); // user id | |
31 | $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) | |
32 | $enable = optional_param('enable', 0, PARAM_BOOL); // enable email | |
33 | $disable = optional_param('disable', 0, PARAM_BOOL); // disable email | |
34 | ||
35 | if (empty($id)) { // See your own profile by default | |
36 | require_login(); | |
37 | $id = $USER->id; | |
38 | } | |
f9903ed0 | 39 | |
a6855934 | 40 | $url = new moodle_url('/user/view.php', array('id'=>$id)); |
7a7e209d | 41 | if ($course != SITEID) { |
ce221eb5 | 42 | $url->param('course', $course); |
43 | } | |
44 | if ($enable !== 0) { | |
45 | $url->param('enable', $enable); | |
46 | } | |
47 | if ($disable !== 0) { | |
48 | $url->param('disable', $disable); | |
49 | } | |
50 | $PAGE->set_url($url); | |
e41ddc4b | 51 | |
ce221eb5 | 52 | if (! $user = $DB->get_record("user", array("id"=>$id))) { |
53 | print_error('invaliduserid'); | |
54 | } | |
f9903ed0 | 55 | |
ce221eb5 | 56 | if (! $course = $DB->get_record("course", array("id"=>$course))) { |
57 | print_error('invalidcourseid'); | |
58 | } | |
f9903ed0 | 59 | |
ce221eb5 | 60 | // special hack for cli installer - continue to site settings |
61 | $systemcontext = get_context_instance(CONTEXT_SYSTEM); | |
62 | if ($SITE->shortname === '' and has_capability('moodle/site:config', $systemcontext)) { | |
63 | redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php'); | |
64 | } | |
1deff123 | 65 | |
bad59bc0 | 66 | /// Make sure the current user is allowed to see this user |
67 | ||
ce221eb5 | 68 | if (empty($USER->id)) { |
69 | $currentuser = false; | |
70 | } else { | |
71 | $currentuser = ($user->id == $USER->id); | |
72 | } | |
bad59bc0 | 73 | |
ce221eb5 | 74 | if ($course->id == SITEID) { |
75 | $coursecontext = $systemcontext; // SYSTEM context | |
76 | } else { | |
77 | $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context | |
78 | } | |
79 | $usercontext = get_context_instance(CONTEXT_USER, $user->id); // User context | |
0be6f678 | 80 | |
ce221eb5 | 81 | $PAGE->set_context($usercontext); |
cb4f6179 | 82 | |
ce221eb5 | 83 | if (!empty($CFG->forcelogin) || $course->id != SITEID) { |
84 | // do not force parents to enrol | |
85 | if (!$DB->get_record('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id))) { | |
86 | require_login($course->id); | |
7034b46c | 87 | } |
ce221eb5 | 88 | } |
0be6f678 | 89 | |
ce221eb5 | 90 | if (!empty($CFG->forceloginforprofiles)) { |
91 | require_login(); | |
92 | if (has_capability('moodle/legacy:guest', $systemcontext, 0, false)) { | |
93 | redirect(get_login_url()); | |
f9903ed0 | 94 | } |
ce221eb5 | 95 | } |
f9903ed0 | 96 | |
ce221eb5 | 97 | $strpersonalprofile = get_string('personalprofile'); |
98 | $strparticipants = get_string("participants"); | |
99 | $struser = get_string("user"); | |
f9903ed0 | 100 | |
ce221eb5 | 101 | $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext)); |
f1603208 | 102 | |
ce221eb5 | 103 | $link = null; |
104 | if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) { | |
a6855934 | 105 | $link = new moodle_url("/user/index.php", array('id'=>$course->id)); |
ce221eb5 | 106 | } |
0be6f678 | 107 | |
499e78b4 | 108 | /// If the user being shown is not ourselves, then make sure we are allowed to see them! |
ce221eb5 | 109 | if (!$currentuser) { |
caa8363f | 110 | |
ce221eb5 | 111 | $PAGE->set_title("$strpersonalprofile: "); |
112 | $PAGE->set_heading("$strpersonalprofile: "); | |
caa8363f | 113 | |
ce221eb5 | 114 | if ($course->id == SITEID) { // Reduce possibility of "browsing" userbase at site level |
115 | if ($CFG->forceloginforprofiles and !isteacherinanycourse() | |
116 | and !isteacherinanycourse($user->id) | |
117 | and !has_capability('moodle/user:viewdetails', $usercontext)) { // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366) | |
0be6f678 | 118 | |
ce221eb5 | 119 | $PAGE->navbar->add($struser); |
120 | echo $OUTPUT->header(); | |
121 | echo $OUTPUT->heading(get_string('usernotavailable', 'error')); | |
122 | echo $OUTPUT->footer(); | |
123 | exit; | |
124 | } | |
125 | } else { // Normal course | |
126 | // check capabilities | |
127 | if (!has_capability('moodle/user:viewdetails', $coursecontext) && | |
128 | !has_capability('moodle/user:viewdetails', $usercontext)) { | |
129 | print_error('cannotviewprofile'); | |
130 | } | |
8005d470 | 131 | |
ce221eb5 | 132 | if (!has_capability('moodle/course:view', $coursecontext, $user->id, false)) { |
871e5728 | 133 | if (has_capability('moodle/role:assign', $coursecontext)) { |
ce221eb5 | 134 | $PAGE->navbar->add($fullname); |
135 | echo $OUTPUT->heading(get_string('notenrolled', $fullname)); | |
136 | } else { | |
137 | $PAGE->navbar->add($struser); | |
138 | echo $OUTPUT->heading(get_string('notenrolledprofile')); | |
fa22fd5f | 139 | } |
ce221eb5 | 140 | echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']); |
141 | echo $OUTPUT->footer(); | |
142 | exit; | |
fa22fd5f | 143 | } |
ce221eb5 | 144 | } |
499e78b4 | 145 | |
146 | ||
ce221eb5 | 147 | // If groups are in use, make sure we can see that group |
148 | if (groups_get_course_groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext)) { | |
149 | require_login(); | |
150 | ///this is changed because of mygroupid | |
151 | $gtrue = (bool)groups_get_all_groups($course->id, $user->id); | |
152 | if (!$gtrue) { | |
153 | print_error("groupnotamember", '', "../course/view.php?id=$course->id"); | |
dd780a3b | 154 | } |
155 | } | |
ce221eb5 | 156 | } |
0be6f678 | 157 | |
f5ecf2e9 | 158 | |
bad59bc0 | 159 | /// We've established they can see the user's name at least, so what about the rest? |
160 | ||
7a7e209d | 161 | $PAGE->navigation->extend_for_user($user); |
ce221eb5 | 162 | $PAGE->set_title("$course->fullname: $strpersonalprofile: $fullname"); |
163 | $PAGE->set_heading($course->fullname); | |
ad1e8f13 | 164 | $PAGE->set_pagelayout('standard'); |
ce221eb5 | 165 | echo $OUTPUT->header(); |
b1d530d2 | 166 | |
ce221eb5 | 167 | if (($course->id != SITEID) and ! has_capability('moodle/legacy:guest', $systemcontext, 0, false) ) { // Need to have access to a course to see that info |
168 | if (!has_capability('moodle/course:view', $coursecontext, $user->id)) { | |
169 | echo $OUTPUT->heading(get_string('notenrolled', '', $fullname)); | |
170 | echo $OUTPUT->footer(); | |
171 | die; | |
8a3b358b | 172 | } |
ce221eb5 | 173 | } |
8a3b358b | 174 | |
ce221eb5 | 175 | if ($user->deleted) { |
176 | echo $OUTPUT->heading(get_string('userdeleted')); | |
177 | if (!has_capability('moodle/user:update', $coursecontext)) { | |
178 | echo $OUTPUT->footer(); | |
179 | die; | |
bb09fb11 | 180 | } |
ce221eb5 | 181 | } |
bb09fb11 | 182 | |
bad59bc0 | 183 | /// OK, security out the way, now we are showing the user |
184 | ||
ce221eb5 | 185 | add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id"); |
bad59bc0 | 186 | |
ce221eb5 | 187 | if ($course->id != SITEID) { |
188 | $user->lastaccess = false; | |
189 | if ($lastaccess = $DB->get_record('user_lastaccess', array('userid'=>$user->id, 'courseid'=>$course->id))) { | |
190 | $user->lastaccess = $lastaccess->timeaccess; | |
499e78b4 | 191 | } |
ce221eb5 | 192 | } |
499e78b4 | 193 | |
bad59bc0 | 194 | |
4801fe93 | 195 | /// Get the hidden field list |
ce221eb5 | 196 | if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) { |
197 | $hiddenfields = array(); | |
198 | } else { | |
199 | $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); | |
200 | } | |
f9903ed0 | 201 | |
f9a0ea69 | 202 | /// Print tabs at top |
203 | /// This same call is made in: | |
204 | /// /user/view.php | |
205 | /// /user/edit.php | |
206 | /// /course/user.php | |
4801fe93 | 207 | |
ce221eb5 | 208 | $currenttab = 'profile'; |
209 | $showroles = 1; | |
210 | if (!$user->deleted) { | |
211 | include('tabs.php'); | |
212 | } | |
f9903ed0 | 213 | |
ce221eb5 | 214 | if (is_mnet_remote_user($user)) { |
215 | $sql = " | |
216 | SELECT DISTINCT h.id, h.name, h.wwwroot, | |
217 | a.name as application, a.display_name | |
218 | FROM {mnet_host} h, {mnet_application} a | |
219 | WHERE h.id = ? AND h.applicationid = a.id | |
220 | ORDER BY a.display_name, h.name"; | |
ce8c75ee | 221 | |
ce221eb5 | 222 | $remotehost = $DB->get_record_sql($sql, array($user->mnethostid)); |
0be6f678 | 223 | |
ce221eb5 | 224 | echo '<p class="errorboxcontent">'.get_string('remoteappuser', $remotehost->application)." <br />\n"; |
225 | if ($USER->id == $user->id) { | |
226 | if ($remotehost->application =='moodle') { | |
227 | echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/user/edit.php\">{$remotehost->name}</a> ".get_string('editremoteprofile')." </p>\n"; | |
25202581 | 228 | } else { |
ce221eb5 | 229 | echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a> ".get_string('gotoyourserver')." </p>\n"; |
25202581 | 230 | } |
ce221eb5 | 231 | } else { |
232 | echo "Remote {$remotehost->display_name}: <a href=\"{$remotehost->wwwroot}/\">{$remotehost->name}</a></p>\n"; | |
56f52742 | 233 | } |
ce221eb5 | 234 | } |
56f52742 | 235 | |
90723839 | 236 | echo '<table class="userinfobox" summary="">'; |
ce221eb5 | 237 | echo '<tr>'; |
238 | echo '<td class="side">'; | |
812dbaf7 | 239 | echo $OUTPUT->user_picture($user, array('courseid'=>$course->id, 'size'=>100)); |
ce221eb5 | 240 | echo '</td><td class="content">'; |
f9903ed0 | 241 | |
ce221eb5 | 242 | // Print the description |
f9903ed0 | 243 | |
ce221eb5 | 244 | if ($user->description && !isset($hiddenfields['description'])) { |
245 | $has_courseid = ($course->id != SITEID); | |
246 | if (!$has_courseid && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid'=>$id))) { | |
247 | echo get_string('profilenotshown', 'moodle').'<hr />'; | |
248 | } else { | |
aa6c1ced | 249 | |
8bdc9cac SH |
250 | $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user_profile', $id); |
251 | echo format_text($user->description, $user->descriptionformat)."<hr />"; | |
f9903ed0 | 252 | } |
ce221eb5 | 253 | } |
f9903ed0 | 254 | |
ce221eb5 | 255 | // Print all the little details in a list |
f9903ed0 | 256 | |
ce221eb5 | 257 | echo '<table class="list">'; |
f9903ed0 | 258 | |
ce221eb5 | 259 | if (! isset($hiddenfields['country']) && $user->country) { |
260 | $countries = get_list_of_countries(); | |
261 | print_row(get_string('country') . ':', $countries[$user->country]); | |
262 | } | |
910bd9e1 | 263 | |
ce221eb5 | 264 | if (! isset($hiddenfields['city']) && $user->city) { |
265 | print_row(get_string('city') . ':', $user->city); | |
266 | } | |
f9903ed0 | 267 | |
ce221eb5 | 268 | if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) { |
269 | if ($user->address) { | |
270 | print_row(get_string("address").":", "$user->address"); | |
271 | } | |
272 | if ($user->phone1) { | |
273 | print_row(get_string("phone").":", "$user->phone1"); | |
274 | } | |
275 | if ($user->phone2) { | |
276 | print_row(get_string("phone2").":", "$user->phone2"); | |
f9903ed0 | 277 | } |
ce221eb5 | 278 | } |
f9903ed0 | 279 | |
ce221eb5 | 280 | if ($user->maildisplay == 1 or |
474f6bfe | 281 | ($user->maildisplay == 2 and ($course->id != SITEID) and !isguestuser()) or |
ce221eb5 | 282 | has_capability('moodle/course:useremail', $coursecontext)) { |
cadb96f2 | 283 | |
ce221eb5 | 284 | $emailswitch = ''; |
c6c558d7 | 285 | |
ce221eb5 | 286 | if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff |
deaa8a19 | 287 | if (!empty($enable) and confirm_sesskey()) { /// Recieved a parameter to enable the email address |
ce221eb5 | 288 | $DB->set_field('user', 'emailstop', 0, array('id'=>$user->id)); |
289 | $user->emailstop = 0; | |
c6c558d7 | 290 | } |
deaa8a19 | 291 | if (!empty($disable) and confirm_sesskey()) { /// Recieved a parameter to disable the email address |
ce221eb5 | 292 | $DB->set_field('user', 'emailstop', 1, array('id'=>$user->id)); |
293 | $user->emailstop = 1; | |
cadb96f2 | 294 | } |
55e078c0 | 295 | } |
f9903ed0 | 296 | |
ce221eb5 | 297 | if (has_capability('moodle/course:useremail', $coursecontext)) { /// Can use the enable/disable email stuff |
298 | if ($user->emailstop) { | |
299 | $switchparam = 'enable'; | |
300 | $switchtitle = get_string('emaildisable'); | |
301 | $switchclick = get_string('emailenableclick'); | |
302 | $switchpix = 't/emailno'; | |
303 | } else { | |
304 | $switchparam = 'disable'; | |
305 | $switchtitle = get_string('emailenable'); | |
306 | $switchclick = get_string('emaildisableclick'); | |
307 | $switchpix = 't/email'; | |
308 | } | |
309 | $emailswitch = " <a title=\"$switchclick\" ". | |
deaa8a19 | 310 | "href=\"view.php?id=$user->id&course=$course->id&$switchparam=1&sesskey=".sesskey()."\">". |
b5d0cafc | 311 | "<img src=\"" . $OUTPUT->pix_url("$switchpix") . "\" alt=\"$switchclick\" /></a>"; |
ce221eb5 | 312 | |
313 | } else if ($currentuser) { /// Can only re-enable an email this way | |
314 | if ($user->emailstop) { // Include link that tells how to re-enable their email | |
315 | $switchparam = 'enable'; | |
316 | $switchtitle = get_string('emaildisable'); | |
317 | $switchclick = get_string('emailenableclick'); | |
318 | ||
319 | $emailswitch = " (<a title=\"$switchclick\" ". | |
deaa8a19 | 320 | "href=\"view.php?id=$user->id&course=$course->id&enable=1&sesskey=".sesskey()."\">$switchtitle</a>)"; |
c18a3c1f | 321 | } |
f9903ed0 | 322 | } |
323 | ||
ce221eb5 | 324 | print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch"); |
325 | } | |
766d2bf3 | 326 | |
ce221eb5 | 327 | if ($user->url && !isset($hiddenfields['webpage'])) { |
328 | $url = $user->url; | |
329 | if (strpos($user->url, '://') === false) { | |
330 | $url = 'http://'. $url; | |
f9903ed0 | 331 | } |
ce221eb5 | 332 | print_row(get_string("webpage") .":", "<a href=\"$url\">$user->url</a>"); |
333 | } | |
f9903ed0 | 334 | |
ce221eb5 | 335 | if ($user->icq && !isset($hiddenfields['icqnumber'])) { |
336 | print_row(get_string('icqnumber').':',"<a href=\"http://web.icq.com/wwp?uin=$user->icq\">$user->icq <img src=\"http://web.icq.com/whitepages/online?icq=$user->icq&img=5\" alt=\"\" /></a>"); | |
337 | } | |
338 | ||
339 | if ($user->skype && !isset($hiddenfields['skypeid'])) { | |
340 | print_row(get_string('skypeid').':','<a href="callto:'.urlencode($user->skype).'">'.s($user->skype). | |
341 | ' <img src="http://mystatus.skype.com/smallicon/'.urlencode($user->skype).'" alt="'.get_string('status').'" '. | |
342 | ' /></a>'); | |
343 | } | |
344 | if ($user->yahoo && !isset($hiddenfields['yahooid'])) { | |
345 | print_row(get_string('yahooid').':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target='.urlencode($user->yahoo).'&.src=pg">'.s($user->yahoo)." <img src=\"http://opi.yahoo.com/online?u=".urlencode($user->yahoo)."&m=g&t=0\" alt=\"\"></a>"); | |
346 | } | |
347 | if ($user->aim && !isset($hiddenfields['aimid'])) { | |
348 | print_row(get_string('aimid').':', '<a href="aim:goim?screenname='.s($user->aim).'">'.s($user->aim).'</a>'); | |
349 | } | |
350 | if ($user->msn && !isset($hiddenfields['msnid'])) { | |
351 | print_row(get_string('msnid').':', s($user->msn)); | |
352 | } | |
353 | ||
354 | /// Print the Custom User Fields | |
355 | profile_display_fields($user->id); | |
356 | ||
357 | ||
358 | if (!isset($hiddenfields['mycourses'])) { | |
183ea489 | 359 | if ($mycourses = get_my_courses($user->id, 'visible DESC,sortorder ASC', null, false, 21)) { |
ce221eb5 | 360 | $shown=0; |
361 | $courselisting = ''; | |
362 | foreach ($mycourses as $mycourse) { | |
363 | if ($mycourse->category) { | |
364 | if ($mycourse->id != $course->id){ | |
365 | $class = ''; | |
366 | if ($mycourse->visible == 0) { | |
367 | // get_my_courses will filter courses $USER cannot see | |
368 | // if we get one with visible 0 it just means it's hidden | |
369 | // ... but not from $USER | |
370 | $class = 'class="dimmed"'; | |
472b647a | 371 | } |
ce221eb5 | 372 | $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >" |
373 | . format_string($mycourse->fullname) . "</a>, "; | |
dd5e0901 | 374 | } |
ce221eb5 | 375 | else { |
376 | $courselisting .= format_string($mycourse->fullname) . ", "; | |
9c72928d | 377 | } |
378 | } | |
ce221eb5 | 379 | $shown++; |
380 | if($shown==20) { | |
381 | $courselisting.= "..."; | |
382 | break; | |
383 | } | |
9c72928d | 384 | } |
ce221eb5 | 385 | print_row(get_string('courses').':', rtrim($courselisting,', ')); |
9c72928d | 386 | } |
ce221eb5 | 387 | } |
388 | if (!isset($hiddenfields['firstaccess'])) { | |
389 | if ($user->firstaccess) { | |
390 | $datestring = userdate($user->firstaccess)." (".format_time(time() - $user->firstaccess).")"; | |
391 | } else { | |
392 | $datestring = get_string("never"); | |
1263a0ff | 393 | } |
ce221eb5 | 394 | print_row(get_string("firstaccess").":", $datestring); |
395 | } | |
396 | if (!isset($hiddenfields['lastaccess'])) { | |
397 | if ($user->lastaccess) { | |
398 | $datestring = userdate($user->lastaccess)." (".format_time(time() - $user->lastaccess).")"; | |
399 | } else { | |
400 | $datestring = get_string("never"); | |
d21fef3a | 401 | } |
ce221eb5 | 402 | print_row(get_string("lastaccess").":", $datestring); |
403 | } | |
0a8a95c9 | 404 | /// printing roles |
f2f085ee | 405 | |
ce221eb5 | 406 | if ($rolestring = get_user_roles_in_context($id, $coursecontext)) { |
407 | print_row(get_string('roles').':', format_string($rolestring, false)); | |
408 | } | |
fa22fd5f | 409 | |
f90e9ff6 | 410 | /// Printing groups |
ce221eb5 | 411 | if (!isset($hiddenfields['groups'])) { |
412 | $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext)); | |
413 | if (!$isseparategroups){ | |
414 | if ($usergroups = groups_get_all_groups($course->id, $user->id)){ | |
415 | $groupstr = ''; | |
416 | foreach ($usergroups as $group){ | |
417 | $groupstr .= ' <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&group='.$group->id.'">'.format_string($group->name).'</a>,'; | |
fa22fd5f | 418 | } |
ce221eb5 | 419 | print_row(get_string("group").":", rtrim($groupstr, ', ')); |
fa22fd5f | 420 | } |
fa22fd5f | 421 | } |
ce221eb5 | 422 | } |
f90e9ff6 | 423 | /// End of printing groups |
fa22fd5f | 424 | |
1e1c51a3 | 425 | /// Printing Interests |
ce221eb5 | 426 | if( !empty($CFG->usetags)) { |
427 | if ( $interests = tag_get_tags_csv('user', $user->id) ) { | |
428 | print_row(get_string('interests') .": ", $interests); | |
1e1c51a3 | 429 | } |
ce221eb5 | 430 | } |
0be6f678 | 431 | /// End of Printing Interests |
1e1c51a3 | 432 | |
ce221eb5 | 433 | echo "</table>"; |
f9903ed0 | 434 | |
ce221eb5 | 435 | echo "</td></tr></table>"; |
f9903ed0 | 436 | |
ce221eb5 | 437 | $userauth = get_auth_plugin($user->auth); |
210560e3 | 438 | |
ce221eb5 | 439 | $passwordchangeurl = false; |
440 | if ($currentuser and $userauth->can_change_password() and !isguestuser() and has_capability('moodle/user:changeownpassword', $systemcontext)) { | |
441 | if (!$passwordchangeurl = $userauth->change_password_url()) { | |
442 | if (empty($CFG->loginhttps)) { | |
443 | $passwordchangeurl = "$CFG->wwwroot/login/change_password.php"; | |
444 | } else { | |
445 | $passwordchangeurl = str_replace('http:', 'https:', $CFG->wwwroot.'/login/change_password.php'); | |
ab1324e4 | 446 | } |
3086f3f6 | 447 | } |
ce221eb5 | 448 | } |
3086f3f6 | 449 | |
c888501c | 450 | // Print other functions |
ce221eb5 | 451 | echo '<div class="buttons">'; |
b506bb51 | 452 | |
ce221eb5 | 453 | if ($passwordchangeurl) { |
454 | $params = array('id'=>$course->id); | |
65acd2bb | 455 | |
ce221eb5 | 456 | if (session_is_loggedinas()) { |
457 | $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data | |
458 | } else { | |
459 | $parts = explode('?', $passwordchangeurl); | |
460 | $passwordchangeurl = reset($parts); | |
461 | $after = next($parts); | |
462 | preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches); | |
463 | if (count($matches)) { | |
464 | foreach($matches[0] as $key=>$match) { | |
465 | $params[$matches[1][$key]] = $matches[2][$key]; | |
65acd2bb | 466 | } |
80274abf | 467 | } |
e1ac4272 | 468 | } |
ce221eb5 | 469 | echo "<form action=\"$passwordchangeurl\" method=\"get\">"; |
470 | echo "<div>"; | |
471 | foreach($params as $key=>$value) { | |
472 | echo '<input type="hidden" name="'.$key.'" value="'.s($value).'" />'; | |
473 | } | |
474 | if (session_is_loggedinas()) { | |
475 | // changing of password when "Logged in as" is not allowed | |
476 | echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" disabled=\"disabled\" />"; | |
477 | } else { | |
478 | echo "<input type=\"submit\" value=\"".get_string("changepassword")."\" />"; | |
479 | } | |
480 | echo "</div>"; | |
481 | echo "</form>"; | |
482 | } | |
4801fe93 | 483 | |
ce221eb5 | 484 | if ($course->id != SITEID && empty($course->metacourse)) { // Mostly only useful at course level |
4801fe93 | 485 | |
ce221eb5 | 486 | $canunenrol = false; |
76b570d6 | 487 | |
ce221eb5 | 488 | if ($user->id == $USER->id) { // Myself |
489 | $canunenrol = has_capability('moodle/course:view', $coursecontext, NULL) && // Course participant | |
490 | has_capability('moodle/role:unassignself', $coursecontext, NULL, false) && // Can unassign myself | |
491 | get_user_roles($coursecontext, $user->id, false); // Must have role in course | |
76b570d6 | 492 | |
ce221eb5 | 493 | } else if (has_capability('moodle/role:assign', $coursecontext, NULL)) { // I can assign roles |
494 | if ($roles = get_user_roles($coursecontext, $user->id, false)) { | |
495 | $canunenrol = true; | |
496 | foreach($roles as $role) { | |
497 | if (!user_can_assign($coursecontext, $role->roleid)) { | |
498 | $canunenrol = false; // I can not unassign all roles in this course :-( | |
499 | break; | |
76b570d6 | 500 | } |
501 | } | |
502 | } | |
8f850172 | 503 | } |
4801fe93 | 504 | |
ce221eb5 | 505 | if ($canunenrol) { |
506 | echo '<form action="'.$CFG->wwwroot.'/course/unenrol.php" method="get">'; | |
76b570d6 | 507 | echo '<div>'; |
4801fe93 | 508 | echo '<input type="hidden" name="id" value="'.$course->id.'" />'; |
509 | echo '<input type="hidden" name="user" value="'.$user->id.'" />'; | |
ce221eb5 | 510 | echo '<input type="submit" value="'.s(get_string('unenrolme', '', $course->shortname)).'" />'; |
76b570d6 | 511 | echo '</div>'; |
c1138797 | 512 | echo '</form>'; |
803b2c76 | 513 | } |
ce221eb5 | 514 | } |
bad59bc0 | 515 | |
ce221eb5 | 516 | if (!$user->deleted and $USER->id != $user->id && !session_is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) && |
517 | ! has_capability('moodle/site:doanything', $coursecontext, $user->id, false)) { | |
518 | echo '<form action="'.$CFG->wwwroot.'/course/loginas.php" method="get">'; | |
519 | echo '<div>'; | |
520 | echo '<input type="hidden" name="id" value="'.$course->id.'" />'; | |
521 | echo '<input type="hidden" name="user" value="'.$user->id.'" />'; | |
522 | echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; | |
523 | echo '<input type="submit" value="'.get_string('loginas').'" />'; | |
524 | echo '</div>'; | |
525 | echo '</form>'; | |
526 | } | |
527 | ||
474f6bfe | 528 | if (!$user->deleted and !empty($CFG->messaging) and !isguestuser() and has_capability('moodle/site:sendmessage', $systemcontext)) { |
ce221eb5 | 529 | if (!empty($USER->id) and ($USER->id == $user->id)) { |
530 | if ($countmessages = $DB->count_records('message', array('useridto'=>$user->id))) { | |
531 | $messagebuttonname = get_string("messages", "message")."($countmessages)"; | |
2fc1b1fe | 532 | } else { |
ce221eb5 | 533 | $messagebuttonname = get_string("messages", "message"); |
2fc1b1fe | 534 | } |
ce221eb5 | 535 | echo "<form onclick=\"this.target='message'\" action=\"../message/index.php\" method=\"get\">"; |
536 | echo "<div>"; | |
537 | echo "<input type=\"submit\" value=\"$messagebuttonname\" onclick=\"return openpopup('/message/index.php', 'message', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />"; | |
538 | echo "</div>"; | |
539 | echo "</form>"; | |
540 | } else { | |
541 | echo "<form onclick=\"this.target='message$user->id'\" action=\"../message/discussion.php\" method=\"get\">"; | |
4e7b349e | 542 | echo "<div>"; |
ce221eb5 | 543 | echo "<input type=\"hidden\" name=\"id\" value=\"$user->id\" />"; |
544 | echo "<input type=\"submit\" value=\"".get_string("sendmessage", "message")."\" onclick=\"return openpopup('/message/discussion.php?id=$user->id', 'message_$user->id', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />"; | |
4e7b349e | 545 | echo "</div>"; |
c1138797 | 546 | echo "</form>"; |
96a7973e | 547 | } |
ce221eb5 | 548 | } |
549 | // Authorize.net: User Payments | |
550 | if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize')) { | |
551 | echo "<form action=\"../enrol/authorize/index.php\" method=\"get\">"; | |
552 | echo "<div>"; | |
553 | echo "<input type=\"hidden\" name=\"course\" value=\"$course->id\" />"; | |
554 | echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />"; | |
555 | echo "<input type=\"submit\" value=\"".get_string('payments')."\" />"; | |
556 | echo "</div>"; | |
557 | echo "</form>"; | |
558 | } | |
559 | echo "</div>\n"; | |
3de34ccf | 560 | |
ce221eb5 | 561 | if ($CFG->debugdisplay && debugging('', DEBUG_DEVELOPER) && $USER->id == $user->id) { // Show user object |
562 | echo '<hr />'; | |
563 | echo $OUTPUT->heading('DEBUG MODE: User session variables'); | |
564 | print_object($USER); | |
565 | } | |
3de34ccf | 566 | |
ce221eb5 | 567 | echo $OUTPUT->footer(); |
f9903ed0 | 568 | |
569 | /// Functions /////// | |
570 | ||
571 | function print_row($left, $right) { | |
c1138797 | 572 | echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n"; |
f9903ed0 | 573 | } |
574 | ||
aa6c1ced | 575 |