MDL-10723 Removed all uses of print_navigation() throughout moodle, the function...
[moodle-pu.git] / course / unenrol.php
blobd2b4446f48f06e03a2acc8c9d325c84c5f1901cc
1 <?php // $Id$
3 // Remove oneself or someone else from a course, unassigning all
4 // roles one might have
5 //
6 // This will not delete any of their data from the course,
7 // but will remove them from the participant list and prevent
8 // any course email being sent to them.
10 require_once("../config.php");
11 require_once("lib.php");
13 $id = required_param('id', PARAM_INT); //course
14 $userid = optional_param('user', 0, PARAM_INT); //course
15 $confirm = optional_param('confirm', 0, PARAM_BOOL);
17 if (! $course = get_record('course', 'id', $id) ) {
18 error('Invalid course id');
21 if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
22 error('Invalid context');
25 require_login($course->id);
27 if ($course->metacourse) {
28 print_error('cantunenrollfrommetacourse', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
31 if ($userid) { // Unenrolling someone else
32 require_capability('moodle/role:assign', $context, NULL, false);
33 } else { // Unenrol yourself
34 require_capability('moodle/role:unassignself', $context, NULL, false);
37 if (!empty($USER->switchrole[$context->id])) {
38 print_error('cantunenrollinthisrole', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
41 if ($confirm and confirm_sesskey()) {
42 if ($userid) {
43 if (! role_unassign(0, $userid, 0, $context->id)) {
44 error("An error occurred while trying to unenrol that person.");
47 add_to_log($course->id, 'course', 'unenrol', "view.php?id=$course->id", $userid);
48 redirect($CFG->wwwroot.'/user/index.php?id='.$course->id);
50 } else {
51 if (! role_unassign(0, $USER->id, 0, $context->id)) {
52 error("An error occurred while trying to unenrol you.");
54 add_to_log($course->id, 'course', 'unenrol', "view.php?id=$course->id", $USER->id);
56 redirect($CFG->wwwroot);
61 $strunenrol = get_string('unenrol');
62 $navlinks = array();
63 $navlinks[] = array('name' => $strunenrol, 'link' => null, 'type' => 'misc');
64 $navigation = build_navigation($navlinks);
66 print_header("$course->shortname: $strunenrol", $course->fullname, $navigation);
68 if ($userid) {
69 if (!$user = get_record('user', 'id', $userid)) {
70 error('That user does not exist!');
72 $strunenrolsure = get_string('unenrolsure', '', fullname($user, true));
73 notice_yesno($strunenrolsure, "unenrol.php?id=$id&amp;user=$user->id&amp;confirm=yes&amp;sesskey=".sesskey(),
74 $_SERVER['HTTP_REFERER']);
75 } else {
76 $strunenrolsure = get_string('unenrolsure', '', get_string("yourself"));
77 notice_yesno($strunenrolsure, "unenrol.php?id=$id&amp;confirm=yes&amp;sesskey=".sesskey(),
78 $_SERVER['HTTP_REFERER']);
81 print_footer($course);