[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm

raeburn raeburn@source.lon-capa.org
Mon, 02 Feb 2009 00:12:01 -0000


This is a MIME encoded message

--raeburn1233533521
Content-Type: text/plain

raeburn		Mon Feb  2 00:12:01 2009 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  - Functionality for Domain Coordinators to display/set availability of user tools (portfolio, blog, aboutme) for individual users moved to two new routines:
  
  &build_tools_display()
  &tool_changes()
  
  - These routines are re-used to allow DCs to display/set ability of individual users to request creation of (a) official courses, and (b) unofficial courses.
  
  
--raeburn1233533521
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090202001201.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.274 loncom/interface/loncreateuser.pm:1.275
--- loncom/interface/loncreateuser.pm:1.274	Fri Jan 16 10:59:48 2009
+++ loncom/interface/loncreateuser.pm	Mon Feb  2 00:12:01 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.274 2009/01/16 10:59:48 bisitz Exp $
+# $Id: loncreateuser.pm,v 1.275 2009/02/02 00:12:01 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -123,18 +123,10 @@
     my ($ccuname,$ccdomain) = @_;
     my %lt = &Apache::lonlocal::texthash(
                    'usrt'      => "User Tools",
-                   'blog'      => "Personal User Blog",
-                   'aboutme'   => "Personal Information Page",
-                   'portfolio' => "Personal User Portfolio",
-                   'avai'      => "Available",
-                   'cusa'      => "availability",
-                   'chse'      => "Change setting",
                    'disk'      => "Disk space allocated to user's portfolio files",
                    'cuqu'      => "Current quota",
                    'cust'      => "Custom quota",
                    'defa'      => "Default",
-                   'usde'      => "Use default",
-                   'uscu'      => "Use custom",
                    'chqu'      => "Change quota",
     );
     my ($currquota,$quotatype,$inststatus,$defquota) = 
@@ -190,50 +182,7 @@
                  &Apache::loncommon::start_data_table();
 
     if (&Apache::lonnet::allowed('mut',$ccdomain)) {
-        my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
-                          'tools.aboutme','tools.portfolio','tools.blog');
-        my @usertools = ('aboutme','blog','portfolio');
-        foreach my $item (@usertools) {
-            my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off);
-            $cust_off = 'checked="checked" ';
-            $tool_on = 'checked="checked" ';
-            $curr_access = &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item);
-            if ($userenv{'tools.'.$item} eq '') {
-                $custom_access = 'default';
-                if (!$curr_access) {
-                    $tool_off = 'checked="checked" ';
-                    $tool_on = '';
-                }
-            } else {
-                $custom_access = 'custom';
-                $cust_on = ' checked="checked" ';
-                $cust_off = '';
-                if ($userenv{'tools.'.$item} == 0) {
-                    $tool_off = 'checked="checked" ';
-                    $tool_on = '';
-                }
-            }
-            $output .= '  <tr class="LC_info_row">'."\n".
-                       '   <td>'.$lt{$item}.'</td>'."\n".
-                       '  </tr>'."\n".
-                       &Apache::loncommon::start_data_table_row()."\n".
-                       '  <td>'.&mt('Availability determined currently from [_1] setting.',$custom_access).
-                       '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$lt{'avai'}.': '.
-                       ($curr_access?&mt('Yes'):&mt('No')).'</td>'."\n".
-                       &Apache::loncommon::end_data_table_row()."\n".
-                       &Apache::loncommon::start_data_table_row()."\n".
-                       '  <td><span class="LC_nobreak">'.$lt{'chse'}.': <label>'.
-                       '<input type="radio" name="custom'.$item.'" value="0" '.
-                       $cust_off.'/>'.$lt{'usde'}.'</label>&nbsp;&nbsp;&nbsp;'.
-                       '<label><input type="radio" name="custom'.$item.'" value="1" '.
-                       $cust_on.'/>'.$lt{'uscu'}.'</label>&nbsp;&nbsp;--&nbsp;&nbsp;'.
-                       $lt{'cusa'}.':&nbsp;<label>'.
-                       '<input type="radio" name="tools_'.$item.'" value="1" '.
-                       $tool_on.'/>'.&mt('On').'</label>&nbsp;<label>'.
-                       '<input type="radio" name="tools_'.$item.'" value="0" '.
-                       $tool_off.'/>'.&mt('Off').'</label></span></td>'."\n".
-                       &Apache::loncommon::end_data_table_row()."\n";
-        }
+        $output .= &build_tools_display($ccuname,$ccdomain,'tools');
     }
     if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
         $output .= '<tr class="LC_info_row">'."\n".
@@ -262,6 +211,76 @@
     return $output;
 }
 
+sub build_tools_display {
+    my ($ccuname,$ccdomain,$context) = @_;
+    my (@usertools,%userenv,$output);
+    my %lt = &Apache::lonlocal::texthash (
+                   'blog'       => "Personal User Blog",
+                   'aboutme'    => "Personal Information Page",
+                   'portfolio'  => "Personal User Portfolio",
+                   'avai'       => "Available",
+                   'cusa'       => "availability",
+                   'chse'       => "Change setting",
+                   'usde'       => "Use default",
+                   'uscu'       => "Use custom",
+                   'official'   => 'Can request creation of official courses',
+                   'unofficial' => 'Can request creation of unofficial courses',  
+    );
+    if ($context eq 'requestcourse') {
+        %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+                      'requestcourse.official','requestcourse.unofficial');
+        @usertools = ('official','unofficial');
+    } else {
+        %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+                          'tools.aboutme','tools.portfolio','tools.blog');
+        @usertools = ('aboutme','blog','portfolio');
+    }
+    foreach my $item (@usertools) {
+        my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off);
+        $cust_off = 'checked="checked" ';
+        $tool_on = 'checked="checked" ';
+        $curr_access =  
+            &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
+                                              $context);
+        if ($userenv{$context.'.'.$item} eq '') {
+            $custom_access = 'default';
+            if (!$curr_access) {
+                $tool_off = 'checked="checked" ';
+                $tool_on = '';
+            }
+        } else {
+            $custom_access = 'custom';
+            $cust_on = ' checked="checked" ';
+            $cust_off = '';
+            if ($userenv{$context.'.'.$item} == 0) {
+                $tool_off = 'checked="checked" ';
+                $tool_on = '';
+            }
+        }
+        $output .= '  <tr class="LC_info_row">'."\n".
+                   '   <td>'.$lt{$item}.'</td>'."\n".
+                   '  </tr>'."\n".
+                   &Apache::loncommon::start_data_table_row()."\n".
+                   '  <td>'.&mt('Availability determined currently from [_1] setting.',$custom_access).
+                   '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$lt{'avai'}.': '.
+                   ($curr_access?&mt('Yes'):&mt('No')).'</td>'."\n".
+                   &Apache::loncommon::end_data_table_row()."\n".
+                   &Apache::loncommon::start_data_table_row()."\n".
+                   '  <td><span class="LC_nobreak">'.$lt{'chse'}.': <label>'.
+                   '<input type="radio" name="custom'.$item.'" value="0" '.
+                   $cust_off.'/>'.$lt{'usde'}.'</label>&nbsp;&nbsp;&nbsp;'.
+                    '<label><input type="radio" name="custom'.$item.'" value="1" '.
+                   $cust_on.'/>'.$lt{'uscu'}.'</label>&nbsp;&nbsp;--&nbsp;&nbsp;'.
+                   $lt{'cusa'}.':&nbsp;<label>'.
+                   '<input type="radio" name="'.$context.'_'.$item.'" value="1" '.
+                   $tool_on.'/>'.&mt('On').'</label>&nbsp;<label>'.
+                   '<input type="radio" name="'.$context.'_'.$item.'" value="0" '.
+                   $tool_off.'/>'.&mt('Off').'</label></span></td>'."\n".
+                   &Apache::loncommon::end_data_table_row()."\n";
+    }
+    return $output;
+}
+
 # =================================================================== Phase one
 
 sub print_username_entry_form {
@@ -769,7 +788,7 @@
                     my $authtype = $rules->{$matchedrule}{'authtype'};
                     if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
                         $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
-                    } else {
+                    } else { 
                         my $authparm = $rules->{$matchedrule}{'authparm'};
                         $authmsg = $rules->{$matchedrule}{'authmsg'};
                         if ($authtype =~ /^krb(4|5)$/) {
@@ -847,9 +866,15 @@
         if ($showforceid) {
             $r->print(&Apache::lonuserutils::forceid_change($context));
         }
+        if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
+            $r->print('<h3>'.&mt('User Can Request Creation of Courses?').'</h3>'.
+                      &Apache::loncommon::start_data_table().
+                      &build_tools_display($ccuname,$ccdomain,'requestcourse').
+                      &Apache::loncommon::end_data_table());
+        }
         $r->print('</div>');
         my $user_auth_text =  &user_authentication($ccuname,$ccdomain,$formname);
-        my ($user_quota_text,$user_tools_text);
+        my ($user_quota_text,$user_tools_text,$user_reqcrs_text);
         if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
             (&Apache::lonnet::allowed('mut',$ccdomain))) {
             # Current user has quota modification privileges
@@ -1747,6 +1772,7 @@
 			 $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
     my (%alerts,%rulematch,%inst_results,%curr_rules);
     my @usertools = ('aboutme','blog','portfolio');
+    my @requestcourses = ('official','unofficial');
     if ($env{'form.makeuser'}) {
 	$r->print('<h3>'.&mt('Creating new account.').'</h3>');
         # Check for the authentication mode and password
@@ -1820,7 +1846,15 @@
             foreach my $item (@usertools) {
                 if ($env{'form.custom'.$item} == 1) {
                     $newcustom{$item} = $env{'form.tools_'.$item};
-                    $changed{$item} = &tool_admin($item,$newcustom{$item},\%changeHash);
+                    $changed{$item} = &tool_admin($item,$newcustom{$item},
+                                                 \%changeHash,'tools');
+                }
+            }
+            if (&Apache::lonnet::allowed('ccc',$env{'request.domain'})) {
+                foreach my $item (@requestcourses) {
+                    $newcustom{$item} = $env{'form.requestcourse_'.$item};
+                    $changed{$item} = &tool_admin($item,$newcustom{$item},
+                                                  \%changeHash,'requestcourse');
                 }
             }
             if (keys(%changed)) {
@@ -1867,7 +1901,8 @@
         my %userenv = &Apache::lonnet::get
             ('environment',['firstname','middlename','lastname','generation',
              'id','permanentemail','portfolioquota','inststatus','tools.aboutme',
-             'tools.blog','tools.portfolio'],
+             'tools.blog','tools.portfolio','requestcourse.official',
+             'requestcourse.unofficial'],
               $env{'form.ccdomain'},$env{'form.ccuname'});
         my ($tmp) = keys(%userenv);
         if ($tmp =~ /^(con_lost|error)/i) { 
@@ -1995,13 +2030,16 @@
             $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext);
         my ($defquota,$settingstatus) = 
             &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
-        my ($showquota,$showtools);
+        my ($showquota,$showtools,$showrequestcourses);
         if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
             $showquota = 1;
         }
         if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
             $showtools = 1;
         }
+        if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
+            $showrequestcourses = 1;
+        }
         my (%changeHash,%changed);
         $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
         if ($userenv{'portfolioquota'} ne '') {
@@ -2043,73 +2081,10 @@
         if ($newisdefault) {
             $newdefquotatext = &get_defaultquota_text($settingstatus);
         }
-        
-        foreach my $tool (@usertools) {
-            if ($userenv{'tools.'.$tool} ne '') {
-                $oldaccess{$tool} = &mt('custom');
-                if ($userenv{'tools_'.$tool}) {
-                    $oldaccesstext{$tool} = &mt("availability set to 'on'");
-                } else {
-                    $oldaccesstext{$tool} = &mt("availability set to 'off'");
-                }
-                $changeHash{'tools.'.$tool} = $userenv{'tools.'.$tool};
-                if ($env{'form.custom'.$tool} == 1) {
-                    if ($env{'form.tools_'.$tool} ne $userenv{'tools.'.$tool}) {
-                        $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool},
-                                                      \%changeHash);
-                        if ($changed{$tool}) {
-                            $newaccess{$tool} = &mt('custom');
-                            if ($env{'form.tools_'.$tool}) { 
-                                $newaccesstext{$tool} = &mt("availability set to 'on'");
-                            } else {
-                                $newaccesstext{$tool} = &mt("availability set to 'off'");
-                            }
-                        } else {
-                            $newaccess{$tool} = $oldaccess{$tool};
-                            if ($userenv{'tools.'.$tool}) {
-                                $newaccesstext{$tool} = &mt("availability set to 'on'");
-                            } else {
-                                $newaccesstext{$tool} = &mt("availability set to 'off'");
-                            }
-                        }
-                    } else {
-                        $newaccess{$tool} = $oldaccess{$tool};
-                        $newaccesstext{$tool} = $oldaccesstext{$tool};
-                    }
-                } else {
-                    $changed{$tool} = &tool_admin($tool,'',\%changeHash);
-                    if ($changed{$tool}) {
-                        $newaccess{$tool} = &mt('default');
-                    } else {
-                        $newaccess{$tool} = $oldaccess{$tool};
-                        if ($userenv{'tools.'.$tool}) {
-                             $newaccesstext{$tool} = &mt("availability set to 'on'");
-                        } else {
-                             $newaccesstext{$tool} = &mt("availability set to 'off'");
-                        }
-                    }
-                }
-            } else {
-                $oldaccess{$tool} = &mt('default');
-                if ($env{'form.custom'.$tool} == 1) {
-                    $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool},
-                                                  \%changeHash);
-                    if ($changed{$tool}) {
-                        $newaccess{$tool} = &mt('custom');
-                        if ($env{'form.tools_'.$tool}) {
-                            $newaccesstext{$tool} = &mt("availability set to 'on'");
-                        } else {
-                            $newaccesstext{$tool} = &mt("availability set to 'off'");
-                        }
-                    } else {
-                        $newaccess{$tool} = $oldaccess{$tool};
-                    }
-                } else {
-                    $newaccess{$tool} = $oldaccess{$tool};
-                }
-            }
-        }
-
+        &tool_changes('tools',\@usertools,\%oldaccess,\%oldaccesstext,\%userenv,
+                      \%changeHash,\%changed,\%newaccess,\%newaccesstext);
+        &tool_changes('requestcourse',\@requestcourses,\%oldaccess,\%oldaccesstext,
+                      \%userenv, \%changeHash,\%changed,\%newaccess,\%newaccesstext);
         if ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
             $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
             $env{'form.clastname'}   ne $userenv{'lastname'}   ||
@@ -2135,7 +2110,13 @@
                         ($env{'user.domain'} eq $env{'form.ccdomain'})) {
                         my %newenvhash;
                         foreach my $key (keys(%changed)) {
-                            if ($key ne 'quota') {
+                            if (($key eq 'official') || ($key eq 'unofficial')) {
+                                $newenvhash{'environment.canrequest.'.$key} =
+                                    $changeHash{'requestcourse.'.$key};
+                                $newenvhash{'environment.canrequest.'.$key} =
+                                    $changeHash{'requestcourse.'.$key};
+
+                            } elsif ($key ne 'quota') {
                                 $newenvhash{'environment.tools.'.$key} = 
                                     $changeHash{'tools.'.$key};
                                 $newenvhash{'environment.availabletools.'.$key} =
@@ -2168,19 +2149,21 @@
                 ((keys(%changed) > 0) && $chgresult eq 'ok')) {
             # Tell the user we changed the name
 		my %lt=&Apache::lonlocal::texthash(
-                             'uic'       => "User Information Changed",             
-                             'frst'      => "First",
-                             'mddl'      => "Middle",
-                             'lst'       => "Last",
-			     'gen'       => "Generation",
-                             'id'        => "Student/Employee ID",
-                             'mail'      => "Permanent E-mail",
-                             'disk'      => "Disk space allocated to portfolio files",
-                             'blog'      => "Blog Availability",
-                             'aboutme'   => "Home Page Availability",
-                             'portfolio' => "Portfolio Availability",
-                             'prvs'      => "Previous",
-                             'chto'      => "Changed To"
+                             'uic'        => "User Information Changed",             
+                             'frst'       => "First",
+                             'mddl'       => "Middle",
+                             'lst'        => "Last",
+			     'gen'        => "Generation",
+                             'id'         => "Student/Employee ID",
+                             'mail'       => "Permanent E-mail",
+                             'disk'       => "Disk space allocated to portfolio files",
+                             'blog'       => "Blog Availability",
+                             'aboutme'    => "Home Page Availability",
+                             'portfolio'  => "Portfolio Availability",
+                             'official'   => "Can Request Official Courses",
+                             'unofficial' => "Can Request Unofficial Courses",
+                             'prvs'       => "Previous",
+                             'chto'       => "Changed To"
 						   );
                 $r->print('<h4>'.$lt{'uic'}.'</h4>'.
                           &Apache::loncommon::start_data_table().
@@ -2194,6 +2177,12 @@
     <th>$lt{'id'}</th>
     <th>$lt{'mail'}</th>
 END
+                if ($showrequestcourses) {
+                    foreach my $item (@requestcourses) {
+                        $r->print("
+    <th>$lt{$item}</th>\n");
+                    }
+                }
                 if ($showquota) {
                     $r->print("
     <th>$lt{'disk'}</th>\n");
@@ -2215,6 +2204,12 @@
     <td>$userenv{'id'}</td>
     <td>$userenv{'permanentemail'} </td>
 END
+                if ($showrequestcourses) {
+                    foreach my $item (@requestcourses) {
+                        $r->print("
+    <td>$oldaccess{$item} $oldaccesstext{$item}</td>\n");
+                    }
+                }
                 if ($showquota) {
                     $r->print("
     <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
@@ -2236,6 +2231,12 @@
     <td>$env{'form.cid'} </td>
     <td>$env{'form.cpermanentemail'} </td>
 END
+                if ($showrequestcourses) {
+                    foreach my $item (@requestcourses) {
+                        $r->print("
+    <td>$newaccess{$item} $newaccesstext{$item} </td>\n");
+                    }
+                }
                 if ($showquota) {
                     $r->print("
     <td>$newportfolioquota Mb $newdefquotatext </td>\n");
@@ -2274,15 +2275,18 @@
                       $env{'form.ccdomain'}.'</span><br />');
             }
         }  else { # End of if ($env ... ) logic
-            # They did not want to change the users name, quota or tool availability,
+            # They did not want to change the users name, quota, tool availability,
+            # or ability to request creation of courses, 
             # but we can still tell them what the name and quota and availabilities are  
 	    my %lt=&Apache::lonlocal::texthash(
-                           'id'        => "Student/Employee ID",
-                           'mail'      => "Permanent e-mail",
-                           'disk'      => "Disk space allocated to user's portfolio files",
-                           'blog'      => "Blog Availability",
-                           'aboutme'   => "Home Page Availability",
-                           'portfolio' => "Portfolio Availability",
+                           'id'         => "Student/Employee ID",
+                           'mail'       => "Permanent e-mail",
+                           'disk'       => "Disk space allocated to user's portfolio files",
+                           'blog'       => "Blog Availability",
+                           'aboutme'    => "Home Page Availability",
+                           'portfolio'  => "Portfolio Availability",
+                           'official'   => "Can Request Official Courses",
+                           'unofficial' => "Can Request Unofficial Course",
 					       );
             $r->print(<<"END");
 <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
@@ -2291,6 +2295,12 @@
                 $r->print('<br />['.$lt{'mail'}.': '.
                           $userenv{'permanentemail'}.']');
             }
+            if ($showrequestcourses) {
+                foreach my $item (@requestcourses) {
+                    $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
+                              $newaccesstext{$item}.']'."\n");
+                }
+            }
             if ($showtools) {
                 foreach my $item (@usertools) {
                     $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
@@ -2369,6 +2379,83 @@
     $r->print(&Apache::loncommon::end_page());
 }
 
+sub tool_changes {
+    my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
+        $changed,$newaccess,$newaccesstext) = @_;
+    if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
+          (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
+          (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
+          (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
+        return;
+    }
+    foreach my $tool (@{$usertools}) {
+        if ($userenv->{$context.'.'.$tool} ne '') {
+            $oldaccess->{$tool} = &mt('custom');
+            if ($userenv->{$context.'.'.$tool}) {
+                $oldaccesstext->{$tool} = &mt("availability set to 'on'");
+            } else {
+                $oldaccesstext->{$tool} = &mt("availability set to 'off'");
+            }
+            $changeHash->{$context.'.'.$tool} = $userenv->{'tools.'.$tool};
+            if ($env{'form.custom'.$tool} == 1) {
+                if ($env{'form.'.$context.'_'.$tool} ne $userenv->{'tools.'.$tool}) {
+                    $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool},
+                                                  $changeHash,$context);
+                    if ($changed->{$tool}) {
+                        $newaccess->{$tool} = &mt('custom');
+                        if ($env{'form.'.$context.'_'.$tool}) {
+                            $newaccesstext->{$tool} = &mt("availability set to 'on'");
+                        } else {
+                            $newaccesstext->{$tool} = &mt("availability set to 'off'");
+                        }
+                    } else {
+                        $newaccess->{$tool} = $oldaccess->{$tool};
+                        if ($userenv->{$context.'.'.$tool}) {
+                            $newaccesstext->{$tool} = &mt("availability set to 'on'");
+                        } else {
+                            $newaccesstext->{$tool} = &mt("availability set to 'off'");
+                        }
+                    }
+                } else {
+                    $newaccess->{$tool} = $oldaccess->{$tool};
+                    $newaccesstext->{$tool} = $oldaccesstext->{$tool};
+                }
+            } else {
+                $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
+                if ($changed->{$tool}) {
+                    $newaccess->{$tool} = &mt('default');
+                } else {
+                    $newaccess->{$tool} = $oldaccess->{$tool};
+                    if ($userenv->{$context.'.'.$tool}) {
+                         $newaccesstext->{$tool} = &mt("availability set to 'on'");
+                    } else {
+                         $newaccesstext->{$tool} = &mt("availability set to 'off'");
+                    }
+                }
+            }
+        } else {
+            $oldaccess->{$tool} = &mt('default');
+            if ($env{'form.custom'.$tool} == 1) {
+                $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool},
+                                                $changeHash,$context);
+                if ($changed->{$tool}) {
+                    $newaccess->{$tool} = &mt('custom');
+                    if ($env{'form.'.$context.'_'.$tool}) {
+                        $newaccesstext->{$tool} = &mt("availability set to 'on'");
+                    } else {
+                        $newaccesstext->{$tool} = &mt("availability set to 'off'");
+                    }
+                } else {
+                    $newaccess->{$tool} = $oldaccess->{$tool};
+                }
+            } else {
+                $newaccess->{$tool} = $oldaccess->{$tool};
+            }
+        }
+    }
+    return;
+}
+
 sub update_roles {
     my ($r,$context) = @_;
     my $now=time;
@@ -2733,13 +2820,21 @@
 }
 
 sub tool_admin {
-    my ($tool,$settool,$changeHash) = @_;
-    my $toolchanged;
-    if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
+    my ($tool,$settool,$changeHash,$context) = @_;
+    my $canchange = 0; 
+    if ($context eq 'requestcourse') {
+        if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
+            $canchange = 1;
+        }
+    } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
         # Current user has quota modification privileges
+        $canchange = 1;
+    }
+    my $toolchanged;
+    if ($canchange) {
         if (ref($changeHash) eq 'HASH') {
             $toolchanged = 1;
-            $changeHash->{'tools.'.$tool} = $settool;
+            $changeHash->{$context.'.'.$tool} = $settool;
         }
     }
     return $toolchanged;

--raeburn1233533521--