File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.204: download - view: text, annotated - select for diffs
Tue Aug 13 16:19:26 2013 UTC (10 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Fix typo.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.204 2013/08/13 16:19:26 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 affiliated 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 (quotas,  
   90: requestcourses or requestauthor).
   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, and to display/store
   98: default quota sizes for authoring spaces.
   99: 
  100: Outputs: 1
  101: 
  102: $datatable  - HTML containing form elements which allow settings to be changed. 
  103: 
  104: In the case of course requests, radio buttons are displayed for each institutional
  105: affiliate type (and also default, and _LC_adv) for each of the course types 
  106: (official, unofficial and community).  In each case the radio buttons allow the 
  107: selection of one of four values:
  108: 
  109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
  110: which have the following effects:
  111: 
  112: 0
  113: 
  114: =over
  115: 
  116: - course requests are not allowed for this course types/affiliation
  117: 
  118: =back
  119: 
  120: approval 
  121: 
  122: =over 
  123: 
  124: - course requests must be approved by a Doman Coordinator in the 
  125: course's domain
  126: 
  127: =back
  128: 
  129: validate 
  130: 
  131: =over
  132: 
  133: - an institutional validation (e.g., check requestor is instructor
  134: of record) needs to be passed before the course will be created.  The required
  135: validation is in localenroll.pm on the primary library server for the course 
  136: domain.
  137: 
  138: =back
  139: 
  140: autolimit 
  141: 
  142: =over
  143:  
  144: - course requests will be processed automatically up to a limit of
  145: N requests for the course type for the particular requestor.
  146: If N is undefined, there is no limit to the number of course requests
  147: which a course owner may submit and have processed automatically. 
  148: 
  149: =back
  150: 
  151: =item modify_quotas() 
  152: 
  153: =back
  154: 
  155: =cut
  156: 
  157: package Apache::domainprefs;
  158: 
  159: use strict;
  160: use Apache::Constants qw(:common :http);
  161: use Apache::lonnet;
  162: use Apache::loncommon();
  163: use Apache::lonhtmlcommon();
  164: use Apache::lonlocal;
  165: use Apache::lonmsg();
  166: use Apache::lonconfigsettings;
  167: use LONCAPA qw(:DEFAULT :match);
  168: use LONCAPA::Enrollment;
  169: use LONCAPA::lonauthcgi();
  170: use File::Copy;
  171: use Locale::Language;
  172: use DateTime::TimeZone;
  173: use DateTime::Locale;
  174: 
  175: my $registered_cleanup;
  176: my $modified_urls;
  177: 
  178: sub handler {
  179:     my $r=shift;
  180:     if ($r->header_only) {
  181:         &Apache::loncommon::content_type($r,'text/html');
  182:         $r->send_http_header;
  183:         return OK;
  184:     }
  185: 
  186:     my $context = 'domain';
  187:     my $dom = $env{'request.role.domain'};
  188:     my $domdesc = &Apache::lonnet::domain($dom,'description');
  189:     if (&Apache::lonnet::allowed('mau',$dom)) {
  190:         &Apache::loncommon::content_type($r,'text/html');
  191:         $r->send_http_header;
  192:     } else {
  193:         $env{'user.error.msg'}=
  194:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
  195:         return HTTP_NOT_ACCEPTABLE;
  196:     }
  197: 
  198:     $registered_cleanup=0;
  199:     @{$modified_urls}=();
  200: 
  201:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  202:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  203:                                             ['phase','actions']);
  204:     my $phase = 'pickactions';
  205:     if ( exists($env{'form.phase'}) ) {
  206:         $phase = $env{'form.phase'};
  207:     }
  208:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
  209:     my %domconfig =
  210:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
  211:                 'quotas','autoenroll','autoupdate','autocreate',
  212:                 'directorysrch','usercreation','usermodification',
  213:                 'contacts','defaults','scantron','coursecategories',
  214:                 'serverstatuses','requestcourses','helpsettings',
  215:                 'coursedefaults','usersessions','loadbalancing',
  216:                 'requestauthor'],$dom);
  217:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
  218:                        'autoupdate','autocreate','directorysrch','contacts',
  219:                        'usercreation','usermodification','scantron',
  220:                        'requestcourses','requestauthor','coursecategories',
  221:                        'serverstatuses','helpsettings',
  222:                        'coursedefaults','usersessions');
  223:     my %existing;
  224:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
  225:         %existing = %{$domconfig{'loadbalancing'}};
  226:     }
  227:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
  228:         push(@prefs_order,'loadbalancing');
  229:     }
  230:     my %prefs = (
  231:         'rolecolors' =>
  232:                    { text => 'Default color schemes',
  233:                      help => 'Domain_Configuration_Color_Schemes',
  234:                      header => [{col1 => 'Student Settings',
  235:                                  col2 => '',},
  236:                                 {col1 => 'Coordinator Settings',
  237:                                  col2 => '',},
  238:                                 {col1 => 'Author Settings',
  239:                                  col2 => '',},
  240:                                 {col1 => 'Administrator Settings',
  241:                                  col2 => '',}],
  242:                     },
  243:         'login' =>
  244:                     { text => 'Log-in page options',
  245:                       help => 'Domain_Configuration_Login_Page',
  246:                       header => [{col1 => 'Log-in Page Items',
  247:                                   col2 => '',},
  248:                                  {col1 => 'Log-in Help',
  249:                                   col2 => 'Value'}],
  250:                     },
  251:         'defaults' => 
  252:                     { text => 'Default authentication/language/timezone/portal',
  253:                       help => 'Domain_Configuration_LangTZAuth',
  254:                       header => [{col1 => 'Setting',
  255:                                   col2 => 'Value'}],
  256:                     },
  257:         'quotas' => 
  258:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
  259:                       help => 'Domain_Configuration_Quotas',
  260:                       header => [{col1 => 'User affiliation',
  261:                                   col2 => 'Available tools',
  262:                                   col3 => 'Quotas, Mb; (Authoring requires role)',}],
  263:                     },
  264:         'autoenroll' =>
  265:                    { text => 'Auto-enrollment settings',
  266:                      help => 'Domain_Configuration_Auto_Enrollment',
  267:                      header => [{col1 => 'Configuration setting',
  268:                                  col2 => 'Value(s)'}],
  269:                    },
  270:         'autoupdate' => 
  271:                    { text => 'Auto-update settings',
  272:                      help => 'Domain_Configuration_Auto_Updates',
  273:                      header => [{col1 => 'Setting',
  274:                                  col2 => 'Value',},
  275:                                 {col1 => 'Setting',
  276:                                  col2 => 'Affiliation'},
  277:                                 {col1 => 'User population',
  278:                                  col2 => 'Updateable user data'}],
  279:                   },
  280:         'autocreate' => 
  281:                   { text => 'Auto-course creation settings',
  282:                      help => 'Domain_Configuration_Auto_Creation',
  283:                      header => [{col1 => 'Configuration Setting',
  284:                                  col2 => 'Value',}],
  285:                   },
  286:         'directorysrch' => 
  287:                   { text => 'Institutional directory searches',
  288:                     help => 'Domain_Configuration_InstDirectory_Search',
  289:                     header => [{col1 => 'Setting',
  290:                                 col2 => 'Value',}],
  291:                   },
  292:         'contacts' =>
  293:                   { text => 'Contact Information',
  294:                     help => 'Domain_Configuration_Contact_Info',
  295:                     header => [{col1 => 'Setting',
  296:                                 col2 => 'Value',}],
  297:                   },
  298: 
  299:         'usercreation' => 
  300:                   { text => 'User creation',
  301:                     help => 'Domain_Configuration_User_Creation',
  302:                     header => [{col1 => 'Format rule type',
  303:                                 col2 => 'Format rules in force'},
  304:                                {col1 => 'User account creation',
  305:                                 col2 => 'Usernames which may be created',},
  306:                                {col1 => 'Context',
  307:                                 col2 => 'Assignable authentication types'}],
  308:                   },
  309:         'usermodification' =>
  310:                   { text => 'User modification',
  311:                     help => 'Domain_Configuration_User_Modification',
  312:                     header => [{col1 => 'Target user has role',
  313:                                 col2 => 'User information updateable in author context'},
  314:                                {col1 => 'Target user has role',
  315:                                 col2 => 'User information updateable in course context'},
  316:                                {col1 => "Status of user",
  317:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
  318:                   },
  319:         'scantron' =>
  320:                   { text => 'Bubblesheet format file',
  321:                     help => 'Domain_Configuration_Scantron_Format',
  322:                     header => [ {col1 => 'Item',
  323:                                  col2 => '',
  324:                               }],
  325:                   },
  326:         'requestcourses' => 
  327:                  {text => 'Request creation of courses',
  328:                   help => 'Domain_Configuration_Request_Courses',
  329:                   header => [{col1 => 'User affiliation',
  330:                               col2 => 'Availability/Processing of requests',},
  331:                              {col1 => 'Setting',
  332:                               col2 => 'Value'}],
  333:                  },
  334:         'requestauthor' =>
  335:                  {text => 'Request authoring space',
  336:                   help => 'Domain_Configuration_Request_Author',
  337:                   header => [{col1 => 'User affiliation',
  338:                               col2 => 'Availability/Processing of requests',},
  339:                              {col1 => 'Setting',
  340:                               col2 => 'Value'}],
  341:                  },
  342:         'coursecategories' =>
  343:                   { text => 'Cataloging of courses/communities',
  344:                     help => 'Domain_Configuration_Cataloging_Courses',
  345:                     header => [{col1 => 'Category settings',
  346:                                 col2 => '',},
  347:                                {col1 => 'Categories',
  348:                                 col2 => '',
  349:                                }],
  350:                   },
  351:         'serverstatuses' =>
  352:                  {text   => 'Access to server status pages',
  353:                   help   => 'Domain_Configuration_Server_Status',
  354:                   header => [{col1 => 'Status Page',
  355:                               col2 => 'Other named users',
  356:                               col3 => 'Specific IPs',
  357:                             }],
  358:                  },
  359:         'helpsettings' =>
  360:                  {text   => 'Help page settings',
  361:                   help   => 'Domain_Configuration_Help_Settings',
  362:                   header => [{col1 => 'Help Settings (logged-in users)',
  363:                               col2 => 'Value'}],
  364:                  },
  365:         'coursedefaults' => 
  366:                  {text => 'Course/Community defaults',
  367:                   help => 'Domain_Configuration_Course_Defaults',
  368:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
  369:                               col2 => 'Value',},
  370:                              {col1 => 'Defaults which can be overridden for each course by a DC',
  371:                               col2 => 'Value',},],
  372:                  },
  373:         'privacy' => 
  374:                  {text   => 'User Privacy',
  375:                   help   => 'Domain_Configuration_User_Privacy',
  376:                   header => [{col1 => 'Setting',
  377:                               col2 => 'Value',}],
  378:                  },
  379:         'usersessions' =>
  380:                  {text  => 'User session hosting/offloading',
  381:                   help  => 'Domain_Configuration_User_Sessions',
  382:                   header => [{col1 => 'Domain server',
  383:                               col2 => 'Servers to offload sessions to when busy'},
  384:                              {col1 => 'Hosting of users from other domains',
  385:                               col2 => 'Rules'},
  386:                              {col1 => "Hosting domain's own users elsewhere",
  387:                               col2 => 'Rules'}],
  388:                  },
  389:          'loadbalancing' =>
  390:                  {text  => 'Dedicated Load Balancer(s)',
  391:                   help  => 'Domain_Configuration_Load_Balancing',
  392:                   header => [{col1 => 'Balancers',
  393:                               col2 => 'Default destinations',
  394:                               col3 => 'User affiliation',
  395:                               col4 => 'Overrides'},
  396:                             ],
  397:                  },
  398:     );
  399:     if (keys(%servers) > 1) {
  400:         $prefs{'login'}  = { text   => 'Log-in page options',
  401:                              help   => 'Domain_Configuration_Login_Page',
  402:                             header => [{col1 => 'Log-in Service',
  403:                                         col2 => 'Server Setting',},
  404:                                        {col1 => 'Log-in Page Items',
  405:                                         col2 => ''},
  406:                                        {col1 => 'Log-in Help',
  407:                                         col2 => 'Value'}],
  408:                            };
  409:     }
  410: 
  411:     my @roles = ('student','coordinator','author','admin');
  412:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  413:     &Apache::lonhtmlcommon::add_breadcrumb
  414:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  415:       text=>"Settings to display/modify"});
  416:     my $confname = $dom.'-domainconfig';
  417: 
  418:     if ($phase eq 'process') {
  419:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
  420:     } elsif ($phase eq 'display') {
  421:         my $js = &recaptcha_js().
  422:                  &credits_js();
  423:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
  424:             my ($othertitle,$usertypes,$types) =
  425:                 &Apache::loncommon::sorted_inst_types($dom);
  426:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
  427:                                           $domconfig{'loadbalancing'}).
  428:                    &new_spares_js().
  429:                    &common_domprefs_js().
  430:                    &Apache::loncommon::javascript_array_indexof();
  431:         }
  432:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
  433:     } else {
  434: # check if domconfig user exists for the domain.
  435:         my $servadm = $r->dir_config('lonAdmEMail');
  436:         my ($configuserok,$author_ok,$switchserver) =
  437:             &config_check($dom,$confname,$servadm);
  438:         unless ($configuserok eq 'ok') {
  439:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
  440:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
  441:                            $confname).
  442:                       '<br />'
  443:             );
  444:             if ($switchserver) {
  445:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
  446:                           '<br />'.
  447:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
  448:                           '<br />'.
  449:                           &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
  450:                           '<br />'.
  451:                           &mt('To do that now, use the following link: [_1]',$switchserver)
  452:                 );
  453:             } else {
  454:                 $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
  455:                           '<br />'.
  456:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
  457:                 );
  458:             }
  459:             $r->print(&Apache::loncommon::end_page());
  460:             return OK;
  461:         }
  462:         if (keys(%domconfig) == 0) {
  463:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  464:             my @ids=&Apache::lonnet::current_machine_ids();
  465:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  466:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  467:                 my @loginimages = ('img','logo','domlogo','login');
  468:                 my $custom_img_count = 0;
  469:                 foreach my $img (@loginimages) {
  470:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  471:                         $custom_img_count ++;
  472:                     }
  473:                 }
  474:                 foreach my $role (@roles) {
  475:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  476:                         $custom_img_count ++;
  477:                     }
  478:                 }
  479:                 if ($custom_img_count > 0) {
  480:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
  481:                     my $switch_server = &check_switchserver($dom,$confname);
  482:                     $r->print(
  483:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  484:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  485:     &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 />'.
  486:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  487:                     if ($switch_server) {
  488:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  489:                     }
  490:                     $r->print(&Apache::loncommon::end_page());
  491:                     return OK;
  492:                 }
  493:             }
  494:         }
  495:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
  496:     }
  497:     return OK;
  498: }
  499: 
  500: sub process_changes {
  501:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
  502:     my %domconfig;
  503:     if (ref($values) eq 'HASH') {
  504:         %domconfig = %{$values};
  505:     }
  506:     my $output;
  507:     if ($action eq 'login') {
  508:         $output = &modify_login($r,$dom,$confname,%domconfig);
  509:     } elsif ($action eq 'rolecolors') {
  510:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  511:                                      %domconfig);
  512:     } elsif ($action eq 'quotas') {
  513:         $output = &modify_quotas($dom,$action,%domconfig);
  514:     } elsif ($action eq 'autoenroll') {
  515:         $output = &modify_autoenroll($dom,%domconfig);
  516:     } elsif ($action eq 'autoupdate') {
  517:         $output = &modify_autoupdate($dom,%domconfig);
  518:     } elsif ($action eq 'autocreate') {
  519:         $output = &modify_autocreate($dom,%domconfig);
  520:     } elsif ($action eq 'directorysrch') {
  521:         $output = &modify_directorysrch($dom,%domconfig);
  522:     } elsif ($action eq 'usercreation') {
  523:         $output = &modify_usercreation($dom,%domconfig);
  524:     } elsif ($action eq 'usermodification') {
  525:         $output = &modify_usermodification($dom,%domconfig);
  526:     } elsif ($action eq 'contacts') {
  527:         $output = &modify_contacts($dom,%domconfig);
  528:     } elsif ($action eq 'defaults') {
  529:         $output = &modify_defaults($dom,$r,%domconfig);
  530:     } elsif ($action eq 'scantron') {
  531:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
  532:     } elsif ($action eq 'coursecategories') {
  533:         $output = &modify_coursecategories($dom,%domconfig);
  534:     } elsif ($action eq 'serverstatuses') {
  535:         $output = &modify_serverstatuses($dom,%domconfig);
  536:     } elsif ($action eq 'requestcourses') {
  537:         $output = &modify_quotas($dom,$action,%domconfig);
  538:     } elsif ($action eq 'requestauthor') {
  539:         $output = &modify_quotas($dom,$action,%domconfig);
  540:     } elsif ($action eq 'helpsettings') {
  541:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
  542:     } elsif ($action eq 'coursedefaults') {
  543:         $output = &modify_coursedefaults($dom,%domconfig);
  544:     } elsif ($action eq 'usersessions') {
  545:         $output = &modify_usersessions($dom,%domconfig);
  546:     } elsif ($action eq 'loadbalancing') {
  547:         $output = &modify_loadbalancing($dom,%domconfig);
  548:     }
  549:     return $output;
  550: }
  551: 
  552: sub print_config_box {
  553:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  554:     my $rowtotal = 0;
  555:     my $output;
  556:     if ($action eq 'coursecategories') {
  557:         $output = &coursecategories_javascript($settings);
  558:     }
  559:     $output .= 
  560:          '<table class="LC_nested_outer">
  561:           <tr>
  562:            <th align="left" valign="middle"><span class="LC_nobreak">'.
  563:            &mt($item->{text}).'&nbsp;'.
  564:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
  565:           '</tr>';
  566:     $rowtotal ++;
  567:     my $numheaders = 1;
  568:     if (ref($item->{'header'}) eq 'ARRAY') {
  569:         $numheaders = scalar(@{$item->{'header'}});
  570:     }
  571:     if ($numheaders > 1) {
  572:         my $colspan = '';
  573:         my $rightcolspan = '';
  574:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || 
  575:             (($action eq 'login') && ($numheaders < 3))) {
  576:             $colspan = ' colspan="2"';
  577:         }
  578:         if ($action eq 'usersessions') {
  579:             $rightcolspan = ' colspan="3"'; 
  580:         }
  581:         $output .= '
  582:           <tr>
  583:            <td>
  584:             <table class="LC_nested">
  585:              <tr class="LC_info_row">
  586:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
  587:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  588:              </tr>';
  589:         $rowtotal ++;
  590:         if ($action eq 'autoupdate') {
  591:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
  592:         } elsif ($action eq 'usercreation') {
  593:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
  594:         } elsif ($action eq 'usermodification') {
  595:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
  596:         } elsif ($action eq 'coursecategories') {
  597:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
  598:         } elsif ($action eq 'login') {
  599:             if ($numheaders == 3) {
  600:                 $colspan = ' colspan="2"';
  601:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
  602:             } else {
  603:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
  604:             }
  605:         } elsif ($action eq 'requestcourses') {
  606:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  607:         } elsif ($action eq 'requestauthor') {
  608:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  609:         } elsif ($action eq 'usersessions') {
  610:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
  611:         } elsif ($action eq 'rolecolors') {
  612:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  613:         } elsif ($action eq 'coursedefaults') {
  614:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
  615:         }
  616:         $output .= '
  617:            </table>
  618:           </td>
  619:          </tr>
  620:          <tr>
  621:            <td>
  622:             <table class="LC_nested">
  623:              <tr class="LC_info_row">
  624:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
  625:         $output .= '
  626:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
  627:              </tr>';
  628:             $rowtotal ++;
  629:         if ($action eq 'autoupdate') {
  630:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
  631:            </table>
  632:           </td>
  633:          </tr>
  634:          <tr>
  635:            <td>
  636:             <table class="LC_nested">
  637:              <tr class="LC_info_row">
  638:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  639:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  640:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
  641:             $rowtotal ++;
  642:         } elsif ($action eq 'usercreation') {
  643:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
  644:            </table>
  645:           </td>
  646:          </tr>
  647:          <tr>
  648:            <td>
  649:             <table class="LC_nested">
  650:              <tr class="LC_info_row">
  651:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  652:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
  653:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
  654:             $rowtotal ++;
  655:         } elsif ($action eq 'usermodification') {
  656:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
  657:            </table>
  658:           </td>
  659:          </tr>
  660:          <tr>
  661:            <td>
  662:             <table class="LC_nested">
  663:              <tr class="LC_info_row">
  664:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  665:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  666:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
  667:             $rowtotal ++;
  668:         } elsif ($action eq 'coursecategories') {
  669:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
  670:         } elsif ($action eq 'login') {
  671:             if ($numheaders == 3) {
  672:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
  673:            </table>
  674:           </td>
  675:          </tr>
  676:          <tr>
  677:            <td>
  678:             <table class="LC_nested">
  679:              <tr class="LC_info_row">
  680:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  681:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  682:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
  683:                 $rowtotal ++;
  684:             } else {
  685:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
  686:             }
  687:         } elsif ($action eq 'requestcourses') {
  688:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
  689:         } elsif ($action eq 'requestauthor') {
  690:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
  691:         } elsif ($action eq 'usersessions') {
  692:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
  693:            </table>
  694:           </td>
  695:          </tr>
  696:          <tr>
  697:            <td>
  698:             <table class="LC_nested">
  699:              <tr class="LC_info_row">
  700:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  701:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  702:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
  703:             $rowtotal ++;
  704:         } elsif ($action eq 'coursedefaults') {
  705:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
  706:         } elsif ($action eq 'rolecolors') {
  707:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  708:            </table>
  709:           </td>
  710:          </tr>
  711:          <tr>
  712:            <td>
  713:             <table class="LC_nested">
  714:              <tr class="LC_info_row">
  715:               <td class="LC_left_item"'.$colspan.' valign="top">'.
  716:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
  717:               <td class="LC_right_item" valign="top">'.
  718:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
  719:              </tr>'.
  720:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  721:            </table>
  722:           </td>
  723:          </tr>
  724:          <tr>
  725:            <td>
  726:             <table class="LC_nested">
  727:              <tr class="LC_info_row">
  728:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  729:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  730:              </tr>'.
  731:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  732:             $rowtotal += 2;
  733:         }
  734:     } else {
  735:         $output .= '
  736:           <tr>
  737:            <td>
  738:             <table class="LC_nested">
  739:              <tr class="LC_info_row">';
  740:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  741:             $output .= '  
  742:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  743:         } elsif ($action eq 'serverstatuses') {
  744:             $output .= '
  745:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
  746:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
  747: 
  748:         } else {
  749:             $output .= '
  750:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  751:         }
  752:         if (defined($item->{'header'}->[0]->{'col3'})) {
  753:             $output .= '<td class="LC_left_item" valign="top">'.
  754:                        &mt($item->{'header'}->[0]->{'col2'});
  755:             if ($action eq 'serverstatuses') {
  756:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
  757:             } 
  758:         } else {
  759:             $output .= '<td class="LC_right_item" valign="top">'.
  760:                        &mt($item->{'header'}->[0]->{'col2'});
  761:         }
  762:         $output .= '</td>';
  763:         if ($item->{'header'}->[0]->{'col3'}) {
  764:             if (defined($item->{'header'}->[0]->{'col4'})) {
  765:                 $output .= '<td class="LC_left_item" valign="top">'.
  766:                             &mt($item->{'header'}->[0]->{'col3'});
  767:             } else {
  768:                 $output .= '<td class="LC_right_item" valign="top">'.
  769:                            &mt($item->{'header'}->[0]->{'col3'});
  770:             }
  771:             if ($action eq 'serverstatuses') {
  772:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
  773:             }
  774:             $output .= '</td>';
  775:         }
  776:         if ($item->{'header'}->[0]->{'col4'}) {
  777:             $output .= '<td class="LC_right_item" valign="top">'.
  778:                        &mt($item->{'header'}->[0]->{'col4'});
  779:         }
  780:         $output .= '</tr>';
  781:         $rowtotal ++;
  782:         if ($action eq 'quotas') {
  783:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  784:         } elsif ($action eq 'autoenroll') {
  785:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
  786:         } elsif ($action eq 'autocreate') {
  787:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
  788:         } elsif ($action eq 'directorysrch') {
  789:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
  790:         } elsif ($action eq 'contacts') {
  791:             $output .= &print_contacts($dom,$settings,\$rowtotal);
  792:         } elsif ($action eq 'defaults') {
  793:             $output .= &print_defaults($dom,\$rowtotal);
  794:         } elsif ($action eq 'scantron') {
  795:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
  796:         } elsif ($action eq 'serverstatuses') {
  797:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
  798:         } elsif ($action eq 'helpsettings') {
  799:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
  800:         } elsif ($action eq 'loadbalancing') {
  801:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
  802:         }
  803:     }
  804:     $output .= '
  805:    </table>
  806:   </td>
  807:  </tr>
  808: </table><br />';
  809:     return ($output,$rowtotal);
  810: }
  811: 
  812: sub print_login {
  813:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
  814:     my ($css_class,$datatable);
  815:     my %choices = &login_choices();
  816: 
  817:     if ($caller eq 'service') {
  818:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
  819:         my $choice = $choices{'disallowlogin'};
  820:         $css_class = ' class="LC_odd_row"';
  821:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
  822:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
  823:                       '<th>'.$choices{'server'}.'</th>'.
  824:                       '<th>'.$choices{'serverpath'}.'</th>'.
  825:                       '<th>'.$choices{'custompath'}.'</th>'.
  826:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
  827:         my %disallowed;
  828:         if (ref($settings) eq 'HASH') {
  829:             if (ref($settings->{'loginvia'}) eq 'HASH') {
  830:                %disallowed = %{$settings->{'loginvia'}};
  831:             }
  832:         }
  833:         foreach my $lonhost (sort(keys(%servers))) {
  834:             my $direct = 'selected="selected"';
  835:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  836:                 if ($disallowed{$lonhost}{'server'} ne '') {
  837:                     $direct = '';
  838:                 }
  839:             }
  840:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
  841:                           '<td><select name="'.$lonhost.'_server">'.
  842:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
  843:                           '</option>';
  844:             foreach my $hostid (sort(keys(%servers))) {
  845:                 next if ($servers{$hostid} eq $servers{$lonhost});
  846:                 my $selected = '';
  847:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  848:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
  849:                         $selected = 'selected="selected"';
  850:                     }
  851:                 }
  852:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
  853:                               $servers{$hostid}.'</option>';
  854:             }
  855:             $datatable .= '</select></td>'.
  856:                           '<td><select name="'.$lonhost.'_serverpath">';
  857:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
  858:                 my $pathname = $path;
  859:                 if ($path eq 'custom') {
  860:                     $pathname = &mt('Custom Path').' ->';
  861:                 }
  862:                 my $selected = '';
  863:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  864:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
  865:                         $selected = 'selected="selected"';
  866:                     }
  867:                 } elsif ($path eq '') {
  868:                     $selected = 'selected="selected"';
  869:                 }
  870:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
  871:             }
  872:             $datatable .= '</select></td>';
  873:             my ($custom,$exempt);
  874:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  875:                 $custom = $disallowed{$lonhost}{'custompath'};
  876:                 $exempt = $disallowed{$lonhost}{'exempt'};
  877:             }
  878:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
  879:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
  880:                           '</tr>';
  881:         }
  882:         $datatable .= '</table></td></tr>';
  883:         return $datatable;
  884:     } elsif ($caller eq 'page') {
  885:         my %defaultchecked = ( 
  886:                                'coursecatalog' => 'on',
  887:                                'helpdesk'      => 'on',
  888:                                'adminmail'     => 'off',
  889:                                'newuser'       => 'off',
  890:                              );
  891:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
  892:         my (%checkedon,%checkedoff);
  893:         foreach my $item (@toggles) {
  894:             if ($defaultchecked{$item} eq 'on') { 
  895:                 $checkedon{$item} = ' checked="checked" ';
  896:                 $checkedoff{$item} = ' ';
  897:             } elsif ($defaultchecked{$item} eq 'off') {
  898:                 $checkedoff{$item} = ' checked="checked" ';
  899:                 $checkedon{$item} = ' ';
  900:             }
  901:         }
  902:         my @images = ('img','logo','domlogo','login');
  903:         my @logintext = ('textcol','bgcol');
  904:         my @bgs = ('pgbg','mainbg','sidebg');
  905:         my @links = ('link','alink','vlink');
  906:         my %designhash = &Apache::loncommon::get_domainconf($dom);
  907:         my %defaultdesign = %Apache::loncommon::defaultdesign;
  908:         my (%is_custom,%designs);
  909:         my %defaults = (
  910:                        font => $defaultdesign{'login.font'},
  911:                        );
  912:         foreach my $item (@images) {
  913:             $defaults{$item} = $defaultdesign{'login.'.$item};
  914:             $defaults{'showlogo'}{$item} = 1;
  915:         }
  916:         foreach my $item (@bgs) {
  917:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  918:         }
  919:         foreach my $item (@logintext) {
  920:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
  921:         }
  922:         foreach my $item (@links) {
  923:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  924:         }
  925:         if (ref($settings) eq 'HASH') {
  926:             foreach my $item (@toggles) {
  927:                 if ($settings->{$item} eq '1') {
  928:                     $checkedon{$item} =  ' checked="checked" ';
  929:                     $checkedoff{$item} = ' ';
  930:                 } elsif ($settings->{$item} eq '0') {
  931:                     $checkedoff{$item} =  ' checked="checked" ';
  932:                     $checkedon{$item} = ' ';
  933:                 }
  934:             }
  935:             foreach my $item (@images) {
  936:                 if (defined($settings->{$item})) {
  937:                     $designs{$item} = $settings->{$item};
  938:                     $is_custom{$item} = 1;
  939:                 }
  940:                 if (defined($settings->{'showlogo'}{$item})) {
  941:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
  942:                 }
  943:             }
  944:             foreach my $item (@logintext) {
  945:                 if ($settings->{$item} ne '') {
  946:                     $designs{'logintext'}{$item} = $settings->{$item};
  947:                     $is_custom{$item} = 1;
  948:                 }
  949:             }
  950:             if ($settings->{'font'} ne '') {
  951:                 $designs{'font'} = $settings->{'font'};
  952:                 $is_custom{'font'} = 1;
  953:             }
  954:             foreach my $item (@bgs) {
  955:                 if ($settings->{$item} ne '') {
  956:                     $designs{'bgs'}{$item} = $settings->{$item};
  957:                     $is_custom{$item} = 1;
  958:                 }
  959:             }
  960:             foreach my $item (@links) {
  961:                 if ($settings->{$item} ne '') {
  962:                     $designs{'links'}{$item} = $settings->{$item};
  963:                     $is_custom{$item} = 1;
  964:                 }
  965:             }
  966:         } else {
  967:             if ($designhash{$dom.'.login.font'} ne '') {
  968:                 $designs{'font'} = $designhash{$dom.'.login.font'};
  969:                 $is_custom{'font'} = 1;
  970:             }
  971:             foreach my $item (@images) {
  972:                 if ($designhash{$dom.'.login.'.$item} ne '') {
  973:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
  974:                     $is_custom{$item} = 1;
  975:                 }
  976:             }
  977:             foreach my $item (@bgs) {
  978:                 if ($designhash{$dom.'.login.'.$item} ne '') {
  979:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  980:                     $is_custom{$item} = 1;
  981:                 }
  982:             }
  983:             foreach my $item (@links) {
  984:                 if ($designhash{$dom.'.login.'.$item} ne '') {
  985:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  986:                     $is_custom{$item} = 1;
  987:                 }
  988:             }
  989:         }
  990:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  991:                                                       logo => 'Institution Logo',
  992:                                                       domlogo => 'Domain Logo',
  993:                                                       login => 'Login box');
  994:         my $itemcount = 1;
  995:         foreach my $item (@toggles) {
  996:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
  997:             $datatable .=  
  998:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
  999:                 '</td><td>'.
 1000:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
 1001:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
 1002:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
 1003:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
 1004:                 '</tr>';
 1005:             $itemcount ++;
 1006:         }
 1007:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
 1008:         $datatable .= '</tr></table></td></tr>';
 1009:     } elsif ($caller eq 'help') {
 1010:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
 1011:         my $switchserver = &check_switchserver($dom,$confname);
 1012:         my $itemcount = 1;
 1013:         $defaulturl = '/adm/loginproblems.html';
 1014:         $defaulttype = 'default';
 1015:         %lt = &Apache::lonlocal::texthash (
 1016:                      del     => 'Delete?',
 1017:                      rep     => 'Replace:',
 1018:                      upl     => 'Upload:',
 1019:                      default => 'Default',
 1020:                      custom  => 'Custom',
 1021:                                              );
 1022:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 1023:         my @currlangs;
 1024:         if (ref($settings) eq 'HASH') {
 1025:             if (ref($settings->{'helpurl'}) eq 'HASH') {
 1026:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
 1027:                     next if ($settings->{'helpurl'}{$key} eq '');
 1028:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
 1029:                     $type{$key} = 'custom';
 1030:                     unless ($key eq 'nolang') {
 1031:                         push(@currlangs,$key);
 1032:                     }
 1033:                 }
 1034:             } elsif ($settings->{'helpurl'} ne '') {
 1035:                 $type{'nolang'} = 'custom';
 1036:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
 1037:             }
 1038:         }
 1039:         foreach my $lang ('nolang',sort(@currlangs)) {
 1040:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 1041:             $datatable .= '<tr'.$css_class.'>';
 1042:             if ($url{$lang} eq '') {
 1043:                 $url{$lang} = $defaulturl;
 1044:             }
 1045:             if ($type{$lang} eq '') {
 1046:                 $type{$lang} = $defaulttype;
 1047:             }
 1048:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
 1049:             if ($lang eq 'nolang') {
 1050:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
 1051:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
 1052:             } else {
 1053:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
 1054:                                   $langchoices{$lang},
 1055:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
 1056:             }
 1057:             $datatable .= '</span></td>'."\n".
 1058:                           '<td class="LC_left_item">';
 1059:             if ($type{$lang} eq 'custom') {
 1060:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1061:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
 1062:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
 1063:             } else {
 1064:                 $datatable .= $lt{'upl'};
 1065:             }
 1066:             $datatable .='<br />';
 1067:             if ($switchserver) {
 1068:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1069:             } else {
 1070:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
 1071:             }
 1072:             $datatable .= '</td></tr>';
 1073:             $itemcount ++;
 1074:         }
 1075:         my @addlangs;
 1076:         foreach my $lang (sort(keys(%langchoices))) {
 1077:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
 1078:             push(@addlangs,$lang);
 1079:         }
 1080:         if (@addlangs > 0) {
 1081:             my %toadd;
 1082:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
 1083:             $toadd{''} = &mt('Select');
 1084:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 1085:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
 1086:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
 1087:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
 1088:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
 1089:             if ($switchserver) {
 1090:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1091:             } else {
 1092:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
 1093:             }
 1094:             $datatable .= '</td></tr>';
 1095:             $itemcount ++;
 1096:         }
 1097:         $datatable .= &captcha_choice('login',$settings,$itemcount);
 1098:     }
 1099:     return $datatable;
 1100: }
 1101: 
 1102: sub login_choices {
 1103:     my %choices =
 1104:         &Apache::lonlocal::texthash (
 1105:             coursecatalog => 'Display Course/Community Catalog link?',
 1106:             adminmail     => "Display Administrator's E-mail Address?",
 1107:             helpdesk      => 'Display "Contact Helpdesk" link',
 1108:             disallowlogin => "Login page requests redirected",
 1109:             hostid        => "Server",
 1110:             server        => "Redirect to:",
 1111:             serverpath    => "Path",
 1112:             custompath    => "Custom", 
 1113:             exempt        => "Exempt IP(s)",
 1114:             directlogin   => "No redirect",
 1115:             newuser       => "Link to create a user account",
 1116:             img           => "Header",
 1117:             logo          => "Main Logo",
 1118:             domlogo       => "Domain Logo",
 1119:             login         => "Log-in Header", 
 1120:             textcol       => "Text color",
 1121:             bgcol         => "Box color",
 1122:             bgs           => "Background colors",
 1123:             links         => "Link colors",
 1124:             font          => "Font color",
 1125:             pgbg          => "Header",
 1126:             mainbg        => "Page",
 1127:             sidebg        => "Login box",
 1128:             link          => "Link",
 1129:             alink         => "Active link",
 1130:             vlink         => "Visited link",
 1131:         );
 1132:     return %choices;
 1133: }
 1134: 
 1135: sub print_rolecolors {
 1136:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
 1137:     my %choices = &color_font_choices();
 1138:     my @bgs = ('pgbg','tabbg','sidebg');
 1139:     my @links = ('link','alink','vlink');
 1140:     my @images = ('img');
 1141:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
 1142:     my %designhash = &Apache::loncommon::get_domainconf($dom);
 1143:     my %defaultdesign = %Apache::loncommon::defaultdesign;
 1144:     my (%is_custom,%designs);
 1145:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
 1146:     if (ref($settings) eq 'HASH') {
 1147:         if (ref($settings->{$role}) eq 'HASH') {
 1148:             if ($settings->{$role}->{'img'} ne '') {
 1149:                 $designs{'img'} = $settings->{$role}->{'img'};
 1150:                 $is_custom{'img'} = 1;
 1151:             }
 1152:             if ($settings->{$role}->{'font'} ne '') {
 1153:                 $designs{'font'} = $settings->{$role}->{'font'};
 1154:                 $is_custom{'font'} = 1;
 1155:             }
 1156:             if ($settings->{$role}->{'fontmenu'} ne '') {
 1157:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
 1158:                 $is_custom{'fontmenu'} = 1;
 1159:             }
 1160:             foreach my $item (@bgs) {
 1161:                 if ($settings->{$role}->{$item} ne '') {
 1162:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
 1163:                     $is_custom{$item} = 1;
 1164:                 }
 1165:             }
 1166:             foreach my $item (@links) {
 1167:                 if ($settings->{$role}->{$item} ne '') {
 1168:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
 1169:                     $is_custom{$item} = 1;
 1170:                 }
 1171:             }
 1172:         }
 1173:     } else {
 1174:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
 1175:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
 1176:             $is_custom{'img'} = 1;
 1177:         }
 1178:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
 1179:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
 1180:             $is_custom{'fontmenu'} = 1; 
 1181:         }
 1182:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
 1183:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
 1184:             $is_custom{'font'} = 1;
 1185:         }
 1186:         foreach my $item (@bgs) {
 1187:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1188:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1189:                 $is_custom{$item} = 1;
 1190:             
 1191:             }
 1192:         }
 1193:         foreach my $item (@links) {
 1194:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1195:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1196:                 $is_custom{$item} = 1;
 1197:             }
 1198:         }
 1199:     }
 1200:     my $itemcount = 1;
 1201:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
 1202:     $datatable .= '</tr></table></td></tr>';
 1203:     return $datatable;
 1204: }
 1205: 
 1206: sub role_defaults {
 1207:     my ($role,$bgs,$links,$images,$logintext) = @_;
 1208:     my %defaults;
 1209:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
 1210:         return %defaults;
 1211:     }
 1212:     my %defaultdesign = %Apache::loncommon::defaultdesign;
 1213:     if ($role eq 'login') {
 1214:         %defaults = (
 1215:                        font => $defaultdesign{$role.'.font'},
 1216:                     );
 1217:         if (ref($logintext) eq 'ARRAY') {
 1218:             foreach my $item (@{$logintext}) {
 1219:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
 1220:             }
 1221:         }
 1222:         foreach my $item (@{$images}) {
 1223:             $defaults{'showlogo'}{$item} = 1;
 1224:         }
 1225:     } else {
 1226:         %defaults = (
 1227:                        img => $defaultdesign{$role.'.img'},
 1228:                        font => $defaultdesign{$role.'.font'},
 1229:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
 1230:                     );
 1231:     }
 1232:     foreach my $item (@{$bgs}) {
 1233:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
 1234:     }
 1235:     foreach my $item (@{$links}) {
 1236:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
 1237:     }
 1238:     foreach my $item (@{$images}) {
 1239:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
 1240:     }
 1241:     return %defaults;
 1242: }
 1243: 
 1244: sub display_color_options {
 1245:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
 1246:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
 1247:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
 1248:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1249:     my $datatable = '<tr'.$css_class.'>'.
 1250:         '<td>'.$choices->{'font'}.'</td>';
 1251:     if (!$is_custom->{'font'}) {
 1252:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
 1253:     } else {
 1254:         $datatable .= '<td>&nbsp;</td>';
 1255:     }
 1256:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
 1257: 
 1258:     $datatable .= '<td><span class="LC_nobreak">'.
 1259:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
 1260:                   ' value="'.$current_color.'" />&nbsp;'.
 1261:                   '&nbsp;</td></tr>';
 1262:     unless ($role eq 'login') { 
 1263:         $datatable .= '<tr'.$css_class.'>'.
 1264:                       '<td>'.$choices->{'fontmenu'}.'</td>';
 1265:         if (!$is_custom->{'fontmenu'}) {
 1266:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
 1267:         } else {
 1268:             $datatable .= '<td>&nbsp;</td>';
 1269:         }
 1270: 	$current_color = $designs->{'fontmenu'} ?
 1271: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
 1272:         $datatable .= '<td><span class="LC_nobreak">'.
 1273:                       '<input class="colorchooser" type="text" size="10" name="'
 1274: 		      .$role.'_fontmenu"'.
 1275:                       ' value="'.$current_color.'" />&nbsp;'.
 1276:                       '&nbsp;</td></tr>';
 1277:     }
 1278:     my $switchserver = &check_switchserver($dom,$confname);
 1279:     foreach my $img (@{$images}) {
 1280: 	$itemcount ++;
 1281:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1282:         $datatable .= '<tr'.$css_class.'>'.
 1283:                       '<td>'.$choices->{$img};
 1284:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
 1285:         if ($role eq 'login') {
 1286:             if ($img eq 'login') {
 1287:                 $login_hdr_pick =
 1288:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
 1289:                 $logincolors =
 1290:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
 1291:                                        $designs,$defaults);
 1292:             } elsif ($img ne 'domlogo') {
 1293:                 $datatable.= &logo_display_options($img,$defaults,$designs);
 1294:             }
 1295:         }
 1296:         $datatable .= '</td>';
 1297:         if ($designs->{$img} ne '') {
 1298:             $imgfile = $designs->{$img};
 1299: 	    $img_import = ($imgfile =~ m{^/adm/});
 1300:         } else {
 1301:             $imgfile = $defaults->{$img};
 1302:         }
 1303:         if ($imgfile) {
 1304:             my ($showfile,$fullsize);
 1305:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1306:                 my $urldir = $1;
 1307:                 my $filename = $2;
 1308:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
 1309:                 if (@info) {
 1310:                     my $thumbfile = 'tn-'.$filename;
 1311:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
 1312:                     if (@thumb) {
 1313:                         $showfile = $urldir.'/'.$thumbfile;
 1314:                     } else {
 1315:                         $showfile = $imgfile;
 1316:                     }
 1317:                 } else {
 1318:                     $showfile = '';
 1319:                 }
 1320:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
 1321:                 $showfile = $imgfile;
 1322:                 my $imgdir = $1;
 1323:                 my $filename = $2;
 1324:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
 1325:                     $showfile = "/$imgdir/tn-".$filename;
 1326:                 } else {
 1327:                     my $input = $londocroot.$imgfile;
 1328:                     my $output = "$londocroot/$imgdir/tn-".$filename;
 1329:                     if (!-e $output) {
 1330:                         my ($width,$height) = &thumb_dimensions();
 1331:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
 1332:                         if ($fullwidth ne '' && $fullheight ne '') {
 1333:                             if ($fullwidth > $width && $fullheight > $height) { 
 1334:                                 my $size = $width.'x'.$height;
 1335:                                 system("convert -sample $size $input $output");
 1336:                                 $showfile = "/$imgdir/tn-".$filename;
 1337:                             }
 1338:                         }
 1339:                     }
 1340:                 }
 1341:             }
 1342:             if ($showfile) {
 1343:                 if ($showfile =~ m{^/(adm|res)/}) {
 1344:                     if ($showfile =~ m{^/res/}) {
 1345:                         my $local_showfile =
 1346:                             &Apache::lonnet::filelocation('',$showfile);
 1347:                         &Apache::lonnet::repcopy($local_showfile);
 1348:                     }
 1349:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
 1350:                 }
 1351:                 if ($imgfile) {
 1352:                     if ($imgfile  =~ m{^/(adm|res)/}) {
 1353:                         if ($imgfile =~ m{^/res/}) {
 1354:                             my $local_imgfile =
 1355:                                 &Apache::lonnet::filelocation('',$imgfile);
 1356:                             &Apache::lonnet::repcopy($local_imgfile);
 1357:                         }
 1358:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
 1359:                     } else {
 1360:                         $fullsize = $imgfile;
 1361:                     }
 1362:                 }
 1363:                 $datatable .= '<td>';
 1364:                 if ($img eq 'login') {
 1365:                     $datatable .= $login_hdr_pick;
 1366:                 } 
 1367:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
 1368:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
 1369:             } else {
 1370:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
 1371:                               &mt('Upload:').'<br />';
 1372:             }
 1373:         } else {
 1374:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
 1375:                           &mt('Upload:').'<br />';
 1376:         }
 1377:         if ($switchserver) {
 1378:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1379:         } else {
 1380:             if ($img ne 'login') { # suppress file selection for Log-in header
 1381:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
 1382:             }
 1383:         }
 1384:         $datatable .= '</td></tr>';
 1385:     }
 1386:     $itemcount ++;
 1387:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1388:     $datatable .= '<tr'.$css_class.'>'.
 1389:                   '<td>'.$choices->{'bgs'}.'</td>';
 1390:     my $bgs_def;
 1391:     foreach my $item (@{$bgs}) {
 1392:         if (!$is_custom->{$item}) {
 1393:             $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>';
 1394:         }
 1395:     }
 1396:     if ($bgs_def) {
 1397:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
 1398:     } else {
 1399:         $datatable .= '<td>&nbsp;</td>';
 1400:     }
 1401:     $datatable .= '<td class="LC_right_item">'.
 1402:                   '<table border="0"><tr>';
 1403: 
 1404:     foreach my $item (@{$bgs}) {
 1405:         $datatable .= '<td align="center">'.$choices->{$item};
 1406: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
 1407:         if ($designs->{'bgs'}{$item}) {
 1408:             $datatable .= '&nbsp;';
 1409:         }
 1410:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1411:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1412:     }
 1413:     $datatable .= '</tr></table></td></tr>';
 1414:     $itemcount ++;
 1415:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1416:     $datatable .= '<tr'.$css_class.'>'.
 1417:                   '<td>'.$choices->{'links'}.'</td>';
 1418:     my $links_def;
 1419:     foreach my $item (@{$links}) {
 1420:         if (!$is_custom->{$item}) {
 1421:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
 1422:         }
 1423:     }
 1424:     if ($links_def) {
 1425:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
 1426:     } else {
 1427:         $datatable .= '<td>&nbsp;</td>';
 1428:     }
 1429:     $datatable .= '<td class="LC_right_item">'.
 1430:                   '<table border="0"><tr>';
 1431:     foreach my $item (@{$links}) {
 1432: 	my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
 1433:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
 1434:         if ($designs->{'links'}{$item}) {
 1435:             $datatable.='&nbsp;';
 1436:         }
 1437:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
 1438:                       '" /></td>';
 1439:     }
 1440:     $$rowtotal += $itemcount;
 1441:     return $datatable;
 1442: }
 1443: 
 1444: sub logo_display_options {
 1445:     my ($img,$defaults,$designs) = @_;
 1446:     my $checkedon;
 1447:     if (ref($defaults) eq 'HASH') {
 1448:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
 1449:             if ($defaults->{'showlogo'}{$img}) {
 1450:                 $checkedon = 'checked="checked" ';     
 1451:             }
 1452:         } 
 1453:     }
 1454:     if (ref($designs) eq 'HASH') {
 1455:         if (ref($designs->{'showlogo'}) eq 'HASH') {
 1456:             if (defined($designs->{'showlogo'}{$img})) {
 1457:                 if ($designs->{'showlogo'}{$img} == 0) {
 1458:                     $checkedon = '';
 1459:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
 1460:                     $checkedon = 'checked="checked" ';
 1461:                 }
 1462:             }
 1463:         }
 1464:     }
 1465:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
 1466:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
 1467:            &mt('show').'</label>'."\n";
 1468: }
 1469: 
 1470: sub login_header_options  {
 1471:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
 1472:     my $output = '';
 1473:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1474:         $output .= &mt('Text default(s):').'<br />';
 1475:         if (!$is_custom->{'textcol'}) {
 1476:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1477:                        '&nbsp;&nbsp;&nbsp;';
 1478:         }
 1479:         if (!$is_custom->{'bgcol'}) {
 1480:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1481:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1482:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1483:         }
 1484:         $output .= '<br />';
 1485:     }
 1486:     $output .='<br />';
 1487:     return $output;
 1488: }
 1489: 
 1490: sub login_text_colors {
 1491:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
 1492:     my $color_menu = '<table border="0"><tr>';
 1493:     foreach my $item (@{$logintext}) {
 1494:         $color_menu .= '<td align="center">'.$choices->{$item};
 1495:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
 1496:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1497:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1498:     }
 1499:     $color_menu .= '</tr></table><br />';
 1500:     return $color_menu;
 1501: }
 1502: 
 1503: sub image_changes {
 1504:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1505:     my $output;
 1506:     if ($img eq 'login') {
 1507:             # suppress image for Log-in header
 1508:     } elsif (!$is_custom) {
 1509:         if ($img ne 'domlogo') {
 1510:             $output .= &mt('Default image:').'<br />';
 1511:         } else {
 1512:             $output .= &mt('Default in use:').'<br />';
 1513:         }
 1514:     }
 1515:     if ($img eq 'login') { # suppress image for Log-in header
 1516:         $output .= '<td>'.$logincolors;
 1517:     } else {
 1518:         if ($img_import) {
 1519:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1520:         }
 1521:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1522:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1523:         if ($is_custom) {
 1524:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1525:                        '<input type="checkbox" name="'.
 1526:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1527:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1528:         } else {
 1529:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
 1530:         }
 1531:     }
 1532:     return $output;
 1533: }
 1534: 
 1535: sub print_quotas {
 1536:     my ($dom,$settings,$rowtotal,$action) = @_;
 1537:     my $context;
 1538:     if ($action eq 'quotas') {
 1539:         $context = 'tools';
 1540:     } else {
 1541:         $context = $action;
 1542:     }
 1543:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
 1544:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1545:     my $typecount = 0;
 1546:     my ($css_class,%titles);
 1547:     if ($context eq 'requestcourses') {
 1548:         @usertools = ('official','unofficial','community');
 1549:         @options =('norequest','approval','validate','autolimit');
 1550:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 1551:         %titles = &courserequest_titles();
 1552:     } elsif ($context eq 'requestauthor') {
 1553:         @usertools = ('author');
 1554:         @options = ('norequest','approval','automatic');
 1555:         %titles = &authorrequest_titles(); 
 1556:     } else {
 1557:         @usertools = ('aboutme','blog','webdav','portfolio');
 1558:         %titles = &tool_titles();
 1559:     }
 1560:     if (ref($types) eq 'ARRAY') {
 1561:         foreach my $type (@{$types}) {
 1562:             my ($currdefquota,$currauthorquota);
 1563:             unless (($context eq 'requestcourses') ||
 1564:                     ($context eq 'requestauthor')) {
 1565:                 if (ref($settings) eq 'HASH') {
 1566:                     if (ref($settings->{defaultquota}) eq 'HASH') {
 1567:                         $currdefquota = $settings->{defaultquota}->{$type};
 1568:                     } else {
 1569:                         $currdefquota = $settings->{$type};
 1570:                     }
 1571:                     if (ref($settings->{authorquota}) eq 'HASH') {
 1572:                         $currauthorquota = $settings->{authorquota}->{$type};
 1573:                     }
 1574:                 }
 1575:             }
 1576:             if (defined($usertypes->{$type})) {
 1577:                 $typecount ++;
 1578:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1579:                 $datatable .= '<tr'.$css_class.'>'.
 1580:                               '<td>'.$usertypes->{$type}.'</td>'.
 1581:                               '<td class="LC_left_item">';
 1582:                 if ($context eq 'requestcourses') {
 1583:                     $datatable .= '<table><tr>';
 1584:                 }
 1585:                 my %cell;  
 1586:                 foreach my $item (@usertools) {
 1587:                     if ($context eq 'requestcourses') {
 1588:                         my ($curroption,$currlimit);
 1589:                         if (ref($settings) eq 'HASH') {
 1590:                             if (ref($settings->{$item}) eq 'HASH') {
 1591:                                 $curroption = $settings->{$item}->{$type};
 1592:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
 1593:                                     $currlimit = $1; 
 1594:                                 }
 1595:                             }
 1596:                         }
 1597:                         if (!$curroption) {
 1598:                             $curroption = 'norequest';
 1599:                         }
 1600:                         $datatable .= '<th>'.$titles{$item}.'</th>';
 1601:                         foreach my $option (@options) {
 1602:                             my $val = $option;
 1603:                             if ($option eq 'norequest') {
 1604:                                 $val = 0;  
 1605:                             }
 1606:                             if ($option eq 'validate') {
 1607:                                 my $canvalidate = 0;
 1608:                                 if (ref($validations{$item}) eq 'HASH') { 
 1609:                                     if ($validations{$item}{$type}) {
 1610:                                         $canvalidate = 1;
 1611:                                     }
 1612:                                 }
 1613:                                 next if (!$canvalidate);
 1614:                             }
 1615:                             my $checked = '';
 1616:                             if ($option eq $curroption) {
 1617:                                 $checked = ' checked="checked"';
 1618:                             } elsif ($option eq 'autolimit') {
 1619:                                 if ($curroption =~ /^autolimit/) {
 1620:                                     $checked = ' checked="checked"';
 1621:                                 }                       
 1622:                             } 
 1623:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
 1624:                                   '<input type="radio" name="crsreq_'.$item.
 1625:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
 1626:                                   $titles{$option}.'</label>';
 1627:                             if ($option eq 'autolimit') {
 1628:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1629:                                                 $item.'_limit_'.$type.'" size="1" '.
 1630:                                                 'value="'.$currlimit.'" />';
 1631:                             }
 1632:                             $cell{$item} .= '</span> ';
 1633:                             if ($option eq 'autolimit') {
 1634:                                 $cell{$item} .= $titles{'unlimited'};
 1635:                             }
 1636:                         }
 1637:                     } elsif ($context eq 'requestauthor') {
 1638:                         my $curroption;
 1639:                         if (ref($settings) eq 'HASH') {
 1640:                             $curroption = $settings->{$type};
 1641:                         }
 1642:                         if (!$curroption) {
 1643:                             $curroption = 'norequest';
 1644:                         }
 1645:                         foreach my $option (@options) {
 1646:                             my $val = $option;
 1647:                             if ($option eq 'norequest') {
 1648:                                 $val = 0;
 1649:                             }
 1650:                             my $checked = '';
 1651:                             if ($option eq $curroption) {
 1652:                                 $checked = ' checked="checked"';
 1653:                             }
 1654:                             $datatable .= '<span class="LC_nobreak"><label>'.
 1655:                                   '<input type="radio" name="authorreq_'.$type.
 1656:                                   '" value="'.$val.'"'.$checked.' />'.
 1657:                                   $titles{$option}.'</label></span>&nbsp; ';
 1658:                         }
 1659:                     } else {
 1660:                         my $checked = 'checked="checked" ';
 1661:                         if (ref($settings) eq 'HASH') {
 1662:                             if (ref($settings->{$item}) eq 'HASH') {
 1663:                                 if ($settings->{$item}->{$type} == 0) {
 1664:                                     $checked = '';
 1665:                                 } elsif ($settings->{$item}->{$type} == 1) {
 1666:                                     $checked =  'checked="checked" ';
 1667:                                 }
 1668:                             }
 1669:                         }
 1670:                         $datatable .= '<span class="LC_nobreak"><label>'.
 1671:                                       '<input type="checkbox" name="'.$context.'_'.$item.
 1672:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1673:                                       '</label></span>&nbsp; ';
 1674:                     }
 1675:                 }
 1676:                 if ($context eq 'requestcourses') {
 1677:                     $datatable .= '</tr><tr>';
 1678:                     foreach my $item (@usertools) {
 1679:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
 1680:                     }
 1681:                     $datatable .= '</tr></table>';
 1682:                 }
 1683:                 $datatable .= '</td>';
 1684:                 unless (($context eq 'requestcourses') ||
 1685:                         ($context eq 'requestauthor')) {
 1686:                     $datatable .= 
 1687:                               '<td class="LC_right_item">'.
 1688:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1689:                               '<input type="text" name="quota_'.$type.
 1690:                               '" value="'.$currdefquota.
 1691:                               '" size="5" /></span>'.('&nbsp;' x 2).
 1692:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1693:                               '<input type="text" name="authorquota_'.$type.
 1694:                               '" value="'.$currauthorquota.
 1695:                               '" size="5" /></span></td>';
 1696:                 }
 1697:                 $datatable .= '</tr>';
 1698:             }
 1699:         }
 1700:     }
 1701:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1702:         $defaultquota = '20';
 1703:         $authorquota = '500';
 1704:         if (ref($settings) eq 'HASH') {
 1705:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1706:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
 1707:             } elsif (defined($settings->{'default'})) {
 1708:                 $defaultquota = $settings->{'default'};
 1709:             }
 1710:             if (ref($settings->{'authorquota'}) eq 'HASH') {
 1711:                 $authorquota = $settings->{'authorquota'}->{'default'};
 1712:             }
 1713:         }
 1714:     }
 1715:     $typecount ++;
 1716:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1717:     $datatable .= '<tr'.$css_class.'>'.
 1718:                   '<td>'.$othertitle.'</td>'.
 1719:                   '<td class="LC_left_item">';
 1720:     if ($context eq 'requestcourses') {
 1721:         $datatable .= '<table><tr>';
 1722:     }
 1723:     my %defcell;
 1724:     foreach my $item (@usertools) {
 1725:         if ($context eq 'requestcourses') {
 1726:             my ($curroption,$currlimit);
 1727:             if (ref($settings) eq 'HASH') {
 1728:                 if (ref($settings->{$item}) eq 'HASH') {
 1729:                     $curroption = $settings->{$item}->{'default'};
 1730:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1731:                         $currlimit = $1;
 1732:                     }
 1733:                 }
 1734:             }
 1735:             if (!$curroption) {
 1736:                 $curroption = 'norequest';
 1737:             }
 1738:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1739:             foreach my $option (@options) {
 1740:                 my $val = $option;
 1741:                 if ($option eq 'norequest') {
 1742:                     $val = 0;
 1743:                 }
 1744:                 if ($option eq 'validate') {
 1745:                     my $canvalidate = 0;
 1746:                     if (ref($validations{$item}) eq 'HASH') {
 1747:                         if ($validations{$item}{'default'}) {
 1748:                             $canvalidate = 1;
 1749:                         }
 1750:                     }
 1751:                     next if (!$canvalidate);
 1752:                 }
 1753:                 my $checked = '';
 1754:                 if ($option eq $curroption) {
 1755:                     $checked = ' checked="checked"';
 1756:                 } elsif ($option eq 'autolimit') {
 1757:                     if ($curroption =~ /^autolimit/) {
 1758:                         $checked = ' checked="checked"';
 1759:                     }
 1760:                 }
 1761:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
 1762:                                   '<input type="radio" name="crsreq_'.$item.
 1763:                                   '_default" value="'.$val.'"'.$checked.' />'.
 1764:                                   $titles{$option}.'</label>';
 1765:                 if ($option eq 'autolimit') {
 1766:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1767:                                        $item.'_limit_default" size="1" '.
 1768:                                        'value="'.$currlimit.'" />';
 1769:                 }
 1770:                 $defcell{$item} .= '</span> ';
 1771:                 if ($option eq 'autolimit') {
 1772:                     $defcell{$item} .= $titles{'unlimited'};
 1773:                 }
 1774:             }
 1775:         } elsif ($context eq 'requestauthor') {
 1776:             my $curroption;
 1777:             if (ref($settings) eq 'HASH') {
 1778:                 $curroption = $settings->{'default'};
 1779:             }
 1780:             if (!$curroption) {
 1781:                 $curroption = 'norequest';
 1782:             }
 1783:             foreach my $option (@options) {
 1784:                 my $val = $option;
 1785:                 if ($option eq 'norequest') {
 1786:                     $val = 0;
 1787:                 }
 1788:                 my $checked = '';
 1789:                 if ($option eq $curroption) {
 1790:                     $checked = ' checked="checked"';
 1791:                 }
 1792:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1793:                               '<input type="radio" name="authorreq_default"'.
 1794:                               ' value="'.$val.'"'.$checked.' />'.
 1795:                               $titles{$option}.'</label></span>&nbsp; ';
 1796:             }
 1797:         } else {
 1798:             my $checked = 'checked="checked" ';
 1799:             if (ref($settings) eq 'HASH') {
 1800:                 if (ref($settings->{$item}) eq 'HASH') {
 1801:                     if ($settings->{$item}->{'default'} == 0) {
 1802:                         $checked = '';
 1803:                     } elsif ($settings->{$item}->{'default'} == 1) {
 1804:                         $checked = 'checked="checked" ';
 1805:                     }
 1806:                 }
 1807:             }
 1808:             $datatable .= '<span class="LC_nobreak"><label>'.
 1809:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1810:                           '" value="default" '.$checked.'/>'.$titles{$item}.
 1811:                           '</label></span>&nbsp; ';
 1812:         }
 1813:     }
 1814:     if ($context eq 'requestcourses') {
 1815:         $datatable .= '</tr><tr>';
 1816:         foreach my $item (@usertools) {
 1817:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
 1818:         }
 1819:         $datatable .= '</tr></table>';
 1820:     }
 1821:     $datatable .= '</td>';
 1822:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1823:         $datatable .= '<td class="LC_right_item">'.
 1824:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1825:                       '<input type="text" name="defaultquota" value="'.
 1826:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
 1827:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1828:                       '<input type="text" name="authorquota" value="'.
 1829:                       $authorquota.'" size="5" /></span></td>';
 1830:     }
 1831:     $datatable .= '</tr>';
 1832:     $typecount ++;
 1833:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1834:     $datatable .= '<tr'.$css_class.'>'.
 1835:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
 1836:     if ($context eq 'requestcourses') {
 1837:         $datatable .= &mt('(overrides affiliation, if set)').
 1838:                       '</td>'.
 1839:                       '<td class="LC_left_item">'.
 1840:                       '<table><tr>';
 1841:     } else {
 1842:         $datatable .= &mt('(overrides affiliation, if checked)').
 1843:                       '</td>'.
 1844:                       '<td class="LC_left_item" colspan="2">'.
 1845:                       '<br />';
 1846:     }
 1847:     my %advcell;
 1848:     foreach my $item (@usertools) {
 1849:         if ($context eq 'requestcourses') {
 1850:             my ($curroption,$currlimit);
 1851:             if (ref($settings) eq 'HASH') {
 1852:                 if (ref($settings->{$item}) eq 'HASH') {
 1853:                     $curroption = $settings->{$item}->{'_LC_adv'};
 1854:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1855:                         $currlimit = $1;
 1856:                     }
 1857:                 }
 1858:             }
 1859:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1860:             my $checked = '';
 1861:             if ($curroption eq '') {
 1862:                 $checked = ' checked="checked"';
 1863:             }
 1864:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1865:                                '<input type="radio" name="crsreq_'.$item.
 1866:                                '__LC_adv" value=""'.$checked.' />'.
 1867:                                &mt('No override set').'</label></span>&nbsp; ';
 1868:             foreach my $option (@options) {
 1869:                 my $val = $option;
 1870:                 if ($option eq 'norequest') {
 1871:                     $val = 0;
 1872:                 }
 1873:                 if ($option eq 'validate') {
 1874:                     my $canvalidate = 0;
 1875:                     if (ref($validations{$item}) eq 'HASH') {
 1876:                         if ($validations{$item}{'_LC_adv'}) {
 1877:                             $canvalidate = 1;
 1878:                         }
 1879:                     }
 1880:                     next if (!$canvalidate);
 1881:                 }
 1882:                 my $checked = '';
 1883:                 if ($val eq $curroption) {
 1884:                     $checked = ' checked="checked"';
 1885:                 } elsif ($option eq 'autolimit') {
 1886:                     if ($curroption =~ /^autolimit/) {
 1887:                         $checked = ' checked="checked"';
 1888:                     }
 1889:                 }
 1890:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1891:                                   '<input type="radio" name="crsreq_'.$item.
 1892:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
 1893:                                   $titles{$option}.'</label>';
 1894:                 if ($option eq 'autolimit') {
 1895:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1896:                                        $item.'_limit__LC_adv" size="1" '.
 1897:                                        'value="'.$currlimit.'" />';
 1898:                 }
 1899:                 $advcell{$item} .= '</span> ';
 1900:                 if ($option eq 'autolimit') {
 1901:                     $advcell{$item} .= $titles{'unlimited'};
 1902:                 }
 1903:             }
 1904:         } elsif ($context eq 'requestauthor') {
 1905:             my $curroption;
 1906:             if (ref($settings) eq 'HASH') {
 1907:                 $curroption = $settings->{'_LC_adv'};
 1908:             }
 1909:             my $checked = '';
 1910:             if ($curroption eq '') {
 1911:                 $checked = ' checked="checked"';
 1912:             }
 1913:             $datatable .= '<span class="LC_nobreak"><label>'.
 1914:                           '<input type="radio" name="authorreq__LC_adv"'.
 1915:                           ' value=""'.$checked.' />'.
 1916:                           &mt('No override set').'</label></span>&nbsp; ';
 1917:             foreach my $option (@options) {
 1918:                 my $val = $option;
 1919:                 if ($option eq 'norequest') {
 1920:                     $val = 0;
 1921:                 }
 1922:                 my $checked = '';
 1923:                 if ($val eq $curroption) {
 1924:                     $checked = ' checked="checked"';
 1925:                 }
 1926:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1927:                               '<input type="radio" name="authorreq__LC_adv"'.
 1928:                               ' value="'.$val.'"'.$checked.' />'.
 1929:                               $titles{$option}.'</label></span>&nbsp; ';
 1930:             }
 1931:         } else {
 1932:             my $checked = 'checked="checked" ';
 1933:             if (ref($settings) eq 'HASH') {
 1934:                 if (ref($settings->{$item}) eq 'HASH') {
 1935:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
 1936:                         $checked = '';
 1937:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
 1938:                         $checked = 'checked="checked" ';
 1939:                     }
 1940:                 }
 1941:             }
 1942:             $datatable .= '<span class="LC_nobreak"><label>'.
 1943:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1944:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 1945:                           '</label></span>&nbsp; ';
 1946:         }
 1947:     }
 1948:     if ($context eq 'requestcourses') {
 1949:         $datatable .= '</tr><tr>';
 1950:         foreach my $item (@usertools) {
 1951:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
 1952:         }
 1953:         $datatable .= '</tr></table>';
 1954:     }
 1955:     $datatable .= '</td></tr>';
 1956:     $$rowtotal += $typecount;
 1957:     return $datatable;
 1958: }
 1959: 
 1960: sub print_requestmail {
 1961:     my ($dom,$action,$settings,$rowtotal) = @_;
 1962:     my ($now,$datatable,%currapp,$rows);
 1963:     $now = time;
 1964:     if (ref($settings) eq 'HASH') {
 1965:         if (ref($settings->{'notify'}) eq 'HASH') {
 1966:             if ($settings->{'notify'}{'approval'} ne '') {
 1967:                map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
 1968:             }
 1969:         }
 1970:     }
 1971:     my $numinrow = 2;
 1972:     my $css_class = 'class="LC_odd_row"';
 1973:     my $text;
 1974:     if ($action eq 'requestcourses') {
 1975:         $text = &mt('Receive notification of course requests requiring approval');
 1976:     } else {
 1977:         $text = &mt('Receive notification of authoring space requests requiring approval')
 1978:     }
 1979:     $datatable = '<tr '.$css_class.'>'.
 1980:                  ' <td>'.$text.'</td>'.
 1981:                  ' <td class="LC_left_item">';
 1982:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
 1983:                                                  'reqapprovalnotify',%currapp);
 1984:     if ($numdc > 0) {
 1985:         $datatable .= $table;
 1986:     } else {
 1987:         $datatable .= &mt('There are no active Domain Coordinators');
 1988:     }
 1989:     $datatable .='</td></tr>';
 1990:     $$rowtotal += $rows;
 1991:     return $datatable;
 1992: }
 1993: 
 1994: sub print_autoenroll {
 1995:     my ($dom,$settings,$rowtotal) = @_;
 1996:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1997:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
 1998:     if (ref($settings) eq 'HASH') {
 1999:         if (exists($settings->{'run'})) {
 2000:             if ($settings->{'run'} eq '0') {
 2001:                 $runoff = ' checked="checked" ';
 2002:                 $runon = ' ';
 2003:             } else {
 2004:                 $runon = ' checked="checked" ';
 2005:                 $runoff = ' ';
 2006:             }
 2007:         } else {
 2008:             if ($autorun) {
 2009:                 $runon = ' checked="checked" ';
 2010:                 $runoff = ' ';
 2011:             } else {
 2012:                 $runoff = ' checked="checked" ';
 2013:                 $runon = ' ';
 2014:             }
 2015:         }
 2016:         if (exists($settings->{'co-owners'})) {
 2017:             if ($settings->{'co-owners'} eq '0') {
 2018:                 $coownersoff = ' checked="checked" ';
 2019:                 $coownerson = ' ';
 2020:             } else {
 2021:                 $coownerson = ' checked="checked" ';
 2022:                 $coownersoff = ' ';
 2023:             }
 2024:         } else {
 2025:             $coownersoff = ' checked="checked" ';
 2026:             $coownerson = ' ';
 2027:         }
 2028:         if (exists($settings->{'sender_domain'})) {
 2029:             $defdom = $settings->{'sender_domain'};
 2030:         }
 2031:     } else {
 2032:         if ($autorun) {
 2033:             $runon = ' checked="checked" ';
 2034:             $runoff = ' ';
 2035:         } else {
 2036:             $runoff = ' checked="checked" ';
 2037:             $runon = ' ';
 2038:         }
 2039:     }
 2040:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 2041:     my $notif_sender;
 2042:     if (ref($settings) eq 'HASH') {
 2043:         $notif_sender = $settings->{'sender_uname'};
 2044:     }
 2045:     my $datatable='<tr class="LC_odd_row">'.
 2046:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 2047:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2048:                   '<input type="radio" name="autoenroll_run"'.
 2049:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2050:                   '<label><input type="radio" name="autoenroll_run"'.
 2051:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2052:                   '</tr><tr>'.
 2053:                   '<td>'.&mt('Notification messages - sender').
 2054:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 2055:                   &mt('username').':&nbsp;'.
 2056:                   '<input type="text" name="sender_uname" value="'.
 2057:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 2058:                   ':&nbsp;'.$domform.'</span></td></tr>'.
 2059:                   '<tr class="LC_odd_row">'.
 2060:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
 2061:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2062:                   '<input type="radio" name="autoassign_coowners"'.
 2063:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2064:                   '<label><input type="radio" name="autoassign_coowners"'.
 2065:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2066:                   '</tr>';
 2067:     $$rowtotal += 3;
 2068:     return $datatable;
 2069: }
 2070: 
 2071: sub print_autoupdate {
 2072:     my ($position,$dom,$settings,$rowtotal) = @_;
 2073:     my $datatable;
 2074:     if ($position eq 'top') {
 2075:         my $updateon = ' ';
 2076:         my $updateoff = ' checked="checked" ';
 2077:         my $classlistson = ' ';
 2078:         my $classlistsoff = ' checked="checked" ';
 2079:         if (ref($settings) eq 'HASH') {
 2080:             if ($settings->{'run'} eq '1') {
 2081:                 $updateon = $updateoff;
 2082:                 $updateoff = ' ';
 2083:             }
 2084:             if ($settings->{'classlists'} eq '1') {
 2085:                 $classlistson = $classlistsoff;
 2086:                 $classlistsoff = ' ';
 2087:             }
 2088:         }
 2089:         my %title = (
 2090:                    run => 'Auto-update active?',
 2091:                    classlists => 'Update information in classlists?',
 2092:                     );
 2093:         $datatable = '<tr class="LC_odd_row">'. 
 2094:                   '<td>'.&mt($title{'run'}).'</td>'.
 2095:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2096:                   '<input type="radio" name="autoupdate_run"'.
 2097:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2098:                   '<label><input type="radio" name="autoupdate_run"'.
 2099:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2100:                   '</tr><tr>'.
 2101:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 2102:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 2103:                   '<label><input type="radio" name="classlists"'.
 2104:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2105:                   '<label><input type="radio" name="classlists"'.
 2106:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2107:                   '</tr>';
 2108:         $$rowtotal += 2;
 2109:     } elsif ($position eq 'middle') {
 2110:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2111:         my $numinrow = 3;
 2112:         my $locknamesettings;
 2113:         $datatable .= &insttypes_row($settings,$types,$usertypes,
 2114:                                      $dom,$numinrow,$othertitle,
 2115:                                     'lockablenames');
 2116:         $$rowtotal ++;
 2117:     } else {
 2118:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2119:         my @fields = ('lastname','firstname','middlename','generation',
 2120:                       'permanentemail','id');
 2121:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 2122:         my $numrows = 0;
 2123:         if (ref($types) eq 'ARRAY') {
 2124:             if (@{$types} > 0) {
 2125:                 $datatable = 
 2126:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 2127:                                          \@fields,$types,\$numrows);
 2128:                     $$rowtotal += @{$types}; 
 2129:             }
 2130:         }
 2131:         $datatable .= 
 2132:             &usertype_update_row($settings,{'default' => $othertitle},
 2133:                                  \%fieldtitles,\@fields,['default'],
 2134:                                  \$numrows);
 2135:         $$rowtotal ++;     
 2136:     }
 2137:     return $datatable;
 2138: }
 2139: 
 2140: sub print_autocreate {
 2141:     my ($dom,$settings,$rowtotal) = @_;
 2142:     my (%createon,%createoff,%currhash);
 2143:     my @types = ('xml','req');
 2144:     if (ref($settings) eq 'HASH') {
 2145:         foreach my $item (@types) {
 2146:             $createoff{$item} = ' checked="checked" ';
 2147:             $createon{$item} = ' ';
 2148:             if (exists($settings->{$item})) {
 2149:                 if ($settings->{$item}) {
 2150:                     $createon{$item} = ' checked="checked" ';
 2151:                     $createoff{$item} = ' ';
 2152:                 }
 2153:             }
 2154:         }
 2155:         if ($settings->{'xmldc'} ne '') { 
 2156:             $currhash{$settings->{'xmldc'}} = 1;
 2157:         }
 2158:     } else {
 2159:         foreach my $item (@types) {
 2160:             $createoff{$item} = ' checked="checked" ';
 2161:             $createon{$item} = ' ';
 2162:         }
 2163:     }
 2164:     $$rowtotal += 2;
 2165:     my $numinrow = 2;
 2166:     my $datatable='<tr class="LC_odd_row">'.
 2167:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
 2168:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2169:                   '<input type="radio" name="autocreate_xml"'.
 2170:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2171:                   '<label><input type="radio" name="autocreate_xml"'.
 2172:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
 2173:                   '</td></tr><tr>'.
 2174:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
 2175:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2176:                   '<input type="radio" name="autocreate_req"'.
 2177:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2178:                   '<label><input type="radio" name="autocreate_req"'.
 2179:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
 2180:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
 2181:                                                    'autocreate_xmldc',%currhash);
 2182:     if ($numdc > 1) {
 2183:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
 2184:                       &mt('Course creation processed as: (choose Dom. Coord.)').
 2185:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
 2186:     } else {
 2187:         $datatable .= $dctable.'</td></tr>';
 2188:     }
 2189:     $$rowtotal += $rows;
 2190:     return $datatable;
 2191: }
 2192: 
 2193: sub print_directorysrch {
 2194:     my ($dom,$settings,$rowtotal) = @_;
 2195:     my $srchon = ' ';
 2196:     my $srchoff = ' checked="checked" ';
 2197:     my ($exacton,$containson,$beginson);
 2198:     my $localon = ' ';
 2199:     my $localoff = ' checked="checked" ';
 2200:     if (ref($settings) eq 'HASH') {
 2201:         if ($settings->{'available'} eq '1') {
 2202:             $srchon = $srchoff;
 2203:             $srchoff = ' ';
 2204:         }
 2205:         if ($settings->{'localonly'} eq '1') {
 2206:             $localon = $localoff;
 2207:             $localoff = ' ';
 2208:         }
 2209:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 2210:             foreach my $type (@{$settings->{'searchtypes'}}) {
 2211:                 if ($type eq 'exact') {
 2212:                     $exacton = ' checked="checked" ';
 2213:                 } elsif ($type eq 'contains') {
 2214:                     $containson = ' checked="checked" ';
 2215:                 } elsif ($type eq 'begins') {
 2216:                     $beginson = ' checked="checked" ';
 2217:                 }
 2218:             }
 2219:         } else {
 2220:             if ($settings->{'searchtypes'} eq 'exact') {
 2221:                 $exacton = ' checked="checked" ';
 2222:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 2223:                 $containson = ' checked="checked" ';
 2224:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 2225:                 $exacton = ' checked="checked" ';
 2226:                 $containson = ' checked="checked" ';
 2227:             }
 2228:         }
 2229:     }
 2230:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 2231:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2232: 
 2233:     my $numinrow = 4;
 2234:     my $cansrchrow = 0;
 2235:     my $datatable='<tr class="LC_odd_row">'.
 2236:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 2237:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2238:                   '<input type="radio" name="dirsrch_available"'.
 2239:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2240:                   '<label><input type="radio" name="dirsrch_available"'.
 2241:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2242:                   '</tr><tr>'.
 2243:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 2244:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2245:                   '<input type="radio" name="dirsrch_localonly"'.
 2246:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 2247:                   '<label><input type="radio" name="dirsrch_localonly"'.
 2248:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 2249:                   '</tr>';
 2250:     $$rowtotal += 2;
 2251:     if (ref($usertypes) eq 'HASH') {
 2252:         if (keys(%{$usertypes}) > 0) {
 2253:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
 2254:                                          $numinrow,$othertitle,'cansearch');
 2255:             $cansrchrow = 1;
 2256:         }
 2257:     }
 2258:     if ($cansrchrow) {
 2259:         $$rowtotal ++;
 2260:         $datatable .= '<tr>';
 2261:     } else {
 2262:         $datatable .= '<tr class="LC_odd_row">';
 2263:     }
 2264:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 2265:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 2266:     foreach my $title (@{$titleorder}) {
 2267:         if (defined($searchtitles->{$title})) {
 2268:             my $check = ' ';
 2269:             if (ref($settings) eq 'HASH') {
 2270:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 2271:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 2272:                         $check = ' checked="checked" ';
 2273:                     }
 2274:                 }
 2275:             }
 2276:             $datatable .= '<td class="LC_left_item">'.
 2277:                           '<span class="LC_nobreak"><label>'.
 2278:                           '<input type="checkbox" name="searchby" '.
 2279:                           'value="'.$title.'"'.$check.'/>'.
 2280:                           $searchtitles->{$title}.'</label></span></td>';
 2281:         }
 2282:     }
 2283:     $datatable .= '</tr></table></td></tr>';
 2284:     $$rowtotal ++;
 2285:     if ($cansrchrow) {
 2286:         $datatable .= '<tr class="LC_odd_row">';
 2287:     } else {
 2288:         $datatable .= '<tr>';
 2289:     }
 2290:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 2291:                   '<td class="LC_left_item" colspan="2">'.
 2292:                   '<span class="LC_nobreak"><label>'.
 2293:                   '<input type="checkbox" name="searchtypes" '.
 2294:                   $exacton.' value="exact" />'.&mt('Exact match').
 2295:                   '</label>&nbsp;'.
 2296:                   '<label><input type="checkbox" name="searchtypes" '.
 2297:                   $beginson.' value="begins" />'.&mt('Begins with').
 2298:                   '</label>&nbsp;'.
 2299:                   '<label><input type="checkbox" name="searchtypes" '.
 2300:                   $containson.' value="contains" />'.&mt('Contains').
 2301:                   '</label></span></td></tr>';
 2302:     $$rowtotal ++;
 2303:     return $datatable;
 2304: }
 2305: 
 2306: sub print_contacts {
 2307:     my ($dom,$settings,$rowtotal) = @_;
 2308:     my $datatable;
 2309:     my @contacts = ('adminemail','supportemail');
 2310:     my (%checked,%to,%otheremails,%bccemails);
 2311:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
 2312:                     'requestsmail','updatesmail','idconflictsmail');
 2313:     foreach my $type (@mailings) {
 2314:         $otheremails{$type} = '';
 2315:     }
 2316:     $bccemails{'helpdeskmail'} = '';
 2317:     if (ref($settings) eq 'HASH') {
 2318:         foreach my $item (@contacts) {
 2319:             if (exists($settings->{$item})) {
 2320:                 $to{$item} = $settings->{$item};
 2321:             }
 2322:         }
 2323:         foreach my $type (@mailings) {
 2324:             if (exists($settings->{$type})) {
 2325:                 if (ref($settings->{$type}) eq 'HASH') {
 2326:                     foreach my $item (@contacts) {
 2327:                         if ($settings->{$type}{$item}) {
 2328:                             $checked{$type}{$item} = ' checked="checked" ';
 2329:                         }
 2330:                     }
 2331:                     $otheremails{$type} = $settings->{$type}{'others'};
 2332:                     if ($type eq 'helpdeskmail') {
 2333:                         $bccemails{$type} = $settings->{$type}{'bcc'};
 2334:                     }
 2335:                 }
 2336:             } elsif ($type eq 'lonstatusmail') {
 2337:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
 2338:             }
 2339:         }
 2340:     } else {
 2341:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2342:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2343:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 2344:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 2345:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
 2346:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
 2347:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
 2348:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
 2349:         $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
 2350:     }
 2351:     my ($titles,$short_titles) = &contact_titles();
 2352:     my $rownum = 0;
 2353:     my $css_class;
 2354:     foreach my $item (@contacts) {
 2355:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2356:         $datatable .= '<tr'.$css_class.'>'. 
 2357:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2358:                   '</span></td><td class="LC_right_item">'.
 2359:                   '<input type="text" name="'.$item.'" value="'.
 2360:                   $to{$item}.'" /></td></tr>';
 2361:         $rownum ++;
 2362:     }
 2363:     foreach my $type (@mailings) {
 2364:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2365:         $datatable .= '<tr'.$css_class.'>'.
 2366:                       '<td><span class="LC_nobreak">'.
 2367:                       $titles->{$type}.': </span></td>'.
 2368:                       '<td class="LC_left_item">'.
 2369:                       '<span class="LC_nobreak">';
 2370:         foreach my $item (@contacts) {
 2371:             $datatable .= '<label>'.
 2372:                           '<input type="checkbox" name="'.$type.'"'.
 2373:                           $checked{$type}{$item}.
 2374:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 2375:                           '</label>&nbsp;';
 2376:         }
 2377:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 2378:                       '<input type="text" name="'.$type.'_others" '.
 2379:                       'value="'.$otheremails{$type}.'"  />';
 2380:         if ($type eq 'helpdeskmail') {
 2381:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
 2382:                           '<input type="text" name="'.$type.'_bcc" '.
 2383:                           'value="'.$bccemails{$type}.'"  />';
 2384:         }
 2385:         $datatable .= '</td></tr>'."\n";
 2386:         $rownum ++;
 2387:     }
 2388:     my %choices;
 2389:     $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
 2390:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 2391:                                    &mt('LON-CAPA core group - MSU'),600,500));
 2392:     $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
 2393:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 2394:                                     &mt('LON-CAPA core group - MSU'),600,500));
 2395:     my @toggles = ('reporterrors','reportupdates');
 2396:     my %defaultchecked = ('reporterrors'  => 'on',
 2397:                           'reportupdates' => 'on');
 2398:     (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2399:                                                \%choices,$rownum);
 2400:     $datatable .= $reports;
 2401:     $$rowtotal += $rownum;
 2402:     return $datatable;
 2403: }
 2404: 
 2405: sub print_helpsettings {
 2406:     my ($dom,$confname,$settings,$rowtotal) = @_;
 2407:     my ($datatable,$itemcount);
 2408:     $itemcount = 1;
 2409:     my (%choices,%defaultchecked,@toggles);
 2410:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
 2411:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
 2412:                                  &mt('LON-CAPA bug tracker'),600,500));
 2413:     %defaultchecked = ('submitbugs' => 'on');
 2414:     @toggles = ('submitbugs',);
 2415: 
 2416:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2417:                                                  \%choices,$itemcount);
 2418:     return $datatable;
 2419: }
 2420: 
 2421: sub radiobutton_prefs {
 2422:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
 2423:         $additional) = @_;
 2424:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
 2425:                    (ref($choices) eq 'HASH'));
 2426: 
 2427:     my (%checkedon,%checkedoff,$datatable,$css_class);
 2428: 
 2429:     foreach my $item (@{$toggles}) {
 2430:         if ($defaultchecked->{$item} eq 'on') {
 2431:             $checkedon{$item} = ' checked="checked" ';
 2432:             $checkedoff{$item} = ' ';
 2433:         } elsif ($defaultchecked->{$item} eq 'off') {
 2434:             $checkedoff{$item} = ' checked="checked" ';
 2435:             $checkedon{$item} = ' ';
 2436:         }
 2437:     }
 2438:     if (ref($settings) eq 'HASH') {
 2439:         foreach my $item (@{$toggles}) {
 2440:             if ($settings->{$item} eq '1') {
 2441:                 $checkedon{$item} =  ' checked="checked" ';
 2442:                 $checkedoff{$item} = ' ';
 2443:             } elsif ($settings->{$item} eq '0') {
 2444:                 $checkedoff{$item} =  ' checked="checked" ';
 2445:                 $checkedon{$item} = ' ';
 2446:             }
 2447:         }
 2448:     }
 2449:     if ($onclick) {
 2450:         $onclick = ' onclick="'.$onclick.'"';
 2451:     }
 2452:     foreach my $item (@{$toggles}) {
 2453:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2454:         $datatable .=
 2455:             '<tr'.$css_class.'><td valign="top">'.
 2456:             '<span class="LC_nobreak">'.$choices->{$item}.
 2457:             '</span></td>'.
 2458:             '<td class="LC_right_item"><span class="LC_nobreak">'.
 2459:             '<label><input type="radio" name="'.
 2460:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
 2461:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
 2462:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
 2463:             '</span>'.$additional.
 2464:             '</td>'.
 2465:             '</tr>';
 2466:         $itemcount ++;
 2467:     }
 2468:     return ($datatable,$itemcount);
 2469: }
 2470: 
 2471: sub print_coursedefaults {
 2472:     my ($position,$dom,$settings,$rowtotal) = @_;
 2473:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
 2474:     my $itemcount = 1;
 2475:     my %choices =  &Apache::lonlocal::texthash (
 2476:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
 2477:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
 2478:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
 2479:         coursecredits        => 'Credits can be specified for courses',
 2480:     );
 2481:     my %staticdefaults = (
 2482:                            anonsurvey_threshold => 10,
 2483:                            uploadquota          => 500,
 2484:                          );
 2485:     if ($position eq 'top') {
 2486:         %defaultchecked = ('canuse_pdfforms' => 'off');
 2487:         @toggles = ('canuse_pdfforms');
 2488:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2489:                                                  \%choices,$itemcount);
 2490:     } else {
 2491:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2492:         my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
 2493:         my $currusecredits = 0;
 2494:         my @types = ('official','unofficial','community');
 2495:         if (ref($settings) eq 'HASH') {
 2496:             $currdefresponder = $settings->{'anonsurvey_threshold'};
 2497:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
 2498:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
 2499:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
 2500:                 }
 2501:             }
 2502:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
 2503:                 $def_official_credits = $settings->{'coursecredits'}->{'official'};
 2504:                 $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
 2505:                 if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
 2506:                     $currusecredits = 1;
 2507:                 }
 2508:             }
 2509:         }
 2510:         if (!$currdefresponder) {
 2511:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
 2512:         } elsif ($currdefresponder < 1) {
 2513:             $currdefresponder = 1;
 2514:         }
 2515:         foreach my $type (@types) {
 2516:             if ($curruploadquota{$type} eq '') {
 2517:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
 2518:             }
 2519:         }
 2520:         $datatable .=
 2521:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 2522:                 $choices{'anonsurvey_threshold'}.
 2523:                 '</span></td>'.
 2524:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
 2525:                 '<input type="text" name="anonsurvey_threshold"'.
 2526:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
 2527:                 '</td></tr>'."\n".
 2528:                 '<tr><td><span class="LC_nobreak">'.
 2529:                 $choices{'uploadquota'}.
 2530:                 '</span></td>'.
 2531:                 '<td align="right" class="LC_right_item">'.
 2532:                 '<table><tr>';
 2533:         foreach my $type (@types) {
 2534:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
 2535:                            '<input type="text" name="uploadquota_'.$type.'"'.
 2536:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
 2537:         }
 2538:         $datatable .= '</tr></table></td></tr>'."\n";
 2539:         $itemcount += 2;
 2540:         my $onclick = 'toggleCredits(this.form);';
 2541:         my $display = 'none';  
 2542:         if ($currusecredits) {
 2543:             $display = 'block';
 2544:         }
 2545:         my $additional = '<div id="credits" style="display: '.$display.'">'.
 2546:                          '<span class="LC_nobreak">'.
 2547:                          &mt('Default credits for official courses [_1]',
 2548:                          '<input type="text" name="official_credits" value="'.
 2549:                          $def_official_credits.'" size="3" />').
 2550:                          '</span><br />'.
 2551:                          '<span class="LC_nobreak">'.
 2552:                          &mt('Default credits for unofficial courses [_1]',
 2553:                          '<input type="text" name="unofficial_credits" value="'.
 2554:                          $def_unofficial_credits.'" size="3" />').
 2555:                          '</span></div>'."\n";
 2556:         %defaultchecked = ('coursecredits' => 'off');
 2557:         @toggles = ('coursecredits');
 2558:         my $current = {
 2559:                         'coursecredits' => $currusecredits,
 2560:                       };
 2561:         (my $table,$itemcount) =
 2562:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
 2563:                                \%choices,$itemcount,$onclick,$additional);
 2564:         $datatable .= $table;
 2565:     }
 2566:     $$rowtotal += $itemcount;
 2567:     return $datatable;
 2568: }
 2569: 
 2570: sub print_usersessions {
 2571:     my ($position,$dom,$settings,$rowtotal) = @_;
 2572:     my ($css_class,$datatable,%checked,%choices);
 2573:     my (%by_ip,%by_location,@intdoms);
 2574:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 2575: 
 2576:     my @alldoms = &Apache::lonnet::all_domains();
 2577:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
 2578:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 2579:     my %altids = &id_for_thisdom(%servers);
 2580:     my $itemcount = 1;
 2581:     if ($position eq 'top') {
 2582:         if (keys(%serverhomes) > 1) {
 2583:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
 2584:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
 2585:         } else {
 2586:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 2587:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
 2588:         }
 2589:     } else {
 2590:         if (keys(%by_location) == 0) {
 2591:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 2592:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
 2593:         } else {
 2594:             my %lt = &usersession_titles();
 2595:             my $numinrow = 5;
 2596:             my $prefix;
 2597:             my @types;
 2598:             if ($position eq 'bottom') {
 2599:                 $prefix = 'remote';
 2600:                 @types = ('version','excludedomain','includedomain');
 2601:             } else {
 2602:                 $prefix = 'hosted';
 2603:                 @types = ('excludedomain','includedomain');
 2604:             }
 2605:             my (%current,%checkedon,%checkedoff);
 2606:             my @lcversions = &Apache::lonnet::all_loncaparevs();
 2607:             my @locations = sort(keys(%by_location));
 2608:             foreach my $type (@types) {
 2609:                 $checkedon{$type} = '';
 2610:                 $checkedoff{$type} = ' checked="checked"';
 2611:             }
 2612:             if (ref($settings) eq 'HASH') {
 2613:                 if (ref($settings->{$prefix}) eq 'HASH') {
 2614:                     foreach my $key (keys(%{$settings->{$prefix}})) {
 2615:                         $current{$key} = $settings->{$prefix}{$key};
 2616:                         if ($key eq 'version') {
 2617:                             if ($current{$key} ne '') {
 2618:                                 $checkedon{$key} = ' checked="checked"';
 2619:                                 $checkedoff{$key} = '';
 2620:                             }
 2621:                         } elsif (ref($current{$key}) eq 'ARRAY') {
 2622:                             $checkedon{$key} = ' checked="checked"';
 2623:                             $checkedoff{$key} = '';
 2624:                         }
 2625:                     }
 2626:                 }
 2627:             }
 2628:             foreach my $type (@types) {
 2629:                 next if ($type ne 'version' && !@locations);
 2630:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2631:                 $datatable .= '<tr'.$css_class.'>
 2632:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
 2633:                                <span class="LC_nobreak">&nbsp;
 2634:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
 2635:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
 2636:                 if ($type eq 'version') {
 2637:                     my $selector = '<select name="'.$prefix.'_version">';
 2638:                     foreach my $version (@lcversions) {
 2639:                         my $selected = '';
 2640:                         if ($current{'version'} eq $version) {
 2641:                             $selected = ' selected="selected"';
 2642:                         }
 2643:                         $selector .= ' <option value="'.$version.'"'.
 2644:                                      $selected.'>'.$version.'</option>';
 2645:                     }
 2646:                     $selector .= '</select> ';
 2647:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
 2648:                 } else {
 2649:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
 2650:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
 2651:                                  ' />'.('&nbsp;'x2).
 2652:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
 2653:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
 2654:                                  "\n".
 2655:                                  '</div><div><table>';
 2656:                     my $rem;
 2657:                     for (my $i=0; $i<@locations; $i++) {
 2658:                         my ($showloc,$value,$checkedtype);
 2659:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
 2660:                             my $ip = $by_location{$locations[$i]}->[0];
 2661:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
 2662:                                  $value = join(':',@{$by_ip{$ip}});
 2663:                                 $showloc = join(', ',@{$by_ip{$ip}});
 2664:                                 if (ref($current{$type}) eq 'ARRAY') {
 2665:                                     foreach my $loc (@{$by_ip{$ip}}) {  
 2666:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
 2667:                                             $checkedtype = ' checked="checked"';
 2668:                                             last;
 2669:                                         }
 2670:                                     }
 2671:                                 }
 2672:                             }
 2673:                         }
 2674:                         $rem = $i%($numinrow);
 2675:                         if ($rem == 0) {
 2676:                             if ($i > 0) {
 2677:                                 $datatable .= '</tr>';
 2678:                             }
 2679:                             $datatable .= '<tr>';
 2680:                         }
 2681:                         $datatable .= '<td class="LC_left_item">'.
 2682:                                       '<span class="LC_nobreak"><label>'.
 2683:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
 2684:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
 2685:                                       '</label></span></td>';
 2686:                     }
 2687:                     $rem = @locations%($numinrow);
 2688:                     my $colsleft = $numinrow - $rem;
 2689:                     if ($colsleft > 1 ) {
 2690:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2691:                                       '&nbsp;</td>';
 2692:                     } elsif ($colsleft == 1) {
 2693:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 2694:                     }
 2695:                     $datatable .= '</tr></table>';
 2696:                 }
 2697:                 $datatable .= '</td></tr>';
 2698:                 $itemcount ++;
 2699:             }
 2700:         }
 2701:     }
 2702:     $$rowtotal += $itemcount;
 2703:     return $datatable;
 2704: }
 2705: 
 2706: sub build_location_hashes {
 2707:     my ($intdoms,$by_ip,$by_location) = @_;
 2708:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
 2709:                   (ref($by_location) eq 'HASH')); 
 2710:     my %iphost = &Apache::lonnet::get_iphost();
 2711:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
 2712:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
 2713:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
 2714:         foreach my $id (@{$iphost{$primary_ip}}) {
 2715:             my $intdom = &Apache::lonnet::internet_dom($id);
 2716:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
 2717:                 push(@{$intdoms},$intdom);
 2718:             }
 2719:         }
 2720:     }
 2721:     foreach my $ip (keys(%iphost)) {
 2722:         if (ref($iphost{$ip}) eq 'ARRAY') {
 2723:             foreach my $id (@{$iphost{$ip}}) {
 2724:                 my $location = &Apache::lonnet::internet_dom($id);
 2725:                 if ($location) {
 2726:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
 2727:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2728:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
 2729:                             push(@{$by_ip->{$ip}},$location);
 2730:                         }
 2731:                     } else {
 2732:                         $by_ip->{$ip} = [$location];
 2733:                     }
 2734:                 }
 2735:             }
 2736:         }
 2737:     }
 2738:     foreach my $ip (sort(keys(%{$by_ip}))) {
 2739:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2740:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
 2741:             my $first = $by_ip->{$ip}->[0];
 2742:             if (ref($by_location->{$first}) eq 'ARRAY') {
 2743:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
 2744:                     push(@{$by_location->{$first}},$ip);
 2745:                 }
 2746:             } else {
 2747:                 $by_location->{$first} = [$ip];
 2748:             }
 2749:         }
 2750:     }
 2751:     return;
 2752: }
 2753: 
 2754: sub current_offloads_to {
 2755:     my ($dom,$settings,$servers) = @_;
 2756:     my (%spareid,%otherdomconfigs);
 2757:     if (ref($servers) eq 'HASH') {
 2758:         foreach my $lonhost (sort(keys(%{$servers}))) {
 2759:             my $gotspares;
 2760:             if (ref($settings) eq 'HASH') {
 2761:                 if (ref($settings->{'spares'}) eq 'HASH') {
 2762:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
 2763:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
 2764:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
 2765:                         $gotspares = 1;
 2766:                     }
 2767:                 }
 2768:             }
 2769:             unless ($gotspares) {
 2770:                 my $gotspares;
 2771:                 my $serverhomeID =
 2772:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
 2773:                 my $serverhomedom =
 2774:                     &Apache::lonnet::host_domain($serverhomeID);
 2775:                 if ($serverhomedom ne $dom) {
 2776:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
 2777:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 2778:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 2779:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 2780:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 2781:                                 $gotspares = 1;
 2782:                             }
 2783:                         }
 2784:                     } else {
 2785:                         $otherdomconfigs{$serverhomedom} =
 2786:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
 2787:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
 2788:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 2789:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 2790:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
 2791:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 2792:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 2793:                                         $gotspares = 1;
 2794:                                     }
 2795:                                 }
 2796:                             }
 2797:                         }
 2798:                     }
 2799:                 }
 2800:             }
 2801:             unless ($gotspares) {
 2802:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
 2803:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 2804:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 2805:                } else {
 2806:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
 2807:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
 2808:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
 2809:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 2810:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 2811:                     } else {
 2812:                         my %what = (
 2813:                              spareid => 1,
 2814:                         );
 2815:                         my ($result,$returnhash) = 
 2816:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
 2817:                         if ($result eq 'ok') { 
 2818:                             if (ref($returnhash) eq 'HASH') {
 2819:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
 2820:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
 2821:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
 2822:                                 }
 2823:                             }
 2824:                         }
 2825:                     }
 2826:                 }
 2827:             }
 2828:         }
 2829:     }
 2830:     return %spareid;
 2831: }
 2832: 
 2833: sub spares_row {
 2834:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
 2835:     my $css_class;
 2836:     my $numinrow = 4;
 2837:     my $itemcount = 1;
 2838:     my $datatable;
 2839:     my %typetitles = &sparestype_titles();
 2840:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
 2841:         foreach my $server (sort(keys(%{$servers}))) {
 2842:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
 2843:             my ($othercontrol,$serverdom);
 2844:             if ($serverhome ne $server) {
 2845:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
 2846:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 2847:             } else {
 2848:                 $serverdom = &Apache::lonnet::host_domain($server);
 2849:                 if ($serverdom ne $dom) {
 2850:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 2851:                 }
 2852:             }
 2853:             next unless (ref($spareid->{$server}) eq 'HASH');
 2854:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2855:             $datatable .= '<tr'.$css_class.'>
 2856:                            <td rowspan="2">
 2857:                             <span class="LC_nobreak">'.
 2858:                           &mt('[_1] when busy, offloads to:'
 2859:                               ,'<b>'.$server.'</b>').
 2860:                           "\n";
 2861:             my (%current,%canselect);
 2862:             my @choices = 
 2863:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
 2864:             foreach my $type ('primary','default') {
 2865:                 if (ref($spareid->{$server}) eq 'HASH') {
 2866:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
 2867:                         my @spares = @{$spareid->{$server}{$type}};
 2868:                         if (@spares > 0) {
 2869:                             if ($othercontrol) {
 2870:                                 $current{$type} = join(', ',@spares);
 2871:                             } else {
 2872:                                 $current{$type} .= '<table>';
 2873:                                 my $numspares = scalar(@spares);
 2874:                                 for (my $i=0;  $i<@spares; $i++) {
 2875:                                     my $rem = $i%($numinrow);
 2876:                                     if ($rem == 0) {
 2877:                                         if ($i > 0) {
 2878:                                             $current{$type} .= '</tr>';
 2879:                                         }
 2880:                                         $current{$type} .= '<tr>';
 2881:                                     }
 2882:                                     $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" />&nbsp;'.
 2883:                                                        $spareid->{$server}{$type}[$i].
 2884:                                                        '</label></td>'."\n";
 2885:                                 }
 2886:                                 my $rem = @spares%($numinrow);
 2887:                                 my $colsleft = $numinrow - $rem;
 2888:                                 if ($colsleft > 1 ) {
 2889:                                     $current{$type} .= '<td colspan="'.$colsleft.
 2890:                                                        '" class="LC_left_item">'.
 2891:                                                        '&nbsp;</td>';
 2892:                                 } elsif ($colsleft == 1) {
 2893:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
 2894:                                 }
 2895:                                 $current{$type} .= '</tr></table>';
 2896:                             }
 2897:                         }
 2898:                     }
 2899:                     if ($current{$type} eq '') {
 2900:                         $current{$type} = &mt('None specified');
 2901:                     }
 2902:                     if ($othercontrol) {
 2903:                         if ($type eq 'primary') {
 2904:                             $canselect{$type} = $othercontrol;
 2905:                         }
 2906:                     } else {
 2907:                         $canselect{$type} = 
 2908:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
 2909:                             '<select name="newspare_'.$type.'_'.$server.'" '.
 2910:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
 2911:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
 2912:                         if (@choices > 0) {
 2913:                             foreach my $lonhost (@choices) {
 2914:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
 2915:                             }
 2916:                         }
 2917:                         $canselect{$type} .= '</select>'."\n";
 2918:                     }
 2919:                 } else {
 2920:                     $current{$type} = &mt('Could not be determined');
 2921:                     if ($type eq 'primary') {
 2922:                         $canselect{$type} =  $othercontrol;
 2923:                     }
 2924:                 }
 2925:                 if ($type eq 'default') {
 2926:                     $datatable .= '<tr'.$css_class.'>';
 2927:                 }
 2928:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
 2929:                               '<td>'.$current{$type}.'</td>'."\n".
 2930:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
 2931:             }
 2932:             $itemcount ++;
 2933:         }
 2934:     }
 2935:     $$rowtotal += $itemcount;
 2936:     return $datatable;
 2937: }
 2938: 
 2939: sub possible_newspares {
 2940:     my ($server,$currspares,$serverhomes,$altids) = @_;
 2941:     my $serverhostname = &Apache::lonnet::hostname($server);
 2942:     my %excluded;
 2943:     if ($serverhostname ne '') {
 2944:         %excluded = (
 2945:                        $serverhostname => 1,
 2946:                     );
 2947:     }
 2948:     if (ref($currspares) eq 'HASH') {
 2949:         foreach my $type (keys(%{$currspares})) {
 2950:             if (ref($currspares->{$type}) eq 'ARRAY') {
 2951:                 if (@{$currspares->{$type}} > 0) {
 2952:                     foreach my $curr (@{$currspares->{$type}}) {
 2953:                         my $hostname = &Apache::lonnet::hostname($curr);
 2954:                         $excluded{$hostname} = 1;
 2955:                     }
 2956:                 }
 2957:             }
 2958:         }
 2959:     }
 2960:     my @choices;
 2961:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
 2962:         if (keys(%{$serverhomes}) > 1) {
 2963:             foreach my $name (sort(keys(%{$serverhomes}))) {
 2964:                 unless ($excluded{$name}) {
 2965:                     if (exists($altids->{$serverhomes->{$name}})) {
 2966:                         push(@choices,$altids->{$serverhomes->{$name}});
 2967:                     } else {
 2968:                         push(@choices,$serverhomes->{$name});
 2969:                     }
 2970:                 }
 2971:             }
 2972:         }
 2973:     }
 2974:     return sort(@choices);
 2975: }
 2976: 
 2977: sub print_loadbalancing {
 2978:     my ($dom,$settings,$rowtotal) = @_;
 2979:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
 2980:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
 2981:     my $numinrow = 1;
 2982:     my $datatable;
 2983:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 2984:     my (%currbalancer,%currtargets,%currrules,%existing);
 2985:     if (ref($settings) eq 'HASH') {
 2986:         %existing = %{$settings};
 2987:     }
 2988:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
 2989:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
 2990:                                   \%currtargets,\%currrules);
 2991:     } else {
 2992:         return;
 2993:     }
 2994:     my ($othertitle,$usertypes,$types) =
 2995:         &Apache::loncommon::sorted_inst_types($dom);
 2996:     my $rownum = 6;
 2997:     if (ref($types) eq 'ARRAY') {
 2998:         $rownum += scalar(@{$types});
 2999:     }
 3000:     my @css_class = ('LC_odd_row','LC_even_row');
 3001:     my $balnum = 0;
 3002:     my $islast;
 3003:     my (@toshow,$disabledtext);
 3004:     if (keys(%currbalancer) > 0) {
 3005:         @toshow = sort(keys(%currbalancer));
 3006:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
 3007:             push(@toshow,'');
 3008:         }
 3009:     } else {
 3010:         @toshow = ('');
 3011:         $disabledtext = &mt('No existing load balancer');
 3012:     }
 3013:     foreach my $lonhost (@toshow) {
 3014:         if ($balnum == scalar(@toshow)-1) {
 3015:             $islast = 1;
 3016:         } else {
 3017:             $islast = 0;
 3018:         }
 3019:         my $cssidx = $balnum%2;
 3020:         my $targets_div_style = 'display: none';
 3021:         my $disabled_div_style = 'display: block';
 3022:         my $homedom_div_style = 'display: none';
 3023:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
 3024:                       '<td rowspan="'.$rownum.'" valign="top">'.
 3025:                       '<p>';
 3026:         if ($lonhost eq '') {
 3027:             $datatable .= '<span class="LC_nobreak">'; 
 3028:             if (keys(%currbalancer) > 0) {
 3029:                 $datatable .= &mt('Add balancer:');
 3030:             } else {
 3031:                 $datatable .= &mt('Enable balancer:');
 3032:             }
 3033:             $datatable .= '&nbsp;'.
 3034:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
 3035:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
 3036:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
 3037:                           '<option value="" selected="selected">'.&mt('None').
 3038:                           '</option>'."\n";
 3039:             foreach my $server (sort(keys(%servers))) {
 3040:                 next if ($currbalancer{$server});
 3041:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
 3042:             }
 3043:             $datatable .= 
 3044:                 '</select>'."\n".
 3045:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
 3046:         } else {
 3047:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
 3048:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
 3049:                            &mt('Stop balancing').'</label>'.
 3050:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
 3051:             $targets_div_style = 'display: block';
 3052:             $disabled_div_style = 'display: none';
 3053:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
 3054:                 $homedom_div_style = 'display: block';
 3055:             }
 3056:         }
 3057:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
 3058:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
 3059:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
 3060:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
 3061:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
 3062:         my @sparestypes = ('primary','default');
 3063:         my %typetitles = &sparestype_titles();
 3064:         foreach my $sparetype (@sparestypes) {
 3065:             my $targettable;
 3066:             for (my $i=0; $i<$numspares; $i++) {
 3067:                 my $checked;
 3068:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
 3069:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
 3070:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
 3071:                             $checked = ' checked="checked"';
 3072:                         }
 3073:                     }
 3074:                 }
 3075:                 my ($chkboxval,$disabled);
 3076:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
 3077:                     $chkboxval = $spares[$i];
 3078:                 }
 3079:                 if (exists($currbalancer{$spares[$i]})) {
 3080:                     $disabled = ' disabled="disabled"';
 3081:                 }
 3082:                 $targettable .= 
 3083:                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
 3084:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
 3085:                     '</span></label></td>';
 3086:                 my $rem = $i%($numinrow);
 3087:                 if ($rem == 0) {
 3088:                     if (($i > 0) && ($i < $numspares-1)) {
 3089:                         $targettable .= '</tr>';
 3090:                     }
 3091:                     if ($i < $numspares-1) {
 3092:                         $targettable .= '<tr>';
 3093:                     }
 3094:                 }
 3095:             }
 3096:             if ($targettable ne '') {
 3097:                 my $rem = $numspares%($numinrow);
 3098:                 my $colsleft = $numinrow - $rem;
 3099:                 if ($colsleft > 1 ) {
 3100:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3101:                                     '&nbsp;</td>';
 3102:                 } elsif ($colsleft == 1) {
 3103:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
 3104:                 }
 3105:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
 3106:                                '<table><tr>'.$targettable.'</tr></table><br />';
 3107:             }
 3108:         }
 3109:         $datatable .= '</div></td></tr>'.
 3110:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
 3111:                                            $othertitle,$usertypes,$types,\%servers,
 3112:                                            \%currbalancer,$lonhost,
 3113:                                            $targets_div_style,$homedom_div_style,
 3114:                                            $css_class[$cssidx],$balnum,$islast);
 3115:         $$rowtotal += $rownum;
 3116:         $balnum ++;
 3117:     }
 3118:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
 3119:     return $datatable;
 3120: }
 3121: 
 3122: sub get_loadbalancers_config {
 3123:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
 3124:     return unless ((ref($servers) eq 'HASH') &&
 3125:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
 3126:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
 3127:     if (keys(%{$existing}) > 0) {
 3128:         my $oldlonhost;
 3129:         foreach my $key (sort(keys(%{$existing}))) {
 3130:             if ($key eq 'lonhost') {
 3131:                 $oldlonhost = $existing->{'lonhost'};
 3132:                 $currbalancer->{$oldlonhost} = 1;
 3133:             } elsif ($key eq 'targets') {
 3134:                 if ($oldlonhost) {
 3135:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
 3136:                 }
 3137:             } elsif ($key eq 'rules') {
 3138:                 if ($oldlonhost) {
 3139:                     $currrules->{$oldlonhost} = $existing->{'rules'};
 3140:                 }
 3141:             } elsif (ref($existing->{$key}) eq 'HASH') {
 3142:                 $currbalancer->{$key} = 1;
 3143:                 $currtargets->{$key} = $existing->{$key}{'targets'};
 3144:                 $currrules->{$key} = $existing->{$key}{'rules'};
 3145:             }
 3146:         }
 3147:     } else {
 3148:         my ($balancerref,$targetsref) =
 3149:                 &Apache::lonnet::get_lonbalancer_config($servers);
 3150:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
 3151:             foreach my $server (sort(keys(%{$balancerref}))) {
 3152:                 $currbalancer->{$server} = 1;
 3153:                 $currtargets->{$server} = $targetsref->{$server};
 3154:             }
 3155:         }
 3156:     }
 3157:     return;
 3158: }
 3159: 
 3160: sub loadbalancing_rules {
 3161:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
 3162:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
 3163:         $css_class,$balnum,$islast) = @_;
 3164:     my $output;
 3165:     my $num = 0;
 3166:     my ($alltypes,$othertypes,$titles) = 
 3167:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
 3168:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
 3169:         foreach my $type (@{$alltypes}) {
 3170:             $num ++;
 3171:             my $current;
 3172:             if (ref($currrules) eq 'HASH') {
 3173:                 $current = $currrules->{$type};
 3174:             }
 3175:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3176:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
 3177:                     $current = '';
 3178:                 }
 3179:             }
 3180:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
 3181:                                              $servers,$currbalancer,$lonhost,$dom,
 3182:                                              $targets_div_style,$homedom_div_style,
 3183:                                              $css_class,$balnum,$num,$islast);
 3184:         }
 3185:     }
 3186:     return $output;
 3187: }
 3188: 
 3189: sub loadbalancing_titles {
 3190:     my ($dom,$intdom,$usertypes,$types) = @_;
 3191:     my %othertypes = (
 3192:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
 3193:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
 3194:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
 3195:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
 3196:                      );
 3197:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
 3198:     if (ref($types) eq 'ARRAY') {
 3199:         unshift(@alltypes,@{$types},'default');
 3200:     }
 3201:     my %titles;
 3202:     foreach my $type (@alltypes) {
 3203:         if ($type =~ /^_LC_/) {
 3204:             $titles{$type} = $othertypes{$type};
 3205:         } elsif ($type eq 'default') {
 3206:             $titles{$type} = &mt('All users from [_1]',$dom);
 3207:             if (ref($types) eq 'ARRAY') {
 3208:                 if (@{$types} > 0) {
 3209:                     $titles{$type} = &mt('Other users from [_1]',$dom);
 3210:                 }
 3211:             }
 3212:         } elsif (ref($usertypes) eq 'HASH') {
 3213:             $titles{$type} = $usertypes->{$type};
 3214:         }
 3215:     }
 3216:     return (\@alltypes,\%othertypes,\%titles);
 3217: }
 3218: 
 3219: sub loadbalance_rule_row {
 3220:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
 3221:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
 3222:     my @rulenames = ('default','homeserver');
 3223:     my %ruletitles = &offloadtype_text();
 3224:     if ($type eq '_LC_external') {
 3225:         push(@rulenames,'externalbalancer');
 3226:     } else {
 3227:         push(@rulenames,'specific');
 3228:     }
 3229:     push(@rulenames,'none');
 3230:     my $style = $targets_div_style;
 3231:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3232:         $style = $homedom_div_style;
 3233:     }
 3234:     my $space;
 3235:     if ($islast && $num == 1) {
 3236:         $space = '<div display="inline-block">&nbsp;</div>';
 3237:     }
 3238:     my $output = 
 3239:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
 3240:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
 3241:         '<td valaign="top">'.$space.
 3242:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
 3243:     for (my $i=0; $i<@rulenames; $i++) {
 3244:         my $rule = $rulenames[$i];
 3245:         my ($checked,$extra);
 3246:         if ($rulenames[$i] eq 'default') {
 3247:             $rule = '';
 3248:         }
 3249:         if ($rulenames[$i] eq 'specific') {
 3250:             if (ref($servers) eq 'HASH') {
 3251:                 my $default;
 3252:                 if (($current ne '') && (exists($servers->{$current}))) {
 3253:                     $checked = ' checked="checked"';
 3254:                 }
 3255:                 unless ($checked) {
 3256:                     $default = ' selected="selected"';
 3257:                 }
 3258:                 $extra = 
 3259:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
 3260:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
 3261:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
 3262:                     '<option value=""'.$default.'></option>'."\n";
 3263:                 foreach my $server (sort(keys(%{$servers}))) {
 3264:                     if (ref($currbalancer) eq 'HASH') {
 3265:                         next if (exists($currbalancer->{$server}));
 3266:                     }
 3267:                     my $selected;
 3268:                     if ($server eq $current) {
 3269:                         $selected = ' selected="selected"';
 3270:                     }
 3271:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
 3272:                 }
 3273:                 $extra .= '</select>';
 3274:             }
 3275:         } elsif ($rule eq $current) {
 3276:             $checked = ' checked="checked"';
 3277:         }
 3278:         $output .= '<span class="LC_nobreak"><label>'.
 3279:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
 3280:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
 3281:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
 3282:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
 3283:                    '</label>'.$extra.'</span><br />'."\n";
 3284:     }
 3285:     $output .= '</div></td></tr>'."\n";
 3286:     return $output;
 3287: }
 3288: 
 3289: sub offloadtype_text {
 3290:     my %ruletitles = &Apache::lonlocal::texthash (
 3291:            'default'          => 'Offloads to default destinations',
 3292:            'homeserver'       => "Offloads to user's home server",
 3293:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
 3294:            'specific'         => 'Offloads to specific server',
 3295:            'none'             => 'No offload',
 3296:     );
 3297:     return %ruletitles;
 3298: }
 3299: 
 3300: sub sparestype_titles {
 3301:     my %typestitles = &Apache::lonlocal::texthash (
 3302:                           'primary' => 'primary',
 3303:                           'default' => 'default',
 3304:                       );
 3305:     return %typestitles;
 3306: }
 3307: 
 3308: sub contact_titles {
 3309:     my %titles = &Apache::lonlocal::texthash (
 3310:                    'supportemail' => 'Support E-mail address',
 3311:                    'adminemail'   => 'Default Server Admin E-mail address',
 3312:                    'errormail'    => 'Error reports to be e-mailed to',
 3313:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 3314:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
 3315:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
 3316:                    'requestsmail' => 'E-mail from course requests requiring approval',
 3317:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
 3318:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
 3319:                  );
 3320:     my %short_titles = &Apache::lonlocal::texthash (
 3321:                            adminemail   => 'Admin E-mail address',
 3322:                            supportemail => 'Support E-mail',
 3323:                        );   
 3324:     return (\%titles,\%short_titles);
 3325: }
 3326: 
 3327: sub tool_titles {
 3328:     my %titles = &Apache::lonlocal::texthash (
 3329:                      aboutme    => 'Personal web page',
 3330:                      blog       => 'Blog',
 3331:                      webdav     => 'WebDAV',
 3332:                      portfolio  => 'Portfolio',
 3333:                      official   => 'Official courses (with institutional codes)',
 3334:                      unofficial => 'Unofficial courses',
 3335:                      community  => 'Communities',
 3336:                  );
 3337:     return %titles;
 3338: }
 3339: 
 3340: sub courserequest_titles {
 3341:     my %titles = &Apache::lonlocal::texthash (
 3342:                                    official   => 'Official',
 3343:                                    unofficial => 'Unofficial',
 3344:                                    community  => 'Communities',
 3345:                                    norequest  => 'Not allowed',
 3346:                                    approval   => 'Approval by Dom. Coord.',
 3347:                                    validate   => 'With validation',
 3348:                                    autolimit  => 'Numerical limit',
 3349:                                    unlimited  => '(blank for unlimited)',
 3350:                  );
 3351:     return %titles;
 3352: }
 3353: 
 3354: sub authorrequest_titles {
 3355:     my %titles = &Apache::lonlocal::texthash (
 3356:                                    norequest  => 'Not allowed',
 3357:                                    approval   => 'Approval by Dom. Coord.',
 3358:                                    automatic  => 'Automatic approval',
 3359:                  );
 3360:     return %titles;
 3361: } 
 3362: 
 3363: sub courserequest_conditions {
 3364:     my %conditions = &Apache::lonlocal::texthash (
 3365:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
 3366:        validate   => '(Processing of request subject to institutional validation).',
 3367:                  );
 3368:     return %conditions;
 3369: }
 3370: 
 3371: 
 3372: sub print_usercreation {
 3373:     my ($position,$dom,$settings,$rowtotal) = @_;
 3374:     my $numinrow = 4;
 3375:     my $datatable;
 3376:     if ($position eq 'top') {
 3377:         $$rowtotal ++;
 3378:         my $rowcount = 0;
 3379:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 3380:         if (ref($rules) eq 'HASH') {
 3381:             if (keys(%{$rules}) > 0) {
 3382:                 $datatable .= &user_formats_row('username',$settings,$rules,
 3383:                                                 $ruleorder,$numinrow,$rowcount);
 3384:                 $$rowtotal ++;
 3385:                 $rowcount ++;
 3386:             }
 3387:         }
 3388:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 3389:         if (ref($idrules) eq 'HASH') {
 3390:             if (keys(%{$idrules}) > 0) {
 3391:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 3392:                                                 $idruleorder,$numinrow,$rowcount);
 3393:                 $$rowtotal ++;
 3394:                 $rowcount ++;
 3395:             }
 3396:         }
 3397:         my ($emailrules,$emailruleorder) = 
 3398:             &Apache::lonnet::inst_userrules($dom,'email');
 3399:         if (ref($emailrules) eq 'HASH') {
 3400:             if (keys(%{$emailrules}) > 0) {
 3401:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 3402:                                                 $emailruleorder,$numinrow,$rowcount);
 3403:                 $$rowtotal ++;
 3404:                 $rowcount ++;
 3405:             }
 3406:         }
 3407:         if ($rowcount == 0) {
 3408:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 3409:             $$rowtotal ++;
 3410:             $rowcount ++;
 3411:         }
 3412:     } elsif ($position eq 'middle') {
 3413:         my @creators = ('author','course','requestcrs','selfcreate');
 3414:         my ($rules,$ruleorder) =
 3415:             &Apache::lonnet::inst_userrules($dom,'username');
 3416:         my %lt = &usercreation_types();
 3417:         my %checked;
 3418:         my @selfcreate; 
 3419:         if (ref($settings) eq 'HASH') {
 3420:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 3421:                 foreach my $item (@creators) {
 3422:                     $checked{$item} = $settings->{'cancreate'}{$item};
 3423:                 }
 3424:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
 3425:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
 3426:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
 3427:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 3428:                         @selfcreate = ('email','login','sso');
 3429:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
 3430:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
 3431:                     }
 3432:                 }
 3433:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 3434:                 foreach my $item (@creators) {
 3435:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 3436:                         $checked{$item} = 'none';
 3437:                     }
 3438:                 }
 3439:             }
 3440:         }
 3441:         my $rownum = 0;
 3442:         foreach my $item (@creators) {
 3443:             $rownum ++;
 3444:             if ($item ne 'selfcreate') {  
 3445:                 if ($checked{$item} eq '') {
 3446:                     $checked{$item} = 'any';
 3447:                 }
 3448:             }
 3449:             my $css_class;
 3450:             if ($rownum%2) {
 3451:                 $css_class = '';
 3452:             } else {
 3453:                 $css_class = ' class="LC_odd_row" ';
 3454:             }
 3455:             $datatable .= '<tr'.$css_class.'>'.
 3456:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 3457:                          '</span></td><td align="right">';
 3458:             my @options;
 3459:             if ($item eq 'selfcreate') {
 3460:                 push(@options,('email','login','sso'));
 3461:             } else {
 3462:                 @options = ('any');
 3463:                 if (ref($rules) eq 'HASH') {
 3464:                     if (keys(%{$rules}) > 0) {
 3465:                         push(@options,('official','unofficial'));
 3466:                     }
 3467:                 }
 3468:                 push(@options,'none');
 3469:             }
 3470:             foreach my $option (@options) {
 3471:                 my $type = 'radio';
 3472:                 my $check = ' ';
 3473:                 if ($item eq 'selfcreate') {
 3474:                     $type = 'checkbox';
 3475:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
 3476:                         $check = ' checked="checked" ';
 3477:                     }
 3478:                 } else {
 3479:                     if ($checked{$item} eq $option) {
 3480:                         $check = ' checked="checked" ';
 3481:                     }
 3482:                 } 
 3483:                 $datatable .= '<span class="LC_nobreak"><label>'.
 3484:                               '<input type="'.$type.'" name="can_createuser_'.
 3485:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 3486:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 3487:             }
 3488:             $datatable .= '</td></tr>';
 3489:         }
 3490:         my ($othertitle,$usertypes,$types) =
 3491:             &Apache::loncommon::sorted_inst_types($dom);
 3492:         my $createsettings;
 3493:         if (ref($settings) eq 'HASH') {
 3494:             $createsettings = $settings->{cancreate};
 3495:         }
 3496:         if (ref($usertypes) eq 'HASH') {
 3497:             if (keys(%{$usertypes}) > 0) {
 3498:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
 3499:                                              $dom,$numinrow,$othertitle,
 3500:                                              'statustocreate');
 3501:                 $$rowtotal ++;
 3502:                 $rownum ++;
 3503:             }
 3504:         }
 3505:         $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
 3506:     } else {
 3507:         my @contexts = ('author','course','domain');
 3508:         my @authtypes = ('int','krb4','krb5','loc');
 3509:         my %checked;
 3510:         if (ref($settings) eq 'HASH') {
 3511:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 3512:                 foreach my $item (@contexts) {
 3513:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 3514:                         foreach my $auth (@authtypes) {
 3515:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 3516:                                 $checked{$item}{$auth} = ' checked="checked" ';
 3517:                             }
 3518:                         }
 3519:                     }
 3520:                 }
 3521:             }
 3522:         } else {
 3523:             foreach my $item (@contexts) {
 3524:                 foreach my $auth (@authtypes) {
 3525:                     $checked{$item}{$auth} = ' checked="checked" ';
 3526:                 }
 3527:             }
 3528:         }
 3529:         my %title = &context_names();
 3530:         my %authname = &authtype_names();
 3531:         my $rownum = 0;
 3532:         my $css_class; 
 3533:         foreach my $item (@contexts) {
 3534:             if ($rownum%2) {
 3535:                 $css_class = '';
 3536:             } else {
 3537:                 $css_class = ' class="LC_odd_row" ';
 3538:             }
 3539:             $datatable .=   '<tr'.$css_class.'>'.
 3540:                             '<td>'.$title{$item}.
 3541:                             '</td><td class="LC_left_item">'.
 3542:                             '<span class="LC_nobreak">';
 3543:             foreach my $auth (@authtypes) {
 3544:                 $datatable .= '<label>'. 
 3545:                               '<input type="checkbox" name="'.$item.'_auth" '.
 3546:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 3547:                               $authname{$auth}.'</label>&nbsp;';
 3548:             }
 3549:             $datatable .= '</span></td></tr>';
 3550:             $rownum ++;
 3551:         }
 3552:         $$rowtotal += $rownum;
 3553:     }
 3554:     return $datatable;
 3555: }
 3556: 
 3557: sub captcha_choice {
 3558:     my ($context,$settings,$itemcount) = @_;
 3559:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
 3560:     my %lt = &captcha_phrases();
 3561:     $keyentry = 'hidden';
 3562:     if ($context eq 'cancreate') {
 3563:         $rowname = &mt('CAPTCHA validation (e-mail as username)');
 3564:     } elsif ($context eq 'login') {
 3565:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
 3566:     }
 3567:     if (ref($settings) eq 'HASH') {
 3568:         if ($settings->{'captcha'}) {
 3569:             $checked{$settings->{'captcha'}} = ' checked="checked"';
 3570:         } else {
 3571:             $checked{'original'} = ' checked="checked"';
 3572:         }
 3573:         if ($settings->{'captcha'} eq 'recaptcha') {
 3574:             $pubtext = $lt{'pub'};
 3575:             $privtext = $lt{'priv'};
 3576:             $keyentry = 'text';
 3577:         }
 3578:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
 3579:             $currpub = $settings->{'recaptchakeys'}{'public'};
 3580:             $currpriv = $settings->{'recaptchakeys'}{'private'};
 3581:         }
 3582:     } else {
 3583:         $checked{'original'} = ' checked="checked"';
 3584:     }
 3585:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3586:     my $output = '<tr'.$css_class.'>'.
 3587:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
 3588:                  '<table><tr><td>'."\n";
 3589:     foreach my $option ('original','recaptcha','notused') {
 3590:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
 3591:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
 3592:                    $lt{$option}.'</label></span>';
 3593:         unless ($option eq 'notused') {
 3594:             $output .= ('&nbsp;'x2)."\n";
 3595:         }
 3596:     }
 3597: #
 3598: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
 3599: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
 3600: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu) 
 3601: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
 3602: #  
 3603:     $output .= '</td></tr>'."\n".
 3604:                '<tr><td>'."\n".
 3605:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
 3606:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
 3607:                $currpub.'" size="40" /></span><br />'."\n".
 3608:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
 3609:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
 3610:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
 3611:                '</td></tr>';
 3612:     return $output;
 3613: }
 3614: 
 3615: sub user_formats_row {
 3616:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 3617:     my $output;
 3618:     my %text = (
 3619:                    'username' => 'new usernames',
 3620:                    'id'       => 'IDs',
 3621:                    'email'    => 'self-created accounts (e-mail)',
 3622:                );
 3623:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 3624:     $output = '<tr '.$css_class.'>'.
 3625:               '<td><span class="LC_nobreak">';
 3626:     if ($type eq 'email') {
 3627:         $output .= &mt("Formats disallowed for $text{$type}: ");
 3628:     } else {
 3629:         $output .= &mt("Format rules to check for $text{$type}: ");
 3630:     }
 3631:     $output .= '</span></td>'.
 3632:                '<td class="LC_left_item" colspan="2"><table>';
 3633:     my $rem;
 3634:     if (ref($ruleorder) eq 'ARRAY') {
 3635:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 3636:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 3637:                 my $rem = $i%($numinrow);
 3638:                 if ($rem == 0) {
 3639:                     if ($i > 0) {
 3640:                         $output .= '</tr>';
 3641:                     }
 3642:                     $output .= '<tr>';
 3643:                 }
 3644:                 my $check = ' ';
 3645:                 if (ref($settings) eq 'HASH') {
 3646:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 3647:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 3648:                             $check = ' checked="checked" ';
 3649:                         }
 3650:                     }
 3651:                 }
 3652:                 $output .= '<td class="LC_left_item">'.
 3653:                            '<span class="LC_nobreak"><label>'.
 3654:                            '<input type="checkbox" name="'.$type.'_rule" '.
 3655:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 3656:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 3657:             }
 3658:         }
 3659:         $rem = @{$ruleorder}%($numinrow);
 3660:     }
 3661:     my $colsleft = $numinrow - $rem;
 3662:     if ($colsleft > 1 ) {
 3663:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3664:                    '&nbsp;</td>';
 3665:     } elsif ($colsleft == 1) {
 3666:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 3667:     }
 3668:     $output .= '</tr></table></td></tr>';
 3669:     return $output;
 3670: }
 3671: 
 3672: sub usercreation_types {
 3673:     my %lt = &Apache::lonlocal::texthash (
 3674:                     author     => 'When adding a co-author',
 3675:                     course     => 'When adding a user to a course',
 3676:                     requestcrs => 'When requesting a course',
 3677:                     selfcreate => 'User creates own account', 
 3678:                     any        => 'Any',
 3679:                     official   => 'Institutional only ',
 3680:                     unofficial => 'Non-institutional only',
 3681:                     email      => 'E-mail address',
 3682:                     login      => 'Institutional Login',
 3683:                     sso        => 'SSO', 
 3684:                     none       => 'None',
 3685:     );
 3686:     return %lt;
 3687: }
 3688: 
 3689: sub authtype_names {
 3690:     my %lt = &Apache::lonlocal::texthash(
 3691:                       int    => 'Internal',
 3692:                       krb4   => 'Kerberos 4',
 3693:                       krb5   => 'Kerberos 5',
 3694:                       loc    => 'Local',
 3695:                   );
 3696:     return %lt;
 3697: }
 3698: 
 3699: sub context_names {
 3700:     my %context_title = &Apache::lonlocal::texthash(
 3701:        author => 'Creating users when an Author',
 3702:        course => 'Creating users when in a course',
 3703:        domain => 'Creating users when a Domain Coordinator',
 3704:     );
 3705:     return %context_title;
 3706: }
 3707: 
 3708: sub print_usermodification {
 3709:     my ($position,$dom,$settings,$rowtotal) = @_;
 3710:     my $numinrow = 4;
 3711:     my ($context,$datatable,$rowcount);
 3712:     if ($position eq 'top') {
 3713:         $rowcount = 0;
 3714:         $context = 'author'; 
 3715:         foreach my $role ('ca','aa') {
 3716:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 3717:                                                    $numinrow,$rowcount);
 3718:             $$rowtotal ++;
 3719:             $rowcount ++;
 3720:         }
 3721:     } elsif ($position eq 'middle') {
 3722:         $context = 'course';
 3723:         $rowcount = 0;
 3724:         foreach my $role ('st','ep','ta','in','cr') {
 3725:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 3726:                                                    $numinrow,$rowcount);
 3727:             $$rowtotal ++;
 3728:             $rowcount ++;
 3729:         }
 3730:     } elsif ($position eq 'bottom') {
 3731:         $context = 'selfcreate';
 3732:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3733:         $usertypes->{'default'} = $othertitle;
 3734:         if (ref($types) eq 'ARRAY') {
 3735:             push(@{$types},'default');
 3736:             $usertypes->{'default'} = $othertitle;
 3737:             foreach my $status (@{$types}) {
 3738:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
 3739:                                                        $numinrow,$rowcount,$usertypes);
 3740:                 $$rowtotal ++;
 3741:                 $rowcount ++;
 3742:             }
 3743:         }
 3744:     }
 3745:     return $datatable;
 3746: }
 3747: 
 3748: sub print_defaults {
 3749:     my ($dom,$rowtotal) = @_;
 3750:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 3751:                  'datelocale_def','portal_def');
 3752:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 3753:     my $titles = &defaults_titles($dom);
 3754:     my $rownum = 0;
 3755:     my ($datatable,$css_class);
 3756:     foreach my $item (@items) {
 3757:         if ($rownum%2) {
 3758:             $css_class = '';
 3759:         } else {
 3760:             $css_class = ' class="LC_odd_row" ';
 3761:         }
 3762:         $datatable .= '<tr'.$css_class.'>'.
 3763:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 3764:                   '</span></td><td class="LC_right_item">';
 3765:         if ($item eq 'auth_def') {
 3766:             my @authtypes = ('internal','krb4','krb5','localauth');
 3767:             my %shortauth = (
 3768:                              internal => 'int',
 3769:                              krb4 => 'krb4',
 3770:                              krb5 => 'krb5',
 3771:                              localauth  => 'loc'
 3772:                            );
 3773:             my %authnames = &authtype_names();
 3774:             foreach my $auth (@authtypes) {
 3775:                 my $checked = ' ';
 3776:                 if ($domdefaults{$item} eq $auth) {
 3777:                     $checked = ' checked="checked" ';
 3778:                 }
 3779:                 $datatable .= '<label><input type="radio" name="'.$item.
 3780:                               '" value="'.$auth.'"'.$checked.'/>'.
 3781:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 3782:             }
 3783:         } elsif ($item eq 'timezone_def') {
 3784:             my $includeempty = 1;
 3785:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
 3786:         } elsif ($item eq 'datelocale_def') {
 3787:             my $includeempty = 1;
 3788:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
 3789:         } elsif ($item eq 'lang_def') {
 3790:             my %langchoices = &get_languages_hash();
 3791:             $langchoices{''} = 'No language preference';
 3792:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
 3793:             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
 3794:                                                           \%langchoices);
 3795:         } else {
 3796:             my $size;
 3797:             if ($item eq 'portal_def') {
 3798:                 $size = ' size="25"';
 3799:             }
 3800:             $datatable .= '<input type="text" name="'.$item.'" value="'.
 3801:                           $domdefaults{$item}.'"'.$size.' />';
 3802:         }
 3803:         $datatable .= '</td></tr>';
 3804:         $rownum ++;
 3805:     }
 3806:     $$rowtotal += $rownum;
 3807:     return $datatable;
 3808: }
 3809: 
 3810: sub get_languages_hash {
 3811:     my %langchoices;
 3812:     foreach my $id (&Apache::loncommon::languageids()) {
 3813:         my $code = &Apache::loncommon::supportedlanguagecode($id);
 3814:         if ($code ne '') {
 3815:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
 3816:         }
 3817:     }
 3818:     return %langchoices;
 3819: }
 3820: 
 3821: sub defaults_titles {
 3822:     my ($dom) = @_;
 3823:     my %titles = &Apache::lonlocal::texthash (
 3824:                    'auth_def'      => 'Default authentication type',
 3825:                    'auth_arg_def'  => 'Default authentication argument',
 3826:                    'lang_def'      => 'Default language',
 3827:                    'timezone_def'  => 'Default timezone',
 3828:                    'datelocale_def' => 'Default locale for dates',
 3829:                    'portal_def'     => 'Portal/Default URL',
 3830:                  );
 3831:     if ($dom) {
 3832:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
 3833:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
 3834:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
 3835:         $protocol = 'http' if ($protocol ne 'https');
 3836:         if ($uint_dom) {
 3837:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
 3838:                                          $uint_dom);
 3839:         }
 3840:     }
 3841:     return (\%titles);
 3842: }
 3843: 
 3844: sub print_scantronformat {
 3845:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 3846:     my $itemcount = 1;
 3847:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 3848:         %confhash);
 3849:     my $switchserver = &check_switchserver($dom,$confname);
 3850:     my %lt = &Apache::lonlocal::texthash (
 3851:                 default => 'Default bubblesheet format file error',
 3852:                 custom  => 'Custom bubblesheet format file error',
 3853:              );
 3854:     my %scantronfiles = (
 3855:         default => 'default.tab',
 3856:         custom => 'custom.tab',
 3857:     );
 3858:     foreach my $key (keys(%scantronfiles)) {
 3859:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 3860:                               .$scantronfiles{$key};
 3861:     }
 3862:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 3863:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 3864:         if (!$switchserver) {
 3865:             my $servadm = $r->dir_config('lonAdmEMail');
 3866:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 3867:             if ($configuserok eq 'ok') {
 3868:                 if ($author_ok eq 'ok') {
 3869:                     my %legacyfile = (
 3870:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 3871:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 3872:                     );
 3873:                     my %md5chk;
 3874:                     foreach my $type (keys(%legacyfile)) {
 3875:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 3876:                         chomp($md5chk{$type});
 3877:                     }
 3878:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 3879:                         foreach my $type (keys(%legacyfile)) {
 3880:                             ($scantronurls{$type},my $error) = 
 3881:                                 &legacy_scantronformat($r,$dom,$confname,
 3882:                                                  $type,$legacyfile{$type},
 3883:                                                  $scantronurls{$type},
 3884:                                                  $scantronfiles{$type});
 3885:                             if ($error ne '') {
 3886:                                 $error{$type} = $error;
 3887:                             }
 3888:                         }
 3889:                         if (keys(%error) == 0) {
 3890:                             $is_custom = 1;
 3891:                             $confhash{'scantron'}{'scantronformat'} = 
 3892:                                 $scantronurls{'custom'};
 3893:                             my $putresult = 
 3894:                                 &Apache::lonnet::put_dom('configuration',
 3895:                                                          \%confhash,$dom);
 3896:                             if ($putresult ne 'ok') {
 3897:                                 $error{'custom'} = 
 3898:                                     '<span class="LC_error">'.
 3899:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 3900:                             }
 3901:                         }
 3902:                     } else {
 3903:                         ($scantronurls{'default'},my $error) =
 3904:                             &legacy_scantronformat($r,$dom,$confname,
 3905:                                           'default',$legacyfile{'default'},
 3906:                                           $scantronurls{'default'},
 3907:                                           $scantronfiles{'default'});
 3908:                         if ($error eq '') {
 3909:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 3910:                             my $putresult =
 3911:                                 &Apache::lonnet::put_dom('configuration',
 3912:                                                          \%confhash,$dom);
 3913:                             if ($putresult ne 'ok') {
 3914:                                 $error{'default'} =
 3915:                                     '<span class="LC_error">'.
 3916:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 3917:                             }
 3918:                         } else {
 3919:                             $error{'default'} = $error;
 3920:                         }
 3921:                     }
 3922:                 }
 3923:             }
 3924:         } else {
 3925:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
 3926:         }
 3927:     }
 3928:     if (ref($settings) eq 'HASH') {
 3929:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 3930:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 3931:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 3932:                 $scantronurl = '';
 3933:             } else {
 3934:                 $scantronurl = $settings->{'scantronformat'};
 3935:             }
 3936:             $is_custom = 1;
 3937:         } else {
 3938:             $scantronurl = $scantronurls{'default'};
 3939:         }
 3940:     } else {
 3941:         if ($is_custom) {
 3942:             $scantronurl = $scantronurls{'custom'};
 3943:         } else {
 3944:             $scantronurl = $scantronurls{'default'};
 3945:         }
 3946:     }
 3947:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3948:     $datatable .= '<tr'.$css_class.'>';
 3949:     if (!$is_custom) {
 3950:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 3951:                       '<span class="LC_nobreak">';
 3952:         if ($scantronurl) {
 3953:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
 3954:                                                          undef,undef,undef,undef,'background-color:#ffffff');
 3955:         } else {
 3956:             $datatable = &mt('File unavailable for display');
 3957:         }
 3958:         $datatable .= '</span></td>';
 3959:         if (keys(%error) == 0) { 
 3960:             $datatable .= '<td valign="bottom">';
 3961:             if (!$switchserver) {
 3962:                 $datatable .= &mt('Upload:').'<br />';
 3963:             }
 3964:         } else {
 3965:             my $errorstr;
 3966:             foreach my $key (sort(keys(%error))) {
 3967:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 3968:             }
 3969:             $datatable .= '<td>'.$errorstr;
 3970:         }
 3971:     } else {
 3972:         if (keys(%error) > 0) {
 3973:             my $errorstr;
 3974:             foreach my $key (sort(keys(%error))) {
 3975:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 3976:             } 
 3977:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 3978:         } elsif ($scantronurl) {
 3979:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
 3980:                                                        undef,undef,undef,undef,'background-color:#ffffff');
 3981:             $datatable .= '<td><span class="LC_nobreak">'.
 3982:                           $link.
 3983:                           '<label><input type="checkbox" name="scantronformat_del"'.
 3984:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
 3985:                           '<td><span class="LC_nobreak">&nbsp;'.
 3986:                           &mt('Replace:').'</span><br />';
 3987:         }
 3988:     }
 3989:     if (keys(%error) == 0) {
 3990:         if ($switchserver) {
 3991:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 3992:         } else {
 3993:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 3994:                          '<input type="file" name="scantronformat" /></span>';
 3995:         }
 3996:     }
 3997:     $datatable .= '</td></tr>';
 3998:     $$rowtotal ++;
 3999:     return $datatable;
 4000: }
 4001: 
 4002: sub legacy_scantronformat {
 4003:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 4004:     my ($url,$error);
 4005:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 4006:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 4007:         (my $result,$url) =
 4008:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 4009:                          '','',$newfile);
 4010:         if ($result ne 'ok') {
 4011:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
 4012:         }
 4013:     }
 4014:     return ($url,$error);
 4015: }
 4016: 
 4017: sub print_coursecategories {
 4018:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 4019:     my $datatable;
 4020:     if ($position eq 'top') {
 4021:         my $toggle_cats_crs = ' ';
 4022:         my $toggle_cats_dom = ' checked="checked" ';
 4023:         my $can_cat_crs = ' ';
 4024:         my $can_cat_dom = ' checked="checked" ';
 4025:         my $toggle_catscomm_comm = ' ';
 4026:         my $toggle_catscomm_dom = ' checked="checked" ';
 4027:         my $can_catcomm_comm = ' ';
 4028:         my $can_catcomm_dom = ' checked="checked" ';
 4029: 
 4030:         if (ref($settings) eq 'HASH') {
 4031:             if ($settings->{'togglecats'} eq 'crs') {
 4032:                 $toggle_cats_crs = $toggle_cats_dom;
 4033:                 $toggle_cats_dom = ' ';
 4034:             }
 4035:             if ($settings->{'categorize'} eq 'crs') {
 4036:                 $can_cat_crs = $can_cat_dom;
 4037:                 $can_cat_dom = ' ';
 4038:             }
 4039:             if ($settings->{'togglecatscomm'} eq 'comm') {
 4040:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
 4041:                 $toggle_catscomm_dom = ' ';
 4042:             }
 4043:             if ($settings->{'categorizecomm'} eq 'comm') {
 4044:                 $can_catcomm_comm = $can_catcomm_dom;
 4045:                 $can_catcomm_dom = ' ';
 4046:             }
 4047:         }
 4048:         my %title = &Apache::lonlocal::texthash (
 4049:                      togglecats     => 'Show/Hide a course in catalog',
 4050:                      togglecatscomm => 'Show/Hide a community in catalog',
 4051:                      categorize     => 'Assign a category to a course',
 4052:                      categorizecomm => 'Assign a category to a community',
 4053:                     );
 4054:         my %level = &Apache::lonlocal::texthash (
 4055:                      dom  => 'Set in Domain',
 4056:                      crs  => 'Set in Course',
 4057:                      comm => 'Set in Community',
 4058:                     );
 4059:         $datatable = '<tr class="LC_odd_row">'.
 4060:                   '<td>'.$title{'togglecats'}.'</td>'.
 4061:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 4062:                   '<input type="radio" name="togglecats"'.
 4063:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4064:                   '<label><input type="radio" name="togglecats"'.
 4065:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 4066:                   '</tr><tr>'.
 4067:                   '<td>'.$title{'categorize'}.'</td>'.
 4068:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 4069:                   '<label><input type="radio" name="categorize"'.
 4070:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4071:                   '<label><input type="radio" name="categorize"'.
 4072:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 4073:                   '</tr><tr class="LC_odd_row">'.
 4074:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
 4075:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 4076:                   '<input type="radio" name="togglecatscomm"'.
 4077:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4078:                   '<label><input type="radio" name="togglecatscomm"'.
 4079:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
 4080:                   '</tr><tr>'.
 4081:                   '<td>'.$title{'categorizecomm'}.'</td>'.
 4082:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 4083:                   '<label><input type="radio" name="categorizecomm"'.
 4084:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4085:                   '<label><input type="radio" name="categorizecomm"'.
 4086:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
 4087:                   '</tr>';
 4088:         $$rowtotal += 4;
 4089:     } else {
 4090:         my $css_class;
 4091:         my $itemcount = 1;
 4092:         my $cathash; 
 4093:         if (ref($settings) eq 'HASH') {
 4094:             $cathash = $settings->{'cats'};
 4095:         }
 4096:         if (ref($cathash) eq 'HASH') {
 4097:             my (@cats,@trails,%allitems,%idx,@jsarray);
 4098:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 4099:                                                    \%allitems,\%idx,\@jsarray);
 4100:             my $maxdepth = scalar(@cats);
 4101:             my $colattrib = '';
 4102:             if ($maxdepth > 2) {
 4103:                 $colattrib = ' colspan="2" ';
 4104:             }
 4105:             my @path;
 4106:             if (@cats > 0) {
 4107:                 if (ref($cats[0]) eq 'ARRAY') {
 4108:                     my $numtop = @{$cats[0]};
 4109:                     my $maxnum = $numtop;
 4110:                     my %default_names = (
 4111:                           instcode    => &mt('Official courses'),
 4112:                           communities => &mt('Communities'),
 4113:                     );
 4114: 
 4115:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
 4116:                         ($cathash->{'instcode::0'} eq '') ||
 4117:                         (!grep(/^communities$/,@{$cats[0]})) || 
 4118:                         ($cathash->{'communities::0'} eq '')) {
 4119:                         $maxnum ++;
 4120:                     }
 4121:                     my $lastidx;
 4122:                     for (my $i=0; $i<$numtop; $i++) {
 4123:                         my $parent = $cats[0][$i];
 4124:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4125:                         my $item = &escape($parent).'::0';
 4126:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 4127:                         $lastidx = $idx{$item};
 4128:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4129:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 4130:                         for (my $k=0; $k<=$maxnum; $k++) {
 4131:                             my $vpos = $k+1;
 4132:                             my $selstr;
 4133:                             if ($k == $i) {
 4134:                                 $selstr = ' selected="selected" ';
 4135:                             }
 4136:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4137:                         }
 4138:                         $datatable .= '</select></td><td>';
 4139:                         if ($parent eq 'instcode' || $parent eq 'communities') {
 4140:                             $datatable .=  '<span class="LC_nobreak">'
 4141:                                            .$default_names{$parent}.'</span>';
 4142:                             if ($parent eq 'instcode') {
 4143:                                 $datatable .= '<br /><span class="LC_nobreak">('
 4144:                                               .&mt('with institutional codes')
 4145:                                               .')</span></td><td'.$colattrib.'>';
 4146:                             } else {
 4147:                                 $datatable .= '<table><tr><td>';
 4148:                             }
 4149:                             $datatable .= '<span class="LC_nobreak">'
 4150:                                           .'<label><input type="radio" name="'
 4151:                                           .$parent.'" value="1" checked="checked" />'
 4152:                                           .&mt('Display').'</label>';
 4153:                             if ($parent eq 'instcode') {
 4154:                                 $datatable .= '&nbsp;';
 4155:                             } else {
 4156:                                 $datatable .= '</span></td></tr><tr><td>'
 4157:                                               .'<span class="LC_nobreak">';
 4158:                             }
 4159:                             $datatable .= '<label><input type="radio" name="'
 4160:                                           .$parent.'" value="0" />'
 4161:                                           .&mt('Do not display').'</label></span>';
 4162:                             if ($parent eq 'communities') {
 4163:                                 $datatable .= '</td></tr></table>';
 4164:                             }
 4165:                             $datatable .= '</td>';
 4166:                         } else {
 4167:                             $datatable .= $parent
 4168:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
 4169:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 4170:                         }
 4171:                         my $depth = 1;
 4172:                         push(@path,$parent);
 4173:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 4174:                         pop(@path);
 4175:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 4176:                         $itemcount ++;
 4177:                     }
 4178:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4179:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 4180:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 4181:                     for (my $k=0; $k<=$maxnum; $k++) {
 4182:                         my $vpos = $k+1;
 4183:                         my $selstr;
 4184:                         if ($k == $numtop) {
 4185:                             $selstr = ' selected="selected" ';
 4186:                         }
 4187:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4188:                     }
 4189:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 4190:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 4191:                                   .'</tr>'."\n";
 4192:                     $itemcount ++;
 4193:                     foreach my $default ('instcode','communities') {
 4194:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
 4195:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4196:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
 4197:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 4198:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
 4199:                             for (my $k=0; $k<=$maxnum; $k++) {
 4200:                                 my $vpos = $k+1;
 4201:                                 my $selstr;
 4202:                                 if ($k == $maxnum) {
 4203:                                     $selstr = ' selected="selected" ';
 4204:                                 }
 4205:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4206:                             }
 4207:                             $datatable .= '</select></span></td>'.
 4208:                                           '<td><span class="LC_nobreak">'.
 4209:                                           $default_names{$default}.'</span>';
 4210:                             if ($default eq 'instcode') {
 4211:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
 4212:                                               .&mt('with institutional codes').')</span>';
 4213:                             }
 4214:                             $datatable .= '</td>'
 4215:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
 4216:                                           .&mt('Display').'</label>&nbsp;'
 4217:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
 4218:                                           .&mt('Do not display').'</label></span></td></tr>';
 4219:                         }
 4220:                     }
 4221:                 }
 4222:             } else {
 4223:                 $datatable .= &initialize_categories($itemcount);
 4224:             }
 4225:         } else {
 4226:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
 4227:                           .&initialize_categories($itemcount);
 4228:         }
 4229:         $$rowtotal += $itemcount;
 4230:     }
 4231:     return $datatable;
 4232: }
 4233: 
 4234: sub print_serverstatuses {
 4235:     my ($dom,$settings,$rowtotal) = @_;
 4236:     my $datatable;
 4237:     my @pages = &serverstatus_pages();
 4238:     my (%namedaccess,%machineaccess);
 4239:     foreach my $type (@pages) {
 4240:         $namedaccess{$type} = '';
 4241:         $machineaccess{$type}= '';
 4242:     }
 4243:     if (ref($settings) eq 'HASH') {
 4244:         foreach my $type (@pages) {
 4245:             if (exists($settings->{$type})) {
 4246:                 if (ref($settings->{$type}) eq 'HASH') {
 4247:                     foreach my $key (keys(%{$settings->{$type}})) {
 4248:                         if ($key eq 'namedusers') {
 4249:                             $namedaccess{$type} = $settings->{$type}->{$key};
 4250:                         } elsif ($key eq 'machines') {
 4251:                             $machineaccess{$type} = $settings->{$type}->{$key};
 4252:                         }
 4253:                     }
 4254:                 }
 4255:             }
 4256:         }
 4257:     }
 4258:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 4259:     my $rownum = 0;
 4260:     my $css_class;
 4261:     foreach my $type (@pages) {
 4262:         $rownum ++;
 4263:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 4264:         $datatable .= '<tr'.$css_class.'>'.
 4265:                       '<td><span class="LC_nobreak">'.
 4266:                       $titles->{$type}.'</span></td>'.
 4267:                       '<td class="LC_left_item">'.
 4268:                       '<input type="text" name="'.$type.'_namedusers" '.
 4269:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 4270:                       '<td class="LC_right_item">'.
 4271:                       '<span class="LC_nobreak">'.
 4272:                       '<input type="text" name="'.$type.'_machines" '.
 4273:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 4274:                       '</td></tr>'."\n";
 4275:     }
 4276:     $$rowtotal += $rownum;
 4277:     return $datatable;
 4278: }
 4279: 
 4280: sub serverstatus_pages {
 4281:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 4282:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
 4283:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
 4284: }
 4285: 
 4286: sub coursecategories_javascript {
 4287:     my ($settings) = @_;
 4288:     my ($output,$jstext,$cathash);
 4289:     if (ref($settings) eq 'HASH') {
 4290:         $cathash = $settings->{'cats'};
 4291:     }
 4292:     if (ref($cathash) eq 'HASH') {
 4293:         my (@cats,@jsarray,%idx);
 4294:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 4295:         if (@jsarray > 0) {
 4296:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 4297:             for (my $i=0; $i<@jsarray; $i++) {
 4298:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 4299:                     my $catstr = join('","',@{$jsarray[$i]});
 4300:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 4301:                 }
 4302:             }
 4303:         }
 4304:     } else {
 4305:         $jstext  = '    var categories = Array(1);'."\n".
 4306:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 4307:     }
 4308:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
 4309:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
 4310:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
 4311:     $output = <<"ENDSCRIPT";
 4312: <script type="text/javascript">
 4313: // <![CDATA[
 4314: function reorderCats(form,parent,item,idx) {
 4315:     var changedVal;
 4316: $jstext
 4317:     var newpos = 'addcategory_pos';
 4318:     var current = new Array;
 4319:     if (parent == '') {
 4320:         var has_instcode = 0;
 4321:         var maxtop = categories[idx].length;
 4322:         for (var j=0; j<maxtop; j++) {
 4323:             if (categories[idx][j] == 'instcode::0') {
 4324:                 has_instcode == 1;
 4325:             }
 4326:         }
 4327:         if (has_instcode == 0) {
 4328:             categories[idx][maxtop] = 'instcode_pos';
 4329:         }
 4330:     } else {
 4331:         newpos += '_'+parent;
 4332:     }
 4333:     var maxh = 1 + categories[idx].length;
 4334:     var current = new Array;
 4335:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 4336:     if (item == newpos) {
 4337:         changedVal = newitemVal;
 4338:     } else {
 4339:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 4340:         current[newitemVal] = newpos;
 4341:     }
 4342:     for (var i=0; i<categories[idx].length; i++) {
 4343:         var elementName = categories[idx][i];
 4344:         if (elementName != item) {
 4345:             if (form.elements[elementName]) {
 4346:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 4347:                 current[currVal] = elementName;
 4348:             }
 4349:         }
 4350:     }
 4351:     var oldVal;
 4352:     for (var j=0; j<maxh; j++) {
 4353:         if (current[j] == undefined) {
 4354:             oldVal = j;
 4355:         }
 4356:     }
 4357:     if (oldVal < changedVal) {
 4358:         for (var k=oldVal+1; k<=changedVal ; k++) {
 4359:            var elementName = current[k];
 4360:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 4361:         }
 4362:     } else {
 4363:         for (var k=changedVal; k<oldVal; k++) {
 4364:             var elementName = current[k];
 4365:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 4366:         }
 4367:     }
 4368:     return;
 4369: }
 4370: 
 4371: function categoryCheck(form) {
 4372:     if (form.elements['addcategory_name'].value == 'instcode') {
 4373:         alert('$instcode_reserved\\n$choose_again');
 4374:         return false;
 4375:     }
 4376:     if (form.elements['addcategory_name'].value == 'communities') {
 4377:         alert('$communities_reserved\\n$choose_again');
 4378:         return false;
 4379:     }
 4380:     return true;
 4381: }
 4382: 
 4383: // ]]>
 4384: </script>
 4385: 
 4386: ENDSCRIPT
 4387:     return $output;
 4388: }
 4389: 
 4390: sub initialize_categories {
 4391:     my ($itemcount) = @_;
 4392:     my ($datatable,$css_class,$chgstr);
 4393:     my %default_names = (
 4394:                       instcode    => 'Official courses (with institutional codes)',
 4395:                       communities => 'Communities',
 4396:                         );
 4397:     my $select0 = ' selected="selected"';
 4398:     my $select1 = '';
 4399:     foreach my $default ('instcode','communities') {
 4400:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4401:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
 4402:         if ($default eq 'communities') {
 4403:             $select1 = $select0;
 4404:             $select0 = '';
 4405:         }
 4406:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4407:                      .'<select name="'.$default.'_pos">'
 4408:                      .'<option value="0"'.$select0.'>1</option>'
 4409:                      .'<option value="1"'.$select1.'>2</option>'
 4410:                      .'<option value="2">3</option></select>&nbsp;'
 4411:                      .$default_names{$default}
 4412:                      .'</span></td><td><span class="LC_nobreak">'
 4413:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
 4414:                      .&mt('Display').'</label>&nbsp;<label>'
 4415:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
 4416:                  .'</label></span></td></tr>';
 4417:         $itemcount ++;
 4418:     }
 4419:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4420:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 4421:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4422:                   .'<select name="addcategory_pos"'.$chgstr.'>'
 4423:                   .'<option value="0">1</option>'
 4424:                   .'<option value="1">2</option>'
 4425:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
 4426:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 4427:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 4428:     return $datatable;
 4429: }
 4430: 
 4431: sub build_category_rows {
 4432:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 4433:     my ($text,$name,$item,$chgstr);
 4434:     if (ref($cats) eq 'ARRAY') {
 4435:         my $maxdepth = scalar(@{$cats});
 4436:         if (ref($cats->[$depth]) eq 'HASH') {
 4437:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 4438:                 my $numchildren = @{$cats->[$depth]{$parent}};
 4439:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4440:                 $text .= '<td><table class="LC_data_table">';
 4441:                 my ($idxnum,$parent_name,$parent_item);
 4442:                 my $higher = $depth - 1;
 4443:                 if ($higher == 0) {
 4444:                     $parent_name = &escape($parent).'::'.$higher;
 4445:                 } else {
 4446:                     if (ref($path) eq 'ARRAY') {
 4447:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 4448:                     }
 4449:                 }
 4450:                 $parent_item = 'addcategory_pos_'.$parent_name;
 4451:                 for (my $j=0; $j<=$numchildren; $j++) {
 4452:                     if ($j < $numchildren) {
 4453:                         $name = $cats->[$depth]{$parent}[$j];
 4454:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 4455:                         $idxnum = $idx->{$item};
 4456:                     } else {
 4457:                         $name = $parent_name;
 4458:                         $item = $parent_item;
 4459:                     }
 4460:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 4461:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 4462:                     for (my $i=0; $i<=$numchildren; $i++) {
 4463:                         my $vpos = $i+1;
 4464:                         my $selstr;
 4465:                         if ($j == $i) {
 4466:                             $selstr = ' selected="selected" ';
 4467:                         }
 4468:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 4469:                     }
 4470:                     $text .= '</select>&nbsp;';
 4471:                     if ($j < $numchildren) {
 4472:                         my $deeper = $depth+1;
 4473:                         $text .= $name.'&nbsp;'
 4474:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 4475:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 4476:                         if(ref($path) eq 'ARRAY') {
 4477:                             push(@{$path},$name);
 4478:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 4479:                             pop(@{$path});
 4480:                         }
 4481:                     } else {
 4482:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 4483:                         if ($j == $numchildren) {
 4484:                             $text .= $name;
 4485:                         } else {
 4486:                             $text .= $item;
 4487:                         }
 4488:                         $text .= '" value="" />';
 4489:                     }
 4490:                     $text .= '</td></tr>';
 4491:                 }
 4492:                 $text .= '</table></td>';
 4493:             } else {
 4494:                 my $higher = $depth-1;
 4495:                 if ($higher == 0) {
 4496:                     $name = &escape($parent).'::'.$higher;
 4497:                 } else {
 4498:                     if (ref($path) eq 'ARRAY') {
 4499:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 4500:                     }
 4501:                 }
 4502:                 my $colspan;
 4503:                 if ($parent ne 'instcode') {
 4504:                     $colspan = $maxdepth - $depth - 1;
 4505:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 4506:                 }
 4507:             }
 4508:         }
 4509:     }
 4510:     return $text;
 4511: }
 4512: 
 4513: sub modifiable_userdata_row {
 4514:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
 4515:     my $rolename;
 4516:     if ($context eq 'selfcreate') {
 4517:         if (ref($usertypes) eq 'HASH') {
 4518:             $rolename = $usertypes->{$role};
 4519:         } else {
 4520:             $rolename = $role;
 4521:         }
 4522:     } else {
 4523:         if ($role eq 'cr') {
 4524:             $rolename = &mt('Custom role');
 4525:         } else {
 4526:             $rolename = &Apache::lonnet::plaintext($role);
 4527:         }
 4528:     }
 4529:     my @fields = ('lastname','firstname','middlename','generation',
 4530:                   'permanentemail','id');
 4531:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 4532:     my $output;
 4533:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 4534:     $output = '<tr '.$css_class.'>'.
 4535:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 4536:               '<td class="LC_left_item" colspan="2"><table>';
 4537:     my $rem;
 4538:     my %checks;
 4539:     if (ref($settings) eq 'HASH') {
 4540:         if (ref($settings->{$context}) eq 'HASH') {
 4541:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 4542:                 foreach my $field (@fields) {
 4543:                     if ($settings->{$context}->{$role}->{$field}) {
 4544:                         $checks{$field} = ' checked="checked" ';
 4545:                     }
 4546:                 }
 4547:             }
 4548:         }
 4549:     }
 4550:     for (my $i=0; $i<@fields; $i++) {
 4551:         my $rem = $i%($numinrow);
 4552:         if ($rem == 0) {
 4553:             if ($i > 0) {
 4554:                 $output .= '</tr>';
 4555:             }
 4556:             $output .= '<tr>';
 4557:         }
 4558:         my $check = ' ';
 4559:         if (exists($checks{$fields[$i]})) {
 4560:             $check = $checks{$fields[$i]}
 4561:         } else {
 4562:             if ($role eq 'st') {
 4563:                 if (ref($settings) ne 'HASH') {
 4564:                     $check = ' checked="checked" '; 
 4565:                 }
 4566:             }
 4567:         }
 4568:         $output .= '<td class="LC_left_item">'.
 4569:                    '<span class="LC_nobreak"><label>'.
 4570:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 4571:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 4572:                    '</label></span></td>';
 4573:         $rem = @fields%($numinrow);
 4574:     }
 4575:     my $colsleft = $numinrow - $rem;
 4576:     if ($colsleft > 1 ) {
 4577:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 4578:                    '&nbsp;</td>';
 4579:     } elsif ($colsleft == 1) {
 4580:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 4581:     }
 4582:     $output .= '</tr></table></td></tr>';
 4583:     return $output;
 4584: }
 4585: 
 4586: sub insttypes_row {
 4587:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
 4588:     my %lt = &Apache::lonlocal::texthash (
 4589:                       cansearch => 'Users allowed to search',
 4590:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
 4591:                       lockablenames => 'User preference to lock name',
 4592:              );
 4593:     my $showdom;
 4594:     if ($context eq 'cansearch') {
 4595:         $showdom = ' ('.$dom.')';
 4596:     }
 4597:     my $class = 'LC_left_item';
 4598:     if ($context eq 'statustocreate') {
 4599:         $class = 'LC_right_item';
 4600:     }
 4601:     my $output =  '<tr class="LC_odd_row">'.
 4602:                   '<td>'.$lt{$context}.$showdom.
 4603:                   '</td><td class="'.$class.'" colspan="2"><table>';
 4604:     my $rem;
 4605:     if (ref($types) eq 'ARRAY') {
 4606:         for (my $i=0; $i<@{$types}; $i++) {
 4607:             if (defined($usertypes->{$types->[$i]})) {
 4608:                 my $rem = $i%($numinrow);
 4609:                 if ($rem == 0) {
 4610:                     if ($i > 0) {
 4611:                         $output .= '</tr>';
 4612:                     }
 4613:                     $output .= '<tr>';
 4614:                 }
 4615:                 my $check = ' ';
 4616:                 if (ref($settings) eq 'HASH') {
 4617:                     if (ref($settings->{$context}) eq 'ARRAY') {
 4618:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
 4619:                             $check = ' checked="checked" ';
 4620:                         }
 4621:                     } elsif ($context eq 'statustocreate') {
 4622:                         $check = ' checked="checked" ';
 4623:                     }
 4624:                 }
 4625:                 $output .= '<td class="LC_left_item">'.
 4626:                            '<span class="LC_nobreak"><label>'.
 4627:                            '<input type="checkbox" name="'.$context.'" '.
 4628:                            'value="'.$types->[$i].'"'.$check.'/>'.
 4629:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 4630:             }
 4631:         }
 4632:         $rem = @{$types}%($numinrow);
 4633:     }
 4634:     my $colsleft = $numinrow - $rem;
 4635:     if (($rem == 0) && (@{$types} > 0)) {
 4636:         $output .= '<tr>';
 4637:     }
 4638:     if ($colsleft > 1) {
 4639:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 4640:     } else {
 4641:         $output .= '<td class="LC_left_item">';
 4642:     }
 4643:     my $defcheck = ' ';
 4644:     if (ref($settings) eq 'HASH') {  
 4645:         if (ref($settings->{$context}) eq 'ARRAY') {
 4646:             if (grep(/^default$/,@{$settings->{$context}})) {
 4647:                 $defcheck = ' checked="checked" ';
 4648:             }
 4649:         } elsif ($context eq 'statustocreate') {
 4650:             $defcheck = ' checked="checked" ';
 4651:         }
 4652:     }
 4653:     $output .= '<span class="LC_nobreak"><label>'.
 4654:                '<input type="checkbox" name="'.$context.'" '.
 4655:                'value="default"'.$defcheck.'/>'.
 4656:                $othertitle.'</label></span></td>'.
 4657:                '</tr></table></td></tr>';
 4658:     return $output;
 4659: }
 4660: 
 4661: sub sorted_searchtitles {
 4662:     my %searchtitles = &Apache::lonlocal::texthash(
 4663:                          'uname' => 'username',
 4664:                          'lastname' => 'last name',
 4665:                          'lastfirst' => 'last name, first name',
 4666:                      );
 4667:     my @titleorder = ('uname','lastname','lastfirst');
 4668:     return (\%searchtitles,\@titleorder);
 4669: }
 4670: 
 4671: sub sorted_searchtypes {
 4672:     my %srchtypes_desc = (
 4673:                            exact    => 'is exact match',
 4674:                            contains => 'contains ..',
 4675:                            begins   => 'begins with ..',
 4676:                          );
 4677:     my @srchtypeorder = ('exact','begins','contains');
 4678:     return (\%srchtypes_desc,\@srchtypeorder);
 4679: }
 4680: 
 4681: sub usertype_update_row {
 4682:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 4683:     my $datatable;
 4684:     my $numinrow = 4;
 4685:     foreach my $type (@{$types}) {
 4686:         if (defined($usertypes->{$type})) {
 4687:             $$rownums ++;
 4688:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 4689:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 4690:                           '</td><td class="LC_left_item"><table>';
 4691:             for (my $i=0; $i<@{$fields}; $i++) {
 4692:                 my $rem = $i%($numinrow);
 4693:                 if ($rem == 0) {
 4694:                     if ($i > 0) {
 4695:                         $datatable .= '</tr>';
 4696:                     }
 4697:                     $datatable .= '<tr>';
 4698:                 }
 4699:                 my $check = ' ';
 4700:                 if (ref($settings) eq 'HASH') {
 4701:                     if (ref($settings->{'fields'}) eq 'HASH') {
 4702:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 4703:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 4704:                                 $check = ' checked="checked" ';
 4705:                             }
 4706:                         }
 4707:                     }
 4708:                 }
 4709: 
 4710:                 if ($i == @{$fields}-1) {
 4711:                     my $colsleft = $numinrow - $rem;
 4712:                     if ($colsleft > 1) {
 4713:                         $datatable .= '<td colspan="'.$colsleft.'">';
 4714:                     } else {
 4715:                         $datatable .= '<td>';
 4716:                     }
 4717:                 } else {
 4718:                     $datatable .= '<td>';
 4719:                 }
 4720:                 $datatable .= '<span class="LC_nobreak"><label>'.
 4721:                               '<input type="checkbox" name="updateable_'.$type.
 4722:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 4723:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 4724:             }
 4725:             $datatable .= '</tr></table></td></tr>';
 4726:         }
 4727:     }
 4728:     return $datatable;
 4729: }
 4730: 
 4731: sub modify_login {
 4732:     my ($r,$dom,$confname,%domconfig) = @_;
 4733:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
 4734:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
 4735:     %title = ( coursecatalog => 'Display course catalog',
 4736:                adminmail => 'Display administrator E-mail address',
 4737:                helpdesk  => 'Display "Contact Helpdesk" link',
 4738:                newuser => 'Link for visitors to create a user account',
 4739:                loginheader => 'Log-in box header');
 4740:     @offon = ('off','on');
 4741:     if (ref($domconfig{login}) eq 'HASH') {
 4742:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
 4743:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
 4744:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
 4745:             }
 4746:         }
 4747:     }
 4748:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 4749:                                            \%domconfig,\%loginhash);
 4750:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 4751:     foreach my $item (@toggles) {
 4752:         $loginhash{login}{$item} = $env{'form.'.$item};
 4753:     }
 4754:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 4755:     if (ref($colchanges{'login'}) eq 'HASH') {  
 4756:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 4757:                                          \%loginhash);
 4758:     }
 4759: 
 4760:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 4761:     my @loginvia_attribs = ('serverpath','custompath','exempt');
 4762:     if (keys(%servers) > 1) {
 4763:         foreach my $lonhost (keys(%servers)) {
 4764:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
 4765:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
 4766:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
 4767:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
 4768:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
 4769:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4770:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4771:                         $changes{'loginvia'}{$lonhost} = 1;
 4772:                     } else {
 4773:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
 4774:                         $changes{'loginvia'}{$lonhost} = 1;
 4775:                     }
 4776:                 } else {
 4777:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4778:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4779:                         $changes{'loginvia'}{$lonhost} = 1;
 4780:                     }
 4781:                 }
 4782:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
 4783:                     foreach my $item (@loginvia_attribs) {
 4784:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
 4785:                     }
 4786:                 } else {
 4787:                     foreach my $item (@loginvia_attribs) {
 4788:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 4789:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 4790:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
 4791:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 4792:                                 $new = '/';
 4793:                             }
 4794:                         }
 4795:                         if (($item eq 'custompath') && 
 4796:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 4797:                             $new = '';
 4798:                         }
 4799:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
 4800:                             $changes{'loginvia'}{$lonhost} = 1;
 4801:                         }
 4802:                         if ($item eq 'exempt') {
 4803:                             $new =~ s/^\s+//;
 4804:                             $new =~ s/\s+$//;
 4805:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
 4806:                             my @okips;
 4807:                             foreach my $ip (@poss_ips) {
 4808:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
 4809:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
 4810:                                         push(@okips,$ip); 
 4811:                                     }
 4812:                                 }
 4813:                             }
 4814:                             if (@okips > 0) {
 4815:                                 $new = join(',',@okips); 
 4816:                             } else {
 4817:                                 $new = ''; 
 4818:                             }
 4819:                         }
 4820:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 4821:                     }
 4822:                 }
 4823:             } else {
 4824:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4825:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4826:                     $changes{'loginvia'}{$lonhost} = 1;
 4827:                     foreach my $item (@loginvia_attribs) {
 4828:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 4829:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 4830:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 4831:                                 $new = '/';
 4832:                             }
 4833:                         }
 4834:                         if (($item eq 'custompath') && 
 4835:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 4836:                             $new = '';
 4837:                         }
 4838:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 4839:                     }
 4840:                 }
 4841:             }
 4842:         }
 4843:     }
 4844: 
 4845:     my $servadm = $r->dir_config('lonAdmEMail');
 4846:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 4847:     if (ref($domconfig{'login'}) eq 'HASH') {
 4848:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
 4849:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
 4850:                 if ($lang eq 'nolang') {
 4851:                     push(@currlangs,$lang);
 4852:                 } elsif (defined($langchoices{$lang})) {
 4853:                     push(@currlangs,$lang);
 4854:                 } else {
 4855:                     next;
 4856:                 }
 4857:             }
 4858:         }
 4859:     }
 4860:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
 4861:     if (@currlangs > 0) {
 4862:         foreach my $lang (@currlangs) {
 4863:             if (grep(/^\Q$lang\E$/,@delurls)) {
 4864:                 $changes{'helpurl'}{$lang} = 1;
 4865:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
 4866:                 $changes{'helpurl'}{$lang} = 1;
 4867:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
 4868:                 push(@newlangs,$lang);
 4869:             } else {
 4870:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 4871:             }
 4872:         }
 4873:     }
 4874:     unless (grep(/^nolang$/,@currlangs)) {
 4875:         if ($env{'form.loginhelpurl_nolang.filename'}) {
 4876:             $changes{'helpurl'}{'nolang'} = 1;
 4877:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
 4878:             push(@newlangs,'nolang');
 4879:         }
 4880:     }
 4881:     if ($env{'form.loginhelpurl_add_lang'}) {
 4882:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
 4883:             ($env{'form.loginhelpurl_add_file.filename'})) {
 4884:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
 4885:             $addedfile = $env{'form.loginhelpurl_add_lang'};
 4886:         }
 4887:     }
 4888:     if ((@newlangs > 0) || ($addedfile)) {
 4889:         my $error;
 4890:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 4891:         if ($configuserok eq 'ok') {
 4892:             if ($switchserver) {
 4893:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
 4894:             } elsif ($author_ok eq 'ok') {
 4895:                 my @allnew = @newlangs;
 4896:                 if ($addedfile ne '') {
 4897:                     push(@allnew,$addedfile);
 4898:                 }
 4899:                 foreach my $lang (@allnew) {
 4900:                     my $formelem = 'loginhelpurl_'.$lang;
 4901:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
 4902:                         $formelem = 'loginhelpurl_add_file';
 4903:                     }
 4904:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
 4905:                                                                "help/$lang",'','',$newfile{$lang});
 4906:                     if ($result eq 'ok') {
 4907:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
 4908:                         $changes{'helpurl'}{$lang} = 1;
 4909:                     } else {
 4910:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
 4911:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
 4912:                         if ((grep(/^\Q$lang\E$/,@currlangs)) && 
 4913:                             (!grep(/^\Q$lang\E$/,@delurls))) {
 4914: 
 4915:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 4916:                         }
 4917:                     }
 4918:                 }
 4919:             } else {
 4920:                 $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2].  Error was: [_3].",$confname,$dom,$author_ok);
 4921:             }
 4922:         } else {
 4923:             $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
 4924:         }
 4925:         if ($error) {
 4926:             &Apache::lonnet::logthis($error);
 4927:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 4928:         }
 4929:     }
 4930:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
 4931: 
 4932:     my $defaulthelpfile = '/adm/loginproblems.html';
 4933:     my $defaulttext = &mt('Default in use');
 4934: 
 4935:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 4936:                                              $dom);
 4937:     if ($putresult eq 'ok') {
 4938:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 4939:         my %defaultchecked = (
 4940:                     'coursecatalog' => 'on',
 4941:                     'helpdesk'      => 'on',
 4942:                     'adminmail'     => 'off',
 4943:                     'newuser'       => 'off',
 4944:         );
 4945:         if (ref($domconfig{'login'}) eq 'HASH') {
 4946:             foreach my $item (@toggles) {
 4947:                 if ($defaultchecked{$item} eq 'on') { 
 4948:                     if (($domconfig{'login'}{$item} eq '0') &&
 4949:                         ($env{'form.'.$item} eq '1')) {
 4950:                         $changes{$item} = 1;
 4951:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 4952:                               $domconfig{'login'}{$item} eq '1') &&
 4953:                              ($env{'form.'.$item} eq '0')) {
 4954:                         $changes{$item} = 1;
 4955:                     }
 4956:                 } elsif ($defaultchecked{$item} eq 'off') {
 4957:                     if (($domconfig{'login'}{$item} eq '1') &&
 4958:                         ($env{'form.'.$item} eq '0')) {
 4959:                         $changes{$item} = 1;
 4960:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 4961:                               $domconfig{'login'}{$item} eq '0') &&
 4962:                              ($env{'form.'.$item} eq '1')) {
 4963:                         $changes{$item} = 1;
 4964:                     }
 4965:                 }
 4966:             }
 4967:         }
 4968:         if (keys(%changes) > 0 || $colchgtext) {
 4969:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 4970:             $resulttext = &mt('Changes made:').'<ul>';
 4971:             foreach my $item (sort(keys(%changes))) {
 4972:                 if ($item eq 'loginvia') {
 4973:                     if (ref($changes{$item}) eq 'HASH') {
 4974:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
 4975:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 4976:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
 4977:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
 4978:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
 4979:                                     $protocol = 'http' if ($protocol ne 'https');
 4980:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
 4981: 
 4982:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
 4983:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
 4984:                                     } else {
 4985:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
 4986:                                     }
 4987:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
 4988:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
 4989:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
 4990:                                     }
 4991:                                     $resulttext .= '</li>';
 4992:                                 } else {
 4993:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
 4994:                                 }
 4995:                             } else {
 4996:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
 4997:                             }
 4998:                         }
 4999:                         $resulttext .= '</ul></li>';
 5000:                     }
 5001:                 } elsif ($item eq 'helpurl') {
 5002:                     if (ref($changes{$item}) eq 'HASH') {
 5003:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
 5004:                             if (grep(/^\Q$lang\E$/,@delurls)) {
 5005:                                 my ($chg,$link);
 5006:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
 5007:                                 if ($lang eq 'nolang') {
 5008:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
 5009:                                 } else {
 5010:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
 5011:                                 }
 5012:                                 $resulttext .= '<li>'.$chg.'</li>';
 5013:                             } else {
 5014:                                 my $chg;
 5015:                                 if ($lang eq 'nolang') {
 5016:                                     $chg = &mt('custom log-in help file for no preferred language');
 5017:                                 } else {
 5018:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
 5019:                                 }
 5020:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
 5021:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
 5022:                                                       '?inhibitmenu=yes',$chg,600,500).
 5023:                                                '</li>';
 5024:                             }
 5025:                         }
 5026:                     }
 5027:                 } elsif ($item eq 'captcha') {
 5028:                     if (ref($loginhash{'login'}) eq 'HASH') {
 5029:                         my $chgtxt; 
 5030:                         if ($loginhash{'login'}{$item} eq 'notused') {
 5031:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
 5032:                         } else {
 5033:                             my %captchas = &captcha_phrases();
 5034:                             if ($captchas{$loginhash{'login'}{$item}}) {
 5035:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
 5036:                             } else {
 5037:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
 5038:                             }
 5039:                         }
 5040:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 5041:                     }
 5042:                 } elsif ($item eq 'recaptchakeys') {
 5043:                     if (ref($loginhash{'login'}) eq 'HASH') {
 5044:                         my ($privkey,$pubkey);
 5045:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
 5046:                             $pubkey = $loginhash{'login'}{$item}{'public'};
 5047:                             $privkey = $loginhash{'login'}{$item}{'private'};
 5048:                         }
 5049:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
 5050:                         if (!$pubkey) {
 5051:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
 5052:                         } else {
 5053:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 5054:                         }
 5055:                         if (!$privkey) {
 5056:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
 5057:                         } else {
 5058:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
 5059:                         }
 5060:                         $chgtxt .= '</ul>';
 5061:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 5062:                     }
 5063:                 } else {
 5064:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 5065:                 }
 5066:             }
 5067:             $resulttext .= $colchgtext.'</ul>';
 5068:         } else {
 5069:             $resulttext = &mt('No changes made to log-in page settings');
 5070:         }
 5071:     } else {
 5072:         $resulttext = '<span class="LC_error">'.
 5073: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5074:     }
 5075:     if ($errors) {
 5076:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 5077:                        $errors.'</ul>';
 5078:     }
 5079:     return $resulttext;
 5080: }
 5081: 
 5082: sub color_font_choices {
 5083:     my %choices =
 5084:         &Apache::lonlocal::texthash (
 5085:             img => "Header",
 5086:             bgs => "Background colors",
 5087:             links => "Link colors",
 5088:             images => "Images",
 5089:             font => "Font color",
 5090:             fontmenu => "Font menu",
 5091:             pgbg => "Page",
 5092:             tabbg => "Header",
 5093:             sidebg => "Border",
 5094:             link => "Link",
 5095:             alink => "Active link",
 5096:             vlink => "Visited link",
 5097:         );
 5098:     return %choices;
 5099: }
 5100: 
 5101: sub modify_rolecolors {
 5102:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 5103:     my ($resulttext,%rolehash);
 5104:     $rolehash{'rolecolors'} = {};
 5105:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 5106:         if ($domconfig{'rolecolors'} eq '') {
 5107:             $domconfig{'rolecolors'} = {};
 5108:         }
 5109:     }
 5110:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 5111:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 5112:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 5113:                                              $dom);
 5114:     if ($putresult eq 'ok') {
 5115:         if (keys(%changes) > 0) {
 5116:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 5117:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 5118:                                              $rolehash{'rolecolors'});
 5119:         } else {
 5120:             $resulttext = &mt('No changes made to default color schemes');
 5121:         }
 5122:     } else {
 5123:         $resulttext = '<span class="LC_error">'.
 5124: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5125:     }
 5126:     if ($errors) {
 5127:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 5128:                        $errors.'</ul>';
 5129:     }
 5130:     return $resulttext;
 5131: }
 5132: 
 5133: sub modify_colors {
 5134:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 5135:     my (%changes,%choices);
 5136:     my @bgs;
 5137:     my @links = ('link','alink','vlink');
 5138:     my @logintext;
 5139:     my @images;
 5140:     my $servadm = $r->dir_config('lonAdmEMail');
 5141:     my $errors;
 5142:     my %defaults;
 5143:     foreach my $role (@{$roles}) {
 5144:         if ($role eq 'login') {
 5145:             %choices = &login_choices();
 5146:             @logintext = ('textcol','bgcol');
 5147:         } else {
 5148:             %choices = &color_font_choices();
 5149:         }
 5150:         if ($role eq 'login') {
 5151:             @images = ('img','logo','domlogo','login');
 5152:             @bgs = ('pgbg','mainbg','sidebg');
 5153:         } else {
 5154:             @images = ('img');
 5155:             @bgs = ('pgbg','tabbg','sidebg');
 5156:         }
 5157:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
 5158:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
 5159:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 5160:         }
 5161:         if ($role eq 'login') {
 5162:             foreach my $item (@logintext) {
 5163:                 unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'logintext'}{$item}) {
 5164:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5165:                 }
 5166:             }
 5167:         } else {
 5168:             unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
 5169:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
 5170:             }
 5171:         }
 5172:         foreach my $item (@bgs) {
 5173:             unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
 5174:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5175:             }
 5176:         }
 5177:         foreach my $item (@links) {
 5178:             unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'links'}{$item}) {
 5179:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5180:             }
 5181:         }
 5182:         my ($configuserok,$author_ok,$switchserver) = 
 5183:             &config_check($dom,$confname,$servadm);
 5184:         my ($width,$height) = &thumb_dimensions();
 5185:         if (ref($domconfig->{$role}) ne 'HASH') {
 5186:             $domconfig->{$role} = {};
 5187:         }
 5188:         foreach my $img (@images) {
 5189:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 5190:                 if (defined($env{'form.login_showlogo_'.$img})) {
 5191:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 5192:                 } else { 
 5193:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 5194:                 }
 5195:             } 
 5196: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 5197: 		 && !defined($domconfig->{$role}{$img})
 5198: 		 && !$env{'form.'.$role.'_del_'.$img}
 5199: 		 && $env{'form.'.$role.'_import_'.$img}) {
 5200: 		# import the old configured image from the .tab setting
 5201: 		# if they haven't provided a new one 
 5202: 		$domconfig->{$role}{$img} = 
 5203: 		    $env{'form.'.$role.'_import_'.$img};
 5204: 	    }
 5205:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 5206:                 my $error;
 5207:                 if ($configuserok eq 'ok') {
 5208:                     if ($switchserver) {
 5209:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 5210:                     } else {
 5211:                         if ($author_ok eq 'ok') {
 5212:                             my ($result,$logourl) = 
 5213:                                 &publishlogo($r,'upload',$role.'_'.$img,
 5214:                                            $dom,$confname,$img,$width,$height);
 5215:                             if ($result eq 'ok') {
 5216:                                 $confhash->{$role}{$img} = $logourl;
 5217:                                 $changes{$role}{'images'}{$img} = 1;
 5218:                             } else {
 5219:                                 $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);
 5220:                             }
 5221:                         } else {
 5222:                             $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);
 5223:                         }
 5224:                     }
 5225:                 } else {
 5226:                     $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);
 5227:                 }
 5228:                 if ($error) {
 5229:                     &Apache::lonnet::logthis($error);
 5230:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 5231:                 }
 5232:             } elsif ($domconfig->{$role}{$img} ne '') {
 5233:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 5234:                     my $error;
 5235:                     if ($configuserok eq 'ok') {
 5236: # is confname an author?
 5237:                         if ($switchserver eq '') {
 5238:                             if ($author_ok eq 'ok') {
 5239:                                 my ($result,$logourl) = 
 5240:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 5241:                                             $dom,$confname,$img,$width,$height);
 5242:                                 if ($result eq 'ok') {
 5243:                                     $confhash->{$role}{$img} = $logourl;
 5244: 				    $changes{$role}{'images'}{$img} = 1;
 5245:                                 }
 5246:                             }
 5247:                         }
 5248:                     }
 5249:                 }
 5250:             }
 5251:         }
 5252:         if (ref($domconfig) eq 'HASH') {
 5253:             if (ref($domconfig->{$role}) eq 'HASH') {
 5254:                 foreach my $img (@images) {
 5255:                     if ($domconfig->{$role}{$img} ne '') {
 5256:                         if ($env{'form.'.$role.'_del_'.$img}) {
 5257:                             $confhash->{$role}{$img} = '';
 5258:                             $changes{$role}{'images'}{$img} = 1;
 5259:                         } else {
 5260:                             if ($confhash->{$role}{$img} eq '') {
 5261:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 5262:                             }
 5263:                         }
 5264:                     } else {
 5265:                         if ($env{'form.'.$role.'_del_'.$img}) {
 5266:                             $confhash->{$role}{$img} = '';
 5267:                             $changes{$role}{'images'}{$img} = 1;
 5268:                         } 
 5269:                     }
 5270:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 5271:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 5272:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 5273:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 5274:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 5275:                             }
 5276:                         } else {
 5277:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 5278:                                 $changes{$role}{'showlogo'}{$img} = 1;
 5279:                             }
 5280:                         }
 5281:                     }
 5282:                 }
 5283:                 if ($domconfig->{$role}{'font'} ne '') {
 5284:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 5285:                         $changes{$role}{'font'} = 1;
 5286:                     }
 5287:                 } else {
 5288:                     if ($confhash->{$role}{'font'}) {
 5289:                         $changes{$role}{'font'} = 1;
 5290:                     }
 5291:                 }
 5292:                 if ($role ne 'login') {
 5293:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
 5294:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
 5295:                             $changes{$role}{'fontmenu'} = 1;
 5296:                         }
 5297:                     } else {
 5298:                         if ($confhash->{$role}{'fontmenu'}) {
 5299:                             $changes{$role}{'fontmenu'} = 1;
 5300:                         }
 5301:                     }
 5302:                 }
 5303:                 foreach my $item (@bgs) {
 5304:                     if ($domconfig->{$role}{$item} ne '') {
 5305:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5306:                             $changes{$role}{'bgs'}{$item} = 1;
 5307:                         } 
 5308:                     } else {
 5309:                         if ($confhash->{$role}{$item}) {
 5310:                             $changes{$role}{'bgs'}{$item} = 1;
 5311:                         }
 5312:                     }
 5313:                 }
 5314:                 foreach my $item (@links) {
 5315:                     if ($domconfig->{$role}{$item} ne '') {
 5316:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5317:                             $changes{$role}{'links'}{$item} = 1;
 5318:                         }
 5319:                     } else {
 5320:                         if ($confhash->{$role}{$item}) {
 5321:                             $changes{$role}{'links'}{$item} = 1;
 5322:                         }
 5323:                     }
 5324:                 }
 5325:                 foreach my $item (@logintext) {
 5326:                     if ($domconfig->{$role}{$item} ne '') {
 5327:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5328:                             $changes{$role}{'logintext'}{$item} = 1;
 5329:                         }
 5330:                     } else {
 5331:                         if ($confhash->{$role}{$item}) {
 5332:                             $changes{$role}{'logintext'}{$item} = 1;
 5333:                         }
 5334:                     }
 5335:                 }
 5336:             } else {
 5337:                 &default_change_checker($role,\@images,\@links,\@bgs,
 5338:                                         \@logintext,$confhash,\%changes); 
 5339:             }
 5340:         } else {
 5341:             &default_change_checker($role,\@images,\@links,\@bgs,
 5342:                                     \@logintext,$confhash,\%changes); 
 5343:         }
 5344:     }
 5345:     return ($errors,%changes);
 5346: }
 5347: 
 5348: sub config_check {
 5349:     my ($dom,$confname,$servadm) = @_;
 5350:     my ($configuserok,$author_ok,$switchserver,%currroles);
 5351:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 5352:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 5353:                                                    $confname,$servadm);
 5354:     if ($configuserok eq 'ok') {
 5355:         $switchserver = &check_switchserver($dom,$confname);
 5356:         if ($switchserver eq '') {
 5357:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 5358:         }
 5359:     }
 5360:     return ($configuserok,$author_ok,$switchserver);
 5361: }
 5362: 
 5363: sub default_change_checker {
 5364:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 5365:     foreach my $item (@{$links}) {
 5366:         if ($confhash->{$role}{$item}) {
 5367:             $changes->{$role}{'links'}{$item} = 1;
 5368:         }
 5369:     }
 5370:     foreach my $item (@{$bgs}) {
 5371:         if ($confhash->{$role}{$item}) {
 5372:             $changes->{$role}{'bgs'}{$item} = 1;
 5373:         }
 5374:     }
 5375:     foreach my $item (@{$logintext}) {
 5376:         if ($confhash->{$role}{$item}) {
 5377:             $changes->{$role}{'logintext'}{$item} = 1;
 5378:         }
 5379:     }
 5380:     foreach my $img (@{$images}) {
 5381:         if ($env{'form.'.$role.'_del_'.$img}) {
 5382:             $confhash->{$role}{$img} = '';
 5383:             $changes->{$role}{'images'}{$img} = 1;
 5384:         }
 5385:         if ($role eq 'login') {
 5386:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 5387:                 $changes->{$role}{'showlogo'}{$img} = 1;
 5388:             }
 5389:         }
 5390:     }
 5391:     if ($confhash->{$role}{'font'}) {
 5392:         $changes->{$role}{'font'} = 1;
 5393:     }
 5394: }
 5395: 
 5396: sub display_colorchgs {
 5397:     my ($dom,$changes,$roles,$confhash) = @_;
 5398:     my (%choices,$resulttext);
 5399:     if (!grep(/^login$/,@{$roles})) {
 5400:         $resulttext = &mt('Changes made:').'<br />';
 5401:     }
 5402:     foreach my $role (@{$roles}) {
 5403:         if ($role eq 'login') {
 5404:             %choices = &login_choices();
 5405:         } else {
 5406:             %choices = &color_font_choices();
 5407:         }
 5408:         if (ref($changes->{$role}) eq 'HASH') {
 5409:             if ($role ne 'login') {
 5410:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 5411:             }
 5412:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 5413:                 if ($role ne 'login') {
 5414:                     $resulttext .= '<ul>';
 5415:                 }
 5416:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 5417:                     if ($role ne 'login') {
 5418:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 5419:                     }
 5420:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 5421:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 5422:                             if ($confhash->{$role}{$key}{$item}) {
 5423:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 5424:                             } else {
 5425:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 5426:                             }
 5427:                         } elsif ($confhash->{$role}{$item} eq '') {
 5428:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 5429:                         } else {
 5430:                             my $newitem = $confhash->{$role}{$item};
 5431:                             if ($key eq 'images') {
 5432:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 5433:                             }
 5434:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 5435:                         }
 5436:                     }
 5437:                     if ($role ne 'login') {
 5438:                         $resulttext .= '</ul></li>';
 5439:                     }
 5440:                 } else {
 5441:                     if ($confhash->{$role}{$key} eq '') {
 5442:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 5443:                     } else {
 5444:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 5445:                     }
 5446:                 }
 5447:                 if ($role ne 'login') {
 5448:                     $resulttext .= '</ul>';
 5449:                 }
 5450:             }
 5451:         }
 5452:     }
 5453:     return $resulttext;
 5454: }
 5455: 
 5456: sub thumb_dimensions {
 5457:     return ('200','50');
 5458: }
 5459: 
 5460: sub check_dimensions {
 5461:     my ($inputfile) = @_;
 5462:     my ($fullwidth,$fullheight);
 5463:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 5464:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 5465:             my $imageinfo = <PIPE>;
 5466:             if (!close(PIPE)) {
 5467:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 5468:             }
 5469:             chomp($imageinfo);
 5470:             my ($fullsize) = 
 5471:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 5472:             if ($fullsize) {
 5473:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 5474:             }
 5475:         }
 5476:     }
 5477:     return ($fullwidth,$fullheight);
 5478: }
 5479: 
 5480: sub check_configuser {
 5481:     my ($uhome,$dom,$confname,$servadm) = @_;
 5482:     my ($configuserok,%currroles);
 5483:     if ($uhome eq 'no_host') {
 5484:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 5485:         my $configpass = &LONCAPA::Enrollment::create_password();
 5486:         $configuserok = 
 5487:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 5488:                              $configpass,'','','','','',undef,$servadm);
 5489:     } else {
 5490:         $configuserok = 'ok';
 5491:         %currroles = 
 5492:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 5493:     }
 5494:     return ($configuserok,%currroles);
 5495: }
 5496: 
 5497: sub check_authorstatus {
 5498:     my ($dom,$confname,%currroles) = @_;
 5499:     my $author_ok;
 5500:     if (!$currroles{':'.$dom.':au'}) {
 5501:         my $start = time;
 5502:         my $end = 0;
 5503:         $author_ok = 
 5504:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 5505:                                         'au',$end,$start,'','','domconfig');
 5506:     } else {
 5507:         $author_ok = 'ok';
 5508:     }
 5509:     return $author_ok;
 5510: }
 5511: 
 5512: sub publishlogo {
 5513:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 5514:     my ($output,$fname,$logourl);
 5515:     if ($action eq 'upload') {
 5516:         $fname=$env{'form.'.$formname.'.filename'};
 5517:         chop($env{'form.'.$formname});
 5518:     } else {
 5519:         ($fname) = ($formname =~ /([^\/]+)$/);
 5520:     }
 5521:     if ($savefileas ne '') {
 5522:         $fname = $savefileas;
 5523:     }
 5524:     $fname=&Apache::lonnet::clean_filename($fname);
 5525: # See if there is anything left
 5526:     unless ($fname) { return ('error: no uploaded file'); }
 5527:     $fname="$subdir/$fname";
 5528:     my $docroot=$r->dir_config('lonDocRoot'); 
 5529:     my $filepath="$docroot/priv";
 5530:     my $relpath = "$dom/$confname";
 5531:     my ($fnamepath,$file,$fetchthumb);
 5532:     $file=$fname;
 5533:     if ($fname=~m|/|) {
 5534:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 5535:     }
 5536:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
 5537:     my $count;
 5538:     for ($count=5;$count<=$#parts;$count++) {
 5539:         $filepath.="/$parts[$count]";
 5540:         if ((-e $filepath)!=1) {
 5541:             mkdir($filepath,02770);
 5542:         }
 5543:     }
 5544:     # Check for bad extension and disallow upload
 5545:     if ($file=~/\.(\w+)$/ &&
 5546:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 5547:         $output = 
 5548:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 5549:     } elsif ($file=~/\.(\w+)$/ &&
 5550:         !defined(&Apache::loncommon::fileembstyle($1))) {
 5551:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 5552:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 5553:         $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 5554:     } elsif (-d "$filepath/$file") {
 5555:         $output = &mt('Filename is a directory name - rename the file and re-upload');
 5556:     } else {
 5557:         my $source = $filepath.'/'.$file;
 5558:         my $logfile;
 5559:         if (!open($logfile,">>$source".'.log')) {
 5560:             return (&mt('No write permission to Authoring Space'));
 5561:         }
 5562:         print $logfile
 5563: "\n================= Publish ".localtime()." ================\n".
 5564: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 5565: # Save the file
 5566:         if (!open(FH,'>'.$source)) {
 5567:             &Apache::lonnet::logthis('Failed to create '.$source);
 5568:             return (&mt('Failed to create file'));
 5569:         }
 5570:         if ($action eq 'upload') {
 5571:             if (!print FH ($env{'form.'.$formname})) {
 5572:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 5573:                 return (&mt('Failed to write file'));
 5574:             }
 5575:         } else {
 5576:             my $original = &Apache::lonnet::filelocation('',$formname);
 5577:             if(!copy($original,$source)) {
 5578:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 5579:                 return (&mt('Failed to write file'));
 5580:             }
 5581:         }
 5582:         close(FH);
 5583:         chmod(0660, $source); # Permissions to rw-rw---.
 5584: 
 5585:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 5586:         my $copyfile=$targetdir.'/'.$file;
 5587: 
 5588:         my @parts=split(/\//,$targetdir);
 5589:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 5590:         for (my $count=5;$count<=$#parts;$count++) {
 5591:             $path.="/$parts[$count]";
 5592:             if (!-e $path) {
 5593:                 print $logfile "\nCreating directory ".$path;
 5594:                 mkdir($path,02770);
 5595:             }
 5596:         }
 5597:         my $versionresult;
 5598:         if (-e $copyfile) {
 5599:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 5600:         } else {
 5601:             $versionresult = 'ok';
 5602:         }
 5603:         if ($versionresult eq 'ok') {
 5604:             if (copy($source,$copyfile)) {
 5605:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 5606:                 $output = 'ok';
 5607:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 5608:                 push(@{$modified_urls},[$copyfile,$source]);
 5609:                 my $metaoutput = 
 5610:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 5611:                 unless ($registered_cleanup) {
 5612:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 5613:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 5614:                     $registered_cleanup=1;
 5615:                 }
 5616:             } else {
 5617:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 5618:                 $output = &mt('Failed to copy file to RES space').", $!";
 5619:             }
 5620:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 5621:                 my $inputfile = $filepath.'/'.$file;
 5622:                 my $outfile = $filepath.'/'.'tn-'.$file;
 5623:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 5624:                 if ($fullwidth ne '' && $fullheight ne '') { 
 5625:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 5626:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 5627:                         system("convert -sample $thumbsize $inputfile $outfile");
 5628:                         chmod(0660, $filepath.'/tn-'.$file);
 5629:                         if (-e $outfile) {
 5630:                             my $copyfile=$targetdir.'/tn-'.$file;
 5631:                             if (copy($outfile,$copyfile)) {
 5632:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 5633:                                 my $thumb_metaoutput = 
 5634:                                     &write_metadata($dom,$confname,$formname,
 5635:                                                     $targetdir,'tn-'.$file,$logfile);
 5636:                                 push(@{$modified_urls},[$copyfile,$outfile]);
 5637:                                 unless ($registered_cleanup) {
 5638:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 5639:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 5640:                                     $registered_cleanup=1;
 5641:                                 }
 5642:                             } else {
 5643:                                 print $logfile "\nUnable to write ".$copyfile.
 5644:                                                ':'.$!."\n";
 5645:                             }
 5646:                         }
 5647:                     }
 5648:                 }
 5649:             }
 5650:         } else {
 5651:             $output = $versionresult;
 5652:         }
 5653:     }
 5654:     return ($output,$logourl);
 5655: }
 5656: 
 5657: sub logo_versioning {
 5658:     my ($targetdir,$file,$logfile) = @_;
 5659:     my $target = $targetdir.'/'.$file;
 5660:     my ($maxversion,$fn,$extn,$output);
 5661:     $maxversion = 0;
 5662:     if ($file =~ /^(.+)\.(\w+)$/) {
 5663:         $fn=$1;
 5664:         $extn=$2;
 5665:     }
 5666:     opendir(DIR,$targetdir);
 5667:     while (my $filename=readdir(DIR)) {
 5668:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 5669:             $maxversion=($1>$maxversion)?$1:$maxversion;
 5670:         }
 5671:     }
 5672:     $maxversion++;
 5673:     print $logfile "\nCreating old version ".$maxversion."\n";
 5674:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 5675:     if (copy($target,$copyfile)) {
 5676:         print $logfile "Copied old target to ".$copyfile."\n";
 5677:         $copyfile=$copyfile.'.meta';
 5678:         if (copy($target.'.meta',$copyfile)) {
 5679:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 5680:             $output = 'ok';
 5681:         } else {
 5682:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 5683:             $output = &mt('Failed to copy old meta').", $!, ";
 5684:         }
 5685:     } else {
 5686:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 5687:         $output = &mt('Failed to copy old target').", $!, ";
 5688:     }
 5689:     return $output;
 5690: }
 5691: 
 5692: sub write_metadata {
 5693:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 5694:     my (%metadatafields,%metadatakeys,$output);
 5695:     $metadatafields{'title'}=$formname;
 5696:     $metadatafields{'creationdate'}=time;
 5697:     $metadatafields{'lastrevisiondate'}=time;
 5698:     $metadatafields{'copyright'}='public';
 5699:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 5700:                                          $env{'user.domain'};
 5701:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 5702:     $metadatafields{'domain'}=$dom;
 5703:     {
 5704:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 5705:         my $mfh;
 5706:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 5707:             foreach (sort(keys(%metadatafields))) {
 5708:                 unless ($_=~/\./) {
 5709:                     my $unikey=$_;
 5710:                     $unikey=~/^([A-Za-z]+)/;
 5711:                     my $tag=$1;
 5712:                     $tag=~tr/A-Z/a-z/;
 5713:                     print $mfh "\n\<$tag";
 5714:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
 5715:                         my $value=$metadatafields{$unikey.'.'.$_};
 5716:                         $value=~s/\"/\'\'/g;
 5717:                         print $mfh ' '.$_.'="'.$value.'"';
 5718:                     }
 5719:                     print $mfh '>'.
 5720:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 5721:                             .'</'.$tag.'>';
 5722:                 }
 5723:             }
 5724:             $output = 'ok';
 5725:             print $logfile "\nWrote metadata";
 5726:             close($mfh);
 5727:         } else {
 5728:             print $logfile "\nFailed to open metadata file";
 5729:             $output = &mt('Could not write metadata');
 5730:         }
 5731:     }
 5732:     return $output;
 5733: }
 5734: 
 5735: sub notifysubscribed {
 5736:     foreach my $targetsource (@{$modified_urls}){
 5737:         next unless (ref($targetsource) eq 'ARRAY');
 5738:         my ($target,$source)=@{$targetsource};
 5739:         if ($source ne '') {
 5740:             if (open(my $logfh,'>>'.$source.'.log')) {
 5741:                 print $logfh "\nCleanup phase: Notifications\n";
 5742:                 my @subscribed=&subscribed_hosts($target);
 5743:                 foreach my $subhost (@subscribed) {
 5744:                     print $logfh "\nNotifying host ".$subhost.':';
 5745:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
 5746:                     print $logfh $reply;
 5747:                 }
 5748:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
 5749:                 foreach my $subhost (@subscribedmeta) {
 5750:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
 5751:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
 5752:                                                         $subhost);
 5753:                     print $logfh $reply;
 5754:                 }
 5755:                 print $logfh "\n============ Done ============\n";
 5756:                 close($logfh);
 5757:             }
 5758:         }
 5759:     }
 5760:     return OK;
 5761: }
 5762: 
 5763: sub subscribed_hosts {
 5764:     my ($target) = @_;
 5765:     my @subscribed;
 5766:     if (open(my $fh,"<$target.subscription")) {
 5767:         while (my $subline=<$fh>) {
 5768:             if ($subline =~ /^($match_lonid):/) {
 5769:                 my $host = $1;
 5770:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
 5771:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
 5772:                         push(@subscribed,$host);
 5773:                     }
 5774:                 }
 5775:             }
 5776:         }
 5777:     }
 5778:     return @subscribed;
 5779: }
 5780: 
 5781: sub check_switchserver {
 5782:     my ($dom,$confname) = @_;
 5783:     my ($allowed,$switchserver);
 5784:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 5785:     if ($home eq 'no_host') {
 5786:         $home = &Apache::lonnet::domain($dom,'primary');
 5787:     }
 5788:     my @ids=&Apache::lonnet::current_machine_ids();
 5789:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 5790:     if (!$allowed) {
 5791: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
 5792:     }
 5793:     return $switchserver;
 5794: }
 5795: 
 5796: sub modify_quotas {
 5797:     my ($dom,$action,%domconfig) = @_;
 5798:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
 5799:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
 5800:     if ($action eq 'quotas') {
 5801:         $context = 'tools'; 
 5802:     } else {
 5803:         $context = $action;
 5804:     }
 5805:     if ($context eq 'requestcourses') {
 5806:         @usertools = ('official','unofficial','community');
 5807:         @options =('norequest','approval','validate','autolimit');
 5808:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 5809:         %titles = &courserequest_titles();
 5810:         $toolregexp = join('|',@usertools);
 5811:         %conditions = &courserequest_conditions();
 5812:     } elsif ($context eq 'requestauthor') {
 5813:         @usertools = ('author');
 5814:         %titles = &authorrequest_titles();
 5815:     } else {
 5816:         @usertools = ('aboutme','blog','webdav','portfolio');
 5817:         %titles = &tool_titles();
 5818:     }
 5819:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 5820:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5821:     foreach my $key (keys(%env)) {
 5822:         if ($context eq 'requestcourses') {
 5823:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
 5824:                 my $item = $1;
 5825:                 my $type = $2;
 5826:                 if ($type =~ /^limit_(.+)/) {
 5827:                     $limithash{$item}{$1} = $env{$key};
 5828:                 } else {
 5829:                     $confhash{$item}{$type} = $env{$key};
 5830:                 }
 5831:             }
 5832:         } elsif ($context eq 'requestauthor') {
 5833:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
 5834:                 $confhash{$1} = $env{$key};
 5835:             }
 5836:         } else {
 5837:             if ($key =~ /^form\.quota_(.+)$/) {
 5838:                 $confhash{'defaultquota'}{$1} = $env{$key};
 5839:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
 5840:                 $confhash{'authorquota'}{$1} = $env{$key};
 5841:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
 5842:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 5843:             }
 5844:         }
 5845:     }
 5846:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 5847:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
 5848:         @approvalnotify = sort(@approvalnotify);
 5849:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
 5850:         if (ref($domconfig{$action}) eq 'HASH') {
 5851:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
 5852:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
 5853:                     $changes{'notify'}{'approval'} = 1;
 5854:                 }
 5855:             } else {
 5856:                 if ($confhash{'notify'}{'approval'}) {
 5857:                     $changes{'notify'}{'approval'} = 1;
 5858:                 }
 5859:             }
 5860:         } else {
 5861:             if ($confhash{'notify'}{'approval'}) {
 5862:                 $changes{'notify'}{'approval'} = 1;
 5863:             }
 5864:         }
 5865:     } else {
 5866:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 5867:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
 5868:     }
 5869:     foreach my $item (@usertools) {
 5870:         foreach my $type (@{$types},'default','_LC_adv') {
 5871:             my $unset; 
 5872:             if ($context eq 'requestcourses') {
 5873:                 $unset = '0';
 5874:                 if ($type eq '_LC_adv') {
 5875:                     $unset = '';
 5876:                 }
 5877:                 if ($confhash{$item}{$type} eq 'autolimit') {
 5878:                     $confhash{$item}{$type} .= '=';
 5879:                     unless ($limithash{$item}{$type} =~ /\D/) {
 5880:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
 5881:                     }
 5882:                 }
 5883:             } elsif ($context eq 'requestauthor') {
 5884:                 $unset = '0';
 5885:                 if ($type eq '_LC_adv') {
 5886:                     $unset = '';
 5887:                 }
 5888:             } else {
 5889:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 5890:                     $confhash{$item}{$type} = 1;
 5891:                 } else {
 5892:                     $confhash{$item}{$type} = 0;
 5893:                 }
 5894:             }
 5895:             if (ref($domconfig{$action}) eq 'HASH') {
 5896:                 if ($action eq 'requestauthor') {
 5897:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
 5898:                         $changes{$type} = 1;
 5899:                     }
 5900:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
 5901:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
 5902:                         $changes{$item}{$type} = 1;
 5903:                     }
 5904:                 } else {
 5905:                     if ($context eq 'requestcourses') {
 5906:                         if ($confhash{$item}{$type} ne $unset) {
 5907:                             $changes{$item}{$type} = 1;
 5908:                         }
 5909:                     } else {
 5910:                         if (!$confhash{$item}{$type}) {
 5911:                             $changes{$item}{$type} = 1;
 5912:                         }
 5913:                     }
 5914:                 }
 5915:             } else {
 5916:                 if ($context eq 'requestcourses') {
 5917:                     if ($confhash{$item}{$type} ne $unset) {
 5918:                         $changes{$item}{$type} = 1;
 5919:                     }
 5920:                 } elsif ($context eq 'requestauthor') {
 5921:                     if ($confhash{$type} ne $unset) {
 5922:                         $changes{$type} = 1;
 5923:                     }
 5924:                 } else {
 5925:                     if (!$confhash{$item}{$type}) {
 5926:                         $changes{$item}{$type} = 1;
 5927:                     }
 5928:                 }
 5929:             }
 5930:         }
 5931:     }
 5932:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 5933:         if (ref($domconfig{'quotas'}) eq 'HASH') {
 5934:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 5935:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 5936:                     if (exists($confhash{'defaultquota'}{$key})) {
 5937:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 5938:                             $changes{'defaultquota'}{$key} = 1;
 5939:                         }
 5940:                     } else {
 5941:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 5942:                     }
 5943:                 }
 5944:             } else {
 5945:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
 5946:                     if (exists($confhash{'defaultquota'}{$key})) {
 5947:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 5948:                             $changes{'defaultquota'}{$key} = 1;
 5949:                         }
 5950:                     } else {
 5951:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 5952:                     }
 5953:                 }
 5954:             }
 5955:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 5956:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
 5957:                     if (exists($confhash{'authorquota'}{$key})) {
 5958:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
 5959:                             $changes{'authorquota'}{$key} = 1;
 5960:                         }
 5961:                     } else {
 5962:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
 5963:                     }
 5964:                 }
 5965:             }
 5966:         }
 5967:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
 5968:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 5969:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 5970:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 5971:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 5972:                             $changes{'defaultquota'}{$key} = 1;
 5973:                         }
 5974:                     } else {
 5975:                         if (!exists($domconfig{'quotas'}{$key})) {
 5976:                             $changes{'defaultquota'}{$key} = 1;
 5977:                         }
 5978:                     }
 5979:                 } else {
 5980:                     $changes{'defaultquota'}{$key} = 1;
 5981:                 }
 5982:             }
 5983:         }
 5984:         if (ref($confhash{'authorquota'}) eq 'HASH') {
 5985:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
 5986:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 5987:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 5988:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
 5989:                             $changes{'authorquota'}{$key} = 1;
 5990:                         }
 5991:                     } else {
 5992:                         $changes{'authorquota'}{$key} = 1;
 5993:                     }
 5994:                 } else {
 5995:                     $changes{'authorquota'}{$key} = 1;
 5996:                 }
 5997:             }
 5998:         }
 5999:     }
 6000: 
 6001:     if ($context eq 'requestauthor') {
 6002:         $domdefaults{'requestauthor'} = \%confhash;
 6003:     } else {
 6004:         foreach my $key (keys(%confhash)) {
 6005:             $domdefaults{$key} = $confhash{$key};
 6006:         }
 6007:     }
 6008: 
 6009:     my %quotahash = (
 6010:                       $action => { %confhash }
 6011:                     );
 6012:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 6013:                                              $dom);
 6014:     if ($putresult eq 'ok') {
 6015:         if (keys(%changes) > 0) {
 6016:             my $cachetime = 24*60*60;
 6017:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6018: 
 6019:             $resulttext = &mt('Changes made:').'<ul>';
 6020:             unless (($context eq 'requestcourses') || 
 6021:                     ($context eq 'requestauthor')) {
 6022:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
 6023:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 6024:                     foreach my $type (@{$types},'default') {
 6025:                         if (defined($changes{'defaultquota'}{$type})) {
 6026:                             my $typetitle = $usertypes->{$type};
 6027:                             if ($type eq 'default') {
 6028:                                 $typetitle = $othertitle;
 6029:                             }
 6030:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 6031:                         }
 6032:                     }
 6033:                     $resulttext .= '</ul></li>';
 6034:                 }
 6035:                 if (ref($changes{'authorquota'}) eq 'HASH') {
 6036:                     $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
 6037:                     foreach my $type (@{$types},'default') {
 6038:                         if (defined($changes{'authorquota'}{$type})) {
 6039:                             my $typetitle = $usertypes->{$type};
 6040:                             if ($type eq 'default') {
 6041:                                 $typetitle = $othertitle;
 6042:                             }
 6043:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
 6044:                         }
 6045:                     }
 6046:                     $resulttext .= '</ul></li>';
 6047:                 }
 6048:             }
 6049:             my %newenv;
 6050:             foreach my $item (@usertools) {
 6051:                 my (%haschgs,%inconf);
 6052:                 if ($context eq 'requestauthor') {
 6053:                     %haschgs = %changes;
 6054:                     %inconf = %confhash; 
 6055:                 } else {
 6056:                     if (ref($changes{$item}) eq 'HASH') {
 6057:                         %haschgs = %{$changes{$item}};
 6058:                     }
 6059:                     if (ref($confhash{$item}) eq 'HASH') {
 6060:                         %inconf = %{$confhash{$item}};
 6061:                     }
 6062:                 }
 6063:                 if (keys(%haschgs) > 0) {
 6064:                     my $newacc = 
 6065:                         &Apache::lonnet::usertools_access($env{'user.name'},
 6066:                                                           $env{'user.domain'},
 6067:                                                           $item,'reload',$context);
 6068:                     if (($context eq 'requestcourses') || 
 6069:                         ($context eq 'requestauthor')) {
 6070:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
 6071:                             $newenv{'environment.canrequest.'.$item} = $newacc;
 6072:                         }
 6073:                     } else {
 6074:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 6075:                             $newenv{'environment.availabletools.'.$item} = $newacc;
 6076:                         }
 6077:                     }
 6078:                     unless ($context eq 'requestauthor') {
 6079:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
 6080:                     }
 6081:                     foreach my $type (@{$types},'default','_LC_adv') {
 6082:                         if ($haschgs{$type}) {
 6083:                             my $typetitle = $usertypes->{$type};
 6084:                             if ($type eq 'default') {
 6085:                                 $typetitle = $othertitle;
 6086:                             } elsif ($type eq '_LC_adv') {
 6087:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 6088:                             }
 6089:                             if ($inconf{$type}) {
 6090:                                 if ($context eq 'requestcourses') {
 6091:                                     my $cond;
 6092:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
 6093:                                         if ($1 eq '') {
 6094:                                             $cond = &mt('(Automatic processing of any request).');
 6095:                                         } else {
 6096:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
 6097:                                         }
 6098:                                     } else { 
 6099:                                         $cond = $conditions{$inconf{$type}};
 6100:                                     }
 6101:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
 6102:                                 } elsif ($context eq 'requestauthor') {
 6103:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
 6104:                                                              $titles{$inconf{$type}},$typetitle);
 6105: 
 6106:                                 } else {
 6107:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 6108:                                 }
 6109:                             } else {
 6110:                                 if ($type eq '_LC_adv') {
 6111:                                     if ($inconf{$type} eq '0') {
 6112:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 6113:                                     } else { 
 6114:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
 6115:                                     }
 6116:                                 } else {
 6117:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 6118:                                 }
 6119:                             }
 6120:                         }
 6121:                     }
 6122:                     unless ($context eq 'requestauthor') {
 6123:                         $resulttext .= '</ul></li>';
 6124:                     }
 6125:                 }
 6126:             }
 6127:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
 6128:                 if (ref($changes{'notify'}) eq 'HASH') {
 6129:                     if ($changes{'notify'}{'approval'}) {
 6130:                         if (ref($confhash{'notify'}) eq 'HASH') {
 6131:                             if ($confhash{'notify'}{'approval'}) {
 6132:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
 6133:                             } else {
 6134:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
 6135:                             }
 6136:                         }
 6137:                     }
 6138:                 }
 6139:             }
 6140:             $resulttext .= '</ul>';
 6141:             if (keys(%newenv)) {
 6142:                 &Apache::lonnet::appenv(\%newenv);
 6143:             }
 6144:         } else {
 6145:             if ($context eq 'requestcourses') {
 6146:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
 6147:             } elsif ($context eq 'requestauthor') {
 6148:                 $resulttext = &mt('No changes made to rights to request author space.');
 6149:             } else {
 6150:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
 6151:             }
 6152:         }
 6153:     } else {
 6154:         $resulttext = '<span class="LC_error">'.
 6155: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6156:     }
 6157:     return $resulttext;
 6158: }
 6159: 
 6160: sub modify_autoenroll {
 6161:     my ($dom,%domconfig) = @_;
 6162:     my ($resulttext,%changes);
 6163:     my %currautoenroll;
 6164:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 6165:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 6166:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 6167:         }
 6168:     }
 6169:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 6170:     my %title = ( run => 'Auto-enrollment active',
 6171:                   sender => 'Sender for notification messages',
 6172:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
 6173:     my @offon = ('off','on');
 6174:     my $sender_uname = $env{'form.sender_uname'};
 6175:     my $sender_domain = $env{'form.sender_domain'};
 6176:     if ($sender_domain eq '') {
 6177:         $sender_uname = '';
 6178:     } elsif ($sender_uname eq '') {
 6179:         $sender_domain = '';
 6180:     }
 6181:     my $coowners = $env{'form.autoassign_coowners'};
 6182:     my %autoenrollhash =  (
 6183:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
 6184:                                        'sender_uname' => $sender_uname,
 6185:                                        'sender_domain' => $sender_domain,
 6186:                                        'co-owners' => $coowners,
 6187:                                 }
 6188:                      );
 6189:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 6190:                                              $dom);
 6191:     if ($putresult eq 'ok') {
 6192:         if (exists($currautoenroll{'run'})) {
 6193:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 6194:                  $changes{'run'} = 1;
 6195:              }
 6196:         } elsif ($autorun) {
 6197:             if ($env{'form.autoenroll_run'} ne '1') {
 6198:                  $changes{'run'} = 1;
 6199:             }
 6200:         }
 6201:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 6202:             $changes{'sender'} = 1;
 6203:         }
 6204:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 6205:             $changes{'sender'} = 1;
 6206:         }
 6207:         if ($currautoenroll{'co-owners'} ne '') {
 6208:             if ($currautoenroll{'co-owners'} ne $coowners) {
 6209:                 $changes{'coowners'} = 1;
 6210:             }
 6211:         } elsif ($coowners) {
 6212:             $changes{'coowners'} = 1;
 6213:         }      
 6214:         if (keys(%changes) > 0) {
 6215:             $resulttext = &mt('Changes made:').'<ul>';
 6216:             if ($changes{'run'}) {
 6217:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 6218:             }
 6219:             if ($changes{'sender'}) {
 6220:                 if ($sender_uname eq '' || $sender_domain eq '') {
 6221:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 6222:                 } else {
 6223:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 6224:                 }
 6225:             }
 6226:             if ($changes{'coowners'}) {
 6227:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
 6228:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 6229:             }
 6230:             $resulttext .= '</ul>';
 6231:         } else {
 6232:             $resulttext = &mt('No changes made to auto-enrollment settings');
 6233:         }
 6234:     } else {
 6235:         $resulttext = '<span class="LC_error">'.
 6236: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6237:     }
 6238:     return $resulttext;
 6239: }
 6240: 
 6241: sub modify_autoupdate {
 6242:     my ($dom,%domconfig) = @_;
 6243:     my ($resulttext,%currautoupdate,%fields,%changes);
 6244:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 6245:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 6246:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 6247:         }
 6248:     }
 6249:     my @offon = ('off','on');
 6250:     my %title = &Apache::lonlocal::texthash (
 6251:                    run => 'Auto-update:',
 6252:                    classlists => 'Updates to user information in classlists?'
 6253:                 );
 6254:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 6255:     my %fieldtitles = &Apache::lonlocal::texthash (
 6256:                         id => 'Student/Employee ID',
 6257:                         permanentemail => 'E-mail address',
 6258:                         lastname => 'Last Name',
 6259:                         firstname => 'First Name',
 6260:                         middlename => 'Middle Name',
 6261:                         generation => 'Generation',
 6262:                       );
 6263:     $othertitle = &mt('All users');
 6264:     if (keys(%{$usertypes}) >  0) {
 6265:         $othertitle = &mt('Other users');
 6266:     }
 6267:     foreach my $key (keys(%env)) {
 6268:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 6269:             my ($usertype,$item) = ($1,$2);
 6270:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
 6271:                 if ($usertype eq 'default') {   
 6272:                     push(@{$fields{$1}},$2);
 6273:                 } elsif (ref($types) eq 'ARRAY') {
 6274:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
 6275:                         push(@{$fields{$1}},$2);
 6276:                     }
 6277:                 }
 6278:             }
 6279:         }
 6280:     }
 6281:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
 6282:     @lockablenames = sort(@lockablenames);
 6283:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
 6284:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 6285:         if (@changed) {
 6286:             $changes{'lockablenames'} = 1;
 6287:         }
 6288:     } else {
 6289:         if (@lockablenames) {
 6290:             $changes{'lockablenames'} = 1;
 6291:         }
 6292:     }
 6293:     my %updatehash = (
 6294:                       autoupdate => { run => $env{'form.autoupdate_run'},
 6295:                                       classlists => $env{'form.classlists'},
 6296:                                       fields => {%fields},
 6297:                                       lockablenames => \@lockablenames,
 6298:                                     }
 6299:                      );
 6300:     foreach my $key (keys(%currautoupdate)) {
 6301:         if (($key eq 'run') || ($key eq 'classlists')) {
 6302:             if (exists($updatehash{autoupdate}{$key})) {
 6303:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 6304:                     $changes{$key} = 1;
 6305:                 }
 6306:             }
 6307:         } elsif ($key eq 'fields') {
 6308:             if (ref($currautoupdate{$key}) eq 'HASH') {
 6309:                 foreach my $item (@{$types},'default') {
 6310:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 6311:                         my $change = 0;
 6312:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 6313:                             if (!exists($fields{$item})) {
 6314:                                 $change = 1;
 6315:                                 last;
 6316:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 6317:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 6318:                                     $change = 1;
 6319:                                     last;
 6320:                                 }
 6321:                             }
 6322:                         }
 6323:                         if ($change) {
 6324:                             push(@{$changes{$key}},$item);
 6325:                         }
 6326:                     } 
 6327:                 }
 6328:             }
 6329:         } elsif ($key eq 'lockablenames') {
 6330:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
 6331:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 6332:                 if (@changed) {
 6333:                     $changes{'lockablenames'} = 1;
 6334:                 }
 6335:             } else {
 6336:                 if (@lockablenames) {
 6337:                     $changes{'lockablenames'} = 1;
 6338:                 }
 6339:             }
 6340:         }
 6341:     }
 6342:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
 6343:         if (@lockablenames) {
 6344:             $changes{'lockablenames'} = 1;
 6345:         }
 6346:     }
 6347:     foreach my $item (@{$types},'default') {
 6348:         if (defined($fields{$item})) {
 6349:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 6350:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
 6351:                     my $change = 0;
 6352:                     if (ref($fields{$item}) eq 'ARRAY') {
 6353:                         foreach my $type (@{$fields{$item}}) {
 6354:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
 6355:                                 $change = 1;
 6356:                                 last;
 6357:                             }
 6358:                         }
 6359:                     }
 6360:                     if ($change) {
 6361:                         push(@{$changes{'fields'}},$item);
 6362:                     }
 6363:                 } else {
 6364:                     push(@{$changes{'fields'}},$item);
 6365:                 }
 6366:             } else {
 6367:                 push(@{$changes{'fields'}},$item);
 6368:             }
 6369:         }
 6370:     }
 6371:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 6372:                                              $dom);
 6373:     if ($putresult eq 'ok') {
 6374:         if (keys(%changes) > 0) {
 6375:             $resulttext = &mt('Changes made:').'<ul>';
 6376:             foreach my $key (sort(keys(%changes))) {
 6377:                 if ($key eq 'lockablenames') {
 6378:                     $resulttext .= '<li>';
 6379:                     if (@lockablenames) {
 6380:                         $usertypes->{'default'} = $othertitle;
 6381:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
 6382:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
 6383:                     } else {
 6384:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
 6385:                     }
 6386:                     $resulttext .= '</li>';
 6387:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
 6388:                     foreach my $item (@{$changes{$key}}) {
 6389:                         my @newvalues;
 6390:                         foreach my $type (@{$fields{$item}}) {
 6391:                             push(@newvalues,$fieldtitles{$type});
 6392:                         }
 6393:                         my $newvaluestr;
 6394:                         if (@newvalues > 0) {
 6395:                             $newvaluestr = join(', ',@newvalues);
 6396:                         } else {
 6397:                             $newvaluestr = &mt('none');
 6398:                         }
 6399:                         if ($item eq 'default') {
 6400:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 6401:                         } else {
 6402:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 6403:                         }
 6404:                     }
 6405:                 } else {
 6406:                     my $newvalue;
 6407:                     if ($key eq 'run') {
 6408:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 6409:                     } else {
 6410:                         $newvalue = $offon[$env{'form.'.$key}];
 6411:                     }
 6412:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 6413:                 }
 6414:             }
 6415:             $resulttext .= '</ul>';
 6416:         } else {
 6417:             $resulttext = &mt('No changes made to autoupdates');
 6418:         }
 6419:     } else {
 6420:         $resulttext = '<span class="LC_error">'.
 6421: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6422:     }
 6423:     return $resulttext;
 6424: }
 6425: 
 6426: sub modify_autocreate {
 6427:     my ($dom,%domconfig) = @_;
 6428:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
 6429:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
 6430:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
 6431:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
 6432:         }
 6433:     }
 6434:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
 6435:                  req => 'Auto-creation of validated requests for official courses',
 6436:                  xmldc => 'Identity of course creator of courses from XML files',
 6437:                );
 6438:     my @types = ('xml','req');
 6439:     foreach my $item (@types) {
 6440:         $newvals{$item} = $env{'form.autocreate_'.$item};
 6441:         $newvals{$item} =~ s/\D//g;
 6442:         $newvals{$item} = 0 if ($newvals{$item} eq '');
 6443:     }
 6444:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
 6445:     my %domcoords = &get_active_dcs($dom);
 6446:     unless (exists($domcoords{$newvals{'xmldc'}})) {
 6447:         $newvals{'xmldc'} = '';
 6448:     } 
 6449:     %autocreatehash =  (
 6450:                         autocreate => { xml => $newvals{'xml'},
 6451:                                         req => $newvals{'req'},
 6452:                                       }
 6453:                        );
 6454:     if ($newvals{'xmldc'} ne '') {
 6455:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
 6456:     }
 6457:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
 6458:                                              $dom);
 6459:     if ($putresult eq 'ok') {
 6460:         my @items = @types;
 6461:         if ($newvals{'xml'}) {
 6462:             push(@items,'xmldc');
 6463:         }
 6464:         foreach my $item (@items) {
 6465:             if (exists($currautocreate{$item})) {
 6466:                 if ($currautocreate{$item} ne $newvals{$item}) {
 6467:                     $changes{$item} = 1;
 6468:                 }
 6469:             } elsif ($newvals{$item}) {
 6470:                 $changes{$item} = 1;
 6471:             }
 6472:         }
 6473:         if (keys(%changes) > 0) {
 6474:             my @offon = ('off','on'); 
 6475:             $resulttext = &mt('Changes made:').'<ul>';
 6476:             foreach my $item (@types) {
 6477:                 if ($changes{$item}) {
 6478:                     my $newtxt = $offon[$newvals{$item}];
 6479:                     $resulttext .= '<li>'.
 6480:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
 6481:                                        '<b>','</b>').
 6482:                                    '</li>';
 6483:                 }
 6484:             }
 6485:             if ($changes{'xmldc'}) {
 6486:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
 6487:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
 6488:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
 6489:             }
 6490:             $resulttext .= '</ul>';
 6491:         } else {
 6492:             $resulttext = &mt('No changes made to auto-creation settings');
 6493:         }
 6494:     } else {
 6495:         $resulttext = '<span class="LC_error">'.
 6496:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6497:     }
 6498:     return $resulttext;
 6499: }
 6500: 
 6501: sub modify_directorysrch {
 6502:     my ($dom,%domconfig) = @_;
 6503:     my ($resulttext,%changes);
 6504:     my %currdirsrch;
 6505:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 6506:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 6507:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 6508:         }
 6509:     }
 6510:     my %title = ( available => 'Directory search available',
 6511:                   localonly => 'Other domains can search',
 6512:                   searchby => 'Search types',
 6513:                   searchtypes => 'Search latitude');
 6514:     my @offon = ('off','on');
 6515:     my @otherdoms = ('Yes','No');
 6516: 
 6517:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 6518:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 6519:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 6520: 
 6521:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 6522:     if (keys(%{$usertypes}) == 0) {
 6523:         @cansearch = ('default');
 6524:     } else {
 6525:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 6526:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 6527:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 6528:                     push(@{$changes{'cansearch'}},$type);
 6529:                 }
 6530:             }
 6531:             foreach my $type (@cansearch) {
 6532:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 6533:                     push(@{$changes{'cansearch'}},$type);
 6534:                 }
 6535:             }
 6536:         } else {
 6537:             push(@{$changes{'cansearch'}},@cansearch);
 6538:         }
 6539:     }
 6540: 
 6541:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 6542:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 6543:             if (!grep(/^\Q$by\E$/,@searchby)) {
 6544:                 push(@{$changes{'searchby'}},$by);
 6545:             }
 6546:         }
 6547:         foreach my $by (@searchby) {
 6548:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 6549:                 push(@{$changes{'searchby'}},$by);
 6550:             }
 6551:         }
 6552:     } else {
 6553:         push(@{$changes{'searchby'}},@searchby);
 6554:     }
 6555: 
 6556:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 6557:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 6558:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 6559:                 push(@{$changes{'searchtypes'}},$type);
 6560:             }
 6561:         }
 6562:         foreach my $type (@searchtypes) {
 6563:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 6564:                 push(@{$changes{'searchtypes'}},$type);
 6565:             }
 6566:         }
 6567:     } else {
 6568:         if (exists($currdirsrch{'searchtypes'})) {
 6569:             foreach my $type (@searchtypes) {  
 6570:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 6571:                     push(@{$changes{'searchtypes'}},$type);
 6572:                 }
 6573:             }
 6574:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 6575:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 6576:             }   
 6577:         } else {
 6578:             push(@{$changes{'searchtypes'}},@searchtypes); 
 6579:         }
 6580:     }
 6581: 
 6582:     my %dirsrch_hash =  (
 6583:             directorysrch => { available => $env{'form.dirsrch_available'},
 6584:                                cansearch => \@cansearch,
 6585:                                localonly => $env{'form.dirsrch_localonly'},
 6586:                                searchby => \@searchby,
 6587:                                searchtypes => \@searchtypes,
 6588:                              }
 6589:             );
 6590:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 6591:                                              $dom);
 6592:     if ($putresult eq 'ok') {
 6593:         if (exists($currdirsrch{'available'})) {
 6594:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 6595:                  $changes{'available'} = 1;
 6596:              }
 6597:         } else {
 6598:             if ($env{'form.dirsrch_available'} eq '1') {
 6599:                 $changes{'available'} = 1;
 6600:             }
 6601:         }
 6602:         if (exists($currdirsrch{'localonly'})) {
 6603:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 6604:                  $changes{'localonly'} = 1;
 6605:              }
 6606:         } else {
 6607:             if ($env{'form.dirsrch_localonly'} eq '1') {
 6608:                 $changes{'localonly'} = 1;
 6609:             }
 6610:         }
 6611:         if (keys(%changes) > 0) {
 6612:             $resulttext = &mt('Changes made:').'<ul>';
 6613:             if ($changes{'available'}) {
 6614:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 6615:             }
 6616:             if ($changes{'localonly'}) {
 6617:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 6618:             }
 6619: 
 6620:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 6621:                 my $chgtext;
 6622:                 if (ref($usertypes) eq 'HASH') {
 6623:                     if (keys(%{$usertypes}) > 0) {
 6624:                         foreach my $type (@{$types}) {
 6625:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 6626:                                 $chgtext .= $usertypes->{$type}.'; ';
 6627:                             }
 6628:                         }
 6629:                         if (grep(/^default$/,@cansearch)) {
 6630:                             $chgtext .= $othertitle;
 6631:                         } else {
 6632:                             $chgtext =~ s/\; $//;
 6633:                         }
 6634:                         $resulttext .= 
 6635:                             '<li>'.
 6636:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
 6637:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
 6638:                             '</li>';
 6639:                     }
 6640:                 }
 6641:             }
 6642:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 6643:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 6644:                 my $chgtext;
 6645:                 foreach my $type (@{$titleorder}) {
 6646:                     if (grep(/^\Q$type\E$/,@searchby)) {
 6647:                         if (defined($searchtitles->{$type})) {
 6648:                             $chgtext .= $searchtitles->{$type}.'; ';
 6649:                         }
 6650:                     }
 6651:                 }
 6652:                 $chgtext =~ s/\; $//;
 6653:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 6654:             }
 6655:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 6656:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 6657:                 my $chgtext;
 6658:                 foreach my $type (@{$srchtypeorder}) {
 6659:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 6660:                         if (defined($srchtypes_desc->{$type})) {
 6661:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 6662:                         }
 6663:                     }
 6664:                 }
 6665:                 $chgtext =~ s/\; $//;
 6666:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
 6667:             }
 6668:             $resulttext .= '</ul>';
 6669:         } else {
 6670:             $resulttext = &mt('No changes made to institution directory search settings');
 6671:         }
 6672:     } else {
 6673:         $resulttext = '<span class="LC_error">'.
 6674:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 6675:     }
 6676:     return $resulttext;
 6677: }
 6678: 
 6679: sub modify_contacts {
 6680:     my ($dom,%domconfig) = @_;
 6681:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 6682:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 6683:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 6684:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 6685:         }
 6686:     }
 6687:     my (%others,%to,%bcc);
 6688:     my @contacts = ('supportemail','adminemail');
 6689:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
 6690:                     'requestsmail','updatesmail','idconflictsmail');
 6691:     my @toggles = ('reporterrors','reportupdates');
 6692:     foreach my $type (@mailings) {
 6693:         @{$newsetting{$type}} = 
 6694:             &Apache::loncommon::get_env_multiple('form.'.$type);
 6695:         foreach my $item (@contacts) {
 6696:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 6697:                 $contacts_hash{contacts}{$type}{$item} = 1;
 6698:             } else {
 6699:                 $contacts_hash{contacts}{$type}{$item} = 0;
 6700:             }
 6701:         }  
 6702:         $others{$type} = $env{'form.'.$type.'_others'};
 6703:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 6704:         if ($type eq 'helpdeskmail') {
 6705:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
 6706:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
 6707:         }
 6708:     }
 6709:     foreach my $item (@contacts) {
 6710:         $to{$item} = $env{'form.'.$item};
 6711:         $contacts_hash{'contacts'}{$item} = $to{$item};
 6712:     }
 6713:     foreach my $item (@toggles) {
 6714:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
 6715:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
 6716:         }
 6717:     }
 6718:     if (keys(%currsetting) > 0) {
 6719:         foreach my $item (@contacts) {
 6720:             if ($to{$item} ne $currsetting{$item}) {
 6721:                 $changes{$item} = 1;
 6722:             }
 6723:         }
 6724:         foreach my $type (@mailings) {
 6725:             foreach my $item (@contacts) {
 6726:                 if (ref($currsetting{$type}) eq 'HASH') {
 6727:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 6728:                         push(@{$changes{$type}},$item);
 6729:                     }
 6730:                 } else {
 6731:                     push(@{$changes{$type}},@{$newsetting{$type}});
 6732:                 }
 6733:             }
 6734:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 6735:                 push(@{$changes{$type}},'others');
 6736:             }
 6737:             if ($type eq 'helpdeskmail') {   
 6738:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
 6739:                     push(@{$changes{$type}},'bcc'); 
 6740:                 }
 6741:             }
 6742:         }
 6743:     } else {
 6744:         my %default;
 6745:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 6746:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 6747:         $default{'errormail'} = 'adminemail';
 6748:         $default{'packagesmail'} = 'adminemail';
 6749:         $default{'helpdeskmail'} = 'supportemail';
 6750:         $default{'lonstatusmail'} = 'adminemail';
 6751:         $default{'requestsmail'} = 'adminemail';
 6752:         $default{'updatesmail'} = 'adminemail';
 6753:         foreach my $item (@contacts) {
 6754:            if ($to{$item} ne $default{$item}) {
 6755:               $changes{$item} = 1;
 6756:            }
 6757:         }
 6758:         foreach my $type (@mailings) {
 6759:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 6760:                
 6761:                 push(@{$changes{$type}},@{$newsetting{$type}});
 6762:             }
 6763:             if ($others{$type} ne '') {
 6764:                 push(@{$changes{$type}},'others');
 6765:             }
 6766:             if ($type eq 'helpdeskmail') {
 6767:                 if ($bcc{$type} ne '') {
 6768:                     push(@{$changes{$type}},'bcc');
 6769:                 }
 6770:             }
 6771:         }
 6772:     }
 6773:     foreach my $item (@toggles) {
 6774:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
 6775:             $changes{$item} = 1;
 6776:         } elsif ((!$env{'form.'.$item}) &&
 6777:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
 6778:             $changes{$item} = 1;
 6779:         }
 6780:     }
 6781:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 6782:                                              $dom);
 6783:     if ($putresult eq 'ok') {
 6784:         if (keys(%changes) > 0) {
 6785:             my ($titles,$short_titles)  = &contact_titles();
 6786:             $resulttext = &mt('Changes made:').'<ul>';
 6787:             foreach my $item (@contacts) {
 6788:                 if ($changes{$item}) {
 6789:                     $resulttext .= '<li>'.$titles->{$item}.
 6790:                                     &mt(' set to: ').
 6791:                                     '<span class="LC_cusr_emph">'.
 6792:                                     $to{$item}.'</span></li>';
 6793:                 }
 6794:             }
 6795:             foreach my $type (@mailings) {
 6796:                 if (ref($changes{$type}) eq 'ARRAY') {
 6797:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 6798:                     my @text;
 6799:                     foreach my $item (@{$newsetting{$type}}) {
 6800:                         push(@text,$short_titles->{$item});
 6801:                     }
 6802:                     if ($others{$type} ne '') {
 6803:                         push(@text,$others{$type});
 6804:                     }
 6805:                     $resulttext .= '<span class="LC_cusr_emph">'.
 6806:                                    join(', ',@text).'</span>';
 6807:                     if ($type eq 'helpdeskmail') {
 6808:                         if ($bcc{$type} ne '') {
 6809:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
 6810:                         }
 6811:                     }
 6812:                     $resulttext .= '</li>';
 6813:                 }
 6814:             }
 6815:             my @offon = ('off','on');
 6816:             if ($changes{'reporterrors'}) {
 6817:                 $resulttext .= '<li>'.
 6818:                                &mt('E-mail error reports to [_1] set to "'.
 6819:                                    $offon[$env{'form.reporterrors'}].'".',
 6820:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 6821:                                        &mt('LON-CAPA core group - MSU'),600,500)).
 6822:                                '</li>';
 6823:             }
 6824:             if ($changes{'reportupdates'}) {
 6825:                 $resulttext .= '<li>'.
 6826:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
 6827:                                     $offon[$env{'form.reportupdates'}].'".',
 6828:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 6829:                                         &mt('LON-CAPA core group - MSU'),600,500)).
 6830:                                 '</li>';
 6831:             }
 6832:             $resulttext .= '</ul>';
 6833:         } else {
 6834:             $resulttext = &mt('No changes made to contact information');
 6835:         }
 6836:     } else {
 6837:         $resulttext = '<span class="LC_error">'.
 6838:             &mt('An error occurred: [_1].',$putresult).'</span>';
 6839:     }
 6840:     return $resulttext;
 6841: }
 6842: 
 6843: sub modify_usercreation {
 6844:     my ($dom,%domconfig) = @_;
 6845:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 6846:     my $warningmsg;
 6847:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 6848:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 6849:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 6850:         }
 6851:     }
 6852:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 6853:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 6854:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 6855:     my @contexts = ('author','course','requestcrs','selfcreate');
 6856:     foreach my $item(@contexts) {
 6857:         if ($item eq 'selfcreate') {
 6858:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
 6859:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6860:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
 6861:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
 6862:                     if (grep(/^login$/,@{$cancreate{$item}})) {
 6863:                         $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.');   
 6864:                     }
 6865:                 }
 6866:             }
 6867:         } else {
 6868:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
 6869:         }
 6870:     }
 6871:     my ($othertitle,$usertypes,$types) = 
 6872:         &Apache::loncommon::sorted_inst_types($dom);
 6873:     if (ref($types) eq 'ARRAY') {
 6874:         if (@{$types} > 0) {
 6875:             @{$cancreate{'statustocreate'}} = 
 6876:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
 6877:         } else {
 6878:             @{$cancreate{'statustocreate'}} = ();
 6879:         }
 6880:         push(@contexts,'statustocreate');
 6881:     }
 6882:     &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
 6883:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 6884:         foreach my $item (@contexts) {
 6885:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
 6886:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 6887:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 6888:                         if (ref($cancreate{$item}) eq 'ARRAY') {
 6889:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 6890:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6891:                                     push(@{$changes{'cancreate'}},$item);
 6892:                                 }
 6893:                             }
 6894:                         }
 6895:                     }
 6896:                 } else {
 6897:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
 6898:                         if (@{$cancreate{$item}} > 0) {
 6899:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6900:                                 push(@{$changes{'cancreate'}},$item);
 6901:                             }
 6902:                         }
 6903:                     } else {
 6904:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
 6905:                             if (@{$cancreate{$item}} < 3) {
 6906:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6907:                                     push(@{$changes{'cancreate'}},$item);
 6908:                                 }
 6909:                             }
 6910:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
 6911:                             if (@{$cancreate{$item}} > 0) {
 6912:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6913:                                     push(@{$changes{'cancreate'}},$item);
 6914:                                 }
 6915:                             }
 6916:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
 6917:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6918:                                 push(@{$changes{'cancreate'}},$item);
 6919:                             }
 6920:                         }
 6921:                     }
 6922:                 }
 6923:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6924:                     foreach my $type (@{$cancreate{$item}}) {
 6925:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 6926:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 6927:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6928:                                     push(@{$changes{'cancreate'}},$item);
 6929:                                 }
 6930:                             }
 6931:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
 6932:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
 6933:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
 6934:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6935:                                     push(@{$changes{'cancreate'}},$item);
 6936:                                 }
 6937:                             }
 6938:                         }
 6939:                     }
 6940:                 }
 6941:             } else {
 6942:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 6943:                     push(@{$changes{'cancreate'}},$item);
 6944:                 }
 6945:             }
 6946:         }
 6947:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 6948:         foreach my $item (@contexts) {
 6949:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 6950:                 if ($cancreate{$item} ne 'any') {
 6951:                     push(@{$changes{'cancreate'}},$item);
 6952:                 }
 6953:             } else {
 6954:                 if ($cancreate{$item} ne 'none') {
 6955:                     push(@{$changes{'cancreate'}},$item);
 6956:                 }
 6957:             }
 6958:         }
 6959:     } else {
 6960:         foreach my $item (@contexts)  {
 6961:             push(@{$changes{'cancreate'}},$item);
 6962:         }
 6963:     }
 6964: 
 6965:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 6966:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 6967:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 6968:                 push(@{$changes{'username_rule'}},$type);
 6969:             }
 6970:         }
 6971:         foreach my $type (@username_rule) {
 6972:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 6973:                 push(@{$changes{'username_rule'}},$type);
 6974:             }
 6975:         }
 6976:     } else {
 6977:         push(@{$changes{'username_rule'}},@username_rule);
 6978:     }
 6979: 
 6980:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 6981:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 6982:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 6983:                 push(@{$changes{'id_rule'}},$type);
 6984:             }
 6985:         }
 6986:         foreach my $type (@id_rule) {
 6987:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 6988:                 push(@{$changes{'id_rule'}},$type);
 6989:             }
 6990:         }
 6991:     } else {
 6992:         push(@{$changes{'id_rule'}},@id_rule);
 6993:     }
 6994: 
 6995:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 6996:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 6997:             if (!grep(/^\Q$type\E$/,@email_rule)) {
 6998:                 push(@{$changes{'email_rule'}},$type);
 6999:             }
 7000:         }
 7001:         foreach my $type (@email_rule) {
 7002:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 7003:                 push(@{$changes{'email_rule'}},$type);
 7004:             }
 7005:         }
 7006:     } else {
 7007:         push(@{$changes{'email_rule'}},@email_rule);
 7008:     }
 7009: 
 7010:     my @authen_contexts = ('author','course','domain');
 7011:     my @authtypes = ('int','krb4','krb5','loc');
 7012:     my %authhash;
 7013:     foreach my $item (@authen_contexts) {
 7014:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 7015:         foreach my $auth (@authtypes) {
 7016:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 7017:                 $authhash{$item}{$auth} = 1;
 7018:             } else {
 7019:                 $authhash{$item}{$auth} = 0;
 7020:             }
 7021:         }
 7022:     }
 7023:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 7024:         foreach my $item (@authen_contexts) {
 7025:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 7026:                 foreach my $auth (@authtypes) {
 7027:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 7028:                         push(@{$changes{'authtypes'}},$item);
 7029:                         last;
 7030:                     }
 7031:                 }
 7032:             }
 7033:         }
 7034:     } else {
 7035:         foreach my $item (@authen_contexts) {
 7036:             push(@{$changes{'authtypes'}},$item);
 7037:         }
 7038:     }
 7039: 
 7040:     my %usercreation_hash =  (
 7041:             usercreation => {
 7042:                               cancreate     => \%cancreate,
 7043:                               username_rule => \@username_rule,
 7044:                               id_rule       => \@id_rule,
 7045:                               email_rule    => \@email_rule,
 7046:                               authtypes     => \%authhash,
 7047:                             }
 7048:             );
 7049: 
 7050:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 7051:                                              $dom);
 7052: 
 7053:     my %selfcreatetypes = (
 7054:                              sso   => 'users authenticated by institutional single sign on',
 7055:                              login => 'users authenticated by institutional log-in',
 7056:                              email => 'users who provide a valid e-mail address for use as the username',
 7057:                           );
 7058:     if ($putresult eq 'ok') {
 7059:         if (keys(%changes) > 0) {
 7060:             $resulttext = &mt('Changes made:').'<ul>';
 7061:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 7062:                 my %lt = &usercreation_types();
 7063:                 foreach my $type (@{$changes{'cancreate'}}) {
 7064:                     my $chgtext;
 7065:                     unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
 7066:                         $chgtext = $lt{$type}.', ';
 7067:                     }
 7068:                     if ($type eq 'selfcreate') {
 7069:                         if (@{$cancreate{$type}} == 0) {
 7070:                             $chgtext .= &mt('creation of a new user account is not permitted.');
 7071:                         } else {
 7072:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
 7073:                             foreach my $case (@{$cancreate{$type}}) {
 7074:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 7075:                             }
 7076:                             $chgtext .= '</ul>';
 7077:                             if (ref($cancreate{$type}) eq 'ARRAY') {
 7078:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
 7079:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 7080:                                         if (@{$cancreate{'statustocreate'}} == 0) {
 7081:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 7082:                                         }
 7083:                                     }
 7084:                                 }
 7085:                             }
 7086:                         }
 7087:                     } elsif ($type eq 'statustocreate') {
 7088:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
 7089:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
 7090:                             if (@{$cancreate{'selfcreate'}} > 0) {
 7091:                                 if (@{$cancreate{'statustocreate'}} == 0) {
 7092: 
 7093:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
 7094:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
 7095:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 7096:                                     } 
 7097:                                 } elsif (ref($usertypes) eq 'HASH') {
 7098:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 7099:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
 7100:                                     } else {
 7101:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
 7102:                                     }
 7103:                                     $chgtext .= '<ul>';
 7104:                                     foreach my $case (@{$cancreate{$type}}) {
 7105:                                         if ($case eq 'default') {
 7106:                                             $chgtext .= '<li>'.$othertitle.'</li>';
 7107:                                         } else {
 7108:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
 7109:                                         }
 7110:                                     }
 7111:                                     $chgtext .= '</ul>';
 7112:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 7113:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
 7114:                                     }
 7115:                                 }
 7116:                             } else {
 7117:                                 if (@{$cancreate{$type}} == 0) {
 7118:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
 7119:                                 } else {
 7120:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
 7121:                                 }
 7122:                             }
 7123:                         }
 7124:                     } elsif ($type eq 'captcha') {
 7125:                         if ($cancreate{$type} eq 'notused') {
 7126:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
 7127:                         } else {
 7128:                             my %captchas = &captcha_phrases();
 7129:                             if ($captchas{$cancreate{$type}}) {
 7130:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
 7131:                             } else {
 7132:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.'); 
 7133:                             }
 7134:                         }
 7135:                     } elsif ($type eq 'recaptchakeys') {
 7136:                         my ($privkey,$pubkey);
 7137:                         if (ref($cancreate{$type}) eq 'HASH') {
 7138:                             $pubkey = $cancreate{$type}{'public'};
 7139:                             $privkey = $cancreate{$type}{'private'};
 7140:                         }
 7141:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
 7142:                         if (!$pubkey) {
 7143:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
 7144:                         } else {
 7145:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 7146:                         }
 7147:                         if (!$privkey) {
 7148:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
 7149:                         } else {
 7150:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
 7151:                         }
 7152:                         $chgtext .= '</ul>';
 7153:                     } else {
 7154:                         if ($cancreate{$type} eq 'none') {
 7155:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 7156:                         } elsif ($cancreate{$type} eq 'any') {
 7157:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 7158:                         } elsif ($cancreate{$type} eq 'official') {
 7159:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 7160:                         } elsif ($cancreate{$type} eq 'unofficial') {
 7161:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 7162:                         }
 7163:                     }
 7164:                     $resulttext .= '<li>'.$chgtext.'</li>';
 7165:                 }
 7166:             }
 7167:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 7168:                 my ($rules,$ruleorder) = 
 7169:                     &Apache::lonnet::inst_userrules($dom,'username');
 7170:                 my $chgtext = '<ul>';
 7171:                 foreach my $type (@username_rule) {
 7172:                     if (ref($rules->{$type}) eq 'HASH') {
 7173:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 7174:                     }
 7175:                 }
 7176:                 $chgtext .= '</ul>';
 7177:                 if (@username_rule > 0) {
 7178:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 7179:                 } else {
 7180:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 7181:                 }
 7182:             }
 7183:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 7184:                 my ($idrules,$idruleorder) = 
 7185:                     &Apache::lonnet::inst_userrules($dom,'id');
 7186:                 my $chgtext = '<ul>';
 7187:                 foreach my $type (@id_rule) {
 7188:                     if (ref($idrules->{$type}) eq 'HASH') {
 7189:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 7190:                     }
 7191:                 }
 7192:                 $chgtext .= '</ul>';
 7193:                 if (@id_rule > 0) {
 7194:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 7195:                 } else {
 7196:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 7197:                 }
 7198:             }
 7199:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 7200:                 my ($emailrules,$emailruleorder) =
 7201:                     &Apache::lonnet::inst_userrules($dom,'email');
 7202:                 my $chgtext = '<ul>';
 7203:                 foreach my $type (@email_rule) {
 7204:                     if (ref($emailrules->{$type}) eq 'HASH') {
 7205:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 7206:                     }
 7207:                 }
 7208:                 $chgtext .= '</ul>';
 7209:                 if (@email_rule > 0) {
 7210:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
 7211:                 } else {
 7212:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
 7213:                 }
 7214:             }
 7215: 
 7216:             my %authname = &authtype_names();
 7217:             my %context_title = &context_names();
 7218:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 7219:                 my $chgtext = '<ul>';
 7220:                 foreach my $type (@{$changes{'authtypes'}}) {
 7221:                     my @allowed;
 7222:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 7223:                     foreach my $auth (@authtypes) {
 7224:                         if ($authhash{$type}{$auth}) {
 7225:                             push(@allowed,$authname{$auth});
 7226:                         }
 7227:                     }
 7228:                     if (@allowed > 0) {
 7229:                         $chgtext .= join(', ',@allowed).'</li>';
 7230:                     } else {
 7231:                         $chgtext .= &mt('none').'</li>';
 7232:                     }
 7233:                 }
 7234:                 $chgtext .= '</ul>';
 7235:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 7236:                 $resulttext .= '</li>';
 7237:             }
 7238:             $resulttext .= '</ul>';
 7239:         } else {
 7240:             $resulttext = &mt('No changes made to user creation settings');
 7241:         }
 7242:     } else {
 7243:         $resulttext = '<span class="LC_error">'.
 7244:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7245:     }
 7246:     if ($warningmsg ne '') {
 7247:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 7248:     }
 7249:     return $resulttext;
 7250: }
 7251: 
 7252: sub process_captcha {
 7253:     my ($container,$changes,$newsettings,$current) = @_;
 7254:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
 7255:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
 7256:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
 7257:         $newsettings->{'captcha'} = 'original';
 7258:     }
 7259:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
 7260:         if ($container eq 'cancreate') { 
 7261:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 7262:                 push(@{$changes->{'cancreate'}},'captcha');
 7263:             } elsif (!defined($changes->{'cancreate'})) {
 7264:                 $changes->{'cancreate'} = ['captcha'];
 7265:             }
 7266:         } else {
 7267:             $changes->{'captcha'} = 1;
 7268:         }
 7269:     }
 7270:     my ($newpub,$newpriv,$currpub,$currpriv);
 7271:     if ($newsettings->{'captcha'} eq 'recaptcha') {
 7272:         $newpub = $env{'form.'.$container.'_recaptchapub'};
 7273:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
 7274:         $newpub =~ s/\W//g;
 7275:         $newpriv =~ s/\W//g;
 7276:         $newsettings->{'recaptchakeys'} = {
 7277:                                              public  => $newpub,
 7278:                                              private => $newpriv,
 7279:                                           };
 7280:     }
 7281:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
 7282:         $currpub = $current->{'recaptchakeys'}{'public'};
 7283:         $currpriv = $current->{'recaptchakeys'}{'private'};
 7284:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
 7285:             $newsettings->{'recaptchakeys'} = {
 7286:                                                  public  => '',
 7287:                                                  private => '',
 7288:                                               }
 7289:         }
 7290:     }
 7291:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
 7292:         if ($container eq 'cancreate') {
 7293:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 7294:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
 7295:             } elsif (!defined($changes->{'cancreate'})) {
 7296:                 $changes->{'cancreate'} = ['recaptchakeys'];
 7297:             }
 7298:         } else {
 7299:             $changes->{'recaptchakeys'} = 1; 
 7300:         }
 7301:     }
 7302:     return;
 7303: }
 7304: 
 7305: sub modify_usermodification {
 7306:     my ($dom,%domconfig) = @_;
 7307:     my ($resulttext,%curr_usermodification,%changes);
 7308:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 7309:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 7310:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 7311:         }
 7312:     }
 7313:     my @contexts = ('author','course','selfcreate');
 7314:     my %context_title = (
 7315:                            author => 'In author context',
 7316:                            course => 'In course context',
 7317:                            selfcreate => 'When self creating account', 
 7318:                         );
 7319:     my @fields = ('lastname','firstname','middlename','generation',
 7320:                   'permanentemail','id');
 7321:     my %roles = (
 7322:                   author => ['ca','aa'],
 7323:                   course => ['st','ep','ta','in','cr'],
 7324:                 );
 7325:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 7326:     if (ref($types) eq 'ARRAY') {
 7327:         push(@{$types},'default');
 7328:         $usertypes->{'default'} = $othertitle;
 7329:     }
 7330:     $roles{'selfcreate'} = $types;  
 7331:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 7332:     my %modifyhash;
 7333:     foreach my $context (@contexts) {
 7334:         foreach my $role (@{$roles{$context}}) {
 7335:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 7336:             foreach my $item (@fields) {
 7337:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 7338:                     $modifyhash{$context}{$role}{$item} = 1;
 7339:                 } else {
 7340:                     $modifyhash{$context}{$role}{$item} = 0;
 7341:                 }
 7342:             }
 7343:         }
 7344:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 7345:             foreach my $role (@{$roles{$context}}) {
 7346:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 7347:                     foreach my $field (@fields) {
 7348:                         if ($modifyhash{$context}{$role}{$field} ne 
 7349:                                 $curr_usermodification{$context}{$role}{$field}) {
 7350:                             push(@{$changes{$context}},$role);
 7351:                             last;
 7352:                         }
 7353:                     }
 7354:                 }
 7355:             }
 7356:         } else {
 7357:             foreach my $context (@contexts) {
 7358:                 foreach my $role (@{$roles{$context}}) {
 7359:                     push(@{$changes{$context}},$role);
 7360:                 }
 7361:             }
 7362:         }
 7363:     }
 7364:     my %usermodification_hash =  (
 7365:                                    usermodification => \%modifyhash,
 7366:                                  );
 7367:     my $putresult = &Apache::lonnet::put_dom('configuration',
 7368:                                              \%usermodification_hash,$dom);
 7369:     if ($putresult eq 'ok') {
 7370:         if (keys(%changes) > 0) {
 7371:             $resulttext = &mt('Changes made: ').'<ul>';
 7372:             foreach my $context (@contexts) {
 7373:                 if (ref($changes{$context}) eq 'ARRAY') {
 7374:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 7375:                     if (ref($changes{$context}) eq 'ARRAY') {
 7376:                         foreach my $role (@{$changes{$context}}) {
 7377:                             my $rolename;
 7378:                             if ($context eq 'selfcreate') {
 7379:                                 $rolename = $role;
 7380:                                 if (ref($usertypes) eq 'HASH') {
 7381:                                     if ($usertypes->{$role} ne '') {
 7382:                                         $rolename = $usertypes->{$role};
 7383:                                     }
 7384:                                 }
 7385:                             } else {
 7386:                                 if ($role eq 'cr') {
 7387:                                     $rolename = &mt('Custom');
 7388:                                 } else {
 7389:                                     $rolename = &Apache::lonnet::plaintext($role);
 7390:                                 }
 7391:                             }
 7392:                             my @modifiable;
 7393:                             if ($context eq 'selfcreate') {
 7394:                                 $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): ');
 7395:                             } else {
 7396:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 7397:                             }
 7398:                             foreach my $field (@fields) {
 7399:                                 if ($modifyhash{$context}{$role}{$field}) {
 7400:                                     push(@modifiable,$fieldtitles{$field});
 7401:                                 }
 7402:                             }
 7403:                             if (@modifiable > 0) {
 7404:                                 $resulttext .= join(', ',@modifiable);
 7405:                             } else {
 7406:                                 $resulttext .= &mt('none'); 
 7407:                             }
 7408:                             $resulttext .= '</li>';
 7409:                         }
 7410:                         $resulttext .= '</ul></li>';
 7411:                     }
 7412:                 }
 7413:             }
 7414:             $resulttext .= '</ul>';
 7415:         } else {
 7416:             $resulttext = &mt('No changes made to user modification settings');
 7417:         }
 7418:     } else {
 7419:         $resulttext = '<span class="LC_error">'.
 7420:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7421:     }
 7422:     return $resulttext;
 7423: }
 7424: 
 7425: sub modify_defaults {
 7426:     my ($dom,$r,%domconfig) = @_;
 7427:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 7428:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 7429:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
 7430:     my @authtypes = ('internal','krb4','krb5','localauth');
 7431:     foreach my $item (@items) {
 7432:         $newvalues{$item} = $env{'form.'.$item};
 7433:         if ($item eq 'auth_def') {
 7434:             if ($newvalues{$item} ne '') {
 7435:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 7436:                     push(@errors,$item);
 7437:                 }
 7438:             }
 7439:         } elsif ($item eq 'lang_def') {
 7440:             if ($newvalues{$item} ne '') {
 7441:                 if ($newvalues{$item} =~ /^(\w+)/) {
 7442:                     my $langcode = $1;
 7443:                     if ($langcode ne 'x_chef') {
 7444:                         if (code2language($langcode) eq '') {
 7445:                             push(@errors,$item);
 7446:                         }
 7447:                     }
 7448:                 } else {
 7449:                     push(@errors,$item);
 7450:                 }
 7451:             }
 7452:         } elsif ($item eq 'timezone_def') {
 7453:             if ($newvalues{$item} ne '') {
 7454:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 7455:                     push(@errors,$item);   
 7456:                 }
 7457:             }
 7458:         } elsif ($item eq 'datelocale_def') {
 7459:             if ($newvalues{$item} ne '') {
 7460:                 my @datelocale_ids = DateTime::Locale->ids();
 7461:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 7462:                     push(@errors,$item);
 7463:                 }
 7464:             }
 7465:         } elsif ($item eq 'portal_def') {
 7466:             if ($newvalues{$item} ne '') {
 7467:                 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])\/?$/) {
 7468:                     push(@errors,$item);
 7469:                 }
 7470:             }
 7471:         }
 7472:         if (grep(/^\Q$item\E$/,@errors)) {
 7473:             $newvalues{$item} = $domdefaults{$item};
 7474:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 7475:             $changes{$item} = 1;
 7476:         }
 7477:         $domdefaults{$item} = $newvalues{$item};
 7478:     }
 7479:     my %defaults_hash = (
 7480:                          defaults => \%newvalues,
 7481:                         );
 7482:     my $title = &defaults_titles();
 7483:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 7484:                                              $dom);
 7485:     if ($putresult eq 'ok') {
 7486:         if (keys(%changes) > 0) {
 7487:             $resulttext = &mt('Changes made:').'<ul>';
 7488:             my $version = $r->dir_config('lonVersion');
 7489:             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";
 7490:             foreach my $item (sort(keys(%changes))) {
 7491:                 my $value = $env{'form.'.$item};
 7492:                 if ($value eq '') {
 7493:                     $value = &mt('none');
 7494:                 } elsif ($item eq 'auth_def') {
 7495:                     my %authnames = &authtype_names();
 7496:                     my %shortauth = (
 7497:                              internal => 'int',
 7498:                              krb4 => 'krb4',
 7499:                              krb5 => 'krb5',
 7500:                              localauth  => 'loc',
 7501:                     );
 7502:                     $value = $authnames{$shortauth{$value}};
 7503:                 }
 7504:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 7505:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
 7506:             }
 7507:             $resulttext .= '</ul>';
 7508:             $mailmsgtext .= "\n";
 7509:             my $cachetime = 24*60*60;
 7510:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 7511:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 7512:                 my $notify = 1;
 7513:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
 7514:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
 7515:                         $notify = 0;
 7516:                     }
 7517:                 }
 7518:                 if ($notify) {
 7519:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
 7520:                                                "LON-CAPA Domain Settings Change - $dom",
 7521:                                                $mailmsgtext);
 7522:                 }
 7523:             }
 7524:         } else {
 7525:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 7526:         }
 7527:     } else {
 7528:         $resulttext = '<span class="LC_error">'.
 7529:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7530:     }
 7531:     if (@errors > 0) {
 7532:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 7533:         foreach my $item (@errors) {
 7534:             $resulttext .= ' "'.$title->{$item}.'",';
 7535:         }
 7536:         $resulttext =~ s/,$//;
 7537:     }
 7538:     return $resulttext;
 7539: }
 7540: 
 7541: sub modify_scantron {
 7542:     my ($r,$dom,$confname,%domconfig) = @_;
 7543:     my ($resulttext,%confhash,%changes,$errors);
 7544:     my $custom = 'custom.tab';
 7545:     my $default = 'default.tab';
 7546:     my $servadm = $r->dir_config('lonAdmEMail');
 7547:     my ($configuserok,$author_ok,$switchserver) = 
 7548:         &config_check($dom,$confname,$servadm);
 7549:     if ($env{'form.scantronformat.filename'} ne '') {
 7550:         my $error;
 7551:         if ($configuserok eq 'ok') {
 7552:             if ($switchserver) {
 7553:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
 7554:             } else {
 7555:                 if ($author_ok eq 'ok') {
 7556:                     my ($result,$scantronurl) =
 7557:                         &publishlogo($r,'upload','scantronformat',$dom,
 7558:                                      $confname,'scantron','','',$custom);
 7559:                     if ($result eq 'ok') {
 7560:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 7561:                         $changes{'scantronformat'} = 1;
 7562:                     } else {
 7563:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 7564:                     }
 7565:                 } else {
 7566:                     $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);
 7567:                 }
 7568:             }
 7569:         } else {
 7570:             $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);
 7571:         }
 7572:         if ($error) {
 7573:             &Apache::lonnet::logthis($error);
 7574:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 7575:         }
 7576:     }
 7577:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 7578:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 7579:             if ($env{'form.scantronformat_del'}) {
 7580:                 $confhash{'scantron'}{'scantronformat'} = '';
 7581:                 $changes{'scantronformat'} = 1;
 7582:             }
 7583:         }
 7584:     }
 7585:     if (keys(%confhash) > 0) {
 7586:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 7587:                                                  $dom);
 7588:         if ($putresult eq 'ok') {
 7589:             if (keys(%changes) > 0) {
 7590:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 7591:                     $resulttext = &mt('Changes made:').'<ul>';
 7592:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 7593:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 7594:                     } else {
 7595:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 7596:                     }
 7597:                     $resulttext .= '</ul>';
 7598:                 } else {
 7599:                     $resulttext = &mt('Changes made to bubblesheet format file.');
 7600:                 }
 7601:                 $resulttext .= '</ul>';
 7602:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 7603:             } else {
 7604:                 $resulttext = &mt('No changes made to bubblesheet format file');
 7605:             }
 7606:         } else {
 7607:             $resulttext = '<span class="LC_error">'.
 7608:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 7609:         }
 7610:     } else {
 7611:         $resulttext = &mt('No changes made to bubblesheet format file'); 
 7612:     }
 7613:     if ($errors) {
 7614:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 7615:                        $errors.'</ul>';
 7616:     }
 7617:     return $resulttext;
 7618: }
 7619: 
 7620: sub modify_coursecategories {
 7621:     my ($dom,%domconfig) = @_;
 7622:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 7623:         $cathash);
 7624:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 7625:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 7626:         $cathash = $domconfig{'coursecategories'}{'cats'};
 7627:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 7628:             $changes{'togglecats'} = 1;
 7629:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 7630:         }
 7631:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 7632:             $changes{'categorize'} = 1;
 7633:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 7634:         }
 7635:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
 7636:             $changes{'togglecatscomm'} = 1;
 7637:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
 7638:         }
 7639:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
 7640:             $changes{'categorizecomm'} = 1;
 7641:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
 7642:         }
 7643:     } else {
 7644:         $changes{'togglecats'} = 1;
 7645:         $changes{'categorize'} = 1;
 7646:         $changes{'togglecatscomm'} = 1;
 7647:         $changes{'categorizecomm'} = 1;
 7648:         $domconfig{'coursecategories'} = {
 7649:                                              togglecats => $env{'form.togglecats'},
 7650:                                              categorize => $env{'form.categorize'},
 7651:                                              togglecatscomm => $env{'form.togglecatscomm'},
 7652:                                              categorizecomm => $env{'form.categorizecomm'},
 7653:                                          };
 7654:     }
 7655:     if (ref($cathash) eq 'HASH') {
 7656:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 7657:             push (@deletecategory,'instcode::0');
 7658:         }
 7659:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
 7660:             push(@deletecategory,'communities::0');
 7661:         }
 7662:     }
 7663:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 7664:     if (ref($cathash) eq 'HASH') {
 7665:         if (@deletecategory > 0) {
 7666:             #FIXME Need to remove category from all courses using a deleted category 
 7667:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 7668:             foreach my $item (@deletecategory) {
 7669:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 7670:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 7671:                     $deletions{$item} = 1;
 7672:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 7673:                 }
 7674:             }
 7675:         }
 7676:         foreach my $item (keys(%{$cathash})) {
 7677:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 7678:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 7679:                 $reorderings{$item} = 1;
 7680:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 7681:             }
 7682:             if ($env{'form.addcategory_name_'.$item} ne '') {
 7683:                 my $newcat = $env{'form.addcategory_name_'.$item};
 7684:                 my $newdepth = $depth+1;
 7685:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 7686:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 7687:                 $adds{$newitem} = 1; 
 7688:             }
 7689:             if ($env{'form.subcat_'.$item} ne '') {
 7690:                 my $newcat = $env{'form.subcat_'.$item};
 7691:                 my $newdepth = $depth+1;
 7692:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 7693:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 7694:                 $adds{$newitem} = 1;
 7695:             }
 7696:         }
 7697:     }
 7698:     if ($env{'form.instcode'} eq '1') {
 7699:         if (ref($cathash) eq 'HASH') {
 7700:             my $newitem = 'instcode::0';
 7701:             if ($cathash->{$newitem} eq '') {  
 7702:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 7703:                 $adds{$newitem} = 1;
 7704:             }
 7705:         } else {
 7706:             my $newitem = 'instcode::0';
 7707:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 7708:             $adds{$newitem} = 1;
 7709:         }
 7710:     }
 7711:     if ($env{'form.communities'} eq '1') {
 7712:         if (ref($cathash) eq 'HASH') {
 7713:             my $newitem = 'communities::0';
 7714:             if ($cathash->{$newitem} eq '') {
 7715:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 7716:                 $adds{$newitem} = 1;
 7717:             }
 7718:         } else {
 7719:             my $newitem = 'communities::0';
 7720:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 7721:             $adds{$newitem} = 1;
 7722:         }
 7723:     }
 7724:     if ($env{'form.addcategory_name'} ne '') {
 7725:         if (($env{'form.addcategory_name'} ne 'instcode') &&
 7726:             ($env{'form.addcategory_name'} ne 'communities')) {
 7727:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 7728:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 7729:             $adds{$newitem} = 1;
 7730:         }
 7731:     }
 7732:     my $putresult;
 7733:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7734:         if (keys(%deletions) > 0) {
 7735:             foreach my $key (keys(%deletions)) {
 7736:                 if ($predelallitems{$key} ne '') {
 7737:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 7738:                 }
 7739:             }
 7740:         }
 7741:         my (@chkcats,@chktrails,%chkallitems);
 7742:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 7743:         if (ref($chkcats[0]) eq 'ARRAY') {
 7744:             my $depth = 0;
 7745:             my $chg = 0;
 7746:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 7747:                 my $name = $chkcats[0][$i];
 7748:                 my $item;
 7749:                 if ($name eq '') {
 7750:                     $chg ++;
 7751:                 } else {
 7752:                     $item = &escape($name).'::0';
 7753:                     if ($chg) {
 7754:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 7755:                     }
 7756:                     $depth ++; 
 7757:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 7758:                     $depth --;
 7759:                 }
 7760:             }
 7761:         }
 7762:     }
 7763:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7764:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 7765:         if ($putresult eq 'ok') {
 7766:             my %title = (
 7767:                          togglecats     => 'Show/Hide a course in catalog',
 7768:                          categorize     => 'Assign a category to a course',
 7769:                          togglecatscomm => 'Show/Hide a community in catalog',
 7770:                          categorizecomm => 'Assign a category to a community',
 7771:                         );
 7772:             my %level = (
 7773:                          dom  => 'set in Domain ("Modify Course/Community")',
 7774:                          crs  => 'set in Course ("Course Configuration")',
 7775:                          comm => 'set in Community ("Community Configuration")',
 7776:                         );
 7777:             $resulttext = &mt('Changes made:').'<ul>';
 7778:             if ($changes{'togglecats'}) {
 7779:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 7780:             }
 7781:             if ($changes{'categorize'}) {
 7782:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 7783:             }
 7784:             if ($changes{'togglecatscomm'}) {
 7785:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
 7786:             }
 7787:             if ($changes{'categorizecomm'}) {
 7788:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
 7789:             }
 7790:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7791:                 my $cathash;
 7792:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 7793:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 7794:                 } else {
 7795:                     $cathash = {};
 7796:                 } 
 7797:                 my (@cats,@trails,%allitems);
 7798:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 7799:                 if (keys(%deletions) > 0) {
 7800:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 7801:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 7802:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 7803:                     }
 7804:                     $resulttext .= '</ul></li>';
 7805:                 }
 7806:                 if (keys(%reorderings) > 0) {
 7807:                     my %sort_by_trail;
 7808:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 7809:                     foreach my $key (keys(%reorderings)) {
 7810:                         if ($allitems{$key} ne '') {
 7811:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 7812:                         }
 7813:                     }
 7814:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 7815:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 7816:                     }
 7817:                     $resulttext .= '</ul></li>';
 7818:                 }
 7819:                 if (keys(%adds) > 0) {
 7820:                     my %sort_by_trail;
 7821:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
 7822:                     foreach my $key (keys(%adds)) {
 7823:                         if ($allitems{$key} ne '') {
 7824:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 7825:                         }
 7826:                     }
 7827:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 7828:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 7829:                     }
 7830:                     $resulttext .= '</ul></li>';
 7831:                 }
 7832:             }
 7833:             $resulttext .= '</ul>';
 7834:         } else {
 7835:             $resulttext = '<span class="LC_error">'.
 7836:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 7837:         }
 7838:     } else {
 7839:         $resulttext = &mt('No changes made to course and community categories');
 7840:     }
 7841:     return $resulttext;
 7842: }
 7843: 
 7844: sub modify_serverstatuses {
 7845:     my ($dom,%domconfig) = @_;
 7846:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
 7847:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
 7848:         %currserverstatus = %{$domconfig{'serverstatuses'}};
 7849:     }
 7850:     my @pages = &serverstatus_pages();
 7851:     foreach my $type (@pages) {
 7852:         $newserverstatus{$type}{'namedusers'} = '';
 7853:         $newserverstatus{$type}{'machines'} = '';
 7854:         if (defined($env{'form.'.$type.'_namedusers'})) {
 7855:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
 7856:             my @okusers;
 7857:             foreach my $user (@users) {
 7858:                 my ($uname,$udom) = split(/:/,$user);
 7859:                 if (($udom =~ /^$match_domain$/) &&   
 7860:                     (&Apache::lonnet::domain($udom)) &&
 7861:                     ($uname =~ /^$match_username$/)) {
 7862:                     if (!grep(/^\Q$user\E/,@okusers)) {
 7863:                         push(@okusers,$user);
 7864:                     }
 7865:                 }
 7866:             }
 7867:             if (@okusers > 0) {
 7868:                  @okusers = sort(@okusers);
 7869:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
 7870:             }
 7871:         }
 7872:         if (defined($env{'form.'.$type.'_machines'})) {
 7873:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
 7874:             my @okmachines;
 7875:             foreach my $ip (@machines) {
 7876:                 my @parts = split(/\./,$ip);
 7877:                 next if (@parts < 4);
 7878:                 my $badip = 0;
 7879:                 for (my $i=0; $i<4; $i++) {
 7880:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
 7881:                         $badip = 1;
 7882:                         last;
 7883:                     }
 7884:                 }
 7885:                 if (!$badip) {
 7886:                     push(@okmachines,$ip);     
 7887:                 }
 7888:             }
 7889:             @okmachines = sort(@okmachines);
 7890:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
 7891:         }
 7892:     }
 7893:     my %serverstatushash =  (
 7894:                                 serverstatuses => \%newserverstatus,
 7895:                             );
 7896:     foreach my $type (@pages) {
 7897:         foreach my $setting ('namedusers','machines') {
 7898:             my (@current,@new);
 7899:             if (ref($currserverstatus{$type}) eq 'HASH') {
 7900:                 if ($currserverstatus{$type}{$setting} ne '') { 
 7901:                     @current = split(/,/,$currserverstatus{$type}{$setting});
 7902:                 }
 7903:             }
 7904:             if ($newserverstatus{$type}{$setting} ne '') {
 7905:                 @new = split(/,/,$newserverstatus{$type}{$setting});
 7906:             }
 7907:             if (@current > 0) {
 7908:                 if (@new > 0) {
 7909:                     foreach my $item (@current) {
 7910:                         if (!grep(/^\Q$item\E$/,@new)) {
 7911:                             $changes{$type}{$setting} = 1;
 7912:                             last;
 7913:                         }
 7914:                     }
 7915:                     foreach my $item (@new) {
 7916:                         if (!grep(/^\Q$item\E$/,@current)) {
 7917:                             $changes{$type}{$setting} = 1;
 7918:                             last;
 7919:                         }
 7920:                     }
 7921:                 } else {
 7922:                     $changes{$type}{$setting} = 1;
 7923:                 }
 7924:             } elsif (@new > 0) {
 7925:                 $changes{$type}{$setting} = 1;
 7926:             }
 7927:         }
 7928:     }
 7929:     if (keys(%changes) > 0) {
 7930:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 7931:         my $putresult = &Apache::lonnet::put_dom('configuration',
 7932:                                                  \%serverstatushash,$dom);
 7933:         if ($putresult eq 'ok') {
 7934:             $resulttext .= &mt('Changes made:').'<ul>';
 7935:             foreach my $type (@pages) {
 7936:                 if (ref($changes{$type}) eq 'HASH') {
 7937:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
 7938:                     if ($changes{$type}{'namedusers'}) {
 7939:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
 7940:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
 7941:                         } else {
 7942:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
 7943:                         }
 7944:                     }
 7945:                     if ($changes{$type}{'machines'}) {
 7946:                         if ($newserverstatus{$type}{'machines'} eq '') {
 7947:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
 7948:                         } else {
 7949:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
 7950:                         }
 7951: 
 7952:                     }
 7953:                     $resulttext .= '</ul></li>';
 7954:                 }
 7955:             }
 7956:             $resulttext .= '</ul>';
 7957:         } else {
 7958:             $resulttext = '<span class="LC_error">'.
 7959:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
 7960: 
 7961:         }
 7962:     } else {
 7963:         $resulttext = &mt('No changes made to access to server status pages');
 7964:     }
 7965:     return $resulttext;
 7966: }
 7967: 
 7968: sub modify_helpsettings {
 7969:     my ($r,$dom,$confname,%domconfig) = @_;
 7970:     my ($resulttext,$errors,%changes,%helphash);
 7971:     my %defaultchecked = ('submitbugs' => 'on');
 7972:     my @offon = ('off','on');
 7973:     my @toggles = ('submitbugs');
 7974:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
 7975:         foreach my $item (@toggles) {
 7976:             if ($defaultchecked{$item} eq 'on') { 
 7977:                 if ($domconfig{'helpsettings'}{$item} eq '') {
 7978:                     if ($env{'form.'.$item} eq '0') {
 7979:                         $changes{$item} = 1;
 7980:                     }
 7981:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 7982:                     $changes{$item} = 1;
 7983:                 }
 7984:             } elsif ($defaultchecked{$item} eq 'off') {
 7985:                 if ($domconfig{'helpsettings'}{$item} eq '') {
 7986:                     if ($env{'form.'.$item} eq '1') {
 7987:                         $changes{$item} = 1;
 7988:                     }
 7989:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 7990:                     $changes{$item} = 1;
 7991:                 }
 7992:             }
 7993:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { 
 7994:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
 7995:             }
 7996:         }
 7997:     }
 7998:     my $putresult;
 7999:     if (keys(%changes) > 0) {
 8000:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
 8001:         if ($putresult eq 'ok') {
 8002:             $resulttext = &mt('Changes made:').'<ul>';
 8003:             foreach my $item (sort(keys(%changes))) {
 8004:                 if ($item eq 'submitbugs') {
 8005:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
 8006:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
 8007:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
 8008:                 }
 8009:             }
 8010:             $resulttext .= '</ul>';
 8011:         } else {
 8012:             $resulttext = &mt('No changes made to help settings');
 8013:             $errors .= '<li><span class="LC_error">'.
 8014:                        &mt('An error occurred storing the settings: [_1]',
 8015:                            $putresult).'</span></li>';
 8016:         }
 8017:     }
 8018:     if ($errors) {
 8019:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 8020:                        $errors.'</ul>';
 8021:     }
 8022:     return $resulttext;
 8023: }
 8024: 
 8025: sub modify_coursedefaults {
 8026:     my ($dom,%domconfig) = @_;
 8027:     my ($resulttext,$errors,%changes,%defaultshash);
 8028:     my %defaultchecked = ('canuse_pdfforms' => 'off');
 8029:     my @toggles = ('canuse_pdfforms');
 8030:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
 8031:                    'uploadquota_community');
 8032:     my @types = ('official','unofficial','community');
 8033:     my %staticdefaults = (
 8034:                            anonsurvey_threshold => 10,
 8035:                            uploadquota          => 500,
 8036:                          );
 8037: 
 8038:     $defaultshash{'coursedefaults'} = {};
 8039: 
 8040:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
 8041:         if ($domconfig{'coursedefaults'} eq '') {
 8042:             $domconfig{'coursedefaults'} = {};
 8043:         }
 8044:     }
 8045: 
 8046:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
 8047:         foreach my $item (@toggles) {
 8048:             if ($defaultchecked{$item} eq 'on') {
 8049:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 8050:                     ($env{'form.'.$item} eq '0')) {
 8051:                     $changes{$item} = 1;
 8052:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 8053:                     $changes{$item} = 1;
 8054:                 }
 8055:             } elsif ($defaultchecked{$item} eq 'off') {
 8056:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 8057:                     ($env{'form.'.$item} eq '1')) {
 8058:                     $changes{$item} = 1;
 8059:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 8060:                     $changes{$item} = 1;
 8061:                 }
 8062:             }
 8063:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
 8064:         }
 8065:         foreach my $item (@numbers) {
 8066:             my ($currdef,$newdef);
 8067:             my $newdef = $env{'form.'.$item};
 8068:             if ($item eq 'anonsurvey_threshold') {
 8069:                 $currdef = $domconfig{'coursedefaults'}{$item};
 8070:                 $newdef =~ s/\D//g;
 8071:                 if ($newdef eq '' || $newdef < 1) {
 8072:                     $newdef = 1;
 8073:                 }
 8074:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
 8075:             } else {
 8076:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
 8077:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8078:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
 8079:                 }
 8080:                 $newdef =~ s/[^\w.\-]//g;
 8081:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
 8082:             }
 8083:             if ($currdef ne $newdef) {
 8084:                 my $staticdef;
 8085:                 if ($item eq 'anonsurvey_threshold') {
 8086:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
 8087:                         $changes{$item} = 1;
 8088:                     }
 8089:                 } else {
 8090:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
 8091:                         $changes{'uploadquota'} = 1;
 8092:                     }
 8093:                 }
 8094:             }
 8095:         }
 8096:         my $officialcreds = $env{'form.official_credits'};
 8097:         $officialcreds =~ s/^[^\d\.]//g;
 8098:         my $unofficialcreds = $env{'form.unofficial_credits'};
 8099:         $unofficialcreds =~ s/^[^\d\.]//g;
 8100:         if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
 8101:                 ($env{'form.coursecredits'} eq '1')) {
 8102:                 $changes{'coursecredits'} = 1;
 8103:         } else {
 8104:             if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
 8105:                 ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
 8106:                 $changes{'coursecredits'} = 1;
 8107:             }
 8108:         }
 8109:         $defaultshash{'coursedefaults'}{'coursecredits'} = {
 8110:             official   => $officialcreds,
 8111:             unofficial => $unofficialcreds,
 8112:         }
 8113:     }
 8114:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 8115:                                              $dom);
 8116:     if ($putresult eq 'ok') {
 8117:         my %domdefaults;
 8118:         if (keys(%changes) > 0) {
 8119:             if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
 8120:                 %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 8121:                 if ($changes{'canuse_pdfforms'}) {
 8122:                     $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
 8123:                 }
 8124:                 if ($changes{'coursecredits'}) {
 8125:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
 8126:                         $domdefaults{'officialcredits'} =
 8127:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
 8128:                         $domdefaults{'unofficialcredits'} =
 8129:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
 8130:                     }
 8131:                 }
 8132:                 if ($changes{'uploadquota'}) {
 8133:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8134:                         foreach my $type (@types) {
 8135:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
 8136:                         }
 8137:                     }
 8138:                 }
 8139:                 my $cachetime = 24*60*60;
 8140:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 8141:             }
 8142:             $resulttext = &mt('Changes made:').'<ul>';
 8143:             foreach my $item (sort(keys(%changes))) {
 8144:                 if ($item eq 'canuse_pdfforms') {
 8145:                     if ($env{'form.'.$item} eq '1') {
 8146:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
 8147:                     } else {
 8148:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
 8149:                     }
 8150:                 } elsif ($item eq 'anonsurvey_threshold') {
 8151:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
 8152:                 } elsif ($item eq 'uploadquota') {
 8153:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8154:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
 8155:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
 8156:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
 8157:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
 8158:                                        '</ul>'.
 8159:                                        '</li>';
 8160:                     } else {
 8161:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
 8162:                     }
 8163:                 } elsif ($item eq 'coursecredits') {
 8164:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
 8165:                         if (($domdefaults{'officialcredits'} eq '') &&
 8166:                             ($domdefaults{'unofficialcredits'} eq '')) {
 8167:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
 8168:                         } else {
 8169:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
 8170:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
 8171:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
 8172:                                            '</ul>'.
 8173:                                            '</li>';
 8174:                         }
 8175:                     } else {
 8176:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
 8177:                     }
 8178:                 }
 8179:             }
 8180:             $resulttext .= '</ul>';
 8181:         } else {
 8182:             $resulttext = &mt('No changes made to course defaults');
 8183:         }
 8184:     } else {
 8185:         $resulttext = '<span class="LC_error">'.
 8186:             &mt('An error occurred: [_1]',$putresult).'</span>';
 8187:     }
 8188:     return $resulttext;
 8189: }
 8190: 
 8191: sub modify_usersessions {
 8192:     my ($dom,%domconfig) = @_;
 8193:     my @hostingtypes = ('version','excludedomain','includedomain');
 8194:     my @offloadtypes = ('primary','default');
 8195:     my %types = (
 8196:                   remote => \@hostingtypes,
 8197:                   hosted => \@hostingtypes,
 8198:                   spares => \@offloadtypes,
 8199:                 );
 8200:     my @prefixes = ('remote','hosted','spares');
 8201:     my @lcversions = &Apache::lonnet::all_loncaparevs();
 8202:     my (%by_ip,%by_location,@intdoms);
 8203:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 8204:     my @locations = sort(keys(%by_location));
 8205:     my (%defaultshash,%changes);
 8206:     foreach my $prefix (@prefixes) {
 8207:         $defaultshash{'usersessions'}{$prefix} = {};
 8208:     }
 8209:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 8210:     my $resulttext;
 8211:     my %iphost = &Apache::lonnet::get_iphost();
 8212:     foreach my $prefix (@prefixes) {
 8213:         next if ($prefix eq 'spares');
 8214:         foreach my $type (@{$types{$prefix}}) {
 8215:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
 8216:             if ($type eq 'version') {
 8217:                 my $value = $env{'form.'.$prefix.'_'.$type};
 8218:                 my $okvalue;
 8219:                 if ($value ne '') {
 8220:                     if (grep(/^\Q$value\E$/,@lcversions)) {
 8221:                         $okvalue = $value;
 8222:                     }
 8223:                 }
 8224:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8225:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 8226:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
 8227:                             if ($inuse == 0) {
 8228:                                 $changes{$prefix}{$type} = 1;
 8229:                             } else {
 8230:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
 8231:                                     $changes{$prefix}{$type} = 1;
 8232:                                 }
 8233:                                 if ($okvalue ne '') {
 8234:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8235:                                 } 
 8236:                             }
 8237:                         } else {
 8238:                             if (($inuse == 1) && ($okvalue ne '')) {
 8239:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8240:                                 $changes{$prefix}{$type} = 1;
 8241:                             }
 8242:                         }
 8243:                     } else {
 8244:                         if (($inuse == 1) && ($okvalue ne '')) {
 8245:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8246:                             $changes{$prefix}{$type} = 1;
 8247:                         }
 8248:                     }
 8249:                 } else {
 8250:                     if (($inuse == 1) && ($okvalue ne '')) {
 8251:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8252:                         $changes{$prefix}{$type} = 1;
 8253:                     }
 8254:                 }
 8255:             } else {
 8256:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
 8257:                 my @okvals;
 8258:                 foreach my $val (@vals) {
 8259:                     if ($val =~ /:/) {
 8260:                         my @items = split(/:/,$val);
 8261:                         foreach my $item (@items) {
 8262:                             if (ref($by_location{$item}) eq 'ARRAY') {
 8263:                                 push(@okvals,$item);
 8264:                             }
 8265:                         }
 8266:                     } else {
 8267:                         if (ref($by_location{$val}) eq 'ARRAY') {
 8268:                             push(@okvals,$val);
 8269:                         }
 8270:                     }
 8271:                 }
 8272:                 @okvals = sort(@okvals);
 8273:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8274:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 8275:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 8276:                             if ($inuse == 0) {
 8277:                                 $changes{$prefix}{$type} = 1; 
 8278:                             } else {
 8279:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8280:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
 8281:                                 if (@changed > 0) {
 8282:                                     $changes{$prefix}{$type} = 1;
 8283:                                 }
 8284:                             }
 8285:                         } else {
 8286:                             if ($inuse == 1) {
 8287:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8288:                                 $changes{$prefix}{$type} = 1;
 8289:                             }
 8290:                         } 
 8291:                     } else {
 8292:                         if ($inuse == 1) {
 8293:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8294:                             $changes{$prefix}{$type} = 1;
 8295:                         }
 8296:                     }
 8297:                 } else {
 8298:                     if ($inuse == 1) {
 8299:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8300:                         $changes{$prefix}{$type} = 1;
 8301:                     }
 8302:                 }
 8303:             }
 8304:         }
 8305:     }
 8306: 
 8307:     my @alldoms = &Apache::lonnet::all_domains();
 8308:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 8309:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
 8310:     my $savespares;
 8311: 
 8312:     foreach my $lonhost (sort(keys(%servers))) {
 8313:         my $serverhomeID =
 8314:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
 8315:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
 8316:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
 8317:         my %spareschg;
 8318:         foreach my $type (@{$types{'spares'}}) {
 8319:             my @okspares;
 8320:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
 8321:             foreach my $server (@checked) {
 8322:                 if (&Apache::lonnet::hostname($server) ne '') {
 8323:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
 8324:                         unless (grep(/^\Q$server\E$/,@okspares)) {
 8325:                             push(@okspares,$server);
 8326:                         }
 8327:                     }
 8328:                 }
 8329:             }
 8330:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
 8331:             my $newspare;
 8332:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
 8333:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
 8334:                     $newspare = $new;
 8335:                 }
 8336:             }
 8337:             my @spares;
 8338:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
 8339:                 @spares = sort(@okspares,$newspare);
 8340:             } else {
 8341:                 @spares = sort(@okspares);
 8342:             }
 8343:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
 8344:             if (ref($spareid{$lonhost}) eq 'HASH') {
 8345:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
 8346:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
 8347:                     if (@diffs > 0) {
 8348:                         $spareschg{$type} = 1;
 8349:                     }
 8350:                 }
 8351:             }
 8352:         }
 8353:         if (keys(%spareschg) > 0) {
 8354:             $changes{'spares'}{$lonhost} = \%spareschg;
 8355:         }
 8356:     }
 8357: 
 8358:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8359:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
 8360:             if (ref($changes{'spares'}) eq 'HASH') {
 8361:                 if (keys(%{$changes{'spares'}}) > 0) {
 8362:                     $savespares = 1;
 8363:                 }
 8364:             }
 8365:         } else {
 8366:             $savespares = 1;
 8367:         }
 8368:     }
 8369: 
 8370:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
 8371:     if ((keys(%changes) > 0) || ($savespares)) {
 8372:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 8373:                                                  $dom);
 8374:         if ($putresult eq 'ok') {
 8375:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 8376:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
 8377:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
 8378:                 }
 8379:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
 8380:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
 8381:                 }
 8382:             }
 8383:             my $cachetime = 24*60*60;
 8384:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 8385:             if (keys(%changes) > 0) {
 8386:                 my %lt = &usersession_titles();
 8387:                 $resulttext = &mt('Changes made:').'<ul>';
 8388:                 foreach my $prefix (@prefixes) {
 8389:                     if (ref($changes{$prefix}) eq 'HASH') {
 8390:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
 8391:                         if ($prefix eq 'spares') {
 8392:                             if (ref($changes{$prefix}) eq 'HASH') {
 8393:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
 8394:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
 8395:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
 8396:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
 8397:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
 8398:                                         foreach my $type (@{$types{$prefix}}) {
 8399:                                             if ($changes{$prefix}{$lonhost}{$type}) {
 8400:                                                 my $offloadto = &mt('None');
 8401:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
 8402:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
 8403:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
 8404:                                                     }
 8405:                                                 }
 8406:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
 8407:                                             }
 8408:                                         }
 8409:                                     }
 8410:                                     $resulttext .= '</li>';
 8411:                                 }
 8412:                             }
 8413:                         } else {
 8414:                             foreach my $type (@{$types{$prefix}}) {
 8415:                                 if (defined($changes{$prefix}{$type})) {
 8416:                                     my $newvalue;
 8417:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 8418:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
 8419:                                             if ($type eq 'version') {
 8420:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
 8421:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 8422:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
 8423:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
 8424:                                                 }
 8425:                                             }
 8426:                                         }
 8427:                                     }
 8428:                                     if ($newvalue eq '') {
 8429:                                         if ($type eq 'version') {
 8430:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
 8431:                                         } else {
 8432:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
 8433:                                         }
 8434:                                     } else {
 8435:                                         if ($type eq 'version') {
 8436:                                             $newvalue .= ' '.&mt('(or later)'); 
 8437:                                         }
 8438:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
 8439:                                     }
 8440:                                 }
 8441:                             }
 8442:                         }
 8443:                         $resulttext .= '</ul>';
 8444:                     }
 8445:                 }
 8446:                 $resulttext .= '</ul>';
 8447:             } else {
 8448:                 $resulttext = $nochgmsg;
 8449:             }
 8450:         } else {
 8451:             $resulttext = '<span class="LC_error">'.
 8452:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 8453:         }
 8454:     } else {
 8455:         $resulttext = $nochgmsg;
 8456:     }
 8457:     return $resulttext;
 8458: }
 8459: 
 8460: sub modify_loadbalancing {
 8461:     my ($dom,%domconfig) = @_;
 8462:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
 8463:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
 8464:     my ($othertitle,$usertypes,$types) =
 8465:         &Apache::loncommon::sorted_inst_types($dom);
 8466:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 8467:     my @sparestypes = ('primary','default');
 8468:     my %typetitles = &sparestype_titles();
 8469:     my $resulttext;
 8470:     my (%currbalancer,%currtargets,%currrules,%existing);
 8471:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
 8472:         %existing = %{$domconfig{'loadbalancing'}};
 8473:     }
 8474:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
 8475:                               \%currtargets,\%currrules);
 8476:     my ($saveloadbalancing,%defaultshash,%changes);
 8477:     my ($alltypes,$othertypes,$titles) =
 8478:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
 8479:     my %ruletitles = &offloadtype_text();
 8480:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
 8481:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
 8482:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
 8483:         if ($balancer eq '') {
 8484:             next;
 8485:         }
 8486:         if (!exists($servers{$balancer})) { 
 8487:             if (exists($currbalancer{$balancer})) {
 8488:                 push(@{$changes{'delete'}},$balancer);
 8489:             }
 8490:             next;
 8491:         }
 8492:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
 8493:             push(@{$changes{'delete'}},$balancer);
 8494:             next;
 8495:         }
 8496:         if (!exists($currbalancer{$balancer})) {
 8497:             push(@{$changes{'add'}},$balancer);
 8498:         }
 8499:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
 8500:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
 8501:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
 8502:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
 8503:             $saveloadbalancing = 1;
 8504:         }
 8505:         foreach my $sparetype (@sparestypes) {
 8506:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
 8507:             my @offloadto;
 8508:             foreach my $target (@targets) {
 8509:                 if (($servers{$target}) && ($target ne $balancer)) {
 8510:                     if ($sparetype eq 'default') {
 8511:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
 8512:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
 8513:                         }
 8514:                     }
 8515:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
 8516:                         push(@offloadto,$target);
 8517:                     }
 8518:                 }
 8519:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
 8520:             }
 8521:         }
 8522:         if (ref($currtargets{$balancer}) eq 'HASH') {
 8523:             foreach my $sparetype (@sparestypes) {
 8524:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
 8525:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
 8526:                     if (@targetdiffs > 0) {
 8527:                         $changes{'curr'}{$balancer}{'targets'} = 1;
 8528:                     }
 8529:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8530:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8531:                         $changes{'curr'}{$balancer}{'targets'} = 1;
 8532:                     }
 8533:                 }
 8534:             }
 8535:         } else {
 8536:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
 8537:                 foreach my $sparetype (@sparestypes) { 
 8538:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8539:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8540:                             $changes{'curr'}{$balancer}{'targets'} = 1;
 8541:                         }
 8542:                     }
 8543:                 }
 8544:             }  
 8545:         }
 8546:         my $ishomedom;
 8547:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
 8548:             $ishomedom = 1;
 8549:         }
 8550:         if (ref($alltypes) eq 'ARRAY') {
 8551:             foreach my $type (@{$alltypes}) {
 8552:                 my $rule;
 8553:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
 8554:                          (!$ishomedom)) {
 8555:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
 8556:                 }
 8557:                 if ($rule eq 'specific') {
 8558:                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
 8559:                 }
 8560:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
 8561:                 if (ref($currrules{$balancer}) eq 'HASH') {
 8562:                     if ($rule ne $currrules{$balancer}{$type}) {
 8563:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
 8564:                     }
 8565:                 } elsif ($rule ne '') {
 8566:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
 8567:                 }
 8568:             }
 8569:         }
 8570:     }
 8571:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
 8572:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
 8573:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
 8574:             $defaultshash{'loadbalancing'} = {};
 8575:         }
 8576:         my $putresult = &Apache::lonnet::put_dom('configuration',
 8577:                                                  \%defaultshash,$dom);
 8578:  
 8579:         if ($putresult eq 'ok') {
 8580:             if (keys(%changes) > 0) {
 8581:                 if (ref($changes{'delete'}) eq 'ARRAY') {
 8582:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
 8583:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
 8584:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
 8585:                     }
 8586:                 }
 8587:                 if (ref($changes{'add'}) eq 'ARRAY') {
 8588:                     foreach my $balancer (sort(@{$changes{'add'}})) {   
 8589:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
 8590:                     }
 8591:                 }
 8592:                 if (ref($changes{'curr'}) eq 'HASH') {
 8593:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
 8594:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
 8595:                             if ($changes{'curr'}{$balancer}{'targets'}) {
 8596:                                 my %offloadstr;
 8597:                                 foreach my $sparetype (@sparestypes) {
 8598:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8599:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8600:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
 8601:                                         }
 8602:                                     }
 8603:                                 }
 8604:                                 if (keys(%offloadstr) == 0) {
 8605:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
 8606:                                 } else {
 8607:                                     my $showoffload;
 8608:                                     foreach my $sparetype (@sparestypes) {
 8609:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
 8610:                                         if (defined($offloadstr{$sparetype})) {
 8611:                                             $showoffload .= $offloadstr{$sparetype};
 8612:                                         } else {
 8613:                                             $showoffload .= &mt('None');
 8614:                                         }
 8615:                                         $showoffload .= ('&nbsp;'x3);
 8616:                                     }
 8617:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
 8618:                                 }
 8619:                             }
 8620:                         }
 8621:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
 8622:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
 8623:                                 foreach my $type (@{$alltypes}) {
 8624:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
 8625:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
 8626:                                         my $balancetext;
 8627:                                         if ($rule eq '') {
 8628:                                             $balancetext =  $ruletitles{'default'};
 8629:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
 8630:                                             $balancetext =  $ruletitles{$rule};
 8631:                                         } else {
 8632:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
 8633:                                         }
 8634:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';     
 8635:                                     }
 8636:                                 }
 8637:                             }
 8638:                         }
 8639:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
 8640:                     }
 8641:                 }
 8642:                 if ($resulttext ne '') {
 8643:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
 8644:                 } else {
 8645:                     $resulttext = $nochgmsg;
 8646:                 }
 8647:             } else {
 8648:                 $resulttext = $nochgmsg;
 8649:             }
 8650:         } else {
 8651:             $resulttext = '<span class="LC_error">'.
 8652:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 8653:         }
 8654:     } else {
 8655:         $resulttext = $nochgmsg;
 8656:     }
 8657:     return $resulttext;
 8658: }
 8659: 
 8660: sub recurse_check {
 8661:     my ($chkcats,$categories,$depth,$name) = @_;
 8662:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
 8663:         my $chg = 0;
 8664:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
 8665:             my $category = $chkcats->[$depth]{$name}[$j];
 8666:             my $item;
 8667:             if ($category eq '') {
 8668:                 $chg ++;
 8669:             } else {
 8670:                 my $deeper = $depth + 1;
 8671:                 $item = &escape($category).':'.&escape($name).':'.$depth;
 8672:                 if ($chg) {
 8673:                     $categories->{$item} -= $chg;
 8674:                 }
 8675:                 &recurse_check($chkcats,$categories,$deeper,$category);
 8676:                 $deeper --;
 8677:             }
 8678:         }
 8679:     }
 8680:     return;
 8681: }
 8682: 
 8683: sub recurse_cat_deletes {
 8684:     my ($item,$coursecategories,$deletions) = @_;
 8685:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 8686:     my $subdepth = $depth + 1;
 8687:     if (ref($coursecategories) eq 'HASH') {
 8688:         foreach my $subitem (keys(%{$coursecategories})) {
 8689:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
 8690:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
 8691:                 delete($coursecategories->{$subitem});
 8692:                 $deletions->{$subitem} = 1;
 8693:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
 8694:             }
 8695:         }
 8696:     }
 8697:     return;
 8698: }
 8699: 
 8700: sub get_active_dcs {
 8701:     my ($dom) = @_;
 8702:     my $now = time;
 8703:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
 8704:     my %domcoords;
 8705:     my $numdcs = 0;
 8706:     foreach my $server (keys(%dompersonnel)) {
 8707:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 8708:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 8709:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
 8710:         }
 8711:     }
 8712:     return %domcoords;
 8713: }
 8714: 
 8715: sub active_dc_picker {
 8716:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
 8717:     my %domcoords = &get_active_dcs($dom); 
 8718:     my @domcoord = keys(%domcoords);
 8719:     if (keys(%currhash)) {
 8720:         foreach my $dc (keys(%currhash)) {
 8721:             unless (exists($domcoords{$dc})) {
 8722:                 push(@domcoord,$dc);
 8723:             }
 8724:         }
 8725:     }
 8726:     @domcoord = sort(@domcoord);
 8727:     my $numdcs = scalar(@domcoord); 
 8728:     my $rows = 0;
 8729:     my $table;
 8730:     if ($numdcs > 1) {
 8731:         $table = '<table>';
 8732:         for (my $i=0; $i<@domcoord; $i++) {
 8733:             my $rem = $i%($numinrow);
 8734:             if ($rem == 0) {
 8735:                 if ($i > 0) {
 8736:                     $table .= '</tr>';
 8737:                 }
 8738:                 $table .= '<tr>';
 8739:                 $rows ++;
 8740:             }
 8741:             my $check = '';
 8742:             if ($inputtype eq 'radio') {
 8743:                 if (keys(%currhash) == 0) {
 8744:                     if (!$i) {
 8745:                         $check = ' checked="checked"';
 8746:                     }
 8747:                 } elsif (exists($currhash{$domcoord[$i]})) {
 8748:                     $check = ' checked="checked"';
 8749:                 }
 8750:             } else {
 8751:                 if (exists($currhash{$domcoord[$i]})) {
 8752:                     $check = ' checked="checked"';
 8753:                 }
 8754:             }
 8755:             if ($i == @domcoord - 1) {
 8756:                 my $colsleft = $numinrow - $rem;
 8757:                 if ($colsleft > 1) {
 8758:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
 8759:                 } else {
 8760:                     $table .= '<td class="LC_left_item">';
 8761:                 }
 8762:             } else {
 8763:                 $table .= '<td class="LC_left_item">';
 8764:             }
 8765:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
 8766:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
 8767:             $table .= '<span class="LC_nobreak"><label>'.
 8768:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
 8769:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
 8770:             if ($user ne $dcname.':'.$dcdom) {
 8771:                 $table .=  ' ('.$dcname.':'.$dcdom.')'.
 8772:                            '</label></span></td>';
 8773:             }
 8774:         }
 8775:         $table .= '</tr></table>';
 8776:     } elsif ($numdcs == 1) {
 8777:         if ($inputtype eq 'radio') {
 8778:             $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
 8779:         } else {
 8780:             my $check;
 8781:             if (exists($currhash{$domcoord[0]})) {
 8782:                 $check = ' checked="checked"';
 8783:             }
 8784:             $table .= '<input type="checkbox" name="'.$name.'" '.
 8785:                       'value="'.$domcoord[0].'"'.$check.' />';
 8786:             $rows ++;
 8787:         }
 8788:     }
 8789:     return ($numdcs,$table,$rows);
 8790: }
 8791: 
 8792: sub usersession_titles {
 8793:     return &Apache::lonlocal::texthash(
 8794:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
 8795:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
 8796:                spares => 'Servers offloaded to, when busy',
 8797:                version => 'LON-CAPA version requirement',
 8798:                excludedomain => 'Allow all, but exclude specific domains',
 8799:                includedomain => 'Deny all, but include specific domains',
 8800:                primary => 'Primary (checked first)',
 8801:                default => 'Default',
 8802:            );
 8803: }
 8804: 
 8805: sub id_for_thisdom {
 8806:     my (%servers) = @_;
 8807:     my %altids;
 8808:     foreach my $server (keys(%servers)) {
 8809:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
 8810:         if ($serverhome ne $server) {
 8811:             $altids{$serverhome} = $server;
 8812:         }
 8813:     }
 8814:     return %altids;
 8815: }
 8816: 
 8817: sub count_servers {
 8818:     my ($currbalancer,%servers) = @_;
 8819:     my (@spares,$numspares);
 8820:     foreach my $lonhost (sort(keys(%servers))) {
 8821:         next if ($currbalancer eq $lonhost);
 8822:         push(@spares,$lonhost);
 8823:     }
 8824:     if ($currbalancer) {
 8825:         $numspares = scalar(@spares);
 8826:     } else {
 8827:         $numspares = scalar(@spares) - 1;
 8828:     }
 8829:     return ($numspares,@spares);
 8830: }
 8831: 
 8832: sub lonbalance_targets_js {
 8833:     my ($dom,$types,$servers,$settings) = @_;
 8834:     my $select = &mt('Select');
 8835:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
 8836:     if (ref($servers) eq 'HASH') {
 8837:         $alltargets = join("','",sort(keys(%{$servers})));
 8838:         my @homedoms;
 8839:         foreach my $server (sort(keys(%{$servers}))) {
 8840:             if (&Apache::lonnet::host_domain($server) eq $dom) {
 8841:                 push(@homedoms,'1');
 8842:             } else {
 8843:                 push(@homedoms,'0');
 8844:             }
 8845:         }
 8846:         $allishome = join("','",@homedoms);
 8847:     }
 8848:     if (ref($types) eq 'ARRAY') {
 8849:         if (@{$types} > 0) {
 8850:             @alltypes = @{$types};
 8851:         }
 8852:     }
 8853:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
 8854:     $allinsttypes = join("','",@alltypes);
 8855:     my (%currbalancer,%currtargets,%currrules,%existing);
 8856:     if (ref($settings) eq 'HASH') {
 8857:         %existing = %{$settings};
 8858:     }
 8859:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
 8860:                               \%currtargets,\%currrules);
 8861:     my $balancers = join("','",sort(keys(%currbalancer))); 
 8862:     return <<"END";
 8863: 
 8864: <script type="text/javascript">
 8865: // <![CDATA[
 8866: 
 8867: currBalancers = new Array('$balancers');
 8868: 
 8869: function toggleTargets(balnum) {
 8870:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
 8871:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
 8872:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
 8873:     var prevbalancer = prevhostitem.value;
 8874:     var baltotal = document.getElementById('loadbalancing_total').value;
 8875:     prevhostitem.value = balancer;
 8876:     if (prevbalancer != '') {
 8877:         var prevIdx = currBalancers.indexOf(prevbalancer);
 8878:         if (prevIdx != -1) {
 8879:             currBalancers.splice(prevIdx,1);
 8880:         }
 8881:     }
 8882:     if (balancer == '') {
 8883:         hideSpares(balnum);
 8884:     } else {
 8885:         var currIdx = currBalancers.indexOf(balancer);
 8886:         if (currIdx == -1) {
 8887:             currBalancers.push(balancer);
 8888:         }
 8889:         var homedoms = new Array('$allishome');
 8890:         var ishomedom = homedoms[lonhostitem.selectedIndex];
 8891:         showSpares(balancer,ishomedom,balnum);
 8892:     }
 8893:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
 8894:     return;
 8895: }
 8896: 
 8897: function showSpares(balancer,ishomedom,balnum) {
 8898:     var alltargets = new Array('$alltargets');
 8899:     var insttypes = new Array('$allinsttypes');
 8900:     var offloadtypes = new Array('primary','default');
 8901: 
 8902:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
 8903:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
 8904:  
 8905:     for (var i=0; i<offloadtypes.length; i++) {
 8906:         var count = 0;
 8907:         for (var j=0; j<alltargets.length; j++) {
 8908:             if (alltargets[j] != balancer) {
 8909:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
 8910:                 item.value = alltargets[j];
 8911:                 item.style.textAlign='left';
 8912:                 item.style.textFace='normal';
 8913:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
 8914:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
 8915:                     item.disabled = '';
 8916:                 } else {
 8917:                     item.disabled = 'disabled';
 8918:                     item.checked = false;
 8919:                 }
 8920:                 count ++;
 8921:             }
 8922:         }
 8923:     }
 8924:     for (var k=0; k<insttypes.length; k++) {
 8925:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
 8926:             if (ishomedom == 1) {
 8927:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
 8928:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
 8929:             } else {
 8930:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
 8931:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
 8932: 
 8933:             }
 8934:         } else {
 8935:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
 8936:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
 8937:         }
 8938:         if ((insttypes[k] != '_LC_external') && 
 8939:             ((insttypes[k] != '_LC_internetdom') ||
 8940:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
 8941:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
 8942:             item.options.length = 0;
 8943:             item.options[0] = new Option("","",true,true);
 8944:             var idx = 0;  
 8945:             for (var m=0; m<alltargets.length; m++) {
 8946:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
 8947:                     idx ++;
 8948:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
 8949:                     
 8950:                 }
 8951:             }
 8952:         }
 8953:     }
 8954:     return;
 8955: }
 8956: 
 8957: function hideSpares(balnum) {
 8958:     var alltargets = new Array('$alltargets');
 8959:     var insttypes = new Array('$allinsttypes');
 8960:     var offloadtypes = new Array('primary','default');
 8961: 
 8962:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
 8963:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
 8964: 
 8965:     var total = alltargets.length - 1;
 8966:     for (var i=0; i<offloadtypes; i++) {
 8967:         for (var j=0; j<total; j++) {
 8968:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
 8969:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
 8970:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
 8971:         }
 8972:     }
 8973:     for (var k=0; k<insttypes.length; k++) {
 8974:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
 8975:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
 8976:         if (insttypes[k] != '_LC_external') {
 8977:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
 8978:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
 8979:         }
 8980:     }
 8981:     return;
 8982: }
 8983: 
 8984: function checkOffloads(item,balnum,type) {
 8985:     var alltargets = new Array('$alltargets');
 8986:     var offloadtypes = new Array('primary','default');
 8987:     if (item.checked) {
 8988:         var total = alltargets.length - 1;
 8989:         var other;
 8990:         if (type == offloadtypes[0]) {
 8991:             other = offloadtypes[1];
 8992:         } else {
 8993:             other = offloadtypes[0];
 8994:         }
 8995:         for (var i=0; i<total; i++) {
 8996:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
 8997:             if (server == item.value) {
 8998:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
 8999:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
 9000:                 }
 9001:             }
 9002:         }
 9003:     }
 9004:     return;
 9005: }
 9006: 
 9007: function singleServerToggle(balnum,type) {
 9008:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
 9009:     if (offloadtoSelIdx == 0) {
 9010:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
 9011:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
 9012: 
 9013:     } else {
 9014:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
 9015:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
 9016:     }
 9017:     return;
 9018: }
 9019: 
 9020: function balanceruleChange(formname,balnum,type) {
 9021:     if (type == '_LC_external') {
 9022:         return;
 9023:     }
 9024:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
 9025:     for (var i=0; i<typesRules.length; i++) {
 9026:         if (formname.elements[typesRules[i]].checked) {
 9027:             if (formname.elements[typesRules[i]].value != 'specific') {
 9028:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
 9029:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
 9030:             } else {
 9031:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
 9032:             }
 9033:         }
 9034:     }
 9035:     return;
 9036: }
 9037: 
 9038: function balancerDeleteChange(balnum) {
 9039:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
 9040:     var baltotal = document.getElementById('loadbalancing_total').value;
 9041:     var addtarget;
 9042:     var removetarget;
 9043:     var action = 'delete';
 9044:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
 9045:         var lonhost = hostitem.value;
 9046:         var currIdx = currBalancers.indexOf(lonhost);
 9047:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
 9048:             if (currIdx != -1) {
 9049:                 currBalancers.splice(currIdx,1);
 9050:             }
 9051:             addtarget = lonhost;
 9052:         } else {
 9053:             if (currIdx == -1) {
 9054:                 currBalancers.push(lonhost);
 9055:             }
 9056:             removetarget = lonhost;
 9057:             action = 'undelete';
 9058:         }
 9059:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
 9060:     }
 9061:     return;
 9062: }
 9063: 
 9064: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
 9065:     if (baltotal > 1) {
 9066:         var offloadtypes = new Array('primary','default');
 9067:         var alltargets = new Array('$alltargets');
 9068:         var insttypes = new Array('$allinsttypes');
 9069:         for (var i=0; i<baltotal; i++) {
 9070:             if (i != balnum) {
 9071:                 for (var j=0; j<offloadtypes.length; j++) {
 9072:                     var total = alltargets.length - 1;
 9073:                     for (var k=0; k<total; k++) {
 9074:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
 9075:                         var server = serveritem.value;
 9076:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
 9077:                             if (server == addtarget) {
 9078:                                 serveritem.disabled = '';
 9079:                             }
 9080:                         }
 9081:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
 9082:                             if (server == removetarget) {
 9083:                                 serveritem.disabled = 'disabled';
 9084:                                 serveritem.checked = false;
 9085:                             }
 9086:                         }
 9087:                     }
 9088:                 }
 9089:                 for (var j=0; j<insttypes.length; j++) {
 9090:                     if (insttypes[j] != '_LC_external') {
 9091:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
 9092:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
 9093:                             var currSel = singleserver.selectedIndex;
 9094:                             var currVal = singleserver.options[currSel].value;
 9095:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
 9096:                                 var numoptions = singleserver.options.length;
 9097:                                 var needsnew = 1;
 9098:                                 for (var k=0; k<numoptions; k++) {
 9099:                                     if (singleserver.options[k] == addtarget) {
 9100:                                         needsnew = 0;
 9101:                                         break;
 9102:                                     }
 9103:                                 }
 9104:                                 if (needsnew == 1) {
 9105:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
 9106:                                 }
 9107:                             }
 9108:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
 9109:                                 singleserver.options.length = 0;
 9110:                                 if ((currVal) && (currVal != removetarget)) {
 9111:                                     singleserver.options[0] = new Option("","",false,false);
 9112:                                 } else {
 9113:                                     singleserver.options[0] = new Option("","",true,true);
 9114:                                 }
 9115:                                 var idx = 0;
 9116:                                 for (var m=0; m<alltargets.length; m++) {
 9117:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
 9118:                                         idx ++;
 9119:                                         if (currVal == alltargets[m]) {
 9120:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
 9121:                                         } else {
 9122:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
 9123:                                         }
 9124:                                     }
 9125:                                 }
 9126:                             }
 9127:                         }
 9128:                     }
 9129:                 }
 9130:             }
 9131:         }
 9132:     }
 9133:     return;
 9134: }
 9135: 
 9136: // ]]>
 9137: </script>
 9138: 
 9139: END
 9140: }
 9141: 
 9142: sub new_spares_js {
 9143:     my @sparestypes = ('primary','default');
 9144:     my $types = join("','",@sparestypes);
 9145:     my $select = &mt('Select');
 9146:     return <<"END";
 9147: 
 9148: <script type="text/javascript">
 9149: // <![CDATA[
 9150: 
 9151: function updateNewSpares(formname,lonhost) {
 9152:     var types = new Array('$types');
 9153:     var include = new Array();
 9154:     var exclude = new Array();
 9155:     for (var i=0; i<types.length; i++) {
 9156:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
 9157:         for (var j=0; j<spareboxes.length; j++) {
 9158:             if (formname.elements[spareboxes[j]].checked) {
 9159:                 exclude.push(formname.elements[spareboxes[j]].value);
 9160:             } else {
 9161:                 include.push(formname.elements[spareboxes[j]].value);
 9162:             }
 9163:         }
 9164:     }
 9165:     for (var i=0; i<types.length; i++) {
 9166:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
 9167:         var selIdx = newSpare.selectedIndex;
 9168:         var currnew = newSpare.options[selIdx].value;
 9169:         var okSpares = new Array();
 9170:         for (var j=0; j<newSpare.options.length; j++) {
 9171:             var possible = newSpare.options[j].value;
 9172:             if (possible != '') {
 9173:                 if (exclude.indexOf(possible) == -1) {
 9174:                     okSpares.push(possible);
 9175:                 } else {
 9176:                     if (currnew == possible) {
 9177:                         selIdx = 0;
 9178:                     }
 9179:                 }
 9180:             }
 9181:         }
 9182:         for (var k=0; k<include.length; k++) {
 9183:             if (okSpares.indexOf(include[k]) == -1) {
 9184:                 okSpares.push(include[k]);
 9185:             }
 9186:         }
 9187:         okSpares.sort();
 9188:         newSpare.options.length = 0;
 9189:         if (selIdx == 0) {
 9190:             newSpare.options[0] = new Option("$select","",true,true);
 9191:         } else {
 9192:             newSpare.options[0] = new Option("$select","",false,false);
 9193:         }
 9194:         for (var m=0; m<okSpares.length; m++) {
 9195:             var idx = m+1;
 9196:             var selThis = 0;
 9197:             if (selIdx != 0) {
 9198:                 if (okSpares[m] == currnew) {
 9199:                     selThis = 1;
 9200:                 }
 9201:             }
 9202:             if (selThis == 1) {
 9203:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
 9204:             } else {
 9205:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
 9206:             }
 9207:         }
 9208:     }
 9209:     return;
 9210: }
 9211: 
 9212: function checkNewSpares(lonhost,type) {
 9213:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
 9214:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
 9215:     if (chosen != '') { 
 9216:         var othertype;
 9217:         var othernewSpare;
 9218:         if (type == 'primary') {
 9219:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
 9220:         }
 9221:         if (type == 'default') {
 9222:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
 9223:         }
 9224:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
 9225:             othernewSpare.selectedIndex = 0;
 9226:         }
 9227:     }
 9228:     return;
 9229: }
 9230: 
 9231: // ]]>
 9232: </script>
 9233: 
 9234: END
 9235: 
 9236: }
 9237: 
 9238: sub common_domprefs_js {
 9239:     return <<"END";
 9240: 
 9241: <script type="text/javascript">
 9242: // <![CDATA[
 9243: 
 9244: function getIndicesByName(formname,item) {
 9245:     var group = new Array();
 9246:     for (var i=0;i<formname.elements.length;i++) {
 9247:         if (formname.elements[i].name == item) {
 9248:             group.push(formname.elements[i].id);
 9249:         }
 9250:     }
 9251:     return group;
 9252: }
 9253: 
 9254: // ]]>
 9255: </script>
 9256: 
 9257: END
 9258: 
 9259: }
 9260: 
 9261: sub recaptcha_js {
 9262:     my %lt = &captcha_phrases();
 9263:     return <<"END";
 9264: 
 9265: <script type="text/javascript">
 9266: // <![CDATA[
 9267: 
 9268: function updateCaptcha(caller,context) {
 9269:     var privitem;
 9270:     var pubitem;
 9271:     var privtext;
 9272:     var pubtext;
 9273:     if (document.getElementById(context+'_recaptchapub')) {
 9274:         pubitem = document.getElementById(context+'_recaptchapub');
 9275:     } else {
 9276:         return;
 9277:     }
 9278:     if (document.getElementById(context+'_recaptchapriv')) {
 9279:         privitem = document.getElementById(context+'_recaptchapriv');
 9280:     } else {
 9281:         return;
 9282:     }
 9283:     if (document.getElementById(context+'_recaptchapubtxt')) {
 9284:         pubtext = document.getElementById(context+'_recaptchapubtxt');
 9285:     } else {
 9286:         return;
 9287:     }
 9288:     if (document.getElementById(context+'_recaptchaprivtxt')) {
 9289:         privtext = document.getElementById(context+'_recaptchaprivtxt');
 9290:     } else {
 9291:         return;
 9292:     }
 9293:     if (caller.checked) {
 9294:         if (caller.value == 'recaptcha') {
 9295:             pubitem.type = 'text';
 9296:             privitem.type = 'text';
 9297:             pubitem.size = '40';
 9298:             privitem.size = '40';
 9299:             pubtext.innerHTML = "$lt{'pub'}";
 9300:             privtext.innerHTML = "$lt{'priv'}";
 9301:         } else {
 9302:             pubitem.type = 'hidden';
 9303:             privitem.type = 'hidden';
 9304:             pubtext.innerHTML = '';
 9305:             privtext.innerHTML = '';
 9306:         }
 9307:     }
 9308:     return;
 9309: }
 9310: 
 9311: // ]]>
 9312: </script>
 9313: 
 9314: END
 9315: 
 9316: }
 9317: 
 9318: sub credits_js {
 9319:     return <<"END";
 9320: 
 9321: <script type="text/javascript">
 9322: // <![CDATA[
 9323: 
 9324: function toggleCredits(domForm) {
 9325:     if (document.getElementById('credits')) {
 9326:         creditsitem = document.getElementById('credits');
 9327:         var creditsLength = domForm.coursecredits.length;
 9328:         if (creditsLength) {
 9329:             var currval;
 9330:             for (var i=0; i<creditsLength; i++) {
 9331:                 if (domForm.coursecredits[i].checked) {
 9332:                    currval = domForm.coursecredits[i].value;
 9333:                 }
 9334:             }
 9335:             if (currval == 1) {
 9336:                 creditsitem.style.display = 'block';
 9337:             } else {
 9338:                 creditsitem.style.display = 'none';
 9339:             }
 9340:         }
 9341:     }
 9342:     return;
 9343: }
 9344: 
 9345: // ]]>
 9346: </script>
 9347: 
 9348: END
 9349: 
 9350: }
 9351: 
 9352: sub captcha_phrases {
 9353:     return &Apache::lonlocal::texthash (
 9354:                  priv => 'Private key',
 9355:                  pub  => 'Public key',
 9356:                  original  => 'original (CAPTCHA)',
 9357:                  recaptcha => 'successor (ReCAPTCHA)',
 9358:                  notused   => 'unused',
 9359:     );
 9360: }
 9361: 
 9362: 1;

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