Clean up strings
[moodle.git] / course / unenrol.php
blobe007e88cc39d39bad27e2b464e260d5ae992eb18
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');
63 print_header("$course->shortname: $strunenrol", $course->fullname,
64 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> $strunenrol");
66 if ($userid) {
67 if (!$user = get_record('user', 'id', $userid)) {
68 error('That user does not exist!');
70 $strunenrolsure = get_string('unenrolsure', '', fullname($user, true));
71 notice_yesno($strunenrolsure, "unenrol.php?id=$id&amp;user=$user->id&amp;confirm=yes&amp;sesskey=".sesskey(),
72 $_SERVER['HTTP_REFERER']);
73 } else {
74 $strunenrolsure = get_string('unenrolsure', '', get_string("yourself"));
75 notice_yesno($strunenrolsure, "unenrol.php?id=$id&amp;confirm=yes&amp;sesskey=".sesskey(),
76 $_SERVER['HTTP_REFERER']);
79 print_footer($course);