| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: unenrol.php,v 1.32.2.3 2008/05/16 02:07:58 dongsheng Exp $ 2 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. 9 10 require_once("../config.php"); 11 require_once ("lib.php"); 12 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); 16 17 if($userid == $USER->id){ 18 // the rest of this code assumes $userid=0 means 19 // you are unassigning yourself, so set this for the 20 // correct capabiliy checks & language later 21 $userid = 0; 22 } 23 24 if (! $course = get_record('course', 'id', $id) ) { 25 error('Invalid course id'); 26 } 27 28 if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) { 29 error('Invalid context'); 30 } 31 32 require_login($course->id); 33 34 if ($course->metacourse) { 35 print_error('cantunenrollfrommetacourse', '', $CFG->wwwroot.'/course/view.php?id='.$course->id); 36 } 37 38 if ($userid) { // Unenrolling someone else 39 require_capability('moodle/role:assign', $context, NULL, false); 40 41 $roles = get_user_roles($context, $userid, false); 42 43 // verify user may unassign all roles at course context 44 foreach($roles as $role) { 45 if (!user_can_assign($context, $role->roleid)) { 46 error('Can not unassign this user from role id:'.$role->roleid); 47 } 48 } 49 50 } else { // Unenrol yourself 51 require_capability('moodle/role:unassignself', $context, NULL, false); 52 } 53 54 if (!empty($USER->access['rsw'][$context->path])) { 55 print_error('cantunenrollinthisrole', '', 56 $CFG->wwwroot.'/course/view.php?id='.$course->id); 57 } 58 59 if ($confirm and confirm_sesskey()) { 60 if ($userid) { 61 if (! role_unassign(0, $userid, 0, $context->id)) { 62 error("An error occurred while trying to unenrol that person."); 63 } 64 65 add_to_log($course->id, 'course', 'unenrol', 66 "view.php?id=$course->id", $course->id); 67 redirect($CFG->wwwroot.'/user/index.php?id='.$course->id); 68 69 } else { 70 if (! role_unassign(0, $USER->id, 0, $context->id)) { 71 error("An error occurred while trying to unenrol you."); 72 } 73 74 // force a refresh of mycourses 75 unset($USER->mycourses); 76 add_to_log($course->id, 'course', 'unenrol', 77 "view.php?id=$course->id", $course->id); 78 79 redirect($CFG->wwwroot); 80 } 81 } 82 83 84 $strunenrol = get_string('unenrol'); 85 $navlinks = array(); 86 $navlinks[] = array('name' => $strunenrol, 'link' => null, 'type' => 'misc'); 87 $navigation = build_navigation($navlinks); 88 89 print_header("$course->shortname: $strunenrol", $course->fullname, $navigation); 90 91 if ($userid) { 92 if (!$user = get_record('user', 'id', $userid)) { 93 error('That user does not exist!'); 94 } 95 $strunenrolsure = get_string('unenrolsure', '', fullname($user, true)); 96 notice_yesno($strunenrolsure, "unenrol.php?id=$id&user=$user->id&confirm=yes&sesskey=".sesskey(), 97 $_SERVER['HTTP_REFERER']); 98 } else { 99 $strunenrolsure = get_string('unenrolsure', '', get_string("yourself")); 100 notice_yesno($strunenrolsure, "unenrol.php?id=$id&confirm=yes&sesskey=".sesskey(), 101 $_SERVER['HTTP_REFERER']); 102 } 103 104 print_footer($course); 105 106 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |