# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/admin/settings/users.php
--- moodle/admin/settings/users.php Base (1.26.2.12)
+++ moodle/admin/settings/users.php Locally Modified (Based On 1.26.2.12)
@@ -168,6 +168,8 @@
                              'mycourses' => get_string('mycourses'))));
     }
 
+    $temp->add(new admin_setting_configcheckbox('allowuserswitchrolestheycantassign', get_string('allowuserswitchrolestheycantassign', 'admin'), get_string('configallowuserswitchrolestheycantassign', 'admin'), 0));
+
     $ADMIN->add('roles', $temp);
 
 } // end of speedup
Index: moodle/course/view.php
--- moodle/course/view.php Base (1.106.2.5)
+++ moodle/course/view.php Locally Modified (Based On 1.106.2.5)
@@ -57,7 +57,7 @@
         has_capability('moodle/role:switchroles', $context)) {
         // is this role assignable in this context?
         // inquiring minds want to know...
-        $aroles = get_assignable_roles($context);
+        $aroles = get_assignable_roles_for_switchrole($context);
         if (is_array($aroles) && isset($aroles[$switchrole])) {
             role_switch($switchrole, $context);
             // Double check that this role is allowed here
Index: moodle/lang/en_utf8/admin.php
--- moodle/lang/en_utf8/admin.php Base (1.154.2.79)
+++ moodle/lang/en_utf8/admin.php Locally Modified (Based On 1.154.2.79)
@@ -13,6 +13,7 @@
 $string['allowuserblockhiding'] = 'Allow users to hide blocks';
 $string['allowusermailcharset'] = 'Allow user to select character set';
 $string['allowuserthemes'] = 'Allow user themes';
+$string['allowuserswitchrolestheycantassign'] = 'Allow users to switch to roles that they can\'t assign';
 $string['allowvisiblecoursesinhiddencategories'] = 'Allow visible courses in hidden categories';
 $string['antivirus'] = 'Anti-Virus';
 $string['appearance'] = 'Appearance';
@@ -254,6 +255,7 @@
 $string['configtimezone'] = 'You can set the default timezone here.  This is the only the DEFAULT timezone for displaying dates - each user can override this by setting their own in their profile. \"Server time\" here will make Moodle default to the server\'s operating system setting, but \"Server time\" in the user profile will make the user default to this timezone setting.  Cronjobs that depend on a time of day to run will use this timezone.';
 $string['configunzip'] = 'Indicate the location of your unzip program (Unix only, optional).  If specified, this will be used to unpack zip archives on the server.  If you leave this blank, then Moodle will use internal routines.';
 $string['configusetags'] = 'Should tags functionality across the site be enabled?';
+$string['configallowuserswitchrolestheycantassign'] = 'Allow users to switch to roles that they can\'t assign';
 $string['configvariables'] = 'Variables';
 $string['configverifychangedemail'] = 'Enables verification of changed email addresses using allowed and denied email domains settings. If this setting is disabled the domains are enforced only when creating new users.';
 $string['configwarning'] = 'Be careful modifying these settings - strange values could cause problems.';
Index: moodle/lib/accesslib.php
--- moodle/lib/accesslib.php Base (1.421.2.97)
+++ moodle/lib/accesslib.php Locally Modified (Based On 1.421.2.97)
@@ -4242,9 +4242,11 @@
 function get_assignable_roles_for_switchrole($context, $field='name', $rolenamedisplay=ROLENAME_ALIAS) {
     global $USER, $CFG;
 
+    if (!$CFG->allowuserswitchrolestheycantassign) { //config implemented for MDL-11313
     if (!has_capability('moodle/role:assign', $context)) {
         return array();
     } 
+    }
 
     $parents = get_parent_contexts($context);
     $parents[] = $context->id;
Index: moodle/version.php
--- moodle/version.php Base (1.563.2.404)
+++ moodle/version.php Locally Modified (Based On 1.563.2.404)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2007101540;  // YYYYMMDD      = date of the 1.9 branch (don't change)
+    $version = 2007101541;  // YYYYMMDD      = date of the 1.9 branch (don't change)
                             //         X     = release number 1.9.[0,1,2,3,4,5...]
                             //          Y.YY = micro-increments between releases
 

