--- loncom/interface/domainprefs.pm	2009/12/04 14:17:38	1.122
+++ loncom/interface/domainprefs.pm	2011/08/01 23:33:43	1.147
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.122 2009/12/04 14:17:38 jms Exp $
+# $Id: domainprefs.pm,v 1.147 2011/08/01 23:33:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -140,7 +140,7 @@ autolimit
 
 =over
  
-- course requests will be processed autoatically up to a limit of
+- course requests will be processed automatically up to a limit of
 N requests for the course type for the particular requestor.
 If N is undefined, there is no limit to the number of course requests
 which a course owner may submit and have processed automatically. 
@@ -199,15 +199,16 @@ sub handler {
     }
     my %domconfig =
       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
-                'quotas','autoenroll','autoupdate','directorysrch',
-                'usercreation','usermodification','contacts','defaults',
-                'scantron','coursecategories','serverstatuses',
-                'requestcourses','helpsettings','coursedefaults'],$dom);
+                'quotas','autoenroll','autoupdate','autocreate',
+                'directorysrch','usercreation','usermodification',
+                'contacts','defaults','scantron','coursecategories',
+                'serverstatuses','requestcourses','helpsettings',
+                'coursedefaults','usersessions'],$dom);
     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
-                       'autoupdate','directorysrch','contacts',
+                       'autoupdate','autocreate','directorysrch','contacts',
                        'usercreation','usermodification','scantron',
                        'requestcourses','coursecategories','serverstatuses','helpsettings',
-                       'coursedefaults');
+                       'coursedefaults','usersessions');
     my %prefs = (
         'rolecolors' =>
                    { text => 'Default color schemes',
@@ -229,13 +230,13 @@ sub handler {
                     },
 
         'defaults' => 
-                    { text => 'Default authentication/language/timezone',
+                    { text => 'Default authentication/language/timezone/portal',
                       help => 'Domain_Configuration_LangTZAuth',
                       header => [{col1 => 'Setting',
                                   col2 => 'Value'}],
                     },
         'quotas' => 
-                    { text => 'User blogs, personal information pages and portfolios',
+                    { text => 'User blogs, personal information pages, portfolios',
                       help => 'Domain_Configuration_Quotas',
                       header => [{col1 => 'User affiliation',
                                   col2 => 'Available tools',
@@ -252,8 +253,16 @@ sub handler {
                      help => 'Domain_Configuration_Auto_Updates',
                      header => [{col1 => 'Setting',
                                  col2 => 'Value',},
+                                {col1 => 'Setting',
+                                 col2 => 'Affiliation'},
                                 {col1 => 'User population',
-                                 col2 => 'Updataeable user data'}],
+                                 col2 => 'Updateable user data'}],
+                  },
+        'autocreate' => 
+                  { text => 'Auto-course creation settings',
+                     help => 'Domain_Configuration_Auto_Creation',
+                     header => [{col1 => 'Configuration Setting',
+                                 col2 => 'Value',}],
                   },
         'directorysrch' => 
                   { text => 'Institutional directory searches',
@@ -331,8 +340,10 @@ sub handler {
         'coursedefaults' => 
                  {text => 'Course/Community defaults',
                   help => 'Domain_Configuration_Course_Defaults',
-                  header => [{col1 => 'Setting',
-                              col2 => 'Value',}],
+                  header => [{col1 => 'Defaults which can be overridden in each course by a CC',
+                              col2 => 'Value',},
+                             {col1 => 'Defaults which can be overridden for each course by a DC',
+                              col2 => 'Value',},],
                  },
         'privacy' => 
                  {text   => 'User Privacy',
@@ -340,6 +351,16 @@ sub handler {
                   header => [{col1 => 'Setting',
                               col2 => 'Value',}],
                  },
+        'usersessions' =>
+                 {text  => 'User session hosting/offloading',
+                  help  => 'Domain_Configuration_User_Sessions',
+                  header => [{col1 => 'Domain server',
+                              col2 => 'Servers to offload sessions to when busy'},
+                             {col1 => 'Hosting of users from other domains',
+                              col2 => 'Rules'},
+                             {col1 => "Hosting domain's own users elsewhere",
+                              col2 => 'Rules'}],
+                 },
     );
     my %servers = &dom_servers($dom);
     if (keys(%servers) > 1) {
@@ -355,7 +376,7 @@ sub handler {
     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
     &Apache::lonhtmlcommon::add_breadcrumb
     ({href=>"javascript:changePage(document.$phase,'pickactions')",
-      text=>"Pick functionality"});
+      text=>"Settings to display/modify"});
     my $confname = $dom.'-domainconfig';
     if ($phase eq 'process') {
         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
@@ -418,6 +439,8 @@ sub process_changes {
         $output = &modify_autoenroll($dom,%domconfig);
     } elsif ($action eq 'autoupdate') {
         $output = &modify_autoupdate($dom,%domconfig);
+    } elsif ($action eq 'autocreate') {
+        $output = &modify_autocreate($dom,%domconfig);
     } elsif ($action eq 'directorysrch') {
         $output = &modify_directorysrch($dom,%domconfig);
     } elsif ($action eq 'usercreation') {
@@ -440,6 +463,8 @@ sub process_changes {
         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
     } elsif ($action eq 'coursedefaults') {
         $output = &modify_coursedefaults($dom,%domconfig);
+    } elsif ($action eq 'usersessions') {
+        $output = &modify_usersessions($dom,%domconfig);
     }
     return $output;
 }
@@ -465,16 +490,20 @@ sub print_config_box {
     }
     if ($numheaders > 1) {
         my $colspan = '';
+        my $rightcolspan = '';
         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
             $colspan = ' colspan="2"';
         }
+        if ($action eq 'usersessions') {
+            $rightcolspan = ' colspan="3"'; 
+        }
         $output .= '
           <tr>
            <td>
             <table class="LC_nested">
              <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
-              <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
+              <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
              </tr>';
         $rowtotal ++;
         if ($action eq 'autoupdate') {
@@ -492,8 +521,12 @@ sub print_config_box {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif ($action eq 'helpsettings') {
             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
+        } elsif ($action eq 'usersessions') {
+            $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
         } elsif ($action eq 'rolecolors') {
             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
+        } elsif ($action eq 'coursedefaults') {
+            $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
         }
         $output .= '
            </table>
@@ -509,7 +542,18 @@ sub print_config_box {
              </tr>';
             $rowtotal ++;
         if ($action eq 'autoupdate') {
-            $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
+            $output .= &print_autoupdate('middle',$dom,$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_autoupdate('bottom',$dom,$settings,\$rowtotal);
+            $rowtotal ++;
         } elsif ($action eq 'usercreation') {
             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
            </table>
@@ -534,7 +578,6 @@ sub print_config_box {
              <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_usermodification('bottom',$dom,$settings,\$rowtotal);
             $rowtotal ++;
         } elsif ($action eq 'coursecategories') {
@@ -545,6 +588,21 @@ sub print_config_box {
             $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
         } elsif ($action eq 'helpsettings') {
             $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
+        } elsif ($action eq 'usersessions') {
+            $output .= &print_usersessions('middle',$dom,$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_usersessions('bottom',$dom,$settings,\$rowtotal);
+            $rowtotal ++;
+        } elsif ($action eq 'coursedefaults') {
+            $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'rolecolors') {
             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
            </table>
@@ -619,6 +677,8 @@ sub print_config_box {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif ($action eq 'autoenroll') {
             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
+        } elsif ($action eq 'autocreate') {
+            $output .= &print_autocreate($dom,$settings,\$rowtotal);
         } elsif ($action eq 'directorysrch') {
             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
         } elsif ($action eq 'contacts') {
@@ -631,8 +691,6 @@ sub print_config_box {
             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
         } elsif ($action eq 'helpsettings') {
             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
-    	} elsif ($action eq 'coursedefaults') {
-            $output .= &print_coursedefaults($dom,$settings,\$rowtotal);
         }
     }
     $output .= '
@@ -647,15 +705,17 @@ sub print_login {
     my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
     my ($css_class,$datatable);
     my %choices = &login_choices();
-    my $itemcount = 1;
 
     if ($position eq 'top') {
         my %servers = &dom_servers($dom);
         my $choice = $choices{'disallowlogin'};
         $css_class = ' class="LC_odd_row"';
-        $datatable .= '<tr'.$css_class.'><td>'.$choices{'disallowlogin'}.'</td>'.
+        $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
-                      '<th>'.$choices{'serverurl'}.'</th></tr>'."\n";
+                      '<th>'.$choices{'server'}.'</th>'.
+                      '<th>'.$choices{'serverpath'}.'</th>'.
+                      '<th>'.$choices{'custompath'}.'</th>'.
+                      '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
         my %disallowed;
         if (ref($settings) eq 'HASH') {
             if (ref($settings->{'loginvia'}) eq 'HASH') {
@@ -664,23 +724,52 @@ sub print_login {
         }
         foreach my $lonhost (sort(keys(%servers))) {
             my $direct = 'selected="selected"';
-            if ($disallowed{$lonhost} eq '') {
-                $direct = '';
+            if (ref($disallowed{$lonhost}) eq 'HASH') {
+                if ($disallowed{$lonhost}{'server'} ne '') {
+                    $direct = '';
+                }
             }
             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
-                          '<td><select name="'.$lonhost.'_serverurl">'.
+                          '<td><select name="'.$lonhost.'_server">'.
                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                           '</option>';
             foreach my $hostid (keys(%servers)) {
                 next if ($servers{$hostid} eq $servers{$lonhost});
                 my $selected = '';
-                if ($hostid eq $disallowed{$lonhost}) {
-                    $selected = 'selected="selected"';
+                if (ref($disallowed{$lonhost}) eq 'HASH') {
+                    if ($hostid eq $disallowed{$lonhost}{'server'}) {
+                        $selected = 'selected="selected"';
+                    }
                 }
                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                               $servers{$hostid}.'</option>';
             }
-            $datatable .= '</select></td></tr>';
+            $datatable .= '</select></td>'.
+                          '<td><select name="'.$lonhost.'_serverpath">';
+            foreach my $path ('','/','/adm/login','/adm/roles','custom') {
+                my $pathname = $path;
+                if ($path eq 'custom') {
+                    $pathname = &mt('Custom Path').' ->';
+                }
+                my $selected = '';
+                if (ref($disallowed{$lonhost}) eq 'HASH') {
+                    if ($path eq $disallowed{$lonhost}{'serverpath'}) {
+                        $selected = 'selected="selected"';
+                    }
+                } elsif ($path eq '') {
+                    $selected = 'selected="selected"';
+                }
+                $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
+            }
+            $datatable .= '</select></td>';
+            my ($custom,$exempt);
+            if (ref($disallowed{$lonhost}) eq 'HASH') {
+                $custom = $disallowed{$lonhost}{'custompath'};
+                $exempt = $disallowed{$lonhost}{'exempt'};
+            }
+            $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
+                          '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
+                          '</tr>';
         }
         $datatable .= '</table></td></tr>';
         return $datatable;
@@ -702,7 +791,6 @@ sub print_login {
             $checkedon{$item} = ' ';
         }
     }
-    my $loginheader = 'image';
     my @images = ('img','logo','domlogo','login');
     my @logintext = ('textcol','bgcol');
     my @bgs = ('pgbg','mainbg','sidebg');
@@ -751,9 +839,6 @@ sub print_login {
                 $is_custom{$item} = 1;
             }
         }
-        if ($settings->{'loginheader'} ne '') {
-            $loginheader = $settings->{'loginheader'};
-        }
         if ($settings->{'font'} ne '') {
             $designs{'font'} = $settings->{'font'};
             $is_custom{'font'} = 1;
@@ -799,7 +884,6 @@ sub print_login {
                                                   domlogo => 'Domain Logo',
                                                   login => 'Login box');
     my $itemcount = 1;
-    my ($css_class,$datatable);
     foreach my $item (@toggles) {
         $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .=  
@@ -812,7 +896,7 @@ sub print_login {
             '</tr>';
         $itemcount ++;
     }
-    $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader);
+    $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
     $datatable .= '</tr></table></td></tr>';
     return $datatable;
 }
@@ -824,7 +908,10 @@ sub login_choices {
             adminmail     => "Display Administrator's E-mail Address?",
             disallowlogin => "Login page requests redirected",
             hostid        => "Server",
-            serverurl     => "Redirect to log-in via:",
+            server        => "Redirect to:",
+            serverpath    => "Path",
+            custompath    => "Custom", 
+            exempt        => "Exempt IP(s)",
             directlogin   => "No redirect",
             newuser       => "Link to create a user account",
             img           => "Header",
@@ -929,9 +1016,9 @@ sub print_rolecolors {
 
 sub display_color_options {
     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
-        $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
+        $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
-    my $datatable = '<tr>'.
+    my $datatable = '<tr'.$css_class.'>'.
         '<td>'.$choices->{'font'}.'</td>';
     if (!$is_custom->{'font'}) {
         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
@@ -971,8 +1058,7 @@ sub display_color_options {
         if ($role eq 'login') {
             if ($img eq 'login') {
                 $login_hdr_pick =
-                    &login_header_options($img,$role,$defaults,$is_custom,$choices,
-                                          $loginheader);
+                    &login_header_options($img,$role,$defaults,$is_custom,$choices);
                 $logincolors =
                     &login_text_colors($img,$role,$logintext,$phase,$choices,
                                             $designs);
@@ -1049,8 +1135,8 @@ sub display_color_options {
                 }
                 $datatable .= '<td>';
                 if ($img eq 'login') {
-                    $datatable .= $login_hdr_pick;    
-                }
+                    $datatable .= $login_hdr_pick;
+                } 
                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
             } else {
@@ -1064,7 +1150,9 @@ sub display_color_options {
         if ($switchserver) {
             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
         } else {
-            $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
+            if ($img ne 'login') { # suppress file selection for Log-in header
+                $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
+            }
         }
         $datatable .= '</td></tr>';
     }
@@ -1153,20 +1241,10 @@ sub logo_display_options {
 }
 
 sub login_header_options  {
-    my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
-    my $image_checked = ' checked="checked" ';
-    my $text_checked = ' ';
-    if ($loginheader eq 'text') {
-        $image_checked = ' ';
-        $text_checked = ' checked="checked" ';
-    }
-    my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
-              'loginheader" value="image" '.$image_checked.'/>'.
-              &mt('use image').'</label>&nbsp;&nbsp;&nbsp;'.
-              '<label><input type="radio" name="loginheader" value="text"'.
-              $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
+    my ($img,$role,$defaults,$is_custom,$choices) = @_;
+    my $output = '';
     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
-        $output .= &mt('Text default(s)').':<br />';
+        $output .= &mt('Text default(s):').'<br />';
         if (!$is_custom->{'textcol'}) {
             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                        '&nbsp;&nbsp;&nbsp;';
@@ -1202,25 +1280,31 @@ sub login_text_colors {
 sub image_changes {
     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
     my $output;
-    if (!$is_custom) {
+    if ($img eq 'login') {
+            # suppress image for Log-in header
+    } elsif (!$is_custom) {
         if ($img ne 'domlogo') {
             $output .= &mt('Default image:').'<br />';
         } else {
             $output .= &mt('Default in use:').'<br />';
         }
     }
-    if ($img_import) {
-        $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
-    }
-    $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
-               $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
-    if ($is_custom) {
-        $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
-                   '<input type="checkbox" name="'.
-                   $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
-                   '</label>&nbsp;'.&mt('Replace:').'</span><br />';
+    if ($img eq 'login') { # suppress image for Log-in header
+        $output .= '<td>'.$logincolors;
     } else {
-        $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
+        if ($img_import) {
+            $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
+        }
+        $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
+                   $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
+        if ($is_custom) {
+            $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
+                       '<input type="checkbox" name="'.
+                       $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
+                       '</label>&nbsp;'.&mt('Replace:').'</span><br />';
+        } else {
+            $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
+        }
     }
     return $output;
 }
@@ -1316,15 +1400,15 @@ sub print_quotas {
                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                                   '<input type="radio" name="crsreq_'.$item.
                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
-                                  $titles{$option}.'</label>&nbsp;';
+                                  $titles{$option}.'</label>';
                             if ($option eq 'autolimit') {
-                                $cell{$item} .= '<input type="text" name="crsreq_'.
+                                $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
                                                 $item.'_limit_'.$type.'" size="1" '.
                                                 'value="'.$currlimit.'" />';
                             }
-                            $cell{$item} .= '</span>&nbsp; ';
+                            $cell{$item} .= '</span> ';
                             if ($option eq 'autolimit') {
-                                $cell{$item} .= $titles{'unlimited'}
+                                $cell{$item} .= $titles{'unlimited'};
                             }
                         }
                     } else {
@@ -1424,13 +1508,13 @@ sub print_quotas {
                                   '_default" value="'.$val.'"'.$checked.' />'.
                                   $titles{$option}.'</label>';
                 if ($option eq 'autolimit') {
-                    $defcell{$item} .= '<input type="text" name="crsreq_'.
+                    $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
                                        $item.'_limit_default" size="1" '.
                                        'value="'.$currlimit.'" />';
                 }
-                $defcell{$item} .= '</span>&nbsp; ';
+                $defcell{$item} .= '</span> ';
                 if ($option eq 'autolimit') {
-                    $defcell{$item} .= $titles{'unlimited'}
+                    $defcell{$item} .= $titles{'unlimited'};
                 }
             }
         } else {
@@ -1527,13 +1611,13 @@ sub print_quotas {
                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                                   $titles{$option}.'</label>';
                 if ($option eq 'autolimit') {
-                    $advcell{$item} .= '<input type="text" name="crsreq_'.
+                    $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
                                        $item.'_limit__LC_adv" size="1" '.
                                        'value="'.$currlimit.'" />';
                 }
-                $advcell{$item} .= '</span>&nbsp; ';
+                $advcell{$item} .= '</span> ';
                 if ($option eq 'autolimit') {
-                    $advcell{$item} .= $titles{'unlimited'}
+                    $advcell{$item} .= $titles{'unlimited'};
                 }
             }
         } else {
@@ -1646,7 +1730,7 @@ sub print_courserequestmail {
 sub print_autoenroll {
     my ($dom,$settings,$rowtotal) = @_;
     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
-    my ($defdom,$runon,$runoff);
+    my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
     if (ref($settings) eq 'HASH') {
         if (exists($settings->{'run'})) {
             if ($settings->{'run'} eq '0') {
@@ -1665,6 +1749,18 @@ sub print_autoenroll {
                 $runon = ' ';
             }
         }
+        if (exists($settings->{'co-owners'})) {
+            if ($settings->{'co-owners'} eq '0') {
+                $coownersoff = ' checked="checked" ';
+                $coownerson = ' ';
+            } else {
+                $coownerson = ' checked="checked" ';
+                $coownersoff = ' ';
+            }
+        } else {
+            $coownersoff = ' checked="checked" ';
+            $coownerson = ' ';
+        }
         if (exists($settings->{'sender_domain'})) {
             $defdom = $settings->{'sender_domain'};
         }
@@ -1695,8 +1791,16 @@ sub print_autoenroll {
                   &mt('username').':&nbsp;'.
                   '<input type="text" name="sender_uname" value="'.
                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
-                  ':&nbsp;'.$domform.'</span></td></tr>';
-    $$rowtotal += 2;
+                  ':&nbsp;'.$domform.'</span></td></tr>'.
+                  '<tr class="LC_odd_row">'.
+                  '<td>'.&mt('Automatically assign co-ownership').'</td>'.
+                  '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
+                  '<input type="radio" name="autoassign_coowners"'.
+                  $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
+                  '<label><input type="radio" name="autoassign_coowners"'.
+                  $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
+                  '</tr>';
+    $$rowtotal += 3;
     return $datatable;
 }
 
@@ -1738,9 +1842,17 @@ sub print_autoupdate {
                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
                   '</tr>';
         $$rowtotal += 2;
+    } elsif ($position eq 'middle') {
+        my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+        my $numinrow = 3;
+        my $locknamesettings;
+        $datatable .= &insttypes_row($settings,$types,$usertypes,
+                                     $dom,$numinrow,$othertitle,
+                                    'lockablenames');
+        $$rowtotal ++;
     } else {
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
-        my @fields = ('lastname','firstname','middlename','gen',
+        my @fields = ('lastname','firstname','middlename','generation',
                       'permanentemail','id');
         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
         my $numrows = 0;
@@ -1761,6 +1873,56 @@ sub print_autoupdate {
     return $datatable;
 }
 
+sub print_autocreate {
+    my ($dom,$settings,$rowtotal) = @_;
+    my (%createon,%createoff);
+    my $curr_dc;
+    my @types = ('xml','req');
+    if (ref($settings) eq 'HASH') {
+        foreach my $item (@types) {
+            $createoff{$item} = ' checked="checked" ';
+            $createon{$item} = ' ';
+            if (exists($settings->{$item})) {
+                if ($settings->{$item}) {
+                    $createon{$item} = ' checked="checked" ';
+                    $createoff{$item} = ' ';
+                }
+            }
+        }
+        $curr_dc = $settings->{'xmldc'};
+    } else {
+        foreach my $item (@types) {
+            $createoff{$item} = ' checked="checked" ';
+            $createon{$item} = ' ';
+        }
+    }
+    $$rowtotal += 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>'.
+                  '<input type="radio" name="autocreate_xml"'.
+                  $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
+                  '<label><input type="radio" name="autocreate_xml"'.
+                  $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
+                  '</td></tr><tr>'.
+                  '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
+                  '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
+                  '<input type="radio" name="autocreate_req"'.
+                  $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);
+    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>';
+    }
+    return $datatable;
+}
+
 sub print_directorysrch {
     my ($dom,$settings,$rowtotal) = @_;
     my $srchon = ' ';
@@ -1878,12 +2040,13 @@ sub print_contacts {
     my ($dom,$settings,$rowtotal) = @_;
     my $datatable;
     my @contacts = ('adminemail','supportemail');
-    my (%checked,%to,%otheremails);
+    my (%checked,%to,%otheremails,%bccemails);
     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
                     'requestsmail');
     foreach my $type (@mailings) {
         $otheremails{$type} = '';
     }
+    $bccemails{'helpdeskmail'} = '';
     if (ref($settings) eq 'HASH') {
         foreach my $item (@contacts) {
             if (exists($settings->{$item})) {
@@ -1899,6 +2062,9 @@ sub print_contacts {
                         }
                     }
                     $otheremails{$type} = $settings->{$type}{'others'};
+                    if ($type eq 'helpdeskmail') {
+                        $bccemails{$type} = $settings->{$type}{'bcc'};
+                    }
                 }
             } elsif ($type eq 'lonstatusmail') {
                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
@@ -1942,8 +2108,13 @@ sub print_contacts {
         }
         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                       '<input type="text" name="'.$type.'_others" '.
-                      'value="'.$otheremails{$type}.'"  />'.
-                      '</td></tr>'."\n";
+                      'value="'.$otheremails{$type}.'"  />';
+        if ($type eq 'helpdeskmail') {
+            $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
+                          '<input type="text" name="'.$type.'_bcc" '.
+                          'value="'.$bccemails{$type}.'"  />';
+        }
+        $datatable .= '</td></tr>'."\n";
     }
     $$rowtotal += $rownum;
     return $datatable;
@@ -2088,22 +2259,379 @@ sub radiobutton_prefs {
 }
 
 sub print_coursedefaults {
-    my ($dom,$settings,$rowtotal) = @_;
+    my ($position,$dom,$settings,$rowtotal) = @_;
     my ($css_class,$datatable);
     my $itemcount = 1;
-    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',);
-    ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+    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',);
+        ($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;
+        if (ref($settings) eq 'HASH') {
+            $currdefresponder = $settings->{'anonsurvey_threshold'};
+        }
+        if (!$currdefresponder) {
+            $currdefresponder = 10;
+        } elsif ($currdefresponder < 1) {
+            $currdefresponder = 1;
+        }
+        $datatable .=
+               '<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>';
+    }
+    return $datatable;
+}
+
+sub print_usersessions {
+    my ($position,$dom,$settings,$rowtotal) = @_;
+    my ($css_class,$datatable,%checked,%choices);
+    my (%by_ip,%by_location,@intdoms);
+    &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
+
+    my @alldoms = &Apache::lonnet::all_domains();
+    my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
+    my %servers = &dom_servers($dom);
+    my $itemcount = 1;
+    if ($position eq 'top') {
+        if (keys(%uniques) > 1) {
+            my %spareid = &current_offloads_to($dom,$settings,\%servers);
+            $datatable .= &spares_row(\%servers,\%spareid,\%uniques,$rowtotal);
+        } else {
+            $datatable .= '<tr'.$css_class.'><td colspan="2">'.
+                          &mt('Nothing to set here, as the cluster to which this domain belongs only contains this server.');
+        }
+    } else {
+        if (keys(%by_location) == 0) {
+            $datatable .= '<tr'.$css_class.'><td colspan="2">'.
+                          &mt('Nothing to set here, as the cluster to which this domain belongs only contains this institution.');
+        } else {
+            my %lt = &usersession_titles();
+            my $numinrow = 5;
+            my $prefix;
+            my @types;
+            if ($position eq 'bottom') {
+                $prefix = 'remote';
+                @types = ('version','excludedomain','includedomain');
+            } else {
+                $prefix = 'hosted';
+                @types = ('excludedomain','includedomain');
+            }
+            my (%current,%checkedon,%checkedoff);
+            my @lcversions = &Apache::lonnet::all_loncaparevs();
+            my @locations = sort(keys(%by_location));
+            foreach my $type (@types) {
+                $checkedon{$type} = '';
+                $checkedoff{$type} = ' checked="checked"';
+            }
+            if (ref($settings) eq 'HASH') {
+                if (ref($settings->{$prefix}) eq 'HASH') {
+                    foreach my $key (keys(%{$settings->{$prefix}})) {
+                        $current{$key} = $settings->{$prefix}{$key};
+                        if ($key eq 'version') {
+                            if ($current{$key} ne '') {
+                                $checkedon{$key} = ' checked="checked"';
+                                $checkedoff{$key} = '';
+                            }
+                        } elsif (ref($current{$key}) eq 'ARRAY') {
+                            $checkedon{$key} = ' checked="checked"';
+                            $checkedoff{$key} = '';
+                        }
+                    }
+                }
+            }
+            foreach my $type (@types) {
+                next if ($type ne 'version' && !@locations);
+                $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
+                $datatable .= '<tr'.$css_class.'>
+                               <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
+                               <span class="LC_nobreak">&nbsp;
+                               <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
+                               <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
+                if ($type eq 'version') {
+                    my $selector = '<select name="'.$prefix.'_version">';
+                    foreach my $version (@lcversions) {
+                        my $selected = '';
+                        if ($current{'version'} eq $version) {
+                            $selected = ' selected="selected"';
+                        }
+                        $selector .= ' <option value="'.$version.'"'.
+                                     $selected.'>'.$version.'</option>';
+                    }
+                    $selector .= '</select> ';
+                    $datatable .= &mt('remote server must be version: [_1] or later',$selector);
+                } else {
+                    $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
+                                 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
+                                 ' />'.('&nbsp;'x2).
+                                 '<input type="button" value="'.&mt('uncheck all').'" '.
+                                 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
+                                 "\n".
+                                 '</div><div><table>';
+                    my $rem;
+                    for (my $i=0; $i<@locations; $i++) {
+                        my ($showloc,$value,$checkedtype);
+                        if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
+                            my $ip = $by_location{$locations[$i]}->[0];
+                            if (ref($by_ip{$ip}) eq 'ARRAY') {
+                                 $value = join(':',@{$by_ip{$ip}});
+                                $showloc = join(', ',@{$by_ip{$ip}});
+                                if (ref($current{$type}) eq 'ARRAY') {
+                                    foreach my $loc (@{$by_ip{$ip}}) {  
+                                        if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
+                                            $checkedtype = ' checked="checked"';
+                                            last;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        $rem = $i%($numinrow);
+                        if ($rem == 0) {
+                            if ($i > 0) {
+                                $datatable .= '</tr>';
+                            }
+                            $datatable .= '<tr>';
+                        }
+                        $datatable .= '<td class="LC_left_item">'.
+                                      '<span class="LC_nobreak"><label>'.
+                                      '<input type="checkbox" name="'.$prefix.'_'.$type.
+                                      '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
+                                      '</label></span></td>';
+                    }
+                    $rem = @locations%($numinrow);
+                    my $colsleft = $numinrow - $rem;
+                    if ($colsleft > 1 ) {
+                        $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
+                                      '&nbsp;</td>';
+                    } elsif ($colsleft == 1) {
+                        $datatable .= '<td class="LC_left_item">&nbsp;</td>';
+                    }
+                    $datatable .= '</tr></table>';
+                }
+                $datatable .= '</td></tr>';
+                $itemcount ++;
+            }
+        }
+    }
+    $$rowtotal += $itemcount;
+    return $datatable;
+}
+
+sub build_location_hashes {
+    my ($intdoms,$by_ip,$by_location) = @_;
+    return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
+                  (ref($by_location) eq 'HASH')); 
+    my %iphost = &Apache::lonnet::get_iphost();
+    my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
+    my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
+    if (ref($iphost{$primary_ip}) eq 'ARRAY') {
+        foreach my $id (@{$iphost{$primary_ip}}) {
+            my $intdom = &Apache::lonnet::internet_dom($id);
+            unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
+                push(@{$intdoms},$intdom);
+            }
+        }
+    }
+    foreach my $ip (keys(%iphost)) {
+        if (ref($iphost{$ip}) eq 'ARRAY') {
+            foreach my $id (@{$iphost{$ip}}) {
+                my $location = &Apache::lonnet::internet_dom($id);
+                if ($location) {
+                    next if (grep(/^\Q$location\E$/,@{$intdoms}));
+                    if (ref($by_ip->{$ip}) eq 'ARRAY') {
+                        unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
+                            push(@{$by_ip->{$ip}},$location);
+                        }
+                    } else {
+                        $by_ip->{$ip} = [$location];
+                    }
+                }
+            }
+        }
+    }
+    foreach my $ip (sort(keys(%{$by_ip}))) {
+        if (ref($by_ip->{$ip}) eq 'ARRAY') {
+            @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
+            my $first = $by_ip->{$ip}->[0];
+            if (ref($by_location->{$first}) eq 'ARRAY') {
+                unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
+                    push(@{$by_location->{$first}},$ip);
+                }
+            } else {
+                $by_location->{$first} = [$ip];
+            }
+        }
+    }
+    return;
+}
+
+sub current_offloads_to {
+    my ($dom,$settings,$servers) = @_;
+    my (%spareid,%otherdomconfigs);
+    if ((ref($settings) eq 'HASH') && (ref($servers) eq 'HASH')) {
+        foreach my $lonhost (sort(keys(%{$servers}))) {
+            my $gotspares;
+            if (ref($settings->{'spares'}) eq 'HASH') {
+                if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
+                    $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
+                    $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
+                    $gotspares = 1;
+                }
+            }
+            unless ($gotspares) {
+                my $gotspares;
+                my $serverhomeID =
+                    &Apache::lonnet::get_server_homeID($servers->{$lonhost});
+                my $serverhomedom =
+                    &Apache::lonnet::host_domain($serverhomeID);
+                if ($serverhomedom ne $dom) {
+                    if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
+                        if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
+                            if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
+                                $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
+                                $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
+                                $gotspares = 1;
+                            }
+                        }
+                    } else {
+                        $otherdomconfigs{$serverhomedom} =
+                            &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
+                        if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
+                            if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
+                                if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
+                                    if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
+                                        $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
+                                        $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
+                                        $gotspares = 1;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            unless ($gotspares) {
+                if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
+                    $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
+                    $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
+               } else {
+                    my $server_hostname = &Apache::lonnet::hostname($lonhost);
+                    my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
+                    if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
+                        $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
+                        $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
+                    } else {
+                        my %requested;
+                        $requested{'spareid'} = 'HASH';
+                        my %returnhash = &Apache::lonnet::get_remote_globals($lonhost,\%requested);
+                        my $spareshash = $returnhash{'spareid'};
+                        if (ref($spareshash) eq 'HASH') {
+                            $spareid{$lonhost}{'primary'} = $spareshash->{'primary'};
+                            $spareid{$lonhost}{'default'} = $spareshash->{'default'};
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return %spareid;
+}
+
+sub spares_row {
+    my ($servers,$spareid,$uniques,$rowtotal) = @_;
+    my $css_class;
+    my $numinrow = 4;
+    my $itemcount = 1;
+    my $datatable;
+    if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH')) {
+        foreach my $server (sort(keys(%{$servers}))) {
+            $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
+            $datatable .= '<tr'.$css_class.'>
+                           <td rowspan="2">
+                            <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>';
+            my (%current,%canselect);
+            if (ref($spareid->{$server}) eq 'HASH') {
+                foreach my $type ('primary','default') {
+                    if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
+                        my @spares = @{$spareid->{$server}{$type}};
+                        if (@spares > 0) {
+                            $current{$type} .= '<table>';
+                            for (my $i=0;  $i<@spares; $i++) {
+                                my $rem = $i%($numinrow);
+                                if ($rem == 0) {
+                                    if ($i > 0) {
+                                        $current{$type} .= '</tr>';
+                                    }
+                                    $current{$type} .= '<tr>';
+                                }
+                                $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" />&nbsp;'.
+                                                   $spareid->{$server}{$type}[$i].
+                                                   '</label></td>';
+                            }
+                            $current{$type} .= '</tr></table>';
+                        }
+                    }
+                    if ($current{$type} eq '') {
+                        $current{$type} = &mt('None specified');
+                    }
+                    $canselect{$type} =
+                        &newspare_select($server,$type,$spareid->{$server}{$type},$uniques);
+                }
+            }
+            $datatable .= '<td><i>'.&mt('primary').'</i><td>'.$current{'primary'}.'</td>'.
+                          '<td>'.&mt('Add new [_1]primary[_2]:','<i>','</i>').'&nbsp;'.
+                          $canselect{'primary'}.'</td></tr>'.
+                          '<tr'.$css_class.'>'.
+                          '<td><i>'.&mt('default').'</i></td>'.
+                          '<td>'.$current{'default'}.'</td>'.
+                          '<td>'.&mt('Add new [_1]default[_2]:','<i>','</i>').'&nbsp;'.
+                          $canselect{'default'}.'</td></tr>';
+            $itemcount ++;
+        }
+    }
     $$rowtotal += $itemcount;
     return $datatable;
 }
 
+sub newspare_select {
+    my ($server,$type,$currspares,$uniques) = @_;
+    my $output;
+    if (ref($uniques) eq 'HASH') {
+        if (keys(%{$uniques}) > 1) {
+            $output = '<select name="newspare_'.$type.'_'.$server.'">'."\n".
+                      '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
+            foreach my $lonhost (sort(keys(%{$uniques}))) {
+                next if ($lonhost eq $server);
+                if (ref($currspares) eq 'ARRAY') {
+                    if (@{$currspares} > 0) {
+                        next if (grep(/^\Q$lonhost\E$/,@{$currspares}));
+                    }
+                }
+                $output .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
+            }
+            $output .= '<select>';
+        }
+    }
+    return $output;
+}
+
 sub contact_titles {
     my %titles = &Apache::lonlocal::texthash (
                    'supportemail' => 'Support E-mail address',
@@ -2475,9 +3003,9 @@ sub print_usermodification {
 sub print_defaults {
     my ($dom,$rowtotal) = @_;
     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
-                 'datelocale_def');
+                 'datelocale_def','portal_def');
     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
-    my $titles = &defaults_titles();
+    my $titles = &defaults_titles($dom);
     my $rownum = 0;
     my ($datatable,$css_class);
     foreach my $item (@items) {
@@ -2514,8 +3042,12 @@ sub print_defaults {
             my $includeempty = 1;
             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
         } else {
+            my $size;
+            if ($item eq 'portal_def') {
+                $size = ' size="25"';
+            }
             $datatable .= '<input type="text" name="'.$item.'" value="'.
-                          $domdefaults{$item}.'" />';
+                          $domdefaults{$item}.'"'.$size.' />';
         }
         $datatable .= '</td></tr>';
         $rownum ++;
@@ -2525,13 +3057,25 @@ sub print_defaults {
 }
 
 sub defaults_titles {
+    my ($dom) = @_;
     my %titles = &Apache::lonlocal::texthash (
                    'auth_def'      => 'Default authentication type',
                    'auth_arg_def'  => 'Default authentication argument',
                    'lang_def'      => 'Default language',
                    'timezone_def'  => 'Default timezone',
                    'datelocale_def' => 'Default locale for dates',
+                   'portal_def'     => 'Portal/Default URL',
                  );
+    if ($dom) {
+        my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
+        my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
+        my $protocol = $Apache::lonnet::protocol{$uprimary_id};
+        $protocol = 'http' if ($protocol ne 'https');
+        if ($uint_dom) {
+            $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
+                                         $uint_dom);
+        }
+    }
     return (\%titles);
 }
 
@@ -2645,7 +3189,7 @@ sub print_scantronformat {
                       '<span class="LC_nobreak">';
         if ($scantronurl) {
             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
-                          &mt('Default scantron format file').'</a>';
+                          &mt('Default bubblesheet format file').'</a>';
         } else {
             $datatable = &mt('File unavailable for display');
         }
@@ -2672,7 +3216,7 @@ sub print_scantronformat {
         } elsif ($scantronurl) {
             $datatable .= '<td><span class="LC_nobreak">'.
                           '<a href="'.$scantronurl.'" target="_blank">'.
-                          &mt('Custom scantron format file').'</a><label>'.
+                          &mt('Custom bubblesheet format file').'</a><label>'.
                           '<input type="checkbox" name="scantronformat_del"'.
                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
                           '<td><span class="LC_nobreak">&nbsp;'.
@@ -2701,7 +3245,7 @@ sub legacy_scantronformat {
             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                          '','',$newfile);
         if ($result ne 'ok') {
-            $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
+            $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
         }
     }
     return ($url,$error);
@@ -3281,6 +3825,7 @@ sub insttypes_row {
     my %lt = &Apache::lonlocal::texthash (
                       cansearch => 'Users allowed to search',
                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
+                      lockablenames => 'User preference to lock name',
              );
     my $showdom;
     if ($context eq 'cansearch') {
@@ -3317,10 +3862,12 @@ sub insttypes_row {
                            $usertypes->{$types->[$i]}.'</label></span></td>';
             }
         }
-       
         $rem = @{$types}%($numinrow);
     }
     my $colsleft = $numinrow - $rem;
+    if (($rem == 0) && (@{$types} > 0)) {
+        $output .= '<tr>';
+    }
     if ($colsleft > 1) {
         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
     } else {
@@ -3444,19 +3991,86 @@ sub modify_login {
     }
 
     my %servers = &dom_servers($dom);
+    my @loginvia_attribs = ('serverpath','custompath','exempt');
     if (keys(%servers) > 1) {
         foreach my $lonhost (keys(%servers)) {
-            next if ($env{'form.'.$lonhost.'_serverurl'} eq $lonhost);
-            if ($env{'form.'.$lonhost.'_serverurl'} eq $curr_loginvia{$lonhost}) {
-                $loginhash{login}{loginvia}{$lonhost} = $curr_loginvia{$lonhost};                next;
-            }
-            if ($curr_loginvia{$lonhost} ne '') {
-                $loginhash{login}{loginvia}{$lonhost} = $env{'form.'.$lonhost.'_serverurl'};
-                $changes{'loginvia'}{$lonhost} = 1;
+            next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
+            if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
+                if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
+                    $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
+                } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
+                    if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+                        $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
+                        $changes{'loginvia'}{$lonhost} = 1;
+                    } else {
+                        $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
+                        $changes{'loginvia'}{$lonhost} = 1;
+                    }
+                } else {
+                    if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+                        $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
+                        $changes{'loginvia'}{$lonhost} = 1;
+                    }
+                }
+                if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
+                    foreach my $item (@loginvia_attribs) {
+                        $loginhash{login}{loginvia}{$lonhost}{$item} = '';
+                    }
+                } else {
+                    foreach my $item (@loginvia_attribs) {
+                        my $new = $env{'form.'.$lonhost.'_'.$item};
+                        if (($item eq 'serverpath') && ($new eq 'custom')) {
+                            $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
+                            if ($env{'form.'.$lonhost.'_custompath'} eq '') {
+                                $new = '/';
+                            }
+                        }
+                        if (($item eq 'custompath') && 
+                            ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
+                            $new = '';
+                        }
+                        if ($new ne $curr_loginvia{$lonhost}{$item}) {
+                            $changes{'loginvia'}{$lonhost} = 1;
+                        }
+                        if ($item eq 'exempt') {
+                            $new =~ s/^\s+//;
+                            $new =~ s/\s+$//;
+                            my @poss_ips = split(/\s*[,:]\s*/,$new);
+                            my @okips;
+                            foreach my $ip (@poss_ips) {
+                                if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+                                    if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
+                                        push(@okips,$ip); 
+                                    }
+                                }
+                            }
+                            if (@okips > 0) {
+                                $new = join(',',@okips); 
+                            } else {
+                                $new = ''; 
+                            }
+                        }
+
+                        $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
+                    }
+                }
             } else {
-                if (defined($servers{$env{'form.'.$lonhost.'_serverurl'}})) {
-                    $loginhash{login}{loginvia}{$lonhost} = $env{'form.'.$lonhost.'_serverurl'};
+                if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+                    $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                     $changes{'loginvia'}{$lonhost} = 1;
+                    foreach my $item (@loginvia_attribs) {
+                        my $new = $env{'form.'.$lonhost.'_'.$item};
+                        if (($item eq 'serverpath') && ($new eq 'custom')) {
+                            if ($env{'form.'.$lonhost.'_custompath'} eq '') {
+                                $new = '/';
+                            }
+                        }
+                        if (($item eq 'custompath') && 
+                            ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
+                            $new = '';
+                        }
+                        $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
+                    }
                 }
             }
         }
@@ -3493,32 +4107,39 @@ sub modify_login {
                     }
                 }
             }
-            if (($domconfig{'login'}{'loginheader'} eq 'text') && 
-                ($env{'form.loginheader'} eq 'image')) {
-                $changes{'loginheader'} = 1;
-            } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
-                      $domconfig{'login'}{'loginheader'} eq 'image') &&
-                     ($env{'form.loginheader'} eq 'text')) {
-                $changes{'loginheader'} = 1;
-            }
         }
         if (keys(%changes) > 0 || $colchgtext) {
             &Apache::loncommon::devalidate_domconfig_cache($dom);
             $resulttext = &mt('Changes made:').'<ul>';
             foreach my $item (sort(keys(%changes))) {
-                if ($item eq 'loginheader') {
-                    $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
-                } elsif ($item eq 'loginvia') {
+                if ($item eq 'loginvia') {
                     if (ref($changes{$item}) eq 'HASH') {
                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
-                            if ($servers{$env{'form.'.$lonhost.'_serverurl'}} ne '') {
-                                $resulttext .= '<li>'.&mt('Server: [_1] log-in page now redirects to [_2]',$lonhost,$servers{$env{'form.'.$lonhost.'_serverurl'}}).'</li>';
+                            if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
+                                if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
+                                    my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
+                                    $protocol = 'http' if ($protocol ne 'https');
+                                    my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
+
+                                    if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
+                                        $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
+                                    } else {
+                                        $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
+                                    }
+                                    $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
+                                    if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
+                                        $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
+                                    }
+                                    $resulttext .= '</li>';
+                                } else {
+                                    $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
+                                }
                             } else {
-                                $resulttext .= '<li>'.&mt('Server: [_1] now has standard log-in page.',$lonhost).'</li>';
+                                $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
                             }
                         }
-                        $resulttext .= '</ul></li>'; 
+                        $resulttext .= '</ul></li>';
                     }
                 } else {
                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
@@ -4220,12 +4841,12 @@ sub modify_quotas {
                     $changes{'notify'}{'approval'} = 1;
                 }
             } else {
-                if ($domconfig{$action}{'notify'}{'approval'}) {
+                if ($confhash{'notify'}{'approval'}) {
                     $changes{'notify'}{'approval'} = 1;
                 }
             }
         } else {
-            if ($domconfig{$action}{'notify'}{'approval'}) {
+            if ($confhash{'notify'}{'approval'}) {
                 $changes{'notify'}{'approval'} = 1;
             }
         }
@@ -4454,7 +5075,8 @@ sub modify_autoenroll {
     }
     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
     my %title = ( run => 'Auto-enrollment active',
-                  sender => 'Sender for notification messages');
+                  sender => 'Sender for notification messages',
+                  coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
     my @offon = ('off','on');
     my $sender_uname = $env{'form.sender_uname'};
     my $sender_domain = $env{'form.sender_domain'};
@@ -4463,11 +5085,12 @@ sub modify_autoenroll {
     } elsif ($sender_uname eq '') {
         $sender_domain = '';
     }
+    my $coowners = $env{'form.autoassign_coowners'};
     my %autoenrollhash =  (
-                       autoenroll => { run => $env{'form.autoenroll_run'},
-                                       sender_uname => $sender_uname,
-                                       sender_domain => $sender_domain,
-
+                       autoenroll => { 'run' => $env{'form.autoenroll_run'},
+                                       'sender_uname' => $sender_uname,
+                                       'sender_domain' => $sender_domain,
+                                       'co-owners' => $coowners,
                                 }
                      );
     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
@@ -4488,6 +5111,13 @@ sub modify_autoenroll {
         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
             $changes{'sender'} = 1;
         }
+        if ($currautoenroll{'co-owners'} ne '') {
+            if ($currautoenroll{'co-owners'} ne $coowners) {
+                $changes{'coowners'} = 1;
+            }
+        } elsif ($coowners) {
+            $changes{'coowners'} = 1;
+        }      
         if (keys(%changes) > 0) {
             $resulttext = &mt('Changes made:').'<ul>';
             if ($changes{'run'}) {
@@ -4500,6 +5130,10 @@ sub modify_autoenroll {
                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                 }
             }
+            if ($changes{'coowners'}) {
+                $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
+                &Apache::loncommon::devalidate_domconfig_cache($dom);
+            }
             $resulttext .= '</ul>';
         } else {
             $resulttext = &mt('No changes made to auto-enrollment settings');
@@ -4531,21 +5165,43 @@ sub modify_autoupdate {
                         lastname => 'Last Name',
                         firstname => 'First Name',
                         middlename => 'Middle Name',
-                        gen => 'Generation',
+                        generation => 'Generation',
                       );
-    my $othertitle = &mt('All users');
+    $othertitle = &mt('All users');
     if (keys(%{$usertypes}) >  0) {
         $othertitle = &mt('Other users');
     }
     foreach my $key (keys(%env)) {
         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
-            push(@{$fields{$1}},$2);
+            my ($usertype,$item) = ($1,$2);
+            if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
+                if ($usertype eq 'default') {   
+                    push(@{$fields{$1}},$2);
+                } elsif (ref($types) eq 'ARRAY') {
+                    if (grep(/^\Q$usertype\E$/,@{$types})) {
+                        push(@{$fields{$1}},$2);
+                    }
+                }
+            }
+        }
+    }
+    my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
+    @lockablenames = sort(@lockablenames);
+    if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
+        my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
+        if (@changed) {
+            $changes{'lockablenames'} = 1;
+        }
+    } else {
+        if (@lockablenames) {
+            $changes{'lockablenames'} = 1;
         }
     }
     my %updatehash = (
                       autoupdate => { run => $env{'form.autoupdate_run'},
                                       classlists => $env{'form.classlists'},
                                       fields => {%fields},
+                                      lockablenames => \@lockablenames,
                                     }
                      );
     foreach my $key (keys(%currautoupdate)) {
@@ -4563,9 +5219,11 @@ sub modify_autoupdate {
                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                             if (!exists($fields{$item})) {
                                 $change = 1;
+                                last;
                             } elsif (ref($fields{$item}) eq 'ARRAY') {
                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
                                     $change = 1;
+                                    last;
                                 }
                             }
                         }
@@ -4575,12 +5233,41 @@ sub modify_autoupdate {
                     } 
                 }
             }
+        } elsif ($key eq 'lockablenames') {
+            if (ref($currautoupdate{$key}) eq 'ARRAY') {
+                my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
+                if (@changed) {
+                    $changes{'lockablenames'} = 1;
+                }
+            } else {
+                if (@lockablenames) {
+                    $changes{'lockablenames'} = 1;
+                }
+            }
+        }
+    }
+    unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
+        if (@lockablenames) {
+            $changes{'lockablenames'} = 1;
         }
     }
     foreach my $item (@{$types},'default') {
         if (defined($fields{$item})) {
             if (ref($currautoupdate{'fields'}) eq 'HASH') {
-                if (!exists($currautoupdate{'fields'}{$item})) {
+                if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
+                    my $change = 0;
+                    if (ref($fields{$item}) eq 'ARRAY') {
+                        foreach my $type (@{$fields{$item}}) {
+                            if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
+                                $change = 1;
+                                last;
+                            }
+                        }
+                    }
+                    if ($change) {
+                        push(@{$changes{'fields'}},$item);
+                    }
+                } else {
                     push(@{$changes{'fields'}},$item);
                 }
             } else {
@@ -4594,7 +5281,17 @@ sub modify_autoupdate {
         if (keys(%changes) > 0) {
             $resulttext = &mt('Changes made:').'<ul>';
             foreach my $key (sort(keys(%changes))) {
-                if (ref($changes{$key}) eq 'ARRAY') {
+                if ($key eq 'lockablenames') {
+                    $resulttext .= '<li>';
+                    if (@lockablenames) {
+                        $usertypes->{'default'} = $othertitle;
+                        $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
+                                   join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
+                    } else {
+                        $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
+                    }
+                    $resulttext .= '</li>';
+                } elsif (ref($changes{$key}) eq 'ARRAY') {
                     foreach my $item (@{$changes{$key}}) {
                         my @newvalues;
                         foreach my $type (@{$fields{$item}}) {
@@ -4633,6 +5330,78 @@ sub modify_autoupdate {
     return $resulttext;
 }
 
+sub modify_autocreate {
+    my ($dom,%domconfig) = @_;
+    my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
+    if (ref($domconfig{'autocreate'}) eq 'HASH') {
+        foreach my $key (keys(%{$domconfig{'autocreate'}})) {
+            $currautocreate{$key} = $domconfig{'autocreate'}{$key};
+        }
+    }
+    my %title= ( xml => 'Auto-creation of courses in XML course description files',
+                 req => 'Auto-creation of validated requests for official courses',
+                 xmldc => 'Identity of course creator of courses from XML files',
+               );
+    my @types = ('xml','req');
+    foreach my $item (@types) {
+        $newvals{$item} = $env{'form.autocreate_'.$item};
+        $newvals{$item} =~ s/\D//g;
+        $newvals{$item} = 0 if ($newvals{$item} eq '');
+    }
+    $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
+    my %domcoords = &get_active_dcs($dom);
+    unless (exists($domcoords{$newvals{'xmldc'}})) {
+        $newvals{'xmldc'} = '';
+    } 
+    %autocreatehash =  (
+                        autocreate => { xml => $newvals{'xml'},
+                                        req => $newvals{'req'},
+                                      }
+                       );
+    if ($newvals{'xmldc'} ne '') {
+        $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
+    }
+    my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
+                                             $dom);
+    if ($putresult eq 'ok') {
+        my @items = @types;
+        if ($newvals{'xml'}) {
+            push(@items,'xmldc');
+        }
+        foreach my $item (@items) {
+            if (exists($currautocreate{$item})) {
+                if ($currautocreate{$item} ne $newvals{$item}) {
+                    $changes{$item} = 1;
+                }
+            } elsif ($newvals{$item}) {
+                $changes{$item} = 1;
+            }
+        }
+        if (keys(%changes) > 0) {
+            my @offon = ('off','on'); 
+            $resulttext = &mt('Changes made:').'<ul>';
+            foreach my $item (@types) {
+                if ($changes{$item}) {
+                    my $newtxt = $offon[$newvals{$item}];
+                    $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
+                }
+            }
+            if ($changes{'xmldc'}) {
+                my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
+                my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
+                $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
+            }
+            $resulttext .= '</ul>';
+        } else {
+            $resulttext = &mt('No changes made to auto-creation settings');
+        }
+    } else {
+        $resulttext = '<span class="LC_error">'.
+            &mt('An error occurred: [_1]',$putresult).'</span>';
+    }
+    return $resulttext;
+}
+
 sub modify_directorysrch {
     my ($dom,%domconfig) = @_;
     my ($resulttext,%changes);
@@ -4815,7 +5584,7 @@ sub modify_contacts {
             $currsetting{$key} = $domconfig{'contacts'}{$key};
         }
     }
-    my (%others,%to);
+    my (%others,%to,%bcc);
     my @contacts = ('supportemail','adminemail');
     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
                     'requestsmail');
@@ -4831,6 +5600,10 @@ sub modify_contacts {
         }  
         $others{$type} = $env{'form.'.$type.'_others'};
         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
+        if ($type eq 'helpdeskmail') {
+            $bcc{$type} = $env{'form.'.$type.'_bcc'};
+            $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
+        }
     }
     foreach my $item (@contacts) {
         $to{$item} = $env{'form.'.$item};
@@ -4855,6 +5628,11 @@ sub modify_contacts {
             if ($others{$type} ne $currsetting{$type}{'others'}) {
                 push(@{$changes{$type}},'others');
             }
+            if ($type eq 'helpdeskmail') {   
+                if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
+                    push(@{$changes{$type}},'bcc'); 
+                }
+            }
         }
     } else {
         my %default;
@@ -4877,7 +5655,12 @@ sub modify_contacts {
             }
             if ($others{$type} ne '') {
                 push(@{$changes{$type}},'others');
-            } 
+            }
+            if ($type eq 'helpdeskmail') {
+                if ($bcc{$type} ne '') {
+                    push(@{$changes{$type}},'bcc');
+                }
+            }
         }
     }
     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
@@ -4905,7 +5688,13 @@ sub modify_contacts {
                         push(@text,$others{$type});
                     }
                     $resulttext .= '<span class="LC_cusr_emph">'.
-                                   join(', ',@text).'</span></li>';
+                                   join(', ',@text).'</span>';
+                    if ($type eq 'helpdeskmail') {
+                        if ($bcc{$type} ne '') {
+                            $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
+                        }
+                    }
+                    $resulttext .= '</li>';
                 }
             }
             $resulttext .= '</ul>';
@@ -5387,7 +6176,7 @@ sub modify_usermodification {
                             }
                             my @modifiable;
                             if ($context eq 'selfcreate') {
-                                $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]  ',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
+                                $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
                             } else {
                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                             }
@@ -5422,7 +6211,7 @@ sub modify_defaults {
     my ($dom,$r) = @_;
     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
-    my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
+    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) {
         $newvalues{$item} = $env{'form.'.$item};
@@ -5458,6 +6247,12 @@ sub modify_defaults {
                     push(@errors,$item);
                 }
             }
+        } elsif ($item eq 'portal_def') {
+            if ($newvalues{$item} ne '') {
+                unless ($newvalues{$item} =~ /^https?\:\/\/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/?$/) {
+                    push(@errors,$item);
+                }
+            }
         }
         if (grep(/^\Q$item\E$/,@errors)) {
             $newvalues{$item} = $domdefaults{$item};
@@ -5531,7 +6326,7 @@ sub modify_scantron {
         my $error;
         if ($configuserok eq 'ok') {
             if ($switchserver) {
-                $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
+                $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
             } else {
                 if ($author_ok eq 'ok') {
                     my ($result,$scantronurl) =
@@ -5571,25 +6366,25 @@ sub modify_scantron {
                 if (ref($confhash{'scantron'}) eq 'HASH') {
                     $resulttext = &mt('Changes made:').'<ul>';
                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
-                        $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
+                        $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                     } else {
-                        $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
+                        $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                     }
                     $resulttext .= '</ul>';
                 } else {
-                    $resulttext = &mt('Changes made to scantron format file.');
+                    $resulttext = &mt('Changes made to bubblesheet format file.');
                 }
                 $resulttext .= '</ul>';
                 &Apache::loncommon::devalidate_domconfig_cache($dom);
             } else {
-                $resulttext = &mt('No changes made to scantron format file');
+                $resulttext = &mt('No changes made to bubblesheet format file');
             }
         } else {
             $resulttext = '<span class="LC_error">'.
                 &mt('An error occurred: [_1]',$putresult).'</span>';
         }
     } else {
-        $resulttext = &mt('No changes made to scantron format file'); 
+        $resulttext = &mt('No changes made to bubblesheet format file'); 
     }
     if ($errors) {
         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
@@ -5624,15 +6419,13 @@ sub modify_coursecategories {
     } else {
         $changes{'togglecats'} = 1;
         $changes{'categorize'} = 1;
-        $domconfig{'coursecategories'} = {
-                                             togglecats => $env{'form.togglecats'},
-                                             categorize => $env{'form.categorize'},
-                                         };
         $changes{'togglecatscomm'} = 1;
         $changes{'categorizecomm'} = 1;
         $domconfig{'coursecategories'} = {
-                                             togglecats => $env{'form.togglecatscomm'},
-                                             categorize => $env{'form.categorizecomm'},
+                                             togglecats => $env{'form.togglecats'},
+                                             categorize => $env{'form.categorize'},
+                                             togglecatscomm => $env{'form.togglecatscomm'},
+                                             categorizecomm => $env{'form.categorizecomm'},
                                          };
     }
     if (ref($cathash) eq 'HASH') {
@@ -5876,7 +6669,6 @@ sub modify_serverstatuses {
     my %serverstatushash =  (
                                 serverstatuses => \%newserverstatus,
                             );
-    my %changes;
     foreach my $type (@pages) {
         foreach my $setting ('namedusers','machines') {
             my (@current,@new);
@@ -6033,7 +6825,14 @@ sub modify_helpsettings {
         }
     }
     
-    my $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
+    
+    my $putresult;
+    
+    if (keys(%changes) > 0) {
+    	$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
+    } else {
+    	$putresult = 'ok';
+    }
                                              
     if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {
@@ -6099,6 +6898,18 @@ 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;
+            }
+        }
     }
     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                                              $dom);
@@ -6118,6 +6929,8 @@ sub modify_coursedefaults {
                     } else {
                         $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 .= '</ul>';
@@ -6131,6 +6944,274 @@ sub modify_coursedefaults {
     return $resulttext;
 }
 
+sub modify_usersessions {
+    my ($dom,%domconfig) = @_;
+    my @hostingtypes = ('version','excludedomain','includedomain');
+    my @offloadtypes = ('primary','default');
+    my %types = (
+                  remote => \@hostingtypes,
+                  hosted => \@hostingtypes,
+                  spares => \@offloadtypes,
+                );
+    my @prefixes = ('remote','hosted','spares');
+    my @lcversions = &Apache::lonnet::all_loncaparevs();
+    my (%by_ip,%by_location,@intdoms);
+    &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
+    my @locations = sort(keys(%by_location));
+    my (%defaultshash,%changes);
+    foreach my $prefix (@prefixes) {
+        $defaultshash{'usersessions'}{$prefix} = {};
+    }
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+    my $resulttext;
+    my %iphost = &Apache::lonnet::get_iphost();
+    foreach my $prefix (@prefixes) {
+        next if ($prefix eq 'spares');
+        foreach my $type (@{$types{$prefix}}) {
+            my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
+            if ($type eq 'version') {
+                my $value = $env{'form.'.$prefix.'_'.$type};
+                my $okvalue;
+                if ($value ne '') {
+                    if (grep(/^\Q$value\E$/,@lcversions)) {
+                        $okvalue = $value;
+                    }
+                }
+                if (ref($domconfig{'usersessions'}) eq 'HASH') {
+                    if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
+                        if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
+                            if ($inuse == 0) {
+                                $changes{$prefix}{$type} = 1;
+                            } else {
+                                if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
+                                    $changes{$prefix}{$type} = 1;
+                                }
+                                if ($okvalue ne '') {
+                                    $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
+                                } 
+                            }
+                        } else {
+                            if (($inuse == 1) && ($okvalue ne '')) {
+                                $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
+                                $changes{$prefix}{$type} = 1;
+                            }
+                        }
+                    } else {
+                        if (($inuse == 1) && ($okvalue ne '')) {
+                            $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
+                            $changes{$prefix}{$type} = 1;
+                        }
+                    }
+                } else {
+                    if (($inuse == 1) && ($okvalue ne '')) {
+                        $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
+                        $changes{$prefix}{$type} = 1;
+                    }
+                }
+            } else {
+                my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
+                my @okvals;
+                foreach my $val (@vals) {
+                    if ($val =~ /:/) {
+                        my @items = split(/:/,$val);
+                        foreach my $item (@items) {
+                            if (ref($by_location{$item}) eq 'ARRAY') {
+                                push(@okvals,$item);
+                            }
+                        }
+                    } else {
+                        if (ref($by_location{$val}) eq 'ARRAY') {
+                            push(@okvals,$val);
+                        }
+                    }
+                }
+                @okvals = sort(@okvals);
+                if (ref($domconfig{'usersessions'}) eq 'HASH') {
+                    if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
+                        if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
+                            if ($inuse == 0) {
+                                $changes{$prefix}{$type} = 1; 
+                            } else {
+                                $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
+                                my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
+                                if (@changed > 0) {
+                                    $changes{$prefix}{$type} = 1;
+                                }
+                            }
+                        } else {
+                            if ($inuse == 1) {
+                                $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
+                                $changes{$prefix}{$type} = 1;
+                            }
+                        } 
+                    } else {
+                        if ($inuse == 1) {
+                            $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
+                            $changes{$prefix}{$type} = 1;
+                        }
+                    }
+                } else {
+                    if ($inuse == 1) {
+                        $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
+                        $changes{$prefix}{$type} = 1;
+                    }
+                }
+            }
+        }
+    }
+
+    my @alldoms = &Apache::lonnet::all_domains();
+    my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
+    my %servers = &dom_servers($dom);
+    my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
+    my $savespares;
+
+    foreach my $lonhost (sort(keys(%servers))) {
+        my $serverhomeID =
+            &Apache::lonnet::get_server_homeID($servers{$lonhost});
+        $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
+        my %spareschg;
+        foreach my $type (@{$types{'spares'}}) {
+            my @okspares;
+            my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
+            foreach my $server (@checked) {
+                unless (($server eq $lonhost) || ($server eq $serverhomeID)) {
+                    if ($uniques{$server}) {
+                        push(@okspares,$server);
+                    }
+                }
+            }
+            my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
+            my $newspare;
+            if (($new ne '') && ($uniques{$new})) {
+                unless (($new eq $lonhost) || ($new eq $serverhomeID)) {
+                    $newspare = $new;
+                    $spareschg{$type} = 1;
+                }
+            }
+            if (ref($spareid{$lonhost}) eq 'HASH') {
+                if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
+                    my @diffs = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{'spares'}{$lonhost}{$type},\@okspares);
+                    if (@diffs > 0) {
+                        $spareschg{$type} = 1;
+                    } elsif ($new ne '') {
+                        $spareschg{$type} = 1;
+                    }
+                }
+            }
+            my @spares;
+            if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
+                @spares = sort(@okspares,$newspare);
+            } else {
+                @spares = sort(@okspares);
+            }
+            $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
+        }
+        if (keys(%spareschg) > 0) {
+            $changes{'spares'}{$lonhost} = \%spareschg;
+        }
+    }
+
+    if (ref($domconfig{'usersessions'}) eq 'HASH') {
+        if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
+            if (ref($changes{'spares'}) eq 'HASH') {
+                if (keys(%{$changes{'spares'}}) > 0) {
+                    $savespares = 1;
+                }
+            }
+        } else {
+            $savespares = 1;
+        }
+    }
+
+    my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
+    if ((keys(%changes) > 0) || ($savespares)) {
+        my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
+                                                 $dom);
+        if ($putresult eq 'ok') {
+            if (ref($defaultshash{'usersessions'}) eq 'HASH') {
+                if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
+                    $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
+                }
+                if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
+                    $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
+                }
+            }
+            my $cachetime = 24*60*60;
+            &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+            if (keys(%changes) > 0) {
+                my %lt = &usersession_titles();
+                $resulttext = &mt('Changes made:').'<ul>';
+                foreach my $prefix (@prefixes) {
+                    if (ref($changes{$prefix}) eq 'HASH') {
+                        $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
+                        if ($prefix eq 'spares') {
+                            if (ref($changes{$prefix}) eq 'HASH') {
+                                foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
+                                    $resulttext .= '<li><b>'.$lonhost.'</b> ';
+                                    if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
+                                        foreach my $type (@{$types{$prefix}}) {
+                                            if ($changes{$prefix}{$lonhost}{$type}) {
+                                                my $offloadto = &mt('None');
+                                                if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
+                                                    if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
+                                                        $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
+                                                    }
+                                                }
+                                                $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
+                                            }
+                                        }
+                                    }
+                                    $resulttext .= '</li>';
+                                }
+                            }
+                        } else {
+                            foreach my $type (@{$types{$prefix}}) {
+                                if (defined($changes{$prefix}{$type})) {
+                                    my $newvalue;
+                                    if (ref($defaultshash{'usersessions'}) eq 'HASH') {
+                                        if (ref($defaultshash{'usersessions'}{$prefix})) {
+                                            if ($type eq 'version') {
+                                                $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
+                                            } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
+                                                if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
+                                                    $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
+                                                }
+                                            }
+                                        }
+                                    }
+                                    if ($newvalue eq '') {
+                                        if ($type eq 'version') {
+                                            $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
+                                        } else {
+                                            $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
+                                        }
+                                    } else {
+                                        if ($type eq 'version') {
+                                            $newvalue .= ' '.&mt('(or later)'); 
+                                        }
+                                        $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
+                                    }
+                                }
+                            }
+                        }
+                        $resulttext .= '</ul>';
+                    }
+                }
+                $resulttext .= '</ul>';
+            } else {
+                $resulttext = $nochgmsg;
+            }
+        } else {
+            $resulttext = '<span class="LC_error">'.
+                          &mt('An error occurred: [_1]',$putresult).'</span>';
+        }
+    } else {
+        $resulttext = $nochgmsg;
+    }
+    return $resulttext;
+}
+
 sub recurse_check {
     my ($chkcats,$categories,$depth,$name) = @_;
     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
@@ -6204,4 +7285,88 @@ sub dom_servers {
     return %uniqservers;
 }
 
+sub get_active_dcs {
+    my ($dom) = @_;
+    my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
+    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};
+                }
+            }
+        }
+    }
+    return %domcoords;
+}
+
+sub active_dc_picker {
+    my ($dom,$curr_dc) = @_;
+    my %domcoords = &get_active_dcs($dom); 
+    my @dcs = sort(keys(%domcoords));
+    my $numdcs = scalar(@dcs); 
+    my $datatable;
+    my $numinrow = 2;
+    if ($numdcs > 1) {
+        $datatable = '<table>';
+        for (my $i=0; $i<@dcs; $i++) {
+            my $rem = $i%($numinrow);
+            if ($rem == 0) {
+                if ($i > 0) {
+                    $datatable .= '</tr>';
+                }
+                $datatable .= '<tr>';
+            }
+            my $check = ' ';
+            if ($curr_dc eq '') {
+                if (!$i) { 
+                    $check = ' checked="checked" ';
+                }
+            } elsif ($dcs[$i] eq $curr_dc) {
+                $check = ' checked="checked" ';
+            }
+            if ($i == @dcs - 1) {
+                my $colsleft = $numinrow - $rem;
+                if ($colsleft > 1) {
+                    $datatable .= '<td colspan="'.$colsleft.'">';
+                } else {
+                    $datatable .= '<td>';
+                }
+            } else {
+                $datatable .= '<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).
+                          '</label></span></td>';
+        }
+        $datatable .= '</tr></table>';
+    } elsif (@dcs) {
+        $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
+                      $dcs[0].'" />';
+    }
+    return ($numdcs,$datatable);
+}
+
+sub usersession_titles {
+    return &Apache::lonlocal::texthash(
+               hosted => 'Hosting of sessions for users from other domains on servers in this domain',
+
+               remote => 'Hosting of sessions for users in this domain on servers in other domains',
+               spares => 'Servers offloaded to, when busy',
+               version => 'LON-CAPA version requirement',
+               excludedomain => 'Allow all, but exclude specific domains',
+               includedomain => 'Deny all, but include specific domains',
+               primary => 'Primary (checked first)',
+               default => 'Default', 
+           );
+}
+
 1;