--- loncom/interface/domainprefs.pm	2013/01/09 21:34:26	1.187
+++ loncom/interface/domainprefs.pm	2013/12/24 21:59:36	1.217
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.187 2013/01/09 21:34:26 raeburn Exp $
+# $Id: domainprefs.pm,v 1.217 2013/12/24 21:59:36 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -86,7 +86,7 @@ $dom,$settings,$rowtotal,$action.
 
 $dom is the domain, $settings is a reference to a hash of current settings for
 the current context, $rowtotal is a reference to the scalar used to record the 
-number of rows displayed on the page, and $action is the context (quotas,  
+number of rows displayed on the page, and $action is the context (quotas, 
 requestcourses or requestauthor).
 
 The print_quotas routine was orginally created to display/store information
@@ -94,7 +94,8 @@ about default quota sizes for portfolio
 institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
 but is now also used to manage availability of user tools: 
 i.e., blogs, aboutme page, and portfolios, and the course request tool,
-used by course owners to request creation of a course.
+used by course owners to request creation of a course, and to display/store
+default quota sizes for authoring spaces.
 
 Outputs: 1
 
@@ -102,8 +103,8 @@ $datatable  - HTML containing form eleme
 
 In the case of course requests, radio buttons are displayed for each institutional
 affiliate type (and also default, and _LC_adv) for each of the course types 
-(official, unofficial and community).  In each case the radio buttons allow the 
-selection of one of four values:
+(official, unofficial, community, and textbook).  In each case the radio buttons 
+allow the selection of one of four values:
 
 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
 which have the following effects:
@@ -254,11 +255,11 @@ sub handler {
                                   col2 => 'Value'}],
                     },
         'quotas' => 
-                    { text => 'Blogs, personal web pages, webDAV, portfolios',
+                    { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
                       help => 'Domain_Configuration_Quotas',
                       header => [{col1 => 'User affiliation',
                                   col2 => 'Available tools',
-                                  col3 => 'Portfolio quota',}],
+                                  col3 => 'Quotas, MB; (Authoring requires role)',}],
                     },
         'autoenroll' =>
                    { text => 'Auto-enrollment settings',
@@ -328,7 +329,9 @@ sub handler {
                   header => [{col1 => 'User affiliation',
                               col2 => 'Availability/Processing of requests',},
                              {col1 => 'Setting',
-                              col2 => 'Value'}],
+                              col2 => 'Value'},
+                             {col1 => 'Available textbooks',
+                              col2 => ''}],
                  },
         'requestauthor' =>
                  {text => 'Request authoring space',
@@ -415,9 +418,15 @@ sub handler {
     my $confname = $dom.'-domainconfig';
 
     if ($phase eq 'process') {
-        &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
+        my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
+                                                              \%prefs,\%domconfig,$confname,\@roles);
+        if (ref($result) eq 'HASH') {
+            $r->rflush();
+            &devalidate_remote_domconfs($dom,$result);
+        }
     } elsif ($phase eq 'display') {
-        my $js = &recaptcha_js();
+        my $js = &recaptcha_js().
+                 &credits_js();
         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
             my ($othertitle,$usertypes,$types) =
                 &Apache::loncommon::sorted_inst_types($dom);
@@ -427,6 +436,16 @@ sub handler {
                    &common_domprefs_js().
                    &Apache::loncommon::javascript_array_indexof();
         }
+        if (grep(/^requestcourses$/,@actions)) {
+            my $javascript_validations;
+            my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
+            $js .= <<END;
+<script type="text/javascript">
+$javascript_validations
+</script>
+$coursebrowserjs
+END
+        }
         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
     } else {
 # check if domconfig user exists for the domain.
@@ -436,7 +455,7 @@ sub handler {
         unless ($configuserok eq 'ok') {
             &Apache::lonconfigsettings::print_header($r,$phase,$context);
             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
-                           $confname).
+                          $confname).
                       '<br />'
             );
             if ($switchserver) {
@@ -496,21 +515,21 @@ sub handler {
 }
 
 sub process_changes {
-    my ($r,$dom,$confname,$action,$roles,$values) = @_;
+    my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
     my %domconfig;
     if (ref($values) eq 'HASH') {
         %domconfig = %{$values};
     }
     my $output;
     if ($action eq 'login') {
-        $output = &modify_login($r,$dom,$confname,%domconfig);
+        $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
     } elsif ($action eq 'rolecolors') {
         $output = &modify_rolecolors($r,$dom,$confname,$roles,
-                                     %domconfig);
+                                     $lastactref,%domconfig);
     } elsif ($action eq 'quotas') {
-        $output = &modify_quotas($dom,$action,%domconfig);
+        $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
     } elsif ($action eq 'autoenroll') {
-        $output = &modify_autoenroll($dom,%domconfig);
+        $output = &modify_autoenroll($dom,$lastactref,%domconfig);
     } elsif ($action eq 'autoupdate') {
         $output = &modify_autoupdate($dom,%domconfig);
     } elsif ($action eq 'autocreate') {
@@ -522,25 +541,25 @@ sub process_changes {
     } elsif ($action eq 'usermodification') {
         $output = &modify_usermodification($dom,%domconfig);
     } elsif ($action eq 'contacts') {
-        $output = &modify_contacts($dom,%domconfig);
+        $output = &modify_contacts($dom,$lastactref,%domconfig);
     } elsif ($action eq 'defaults') {
-        $output = &modify_defaults($dom,$r);
+        $output = &modify_defaults($dom,$lastactref,%domconfig);
     } elsif ($action eq 'scantron') {
-        $output = &modify_scantron($r,$dom,$confname,%domconfig);
+        $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
     } elsif ($action eq 'coursecategories') {
         $output = &modify_coursecategories($dom,%domconfig);
     } elsif ($action eq 'serverstatuses') {
         $output = &modify_serverstatuses($dom,%domconfig);
     } elsif ($action eq 'requestcourses') {
-        $output = &modify_quotas($dom,$action,%domconfig);
+        $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
     } elsif ($action eq 'requestauthor') {
-        $output = &modify_quotas($dom,$action,%domconfig);
+        $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
     } elsif ($action eq 'helpsettings') {
         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
     } elsif ($action eq 'coursedefaults') {
-        $output = &modify_coursedefaults($dom,%domconfig);
+        $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
     } elsif ($action eq 'usersessions') {
-        $output = &modify_usersessions($dom,%domconfig);
+        $output = &modify_usersessions($dom,$lastactref,%domconfig);
     } elsif ($action eq 'loadbalancing') {
         $output = &modify_loadbalancing($dom,%domconfig);
     }
@@ -569,7 +588,7 @@ sub print_config_box {
     if ($numheaders > 1) {
         my $colspan = '';
         my $rightcolspan = '';
-        if (($action eq 'rolecolors') || ($action eq 'coursecategories') || 
+        if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
             (($action eq 'login') && ($numheaders < 3))) {
             $colspan = ' colspan="2"';
         }
@@ -660,7 +679,7 @@ sub print_config_box {
             <table class="LC_nested">
              <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
-              <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
+              <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
             $rowtotal ++;
         } elsif ($action eq 'coursecategories') {
@@ -676,14 +695,25 @@ sub print_config_box {
             <table class="LC_nested">
              <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
-              <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
+              <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                 $rowtotal ++;
             } else {
                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
             }
         } elsif ($action eq 'requestcourses') {
-            $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
+            $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
+                       &print_studentcode($settings,\$rowtotal).'
+           </table>
+          </td>
+         </tr>
+         <tr>
+           <td>
+            <table class="LC_nested">
+             <tr class="LC_info_row">
+              <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
+              <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
+                       &print_textbookcourses($dom,$settings,\$rowtotal);
         } elsif ($action eq 'requestauthor') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
         } elsif ($action eq 'usersessions') {
@@ -788,7 +818,7 @@ sub print_config_box {
         } elsif ($action eq 'contacts') {
             $output .= &print_contacts($dom,$settings,\$rowtotal);
         } elsif ($action eq 'defaults') {
-            $output .= &print_defaults($dom,\$rowtotal);
+            $output .= &print_defaults($dom,$settings,\$rowtotal);
         } elsif ($action eq 'scantron') {
             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'serverstatuses') {
@@ -882,10 +912,11 @@ sub print_login {
     } elsif ($caller eq 'page') {
         my %defaultchecked = ( 
                                'coursecatalog' => 'on',
+                               'helpdesk'      => 'on',
                                'adminmail'     => 'off',
                                'newuser'       => 'off',
                              );
-        my @toggles = ('coursecatalog','adminmail','newuser');
+        my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
         my (%checkedon,%checkedoff);
         foreach my $item (@toggles) {
             if ($defaultchecked{$item} eq 'on') { 
@@ -1101,6 +1132,7 @@ sub login_choices {
         &Apache::lonlocal::texthash (
             coursecatalog => 'Display Course/Community Catalog link?',
             adminmail     => "Display Administrator's E-mail Address?",
+            helpdesk      => 'Display "Contact Helpdesk" link',
             disallowlogin => "Login page requests redirected",
             hostid        => "Server",
             server        => "Redirect to:",
@@ -1138,17 +1170,7 @@ sub print_rolecolors {
     my %designhash = &Apache::loncommon::get_domainconf($dom);
     my %defaultdesign = %Apache::loncommon::defaultdesign;
     my (%is_custom,%designs);
-    my %defaults = (
-                   img => $defaultdesign{$role.'.img'},
-                   font => $defaultdesign{$role.'.font'},
-		   fontmenu => $defaultdesign{$role.'.fontmenu'},
-                   );
-    foreach my $item (@bgs) {
-        $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
-    }
-    foreach my $item (@links) {
-        $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
-    }
+    my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
     if (ref($settings) eq 'HASH') {
         if (ref($settings->{$role}) eq 'HASH') {
             if ($settings->{$role}->{'img'} ne '') {
@@ -1209,6 +1231,44 @@ sub print_rolecolors {
     return $datatable;
 }
 
+sub role_defaults {
+    my ($role,$bgs,$links,$images,$logintext) = @_;
+    my %defaults;
+    unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
+        return %defaults;
+    }
+    my %defaultdesign = %Apache::loncommon::defaultdesign;
+    if ($role eq 'login') {
+        %defaults = (
+                       font => $defaultdesign{$role.'.font'},
+                    );
+        if (ref($logintext) eq 'ARRAY') {
+            foreach my $item (@{$logintext}) {
+                $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
+            }
+        }
+        foreach my $item (@{$images}) {
+            $defaults{'showlogo'}{$item} = 1;
+        }
+    } else {
+        %defaults = (
+                       img => $defaultdesign{$role.'.img'},
+                       font => $defaultdesign{$role.'.font'},
+                       fontmenu => $defaultdesign{$role.'.fontmenu'},
+                    );
+    }
+    foreach my $item (@{$bgs}) {
+        $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
+    }
+    foreach my $item (@{$links}) {
+        $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
+    }
+    foreach my $item (@{$images}) {
+        $defaults{$item} = $defaultdesign{$role.'.'.$item};
+    }
+    return %defaults;
+}
+
 sub display_color_options {
     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
@@ -1225,7 +1285,7 @@ sub display_color_options {
 
     $datatable .= '<td><span class="LC_nobreak">'.
                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
-                  ' value="'.$current_color.'" />&nbsp;'. 
+                  ' value="'.$current_color.'" />&nbsp;'.
                   '&nbsp;</td></tr>';
     unless ($role eq 'login') { 
         $datatable .= '<tr'.$css_class.'>'.
@@ -1235,7 +1295,7 @@ sub display_color_options {
         } else {
             $datatable .= '<td>&nbsp;</td>';
         }
-	$current_color = $designs->{'fontmenu'} ? 
+	$current_color = $designs->{'fontmenu'} ?
 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
         $datatable .= '<td><span class="LC_nobreak">'.
                       '<input class="colorchooser" type="text" size="10" name="'
@@ -1256,7 +1316,7 @@ sub display_color_options {
                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
                 $logincolors =
                     &login_text_colors($img,$role,$logintext,$phase,$choices,
-                                            $designs);
+                                       $designs,$defaults);
             } elsif ($img ne 'domlogo') {
                 $datatable.= &logo_display_options($img,$defaults,$designs);
             }
@@ -1335,12 +1395,12 @@ sub display_color_options {
                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
             } else {
-                $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
-                              &mt('Upload:');
+                $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
+                              &mt('Upload:').'<br />';
             }
         } else {
-            $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
-                          &mt('Upload:');
+            $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
+                          &mt('Upload:').'<br />';
         }
         if ($switchserver) {
             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
@@ -1370,7 +1430,7 @@ sub display_color_options {
                   '<table border="0"><tr>';
 
     foreach my $item (@{$bgs}) {
-        $datatable .= '<td align="center">';
+        $datatable .= '<td align="center">'.$choices->{$item};
 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
         if ($designs->{'bgs'}{$item}) {
             $datatable .= '&nbsp;';
@@ -1398,8 +1458,7 @@ sub display_color_options {
                   '<table border="0"><tr>';
     foreach my $item (@{$links}) {
 	my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
-        $datatable .= '<td align="center">'."\n";
-
+        $datatable .= '<td align="center">'.$choices->{$item}."\n";
         if ($designs->{'links'}{$item}) {
             $datatable.='&nbsp;';
         }
@@ -1457,17 +1516,13 @@ sub login_header_options  {
 }
 
 sub login_text_colors {
-    my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
+    my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
     my $color_menu = '<table border="0"><tr>';
     foreach my $item (@{$logintext}) {
-        my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
-        $color_menu .= '<td align="center">'.$link;
-        if ($designs->{'logintext'}{$item}) {
-            $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
-        }
-        $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
-                       $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
-                       '<td>&nbsp;</td>';
+        $color_menu .= '<td align="center">'.$choices->{$item};
+        my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
+        $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
+                      '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
     }
     $color_menu .= '</tr></table><br />';
     return $color_menu;
@@ -1499,20 +1554,12 @@ sub image_changes {
                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
         } else {
-            $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
+            $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
         }
     }
     return $output;
 }
 
-sub color_pick {
-    my ($phase,$role,$item,$desc,$curcol) = @_;
-    my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
-               "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
-               ');">'.$desc.'</a>';
-    return $link;
-}
-
 sub print_quotas {
     my ($dom,$settings,$rowtotal,$action) = @_;
     my $context;
@@ -1521,34 +1568,37 @@ sub print_quotas {
     } else {
         $context = $action;
     }
-    my ($datatable,$defaultquota,@usertools,@options,%validations);
+    my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
     my $typecount = 0;
     my ($css_class,%titles);
     if ($context eq 'requestcourses') {
-        @usertools = ('official','unofficial','community');
+        @usertools = ('official','unofficial','community','textbook');
         @options =('norequest','approval','validate','autolimit');
         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
         %titles = &courserequest_titles();
     } elsif ($context eq 'requestauthor') {
         @usertools = ('author');
         @options = ('norequest','approval','automatic');
-        %titles = &authorrequest_titles(); 
+        %titles = &authorrequest_titles();
     } else {
         @usertools = ('aboutme','blog','webdav','portfolio');
         %titles = &tool_titles();
     }
     if (ref($types) eq 'ARRAY') {
         foreach my $type (@{$types}) {
-            my $currdefquota;
+            my ($currdefquota,$currauthorquota);
             unless (($context eq 'requestcourses') ||
                     ($context eq 'requestauthor')) {
                 if (ref($settings) eq 'HASH') {
                     if (ref($settings->{defaultquota}) eq 'HASH') {
-                        $currdefquota = $settings->{defaultquota}->{$type}; 
+                        $currdefquota = $settings->{defaultquota}->{$type};
                     } else {
                         $currdefquota = $settings->{$type};
                     }
+                    if (ref($settings->{authorquota}) eq 'HASH') {
+                        $currauthorquota = $settings->{authorquota}->{$type};
+                    }
                 }
             }
             if (defined($usertypes->{$type})) {
@@ -1662,10 +1712,15 @@ sub print_quotas {
                 unless (($context eq 'requestcourses') ||
                         ($context eq 'requestauthor')) {
                     $datatable .= 
-                              '<td class="LC_right_item"><span class="LC_nobreak">'.
+                              '<td class="LC_right_item">'.
+                              '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
                               '<input type="text" name="quota_'.$type.
                               '" value="'.$currdefquota.
-                              '" size="5" /> Mb</span></td>';
+                              '" size="5" /></span>'.('&nbsp;' x 2).
+                              '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
+                              '<input type="text" name="authorquota_'.$type.
+                              '" value="'.$currauthorquota.
+                              '" size="5" /></span></td>';
                 }
                 $datatable .= '</tr>';
             }
@@ -1673,12 +1728,16 @@ sub print_quotas {
     }
     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
         $defaultquota = '20';
+        $authorquota = '500';
         if (ref($settings) eq 'HASH') {
             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                 $defaultquota = $settings->{'defaultquota'}->{'default'};
             } elsif (defined($settings->{'default'})) {
                 $defaultquota = $settings->{'default'};
             }
+            if (ref($settings->{'authorquota'}) eq 'HASH') {
+                $authorquota = $settings->{'authorquota'}->{'default'};
+            }
         }
     }
     $typecount ++;
@@ -1789,15 +1848,19 @@ sub print_quotas {
     }
     $datatable .= '</td>';
     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
-        $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
+        $datatable .= '<td class="LC_right_item">'.
+                      '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
                       '<input type="text" name="defaultquota" value="'.
-                      $defaultquota.'" size="5" /> Mb</span></td>';
+                      $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
+                      '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
+                      '<input type="text" name="authorquota" value="'.
+                      $authorquota.'" size="5" /></span></td>';
     }
     $datatable .= '</tr>';
     $typecount ++;
     $css_class = $typecount%2?' class="LC_odd_row"':'';
     $datatable .= '<tr'.$css_class.'>'.
-                  '<td>'.&mt('LON-CAPA Advanced Users').' ';
+                  '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
     if ($context eq 'requestcourses') {
         $datatable .= &mt('(overrides affiliation, if set)').
                       '</td>'.
@@ -1924,35 +1987,16 @@ sub print_quotas {
 
 sub print_requestmail {
     my ($dom,$action,$settings,$rowtotal) = @_;
-    my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
+    my ($now,$datatable,%currapp);
     $now = time;
-    $rows = 0;
-    %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
-    foreach my $server (keys(%dompersonnel)) {
-        foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
-            my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
-            if (!grep(/^$uname:$udom$/,@domcoord)) {
-                push(@domcoord,$uname.':'.$udom);
-            }
-        }
-    }
     if (ref($settings) eq 'HASH') {
         if (ref($settings->{'notify'}) eq 'HASH') {
             if ($settings->{'notify'}{'approval'} ne '') {
-               @currapproval = split(',',$settings->{'notify'}{'approval'});
-            }
-        }
-    }
-    if (@currapproval) {
-        foreach my $dc (@currapproval) {
-            unless (grep(/^\Q$dc\E$/,@domcoord)) {
-                push(@domcoord,$dc);
+               map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
             }
         }
     }
-    @domcoord = sort(@domcoord);
-    my $numinrow = 4;
-    my $numdc = @domcoord;
+    my $numinrow = 2;
     my $css_class = 'class="LC_odd_row"';
     my $text;
     if ($action eq 'requestcourses') {
@@ -1963,48 +2007,214 @@ sub print_requestmail {
     $datatable = '<tr '.$css_class.'>'.
                  ' <td>'.$text.'</td>'.
                  ' <td class="LC_left_item">';
-    if (@domcoord > 0) {
-        $datatable .= '<table>';
-        for (my $i=0; $i<$numdc; $i++) {
-            my $rem = $i%($numinrow);
-            if ($rem == 0) {
-                if ($i > 0) {
-                    $datatable .= '</tr>';
-                }
-                $datatable .= '<tr>';
-                $rows ++;
+    my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
+                                                 'reqapprovalnotify',%currapp);
+    if ($numdc > 0) {
+        $datatable .= $table;
+    } else {
+        $datatable .= &mt('There are no active Domain Coordinators');
+    }
+    $datatable .='</td></tr>';
+    $$rowtotal += $rows;
+    return $datatable;
+}
+
+sub print_studentcode {
+    my ($settings,$rowtotal) = @_;
+    my $rownum = 0; 
+    my %choices;
+    $choices{'uniquecode'} = &mt('Generate unique six character code as course identifier?');
+    my @toggles = ('uniquecode');
+    my %defaultchecked = ('uniquecode'  => 'off');
+    (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                               \%choices,$rownum);
+    $$rowtotal += $rownum;
+    return $reports;
+}
+
+sub print_textbookcourses {
+    my ($dom,$settings,$rowtotal) = @_;
+    my $rownum = 0;
+    my $css_class;
+    my $itemcount = 1;
+    my $maxnum = 0;
+    my $bookshash;
+    if (ref($settings) eq 'HASH') {
+        $bookshash = $settings->{'textbooks'};
+    }
+    my %ordered;
+    if (ref($bookshash) eq 'HASH') {
+        foreach my $item (keys(%{$bookshash})) {
+            if (ref($bookshash->{$item}) eq 'HASH') {
+                my $num = $bookshash->{$item}{'order'};
+                $ordered{$num} = $item;
             }
-            my $check = ' ';
-            if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
-                $check = ' checked="checked" ';
+        }
+    }
+    my $confname = $dom.'-domainconfig';
+    my $switchserver = &check_switchserver($dom,$confname);
+    my $maxnum = scalar(keys(%ordered));
+    my $datatable = &textbookcourses_javascript(\%ordered);
+    if (keys(%ordered)) {
+        my @items = sort { $a <=> $b } keys(%ordered);
+        for (my $i=0; $i<@items; $i++) {
+            $css_class = $itemcount%2?' class="LC_odd_row"':'';
+            my $key = $ordered{$items[$i]};
+            my %coursehash=&Apache::lonnet::coursedescription($key);
+            my $coursetitle = $coursehash{'description'};
+            my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
+            if (ref($bookshash->{$key}) eq 'HASH') {
+                $subject = $bookshash->{$key}->{'subject'};
+                $title = $bookshash->{$key}->{'title'};
+                $author = $bookshash->{$key}->{'author'};
+                $image = $bookshash->{$key}->{'image'};
+                if ($image ne '') {
+                    my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
+                    my $imagethumb = "$path/tn-".$imagefile;
+                    $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
+                }
+            }
+            my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
+            $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
+                         .'<select name="'.$key.'"'.$chgstr.'>';
+            for (my $k=0; $k<=$maxnum; $k++) {
+                my $vpos = $k+1;
+                my $selstr;
+                if ($k == $i) {
+                    $selstr = ' selected="selected" ';
+                }
+                $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
+            }
+            $datatable .= '</select>'.('&nbsp;'x2).
+                '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
+                &mt('Delete?').'</label></span></td>'.
+                '<td colspan="2">'.
+                '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
+                ('&nbsp;'x2).
+                '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
+                ('&nbsp;'x2).
+                '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
+                ('&nbsp;'x2).
+                '<span class="LC_nobreak">'.&mt('Thumbnail:');
+            if ($image) {
+                $datatable .= '<span class="LC_nobreak">'.
+                              $imgsrc.
+                              '<label><input type="checkbox" name="book_image_del"'.
+                              ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
+                              '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
             }
-            my ($uname,$udom) = split(':',$domcoord[$i]);
-            my $fullname = &Apache::loncommon::plainname($uname,$udom);
-            if ($i == $numdc-1) {
-                my $colsleft = $numinrow-$rem;
-                if ($colsleft > 1) {
-                    $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
-                } else {
-                    $datatable .= '<td class="LC_left_item">';
-                }
+            if ($switchserver) {
+                $datatable .= &mt('Upload to library server: [_1]',$switchserver);
             } else {
-                $datatable .= '<td class="LC_left_item">';
+                $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
             }
-            $datatable .= '<span class="LC_nobreak"><label>'.
-                          '<input type="checkbox" name="reqapprovalnotify" '.
-                          'value="'.$domcoord[$i].'"'.$check.'/>'.
-                          $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
+            $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
+                          '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
+                          $coursetitle.'</span></td></tr>'."\n";
+            $itemcount ++;
         }
-        $datatable .= '</tr></table>';
-    } else {
-        $datatable .= &mt('There are no active Domain Coordinators');
-        $rows ++;
     }
-    $datatable .='</td></tr>';
-    $$rowtotal += $rows;
+    $css_class = $itemcount%2?' class="LC_odd_row"':'';
+    my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
+    $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
+                  '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
+                  '<select name="addbook_pos"'.$chgstr.'>';
+    for (my $k=0; $k<$maxnum+1; $k++) {
+        my $vpos = $k+1;
+        my $selstr;
+        if ($k == $maxnum) {
+            $selstr = ' selected="selected" ';
+        }
+        $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
+    }
+    $datatable .= '</select>&nbsp;'."\n".
+                  '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
+                  '<td colspan="2">'.
+                  '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
+                  ('&nbsp;'x2).
+                  '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
+                  ('&nbsp;'x2).
+                  '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
+                  ('&nbsp;'x2).
+                  '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
+    if ($switchserver) {
+        $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+    } else {
+        $datatable .= '<input type="file" name="addbook_image" value="" />';
+    }
+    $datatable .= '</span>'."\n".
+                  '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
+                  &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
+                  '<input type="text" size="25" name="addbook_cnum" value="" />'.
+                  &Apache::loncommon::selectcourse_link
+                      ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
+                  '</span></td>'."\n".
+                  '</tr>'."\n";
+    $itemcount ++;
     return $datatable;
 }
 
+sub textbookcourses_javascript {
+    my ($textbooks) = @_;
+    return unless(ref($textbooks) eq 'HASH');
+    my $num = scalar(keys(%{$textbooks}));
+    my @jsarray;
+    foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
+        push(@jsarray,$textbooks->{$item});
+    }
+    my $jstext = '    var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
+    return <<"ENDSCRIPT";
+<script type="text/javascript">
+// <![CDATA[
+function reorderBooks(form,item) {
+    var changedVal;
+$jstext 
+    var newpos = 'addbook_pos';
+    var current = new Array;
+    var maxh = 1 + $num;
+    var current = new Array;
+    var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
+    if (item == newpos) {
+        changedVal = newitemVal;
+    } else {
+        changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
+        current[newitemVal] = newpos;
+    }
+    for (var i=0; i<textbooks.length; i++) {
+        var elementName = textbooks[i];
+        if (elementName != item) {
+            if (form.elements[elementName]) {
+                var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
+                current[currVal] = elementName;
+            }
+        }
+    }
+    var oldVal;
+    for (var j=0; j<maxh; j++) {
+        if (current[j] == undefined) {
+            oldVal = j;
+        }
+    }
+    if (oldVal < changedVal) {
+        for (var k=oldVal+1; k<=changedVal ; k++) {
+           var elementName = current[k];
+           form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
+        }
+    } else {
+        for (var k=changedVal; k<oldVal; k++) {
+            var elementName = current[k];
+            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
+        }
+    }
+    return;
+}
+
+// ]]>
+</script>
+
+ENDSCRIPT
+}
+
 sub print_autoenroll {
     my ($dom,$settings,$rowtotal) = @_;
     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
@@ -2153,8 +2363,7 @@ sub print_autoupdate {
 
 sub print_autocreate {
     my ($dom,$settings,$rowtotal) = @_;
-    my (%createon,%createoff);
-    my $curr_dc;
+    my (%createon,%createoff,%currhash);
     my @types = ('xml','req');
     if (ref($settings) eq 'HASH') {
         foreach my $item (@types) {
@@ -2167,7 +2376,9 @@ sub print_autocreate {
                 }
             }
         }
-        $curr_dc = $settings->{'xmldc'};
+        if ($settings->{'xmldc'} ne '') {
+            $currhash{$settings->{'xmldc'}} = 1;
+        }
     } else {
         foreach my $item (@types) {
             $createoff{$item} = ' checked="checked" ';
@@ -2175,6 +2386,7 @@ sub print_autocreate {
         }
     }
     $$rowtotal += 2;
+    my $numinrow = 2;
     my $datatable='<tr class="LC_odd_row">'.
                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
@@ -2189,15 +2401,16 @@ sub print_autocreate {
                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   '<label><input type="radio" name="autocreate_req"'.
                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
-    my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
+    my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
+                                                   'autocreate_xmldc',%currhash);
     if ($numdc > 1) {
         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                       &mt('Course creation processed as: (choose Dom. Coord.)').
                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
-        $$rowtotal ++ ;
     } else {
         $datatable .= $dctable.'</td></tr>';
     }
+    $$rowtotal += $rows;
     return $datatable;
 }
 
@@ -2320,7 +2533,7 @@ sub print_contacts {
     my @contacts = ('adminemail','supportemail');
     my (%checked,%to,%otheremails,%bccemails);
     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
-                    'requestsmail');
+                    'requestsmail','updatesmail','idconflictsmail');
     foreach my $type (@mailings) {
         $otheremails{$type} = '';
     }
@@ -2356,21 +2569,22 @@ sub print_contacts {
         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
+        $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
+        $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
     }
     my ($titles,$short_titles) = &contact_titles();
     my $rownum = 0;
     my $css_class;
     foreach my $item (@contacts) {
-        $rownum ++;
         $css_class = $rownum%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'. 
                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   '</span></td><td class="LC_right_item">'.
                   '<input type="text" name="'.$item.'" value="'.
                   $to{$item}.'" /></td></tr>';
+        $rownum ++;
     }
     foreach my $type (@mailings) {
-        $rownum ++;
         $css_class = $rownum%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'.
                       '<td><span class="LC_nobreak">'.
@@ -2393,7 +2607,21 @@ sub print_contacts {
                           'value="'.$bccemails{$type}.'"  />';
         }
         $datatable .= '</td></tr>'."\n";
+        $rownum ++;
     }
+    my %choices;
+    $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
+                                   &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                   &mt('LON-CAPA core group - MSU'),600,500));
+    $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
+                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                    &mt('LON-CAPA core group - MSU'),600,500));
+    my @toggles = ('reporterrors','reportupdates');
+    my %defaultchecked = ('reporterrors'  => 'on',
+                          'reportupdates' => 'on');
+    (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                               \%choices,$rownum);
+    $datatable .= $reports;
     $$rowtotal += $rownum;
     return $datatable;
 }
@@ -2415,7 +2643,8 @@ sub print_helpsettings {
 }
 
 sub radiobutton_prefs {
-    my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
+    my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
+        $additional) = @_;
     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                    (ref($choices) eq 'HASH'));
 
@@ -2441,17 +2670,22 @@ sub radiobutton_prefs {
             }
         }
     }
+    if ($onclick) {
+        $onclick = ' onclick="'.$onclick.'"';
+    }
     foreach my $item (@{$toggles}) {
         $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .=
-            '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
+            '<tr'.$css_class.'><td valign="top">'.
+            '<span class="LC_nobreak">'.$choices->{$item}.
             '</span></td>'.
             '<td class="LC_right_item"><span class="LC_nobreak">'.
             '<label><input type="radio" name="'.
-            $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
+            $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
-            $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
-            '</span></td>'.
+            $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
+            '</span>'.$additional.
+            '</td>'.
             '</tr>';
         $itemcount ++;
     }
@@ -2460,42 +2694,108 @@ sub radiobutton_prefs {
 
 sub print_coursedefaults {
     my ($position,$dom,$settings,$rowtotal) = @_;
-    my ($css_class,$datatable);
+    my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
     my $itemcount = 1;
+    my %choices =  &Apache::lonlocal::texthash (
+        canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
+        uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
+        anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
+        coursecredits        => 'Credits can be specified for courses',
+    );
+    my %staticdefaults = (
+                           anonsurvey_threshold => 10,
+                           uploadquota          => 500,
+                         );
     if ($position eq 'top') {
-        my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
-        %choices =
-            &Apache::lonlocal::texthash (
-                canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
-        );
         %defaultchecked = ('canuse_pdfforms' => 'off');
-        @toggles = ('canuse_pdfforms',);
+        @toggles = ('canuse_pdfforms');
         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                                                  \%choices,$itemcount);
-        $$rowtotal += $itemcount;
     } else {
         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-        my %choices =
-            &Apache::lonlocal::texthash (
-                anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
-        );
-        my $currdefresponder;
+        my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
+            %curruploadquota);
+        my $currusecredits = 0;
+        my @types = ('official','unofficial','community','textbook');
         if (ref($settings) eq 'HASH') {
             $currdefresponder = $settings->{'anonsurvey_threshold'};
+            if (ref($settings->{'uploadquota'}) eq 'HASH') {
+                foreach my $type (keys(%{$settings->{'uploadquota'}})) {
+                    $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
+                }
+            }
+            if (ref($settings->{'coursecredits'}) eq 'HASH') {
+                $def_official_credits = $settings->{'coursecredits'}->{'official'};
+                $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
+                $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
+                if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
+                    ($def_textbook_credits ne '')) {
+                    $currusecredits = 1;
+                }
+            }
         }
         if (!$currdefresponder) {
-            $currdefresponder = 10;
+            $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
         } elsif ($currdefresponder < 1) {
             $currdefresponder = 1;
         }
+        foreach my $type (@types) {
+            if ($curruploadquota{$type} eq '') {
+                $curruploadquota{$type} = $staticdefaults{'uploadquota'};
+            }
+        }
         $datatable .=
-               '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
+                '<tr'.$css_class.'><td><span class="LC_nobreak">'.
+                $choices{'anonsurvey_threshold'}.
                 '</span></td>'.
                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                 '<input type="text" name="anonsurvey_threshold"'.
                 ' value="'.$currdefresponder.'" size="5" /></span>'.
-                '</td></tr>';
+                '</td></tr>'."\n".
+                '<tr><td><span class="LC_nobreak">'.
+                $choices{'uploadquota'}.
+                '</span></td>'.
+                '<td align="right" class="LC_right_item">'.
+                '<table><tr>';
+        foreach my $type (@types) {
+            $datatable .= '<td align="center">'.&mt($type).'<br />'.
+                           '<input type="text" name="uploadquota_'.$type.'"'.
+                           ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
+        }
+        $datatable .= '</tr></table></td></tr>'."\n";
+        $itemcount += 2;
+        my $onclick = 'toggleCredits(this.form);';
+        my $display = 'none';
+        if ($currusecredits) {
+            $display = 'block';
+        }
+        my $additional = '<div id="credits" style="display: '.$display.'">'.
+                         '<span class="LC_nobreak">'.
+                         &mt('Default credits for official courses [_1]',
+                         '<input type="text" name="official_credits" value="'.
+                         $def_official_credits.'" size="3" />').
+                         '</span><br />'.
+                         '<span class="LC_nobreak">'.
+                         &mt('Default credits for unofficial courses [_1]',
+                         '<input type="text" name="unofficial_credits" value="'.
+                         $def_unofficial_credits.'" size="3" />').
+                         '</span><br />'.
+                         '<span class="LC_nobreak">'.
+                         &mt('Default credits for textbook courses [_1]',
+                         '<input type="text" name="textbook_credits" value="'.
+                         $def_textbook_credits.'" size="3" />').
+                         '</span></div>'."\n";
+        %defaultchecked = ('coursecredits' => 'off');
+        @toggles = ('coursecredits');
+        my $current = {
+                        'coursecredits' => $currusecredits,
+                      };
+        (my $table,$itemcount) =
+            &radiobutton_prefs($current,\@toggles,\%defaultchecked,
+                               \%choices,$itemcount,$onclick,$additional);
+        $datatable .= $table;
     }
+    $$rowtotal += $itemcount;
     return $datatable;
 }
 
@@ -2925,7 +3225,7 @@ sub print_loadbalancing {
     }
     my ($othertitle,$usertypes,$types) =
         &Apache::loncommon::sorted_inst_types($dom);
-    my $rownum = 6;
+    my $rownum = 8;
     if (ref($types) eq 'ARRAY') {
         $rownum += scalar(@{$types});
     }
@@ -2956,7 +3256,7 @@ sub print_loadbalancing {
                       '<td rowspan="'.$rownum.'" valign="top">'.
                       '<p>';
         if ($lonhost eq '') {
-            $datatable .= '<span class="LC_nobreak">'; 
+            $datatable .= '<span class="LC_nobreak">';
             if (keys(%currbalancer) > 0) {
                 $datatable .= &mt('Add balancer:');
             } else {
@@ -2972,7 +3272,7 @@ sub print_loadbalancing {
                 next if ($currbalancer{$server});
                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
             }
-            $datatable .= 
+            $datatable .=
                 '</select>'."\n".
                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
         } else {
@@ -3011,7 +3311,7 @@ sub print_loadbalancing {
                 if (exists($currbalancer{$spares[$i]})) {
                     $disabled = ' disabled="disabled"';
                 }
-                $targettable .= 
+                $targettable .=
                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                     '</span></label></td>';
@@ -3095,7 +3395,7 @@ sub loadbalancing_rules {
         $css_class,$balnum,$islast) = @_;
     my $output;
     my $num = 0;
-    my ($alltypes,$othertypes,$titles) = 
+    my ($alltypes,$othertypes,$titles) =
         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
         foreach my $type (@{$alltypes}) {
@@ -3104,7 +3404,7 @@ sub loadbalancing_rules {
             if (ref($currrules) eq 'HASH') {
                 $current = $currrules->{$type};
             }
-            if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
+            if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
                     $current = '';
                 }
@@ -3125,8 +3425,10 @@ sub loadbalancing_titles {
            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
            '_LC_external'    => &mt('Users not from [_1]',$intdom),
+           '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
+           '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
                      );
-    my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
+    my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
     if (ref($types) eq 'ARRAY') {
         unshift(@alltypes,@{$types},'default');
     }
@@ -3151,23 +3453,28 @@ sub loadbalancing_titles {
 sub loadbalance_rule_row {
     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
-    my @rulenames = ('default','homeserver');
+    my @rulenames;
     my %ruletitles = &offloadtype_text();
-    if ($type eq '_LC_external') {
-        push(@rulenames,'externalbalancer');
+    if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
+        @rulenames = ('balancer','offloadedto');
     } else {
-        push(@rulenames,'specific');
+        @rulenames = ('default','homeserver');
+        if ($type eq '_LC_external') {
+            push(@rulenames,'externalbalancer');
+        } else {
+            push(@rulenames,'specific');
+        }
+        push(@rulenames,'none');
     }
-    push(@rulenames,'none');
     my $style = $targets_div_style;
-    if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
+    if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
         $style = $homedom_div_style;
     }
     my $space;
     if ($islast && $num == 1) {
         $space = '<div display="inline-block">&nbsp;</div>';
     }
-    my $output = 
+    my $output =
         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
         '<td valaign="top">'.$space.
@@ -3187,7 +3494,7 @@ sub loadbalance_rule_row {
                 unless ($checked) {
                     $default = ' selected="selected"';
                 }
-                $extra = 
+                $extra =
                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
@@ -3225,6 +3532,8 @@ sub offloadtype_text {
            'externalbalancer' => "Offloads to Load Balancer in user's domain",
            'specific'         => 'Offloads to specific server',
            'none'             => 'No offload',
+           'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
+           'offloadedto'      => 'Session hosted on offload server, after re-authentication',
     );
     return %ruletitles;
 }
@@ -3246,6 +3555,8 @@ sub contact_titles {
                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
                    'requestsmail' => 'E-mail from course requests requiring approval',
+                   'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
+                   'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
                  );
     my %short_titles = &Apache::lonlocal::texthash (
                            adminemail   => 'Admin E-mail address',
@@ -3263,6 +3574,7 @@ sub tool_titles {
                      official   => 'Official courses (with institutional codes)',
                      unofficial => 'Unofficial courses',
                      community  => 'Communities',
+                     textbook   => 'Textbook courses',
                  );
     return %titles;
 }
@@ -3272,6 +3584,7 @@ sub courserequest_titles {
                                    official   => 'Official',
                                    unofficial => 'Unofficial',
                                    community  => 'Communities',
+                                   textbook   => 'Textbook',
                                    norequest  => 'Not allowed',
                                    approval   => 'Approval by Dom. Coord.',
                                    validate   => 'With validation',
@@ -3288,12 +3601,12 @@ sub authorrequest_titles {
                                    automatic  => 'Automatic approval',
                  );
     return %titles;
-} 
+}
 
 sub courserequest_conditions {
     my %conditions = &Apache::lonlocal::texthash (
        approval    => '(Processing of request subject to approval by Domain Coordinator).',
-       validate   => '(Processing of request subject to instittutional validation).',
+       validate   => '(Processing of request subject to institutional validation).',
                  );
     return %conditions;
 }
@@ -3527,9 +3840,9 @@ sub captcha_choice {
 #
 # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
 # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
-# servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu) 
+# servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
 # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
-#  
+#
     $output .= '</td></tr>'."\n".
                '<tr><td>'."\n".
                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
@@ -3676,10 +3989,18 @@ sub print_usermodification {
 }
 
 sub print_defaults {
-    my ($dom,$rowtotal) = @_;
+    my ($dom,$settings,$rowtotal) = @_;
     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                  'datelocale_def','portal_def');
-    my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+    my %defaults;
+    if (ref($settings) eq 'HASH') {
+        %defaults = %{$settings};
+    } else {
+        my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
+        foreach my $item (@items) {
+            $defaults{$item} = $domdefaults{$item};
+        }
+    }
     my $titles = &defaults_titles($dom);
     my $rownum = 0;
     my ($datatable,$css_class);
@@ -3703,7 +4024,7 @@ sub print_defaults {
             my %authnames = &authtype_names();
             foreach my $auth (@authtypes) {
                 my $checked = ' ';
-                if ($domdefaults{$item} eq $auth) {
+                if ($defaults{$item} eq $auth) {
                     $checked = ' checked="checked" ';
                 }
                 $datatable .= '<label><input type="radio" name="'.$item.
@@ -3712,15 +4033,15 @@ sub print_defaults {
             }
         } elsif ($item eq 'timezone_def') {
             my $includeempty = 1;
-            $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
+            $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
         } elsif ($item eq 'datelocale_def') {
             my $includeempty = 1;
-            $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
+            $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
         } elsif ($item eq 'lang_def') {
             my %langchoices = &get_languages_hash();
             $langchoices{''} = 'No language preference';
             %langchoices = &Apache::lonlocal::texthash(%langchoices);
-            $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
+            $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
                                                           \%langchoices);
         } else {
             my $size;
@@ -3728,7 +4049,7 @@ sub print_defaults {
                 $size = ' size="25"';
             }
             $datatable .= '<input type="text" name="'.$item.'" value="'.
-                          $domdefaults{$item}.'"'.$size.' />';
+                          $defaults{$item}.'"'.$size.' />';
         }
         $datatable .= '</td></tr>';
         $rownum ++;
@@ -3880,8 +4201,8 @@ sub print_scantronformat {
         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                       '<span class="LC_nobreak">';
         if ($scantronurl) {
-            $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
-                          &mt('Default bubblesheet format file').'</a>';
+            $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
+                                                         undef,undef,undef,undef,'background-color:#ffffff');
         } else {
             $datatable = &mt('File unavailable for display');
         }
@@ -3906,11 +4227,12 @@ sub print_scantronformat {
             } 
             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
         } elsif ($scantronurl) {
+            my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
+                                                       undef,undef,undef,undef,'background-color:#ffffff');
             $datatable .= '<td><span class="LC_nobreak">'.
-                          '<a href="'.$scantronurl.'" target="_blank">'.
-                          &mt('Custom bubblesheet format file').'</a><label>'.
-                          '<input type="checkbox" name="scantronformat_del"'.
-                          '" value="1" />'.&mt('Delete?').'</label></span></td>'.
+                          $link.
+                          '<label><input type="checkbox" name="scantronformat_del"'.
+                          ' value="1" />'.&mt('Delete?').'</label></span></td>'.
                           '<td><span class="LC_nobreak">&nbsp;'.
                           &mt('Replace:').'</span><br />';
         }
@@ -4064,7 +4386,7 @@ sub print_coursecategories {
                             }
                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                         }
-                        $datatable .= '</select></td><td>';
+                        $datatable .= '</select></span></td><td>';
                         if ($parent eq 'instcode' || $parent eq 'communities') {
                             $datatable .=  '<span class="LC_nobreak">'
                                            .$default_names{$parent}.'</span>';
@@ -4094,7 +4416,8 @@ sub print_coursecategories {
                             $datatable .= '</td>';
                         } else {
                             $datatable .= $parent
-                                          .'&nbsp;<label><input type="checkbox" name="deletecategory" '
+                                          .'&nbsp;<span class="LC_nobreak"><label>'
+                                          .'<input type="checkbox" name="deletecategory" '
                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                         }
                         my $depth = 1;
@@ -4208,7 +4531,7 @@ sub print_serverstatuses {
 
 sub serverstatus_pages {
     return ('userstatus','lonstatus','loncron','server-status','codeversions',
-            'clusterstatus','metadata_keywords','metadata_harvest',
+            'checksums','clusterstatus','metadata_keywords','metadata_harvest',
             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
 }
 
@@ -4366,7 +4689,7 @@ sub build_category_rows {
             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                 my $numchildren = @{$cats->[$depth]{$parent}};
                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
-                $text .= '<td><table class="LC_datatable">';
+                $text .= '<td><table class="LC_data_table">';
                 my ($idxnum,$parent_name,$parent_item);
                 my $higher = $depth - 1;
                 if ($higher == 0) {
@@ -4658,11 +4981,12 @@ sub usertype_update_row {
 }
 
 sub modify_login {
-    my ($r,$dom,$confname,%domconfig) = @_;
+    my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
     %title = ( coursecatalog => 'Display course catalog',
                adminmail => 'Display administrator E-mail address',
+               helpdesk  => 'Display "Contact Helpdesk" link',
                newuser => 'Link for visitors to create a user account',
                loginheader => 'Log-in box header');
     @offon = ('off','on');
@@ -4675,7 +4999,7 @@ sub modify_login {
     }
     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                                            \%domconfig,\%loginhash);
-    my @toggles = ('coursecatalog','adminmail','newuser');
+    my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
     foreach my $item (@toggles) {
         $loginhash{login}{$item} = $env{'form.'.$item};
     }
@@ -4837,7 +5161,7 @@ sub modify_login {
                     } else {
                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
-                        if ((grep(/^\Q$lang\E$/,@currlangs)) && 
+                        if ((grep(/^\Q$lang\E$/,@currlangs)) &&
                             (!grep(/^\Q$lang\E$/,@delurls))) {
 
                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
@@ -4863,9 +5187,10 @@ sub modify_login {
     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                                              $dom);
     if ($putresult eq 'ok') {
-        my @toggles = ('coursecatalog','adminmail','newuser');
+        my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
         my %defaultchecked = (
                     'coursecatalog' => 'on',
+                    'helpdesk'      => 'on',
                     'adminmail'     => 'off',
                     'newuser'       => 'off',
         );
@@ -4894,6 +5219,9 @@ sub modify_login {
         }
         if (keys(%changes) > 0 || $colchgtext) {
             &Apache::loncommon::devalidate_domconfig_cache($dom);
+            if (ref($lastactref) eq 'HASH') {
+                $lastactref->{'domainconfig'} = 1;
+            }
             $resulttext = &mt('Changes made:').'<ul>';
             foreach my $item (sort(keys(%changes))) {
                 if ($item eq 'loginvia') {
@@ -4953,7 +5281,7 @@ sub modify_login {
                     }
                 } elsif ($item eq 'captcha') {
                     if (ref($loginhash{'login'}) eq 'HASH') {
-                        my $chgtxt; 
+                        my $chgtxt;
                         if ($loginhash{'login'}{$item} eq 'notused') {
                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                         } else {
@@ -5014,7 +5342,7 @@ sub color_font_choices {
             links => "Link colors",
             images => "Images",
             font => "Font color",
-            fontmenu => "Font Menu",
+            fontmenu => "Font menu",
             pgbg => "Page",
             tabbg => "Header",
             sidebg => "Border",
@@ -5026,7 +5354,7 @@ sub color_font_choices {
 }
 
 sub modify_rolecolors {
-    my ($r,$dom,$confname,$roles,%domconfig) = @_;
+    my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
     my ($resulttext,%rolehash);
     $rolehash{'rolecolors'} = {};
     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
@@ -5041,6 +5369,9 @@ sub modify_rolecolors {
     if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {
             &Apache::loncommon::devalidate_domconfig_cache($dom);
+            if (ref($lastactref) eq 'HASH') {
+                $lastactref->{'domainconfig'} = 1;
+            }
             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                                              $rolehash{'rolecolors'});
         } else {
@@ -5066,24 +5397,45 @@ sub modify_colors {
     my @images;
     my $servadm = $r->dir_config('lonAdmEMail');
     my $errors;
+    my %defaults;
     foreach my $role (@{$roles}) {
         if ($role eq 'login') {
             %choices = &login_choices();
             @logintext = ('textcol','bgcol');
         } else {
             %choices = &color_font_choices();
-            $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
         }
         if ($role eq 'login') {
             @images = ('img','logo','domlogo','login');
             @bgs = ('pgbg','mainbg','sidebg');
         } else {
             @images = ('img');
-            @bgs = ('pgbg','tabbg','sidebg'); 
+            @bgs = ('pgbg','tabbg','sidebg');
+        }
+        my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
+        unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
+            $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
+        }
+        if ($role eq 'login') {
+            foreach my $item (@logintext) {
+                unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'logintext'}{$item}) {
+                    $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
+                }
+            }
+        } else {
+            unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
+                $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
+            }
         }
-        $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
-        foreach my $item (@bgs,@links,@logintext) {
-            $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
+        foreach my $item (@bgs) {
+            unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
+                $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
+            }
+        }
+        foreach my $item (@links) {
+            unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'links'}{$item}) {
+                $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
+            }
         }
         my ($configuserok,$author_ok,$switchserver) = 
             &config_check($dom,$confname,$servadm);
@@ -5431,7 +5783,7 @@ sub publishlogo {
 # See if there is anything left
     unless ($fname) { return ('error: no uploaded file'); }
     $fname="$subdir/$fname";
-    my $docroot=$r->dir_config('lonDocRoot'); 
+    my $docroot=$r->dir_config('lonDocRoot');
     my $filepath="$docroot/priv";
     my $relpath = "$dom/$confname";
     my ($fnamepath,$file,$fetchthumb);
@@ -5451,19 +5803,19 @@ sub publishlogo {
     if ($file=~/\.(\w+)$/ &&
         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
         $output = 
-            &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
+            &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
     } elsif ($file=~/\.(\w+)$/ &&
         !defined(&Apache::loncommon::fileembstyle($1))) {
         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
-        $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
+        $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
     } elsif (-d "$filepath/$file") {
-        $output = &mt('File name is a directory name - rename the file and re-upload');
+        $output = &mt('Filename is a directory name - rename the file and re-upload');
     } else {
         my $source = $filepath.'/'.$file;
         my $logfile;
         if (!open($logfile,">>$source".'.log')) {
-            return (&mt('No write permission to Construction Space'));
+            return (&mt('No write permission to Authoring Space'));
         }
         print $logfile
 "\n================= Publish ".localtime()." ================\n".
@@ -5700,21 +6052,25 @@ sub check_switchserver {
 }
 
 sub modify_quotas {
-    my ($dom,$action,%domconfig) = @_;
+    my ($r,$dom,$action,$lastactref,%domconfig) = @_;
     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
-        %limithash,$toolregexp,%conditions,$resulttext,%changes);
+        %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
+        $author_ok,$switchserver,$errors);
     if ($action eq 'quotas') {
         $context = 'tools'; 
     } else {
         $context = $action;
     }
     if ($context eq 'requestcourses') {
-        @usertools = ('official','unofficial','community');
+        @usertools = ('official','unofficial','community','textbook');
         @options =('norequest','approval','validate','autolimit');
         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
         %titles = &courserequest_titles();
         $toolregexp = join('|',@usertools);
         %conditions = &courserequest_conditions();
+        $confname = $dom.'-domainconfig';
+        my $servadm = $r->dir_config('lonAdmEMail');
+        ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
     } elsif ($context eq 'requestauthor') {
         @usertools = ('author');
         %titles = &authorrequest_titles();
@@ -5722,7 +6078,7 @@ sub modify_quotas {
         @usertools = ('aboutme','blog','webdav','portfolio');
         %titles = &tool_titles();
     }
-    my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
     foreach my $key (keys(%env)) {
         if ($context eq 'requestcourses') {
@@ -5742,8 +6098,9 @@ sub modify_quotas {
         } else {
             if ($key =~ /^form\.quota_(.+)$/) {
                 $confhash{'defaultquota'}{$1} = $env{$key};
-            }
-            if ($key =~ /^form\.\Q$context\E_(.+)$/) {
+            } elsif ($key =~ /^form\.authorquota_(.+)$/) {
+                $confhash{'authorquota'}{$1} = $env{$key};
+            } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
             }
         }
@@ -5752,6 +6109,34 @@ sub modify_quotas {
         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
         @approvalnotify = sort(@approvalnotify);
         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
+        if ($env{'form.uniquecode'}) {
+            $confhash{'uniquecode'} = 1;
+        } else {
+            $confhash{'uniquecode'} = '';
+        }
+        my ($newbook,@allpos);
+        if ($context eq 'requestcourses') {
+            if ($env{'form.addbook'}) {
+                if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
+                    ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
+                    if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
+                                                    $env{'form.addbook_cdom'}) eq 'no_host') {
+                        $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
+                                   '</span></li>';
+                    } else {
+                        $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
+                        my $position = $env{'form.addbook_pos'};
+                        $position =~ s/\D+//g;
+                        if ($position ne '') {
+                            $allpos[$position] = $newbook;
+                        }
+                    }
+                } else {
+                    $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
+                               '</span></li>';
+                }
+            }
+        }
         if (ref($domconfig{$action}) eq 'HASH') {
             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
@@ -5762,13 +6147,124 @@ sub modify_quotas {
                     $changes{'notify'}{'approval'} = 1;
                 }
             }
+            if ($domconfig{$action}{'uniquecode'}) {
+                unless ($confhash{'uniquecode'}) {
+                    $changes{'uniquecode'} = 1;
+                }
+            } else {
+                if ($confhash{'uniquecode'}) {
+                    $changes{'uniquecode'} = 1;
+                }
+            }
+            if ($context eq 'requestcourses') {
+                if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
+                    my %deletions;
+                    my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
+                    if (@todelete) {
+                        map { $deletions{$_} = 1; } @todelete;
+                    }
+                    my %imgdeletions;
+                    my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
+                    if (@todeleteimages) {
+                        map { $imgdeletions{$_} = 1; } @todeleteimages;
+                    }
+                    my $maxnum = $env{'form.book_maxnum'};
+                    for (my $i=0; $i<=$maxnum; $i++) {
+                        my $key = $env{'form.book_id_'.$i};
+                        if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
+                            if ($deletions{$key}) {
+                                if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
+                                    #FIXME need to obsolete item in RES space
+                                }
+                                next;
+                            } else {
+                                my $newpos = $env{'form.'.$key};
+                                $newpos =~ s/\D+//g;
+                                foreach my $item ('subject','title','author') {
+                                    $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
+                                    if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
+                                        $changes{'textbooks'}{$key} = 1;
+                                    }
+                                }
+                                $allpos[$newpos] = $key;
+                            }
+                            if ($imgdeletions{$key}) {
+                                $changes{'textbooks'}{$key} = 1;
+                                #FIXME need to obsolete item in RES space
+                            } elsif ($env{'form.book_image_'.$i.'.filename'}) {
+                                my ($cdom,$cnum) = split(/_/,$key);
+                                my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
+                                                                              $cdom,$cnum,$configuserok,
+                                                                              $switchserver,$author_ok);
+                                if ($imgurl) {
+                                    $confhash{'textbooks'}{$key}{'image'} = $imgurl;
+                                    $changes{'textbooks'}{$key} = 1; 
+                                }
+                                if ($error) {
+                                    &Apache::lonnet::logthis($error);
+                                    $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+                                } 
+                            } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
+                                $confhash{'textbooks'}{$key}{'image'} = 
+                                    $domconfig{$action}{'textbooks'}{$key}{'image'};
+                            }
+                        }
+                    }
+                }
+            }
         } else {
             if ($confhash{'notify'}{'approval'}) {
                 $changes{'notify'}{'approval'} = 1;
             }
+            if ($confhash{'uniquecode'}) {
+                $changes{'uniquecode'} = 1;
+            }
+        }
+        if ($context eq 'requestcourses') {
+            if ($newbook) {
+                $changes{'textbooks'}{$newbook} = 1;
+                foreach my $item ('subject','title','author') {
+                    $env{'form.addbook_'.$item} =~ s/(`)/'/g;
+                    if ($env{'form.addbook_'.$item}) {
+                        $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
+                    }
+                }
+                if ($env{'form.addbook_image.filename'} ne '') {
+                    my ($cdom,$cnum) = split(/_/,$newbook);
+                    my ($imageurl,$error) = 
+                        &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
+                                                $switchserver,$author_ok);
+                    if ($imageurl) {
+                        $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
+                    }
+                    if ($error) {
+                        &Apache::lonnet::logthis($error);
+                        $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+                    }
+                }
+            }
+            if (@allpos > 0) {
+                my $idx = 0;
+                foreach my $item (@allpos) {
+                    if ($item ne '') {
+                        $confhash{'textbooks'}{$item}{'order'} = $idx;
+                        if (ref($domconfig{$action}) eq 'HASH') {
+                            if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
+                                if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
+                                    if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
+                                        $changes{'textbooks'}{$item} = 1;
+                                    }
+                                }
+                            }
+                        }
+                        $idx ++;
+                    }
+                }
+            }
         }
     } else {
         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
+        $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
     }
     foreach my $item (@usertools) {
         foreach my $type (@{$types},'default','_LC_adv') {
@@ -5856,6 +6352,17 @@ sub modify_quotas {
                     }
                 }
             }
+            if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
+                foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
+                    if (exists($confhash{'authorquota'}{$key})) {
+                        if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
+                            $changes{'authorquota'}{$key} = 1;
+                        }
+                    } else {
+                        $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
+                    }
+                }
+            }
         }
         if (ref($confhash{'defaultquota'}) eq 'HASH') {
             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
@@ -5874,13 +6381,30 @@ sub modify_quotas {
                 }
             }
         }
+        if (ref($confhash{'authorquota'}) eq 'HASH') {
+            foreach my $key (keys(%{$confhash{'authorquota'}})) {
+                if (ref($domconfig{'quotas'}) eq 'HASH') {
+                    if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
+                        if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
+                            $changes{'authorquota'}{$key} = 1;
+                        }
+                    } else {
+                        $changes{'authorquota'}{$key} = 1;
+                    }
+                } else {
+                    $changes{'authorquota'}{$key} = 1;
+                }
+            }
+        }
     }
 
     if ($context eq 'requestauthor') {
         $domdefaults{'requestauthor'} = \%confhash;
     } else {
         foreach my $key (keys(%confhash)) {
-            $domdefaults{$key} = $confhash{$key};
+            unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
+                $domdefaults{$key} = $confhash{$key};
+            }
         }
     }
 
@@ -5893,9 +6417,11 @@ sub modify_quotas {
         if (keys(%changes) > 0) {
             my $cachetime = 24*60*60;
             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
-
+            if (ref($lastactref) eq 'HASH') {
+                $lastactref->{'domdefaults'} = 1;
+            }
             $resulttext = &mt('Changes made:').'<ul>';
-            unless (($context eq 'requestcourses') || 
+            unless (($context eq 'requestcourses') ||
                     ($context eq 'requestauthor')) {
                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
@@ -5905,7 +6431,20 @@ sub modify_quotas {
                             if ($type eq 'default') {
                                 $typetitle = $othertitle;
                             }
-                            $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
+                            $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
+                        }
+                    }
+                    $resulttext .= '</ul></li>';
+                }
+                if (ref($changes{'authorquota'}) eq 'HASH') {
+                    $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
+                    foreach my $type (@{$types},'default') {
+                        if (defined($changes{'authorquota'}{$type})) {
+                            my $typetitle = $usertypes->{$type};
+                            if ($type eq 'default') {
+                                $typetitle = $othertitle;
+                            }
+                            $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
                         }
                     }
                     $resulttext .= '</ul></li>';
@@ -5916,7 +6455,7 @@ sub modify_quotas {
                 my (%haschgs,%inconf);
                 if ($context eq 'requestauthor') {
                     %haschgs = %changes;
-                    %inconf = %confhash; 
+                    %inconf = %confhash;
                 } else {
                     if (ref($changes{$item}) eq 'HASH') {
                         %haschgs = %{$changes{$item}};
@@ -5930,7 +6469,7 @@ sub modify_quotas {
                         &Apache::lonnet::usertools_access($env{'user.name'},
                                                           $env{'user.domain'},
                                                           $item,'reload',$context);
-                    if (($context eq 'requestcourses') || 
+                    if (($context eq 'requestcourses') ||
                         ($context eq 'requestauthor')) {
                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                             $newenv{'environment.canrequest.'.$item} = $newacc;
@@ -6002,6 +6541,37 @@ sub modify_quotas {
                     }
                 }
             }
+            if ($action eq 'requestcourses') {
+                my @offon = ('off','on');
+                if ($changes{'uniquecode'}) {
+                    $resulttext .= '<li>'.
+                                   &mt('Generation of six character code as course identifier for distribution to students set to '.
+                                       $offon[$env{'form.uniquecode'}]).
+                                   '</li>';
+                }
+                if (ref($changes{'textbooks'}) eq 'HASH') {
+                    $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
+                    foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
+                        my %coursehash = &Apache::lonnet::coursedescription($key);
+                        my $coursetitle = $coursehash{'description'};
+                        my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
+                        $resulttext .= '<li>';
+                        foreach my $item ('subject','title','author') {
+                            my $name = $item.':';
+                            $name =~ s/^(\w)/\U$1/;
+                            $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
+                        }
+                        $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
+                        if ($confhash{'textbooks'}{$key}{'image'}) {
+                            $resulttext .= ' '.&mt('Image: [_1]',
+                                               '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
+                                               ' alt="Textbook cover" />').'<br />';
+                        }
+                        $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
+                    }
+                    $resulttext .= '</ul></li>';
+                }
+            }
             $resulttext .= '</ul>';
             if (keys(%newenv)) {
                 &Apache::lonnet::appenv(\%newenv);
@@ -6019,11 +6589,42 @@ sub modify_quotas {
         $resulttext = '<span class="LC_error">'.
 	    &mt('An error occurred: [_1]',$putresult).'</span>';
     }
+    if ($errors) {
+        $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
+                       '<ul>'.$errors.'</ul></p>';
+    }
     return $resulttext;
 }
 
+sub process_textbook_image {
+    my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
+    my $filename = $env{'form.'.$caller.'.filename'};
+    my ($error,$url);
+    my ($width,$height) = (50,50);
+    if ($configuserok eq 'ok') {
+        if ($switchserver) {
+            $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
+                         $switchserver);
+        } elsif ($author_ok eq 'ok') {
+            my ($result,$imageurl) =
+                &publishlogo($r,'upload',$caller,$dom,$confname,
+                             "textbooks/$dom/$cnum/cover",$width,$height);
+            if ($result eq 'ok') {
+                $url = $imageurl;
+            } else {
+                $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
+            }
+        } else {
+            $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$author_ok);
+        }
+    } else {
+        $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$configuserok);
+    }
+    return ($url,$error);
+}
+
 sub modify_autoenroll {
-    my ($dom,%domconfig) = @_;
+    my ($dom,$lastactref,%domconfig) = @_;
     my ($resulttext,%changes);
     my %currautoenroll;
     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
@@ -6091,6 +6692,9 @@ sub modify_autoenroll {
             if ($changes{'coowners'}) {
                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                 &Apache::loncommon::devalidate_domconfig_cache($dom);
+                if (ref($lastactref) eq 'HASH') {
+                    $lastactref->{'domainconfig'} = 1;
+                }
             }
             $resulttext .= '</ul>';
         } else {
@@ -6496,7 +7100,7 @@ sub modify_directorysrch {
                         } else {
                             $chgtext =~ s/\; $//;
                         }
-                        $resulttext .= 
+                        $resulttext .=
                             '<li>'.
                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
@@ -6542,7 +7146,7 @@ sub modify_directorysrch {
 }
 
 sub modify_contacts {
-    my ($dom,%domconfig) = @_;
+    my ($dom,$lastactref,%domconfig) = @_;
     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
     if (ref($domconfig{'contacts'}) eq 'HASH') {
         foreach my $key (keys(%{$domconfig{'contacts'}})) {
@@ -6552,7 +7156,8 @@ sub modify_contacts {
     my (%others,%to,%bcc);
     my @contacts = ('supportemail','adminemail');
     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
-                    'requestsmail');
+                    'requestsmail','updatesmail','idconflictsmail');
+    my @toggles = ('reporterrors','reportupdates');
     foreach my $type (@mailings) {
         @{$newsetting{$type}} = 
             &Apache::loncommon::get_env_multiple('form.'.$type);
@@ -6574,6 +7179,11 @@ sub modify_contacts {
         $to{$item} = $env{'form.'.$item};
         $contacts_hash{'contacts'}{$item} = $to{$item};
     }
+    foreach my $item (@toggles) {
+        if ($env{'form.'.$item} =~ /^(0|1)$/) {
+            $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
+        }
+    }
     if (keys(%currsetting) > 0) {
         foreach my $item (@contacts) {
             if ($to{$item} ne $currsetting{$item}) {
@@ -6608,10 +7218,11 @@ sub modify_contacts {
         $default{'helpdeskmail'} = 'supportemail';
         $default{'lonstatusmail'} = 'adminemail';
         $default{'requestsmail'} = 'adminemail';
+        $default{'updatesmail'} = 'adminemail';
         foreach my $item (@contacts) {
            if ($to{$item} ne $default{$item}) {
               $changes{$item} = 1;
-           } 
+           }
         }
         foreach my $type (@mailings) {
             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
@@ -6628,10 +7239,22 @@ sub modify_contacts {
             }
         }
     }
+    foreach my $item (@toggles) {
+        if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
+            $changes{$item} = 1;
+        } elsif ((!$env{'form.'.$item}) &&
+                 (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
+            $changes{$item} = 1;
+        }
+    }
     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                                              $dom);
     if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {
+            &Apache::loncommon::devalidate_domconfig_cache($dom);
+            if (ref($lastactref) eq 'HASH') {
+                $lastactref->{'domainconfig'} = 1;
+            }
             my ($titles,$short_titles)  = &contact_titles();
             $resulttext = &mt('Changes made:').'<ul>';
             foreach my $item (@contacts) {
@@ -6662,6 +7285,23 @@ sub modify_contacts {
                     $resulttext .= '</li>';
                 }
             }
+            my @offon = ('off','on');
+            if ($changes{'reporterrors'}) {
+                $resulttext .= '<li>'.
+                               &mt('E-mail error reports to [_1] set to "'.
+                                   $offon[$env{'form.reporterrors'}].'".',
+                                   &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                       &mt('LON-CAPA core group - MSU'),600,500)).
+                               '</li>';
+            }
+            if ($changes{'reportupdates'}) {
+                $resulttext .= '<li>'.
+                                &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
+                                    $offon[$env{'form.reportupdates'}].'".',
+                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                        &mt('LON-CAPA core group - MSU'),600,500)).
+                                '</li>';
+            }
             $resulttext .= '</ul>';
         } else {
             $resulttext = &mt('No changes made to contact information');
@@ -6689,7 +7329,7 @@ sub modify_usercreation {
     foreach my $item(@contexts) {
         if ($item eq 'selfcreate') {
             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
-            my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+            my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                     if (grep(/^login$/,@{$cancreate{$item}})) {
@@ -6962,7 +7602,7 @@ sub modify_usercreation {
                             if ($captchas{$cancreate{$type}}) {
                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
                             } else {
-                                $chgtext .= &mt('Validation for self-creation screen set to unknown type.'); 
+                                $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
                             }
                         }
                     } elsif ($type eq 'recaptchakeys') {
@@ -7090,7 +7730,7 @@ sub process_captcha {
         $newsettings->{'captcha'} = 'original';
     }
     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
-        if ($container eq 'cancreate') { 
+        if ($container eq 'cancreate') {
             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                 push(@{$changes->{'cancreate'}},'captcha');
             } elsif (!defined($changes->{'cancreate'})) {
@@ -7129,7 +7769,7 @@ sub process_captcha {
                 $changes->{'cancreate'} = ['recaptchakeys'];
             }
         } else {
-            $changes->{'recaptchakeys'} = 1; 
+            $changes->{'recaptchakeys'} = 1;
         }
     }
     return;
@@ -7256,9 +7896,9 @@ sub modify_usermodification {
 }
 
 sub modify_defaults {
-    my ($dom,$r) = @_;
+    my ($dom,$lastactref,%domconfig) = @_;
     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
-    my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
     my @authtypes = ('internal','krb4','krb5','localauth');
     foreach my $item (@items) {
@@ -7318,7 +7958,7 @@ sub modify_defaults {
     if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {
             $resulttext = &mt('Changes made:').'<ul>';
-            my $version = $r->dir_config('lonVersion');
+            my $version = &Apache::lonnet::get_server_loncaparev($dom);
             my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
             foreach my $item (sort(keys(%changes))) {
                 my $value = $env{'form.'.$item};
@@ -7341,9 +7981,21 @@ sub modify_defaults {
             $mailmsgtext .= "\n";
             my $cachetime = 24*60*60;
             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+            if (ref($lastactref) eq 'HASH') {
+                $lastactref->{'domdefaults'} = 1;
+            }
             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
-                my $sysmail = $r->dir_config('lonSysEMail');
-                &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
+                my $notify = 1;
+                if (ref($domconfig{'contacts'}) eq 'HASH') {
+                    if ($domconfig{'contacts'}{'reportupdates'} == 0) {
+                        $notify = 0;
+                    }
+                }
+                if ($notify) {
+                    &Apache::lonmsg::sendemail('installrecord@loncapa.org',
+                                               "LON-CAPA Domain Settings Change - $dom",
+                                               $mailmsgtext);
+                }
             }
         } else {
             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
@@ -7363,7 +8015,7 @@ sub modify_defaults {
 }
 
 sub modify_scantron {
-    my ($r,$dom,$confname,%domconfig) = @_;
+    my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
     my ($resulttext,%confhash,%changes,$errors);
     my $custom = 'custom.tab';
     my $default = 'default.tab';
@@ -7424,6 +8076,9 @@ sub modify_scantron {
                 }
                 $resulttext .= '</ul>';
                 &Apache::loncommon::devalidate_domconfig_cache($dom);
+                if (ref($lastactref) eq 'HASH') {
+                    $lastactref->{'domainconfig'} = 1;
+                }
             } else {
                 $resulttext = &mt('No changes made to bubblesheet format file');
             }
@@ -7814,7 +8469,7 @@ sub modify_helpsettings {
                     $changes{$item} = 1;
                 }
             }
-            if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { 
+            if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
             }
         }
@@ -7847,11 +8502,17 @@ sub modify_helpsettings {
 }
 
 sub modify_coursedefaults {
-    my ($dom,%domconfig) = @_;
+    my ($dom,$lastactref,%domconfig) = @_;
     my ($resulttext,$errors,%changes,%defaultshash);
     my %defaultchecked = ('canuse_pdfforms' => 'off');
-    my @offon = ('off','on');
     my @toggles = ('canuse_pdfforms');
+    my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
+                   'uploadquota_community','uploadquota_textbook');
+    my @types = ('official','unofficial','community','textbook');
+    my %staticdefaults = (
+                           anonsurvey_threshold => 10,
+                           uploadquota          => 500,
+                         );
 
     $defaultshash{'coursedefaults'} = {};
 
@@ -7867,7 +8528,7 @@ sub modify_coursedefaults {
                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                     ($env{'form.'.$item} eq '0')) {
                     $changes{$item} = 1;
-                } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
+                } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                     $changes{$item} = 1;
                 }
             } elsif ($defaultchecked{$item} eq 'off') {
@@ -7880,28 +8541,90 @@ sub modify_coursedefaults {
             }
             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
         }
-        my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
-        my $newdefresponder = $env{'form.anonsurvey_threshold'};
-        $newdefresponder =~ s/\D//g;
-        if ($newdefresponder eq '' || $newdefresponder < 1) {
-            $newdefresponder = 1;
-        }
-        $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
-        if ($currdefresponder ne $newdefresponder) {
-            unless ($currdefresponder eq '' && $newdefresponder == 10) {
-                $changes{'anonsurvey_threshold'} = 1;
+        foreach my $item (@numbers) {
+            my ($currdef,$newdef);
+            $newdef = $env{'form.'.$item};
+            if ($item eq 'anonsurvey_threshold') {
+                $currdef = $domconfig{'coursedefaults'}{$item};
+                $newdef =~ s/\D//g;
+                if ($newdef eq '' || $newdef < 1) {
+                    $newdef = 1;
+                }
+                $defaultshash{'coursedefaults'}{$item} = $newdef;
+            } else {
+                my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
+                if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
+                    $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
+                }
+                $newdef =~ s/[^\w.\-]//g;
+                $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
+            }
+            if ($currdef ne $newdef) {
+                my $staticdef;
+                if ($item eq 'anonsurvey_threshold') {
+                    unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
+                        $changes{$item} = 1;
+                    }
+                } else {
+                    unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
+                        $changes{'uploadquota'} = 1;
+                    }
+                }
             }
         }
+        my $officialcreds = $env{'form.official_credits'};
+        $officialcreds =~ s/[^\d.]+//g;
+        my $unofficialcreds = $env{'form.unofficial_credits'};
+        $unofficialcreds =~ s/[^\d.]+//g;
+        my $textbookcreds = $env{'form.textbook_credits'};
+        $textbookcreds =~ s/[^\d.]+//g;
+        if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
+                ($env{'form.coursecredits'} eq '1')) {
+                $changes{'coursecredits'} = 1;
+        } else {
+            if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
+                ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
+                ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
+                $changes{'coursecredits'} = 1;
+            }
+        }
+        $defaultshash{'coursedefaults'}{'coursecredits'} = {
+            official   => $officialcreds,
+            unofficial => $unofficialcreds,
+            textbook   => $textbookcreds,
+        }
     }
     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                                              $dom);
     if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {
-            if ($changes{'canuse_pdfforms'}) {
-                my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
-                $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
+            my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
+            if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
+                if ($changes{'canuse_pdfforms'}) {
+                    $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
+                }
+                if ($changes{'coursecredits'}) {
+                    if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+                        $domdefaults{'officialcredits'} =
+                            $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
+                        $domdefaults{'unofficialcredits'} =
+                            $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
+                        $domdefaults{'textbookcredits'} =
+                            $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
+                    }
+                }
+                if ($changes{'uploadquota'}) {
+                    if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
+                        foreach my $type (@types) {
+                            $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
+                        }
+                    }
+                }
                 my $cachetime = 24*60*60;
                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+                if (ref($lastactref) eq 'HASH') {
+                    $lastactref->{'domdefaults'} = 1;
+                }
             }
             $resulttext = &mt('Changes made:').'<ul>';
             foreach my $item (sort(keys(%changes))) {
@@ -7912,7 +8635,37 @@ sub modify_coursedefaults {
                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                     }
                 } elsif ($item eq 'anonsurvey_threshold') {
-                        $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
+                    $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
+                } elsif ($item eq 'uploadquota') {
+                    if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
+                        $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
+                                       '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
+                                       '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
+                                       '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
+
+                                       '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
+                                       '</ul>'.
+                                       '</li>';
+                    } else {
+                        $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
+                    }
+                } elsif ($item eq 'coursecredits') {
+                    if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+                        if (($domdefaults{'officialcredits'} eq '') &&
+                            ($domdefaults{'unofficialcredits'} eq '') &&
+                            ($domdefaults{'textbookcredits'} eq '')) {
+                            $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
+                        } else {
+                            $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
+                                           '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
+                                           '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
+                                           '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
+                                           '</ul>'.
+                                           '</li>';
+                        }
+                    } else {
+                        $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
+                    }
                 }
             }
             $resulttext .= '</ul>';
@@ -7927,7 +8680,7 @@ sub modify_coursedefaults {
 }
 
 sub modify_usersessions {
-    my ($dom,%domconfig) = @_;
+    my ($dom,$lastactref,%domconfig) = @_;
     my @hostingtypes = ('version','excludedomain','includedomain');
     my @offloadtypes = ('primary','default');
     my %types = (
@@ -7944,7 +8697,7 @@ sub modify_usersessions {
     foreach my $prefix (@prefixes) {
         $defaultshash{'usersessions'}{$prefix} = {};
     }
-    my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
     my $resulttext;
     my %iphost = &Apache::lonnet::get_iphost();
     foreach my $prefix (@prefixes) {
@@ -8120,6 +8873,9 @@ sub modify_usersessions {
             }
             my $cachetime = 24*60*60;
             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+            if (ref($lastactref) eq 'HASH') {
+                $lastactref->{'domdefaults'} = 1;
+            }
             if (keys(%changes) > 0) {
                 my %lt = &usersession_titles();
                 $resulttext = &mt('Changes made:').'<ul>';
@@ -8131,7 +8887,8 @@ sub modify_usersessions {
                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
-                                    &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
+                                    my $cachekey = &escape('spares').':'.&escape($lonhostdom);
+                                    &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                                         foreach my $type (@{$types{$prefix}}) {
                                             if ($changes{$prefix}{$lonhost}{$type}) {
@@ -8221,7 +8978,7 @@ sub modify_loadbalancing {
         if ($balancer eq '') {
             next;
         }
-        if (!exists($servers{$balancer})) { 
+        if (!exists($servers{$balancer})) {
             if (exists($currbalancer{$balancer})) {
                 push(@{$changes{'delete'}},$balancer);
             }
@@ -8272,14 +9029,14 @@ sub modify_loadbalancing {
             }
         } else {
             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
-                foreach my $sparetype (@sparestypes) { 
+                foreach my $sparetype (@sparestypes) {
                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                             $changes{'curr'}{$balancer}{'targets'} = 1;
                         }
                     }
                 }
-            }  
+            }
         }
         my $ishomedom;
         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
@@ -8288,7 +9045,7 @@ sub modify_loadbalancing {
         if (ref($alltypes) eq 'ARRAY') {
             foreach my $type (@{$alltypes}) {
                 my $rule;
-                unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
+                unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
                          (!$ishomedom)) {
                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                 }
@@ -8313,17 +9070,17 @@ sub modify_loadbalancing {
         }
         my $putresult = &Apache::lonnet::put_dom('configuration',
                                                  \%defaultshash,$dom);
- 
         if ($putresult eq 'ok') {
             if (keys(%changes) > 0) {
                 if (ref($changes{'delete'}) eq 'ARRAY') {
                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
-                        &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
+                        my $cachekey = &escape('loadbalancing').':'.&escape($dom);
+                        &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
                     }
                 }
                 if (ref($changes{'add'}) eq 'ARRAY') {
-                    foreach my $balancer (sort(@{$changes{'add'}})) {   
+                    foreach my $balancer (sort(@{$changes{'add'}})) {
                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
                     }
                 }
@@ -8364,17 +9121,19 @@ sub modify_loadbalancing {
                                         my $balancetext;
                                         if ($rule eq '') {
                                             $balancetext =  $ruletitles{'default'};
-                                        } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
+                                        } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
+                                                 ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                                             $balancetext =  $ruletitles{$rule};
                                         } else {
                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                                         }
-                                        $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';     
+                                        $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
                                     }
                                 }
                             }
                         }
-                        &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
+                        my $cachekey = &escape('loadbalancing').':'.&escape($dom);
+                        &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
                     }
                 }
                 if ($resulttext ne '') {
@@ -8437,73 +9196,94 @@ sub recurse_cat_deletes {
 
 sub get_active_dcs {
     my ($dom) = @_;
-    my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
+    my $now = time;
+    my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
     my %domcoords;
     my $numdcs = 0;
-    my $now = time;
     foreach my $server (keys(%dompersonnel)) {
         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
-            my ($end,$start) = split(':',$dompersonnel{$server}{$user});
-            if (($end eq '') || ($end == 0) || ($end > $now)) {
-                if ($start <= $now) {
-                    $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
-                }
-            }
+            $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
         }
     }
     return %domcoords;
 }
 
 sub active_dc_picker {
-    my ($dom,$curr_dc) = @_;
+    my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
     my %domcoords = &get_active_dcs($dom); 
-    my @dcs = sort(keys(%domcoords));
-    my $numdcs = scalar(@dcs); 
-    my $datatable;
-    my $numinrow = 2;
+    my @domcoord = keys(%domcoords);
+    if (keys(%currhash)) {
+        foreach my $dc (keys(%currhash)) {
+            unless (exists($domcoords{$dc})) {
+                push(@domcoord,$dc);
+            }
+        }
+    }
+    @domcoord = sort(@domcoord);
+    my $numdcs = scalar(@domcoord);
+    my $rows = 0;
+    my $table;
     if ($numdcs > 1) {
-        $datatable = '<table>';
-        for (my $i=0; $i<@dcs; $i++) {
+        $table = '<table>';
+        for (my $i=0; $i<@domcoord; $i++) {
             my $rem = $i%($numinrow);
             if ($rem == 0) {
                 if ($i > 0) {
-                    $datatable .= '</tr>';
+                    $table .= '</tr>';
                 }
-                $datatable .= '<tr>';
+                $table .= '<tr>';
+                $rows ++;
             }
-            my $check = ' ';
-            if ($curr_dc eq '') {
-                if (!$i) { 
-                    $check = ' checked="checked" ';
+            my $check = '';
+            if ($inputtype eq 'radio') {
+                if (keys(%currhash) == 0) {
+                    if (!$i) {
+                        $check = ' checked="checked"';
+                    }
+                } elsif (exists($currhash{$domcoord[$i]})) {
+                    $check = ' checked="checked"';
+                }
+            } else {
+                if (exists($currhash{$domcoord[$i]})) {
+                    $check = ' checked="checked"';
                 }
-            } elsif ($dcs[$i] eq $curr_dc) {
-                $check = ' checked="checked" ';
             }
-            if ($i == @dcs - 1) {
+            if ($i == @domcoord - 1) {
                 my $colsleft = $numinrow - $rem;
                 if ($colsleft > 1) {
-                    $datatable .= '<td colspan="'.$colsleft.'">';
+                    $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
                 } else {
-                    $datatable .= '<td>';
+                    $table .= '<td class="LC_left_item">';
                 }
             } else {
-                $datatable .= '<td>';
+                $table .= '<td class="LC_left_item">';
+            }
+            my ($dcname,$dcdom) = split(':',$domcoord[$i]);
+            my $user = &Apache::loncommon::plainname($dcname,$dcdom);
+            $table .= '<span class="LC_nobreak"><label>'.
+                      '<input type="'.$inputtype.'" name="'.$name.'"'.
+                      ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
+            if ($user ne $dcname.':'.$dcdom) {
+                $table .=  ' ('.$dcname.':'.$dcdom.')'.
+                           '</label></span></td>';
             }
-            my ($dcname,$dcdom) = split(':',$dcs[$i]);
-            $datatable .= '<span class="LC_nobreak"><label>'.
-                          '<input type="radio" name="autocreate_xmldc"'.
-                          ' value="'.$dcs[$i].'"'.$check.'/>'.
-                          &Apache::loncommon::plainname($dcname,$dcdom).
-                          ' ('.$dcname.':'.$dcdom.')'.
-                          '</label></span></td>';
         }
-        $datatable .= '</tr></table>';
-    } elsif (@dcs) {
-        $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
-                      $dcs[0].'" />';
+        $table .= '</tr></table>';
+    } elsif ($numdcs == 1) {
+        if ($inputtype eq 'radio') {
+            $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
+        } else {
+            my $check;
+            if (exists($currhash{$domcoord[0]})) {
+                $check = ' checked="checked"';
+            }
+            $table .= '<input type="checkbox" name="'.$name.'" '.
+                      'value="'.$domcoord[0].'"'.$check.' />';
+            $rows ++;
+        }
     }
-    return ($numdcs,$datatable);
+    return ($numdcs,$table,$rows);
 }
 
 sub usersession_titles {
@@ -8575,7 +9355,7 @@ sub lonbalance_targets_js {
     }
     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                               \%currtargets,\%currrules);
-    my $balancers = join("','",sort(keys(%currbalancer))); 
+    my $balancers = join("','",sort(keys(%currbalancer)));
     return <<"END";
 
 <script type="text/javascript">
@@ -8646,7 +9426,6 @@ function showSpares(balancer,ishomedom,b
             } else {
                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
-
             }
         } else {
             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
@@ -8658,12 +9437,11 @@ function showSpares(balancer,ishomedom,b
             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
             item.options.length = 0;
             item.options[0] = new Option("","",true,true);
-            var idx = 0;  
+            var idx = 0;
             for (var m=0; m<alltargets.length; m++) {
                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                     idx ++;
                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
-                    
                 }
             }
         }
@@ -9032,6 +9810,40 @@ END
 
 }
 
+sub credits_js {
+    return <<"END";
+
+<script type="text/javascript">
+// <![CDATA[
+
+function toggleCredits(domForm) {
+    if (document.getElementById('credits')) {
+        creditsitem = document.getElementById('credits');
+        var creditsLength = domForm.coursecredits.length;
+        if (creditsLength) {
+            var currval;
+            for (var i=0; i<creditsLength; i++) {
+                if (domForm.coursecredits[i].checked) {
+                   currval = domForm.coursecredits[i].value;
+                }
+            }
+            if (currval == 1) {
+                creditsitem.style.display = 'block';
+            } else {
+                creditsitem.style.display = 'none';
+            }
+        }
+    }
+    return;
+}
+
+// ]]>
+</script>
+
+END
+
+}
+
 sub captcha_phrases {
     return &Apache::lonlocal::texthash (
                  priv => 'Private key',
@@ -9042,4 +9854,28 @@ sub captcha_phrases {
     );
 }
 
+sub devalidate_remote_domconfs {
+    my ($dom,$cachekeys) = @_;
+    return unless (ref($cachekeys) eq 'HASH');
+    my %servers = &Apache::lonnet::internet_dom_servers($dom);
+    my %thismachine;
+    map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
+    my @posscached = ('domainconfig','domdefaults');
+    if (keys(%servers) > 1) {
+        foreach my $server (keys(%servers)) {
+            next if ($thismachine{$server});
+            my @cached;
+            foreach my $name (@posscached) {
+                if ($cachekeys->{$name}) {
+                    push(@cached,&escape($name).':'.&escape($dom));
+                }
+            }
+            if (@cached) {
+                &Apache::lonnet::remote_devalidate_cache($server,\@cached);
+            }
+        }
+    }
+    return;
+}
+
 1;