File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.146: download - view: text, annotated - select for diffs
Mon Aug 1 19:46:49 2011 UTC (12 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Check if selection for new spare was not blank.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.146 2011/08/01 19:46:49 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
   23: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: #
   28: ###############################################################
   29: ##############################################################
   30: 
   31: =pod
   32: 
   33: =head1 NAME
   34: 
   35: Apache::domainprefs.pm
   36: 
   37: =head1 SYNOPSIS
   38: 
   39: Handles configuration of a LON-CAPA domain.  
   40: 
   41: This is part of the LearningOnline Network with CAPA project
   42: described at http://www.lon-capa.org.
   43: 
   44: 
   45: =head1 OVERVIEW
   46: 
   47: Each institution using LON-CAPA will typically have a single domain designated 
   48: for use by individuals affliated with the institution.  Accordingly, each domain
   49: may define a default set of logos and a color scheme which can be used to "brand"
   50: the LON-CAPA instance. In addition, an institution will typically have a language
   51: and timezone which are used for the majority of courses.
   52: 
   53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
   54: host of other domain-wide settings which determine the types of functionality
   55: available to users and courses in the domain.
   56: 
   57: There is also a mechanism to configure cataloging of courses in the domain, and
   58: controls on the operation of automated processes which govern such things as
   59: roster updates, user directory updates and processing of course requests.
   60: 
   61: The domain coordination manual which is built dynamically on install/update of 
   62: LON-CAPA from the relevant help items provides more information about domain 
   63: configuration.
   64: 
   65: Most of the domain settings are stored in the configuration.db GDBM file which is
   66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
   67: where $dom is the domain.  The configuration.db stores settings in a number of 
   68: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
   69: the domain as files (e.g., image files for logos etc., or plain text files for
   70: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
   71: session hosted on the primary library server in the domain, as these files are 
   72: stored in author space belonging to a special $dom-domainconfig user.   
   73: 
   74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
   75: the current settings, and provides an interface to make modifications.
   76: 
   77: =head1 SUBROUTINES
   78: 
   79: =over
   80: 
   81: =item print_quotas()
   82: 
   83: Inputs: 4 
   84: 
   85: $dom,$settings,$rowtotal,$action.
   86: 
   87: $dom is the domain, $settings is a reference to a hash of current settings for
   88: the current context, $rowtotal is a reference to the scalar used to record the 
   89: number of rows displayed on the page, and $action is the context (either quotas 
   90: or requestcourses).
   91: 
   92: The print_quotas routine was orginally created to display/store information
   93: about default quota sizes for portfolio spaces for the different types of 
   94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
   95: but is now also used to manage availability of user tools: 
   96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
   97: used by course owners to request creation of a course.
   98: 
   99: Outputs: 1
  100: 
  101: $datatable  - HTML containing form elements which allow settings to be changed. 
  102: 
  103: In the case of course requests, radio buttons are displayed for each institutional
  104: affiliate type (and also default, and _LC_adv) for each of the course types 
  105: (official, unofficial and community).  In each case the radio buttons allow the 
  106: selection of one of four values:
  107: 
  108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
  109: which have the following effects:
  110: 
  111: 0
  112: 
  113: =over
  114: 
  115: - course requests are not allowed for this course types/affiliation
  116: 
  117: =back
  118: 
  119: approval 
  120: 
  121: =over 
  122: 
  123: - course requests must be approved by a Doman Coordinator in the 
  124: course's domain
  125: 
  126: =back
  127: 
  128: validate 
  129: 
  130: =over
  131: 
  132: - an institutional validation (e.g., check requestor is instructor
  133: of record) needs to be passed before the course will be created.  The required
  134: validation is in localenroll.pm on the primary library server for the course 
  135: domain.
  136: 
  137: =back
  138: 
  139: autolimit 
  140: 
  141: =over
  142:  
  143: - course requests will be processed automatically up to a limit of
  144: N requests for the course type for the particular requestor.
  145: If N is undefined, there is no limit to the number of course requests
  146: which a course owner may submit and have processed automatically. 
  147: 
  148: =back
  149: 
  150: =item modify_quotas() 
  151: 
  152: =back
  153: 
  154: =cut
  155: 
  156: package Apache::domainprefs;
  157: 
  158: use strict;
  159: use Apache::Constants qw(:common :http);
  160: use Apache::lonnet;
  161: use Apache::loncommon();
  162: use Apache::lonhtmlcommon();
  163: use Apache::lonlocal;
  164: use Apache::lonmsg();
  165: use Apache::lonconfigsettings;
  166: use LONCAPA qw(:DEFAULT :match);
  167: use LONCAPA::Enrollment;
  168: use LONCAPA::lonauthcgi();
  169: use File::Copy;
  170: use Locale::Language;
  171: use DateTime::TimeZone;
  172: use DateTime::Locale;
  173: 
  174: sub handler {
  175:     my $r=shift;
  176:     if ($r->header_only) {
  177:         &Apache::loncommon::content_type($r,'text/html');
  178:         $r->send_http_header;
  179:         return OK;
  180:     }
  181: 
  182:     my $context = 'domain';
  183:     my $dom = $env{'request.role.domain'};
  184:     my $domdesc = &Apache::lonnet::domain($dom,'description');
  185:     if (&Apache::lonnet::allowed('mau',$dom)) {
  186:         &Apache::loncommon::content_type($r,'text/html');
  187:         $r->send_http_header;
  188:     } else {
  189:         $env{'user.error.msg'}=
  190:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
  191:         return HTTP_NOT_ACCEPTABLE;
  192:     }
  193:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  194:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  195:                                             ['phase','actions']);
  196:     my $phase = 'pickactions';
  197:     if ( exists($env{'form.phase'}) ) {
  198:         $phase = $env{'form.phase'};
  199:     }
  200:     my %domconfig =
  201:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
  202:                 'quotas','autoenroll','autoupdate','autocreate',
  203:                 'directorysrch','usercreation','usermodification',
  204:                 'contacts','defaults','scantron','coursecategories',
  205:                 'serverstatuses','requestcourses','helpsettings',
  206:                 'coursedefaults','usersessions'],$dom);
  207:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
  208:                        'autoupdate','autocreate','directorysrch','contacts',
  209:                        'usercreation','usermodification','scantron',
  210:                        'requestcourses','coursecategories','serverstatuses','helpsettings',
  211:                        'coursedefaults','usersessions');
  212:     my %prefs = (
  213:         'rolecolors' =>
  214:                    { text => 'Default color schemes',
  215:                      help => 'Domain_Configuration_Color_Schemes',
  216:                      header => [{col1 => 'Student Settings',
  217:                                  col2 => '',},
  218:                                 {col1 => 'Coordinator Settings',
  219:                                  col2 => '',},
  220:                                 {col1 => 'Author Settings',
  221:                                  col2 => '',},
  222:                                 {col1 => 'Administrator Settings',
  223:                                  col2 => '',}],
  224:                     },
  225:         'login' =>
  226:                     { text => 'Log-in page options',
  227:                       help => 'Domain_Configuration_Login_Page',
  228:                       header => [{col1 => 'Item',
  229:                                   col2 => '',}],
  230:                     },
  231: 
  232:         'defaults' => 
  233:                     { text => 'Default authentication/language/timezone/portal',
  234:                       help => 'Domain_Configuration_LangTZAuth',
  235:                       header => [{col1 => 'Setting',
  236:                                   col2 => 'Value'}],
  237:                     },
  238:         'quotas' => 
  239:                     { text => 'User blogs, personal information pages, portfolios',
  240:                       help => 'Domain_Configuration_Quotas',
  241:                       header => [{col1 => 'User affiliation',
  242:                                   col2 => 'Available tools',
  243:                                   col3 => 'Portfolio quota',}],
  244:                     },
  245:         'autoenroll' =>
  246:                    { text => 'Auto-enrollment settings',
  247:                      help => 'Domain_Configuration_Auto_Enrollment',
  248:                      header => [{col1 => 'Configuration setting',
  249:                                  col2 => 'Value(s)'}],
  250:                    },
  251:         'autoupdate' => 
  252:                    { text => 'Auto-update settings',
  253:                      help => 'Domain_Configuration_Auto_Updates',
  254:                      header => [{col1 => 'Setting',
  255:                                  col2 => 'Value',},
  256:                                 {col1 => 'Setting',
  257:                                  col2 => 'Affiliation'},
  258:                                 {col1 => 'User population',
  259:                                  col2 => 'Updateable user data'}],
  260:                   },
  261:         'autocreate' => 
  262:                   { text => 'Auto-course creation settings',
  263:                      help => 'Domain_Configuration_Auto_Creation',
  264:                      header => [{col1 => 'Configuration Setting',
  265:                                  col2 => 'Value',}],
  266:                   },
  267:         'directorysrch' => 
  268:                   { text => 'Institutional directory searches',
  269:                     help => 'Domain_Configuration_InstDirectory_Search',
  270:                     header => [{col1 => 'Setting',
  271:                                 col2 => 'Value',}],
  272:                   },
  273:         'contacts' =>
  274:                   { text => 'Contact Information',
  275:                     help => 'Domain_Configuration_Contact_Info',
  276:                     header => [{col1 => 'Setting',
  277:                                 col2 => 'Value',}],
  278:                   },
  279: 
  280:         'usercreation' => 
  281:                   { text => 'User creation',
  282:                     help => 'Domain_Configuration_User_Creation',
  283:                     header => [{col1 => 'Format rule type',
  284:                                 col2 => 'Format rules in force'},
  285:                                {col1 => 'User account creation',
  286:                                 col2 => 'Usernames which may be created',},
  287:                                {col1 => 'Context',
  288:                                 col2 => 'Assignable authentication types'}],
  289:                   },
  290:         'usermodification' =>
  291:                   { text => 'User modification',
  292:                     help => 'Domain_Configuration_User_Modification',
  293:                     header => [{col1 => 'Target user has role',
  294:                                 col2 => 'User information updateable in author context'},
  295:                                {col1 => 'Target user has role',
  296:                                 col2 => 'User information updateable in course context'},
  297:                                {col1 => "Status of user",
  298:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
  299:                   },
  300:         'scantron' =>
  301:                   { text => 'Bubblesheet format file',
  302:                     help => 'Domain_Configuration_Scantron_Format',
  303:                     header => [ {col1 => 'Item',
  304:                                  col2 => '',
  305:                               }],
  306:                   },
  307:         'requestcourses' => 
  308:                  {text => 'Request creation of courses',
  309:                   help => 'Domain_Configuration_Request_Courses',
  310:                   header => [{col1 => 'User affiliation',
  311:                               col2 => 'Availability/Processing of requests',},
  312:                              {col1 => 'Setting',
  313:                               col2 => 'Value'}],
  314:                  },
  315:         'coursecategories' =>
  316:                   { text => 'Cataloging of courses/communities',
  317:                     help => 'Domain_Configuration_Cataloging_Courses',
  318:                     header => [{col1 => 'Category settings',
  319:                                 col2 => '',},
  320:                                {col1 => 'Categories',
  321:                                 col2 => '',
  322:                                }],
  323:                   },
  324:         'serverstatuses' =>
  325:                  {text   => 'Access to server status pages',
  326:                   help   => 'Domain_Configuration_Server_Status',
  327:                   header => [{col1 => 'Status Page',
  328:                               col2 => 'Other named users',
  329:                               col3 => 'Specific IPs',
  330:                             }],
  331:                  },
  332:         'helpsettings' =>
  333:                  {text   => 'Help page settings',
  334:                   help   => 'Domain_Configuration_Help_Settings',
  335:                   header => [{col1 => 'Authenticated Help Settings',
  336:                               col2 => ''},
  337:                              {col1 => 'Unauthenticated Help Settings',
  338:                               col2 => ''}],
  339:                  },
  340:         'coursedefaults' => 
  341:                  {text => 'Course/Community defaults',
  342:                   help => 'Domain_Configuration_Course_Defaults',
  343:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
  344:                               col2 => 'Value',},
  345:                              {col1 => 'Defaults which can be overridden for each course by a DC',
  346:                               col2 => 'Value',},],
  347:                  },
  348:         'privacy' => 
  349:                  {text   => 'User Privacy',
  350:                   help   => 'Domain_Configuration_User_Privacy',
  351:                   header => [{col1 => 'Setting',
  352:                               col2 => 'Value',}],
  353:                  },
  354:         'usersessions' =>
  355:                  {text  => 'User session hosting/offloading',
  356:                   help  => 'Domain_Configuration_User_Sessions',
  357:                   header => [{col1 => 'Domain server',
  358:                               col2 => 'Servers to offload sessions to when busy'},
  359:                              {col1 => 'Hosting of users from other domains',
  360:                               col2 => 'Rules'},
  361:                              {col1 => "Hosting domain's own users elsewhere",
  362:                               col2 => 'Rules'}],
  363:                  },
  364:     );
  365:     my %servers = &dom_servers($dom);
  366:     if (keys(%servers) > 1) {
  367:         $prefs{'login'}  = { text   => 'Log-in page options',
  368:                              help   => 'Domain_Configuration_Login_Page',
  369:                             header => [{col1 => 'Log-in Service',
  370:                                         col2 => 'Server Setting',},
  371:                                        {col1 => 'Log-in Page Items',
  372:                                         col2 => ''}],
  373:                            };
  374:     }
  375:     my @roles = ('student','coordinator','author','admin');
  376:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  377:     &Apache::lonhtmlcommon::add_breadcrumb
  378:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  379:       text=>"Settings to display/modify"});
  380:     my $confname = $dom.'-domainconfig';
  381:     if ($phase eq 'process') {
  382:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
  383:     } elsif ($phase eq 'display') {
  384:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname);
  385:     } else {
  386:         if (keys(%domconfig) == 0) {
  387:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  388:             my @ids=&Apache::lonnet::current_machine_ids();
  389:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  390:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  391:                 my @loginimages = ('img','logo','domlogo','login');
  392:                 my $custom_img_count = 0;
  393:                 foreach my $img (@loginimages) {
  394:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  395:                         $custom_img_count ++;
  396:                     }
  397:                 }
  398:                 foreach my $role (@roles) {
  399:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  400:                         $custom_img_count ++;
  401:                     }
  402:                 }
  403:                 if ($custom_img_count > 0) {
  404:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
  405:                     my $switch_server = &check_switchserver($dom,$confname);
  406:                     $r->print(
  407:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  408:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  409:     &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
  410:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  411:                     if ($switch_server) {
  412:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  413:                     }
  414:                     $r->print(&Apache::loncommon::end_page());
  415:                     return OK;
  416:                 }
  417:             }
  418:         }
  419:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
  420:     }
  421:     return OK;
  422: }
  423: 
  424: sub process_changes {
  425:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
  426:     my %domconfig;
  427:     if (ref($values) eq 'HASH') {
  428:         %domconfig = %{$values};
  429:     }
  430:     my $output;
  431:     if ($action eq 'login') {
  432:         $output = &modify_login($r,$dom,$confname,%domconfig);
  433:     } elsif ($action eq 'rolecolors') {
  434:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  435:                                      %domconfig);
  436:     } elsif ($action eq 'quotas') {
  437:         $output = &modify_quotas($dom,$action,%domconfig);
  438:     } elsif ($action eq 'autoenroll') {
  439:         $output = &modify_autoenroll($dom,%domconfig);
  440:     } elsif ($action eq 'autoupdate') {
  441:         $output = &modify_autoupdate($dom,%domconfig);
  442:     } elsif ($action eq 'autocreate') {
  443:         $output = &modify_autocreate($dom,%domconfig);
  444:     } elsif ($action eq 'directorysrch') {
  445:         $output = &modify_directorysrch($dom,%domconfig);
  446:     } elsif ($action eq 'usercreation') {
  447:         $output = &modify_usercreation($dom,%domconfig);
  448:     } elsif ($action eq 'usermodification') {
  449:         $output = &modify_usermodification($dom,%domconfig);
  450:     } elsif ($action eq 'contacts') {
  451:         $output = &modify_contacts($dom,%domconfig);
  452:     } elsif ($action eq 'defaults') {
  453:         $output = &modify_defaults($dom,$r);
  454:     } elsif ($action eq 'scantron') {
  455:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
  456:     } elsif ($action eq 'coursecategories') {
  457:         $output = &modify_coursecategories($dom,%domconfig);
  458:     } elsif ($action eq 'serverstatuses') {
  459:         $output = &modify_serverstatuses($dom,%domconfig);
  460:     } elsif ($action eq 'requestcourses') {
  461:         $output = &modify_quotas($dom,$action,%domconfig);
  462:     } elsif ($action eq 'helpsettings') {
  463:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
  464:     } elsif ($action eq 'coursedefaults') {
  465:         $output = &modify_coursedefaults($dom,%domconfig);
  466:     } elsif ($action eq 'usersessions') {
  467:         $output = &modify_usersessions($dom,%domconfig);
  468:     }
  469:     return $output;
  470: }
  471: 
  472: sub print_config_box {
  473:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  474:     my $rowtotal = 0;
  475:     my $output;
  476:     if ($action eq 'coursecategories') {
  477:         $output = &coursecategories_javascript($settings);
  478:     }
  479:     $output .= 
  480:          '<table class="LC_nested_outer">
  481:           <tr>
  482:            <th align="left" valign="middle"><span class="LC_nobreak">'.
  483:            &mt($item->{text}).'&nbsp;'.
  484:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
  485:           '</tr>';
  486:     $rowtotal ++;
  487:     my $numheaders = 1;
  488:     if (ref($item->{'header'}) eq 'ARRAY') {
  489:         $numheaders = scalar(@{$item->{'header'}});
  490:     }
  491:     if ($numheaders > 1) {
  492:         my $colspan = '';
  493:         my $rightcolspan = '';
  494:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
  495:             $colspan = ' colspan="2"';
  496:         }
  497:         if ($action eq 'usersessions') {
  498:             $rightcolspan = ' colspan="3"'; 
  499:         }
  500:         $output .= '
  501:           <tr>
  502:            <td>
  503:             <table class="LC_nested">
  504:              <tr class="LC_info_row">
  505:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
  506:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  507:              </tr>';
  508:         $rowtotal ++;
  509:         if ($action eq 'autoupdate') {
  510:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
  511:         } elsif ($action eq 'usercreation') {
  512:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
  513:         } elsif ($action eq 'usermodification') {
  514:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
  515:         } elsif ($action eq 'coursecategories') {
  516:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
  517:         } elsif ($action eq 'login') {
  518:             $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
  519:             $colspan = ' colspan="2"';
  520:         } elsif ($action eq 'requestcourses') {
  521:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  522:         } elsif ($action eq 'helpsettings') {
  523:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
  524:         } elsif ($action eq 'usersessions') {
  525:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
  526:         } elsif ($action eq 'rolecolors') {
  527:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  528:         } elsif ($action eq 'coursedefaults') {
  529:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
  530:         }
  531:         $output .= '
  532:            </table>
  533:           </td>
  534:          </tr>
  535:          <tr>
  536:            <td>
  537:             <table class="LC_nested">
  538:              <tr class="LC_info_row">
  539:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
  540:         $output .= '
  541:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
  542:              </tr>';
  543:             $rowtotal ++;
  544:         if ($action eq 'autoupdate') {
  545:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
  546:            </table>
  547:           </td>
  548:          </tr>
  549:          <tr>
  550:            <td>
  551:             <table class="LC_nested">
  552:              <tr class="LC_info_row">
  553:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  554:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  555:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
  556:             $rowtotal ++;
  557:         } elsif ($action eq 'usercreation') {
  558:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
  559:            </table>
  560:           </td>
  561:          </tr>
  562:          <tr>
  563:            <td>
  564:             <table class="LC_nested">
  565:              <tr class="LC_info_row">
  566:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  567:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
  568:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
  569:             $rowtotal ++;
  570:         } elsif ($action eq 'usermodification') {
  571:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
  572:            </table>
  573:           </td>
  574:          </tr>
  575:          <tr>
  576:            <td>
  577:             <table class="LC_nested">
  578:              <tr class="LC_info_row">
  579:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  580:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  581:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
  582:             $rowtotal ++;
  583:         } elsif ($action eq 'coursecategories') {
  584:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
  585:         } elsif ($action eq 'login') {
  586:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
  587:         } elsif ($action eq 'requestcourses') {
  588:             $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
  589:         } elsif ($action eq 'helpsettings') {
  590:             $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
  591:         } elsif ($action eq 'usersessions') {
  592:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
  593:            </table>
  594:           </td>
  595:          </tr>
  596:          <tr>
  597:            <td>
  598:             <table class="LC_nested">
  599:              <tr class="LC_info_row">
  600:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  601:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  602:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
  603:             $rowtotal ++;
  604:         } elsif ($action eq 'coursedefaults') {
  605:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
  606:         } elsif ($action eq 'rolecolors') {
  607:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  608:            </table>
  609:           </td>
  610:          </tr>
  611:          <tr>
  612:            <td>
  613:             <table class="LC_nested">
  614:              <tr class="LC_info_row">
  615:               <td class="LC_left_item"'.$colspan.' valign="top">'.
  616:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
  617:               <td class="LC_right_item" valign="top">'.
  618:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
  619:              </tr>'.
  620:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  621:            </table>
  622:           </td>
  623:          </tr>
  624:          <tr>
  625:            <td>
  626:             <table class="LC_nested">
  627:              <tr class="LC_info_row">
  628:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  629:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  630:              </tr>'.
  631:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  632:             $rowtotal += 2;
  633:         }
  634:     } else {
  635:         $output .= '
  636:           <tr>
  637:            <td>
  638:             <table class="LC_nested">
  639:              <tr class="LC_info_row">';
  640:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  641:             $output .= '  
  642:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  643:         } elsif ($action eq 'serverstatuses') {
  644:             $output .= '
  645:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
  646:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
  647: 
  648:         } else {
  649:             $output .= '
  650:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  651:         }
  652:         if (defined($item->{'header'}->[0]->{'col3'})) {
  653:             $output .= '<td class="LC_left_item" valign="top">'.
  654:                        &mt($item->{'header'}->[0]->{'col2'});
  655:             if ($action eq 'serverstatuses') {
  656:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
  657:             } 
  658:         } else {
  659:             $output .= '<td class="LC_right_item" valign="top">'.
  660:                        &mt($item->{'header'}->[0]->{'col2'});
  661:         }
  662:         $output .= '</td>';
  663:         if ($item->{'header'}->[0]->{'col3'}) {
  664:             $output .= '<td class="LC_right_item" valign="top">'.
  665:                        &mt($item->{'header'}->[0]->{'col3'});
  666:             if ($action eq 'serverstatuses') {
  667:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
  668:             }
  669:             $output .= '</td>';
  670:         }
  671:         $output .= '</tr>';
  672:         $rowtotal ++;
  673:         if ($action eq 'login') {
  674:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
  675:                                     \$rowtotal);
  676:         } elsif ($action eq 'quotas') {
  677:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  678:         } elsif ($action eq 'autoenroll') {
  679:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
  680:         } elsif ($action eq 'autocreate') {
  681:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
  682:         } elsif ($action eq 'directorysrch') {
  683:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
  684:         } elsif ($action eq 'contacts') {
  685:             $output .= &print_contacts($dom,$settings,\$rowtotal);
  686:         } elsif ($action eq 'defaults') {
  687:             $output .= &print_defaults($dom,\$rowtotal);
  688:         } elsif ($action eq 'scantron') {
  689:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
  690:         } elsif ($action eq 'serverstatuses') {
  691:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
  692:         } elsif ($action eq 'helpsettings') {
  693:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
  694:         }
  695:     }
  696:     $output .= '
  697:    </table>
  698:   </td>
  699:  </tr>
  700: </table><br />';
  701:     return ($output,$rowtotal);
  702: }
  703: 
  704: sub print_login {
  705:     my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
  706:     my ($css_class,$datatable);
  707:     my %choices = &login_choices();
  708: 
  709:     if ($position eq 'top') {
  710:         my %servers = &dom_servers($dom);
  711:         my $choice = $choices{'disallowlogin'};
  712:         $css_class = ' class="LC_odd_row"';
  713:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
  714:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
  715:                       '<th>'.$choices{'server'}.'</th>'.
  716:                       '<th>'.$choices{'serverpath'}.'</th>'.
  717:                       '<th>'.$choices{'custompath'}.'</th>'.
  718:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
  719:         my %disallowed;
  720:         if (ref($settings) eq 'HASH') {
  721:             if (ref($settings->{'loginvia'}) eq 'HASH') {
  722:                %disallowed = %{$settings->{'loginvia'}};
  723:             }
  724:         }
  725:         foreach my $lonhost (sort(keys(%servers))) {
  726:             my $direct = 'selected="selected"';
  727:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  728:                 if ($disallowed{$lonhost}{'server'} ne '') {
  729:                     $direct = '';
  730:                 }
  731:             }
  732:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
  733:                           '<td><select name="'.$lonhost.'_server">'.
  734:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
  735:                           '</option>';
  736:             foreach my $hostid (keys(%servers)) {
  737:                 next if ($servers{$hostid} eq $servers{$lonhost});
  738:                 my $selected = '';
  739:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  740:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
  741:                         $selected = 'selected="selected"';
  742:                     }
  743:                 }
  744:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
  745:                               $servers{$hostid}.'</option>';
  746:             }
  747:             $datatable .= '</select></td>'.
  748:                           '<td><select name="'.$lonhost.'_serverpath">';
  749:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
  750:                 my $pathname = $path;
  751:                 if ($path eq 'custom') {
  752:                     $pathname = &mt('Custom Path').' ->';
  753:                 }
  754:                 my $selected = '';
  755:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  756:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
  757:                         $selected = 'selected="selected"';
  758:                     }
  759:                 } elsif ($path eq '') {
  760:                     $selected = 'selected="selected"';
  761:                 }
  762:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
  763:             }
  764:             $datatable .= '</select></td>';
  765:             my ($custom,$exempt);
  766:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  767:                 $custom = $disallowed{$lonhost}{'custompath'};
  768:                 $exempt = $disallowed{$lonhost}{'exempt'};
  769:             }
  770:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
  771:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
  772:                           '</tr>';
  773:         }
  774:         $datatable .= '</table></td></tr>';
  775:         return $datatable;
  776:     }
  777: 
  778:     my %defaultchecked = ( 
  779:                            'coursecatalog' => 'on',
  780:                            'adminmail'     => 'off',
  781:                            'newuser'       => 'off',
  782:                          );
  783:     my @toggles = ('coursecatalog','adminmail','newuser');
  784:     my (%checkedon,%checkedoff);
  785:     foreach my $item (@toggles) {
  786:         if ($defaultchecked{$item} eq 'on') { 
  787:             $checkedon{$item} = ' checked="checked" ';
  788:             $checkedoff{$item} = ' ';
  789:         } elsif ($defaultchecked{$item} eq 'off') {
  790:             $checkedoff{$item} = ' checked="checked" ';
  791:             $checkedon{$item} = ' ';
  792:         }
  793:     }
  794:     my @images = ('img','logo','domlogo','login');
  795:     my @logintext = ('textcol','bgcol');
  796:     my @bgs = ('pgbg','mainbg','sidebg');
  797:     my @links = ('link','alink','vlink');
  798:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  799:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  800:     my (%is_custom,%designs);
  801:     my %defaults = (
  802:                    font => $defaultdesign{'login.font'},
  803:                    );
  804:     foreach my $item (@images) {
  805:         $defaults{$item} = $defaultdesign{'login.'.$item};
  806:         $defaults{'showlogo'}{$item} = 1;
  807:     }
  808:     foreach my $item (@bgs) {
  809:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  810:     }
  811:     foreach my $item (@logintext) {
  812:         $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
  813:     }
  814:     foreach my $item (@links) {
  815:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  816:     }
  817:     if (ref($settings) eq 'HASH') {
  818:         foreach my $item (@toggles) {
  819:             if ($settings->{$item} eq '1') {
  820:                 $checkedon{$item} =  ' checked="checked" ';
  821:                 $checkedoff{$item} = ' ';
  822:             } elsif ($settings->{$item} eq '0') {
  823:                 $checkedoff{$item} =  ' checked="checked" ';
  824:                 $checkedon{$item} = ' ';
  825:             }
  826:         }
  827:         foreach my $item (@images) {
  828:             if (defined($settings->{$item})) {
  829:                 $designs{$item} = $settings->{$item};
  830:                 $is_custom{$item} = 1;
  831:             }
  832:             if (defined($settings->{'showlogo'}{$item})) {
  833:                 $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
  834:             }
  835:         }
  836:         foreach my $item (@logintext) {
  837:             if ($settings->{$item} ne '') {
  838:                 $designs{'logintext'}{$item} = $settings->{$item};
  839:                 $is_custom{$item} = 1;
  840:             }
  841:         }
  842:         if ($settings->{'font'} ne '') {
  843:             $designs{'font'} = $settings->{'font'};
  844:             $is_custom{'font'} = 1;
  845:         }
  846:         foreach my $item (@bgs) {
  847:             if ($settings->{$item} ne '') {
  848:                 $designs{'bgs'}{$item} = $settings->{$item};
  849:                 $is_custom{$item} = 1;
  850:             }
  851:         }
  852:         foreach my $item (@links) {
  853:             if ($settings->{$item} ne '') {
  854:                 $designs{'links'}{$item} = $settings->{$item};
  855:                 $is_custom{$item} = 1;
  856:             }
  857:         }
  858:     } else {
  859:         if ($designhash{$dom.'.login.font'} ne '') {
  860:             $designs{'font'} = $designhash{$dom.'.login.font'};
  861:             $is_custom{'font'} = 1;
  862:         }
  863:         foreach my $item (@images) {
  864:             if ($designhash{$dom.'.login.'.$item} ne '') {
  865:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
  866:                 $is_custom{$item} = 1;
  867:             }
  868:         }
  869:         foreach my $item (@bgs) {
  870:             if ($designhash{$dom.'.login.'.$item} ne '') {
  871:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  872:                 $is_custom{$item} = 1;
  873:             }
  874:         }
  875:         foreach my $item (@links) {
  876:             if ($designhash{$dom.'.login.'.$item} ne '') {
  877:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  878:                 $is_custom{$item} = 1;
  879:             }
  880:         }
  881:     }
  882:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  883:                                                   logo => 'Institution Logo',
  884:                                                   domlogo => 'Domain Logo',
  885:                                                   login => 'Login box');
  886:     my $itemcount = 1;
  887:     foreach my $item (@toggles) {
  888:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  889:         $datatable .=  
  890:             '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
  891:             '</td><td>'.
  892:             '<span class="LC_nobreak"><label><input type="radio" name="'.
  893:             $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
  894:             '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
  895:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
  896:             '</tr>';
  897:         $itemcount ++;
  898:     }
  899:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
  900:     $datatable .= '</tr></table></td></tr>';
  901:     return $datatable;
  902: }
  903: 
  904: sub login_choices {
  905:     my %choices =
  906:         &Apache::lonlocal::texthash (
  907:             coursecatalog => 'Display Course/Community Catalog link?',
  908:             adminmail     => "Display Administrator's E-mail Address?",
  909:             disallowlogin => "Login page requests redirected",
  910:             hostid        => "Server",
  911:             server        => "Redirect to:",
  912:             serverpath    => "Path",
  913:             custompath    => "Custom", 
  914:             exempt        => "Exempt IP(s)",
  915:             directlogin   => "No redirect",
  916:             newuser       => "Link to create a user account",
  917:             img           => "Header",
  918:             logo          => "Main Logo",
  919:             domlogo       => "Domain Logo",
  920:             login         => "Log-in Header", 
  921:             textcol       => "Text color",
  922:             bgcol         => "Box color",
  923:             bgs           => "Background colors",
  924:             links         => "Link colors",
  925:             font          => "Font color",
  926:             pgbg          => "Header",
  927:             mainbg        => "Page",
  928:             sidebg        => "Login box",
  929:             link          => "Link",
  930:             alink         => "Active link",
  931:             vlink         => "Visited link",
  932:         );
  933:     return %choices;
  934: }
  935: 
  936: sub print_rolecolors {
  937:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
  938:     my %choices = &color_font_choices();
  939:     my @bgs = ('pgbg','tabbg','sidebg');
  940:     my @links = ('link','alink','vlink');
  941:     my @images = ('img');
  942:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
  943:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  944:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  945:     my (%is_custom,%designs);
  946:     my %defaults = (
  947:                    img => $defaultdesign{$role.'.img'},
  948:                    font => $defaultdesign{$role.'.font'},
  949: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
  950:                    );
  951:     foreach my $item (@bgs) {
  952:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
  953:     }
  954:     foreach my $item (@links) {
  955:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
  956:     }
  957:     if (ref($settings) eq 'HASH') {
  958:         if (ref($settings->{$role}) eq 'HASH') {
  959:             if ($settings->{$role}->{'img'} ne '') {
  960:                 $designs{'img'} = $settings->{$role}->{'img'};
  961:                 $is_custom{'img'} = 1;
  962:             }
  963:             if ($settings->{$role}->{'font'} ne '') {
  964:                 $designs{'font'} = $settings->{$role}->{'font'};
  965:                 $is_custom{'font'} = 1;
  966:             }
  967:             if ($settings->{$role}->{'fontmenu'} ne '') {
  968:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
  969:                 $is_custom{'fontmenu'} = 1;
  970:             }
  971:             foreach my $item (@bgs) {
  972:                 if ($settings->{$role}->{$item} ne '') {
  973:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
  974:                     $is_custom{$item} = 1;
  975:                 }
  976:             }
  977:             foreach my $item (@links) {
  978:                 if ($settings->{$role}->{$item} ne '') {
  979:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
  980:                     $is_custom{$item} = 1;
  981:                 }
  982:             }
  983:         }
  984:     } else {
  985:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  986:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
  987:             $is_custom{'img'} = 1;
  988:         }
  989:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
  990:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
  991:             $is_custom{'fontmenu'} = 1; 
  992:         }
  993:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
  994:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
  995:             $is_custom{'font'} = 1;
  996:         }
  997:         foreach my $item (@bgs) {
  998:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  999:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1000:                 $is_custom{$item} = 1;
 1001:             
 1002:             }
 1003:         }
 1004:         foreach my $item (@links) {
 1005:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1006:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1007:                 $is_custom{$item} = 1;
 1008:             }
 1009:         }
 1010:     }
 1011:     my $itemcount = 1;
 1012:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
 1013:     $datatable .= '</tr></table></td></tr>';
 1014:     return $datatable;
 1015: }
 1016: 
 1017: sub display_color_options {
 1018:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
 1019:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
 1020:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1021:     my $datatable = '<tr'.$css_class.'>'.
 1022:         '<td>'.$choices->{'font'}.'</td>';
 1023:     if (!$is_custom->{'font'}) {
 1024:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
 1025:     } else {
 1026:         $datatable .= '<td>&nbsp;</td>';
 1027:     }
 1028:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
 1029:     $datatable .= '<td><span class="LC_nobreak">'.
 1030:                   '<input type="text" size="10" name="'.$role.'_font"'.
 1031:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
 1032:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
 1033:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
 1034:                   '</span></td></tr>';
 1035:     unless ($role eq 'login') { 
 1036:         $datatable .= '<tr'.$css_class.'>'.
 1037:                       '<td>'.$choices->{'fontmenu'}.'</td>';
 1038:         if (!$is_custom->{'fontmenu'}) {
 1039:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
 1040:         } else {
 1041:             $datatable .= '<td>&nbsp;</td>';
 1042:         }
 1043:         $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
 1044:         $datatable .= '<td><span class="LC_nobreak">'.
 1045:                       '<input type="text" size="10" name="'.$role.'_fontmenu"'.
 1046:                       ' value="'.$designs->{'fontmenu'}.'" />&nbsp;'.$fontlink.
 1047:                       '&nbsp;<span id="css_'.$role.'_fontmenu" style="background-color: '.
 1048:                       $designs->{'fontmenu'}.';">&nbsp;&nbsp;&nbsp;</span>'.
 1049:                       '</span></td></tr>';
 1050:     }
 1051:     my $switchserver = &check_switchserver($dom,$confname);
 1052:     foreach my $img (@{$images}) {
 1053: 	$itemcount ++;
 1054:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1055:         $datatable .= '<tr'.$css_class.'>'.
 1056:                       '<td>'.$choices->{$img};
 1057:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
 1058:         if ($role eq 'login') {
 1059:             if ($img eq 'login') {
 1060:                 $login_hdr_pick =
 1061:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
 1062:                 $logincolors =
 1063:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
 1064:                                             $designs);
 1065:             } elsif ($img ne 'domlogo') {
 1066:                 $datatable.= &logo_display_options($img,$defaults,$designs);
 1067:             }
 1068:         }
 1069:         $datatable .= '</td>';
 1070:         if ($designs->{$img} ne '') {
 1071:             $imgfile = $designs->{$img};
 1072: 	    $img_import = ($imgfile =~ m{^/adm/});
 1073:         } else {
 1074:             $imgfile = $defaults->{$img};
 1075:         }
 1076:         if ($imgfile) {
 1077:             my ($showfile,$fullsize);
 1078:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1079:                 my $urldir = $1;
 1080:                 my $filename = $2;
 1081:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
 1082:                 if (@info) {
 1083:                     my $thumbfile = 'tn-'.$filename;
 1084:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
 1085:                     if (@thumb) {
 1086:                         $showfile = $urldir.'/'.$thumbfile;
 1087:                     } else {
 1088:                         $showfile = $imgfile;
 1089:                     }
 1090:                 } else {
 1091:                     $showfile = '';
 1092:                 }
 1093:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
 1094:                 $showfile = $imgfile;
 1095:                 my $imgdir = $1;
 1096:                 my $filename = $2;
 1097:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
 1098:                     $showfile = "/$imgdir/tn-".$filename;
 1099:                 } else {
 1100:                     my $input = "/home/httpd/html".$imgfile;
 1101:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
 1102:                     if (!-e $output) {
 1103:                         my ($width,$height) = &thumb_dimensions();
 1104:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
 1105:                         if ($fullwidth ne '' && $fullheight ne '') {
 1106:                             if ($fullwidth > $width && $fullheight > $height) { 
 1107:                                 my $size = $width.'x'.$height;
 1108:                                 system("convert -sample $size $input $output");
 1109:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
 1110:                             }
 1111:                         }
 1112:                     }
 1113:                 }
 1114:             }
 1115:             if ($showfile) {
 1116:                 if ($showfile =~ m{^/(adm|res)/}) {
 1117:                     if ($showfile =~ m{^/res/}) {
 1118:                         my $local_showfile =
 1119:                             &Apache::lonnet::filelocation('',$showfile);
 1120:                         &Apache::lonnet::repcopy($local_showfile);
 1121:                     }
 1122:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
 1123:                 }
 1124:                 if ($imgfile) {
 1125:                     if ($imgfile  =~ m{^/(adm|res)/}) {
 1126:                         if ($imgfile =~ m{^/res/}) {
 1127:                             my $local_imgfile =
 1128:                                 &Apache::lonnet::filelocation('',$imgfile);
 1129:                             &Apache::lonnet::repcopy($local_imgfile);
 1130:                         }
 1131:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
 1132:                     } else {
 1133:                         $fullsize = $imgfile;
 1134:                     }
 1135:                 }
 1136:                 $datatable .= '<td>';
 1137:                 if ($img eq 'login') {
 1138:                     $datatable .= $login_hdr_pick;
 1139:                 } 
 1140:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
 1141:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
 1142:             } else {
 1143:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
 1144:                               &mt('Upload:');
 1145:             }
 1146:         } else {
 1147:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
 1148:                           &mt('Upload:');
 1149:         }
 1150:         if ($switchserver) {
 1151:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1152:         } else {
 1153:             if ($img ne 'login') { # suppress file selection for Log-in header
 1154:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
 1155:             }
 1156:         }
 1157:         $datatable .= '</td></tr>';
 1158:     }
 1159:     $itemcount ++;
 1160:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1161:     $datatable .= '<tr'.$css_class.'>'.
 1162:                   '<td>'.$choices->{'bgs'}.'</td>';
 1163:     my $bgs_def;
 1164:     foreach my $item (@{$bgs}) {
 1165:         if (!$is_custom->{$item}) {
 1166:             $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span>&nbsp;<span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';
 1167:         }
 1168:     }
 1169:     if ($bgs_def) {
 1170:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
 1171:     } else {
 1172:         $datatable .= '<td>&nbsp;</td>';
 1173:     }
 1174:     $datatable .= '<td class="LC_right_item">'.
 1175:                   '<table border="0"><tr>';
 1176:     foreach my $item (@{$bgs}) {
 1177:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
 1178:         $datatable .= '<td align="center">'.$link;
 1179:         if ($designs->{'bgs'}{$item}) {
 1180:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1181:         }
 1182:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
 1183:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1184:     }
 1185:     $datatable .= '</tr></table></td></tr>';
 1186:     $itemcount ++;
 1187:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1188:     $datatable .= '<tr'.$css_class.'>'.
 1189:                   '<td>'.$choices->{'links'}.'</td>';
 1190:     my $links_def;
 1191:     foreach my $item (@{$links}) {
 1192:         if (!$is_custom->{$item}) {
 1193:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
 1194:         }
 1195:     }
 1196:     if ($links_def) {
 1197:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
 1198:     } else {
 1199:         $datatable .= '<td>&nbsp;</td>';
 1200:     }
 1201:     $datatable .= '<td class="LC_right_item">'.
 1202:                   '<table border="0"><tr>';
 1203:     foreach my $item (@{$links}) {
 1204:         $datatable .= '<td align="center">'."\n".
 1205:                       &color_pick($phase,$role,$item,$choices->{$item},
 1206:                                   $designs->{'links'}{$item});
 1207:         if ($designs->{'links'}{$item}) {
 1208:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1209:         }
 1210:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
 1211:                       '" /></td>';
 1212:     }
 1213:     $$rowtotal += $itemcount;
 1214:     return $datatable;
 1215: }
 1216: 
 1217: sub logo_display_options {
 1218:     my ($img,$defaults,$designs) = @_;
 1219:     my $checkedon;
 1220:     if (ref($defaults) eq 'HASH') {
 1221:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
 1222:             if ($defaults->{'showlogo'}{$img}) {
 1223:                 $checkedon = 'checked="checked" ';     
 1224:             }
 1225:         } 
 1226:     }
 1227:     if (ref($designs) eq 'HASH') {
 1228:         if (ref($designs->{'showlogo'}) eq 'HASH') {
 1229:             if (defined($designs->{'showlogo'}{$img})) {
 1230:                 if ($designs->{'showlogo'}{$img} == 0) {
 1231:                     $checkedon = '';
 1232:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
 1233:                     $checkedon = 'checked="checked" ';
 1234:                 }
 1235:             }
 1236:         }
 1237:     }
 1238:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
 1239:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
 1240:            &mt('show').'</label>'."\n";
 1241: }
 1242: 
 1243: sub login_header_options  {
 1244:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
 1245:     my $output = '';
 1246:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1247:         $output .= &mt('Text default(s):').'<br />';
 1248:         if (!$is_custom->{'textcol'}) {
 1249:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1250:                        '&nbsp;&nbsp;&nbsp;';
 1251:         }
 1252:         if (!$is_custom->{'bgcol'}) {
 1253:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1254:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1255:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1256:         }
 1257:         $output .= '<br />';
 1258:     }
 1259:     $output .='<br />';
 1260:     return $output;
 1261: }
 1262: 
 1263: sub login_text_colors {
 1264:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
 1265:     my $color_menu = '<table border="0"><tr>';
 1266:     foreach my $item (@{$logintext}) {
 1267:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
 1268:         $color_menu .= '<td align="center">'.$link;
 1269:         if ($designs->{'logintext'}{$item}) {
 1270:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1271:         }
 1272:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
 1273:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
 1274:                        '<td>&nbsp;</td>';
 1275:     }
 1276:     $color_menu .= '</tr></table><br />';
 1277:     return $color_menu;
 1278: }
 1279: 
 1280: sub image_changes {
 1281:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1282:     my $output;
 1283:     if ($img eq 'login') {
 1284:             # suppress image for Log-in header
 1285:     } elsif (!$is_custom) {
 1286:         if ($img ne 'domlogo') {
 1287:             $output .= &mt('Default image:').'<br />';
 1288:         } else {
 1289:             $output .= &mt('Default in use:').'<br />';
 1290:         }
 1291:     }
 1292:     if ($img eq 'login') { # suppress image for Log-in header
 1293:         $output .= '<td>'.$logincolors;
 1294:     } else {
 1295:         if ($img_import) {
 1296:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1297:         }
 1298:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1299:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1300:         if ($is_custom) {
 1301:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1302:                        '<input type="checkbox" name="'.
 1303:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1304:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1305:         } else {
 1306:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
 1307:         }
 1308:     }
 1309:     return $output;
 1310: }
 1311: 
 1312: sub color_pick {
 1313:     my ($phase,$role,$item,$desc,$curcol) = @_;
 1314:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
 1315:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
 1316:                ');">'.$desc.'</a>';
 1317:     return $link;
 1318: }
 1319: 
 1320: sub print_quotas {
 1321:     my ($dom,$settings,$rowtotal,$action) = @_;
 1322:     my $context;
 1323:     if ($action eq 'quotas') {
 1324:         $context = 'tools';
 1325:     } else {
 1326:         $context = $action;
 1327:     }
 1328:     my ($datatable,$defaultquota,@usertools,@options,%validations);
 1329:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1330:     my $typecount = 0;
 1331:     my ($css_class,%titles);
 1332:     if ($context eq 'requestcourses') {
 1333:         @usertools = ('official','unofficial','community');
 1334:         @options =('norequest','approval','validate','autolimit');
 1335:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 1336:         %titles = &courserequest_titles();
 1337:     } else {
 1338:         @usertools = ('aboutme','blog','portfolio');
 1339:         %titles = &tool_titles();
 1340:     }
 1341:     if (ref($types) eq 'ARRAY') {
 1342:         foreach my $type (@{$types}) {
 1343:             my $currdefquota;
 1344:             unless ($context eq 'requestcourses') {
 1345:                 if (ref($settings) eq 'HASH') {
 1346:                     if (ref($settings->{defaultquota}) eq 'HASH') {
 1347:                         $currdefquota = $settings->{defaultquota}->{$type}; 
 1348:                     } else {
 1349:                         $currdefquota = $settings->{$type};
 1350:                     }
 1351:                 }
 1352:             }
 1353:             if (defined($usertypes->{$type})) {
 1354:                 $typecount ++;
 1355:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1356:                 $datatable .= '<tr'.$css_class.'>'.
 1357:                               '<td>'.$usertypes->{$type}.'</td>'.
 1358:                               '<td class="LC_left_item">';
 1359:                 if ($context eq 'requestcourses') {
 1360:                     $datatable .= '<table><tr>';
 1361:                 }
 1362:                 my %cell;  
 1363:                 foreach my $item (@usertools) {
 1364:                     if ($context eq 'requestcourses') {
 1365:                         my ($curroption,$currlimit);
 1366:                         if (ref($settings) eq 'HASH') {
 1367:                             if (ref($settings->{$item}) eq 'HASH') {
 1368:                                 $curroption = $settings->{$item}->{$type};
 1369:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
 1370:                                     $currlimit = $1; 
 1371:                                 }
 1372:                             }
 1373:                         }
 1374:                         if (!$curroption) {
 1375:                             $curroption = 'norequest';
 1376:                         }
 1377:                         $datatable .= '<th>'.$titles{$item}.'</th>';
 1378:                         foreach my $option (@options) {
 1379:                             my $val = $option;
 1380:                             if ($option eq 'norequest') {
 1381:                                 $val = 0;  
 1382:                             }
 1383:                             if ($option eq 'validate') {
 1384:                                 my $canvalidate = 0;
 1385:                                 if (ref($validations{$item}) eq 'HASH') { 
 1386:                                     if ($validations{$item}{$type}) {
 1387:                                         $canvalidate = 1;
 1388:                                     }
 1389:                                 }
 1390:                                 next if (!$canvalidate);
 1391:                             }
 1392:                             my $checked = '';
 1393:                             if ($option eq $curroption) {
 1394:                                 $checked = ' checked="checked"';
 1395:                             } elsif ($option eq 'autolimit') {
 1396:                                 if ($curroption =~ /^autolimit/) {
 1397:                                     $checked = ' checked="checked"';
 1398:                                 }                       
 1399:                             } 
 1400:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
 1401:                                   '<input type="radio" name="crsreq_'.$item.
 1402:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
 1403:                                   $titles{$option}.'</label>';
 1404:                             if ($option eq 'autolimit') {
 1405:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1406:                                                 $item.'_limit_'.$type.'" size="1" '.
 1407:                                                 'value="'.$currlimit.'" />';
 1408:                             }
 1409:                             $cell{$item} .= '</span> ';
 1410:                             if ($option eq 'autolimit') {
 1411:                                 $cell{$item} .= $titles{'unlimited'};
 1412:                             }
 1413:                         }
 1414:                     } else {
 1415:                         my $checked = 'checked="checked" ';
 1416:                         if (ref($settings) eq 'HASH') {
 1417:                             if (ref($settings->{$item}) eq 'HASH') {
 1418:                                 if ($settings->{$item}->{$type} == 0) {
 1419:                                     $checked = '';
 1420:                                 } elsif ($settings->{$item}->{$type} == 1) {
 1421:                                     $checked =  'checked="checked" ';
 1422:                                 }
 1423:                             }
 1424:                         }
 1425:                         $datatable .= '<span class="LC_nobreak"><label>'.
 1426:                                       '<input type="checkbox" name="'.$context.'_'.$item.
 1427:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1428:                                       '</label></span>&nbsp; ';
 1429:                     }
 1430:                 }
 1431:                 if ($context eq 'requestcourses') {
 1432:                     $datatable .= '</tr><tr>';
 1433:                     foreach my $item (@usertools) {
 1434:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
 1435:                     }
 1436:                     $datatable .= '</tr></table>';
 1437:                 }
 1438:                 $datatable .= '</td>';
 1439:                 unless ($context eq 'requestcourses') {
 1440:                     $datatable .= 
 1441:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
 1442:                               '<input type="text" name="quota_'.$type.
 1443:                               '" value="'.$currdefquota.
 1444:                               '" size="5" /> Mb</span></td>';
 1445:                 }
 1446:                 $datatable .= '</tr>';
 1447:             }
 1448:         }
 1449:     }
 1450:     unless ($context eq 'requestcourses') {
 1451:         $defaultquota = '20';
 1452:         if (ref($settings) eq 'HASH') {
 1453:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1454:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
 1455:             } elsif (defined($settings->{'default'})) {
 1456:                 $defaultquota = $settings->{'default'};
 1457:             }
 1458:         }
 1459:     }
 1460:     $typecount ++;
 1461:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1462:     $datatable .= '<tr'.$css_class.'>'.
 1463:                   '<td>'.$othertitle.'</td>'.
 1464:                   '<td class="LC_left_item">';
 1465:     if ($context eq 'requestcourses') {
 1466:         $datatable .= '<table><tr>';
 1467:     }
 1468:     my %defcell;
 1469:     foreach my $item (@usertools) {
 1470:         if ($context eq 'requestcourses') {
 1471:             my ($curroption,$currlimit);
 1472:             if (ref($settings) eq 'HASH') {
 1473:                 if (ref($settings->{$item}) eq 'HASH') {
 1474:                     $curroption = $settings->{$item}->{'default'};
 1475:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1476:                         $currlimit = $1;
 1477:                     }
 1478:                 }
 1479:             }
 1480:             if (!$curroption) {
 1481:                 $curroption = 'norequest';
 1482:             }
 1483:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1484:             foreach my $option (@options) {
 1485:                 my $val = $option;
 1486:                 if ($option eq 'norequest') {
 1487:                     $val = 0;
 1488:                 }
 1489:                 if ($option eq 'validate') {
 1490:                     my $canvalidate = 0;
 1491:                     if (ref($validations{$item}) eq 'HASH') {
 1492:                         if ($validations{$item}{'default'}) {
 1493:                             $canvalidate = 1;
 1494:                         }
 1495:                     }
 1496:                     next if (!$canvalidate);
 1497:                 }
 1498:                 my $checked = '';
 1499:                 if ($option eq $curroption) {
 1500:                     $checked = ' checked="checked"';
 1501:                 } elsif ($option eq 'autolimit') {
 1502:                     if ($curroption =~ /^autolimit/) {
 1503:                         $checked = ' checked="checked"';
 1504:                     }
 1505:                 }
 1506:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
 1507:                                   '<input type="radio" name="crsreq_'.$item.
 1508:                                   '_default" value="'.$val.'"'.$checked.' />'.
 1509:                                   $titles{$option}.'</label>';
 1510:                 if ($option eq 'autolimit') {
 1511:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1512:                                        $item.'_limit_default" size="1" '.
 1513:                                        'value="'.$currlimit.'" />';
 1514:                 }
 1515:                 $defcell{$item} .= '</span> ';
 1516:                 if ($option eq 'autolimit') {
 1517:                     $defcell{$item} .= $titles{'unlimited'};
 1518:                 }
 1519:             }
 1520:         } else {
 1521:             my $checked = 'checked="checked" ';
 1522:             if (ref($settings) eq 'HASH') {
 1523:                 if (ref($settings->{$item}) eq 'HASH') {
 1524:                     if ($settings->{$item}->{'default'} == 0) {
 1525:                         $checked = '';
 1526:                     } elsif ($settings->{$item}->{'default'} == 1) {
 1527:                         $checked = 'checked="checked" ';
 1528:                     }
 1529:                 }
 1530:             }
 1531:             $datatable .= '<span class="LC_nobreak"><label>'.
 1532:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1533:                           '" value="default" '.$checked.'/>'.$titles{$item}.
 1534:                           '</label></span>&nbsp; ';
 1535:         }
 1536:     }
 1537:     if ($context eq 'requestcourses') {
 1538:         $datatable .= '</tr><tr>';
 1539:         foreach my $item (@usertools) {
 1540:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
 1541:         }
 1542:         $datatable .= '</tr></table>';
 1543:     }
 1544:     $datatable .= '</td>';
 1545:     unless ($context eq 'requestcourses') {
 1546:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
 1547:                       '<input type="text" name="defaultquota" value="'.
 1548:                       $defaultquota.'" size="5" /> Mb</span></td>';
 1549:     }
 1550:     $datatable .= '</tr>';
 1551:     $typecount ++;
 1552:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1553:     $datatable .= '<tr'.$css_class.'>'.
 1554:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
 1555:     if ($context eq 'requestcourses') {
 1556:         $datatable .= &mt('(overrides affiliation, if set)').
 1557:                       '</td>'.
 1558:                       '<td class="LC_left_item">'.
 1559:                       '<table><tr>';
 1560:     } else {
 1561:         $datatable .= &mt('(overrides affiliation, if checked)').
 1562:                       '</td>'.
 1563:                       '<td class="LC_left_item" colspan="2">'.
 1564:                       '<br />';
 1565:     }
 1566:     my %advcell;
 1567:     foreach my $item (@usertools) {
 1568:         if ($context eq 'requestcourses') {
 1569:             my ($curroption,$currlimit);
 1570:             if (ref($settings) eq 'HASH') {
 1571:                 if (ref($settings->{$item}) eq 'HASH') {
 1572:                     $curroption = $settings->{$item}->{'_LC_adv'};
 1573:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1574:                         $currlimit = $1;
 1575:                     }
 1576:                 }
 1577:             }
 1578:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1579:             my $checked = '';
 1580:             if ($curroption eq '') {
 1581:                 $checked = ' checked="checked"';
 1582:             }
 1583:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1584:                                '<input type="radio" name="crsreq_'.$item.
 1585:                                '__LC_adv" value=""'.$checked.' />'.
 1586:                                &mt('No override set').'</label></span>&nbsp; ';
 1587:             foreach my $option (@options) {
 1588:                 my $val = $option;
 1589:                 if ($option eq 'norequest') {
 1590:                     $val = 0;
 1591:                 }
 1592:                 if ($option eq 'validate') {
 1593:                     my $canvalidate = 0;
 1594:                     if (ref($validations{$item}) eq 'HASH') {
 1595:                         if ($validations{$item}{'_LC_adv'}) {
 1596:                             $canvalidate = 1;
 1597:                         }
 1598:                     }
 1599:                     next if (!$canvalidate);
 1600:                 }
 1601:                 my $checked = '';
 1602:                 if ($val eq $curroption) {
 1603:                     $checked = ' checked="checked"';
 1604:                 } elsif ($option eq 'autolimit') {
 1605:                     if ($curroption =~ /^autolimit/) {
 1606:                         $checked = ' checked="checked"';
 1607:                     }
 1608:                 }
 1609:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1610:                                   '<input type="radio" name="crsreq_'.$item.
 1611:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
 1612:                                   $titles{$option}.'</label>';
 1613:                 if ($option eq 'autolimit') {
 1614:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1615:                                        $item.'_limit__LC_adv" size="1" '.
 1616:                                        'value="'.$currlimit.'" />';
 1617:                 }
 1618:                 $advcell{$item} .= '</span> ';
 1619:                 if ($option eq 'autolimit') {
 1620:                     $advcell{$item} .= $titles{'unlimited'};
 1621:                 }
 1622:             }
 1623:         } else {
 1624:             my $checked = 'checked="checked" ';
 1625:             if (ref($settings) eq 'HASH') {
 1626:                 if (ref($settings->{$item}) eq 'HASH') {
 1627:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
 1628:                         $checked = '';
 1629:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
 1630:                         $checked = 'checked="checked" ';
 1631:                     }
 1632:                 }
 1633:             }
 1634:             $datatable .= '<span class="LC_nobreak"><label>'.
 1635:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1636:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 1637:                           '</label></span>&nbsp; ';
 1638:         }
 1639:     }
 1640:     if ($context eq 'requestcourses') {
 1641:         $datatable .= '</tr><tr>';
 1642:         foreach my $item (@usertools) {
 1643:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
 1644:         }
 1645:         $datatable .= '</tr></table>';
 1646:     }
 1647:     $datatable .= '</td></tr>';
 1648:     $$rowtotal += $typecount;
 1649:     return $datatable;
 1650: }
 1651: 
 1652: sub print_courserequestmail {
 1653:     my ($dom,$settings,$rowtotal) = @_;
 1654:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
 1655:     $now = time;
 1656:     $rows = 0;
 1657:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
 1658:     foreach my $server (keys(%dompersonnel)) {
 1659:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 1660:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 1661:             if (!grep(/^$uname:$udom$/,@domcoord)) {
 1662:                 push(@domcoord,$uname.':'.$udom);
 1663:             }
 1664:         }
 1665:     }
 1666:     if (ref($settings) eq 'HASH') {
 1667:         if (ref($settings->{'notify'}) eq 'HASH') {
 1668:             if ($settings->{'notify'}{'approval'} ne '') {
 1669:                @currapproval = split(',',$settings->{'notify'}{'approval'});
 1670:             }
 1671:         }
 1672:     }
 1673:     if (@currapproval) {
 1674:         foreach my $dc (@currapproval) {
 1675:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
 1676:                 push(@domcoord,$dc);
 1677:             }
 1678:         }
 1679:     }
 1680:     @domcoord = sort(@domcoord);
 1681:     my $numinrow = 4;
 1682:     my $numdc = @domcoord;
 1683:     my $css_class = 'class="LC_odd_row"';
 1684:     $datatable = '<tr'.$css_class.'>'.
 1685:                  ' <td>'.&mt('Receive notification of course requests requiring approval.').
 1686:                  ' </td>'.
 1687:                  ' <td class="LC_left_item">';
 1688:     if (@domcoord > 0) {
 1689:         $datatable .= '<table>';
 1690:         for (my $i=0; $i<$numdc; $i++) {
 1691:             my $rem = $i%($numinrow);
 1692:             if ($rem == 0) {
 1693:                 if ($i > 0) {
 1694:                     $datatable .= '</tr>';
 1695:                 }
 1696:                 $datatable .= '<tr>';
 1697:                 $rows ++;
 1698:             }
 1699:             my $check = ' ';
 1700:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
 1701:                 $check = ' checked="checked" ';
 1702:             }
 1703:             my ($uname,$udom) = split(':',$domcoord[$i]);
 1704:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
 1705:             if ($i == $numdc-1) {
 1706:                 my $colsleft = $numinrow-$rem;
 1707:                 if ($colsleft > 1) {
 1708:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 1709:                 } else {
 1710:                     $datatable .= '<td class="LC_left_item">';
 1711:                 }
 1712:             } else {
 1713:                 $datatable .= '<td class="LC_left_item">';
 1714:             }
 1715:             $datatable .= '<span class="LC_nobreak"><label>'.
 1716:                           '<input type="checkbox" name="reqapprovalnotify" '.
 1717:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
 1718:                           $fullname.'</label></span></td>';
 1719:         }
 1720:         $datatable .= '</tr></table>';
 1721:     } else {
 1722:         $datatable .= &mt('There are no active Domain Coordinators');
 1723:         $rows ++;
 1724:     }
 1725:     $datatable .='</td></tr>';
 1726:     $$rowtotal += $rows;
 1727:     return $datatable;
 1728: }
 1729: 
 1730: sub print_autoenroll {
 1731:     my ($dom,$settings,$rowtotal) = @_;
 1732:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1733:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
 1734:     if (ref($settings) eq 'HASH') {
 1735:         if (exists($settings->{'run'})) {
 1736:             if ($settings->{'run'} eq '0') {
 1737:                 $runoff = ' checked="checked" ';
 1738:                 $runon = ' ';
 1739:             } else {
 1740:                 $runon = ' checked="checked" ';
 1741:                 $runoff = ' ';
 1742:             }
 1743:         } else {
 1744:             if ($autorun) {
 1745:                 $runon = ' checked="checked" ';
 1746:                 $runoff = ' ';
 1747:             } else {
 1748:                 $runoff = ' checked="checked" ';
 1749:                 $runon = ' ';
 1750:             }
 1751:         }
 1752:         if (exists($settings->{'co-owners'})) {
 1753:             if ($settings->{'co-owners'} eq '0') {
 1754:                 $coownersoff = ' checked="checked" ';
 1755:                 $coownerson = ' ';
 1756:             } else {
 1757:                 $coownerson = ' checked="checked" ';
 1758:                 $coownersoff = ' ';
 1759:             }
 1760:         } else {
 1761:             $coownersoff = ' checked="checked" ';
 1762:             $coownerson = ' ';
 1763:         }
 1764:         if (exists($settings->{'sender_domain'})) {
 1765:             $defdom = $settings->{'sender_domain'};
 1766:         }
 1767:     } else {
 1768:         if ($autorun) {
 1769:             $runon = ' checked="checked" ';
 1770:             $runoff = ' ';
 1771:         } else {
 1772:             $runoff = ' checked="checked" ';
 1773:             $runon = ' ';
 1774:         }
 1775:     }
 1776:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 1777:     my $notif_sender;
 1778:     if (ref($settings) eq 'HASH') {
 1779:         $notif_sender = $settings->{'sender_uname'};
 1780:     }
 1781:     my $datatable='<tr class="LC_odd_row">'.
 1782:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 1783:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1784:                   '<input type="radio" name="autoenroll_run"'.
 1785:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1786:                   '<label><input type="radio" name="autoenroll_run"'.
 1787:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1788:                   '</tr><tr>'.
 1789:                   '<td>'.&mt('Notification messages - sender').
 1790:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 1791:                   &mt('username').':&nbsp;'.
 1792:                   '<input type="text" name="sender_uname" value="'.
 1793:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 1794:                   ':&nbsp;'.$domform.'</span></td></tr>'.
 1795:                   '<tr class="LC_odd_row">'.
 1796:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
 1797:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1798:                   '<input type="radio" name="autoassign_coowners"'.
 1799:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1800:                   '<label><input type="radio" name="autoassign_coowners"'.
 1801:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1802:                   '</tr>';
 1803:     $$rowtotal += 3;
 1804:     return $datatable;
 1805: }
 1806: 
 1807: sub print_autoupdate {
 1808:     my ($position,$dom,$settings,$rowtotal) = @_;
 1809:     my $datatable;
 1810:     if ($position eq 'top') {
 1811:         my $updateon = ' ';
 1812:         my $updateoff = ' checked="checked" ';
 1813:         my $classlistson = ' ';
 1814:         my $classlistsoff = ' checked="checked" ';
 1815:         if (ref($settings) eq 'HASH') {
 1816:             if ($settings->{'run'} eq '1') {
 1817:                 $updateon = $updateoff;
 1818:                 $updateoff = ' ';
 1819:             }
 1820:             if ($settings->{'classlists'} eq '1') {
 1821:                 $classlistson = $classlistsoff;
 1822:                 $classlistsoff = ' ';
 1823:             }
 1824:         }
 1825:         my %title = (
 1826:                    run => 'Auto-update active?',
 1827:                    classlists => 'Update information in classlists?',
 1828:                     );
 1829:         $datatable = '<tr class="LC_odd_row">'. 
 1830:                   '<td>'.&mt($title{'run'}).'</td>'.
 1831:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1832:                   '<input type="radio" name="autoupdate_run"'.
 1833:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1834:                   '<label><input type="radio" name="autoupdate_run"'.
 1835:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1836:                   '</tr><tr>'.
 1837:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 1838:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 1839:                   '<label><input type="radio" name="classlists"'.
 1840:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1841:                   '<label><input type="radio" name="classlists"'.
 1842:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1843:                   '</tr>';
 1844:         $$rowtotal += 2;
 1845:     } elsif ($position eq 'middle') {
 1846:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1847:         my $numinrow = 3;
 1848:         my $locknamesettings;
 1849:         $datatable .= &insttypes_row($settings,$types,$usertypes,
 1850:                                      $dom,$numinrow,$othertitle,
 1851:                                     'lockablenames');
 1852:         $$rowtotal ++;
 1853:     } else {
 1854:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1855:         my @fields = ('lastname','firstname','middlename','generation',
 1856:                       'permanentemail','id');
 1857:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 1858:         my $numrows = 0;
 1859:         if (ref($types) eq 'ARRAY') {
 1860:             if (@{$types} > 0) {
 1861:                 $datatable = 
 1862:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 1863:                                          \@fields,$types,\$numrows);
 1864:                     $$rowtotal += @{$types}; 
 1865:             }
 1866:         }
 1867:         $datatable .= 
 1868:             &usertype_update_row($settings,{'default' => $othertitle},
 1869:                                  \%fieldtitles,\@fields,['default'],
 1870:                                  \$numrows);
 1871:         $$rowtotal ++;     
 1872:     }
 1873:     return $datatable;
 1874: }
 1875: 
 1876: sub print_autocreate {
 1877:     my ($dom,$settings,$rowtotal) = @_;
 1878:     my (%createon,%createoff);
 1879:     my $curr_dc;
 1880:     my @types = ('xml','req');
 1881:     if (ref($settings) eq 'HASH') {
 1882:         foreach my $item (@types) {
 1883:             $createoff{$item} = ' checked="checked" ';
 1884:             $createon{$item} = ' ';
 1885:             if (exists($settings->{$item})) {
 1886:                 if ($settings->{$item}) {
 1887:                     $createon{$item} = ' checked="checked" ';
 1888:                     $createoff{$item} = ' ';
 1889:                 }
 1890:             }
 1891:         }
 1892:         $curr_dc = $settings->{'xmldc'};
 1893:     } else {
 1894:         foreach my $item (@types) {
 1895:             $createoff{$item} = ' checked="checked" ';
 1896:             $createon{$item} = ' ';
 1897:         }
 1898:     }
 1899:     $$rowtotal += 2;
 1900:     my $datatable='<tr class="LC_odd_row">'.
 1901:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
 1902:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1903:                   '<input type="radio" name="autocreate_xml"'.
 1904:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1905:                   '<label><input type="radio" name="autocreate_xml"'.
 1906:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
 1907:                   '</td></tr><tr>'.
 1908:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
 1909:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1910:                   '<input type="radio" name="autocreate_req"'.
 1911:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1912:                   '<label><input type="radio" name="autocreate_req"'.
 1913:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
 1914:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
 1915:     if ($numdc > 1) {
 1916:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
 1917:                       &mt('Course creation processed as: (choose Dom. Coord.)').
 1918:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
 1919:         $$rowtotal ++ ;
 1920:     } else {
 1921:         $datatable .= $dctable.'</td></tr>';
 1922:     }
 1923:     return $datatable;
 1924: }
 1925: 
 1926: sub print_directorysrch {
 1927:     my ($dom,$settings,$rowtotal) = @_;
 1928:     my $srchon = ' ';
 1929:     my $srchoff = ' checked="checked" ';
 1930:     my ($exacton,$containson,$beginson);
 1931:     my $localon = ' ';
 1932:     my $localoff = ' checked="checked" ';
 1933:     if (ref($settings) eq 'HASH') {
 1934:         if ($settings->{'available'} eq '1') {
 1935:             $srchon = $srchoff;
 1936:             $srchoff = ' ';
 1937:         }
 1938:         if ($settings->{'localonly'} eq '1') {
 1939:             $localon = $localoff;
 1940:             $localoff = ' ';
 1941:         }
 1942:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 1943:             foreach my $type (@{$settings->{'searchtypes'}}) {
 1944:                 if ($type eq 'exact') {
 1945:                     $exacton = ' checked="checked" ';
 1946:                 } elsif ($type eq 'contains') {
 1947:                     $containson = ' checked="checked" ';
 1948:                 } elsif ($type eq 'begins') {
 1949:                     $beginson = ' checked="checked" ';
 1950:                 }
 1951:             }
 1952:         } else {
 1953:             if ($settings->{'searchtypes'} eq 'exact') {
 1954:                 $exacton = ' checked="checked" ';
 1955:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 1956:                 $containson = ' checked="checked" ';
 1957:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 1958:                 $exacton = ' checked="checked" ';
 1959:                 $containson = ' checked="checked" ';
 1960:             }
 1961:         }
 1962:     }
 1963:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 1964:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1965: 
 1966:     my $numinrow = 4;
 1967:     my $cansrchrow = 0;
 1968:     my $datatable='<tr class="LC_odd_row">'.
 1969:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 1970:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1971:                   '<input type="radio" name="dirsrch_available"'.
 1972:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1973:                   '<label><input type="radio" name="dirsrch_available"'.
 1974:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1975:                   '</tr><tr>'.
 1976:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 1977:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1978:                   '<input type="radio" name="dirsrch_localonly"'.
 1979:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 1980:                   '<label><input type="radio" name="dirsrch_localonly"'.
 1981:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 1982:                   '</tr>';
 1983:     $$rowtotal += 2;
 1984:     if (ref($usertypes) eq 'HASH') {
 1985:         if (keys(%{$usertypes}) > 0) {
 1986:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
 1987:                                          $numinrow,$othertitle,'cansearch');
 1988:             $cansrchrow = 1;
 1989:         }
 1990:     }
 1991:     if ($cansrchrow) {
 1992:         $$rowtotal ++;
 1993:         $datatable .= '<tr>';
 1994:     } else {
 1995:         $datatable .= '<tr class="LC_odd_row">';
 1996:     }
 1997:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 1998:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 1999:     foreach my $title (@{$titleorder}) {
 2000:         if (defined($searchtitles->{$title})) {
 2001:             my $check = ' ';
 2002:             if (ref($settings) eq 'HASH') {
 2003:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 2004:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 2005:                         $check = ' checked="checked" ';
 2006:                     }
 2007:                 }
 2008:             }
 2009:             $datatable .= '<td class="LC_left_item">'.
 2010:                           '<span class="LC_nobreak"><label>'.
 2011:                           '<input type="checkbox" name="searchby" '.
 2012:                           'value="'.$title.'"'.$check.'/>'.
 2013:                           $searchtitles->{$title}.'</label></span></td>';
 2014:         }
 2015:     }
 2016:     $datatable .= '</tr></table></td></tr>';
 2017:     $$rowtotal ++;
 2018:     if ($cansrchrow) {
 2019:         $datatable .= '<tr class="LC_odd_row">';
 2020:     } else {
 2021:         $datatable .= '<tr>';
 2022:     }
 2023:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 2024:                   '<td class="LC_left_item" colspan="2">'.
 2025:                   '<span class="LC_nobreak"><label>'.
 2026:                   '<input type="checkbox" name="searchtypes" '.
 2027:                   $exacton.' value="exact" />'.&mt('Exact match').
 2028:                   '</label>&nbsp;'.
 2029:                   '<label><input type="checkbox" name="searchtypes" '.
 2030:                   $beginson.' value="begins" />'.&mt('Begins with').
 2031:                   '</label>&nbsp;'.
 2032:                   '<label><input type="checkbox" name="searchtypes" '.
 2033:                   $containson.' value="contains" />'.&mt('Contains').
 2034:                   '</label></span></td></tr>';
 2035:     $$rowtotal ++;
 2036:     return $datatable;
 2037: }
 2038: 
 2039: sub print_contacts {
 2040:     my ($dom,$settings,$rowtotal) = @_;
 2041:     my $datatable;
 2042:     my @contacts = ('adminemail','supportemail');
 2043:     my (%checked,%to,%otheremails,%bccemails);
 2044:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
 2045:                     'requestsmail');
 2046:     foreach my $type (@mailings) {
 2047:         $otheremails{$type} = '';
 2048:     }
 2049:     $bccemails{'helpdeskmail'} = '';
 2050:     if (ref($settings) eq 'HASH') {
 2051:         foreach my $item (@contacts) {
 2052:             if (exists($settings->{$item})) {
 2053:                 $to{$item} = $settings->{$item};
 2054:             }
 2055:         }
 2056:         foreach my $type (@mailings) {
 2057:             if (exists($settings->{$type})) {
 2058:                 if (ref($settings->{$type}) eq 'HASH') {
 2059:                     foreach my $item (@contacts) {
 2060:                         if ($settings->{$type}{$item}) {
 2061:                             $checked{$type}{$item} = ' checked="checked" ';
 2062:                         }
 2063:                     }
 2064:                     $otheremails{$type} = $settings->{$type}{'others'};
 2065:                     if ($type eq 'helpdeskmail') {
 2066:                         $bccemails{$type} = $settings->{$type}{'bcc'};
 2067:                     }
 2068:                 }
 2069:             } elsif ($type eq 'lonstatusmail') {
 2070:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
 2071:             }
 2072:         }
 2073:     } else {
 2074:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2075:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2076:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 2077:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 2078:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
 2079:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
 2080:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
 2081:     }
 2082:     my ($titles,$short_titles) = &contact_titles();
 2083:     my $rownum = 0;
 2084:     my $css_class;
 2085:     foreach my $item (@contacts) {
 2086:         $rownum ++;
 2087:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2088:         $datatable .= '<tr'.$css_class.'>'. 
 2089:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2090:                   '</span></td><td class="LC_right_item">'.
 2091:                   '<input type="text" name="'.$item.'" value="'.
 2092:                   $to{$item}.'" /></td></tr>';
 2093:     }
 2094:     foreach my $type (@mailings) {
 2095:         $rownum ++;
 2096:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2097:         $datatable .= '<tr'.$css_class.'>'.
 2098:                       '<td><span class="LC_nobreak">'.
 2099:                       $titles->{$type}.': </span></td>'.
 2100:                       '<td class="LC_left_item">'.
 2101:                       '<span class="LC_nobreak">';
 2102:         foreach my $item (@contacts) {
 2103:             $datatable .= '<label>'.
 2104:                           '<input type="checkbox" name="'.$type.'"'.
 2105:                           $checked{$type}{$item}.
 2106:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 2107:                           '</label>&nbsp;';
 2108:         }
 2109:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 2110:                       '<input type="text" name="'.$type.'_others" '.
 2111:                       'value="'.$otheremails{$type}.'"  />';
 2112:         if ($type eq 'helpdeskmail') {
 2113:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
 2114:                           '<input type="text" name="'.$type.'_bcc" '.
 2115:                           'value="'.$bccemails{$type}.'"  />';
 2116:         }
 2117:         $datatable .= '</td></tr>'."\n";
 2118:     }
 2119:     $$rowtotal += $rownum;
 2120:     return $datatable;
 2121: }
 2122: 
 2123: sub print_helpsettings {
 2124: 
 2125: 	my ($position,$dom,$confname,$settings,$rowtotal) = @_;
 2126: 	my ($css_class,$datatable);
 2127: 	
 2128: 	my $switchserver = &check_switchserver($dom,$confname);
 2129: 	
 2130: 	my $itemcount = 1;
 2131: 	
 2132: 	if ($position eq 'top') {
 2133: 		
 2134: 		my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
 2135: 		
 2136: 		%choices =
 2137: 			&Apache::lonlocal::texthash (
 2138: 				submitbugs => 'Display &quot;Submit a bug&quot; link?',
 2139: 		);
 2140: 		
 2141: 		%defaultchecked = ('submitbugs' => 'on');
 2142: 		
 2143: 		@toggles = ('submitbugs',);
 2144: 		
 2145: 		foreach my $item (@toggles) {
 2146: 			if ($defaultchecked{$item} eq 'on') { 
 2147: 				$checkedon{$item} = ' checked="checked" ';
 2148: 				$checkedoff{$item} = ' ';
 2149: 			} elsif ($defaultchecked{$item} eq 'off') {
 2150: 				$checkedoff{$item} = ' checked="checked" ';
 2151: 				$checkedon{$item} = ' ';
 2152: 			}
 2153: 		}
 2154: 		
 2155: 		if (ref($settings) eq 'HASH') {
 2156: 			foreach my $item (@toggles) {
 2157: 				if ($settings->{$item} eq '1') {
 2158: 					$checkedon{$item} =  ' checked="checked" ';
 2159: 					$checkedoff{$item} = ' ';
 2160: 				} elsif ($settings->{$item} eq '0') {
 2161: 					$checkedoff{$item} =  ' checked="checked" ';
 2162: 					$checkedon{$item} = ' ';
 2163: 				}
 2164: 			}
 2165: 		 }
 2166: 		
 2167: 		 foreach my $item (@toggles) {
 2168: 			$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2169: 			$datatable .=  
 2170: 				'<tr'.$css_class.'>
 2171: 				<td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
 2172: 				<td><span class="LC_nobreak">&nbsp;</span></td>
 2173: 				<td class="LC_right_item"><span class="LC_nobreak">
 2174: 				<label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>&nbsp;
 2175: 				<label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
 2176: 				'</span></td>'.
 2177: 				'</tr>';
 2178: 			$itemcount ++;
 2179: 		 }
 2180:      
 2181:      } else {
 2182:      
 2183:      	$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2184:      	
 2185:      	$datatable .= '<tr'.$css_class.'>';
 2186:      	
 2187:      	if (ref($settings) eq 'HASH') {
 2188: 			if ($settings->{'loginhelpurl'} ne '') {
 2189: 				my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
 2190: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
 2191: 				$datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
 2192: 			} else {
 2193: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
 2194: 				$datatable .= '<td width="33%"><span class="LC_right_item">&nbsp;</span></td>';
 2195: 			}
 2196: 		} else {
 2197: 			$datatable .= '<td><span class="LC_left_item">&nbsp;</span></td>';
 2198: 			$datatable .= '<td><span class="LC_right_item">&nbsp;</span></td>';
 2199: 		}
 2200:     	
 2201:      	$datatable .= '<td width="33%"><span class="LC_right_item">';
 2202:      	if ($switchserver) {
 2203:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2204:         } else {
 2205:         	$datatable .= &mt('Upload Custom Login Page Help File:');
 2206:             $datatable .='<input type="file" name="loginhelpurl" />';
 2207:         }
 2208:         $datatable .= '</span></td></tr>';
 2209:         
 2210:      }
 2211:      
 2212:      return $datatable;
 2213: 	
 2214: }
 2215: 
 2216: 
 2217: sub radiobutton_prefs {
 2218:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
 2219:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
 2220:                    (ref($choices) eq 'HASH'));
 2221: 
 2222:     my (%checkedon,%checkedoff,$datatable,$css_class);
 2223: 
 2224:     foreach my $item (@{$toggles}) {
 2225:         if ($defaultchecked->{$item} eq 'on') {
 2226:             $checkedon{$item} = ' checked="checked" ';
 2227:             $checkedoff{$item} = ' ';
 2228:         } elsif ($defaultchecked->{$item} eq 'off') {
 2229:             $checkedoff{$item} = ' checked="checked" ';
 2230:             $checkedon{$item} = ' ';
 2231:         }
 2232:     }
 2233:     if (ref($settings) eq 'HASH') {
 2234:         foreach my $item (@{$toggles}) {
 2235:             if ($settings->{$item} eq '1') {
 2236:                 $checkedon{$item} =  ' checked="checked" ';
 2237:                 $checkedoff{$item} = ' ';
 2238:             } elsif ($settings->{$item} eq '0') {
 2239:                 $checkedoff{$item} =  ' checked="checked" ';
 2240:                 $checkedon{$item} = ' ';
 2241:             }
 2242:         }
 2243:     }
 2244:     foreach my $item (@{$toggles}) {
 2245:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2246:         $datatable .=
 2247:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
 2248:             '</span></td>'.
 2249:             '<td class="LC_right_item"><span class="LC_nobreak">'.
 2250:             '<label><input type="radio" name="'.
 2251:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
 2252:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
 2253:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
 2254:             '</span></td>'.
 2255:             '</tr>';
 2256:         $itemcount ++;
 2257:     }
 2258:     return ($datatable,$itemcount);
 2259: }
 2260: 
 2261: sub print_coursedefaults {
 2262:     my ($position,$dom,$settings,$rowtotal) = @_;
 2263:     my ($css_class,$datatable);
 2264:     my $itemcount = 1;
 2265:     if ($position eq 'top') {
 2266:         my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
 2267:         %choices =
 2268:             &Apache::lonlocal::texthash (
 2269:                 canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
 2270:         );
 2271:         %defaultchecked = ('canuse_pdfforms' => 'off');
 2272:         @toggles = ('canuse_pdfforms',);
 2273:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2274:                                                  \%choices,$itemcount);
 2275:         $$rowtotal += $itemcount;
 2276:     } else {
 2277:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2278:         my %choices =
 2279:             &Apache::lonlocal::texthash (
 2280:                 anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
 2281:         );
 2282:         my $currdefresponder;
 2283:         if (ref($settings) eq 'HASH') {
 2284:             $currdefresponder = $settings->{'anonsurvey_threshold'};
 2285:         }
 2286:         if (!$currdefresponder) {
 2287:             $currdefresponder = 10;
 2288:         } elsif ($currdefresponder < 1) {
 2289:             $currdefresponder = 1;
 2290:         }
 2291:         $datatable .=
 2292:                '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
 2293:                 '</span></td>'.
 2294:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
 2295:                 '<input type="text" name="anonsurvey_threshold"'.
 2296:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
 2297:                 '</td></tr>';
 2298:     }
 2299:     return $datatable;
 2300: }
 2301: 
 2302: sub print_usersessions {
 2303:     my ($position,$dom,$settings,$rowtotal) = @_;
 2304:     my ($css_class,$datatable,%checked,%choices);
 2305:     my (%by_ip,%by_location,@intdoms);
 2306:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 2307: 
 2308:     my @alldoms = &Apache::lonnet::all_domains();
 2309:     my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
 2310:     my %servers = &dom_servers($dom);
 2311:     my $itemcount = 1;
 2312:     if ($position eq 'top') {
 2313:         if (keys(%uniques) > 1) {
 2314:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
 2315:             $datatable .= &spares_row(\%servers,\%spareid,\%uniques,$rowtotal);
 2316:         } else {
 2317:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 2318:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains this server.');
 2319:         }
 2320:     } else {
 2321:         if (keys(%by_location) == 0) {
 2322:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 2323:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains this institution.');
 2324:         } else {
 2325:             my %lt = &usersession_titles();
 2326:             my $numinrow = 5;
 2327:             my $prefix;
 2328:             my @types;
 2329:             if ($position eq 'bottom') {
 2330:                 $prefix = 'remote';
 2331:                 @types = ('version','excludedomain','includedomain');
 2332:             } else {
 2333:                 $prefix = 'hosted';
 2334:                 @types = ('excludedomain','includedomain');
 2335:             }
 2336:             my (%current,%checkedon,%checkedoff);
 2337:             my @lcversions = &Apache::lonnet::all_loncaparevs();
 2338:             my @locations = sort(keys(%by_location));
 2339:             foreach my $type (@types) {
 2340:                 $checkedon{$type} = '';
 2341:                 $checkedoff{$type} = ' checked="checked"';
 2342:             }
 2343:             if (ref($settings) eq 'HASH') {
 2344:                 if (ref($settings->{$prefix}) eq 'HASH') {
 2345:                     foreach my $key (keys(%{$settings->{$prefix}})) {
 2346:                         $current{$key} = $settings->{$prefix}{$key};
 2347:                         if ($key eq 'version') {
 2348:                             if ($current{$key} ne '') {
 2349:                                 $checkedon{$key} = ' checked="checked"';
 2350:                                 $checkedoff{$key} = '';
 2351:                             }
 2352:                         } elsif (ref($current{$key}) eq 'ARRAY') {
 2353:                             $checkedon{$key} = ' checked="checked"';
 2354:                             $checkedoff{$key} = '';
 2355:                         }
 2356:                     }
 2357:                 }
 2358:             }
 2359:             foreach my $type (@types) {
 2360:                 next if ($type ne 'version' && !@locations);
 2361:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2362:                 $datatable .= '<tr'.$css_class.'>
 2363:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
 2364:                                <span class="LC_nobreak">&nbsp;
 2365:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
 2366:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
 2367:                 if ($type eq 'version') {
 2368:                     my $selector = '<select name="'.$prefix.'_version">';
 2369:                     foreach my $version (@lcversions) {
 2370:                         my $selected = '';
 2371:                         if ($current{'version'} eq $version) {
 2372:                             $selected = ' selected="selected"';
 2373:                         }
 2374:                         $selector .= ' <option value="'.$version.'"'.
 2375:                                      $selected.'>'.$version.'</option>';
 2376:                     }
 2377:                     $selector .= '</select> ';
 2378:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
 2379:                 } else {
 2380:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
 2381:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
 2382:                                  ' />'.('&nbsp;'x2).
 2383:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
 2384:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
 2385:                                  "\n".
 2386:                                  '</div><div><table>';
 2387:                     my $rem;
 2388:                     for (my $i=0; $i<@locations; $i++) {
 2389:                         my ($showloc,$value,$checkedtype);
 2390:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
 2391:                             my $ip = $by_location{$locations[$i]}->[0];
 2392:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
 2393:                                  $value = join(':',@{$by_ip{$ip}});
 2394:                                 $showloc = join(', ',@{$by_ip{$ip}});
 2395:                                 if (ref($current{$type}) eq 'ARRAY') {
 2396:                                     foreach my $loc (@{$by_ip{$ip}}) {  
 2397:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
 2398:                                             $checkedtype = ' checked="checked"';
 2399:                                             last;
 2400:                                         }
 2401:                                     }
 2402:                                 }
 2403:                             }
 2404:                         }
 2405:                         $rem = $i%($numinrow);
 2406:                         if ($rem == 0) {
 2407:                             if ($i > 0) {
 2408:                                 $datatable .= '</tr>';
 2409:                             }
 2410:                             $datatable .= '<tr>';
 2411:                         }
 2412:                         $datatable .= '<td class="LC_left_item">'.
 2413:                                       '<span class="LC_nobreak"><label>'.
 2414:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
 2415:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
 2416:                                       '</label></span></td>';
 2417:                     }
 2418:                     $rem = @locations%($numinrow);
 2419:                     my $colsleft = $numinrow - $rem;
 2420:                     if ($colsleft > 1 ) {
 2421:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2422:                                       '&nbsp;</td>';
 2423:                     } elsif ($colsleft == 1) {
 2424:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 2425:                     }
 2426:                     $datatable .= '</tr></table>';
 2427:                 }
 2428:                 $datatable .= '</td></tr>';
 2429:                 $itemcount ++;
 2430:             }
 2431:         }
 2432:     }
 2433:     $$rowtotal += $itemcount;
 2434:     return $datatable;
 2435: }
 2436: 
 2437: sub build_location_hashes {
 2438:     my ($intdoms,$by_ip,$by_location) = @_;
 2439:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
 2440:                   (ref($by_location) eq 'HASH')); 
 2441:     my %iphost = &Apache::lonnet::get_iphost();
 2442:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
 2443:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
 2444:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
 2445:         foreach my $id (@{$iphost{$primary_ip}}) {
 2446:             my $intdom = &Apache::lonnet::internet_dom($id);
 2447:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
 2448:                 push(@{$intdoms},$intdom);
 2449:             }
 2450:         }
 2451:     }
 2452:     foreach my $ip (keys(%iphost)) {
 2453:         if (ref($iphost{$ip}) eq 'ARRAY') {
 2454:             foreach my $id (@{$iphost{$ip}}) {
 2455:                 my $location = &Apache::lonnet::internet_dom($id);
 2456:                 if ($location) {
 2457:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
 2458:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2459:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
 2460:                             push(@{$by_ip->{$ip}},$location);
 2461:                         }
 2462:                     } else {
 2463:                         $by_ip->{$ip} = [$location];
 2464:                     }
 2465:                 }
 2466:             }
 2467:         }
 2468:     }
 2469:     foreach my $ip (sort(keys(%{$by_ip}))) {
 2470:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2471:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
 2472:             my $first = $by_ip->{$ip}->[0];
 2473:             if (ref($by_location->{$first}) eq 'ARRAY') {
 2474:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
 2475:                     push(@{$by_location->{$first}},$ip);
 2476:                 }
 2477:             } else {
 2478:                 $by_location->{$first} = [$ip];
 2479:             }
 2480:         }
 2481:     }
 2482:     return;
 2483: }
 2484: 
 2485: sub current_offloads_to {
 2486:     my ($dom,$settings,$servers) = @_;
 2487:     my (%spareid,%otherdomconfigs);
 2488:     if ((ref($settings) eq 'HASH') && (ref($servers) eq 'HASH')) {
 2489:         foreach my $lonhost (sort(keys(%{$servers}))) {
 2490:             my $gotspares;
 2491:             if (ref($settings->{'spares'}) eq 'HASH') {
 2492:                 if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
 2493:                     $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
 2494:                     $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
 2495:                     $gotspares = 1;
 2496:                 }
 2497:             }
 2498:             unless ($gotspares) {
 2499:                 my $gotspares;
 2500:                 my $serverhomeID =
 2501:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
 2502:                 my $serverhomedom =
 2503:                     &Apache::lonnet::host_domain($serverhomeID);
 2504:                 if ($serverhomedom ne $dom) {
 2505:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
 2506:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 2507:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 2508:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 2509:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 2510:                                 $gotspares = 1;
 2511:                             }
 2512:                         }
 2513:                     } else {
 2514:                         $otherdomconfigs{$serverhomedom} =
 2515:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
 2516:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
 2517:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 2518:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 2519:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
 2520:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 2521:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 2522:                                         $gotspares = 1;
 2523:                                     }
 2524:                                 }
 2525:                             }
 2526:                         }
 2527:                     }
 2528:                 }
 2529:             }
 2530:             unless ($gotspares) {
 2531:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
 2532:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 2533:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 2534:                } else {
 2535:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
 2536:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
 2537:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
 2538:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 2539:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 2540:                     } else {
 2541:                         my %requested;
 2542:                         $requested{'spareid'} = 'HASH';
 2543:                         my %returnhash = &Apache::lonnet::get_remote_globals($lonhost,\%requested);
 2544:                         my $spareshash = $returnhash{'spareid'};
 2545:                         if (ref($spareshash) eq 'HASH') {
 2546:                             $spareid{$lonhost}{'primary'} = $spareshash->{'primary'};
 2547:                             $spareid{$lonhost}{'default'} = $spareshash->{'default'};
 2548:                         }
 2549:                     }
 2550:                 }
 2551:             }
 2552:         }
 2553:     }
 2554:     return %spareid;
 2555: }
 2556: 
 2557: sub spares_row {
 2558:     my ($servers,$spareid,$uniques,$rowtotal) = @_;
 2559:     my $css_class;
 2560:     my $numinrow = 4;
 2561:     my $itemcount = 1;
 2562:     my $datatable;
 2563:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH')) {
 2564:         foreach my $server (sort(keys(%{$servers}))) {
 2565:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2566:             $datatable .= '<tr'.$css_class.'>
 2567:                            <td rowspan="2">
 2568:                             <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>';
 2569:             my (%current,%canselect);
 2570:             if (ref($spareid->{$server}) eq 'HASH') {
 2571:                 foreach my $type ('primary','default') {
 2572:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
 2573:                         my @spares = @{$spareid->{$server}{$type}};
 2574:                         if (@spares > 0) {
 2575:                             $current{$type} .= '<table>';
 2576:                             for (my $i=0;  $i<@spares; $i++) {
 2577:                                 my $rem = $i%($numinrow);
 2578:                                 if ($rem == 0) {
 2579:                                     if ($i > 0) {
 2580:                                         $current{$type} .= '</tr>';
 2581:                                     }
 2582:                                     $current{$type} .= '<tr>';
 2583:                                 }
 2584:                                 $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" />&nbsp;'.
 2585:                                                    $spareid->{$server}{$type}[$i].
 2586:                                                    '</label></td>';
 2587:                             }
 2588:                             $current{$type} .= '</tr></table>';
 2589:                         }
 2590:                     }
 2591:                     if ($current{$type} eq '') {
 2592:                         $current{$type} = &mt('None specified');
 2593:                     }
 2594:                     $canselect{$type} =
 2595:                         &newspare_select($server,$type,$spareid->{$server}{$type},$uniques);
 2596:                 }
 2597:             }
 2598:             $datatable .= '<td><i>'.&mt('primary').'</i><td>'.$current{'primary'}.'</td>'.
 2599:                           '<td>'.&mt('Add new [_1]primary[_2]:','<i>','</i>').'&nbsp;'.
 2600:                           $canselect{'primary'}.'</td></tr>'.
 2601:                           '<tr'.$css_class.'>'.
 2602:                           '<td><i>'.&mt('default').'</i></td>'.
 2603:                           '<td>'.$current{'default'}.'</td>'.
 2604:                           '<td>'.&mt('Add new [_1]default[_2]:','<i>','</i>').'&nbsp;'.
 2605:                           $canselect{'default'}.'</td></tr>';
 2606:             $itemcount ++;
 2607:         }
 2608:     }
 2609:     $$rowtotal += $itemcount;
 2610:     return $datatable;
 2611: }
 2612: 
 2613: sub newspare_select {
 2614:     my ($server,$type,$currspares,$uniques) = @_;
 2615:     my $output;
 2616:     if (ref($uniques) eq 'HASH') {
 2617:         if (keys(%{$uniques}) > 1) {
 2618:             $output = '<select name="newspare_'.$type.'_'.$server.'">'."\n".
 2619:                       '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
 2620:             foreach my $lonhost (sort(keys(%{$uniques}))) {
 2621:                 next if ($lonhost eq $server);
 2622:                 if (ref($currspares) eq 'ARRAY') {
 2623:                     if (@{$currspares} > 0) {
 2624:                         next if (grep(/^\Q$lonhost\E$/,@{$currspares}));
 2625:                     }
 2626:                 }
 2627:                 $output .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
 2628:             }
 2629:             $output .= '<select>';
 2630:         }
 2631:     }
 2632:     return $output;
 2633: }
 2634: 
 2635: sub contact_titles {
 2636:     my %titles = &Apache::lonlocal::texthash (
 2637:                    'supportemail' => 'Support E-mail address',
 2638:                    'adminemail'   => 'Default Server Admin E-mail address',
 2639:                    'errormail'    => 'Error reports to be e-mailed to',
 2640:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 2641:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
 2642:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
 2643:                    'requestsmail' => 'E-mail from course requests requiring approval',
 2644:                  );
 2645:     my %short_titles = &Apache::lonlocal::texthash (
 2646:                            adminemail   => 'Admin E-mail address',
 2647:                            supportemail => 'Support E-mail',
 2648:                        );   
 2649:     return (\%titles,\%short_titles);
 2650: }
 2651: 
 2652: sub tool_titles {
 2653:     my %titles = &Apache::lonlocal::texthash (
 2654:                      aboutme    => 'Personal Information Page',
 2655:                      blog       => 'Blog',
 2656:                      portfolio  => 'Portfolio',
 2657:                      official   => 'Official courses (with institutional codes)',
 2658:                      unofficial => 'Unofficial courses',
 2659:                      community  => 'Communities',
 2660:                  );
 2661:     return %titles;
 2662: }
 2663: 
 2664: sub courserequest_titles {
 2665:     my %titles = &Apache::lonlocal::texthash (
 2666:                                    official   => 'Official',
 2667:                                    unofficial => 'Unofficial',
 2668:                                    community  => 'Communities',
 2669:                                    norequest  => 'Not allowed',
 2670:                                    approval   => 'Approval by Dom. Coord.',
 2671:                                    validate   => 'With validation',
 2672:                                    autolimit  => 'Numerical limit',
 2673:                                    unlimited  => '(blank for unlimited)',
 2674:                  );
 2675:     return %titles;
 2676: }
 2677: 
 2678: sub courserequest_conditions {
 2679:     my %conditions = &Apache::lonlocal::texthash (
 2680:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
 2681:        validate   => '(Processing of request subject to instittutional validation).',
 2682:                  );
 2683:     return %conditions;
 2684: }
 2685: 
 2686: 
 2687: sub print_usercreation {
 2688:     my ($position,$dom,$settings,$rowtotal) = @_;
 2689:     my $numinrow = 4;
 2690:     my $datatable;
 2691:     if ($position eq 'top') {
 2692:         $$rowtotal ++;
 2693:         my $rowcount = 0;
 2694:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 2695:         if (ref($rules) eq 'HASH') {
 2696:             if (keys(%{$rules}) > 0) {
 2697:                 $datatable .= &user_formats_row('username',$settings,$rules,
 2698:                                                 $ruleorder,$numinrow,$rowcount);
 2699:                 $$rowtotal ++;
 2700:                 $rowcount ++;
 2701:             }
 2702:         }
 2703:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 2704:         if (ref($idrules) eq 'HASH') {
 2705:             if (keys(%{$idrules}) > 0) {
 2706:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 2707:                                                 $idruleorder,$numinrow,$rowcount);
 2708:                 $$rowtotal ++;
 2709:                 $rowcount ++;
 2710:             }
 2711:         }
 2712:         my ($emailrules,$emailruleorder) = 
 2713:             &Apache::lonnet::inst_userrules($dom,'email');
 2714:         if (ref($emailrules) eq 'HASH') {
 2715:             if (keys(%{$emailrules}) > 0) {
 2716:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 2717:                                                 $emailruleorder,$numinrow,$rowcount);
 2718:                 $$rowtotal ++;
 2719:                 $rowcount ++;
 2720:             }
 2721:         }
 2722:         if ($rowcount == 0) {
 2723:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 2724:             $$rowtotal ++;
 2725:             $rowcount ++;
 2726:         }
 2727:     } elsif ($position eq 'middle') {
 2728:         my @creators = ('author','course','requestcrs','selfcreate');
 2729:         my ($rules,$ruleorder) =
 2730:             &Apache::lonnet::inst_userrules($dom,'username');
 2731:         my %lt = &usercreation_types();
 2732:         my %checked;
 2733:         my @selfcreate; 
 2734:         if (ref($settings) eq 'HASH') {
 2735:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 2736:                 foreach my $item (@creators) {
 2737:                     $checked{$item} = $settings->{'cancreate'}{$item};
 2738:                 }
 2739:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
 2740:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
 2741:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
 2742:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 2743:                         @selfcreate = ('email','login','sso');
 2744:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
 2745:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
 2746:                     }
 2747:                 }
 2748:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 2749:                 foreach my $item (@creators) {
 2750:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 2751:                         $checked{$item} = 'none';
 2752:                     }
 2753:                 }
 2754:             }
 2755:         }
 2756:         my $rownum = 0;
 2757:         foreach my $item (@creators) {
 2758:             $rownum ++;
 2759:             if ($item ne 'selfcreate') {  
 2760:                 if ($checked{$item} eq '') {
 2761:                     $checked{$item} = 'any';
 2762:                 }
 2763:             }
 2764:             my $css_class;
 2765:             if ($rownum%2) {
 2766:                 $css_class = '';
 2767:             } else {
 2768:                 $css_class = ' class="LC_odd_row" ';
 2769:             }
 2770:             $datatable .= '<tr'.$css_class.'>'.
 2771:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 2772:                          '</span></td><td align="right">';
 2773:             my @options;
 2774:             if ($item eq 'selfcreate') {
 2775:                 push(@options,('email','login','sso'));
 2776:             } else {
 2777:                 @options = ('any');
 2778:                 if (ref($rules) eq 'HASH') {
 2779:                     if (keys(%{$rules}) > 0) {
 2780:                         push(@options,('official','unofficial'));
 2781:                     }
 2782:                 }
 2783:                 push(@options,'none');
 2784:             }
 2785:             foreach my $option (@options) {
 2786:                 my $type = 'radio';
 2787:                 my $check = ' ';
 2788:                 if ($item eq 'selfcreate') {
 2789:                     $type = 'checkbox';
 2790:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
 2791:                         $check = ' checked="checked" ';
 2792:                     }
 2793:                 } else {
 2794:                     if ($checked{$item} eq $option) {
 2795:                         $check = ' checked="checked" ';
 2796:                     }
 2797:                 } 
 2798:                 $datatable .= '<span class="LC_nobreak"><label>'.
 2799:                               '<input type="'.$type.'" name="can_createuser_'.
 2800:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 2801:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 2802:             }
 2803:             $datatable .= '</td></tr>';
 2804:         }
 2805:         my ($othertitle,$usertypes,$types) =
 2806:             &Apache::loncommon::sorted_inst_types($dom);
 2807:         if (ref($usertypes) eq 'HASH') {
 2808:             if (keys(%{$usertypes}) > 0) {
 2809:                 my $createsettings;
 2810:                 if (ref($settings) eq 'HASH') {
 2811:                     $createsettings = $settings->{cancreate};
 2812:                 }
 2813:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
 2814:                                              $dom,$numinrow,$othertitle,
 2815:                                              'statustocreate');
 2816:                 $$rowtotal ++;
 2817:             }
 2818:         }
 2819:     } else {
 2820:         my @contexts = ('author','course','domain');
 2821:         my @authtypes = ('int','krb4','krb5','loc');
 2822:         my %checked;
 2823:         if (ref($settings) eq 'HASH') {
 2824:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 2825:                 foreach my $item (@contexts) {
 2826:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 2827:                         foreach my $auth (@authtypes) {
 2828:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 2829:                                 $checked{$item}{$auth} = ' checked="checked" ';
 2830:                             }
 2831:                         }
 2832:                     }
 2833:                 }
 2834:             }
 2835:         } else {
 2836:             foreach my $item (@contexts) {
 2837:                 foreach my $auth (@authtypes) {
 2838:                     $checked{$item}{$auth} = ' checked="checked" ';
 2839:                 }
 2840:             }
 2841:         }
 2842:         my %title = &context_names();
 2843:         my %authname = &authtype_names();
 2844:         my $rownum = 0;
 2845:         my $css_class; 
 2846:         foreach my $item (@contexts) {
 2847:             if ($rownum%2) {
 2848:                 $css_class = '';
 2849:             } else {
 2850:                 $css_class = ' class="LC_odd_row" ';
 2851:             }
 2852:             $datatable .=   '<tr'.$css_class.'>'.
 2853:                             '<td>'.$title{$item}.
 2854:                             '</td><td class="LC_left_item">'.
 2855:                             '<span class="LC_nobreak">';
 2856:             foreach my $auth (@authtypes) {
 2857:                 $datatable .= '<label>'. 
 2858:                               '<input type="checkbox" name="'.$item.'_auth" '.
 2859:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 2860:                               $authname{$auth}.'</label>&nbsp;';
 2861:             }
 2862:             $datatable .= '</span></td></tr>';
 2863:             $rownum ++;
 2864:         }
 2865:         $$rowtotal += $rownum;
 2866:     }
 2867:     return $datatable;
 2868: }
 2869: 
 2870: sub user_formats_row {
 2871:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 2872:     my $output;
 2873:     my %text = (
 2874:                    'username' => 'new usernames',
 2875:                    'id'       => 'IDs',
 2876:                    'email'    => 'self-created accounts (e-mail)',
 2877:                );
 2878:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 2879:     $output = '<tr '.$css_class.'>'.
 2880:               '<td><span class="LC_nobreak">';
 2881:     if ($type eq 'email') {
 2882:         $output .= &mt("Formats disallowed for $text{$type}: ");
 2883:     } else {
 2884:         $output .= &mt("Format rules to check for $text{$type}: ");
 2885:     }
 2886:     $output .= '</span></td>'.
 2887:                '<td class="LC_left_item" colspan="2"><table>';
 2888:     my $rem;
 2889:     if (ref($ruleorder) eq 'ARRAY') {
 2890:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 2891:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 2892:                 my $rem = $i%($numinrow);
 2893:                 if ($rem == 0) {
 2894:                     if ($i > 0) {
 2895:                         $output .= '</tr>';
 2896:                     }
 2897:                     $output .= '<tr>';
 2898:                 }
 2899:                 my $check = ' ';
 2900:                 if (ref($settings) eq 'HASH') {
 2901:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 2902:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 2903:                             $check = ' checked="checked" ';
 2904:                         }
 2905:                     }
 2906:                 }
 2907:                 $output .= '<td class="LC_left_item">'.
 2908:                            '<span class="LC_nobreak"><label>'.
 2909:                            '<input type="checkbox" name="'.$type.'_rule" '.
 2910:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 2911:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 2912:             }
 2913:         }
 2914:         $rem = @{$ruleorder}%($numinrow);
 2915:     }
 2916:     my $colsleft = $numinrow - $rem;
 2917:     if ($colsleft > 1 ) {
 2918:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2919:                    '&nbsp;</td>';
 2920:     } elsif ($colsleft == 1) {
 2921:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 2922:     }
 2923:     $output .= '</tr></table></td></tr>';
 2924:     return $output;
 2925: }
 2926: 
 2927: sub usercreation_types {
 2928:     my %lt = &Apache::lonlocal::texthash (
 2929:                     author     => 'When adding a co-author',
 2930:                     course     => 'When adding a user to a course',
 2931:                     requestcrs => 'When requesting a course',
 2932:                     selfcreate => 'User creates own account', 
 2933:                     any        => 'Any',
 2934:                     official   => 'Institutional only ',
 2935:                     unofficial => 'Non-institutional only',
 2936:                     email      => 'E-mail address',
 2937:                     login      => 'Institutional Login',
 2938:                     sso        => 'SSO', 
 2939:                     none       => 'None',
 2940:     );
 2941:     return %lt;
 2942: }
 2943: 
 2944: sub authtype_names {
 2945:     my %lt = &Apache::lonlocal::texthash(
 2946:                       int    => 'Internal',
 2947:                       krb4   => 'Kerberos 4',
 2948:                       krb5   => 'Kerberos 5',
 2949:                       loc    => 'Local',
 2950:                   );
 2951:     return %lt;
 2952: }
 2953: 
 2954: sub context_names {
 2955:     my %context_title = &Apache::lonlocal::texthash(
 2956:        author => 'Creating users when an Author',
 2957:        course => 'Creating users when in a course',
 2958:        domain => 'Creating users when a Domain Coordinator',
 2959:     );
 2960:     return %context_title;
 2961: }
 2962: 
 2963: sub print_usermodification {
 2964:     my ($position,$dom,$settings,$rowtotal) = @_;
 2965:     my $numinrow = 4;
 2966:     my ($context,$datatable,$rowcount);
 2967:     if ($position eq 'top') {
 2968:         $rowcount = 0;
 2969:         $context = 'author'; 
 2970:         foreach my $role ('ca','aa') {
 2971:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 2972:                                                    $numinrow,$rowcount);
 2973:             $$rowtotal ++;
 2974:             $rowcount ++;
 2975:         }
 2976:     } elsif ($position eq 'middle') {
 2977:         $context = 'course';
 2978:         $rowcount = 0;
 2979:         foreach my $role ('st','ep','ta','in','cr') {
 2980:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 2981:                                                    $numinrow,$rowcount);
 2982:             $$rowtotal ++;
 2983:             $rowcount ++;
 2984:         }
 2985:     } elsif ($position eq 'bottom') {
 2986:         $context = 'selfcreate';
 2987:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2988:         $usertypes->{'default'} = $othertitle;
 2989:         if (ref($types) eq 'ARRAY') {
 2990:             push(@{$types},'default');
 2991:             $usertypes->{'default'} = $othertitle;
 2992:             foreach my $status (@{$types}) {
 2993:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
 2994:                                                        $numinrow,$rowcount,$usertypes);
 2995:                 $$rowtotal ++;
 2996:                 $rowcount ++;
 2997:             }
 2998:         }
 2999:     }
 3000:     return $datatable;
 3001: }
 3002: 
 3003: sub print_defaults {
 3004:     my ($dom,$rowtotal) = @_;
 3005:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 3006:                  'datelocale_def','portal_def');
 3007:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 3008:     my $titles = &defaults_titles($dom);
 3009:     my $rownum = 0;
 3010:     my ($datatable,$css_class);
 3011:     foreach my $item (@items) {
 3012:         if ($rownum%2) {
 3013:             $css_class = '';
 3014:         } else {
 3015:             $css_class = ' class="LC_odd_row" ';
 3016:         }
 3017:         $datatable .= '<tr'.$css_class.'>'.
 3018:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 3019:                   '</span></td><td class="LC_right_item">';
 3020:         if ($item eq 'auth_def') {
 3021:             my @authtypes = ('internal','krb4','krb5','localauth');
 3022:             my %shortauth = (
 3023:                              internal => 'int',
 3024:                              krb4 => 'krb4',
 3025:                              krb5 => 'krb5',
 3026:                              localauth  => 'loc'
 3027:                            );
 3028:             my %authnames = &authtype_names();
 3029:             foreach my $auth (@authtypes) {
 3030:                 my $checked = ' ';
 3031:                 if ($domdefaults{$item} eq $auth) {
 3032:                     $checked = ' checked="checked" ';
 3033:                 }
 3034:                 $datatable .= '<label><input type="radio" name="'.$item.
 3035:                               '" value="'.$auth.'"'.$checked.'/>'.
 3036:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 3037:             }
 3038:         } elsif ($item eq 'timezone_def') {
 3039:             my $includeempty = 1;
 3040:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
 3041:         } elsif ($item eq 'datelocale_def') {
 3042:             my $includeempty = 1;
 3043:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
 3044:         } else {
 3045:             my $size;
 3046:             if ($item eq 'portal_def') {
 3047:                 $size = ' size="25"';
 3048:             }
 3049:             $datatable .= '<input type="text" name="'.$item.'" value="'.
 3050:                           $domdefaults{$item}.'"'.$size.' />';
 3051:         }
 3052:         $datatable .= '</td></tr>';
 3053:         $rownum ++;
 3054:     }
 3055:     $$rowtotal += $rownum;
 3056:     return $datatable;
 3057: }
 3058: 
 3059: sub defaults_titles {
 3060:     my ($dom) = @_;
 3061:     my %titles = &Apache::lonlocal::texthash (
 3062:                    'auth_def'      => 'Default authentication type',
 3063:                    'auth_arg_def'  => 'Default authentication argument',
 3064:                    'lang_def'      => 'Default language',
 3065:                    'timezone_def'  => 'Default timezone',
 3066:                    'datelocale_def' => 'Default locale for dates',
 3067:                    'portal_def'     => 'Portal/Default URL',
 3068:                  );
 3069:     if ($dom) {
 3070:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
 3071:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
 3072:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
 3073:         $protocol = 'http' if ($protocol ne 'https');
 3074:         if ($uint_dom) {
 3075:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
 3076:                                          $uint_dom);
 3077:         }
 3078:     }
 3079:     return (\%titles);
 3080: }
 3081: 
 3082: sub print_scantronformat {
 3083:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 3084:     my $itemcount = 1;
 3085:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 3086:         %confhash);
 3087:     my $switchserver = &check_switchserver($dom,$confname);
 3088:     my %lt = &Apache::lonlocal::texthash (
 3089:                 default => 'Default bubblesheet format file error',
 3090:                 custom  => 'Custom bubblesheet format file error',
 3091:              );
 3092:     my %scantronfiles = (
 3093:         default => 'default.tab',
 3094:         custom => 'custom.tab',
 3095:     );
 3096:     foreach my $key (keys(%scantronfiles)) {
 3097:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 3098:                               .$scantronfiles{$key};
 3099:     }
 3100:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 3101:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 3102:         if (!$switchserver) {
 3103:             my $servadm = $r->dir_config('lonAdmEMail');
 3104:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 3105:             if ($configuserok eq 'ok') {
 3106:                 if ($author_ok eq 'ok') {
 3107:                     my %legacyfile = (
 3108:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 3109:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 3110:                     );
 3111:                     my %md5chk;
 3112:                     foreach my $type (keys(%legacyfile)) {
 3113:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 3114:                         chomp($md5chk{$type});
 3115:                     }
 3116:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 3117:                         foreach my $type (keys(%legacyfile)) {
 3118:                             ($scantronurls{$type},my $error) = 
 3119:                                 &legacy_scantronformat($r,$dom,$confname,
 3120:                                                  $type,$legacyfile{$type},
 3121:                                                  $scantronurls{$type},
 3122:                                                  $scantronfiles{$type});
 3123:                             if ($error ne '') {
 3124:                                 $error{$type} = $error;
 3125:                             }
 3126:                         }
 3127:                         if (keys(%error) == 0) {
 3128:                             $is_custom = 1;
 3129:                             $confhash{'scantron'}{'scantronformat'} = 
 3130:                                 $scantronurls{'custom'};
 3131:                             my $putresult = 
 3132:                                 &Apache::lonnet::put_dom('configuration',
 3133:                                                          \%confhash,$dom);
 3134:                             if ($putresult ne 'ok') {
 3135:                                 $error{'custom'} = 
 3136:                                     '<span class="LC_error">'.
 3137:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 3138:                             }
 3139:                         }
 3140:                     } else {
 3141:                         ($scantronurls{'default'},my $error) =
 3142:                             &legacy_scantronformat($r,$dom,$confname,
 3143:                                           'default',$legacyfile{'default'},
 3144:                                           $scantronurls{'default'},
 3145:                                           $scantronfiles{'default'});
 3146:                         if ($error eq '') {
 3147:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 3148:                             my $putresult =
 3149:                                 &Apache::lonnet::put_dom('configuration',
 3150:                                                          \%confhash,$dom);
 3151:                             if ($putresult ne 'ok') {
 3152:                                 $error{'default'} =
 3153:                                     '<span class="LC_error">'.
 3154:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 3155:                             }
 3156:                         } else {
 3157:                             $error{'default'} = $error;
 3158:                         }
 3159:                     }
 3160:                 }
 3161:             }
 3162:         } else {
 3163:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
 3164:         }
 3165:     }
 3166:     if (ref($settings) eq 'HASH') {
 3167:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 3168:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 3169:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 3170:                 $scantronurl = '';
 3171:             } else {
 3172:                 $scantronurl = $settings->{'scantronformat'};
 3173:             }
 3174:             $is_custom = 1;
 3175:         } else {
 3176:             $scantronurl = $scantronurls{'default'};
 3177:         }
 3178:     } else {
 3179:         if ($is_custom) {
 3180:             $scantronurl = $scantronurls{'custom'};
 3181:         } else {
 3182:             $scantronurl = $scantronurls{'default'};
 3183:         }
 3184:     }
 3185:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3186:     $datatable .= '<tr'.$css_class.'>';
 3187:     if (!$is_custom) {
 3188:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 3189:                       '<span class="LC_nobreak">';
 3190:         if ($scantronurl) {
 3191:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
 3192:                           &mt('Default bubblesheet format file').'</a>';
 3193:         } else {
 3194:             $datatable = &mt('File unavailable for display');
 3195:         }
 3196:         $datatable .= '</span></td>';
 3197:         if (keys(%error) == 0) { 
 3198:             $datatable .= '<td valign="bottom">';
 3199:             if (!$switchserver) {
 3200:                 $datatable .= &mt('Upload:').'<br />';
 3201:             }
 3202:         } else {
 3203:             my $errorstr;
 3204:             foreach my $key (sort(keys(%error))) {
 3205:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 3206:             }
 3207:             $datatable .= '<td>'.$errorstr;
 3208:         }
 3209:     } else {
 3210:         if (keys(%error) > 0) {
 3211:             my $errorstr;
 3212:             foreach my $key (sort(keys(%error))) {
 3213:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 3214:             } 
 3215:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 3216:         } elsif ($scantronurl) {
 3217:             $datatable .= '<td><span class="LC_nobreak">'.
 3218:                           '<a href="'.$scantronurl.'" target="_blank">'.
 3219:                           &mt('Custom bubblesheet format file').'</a><label>'.
 3220:                           '<input type="checkbox" name="scantronformat_del"'.
 3221:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
 3222:                           '<td><span class="LC_nobreak">&nbsp;'.
 3223:                           &mt('Replace:').'</span><br />';
 3224:         }
 3225:     }
 3226:     if (keys(%error) == 0) {
 3227:         if ($switchserver) {
 3228:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 3229:         } else {
 3230:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 3231:                          '<input type="file" name="scantronformat" /></span>';
 3232:         }
 3233:     }
 3234:     $datatable .= '</td></tr>';
 3235:     $$rowtotal ++;
 3236:     return $datatable;
 3237: }
 3238: 
 3239: sub legacy_scantronformat {
 3240:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 3241:     my ($url,$error);
 3242:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 3243:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 3244:         (my $result,$url) =
 3245:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 3246:                          '','',$newfile);
 3247:         if ($result ne 'ok') {
 3248:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
 3249:         }
 3250:     }
 3251:     return ($url,$error);
 3252: }
 3253: 
 3254: sub print_coursecategories {
 3255:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 3256:     my $datatable;
 3257:     if ($position eq 'top') {
 3258:         my $toggle_cats_crs = ' ';
 3259:         my $toggle_cats_dom = ' checked="checked" ';
 3260:         my $can_cat_crs = ' ';
 3261:         my $can_cat_dom = ' checked="checked" ';
 3262:         my $toggle_catscomm_comm = ' ';
 3263:         my $toggle_catscomm_dom = ' checked="checked" ';
 3264:         my $can_catcomm_comm = ' ';
 3265:         my $can_catcomm_dom = ' checked="checked" ';
 3266: 
 3267:         if (ref($settings) eq 'HASH') {
 3268:             if ($settings->{'togglecats'} eq 'crs') {
 3269:                 $toggle_cats_crs = $toggle_cats_dom;
 3270:                 $toggle_cats_dom = ' ';
 3271:             }
 3272:             if ($settings->{'categorize'} eq 'crs') {
 3273:                 $can_cat_crs = $can_cat_dom;
 3274:                 $can_cat_dom = ' ';
 3275:             }
 3276:             if ($settings->{'togglecatscomm'} eq 'comm') {
 3277:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
 3278:                 $toggle_catscomm_dom = ' ';
 3279:             }
 3280:             if ($settings->{'categorizecomm'} eq 'comm') {
 3281:                 $can_catcomm_comm = $can_catcomm_dom;
 3282:                 $can_catcomm_dom = ' ';
 3283:             }
 3284:         }
 3285:         my %title = &Apache::lonlocal::texthash (
 3286:                      togglecats     => 'Show/Hide a course in catalog',
 3287:                      togglecatscomm => 'Show/Hide a community in catalog',
 3288:                      categorize     => 'Assign a category to a course',
 3289:                      categorizecomm => 'Assign a category to a community',
 3290:                     );
 3291:         my %level = &Apache::lonlocal::texthash (
 3292:                      dom  => 'Set in Domain',
 3293:                      crs  => 'Set in Course',
 3294:                      comm => 'Set in Community',
 3295:                     );
 3296:         $datatable = '<tr class="LC_odd_row">'.
 3297:                   '<td>'.$title{'togglecats'}.'</td>'.
 3298:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 3299:                   '<input type="radio" name="togglecats"'.
 3300:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3301:                   '<label><input type="radio" name="togglecats"'.
 3302:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 3303:                   '</tr><tr>'.
 3304:                   '<td>'.$title{'categorize'}.'</td>'.
 3305:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 3306:                   '<label><input type="radio" name="categorize"'.
 3307:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3308:                   '<label><input type="radio" name="categorize"'.
 3309:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 3310:                   '</tr><tr class="LC_odd_row">'.
 3311:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
 3312:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 3313:                   '<input type="radio" name="togglecatscomm"'.
 3314:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3315:                   '<label><input type="radio" name="togglecatscomm"'.
 3316:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
 3317:                   '</tr><tr>'.
 3318:                   '<td>'.$title{'categorizecomm'}.'</td>'.
 3319:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 3320:                   '<label><input type="radio" name="categorizecomm"'.
 3321:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3322:                   '<label><input type="radio" name="categorizecomm"'.
 3323:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
 3324:                   '</tr>';
 3325:         $$rowtotal += 4;
 3326:     } else {
 3327:         my $css_class;
 3328:         my $itemcount = 1;
 3329:         my $cathash; 
 3330:         if (ref($settings) eq 'HASH') {
 3331:             $cathash = $settings->{'cats'};
 3332:         }
 3333:         if (ref($cathash) eq 'HASH') {
 3334:             my (@cats,@trails,%allitems,%idx,@jsarray);
 3335:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 3336:                                                    \%allitems,\%idx,\@jsarray);
 3337:             my $maxdepth = scalar(@cats);
 3338:             my $colattrib = '';
 3339:             if ($maxdepth > 2) {
 3340:                 $colattrib = ' colspan="2" ';
 3341:             }
 3342:             my @path;
 3343:             if (@cats > 0) {
 3344:                 if (ref($cats[0]) eq 'ARRAY') {
 3345:                     my $numtop = @{$cats[0]};
 3346:                     my $maxnum = $numtop;
 3347:                     my %default_names = (
 3348:                           instcode    => &mt('Official courses'),
 3349:                           communities => &mt('Communities'),
 3350:                     );
 3351: 
 3352:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
 3353:                         ($cathash->{'instcode::0'} eq '') ||
 3354:                         (!grep(/^communities$/,@{$cats[0]})) || 
 3355:                         ($cathash->{'communities::0'} eq '')) {
 3356:                         $maxnum ++;
 3357:                     }
 3358:                     my $lastidx;
 3359:                     for (my $i=0; $i<$numtop; $i++) {
 3360:                         my $parent = $cats[0][$i];
 3361:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3362:                         my $item = &escape($parent).'::0';
 3363:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 3364:                         $lastidx = $idx{$item};
 3365:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3366:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 3367:                         for (my $k=0; $k<=$maxnum; $k++) {
 3368:                             my $vpos = $k+1;
 3369:                             my $selstr;
 3370:                             if ($k == $i) {
 3371:                                 $selstr = ' selected="selected" ';
 3372:                             }
 3373:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3374:                         }
 3375:                         $datatable .= '</select></td><td>';
 3376:                         if ($parent eq 'instcode' || $parent eq 'communities') {
 3377:                             $datatable .=  '<span class="LC_nobreak">'
 3378:                                            .$default_names{$parent}.'</span>';
 3379:                             if ($parent eq 'instcode') {
 3380:                                 $datatable .= '<br /><span class="LC_nobreak">('
 3381:                                               .&mt('with institutional codes')
 3382:                                               .')</span></td><td'.$colattrib.'>';
 3383:                             } else {
 3384:                                 $datatable .= '<table><tr><td>';
 3385:                             }
 3386:                             $datatable .= '<span class="LC_nobreak">'
 3387:                                           .'<label><input type="radio" name="'
 3388:                                           .$parent.'" value="1" checked="checked" />'
 3389:                                           .&mt('Display').'</label>';
 3390:                             if ($parent eq 'instcode') {
 3391:                                 $datatable .= '&nbsp;';
 3392:                             } else {
 3393:                                 $datatable .= '</span></td></tr><tr><td>'
 3394:                                               .'<span class="LC_nobreak">';
 3395:                             }
 3396:                             $datatable .= '<label><input type="radio" name="'
 3397:                                           .$parent.'" value="0" />'
 3398:                                           .&mt('Do not display').'</label></span>';
 3399:                             if ($parent eq 'communities') {
 3400:                                 $datatable .= '</td></tr></table>';
 3401:                             }
 3402:                             $datatable .= '</td>';
 3403:                         } else {
 3404:                             $datatable .= $parent
 3405:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
 3406:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 3407:                         }
 3408:                         my $depth = 1;
 3409:                         push(@path,$parent);
 3410:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 3411:                         pop(@path);
 3412:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 3413:                         $itemcount ++;
 3414:                     }
 3415:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3416:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 3417:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 3418:                     for (my $k=0; $k<=$maxnum; $k++) {
 3419:                         my $vpos = $k+1;
 3420:                         my $selstr;
 3421:                         if ($k == $numtop) {
 3422:                             $selstr = ' selected="selected" ';
 3423:                         }
 3424:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3425:                     }
 3426:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 3427:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 3428:                                   .'</tr>'."\n";
 3429:                     $itemcount ++;
 3430:                     foreach my $default ('instcode','communities') {
 3431:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
 3432:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3433:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
 3434:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 3435:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
 3436:                             for (my $k=0; $k<=$maxnum; $k++) {
 3437:                                 my $vpos = $k+1;
 3438:                                 my $selstr;
 3439:                                 if ($k == $maxnum) {
 3440:                                     $selstr = ' selected="selected" ';
 3441:                                 }
 3442:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3443:                             }
 3444:                             $datatable .= '</select></span></td>'.
 3445:                                           '<td><span class="LC_nobreak">'.
 3446:                                           $default_names{$default}.'</span>';
 3447:                             if ($default eq 'instcode') {
 3448:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
 3449:                                               .&mt('with institutional codes').')</span>';
 3450:                             }
 3451:                             $datatable .= '</td>'
 3452:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
 3453:                                           .&mt('Display').'</label>&nbsp;'
 3454:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
 3455:                                           .&mt('Do not display').'</label></span></td></tr>';
 3456:                         }
 3457:                     }
 3458:                 }
 3459:             } else {
 3460:                 $datatable .= &initialize_categories($itemcount);
 3461:             }
 3462:         } else {
 3463:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
 3464:                           .&initialize_categories($itemcount);
 3465:         }
 3466:         $$rowtotal += $itemcount;
 3467:     }
 3468:     return $datatable;
 3469: }
 3470: 
 3471: sub print_serverstatuses {
 3472:     my ($dom,$settings,$rowtotal) = @_;
 3473:     my $datatable;
 3474:     my @pages = &serverstatus_pages();
 3475:     my (%namedaccess,%machineaccess);
 3476:     foreach my $type (@pages) {
 3477:         $namedaccess{$type} = '';
 3478:         $machineaccess{$type}= '';
 3479:     }
 3480:     if (ref($settings) eq 'HASH') {
 3481:         foreach my $type (@pages) {
 3482:             if (exists($settings->{$type})) {
 3483:                 if (ref($settings->{$type}) eq 'HASH') {
 3484:                     foreach my $key (keys(%{$settings->{$type}})) {
 3485:                         if ($key eq 'namedusers') {
 3486:                             $namedaccess{$type} = $settings->{$type}->{$key};
 3487:                         } elsif ($key eq 'machines') {
 3488:                             $machineaccess{$type} = $settings->{$type}->{$key};
 3489:                         }
 3490:                     }
 3491:                 }
 3492:             }
 3493:         }
 3494:     }
 3495:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 3496:     my $rownum = 0;
 3497:     my $css_class;
 3498:     foreach my $type (@pages) {
 3499:         $rownum ++;
 3500:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 3501:         $datatable .= '<tr'.$css_class.'>'.
 3502:                       '<td><span class="LC_nobreak">'.
 3503:                       $titles->{$type}.'</span></td>'.
 3504:                       '<td class="LC_left_item">'.
 3505:                       '<input type="text" name="'.$type.'_namedusers" '.
 3506:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 3507:                       '<td class="LC_right_item">'.
 3508:                       '<span class="LC_nobreak">'.
 3509:                       '<input type="text" name="'.$type.'_machines" '.
 3510:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 3511:                       '</td></tr>'."\n";
 3512:     }
 3513:     $$rowtotal += $rownum;
 3514:     return $datatable;
 3515: }
 3516: 
 3517: sub serverstatus_pages {
 3518:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 3519:             'clusterstatus','metadata_keywords','metadata_harvest',
 3520:             'takeoffline','takeonline','showenv','toggledebug');
 3521: }
 3522: 
 3523: sub coursecategories_javascript {
 3524:     my ($settings) = @_;
 3525:     my ($output,$jstext,$cathash);
 3526:     if (ref($settings) eq 'HASH') {
 3527:         $cathash = $settings->{'cats'};
 3528:     }
 3529:     if (ref($cathash) eq 'HASH') {
 3530:         my (@cats,@jsarray,%idx);
 3531:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 3532:         if (@jsarray > 0) {
 3533:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 3534:             for (my $i=0; $i<@jsarray; $i++) {
 3535:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 3536:                     my $catstr = join('","',@{$jsarray[$i]});
 3537:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 3538:                 }
 3539:             }
 3540:         }
 3541:     } else {
 3542:         $jstext  = '    var categories = Array(1);'."\n".
 3543:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 3544:     }
 3545:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
 3546:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
 3547:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
 3548:     $output = <<"ENDSCRIPT";
 3549: <script type="text/javascript">
 3550: // <![CDATA[
 3551: function reorderCats(form,parent,item,idx) {
 3552:     var changedVal;
 3553: $jstext
 3554:     var newpos = 'addcategory_pos';
 3555:     var current = new Array;
 3556:     if (parent == '') {
 3557:         var has_instcode = 0;
 3558:         var maxtop = categories[idx].length;
 3559:         for (var j=0; j<maxtop; j++) {
 3560:             if (categories[idx][j] == 'instcode::0') {
 3561:                 has_instcode == 1;
 3562:             }
 3563:         }
 3564:         if (has_instcode == 0) {
 3565:             categories[idx][maxtop] = 'instcode_pos';
 3566:         }
 3567:     } else {
 3568:         newpos += '_'+parent;
 3569:     }
 3570:     var maxh = 1 + categories[idx].length;
 3571:     var current = new Array;
 3572:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 3573:     if (item == newpos) {
 3574:         changedVal = newitemVal;
 3575:     } else {
 3576:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 3577:         current[newitemVal] = newpos;
 3578:     }
 3579:     for (var i=0; i<categories[idx].length; i++) {
 3580:         var elementName = categories[idx][i];
 3581:         if (elementName != item) {
 3582:             if (form.elements[elementName]) {
 3583:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 3584:                 current[currVal] = elementName;
 3585:             }
 3586:         }
 3587:     }
 3588:     var oldVal;
 3589:     for (var j=0; j<maxh; j++) {
 3590:         if (current[j] == undefined) {
 3591:             oldVal = j;
 3592:         }
 3593:     }
 3594:     if (oldVal < changedVal) {
 3595:         for (var k=oldVal+1; k<=changedVal ; k++) {
 3596:            var elementName = current[k];
 3597:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 3598:         }
 3599:     } else {
 3600:         for (var k=changedVal; k<oldVal; k++) {
 3601:             var elementName = current[k];
 3602:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 3603:         }
 3604:     }
 3605:     return;
 3606: }
 3607: 
 3608: function categoryCheck(form) {
 3609:     if (form.elements['addcategory_name'].value == 'instcode') {
 3610:         alert('$instcode_reserved\\n$choose_again');
 3611:         return false;
 3612:     }
 3613:     if (form.elements['addcategory_name'].value == 'communities') {
 3614:         alert('$communities_reserved\\n$choose_again');
 3615:         return false;
 3616:     }
 3617:     return true;
 3618: }
 3619: 
 3620: // ]]>
 3621: </script>
 3622: 
 3623: ENDSCRIPT
 3624:     return $output;
 3625: }
 3626: 
 3627: sub initialize_categories {
 3628:     my ($itemcount) = @_;
 3629:     my ($datatable,$css_class,$chgstr);
 3630:     my %default_names = (
 3631:                       instcode    => 'Official courses (with institutional codes)',
 3632:                       communities => 'Communities',
 3633:                         );
 3634:     my $select0 = ' selected="selected"';
 3635:     my $select1 = '';
 3636:     foreach my $default ('instcode','communities') {
 3637:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3638:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
 3639:         if ($default eq 'communities') {
 3640:             $select1 = $select0;
 3641:             $select0 = '';
 3642:         }
 3643:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3644:                      .'<select name="'.$default.'_pos">'
 3645:                      .'<option value="0"'.$select0.'>1</option>'
 3646:                      .'<option value="1"'.$select1.'>2</option>'
 3647:                      .'<option value="2">3</option></select>&nbsp;'
 3648:                      .$default_names{$default}
 3649:                      .'</span></td><td><span class="LC_nobreak">'
 3650:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
 3651:                      .&mt('Display').'</label>&nbsp;<label>'
 3652:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
 3653:                  .'</label></span></td></tr>';
 3654:         $itemcount ++;
 3655:     }
 3656:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3657:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 3658:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3659:                   .'<select name="addcategory_pos"'.$chgstr.'>'
 3660:                   .'<option value="0">1</option>'
 3661:                   .'<option value="1">2</option>'
 3662:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
 3663:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 3664:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 3665:     return $datatable;
 3666: }
 3667: 
 3668: sub build_category_rows {
 3669:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 3670:     my ($text,$name,$item,$chgstr);
 3671:     if (ref($cats) eq 'ARRAY') {
 3672:         my $maxdepth = scalar(@{$cats});
 3673:         if (ref($cats->[$depth]) eq 'HASH') {
 3674:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 3675:                 my $numchildren = @{$cats->[$depth]{$parent}};
 3676:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3677:                 $text .= '<td><table class="LC_datatable">';
 3678:                 my ($idxnum,$parent_name,$parent_item);
 3679:                 my $higher = $depth - 1;
 3680:                 if ($higher == 0) {
 3681:                     $parent_name = &escape($parent).'::'.$higher;
 3682:                 } else {
 3683:                     if (ref($path) eq 'ARRAY') {
 3684:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 3685:                     }
 3686:                 }
 3687:                 $parent_item = 'addcategory_pos_'.$parent_name;
 3688:                 for (my $j=0; $j<=$numchildren; $j++) {
 3689:                     if ($j < $numchildren) {
 3690:                         $name = $cats->[$depth]{$parent}[$j];
 3691:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 3692:                         $idxnum = $idx->{$item};
 3693:                     } else {
 3694:                         $name = $parent_name;
 3695:                         $item = $parent_item;
 3696:                     }
 3697:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 3698:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 3699:                     for (my $i=0; $i<=$numchildren; $i++) {
 3700:                         my $vpos = $i+1;
 3701:                         my $selstr;
 3702:                         if ($j == $i) {
 3703:                             $selstr = ' selected="selected" ';
 3704:                         }
 3705:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 3706:                     }
 3707:                     $text .= '</select>&nbsp;';
 3708:                     if ($j < $numchildren) {
 3709:                         my $deeper = $depth+1;
 3710:                         $text .= $name.'&nbsp;'
 3711:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 3712:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 3713:                         if(ref($path) eq 'ARRAY') {
 3714:                             push(@{$path},$name);
 3715:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 3716:                             pop(@{$path});
 3717:                         }
 3718:                     } else {
 3719:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 3720:                         if ($j == $numchildren) {
 3721:                             $text .= $name;
 3722:                         } else {
 3723:                             $text .= $item;
 3724:                         }
 3725:                         $text .= '" value="" />';
 3726:                     }
 3727:                     $text .= '</td></tr>';
 3728:                 }
 3729:                 $text .= '</table></td>';
 3730:             } else {
 3731:                 my $higher = $depth-1;
 3732:                 if ($higher == 0) {
 3733:                     $name = &escape($parent).'::'.$higher;
 3734:                 } else {
 3735:                     if (ref($path) eq 'ARRAY') {
 3736:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 3737:                     }
 3738:                 }
 3739:                 my $colspan;
 3740:                 if ($parent ne 'instcode') {
 3741:                     $colspan = $maxdepth - $depth - 1;
 3742:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 3743:                 }
 3744:             }
 3745:         }
 3746:     }
 3747:     return $text;
 3748: }
 3749: 
 3750: sub modifiable_userdata_row {
 3751:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
 3752:     my $rolename;
 3753:     if ($context eq 'selfcreate') {
 3754:         if (ref($usertypes) eq 'HASH') {
 3755:             $rolename = $usertypes->{$role};
 3756:         } else {
 3757:             $rolename = $role;
 3758:         }
 3759:     } else {
 3760:         if ($role eq 'cr') {
 3761:             $rolename = &mt('Custom role');
 3762:         } else {
 3763:             $rolename = &Apache::lonnet::plaintext($role);
 3764:         }
 3765:     }
 3766:     my @fields = ('lastname','firstname','middlename','generation',
 3767:                   'permanentemail','id');
 3768:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 3769:     my $output;
 3770:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 3771:     $output = '<tr '.$css_class.'>'.
 3772:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 3773:               '<td class="LC_left_item" colspan="2"><table>';
 3774:     my $rem;
 3775:     my %checks;
 3776:     if (ref($settings) eq 'HASH') {
 3777:         if (ref($settings->{$context}) eq 'HASH') {
 3778:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 3779:                 foreach my $field (@fields) {
 3780:                     if ($settings->{$context}->{$role}->{$field}) {
 3781:                         $checks{$field} = ' checked="checked" ';
 3782:                     }
 3783:                 }
 3784:             }
 3785:         }
 3786:     }
 3787:     for (my $i=0; $i<@fields; $i++) {
 3788:         my $rem = $i%($numinrow);
 3789:         if ($rem == 0) {
 3790:             if ($i > 0) {
 3791:                 $output .= '</tr>';
 3792:             }
 3793:             $output .= '<tr>';
 3794:         }
 3795:         my $check = ' ';
 3796:         if (exists($checks{$fields[$i]})) {
 3797:             $check = $checks{$fields[$i]}
 3798:         } else {
 3799:             if ($role eq 'st') {
 3800:                 if (ref($settings) ne 'HASH') {
 3801:                     $check = ' checked="checked" '; 
 3802:                 }
 3803:             }
 3804:         }
 3805:         $output .= '<td class="LC_left_item">'.
 3806:                    '<span class="LC_nobreak"><label>'.
 3807:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 3808:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 3809:                    '</label></span></td>';
 3810:         $rem = @fields%($numinrow);
 3811:     }
 3812:     my $colsleft = $numinrow - $rem;
 3813:     if ($colsleft > 1 ) {
 3814:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3815:                    '&nbsp;</td>';
 3816:     } elsif ($colsleft == 1) {
 3817:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 3818:     }
 3819:     $output .= '</tr></table></td></tr>';
 3820:     return $output;
 3821: }
 3822: 
 3823: sub insttypes_row {
 3824:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
 3825:     my %lt = &Apache::lonlocal::texthash (
 3826:                       cansearch => 'Users allowed to search',
 3827:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
 3828:                       lockablenames => 'User preference to lock name',
 3829:              );
 3830:     my $showdom;
 3831:     if ($context eq 'cansearch') {
 3832:         $showdom = ' ('.$dom.')';
 3833:     }
 3834:     my $output =  '<tr class="LC_odd_row">'.
 3835:                   '<td>'.$lt{$context}.$showdom.
 3836:                   '</td><td class="LC_left_item" colspan="2"><table>';
 3837:     my $rem;
 3838:     if (ref($types) eq 'ARRAY') {
 3839:         for (my $i=0; $i<@{$types}; $i++) {
 3840:             if (defined($usertypes->{$types->[$i]})) {
 3841:                 my $rem = $i%($numinrow);
 3842:                 if ($rem == 0) {
 3843:                     if ($i > 0) {
 3844:                         $output .= '</tr>';
 3845:                     }
 3846:                     $output .= '<tr>';
 3847:                 }
 3848:                 my $check = ' ';
 3849:                 if (ref($settings) eq 'HASH') {
 3850:                     if (ref($settings->{$context}) eq 'ARRAY') {
 3851:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
 3852:                             $check = ' checked="checked" ';
 3853:                         }
 3854:                     } elsif ($context eq 'statustocreate') {
 3855:                         $check = ' checked="checked" ';
 3856:                     }
 3857:                 }
 3858:                 $output .= '<td class="LC_left_item">'.
 3859:                            '<span class="LC_nobreak"><label>'.
 3860:                            '<input type="checkbox" name="'.$context.'" '.
 3861:                            'value="'.$types->[$i].'"'.$check.'/>'.
 3862:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 3863:             }
 3864:         }
 3865:         $rem = @{$types}%($numinrow);
 3866:     }
 3867:     my $colsleft = $numinrow - $rem;
 3868:     if (($rem == 0) && (@{$types} > 0)) {
 3869:         $output .= '<tr>';
 3870:     }
 3871:     if ($colsleft > 1) {
 3872:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 3873:     } else {
 3874:         $output .= '<td class="LC_left_item">';
 3875:     }
 3876:     my $defcheck = ' ';
 3877:     if (ref($settings) eq 'HASH') {  
 3878:         if (ref($settings->{$context}) eq 'ARRAY') {
 3879:             if (grep(/^default$/,@{$settings->{$context}})) {
 3880:                 $defcheck = ' checked="checked" ';
 3881:             }
 3882:         } elsif ($context eq 'statustocreate') {
 3883:             $defcheck = ' checked="checked" ';
 3884:         }
 3885:     }
 3886:     $output .= '<span class="LC_nobreak"><label>'.
 3887:                '<input type="checkbox" name="'.$context.'" '.
 3888:                'value="default"'.$defcheck.'/>'.
 3889:                $othertitle.'</label></span></td>'.
 3890:                '</tr></table></td></tr>';
 3891:     return $output;
 3892: }
 3893: 
 3894: sub sorted_searchtitles {
 3895:     my %searchtitles = &Apache::lonlocal::texthash(
 3896:                          'uname' => 'username',
 3897:                          'lastname' => 'last name',
 3898:                          'lastfirst' => 'last name, first name',
 3899:                      );
 3900:     my @titleorder = ('uname','lastname','lastfirst');
 3901:     return (\%searchtitles,\@titleorder);
 3902: }
 3903: 
 3904: sub sorted_searchtypes {
 3905:     my %srchtypes_desc = (
 3906:                            exact    => 'is exact match',
 3907:                            contains => 'contains ..',
 3908:                            begins   => 'begins with ..',
 3909:                          );
 3910:     my @srchtypeorder = ('exact','begins','contains');
 3911:     return (\%srchtypes_desc,\@srchtypeorder);
 3912: }
 3913: 
 3914: sub usertype_update_row {
 3915:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 3916:     my $datatable;
 3917:     my $numinrow = 4;
 3918:     foreach my $type (@{$types}) {
 3919:         if (defined($usertypes->{$type})) {
 3920:             $$rownums ++;
 3921:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 3922:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 3923:                           '</td><td class="LC_left_item"><table>';
 3924:             for (my $i=0; $i<@{$fields}; $i++) {
 3925:                 my $rem = $i%($numinrow);
 3926:                 if ($rem == 0) {
 3927:                     if ($i > 0) {
 3928:                         $datatable .= '</tr>';
 3929:                     }
 3930:                     $datatable .= '<tr>';
 3931:                 }
 3932:                 my $check = ' ';
 3933:                 if (ref($settings) eq 'HASH') {
 3934:                     if (ref($settings->{'fields'}) eq 'HASH') {
 3935:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 3936:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 3937:                                 $check = ' checked="checked" ';
 3938:                             }
 3939:                         }
 3940:                     }
 3941:                 }
 3942: 
 3943:                 if ($i == @{$fields}-1) {
 3944:                     my $colsleft = $numinrow - $rem;
 3945:                     if ($colsleft > 1) {
 3946:                         $datatable .= '<td colspan="'.$colsleft.'">';
 3947:                     } else {
 3948:                         $datatable .= '<td>';
 3949:                     }
 3950:                 } else {
 3951:                     $datatable .= '<td>';
 3952:                 }
 3953:                 $datatable .= '<span class="LC_nobreak"><label>'.
 3954:                               '<input type="checkbox" name="updateable_'.$type.
 3955:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 3956:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 3957:             }
 3958:             $datatable .= '</tr></table></td></tr>';
 3959:         }
 3960:     }
 3961:     return $datatable;
 3962: }
 3963: 
 3964: sub modify_login {
 3965:     my ($r,$dom,$confname,%domconfig) = @_;
 3966:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
 3967:     my %title = ( coursecatalog => 'Display course catalog',
 3968:                   adminmail => 'Display administrator E-mail address',
 3969:                   newuser => 'Link for visitors to create a user account',
 3970:                   loginheader => 'Log-in box header');
 3971:     my @offon = ('off','on');
 3972:     my %curr_loginvia;
 3973:     if (ref($domconfig{login}) eq 'HASH') {
 3974:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
 3975:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
 3976:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
 3977:             }
 3978:         }
 3979:     }
 3980:     my %loginhash;
 3981:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 3982:                                            \%domconfig,\%loginhash);
 3983:     my @toggles = ('coursecatalog','adminmail','newuser');
 3984:     foreach my $item (@toggles) {
 3985:         $loginhash{login}{$item} = $env{'form.'.$item};
 3986:     }
 3987:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 3988:     if (ref($colchanges{'login'}) eq 'HASH') {  
 3989:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 3990:                                          \%loginhash);
 3991:     }
 3992: 
 3993:     my %servers = &dom_servers($dom);
 3994:     my @loginvia_attribs = ('serverpath','custompath','exempt');
 3995:     if (keys(%servers) > 1) {
 3996:         foreach my $lonhost (keys(%servers)) {
 3997:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
 3998:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
 3999:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
 4000:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
 4001:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
 4002:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4003:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4004:                         $changes{'loginvia'}{$lonhost} = 1;
 4005:                     } else {
 4006:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
 4007:                         $changes{'loginvia'}{$lonhost} = 1;
 4008:                     }
 4009:                 } else {
 4010:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4011:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4012:                         $changes{'loginvia'}{$lonhost} = 1;
 4013:                     }
 4014:                 }
 4015:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
 4016:                     foreach my $item (@loginvia_attribs) {
 4017:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
 4018:                     }
 4019:                 } else {
 4020:                     foreach my $item (@loginvia_attribs) {
 4021:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 4022:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 4023:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
 4024:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 4025:                                 $new = '/';
 4026:                             }
 4027:                         }
 4028:                         if (($item eq 'custompath') && 
 4029:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 4030:                             $new = '';
 4031:                         }
 4032:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
 4033:                             $changes{'loginvia'}{$lonhost} = 1;
 4034:                         }
 4035:                         if ($item eq 'exempt') {
 4036:                             $new =~ s/^\s+//;
 4037:                             $new =~ s/\s+$//;
 4038:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
 4039:                             my @okips;
 4040:                             foreach my $ip (@poss_ips) {
 4041:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
 4042:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
 4043:                                         push(@okips,$ip); 
 4044:                                     }
 4045:                                 }
 4046:                             }
 4047:                             if (@okips > 0) {
 4048:                                 $new = join(',',@okips); 
 4049:                             } else {
 4050:                                 $new = ''; 
 4051:                             }
 4052:                         }
 4053: 
 4054:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 4055:                     }
 4056:                 }
 4057:             } else {
 4058:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4059:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4060:                     $changes{'loginvia'}{$lonhost} = 1;
 4061:                     foreach my $item (@loginvia_attribs) {
 4062:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 4063:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 4064:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 4065:                                 $new = '/';
 4066:                             }
 4067:                         }
 4068:                         if (($item eq 'custompath') && 
 4069:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 4070:                             $new = '';
 4071:                         }
 4072:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 4073:                     }
 4074:                 }
 4075:             }
 4076:         }
 4077:     }
 4078: 
 4079:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 4080:                                              $dom);
 4081:     if ($putresult eq 'ok') {
 4082:         my @toggles = ('coursecatalog','adminmail','newuser');
 4083:         my %defaultchecked = (
 4084:                     'coursecatalog' => 'on',
 4085:                     'adminmail'     => 'off',
 4086:                     'newuser'       => 'off',
 4087:         );
 4088:         if (ref($domconfig{'login'}) eq 'HASH') {
 4089:             foreach my $item (@toggles) {
 4090:                 if ($defaultchecked{$item} eq 'on') { 
 4091:                     if (($domconfig{'login'}{$item} eq '0') &&
 4092:                         ($env{'form.'.$item} eq '1')) {
 4093:                         $changes{$item} = 1;
 4094:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 4095:                               $domconfig{'login'}{$item} eq '1') &&
 4096:                              ($env{'form.'.$item} eq '0')) {
 4097:                         $changes{$item} = 1;
 4098:                     }
 4099:                 } elsif ($defaultchecked{$item} eq 'off') {
 4100:                     if (($domconfig{'login'}{$item} eq '1') &&
 4101:                         ($env{'form.'.$item} eq '0')) {
 4102:                         $changes{$item} = 1;
 4103:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 4104:                               $domconfig{'login'}{$item} eq '0') &&
 4105:                              ($env{'form.'.$item} eq '1')) {
 4106:                         $changes{$item} = 1;
 4107:                     }
 4108:                 }
 4109:             }
 4110:         }
 4111:         if (keys(%changes) > 0 || $colchgtext) {
 4112:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 4113:             $resulttext = &mt('Changes made:').'<ul>';
 4114:             foreach my $item (sort(keys(%changes))) {
 4115:                 if ($item eq 'loginvia') {
 4116:                     if (ref($changes{$item}) eq 'HASH') {
 4117:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
 4118:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 4119:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
 4120:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
 4121:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
 4122:                                     $protocol = 'http' if ($protocol ne 'https');
 4123:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
 4124: 
 4125:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
 4126:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
 4127:                                     } else {
 4128:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
 4129:                                     }
 4130:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
 4131:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
 4132:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
 4133:                                     }
 4134:                                     $resulttext .= '</li>';
 4135:                                 } else {
 4136:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
 4137:                                 }
 4138:                             } else {
 4139:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
 4140:                             }
 4141:                         }
 4142:                         $resulttext .= '</ul></li>';
 4143:                     }
 4144:                 } else {
 4145:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 4146:                 }
 4147:             }
 4148:             $resulttext .= $colchgtext.'</ul>';
 4149:         } else {
 4150:             $resulttext = &mt('No changes made to log-in page settings');
 4151:         }
 4152:     } else {
 4153:         $resulttext = '<span class="LC_error">'.
 4154: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 4155:     }
 4156:     if ($errors) {
 4157:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 4158:                        $errors.'</ul>';
 4159:     }
 4160:     return $resulttext;
 4161: }
 4162: 
 4163: sub color_font_choices {
 4164:     my %choices =
 4165:         &Apache::lonlocal::texthash (
 4166:             img => "Header",
 4167:             bgs => "Background colors",
 4168:             links => "Link colors",
 4169:             images => "Images",
 4170:             font => "Font color",
 4171:             fontmenu => "Font Menu",
 4172:             pgbg => "Page",
 4173:             tabbg => "Header",
 4174:             sidebg => "Border",
 4175:             link => "Link",
 4176:             alink => "Active link",
 4177:             vlink => "Visited link",
 4178:         );
 4179:     return %choices;
 4180: }
 4181: 
 4182: sub modify_rolecolors {
 4183:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 4184:     my ($resulttext,%rolehash);
 4185:     $rolehash{'rolecolors'} = {};
 4186:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 4187:         if ($domconfig{'rolecolors'} eq '') {
 4188:             $domconfig{'rolecolors'} = {};
 4189:         }
 4190:     }
 4191:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 4192:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 4193:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 4194:                                              $dom);
 4195:     if ($putresult eq 'ok') {
 4196:         if (keys(%changes) > 0) {
 4197:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 4198:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 4199:                                              $rolehash{'rolecolors'});
 4200:         } else {
 4201:             $resulttext = &mt('No changes made to default color schemes');
 4202:         }
 4203:     } else {
 4204:         $resulttext = '<span class="LC_error">'.
 4205: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 4206:     }
 4207:     if ($errors) {
 4208:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 4209:                        $errors.'</ul>';
 4210:     }
 4211:     return $resulttext;
 4212: }
 4213: 
 4214: sub modify_colors {
 4215:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 4216:     my (%changes,%choices);
 4217:     my @bgs;
 4218:     my @links = ('link','alink','vlink');
 4219:     my @logintext;
 4220:     my @images;
 4221:     my $servadm = $r->dir_config('lonAdmEMail');
 4222:     my $errors;
 4223:     foreach my $role (@{$roles}) {
 4224:         if ($role eq 'login') {
 4225:             %choices = &login_choices();
 4226:             @logintext = ('textcol','bgcol');
 4227:         } else {
 4228:             %choices = &color_font_choices();
 4229:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
 4230:         }
 4231:         if ($role eq 'login') {
 4232:             @images = ('img','logo','domlogo','login');
 4233:             @bgs = ('pgbg','mainbg','sidebg');
 4234:         } else {
 4235:             @images = ('img');
 4236:             @bgs = ('pgbg','tabbg','sidebg'); 
 4237:         }
 4238:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 4239:         foreach my $item (@bgs,@links,@logintext) {
 4240:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 4241:         }
 4242:         my ($configuserok,$author_ok,$switchserver) = 
 4243:             &config_check($dom,$confname,$servadm);
 4244:         my ($width,$height) = &thumb_dimensions();
 4245:         if (ref($domconfig->{$role}) ne 'HASH') {
 4246:             $domconfig->{$role} = {};
 4247:         }
 4248:         foreach my $img (@images) {
 4249:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 4250:                 if (defined($env{'form.login_showlogo_'.$img})) {
 4251:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 4252:                 } else { 
 4253:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 4254:                 }
 4255:             } 
 4256: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 4257: 		 && !defined($domconfig->{$role}{$img})
 4258: 		 && !$env{'form.'.$role.'_del_'.$img}
 4259: 		 && $env{'form.'.$role.'_import_'.$img}) {
 4260: 		# import the old configured image from the .tab setting
 4261: 		# if they haven't provided a new one 
 4262: 		$domconfig->{$role}{$img} = 
 4263: 		    $env{'form.'.$role.'_import_'.$img};
 4264: 	    }
 4265:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 4266:                 my $error;
 4267:                 if ($configuserok eq 'ok') {
 4268:                     if ($switchserver) {
 4269:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 4270:                     } else {
 4271:                         if ($author_ok eq 'ok') {
 4272:                             my ($result,$logourl) = 
 4273:                                 &publishlogo($r,'upload',$role.'_'.$img,
 4274:                                            $dom,$confname,$img,$width,$height);
 4275:                             if ($result eq 'ok') {
 4276:                                 $confhash->{$role}{$img} = $logourl;
 4277:                                 $changes{$role}{'images'}{$img} = 1;
 4278:                             } else {
 4279:                                 $error = &mt("Upload of [_1] image for $role page(s) failed because an error occurred publishing the file in RES space. Error was: [_2].",$choices{img},$result);
 4280:                             }
 4281:                         } else {
 4282:                             $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
 4283:                         }
 4284:                     }
 4285:                 } else {
 4286:                     $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
 4287:                 }
 4288:                 if ($error) {
 4289:                     &Apache::lonnet::logthis($error);
 4290:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 4291:                 }
 4292:             } elsif ($domconfig->{$role}{$img} ne '') {
 4293:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 4294:                     my $error;
 4295:                     if ($configuserok eq 'ok') {
 4296: # is confname an author?
 4297:                         if ($switchserver eq '') {
 4298:                             if ($author_ok eq 'ok') {
 4299:                                 my ($result,$logourl) = 
 4300:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 4301:                                             $dom,$confname,$img,$width,$height);
 4302:                                 if ($result eq 'ok') {
 4303:                                     $confhash->{$role}{$img} = $logourl;
 4304: 				    $changes{$role}{'images'}{$img} = 1;
 4305:                                 }
 4306:                             }
 4307:                         }
 4308:                     }
 4309:                 }
 4310:             }
 4311:         }
 4312:         if (ref($domconfig) eq 'HASH') {
 4313:             if (ref($domconfig->{$role}) eq 'HASH') {
 4314:                 foreach my $img (@images) {
 4315:                     if ($domconfig->{$role}{$img} ne '') {
 4316:                         if ($env{'form.'.$role.'_del_'.$img}) {
 4317:                             $confhash->{$role}{$img} = '';
 4318:                             $changes{$role}{'images'}{$img} = 1;
 4319:                         } else {
 4320:                             if ($confhash->{$role}{$img} eq '') {
 4321:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 4322:                             }
 4323:                         }
 4324:                     } else {
 4325:                         if ($env{'form.'.$role.'_del_'.$img}) {
 4326:                             $confhash->{$role}{$img} = '';
 4327:                             $changes{$role}{'images'}{$img} = 1;
 4328:                         } 
 4329:                     }
 4330:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 4331:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 4332:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 4333:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 4334:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 4335:                             }
 4336:                         } else {
 4337:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 4338:                                 $changes{$role}{'showlogo'}{$img} = 1;
 4339:                             }
 4340:                         }
 4341:                     }
 4342:                 }
 4343:                 if ($domconfig->{$role}{'font'} ne '') {
 4344:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 4345:                         $changes{$role}{'font'} = 1;
 4346:                     }
 4347:                 } else {
 4348:                     if ($confhash->{$role}{'font'}) {
 4349:                         $changes{$role}{'font'} = 1;
 4350:                     }
 4351:                 }
 4352:                 if ($role ne 'login') {
 4353:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
 4354:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
 4355:                             $changes{$role}{'fontmenu'} = 1;
 4356:                         }
 4357:                     } else {
 4358:                         if ($confhash->{$role}{'fontmenu'}) {
 4359:                             $changes{$role}{'fontmenu'} = 1;
 4360:                         }
 4361:                     }
 4362:                 }
 4363:                 foreach my $item (@bgs) {
 4364:                     if ($domconfig->{$role}{$item} ne '') {
 4365:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4366:                             $changes{$role}{'bgs'}{$item} = 1;
 4367:                         } 
 4368:                     } else {
 4369:                         if ($confhash->{$role}{$item}) {
 4370:                             $changes{$role}{'bgs'}{$item} = 1;
 4371:                         }
 4372:                     }
 4373:                 }
 4374:                 foreach my $item (@links) {
 4375:                     if ($domconfig->{$role}{$item} ne '') {
 4376:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4377:                             $changes{$role}{'links'}{$item} = 1;
 4378:                         }
 4379:                     } else {
 4380:                         if ($confhash->{$role}{$item}) {
 4381:                             $changes{$role}{'links'}{$item} = 1;
 4382:                         }
 4383:                     }
 4384:                 }
 4385:                 foreach my $item (@logintext) {
 4386:                     if ($domconfig->{$role}{$item} ne '') {
 4387:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4388:                             $changes{$role}{'logintext'}{$item} = 1;
 4389:                         }
 4390:                     } else {
 4391:                         if ($confhash->{$role}{$item}) {
 4392:                             $changes{$role}{'logintext'}{$item} = 1;
 4393:                         }
 4394:                     }
 4395:                 }
 4396:             } else {
 4397:                 &default_change_checker($role,\@images,\@links,\@bgs,
 4398:                                         \@logintext,$confhash,\%changes); 
 4399:             }
 4400:         } else {
 4401:             &default_change_checker($role,\@images,\@links,\@bgs,
 4402:                                     \@logintext,$confhash,\%changes); 
 4403:         }
 4404:     }
 4405:     return ($errors,%changes);
 4406: }
 4407: 
 4408: sub config_check {
 4409:     my ($dom,$confname,$servadm) = @_;
 4410:     my ($configuserok,$author_ok,$switchserver,%currroles);
 4411:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 4412:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 4413:                                                    $confname,$servadm);
 4414:     if ($configuserok eq 'ok') {
 4415:         $switchserver = &check_switchserver($dom,$confname);
 4416:         if ($switchserver eq '') {
 4417:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 4418:         }
 4419:     }
 4420:     return ($configuserok,$author_ok,$switchserver);
 4421: }
 4422: 
 4423: sub default_change_checker {
 4424:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 4425:     foreach my $item (@{$links}) {
 4426:         if ($confhash->{$role}{$item}) {
 4427:             $changes->{$role}{'links'}{$item} = 1;
 4428:         }
 4429:     }
 4430:     foreach my $item (@{$bgs}) {
 4431:         if ($confhash->{$role}{$item}) {
 4432:             $changes->{$role}{'bgs'}{$item} = 1;
 4433:         }
 4434:     }
 4435:     foreach my $item (@{$logintext}) {
 4436:         if ($confhash->{$role}{$item}) {
 4437:             $changes->{$role}{'logintext'}{$item} = 1;
 4438:         }
 4439:     }
 4440:     foreach my $img (@{$images}) {
 4441:         if ($env{'form.'.$role.'_del_'.$img}) {
 4442:             $confhash->{$role}{$img} = '';
 4443:             $changes->{$role}{'images'}{$img} = 1;
 4444:         }
 4445:         if ($role eq 'login') {
 4446:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 4447:                 $changes->{$role}{'showlogo'}{$img} = 1;
 4448:             }
 4449:         }
 4450:     }
 4451:     if ($confhash->{$role}{'font'}) {
 4452:         $changes->{$role}{'font'} = 1;
 4453:     }
 4454: }
 4455: 
 4456: sub display_colorchgs {
 4457:     my ($dom,$changes,$roles,$confhash) = @_;
 4458:     my (%choices,$resulttext);
 4459:     if (!grep(/^login$/,@{$roles})) {
 4460:         $resulttext = &mt('Changes made:').'<br />';
 4461:     }
 4462:     foreach my $role (@{$roles}) {
 4463:         if ($role eq 'login') {
 4464:             %choices = &login_choices();
 4465:         } else {
 4466:             %choices = &color_font_choices();
 4467:         }
 4468:         if (ref($changes->{$role}) eq 'HASH') {
 4469:             if ($role ne 'login') {
 4470:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 4471:             }
 4472:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 4473:                 if ($role ne 'login') {
 4474:                     $resulttext .= '<ul>';
 4475:                 }
 4476:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 4477:                     if ($role ne 'login') {
 4478:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 4479:                     }
 4480:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 4481:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 4482:                             if ($confhash->{$role}{$key}{$item}) {
 4483:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 4484:                             } else {
 4485:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 4486:                             }
 4487:                         } elsif ($confhash->{$role}{$item} eq '') {
 4488:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 4489:                         } else {
 4490:                             my $newitem = $confhash->{$role}{$item};
 4491:                             if ($key eq 'images') {
 4492:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 4493:                             }
 4494:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 4495:                         }
 4496:                     }
 4497:                     if ($role ne 'login') {
 4498:                         $resulttext .= '</ul></li>';
 4499:                     }
 4500:                 } else {
 4501:                     if ($confhash->{$role}{$key} eq '') {
 4502:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 4503:                     } else {
 4504:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 4505:                     }
 4506:                 }
 4507:                 if ($role ne 'login') {
 4508:                     $resulttext .= '</ul>';
 4509:                 }
 4510:             }
 4511:         }
 4512:     }
 4513:     return $resulttext;
 4514: }
 4515: 
 4516: sub thumb_dimensions {
 4517:     return ('200','50');
 4518: }
 4519: 
 4520: sub check_dimensions {
 4521:     my ($inputfile) = @_;
 4522:     my ($fullwidth,$fullheight);
 4523:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 4524:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 4525:             my $imageinfo = <PIPE>;
 4526:             if (!close(PIPE)) {
 4527:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 4528:             }
 4529:             chomp($imageinfo);
 4530:             my ($fullsize) = 
 4531:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 4532:             if ($fullsize) {
 4533:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 4534:             }
 4535:         }
 4536:     }
 4537:     return ($fullwidth,$fullheight);
 4538: }
 4539: 
 4540: sub check_configuser {
 4541:     my ($uhome,$dom,$confname,$servadm) = @_;
 4542:     my ($configuserok,%currroles);
 4543:     if ($uhome eq 'no_host') {
 4544:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 4545:         my $configpass = &LONCAPA::Enrollment::create_password();
 4546:         $configuserok = 
 4547:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 4548:                              $configpass,'','','','','',undef,$servadm);
 4549:     } else {
 4550:         $configuserok = 'ok';
 4551:         %currroles = 
 4552:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 4553:     }
 4554:     return ($configuserok,%currroles);
 4555: }
 4556: 
 4557: sub check_authorstatus {
 4558:     my ($dom,$confname,%currroles) = @_;
 4559:     my $author_ok;
 4560:     if (!$currroles{':'.$dom.':au'}) {
 4561:         my $start = time;
 4562:         my $end = 0;
 4563:         $author_ok = 
 4564:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 4565:                                         'au',$end,$start,'','','domconfig');
 4566:     } else {
 4567:         $author_ok = 'ok';
 4568:     }
 4569:     return $author_ok;
 4570: }
 4571: 
 4572: sub publishlogo {
 4573:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 4574:     my ($output,$fname,$logourl);
 4575:     if ($action eq 'upload') {
 4576:         $fname=$env{'form.'.$formname.'.filename'};
 4577:         chop($env{'form.'.$formname});
 4578:     } else {
 4579:         ($fname) = ($formname =~ /([^\/]+)$/);
 4580:     }
 4581:     if ($savefileas ne '') {
 4582:         $fname = $savefileas;
 4583:     }
 4584:     $fname=&Apache::lonnet::clean_filename($fname);
 4585: # See if there is anything left
 4586:     unless ($fname) { return ('error: no uploaded file'); }
 4587:     $fname="$subdir/$fname";
 4588:     my $filepath='/home/'.$confname.'/public_html';
 4589:     my ($fnamepath,$file,$fetchthumb);
 4590:     $file=$fname;
 4591:     if ($fname=~m|/|) {
 4592:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 4593:     }
 4594:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 4595:     my $count;
 4596:     for ($count=4;$count<=$#parts;$count++) {
 4597:         $filepath.="/$parts[$count]";
 4598:         if ((-e $filepath)!=1) {
 4599:             mkdir($filepath,02770);
 4600:         }
 4601:     }
 4602:     # Check for bad extension and disallow upload
 4603:     if ($file=~/\.(\w+)$/ &&
 4604:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 4605:         $output = 
 4606:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 4607:     } elsif ($file=~/\.(\w+)$/ &&
 4608:         !defined(&Apache::loncommon::fileembstyle($1))) {
 4609:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 4610:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 4611:         $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 4612:     } elsif (-d "$filepath/$file") {
 4613:         $output = &mt('File name is a directory name - rename the file and re-upload');
 4614:     } else {
 4615:         my $source = $filepath.'/'.$file;
 4616:         my $logfile;
 4617:         if (!open($logfile,">>$source".'.log')) {
 4618:             return (&mt('No write permission to Construction Space'));
 4619:         }
 4620:         print $logfile
 4621: "\n================= Publish ".localtime()." ================\n".
 4622: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 4623: # Save the file
 4624:         if (!open(FH,'>'.$source)) {
 4625:             &Apache::lonnet::logthis('Failed to create '.$source);
 4626:             return (&mt('Failed to create file'));
 4627:         }
 4628:         if ($action eq 'upload') {
 4629:             if (!print FH ($env{'form.'.$formname})) {
 4630:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 4631:                 return (&mt('Failed to write file'));
 4632:             }
 4633:         } else {
 4634:             my $original = &Apache::lonnet::filelocation('',$formname);
 4635:             if(!copy($original,$source)) {
 4636:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 4637:                 return (&mt('Failed to write file'));
 4638:             }
 4639:         }
 4640:         close(FH);
 4641:         chmod(0660, $source); # Permissions to rw-rw---.
 4642: 
 4643:         my $docroot=$r->dir_config('lonDocRoot');
 4644:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 4645:         my $copyfile=$targetdir.'/'.$file;
 4646: 
 4647:         my @parts=split(/\//,$targetdir);
 4648:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 4649:         for (my $count=5;$count<=$#parts;$count++) {
 4650:             $path.="/$parts[$count]";
 4651:             if (!-e $path) {
 4652:                 print $logfile "\nCreating directory ".$path;
 4653:                 mkdir($path,02770);
 4654:             }
 4655:         }
 4656:         my $versionresult;
 4657:         if (-e $copyfile) {
 4658:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 4659:         } else {
 4660:             $versionresult = 'ok';
 4661:         }
 4662:         if ($versionresult eq 'ok') {
 4663:             if (copy($source,$copyfile)) {
 4664:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 4665:                 $output = 'ok';
 4666:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 4667:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 4668:             } else {
 4669:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 4670:                 $output = &mt('Failed to copy file to RES space').", $!";
 4671:             }
 4672:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 4673:                 my $inputfile = $filepath.'/'.$file;
 4674:                 my $outfile = $filepath.'/'.'tn-'.$file;
 4675:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 4676:                 if ($fullwidth ne '' && $fullheight ne '') { 
 4677:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 4678:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 4679:                         system("convert -sample $thumbsize $inputfile $outfile");
 4680:                         chmod(0660, $filepath.'/tn-'.$file);
 4681:                         if (-e $outfile) {
 4682:                             my $copyfile=$targetdir.'/tn-'.$file;
 4683:                             if (copy($outfile,$copyfile)) {
 4684:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 4685:                                 &write_metadata($dom,$confname,$formname,
 4686:                                                 $targetdir,'tn-'.$file,$logfile);
 4687:                             } else {
 4688:                                 print $logfile "\nUnable to write ".$copyfile.
 4689:                                                ':'.$!."\n";
 4690:                             }
 4691:                         }
 4692:                     }
 4693:                 }
 4694:             }
 4695:         } else {
 4696:             $output = $versionresult;
 4697:         }
 4698:     }
 4699:     return ($output,$logourl);
 4700: }
 4701: 
 4702: sub logo_versioning {
 4703:     my ($targetdir,$file,$logfile) = @_;
 4704:     my $target = $targetdir.'/'.$file;
 4705:     my ($maxversion,$fn,$extn,$output);
 4706:     $maxversion = 0;
 4707:     if ($file =~ /^(.+)\.(\w+)$/) {
 4708:         $fn=$1;
 4709:         $extn=$2;
 4710:     }
 4711:     opendir(DIR,$targetdir);
 4712:     while (my $filename=readdir(DIR)) {
 4713:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 4714:             $maxversion=($1>$maxversion)?$1:$maxversion;
 4715:         }
 4716:     }
 4717:     $maxversion++;
 4718:     print $logfile "\nCreating old version ".$maxversion."\n";
 4719:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 4720:     if (copy($target,$copyfile)) {
 4721:         print $logfile "Copied old target to ".$copyfile."\n";
 4722:         $copyfile=$copyfile.'.meta';
 4723:         if (copy($target.'.meta',$copyfile)) {
 4724:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 4725:             $output = 'ok';
 4726:         } else {
 4727:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 4728:             $output = &mt('Failed to copy old meta').", $!, ";
 4729:         }
 4730:     } else {
 4731:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 4732:         $output = &mt('Failed to copy old target').", $!, ";
 4733:     }
 4734:     return $output;
 4735: }
 4736: 
 4737: sub write_metadata {
 4738:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 4739:     my (%metadatafields,%metadatakeys,$output);
 4740:     $metadatafields{'title'}=$formname;
 4741:     $metadatafields{'creationdate'}=time;
 4742:     $metadatafields{'lastrevisiondate'}=time;
 4743:     $metadatafields{'copyright'}='public';
 4744:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 4745:                                          $env{'user.domain'};
 4746:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 4747:     $metadatafields{'domain'}=$dom;
 4748:     {
 4749:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 4750:         my $mfh;
 4751:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 4752:             $output = &mt('Could not write metadata');
 4753:         }
 4754:         foreach (sort keys %metadatafields) {
 4755:             unless ($_=~/\./) {
 4756:                 my $unikey=$_;
 4757:                 $unikey=~/^([A-Za-z]+)/;
 4758:                 my $tag=$1;
 4759:                 $tag=~tr/A-Z/a-z/;
 4760:                 print $mfh "\n\<$tag";
 4761:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 4762:                     my $value=$metadatafields{$unikey.'.'.$_};
 4763:                     $value=~s/\"/\'\'/g;
 4764:                     print $mfh ' '.$_.'="'.$value.'"';
 4765:                 }
 4766:                 print $mfh '>'.
 4767:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 4768:                         .'</'.$tag.'>';
 4769:             }
 4770:         }
 4771:         $output = 'ok';
 4772:         print $logfile "\nWrote metadata";
 4773:         close($mfh);
 4774:     }
 4775: }
 4776: 
 4777: sub check_switchserver {
 4778:     my ($dom,$confname) = @_;
 4779:     my ($allowed,$switchserver);
 4780:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 4781:     if ($home eq 'no_host') {
 4782:         $home = &Apache::lonnet::domain($dom,'primary');
 4783:     }
 4784:     my @ids=&Apache::lonnet::current_machine_ids();
 4785:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 4786:     if (!$allowed) {
 4787: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 4788:     }
 4789:     return $switchserver;
 4790: }
 4791: 
 4792: sub modify_quotas {
 4793:     my ($dom,$action,%domconfig) = @_;
 4794:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
 4795:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
 4796:     if ($action eq 'quotas') {
 4797:         $context = 'tools'; 
 4798:     } else { 
 4799:         $context = $action;
 4800:     }
 4801:     if ($context eq 'requestcourses') {
 4802:         @usertools = ('official','unofficial','community');
 4803:         @options =('norequest','approval','validate','autolimit');
 4804:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 4805:         %titles = &courserequest_titles();
 4806:         $toolregexp = join('|',@usertools);
 4807:         %conditions = &courserequest_conditions();
 4808:     } else {
 4809:         @usertools = ('aboutme','blog','portfolio');
 4810:         %titles = &tool_titles();
 4811:     }
 4812:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 4813:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4814:     foreach my $key (keys(%env)) {
 4815:         if ($context eq 'requestcourses') {
 4816:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
 4817:                 my $item = $1;
 4818:                 my $type = $2;
 4819:                 if ($type =~ /^limit_(.+)/) {
 4820:                     $limithash{$item}{$1} = $env{$key};
 4821:                 } else {
 4822:                     $confhash{$item}{$type} = $env{$key};
 4823:                 }
 4824:             }
 4825:         } else {
 4826:             if ($key =~ /^form\.quota_(.+)$/) {
 4827:                 $confhash{'defaultquota'}{$1} = $env{$key};
 4828:             }
 4829:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
 4830:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 4831:             }
 4832:         }
 4833:     }
 4834:     if ($context eq 'requestcourses') {
 4835:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
 4836:         @approvalnotify = sort(@approvalnotify);
 4837:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
 4838:         if (ref($domconfig{$action}) eq 'HASH') {
 4839:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
 4840:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
 4841:                     $changes{'notify'}{'approval'} = 1;
 4842:                 }
 4843:             } else {
 4844:                 if ($confhash{'notify'}{'approval'}) {
 4845:                     $changes{'notify'}{'approval'} = 1;
 4846:                 }
 4847:             }
 4848:         } else {
 4849:             if ($confhash{'notify'}{'approval'}) {
 4850:                 $changes{'notify'}{'approval'} = 1;
 4851:             }
 4852:         }
 4853:     } else {
 4854:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 4855:     }
 4856:     foreach my $item (@usertools) {
 4857:         foreach my $type (@{$types},'default','_LC_adv') {
 4858:             my $unset; 
 4859:             if ($context eq 'requestcourses') {
 4860:                 $unset = '0';
 4861:                 if ($type eq '_LC_adv') {
 4862:                     $unset = '';
 4863:                 }
 4864:                 if ($confhash{$item}{$type} eq 'autolimit') {
 4865:                     $confhash{$item}{$type} .= '=';
 4866:                     unless ($limithash{$item}{$type} =~ /\D/) {
 4867:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
 4868:                     }
 4869:                 }
 4870:             } else {
 4871:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 4872:                     $confhash{$item}{$type} = 1;
 4873:                 } else {
 4874:                     $confhash{$item}{$type} = 0;
 4875:                 }
 4876:             }
 4877:             if (ref($domconfig{$action}) eq 'HASH') {
 4878:                 if (ref($domconfig{$action}{$item}) eq 'HASH') {
 4879:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
 4880:                         $changes{$item}{$type} = 1;
 4881:                     }
 4882:                 } else {
 4883:                     if ($context eq 'requestcourses') {
 4884:                         if ($confhash{$item}{$type} ne $unset) {
 4885:                             $changes{$item}{$type} = 1;
 4886:                         }
 4887:                     } else {
 4888:                         if (!$confhash{$item}{$type}) {
 4889:                             $changes{$item}{$type} = 1;
 4890:                         }
 4891:                     }
 4892:                 }
 4893:             } else {
 4894:                 if ($context eq 'requestcourses') {
 4895:                     if ($confhash{$item}{$type} ne $unset) {
 4896:                         $changes{$item}{$type} = 1;
 4897:                     }
 4898:                 } else {
 4899:                     if (!$confhash{$item}{$type}) {
 4900:                         $changes{$item}{$type} = 1;
 4901:                     }
 4902:                 }
 4903:             }
 4904:         }
 4905:     }
 4906:     unless ($context eq 'requestcourses') {
 4907:         if (ref($domconfig{'quotas'}) eq 'HASH') {
 4908:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 4909:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 4910:                     if (exists($confhash{'defaultquota'}{$key})) {
 4911:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 4912:                             $changes{'defaultquota'}{$key} = 1;
 4913:                         }
 4914:                     } else {
 4915:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 4916:                     }
 4917:                 }
 4918:             } else {
 4919:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
 4920:                     if (exists($confhash{'defaultquota'}{$key})) {
 4921:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 4922:                             $changes{'defaultquota'}{$key} = 1;
 4923:                         }
 4924:                     } else {
 4925:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 4926:                     }
 4927:                 }
 4928:             }
 4929:         }
 4930:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
 4931:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 4932:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 4933:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 4934:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 4935:                             $changes{'defaultquota'}{$key} = 1;
 4936:                         }
 4937:                     } else {
 4938:                         if (!exists($domconfig{'quotas'}{$key})) {
 4939:                             $changes{'defaultquota'}{$key} = 1;
 4940:                         }
 4941:                     }
 4942:                 } else {
 4943:                     $changes{'defaultquota'}{$key} = 1;
 4944:                 }
 4945:             }
 4946:         }
 4947:     }
 4948: 
 4949:     foreach my $key (keys(%confhash)) {
 4950:         $domdefaults{$key} = $confhash{$key};
 4951:     }
 4952:    
 4953:     my %quotahash = (
 4954:                       $action => { %confhash }
 4955:                     );
 4956:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 4957:                                              $dom);
 4958:     if ($putresult eq 'ok') {
 4959:         if (keys(%changes) > 0) {
 4960:             my $cachetime = 24*60*60;
 4961:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 4962: 
 4963:             $resulttext = &mt('Changes made:').'<ul>';
 4964:             unless ($context eq 'requestcourses') {
 4965:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
 4966:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 4967:                     foreach my $type (@{$types},'default') {
 4968:                         if (defined($changes{'defaultquota'}{$type})) {
 4969:                             my $typetitle = $usertypes->{$type};
 4970:                             if ($type eq 'default') {
 4971:                                 $typetitle = $othertitle;
 4972:                             }
 4973:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 4974:                         }
 4975:                     }
 4976:                     $resulttext .= '</ul></li>';
 4977:                 }
 4978:             }
 4979:             my %newenv;
 4980:             foreach my $item (@usertools) {
 4981:                 if (ref($changes{$item}) eq 'HASH') {
 4982:                     my $newacc = 
 4983:                         &Apache::lonnet::usertools_access($env{'user.name'},
 4984:                                                           $env{'user.domain'},
 4985:                                                           $item,'reload',$context);
 4986:                     if ($context eq 'requestcourses') {
 4987:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
 4988:                             $newenv{'environment.canrequest.'.$item} = $newacc;
 4989:                         }
 4990:                     } else {
 4991:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 4992:                             $newenv{'environment.availabletools.'.$item} = $newacc;
 4993:                         }
 4994:                     }
 4995:                     $resulttext .= '<li>'.$titles{$item}.'<ul>';
 4996:                     foreach my $type (@{$types},'default','_LC_adv') {
 4997:                         if ($changes{$item}{$type}) {
 4998:                             my $typetitle = $usertypes->{$type};
 4999:                             if ($type eq 'default') {
 5000:                                 $typetitle = $othertitle;
 5001:                             } elsif ($type eq '_LC_adv') {
 5002:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 5003:                             }
 5004:                             if ($confhash{$item}{$type}) {
 5005:                                 if ($context eq 'requestcourses') {
 5006:                                     my $cond;
 5007:                                     if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
 5008:                                         if ($1 eq '') {
 5009:                                             $cond = &mt('(Automatic processing of any request).');
 5010:                                         } else {
 5011:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
 5012:                                         }
 5013:                                     } else { 
 5014:                                         $cond = $conditions{$confhash{$item}{$type}};
 5015:                                     }
 5016:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
 5017:                                 } else {
 5018:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 5019:                                 }
 5020:                             } else {
 5021:                                 if ($type eq '_LC_adv') {
 5022:                                     if ($confhash{$item}{$type} eq '0') {
 5023:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 5024:                                     } else { 
 5025:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
 5026:                                     }
 5027:                                 } else {
 5028:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 5029:                                 }
 5030:                             }
 5031:                         }
 5032:                     }
 5033:                     $resulttext .= '</ul></li>';
 5034:                 }
 5035:             }
 5036:             if ($action eq 'requestcourses') {
 5037:                 if (ref($changes{'notify'}) eq 'HASH') {
 5038:                     if ($changes{'notify'}{'approval'}) {
 5039:                         if (ref($confhash{'notify'}) eq 'HASH') {
 5040:                             if ($confhash{'notify'}{'approval'}) {
 5041:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
 5042:                             } else {
 5043:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
 5044:                             }
 5045:                         }
 5046:                     }
 5047:                 }
 5048:             }
 5049:             $resulttext .= '</ul>';
 5050:             if (keys(%newenv)) {
 5051:                 &Apache::lonnet::appenv(\%newenv);
 5052:             }
 5053:         } else {
 5054:             if ($context eq 'requestcourses') {
 5055:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
 5056:             } else {
 5057:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
 5058:             }
 5059:         }
 5060:     } else {
 5061:         $resulttext = '<span class="LC_error">'.
 5062: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5063:     }
 5064:     return $resulttext;
 5065: }
 5066: 
 5067: sub modify_autoenroll {
 5068:     my ($dom,%domconfig) = @_;
 5069:     my ($resulttext,%changes);
 5070:     my %currautoenroll;
 5071:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 5072:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 5073:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 5074:         }
 5075:     }
 5076:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 5077:     my %title = ( run => 'Auto-enrollment active',
 5078:                   sender => 'Sender for notification messages',
 5079:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
 5080:     my @offon = ('off','on');
 5081:     my $sender_uname = $env{'form.sender_uname'};
 5082:     my $sender_domain = $env{'form.sender_domain'};
 5083:     if ($sender_domain eq '') {
 5084:         $sender_uname = '';
 5085:     } elsif ($sender_uname eq '') {
 5086:         $sender_domain = '';
 5087:     }
 5088:     my $coowners = $env{'form.autoassign_coowners'};
 5089:     my %autoenrollhash =  (
 5090:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
 5091:                                        'sender_uname' => $sender_uname,
 5092:                                        'sender_domain' => $sender_domain,
 5093:                                        'co-owners' => $coowners,
 5094:                                 }
 5095:                      );
 5096:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 5097:                                              $dom);
 5098:     if ($putresult eq 'ok') {
 5099:         if (exists($currautoenroll{'run'})) {
 5100:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 5101:                  $changes{'run'} = 1;
 5102:              }
 5103:         } elsif ($autorun) {
 5104:             if ($env{'form.autoenroll_run'} ne '1') {
 5105:                  $changes{'run'} = 1;
 5106:             }
 5107:         }
 5108:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 5109:             $changes{'sender'} = 1;
 5110:         }
 5111:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 5112:             $changes{'sender'} = 1;
 5113:         }
 5114:         if ($currautoenroll{'co-owners'} ne '') {
 5115:             if ($currautoenroll{'co-owners'} ne $coowners) {
 5116:                 $changes{'coowners'} = 1;
 5117:             }
 5118:         } elsif ($coowners) {
 5119:             $changes{'coowners'} = 1;
 5120:         }      
 5121:         if (keys(%changes) > 0) {
 5122:             $resulttext = &mt('Changes made:').'<ul>';
 5123:             if ($changes{'run'}) {
 5124:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 5125:             }
 5126:             if ($changes{'sender'}) {
 5127:                 if ($sender_uname eq '' || $sender_domain eq '') {
 5128:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 5129:                 } else {
 5130:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 5131:                 }
 5132:             }
 5133:             if ($changes{'coowners'}) {
 5134:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
 5135:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 5136:             }
 5137:             $resulttext .= '</ul>';
 5138:         } else {
 5139:             $resulttext = &mt('No changes made to auto-enrollment settings');
 5140:         }
 5141:     } else {
 5142:         $resulttext = '<span class="LC_error">'.
 5143: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5144:     }
 5145:     return $resulttext;
 5146: }
 5147: 
 5148: sub modify_autoupdate {
 5149:     my ($dom,%domconfig) = @_;
 5150:     my ($resulttext,%currautoupdate,%fields,%changes);
 5151:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 5152:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 5153:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 5154:         }
 5155:     }
 5156:     my @offon = ('off','on');
 5157:     my %title = &Apache::lonlocal::texthash (
 5158:                    run => 'Auto-update:',
 5159:                    classlists => 'Updates to user information in classlists?'
 5160:                 );
 5161:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5162:     my %fieldtitles = &Apache::lonlocal::texthash (
 5163:                         id => 'Student/Employee ID',
 5164:                         permanentemail => 'E-mail address',
 5165:                         lastname => 'Last Name',
 5166:                         firstname => 'First Name',
 5167:                         middlename => 'Middle Name',
 5168:                         generation => 'Generation',
 5169:                       );
 5170:     $othertitle = &mt('All users');
 5171:     if (keys(%{$usertypes}) >  0) {
 5172:         $othertitle = &mt('Other users');
 5173:     }
 5174:     foreach my $key (keys(%env)) {
 5175:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 5176:             my ($usertype,$item) = ($1,$2);
 5177:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
 5178:                 if ($usertype eq 'default') {   
 5179:                     push(@{$fields{$1}},$2);
 5180:                 } elsif (ref($types) eq 'ARRAY') {
 5181:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
 5182:                         push(@{$fields{$1}},$2);
 5183:                     }
 5184:                 }
 5185:             }
 5186:         }
 5187:     }
 5188:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
 5189:     @lockablenames = sort(@lockablenames);
 5190:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
 5191:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 5192:         if (@changed) {
 5193:             $changes{'lockablenames'} = 1;
 5194:         }
 5195:     } else {
 5196:         if (@lockablenames) {
 5197:             $changes{'lockablenames'} = 1;
 5198:         }
 5199:     }
 5200:     my %updatehash = (
 5201:                       autoupdate => { run => $env{'form.autoupdate_run'},
 5202:                                       classlists => $env{'form.classlists'},
 5203:                                       fields => {%fields},
 5204:                                       lockablenames => \@lockablenames,
 5205:                                     }
 5206:                      );
 5207:     foreach my $key (keys(%currautoupdate)) {
 5208:         if (($key eq 'run') || ($key eq 'classlists')) {
 5209:             if (exists($updatehash{autoupdate}{$key})) {
 5210:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 5211:                     $changes{$key} = 1;
 5212:                 }
 5213:             }
 5214:         } elsif ($key eq 'fields') {
 5215:             if (ref($currautoupdate{$key}) eq 'HASH') {
 5216:                 foreach my $item (@{$types},'default') {
 5217:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 5218:                         my $change = 0;
 5219:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 5220:                             if (!exists($fields{$item})) {
 5221:                                 $change = 1;
 5222:                                 last;
 5223:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 5224:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 5225:                                     $change = 1;
 5226:                                     last;
 5227:                                 }
 5228:                             }
 5229:                         }
 5230:                         if ($change) {
 5231:                             push(@{$changes{$key}},$item);
 5232:                         }
 5233:                     } 
 5234:                 }
 5235:             }
 5236:         } elsif ($key eq 'lockablenames') {
 5237:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
 5238:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 5239:                 if (@changed) {
 5240:                     $changes{'lockablenames'} = 1;
 5241:                 }
 5242:             } else {
 5243:                 if (@lockablenames) {
 5244:                     $changes{'lockablenames'} = 1;
 5245:                 }
 5246:             }
 5247:         }
 5248:     }
 5249:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
 5250:         if (@lockablenames) {
 5251:             $changes{'lockablenames'} = 1;
 5252:         }
 5253:     }
 5254:     foreach my $item (@{$types},'default') {
 5255:         if (defined($fields{$item})) {
 5256:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 5257:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
 5258:                     my $change = 0;
 5259:                     if (ref($fields{$item}) eq 'ARRAY') {
 5260:                         foreach my $type (@{$fields{$item}}) {
 5261:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
 5262:                                 $change = 1;
 5263:                                 last;
 5264:                             }
 5265:                         }
 5266:                     }
 5267:                     if ($change) {
 5268:                         push(@{$changes{'fields'}},$item);
 5269:                     }
 5270:                 } else {
 5271:                     push(@{$changes{'fields'}},$item);
 5272:                 }
 5273:             } else {
 5274:                 push(@{$changes{'fields'}},$item);
 5275:             }
 5276:         }
 5277:     }
 5278:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 5279:                                              $dom);
 5280:     if ($putresult eq 'ok') {
 5281:         if (keys(%changes) > 0) {
 5282:             $resulttext = &mt('Changes made:').'<ul>';
 5283:             foreach my $key (sort(keys(%changes))) {
 5284:                 if ($key eq 'lockablenames') {
 5285:                     $resulttext .= '<li>';
 5286:                     if (@lockablenames) {
 5287:                         $usertypes->{'default'} = $othertitle;
 5288:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
 5289:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
 5290:                     } else {
 5291:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
 5292:                     }
 5293:                     $resulttext .= '</li>';
 5294:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
 5295:                     foreach my $item (@{$changes{$key}}) {
 5296:                         my @newvalues;
 5297:                         foreach my $type (@{$fields{$item}}) {
 5298:                             push(@newvalues,$fieldtitles{$type});
 5299:                         }
 5300:                         my $newvaluestr;
 5301:                         if (@newvalues > 0) {
 5302:                             $newvaluestr = join(', ',@newvalues);
 5303:                         } else {
 5304:                             $newvaluestr = &mt('none');
 5305:                         }
 5306:                         if ($item eq 'default') {
 5307:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 5308:                         } else {
 5309:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 5310:                         }
 5311:                     }
 5312:                 } else {
 5313:                     my $newvalue;
 5314:                     if ($key eq 'run') {
 5315:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 5316:                     } else {
 5317:                         $newvalue = $offon[$env{'form.'.$key}];
 5318:                     }
 5319:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 5320:                 }
 5321:             }
 5322:             $resulttext .= '</ul>';
 5323:         } else {
 5324:             $resulttext = &mt('No changes made to autoupdates');
 5325:         }
 5326:     } else {
 5327:         $resulttext = '<span class="LC_error">'.
 5328: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5329:     }
 5330:     return $resulttext;
 5331: }
 5332: 
 5333: sub modify_autocreate {
 5334:     my ($dom,%domconfig) = @_;
 5335:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
 5336:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
 5337:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
 5338:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
 5339:         }
 5340:     }
 5341:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
 5342:                  req => 'Auto-creation of validated requests for official courses',
 5343:                  xmldc => 'Identity of course creator of courses from XML files',
 5344:                );
 5345:     my @types = ('xml','req');
 5346:     foreach my $item (@types) {
 5347:         $newvals{$item} = $env{'form.autocreate_'.$item};
 5348:         $newvals{$item} =~ s/\D//g;
 5349:         $newvals{$item} = 0 if ($newvals{$item} eq '');
 5350:     }
 5351:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
 5352:     my %domcoords = &get_active_dcs($dom);
 5353:     unless (exists($domcoords{$newvals{'xmldc'}})) {
 5354:         $newvals{'xmldc'} = '';
 5355:     } 
 5356:     %autocreatehash =  (
 5357:                         autocreate => { xml => $newvals{'xml'},
 5358:                                         req => $newvals{'req'},
 5359:                                       }
 5360:                        );
 5361:     if ($newvals{'xmldc'} ne '') {
 5362:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
 5363:     }
 5364:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
 5365:                                              $dom);
 5366:     if ($putresult eq 'ok') {
 5367:         my @items = @types;
 5368:         if ($newvals{'xml'}) {
 5369:             push(@items,'xmldc');
 5370:         }
 5371:         foreach my $item (@items) {
 5372:             if (exists($currautocreate{$item})) {
 5373:                 if ($currautocreate{$item} ne $newvals{$item}) {
 5374:                     $changes{$item} = 1;
 5375:                 }
 5376:             } elsif ($newvals{$item}) {
 5377:                 $changes{$item} = 1;
 5378:             }
 5379:         }
 5380:         if (keys(%changes) > 0) {
 5381:             my @offon = ('off','on'); 
 5382:             $resulttext = &mt('Changes made:').'<ul>';
 5383:             foreach my $item (@types) {
 5384:                 if ($changes{$item}) {
 5385:                     my $newtxt = $offon[$newvals{$item}];
 5386:                     $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
 5387:                 }
 5388:             }
 5389:             if ($changes{'xmldc'}) {
 5390:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
 5391:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
 5392:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
 5393:             }
 5394:             $resulttext .= '</ul>';
 5395:         } else {
 5396:             $resulttext = &mt('No changes made to auto-creation settings');
 5397:         }
 5398:     } else {
 5399:         $resulttext = '<span class="LC_error">'.
 5400:             &mt('An error occurred: [_1]',$putresult).'</span>';
 5401:     }
 5402:     return $resulttext;
 5403: }
 5404: 
 5405: sub modify_directorysrch {
 5406:     my ($dom,%domconfig) = @_;
 5407:     my ($resulttext,%changes);
 5408:     my %currdirsrch;
 5409:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 5410:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 5411:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 5412:         }
 5413:     }
 5414:     my %title = ( available => 'Directory search available',
 5415:                   localonly => 'Other domains can search',
 5416:                   searchby => 'Search types',
 5417:                   searchtypes => 'Search latitude');
 5418:     my @offon = ('off','on');
 5419:     my @otherdoms = ('Yes','No');
 5420: 
 5421:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 5422:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 5423:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 5424: 
 5425:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5426:     if (keys(%{$usertypes}) == 0) {
 5427:         @cansearch = ('default');
 5428:     } else {
 5429:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 5430:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 5431:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 5432:                     push(@{$changes{'cansearch'}},$type);
 5433:                 }
 5434:             }
 5435:             foreach my $type (@cansearch) {
 5436:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 5437:                     push(@{$changes{'cansearch'}},$type);
 5438:                 }
 5439:             }
 5440:         } else {
 5441:             push(@{$changes{'cansearch'}},@cansearch);
 5442:         }
 5443:     }
 5444: 
 5445:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 5446:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 5447:             if (!grep(/^\Q$by\E$/,@searchby)) {
 5448:                 push(@{$changes{'searchby'}},$by);
 5449:             }
 5450:         }
 5451:         foreach my $by (@searchby) {
 5452:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 5453:                 push(@{$changes{'searchby'}},$by);
 5454:             }
 5455:         }
 5456:     } else {
 5457:         push(@{$changes{'searchby'}},@searchby);
 5458:     }
 5459: 
 5460:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 5461:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 5462:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 5463:                 push(@{$changes{'searchtypes'}},$type);
 5464:             }
 5465:         }
 5466:         foreach my $type (@searchtypes) {
 5467:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 5468:                 push(@{$changes{'searchtypes'}},$type);
 5469:             }
 5470:         }
 5471:     } else {
 5472:         if (exists($currdirsrch{'searchtypes'})) {
 5473:             foreach my $type (@searchtypes) {  
 5474:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 5475:                     push(@{$changes{'searchtypes'}},$type);
 5476:                 }
 5477:             }
 5478:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 5479:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 5480:             }   
 5481:         } else {
 5482:             push(@{$changes{'searchtypes'}},@searchtypes); 
 5483:         }
 5484:     }
 5485: 
 5486:     my %dirsrch_hash =  (
 5487:             directorysrch => { available => $env{'form.dirsrch_available'},
 5488:                                cansearch => \@cansearch,
 5489:                                localonly => $env{'form.dirsrch_localonly'},
 5490:                                searchby => \@searchby,
 5491:                                searchtypes => \@searchtypes,
 5492:                              }
 5493:             );
 5494:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 5495:                                              $dom);
 5496:     if ($putresult eq 'ok') {
 5497:         if (exists($currdirsrch{'available'})) {
 5498:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 5499:                  $changes{'available'} = 1;
 5500:              }
 5501:         } else {
 5502:             if ($env{'form.dirsrch_available'} eq '1') {
 5503:                 $changes{'available'} = 1;
 5504:             }
 5505:         }
 5506:         if (exists($currdirsrch{'localonly'})) {
 5507:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 5508:                  $changes{'localonly'} = 1;
 5509:              }
 5510:         } else {
 5511:             if ($env{'form.dirsrch_localonly'} eq '1') {
 5512:                 $changes{'localonly'} = 1;
 5513:             }
 5514:         }
 5515:         if (keys(%changes) > 0) {
 5516:             $resulttext = &mt('Changes made:').'<ul>';
 5517:             if ($changes{'available'}) {
 5518:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 5519:             }
 5520:             if ($changes{'localonly'}) {
 5521:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 5522:             }
 5523: 
 5524:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 5525:                 my $chgtext;
 5526:                 if (ref($usertypes) eq 'HASH') {
 5527:                     if (keys(%{$usertypes}) > 0) {
 5528:                         foreach my $type (@{$types}) {
 5529:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 5530:                                 $chgtext .= $usertypes->{$type}.'; ';
 5531:                             }
 5532:                         }
 5533:                         if (grep(/^default$/,@cansearch)) {
 5534:                             $chgtext .= $othertitle;
 5535:                         } else {
 5536:                             $chgtext =~ s/\; $//;
 5537:                         }
 5538:                         $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
 5539:                     }
 5540:                 }
 5541:             }
 5542:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 5543:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 5544:                 my $chgtext;
 5545:                 foreach my $type (@{$titleorder}) {
 5546:                     if (grep(/^\Q$type\E$/,@searchby)) {
 5547:                         if (defined($searchtitles->{$type})) {
 5548:                             $chgtext .= $searchtitles->{$type}.'; ';
 5549:                         }
 5550:                     }
 5551:                 }
 5552:                 $chgtext =~ s/\; $//;
 5553:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 5554:             }
 5555:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 5556:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 5557:                 my $chgtext;
 5558:                 foreach my $type (@{$srchtypeorder}) {
 5559:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 5560:                         if (defined($srchtypes_desc->{$type})) {
 5561:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 5562:                         }
 5563:                     }
 5564:                 }
 5565:                 $chgtext =~ s/\; $//;
 5566:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
 5567:             }
 5568:             $resulttext .= '</ul>';
 5569:         } else {
 5570:             $resulttext = &mt('No changes made to institution directory search settings');
 5571:         }
 5572:     } else {
 5573:         $resulttext = '<span class="LC_error">'.
 5574:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 5575:     }
 5576:     return $resulttext;
 5577: }
 5578: 
 5579: sub modify_contacts {
 5580:     my ($dom,%domconfig) = @_;
 5581:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 5582:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 5583:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 5584:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 5585:         }
 5586:     }
 5587:     my (%others,%to,%bcc);
 5588:     my @contacts = ('supportemail','adminemail');
 5589:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
 5590:                     'requestsmail');
 5591:     foreach my $type (@mailings) {
 5592:         @{$newsetting{$type}} = 
 5593:             &Apache::loncommon::get_env_multiple('form.'.$type);
 5594:         foreach my $item (@contacts) {
 5595:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 5596:                 $contacts_hash{contacts}{$type}{$item} = 1;
 5597:             } else {
 5598:                 $contacts_hash{contacts}{$type}{$item} = 0;
 5599:             }
 5600:         }  
 5601:         $others{$type} = $env{'form.'.$type.'_others'};
 5602:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 5603:         if ($type eq 'helpdeskmail') {
 5604:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
 5605:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
 5606:         }
 5607:     }
 5608:     foreach my $item (@contacts) {
 5609:         $to{$item} = $env{'form.'.$item};
 5610:         $contacts_hash{'contacts'}{$item} = $to{$item};
 5611:     }
 5612:     if (keys(%currsetting) > 0) {
 5613:         foreach my $item (@contacts) {
 5614:             if ($to{$item} ne $currsetting{$item}) {
 5615:                 $changes{$item} = 1;
 5616:             }
 5617:         }
 5618:         foreach my $type (@mailings) {
 5619:             foreach my $item (@contacts) {
 5620:                 if (ref($currsetting{$type}) eq 'HASH') {
 5621:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 5622:                         push(@{$changes{$type}},$item);
 5623:                     }
 5624:                 } else {
 5625:                     push(@{$changes{$type}},@{$newsetting{$type}});
 5626:                 }
 5627:             }
 5628:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 5629:                 push(@{$changes{$type}},'others');
 5630:             }
 5631:             if ($type eq 'helpdeskmail') {   
 5632:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
 5633:                     push(@{$changes{$type}},'bcc'); 
 5634:                 }
 5635:             }
 5636:         }
 5637:     } else {
 5638:         my %default;
 5639:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 5640:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 5641:         $default{'errormail'} = 'adminemail';
 5642:         $default{'packagesmail'} = 'adminemail';
 5643:         $default{'helpdeskmail'} = 'supportemail';
 5644:         $default{'lonstatusmail'} = 'adminemail';
 5645:         $default{'requestsmail'} = 'adminemail';
 5646:         foreach my $item (@contacts) {
 5647:            if ($to{$item} ne $default{$item}) {
 5648:               $changes{$item} = 1;
 5649:            } 
 5650:         }
 5651:         foreach my $type (@mailings) {
 5652:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 5653:                
 5654:                 push(@{$changes{$type}},@{$newsetting{$type}});
 5655:             }
 5656:             if ($others{$type} ne '') {
 5657:                 push(@{$changes{$type}},'others');
 5658:             }
 5659:             if ($type eq 'helpdeskmail') {
 5660:                 if ($bcc{$type} ne '') {
 5661:                     push(@{$changes{$type}},'bcc');
 5662:                 }
 5663:             }
 5664:         }
 5665:     }
 5666:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 5667:                                              $dom);
 5668:     if ($putresult eq 'ok') {
 5669:         if (keys(%changes) > 0) {
 5670:             my ($titles,$short_titles)  = &contact_titles();
 5671:             $resulttext = &mt('Changes made:').'<ul>';
 5672:             foreach my $item (@contacts) {
 5673:                 if ($changes{$item}) {
 5674:                     $resulttext .= '<li>'.$titles->{$item}.
 5675:                                     &mt(' set to: ').
 5676:                                     '<span class="LC_cusr_emph">'.
 5677:                                     $to{$item}.'</span></li>';
 5678:                 }
 5679:             }
 5680:             foreach my $type (@mailings) {
 5681:                 if (ref($changes{$type}) eq 'ARRAY') {
 5682:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 5683:                     my @text;
 5684:                     foreach my $item (@{$newsetting{$type}}) {
 5685:                         push(@text,$short_titles->{$item});
 5686:                     }
 5687:                     if ($others{$type} ne '') {
 5688:                         push(@text,$others{$type});
 5689:                     }
 5690:                     $resulttext .= '<span class="LC_cusr_emph">'.
 5691:                                    join(', ',@text).'</span>';
 5692:                     if ($type eq 'helpdeskmail') {
 5693:                         if ($bcc{$type} ne '') {
 5694:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
 5695:                         }
 5696:                     }
 5697:                     $resulttext .= '</li>';
 5698:                 }
 5699:             }
 5700:             $resulttext .= '</ul>';
 5701:         } else {
 5702:             $resulttext = &mt('No changes made to contact information');
 5703:         }
 5704:     } else {
 5705:         $resulttext = '<span class="LC_error">'.
 5706:             &mt('An error occurred: [_1].',$putresult).'</span>';
 5707:     }
 5708:     return $resulttext;
 5709: }
 5710: 
 5711: sub modify_usercreation {
 5712:     my ($dom,%domconfig) = @_;
 5713:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 5714:     my $warningmsg;
 5715:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 5716:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 5717:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 5718:         }
 5719:     }
 5720:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 5721:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 5722:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 5723:     my @contexts = ('author','course','requestcrs','selfcreate');
 5724:     foreach my $item(@contexts) {
 5725:         if ($item eq 'selfcreate') {
 5726:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
 5727:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 5728:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
 5729:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
 5730:                     if (grep(/^login$/,@{$cancreate{$item}})) {
 5731:                         $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');   
 5732:                     }
 5733:                 }
 5734:             }
 5735:         } else {
 5736:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
 5737:         }
 5738:     }
 5739:     my ($othertitle,$usertypes,$types) = 
 5740:         &Apache::loncommon::sorted_inst_types($dom);
 5741:     if (ref($types) eq 'ARRAY') {
 5742:         if (@{$types} > 0) {
 5743:             @{$cancreate{'statustocreate'}} = 
 5744:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
 5745:         } else {
 5746:             @{$cancreate{'statustocreate'}} = ();
 5747:         }
 5748:         push(@contexts,'statustocreate');
 5749:     }
 5750:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 5751:         foreach my $item (@contexts) {
 5752:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
 5753:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 5754:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 5755:                         if (ref($cancreate{$item}) eq 'ARRAY') {
 5756:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 5757:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5758:                                     push(@{$changes{'cancreate'}},$item);
 5759:                                 }
 5760:                             }
 5761:                         }
 5762:                     }
 5763:                 } else {
 5764:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
 5765:                         if (@{$cancreate{$item}} > 0) {
 5766:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5767:                                 push(@{$changes{'cancreate'}},$item);
 5768:                             }
 5769:                         }
 5770:                     } else {
 5771:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
 5772:                             if (@{$cancreate{$item}} < 3) {
 5773:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5774:                                     push(@{$changes{'cancreate'}},$item);
 5775:                                 }
 5776:                             }
 5777:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
 5778:                             if (@{$cancreate{$item}} > 0) {
 5779:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5780:                                     push(@{$changes{'cancreate'}},$item);
 5781:                                 }
 5782:                             }
 5783:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
 5784:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5785:                                 push(@{$changes{'cancreate'}},$item);
 5786:                             }
 5787:                         }
 5788:                     }
 5789:                 }
 5790:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5791:                     foreach my $type (@{$cancreate{$item}}) {
 5792:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 5793:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 5794:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5795:                                     push(@{$changes{'cancreate'}},$item);
 5796:                                 }
 5797:                             }
 5798:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
 5799:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
 5800:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
 5801:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5802:                                     push(@{$changes{'cancreate'}},$item);
 5803:                                 }
 5804:                             }
 5805:                         }
 5806:                     }
 5807:                 }
 5808:             } else {
 5809:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 5810:                     push(@{$changes{'cancreate'}},$item);
 5811:                 }
 5812:             }
 5813:         }
 5814:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 5815:         foreach my $item (@contexts) {
 5816:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 5817:                 if ($cancreate{$item} ne 'any') {
 5818:                     push(@{$changes{'cancreate'}},$item);
 5819:                 }
 5820:             } else {
 5821:                 if ($cancreate{$item} ne 'none') {
 5822:                     push(@{$changes{'cancreate'}},$item);
 5823:                 }
 5824:             }
 5825:         }
 5826:     } else {
 5827:         foreach my $item (@contexts)  {
 5828:             push(@{$changes{'cancreate'}},$item);
 5829:         }
 5830:     }
 5831: 
 5832:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 5833:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 5834:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 5835:                 push(@{$changes{'username_rule'}},$type);
 5836:             }
 5837:         }
 5838:         foreach my $type (@username_rule) {
 5839:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 5840:                 push(@{$changes{'username_rule'}},$type);
 5841:             }
 5842:         }
 5843:     } else {
 5844:         push(@{$changes{'username_rule'}},@username_rule);
 5845:     }
 5846: 
 5847:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 5848:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 5849:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 5850:                 push(@{$changes{'id_rule'}},$type);
 5851:             }
 5852:         }
 5853:         foreach my $type (@id_rule) {
 5854:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 5855:                 push(@{$changes{'id_rule'}},$type);
 5856:             }
 5857:         }
 5858:     } else {
 5859:         push(@{$changes{'id_rule'}},@id_rule);
 5860:     }
 5861: 
 5862:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 5863:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 5864:             if (!grep(/^\Q$type\E$/,@email_rule)) {
 5865:                 push(@{$changes{'email_rule'}},$type);
 5866:             }
 5867:         }
 5868:         foreach my $type (@email_rule) {
 5869:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 5870:                 push(@{$changes{'email_rule'}},$type);
 5871:             }
 5872:         }
 5873:     } else {
 5874:         push(@{$changes{'email_rule'}},@email_rule);
 5875:     }
 5876: 
 5877:     my @authen_contexts = ('author','course','domain');
 5878:     my @authtypes = ('int','krb4','krb5','loc');
 5879:     my %authhash;
 5880:     foreach my $item (@authen_contexts) {
 5881:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 5882:         foreach my $auth (@authtypes) {
 5883:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 5884:                 $authhash{$item}{$auth} = 1;
 5885:             } else {
 5886:                 $authhash{$item}{$auth} = 0;
 5887:             }
 5888:         }
 5889:     }
 5890:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 5891:         foreach my $item (@authen_contexts) {
 5892:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 5893:                 foreach my $auth (@authtypes) {
 5894:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 5895:                         push(@{$changes{'authtypes'}},$item);
 5896:                         last;
 5897:                     }
 5898:                 }
 5899:             }
 5900:         }
 5901:     } else {
 5902:         foreach my $item (@authen_contexts) {
 5903:             push(@{$changes{'authtypes'}},$item);
 5904:         }
 5905:     }
 5906: 
 5907:     my %usercreation_hash =  (
 5908:             usercreation => {
 5909:                               cancreate     => \%cancreate,
 5910:                               username_rule => \@username_rule,
 5911:                               id_rule       => \@id_rule,
 5912:                               email_rule    => \@email_rule,
 5913:                               authtypes     => \%authhash,
 5914:                             }
 5915:             );
 5916: 
 5917:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 5918:                                              $dom);
 5919: 
 5920:     my %selfcreatetypes = (
 5921:                              sso   => 'users authenticated by institutional single sign on',
 5922:                              login => 'users authenticated by institutional log-in',
 5923:                              email => 'users who provide a valid e-mail address for use as the username',
 5924:                           );
 5925:     if ($putresult eq 'ok') {
 5926:         if (keys(%changes) > 0) {
 5927:             $resulttext = &mt('Changes made:').'<ul>';
 5928:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 5929:                 my %lt = &usercreation_types();
 5930:                 foreach my $type (@{$changes{'cancreate'}}) {
 5931:                     my $chgtext;
 5932:                     unless ($type eq 'statustocreate') {
 5933:                         $chgtext = $lt{$type}.', ';
 5934:                     }
 5935:                     if ($type eq 'selfcreate') {
 5936:                         if (@{$cancreate{$type}} == 0) {
 5937:                             $chgtext .= &mt('creation of a new user account is not permitted.');
 5938:                         } else {
 5939:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
 5940:                             foreach my $case (@{$cancreate{$type}}) {
 5941:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 5942:                             }
 5943:                             $chgtext .= '</ul>';
 5944:                             if (ref($cancreate{$type}) eq 'ARRAY') {
 5945:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
 5946:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 5947:                                         if (@{$cancreate{'statustocreate'}} == 0) {
 5948:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 5949:                                         }
 5950:                                     }
 5951:                                 }
 5952:                             }
 5953:                         }
 5954:                     } elsif ($type eq 'statustocreate') {
 5955:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
 5956:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
 5957:                             if (@{$cancreate{'selfcreate'}} > 0) {
 5958:                                 if (@{$cancreate{'statustocreate'}} == 0) {
 5959: 
 5960:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
 5961:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
 5962:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 5963:                                     } 
 5964:                                 } elsif (ref($usertypes) eq 'HASH') {
 5965:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 5966:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
 5967:                                     } else {
 5968:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
 5969:                                     }
 5970:                                     $chgtext .= '<ul>';
 5971:                                     foreach my $case (@{$cancreate{$type}}) {
 5972:                                         if ($case eq 'default') {
 5973:                                             $chgtext .= '<li>'.$othertitle.'</li>';
 5974:                                         } else {
 5975:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
 5976:                                         }
 5977:                                     }
 5978:                                     $chgtext .= '</ul>';
 5979:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 5980:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
 5981:                                     }
 5982:                                 }
 5983:                             } else {
 5984:                                 if (@{$cancreate{$type}} == 0) {
 5985:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
 5986:                                 } else {
 5987:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
 5988:                                 }
 5989:                             }
 5990:                         }
 5991:                     } else {
 5992:                         if ($cancreate{$type} eq 'none') {
 5993:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 5994:                         } elsif ($cancreate{$type} eq 'any') {
 5995:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 5996:                         } elsif ($cancreate{$type} eq 'official') {
 5997:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 5998:                         } elsif ($cancreate{$type} eq 'unofficial') {
 5999:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 6000:                         }
 6001:                     }
 6002:                     $resulttext .= '<li>'.$chgtext.'</li>';
 6003:                 }
 6004:             }
 6005:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 6006:                 my ($rules,$ruleorder) = 
 6007:                     &Apache::lonnet::inst_userrules($dom,'username');
 6008:                 my $chgtext = '<ul>';
 6009:                 foreach my $type (@username_rule) {
 6010:                     if (ref($rules->{$type}) eq 'HASH') {
 6011:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 6012:                     }
 6013:                 }
 6014:                 $chgtext .= '</ul>';
 6015:                 if (@username_rule > 0) {
 6016:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 6017:                 } else {
 6018:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 6019:                 }
 6020:             }
 6021:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 6022:                 my ($idrules,$idruleorder) = 
 6023:                     &Apache::lonnet::inst_userrules($dom,'id');
 6024:                 my $chgtext = '<ul>';
 6025:                 foreach my $type (@id_rule) {
 6026:                     if (ref($idrules->{$type}) eq 'HASH') {
 6027:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 6028:                     }
 6029:                 }
 6030:                 $chgtext .= '</ul>';
 6031:                 if (@id_rule > 0) {
 6032:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 6033:                 } else {
 6034:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 6035:                 }
 6036:             }
 6037:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 6038:                 my ($emailrules,$emailruleorder) =
 6039:                     &Apache::lonnet::inst_userrules($dom,'email');
 6040:                 my $chgtext = '<ul>';
 6041:                 foreach my $type (@email_rule) {
 6042:                     if (ref($emailrules->{$type}) eq 'HASH') {
 6043:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 6044:                     }
 6045:                 }
 6046:                 $chgtext .= '</ul>';
 6047:                 if (@email_rule > 0) {
 6048:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
 6049:                 } else {
 6050:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
 6051:                 }
 6052:             }
 6053: 
 6054:             my %authname = &authtype_names();
 6055:             my %context_title = &context_names();
 6056:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 6057:                 my $chgtext = '<ul>';
 6058:                 foreach my $type (@{$changes{'authtypes'}}) {
 6059:                     my @allowed;
 6060:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 6061:                     foreach my $auth (@authtypes) {
 6062:                         if ($authhash{$type}{$auth}) {
 6063:                             push(@allowed,$authname{$auth});
 6064:                         }
 6065:                     }
 6066:                     if (@allowed > 0) {
 6067:                         $chgtext .= join(', ',@allowed).'</li>';
 6068:                     } else {
 6069:                         $chgtext .= &mt('none').'</li>';
 6070:                     }
 6071:                 }
 6072:                 $chgtext .= '</ul>';
 6073:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 6074:                 $resulttext .= '</li>';
 6075:             }
 6076:             $resulttext .= '</ul>';
 6077:         } else {
 6078:             $resulttext = &mt('No changes made to user creation settings');
 6079:         }
 6080:     } else {
 6081:         $resulttext = '<span class="LC_error">'.
 6082:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6083:     }
 6084:     if ($warningmsg ne '') {
 6085:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 6086:     }
 6087:     return $resulttext;
 6088: }
 6089: 
 6090: sub modify_usermodification {
 6091:     my ($dom,%domconfig) = @_;
 6092:     my ($resulttext,%curr_usermodification,%changes);
 6093:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 6094:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 6095:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 6096:         }
 6097:     }
 6098:     my @contexts = ('author','course','selfcreate');
 6099:     my %context_title = (
 6100:                            author => 'In author context',
 6101:                            course => 'In course context',
 6102:                            selfcreate => 'When self creating account', 
 6103:                         );
 6104:     my @fields = ('lastname','firstname','middlename','generation',
 6105:                   'permanentemail','id');
 6106:     my %roles = (
 6107:                   author => ['ca','aa'],
 6108:                   course => ['st','ep','ta','in','cr'],
 6109:                 );
 6110:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 6111:     if (ref($types) eq 'ARRAY') {
 6112:         push(@{$types},'default');
 6113:         $usertypes->{'default'} = $othertitle;
 6114:     }
 6115:     $roles{'selfcreate'} = $types;  
 6116:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 6117:     my %modifyhash;
 6118:     foreach my $context (@contexts) {
 6119:         foreach my $role (@{$roles{$context}}) {
 6120:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 6121:             foreach my $item (@fields) {
 6122:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 6123:                     $modifyhash{$context}{$role}{$item} = 1;
 6124:                 } else {
 6125:                     $modifyhash{$context}{$role}{$item} = 0;
 6126:                 }
 6127:             }
 6128:         }
 6129:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 6130:             foreach my $role (@{$roles{$context}}) {
 6131:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 6132:                     foreach my $field (@fields) {
 6133:                         if ($modifyhash{$context}{$role}{$field} ne 
 6134:                                 $curr_usermodification{$context}{$role}{$field}) {
 6135:                             push(@{$changes{$context}},$role);
 6136:                             last;
 6137:                         }
 6138:                     }
 6139:                 }
 6140:             }
 6141:         } else {
 6142:             foreach my $context (@contexts) {
 6143:                 foreach my $role (@{$roles{$context}}) {
 6144:                     push(@{$changes{$context}},$role);
 6145:                 }
 6146:             }
 6147:         }
 6148:     }
 6149:     my %usermodification_hash =  (
 6150:                                    usermodification => \%modifyhash,
 6151:                                  );
 6152:     my $putresult = &Apache::lonnet::put_dom('configuration',
 6153:                                              \%usermodification_hash,$dom);
 6154:     if ($putresult eq 'ok') {
 6155:         if (keys(%changes) > 0) {
 6156:             $resulttext = &mt('Changes made: ').'<ul>';
 6157:             foreach my $context (@contexts) {
 6158:                 if (ref($changes{$context}) eq 'ARRAY') {
 6159:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 6160:                     if (ref($changes{$context}) eq 'ARRAY') {
 6161:                         foreach my $role (@{$changes{$context}}) {
 6162:                             my $rolename;
 6163:                             if ($context eq 'selfcreate') {
 6164:                                 $rolename = $role;
 6165:                                 if (ref($usertypes) eq 'HASH') {
 6166:                                     if ($usertypes->{$role} ne '') {
 6167:                                         $rolename = $usertypes->{$role};
 6168:                                     }
 6169:                                 }
 6170:                             } else {
 6171:                                 if ($role eq 'cr') {
 6172:                                     $rolename = &mt('Custom');
 6173:                                 } else {
 6174:                                     $rolename = &Apache::lonnet::plaintext($role);
 6175:                                 }
 6176:                             }
 6177:                             my @modifiable;
 6178:                             if ($context eq 'selfcreate') {
 6179:                                 $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): ');
 6180:                             } else {
 6181:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 6182:                             }
 6183:                             foreach my $field (@fields) {
 6184:                                 if ($modifyhash{$context}{$role}{$field}) {
 6185:                                     push(@modifiable,$fieldtitles{$field});
 6186:                                 }
 6187:                             }
 6188:                             if (@modifiable > 0) {
 6189:                                 $resulttext .= join(', ',@modifiable);
 6190:                             } else {
 6191:                                 $resulttext .= &mt('none'); 
 6192:                             }
 6193:                             $resulttext .= '</li>';
 6194:                         }
 6195:                         $resulttext .= '</ul></li>';
 6196:                     }
 6197:                 }
 6198:             }
 6199:             $resulttext .= '</ul>';
 6200:         } else {
 6201:             $resulttext = &mt('No changes made to user modification settings');
 6202:         }
 6203:     } else {
 6204:         $resulttext = '<span class="LC_error">'.
 6205:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6206:     }
 6207:     return $resulttext;
 6208: }
 6209: 
 6210: sub modify_defaults {
 6211:     my ($dom,$r) = @_;
 6212:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 6213:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6214:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
 6215:     my @authtypes = ('internal','krb4','krb5','localauth');
 6216:     foreach my $item (@items) {
 6217:         $newvalues{$item} = $env{'form.'.$item};
 6218:         if ($item eq 'auth_def') {
 6219:             if ($newvalues{$item} ne '') {
 6220:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 6221:                     push(@errors,$item);
 6222:                 }
 6223:             }
 6224:         } elsif ($item eq 'lang_def') {
 6225:             if ($newvalues{$item} ne '') {
 6226:                 if ($newvalues{$item} =~ /^(\w+)/) {
 6227:                     my $langcode = $1;
 6228:                     if ($langcode ne 'x_chef') {
 6229:                         if (code2language($langcode) eq '') {
 6230:                             push(@errors,$item);
 6231:                         }
 6232:                     }
 6233:                 } else {
 6234:                     push(@errors,$item);
 6235:                 }
 6236:             }
 6237:         } elsif ($item eq 'timezone_def') {
 6238:             if ($newvalues{$item} ne '') {
 6239:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 6240:                     push(@errors,$item);   
 6241:                 }
 6242:             }
 6243:         } elsif ($item eq 'datelocale_def') {
 6244:             if ($newvalues{$item} ne '') {
 6245:                 my @datelocale_ids = DateTime::Locale->ids();
 6246:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 6247:                     push(@errors,$item);
 6248:                 }
 6249:             }
 6250:         } elsif ($item eq 'portal_def') {
 6251:             if ($newvalues{$item} ne '') {
 6252:                 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])\/?$/) {
 6253:                     push(@errors,$item);
 6254:                 }
 6255:             }
 6256:         }
 6257:         if (grep(/^\Q$item\E$/,@errors)) {
 6258:             $newvalues{$item} = $domdefaults{$item};
 6259:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 6260:             $changes{$item} = 1;
 6261:         }
 6262:         $domdefaults{$item} = $newvalues{$item};
 6263:     }
 6264:     my %defaults_hash = (
 6265:                          defaults => \%newvalues,
 6266:                         );
 6267:     my $title = &defaults_titles();
 6268:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 6269:                                              $dom);
 6270:     if ($putresult eq 'ok') {
 6271:         if (keys(%changes) > 0) {
 6272:             $resulttext = &mt('Changes made:').'<ul>';
 6273:             my $version = $r->dir_config('lonVersion');
 6274:             my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
 6275:             foreach my $item (sort(keys(%changes))) {
 6276:                 my $value = $env{'form.'.$item};
 6277:                 if ($value eq '') {
 6278:                     $value = &mt('none');
 6279:                 } elsif ($item eq 'auth_def') {
 6280:                     my %authnames = &authtype_names();
 6281:                     my %shortauth = (
 6282:                              internal => 'int',
 6283:                              krb4 => 'krb4',
 6284:                              krb5 => 'krb5',
 6285:                              localauth  => 'loc',
 6286:                     );
 6287:                     $value = $authnames{$shortauth{$value}};
 6288:                 }
 6289:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 6290:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
 6291:             }
 6292:             $resulttext .= '</ul>';
 6293:             $mailmsgtext .= "\n";
 6294:             my $cachetime = 24*60*60;
 6295:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6296:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 6297:                 my $sysmail = $r->dir_config('lonSysEMail');
 6298:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
 6299:             }
 6300:         } else {
 6301:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 6302:         }
 6303:     } else {
 6304:         $resulttext = '<span class="LC_error">'.
 6305:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6306:     }
 6307:     if (@errors > 0) {
 6308:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 6309:         foreach my $item (@errors) {
 6310:             $resulttext .= ' "'.$title->{$item}.'",';
 6311:         }
 6312:         $resulttext =~ s/,$//;
 6313:     }
 6314:     return $resulttext;
 6315: }
 6316: 
 6317: sub modify_scantron {
 6318:     my ($r,$dom,$confname,%domconfig) = @_;
 6319:     my ($resulttext,%confhash,%changes,$errors);
 6320:     my $custom = 'custom.tab';
 6321:     my $default = 'default.tab';
 6322:     my $servadm = $r->dir_config('lonAdmEMail');
 6323:     my ($configuserok,$author_ok,$switchserver) = 
 6324:         &config_check($dom,$confname,$servadm);
 6325:     if ($env{'form.scantronformat.filename'} ne '') {
 6326:         my $error;
 6327:         if ($configuserok eq 'ok') {
 6328:             if ($switchserver) {
 6329:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
 6330:             } else {
 6331:                 if ($author_ok eq 'ok') {
 6332:                     my ($result,$scantronurl) =
 6333:                         &publishlogo($r,'upload','scantronformat',$dom,
 6334:                                      $confname,'scantron','','',$custom);
 6335:                     if ($result eq 'ok') {
 6336:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 6337:                         $changes{'scantronformat'} = 1;
 6338:                     } else {
 6339:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 6340:                     }
 6341:                 } else {
 6342:                     $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$custom,$confname,$dom,$author_ok);
 6343:                 }
 6344:             }
 6345:         } else {
 6346:             $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$custom,$confname,$dom,$configuserok);
 6347:         }
 6348:         if ($error) {
 6349:             &Apache::lonnet::logthis($error);
 6350:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6351:         }
 6352:     }
 6353:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 6354:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 6355:             if ($env{'form.scantronformat_del'}) {
 6356:                 $confhash{'scantron'}{'scantronformat'} = '';
 6357:                 $changes{'scantronformat'} = 1;
 6358:             }
 6359:         }
 6360:     }
 6361:     if (keys(%confhash) > 0) {
 6362:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 6363:                                                  $dom);
 6364:         if ($putresult eq 'ok') {
 6365:             if (keys(%changes) > 0) {
 6366:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 6367:                     $resulttext = &mt('Changes made:').'<ul>';
 6368:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 6369:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 6370:                     } else {
 6371:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 6372:                     }
 6373:                     $resulttext .= '</ul>';
 6374:                 } else {
 6375:                     $resulttext = &mt('Changes made to bubblesheet format file.');
 6376:                 }
 6377:                 $resulttext .= '</ul>';
 6378:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 6379:             } else {
 6380:                 $resulttext = &mt('No changes made to bubblesheet format file');
 6381:             }
 6382:         } else {
 6383:             $resulttext = '<span class="LC_error">'.
 6384:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 6385:         }
 6386:     } else {
 6387:         $resulttext = &mt('No changes made to bubblesheet format file'); 
 6388:     }
 6389:     if ($errors) {
 6390:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 6391:                        $errors.'</ul>';
 6392:     }
 6393:     return $resulttext;
 6394: }
 6395: 
 6396: sub modify_coursecategories {
 6397:     my ($dom,%domconfig) = @_;
 6398:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 6399:         $cathash);
 6400:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 6401:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 6402:         $cathash = $domconfig{'coursecategories'}{'cats'};
 6403:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 6404:             $changes{'togglecats'} = 1;
 6405:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 6406:         }
 6407:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 6408:             $changes{'categorize'} = 1;
 6409:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 6410:         }
 6411:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
 6412:             $changes{'togglecatscomm'} = 1;
 6413:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
 6414:         }
 6415:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
 6416:             $changes{'categorizecomm'} = 1;
 6417:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
 6418:         }
 6419:     } else {
 6420:         $changes{'togglecats'} = 1;
 6421:         $changes{'categorize'} = 1;
 6422:         $changes{'togglecatscomm'} = 1;
 6423:         $changes{'categorizecomm'} = 1;
 6424:         $domconfig{'coursecategories'} = {
 6425:                                              togglecats => $env{'form.togglecats'},
 6426:                                              categorize => $env{'form.categorize'},
 6427:                                              togglecatscomm => $env{'form.togglecatscomm'},
 6428:                                              categorizecomm => $env{'form.categorizecomm'},
 6429:                                          };
 6430:     }
 6431:     if (ref($cathash) eq 'HASH') {
 6432:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 6433:             push (@deletecategory,'instcode::0');
 6434:         }
 6435:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
 6436:             push(@deletecategory,'communities::0');
 6437:         }
 6438:     }
 6439:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 6440:     if (ref($cathash) eq 'HASH') {
 6441:         if (@deletecategory > 0) {
 6442:             #FIXME Need to remove category from all courses using a deleted category 
 6443:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 6444:             foreach my $item (@deletecategory) {
 6445:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 6446:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 6447:                     $deletions{$item} = 1;
 6448:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 6449:                 }
 6450:             }
 6451:         }
 6452:         foreach my $item (keys(%{$cathash})) {
 6453:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 6454:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 6455:                 $reorderings{$item} = 1;
 6456:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 6457:             }
 6458:             if ($env{'form.addcategory_name_'.$item} ne '') {
 6459:                 my $newcat = $env{'form.addcategory_name_'.$item};
 6460:                 my $newdepth = $depth+1;
 6461:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 6462:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 6463:                 $adds{$newitem} = 1; 
 6464:             }
 6465:             if ($env{'form.subcat_'.$item} ne '') {
 6466:                 my $newcat = $env{'form.subcat_'.$item};
 6467:                 my $newdepth = $depth+1;
 6468:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 6469:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 6470:                 $adds{$newitem} = 1;
 6471:             }
 6472:         }
 6473:     }
 6474:     if ($env{'form.instcode'} eq '1') {
 6475:         if (ref($cathash) eq 'HASH') {
 6476:             my $newitem = 'instcode::0';
 6477:             if ($cathash->{$newitem} eq '') {  
 6478:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 6479:                 $adds{$newitem} = 1;
 6480:             }
 6481:         } else {
 6482:             my $newitem = 'instcode::0';
 6483:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 6484:             $adds{$newitem} = 1;
 6485:         }
 6486:     }
 6487:     if ($env{'form.communities'} eq '1') {
 6488:         if (ref($cathash) eq 'HASH') {
 6489:             my $newitem = 'communities::0';
 6490:             if ($cathash->{$newitem} eq '') {
 6491:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 6492:                 $adds{$newitem} = 1;
 6493:             }
 6494:         } else {
 6495:             my $newitem = 'communities::0';
 6496:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 6497:             $adds{$newitem} = 1;
 6498:         }
 6499:     }
 6500:     if ($env{'form.addcategory_name'} ne '') {
 6501:         if (($env{'form.addcategory_name'} ne 'instcode') &&
 6502:             ($env{'form.addcategory_name'} ne 'communities')) {
 6503:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 6504:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 6505:             $adds{$newitem} = 1;
 6506:         }
 6507:     }
 6508:     my $putresult;
 6509:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6510:         if (keys(%deletions) > 0) {
 6511:             foreach my $key (keys(%deletions)) {
 6512:                 if ($predelallitems{$key} ne '') {
 6513:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 6514:                 }
 6515:             }
 6516:         }
 6517:         my (@chkcats,@chktrails,%chkallitems);
 6518:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 6519:         if (ref($chkcats[0]) eq 'ARRAY') {
 6520:             my $depth = 0;
 6521:             my $chg = 0;
 6522:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 6523:                 my $name = $chkcats[0][$i];
 6524:                 my $item;
 6525:                 if ($name eq '') {
 6526:                     $chg ++;
 6527:                 } else {
 6528:                     $item = &escape($name).'::0';
 6529:                     if ($chg) {
 6530:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 6531:                     }
 6532:                     $depth ++; 
 6533:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 6534:                     $depth --;
 6535:                 }
 6536:             }
 6537:         }
 6538:     }
 6539:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6540:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 6541:         if ($putresult eq 'ok') {
 6542:             my %title = (
 6543:                          togglecats     => 'Show/Hide a course in catalog',
 6544:                          categorize     => 'Assign a category to a course',
 6545:                          togglecatscomm => 'Show/Hide a community in catalog',
 6546:                          categorizecomm => 'Assign a category to a community',
 6547:                         );
 6548:             my %level = (
 6549:                          dom  => 'set in Domain ("Modify Course/Community")',
 6550:                          crs  => 'set in Course ("Course Configuration")',
 6551:                          comm => 'set in Community ("Community Configuration")',
 6552:                         );
 6553:             $resulttext = &mt('Changes made:').'<ul>';
 6554:             if ($changes{'togglecats'}) {
 6555:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 6556:             }
 6557:             if ($changes{'categorize'}) {
 6558:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 6559:             }
 6560:             if ($changes{'togglecatscomm'}) {
 6561:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
 6562:             }
 6563:             if ($changes{'categorizecomm'}) {
 6564:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
 6565:             }
 6566:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6567:                 my $cathash;
 6568:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 6569:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 6570:                 } else {
 6571:                     $cathash = {};
 6572:                 } 
 6573:                 my (@cats,@trails,%allitems);
 6574:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 6575:                 if (keys(%deletions) > 0) {
 6576:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 6577:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 6578:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 6579:                     }
 6580:                     $resulttext .= '</ul></li>';
 6581:                 }
 6582:                 if (keys(%reorderings) > 0) {
 6583:                     my %sort_by_trail;
 6584:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 6585:                     foreach my $key (keys(%reorderings)) {
 6586:                         if ($allitems{$key} ne '') {
 6587:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 6588:                         }
 6589:                     }
 6590:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 6591:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 6592:                     }
 6593:                     $resulttext .= '</ul></li>';
 6594:                 }
 6595:                 if (keys(%adds) > 0) {
 6596:                     my %sort_by_trail;
 6597:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
 6598:                     foreach my $key (keys(%adds)) {
 6599:                         if ($allitems{$key} ne '') {
 6600:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 6601:                         }
 6602:                     }
 6603:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 6604:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 6605:                     }
 6606:                     $resulttext .= '</ul></li>';
 6607:                 }
 6608:             }
 6609:             $resulttext .= '</ul>';
 6610:         } else {
 6611:             $resulttext = '<span class="LC_error">'.
 6612:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 6613:         }
 6614:     } else {
 6615:         $resulttext = &mt('No changes made to course and community categories');
 6616:     }
 6617:     return $resulttext;
 6618: }
 6619: 
 6620: sub modify_serverstatuses {
 6621:     my ($dom,%domconfig) = @_;
 6622:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
 6623:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
 6624:         %currserverstatus = %{$domconfig{'serverstatuses'}};
 6625:     }
 6626:     my @pages = &serverstatus_pages();
 6627:     foreach my $type (@pages) {
 6628:         $newserverstatus{$type}{'namedusers'} = '';
 6629:         $newserverstatus{$type}{'machines'} = '';
 6630:         if (defined($env{'form.'.$type.'_namedusers'})) {
 6631:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
 6632:             my @okusers;
 6633:             foreach my $user (@users) {
 6634:                 my ($uname,$udom) = split(/:/,$user);
 6635:                 if (($udom =~ /^$match_domain$/) &&   
 6636:                     (&Apache::lonnet::domain($udom)) &&
 6637:                     ($uname =~ /^$match_username$/)) {
 6638:                     if (!grep(/^\Q$user\E/,@okusers)) {
 6639:                         push(@okusers,$user);
 6640:                     }
 6641:                 }
 6642:             }
 6643:             if (@okusers > 0) {
 6644:                  @okusers = sort(@okusers);
 6645:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
 6646:             }
 6647:         }
 6648:         if (defined($env{'form.'.$type.'_machines'})) {
 6649:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
 6650:             my @okmachines;
 6651:             foreach my $ip (@machines) {
 6652:                 my @parts = split(/\./,$ip);
 6653:                 next if (@parts < 4);
 6654:                 my $badip = 0;
 6655:                 for (my $i=0; $i<4; $i++) {
 6656:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
 6657:                         $badip = 1;
 6658:                         last;
 6659:                     }
 6660:                 }
 6661:                 if (!$badip) {
 6662:                     push(@okmachines,$ip);     
 6663:                 }
 6664:             }
 6665:             @okmachines = sort(@okmachines);
 6666:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
 6667:         }
 6668:     }
 6669:     my %serverstatushash =  (
 6670:                                 serverstatuses => \%newserverstatus,
 6671:                             );
 6672:     foreach my $type (@pages) {
 6673:         foreach my $setting ('namedusers','machines') {
 6674:             my (@current,@new);
 6675:             if (ref($currserverstatus{$type}) eq 'HASH') {
 6676:                 if ($currserverstatus{$type}{$setting} ne '') { 
 6677:                     @current = split(/,/,$currserverstatus{$type}{$setting});
 6678:                 }
 6679:             }
 6680:             if ($newserverstatus{$type}{$setting} ne '') {
 6681:                 @new = split(/,/,$newserverstatus{$type}{$setting});
 6682:             }
 6683:             if (@current > 0) {
 6684:                 if (@new > 0) {
 6685:                     foreach my $item (@current) {
 6686:                         if (!grep(/^\Q$item\E$/,@new)) {
 6687:                             $changes{$type}{$setting} = 1;
 6688:                             last;
 6689:                         }
 6690:                     }
 6691:                     foreach my $item (@new) {
 6692:                         if (!grep(/^\Q$item\E$/,@current)) {
 6693:                             $changes{$type}{$setting} = 1;
 6694:                             last;
 6695:                         }
 6696:                     }
 6697:                 } else {
 6698:                     $changes{$type}{$setting} = 1;
 6699:                 }
 6700:             } elsif (@new > 0) {
 6701:                 $changes{$type}{$setting} = 1;
 6702:             }
 6703:         }
 6704:     }
 6705:     if (keys(%changes) > 0) {
 6706:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 6707:         my $putresult = &Apache::lonnet::put_dom('configuration',
 6708:                                                  \%serverstatushash,$dom);
 6709:         if ($putresult eq 'ok') {
 6710:             $resulttext .= &mt('Changes made:').'<ul>';
 6711:             foreach my $type (@pages) {
 6712:                 if (ref($changes{$type}) eq 'HASH') {
 6713:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
 6714:                     if ($changes{$type}{'namedusers'}) {
 6715:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
 6716:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
 6717:                         } else {
 6718:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
 6719:                         }
 6720:                     }
 6721:                     if ($changes{$type}{'machines'}) {
 6722:                         if ($newserverstatus{$type}{'machines'} eq '') {
 6723:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
 6724:                         } else {
 6725:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
 6726:                         }
 6727: 
 6728:                     }
 6729:                     $resulttext .= '</ul></li>';
 6730:                 }
 6731:             }
 6732:             $resulttext .= '</ul>';
 6733:         } else {
 6734:             $resulttext = '<span class="LC_error">'.
 6735:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
 6736: 
 6737:         }
 6738:     } else {
 6739:         $resulttext = &mt('No changes made to access to server status pages');
 6740:     }
 6741:     return $resulttext;
 6742: }
 6743: 
 6744: sub modify_helpsettings {
 6745:     my ($r,$dom,$confname,%domconfig) = @_;
 6746:  	my ($resulttext,$errors,%changes,%helphash);
 6747:  	
 6748:  	my $customhelpfile  = $env{'form.loginhelpurl.filename'};
 6749:     my $defaulthelpfile = 'defaulthelp.html';
 6750:  	my $servadm = $r->dir_config('lonAdmEMail');
 6751:     my ($configuserok,$author_ok,$switchserver) = 
 6752:         &config_check($dom,$confname,$servadm);
 6753:  	
 6754:  	my %defaultchecked = ('submitbugs'	=> 'on');
 6755:  	my @offon = ('off','on');
 6756:     my %title = ( submitbugs     => 'Display link for users to submit a bug', 
 6757:     			  loginhelpurl  => 'Unauthenticated login help page set to custom file');
 6758:     			  
 6759:     my @toggles = ('submitbugs');
 6760: 
 6761:     $helphash{'helpsettings'} = {};
 6762:     
 6763:     if (ref($domconfig{'helpsettings'}) ne 'HASH') {
 6764:         if ($domconfig{'helpsettings'} eq '') {
 6765:             $domconfig{'helpsettings'} = {};
 6766:         }
 6767:     }
 6768:     
 6769:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
 6770:     	
 6771:         foreach my $item (@toggles) {
 6772:         	
 6773: 			if ($defaultchecked{$item} eq 'on') { 
 6774: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
 6775: 					 ($env{'form.'.$item} eq '0')) {
 6776: 					$changes{$item} = 1;
 6777: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 6778: 					$changes{$item} = 1;
 6779: 				}
 6780: 			} elsif ($defaultchecked{$item} eq 'off') {
 6781: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
 6782: 					 ($env{'form.'.$item} eq '1')) {
 6783: 					$changes{$item} = 1;
 6784: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 6785: 					$changes{$item} = 1;
 6786: 				}
 6787: 			}
 6788: 			$helphash{'helpsettings'}{$item} = $env{'form.'.$item};
 6789: 		}
 6790: 		
 6791: 		if ($customhelpfile ne '') {
 6792: 			my $error;
 6793: 			if ($configuserok eq 'ok') {
 6794: 				if ($switchserver) {
 6795: 					$error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
 6796: 				} else {
 6797: 					if ($author_ok eq 'ok') {
 6798: 						my ($result,$loginhelpurl) =
 6799: 							&publishlogo($r,'upload','loginhelpurl',$dom,
 6800: 										 $confname,'help','','',$customhelpfile);
 6801: 						if ($result eq 'ok') {
 6802: 							$helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
 6803: 							$changes{'loginhelpurl'} = 1;
 6804: 						} else {
 6805: 							$error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
 6806: 						}
 6807: 					} else {
 6808: 						$error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$author_ok);
 6809: 					}
 6810: 				}
 6811: 			} else {
 6812: 				$error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
 6813: 			}
 6814: 			if ($error) {
 6815: 				&Apache::lonnet::logthis($error);
 6816: 				$errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6817: 			}
 6818: 		}
 6819: 		
 6820:         if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
 6821:             if ($env{'form.loginhelpurl_del'}) {
 6822:                 $helphash{'helpsettings'}{'loginhelpurl'} = '';
 6823:                 $changes{'loginhelpurl'} = 1;
 6824:             }
 6825:         }
 6826:     }
 6827:     
 6828:     
 6829:     my $putresult;
 6830:     
 6831:     if (keys(%changes) > 0) {
 6832:     	$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
 6833:     } else {
 6834:     	$putresult = 'ok';
 6835:     }
 6836:                                              
 6837:     if ($putresult eq 'ok') {
 6838:         if (keys(%changes) > 0) {
 6839: 			$resulttext = &mt('Changes made:').'<ul>';
 6840: 			foreach my $item (sort(keys(%changes))) {
 6841: 				if ($item eq 'submitbugs') {
 6842: 					$resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 6843: 				}
 6844: 				if ($item eq 'loginhelpurl') {
 6845: 					if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
 6846:                         $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
 6847:                     } else {
 6848:                         $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
 6849:                     }
 6850: 				}
 6851: 			}
 6852: 			$resulttext .= '</ul>';
 6853: 		} else {
 6854: 			$resulttext = &mt('No changes made to help settings');
 6855: 		}
 6856:     } else {
 6857:         $resulttext = '<span class="LC_error">'.
 6858: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6859:     }
 6860:     if ($errors) {
 6861:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 6862:                        $errors.'</ul>';
 6863:     }
 6864:     return $resulttext;
 6865: }
 6866: 
 6867: sub modify_coursedefaults {
 6868:     my ($dom,%domconfig) = @_;
 6869:     my ($resulttext,$errors,%changes,%defaultshash);
 6870:     my %defaultchecked = ('canuse_pdfforms' => 'off');
 6871:     my @offon = ('off','on');
 6872:     my @toggles = ('canuse_pdfforms');
 6873: 
 6874:     $defaultshash{'coursedefaults'} = {};
 6875: 
 6876:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
 6877:         if ($domconfig{'coursedefaults'} eq '') {
 6878:             $domconfig{'coursedefaults'} = {};
 6879:         }
 6880:     }
 6881: 
 6882:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
 6883:         foreach my $item (@toggles) {
 6884:             if ($defaultchecked{$item} eq 'on') {
 6885:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 6886:                     ($env{'form.'.$item} eq '0')) {
 6887:                     $changes{$item} = 1;
 6888:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
 6889:                     $changes{$item} = 1;
 6890:                 }
 6891:             } elsif ($defaultchecked{$item} eq 'off') {
 6892:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 6893:                     ($env{'form.'.$item} eq '1')) {
 6894:                     $changes{$item} = 1;
 6895:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 6896:                     $changes{$item} = 1;
 6897:                 }
 6898:             }
 6899:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
 6900:         }
 6901:         my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
 6902:         my $newdefresponder = $env{'form.anonsurvey_threshold'};
 6903:         $newdefresponder =~ s/\D//g;
 6904:         if ($newdefresponder eq '' || $newdefresponder < 1) {
 6905:             $newdefresponder = 1;
 6906:         }
 6907:         $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
 6908:         if ($currdefresponder ne $newdefresponder) {
 6909:             unless ($currdefresponder eq '' && $newdefresponder == 10) {
 6910:                 $changes{'anonsurvey_threshold'} = 1;
 6911:             }
 6912:         }
 6913:     }
 6914:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 6915:                                              $dom);
 6916:     if ($putresult eq 'ok') {
 6917:         if (keys(%changes) > 0) {
 6918:             if ($changes{'canuse_pdfforms'}) {
 6919:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6920:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
 6921:                 my $cachetime = 24*60*60;
 6922:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6923:             }
 6924:             $resulttext = &mt('Changes made:').'<ul>';
 6925:             foreach my $item (sort(keys(%changes))) {
 6926:                 if ($item eq 'canuse_pdfforms') {
 6927:                     if ($env{'form.'.$item} eq '1') {
 6928:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
 6929:                     } else {
 6930:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
 6931:                     }
 6932:                 } elsif ($item eq 'anonsurvey_threshold') {
 6933:                         $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
 6934:                 }
 6935:             }
 6936:             $resulttext .= '</ul>';
 6937:         } else {
 6938:             $resulttext = &mt('No changes made to course defaults');
 6939:         }
 6940:     } else {
 6941:         $resulttext = '<span class="LC_error">'.
 6942:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6943:     }
 6944:     return $resulttext;
 6945: }
 6946: 
 6947: sub modify_usersessions {
 6948:     my ($dom,%domconfig) = @_;
 6949:     my @hostingtypes = ('version','excludedomain','includedomain');
 6950:     my @offloadtypes = ('primary','default');
 6951:     my %types = (
 6952:                   remote => \@hostingtypes,
 6953:                   hosted => \@hostingtypes,
 6954:                   spares => \@offloadtypes,
 6955:                 );
 6956:     my @prefixes = ('remote','hosted','spares');
 6957:     my @lcversions = &Apache::lonnet::all_loncaparevs();
 6958:     my (%by_ip,%by_location,@intdoms);
 6959:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 6960:     my @locations = sort(keys(%by_location));
 6961:     my (%defaultshash,%changes);
 6962:     foreach my $prefix (@prefixes) {
 6963:         $defaultshash{'usersessions'}{$prefix} = {};
 6964:     }
 6965:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6966:     my $resulttext;
 6967:     my %iphost = &Apache::lonnet::get_iphost();
 6968:     foreach my $prefix (@prefixes) {
 6969:         next if ($prefix eq 'spares');
 6970:         foreach my $type (@{$types{$prefix}}) {
 6971:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
 6972:             if ($type eq 'version') {
 6973:                 my $value = $env{'form.'.$prefix.'_'.$type};
 6974:                 my $okvalue;
 6975:                 if ($value ne '') {
 6976:                     if (grep(/^\Q$value\E$/,@lcversions)) {
 6977:                         $okvalue = $value;
 6978:                     }
 6979:                 }
 6980:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 6981:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 6982:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
 6983:                             if ($inuse == 0) {
 6984:                                 $changes{$prefix}{$type} = 1;
 6985:                             } else {
 6986:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
 6987:                                     $changes{$prefix}{$type} = 1;
 6988:                                 }
 6989:                                 if ($okvalue ne '') {
 6990:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6991:                                 } 
 6992:                             }
 6993:                         } else {
 6994:                             if (($inuse == 1) && ($okvalue ne '')) {
 6995:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6996:                                 $changes{$prefix}{$type} = 1;
 6997:                             }
 6998:                         }
 6999:                     } else {
 7000:                         if (($inuse == 1) && ($okvalue ne '')) {
 7001:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 7002:                             $changes{$prefix}{$type} = 1;
 7003:                         }
 7004:                     }
 7005:                 } else {
 7006:                     if (($inuse == 1) && ($okvalue ne '')) {
 7007:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 7008:                         $changes{$prefix}{$type} = 1;
 7009:                     }
 7010:                 }
 7011:             } else {
 7012:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
 7013:                 my @okvals;
 7014:                 foreach my $val (@vals) {
 7015:                     if ($val =~ /:/) {
 7016:                         my @items = split(/:/,$val);
 7017:                         foreach my $item (@items) {
 7018:                             if (ref($by_location{$item}) eq 'ARRAY') {
 7019:                                 push(@okvals,$item);
 7020:                             }
 7021:                         }
 7022:                     } else {
 7023:                         if (ref($by_location{$val}) eq 'ARRAY') {
 7024:                             push(@okvals,$val);
 7025:                         }
 7026:                     }
 7027:                 }
 7028:                 @okvals = sort(@okvals);
 7029:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 7030:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 7031:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 7032:                             if ($inuse == 0) {
 7033:                                 $changes{$prefix}{$type} = 1; 
 7034:                             } else {
 7035:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 7036:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
 7037:                                 if (@changed > 0) {
 7038:                                     $changes{$prefix}{$type} = 1;
 7039:                                 }
 7040:                             }
 7041:                         } else {
 7042:                             if ($inuse == 1) {
 7043:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 7044:                                 $changes{$prefix}{$type} = 1;
 7045:                             }
 7046:                         } 
 7047:                     } else {
 7048:                         if ($inuse == 1) {
 7049:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 7050:                             $changes{$prefix}{$type} = 1;
 7051:                         }
 7052:                     }
 7053:                 } else {
 7054:                     if ($inuse == 1) {
 7055:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 7056:                         $changes{$prefix}{$type} = 1;
 7057:                     }
 7058:                 }
 7059:             }
 7060:         }
 7061:     }
 7062: 
 7063:     my @alldoms = &Apache::lonnet::all_domains();
 7064:     my %uniques = &Apache::lonnet::get_unique_servers(\@alldoms);
 7065:     my %servers = &dom_servers($dom);
 7066:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
 7067:     my $savespares;
 7068: 
 7069:     foreach my $lonhost (sort(keys(%servers))) {
 7070:         my $serverhomeID =
 7071:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
 7072:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
 7073:         my %spareschg;
 7074:         foreach my $type (@{$types{'spares'}}) {
 7075:             my @okspares;
 7076:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
 7077:             foreach my $server (@checked) {
 7078:                 unless (($server eq $lonhost) || ($server eq $serverhomeID)) {
 7079:                     if ($uniques{$server}) {
 7080:                         push(@okspares,$server);
 7081:                     }
 7082:                 }
 7083:             }
 7084:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
 7085:             my $newspare;
 7086:             if (($new ne '') && ($uniques{$new})) {
 7087:                 unless (($new eq $lonhost) || ($new eq $serverhomeID)) {
 7088:                     $newspare = $new;
 7089:                     $spareschg{$type} = 1;
 7090:                 }
 7091:             }
 7092:             if (ref($spareid{$lonhost}) eq 'HASH') {
 7093:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
 7094:                     my @diffs = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{'spares'}{$lonhost}{$type},\@okspares);
 7095:                     if (@diffs > 0) {
 7096:                         $spareschg{$type} = 1;
 7097:                     } elsif ($new ne '') {
 7098:                         $spareschg{$type} = 1;
 7099:                     }
 7100:                 }
 7101:             }
 7102:             my @spares;
 7103:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
 7104:                 @spares = sort(@okspares,$newspare);
 7105:             } else {
 7106:                 @spares = sort(@okspares);
 7107:             }
 7108:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
 7109:         }
 7110:         if (keys(%spareschg) > 0) {
 7111:             $changes{'spares'}{$lonhost} = \%spareschg;
 7112:         }
 7113:     }
 7114: 
 7115:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
 7116:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
 7117:             if (ref($changes{'spares'}) eq 'HASH') {
 7118:                 if (keys(%{$changes{'spares'}}) > 0) {
 7119:                     $savespares = 1;
 7120:                 }
 7121:             }
 7122:         } else {
 7123:             $savespares = 1;
 7124:         }
 7125:     }
 7126: 
 7127:     if (keys(%changes) > 0) {
 7128:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 7129:                                                  $dom);
 7130:         if ($putresult eq 'ok') {
 7131:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 7132:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
 7133:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
 7134:                 }
 7135:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
 7136:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
 7137:                 }
 7138:             }
 7139:             my $cachetime = 24*60*60;
 7140:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 7141:             my %lt = &usersession_titles();
 7142:             $resulttext = &mt('Changes made:').'<ul>';
 7143:             foreach my $prefix (@prefixes) {
 7144:                 if (ref($changes{$prefix}) eq 'HASH') {
 7145:                     $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
 7146:                     if ($prefix eq 'spares') {
 7147:                         if (ref($changes{$prefix}) eq 'HASH') {
 7148:                             foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
 7149:                                 $resulttext .= '<li><b>'.$lonhost.'</b> ';
 7150:                                 if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
 7151:                                     foreach my $type (@{$types{$prefix}}) {
 7152:                                         if ($changes{$prefix}{$lonhost}{$type}) {
 7153:                                             my $offloadto = &mt('None');
 7154:                                             if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
 7155:                                                 if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
 7156:                                                     $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
 7157:                                                 }
 7158:                                             }
 7159:                                             $resulttext .= &mt('[_1] set to: [_2]','<i>'.$lt{'type'}.'</i>',$offloadto).('&nbsp;'x3);
 7160:                                         }
 7161:                                     }
 7162:                                 }
 7163:                                 $resulttext .= '</li>';
 7164:                             }
 7165:                         }
 7166:                     } else {
 7167:                         foreach my $type (@{$types{$prefix}}) {
 7168:                             if (defined($changes{$prefix}{$type})) {
 7169:                                 my $newvalue;
 7170:                                 if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 7171:                                     if (ref($defaultshash{'usersessions'}{$prefix})) {
 7172:                                         if ($type eq 'version') {
 7173:                                             $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
 7174:                                         } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 7175:                                             if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
 7176:                                                 $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
 7177:                                             }
 7178:                                         }
 7179:                                     }
 7180:                                 }
 7181:                                 if ($newvalue eq '') {
 7182:                                     if ($type eq 'version') {
 7183:                                         $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
 7184:                                     } else {
 7185:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
 7186:                                     }
 7187:                                 } else {
 7188:                                     if ($type eq 'version') {
 7189:                                         $newvalue .= ' '.&mt('(or later)'); 
 7190:                                     }
 7191:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
 7192:                                 }
 7193:                             }
 7194:                         }
 7195:                     }
 7196:                     $resulttext .= '</ul>';
 7197:                 }
 7198:             }
 7199:             $resulttext .= '</ul>';
 7200:         } else {
 7201:             $resulttext = '<span class="LC_error">'.
 7202:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 7203:         }
 7204:     } else {
 7205:         $resulttext =  &mt('No changes made to settings for user session hosting/offloading.');
 7206:     }
 7207:     return $resulttext;
 7208: }
 7209: 
 7210: sub recurse_check {
 7211:     my ($chkcats,$categories,$depth,$name) = @_;
 7212:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
 7213:         my $chg = 0;
 7214:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
 7215:             my $category = $chkcats->[$depth]{$name}[$j];
 7216:             my $item;
 7217:             if ($category eq '') {
 7218:                 $chg ++;
 7219:             } else {
 7220:                 my $deeper = $depth + 1;
 7221:                 $item = &escape($category).':'.&escape($name).':'.$depth;
 7222:                 if ($chg) {
 7223:                     $categories->{$item} -= $chg;
 7224:                 }
 7225:                 &recurse_check($chkcats,$categories,$deeper,$category);
 7226:                 $deeper --;
 7227:             }
 7228:         }
 7229:     }
 7230:     return;
 7231: }
 7232: 
 7233: sub recurse_cat_deletes {
 7234:     my ($item,$coursecategories,$deletions) = @_;
 7235:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 7236:     my $subdepth = $depth + 1;
 7237:     if (ref($coursecategories) eq 'HASH') {
 7238:         foreach my $subitem (keys(%{$coursecategories})) {
 7239:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
 7240:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
 7241:                 delete($coursecategories->{$subitem});
 7242:                 $deletions->{$subitem} = 1;
 7243:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
 7244:             }  
 7245:         }
 7246:     }
 7247:     return;
 7248: }
 7249: 
 7250: sub dom_servers {
 7251:     my ($dom) = @_;
 7252:     my (%uniqservers,%servers);
 7253:     my $primaryserver = &Apache::lonnet::hostname(&Apache::lonnet::domain($dom,'primary'));
 7254:     my @machinedoms = &Apache::lonnet::machine_domains($primaryserver);
 7255:     foreach my $mdom (@machinedoms) {
 7256:         my %currservers = %servers;
 7257:         my %server = &Apache::lonnet::get_servers($mdom);
 7258:         %servers = (%currservers,%server);
 7259:     }
 7260:     my %by_hostname;
 7261:     foreach my $id (keys(%servers)) {
 7262:         push(@{$by_hostname{$servers{$id}}},$id);
 7263:     }
 7264:     foreach my $hostname (sort(keys(%by_hostname))) {
 7265:         if (@{$by_hostname{$hostname}} > 1) {
 7266:             my $match = 0;
 7267:             foreach my $id (@{$by_hostname{$hostname}}) {
 7268:                 if (&Apache::lonnet::host_domain($id) eq $dom) {
 7269:                     $uniqservers{$id} = $hostname;
 7270:                     $match = 1;
 7271:                 }
 7272:             }
 7273:             unless ($match) {
 7274:                 $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
 7275:             }
 7276:         } else {
 7277:             $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
 7278:         }
 7279:     }
 7280:     return %uniqservers;
 7281: }
 7282: 
 7283: sub get_active_dcs {
 7284:     my ($dom) = @_;
 7285:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
 7286:     my %domcoords;
 7287:     my $numdcs = 0;
 7288:     my $now = time;
 7289:     foreach my $server (keys(%dompersonnel)) {
 7290:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 7291:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 7292:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
 7293:             if (($end eq '') || ($end == 0) || ($end > $now)) {
 7294:                 if ($start <= $now) {
 7295:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
 7296:                 }
 7297:             }
 7298:         }
 7299:     }
 7300:     return %domcoords;
 7301: }
 7302: 
 7303: sub active_dc_picker {
 7304:     my ($dom,$curr_dc) = @_;
 7305:     my %domcoords = &get_active_dcs($dom); 
 7306:     my @dcs = sort(keys(%domcoords));
 7307:     my $numdcs = scalar(@dcs); 
 7308:     my $datatable;
 7309:     my $numinrow = 2;
 7310:     if ($numdcs > 1) {
 7311:         $datatable = '<table>';
 7312:         for (my $i=0; $i<@dcs; $i++) {
 7313:             my $rem = $i%($numinrow);
 7314:             if ($rem == 0) {
 7315:                 if ($i > 0) {
 7316:                     $datatable .= '</tr>';
 7317:                 }
 7318:                 $datatable .= '<tr>';
 7319:             }
 7320:             my $check = ' ';
 7321:             if ($curr_dc eq '') {
 7322:                 if (!$i) { 
 7323:                     $check = ' checked="checked" ';
 7324:                 }
 7325:             } elsif ($dcs[$i] eq $curr_dc) {
 7326:                 $check = ' checked="checked" ';
 7327:             }
 7328:             if ($i == @dcs - 1) {
 7329:                 my $colsleft = $numinrow - $rem;
 7330:                 if ($colsleft > 1) {
 7331:                     $datatable .= '<td colspan="'.$colsleft.'">';
 7332:                 } else {
 7333:                     $datatable .= '<td>';
 7334:                 }
 7335:             } else {
 7336:                 $datatable .= '<td>';
 7337:             }
 7338:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
 7339:             $datatable .= '<span class="LC_nobreak"><label>'.
 7340:                           '<input type="radio" name="autocreate_xmldc"'.
 7341:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
 7342:                           &Apache::loncommon::plainname($dcname,$dcdom).
 7343:                           '</label></span></td>';
 7344:         }
 7345:         $datatable .= '</tr></table>';
 7346:     } elsif (@dcs) {
 7347:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
 7348:                       $dcs[0].'" />';
 7349:     }
 7350:     return ($numdcs,$datatable);
 7351: }
 7352: 
 7353: sub usersession_titles {
 7354:     return &Apache::lonlocal::texthash(
 7355:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
 7356: 
 7357:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
 7358:                spares => 'Servers offloaded to, when busy',
 7359:                version => 'LON-CAPA version requirement',
 7360:                excludedomain => 'Allow all, but exclude specific domains',
 7361:                includedomain => 'Deny all, but include specific domains',
 7362:                primary => 'Primary (checked first)',
 7363:                default => 'Default', 
 7364:            );
 7365: }
 7366: 
 7367: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>