File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.201: download - view: text, annotated - select for diffs
Wed Aug 7 14:41:39 2013 UTC (10 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Colorchooser jquery plugin used for color selection for Text color and Box
  color in Log-in header.
- Consistent capitalization for row items (Font Menu -> Font menu).

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.201 2013/08/07 14:41:39 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);
  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: 
 1435:         if ($designs->{'links'}{$item}) {
 1436:             $datatable.='&nbsp;';
 1437:         }
 1438:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
 1439:                       '" /></td>';
 1440:     }
 1441:     $$rowtotal += $itemcount;
 1442:     return $datatable;
 1443: }
 1444: 
 1445: sub logo_display_options {
 1446:     my ($img,$defaults,$designs) = @_;
 1447:     my $checkedon;
 1448:     if (ref($defaults) eq 'HASH') {
 1449:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
 1450:             if ($defaults->{'showlogo'}{$img}) {
 1451:                 $checkedon = 'checked="checked" ';     
 1452:             }
 1453:         } 
 1454:     }
 1455:     if (ref($designs) eq 'HASH') {
 1456:         if (ref($designs->{'showlogo'}) eq 'HASH') {
 1457:             if (defined($designs->{'showlogo'}{$img})) {
 1458:                 if ($designs->{'showlogo'}{$img} == 0) {
 1459:                     $checkedon = '';
 1460:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
 1461:                     $checkedon = 'checked="checked" ';
 1462:                 }
 1463:             }
 1464:         }
 1465:     }
 1466:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
 1467:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
 1468:            &mt('show').'</label>'."\n";
 1469: }
 1470: 
 1471: sub login_header_options  {
 1472:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
 1473:     my $output = '';
 1474:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1475:         $output .= &mt('Text default(s):').'<br />';
 1476:         if (!$is_custom->{'textcol'}) {
 1477:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1478:                        '&nbsp;&nbsp;&nbsp;';
 1479:         }
 1480:         if (!$is_custom->{'bgcol'}) {
 1481:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1482:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1483:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1484:         }
 1485:         $output .= '<br />';
 1486:     }
 1487:     $output .='<br />';
 1488:     return $output;
 1489: }
 1490: 
 1491: sub login_text_colors {
 1492:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
 1493:     my $color_menu = '<table border="0"><tr>';
 1494:     foreach my $item (@{$logintext}) {
 1495:         $color_menu .= '<td align="center">'.$choices->{$item};
 1496:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
 1497:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1498:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1499: 
 1500:     }
 1501:     $color_menu .= '</tr></table><br />';
 1502:     return $color_menu;
 1503: }
 1504: 
 1505: sub image_changes {
 1506:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1507:     my $output;
 1508:     if ($img eq 'login') {
 1509:             # suppress image for Log-in header
 1510:     } elsif (!$is_custom) {
 1511:         if ($img ne 'domlogo') {
 1512:             $output .= &mt('Default image:').'<br />';
 1513:         } else {
 1514:             $output .= &mt('Default in use:').'<br />';
 1515:         }
 1516:     }
 1517:     if ($img eq 'login') { # suppress image for Log-in header
 1518:         $output .= '<td>'.$logincolors;
 1519:     } else {
 1520:         if ($img_import) {
 1521:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1522:         }
 1523:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1524:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1525:         if ($is_custom) {
 1526:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1527:                        '<input type="checkbox" name="'.
 1528:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1529:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1530:         } else {
 1531:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
 1532:         }
 1533:     }
 1534:     return $output;
 1535: }
 1536: 
 1537: sub print_quotas {
 1538:     my ($dom,$settings,$rowtotal,$action) = @_;
 1539:     my $context;
 1540:     if ($action eq 'quotas') {
 1541:         $context = 'tools';
 1542:     } else {
 1543:         $context = $action;
 1544:     }
 1545:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
 1546:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1547:     my $typecount = 0;
 1548:     my ($css_class,%titles);
 1549:     if ($context eq 'requestcourses') {
 1550:         @usertools = ('official','unofficial','community');
 1551:         @options =('norequest','approval','validate','autolimit');
 1552:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 1553:         %titles = &courserequest_titles();
 1554:     } elsif ($context eq 'requestauthor') {
 1555:         @usertools = ('author');
 1556:         @options = ('norequest','approval','automatic');
 1557:         %titles = &authorrequest_titles(); 
 1558:     } else {
 1559:         @usertools = ('aboutme','blog','webdav','portfolio');
 1560:         %titles = &tool_titles();
 1561:     }
 1562:     if (ref($types) eq 'ARRAY') {
 1563:         foreach my $type (@{$types}) {
 1564:             my ($currdefquota,$currauthorquota);
 1565:             unless (($context eq 'requestcourses') ||
 1566:                     ($context eq 'requestauthor')) {
 1567:                 if (ref($settings) eq 'HASH') {
 1568:                     if (ref($settings->{defaultquota}) eq 'HASH') {
 1569:                         $currdefquota = $settings->{defaultquota}->{$type};
 1570:                     } else {
 1571:                         $currdefquota = $settings->{$type};
 1572:                     }
 1573:                     if (ref($settings->{authorquota}) eq 'HASH') {
 1574:                         $currauthorquota = $settings->{authorquota}->{$type};
 1575:                     }
 1576:                 }
 1577:             }
 1578:             if (defined($usertypes->{$type})) {
 1579:                 $typecount ++;
 1580:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1581:                 $datatable .= '<tr'.$css_class.'>'.
 1582:                               '<td>'.$usertypes->{$type}.'</td>'.
 1583:                               '<td class="LC_left_item">';
 1584:                 if ($context eq 'requestcourses') {
 1585:                     $datatable .= '<table><tr>';
 1586:                 }
 1587:                 my %cell;  
 1588:                 foreach my $item (@usertools) {
 1589:                     if ($context eq 'requestcourses') {
 1590:                         my ($curroption,$currlimit);
 1591:                         if (ref($settings) eq 'HASH') {
 1592:                             if (ref($settings->{$item}) eq 'HASH') {
 1593:                                 $curroption = $settings->{$item}->{$type};
 1594:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
 1595:                                     $currlimit = $1; 
 1596:                                 }
 1597:                             }
 1598:                         }
 1599:                         if (!$curroption) {
 1600:                             $curroption = 'norequest';
 1601:                         }
 1602:                         $datatable .= '<th>'.$titles{$item}.'</th>';
 1603:                         foreach my $option (@options) {
 1604:                             my $val = $option;
 1605:                             if ($option eq 'norequest') {
 1606:                                 $val = 0;  
 1607:                             }
 1608:                             if ($option eq 'validate') {
 1609:                                 my $canvalidate = 0;
 1610:                                 if (ref($validations{$item}) eq 'HASH') { 
 1611:                                     if ($validations{$item}{$type}) {
 1612:                                         $canvalidate = 1;
 1613:                                     }
 1614:                                 }
 1615:                                 next if (!$canvalidate);
 1616:                             }
 1617:                             my $checked = '';
 1618:                             if ($option eq $curroption) {
 1619:                                 $checked = ' checked="checked"';
 1620:                             } elsif ($option eq 'autolimit') {
 1621:                                 if ($curroption =~ /^autolimit/) {
 1622:                                     $checked = ' checked="checked"';
 1623:                                 }                       
 1624:                             } 
 1625:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
 1626:                                   '<input type="radio" name="crsreq_'.$item.
 1627:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
 1628:                                   $titles{$option}.'</label>';
 1629:                             if ($option eq 'autolimit') {
 1630:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1631:                                                 $item.'_limit_'.$type.'" size="1" '.
 1632:                                                 'value="'.$currlimit.'" />';
 1633:                             }
 1634:                             $cell{$item} .= '</span> ';
 1635:                             if ($option eq 'autolimit') {
 1636:                                 $cell{$item} .= $titles{'unlimited'};
 1637:                             }
 1638:                         }
 1639:                     } elsif ($context eq 'requestauthor') {
 1640:                         my $curroption;
 1641:                         if (ref($settings) eq 'HASH') {
 1642:                             $curroption = $settings->{$type};
 1643:                         }
 1644:                         if (!$curroption) {
 1645:                             $curroption = 'norequest';
 1646:                         }
 1647:                         foreach my $option (@options) {
 1648:                             my $val = $option;
 1649:                             if ($option eq 'norequest') {
 1650:                                 $val = 0;
 1651:                             }
 1652:                             my $checked = '';
 1653:                             if ($option eq $curroption) {
 1654:                                 $checked = ' checked="checked"';
 1655:                             }
 1656:                             $datatable .= '<span class="LC_nobreak"><label>'.
 1657:                                   '<input type="radio" name="authorreq_'.$type.
 1658:                                   '" value="'.$val.'"'.$checked.' />'.
 1659:                                   $titles{$option}.'</label></span>&nbsp; ';
 1660:                         }
 1661:                     } else {
 1662:                         my $checked = 'checked="checked" ';
 1663:                         if (ref($settings) eq 'HASH') {
 1664:                             if (ref($settings->{$item}) eq 'HASH') {
 1665:                                 if ($settings->{$item}->{$type} == 0) {
 1666:                                     $checked = '';
 1667:                                 } elsif ($settings->{$item}->{$type} == 1) {
 1668:                                     $checked =  'checked="checked" ';
 1669:                                 }
 1670:                             }
 1671:                         }
 1672:                         $datatable .= '<span class="LC_nobreak"><label>'.
 1673:                                       '<input type="checkbox" name="'.$context.'_'.$item.
 1674:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1675:                                       '</label></span>&nbsp; ';
 1676:                     }
 1677:                 }
 1678:                 if ($context eq 'requestcourses') {
 1679:                     $datatable .= '</tr><tr>';
 1680:                     foreach my $item (@usertools) {
 1681:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
 1682:                     }
 1683:                     $datatable .= '</tr></table>';
 1684:                 }
 1685:                 $datatable .= '</td>';
 1686:                 unless (($context eq 'requestcourses') ||
 1687:                         ($context eq 'requestauthor')) {
 1688:                     $datatable .= 
 1689:                               '<td class="LC_right_item">'.
 1690:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1691:                               '<input type="text" name="quota_'.$type.
 1692:                               '" value="'.$currdefquota.
 1693:                               '" size="5" /></span>'.('&nbsp;' x 2).
 1694:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1695:                               '<input type="text" name="authorquota_'.$type.
 1696:                               '" value="'.$currauthorquota.
 1697:                               '" size="5" /></span></td>';
 1698:                 }
 1699:                 $datatable .= '</tr>';
 1700:             }
 1701:         }
 1702:     }
 1703:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1704:         $defaultquota = '20';
 1705:         $authorquota = '500';
 1706:         if (ref($settings) eq 'HASH') {
 1707:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1708:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
 1709:             } elsif (defined($settings->{'default'})) {
 1710:                 $defaultquota = $settings->{'default'};
 1711:             }
 1712:             if (ref($settings->{'authorquota'}) eq 'HASH') {
 1713:                 $authorquota = $settings->{'authorquota'}->{'default'};
 1714:             }
 1715:         }
 1716:     }
 1717:     $typecount ++;
 1718:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1719:     $datatable .= '<tr'.$css_class.'>'.
 1720:                   '<td>'.$othertitle.'</td>'.
 1721:                   '<td class="LC_left_item">';
 1722:     if ($context eq 'requestcourses') {
 1723:         $datatable .= '<table><tr>';
 1724:     }
 1725:     my %defcell;
 1726:     foreach my $item (@usertools) {
 1727:         if ($context eq 'requestcourses') {
 1728:             my ($curroption,$currlimit);
 1729:             if (ref($settings) eq 'HASH') {
 1730:                 if (ref($settings->{$item}) eq 'HASH') {
 1731:                     $curroption = $settings->{$item}->{'default'};
 1732:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1733:                         $currlimit = $1;
 1734:                     }
 1735:                 }
 1736:             }
 1737:             if (!$curroption) {
 1738:                 $curroption = 'norequest';
 1739:             }
 1740:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1741:             foreach my $option (@options) {
 1742:                 my $val = $option;
 1743:                 if ($option eq 'norequest') {
 1744:                     $val = 0;
 1745:                 }
 1746:                 if ($option eq 'validate') {
 1747:                     my $canvalidate = 0;
 1748:                     if (ref($validations{$item}) eq 'HASH') {
 1749:                         if ($validations{$item}{'default'}) {
 1750:                             $canvalidate = 1;
 1751:                         }
 1752:                     }
 1753:                     next if (!$canvalidate);
 1754:                 }
 1755:                 my $checked = '';
 1756:                 if ($option eq $curroption) {
 1757:                     $checked = ' checked="checked"';
 1758:                 } elsif ($option eq 'autolimit') {
 1759:                     if ($curroption =~ /^autolimit/) {
 1760:                         $checked = ' checked="checked"';
 1761:                     }
 1762:                 }
 1763:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
 1764:                                   '<input type="radio" name="crsreq_'.$item.
 1765:                                   '_default" value="'.$val.'"'.$checked.' />'.
 1766:                                   $titles{$option}.'</label>';
 1767:                 if ($option eq 'autolimit') {
 1768:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1769:                                        $item.'_limit_default" size="1" '.
 1770:                                        'value="'.$currlimit.'" />';
 1771:                 }
 1772:                 $defcell{$item} .= '</span> ';
 1773:                 if ($option eq 'autolimit') {
 1774:                     $defcell{$item} .= $titles{'unlimited'};
 1775:                 }
 1776:             }
 1777:         } elsif ($context eq 'requestauthor') {
 1778:             my $curroption;
 1779:             if (ref($settings) eq 'HASH') {
 1780:                 $curroption = $settings->{'default'};
 1781:             }
 1782:             if (!$curroption) {
 1783:                 $curroption = 'norequest';
 1784:             }
 1785:             foreach my $option (@options) {
 1786:                 my $val = $option;
 1787:                 if ($option eq 'norequest') {
 1788:                     $val = 0;
 1789:                 }
 1790:                 my $checked = '';
 1791:                 if ($option eq $curroption) {
 1792:                     $checked = ' checked="checked"';
 1793:                 }
 1794:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1795:                               '<input type="radio" name="authorreq_default"'.
 1796:                               ' value="'.$val.'"'.$checked.' />'.
 1797:                               $titles{$option}.'</label></span>&nbsp; ';
 1798:             }
 1799:         } else {
 1800:             my $checked = 'checked="checked" ';
 1801:             if (ref($settings) eq 'HASH') {
 1802:                 if (ref($settings->{$item}) eq 'HASH') {
 1803:                     if ($settings->{$item}->{'default'} == 0) {
 1804:                         $checked = '';
 1805:                     } elsif ($settings->{$item}->{'default'} == 1) {
 1806:                         $checked = 'checked="checked" ';
 1807:                     }
 1808:                 }
 1809:             }
 1810:             $datatable .= '<span class="LC_nobreak"><label>'.
 1811:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1812:                           '" value="default" '.$checked.'/>'.$titles{$item}.
 1813:                           '</label></span>&nbsp; ';
 1814:         }
 1815:     }
 1816:     if ($context eq 'requestcourses') {
 1817:         $datatable .= '</tr><tr>';
 1818:         foreach my $item (@usertools) {
 1819:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
 1820:         }
 1821:         $datatable .= '</tr></table>';
 1822:     }
 1823:     $datatable .= '</td>';
 1824:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1825:         $datatable .= '<td class="LC_right_item">'.
 1826:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1827:                       '<input type="text" name="defaultquota" value="'.
 1828:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
 1829:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1830:                       '<input type="text" name="authorquota" value="'.
 1831:                       $authorquota.'" size="5" /></span></td>';
 1832:     }
 1833:     $datatable .= '</tr>';
 1834:     $typecount ++;
 1835:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1836:     $datatable .= '<tr'.$css_class.'>'.
 1837:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
 1838:     if ($context eq 'requestcourses') {
 1839:         $datatable .= &mt('(overrides affiliation, if set)').
 1840:                       '</td>'.
 1841:                       '<td class="LC_left_item">'.
 1842:                       '<table><tr>';
 1843:     } else {
 1844:         $datatable .= &mt('(overrides affiliation, if checked)').
 1845:                       '</td>'.
 1846:                       '<td class="LC_left_item" colspan="2">'.
 1847:                       '<br />';
 1848:     }
 1849:     my %advcell;
 1850:     foreach my $item (@usertools) {
 1851:         if ($context eq 'requestcourses') {
 1852:             my ($curroption,$currlimit);
 1853:             if (ref($settings) eq 'HASH') {
 1854:                 if (ref($settings->{$item}) eq 'HASH') {
 1855:                     $curroption = $settings->{$item}->{'_LC_adv'};
 1856:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1857:                         $currlimit = $1;
 1858:                     }
 1859:                 }
 1860:             }
 1861:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1862:             my $checked = '';
 1863:             if ($curroption eq '') {
 1864:                 $checked = ' checked="checked"';
 1865:             }
 1866:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1867:                                '<input type="radio" name="crsreq_'.$item.
 1868:                                '__LC_adv" value=""'.$checked.' />'.
 1869:                                &mt('No override set').'</label></span>&nbsp; ';
 1870:             foreach my $option (@options) {
 1871:                 my $val = $option;
 1872:                 if ($option eq 'norequest') {
 1873:                     $val = 0;
 1874:                 }
 1875:                 if ($option eq 'validate') {
 1876:                     my $canvalidate = 0;
 1877:                     if (ref($validations{$item}) eq 'HASH') {
 1878:                         if ($validations{$item}{'_LC_adv'}) {
 1879:                             $canvalidate = 1;
 1880:                         }
 1881:                     }
 1882:                     next if (!$canvalidate);
 1883:                 }
 1884:                 my $checked = '';
 1885:                 if ($val eq $curroption) {
 1886:                     $checked = ' checked="checked"';
 1887:                 } elsif ($option eq 'autolimit') {
 1888:                     if ($curroption =~ /^autolimit/) {
 1889:                         $checked = ' checked="checked"';
 1890:                     }
 1891:                 }
 1892:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1893:                                   '<input type="radio" name="crsreq_'.$item.
 1894:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
 1895:                                   $titles{$option}.'</label>';
 1896:                 if ($option eq 'autolimit') {
 1897:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1898:                                        $item.'_limit__LC_adv" size="1" '.
 1899:                                        'value="'.$currlimit.'" />';
 1900:                 }
 1901:                 $advcell{$item} .= '</span> ';
 1902:                 if ($option eq 'autolimit') {
 1903:                     $advcell{$item} .= $titles{'unlimited'};
 1904:                 }
 1905:             }
 1906:         } elsif ($context eq 'requestauthor') {
 1907:             my $curroption;
 1908:             if (ref($settings) eq 'HASH') {
 1909:                 $curroption = $settings->{'_LC_adv'};
 1910:             }
 1911:             my $checked = '';
 1912:             if ($curroption eq '') {
 1913:                 $checked = ' checked="checked"';
 1914:             }
 1915:             $datatable .= '<span class="LC_nobreak"><label>'.
 1916:                           '<input type="radio" name="authorreq__LC_adv"'.
 1917:                           ' value=""'.$checked.' />'.
 1918:                           &mt('No override set').'</label></span>&nbsp; ';
 1919:             foreach my $option (@options) {
 1920:                 my $val = $option;
 1921:                 if ($option eq 'norequest') {
 1922:                     $val = 0;
 1923:                 }
 1924:                 my $checked = '';
 1925:                 if ($val eq $curroption) {
 1926:                     $checked = ' checked="checked"';
 1927:                 }
 1928:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1929:                               '<input type="radio" name="authorreq__LC_adv"'.
 1930:                               ' value="'.$val.'"'.$checked.' />'.
 1931:                               $titles{$option}.'</label></span>&nbsp; ';
 1932:             }
 1933:         } else {
 1934:             my $checked = 'checked="checked" ';
 1935:             if (ref($settings) eq 'HASH') {
 1936:                 if (ref($settings->{$item}) eq 'HASH') {
 1937:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
 1938:                         $checked = '';
 1939:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
 1940:                         $checked = 'checked="checked" ';
 1941:                     }
 1942:                 }
 1943:             }
 1944:             $datatable .= '<span class="LC_nobreak"><label>'.
 1945:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1946:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 1947:                           '</label></span>&nbsp; ';
 1948:         }
 1949:     }
 1950:     if ($context eq 'requestcourses') {
 1951:         $datatable .= '</tr><tr>';
 1952:         foreach my $item (@usertools) {
 1953:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
 1954:         }
 1955:         $datatable .= '</tr></table>';
 1956:     }
 1957:     $datatable .= '</td></tr>';
 1958:     $$rowtotal += $typecount;
 1959:     return $datatable;
 1960: }
 1961: 
 1962: sub print_requestmail {
 1963:     my ($dom,$action,$settings,$rowtotal) = @_;
 1964:     my ($now,$datatable,%currapp,$rows);
 1965:     $now = time;
 1966:     if (ref($settings) eq 'HASH') {
 1967:         if (ref($settings->{'notify'}) eq 'HASH') {
 1968:             if ($settings->{'notify'}{'approval'} ne '') {
 1969:                map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
 1970:             }
 1971:         }
 1972:     }
 1973:     my $numinrow = 2;
 1974:     my $css_class = 'class="LC_odd_row"';
 1975:     my $text;
 1976:     if ($action eq 'requestcourses') {
 1977:         $text = &mt('Receive notification of course requests requiring approval');
 1978:     } else {
 1979:         $text = &mt('Receive notification of authoring space requests requiring approval')
 1980:     }
 1981:     $datatable = '<tr '.$css_class.'>'.
 1982:                  ' <td>'.$text.'</td>'.
 1983:                  ' <td class="LC_left_item">';
 1984:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
 1985:                                                  'reqapprovalnotify',%currapp);
 1986:     if ($numdc > 0) {
 1987:         $datatable .= $table;
 1988:     } else {
 1989:         $datatable .= &mt('There are no active Domain Coordinators');
 1990:     }
 1991:     $datatable .='</td></tr>';
 1992:     $$rowtotal += $rows;
 1993:     return $datatable;
 1994: }
 1995: 
 1996: sub print_autoenroll {
 1997:     my ($dom,$settings,$rowtotal) = @_;
 1998:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1999:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
 2000:     if (ref($settings) eq 'HASH') {
 2001:         if (exists($settings->{'run'})) {
 2002:             if ($settings->{'run'} eq '0') {
 2003:                 $runoff = ' checked="checked" ';
 2004:                 $runon = ' ';
 2005:             } else {
 2006:                 $runon = ' checked="checked" ';
 2007:                 $runoff = ' ';
 2008:             }
 2009:         } else {
 2010:             if ($autorun) {
 2011:                 $runon = ' checked="checked" ';
 2012:                 $runoff = ' ';
 2013:             } else {
 2014:                 $runoff = ' checked="checked" ';
 2015:                 $runon = ' ';
 2016:             }
 2017:         }
 2018:         if (exists($settings->{'co-owners'})) {
 2019:             if ($settings->{'co-owners'} eq '0') {
 2020:                 $coownersoff = ' checked="checked" ';
 2021:                 $coownerson = ' ';
 2022:             } else {
 2023:                 $coownerson = ' checked="checked" ';
 2024:                 $coownersoff = ' ';
 2025:             }
 2026:         } else {
 2027:             $coownersoff = ' checked="checked" ';
 2028:             $coownerson = ' ';
 2029:         }
 2030:         if (exists($settings->{'sender_domain'})) {
 2031:             $defdom = $settings->{'sender_domain'};
 2032:         }
 2033:     } else {
 2034:         if ($autorun) {
 2035:             $runon = ' checked="checked" ';
 2036:             $runoff = ' ';
 2037:         } else {
 2038:             $runoff = ' checked="checked" ';
 2039:             $runon = ' ';
 2040:         }
 2041:     }
 2042:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 2043:     my $notif_sender;
 2044:     if (ref($settings) eq 'HASH') {
 2045:         $notif_sender = $settings->{'sender_uname'};
 2046:     }
 2047:     my $datatable='<tr class="LC_odd_row">'.
 2048:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 2049:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2050:                   '<input type="radio" name="autoenroll_run"'.
 2051:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2052:                   '<label><input type="radio" name="autoenroll_run"'.
 2053:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2054:                   '</tr><tr>'.
 2055:                   '<td>'.&mt('Notification messages - sender').
 2056:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 2057:                   &mt('username').':&nbsp;'.
 2058:                   '<input type="text" name="sender_uname" value="'.
 2059:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 2060:                   ':&nbsp;'.$domform.'</span></td></tr>'.
 2061:                   '<tr class="LC_odd_row">'.
 2062:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
 2063:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2064:                   '<input type="radio" name="autoassign_coowners"'.
 2065:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2066:                   '<label><input type="radio" name="autoassign_coowners"'.
 2067:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2068:                   '</tr>';
 2069:     $$rowtotal += 3;
 2070:     return $datatable;
 2071: }
 2072: 
 2073: sub print_autoupdate {
 2074:     my ($position,$dom,$settings,$rowtotal) = @_;
 2075:     my $datatable;
 2076:     if ($position eq 'top') {
 2077:         my $updateon = ' ';
 2078:         my $updateoff = ' checked="checked" ';
 2079:         my $classlistson = ' ';
 2080:         my $classlistsoff = ' checked="checked" ';
 2081:         if (ref($settings) eq 'HASH') {
 2082:             if ($settings->{'run'} eq '1') {
 2083:                 $updateon = $updateoff;
 2084:                 $updateoff = ' ';
 2085:             }
 2086:             if ($settings->{'classlists'} eq '1') {
 2087:                 $classlistson = $classlistsoff;
 2088:                 $classlistsoff = ' ';
 2089:             }
 2090:         }
 2091:         my %title = (
 2092:                    run => 'Auto-update active?',
 2093:                    classlists => 'Update information in classlists?',
 2094:                     );
 2095:         $datatable = '<tr class="LC_odd_row">'. 
 2096:                   '<td>'.&mt($title{'run'}).'</td>'.
 2097:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2098:                   '<input type="radio" name="autoupdate_run"'.
 2099:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2100:                   '<label><input type="radio" name="autoupdate_run"'.
 2101:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2102:                   '</tr><tr>'.
 2103:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 2104:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 2105:                   '<label><input type="radio" name="classlists"'.
 2106:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2107:                   '<label><input type="radio" name="classlists"'.
 2108:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2109:                   '</tr>';
 2110:         $$rowtotal += 2;
 2111:     } elsif ($position eq 'middle') {
 2112:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2113:         my $numinrow = 3;
 2114:         my $locknamesettings;
 2115:         $datatable .= &insttypes_row($settings,$types,$usertypes,
 2116:                                      $dom,$numinrow,$othertitle,
 2117:                                     'lockablenames');
 2118:         $$rowtotal ++;
 2119:     } else {
 2120:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2121:         my @fields = ('lastname','firstname','middlename','generation',
 2122:                       'permanentemail','id');
 2123:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 2124:         my $numrows = 0;
 2125:         if (ref($types) eq 'ARRAY') {
 2126:             if (@{$types} > 0) {
 2127:                 $datatable = 
 2128:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 2129:                                          \@fields,$types,\$numrows);
 2130:                     $$rowtotal += @{$types}; 
 2131:             }
 2132:         }
 2133:         $datatable .= 
 2134:             &usertype_update_row($settings,{'default' => $othertitle},
 2135:                                  \%fieldtitles,\@fields,['default'],
 2136:                                  \$numrows);
 2137:         $$rowtotal ++;     
 2138:     }
 2139:     return $datatable;
 2140: }
 2141: 
 2142: sub print_autocreate {
 2143:     my ($dom,$settings,$rowtotal) = @_;
 2144:     my (%createon,%createoff,%currhash);
 2145:     my @types = ('xml','req');
 2146:     if (ref($settings) eq 'HASH') {
 2147:         foreach my $item (@types) {
 2148:             $createoff{$item} = ' checked="checked" ';
 2149:             $createon{$item} = ' ';
 2150:             if (exists($settings->{$item})) {
 2151:                 if ($settings->{$item}) {
 2152:                     $createon{$item} = ' checked="checked" ';
 2153:                     $createoff{$item} = ' ';
 2154:                 }
 2155:             }
 2156:         }
 2157:         if ($settings->{'xmldc'} ne '') { 
 2158:             $currhash{$settings->{'xmldc'}} = 1;
 2159:         }
 2160:     } else {
 2161:         foreach my $item (@types) {
 2162:             $createoff{$item} = ' checked="checked" ';
 2163:             $createon{$item} = ' ';
 2164:         }
 2165:     }
 2166:     $$rowtotal += 2;
 2167:     my $numinrow = 2;
 2168:     my $datatable='<tr class="LC_odd_row">'.
 2169:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
 2170:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2171:                   '<input type="radio" name="autocreate_xml"'.
 2172:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2173:                   '<label><input type="radio" name="autocreate_xml"'.
 2174:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
 2175:                   '</td></tr><tr>'.
 2176:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
 2177:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2178:                   '<input type="radio" name="autocreate_req"'.
 2179:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2180:                   '<label><input type="radio" name="autocreate_req"'.
 2181:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
 2182:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
 2183:                                                    'autocreate_xmldc',%currhash);
 2184:     if ($numdc > 1) {
 2185:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
 2186:                       &mt('Course creation processed as: (choose Dom. Coord.)').
 2187:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
 2188:     } else {
 2189:         $datatable .= $dctable.'</td></tr>';
 2190:     }
 2191:     $$rowtotal += $rows;
 2192:     return $datatable;
 2193: }
 2194: 
 2195: sub print_directorysrch {
 2196:     my ($dom,$settings,$rowtotal) = @_;
 2197:     my $srchon = ' ';
 2198:     my $srchoff = ' checked="checked" ';
 2199:     my ($exacton,$containson,$beginson);
 2200:     my $localon = ' ';
 2201:     my $localoff = ' checked="checked" ';
 2202:     if (ref($settings) eq 'HASH') {
 2203:         if ($settings->{'available'} eq '1') {
 2204:             $srchon = $srchoff;
 2205:             $srchoff = ' ';
 2206:         }
 2207:         if ($settings->{'localonly'} eq '1') {
 2208:             $localon = $localoff;
 2209:             $localoff = ' ';
 2210:         }
 2211:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 2212:             foreach my $type (@{$settings->{'searchtypes'}}) {
 2213:                 if ($type eq 'exact') {
 2214:                     $exacton = ' checked="checked" ';
 2215:                 } elsif ($type eq 'contains') {
 2216:                     $containson = ' checked="checked" ';
 2217:                 } elsif ($type eq 'begins') {
 2218:                     $beginson = ' checked="checked" ';
 2219:                 }
 2220:             }
 2221:         } else {
 2222:             if ($settings->{'searchtypes'} eq 'exact') {
 2223:                 $exacton = ' checked="checked" ';
 2224:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 2225:                 $containson = ' checked="checked" ';
 2226:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 2227:                 $exacton = ' checked="checked" ';
 2228:                 $containson = ' checked="checked" ';
 2229:             }
 2230:         }
 2231:     }
 2232:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 2233:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2234: 
 2235:     my $numinrow = 4;
 2236:     my $cansrchrow = 0;
 2237:     my $datatable='<tr class="LC_odd_row">'.
 2238:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 2239:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2240:                   '<input type="radio" name="dirsrch_available"'.
 2241:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2242:                   '<label><input type="radio" name="dirsrch_available"'.
 2243:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2244:                   '</tr><tr>'.
 2245:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 2246:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2247:                   '<input type="radio" name="dirsrch_localonly"'.
 2248:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 2249:                   '<label><input type="radio" name="dirsrch_localonly"'.
 2250:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 2251:                   '</tr>';
 2252:     $$rowtotal += 2;
 2253:     if (ref($usertypes) eq 'HASH') {
 2254:         if (keys(%{$usertypes}) > 0) {
 2255:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
 2256:                                          $numinrow,$othertitle,'cansearch');
 2257:             $cansrchrow = 1;
 2258:         }
 2259:     }
 2260:     if ($cansrchrow) {
 2261:         $$rowtotal ++;
 2262:         $datatable .= '<tr>';
 2263:     } else {
 2264:         $datatable .= '<tr class="LC_odd_row">';
 2265:     }
 2266:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 2267:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 2268:     foreach my $title (@{$titleorder}) {
 2269:         if (defined($searchtitles->{$title})) {
 2270:             my $check = ' ';
 2271:             if (ref($settings) eq 'HASH') {
 2272:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 2273:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 2274:                         $check = ' checked="checked" ';
 2275:                     }
 2276:                 }
 2277:             }
 2278:             $datatable .= '<td class="LC_left_item">'.
 2279:                           '<span class="LC_nobreak"><label>'.
 2280:                           '<input type="checkbox" name="searchby" '.
 2281:                           'value="'.$title.'"'.$check.'/>'.
 2282:                           $searchtitles->{$title}.'</label></span></td>';
 2283:         }
 2284:     }
 2285:     $datatable .= '</tr></table></td></tr>';
 2286:     $$rowtotal ++;
 2287:     if ($cansrchrow) {
 2288:         $datatable .= '<tr class="LC_odd_row">';
 2289:     } else {
 2290:         $datatable .= '<tr>';
 2291:     }
 2292:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 2293:                   '<td class="LC_left_item" colspan="2">'.
 2294:                   '<span class="LC_nobreak"><label>'.
 2295:                   '<input type="checkbox" name="searchtypes" '.
 2296:                   $exacton.' value="exact" />'.&mt('Exact match').
 2297:                   '</label>&nbsp;'.
 2298:                   '<label><input type="checkbox" name="searchtypes" '.
 2299:                   $beginson.' value="begins" />'.&mt('Begins with').
 2300:                   '</label>&nbsp;'.
 2301:                   '<label><input type="checkbox" name="searchtypes" '.
 2302:                   $containson.' value="contains" />'.&mt('Contains').
 2303:                   '</label></span></td></tr>';
 2304:     $$rowtotal ++;
 2305:     return $datatable;
 2306: }
 2307: 
 2308: sub print_contacts {
 2309:     my ($dom,$settings,$rowtotal) = @_;
 2310:     my $datatable;
 2311:     my @contacts = ('adminemail','supportemail');
 2312:     my (%checked,%to,%otheremails,%bccemails);
 2313:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
 2314:                     'requestsmail','updatesmail');
 2315:     foreach my $type (@mailings) {
 2316:         $otheremails{$type} = '';
 2317:     }
 2318:     $bccemails{'helpdeskmail'} = '';
 2319:     if (ref($settings) eq 'HASH') {
 2320:         foreach my $item (@contacts) {
 2321:             if (exists($settings->{$item})) {
 2322:                 $to{$item} = $settings->{$item};
 2323:             }
 2324:         }
 2325:         foreach my $type (@mailings) {
 2326:             if (exists($settings->{$type})) {
 2327:                 if (ref($settings->{$type}) eq 'HASH') {
 2328:                     foreach my $item (@contacts) {
 2329:                         if ($settings->{$type}{$item}) {
 2330:                             $checked{$type}{$item} = ' checked="checked" ';
 2331:                         }
 2332:                     }
 2333:                     $otheremails{$type} = $settings->{$type}{'others'};
 2334:                     if ($type eq 'helpdeskmail') {
 2335:                         $bccemails{$type} = $settings->{$type}{'bcc'};
 2336:                     }
 2337:                 }
 2338:             } elsif ($type eq 'lonstatusmail') {
 2339:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
 2340:             }
 2341:         }
 2342:     } else {
 2343:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2344:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2345:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 2346:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 2347:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
 2348:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
 2349:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
 2350:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
 2351:     }
 2352:     my ($titles,$short_titles) = &contact_titles();
 2353:     my $rownum = 0;
 2354:     my $css_class;
 2355:     foreach my $item (@contacts) {
 2356:         $rownum ++;
 2357:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2358:         $datatable .= '<tr'.$css_class.'>'. 
 2359:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2360:                   '</span></td><td class="LC_right_item">'.
 2361:                   '<input type="text" name="'.$item.'" value="'.
 2362:                   $to{$item}.'" /></td></tr>';
 2363:     }
 2364:     foreach my $type (@mailings) {
 2365:         $rownum ++;
 2366:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2367:         $datatable .= '<tr'.$css_class.'>'.
 2368:                       '<td><span class="LC_nobreak">'.
 2369:                       $titles->{$type}.': </span></td>'.
 2370:                       '<td class="LC_left_item">'.
 2371:                       '<span class="LC_nobreak">';
 2372:         foreach my $item (@contacts) {
 2373:             $datatable .= '<label>'.
 2374:                           '<input type="checkbox" name="'.$type.'"'.
 2375:                           $checked{$type}{$item}.
 2376:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 2377:                           '</label>&nbsp;';
 2378:         }
 2379:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 2380:                       '<input type="text" name="'.$type.'_others" '.
 2381:                       'value="'.$otheremails{$type}.'"  />';
 2382:         if ($type eq 'helpdeskmail') {
 2383:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
 2384:                           '<input type="text" name="'.$type.'_bcc" '.
 2385:                           'value="'.$bccemails{$type}.'"  />';
 2386:         }
 2387:         $datatable .= '</td></tr>'."\n";
 2388:     }
 2389:     $$rowtotal += $rownum;
 2390:     return $datatable;
 2391: }
 2392: 
 2393: sub print_helpsettings {
 2394:     my ($dom,$confname,$settings,$rowtotal) = @_;
 2395:     my ($datatable,$itemcount);
 2396:     $itemcount = 1;
 2397:     my (%choices,%defaultchecked,@toggles);
 2398:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
 2399:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
 2400:                                  &mt('LON-CAPA bug tracker'),600,500));
 2401:     %defaultchecked = ('submitbugs' => 'on');
 2402:     @toggles = ('submitbugs',);
 2403: 
 2404:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2405:                                                  \%choices,$itemcount);
 2406:     return $datatable;
 2407: }
 2408: 
 2409: sub radiobutton_prefs {
 2410:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
 2411:         $additional) = @_;
 2412:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
 2413:                    (ref($choices) eq 'HASH'));
 2414: 
 2415:     my (%checkedon,%checkedoff,$datatable,$css_class);
 2416: 
 2417:     foreach my $item (@{$toggles}) {
 2418:         if ($defaultchecked->{$item} eq 'on') {
 2419:             $checkedon{$item} = ' checked="checked" ';
 2420:             $checkedoff{$item} = ' ';
 2421:         } elsif ($defaultchecked->{$item} eq 'off') {
 2422:             $checkedoff{$item} = ' checked="checked" ';
 2423:             $checkedon{$item} = ' ';
 2424:         }
 2425:     }
 2426:     if (ref($settings) eq 'HASH') {
 2427:         foreach my $item (@{$toggles}) {
 2428:             if ($settings->{$item} eq '1') {
 2429:                 $checkedon{$item} =  ' checked="checked" ';
 2430:                 $checkedoff{$item} = ' ';
 2431:             } elsif ($settings->{$item} eq '0') {
 2432:                 $checkedoff{$item} =  ' checked="checked" ';
 2433:                 $checkedon{$item} = ' ';
 2434:             }
 2435:         }
 2436:     }
 2437:     if ($onclick) {
 2438:         $onclick = ' onclick="'.$onclick.'"';
 2439:     }
 2440:     foreach my $item (@{$toggles}) {
 2441:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2442:         $datatable .=
 2443:             '<tr'.$css_class.'><td valign="top">'.
 2444:             '<span class="LC_nobreak">'.$choices->{$item}.
 2445:             '</span></td>'.
 2446:             '<td class="LC_right_item"><span class="LC_nobreak">'.
 2447:             '<label><input type="radio" name="'.
 2448:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
 2449:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
 2450:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
 2451:             '</span>'.$additional.
 2452:             '</td>'.
 2453:             '</tr>';
 2454:         $itemcount ++;
 2455:     }
 2456:     return ($datatable,$itemcount);
 2457: }
 2458: 
 2459: sub print_coursedefaults {
 2460:     my ($position,$dom,$settings,$rowtotal) = @_;
 2461:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
 2462:     my $itemcount = 1;
 2463:     my %choices =  &Apache::lonlocal::texthash (
 2464:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
 2465:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
 2466:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
 2467:         coursecredits        => 'Credits can be specified for courses',
 2468:     );
 2469:     my %staticdefaults = (
 2470:                            anonsurvey_threshold => 10,
 2471:                            uploadquota          => 500,
 2472:                          );
 2473:     if ($position eq 'top') {
 2474:         %defaultchecked = ('canuse_pdfforms' => 'off');
 2475:         @toggles = ('canuse_pdfforms');
 2476:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2477:                                                  \%choices,$itemcount);
 2478:     } else {
 2479:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2480:         my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
 2481:         my $currusecredits = 0;
 2482:         my @types = ('official','unofficial','community');
 2483:         if (ref($settings) eq 'HASH') {
 2484:             $currdefresponder = $settings->{'anonsurvey_threshold'};
 2485:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
 2486:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
 2487:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
 2488:                 }
 2489:             }
 2490:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
 2491:                 $def_official_credits = $settings->{'coursecredits'}->{'official'};
 2492:                 $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
 2493:                 if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
 2494:                     $currusecredits = 1;
 2495:                 }
 2496:             }
 2497:         }
 2498:         if (!$currdefresponder) {
 2499:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
 2500:         } elsif ($currdefresponder < 1) {
 2501:             $currdefresponder = 1;
 2502:         }
 2503:         foreach my $type (@types) {
 2504:             if ($curruploadquota{$type} eq '') {
 2505:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
 2506:             }
 2507:         }
 2508:         $datatable .=
 2509:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 2510:                 $choices{'anonsurvey_threshold'}.
 2511:                 '</span></td>'.
 2512:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
 2513:                 '<input type="text" name="anonsurvey_threshold"'.
 2514:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
 2515:                 '</td></tr>'."\n".
 2516:                 '<tr><td><span class="LC_nobreak">'.
 2517:                 $choices{'uploadquota'}.
 2518:                 '</span></td>'.
 2519:                 '<td align="right" class="LC_right_item">'.
 2520:                 '<table><tr>';
 2521:         foreach my $type (@types) {
 2522:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
 2523:                            '<input type="text" name="uploadquota_'.$type.'"'.
 2524:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
 2525:         }
 2526:         $datatable .= '</tr></table></td></tr>'."\n";
 2527:         $itemcount += 2;
 2528:         my $onclick = 'toggleCredits(this.form);';
 2529:         my $display = 'none';  
 2530:         if ($currusecredits) {
 2531:             $display = 'block';
 2532:         }
 2533:         my $additional = '<div id="credits" style="display: '.$display.'">'.
 2534:                          '<span class="LC_nobreak">'.
 2535:                          &mt('Default credits for official courses [_1]',
 2536:                          '<input type="text" name="official_credits" value="'.
 2537:                          $def_official_credits.'" size="3" />').
 2538:                          '</span><br />'.
 2539:                          '<span class="LC_nobreak">'.
 2540:                          &mt('Default credits for unofficial courses [_1]',
 2541:                          '<input type="text" name="unofficial_credits" value="'.
 2542:                          $def_unofficial_credits.'" size="3" />').
 2543:                          '</span></div>'."\n";
 2544:         %defaultchecked = ('coursecredits' => 'off');
 2545:         @toggles = ('coursecredits');
 2546:         my $current = {
 2547:                         'coursecredits' => $currusecredits,
 2548:                       };
 2549:         (my $table,$itemcount) =
 2550:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
 2551:                                \%choices,$itemcount,$onclick,$additional);
 2552:         $datatable .= $table;
 2553:     }
 2554:     $$rowtotal += $itemcount;
 2555:     return $datatable;
 2556: }
 2557: 
 2558: sub print_usersessions {
 2559:     my ($position,$dom,$settings,$rowtotal) = @_;
 2560:     my ($css_class,$datatable,%checked,%choices);
 2561:     my (%by_ip,%by_location,@intdoms);
 2562:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 2563: 
 2564:     my @alldoms = &Apache::lonnet::all_domains();
 2565:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
 2566:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 2567:     my %altids = &id_for_thisdom(%servers);
 2568:     my $itemcount = 1;
 2569:     if ($position eq 'top') {
 2570:         if (keys(%serverhomes) > 1) {
 2571:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
 2572:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
 2573:         } else {
 2574:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 2575:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
 2576:         }
 2577:     } else {
 2578:         if (keys(%by_location) == 0) {
 2579:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 2580:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
 2581:         } else {
 2582:             my %lt = &usersession_titles();
 2583:             my $numinrow = 5;
 2584:             my $prefix;
 2585:             my @types;
 2586:             if ($position eq 'bottom') {
 2587:                 $prefix = 'remote';
 2588:                 @types = ('version','excludedomain','includedomain');
 2589:             } else {
 2590:                 $prefix = 'hosted';
 2591:                 @types = ('excludedomain','includedomain');
 2592:             }
 2593:             my (%current,%checkedon,%checkedoff);
 2594:             my @lcversions = &Apache::lonnet::all_loncaparevs();
 2595:             my @locations = sort(keys(%by_location));
 2596:             foreach my $type (@types) {
 2597:                 $checkedon{$type} = '';
 2598:                 $checkedoff{$type} = ' checked="checked"';
 2599:             }
 2600:             if (ref($settings) eq 'HASH') {
 2601:                 if (ref($settings->{$prefix}) eq 'HASH') {
 2602:                     foreach my $key (keys(%{$settings->{$prefix}})) {
 2603:                         $current{$key} = $settings->{$prefix}{$key};
 2604:                         if ($key eq 'version') {
 2605:                             if ($current{$key} ne '') {
 2606:                                 $checkedon{$key} = ' checked="checked"';
 2607:                                 $checkedoff{$key} = '';
 2608:                             }
 2609:                         } elsif (ref($current{$key}) eq 'ARRAY') {
 2610:                             $checkedon{$key} = ' checked="checked"';
 2611:                             $checkedoff{$key} = '';
 2612:                         }
 2613:                     }
 2614:                 }
 2615:             }
 2616:             foreach my $type (@types) {
 2617:                 next if ($type ne 'version' && !@locations);
 2618:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2619:                 $datatable .= '<tr'.$css_class.'>
 2620:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
 2621:                                <span class="LC_nobreak">&nbsp;
 2622:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
 2623:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
 2624:                 if ($type eq 'version') {
 2625:                     my $selector = '<select name="'.$prefix.'_version">';
 2626:                     foreach my $version (@lcversions) {
 2627:                         my $selected = '';
 2628:                         if ($current{'version'} eq $version) {
 2629:                             $selected = ' selected="selected"';
 2630:                         }
 2631:                         $selector .= ' <option value="'.$version.'"'.
 2632:                                      $selected.'>'.$version.'</option>';
 2633:                     }
 2634:                     $selector .= '</select> ';
 2635:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
 2636:                 } else {
 2637:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
 2638:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
 2639:                                  ' />'.('&nbsp;'x2).
 2640:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
 2641:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
 2642:                                  "\n".
 2643:                                  '</div><div><table>';
 2644:                     my $rem;
 2645:                     for (my $i=0; $i<@locations; $i++) {
 2646:                         my ($showloc,$value,$checkedtype);
 2647:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
 2648:                             my $ip = $by_location{$locations[$i]}->[0];
 2649:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
 2650:                                  $value = join(':',@{$by_ip{$ip}});
 2651:                                 $showloc = join(', ',@{$by_ip{$ip}});
 2652:                                 if (ref($current{$type}) eq 'ARRAY') {
 2653:                                     foreach my $loc (@{$by_ip{$ip}}) {  
 2654:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
 2655:                                             $checkedtype = ' checked="checked"';
 2656:                                             last;
 2657:                                         }
 2658:                                     }
 2659:                                 }
 2660:                             }
 2661:                         }
 2662:                         $rem = $i%($numinrow);
 2663:                         if ($rem == 0) {
 2664:                             if ($i > 0) {
 2665:                                 $datatable .= '</tr>';
 2666:                             }
 2667:                             $datatable .= '<tr>';
 2668:                         }
 2669:                         $datatable .= '<td class="LC_left_item">'.
 2670:                                       '<span class="LC_nobreak"><label>'.
 2671:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
 2672:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
 2673:                                       '</label></span></td>';
 2674:                     }
 2675:                     $rem = @locations%($numinrow);
 2676:                     my $colsleft = $numinrow - $rem;
 2677:                     if ($colsleft > 1 ) {
 2678:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2679:                                       '&nbsp;</td>';
 2680:                     } elsif ($colsleft == 1) {
 2681:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 2682:                     }
 2683:                     $datatable .= '</tr></table>';
 2684:                 }
 2685:                 $datatable .= '</td></tr>';
 2686:                 $itemcount ++;
 2687:             }
 2688:         }
 2689:     }
 2690:     $$rowtotal += $itemcount;
 2691:     return $datatable;
 2692: }
 2693: 
 2694: sub build_location_hashes {
 2695:     my ($intdoms,$by_ip,$by_location) = @_;
 2696:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
 2697:                   (ref($by_location) eq 'HASH')); 
 2698:     my %iphost = &Apache::lonnet::get_iphost();
 2699:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
 2700:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
 2701:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
 2702:         foreach my $id (@{$iphost{$primary_ip}}) {
 2703:             my $intdom = &Apache::lonnet::internet_dom($id);
 2704:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
 2705:                 push(@{$intdoms},$intdom);
 2706:             }
 2707:         }
 2708:     }
 2709:     foreach my $ip (keys(%iphost)) {
 2710:         if (ref($iphost{$ip}) eq 'ARRAY') {
 2711:             foreach my $id (@{$iphost{$ip}}) {
 2712:                 my $location = &Apache::lonnet::internet_dom($id);
 2713:                 if ($location) {
 2714:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
 2715:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2716:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
 2717:                             push(@{$by_ip->{$ip}},$location);
 2718:                         }
 2719:                     } else {
 2720:                         $by_ip->{$ip} = [$location];
 2721:                     }
 2722:                 }
 2723:             }
 2724:         }
 2725:     }
 2726:     foreach my $ip (sort(keys(%{$by_ip}))) {
 2727:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2728:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
 2729:             my $first = $by_ip->{$ip}->[0];
 2730:             if (ref($by_location->{$first}) eq 'ARRAY') {
 2731:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
 2732:                     push(@{$by_location->{$first}},$ip);
 2733:                 }
 2734:             } else {
 2735:                 $by_location->{$first} = [$ip];
 2736:             }
 2737:         }
 2738:     }
 2739:     return;
 2740: }
 2741: 
 2742: sub current_offloads_to {
 2743:     my ($dom,$settings,$servers) = @_;
 2744:     my (%spareid,%otherdomconfigs);
 2745:     if (ref($servers) eq 'HASH') {
 2746:         foreach my $lonhost (sort(keys(%{$servers}))) {
 2747:             my $gotspares;
 2748:             if (ref($settings) eq 'HASH') {
 2749:                 if (ref($settings->{'spares'}) eq 'HASH') {
 2750:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
 2751:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
 2752:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
 2753:                         $gotspares = 1;
 2754:                     }
 2755:                 }
 2756:             }
 2757:             unless ($gotspares) {
 2758:                 my $gotspares;
 2759:                 my $serverhomeID =
 2760:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
 2761:                 my $serverhomedom =
 2762:                     &Apache::lonnet::host_domain($serverhomeID);
 2763:                 if ($serverhomedom ne $dom) {
 2764:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
 2765:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 2766:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 2767:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 2768:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 2769:                                 $gotspares = 1;
 2770:                             }
 2771:                         }
 2772:                     } else {
 2773:                         $otherdomconfigs{$serverhomedom} =
 2774:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
 2775:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
 2776:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 2777:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 2778:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) 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:                             }
 2785:                         }
 2786:                     }
 2787:                 }
 2788:             }
 2789:             unless ($gotspares) {
 2790:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
 2791:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 2792:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 2793:                } else {
 2794:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
 2795:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
 2796:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
 2797:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 2798:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 2799:                     } else {
 2800:                         my %what = (
 2801:                              spareid => 1,
 2802:                         );
 2803:                         my ($result,$returnhash) = 
 2804:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
 2805:                         if ($result eq 'ok') { 
 2806:                             if (ref($returnhash) eq 'HASH') {
 2807:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
 2808:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
 2809:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
 2810:                                 }
 2811:                             }
 2812:                         }
 2813:                     }
 2814:                 }
 2815:             }
 2816:         }
 2817:     }
 2818:     return %spareid;
 2819: }
 2820: 
 2821: sub spares_row {
 2822:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
 2823:     my $css_class;
 2824:     my $numinrow = 4;
 2825:     my $itemcount = 1;
 2826:     my $datatable;
 2827:     my %typetitles = &sparestype_titles();
 2828:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
 2829:         foreach my $server (sort(keys(%{$servers}))) {
 2830:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
 2831:             my ($othercontrol,$serverdom);
 2832:             if ($serverhome ne $server) {
 2833:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
 2834:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 2835:             } else {
 2836:                 $serverdom = &Apache::lonnet::host_domain($server);
 2837:                 if ($serverdom ne $dom) {
 2838:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 2839:                 }
 2840:             }
 2841:             next unless (ref($spareid->{$server}) eq 'HASH');
 2842:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2843:             $datatable .= '<tr'.$css_class.'>
 2844:                            <td rowspan="2">
 2845:                             <span class="LC_nobreak">'.
 2846:                           &mt('[_1] when busy, offloads to:'
 2847:                               ,'<b>'.$server.'</b>').
 2848:                           "\n";
 2849:             my (%current,%canselect);
 2850:             my @choices = 
 2851:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
 2852:             foreach my $type ('primary','default') {
 2853:                 if (ref($spareid->{$server}) eq 'HASH') {
 2854:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
 2855:                         my @spares = @{$spareid->{$server}{$type}};
 2856:                         if (@spares > 0) {
 2857:                             if ($othercontrol) {
 2858:                                 $current{$type} = join(', ',@spares);
 2859:                             } else {
 2860:                                 $current{$type} .= '<table>';
 2861:                                 my $numspares = scalar(@spares);
 2862:                                 for (my $i=0;  $i<@spares; $i++) {
 2863:                                     my $rem = $i%($numinrow);
 2864:                                     if ($rem == 0) {
 2865:                                         if ($i > 0) {
 2866:                                             $current{$type} .= '</tr>';
 2867:                                         }
 2868:                                         $current{$type} .= '<tr>';
 2869:                                     }
 2870:                                     $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;'.
 2871:                                                        $spareid->{$server}{$type}[$i].
 2872:                                                        '</label></td>'."\n";
 2873:                                 }
 2874:                                 my $rem = @spares%($numinrow);
 2875:                                 my $colsleft = $numinrow - $rem;
 2876:                                 if ($colsleft > 1 ) {
 2877:                                     $current{$type} .= '<td colspan="'.$colsleft.
 2878:                                                        '" class="LC_left_item">'.
 2879:                                                        '&nbsp;</td>';
 2880:                                 } elsif ($colsleft == 1) {
 2881:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
 2882:                                 }
 2883:                                 $current{$type} .= '</tr></table>';
 2884:                             }
 2885:                         }
 2886:                     }
 2887:                     if ($current{$type} eq '') {
 2888:                         $current{$type} = &mt('None specified');
 2889:                     }
 2890:                     if ($othercontrol) {
 2891:                         if ($type eq 'primary') {
 2892:                             $canselect{$type} = $othercontrol;
 2893:                         }
 2894:                     } else {
 2895:                         $canselect{$type} = 
 2896:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
 2897:                             '<select name="newspare_'.$type.'_'.$server.'" '.
 2898:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
 2899:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
 2900:                         if (@choices > 0) {
 2901:                             foreach my $lonhost (@choices) {
 2902:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
 2903:                             }
 2904:                         }
 2905:                         $canselect{$type} .= '</select>'."\n";
 2906:                     }
 2907:                 } else {
 2908:                     $current{$type} = &mt('Could not be determined');
 2909:                     if ($type eq 'primary') {
 2910:                         $canselect{$type} =  $othercontrol;
 2911:                     }
 2912:                 }
 2913:                 if ($type eq 'default') {
 2914:                     $datatable .= '<tr'.$css_class.'>';
 2915:                 }
 2916:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
 2917:                               '<td>'.$current{$type}.'</td>'."\n".
 2918:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
 2919:             }
 2920:             $itemcount ++;
 2921:         }
 2922:     }
 2923:     $$rowtotal += $itemcount;
 2924:     return $datatable;
 2925: }
 2926: 
 2927: sub possible_newspares {
 2928:     my ($server,$currspares,$serverhomes,$altids) = @_;
 2929:     my $serverhostname = &Apache::lonnet::hostname($server);
 2930:     my %excluded;
 2931:     if ($serverhostname ne '') {
 2932:         %excluded = (
 2933:                        $serverhostname => 1,
 2934:                     );
 2935:     }
 2936:     if (ref($currspares) eq 'HASH') {
 2937:         foreach my $type (keys(%{$currspares})) {
 2938:             if (ref($currspares->{$type}) eq 'ARRAY') {
 2939:                 if (@{$currspares->{$type}} > 0) {
 2940:                     foreach my $curr (@{$currspares->{$type}}) {
 2941:                         my $hostname = &Apache::lonnet::hostname($curr);
 2942:                         $excluded{$hostname} = 1;
 2943:                     }
 2944:                 }
 2945:             }
 2946:         }
 2947:     }
 2948:     my @choices;
 2949:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
 2950:         if (keys(%{$serverhomes}) > 1) {
 2951:             foreach my $name (sort(keys(%{$serverhomes}))) {
 2952:                 unless ($excluded{$name}) {
 2953:                     if (exists($altids->{$serverhomes->{$name}})) {
 2954:                         push(@choices,$altids->{$serverhomes->{$name}});
 2955:                     } else {
 2956:                         push(@choices,$serverhomes->{$name});
 2957:                     }
 2958:                 }
 2959:             }
 2960:         }
 2961:     }
 2962:     return sort(@choices);
 2963: }
 2964: 
 2965: sub print_loadbalancing {
 2966:     my ($dom,$settings,$rowtotal) = @_;
 2967:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
 2968:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
 2969:     my $numinrow = 1;
 2970:     my $datatable;
 2971:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 2972:     my (%currbalancer,%currtargets,%currrules,%existing);
 2973:     if (ref($settings) eq 'HASH') {
 2974:         %existing = %{$settings};
 2975:     }
 2976:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
 2977:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
 2978:                                   \%currtargets,\%currrules);
 2979:     } else {
 2980:         return;
 2981:     }
 2982:     my ($othertitle,$usertypes,$types) =
 2983:         &Apache::loncommon::sorted_inst_types($dom);
 2984:     my $rownum = 6;
 2985:     if (ref($types) eq 'ARRAY') {
 2986:         $rownum += scalar(@{$types});
 2987:     }
 2988:     my @css_class = ('LC_odd_row','LC_even_row');
 2989:     my $balnum = 0;
 2990:     my $islast;
 2991:     my (@toshow,$disabledtext);
 2992:     if (keys(%currbalancer) > 0) {
 2993:         @toshow = sort(keys(%currbalancer));
 2994:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
 2995:             push(@toshow,'');
 2996:         }
 2997:     } else {
 2998:         @toshow = ('');
 2999:         $disabledtext = &mt('No existing load balancer');
 3000:     }
 3001:     foreach my $lonhost (@toshow) {
 3002:         if ($balnum == scalar(@toshow)-1) {
 3003:             $islast = 1;
 3004:         } else {
 3005:             $islast = 0;
 3006:         }
 3007:         my $cssidx = $balnum%2;
 3008:         my $targets_div_style = 'display: none';
 3009:         my $disabled_div_style = 'display: block';
 3010:         my $homedom_div_style = 'display: none';
 3011:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
 3012:                       '<td rowspan="'.$rownum.'" valign="top">'.
 3013:                       '<p>';
 3014:         if ($lonhost eq '') {
 3015:             $datatable .= '<span class="LC_nobreak">'; 
 3016:             if (keys(%currbalancer) > 0) {
 3017:                 $datatable .= &mt('Add balancer:');
 3018:             } else {
 3019:                 $datatable .= &mt('Enable balancer:');
 3020:             }
 3021:             $datatable .= '&nbsp;'.
 3022:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
 3023:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
 3024:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
 3025:                           '<option value="" selected="selected">'.&mt('None').
 3026:                           '</option>'."\n";
 3027:             foreach my $server (sort(keys(%servers))) {
 3028:                 next if ($currbalancer{$server});
 3029:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
 3030:             }
 3031:             $datatable .= 
 3032:                 '</select>'."\n".
 3033:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
 3034:         } else {
 3035:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
 3036:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
 3037:                            &mt('Stop balancing').'</label>'.
 3038:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
 3039:             $targets_div_style = 'display: block';
 3040:             $disabled_div_style = 'display: none';
 3041:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
 3042:                 $homedom_div_style = 'display: block';
 3043:             }
 3044:         }
 3045:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
 3046:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
 3047:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
 3048:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
 3049:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
 3050:         my @sparestypes = ('primary','default');
 3051:         my %typetitles = &sparestype_titles();
 3052:         foreach my $sparetype (@sparestypes) {
 3053:             my $targettable;
 3054:             for (my $i=0; $i<$numspares; $i++) {
 3055:                 my $checked;
 3056:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
 3057:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
 3058:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
 3059:                             $checked = ' checked="checked"';
 3060:                         }
 3061:                     }
 3062:                 }
 3063:                 my ($chkboxval,$disabled);
 3064:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
 3065:                     $chkboxval = $spares[$i];
 3066:                 }
 3067:                 if (exists($currbalancer{$spares[$i]})) {
 3068:                     $disabled = ' disabled="disabled"';
 3069:                 }
 3070:                 $targettable .= 
 3071:                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
 3072:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
 3073:                     '</span></label></td>';
 3074:                 my $rem = $i%($numinrow);
 3075:                 if ($rem == 0) {
 3076:                     if (($i > 0) && ($i < $numspares-1)) {
 3077:                         $targettable .= '</tr>';
 3078:                     }
 3079:                     if ($i < $numspares-1) {
 3080:                         $targettable .= '<tr>';
 3081:                     }
 3082:                 }
 3083:             }
 3084:             if ($targettable ne '') {
 3085:                 my $rem = $numspares%($numinrow);
 3086:                 my $colsleft = $numinrow - $rem;
 3087:                 if ($colsleft > 1 ) {
 3088:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3089:                                     '&nbsp;</td>';
 3090:                 } elsif ($colsleft == 1) {
 3091:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
 3092:                 }
 3093:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
 3094:                                '<table><tr>'.$targettable.'</tr></table><br />';
 3095:             }
 3096:         }
 3097:         $datatable .= '</div></td></tr>'.
 3098:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
 3099:                                            $othertitle,$usertypes,$types,\%servers,
 3100:                                            \%currbalancer,$lonhost,
 3101:                                            $targets_div_style,$homedom_div_style,
 3102:                                            $css_class[$cssidx],$balnum,$islast);
 3103:         $$rowtotal += $rownum;
 3104:         $balnum ++;
 3105:     }
 3106:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
 3107:     return $datatable;
 3108: }
 3109: 
 3110: sub get_loadbalancers_config {
 3111:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
 3112:     return unless ((ref($servers) eq 'HASH') &&
 3113:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
 3114:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
 3115:     if (keys(%{$existing}) > 0) {
 3116:         my $oldlonhost;
 3117:         foreach my $key (sort(keys(%{$existing}))) {
 3118:             if ($key eq 'lonhost') {
 3119:                 $oldlonhost = $existing->{'lonhost'};
 3120:                 $currbalancer->{$oldlonhost} = 1;
 3121:             } elsif ($key eq 'targets') {
 3122:                 if ($oldlonhost) {
 3123:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
 3124:                 }
 3125:             } elsif ($key eq 'rules') {
 3126:                 if ($oldlonhost) {
 3127:                     $currrules->{$oldlonhost} = $existing->{'rules'};
 3128:                 }
 3129:             } elsif (ref($existing->{$key}) eq 'HASH') {
 3130:                 $currbalancer->{$key} = 1;
 3131:                 $currtargets->{$key} = $existing->{$key}{'targets'};
 3132:                 $currrules->{$key} = $existing->{$key}{'rules'};
 3133:             }
 3134:         }
 3135:     } else {
 3136:         my ($balancerref,$targetsref) =
 3137:                 &Apache::lonnet::get_lonbalancer_config($servers);
 3138:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
 3139:             foreach my $server (sort(keys(%{$balancerref}))) {
 3140:                 $currbalancer->{$server} = 1;
 3141:                 $currtargets->{$server} = $targetsref->{$server};
 3142:             }
 3143:         }
 3144:     }
 3145:     return;
 3146: }
 3147: 
 3148: sub loadbalancing_rules {
 3149:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
 3150:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
 3151:         $css_class,$balnum,$islast) = @_;
 3152:     my $output;
 3153:     my $num = 0;
 3154:     my ($alltypes,$othertypes,$titles) = 
 3155:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
 3156:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
 3157:         foreach my $type (@{$alltypes}) {
 3158:             $num ++;
 3159:             my $current;
 3160:             if (ref($currrules) eq 'HASH') {
 3161:                 $current = $currrules->{$type};
 3162:             }
 3163:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3164:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
 3165:                     $current = '';
 3166:                 }
 3167:             }
 3168:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
 3169:                                              $servers,$currbalancer,$lonhost,$dom,
 3170:                                              $targets_div_style,$homedom_div_style,
 3171:                                              $css_class,$balnum,$num,$islast);
 3172:         }
 3173:     }
 3174:     return $output;
 3175: }
 3176: 
 3177: sub loadbalancing_titles {
 3178:     my ($dom,$intdom,$usertypes,$types) = @_;
 3179:     my %othertypes = (
 3180:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
 3181:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
 3182:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
 3183:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
 3184:                      );
 3185:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
 3186:     if (ref($types) eq 'ARRAY') {
 3187:         unshift(@alltypes,@{$types},'default');
 3188:     }
 3189:     my %titles;
 3190:     foreach my $type (@alltypes) {
 3191:         if ($type =~ /^_LC_/) {
 3192:             $titles{$type} = $othertypes{$type};
 3193:         } elsif ($type eq 'default') {
 3194:             $titles{$type} = &mt('All users from [_1]',$dom);
 3195:             if (ref($types) eq 'ARRAY') {
 3196:                 if (@{$types} > 0) {
 3197:                     $titles{$type} = &mt('Other users from [_1]',$dom);
 3198:                 }
 3199:             }
 3200:         } elsif (ref($usertypes) eq 'HASH') {
 3201:             $titles{$type} = $usertypes->{$type};
 3202:         }
 3203:     }
 3204:     return (\@alltypes,\%othertypes,\%titles);
 3205: }
 3206: 
 3207: sub loadbalance_rule_row {
 3208:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
 3209:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
 3210:     my @rulenames = ('default','homeserver');
 3211:     my %ruletitles = &offloadtype_text();
 3212:     if ($type eq '_LC_external') {
 3213:         push(@rulenames,'externalbalancer');
 3214:     } else {
 3215:         push(@rulenames,'specific');
 3216:     }
 3217:     push(@rulenames,'none');
 3218:     my $style = $targets_div_style;
 3219:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3220:         $style = $homedom_div_style;
 3221:     }
 3222:     my $space;
 3223:     if ($islast && $num == 1) {
 3224:         $space = '<div display="inline-block">&nbsp;</div>';
 3225:     }
 3226:     my $output = 
 3227:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
 3228:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
 3229:         '<td valaign="top">'.$space.
 3230:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
 3231:     for (my $i=0; $i<@rulenames; $i++) {
 3232:         my $rule = $rulenames[$i];
 3233:         my ($checked,$extra);
 3234:         if ($rulenames[$i] eq 'default') {
 3235:             $rule = '';
 3236:         }
 3237:         if ($rulenames[$i] eq 'specific') {
 3238:             if (ref($servers) eq 'HASH') {
 3239:                 my $default;
 3240:                 if (($current ne '') && (exists($servers->{$current}))) {
 3241:                     $checked = ' checked="checked"';
 3242:                 }
 3243:                 unless ($checked) {
 3244:                     $default = ' selected="selected"';
 3245:                 }
 3246:                 $extra = 
 3247:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
 3248:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
 3249:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
 3250:                     '<option value=""'.$default.'></option>'."\n";
 3251:                 foreach my $server (sort(keys(%{$servers}))) {
 3252:                     if (ref($currbalancer) eq 'HASH') {
 3253:                         next if (exists($currbalancer->{$server}));
 3254:                     }
 3255:                     my $selected;
 3256:                     if ($server eq $current) {
 3257:                         $selected = ' selected="selected"';
 3258:                     }
 3259:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
 3260:                 }
 3261:                 $extra .= '</select>';
 3262:             }
 3263:         } elsif ($rule eq $current) {
 3264:             $checked = ' checked="checked"';
 3265:         }
 3266:         $output .= '<span class="LC_nobreak"><label>'.
 3267:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
 3268:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
 3269:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
 3270:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
 3271:                    '</label>'.$extra.'</span><br />'."\n";
 3272:     }
 3273:     $output .= '</div></td></tr>'."\n";
 3274:     return $output;
 3275: }
 3276: 
 3277: sub offloadtype_text {
 3278:     my %ruletitles = &Apache::lonlocal::texthash (
 3279:            'default'          => 'Offloads to default destinations',
 3280:            'homeserver'       => "Offloads to user's home server",
 3281:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
 3282:            'specific'         => 'Offloads to specific server',
 3283:            'none'             => 'No offload',
 3284:     );
 3285:     return %ruletitles;
 3286: }
 3287: 
 3288: sub sparestype_titles {
 3289:     my %typestitles = &Apache::lonlocal::texthash (
 3290:                           'primary' => 'primary',
 3291:                           'default' => 'default',
 3292:                       );
 3293:     return %typestitles;
 3294: }
 3295: 
 3296: sub contact_titles {
 3297:     my %titles = &Apache::lonlocal::texthash (
 3298:                    'supportemail' => 'Support E-mail address',
 3299:                    'adminemail'   => 'Default Server Admin E-mail address',
 3300:                    'errormail'    => 'Error reports to be e-mailed to',
 3301:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 3302:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
 3303:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
 3304:                    'requestsmail' => 'E-mail from course requests requiring approval',
 3305:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
 3306:                  );
 3307:     my %short_titles = &Apache::lonlocal::texthash (
 3308:                            adminemail   => 'Admin E-mail address',
 3309:                            supportemail => 'Support E-mail',
 3310:                        );   
 3311:     return (\%titles,\%short_titles);
 3312: }
 3313: 
 3314: sub tool_titles {
 3315:     my %titles = &Apache::lonlocal::texthash (
 3316:                      aboutme    => 'Personal web page',
 3317:                      blog       => 'Blog',
 3318:                      webdav     => 'WebDAV',
 3319:                      portfolio  => 'Portfolio',
 3320:                      official   => 'Official courses (with institutional codes)',
 3321:                      unofficial => 'Unofficial courses',
 3322:                      community  => 'Communities',
 3323:                  );
 3324:     return %titles;
 3325: }
 3326: 
 3327: sub courserequest_titles {
 3328:     my %titles = &Apache::lonlocal::texthash (
 3329:                                    official   => 'Official',
 3330:                                    unofficial => 'Unofficial',
 3331:                                    community  => 'Communities',
 3332:                                    norequest  => 'Not allowed',
 3333:                                    approval   => 'Approval by Dom. Coord.',
 3334:                                    validate   => 'With validation',
 3335:                                    autolimit  => 'Numerical limit',
 3336:                                    unlimited  => '(blank for unlimited)',
 3337:                  );
 3338:     return %titles;
 3339: }
 3340: 
 3341: sub authorrequest_titles {
 3342:     my %titles = &Apache::lonlocal::texthash (
 3343:                                    norequest  => 'Not allowed',
 3344:                                    approval   => 'Approval by Dom. Coord.',
 3345:                                    automatic  => 'Automatic approval',
 3346:                  );
 3347:     return %titles;
 3348: } 
 3349: 
 3350: sub courserequest_conditions {
 3351:     my %conditions = &Apache::lonlocal::texthash (
 3352:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
 3353:        validate   => '(Processing of request subject to institutional validation).',
 3354:                  );
 3355:     return %conditions;
 3356: }
 3357: 
 3358: 
 3359: sub print_usercreation {
 3360:     my ($position,$dom,$settings,$rowtotal) = @_;
 3361:     my $numinrow = 4;
 3362:     my $datatable;
 3363:     if ($position eq 'top') {
 3364:         $$rowtotal ++;
 3365:         my $rowcount = 0;
 3366:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 3367:         if (ref($rules) eq 'HASH') {
 3368:             if (keys(%{$rules}) > 0) {
 3369:                 $datatable .= &user_formats_row('username',$settings,$rules,
 3370:                                                 $ruleorder,$numinrow,$rowcount);
 3371:                 $$rowtotal ++;
 3372:                 $rowcount ++;
 3373:             }
 3374:         }
 3375:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 3376:         if (ref($idrules) eq 'HASH') {
 3377:             if (keys(%{$idrules}) > 0) {
 3378:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 3379:                                                 $idruleorder,$numinrow,$rowcount);
 3380:                 $$rowtotal ++;
 3381:                 $rowcount ++;
 3382:             }
 3383:         }
 3384:         my ($emailrules,$emailruleorder) = 
 3385:             &Apache::lonnet::inst_userrules($dom,'email');
 3386:         if (ref($emailrules) eq 'HASH') {
 3387:             if (keys(%{$emailrules}) > 0) {
 3388:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 3389:                                                 $emailruleorder,$numinrow,$rowcount);
 3390:                 $$rowtotal ++;
 3391:                 $rowcount ++;
 3392:             }
 3393:         }
 3394:         if ($rowcount == 0) {
 3395:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 3396:             $$rowtotal ++;
 3397:             $rowcount ++;
 3398:         }
 3399:     } elsif ($position eq 'middle') {
 3400:         my @creators = ('author','course','requestcrs','selfcreate');
 3401:         my ($rules,$ruleorder) =
 3402:             &Apache::lonnet::inst_userrules($dom,'username');
 3403:         my %lt = &usercreation_types();
 3404:         my %checked;
 3405:         my @selfcreate; 
 3406:         if (ref($settings) eq 'HASH') {
 3407:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 3408:                 foreach my $item (@creators) {
 3409:                     $checked{$item} = $settings->{'cancreate'}{$item};
 3410:                 }
 3411:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
 3412:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
 3413:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
 3414:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 3415:                         @selfcreate = ('email','login','sso');
 3416:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
 3417:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
 3418:                     }
 3419:                 }
 3420:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 3421:                 foreach my $item (@creators) {
 3422:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 3423:                         $checked{$item} = 'none';
 3424:                     }
 3425:                 }
 3426:             }
 3427:         }
 3428:         my $rownum = 0;
 3429:         foreach my $item (@creators) {
 3430:             $rownum ++;
 3431:             if ($item ne 'selfcreate') {  
 3432:                 if ($checked{$item} eq '') {
 3433:                     $checked{$item} = 'any';
 3434:                 }
 3435:             }
 3436:             my $css_class;
 3437:             if ($rownum%2) {
 3438:                 $css_class = '';
 3439:             } else {
 3440:                 $css_class = ' class="LC_odd_row" ';
 3441:             }
 3442:             $datatable .= '<tr'.$css_class.'>'.
 3443:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 3444:                          '</span></td><td align="right">';
 3445:             my @options;
 3446:             if ($item eq 'selfcreate') {
 3447:                 push(@options,('email','login','sso'));
 3448:             } else {
 3449:                 @options = ('any');
 3450:                 if (ref($rules) eq 'HASH') {
 3451:                     if (keys(%{$rules}) > 0) {
 3452:                         push(@options,('official','unofficial'));
 3453:                     }
 3454:                 }
 3455:                 push(@options,'none');
 3456:             }
 3457:             foreach my $option (@options) {
 3458:                 my $type = 'radio';
 3459:                 my $check = ' ';
 3460:                 if ($item eq 'selfcreate') {
 3461:                     $type = 'checkbox';
 3462:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
 3463:                         $check = ' checked="checked" ';
 3464:                     }
 3465:                 } else {
 3466:                     if ($checked{$item} eq $option) {
 3467:                         $check = ' checked="checked" ';
 3468:                     }
 3469:                 } 
 3470:                 $datatable .= '<span class="LC_nobreak"><label>'.
 3471:                               '<input type="'.$type.'" name="can_createuser_'.
 3472:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 3473:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 3474:             }
 3475:             $datatable .= '</td></tr>';
 3476:         }
 3477:         my ($othertitle,$usertypes,$types) =
 3478:             &Apache::loncommon::sorted_inst_types($dom);
 3479:         my $createsettings;
 3480:         if (ref($settings) eq 'HASH') {
 3481:             $createsettings = $settings->{cancreate};
 3482:         }
 3483:         if (ref($usertypes) eq 'HASH') {
 3484:             if (keys(%{$usertypes}) > 0) {
 3485:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
 3486:                                              $dom,$numinrow,$othertitle,
 3487:                                              'statustocreate');
 3488:                 $$rowtotal ++;
 3489:                 $rownum ++;
 3490:             }
 3491:         }
 3492:         $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
 3493:     } else {
 3494:         my @contexts = ('author','course','domain');
 3495:         my @authtypes = ('int','krb4','krb5','loc');
 3496:         my %checked;
 3497:         if (ref($settings) eq 'HASH') {
 3498:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 3499:                 foreach my $item (@contexts) {
 3500:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 3501:                         foreach my $auth (@authtypes) {
 3502:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 3503:                                 $checked{$item}{$auth} = ' checked="checked" ';
 3504:                             }
 3505:                         }
 3506:                     }
 3507:                 }
 3508:             }
 3509:         } else {
 3510:             foreach my $item (@contexts) {
 3511:                 foreach my $auth (@authtypes) {
 3512:                     $checked{$item}{$auth} = ' checked="checked" ';
 3513:                 }
 3514:             }
 3515:         }
 3516:         my %title = &context_names();
 3517:         my %authname = &authtype_names();
 3518:         my $rownum = 0;
 3519:         my $css_class; 
 3520:         foreach my $item (@contexts) {
 3521:             if ($rownum%2) {
 3522:                 $css_class = '';
 3523:             } else {
 3524:                 $css_class = ' class="LC_odd_row" ';
 3525:             }
 3526:             $datatable .=   '<tr'.$css_class.'>'.
 3527:                             '<td>'.$title{$item}.
 3528:                             '</td><td class="LC_left_item">'.
 3529:                             '<span class="LC_nobreak">';
 3530:             foreach my $auth (@authtypes) {
 3531:                 $datatable .= '<label>'. 
 3532:                               '<input type="checkbox" name="'.$item.'_auth" '.
 3533:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 3534:                               $authname{$auth}.'</label>&nbsp;';
 3535:             }
 3536:             $datatable .= '</span></td></tr>';
 3537:             $rownum ++;
 3538:         }
 3539:         $$rowtotal += $rownum;
 3540:     }
 3541:     return $datatable;
 3542: }
 3543: 
 3544: sub captcha_choice {
 3545:     my ($context,$settings,$itemcount) = @_;
 3546:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
 3547:     my %lt = &captcha_phrases();
 3548:     $keyentry = 'hidden';
 3549:     if ($context eq 'cancreate') {
 3550:         $rowname = &mt('CAPTCHA validation (e-mail as username)');
 3551:     } elsif ($context eq 'login') {
 3552:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
 3553:     }
 3554:     if (ref($settings) eq 'HASH') {
 3555:         if ($settings->{'captcha'}) {
 3556:             $checked{$settings->{'captcha'}} = ' checked="checked"';
 3557:         } else {
 3558:             $checked{'original'} = ' checked="checked"';
 3559:         }
 3560:         if ($settings->{'captcha'} eq 'recaptcha') {
 3561:             $pubtext = $lt{'pub'};
 3562:             $privtext = $lt{'priv'};
 3563:             $keyentry = 'text';
 3564:         }
 3565:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
 3566:             $currpub = $settings->{'recaptchakeys'}{'public'};
 3567:             $currpriv = $settings->{'recaptchakeys'}{'private'};
 3568:         }
 3569:     } else {
 3570:         $checked{'original'} = ' checked="checked"';
 3571:     }
 3572:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3573:     my $output = '<tr'.$css_class.'>'.
 3574:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
 3575:                  '<table><tr><td>'."\n";
 3576:     foreach my $option ('original','recaptcha','notused') {
 3577:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
 3578:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
 3579:                    $lt{$option}.'</label></span>';
 3580:         unless ($option eq 'notused') {
 3581:             $output .= ('&nbsp;'x2)."\n";
 3582:         }
 3583:     }
 3584: #
 3585: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
 3586: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
 3587: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu) 
 3588: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
 3589: #  
 3590:     $output .= '</td></tr>'."\n".
 3591:                '<tr><td>'."\n".
 3592:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
 3593:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
 3594:                $currpub.'" size="40" /></span><br />'."\n".
 3595:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
 3596:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
 3597:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
 3598:                '</td></tr>';
 3599:     return $output;
 3600: }
 3601: 
 3602: sub user_formats_row {
 3603:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 3604:     my $output;
 3605:     my %text = (
 3606:                    'username' => 'new usernames',
 3607:                    'id'       => 'IDs',
 3608:                    'email'    => 'self-created accounts (e-mail)',
 3609:                );
 3610:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 3611:     $output = '<tr '.$css_class.'>'.
 3612:               '<td><span class="LC_nobreak">';
 3613:     if ($type eq 'email') {
 3614:         $output .= &mt("Formats disallowed for $text{$type}: ");
 3615:     } else {
 3616:         $output .= &mt("Format rules to check for $text{$type}: ");
 3617:     }
 3618:     $output .= '</span></td>'.
 3619:                '<td class="LC_left_item" colspan="2"><table>';
 3620:     my $rem;
 3621:     if (ref($ruleorder) eq 'ARRAY') {
 3622:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 3623:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 3624:                 my $rem = $i%($numinrow);
 3625:                 if ($rem == 0) {
 3626:                     if ($i > 0) {
 3627:                         $output .= '</tr>';
 3628:                     }
 3629:                     $output .= '<tr>';
 3630:                 }
 3631:                 my $check = ' ';
 3632:                 if (ref($settings) eq 'HASH') {
 3633:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 3634:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 3635:                             $check = ' checked="checked" ';
 3636:                         }
 3637:                     }
 3638:                 }
 3639:                 $output .= '<td class="LC_left_item">'.
 3640:                            '<span class="LC_nobreak"><label>'.
 3641:                            '<input type="checkbox" name="'.$type.'_rule" '.
 3642:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 3643:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 3644:             }
 3645:         }
 3646:         $rem = @{$ruleorder}%($numinrow);
 3647:     }
 3648:     my $colsleft = $numinrow - $rem;
 3649:     if ($colsleft > 1 ) {
 3650:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3651:                    '&nbsp;</td>';
 3652:     } elsif ($colsleft == 1) {
 3653:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 3654:     }
 3655:     $output .= '</tr></table></td></tr>';
 3656:     return $output;
 3657: }
 3658: 
 3659: sub usercreation_types {
 3660:     my %lt = &Apache::lonlocal::texthash (
 3661:                     author     => 'When adding a co-author',
 3662:                     course     => 'When adding a user to a course',
 3663:                     requestcrs => 'When requesting a course',
 3664:                     selfcreate => 'User creates own account', 
 3665:                     any        => 'Any',
 3666:                     official   => 'Institutional only ',
 3667:                     unofficial => 'Non-institutional only',
 3668:                     email      => 'E-mail address',
 3669:                     login      => 'Institutional Login',
 3670:                     sso        => 'SSO', 
 3671:                     none       => 'None',
 3672:     );
 3673:     return %lt;
 3674: }
 3675: 
 3676: sub authtype_names {
 3677:     my %lt = &Apache::lonlocal::texthash(
 3678:                       int    => 'Internal',
 3679:                       krb4   => 'Kerberos 4',
 3680:                       krb5   => 'Kerberos 5',
 3681:                       loc    => 'Local',
 3682:                   );
 3683:     return %lt;
 3684: }
 3685: 
 3686: sub context_names {
 3687:     my %context_title = &Apache::lonlocal::texthash(
 3688:        author => 'Creating users when an Author',
 3689:        course => 'Creating users when in a course',
 3690:        domain => 'Creating users when a Domain Coordinator',
 3691:     );
 3692:     return %context_title;
 3693: }
 3694: 
 3695: sub print_usermodification {
 3696:     my ($position,$dom,$settings,$rowtotal) = @_;
 3697:     my $numinrow = 4;
 3698:     my ($context,$datatable,$rowcount);
 3699:     if ($position eq 'top') {
 3700:         $rowcount = 0;
 3701:         $context = 'author'; 
 3702:         foreach my $role ('ca','aa') {
 3703:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 3704:                                                    $numinrow,$rowcount);
 3705:             $$rowtotal ++;
 3706:             $rowcount ++;
 3707:         }
 3708:     } elsif ($position eq 'middle') {
 3709:         $context = 'course';
 3710:         $rowcount = 0;
 3711:         foreach my $role ('st','ep','ta','in','cr') {
 3712:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 3713:                                                    $numinrow,$rowcount);
 3714:             $$rowtotal ++;
 3715:             $rowcount ++;
 3716:         }
 3717:     } elsif ($position eq 'bottom') {
 3718:         $context = 'selfcreate';
 3719:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3720:         $usertypes->{'default'} = $othertitle;
 3721:         if (ref($types) eq 'ARRAY') {
 3722:             push(@{$types},'default');
 3723:             $usertypes->{'default'} = $othertitle;
 3724:             foreach my $status (@{$types}) {
 3725:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
 3726:                                                        $numinrow,$rowcount,$usertypes);
 3727:                 $$rowtotal ++;
 3728:                 $rowcount ++;
 3729:             }
 3730:         }
 3731:     }
 3732:     return $datatable;
 3733: }
 3734: 
 3735: sub print_defaults {
 3736:     my ($dom,$rowtotal) = @_;
 3737:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 3738:                  'datelocale_def','portal_def');
 3739:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 3740:     my $titles = &defaults_titles($dom);
 3741:     my $rownum = 0;
 3742:     my ($datatable,$css_class);
 3743:     foreach my $item (@items) {
 3744:         if ($rownum%2) {
 3745:             $css_class = '';
 3746:         } else {
 3747:             $css_class = ' class="LC_odd_row" ';
 3748:         }
 3749:         $datatable .= '<tr'.$css_class.'>'.
 3750:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 3751:                   '</span></td><td class="LC_right_item">';
 3752:         if ($item eq 'auth_def') {
 3753:             my @authtypes = ('internal','krb4','krb5','localauth');
 3754:             my %shortauth = (
 3755:                              internal => 'int',
 3756:                              krb4 => 'krb4',
 3757:                              krb5 => 'krb5',
 3758:                              localauth  => 'loc'
 3759:                            );
 3760:             my %authnames = &authtype_names();
 3761:             foreach my $auth (@authtypes) {
 3762:                 my $checked = ' ';
 3763:                 if ($domdefaults{$item} eq $auth) {
 3764:                     $checked = ' checked="checked" ';
 3765:                 }
 3766:                 $datatable .= '<label><input type="radio" name="'.$item.
 3767:                               '" value="'.$auth.'"'.$checked.'/>'.
 3768:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 3769:             }
 3770:         } elsif ($item eq 'timezone_def') {
 3771:             my $includeempty = 1;
 3772:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
 3773:         } elsif ($item eq 'datelocale_def') {
 3774:             my $includeempty = 1;
 3775:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
 3776:         } elsif ($item eq 'lang_def') {
 3777:             my %langchoices = &get_languages_hash();
 3778:             $langchoices{''} = 'No language preference';
 3779:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
 3780:             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
 3781:                                                           \%langchoices);
 3782:         } else {
 3783:             my $size;
 3784:             if ($item eq 'portal_def') {
 3785:                 $size = ' size="25"';
 3786:             }
 3787:             $datatable .= '<input type="text" name="'.$item.'" value="'.
 3788:                           $domdefaults{$item}.'"'.$size.' />';
 3789:         }
 3790:         $datatable .= '</td></tr>';
 3791:         $rownum ++;
 3792:     }
 3793:     $$rowtotal += $rownum;
 3794:     return $datatable;
 3795: }
 3796: 
 3797: sub get_languages_hash {
 3798:     my %langchoices;
 3799:     foreach my $id (&Apache::loncommon::languageids()) {
 3800:         my $code = &Apache::loncommon::supportedlanguagecode($id);
 3801:         if ($code ne '') {
 3802:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
 3803:         }
 3804:     }
 3805:     return %langchoices;
 3806: }
 3807: 
 3808: sub defaults_titles {
 3809:     my ($dom) = @_;
 3810:     my %titles = &Apache::lonlocal::texthash (
 3811:                    'auth_def'      => 'Default authentication type',
 3812:                    'auth_arg_def'  => 'Default authentication argument',
 3813:                    'lang_def'      => 'Default language',
 3814:                    'timezone_def'  => 'Default timezone',
 3815:                    'datelocale_def' => 'Default locale for dates',
 3816:                    'portal_def'     => 'Portal/Default URL',
 3817:                  );
 3818:     if ($dom) {
 3819:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
 3820:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
 3821:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
 3822:         $protocol = 'http' if ($protocol ne 'https');
 3823:         if ($uint_dom) {
 3824:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
 3825:                                          $uint_dom);
 3826:         }
 3827:     }
 3828:     return (\%titles);
 3829: }
 3830: 
 3831: sub print_scantronformat {
 3832:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 3833:     my $itemcount = 1;
 3834:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 3835:         %confhash);
 3836:     my $switchserver = &check_switchserver($dom,$confname);
 3837:     my %lt = &Apache::lonlocal::texthash (
 3838:                 default => 'Default bubblesheet format file error',
 3839:                 custom  => 'Custom bubblesheet format file error',
 3840:              );
 3841:     my %scantronfiles = (
 3842:         default => 'default.tab',
 3843:         custom => 'custom.tab',
 3844:     );
 3845:     foreach my $key (keys(%scantronfiles)) {
 3846:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 3847:                               .$scantronfiles{$key};
 3848:     }
 3849:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 3850:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 3851:         if (!$switchserver) {
 3852:             my $servadm = $r->dir_config('lonAdmEMail');
 3853:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 3854:             if ($configuserok eq 'ok') {
 3855:                 if ($author_ok eq 'ok') {
 3856:                     my %legacyfile = (
 3857:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 3858:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 3859:                     );
 3860:                     my %md5chk;
 3861:                     foreach my $type (keys(%legacyfile)) {
 3862:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 3863:                         chomp($md5chk{$type});
 3864:                     }
 3865:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 3866:                         foreach my $type (keys(%legacyfile)) {
 3867:                             ($scantronurls{$type},my $error) = 
 3868:                                 &legacy_scantronformat($r,$dom,$confname,
 3869:                                                  $type,$legacyfile{$type},
 3870:                                                  $scantronurls{$type},
 3871:                                                  $scantronfiles{$type});
 3872:                             if ($error ne '') {
 3873:                                 $error{$type} = $error;
 3874:                             }
 3875:                         }
 3876:                         if (keys(%error) == 0) {
 3877:                             $is_custom = 1;
 3878:                             $confhash{'scantron'}{'scantronformat'} = 
 3879:                                 $scantronurls{'custom'};
 3880:                             my $putresult = 
 3881:                                 &Apache::lonnet::put_dom('configuration',
 3882:                                                          \%confhash,$dom);
 3883:                             if ($putresult ne 'ok') {
 3884:                                 $error{'custom'} = 
 3885:                                     '<span class="LC_error">'.
 3886:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 3887:                             }
 3888:                         }
 3889:                     } else {
 3890:                         ($scantronurls{'default'},my $error) =
 3891:                             &legacy_scantronformat($r,$dom,$confname,
 3892:                                           'default',$legacyfile{'default'},
 3893:                                           $scantronurls{'default'},
 3894:                                           $scantronfiles{'default'});
 3895:                         if ($error eq '') {
 3896:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 3897:                             my $putresult =
 3898:                                 &Apache::lonnet::put_dom('configuration',
 3899:                                                          \%confhash,$dom);
 3900:                             if ($putresult ne 'ok') {
 3901:                                 $error{'default'} =
 3902:                                     '<span class="LC_error">'.
 3903:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 3904:                             }
 3905:                         } else {
 3906:                             $error{'default'} = $error;
 3907:                         }
 3908:                     }
 3909:                 }
 3910:             }
 3911:         } else {
 3912:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
 3913:         }
 3914:     }
 3915:     if (ref($settings) eq 'HASH') {
 3916:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 3917:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 3918:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 3919:                 $scantronurl = '';
 3920:             } else {
 3921:                 $scantronurl = $settings->{'scantronformat'};
 3922:             }
 3923:             $is_custom = 1;
 3924:         } else {
 3925:             $scantronurl = $scantronurls{'default'};
 3926:         }
 3927:     } else {
 3928:         if ($is_custom) {
 3929:             $scantronurl = $scantronurls{'custom'};
 3930:         } else {
 3931:             $scantronurl = $scantronurls{'default'};
 3932:         }
 3933:     }
 3934:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3935:     $datatable .= '<tr'.$css_class.'>';
 3936:     if (!$is_custom) {
 3937:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 3938:                       '<span class="LC_nobreak">';
 3939:         if ($scantronurl) {
 3940:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
 3941:                                                          undef,undef,undef,undef,'background-color:#ffffff');
 3942:         } else {
 3943:             $datatable = &mt('File unavailable for display');
 3944:         }
 3945:         $datatable .= '</span></td>';
 3946:         if (keys(%error) == 0) { 
 3947:             $datatable .= '<td valign="bottom">';
 3948:             if (!$switchserver) {
 3949:                 $datatable .= &mt('Upload:').'<br />';
 3950:             }
 3951:         } else {
 3952:             my $errorstr;
 3953:             foreach my $key (sort(keys(%error))) {
 3954:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 3955:             }
 3956:             $datatable .= '<td>'.$errorstr;
 3957:         }
 3958:     } else {
 3959:         if (keys(%error) > 0) {
 3960:             my $errorstr;
 3961:             foreach my $key (sort(keys(%error))) {
 3962:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 3963:             } 
 3964:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 3965:         } elsif ($scantronurl) {
 3966:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
 3967:                                                        undef,undef,undef,undef,'background-color:#ffffff');
 3968:             $datatable .= '<td><span class="LC_nobreak">'.
 3969:                           $link.
 3970:                           '<label><input type="checkbox" name="scantronformat_del"'.
 3971:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
 3972:                           '<td><span class="LC_nobreak">&nbsp;'.
 3973:                           &mt('Replace:').'</span><br />';
 3974:         }
 3975:     }
 3976:     if (keys(%error) == 0) {
 3977:         if ($switchserver) {
 3978:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 3979:         } else {
 3980:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 3981:                          '<input type="file" name="scantronformat" /></span>';
 3982:         }
 3983:     }
 3984:     $datatable .= '</td></tr>';
 3985:     $$rowtotal ++;
 3986:     return $datatable;
 3987: }
 3988: 
 3989: sub legacy_scantronformat {
 3990:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 3991:     my ($url,$error);
 3992:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 3993:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 3994:         (my $result,$url) =
 3995:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 3996:                          '','',$newfile);
 3997:         if ($result ne 'ok') {
 3998:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
 3999:         }
 4000:     }
 4001:     return ($url,$error);
 4002: }
 4003: 
 4004: sub print_coursecategories {
 4005:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 4006:     my $datatable;
 4007:     if ($position eq 'top') {
 4008:         my $toggle_cats_crs = ' ';
 4009:         my $toggle_cats_dom = ' checked="checked" ';
 4010:         my $can_cat_crs = ' ';
 4011:         my $can_cat_dom = ' checked="checked" ';
 4012:         my $toggle_catscomm_comm = ' ';
 4013:         my $toggle_catscomm_dom = ' checked="checked" ';
 4014:         my $can_catcomm_comm = ' ';
 4015:         my $can_catcomm_dom = ' checked="checked" ';
 4016: 
 4017:         if (ref($settings) eq 'HASH') {
 4018:             if ($settings->{'togglecats'} eq 'crs') {
 4019:                 $toggle_cats_crs = $toggle_cats_dom;
 4020:                 $toggle_cats_dom = ' ';
 4021:             }
 4022:             if ($settings->{'categorize'} eq 'crs') {
 4023:                 $can_cat_crs = $can_cat_dom;
 4024:                 $can_cat_dom = ' ';
 4025:             }
 4026:             if ($settings->{'togglecatscomm'} eq 'comm') {
 4027:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
 4028:                 $toggle_catscomm_dom = ' ';
 4029:             }
 4030:             if ($settings->{'categorizecomm'} eq 'comm') {
 4031:                 $can_catcomm_comm = $can_catcomm_dom;
 4032:                 $can_catcomm_dom = ' ';
 4033:             }
 4034:         }
 4035:         my %title = &Apache::lonlocal::texthash (
 4036:                      togglecats     => 'Show/Hide a course in catalog',
 4037:                      togglecatscomm => 'Show/Hide a community in catalog',
 4038:                      categorize     => 'Assign a category to a course',
 4039:                      categorizecomm => 'Assign a category to a community',
 4040:                     );
 4041:         my %level = &Apache::lonlocal::texthash (
 4042:                      dom  => 'Set in Domain',
 4043:                      crs  => 'Set in Course',
 4044:                      comm => 'Set in Community',
 4045:                     );
 4046:         $datatable = '<tr class="LC_odd_row">'.
 4047:                   '<td>'.$title{'togglecats'}.'</td>'.
 4048:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 4049:                   '<input type="radio" name="togglecats"'.
 4050:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4051:                   '<label><input type="radio" name="togglecats"'.
 4052:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 4053:                   '</tr><tr>'.
 4054:                   '<td>'.$title{'categorize'}.'</td>'.
 4055:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 4056:                   '<label><input type="radio" name="categorize"'.
 4057:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4058:                   '<label><input type="radio" name="categorize"'.
 4059:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 4060:                   '</tr><tr class="LC_odd_row">'.
 4061:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
 4062:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 4063:                   '<input type="radio" name="togglecatscomm"'.
 4064:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4065:                   '<label><input type="radio" name="togglecatscomm"'.
 4066:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
 4067:                   '</tr><tr>'.
 4068:                   '<td>'.$title{'categorizecomm'}.'</td>'.
 4069:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 4070:                   '<label><input type="radio" name="categorizecomm"'.
 4071:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4072:                   '<label><input type="radio" name="categorizecomm"'.
 4073:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
 4074:                   '</tr>';
 4075:         $$rowtotal += 4;
 4076:     } else {
 4077:         my $css_class;
 4078:         my $itemcount = 1;
 4079:         my $cathash; 
 4080:         if (ref($settings) eq 'HASH') {
 4081:             $cathash = $settings->{'cats'};
 4082:         }
 4083:         if (ref($cathash) eq 'HASH') {
 4084:             my (@cats,@trails,%allitems,%idx,@jsarray);
 4085:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 4086:                                                    \%allitems,\%idx,\@jsarray);
 4087:             my $maxdepth = scalar(@cats);
 4088:             my $colattrib = '';
 4089:             if ($maxdepth > 2) {
 4090:                 $colattrib = ' colspan="2" ';
 4091:             }
 4092:             my @path;
 4093:             if (@cats > 0) {
 4094:                 if (ref($cats[0]) eq 'ARRAY') {
 4095:                     my $numtop = @{$cats[0]};
 4096:                     my $maxnum = $numtop;
 4097:                     my %default_names = (
 4098:                           instcode    => &mt('Official courses'),
 4099:                           communities => &mt('Communities'),
 4100:                     );
 4101: 
 4102:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
 4103:                         ($cathash->{'instcode::0'} eq '') ||
 4104:                         (!grep(/^communities$/,@{$cats[0]})) || 
 4105:                         ($cathash->{'communities::0'} eq '')) {
 4106:                         $maxnum ++;
 4107:                     }
 4108:                     my $lastidx;
 4109:                     for (my $i=0; $i<$numtop; $i++) {
 4110:                         my $parent = $cats[0][$i];
 4111:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4112:                         my $item = &escape($parent).'::0';
 4113:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 4114:                         $lastidx = $idx{$item};
 4115:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4116:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 4117:                         for (my $k=0; $k<=$maxnum; $k++) {
 4118:                             my $vpos = $k+1;
 4119:                             my $selstr;
 4120:                             if ($k == $i) {
 4121:                                 $selstr = ' selected="selected" ';
 4122:                             }
 4123:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4124:                         }
 4125:                         $datatable .= '</select></td><td>';
 4126:                         if ($parent eq 'instcode' || $parent eq 'communities') {
 4127:                             $datatable .=  '<span class="LC_nobreak">'
 4128:                                            .$default_names{$parent}.'</span>';
 4129:                             if ($parent eq 'instcode') {
 4130:                                 $datatable .= '<br /><span class="LC_nobreak">('
 4131:                                               .&mt('with institutional codes')
 4132:                                               .')</span></td><td'.$colattrib.'>';
 4133:                             } else {
 4134:                                 $datatable .= '<table><tr><td>';
 4135:                             }
 4136:                             $datatable .= '<span class="LC_nobreak">'
 4137:                                           .'<label><input type="radio" name="'
 4138:                                           .$parent.'" value="1" checked="checked" />'
 4139:                                           .&mt('Display').'</label>';
 4140:                             if ($parent eq 'instcode') {
 4141:                                 $datatable .= '&nbsp;';
 4142:                             } else {
 4143:                                 $datatable .= '</span></td></tr><tr><td>'
 4144:                                               .'<span class="LC_nobreak">';
 4145:                             }
 4146:                             $datatable .= '<label><input type="radio" name="'
 4147:                                           .$parent.'" value="0" />'
 4148:                                           .&mt('Do not display').'</label></span>';
 4149:                             if ($parent eq 'communities') {
 4150:                                 $datatable .= '</td></tr></table>';
 4151:                             }
 4152:                             $datatable .= '</td>';
 4153:                         } else {
 4154:                             $datatable .= $parent
 4155:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
 4156:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 4157:                         }
 4158:                         my $depth = 1;
 4159:                         push(@path,$parent);
 4160:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 4161:                         pop(@path);
 4162:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 4163:                         $itemcount ++;
 4164:                     }
 4165:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4166:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 4167:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 4168:                     for (my $k=0; $k<=$maxnum; $k++) {
 4169:                         my $vpos = $k+1;
 4170:                         my $selstr;
 4171:                         if ($k == $numtop) {
 4172:                             $selstr = ' selected="selected" ';
 4173:                         }
 4174:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4175:                     }
 4176:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 4177:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 4178:                                   .'</tr>'."\n";
 4179:                     $itemcount ++;
 4180:                     foreach my $default ('instcode','communities') {
 4181:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
 4182:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4183:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
 4184:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 4185:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
 4186:                             for (my $k=0; $k<=$maxnum; $k++) {
 4187:                                 my $vpos = $k+1;
 4188:                                 my $selstr;
 4189:                                 if ($k == $maxnum) {
 4190:                                     $selstr = ' selected="selected" ';
 4191:                                 }
 4192:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4193:                             }
 4194:                             $datatable .= '</select></span></td>'.
 4195:                                           '<td><span class="LC_nobreak">'.
 4196:                                           $default_names{$default}.'</span>';
 4197:                             if ($default eq 'instcode') {
 4198:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
 4199:                                               .&mt('with institutional codes').')</span>';
 4200:                             }
 4201:                             $datatable .= '</td>'
 4202:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
 4203:                                           .&mt('Display').'</label>&nbsp;'
 4204:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
 4205:                                           .&mt('Do not display').'</label></span></td></tr>';
 4206:                         }
 4207:                     }
 4208:                 }
 4209:             } else {
 4210:                 $datatable .= &initialize_categories($itemcount);
 4211:             }
 4212:         } else {
 4213:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
 4214:                           .&initialize_categories($itemcount);
 4215:         }
 4216:         $$rowtotal += $itemcount;
 4217:     }
 4218:     return $datatable;
 4219: }
 4220: 
 4221: sub print_serverstatuses {
 4222:     my ($dom,$settings,$rowtotal) = @_;
 4223:     my $datatable;
 4224:     my @pages = &serverstatus_pages();
 4225:     my (%namedaccess,%machineaccess);
 4226:     foreach my $type (@pages) {
 4227:         $namedaccess{$type} = '';
 4228:         $machineaccess{$type}= '';
 4229:     }
 4230:     if (ref($settings) eq 'HASH') {
 4231:         foreach my $type (@pages) {
 4232:             if (exists($settings->{$type})) {
 4233:                 if (ref($settings->{$type}) eq 'HASH') {
 4234:                     foreach my $key (keys(%{$settings->{$type}})) {
 4235:                         if ($key eq 'namedusers') {
 4236:                             $namedaccess{$type} = $settings->{$type}->{$key};
 4237:                         } elsif ($key eq 'machines') {
 4238:                             $machineaccess{$type} = $settings->{$type}->{$key};
 4239:                         }
 4240:                     }
 4241:                 }
 4242:             }
 4243:         }
 4244:     }
 4245:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 4246:     my $rownum = 0;
 4247:     my $css_class;
 4248:     foreach my $type (@pages) {
 4249:         $rownum ++;
 4250:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 4251:         $datatable .= '<tr'.$css_class.'>'.
 4252:                       '<td><span class="LC_nobreak">'.
 4253:                       $titles->{$type}.'</span></td>'.
 4254:                       '<td class="LC_left_item">'.
 4255:                       '<input type="text" name="'.$type.'_namedusers" '.
 4256:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 4257:                       '<td class="LC_right_item">'.
 4258:                       '<span class="LC_nobreak">'.
 4259:                       '<input type="text" name="'.$type.'_machines" '.
 4260:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 4261:                       '</td></tr>'."\n";
 4262:     }
 4263:     $$rowtotal += $rownum;
 4264:     return $datatable;
 4265: }
 4266: 
 4267: sub serverstatus_pages {
 4268:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 4269:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
 4270:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
 4271: }
 4272: 
 4273: sub coursecategories_javascript {
 4274:     my ($settings) = @_;
 4275:     my ($output,$jstext,$cathash);
 4276:     if (ref($settings) eq 'HASH') {
 4277:         $cathash = $settings->{'cats'};
 4278:     }
 4279:     if (ref($cathash) eq 'HASH') {
 4280:         my (@cats,@jsarray,%idx);
 4281:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 4282:         if (@jsarray > 0) {
 4283:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 4284:             for (my $i=0; $i<@jsarray; $i++) {
 4285:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 4286:                     my $catstr = join('","',@{$jsarray[$i]});
 4287:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 4288:                 }
 4289:             }
 4290:         }
 4291:     } else {
 4292:         $jstext  = '    var categories = Array(1);'."\n".
 4293:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 4294:     }
 4295:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
 4296:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
 4297:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
 4298:     $output = <<"ENDSCRIPT";
 4299: <script type="text/javascript">
 4300: // <![CDATA[
 4301: function reorderCats(form,parent,item,idx) {
 4302:     var changedVal;
 4303: $jstext
 4304:     var newpos = 'addcategory_pos';
 4305:     var current = new Array;
 4306:     if (parent == '') {
 4307:         var has_instcode = 0;
 4308:         var maxtop = categories[idx].length;
 4309:         for (var j=0; j<maxtop; j++) {
 4310:             if (categories[idx][j] == 'instcode::0') {
 4311:                 has_instcode == 1;
 4312:             }
 4313:         }
 4314:         if (has_instcode == 0) {
 4315:             categories[idx][maxtop] = 'instcode_pos';
 4316:         }
 4317:     } else {
 4318:         newpos += '_'+parent;
 4319:     }
 4320:     var maxh = 1 + categories[idx].length;
 4321:     var current = new Array;
 4322:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 4323:     if (item == newpos) {
 4324:         changedVal = newitemVal;
 4325:     } else {
 4326:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 4327:         current[newitemVal] = newpos;
 4328:     }
 4329:     for (var i=0; i<categories[idx].length; i++) {
 4330:         var elementName = categories[idx][i];
 4331:         if (elementName != item) {
 4332:             if (form.elements[elementName]) {
 4333:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 4334:                 current[currVal] = elementName;
 4335:             }
 4336:         }
 4337:     }
 4338:     var oldVal;
 4339:     for (var j=0; j<maxh; j++) {
 4340:         if (current[j] == undefined) {
 4341:             oldVal = j;
 4342:         }
 4343:     }
 4344:     if (oldVal < changedVal) {
 4345:         for (var k=oldVal+1; k<=changedVal ; k++) {
 4346:            var elementName = current[k];
 4347:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 4348:         }
 4349:     } else {
 4350:         for (var k=changedVal; k<oldVal; k++) {
 4351:             var elementName = current[k];
 4352:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 4353:         }
 4354:     }
 4355:     return;
 4356: }
 4357: 
 4358: function categoryCheck(form) {
 4359:     if (form.elements['addcategory_name'].value == 'instcode') {
 4360:         alert('$instcode_reserved\\n$choose_again');
 4361:         return false;
 4362:     }
 4363:     if (form.elements['addcategory_name'].value == 'communities') {
 4364:         alert('$communities_reserved\\n$choose_again');
 4365:         return false;
 4366:     }
 4367:     return true;
 4368: }
 4369: 
 4370: // ]]>
 4371: </script>
 4372: 
 4373: ENDSCRIPT
 4374:     return $output;
 4375: }
 4376: 
 4377: sub initialize_categories {
 4378:     my ($itemcount) = @_;
 4379:     my ($datatable,$css_class,$chgstr);
 4380:     my %default_names = (
 4381:                       instcode    => 'Official courses (with institutional codes)',
 4382:                       communities => 'Communities',
 4383:                         );
 4384:     my $select0 = ' selected="selected"';
 4385:     my $select1 = '';
 4386:     foreach my $default ('instcode','communities') {
 4387:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4388:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
 4389:         if ($default eq 'communities') {
 4390:             $select1 = $select0;
 4391:             $select0 = '';
 4392:         }
 4393:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4394:                      .'<select name="'.$default.'_pos">'
 4395:                      .'<option value="0"'.$select0.'>1</option>'
 4396:                      .'<option value="1"'.$select1.'>2</option>'
 4397:                      .'<option value="2">3</option></select>&nbsp;'
 4398:                      .$default_names{$default}
 4399:                      .'</span></td><td><span class="LC_nobreak">'
 4400:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
 4401:                      .&mt('Display').'</label>&nbsp;<label>'
 4402:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
 4403:                  .'</label></span></td></tr>';
 4404:         $itemcount ++;
 4405:     }
 4406:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4407:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 4408:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4409:                   .'<select name="addcategory_pos"'.$chgstr.'>'
 4410:                   .'<option value="0">1</option>'
 4411:                   .'<option value="1">2</option>'
 4412:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
 4413:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 4414:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 4415:     return $datatable;
 4416: }
 4417: 
 4418: sub build_category_rows {
 4419:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 4420:     my ($text,$name,$item,$chgstr);
 4421:     if (ref($cats) eq 'ARRAY') {
 4422:         my $maxdepth = scalar(@{$cats});
 4423:         if (ref($cats->[$depth]) eq 'HASH') {
 4424:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 4425:                 my $numchildren = @{$cats->[$depth]{$parent}};
 4426:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4427:                 $text .= '<td><table class="LC_datatable">';
 4428:                 my ($idxnum,$parent_name,$parent_item);
 4429:                 my $higher = $depth - 1;
 4430:                 if ($higher == 0) {
 4431:                     $parent_name = &escape($parent).'::'.$higher;
 4432:                 } else {
 4433:                     if (ref($path) eq 'ARRAY') {
 4434:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 4435:                     }
 4436:                 }
 4437:                 $parent_item = 'addcategory_pos_'.$parent_name;
 4438:                 for (my $j=0; $j<=$numchildren; $j++) {
 4439:                     if ($j < $numchildren) {
 4440:                         $name = $cats->[$depth]{$parent}[$j];
 4441:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 4442:                         $idxnum = $idx->{$item};
 4443:                     } else {
 4444:                         $name = $parent_name;
 4445:                         $item = $parent_item;
 4446:                     }
 4447:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 4448:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 4449:                     for (my $i=0; $i<=$numchildren; $i++) {
 4450:                         my $vpos = $i+1;
 4451:                         my $selstr;
 4452:                         if ($j == $i) {
 4453:                             $selstr = ' selected="selected" ';
 4454:                         }
 4455:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 4456:                     }
 4457:                     $text .= '</select>&nbsp;';
 4458:                     if ($j < $numchildren) {
 4459:                         my $deeper = $depth+1;
 4460:                         $text .= $name.'&nbsp;'
 4461:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 4462:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 4463:                         if(ref($path) eq 'ARRAY') {
 4464:                             push(@{$path},$name);
 4465:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 4466:                             pop(@{$path});
 4467:                         }
 4468:                     } else {
 4469:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 4470:                         if ($j == $numchildren) {
 4471:                             $text .= $name;
 4472:                         } else {
 4473:                             $text .= $item;
 4474:                         }
 4475:                         $text .= '" value="" />';
 4476:                     }
 4477:                     $text .= '</td></tr>';
 4478:                 }
 4479:                 $text .= '</table></td>';
 4480:             } else {
 4481:                 my $higher = $depth-1;
 4482:                 if ($higher == 0) {
 4483:                     $name = &escape($parent).'::'.$higher;
 4484:                 } else {
 4485:                     if (ref($path) eq 'ARRAY') {
 4486:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 4487:                     }
 4488:                 }
 4489:                 my $colspan;
 4490:                 if ($parent ne 'instcode') {
 4491:                     $colspan = $maxdepth - $depth - 1;
 4492:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 4493:                 }
 4494:             }
 4495:         }
 4496:     }
 4497:     return $text;
 4498: }
 4499: 
 4500: sub modifiable_userdata_row {
 4501:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
 4502:     my $rolename;
 4503:     if ($context eq 'selfcreate') {
 4504:         if (ref($usertypes) eq 'HASH') {
 4505:             $rolename = $usertypes->{$role};
 4506:         } else {
 4507:             $rolename = $role;
 4508:         }
 4509:     } else {
 4510:         if ($role eq 'cr') {
 4511:             $rolename = &mt('Custom role');
 4512:         } else {
 4513:             $rolename = &Apache::lonnet::plaintext($role);
 4514:         }
 4515:     }
 4516:     my @fields = ('lastname','firstname','middlename','generation',
 4517:                   'permanentemail','id');
 4518:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 4519:     my $output;
 4520:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 4521:     $output = '<tr '.$css_class.'>'.
 4522:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 4523:               '<td class="LC_left_item" colspan="2"><table>';
 4524:     my $rem;
 4525:     my %checks;
 4526:     if (ref($settings) eq 'HASH') {
 4527:         if (ref($settings->{$context}) eq 'HASH') {
 4528:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 4529:                 foreach my $field (@fields) {
 4530:                     if ($settings->{$context}->{$role}->{$field}) {
 4531:                         $checks{$field} = ' checked="checked" ';
 4532:                     }
 4533:                 }
 4534:             }
 4535:         }
 4536:     }
 4537:     for (my $i=0; $i<@fields; $i++) {
 4538:         my $rem = $i%($numinrow);
 4539:         if ($rem == 0) {
 4540:             if ($i > 0) {
 4541:                 $output .= '</tr>';
 4542:             }
 4543:             $output .= '<tr>';
 4544:         }
 4545:         my $check = ' ';
 4546:         if (exists($checks{$fields[$i]})) {
 4547:             $check = $checks{$fields[$i]}
 4548:         } else {
 4549:             if ($role eq 'st') {
 4550:                 if (ref($settings) ne 'HASH') {
 4551:                     $check = ' checked="checked" '; 
 4552:                 }
 4553:             }
 4554:         }
 4555:         $output .= '<td class="LC_left_item">'.
 4556:                    '<span class="LC_nobreak"><label>'.
 4557:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 4558:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 4559:                    '</label></span></td>';
 4560:         $rem = @fields%($numinrow);
 4561:     }
 4562:     my $colsleft = $numinrow - $rem;
 4563:     if ($colsleft > 1 ) {
 4564:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 4565:                    '&nbsp;</td>';
 4566:     } elsif ($colsleft == 1) {
 4567:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 4568:     }
 4569:     $output .= '</tr></table></td></tr>';
 4570:     return $output;
 4571: }
 4572: 
 4573: sub insttypes_row {
 4574:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
 4575:     my %lt = &Apache::lonlocal::texthash (
 4576:                       cansearch => 'Users allowed to search',
 4577:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
 4578:                       lockablenames => 'User preference to lock name',
 4579:              );
 4580:     my $showdom;
 4581:     if ($context eq 'cansearch') {
 4582:         $showdom = ' ('.$dom.')';
 4583:     }
 4584:     my $class = 'LC_left_item';
 4585:     if ($context eq 'statustocreate') {
 4586:         $class = 'LC_right_item';
 4587:     }
 4588:     my $output =  '<tr class="LC_odd_row">'.
 4589:                   '<td>'.$lt{$context}.$showdom.
 4590:                   '</td><td class="'.$class.'" colspan="2"><table>';
 4591:     my $rem;
 4592:     if (ref($types) eq 'ARRAY') {
 4593:         for (my $i=0; $i<@{$types}; $i++) {
 4594:             if (defined($usertypes->{$types->[$i]})) {
 4595:                 my $rem = $i%($numinrow);
 4596:                 if ($rem == 0) {
 4597:                     if ($i > 0) {
 4598:                         $output .= '</tr>';
 4599:                     }
 4600:                     $output .= '<tr>';
 4601:                 }
 4602:                 my $check = ' ';
 4603:                 if (ref($settings) eq 'HASH') {
 4604:                     if (ref($settings->{$context}) eq 'ARRAY') {
 4605:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
 4606:                             $check = ' checked="checked" ';
 4607:                         }
 4608:                     } elsif ($context eq 'statustocreate') {
 4609:                         $check = ' checked="checked" ';
 4610:                     }
 4611:                 }
 4612:                 $output .= '<td class="LC_left_item">'.
 4613:                            '<span class="LC_nobreak"><label>'.
 4614:                            '<input type="checkbox" name="'.$context.'" '.
 4615:                            'value="'.$types->[$i].'"'.$check.'/>'.
 4616:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 4617:             }
 4618:         }
 4619:         $rem = @{$types}%($numinrow);
 4620:     }
 4621:     my $colsleft = $numinrow - $rem;
 4622:     if (($rem == 0) && (@{$types} > 0)) {
 4623:         $output .= '<tr>';
 4624:     }
 4625:     if ($colsleft > 1) {
 4626:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 4627:     } else {
 4628:         $output .= '<td class="LC_left_item">';
 4629:     }
 4630:     my $defcheck = ' ';
 4631:     if (ref($settings) eq 'HASH') {  
 4632:         if (ref($settings->{$context}) eq 'ARRAY') {
 4633:             if (grep(/^default$/,@{$settings->{$context}})) {
 4634:                 $defcheck = ' checked="checked" ';
 4635:             }
 4636:         } elsif ($context eq 'statustocreate') {
 4637:             $defcheck = ' checked="checked" ';
 4638:         }
 4639:     }
 4640:     $output .= '<span class="LC_nobreak"><label>'.
 4641:                '<input type="checkbox" name="'.$context.'" '.
 4642:                'value="default"'.$defcheck.'/>'.
 4643:                $othertitle.'</label></span></td>'.
 4644:                '</tr></table></td></tr>';
 4645:     return $output;
 4646: }
 4647: 
 4648: sub sorted_searchtitles {
 4649:     my %searchtitles = &Apache::lonlocal::texthash(
 4650:                          'uname' => 'username',
 4651:                          'lastname' => 'last name',
 4652:                          'lastfirst' => 'last name, first name',
 4653:                      );
 4654:     my @titleorder = ('uname','lastname','lastfirst');
 4655:     return (\%searchtitles,\@titleorder);
 4656: }
 4657: 
 4658: sub sorted_searchtypes {
 4659:     my %srchtypes_desc = (
 4660:                            exact    => 'is exact match',
 4661:                            contains => 'contains ..',
 4662:                            begins   => 'begins with ..',
 4663:                          );
 4664:     my @srchtypeorder = ('exact','begins','contains');
 4665:     return (\%srchtypes_desc,\@srchtypeorder);
 4666: }
 4667: 
 4668: sub usertype_update_row {
 4669:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 4670:     my $datatable;
 4671:     my $numinrow = 4;
 4672:     foreach my $type (@{$types}) {
 4673:         if (defined($usertypes->{$type})) {
 4674:             $$rownums ++;
 4675:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 4676:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 4677:                           '</td><td class="LC_left_item"><table>';
 4678:             for (my $i=0; $i<@{$fields}; $i++) {
 4679:                 my $rem = $i%($numinrow);
 4680:                 if ($rem == 0) {
 4681:                     if ($i > 0) {
 4682:                         $datatable .= '</tr>';
 4683:                     }
 4684:                     $datatable .= '<tr>';
 4685:                 }
 4686:                 my $check = ' ';
 4687:                 if (ref($settings) eq 'HASH') {
 4688:                     if (ref($settings->{'fields'}) eq 'HASH') {
 4689:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 4690:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 4691:                                 $check = ' checked="checked" ';
 4692:                             }
 4693:                         }
 4694:                     }
 4695:                 }
 4696: 
 4697:                 if ($i == @{$fields}-1) {
 4698:                     my $colsleft = $numinrow - $rem;
 4699:                     if ($colsleft > 1) {
 4700:                         $datatable .= '<td colspan="'.$colsleft.'">';
 4701:                     } else {
 4702:                         $datatable .= '<td>';
 4703:                     }
 4704:                 } else {
 4705:                     $datatable .= '<td>';
 4706:                 }
 4707:                 $datatable .= '<span class="LC_nobreak"><label>'.
 4708:                               '<input type="checkbox" name="updateable_'.$type.
 4709:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 4710:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 4711:             }
 4712:             $datatable .= '</tr></table></td></tr>';
 4713:         }
 4714:     }
 4715:     return $datatable;
 4716: }
 4717: 
 4718: sub modify_login {
 4719:     my ($r,$dom,$confname,%domconfig) = @_;
 4720:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
 4721:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
 4722:     %title = ( coursecatalog => 'Display course catalog',
 4723:                adminmail => 'Display administrator E-mail address',
 4724:                helpdesk  => 'Display "Contact Helpdesk" link',
 4725:                newuser => 'Link for visitors to create a user account',
 4726:                loginheader => 'Log-in box header');
 4727:     @offon = ('off','on');
 4728:     if (ref($domconfig{login}) eq 'HASH') {
 4729:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
 4730:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
 4731:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
 4732:             }
 4733:         }
 4734:     }
 4735:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 4736:                                            \%domconfig,\%loginhash);
 4737:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 4738:     foreach my $item (@toggles) {
 4739:         $loginhash{login}{$item} = $env{'form.'.$item};
 4740:     }
 4741:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 4742:     if (ref($colchanges{'login'}) eq 'HASH') {  
 4743:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 4744:                                          \%loginhash);
 4745:     }
 4746: 
 4747:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 4748:     my @loginvia_attribs = ('serverpath','custompath','exempt');
 4749:     if (keys(%servers) > 1) {
 4750:         foreach my $lonhost (keys(%servers)) {
 4751:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
 4752:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
 4753:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
 4754:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
 4755:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
 4756:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4757:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4758:                         $changes{'loginvia'}{$lonhost} = 1;
 4759:                     } else {
 4760:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
 4761:                         $changes{'loginvia'}{$lonhost} = 1;
 4762:                     }
 4763:                 } else {
 4764:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4765:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4766:                         $changes{'loginvia'}{$lonhost} = 1;
 4767:                     }
 4768:                 }
 4769:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
 4770:                     foreach my $item (@loginvia_attribs) {
 4771:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
 4772:                     }
 4773:                 } else {
 4774:                     foreach my $item (@loginvia_attribs) {
 4775:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 4776:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 4777:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
 4778:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 4779:                                 $new = '/';
 4780:                             }
 4781:                         }
 4782:                         if (($item eq 'custompath') && 
 4783:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 4784:                             $new = '';
 4785:                         }
 4786:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
 4787:                             $changes{'loginvia'}{$lonhost} = 1;
 4788:                         }
 4789:                         if ($item eq 'exempt') {
 4790:                             $new =~ s/^\s+//;
 4791:                             $new =~ s/\s+$//;
 4792:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
 4793:                             my @okips;
 4794:                             foreach my $ip (@poss_ips) {
 4795:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
 4796:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
 4797:                                         push(@okips,$ip); 
 4798:                                     }
 4799:                                 }
 4800:                             }
 4801:                             if (@okips > 0) {
 4802:                                 $new = join(',',@okips); 
 4803:                             } else {
 4804:                                 $new = ''; 
 4805:                             }
 4806:                         }
 4807:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 4808:                     }
 4809:                 }
 4810:             } else {
 4811:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4812:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4813:                     $changes{'loginvia'}{$lonhost} = 1;
 4814:                     foreach my $item (@loginvia_attribs) {
 4815:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 4816:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 4817:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 4818:                                 $new = '/';
 4819:                             }
 4820:                         }
 4821:                         if (($item eq 'custompath') && 
 4822:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 4823:                             $new = '';
 4824:                         }
 4825:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 4826:                     }
 4827:                 }
 4828:             }
 4829:         }
 4830:     }
 4831: 
 4832:     my $servadm = $r->dir_config('lonAdmEMail');
 4833:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 4834:     if (ref($domconfig{'login'}) eq 'HASH') {
 4835:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
 4836:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
 4837:                 if ($lang eq 'nolang') {
 4838:                     push(@currlangs,$lang);
 4839:                 } elsif (defined($langchoices{$lang})) {
 4840:                     push(@currlangs,$lang);
 4841:                 } else {
 4842:                     next;
 4843:                 }
 4844:             }
 4845:         }
 4846:     }
 4847:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
 4848:     if (@currlangs > 0) {
 4849:         foreach my $lang (@currlangs) {
 4850:             if (grep(/^\Q$lang\E$/,@delurls)) {
 4851:                 $changes{'helpurl'}{$lang} = 1;
 4852:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
 4853:                 $changes{'helpurl'}{$lang} = 1;
 4854:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
 4855:                 push(@newlangs,$lang);
 4856:             } else {
 4857:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 4858:             }
 4859:         }
 4860:     }
 4861:     unless (grep(/^nolang$/,@currlangs)) {
 4862:         if ($env{'form.loginhelpurl_nolang.filename'}) {
 4863:             $changes{'helpurl'}{'nolang'} = 1;
 4864:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
 4865:             push(@newlangs,'nolang');
 4866:         }
 4867:     }
 4868:     if ($env{'form.loginhelpurl_add_lang'}) {
 4869:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
 4870:             ($env{'form.loginhelpurl_add_file.filename'})) {
 4871:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
 4872:             $addedfile = $env{'form.loginhelpurl_add_lang'};
 4873:         }
 4874:     }
 4875:     if ((@newlangs > 0) || ($addedfile)) {
 4876:         my $error;
 4877:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 4878:         if ($configuserok eq 'ok') {
 4879:             if ($switchserver) {
 4880:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
 4881:             } elsif ($author_ok eq 'ok') {
 4882:                 my @allnew = @newlangs;
 4883:                 if ($addedfile ne '') {
 4884:                     push(@allnew,$addedfile);
 4885:                 }
 4886:                 foreach my $lang (@allnew) {
 4887:                     my $formelem = 'loginhelpurl_'.$lang;
 4888:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
 4889:                         $formelem = 'loginhelpurl_add_file';
 4890:                     }
 4891:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
 4892:                                                                "help/$lang",'','',$newfile{$lang});
 4893:                     if ($result eq 'ok') {
 4894:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
 4895:                         $changes{'helpurl'}{$lang} = 1;
 4896:                     } else {
 4897:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
 4898:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
 4899:                         if ((grep(/^\Q$lang\E$/,@currlangs)) && 
 4900:                             (!grep(/^\Q$lang\E$/,@delurls))) {
 4901: 
 4902:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 4903:                         }
 4904:                     }
 4905:                 }
 4906:             } else {
 4907:                 $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);
 4908:             }
 4909:         } else {
 4910:             $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);
 4911:         }
 4912:         if ($error) {
 4913:             &Apache::lonnet::logthis($error);
 4914:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 4915:         }
 4916:     }
 4917:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
 4918: 
 4919:     my $defaulthelpfile = '/adm/loginproblems.html';
 4920:     my $defaulttext = &mt('Default in use');
 4921: 
 4922:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 4923:                                              $dom);
 4924:     if ($putresult eq 'ok') {
 4925:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 4926:         my %defaultchecked = (
 4927:                     'coursecatalog' => 'on',
 4928:                     'helpdesk'      => 'on',
 4929:                     'adminmail'     => 'off',
 4930:                     'newuser'       => 'off',
 4931:         );
 4932:         if (ref($domconfig{'login'}) eq 'HASH') {
 4933:             foreach my $item (@toggles) {
 4934:                 if ($defaultchecked{$item} eq 'on') { 
 4935:                     if (($domconfig{'login'}{$item} eq '0') &&
 4936:                         ($env{'form.'.$item} eq '1')) {
 4937:                         $changes{$item} = 1;
 4938:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 4939:                               $domconfig{'login'}{$item} eq '1') &&
 4940:                              ($env{'form.'.$item} eq '0')) {
 4941:                         $changes{$item} = 1;
 4942:                     }
 4943:                 } elsif ($defaultchecked{$item} eq 'off') {
 4944:                     if (($domconfig{'login'}{$item} eq '1') &&
 4945:                         ($env{'form.'.$item} eq '0')) {
 4946:                         $changes{$item} = 1;
 4947:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 4948:                               $domconfig{'login'}{$item} eq '0') &&
 4949:                              ($env{'form.'.$item} eq '1')) {
 4950:                         $changes{$item} = 1;
 4951:                     }
 4952:                 }
 4953:             }
 4954:         }
 4955:         if (keys(%changes) > 0 || $colchgtext) {
 4956:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 4957:             $resulttext = &mt('Changes made:').'<ul>';
 4958:             foreach my $item (sort(keys(%changes))) {
 4959:                 if ($item eq 'loginvia') {
 4960:                     if (ref($changes{$item}) eq 'HASH') {
 4961:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
 4962:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 4963:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
 4964:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
 4965:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
 4966:                                     $protocol = 'http' if ($protocol ne 'https');
 4967:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
 4968: 
 4969:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
 4970:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
 4971:                                     } else {
 4972:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
 4973:                                     }
 4974:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
 4975:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
 4976:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
 4977:                                     }
 4978:                                     $resulttext .= '</li>';
 4979:                                 } else {
 4980:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
 4981:                                 }
 4982:                             } else {
 4983:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
 4984:                             }
 4985:                         }
 4986:                         $resulttext .= '</ul></li>';
 4987:                     }
 4988:                 } elsif ($item eq 'helpurl') {
 4989:                     if (ref($changes{$item}) eq 'HASH') {
 4990:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
 4991:                             if (grep(/^\Q$lang\E$/,@delurls)) {
 4992:                                 my ($chg,$link);
 4993:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
 4994:                                 if ($lang eq 'nolang') {
 4995:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
 4996:                                 } else {
 4997:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
 4998:                                 }
 4999:                                 $resulttext .= '<li>'.$chg.'</li>';
 5000:                             } else {
 5001:                                 my $chg;
 5002:                                 if ($lang eq 'nolang') {
 5003:                                     $chg = &mt('custom log-in help file for no preferred language');
 5004:                                 } else {
 5005:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
 5006:                                 }
 5007:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
 5008:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
 5009:                                                       '?inhibitmenu=yes',$chg,600,500).
 5010:                                                '</li>';
 5011:                             }
 5012:                         }
 5013:                     }
 5014:                 } elsif ($item eq 'captcha') {
 5015:                     if (ref($loginhash{'login'}) eq 'HASH') {
 5016:                         my $chgtxt; 
 5017:                         if ($loginhash{'login'}{$item} eq 'notused') {
 5018:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
 5019:                         } else {
 5020:                             my %captchas = &captcha_phrases();
 5021:                             if ($captchas{$loginhash{'login'}{$item}}) {
 5022:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
 5023:                             } else {
 5024:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
 5025:                             }
 5026:                         }
 5027:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 5028:                     }
 5029:                 } elsif ($item eq 'recaptchakeys') {
 5030:                     if (ref($loginhash{'login'}) eq 'HASH') {
 5031:                         my ($privkey,$pubkey);
 5032:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
 5033:                             $pubkey = $loginhash{'login'}{$item}{'public'};
 5034:                             $privkey = $loginhash{'login'}{$item}{'private'};
 5035:                         }
 5036:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
 5037:                         if (!$pubkey) {
 5038:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
 5039:                         } else {
 5040:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 5041:                         }
 5042:                         if (!$privkey) {
 5043:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
 5044:                         } else {
 5045:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
 5046:                         }
 5047:                         $chgtxt .= '</ul>';
 5048:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 5049:                     }
 5050:                 } else {
 5051:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 5052:                 }
 5053:             }
 5054:             $resulttext .= $colchgtext.'</ul>';
 5055:         } else {
 5056:             $resulttext = &mt('No changes made to log-in page settings');
 5057:         }
 5058:     } else {
 5059:         $resulttext = '<span class="LC_error">'.
 5060: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5061:     }
 5062:     if ($errors) {
 5063:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 5064:                        $errors.'</ul>';
 5065:     }
 5066:     return $resulttext;
 5067: }
 5068: 
 5069: sub color_font_choices {
 5070:     my %choices =
 5071:         &Apache::lonlocal::texthash (
 5072:             img => "Header",
 5073:             bgs => "Background colors",
 5074:             links => "Link colors",
 5075:             images => "Images",
 5076:             font => "Font color",
 5077:             fontmenu => "Font menu",
 5078:             pgbg => "Page",
 5079:             tabbg => "Header",
 5080:             sidebg => "Border",
 5081:             link => "Link",
 5082:             alink => "Active link",
 5083:             vlink => "Visited link",
 5084:         );
 5085:     return %choices;
 5086: }
 5087: 
 5088: sub modify_rolecolors {
 5089:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 5090:     my ($resulttext,%rolehash);
 5091:     $rolehash{'rolecolors'} = {};
 5092:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 5093:         if ($domconfig{'rolecolors'} eq '') {
 5094:             $domconfig{'rolecolors'} = {};
 5095:         }
 5096:     }
 5097:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 5098:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 5099:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 5100:                                              $dom);
 5101:     if ($putresult eq 'ok') {
 5102:         if (keys(%changes) > 0) {
 5103:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 5104:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 5105:                                              $rolehash{'rolecolors'});
 5106:         } else {
 5107:             $resulttext = &mt('No changes made to default color schemes');
 5108:         }
 5109:     } else {
 5110:         $resulttext = '<span class="LC_error">'.
 5111: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5112:     }
 5113:     if ($errors) {
 5114:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 5115:                        $errors.'</ul>';
 5116:     }
 5117:     return $resulttext;
 5118: }
 5119: 
 5120: sub modify_colors {
 5121:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 5122:     my (%changes,%choices);
 5123:     my @bgs;
 5124:     my @links = ('link','alink','vlink');
 5125:     my @logintext;
 5126:     my @images;
 5127:     my $servadm = $r->dir_config('lonAdmEMail');
 5128:     my $errors;
 5129:     my %defaults;
 5130:     foreach my $role (@{$roles}) {
 5131:         if ($role eq 'login') {
 5132:             %choices = &login_choices();
 5133:             @logintext = ('textcol','bgcol');
 5134:         } else {
 5135:             %choices = &color_font_choices();
 5136:         }
 5137:         if ($role eq 'login') {
 5138:             @images = ('img','logo','domlogo','login');
 5139:             @bgs = ('pgbg','mainbg','sidebg');
 5140:         } else {
 5141:             @images = ('img');
 5142:             @bgs = ('pgbg','tabbg','sidebg');
 5143:         }
 5144:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
 5145:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
 5146:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 5147:         }
 5148:         if ($role eq 'login') {
 5149:             foreach my $item (@logintext) {
 5150:                 unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'logintext'}{$item}) {
 5151:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5152:                 }
 5153:             }
 5154:         } else {
 5155:             unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
 5156:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
 5157:             }
 5158:         }
 5159:         foreach my $item (@bgs) {
 5160:             unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
 5161:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5162:             }
 5163:         }
 5164:         foreach my $item (@links) {
 5165:             unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'links'}{$item}) {
 5166:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5167:             }
 5168:         }
 5169:         my ($configuserok,$author_ok,$switchserver) = 
 5170:             &config_check($dom,$confname,$servadm);
 5171:         my ($width,$height) = &thumb_dimensions();
 5172:         if (ref($domconfig->{$role}) ne 'HASH') {
 5173:             $domconfig->{$role} = {};
 5174:         }
 5175:         foreach my $img (@images) {
 5176:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 5177:                 if (defined($env{'form.login_showlogo_'.$img})) {
 5178:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 5179:                 } else { 
 5180:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 5181:                 }
 5182:             } 
 5183: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 5184: 		 && !defined($domconfig->{$role}{$img})
 5185: 		 && !$env{'form.'.$role.'_del_'.$img}
 5186: 		 && $env{'form.'.$role.'_import_'.$img}) {
 5187: 		# import the old configured image from the .tab setting
 5188: 		# if they haven't provided a new one 
 5189: 		$domconfig->{$role}{$img} = 
 5190: 		    $env{'form.'.$role.'_import_'.$img};
 5191: 	    }
 5192:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 5193:                 my $error;
 5194:                 if ($configuserok eq 'ok') {
 5195:                     if ($switchserver) {
 5196:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 5197:                     } else {
 5198:                         if ($author_ok eq 'ok') {
 5199:                             my ($result,$logourl) = 
 5200:                                 &publishlogo($r,'upload',$role.'_'.$img,
 5201:                                            $dom,$confname,$img,$width,$height);
 5202:                             if ($result eq 'ok') {
 5203:                                 $confhash->{$role}{$img} = $logourl;
 5204:                                 $changes{$role}{'images'}{$img} = 1;
 5205:                             } else {
 5206:                                 $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);
 5207:                             }
 5208:                         } else {
 5209:                             $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);
 5210:                         }
 5211:                     }
 5212:                 } else {
 5213:                     $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);
 5214:                 }
 5215:                 if ($error) {
 5216:                     &Apache::lonnet::logthis($error);
 5217:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 5218:                 }
 5219:             } elsif ($domconfig->{$role}{$img} ne '') {
 5220:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 5221:                     my $error;
 5222:                     if ($configuserok eq 'ok') {
 5223: # is confname an author?
 5224:                         if ($switchserver eq '') {
 5225:                             if ($author_ok eq 'ok') {
 5226:                                 my ($result,$logourl) = 
 5227:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 5228:                                             $dom,$confname,$img,$width,$height);
 5229:                                 if ($result eq 'ok') {
 5230:                                     $confhash->{$role}{$img} = $logourl;
 5231: 				    $changes{$role}{'images'}{$img} = 1;
 5232:                                 }
 5233:                             }
 5234:                         }
 5235:                     }
 5236:                 }
 5237:             }
 5238:         }
 5239:         if (ref($domconfig) eq 'HASH') {
 5240:             if (ref($domconfig->{$role}) eq 'HASH') {
 5241:                 foreach my $img (@images) {
 5242:                     if ($domconfig->{$role}{$img} ne '') {
 5243:                         if ($env{'form.'.$role.'_del_'.$img}) {
 5244:                             $confhash->{$role}{$img} = '';
 5245:                             $changes{$role}{'images'}{$img} = 1;
 5246:                         } else {
 5247:                             if ($confhash->{$role}{$img} eq '') {
 5248:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 5249:                             }
 5250:                         }
 5251:                     } else {
 5252:                         if ($env{'form.'.$role.'_del_'.$img}) {
 5253:                             $confhash->{$role}{$img} = '';
 5254:                             $changes{$role}{'images'}{$img} = 1;
 5255:                         } 
 5256:                     }
 5257:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 5258:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 5259:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 5260:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 5261:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 5262:                             }
 5263:                         } else {
 5264:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 5265:                                 $changes{$role}{'showlogo'}{$img} = 1;
 5266:                             }
 5267:                         }
 5268:                     }
 5269:                 }
 5270:                 if ($domconfig->{$role}{'font'} ne '') {
 5271:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 5272:                         $changes{$role}{'font'} = 1;
 5273:                     }
 5274:                 } else {
 5275:                     if ($confhash->{$role}{'font'}) {
 5276:                         $changes{$role}{'font'} = 1;
 5277:                     }
 5278:                 }
 5279:                 if ($role ne 'login') {
 5280:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
 5281:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
 5282:                             $changes{$role}{'fontmenu'} = 1;
 5283:                         }
 5284:                     } else {
 5285:                         if ($confhash->{$role}{'fontmenu'}) {
 5286:                             $changes{$role}{'fontmenu'} = 1;
 5287:                         }
 5288:                     }
 5289:                 }
 5290:                 foreach my $item (@bgs) {
 5291:                     if ($domconfig->{$role}{$item} ne '') {
 5292:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5293:                             $changes{$role}{'bgs'}{$item} = 1;
 5294:                         } 
 5295:                     } else {
 5296:                         if ($confhash->{$role}{$item}) {
 5297:                             $changes{$role}{'bgs'}{$item} = 1;
 5298:                         }
 5299:                     }
 5300:                 }
 5301:                 foreach my $item (@links) {
 5302:                     if ($domconfig->{$role}{$item} ne '') {
 5303:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5304:                             $changes{$role}{'links'}{$item} = 1;
 5305:                         }
 5306:                     } else {
 5307:                         if ($confhash->{$role}{$item}) {
 5308:                             $changes{$role}{'links'}{$item} = 1;
 5309:                         }
 5310:                     }
 5311:                 }
 5312:                 foreach my $item (@logintext) {
 5313:                     if ($domconfig->{$role}{$item} ne '') {
 5314:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5315:                             $changes{$role}{'logintext'}{$item} = 1;
 5316:                         }
 5317:                     } else {
 5318:                         if ($confhash->{$role}{$item}) {
 5319:                             $changes{$role}{'logintext'}{$item} = 1;
 5320:                         }
 5321:                     }
 5322:                 }
 5323:             } else {
 5324:                 &default_change_checker($role,\@images,\@links,\@bgs,
 5325:                                         \@logintext,$confhash,\%changes); 
 5326:             }
 5327:         } else {
 5328:             &default_change_checker($role,\@images,\@links,\@bgs,
 5329:                                     \@logintext,$confhash,\%changes); 
 5330:         }
 5331:     }
 5332:     return ($errors,%changes);
 5333: }
 5334: 
 5335: sub config_check {
 5336:     my ($dom,$confname,$servadm) = @_;
 5337:     my ($configuserok,$author_ok,$switchserver,%currroles);
 5338:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 5339:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 5340:                                                    $confname,$servadm);
 5341:     if ($configuserok eq 'ok') {
 5342:         $switchserver = &check_switchserver($dom,$confname);
 5343:         if ($switchserver eq '') {
 5344:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 5345:         }
 5346:     }
 5347:     return ($configuserok,$author_ok,$switchserver);
 5348: }
 5349: 
 5350: sub default_change_checker {
 5351:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 5352:     foreach my $item (@{$links}) {
 5353:         if ($confhash->{$role}{$item}) {
 5354:             $changes->{$role}{'links'}{$item} = 1;
 5355:         }
 5356:     }
 5357:     foreach my $item (@{$bgs}) {
 5358:         if ($confhash->{$role}{$item}) {
 5359:             $changes->{$role}{'bgs'}{$item} = 1;
 5360:         }
 5361:     }
 5362:     foreach my $item (@{$logintext}) {
 5363:         if ($confhash->{$role}{$item}) {
 5364:             $changes->{$role}{'logintext'}{$item} = 1;
 5365:         }
 5366:     }
 5367:     foreach my $img (@{$images}) {
 5368:         if ($env{'form.'.$role.'_del_'.$img}) {
 5369:             $confhash->{$role}{$img} = '';
 5370:             $changes->{$role}{'images'}{$img} = 1;
 5371:         }
 5372:         if ($role eq 'login') {
 5373:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 5374:                 $changes->{$role}{'showlogo'}{$img} = 1;
 5375:             }
 5376:         }
 5377:     }
 5378:     if ($confhash->{$role}{'font'}) {
 5379:         $changes->{$role}{'font'} = 1;
 5380:     }
 5381: }
 5382: 
 5383: sub display_colorchgs {
 5384:     my ($dom,$changes,$roles,$confhash) = @_;
 5385:     my (%choices,$resulttext);
 5386:     if (!grep(/^login$/,@{$roles})) {
 5387:         $resulttext = &mt('Changes made:').'<br />';
 5388:     }
 5389:     foreach my $role (@{$roles}) {
 5390:         if ($role eq 'login') {
 5391:             %choices = &login_choices();
 5392:         } else {
 5393:             %choices = &color_font_choices();
 5394:         }
 5395:         if (ref($changes->{$role}) eq 'HASH') {
 5396:             if ($role ne 'login') {
 5397:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 5398:             }
 5399:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 5400:                 if ($role ne 'login') {
 5401:                     $resulttext .= '<ul>';
 5402:                 }
 5403:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 5404:                     if ($role ne 'login') {
 5405:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 5406:                     }
 5407:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 5408:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 5409:                             if ($confhash->{$role}{$key}{$item}) {
 5410:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 5411:                             } else {
 5412:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 5413:                             }
 5414:                         } elsif ($confhash->{$role}{$item} eq '') {
 5415:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 5416:                         } else {
 5417:                             my $newitem = $confhash->{$role}{$item};
 5418:                             if ($key eq 'images') {
 5419:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 5420:                             }
 5421:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 5422:                         }
 5423:                     }
 5424:                     if ($role ne 'login') {
 5425:                         $resulttext .= '</ul></li>';
 5426:                     }
 5427:                 } else {
 5428:                     if ($confhash->{$role}{$key} eq '') {
 5429:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 5430:                     } else {
 5431:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 5432:                     }
 5433:                 }
 5434:                 if ($role ne 'login') {
 5435:                     $resulttext .= '</ul>';
 5436:                 }
 5437:             }
 5438:         }
 5439:     }
 5440:     return $resulttext;
 5441: }
 5442: 
 5443: sub thumb_dimensions {
 5444:     return ('200','50');
 5445: }
 5446: 
 5447: sub check_dimensions {
 5448:     my ($inputfile) = @_;
 5449:     my ($fullwidth,$fullheight);
 5450:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 5451:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 5452:             my $imageinfo = <PIPE>;
 5453:             if (!close(PIPE)) {
 5454:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 5455:             }
 5456:             chomp($imageinfo);
 5457:             my ($fullsize) = 
 5458:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 5459:             if ($fullsize) {
 5460:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 5461:             }
 5462:         }
 5463:     }
 5464:     return ($fullwidth,$fullheight);
 5465: }
 5466: 
 5467: sub check_configuser {
 5468:     my ($uhome,$dom,$confname,$servadm) = @_;
 5469:     my ($configuserok,%currroles);
 5470:     if ($uhome eq 'no_host') {
 5471:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 5472:         my $configpass = &LONCAPA::Enrollment::create_password();
 5473:         $configuserok = 
 5474:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 5475:                              $configpass,'','','','','',undef,$servadm);
 5476:     } else {
 5477:         $configuserok = 'ok';
 5478:         %currroles = 
 5479:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 5480:     }
 5481:     return ($configuserok,%currroles);
 5482: }
 5483: 
 5484: sub check_authorstatus {
 5485:     my ($dom,$confname,%currroles) = @_;
 5486:     my $author_ok;
 5487:     if (!$currroles{':'.$dom.':au'}) {
 5488:         my $start = time;
 5489:         my $end = 0;
 5490:         $author_ok = 
 5491:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 5492:                                         'au',$end,$start,'','','domconfig');
 5493:     } else {
 5494:         $author_ok = 'ok';
 5495:     }
 5496:     return $author_ok;
 5497: }
 5498: 
 5499: sub publishlogo {
 5500:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 5501:     my ($output,$fname,$logourl);
 5502:     if ($action eq 'upload') {
 5503:         $fname=$env{'form.'.$formname.'.filename'};
 5504:         chop($env{'form.'.$formname});
 5505:     } else {
 5506:         ($fname) = ($formname =~ /([^\/]+)$/);
 5507:     }
 5508:     if ($savefileas ne '') {
 5509:         $fname = $savefileas;
 5510:     }
 5511:     $fname=&Apache::lonnet::clean_filename($fname);
 5512: # See if there is anything left
 5513:     unless ($fname) { return ('error: no uploaded file'); }
 5514:     $fname="$subdir/$fname";
 5515:     my $docroot=$r->dir_config('lonDocRoot'); 
 5516:     my $filepath="$docroot/priv";
 5517:     my $relpath = "$dom/$confname";
 5518:     my ($fnamepath,$file,$fetchthumb);
 5519:     $file=$fname;
 5520:     if ($fname=~m|/|) {
 5521:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 5522:     }
 5523:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
 5524:     my $count;
 5525:     for ($count=5;$count<=$#parts;$count++) {
 5526:         $filepath.="/$parts[$count]";
 5527:         if ((-e $filepath)!=1) {
 5528:             mkdir($filepath,02770);
 5529:         }
 5530:     }
 5531:     # Check for bad extension and disallow upload
 5532:     if ($file=~/\.(\w+)$/ &&
 5533:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 5534:         $output = 
 5535:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 5536:     } elsif ($file=~/\.(\w+)$/ &&
 5537:         !defined(&Apache::loncommon::fileembstyle($1))) {
 5538:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 5539:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 5540:         $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 5541:     } elsif (-d "$filepath/$file") {
 5542:         $output = &mt('Filename is a directory name - rename the file and re-upload');
 5543:     } else {
 5544:         my $source = $filepath.'/'.$file;
 5545:         my $logfile;
 5546:         if (!open($logfile,">>$source".'.log')) {
 5547:             return (&mt('No write permission to Authoring Space'));
 5548:         }
 5549:         print $logfile
 5550: "\n================= Publish ".localtime()." ================\n".
 5551: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 5552: # Save the file
 5553:         if (!open(FH,'>'.$source)) {
 5554:             &Apache::lonnet::logthis('Failed to create '.$source);
 5555:             return (&mt('Failed to create file'));
 5556:         }
 5557:         if ($action eq 'upload') {
 5558:             if (!print FH ($env{'form.'.$formname})) {
 5559:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 5560:                 return (&mt('Failed to write file'));
 5561:             }
 5562:         } else {
 5563:             my $original = &Apache::lonnet::filelocation('',$formname);
 5564:             if(!copy($original,$source)) {
 5565:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 5566:                 return (&mt('Failed to write file'));
 5567:             }
 5568:         }
 5569:         close(FH);
 5570:         chmod(0660, $source); # Permissions to rw-rw---.
 5571: 
 5572:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 5573:         my $copyfile=$targetdir.'/'.$file;
 5574: 
 5575:         my @parts=split(/\//,$targetdir);
 5576:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 5577:         for (my $count=5;$count<=$#parts;$count++) {
 5578:             $path.="/$parts[$count]";
 5579:             if (!-e $path) {
 5580:                 print $logfile "\nCreating directory ".$path;
 5581:                 mkdir($path,02770);
 5582:             }
 5583:         }
 5584:         my $versionresult;
 5585:         if (-e $copyfile) {
 5586:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 5587:         } else {
 5588:             $versionresult = 'ok';
 5589:         }
 5590:         if ($versionresult eq 'ok') {
 5591:             if (copy($source,$copyfile)) {
 5592:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 5593:                 $output = 'ok';
 5594:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 5595:                 push(@{$modified_urls},[$copyfile,$source]);
 5596:                 my $metaoutput = 
 5597:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 5598:                 unless ($registered_cleanup) {
 5599:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 5600:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 5601:                     $registered_cleanup=1;
 5602:                 }
 5603:             } else {
 5604:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 5605:                 $output = &mt('Failed to copy file to RES space').", $!";
 5606:             }
 5607:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 5608:                 my $inputfile = $filepath.'/'.$file;
 5609:                 my $outfile = $filepath.'/'.'tn-'.$file;
 5610:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 5611:                 if ($fullwidth ne '' && $fullheight ne '') { 
 5612:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 5613:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 5614:                         system("convert -sample $thumbsize $inputfile $outfile");
 5615:                         chmod(0660, $filepath.'/tn-'.$file);
 5616:                         if (-e $outfile) {
 5617:                             my $copyfile=$targetdir.'/tn-'.$file;
 5618:                             if (copy($outfile,$copyfile)) {
 5619:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 5620:                                 my $thumb_metaoutput = 
 5621:                                     &write_metadata($dom,$confname,$formname,
 5622:                                                     $targetdir,'tn-'.$file,$logfile);
 5623:                                 push(@{$modified_urls},[$copyfile,$outfile]);
 5624:                                 unless ($registered_cleanup) {
 5625:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 5626:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 5627:                                     $registered_cleanup=1;
 5628:                                 }
 5629:                             } else {
 5630:                                 print $logfile "\nUnable to write ".$copyfile.
 5631:                                                ':'.$!."\n";
 5632:                             }
 5633:                         }
 5634:                     }
 5635:                 }
 5636:             }
 5637:         } else {
 5638:             $output = $versionresult;
 5639:         }
 5640:     }
 5641:     return ($output,$logourl);
 5642: }
 5643: 
 5644: sub logo_versioning {
 5645:     my ($targetdir,$file,$logfile) = @_;
 5646:     my $target = $targetdir.'/'.$file;
 5647:     my ($maxversion,$fn,$extn,$output);
 5648:     $maxversion = 0;
 5649:     if ($file =~ /^(.+)\.(\w+)$/) {
 5650:         $fn=$1;
 5651:         $extn=$2;
 5652:     }
 5653:     opendir(DIR,$targetdir);
 5654:     while (my $filename=readdir(DIR)) {
 5655:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 5656:             $maxversion=($1>$maxversion)?$1:$maxversion;
 5657:         }
 5658:     }
 5659:     $maxversion++;
 5660:     print $logfile "\nCreating old version ".$maxversion."\n";
 5661:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 5662:     if (copy($target,$copyfile)) {
 5663:         print $logfile "Copied old target to ".$copyfile."\n";
 5664:         $copyfile=$copyfile.'.meta';
 5665:         if (copy($target.'.meta',$copyfile)) {
 5666:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 5667:             $output = 'ok';
 5668:         } else {
 5669:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 5670:             $output = &mt('Failed to copy old meta').", $!, ";
 5671:         }
 5672:     } else {
 5673:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 5674:         $output = &mt('Failed to copy old target').", $!, ";
 5675:     }
 5676:     return $output;
 5677: }
 5678: 
 5679: sub write_metadata {
 5680:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 5681:     my (%metadatafields,%metadatakeys,$output);
 5682:     $metadatafields{'title'}=$formname;
 5683:     $metadatafields{'creationdate'}=time;
 5684:     $metadatafields{'lastrevisiondate'}=time;
 5685:     $metadatafields{'copyright'}='public';
 5686:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 5687:                                          $env{'user.domain'};
 5688:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 5689:     $metadatafields{'domain'}=$dom;
 5690:     {
 5691:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 5692:         my $mfh;
 5693:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 5694:             foreach (sort(keys(%metadatafields))) {
 5695:                 unless ($_=~/\./) {
 5696:                     my $unikey=$_;
 5697:                     $unikey=~/^([A-Za-z]+)/;
 5698:                     my $tag=$1;
 5699:                     $tag=~tr/A-Z/a-z/;
 5700:                     print $mfh "\n\<$tag";
 5701:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
 5702:                         my $value=$metadatafields{$unikey.'.'.$_};
 5703:                         $value=~s/\"/\'\'/g;
 5704:                         print $mfh ' '.$_.'="'.$value.'"';
 5705:                     }
 5706:                     print $mfh '>'.
 5707:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 5708:                             .'</'.$tag.'>';
 5709:                 }
 5710:             }
 5711:             $output = 'ok';
 5712:             print $logfile "\nWrote metadata";
 5713:             close($mfh);
 5714:         } else {
 5715:             print $logfile "\nFailed to open metadata file";
 5716:             $output = &mt('Could not write metadata');
 5717:         }
 5718:     }
 5719:     return $output;
 5720: }
 5721: 
 5722: sub notifysubscribed {
 5723:     foreach my $targetsource (@{$modified_urls}){
 5724:         next unless (ref($targetsource) eq 'ARRAY');
 5725:         my ($target,$source)=@{$targetsource};
 5726:         if ($source ne '') {
 5727:             if (open(my $logfh,'>>'.$source.'.log')) {
 5728:                 print $logfh "\nCleanup phase: Notifications\n";
 5729:                 my @subscribed=&subscribed_hosts($target);
 5730:                 foreach my $subhost (@subscribed) {
 5731:                     print $logfh "\nNotifying host ".$subhost.':';
 5732:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
 5733:                     print $logfh $reply;
 5734:                 }
 5735:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
 5736:                 foreach my $subhost (@subscribedmeta) {
 5737:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
 5738:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
 5739:                                                         $subhost);
 5740:                     print $logfh $reply;
 5741:                 }
 5742:                 print $logfh "\n============ Done ============\n";
 5743:                 close($logfh);
 5744:             }
 5745:         }
 5746:     }
 5747:     return OK;
 5748: }
 5749: 
 5750: sub subscribed_hosts {
 5751:     my ($target) = @_;
 5752:     my @subscribed;
 5753:     if (open(my $fh,"<$target.subscription")) {
 5754:         while (my $subline=<$fh>) {
 5755:             if ($subline =~ /^($match_lonid):/) {
 5756:                 my $host = $1;
 5757:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
 5758:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
 5759:                         push(@subscribed,$host);
 5760:                     }
 5761:                 }
 5762:             }
 5763:         }
 5764:     }
 5765:     return @subscribed;
 5766: }
 5767: 
 5768: sub check_switchserver {
 5769:     my ($dom,$confname) = @_;
 5770:     my ($allowed,$switchserver);
 5771:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 5772:     if ($home eq 'no_host') {
 5773:         $home = &Apache::lonnet::domain($dom,'primary');
 5774:     }
 5775:     my @ids=&Apache::lonnet::current_machine_ids();
 5776:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 5777:     if (!$allowed) {
 5778: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
 5779:     }
 5780:     return $switchserver;
 5781: }
 5782: 
 5783: sub modify_quotas {
 5784:     my ($dom,$action,%domconfig) = @_;
 5785:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
 5786:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
 5787:     if ($action eq 'quotas') {
 5788:         $context = 'tools'; 
 5789:     } else {
 5790:         $context = $action;
 5791:     }
 5792:     if ($context eq 'requestcourses') {
 5793:         @usertools = ('official','unofficial','community');
 5794:         @options =('norequest','approval','validate','autolimit');
 5795:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 5796:         %titles = &courserequest_titles();
 5797:         $toolregexp = join('|',@usertools);
 5798:         %conditions = &courserequest_conditions();
 5799:     } elsif ($context eq 'requestauthor') {
 5800:         @usertools = ('author');
 5801:         %titles = &authorrequest_titles();
 5802:     } else {
 5803:         @usertools = ('aboutme','blog','webdav','portfolio');
 5804:         %titles = &tool_titles();
 5805:     }
 5806:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 5807:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5808:     foreach my $key (keys(%env)) {
 5809:         if ($context eq 'requestcourses') {
 5810:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
 5811:                 my $item = $1;
 5812:                 my $type = $2;
 5813:                 if ($type =~ /^limit_(.+)/) {
 5814:                     $limithash{$item}{$1} = $env{$key};
 5815:                 } else {
 5816:                     $confhash{$item}{$type} = $env{$key};
 5817:                 }
 5818:             }
 5819:         } elsif ($context eq 'requestauthor') {
 5820:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
 5821:                 $confhash{$1} = $env{$key};
 5822:             }
 5823:         } else {
 5824:             if ($key =~ /^form\.quota_(.+)$/) {
 5825:                 $confhash{'defaultquota'}{$1} = $env{$key};
 5826:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
 5827:                 $confhash{'authorquota'}{$1} = $env{$key};
 5828:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
 5829:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 5830:             }
 5831:         }
 5832:     }
 5833:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 5834:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
 5835:         @approvalnotify = sort(@approvalnotify);
 5836:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
 5837:         if (ref($domconfig{$action}) eq 'HASH') {
 5838:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
 5839:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
 5840:                     $changes{'notify'}{'approval'} = 1;
 5841:                 }
 5842:             } else {
 5843:                 if ($confhash{'notify'}{'approval'}) {
 5844:                     $changes{'notify'}{'approval'} = 1;
 5845:                 }
 5846:             }
 5847:         } else {
 5848:             if ($confhash{'notify'}{'approval'}) {
 5849:                 $changes{'notify'}{'approval'} = 1;
 5850:             }
 5851:         }
 5852:     } else {
 5853:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 5854:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
 5855:     }
 5856:     foreach my $item (@usertools) {
 5857:         foreach my $type (@{$types},'default','_LC_adv') {
 5858:             my $unset; 
 5859:             if ($context eq 'requestcourses') {
 5860:                 $unset = '0';
 5861:                 if ($type eq '_LC_adv') {
 5862:                     $unset = '';
 5863:                 }
 5864:                 if ($confhash{$item}{$type} eq 'autolimit') {
 5865:                     $confhash{$item}{$type} .= '=';
 5866:                     unless ($limithash{$item}{$type} =~ /\D/) {
 5867:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
 5868:                     }
 5869:                 }
 5870:             } elsif ($context eq 'requestauthor') {
 5871:                 $unset = '0';
 5872:                 if ($type eq '_LC_adv') {
 5873:                     $unset = '';
 5874:                 }
 5875:             } else {
 5876:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 5877:                     $confhash{$item}{$type} = 1;
 5878:                 } else {
 5879:                     $confhash{$item}{$type} = 0;
 5880:                 }
 5881:             }
 5882:             if (ref($domconfig{$action}) eq 'HASH') {
 5883:                 if ($action eq 'requestauthor') {
 5884:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
 5885:                         $changes{$type} = 1;
 5886:                     }
 5887:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
 5888:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
 5889:                         $changes{$item}{$type} = 1;
 5890:                     }
 5891:                 } else {
 5892:                     if ($context eq 'requestcourses') {
 5893:                         if ($confhash{$item}{$type} ne $unset) {
 5894:                             $changes{$item}{$type} = 1;
 5895:                         }
 5896:                     } else {
 5897:                         if (!$confhash{$item}{$type}) {
 5898:                             $changes{$item}{$type} = 1;
 5899:                         }
 5900:                     }
 5901:                 }
 5902:             } else {
 5903:                 if ($context eq 'requestcourses') {
 5904:                     if ($confhash{$item}{$type} ne $unset) {
 5905:                         $changes{$item}{$type} = 1;
 5906:                     }
 5907:                 } elsif ($context eq 'requestauthor') {
 5908:                     if ($confhash{$type} ne $unset) {
 5909:                         $changes{$type} = 1;
 5910:                     }
 5911:                 } else {
 5912:                     if (!$confhash{$item}{$type}) {
 5913:                         $changes{$item}{$type} = 1;
 5914:                     }
 5915:                 }
 5916:             }
 5917:         }
 5918:     }
 5919:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 5920:         if (ref($domconfig{'quotas'}) eq 'HASH') {
 5921:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 5922:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 5923:                     if (exists($confhash{'defaultquota'}{$key})) {
 5924:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 5925:                             $changes{'defaultquota'}{$key} = 1;
 5926:                         }
 5927:                     } else {
 5928:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 5929:                     }
 5930:                 }
 5931:             } else {
 5932:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
 5933:                     if (exists($confhash{'defaultquota'}{$key})) {
 5934:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 5935:                             $changes{'defaultquota'}{$key} = 1;
 5936:                         }
 5937:                     } else {
 5938:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 5939:                     }
 5940:                 }
 5941:             }
 5942:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 5943:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
 5944:                     if (exists($confhash{'authorquota'}{$key})) {
 5945:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
 5946:                             $changes{'authorquota'}{$key} = 1;
 5947:                         }
 5948:                     } else {
 5949:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
 5950:                     }
 5951:                 }
 5952:             }
 5953:         }
 5954:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
 5955:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 5956:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 5957:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 5958:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 5959:                             $changes{'defaultquota'}{$key} = 1;
 5960:                         }
 5961:                     } else {
 5962:                         if (!exists($domconfig{'quotas'}{$key})) {
 5963:                             $changes{'defaultquota'}{$key} = 1;
 5964:                         }
 5965:                     }
 5966:                 } else {
 5967:                     $changes{'defaultquota'}{$key} = 1;
 5968:                 }
 5969:             }
 5970:         }
 5971:         if (ref($confhash{'authorquota'}) eq 'HASH') {
 5972:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
 5973:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 5974:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 5975:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
 5976:                             $changes{'authorquota'}{$key} = 1;
 5977:                         }
 5978:                     } else {
 5979:                         $changes{'authorquota'}{$key} = 1;
 5980:                     }
 5981:                 } else {
 5982:                     $changes{'authorquota'}{$key} = 1;
 5983:                 }
 5984:             }
 5985:         }
 5986:     }
 5987: 
 5988:     if ($context eq 'requestauthor') {
 5989:         $domdefaults{'requestauthor'} = \%confhash;
 5990:     } else {
 5991:         foreach my $key (keys(%confhash)) {
 5992:             $domdefaults{$key} = $confhash{$key};
 5993:         }
 5994:     }
 5995: 
 5996:     my %quotahash = (
 5997:                       $action => { %confhash }
 5998:                     );
 5999:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 6000:                                              $dom);
 6001:     if ($putresult eq 'ok') {
 6002:         if (keys(%changes) > 0) {
 6003:             my $cachetime = 24*60*60;
 6004:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6005: 
 6006:             $resulttext = &mt('Changes made:').'<ul>';
 6007:             unless (($context eq 'requestcourses') || 
 6008:                     ($context eq 'requestauthor')) {
 6009:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
 6010:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 6011:                     foreach my $type (@{$types},'default') {
 6012:                         if (defined($changes{'defaultquota'}{$type})) {
 6013:                             my $typetitle = $usertypes->{$type};
 6014:                             if ($type eq 'default') {
 6015:                                 $typetitle = $othertitle;
 6016:                             }
 6017:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 6018:                         }
 6019:                     }
 6020:                     $resulttext .= '</ul></li>';
 6021:                 }
 6022:                 if (ref($changes{'authorquota'}) eq 'HASH') {
 6023:                     $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
 6024:                     foreach my $type (@{$types},'default') {
 6025:                         if (defined($changes{'authorquota'}{$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{'authorquota'}{$type}).'</li>';
 6031:                         }
 6032:                     }
 6033:                     $resulttext .= '</ul></li>';
 6034:                 }
 6035:             }
 6036:             my %newenv;
 6037:             foreach my $item (@usertools) {
 6038:                 my (%haschgs,%inconf);
 6039:                 if ($context eq 'requestauthor') {
 6040:                     %haschgs = %changes;
 6041:                     %inconf = %confhash; 
 6042:                 } else {
 6043:                     if (ref($changes{$item}) eq 'HASH') {
 6044:                         %haschgs = %{$changes{$item}};
 6045:                     }
 6046:                     if (ref($confhash{$item}) eq 'HASH') {
 6047:                         %inconf = %{$confhash{$item}};
 6048:                     }
 6049:                 }
 6050:                 if (keys(%haschgs) > 0) {
 6051:                     my $newacc = 
 6052:                         &Apache::lonnet::usertools_access($env{'user.name'},
 6053:                                                           $env{'user.domain'},
 6054:                                                           $item,'reload',$context);
 6055:                     if (($context eq 'requestcourses') || 
 6056:                         ($context eq 'requestauthor')) {
 6057:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
 6058:                             $newenv{'environment.canrequest.'.$item} = $newacc;
 6059:                         }
 6060:                     } else {
 6061:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 6062:                             $newenv{'environment.availabletools.'.$item} = $newacc;
 6063:                         }
 6064:                     }
 6065:                     unless ($context eq 'requestauthor') {
 6066:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
 6067:                     }
 6068:                     foreach my $type (@{$types},'default','_LC_adv') {
 6069:                         if ($haschgs{$type}) {
 6070:                             my $typetitle = $usertypes->{$type};
 6071:                             if ($type eq 'default') {
 6072:                                 $typetitle = $othertitle;
 6073:                             } elsif ($type eq '_LC_adv') {
 6074:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 6075:                             }
 6076:                             if ($inconf{$type}) {
 6077:                                 if ($context eq 'requestcourses') {
 6078:                                     my $cond;
 6079:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
 6080:                                         if ($1 eq '') {
 6081:                                             $cond = &mt('(Automatic processing of any request).');
 6082:                                         } else {
 6083:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
 6084:                                         }
 6085:                                     } else { 
 6086:                                         $cond = $conditions{$inconf{$type}};
 6087:                                     }
 6088:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
 6089:                                 } elsif ($context eq 'requestauthor') {
 6090:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
 6091:                                                              $titles{$inconf{$type}},$typetitle);
 6092: 
 6093:                                 } else {
 6094:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 6095:                                 }
 6096:                             } else {
 6097:                                 if ($type eq '_LC_adv') {
 6098:                                     if ($inconf{$type} eq '0') {
 6099:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 6100:                                     } else { 
 6101:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
 6102:                                     }
 6103:                                 } else {
 6104:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 6105:                                 }
 6106:                             }
 6107:                         }
 6108:                     }
 6109:                     unless ($context eq 'requestauthor') {
 6110:                         $resulttext .= '</ul></li>';
 6111:                     }
 6112:                 }
 6113:             }
 6114:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
 6115:                 if (ref($changes{'notify'}) eq 'HASH') {
 6116:                     if ($changes{'notify'}{'approval'}) {
 6117:                         if (ref($confhash{'notify'}) eq 'HASH') {
 6118:                             if ($confhash{'notify'}{'approval'}) {
 6119:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
 6120:                             } else {
 6121:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
 6122:                             }
 6123:                         }
 6124:                     }
 6125:                 }
 6126:             }
 6127:             $resulttext .= '</ul>';
 6128:             if (keys(%newenv)) {
 6129:                 &Apache::lonnet::appenv(\%newenv);
 6130:             }
 6131:         } else {
 6132:             if ($context eq 'requestcourses') {
 6133:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
 6134:             } elsif ($context eq 'requestauthor') {
 6135:                 $resulttext = &mt('No changes made to rights to request author space.');
 6136:             } else {
 6137:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
 6138:             }
 6139:         }
 6140:     } else {
 6141:         $resulttext = '<span class="LC_error">'.
 6142: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6143:     }
 6144:     return $resulttext;
 6145: }
 6146: 
 6147: sub modify_autoenroll {
 6148:     my ($dom,%domconfig) = @_;
 6149:     my ($resulttext,%changes);
 6150:     my %currautoenroll;
 6151:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 6152:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 6153:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 6154:         }
 6155:     }
 6156:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 6157:     my %title = ( run => 'Auto-enrollment active',
 6158:                   sender => 'Sender for notification messages',
 6159:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
 6160:     my @offon = ('off','on');
 6161:     my $sender_uname = $env{'form.sender_uname'};
 6162:     my $sender_domain = $env{'form.sender_domain'};
 6163:     if ($sender_domain eq '') {
 6164:         $sender_uname = '';
 6165:     } elsif ($sender_uname eq '') {
 6166:         $sender_domain = '';
 6167:     }
 6168:     my $coowners = $env{'form.autoassign_coowners'};
 6169:     my %autoenrollhash =  (
 6170:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
 6171:                                        'sender_uname' => $sender_uname,
 6172:                                        'sender_domain' => $sender_domain,
 6173:                                        'co-owners' => $coowners,
 6174:                                 }
 6175:                      );
 6176:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 6177:                                              $dom);
 6178:     if ($putresult eq 'ok') {
 6179:         if (exists($currautoenroll{'run'})) {
 6180:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 6181:                  $changes{'run'} = 1;
 6182:              }
 6183:         } elsif ($autorun) {
 6184:             if ($env{'form.autoenroll_run'} ne '1') {
 6185:                  $changes{'run'} = 1;
 6186:             }
 6187:         }
 6188:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 6189:             $changes{'sender'} = 1;
 6190:         }
 6191:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 6192:             $changes{'sender'} = 1;
 6193:         }
 6194:         if ($currautoenroll{'co-owners'} ne '') {
 6195:             if ($currautoenroll{'co-owners'} ne $coowners) {
 6196:                 $changes{'coowners'} = 1;
 6197:             }
 6198:         } elsif ($coowners) {
 6199:             $changes{'coowners'} = 1;
 6200:         }      
 6201:         if (keys(%changes) > 0) {
 6202:             $resulttext = &mt('Changes made:').'<ul>';
 6203:             if ($changes{'run'}) {
 6204:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 6205:             }
 6206:             if ($changes{'sender'}) {
 6207:                 if ($sender_uname eq '' || $sender_domain eq '') {
 6208:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 6209:                 } else {
 6210:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 6211:                 }
 6212:             }
 6213:             if ($changes{'coowners'}) {
 6214:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
 6215:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 6216:             }
 6217:             $resulttext .= '</ul>';
 6218:         } else {
 6219:             $resulttext = &mt('No changes made to auto-enrollment settings');
 6220:         }
 6221:     } else {
 6222:         $resulttext = '<span class="LC_error">'.
 6223: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6224:     }
 6225:     return $resulttext;
 6226: }
 6227: 
 6228: sub modify_autoupdate {
 6229:     my ($dom,%domconfig) = @_;
 6230:     my ($resulttext,%currautoupdate,%fields,%changes);
 6231:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 6232:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 6233:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 6234:         }
 6235:     }
 6236:     my @offon = ('off','on');
 6237:     my %title = &Apache::lonlocal::texthash (
 6238:                    run => 'Auto-update:',
 6239:                    classlists => 'Updates to user information in classlists?'
 6240:                 );
 6241:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 6242:     my %fieldtitles = &Apache::lonlocal::texthash (
 6243:                         id => 'Student/Employee ID',
 6244:                         permanentemail => 'E-mail address',
 6245:                         lastname => 'Last Name',
 6246:                         firstname => 'First Name',
 6247:                         middlename => 'Middle Name',
 6248:                         generation => 'Generation',
 6249:                       );
 6250:     $othertitle = &mt('All users');
 6251:     if (keys(%{$usertypes}) >  0) {
 6252:         $othertitle = &mt('Other users');
 6253:     }
 6254:     foreach my $key (keys(%env)) {
 6255:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 6256:             my ($usertype,$item) = ($1,$2);
 6257:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
 6258:                 if ($usertype eq 'default') {   
 6259:                     push(@{$fields{$1}},$2);
 6260:                 } elsif (ref($types) eq 'ARRAY') {
 6261:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
 6262:                         push(@{$fields{$1}},$2);
 6263:                     }
 6264:                 }
 6265:             }
 6266:         }
 6267:     }
 6268:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
 6269:     @lockablenames = sort(@lockablenames);
 6270:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
 6271:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 6272:         if (@changed) {
 6273:             $changes{'lockablenames'} = 1;
 6274:         }
 6275:     } else {
 6276:         if (@lockablenames) {
 6277:             $changes{'lockablenames'} = 1;
 6278:         }
 6279:     }
 6280:     my %updatehash = (
 6281:                       autoupdate => { run => $env{'form.autoupdate_run'},
 6282:                                       classlists => $env{'form.classlists'},
 6283:                                       fields => {%fields},
 6284:                                       lockablenames => \@lockablenames,
 6285:                                     }
 6286:                      );
 6287:     foreach my $key (keys(%currautoupdate)) {
 6288:         if (($key eq 'run') || ($key eq 'classlists')) {
 6289:             if (exists($updatehash{autoupdate}{$key})) {
 6290:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 6291:                     $changes{$key} = 1;
 6292:                 }
 6293:             }
 6294:         } elsif ($key eq 'fields') {
 6295:             if (ref($currautoupdate{$key}) eq 'HASH') {
 6296:                 foreach my $item (@{$types},'default') {
 6297:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 6298:                         my $change = 0;
 6299:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 6300:                             if (!exists($fields{$item})) {
 6301:                                 $change = 1;
 6302:                                 last;
 6303:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 6304:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 6305:                                     $change = 1;
 6306:                                     last;
 6307:                                 }
 6308:                             }
 6309:                         }
 6310:                         if ($change) {
 6311:                             push(@{$changes{$key}},$item);
 6312:                         }
 6313:                     } 
 6314:                 }
 6315:             }
 6316:         } elsif ($key eq 'lockablenames') {
 6317:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
 6318:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 6319:                 if (@changed) {
 6320:                     $changes{'lockablenames'} = 1;
 6321:                 }
 6322:             } else {
 6323:                 if (@lockablenames) {
 6324:                     $changes{'lockablenames'} = 1;
 6325:                 }
 6326:             }
 6327:         }
 6328:     }
 6329:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
 6330:         if (@lockablenames) {
 6331:             $changes{'lockablenames'} = 1;
 6332:         }
 6333:     }
 6334:     foreach my $item (@{$types},'default') {
 6335:         if (defined($fields{$item})) {
 6336:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 6337:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
 6338:                     my $change = 0;
 6339:                     if (ref($fields{$item}) eq 'ARRAY') {
 6340:                         foreach my $type (@{$fields{$item}}) {
 6341:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
 6342:                                 $change = 1;
 6343:                                 last;
 6344:                             }
 6345:                         }
 6346:                     }
 6347:                     if ($change) {
 6348:                         push(@{$changes{'fields'}},$item);
 6349:                     }
 6350:                 } else {
 6351:                     push(@{$changes{'fields'}},$item);
 6352:                 }
 6353:             } else {
 6354:                 push(@{$changes{'fields'}},$item);
 6355:             }
 6356:         }
 6357:     }
 6358:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 6359:                                              $dom);
 6360:     if ($putresult eq 'ok') {
 6361:         if (keys(%changes) > 0) {
 6362:             $resulttext = &mt('Changes made:').'<ul>';
 6363:             foreach my $key (sort(keys(%changes))) {
 6364:                 if ($key eq 'lockablenames') {
 6365:                     $resulttext .= '<li>';
 6366:                     if (@lockablenames) {
 6367:                         $usertypes->{'default'} = $othertitle;
 6368:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
 6369:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
 6370:                     } else {
 6371:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
 6372:                     }
 6373:                     $resulttext .= '</li>';
 6374:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
 6375:                     foreach my $item (@{$changes{$key}}) {
 6376:                         my @newvalues;
 6377:                         foreach my $type (@{$fields{$item}}) {
 6378:                             push(@newvalues,$fieldtitles{$type});
 6379:                         }
 6380:                         my $newvaluestr;
 6381:                         if (@newvalues > 0) {
 6382:                             $newvaluestr = join(', ',@newvalues);
 6383:                         } else {
 6384:                             $newvaluestr = &mt('none');
 6385:                         }
 6386:                         if ($item eq 'default') {
 6387:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 6388:                         } else {
 6389:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 6390:                         }
 6391:                     }
 6392:                 } else {
 6393:                     my $newvalue;
 6394:                     if ($key eq 'run') {
 6395:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 6396:                     } else {
 6397:                         $newvalue = $offon[$env{'form.'.$key}];
 6398:                     }
 6399:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 6400:                 }
 6401:             }
 6402:             $resulttext .= '</ul>';
 6403:         } else {
 6404:             $resulttext = &mt('No changes made to autoupdates');
 6405:         }
 6406:     } else {
 6407:         $resulttext = '<span class="LC_error">'.
 6408: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6409:     }
 6410:     return $resulttext;
 6411: }
 6412: 
 6413: sub modify_autocreate {
 6414:     my ($dom,%domconfig) = @_;
 6415:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
 6416:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
 6417:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
 6418:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
 6419:         }
 6420:     }
 6421:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
 6422:                  req => 'Auto-creation of validated requests for official courses',
 6423:                  xmldc => 'Identity of course creator of courses from XML files',
 6424:                );
 6425:     my @types = ('xml','req');
 6426:     foreach my $item (@types) {
 6427:         $newvals{$item} = $env{'form.autocreate_'.$item};
 6428:         $newvals{$item} =~ s/\D//g;
 6429:         $newvals{$item} = 0 if ($newvals{$item} eq '');
 6430:     }
 6431:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
 6432:     my %domcoords = &get_active_dcs($dom);
 6433:     unless (exists($domcoords{$newvals{'xmldc'}})) {
 6434:         $newvals{'xmldc'} = '';
 6435:     } 
 6436:     %autocreatehash =  (
 6437:                         autocreate => { xml => $newvals{'xml'},
 6438:                                         req => $newvals{'req'},
 6439:                                       }
 6440:                        );
 6441:     if ($newvals{'xmldc'} ne '') {
 6442:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
 6443:     }
 6444:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
 6445:                                              $dom);
 6446:     if ($putresult eq 'ok') {
 6447:         my @items = @types;
 6448:         if ($newvals{'xml'}) {
 6449:             push(@items,'xmldc');
 6450:         }
 6451:         foreach my $item (@items) {
 6452:             if (exists($currautocreate{$item})) {
 6453:                 if ($currautocreate{$item} ne $newvals{$item}) {
 6454:                     $changes{$item} = 1;
 6455:                 }
 6456:             } elsif ($newvals{$item}) {
 6457:                 $changes{$item} = 1;
 6458:             }
 6459:         }
 6460:         if (keys(%changes) > 0) {
 6461:             my @offon = ('off','on'); 
 6462:             $resulttext = &mt('Changes made:').'<ul>';
 6463:             foreach my $item (@types) {
 6464:                 if ($changes{$item}) {
 6465:                     my $newtxt = $offon[$newvals{$item}];
 6466:                     $resulttext .= '<li>'.
 6467:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
 6468:                                        '<b>','</b>').
 6469:                                    '</li>';
 6470:                 }
 6471:             }
 6472:             if ($changes{'xmldc'}) {
 6473:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
 6474:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
 6475:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
 6476:             }
 6477:             $resulttext .= '</ul>';
 6478:         } else {
 6479:             $resulttext = &mt('No changes made to auto-creation settings');
 6480:         }
 6481:     } else {
 6482:         $resulttext = '<span class="LC_error">'.
 6483:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6484:     }
 6485:     return $resulttext;
 6486: }
 6487: 
 6488: sub modify_directorysrch {
 6489:     my ($dom,%domconfig) = @_;
 6490:     my ($resulttext,%changes);
 6491:     my %currdirsrch;
 6492:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 6493:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 6494:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 6495:         }
 6496:     }
 6497:     my %title = ( available => 'Directory search available',
 6498:                   localonly => 'Other domains can search',
 6499:                   searchby => 'Search types',
 6500:                   searchtypes => 'Search latitude');
 6501:     my @offon = ('off','on');
 6502:     my @otherdoms = ('Yes','No');
 6503: 
 6504:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 6505:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 6506:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 6507: 
 6508:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 6509:     if (keys(%{$usertypes}) == 0) {
 6510:         @cansearch = ('default');
 6511:     } else {
 6512:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 6513:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 6514:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 6515:                     push(@{$changes{'cansearch'}},$type);
 6516:                 }
 6517:             }
 6518:             foreach my $type (@cansearch) {
 6519:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 6520:                     push(@{$changes{'cansearch'}},$type);
 6521:                 }
 6522:             }
 6523:         } else {
 6524:             push(@{$changes{'cansearch'}},@cansearch);
 6525:         }
 6526:     }
 6527: 
 6528:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 6529:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 6530:             if (!grep(/^\Q$by\E$/,@searchby)) {
 6531:                 push(@{$changes{'searchby'}},$by);
 6532:             }
 6533:         }
 6534:         foreach my $by (@searchby) {
 6535:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 6536:                 push(@{$changes{'searchby'}},$by);
 6537:             }
 6538:         }
 6539:     } else {
 6540:         push(@{$changes{'searchby'}},@searchby);
 6541:     }
 6542: 
 6543:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 6544:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 6545:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 6546:                 push(@{$changes{'searchtypes'}},$type);
 6547:             }
 6548:         }
 6549:         foreach my $type (@searchtypes) {
 6550:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 6551:                 push(@{$changes{'searchtypes'}},$type);
 6552:             }
 6553:         }
 6554:     } else {
 6555:         if (exists($currdirsrch{'searchtypes'})) {
 6556:             foreach my $type (@searchtypes) {  
 6557:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 6558:                     push(@{$changes{'searchtypes'}},$type);
 6559:                 }
 6560:             }
 6561:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 6562:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 6563:             }   
 6564:         } else {
 6565:             push(@{$changes{'searchtypes'}},@searchtypes); 
 6566:         }
 6567:     }
 6568: 
 6569:     my %dirsrch_hash =  (
 6570:             directorysrch => { available => $env{'form.dirsrch_available'},
 6571:                                cansearch => \@cansearch,
 6572:                                localonly => $env{'form.dirsrch_localonly'},
 6573:                                searchby => \@searchby,
 6574:                                searchtypes => \@searchtypes,
 6575:                              }
 6576:             );
 6577:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 6578:                                              $dom);
 6579:     if ($putresult eq 'ok') {
 6580:         if (exists($currdirsrch{'available'})) {
 6581:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 6582:                  $changes{'available'} = 1;
 6583:              }
 6584:         } else {
 6585:             if ($env{'form.dirsrch_available'} eq '1') {
 6586:                 $changes{'available'} = 1;
 6587:             }
 6588:         }
 6589:         if (exists($currdirsrch{'localonly'})) {
 6590:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 6591:                  $changes{'localonly'} = 1;
 6592:              }
 6593:         } else {
 6594:             if ($env{'form.dirsrch_localonly'} eq '1') {
 6595:                 $changes{'localonly'} = 1;
 6596:             }
 6597:         }
 6598:         if (keys(%changes) > 0) {
 6599:             $resulttext = &mt('Changes made:').'<ul>';
 6600:             if ($changes{'available'}) {
 6601:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 6602:             }
 6603:             if ($changes{'localonly'}) {
 6604:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 6605:             }
 6606: 
 6607:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 6608:                 my $chgtext;
 6609:                 if (ref($usertypes) eq 'HASH') {
 6610:                     if (keys(%{$usertypes}) > 0) {
 6611:                         foreach my $type (@{$types}) {
 6612:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 6613:                                 $chgtext .= $usertypes->{$type}.'; ';
 6614:                             }
 6615:                         }
 6616:                         if (grep(/^default$/,@cansearch)) {
 6617:                             $chgtext .= $othertitle;
 6618:                         } else {
 6619:                             $chgtext =~ s/\; $//;
 6620:                         }
 6621:                         $resulttext .= 
 6622:                             '<li>'.
 6623:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
 6624:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
 6625:                             '</li>';
 6626:                     }
 6627:                 }
 6628:             }
 6629:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 6630:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 6631:                 my $chgtext;
 6632:                 foreach my $type (@{$titleorder}) {
 6633:                     if (grep(/^\Q$type\E$/,@searchby)) {
 6634:                         if (defined($searchtitles->{$type})) {
 6635:                             $chgtext .= $searchtitles->{$type}.'; ';
 6636:                         }
 6637:                     }
 6638:                 }
 6639:                 $chgtext =~ s/\; $//;
 6640:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 6641:             }
 6642:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 6643:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 6644:                 my $chgtext;
 6645:                 foreach my $type (@{$srchtypeorder}) {
 6646:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 6647:                         if (defined($srchtypes_desc->{$type})) {
 6648:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 6649:                         }
 6650:                     }
 6651:                 }
 6652:                 $chgtext =~ s/\; $//;
 6653:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
 6654:             }
 6655:             $resulttext .= '</ul>';
 6656:         } else {
 6657:             $resulttext = &mt('No changes made to institution directory search settings');
 6658:         }
 6659:     } else {
 6660:         $resulttext = '<span class="LC_error">'.
 6661:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 6662:     }
 6663:     return $resulttext;
 6664: }
 6665: 
 6666: sub modify_contacts {
 6667:     my ($dom,%domconfig) = @_;
 6668:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 6669:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 6670:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 6671:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 6672:         }
 6673:     }
 6674:     my (%others,%to,%bcc);
 6675:     my @contacts = ('supportemail','adminemail');
 6676:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
 6677:                     'requestsmail','updatesmail');
 6678:     foreach my $type (@mailings) {
 6679:         @{$newsetting{$type}} = 
 6680:             &Apache::loncommon::get_env_multiple('form.'.$type);
 6681:         foreach my $item (@contacts) {
 6682:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 6683:                 $contacts_hash{contacts}{$type}{$item} = 1;
 6684:             } else {
 6685:                 $contacts_hash{contacts}{$type}{$item} = 0;
 6686:             }
 6687:         }  
 6688:         $others{$type} = $env{'form.'.$type.'_others'};
 6689:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 6690:         if ($type eq 'helpdeskmail') {
 6691:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
 6692:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
 6693:         }
 6694:     }
 6695:     foreach my $item (@contacts) {
 6696:         $to{$item} = $env{'form.'.$item};
 6697:         $contacts_hash{'contacts'}{$item} = $to{$item};
 6698:     }
 6699:     if (keys(%currsetting) > 0) {
 6700:         foreach my $item (@contacts) {
 6701:             if ($to{$item} ne $currsetting{$item}) {
 6702:                 $changes{$item} = 1;
 6703:             }
 6704:         }
 6705:         foreach my $type (@mailings) {
 6706:             foreach my $item (@contacts) {
 6707:                 if (ref($currsetting{$type}) eq 'HASH') {
 6708:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 6709:                         push(@{$changes{$type}},$item);
 6710:                     }
 6711:                 } else {
 6712:                     push(@{$changes{$type}},@{$newsetting{$type}});
 6713:                 }
 6714:             }
 6715:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 6716:                 push(@{$changes{$type}},'others');
 6717:             }
 6718:             if ($type eq 'helpdeskmail') {   
 6719:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
 6720:                     push(@{$changes{$type}},'bcc'); 
 6721:                 }
 6722:             }
 6723:         }
 6724:     } else {
 6725:         my %default;
 6726:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 6727:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 6728:         $default{'errormail'} = 'adminemail';
 6729:         $default{'packagesmail'} = 'adminemail';
 6730:         $default{'helpdeskmail'} = 'supportemail';
 6731:         $default{'lonstatusmail'} = 'adminemail';
 6732:         $default{'requestsmail'} = 'adminemail';
 6733:         $default{'updatesmail'} = 'adminemail';
 6734:         foreach my $item (@contacts) {
 6735:            if ($to{$item} ne $default{$item}) {
 6736:               $changes{$item} = 1;
 6737:            } 
 6738:         }
 6739:         foreach my $type (@mailings) {
 6740:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 6741:                
 6742:                 push(@{$changes{$type}},@{$newsetting{$type}});
 6743:             }
 6744:             if ($others{$type} ne '') {
 6745:                 push(@{$changes{$type}},'others');
 6746:             }
 6747:             if ($type eq 'helpdeskmail') {
 6748:                 if ($bcc{$type} ne '') {
 6749:                     push(@{$changes{$type}},'bcc');
 6750:                 }
 6751:             }
 6752:         }
 6753:     }
 6754:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 6755:                                              $dom);
 6756:     if ($putresult eq 'ok') {
 6757:         if (keys(%changes) > 0) {
 6758:             my ($titles,$short_titles)  = &contact_titles();
 6759:             $resulttext = &mt('Changes made:').'<ul>';
 6760:             foreach my $item (@contacts) {
 6761:                 if ($changes{$item}) {
 6762:                     $resulttext .= '<li>'.$titles->{$item}.
 6763:                                     &mt(' set to: ').
 6764:                                     '<span class="LC_cusr_emph">'.
 6765:                                     $to{$item}.'</span></li>';
 6766:                 }
 6767:             }
 6768:             foreach my $type (@mailings) {
 6769:                 if (ref($changes{$type}) eq 'ARRAY') {
 6770:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 6771:                     my @text;
 6772:                     foreach my $item (@{$newsetting{$type}}) {
 6773:                         push(@text,$short_titles->{$item});
 6774:                     }
 6775:                     if ($others{$type} ne '') {
 6776:                         push(@text,$others{$type});
 6777:                     }
 6778:                     $resulttext .= '<span class="LC_cusr_emph">'.
 6779:                                    join(', ',@text).'</span>';
 6780:                     if ($type eq 'helpdeskmail') {
 6781:                         if ($bcc{$type} ne '') {
 6782:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
 6783:                         }
 6784:                     }
 6785:                     $resulttext .= '</li>';
 6786:                 }
 6787:             }
 6788:             $resulttext .= '</ul>';
 6789:         } else {
 6790:             $resulttext = &mt('No changes made to contact information');
 6791:         }
 6792:     } else {
 6793:         $resulttext = '<span class="LC_error">'.
 6794:             &mt('An error occurred: [_1].',$putresult).'</span>';
 6795:     }
 6796:     return $resulttext;
 6797: }
 6798: 
 6799: sub modify_usercreation {
 6800:     my ($dom,%domconfig) = @_;
 6801:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 6802:     my $warningmsg;
 6803:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 6804:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 6805:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 6806:         }
 6807:     }
 6808:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 6809:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 6810:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 6811:     my @contexts = ('author','course','requestcrs','selfcreate');
 6812:     foreach my $item(@contexts) {
 6813:         if ($item eq 'selfcreate') {
 6814:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
 6815:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6816:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
 6817:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
 6818:                     if (grep(/^login$/,@{$cancreate{$item}})) {
 6819:                         $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.');   
 6820:                     }
 6821:                 }
 6822:             }
 6823:         } else {
 6824:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
 6825:         }
 6826:     }
 6827:     my ($othertitle,$usertypes,$types) = 
 6828:         &Apache::loncommon::sorted_inst_types($dom);
 6829:     if (ref($types) eq 'ARRAY') {
 6830:         if (@{$types} > 0) {
 6831:             @{$cancreate{'statustocreate'}} = 
 6832:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
 6833:         } else {
 6834:             @{$cancreate{'statustocreate'}} = ();
 6835:         }
 6836:         push(@contexts,'statustocreate');
 6837:     }
 6838:     &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
 6839:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 6840:         foreach my $item (@contexts) {
 6841:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
 6842:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 6843:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 6844:                         if (ref($cancreate{$item}) eq 'ARRAY') {
 6845:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 6846:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6847:                                     push(@{$changes{'cancreate'}},$item);
 6848:                                 }
 6849:                             }
 6850:                         }
 6851:                     }
 6852:                 } else {
 6853:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
 6854:                         if (@{$cancreate{$item}} > 0) {
 6855:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6856:                                 push(@{$changes{'cancreate'}},$item);
 6857:                             }
 6858:                         }
 6859:                     } else {
 6860:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
 6861:                             if (@{$cancreate{$item}} < 3) {
 6862:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6863:                                     push(@{$changes{'cancreate'}},$item);
 6864:                                 }
 6865:                             }
 6866:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
 6867:                             if (@{$cancreate{$item}} > 0) {
 6868:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6869:                                     push(@{$changes{'cancreate'}},$item);
 6870:                                 }
 6871:                             }
 6872:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
 6873:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6874:                                 push(@{$changes{'cancreate'}},$item);
 6875:                             }
 6876:                         }
 6877:                     }
 6878:                 }
 6879:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6880:                     foreach my $type (@{$cancreate{$item}}) {
 6881:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 6882:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 6883:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6884:                                     push(@{$changes{'cancreate'}},$item);
 6885:                                 }
 6886:                             }
 6887:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
 6888:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
 6889:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
 6890:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6891:                                     push(@{$changes{'cancreate'}},$item);
 6892:                                 }
 6893:                             }
 6894:                         }
 6895:                     }
 6896:                 }
 6897:             } else {
 6898:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 6899:                     push(@{$changes{'cancreate'}},$item);
 6900:                 }
 6901:             }
 6902:         }
 6903:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 6904:         foreach my $item (@contexts) {
 6905:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 6906:                 if ($cancreate{$item} ne 'any') {
 6907:                     push(@{$changes{'cancreate'}},$item);
 6908:                 }
 6909:             } else {
 6910:                 if ($cancreate{$item} ne 'none') {
 6911:                     push(@{$changes{'cancreate'}},$item);
 6912:                 }
 6913:             }
 6914:         }
 6915:     } else {
 6916:         foreach my $item (@contexts)  {
 6917:             push(@{$changes{'cancreate'}},$item);
 6918:         }
 6919:     }
 6920: 
 6921:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 6922:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 6923:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 6924:                 push(@{$changes{'username_rule'}},$type);
 6925:             }
 6926:         }
 6927:         foreach my $type (@username_rule) {
 6928:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 6929:                 push(@{$changes{'username_rule'}},$type);
 6930:             }
 6931:         }
 6932:     } else {
 6933:         push(@{$changes{'username_rule'}},@username_rule);
 6934:     }
 6935: 
 6936:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 6937:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 6938:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 6939:                 push(@{$changes{'id_rule'}},$type);
 6940:             }
 6941:         }
 6942:         foreach my $type (@id_rule) {
 6943:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 6944:                 push(@{$changes{'id_rule'}},$type);
 6945:             }
 6946:         }
 6947:     } else {
 6948:         push(@{$changes{'id_rule'}},@id_rule);
 6949:     }
 6950: 
 6951:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 6952:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 6953:             if (!grep(/^\Q$type\E$/,@email_rule)) {
 6954:                 push(@{$changes{'email_rule'}},$type);
 6955:             }
 6956:         }
 6957:         foreach my $type (@email_rule) {
 6958:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 6959:                 push(@{$changes{'email_rule'}},$type);
 6960:             }
 6961:         }
 6962:     } else {
 6963:         push(@{$changes{'email_rule'}},@email_rule);
 6964:     }
 6965: 
 6966:     my @authen_contexts = ('author','course','domain');
 6967:     my @authtypes = ('int','krb4','krb5','loc');
 6968:     my %authhash;
 6969:     foreach my $item (@authen_contexts) {
 6970:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 6971:         foreach my $auth (@authtypes) {
 6972:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 6973:                 $authhash{$item}{$auth} = 1;
 6974:             } else {
 6975:                 $authhash{$item}{$auth} = 0;
 6976:             }
 6977:         }
 6978:     }
 6979:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 6980:         foreach my $item (@authen_contexts) {
 6981:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 6982:                 foreach my $auth (@authtypes) {
 6983:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 6984:                         push(@{$changes{'authtypes'}},$item);
 6985:                         last;
 6986:                     }
 6987:                 }
 6988:             }
 6989:         }
 6990:     } else {
 6991:         foreach my $item (@authen_contexts) {
 6992:             push(@{$changes{'authtypes'}},$item);
 6993:         }
 6994:     }
 6995: 
 6996:     my %usercreation_hash =  (
 6997:             usercreation => {
 6998:                               cancreate     => \%cancreate,
 6999:                               username_rule => \@username_rule,
 7000:                               id_rule       => \@id_rule,
 7001:                               email_rule    => \@email_rule,
 7002:                               authtypes     => \%authhash,
 7003:                             }
 7004:             );
 7005: 
 7006:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 7007:                                              $dom);
 7008: 
 7009:     my %selfcreatetypes = (
 7010:                              sso   => 'users authenticated by institutional single sign on',
 7011:                              login => 'users authenticated by institutional log-in',
 7012:                              email => 'users who provide a valid e-mail address for use as the username',
 7013:                           );
 7014:     if ($putresult eq 'ok') {
 7015:         if (keys(%changes) > 0) {
 7016:             $resulttext = &mt('Changes made:').'<ul>';
 7017:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 7018:                 my %lt = &usercreation_types();
 7019:                 foreach my $type (@{$changes{'cancreate'}}) {
 7020:                     my $chgtext;
 7021:                     unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
 7022:                         $chgtext = $lt{$type}.', ';
 7023:                     }
 7024:                     if ($type eq 'selfcreate') {
 7025:                         if (@{$cancreate{$type}} == 0) {
 7026:                             $chgtext .= &mt('creation of a new user account is not permitted.');
 7027:                         } else {
 7028:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
 7029:                             foreach my $case (@{$cancreate{$type}}) {
 7030:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 7031:                             }
 7032:                             $chgtext .= '</ul>';
 7033:                             if (ref($cancreate{$type}) eq 'ARRAY') {
 7034:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
 7035:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 7036:                                         if (@{$cancreate{'statustocreate'}} == 0) {
 7037:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 7038:                                         }
 7039:                                     }
 7040:                                 }
 7041:                             }
 7042:                         }
 7043:                     } elsif ($type eq 'statustocreate') {
 7044:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
 7045:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
 7046:                             if (@{$cancreate{'selfcreate'}} > 0) {
 7047:                                 if (@{$cancreate{'statustocreate'}} == 0) {
 7048: 
 7049:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
 7050:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
 7051:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 7052:                                     } 
 7053:                                 } elsif (ref($usertypes) eq 'HASH') {
 7054:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 7055:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
 7056:                                     } else {
 7057:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
 7058:                                     }
 7059:                                     $chgtext .= '<ul>';
 7060:                                     foreach my $case (@{$cancreate{$type}}) {
 7061:                                         if ($case eq 'default') {
 7062:                                             $chgtext .= '<li>'.$othertitle.'</li>';
 7063:                                         } else {
 7064:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
 7065:                                         }
 7066:                                     }
 7067:                                     $chgtext .= '</ul>';
 7068:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 7069:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
 7070:                                     }
 7071:                                 }
 7072:                             } else {
 7073:                                 if (@{$cancreate{$type}} == 0) {
 7074:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
 7075:                                 } else {
 7076:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
 7077:                                 }
 7078:                             }
 7079:                         }
 7080:                     } elsif ($type eq 'captcha') {
 7081:                         if ($cancreate{$type} eq 'notused') {
 7082:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
 7083:                         } else {
 7084:                             my %captchas = &captcha_phrases();
 7085:                             if ($captchas{$cancreate{$type}}) {
 7086:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
 7087:                             } else {
 7088:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.'); 
 7089:                             }
 7090:                         }
 7091:                     } elsif ($type eq 'recaptchakeys') {
 7092:                         my ($privkey,$pubkey);
 7093:                         if (ref($cancreate{$type}) eq 'HASH') {
 7094:                             $pubkey = $cancreate{$type}{'public'};
 7095:                             $privkey = $cancreate{$type}{'private'};
 7096:                         }
 7097:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
 7098:                         if (!$pubkey) {
 7099:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
 7100:                         } else {
 7101:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 7102:                         }
 7103:                         if (!$privkey) {
 7104:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
 7105:                         } else {
 7106:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
 7107:                         }
 7108:                         $chgtext .= '</ul>';
 7109:                     } else {
 7110:                         if ($cancreate{$type} eq 'none') {
 7111:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 7112:                         } elsif ($cancreate{$type} eq 'any') {
 7113:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 7114:                         } elsif ($cancreate{$type} eq 'official') {
 7115:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 7116:                         } elsif ($cancreate{$type} eq 'unofficial') {
 7117:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 7118:                         }
 7119:                     }
 7120:                     $resulttext .= '<li>'.$chgtext.'</li>';
 7121:                 }
 7122:             }
 7123:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 7124:                 my ($rules,$ruleorder) = 
 7125:                     &Apache::lonnet::inst_userrules($dom,'username');
 7126:                 my $chgtext = '<ul>';
 7127:                 foreach my $type (@username_rule) {
 7128:                     if (ref($rules->{$type}) eq 'HASH') {
 7129:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 7130:                     }
 7131:                 }
 7132:                 $chgtext .= '</ul>';
 7133:                 if (@username_rule > 0) {
 7134:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 7135:                 } else {
 7136:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 7137:                 }
 7138:             }
 7139:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 7140:                 my ($idrules,$idruleorder) = 
 7141:                     &Apache::lonnet::inst_userrules($dom,'id');
 7142:                 my $chgtext = '<ul>';
 7143:                 foreach my $type (@id_rule) {
 7144:                     if (ref($idrules->{$type}) eq 'HASH') {
 7145:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 7146:                     }
 7147:                 }
 7148:                 $chgtext .= '</ul>';
 7149:                 if (@id_rule > 0) {
 7150:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 7151:                 } else {
 7152:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 7153:                 }
 7154:             }
 7155:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 7156:                 my ($emailrules,$emailruleorder) =
 7157:                     &Apache::lonnet::inst_userrules($dom,'email');
 7158:                 my $chgtext = '<ul>';
 7159:                 foreach my $type (@email_rule) {
 7160:                     if (ref($emailrules->{$type}) eq 'HASH') {
 7161:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 7162:                     }
 7163:                 }
 7164:                 $chgtext .= '</ul>';
 7165:                 if (@email_rule > 0) {
 7166:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
 7167:                 } else {
 7168:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
 7169:                 }
 7170:             }
 7171: 
 7172:             my %authname = &authtype_names();
 7173:             my %context_title = &context_names();
 7174:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 7175:                 my $chgtext = '<ul>';
 7176:                 foreach my $type (@{$changes{'authtypes'}}) {
 7177:                     my @allowed;
 7178:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 7179:                     foreach my $auth (@authtypes) {
 7180:                         if ($authhash{$type}{$auth}) {
 7181:                             push(@allowed,$authname{$auth});
 7182:                         }
 7183:                     }
 7184:                     if (@allowed > 0) {
 7185:                         $chgtext .= join(', ',@allowed).'</li>';
 7186:                     } else {
 7187:                         $chgtext .= &mt('none').'</li>';
 7188:                     }
 7189:                 }
 7190:                 $chgtext .= '</ul>';
 7191:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 7192:                 $resulttext .= '</li>';
 7193:             }
 7194:             $resulttext .= '</ul>';
 7195:         } else {
 7196:             $resulttext = &mt('No changes made to user creation settings');
 7197:         }
 7198:     } else {
 7199:         $resulttext = '<span class="LC_error">'.
 7200:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7201:     }
 7202:     if ($warningmsg ne '') {
 7203:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 7204:     }
 7205:     return $resulttext;
 7206: }
 7207: 
 7208: sub process_captcha {
 7209:     my ($container,$changes,$newsettings,$current) = @_;
 7210:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
 7211:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
 7212:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
 7213:         $newsettings->{'captcha'} = 'original';
 7214:     }
 7215:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
 7216:         if ($container eq 'cancreate') { 
 7217:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 7218:                 push(@{$changes->{'cancreate'}},'captcha');
 7219:             } elsif (!defined($changes->{'cancreate'})) {
 7220:                 $changes->{'cancreate'} = ['captcha'];
 7221:             }
 7222:         } else {
 7223:             $changes->{'captcha'} = 1;
 7224:         }
 7225:     }
 7226:     my ($newpub,$newpriv,$currpub,$currpriv);
 7227:     if ($newsettings->{'captcha'} eq 'recaptcha') {
 7228:         $newpub = $env{'form.'.$container.'_recaptchapub'};
 7229:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
 7230:         $newpub =~ s/\W//g;
 7231:         $newpriv =~ s/\W//g;
 7232:         $newsettings->{'recaptchakeys'} = {
 7233:                                              public  => $newpub,
 7234:                                              private => $newpriv,
 7235:                                           };
 7236:     }
 7237:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
 7238:         $currpub = $current->{'recaptchakeys'}{'public'};
 7239:         $currpriv = $current->{'recaptchakeys'}{'private'};
 7240:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
 7241:             $newsettings->{'recaptchakeys'} = {
 7242:                                                  public  => '',
 7243:                                                  private => '',
 7244:                                               }
 7245:         }
 7246:     }
 7247:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
 7248:         if ($container eq 'cancreate') {
 7249:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 7250:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
 7251:             } elsif (!defined($changes->{'cancreate'})) {
 7252:                 $changes->{'cancreate'} = ['recaptchakeys'];
 7253:             }
 7254:         } else {
 7255:             $changes->{'recaptchakeys'} = 1; 
 7256:         }
 7257:     }
 7258:     return;
 7259: }
 7260: 
 7261: sub modify_usermodification {
 7262:     my ($dom,%domconfig) = @_;
 7263:     my ($resulttext,%curr_usermodification,%changes);
 7264:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 7265:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 7266:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 7267:         }
 7268:     }
 7269:     my @contexts = ('author','course','selfcreate');
 7270:     my %context_title = (
 7271:                            author => 'In author context',
 7272:                            course => 'In course context',
 7273:                            selfcreate => 'When self creating account', 
 7274:                         );
 7275:     my @fields = ('lastname','firstname','middlename','generation',
 7276:                   'permanentemail','id');
 7277:     my %roles = (
 7278:                   author => ['ca','aa'],
 7279:                   course => ['st','ep','ta','in','cr'],
 7280:                 );
 7281:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 7282:     if (ref($types) eq 'ARRAY') {
 7283:         push(@{$types},'default');
 7284:         $usertypes->{'default'} = $othertitle;
 7285:     }
 7286:     $roles{'selfcreate'} = $types;  
 7287:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 7288:     my %modifyhash;
 7289:     foreach my $context (@contexts) {
 7290:         foreach my $role (@{$roles{$context}}) {
 7291:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 7292:             foreach my $item (@fields) {
 7293:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 7294:                     $modifyhash{$context}{$role}{$item} = 1;
 7295:                 } else {
 7296:                     $modifyhash{$context}{$role}{$item} = 0;
 7297:                 }
 7298:             }
 7299:         }
 7300:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 7301:             foreach my $role (@{$roles{$context}}) {
 7302:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 7303:                     foreach my $field (@fields) {
 7304:                         if ($modifyhash{$context}{$role}{$field} ne 
 7305:                                 $curr_usermodification{$context}{$role}{$field}) {
 7306:                             push(@{$changes{$context}},$role);
 7307:                             last;
 7308:                         }
 7309:                     }
 7310:                 }
 7311:             }
 7312:         } else {
 7313:             foreach my $context (@contexts) {
 7314:                 foreach my $role (@{$roles{$context}}) {
 7315:                     push(@{$changes{$context}},$role);
 7316:                 }
 7317:             }
 7318:         }
 7319:     }
 7320:     my %usermodification_hash =  (
 7321:                                    usermodification => \%modifyhash,
 7322:                                  );
 7323:     my $putresult = &Apache::lonnet::put_dom('configuration',
 7324:                                              \%usermodification_hash,$dom);
 7325:     if ($putresult eq 'ok') {
 7326:         if (keys(%changes) > 0) {
 7327:             $resulttext = &mt('Changes made: ').'<ul>';
 7328:             foreach my $context (@contexts) {
 7329:                 if (ref($changes{$context}) eq 'ARRAY') {
 7330:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 7331:                     if (ref($changes{$context}) eq 'ARRAY') {
 7332:                         foreach my $role (@{$changes{$context}}) {
 7333:                             my $rolename;
 7334:                             if ($context eq 'selfcreate') {
 7335:                                 $rolename = $role;
 7336:                                 if (ref($usertypes) eq 'HASH') {
 7337:                                     if ($usertypes->{$role} ne '') {
 7338:                                         $rolename = $usertypes->{$role};
 7339:                                     }
 7340:                                 }
 7341:                             } else {
 7342:                                 if ($role eq 'cr') {
 7343:                                     $rolename = &mt('Custom');
 7344:                                 } else {
 7345:                                     $rolename = &Apache::lonnet::plaintext($role);
 7346:                                 }
 7347:                             }
 7348:                             my @modifiable;
 7349:                             if ($context eq 'selfcreate') {
 7350:                                 $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): ');
 7351:                             } else {
 7352:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 7353:                             }
 7354:                             foreach my $field (@fields) {
 7355:                                 if ($modifyhash{$context}{$role}{$field}) {
 7356:                                     push(@modifiable,$fieldtitles{$field});
 7357:                                 }
 7358:                             }
 7359:                             if (@modifiable > 0) {
 7360:                                 $resulttext .= join(', ',@modifiable);
 7361:                             } else {
 7362:                                 $resulttext .= &mt('none'); 
 7363:                             }
 7364:                             $resulttext .= '</li>';
 7365:                         }
 7366:                         $resulttext .= '</ul></li>';
 7367:                     }
 7368:                 }
 7369:             }
 7370:             $resulttext .= '</ul>';
 7371:         } else {
 7372:             $resulttext = &mt('No changes made to user modification settings');
 7373:         }
 7374:     } else {
 7375:         $resulttext = '<span class="LC_error">'.
 7376:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7377:     }
 7378:     return $resulttext;
 7379: }
 7380: 
 7381: sub modify_defaults {
 7382:     my ($dom,$r) = @_;
 7383:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 7384:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 7385:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
 7386:     my @authtypes = ('internal','krb4','krb5','localauth');
 7387:     foreach my $item (@items) {
 7388:         $newvalues{$item} = $env{'form.'.$item};
 7389:         if ($item eq 'auth_def') {
 7390:             if ($newvalues{$item} ne '') {
 7391:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 7392:                     push(@errors,$item);
 7393:                 }
 7394:             }
 7395:         } elsif ($item eq 'lang_def') {
 7396:             if ($newvalues{$item} ne '') {
 7397:                 if ($newvalues{$item} =~ /^(\w+)/) {
 7398:                     my $langcode = $1;
 7399:                     if ($langcode ne 'x_chef') {
 7400:                         if (code2language($langcode) eq '') {
 7401:                             push(@errors,$item);
 7402:                         }
 7403:                     }
 7404:                 } else {
 7405:                     push(@errors,$item);
 7406:                 }
 7407:             }
 7408:         } elsif ($item eq 'timezone_def') {
 7409:             if ($newvalues{$item} ne '') {
 7410:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 7411:                     push(@errors,$item);   
 7412:                 }
 7413:             }
 7414:         } elsif ($item eq 'datelocale_def') {
 7415:             if ($newvalues{$item} ne '') {
 7416:                 my @datelocale_ids = DateTime::Locale->ids();
 7417:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 7418:                     push(@errors,$item);
 7419:                 }
 7420:             }
 7421:         } elsif ($item eq 'portal_def') {
 7422:             if ($newvalues{$item} ne '') {
 7423:                 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])\/?$/) {
 7424:                     push(@errors,$item);
 7425:                 }
 7426:             }
 7427:         }
 7428:         if (grep(/^\Q$item\E$/,@errors)) {
 7429:             $newvalues{$item} = $domdefaults{$item};
 7430:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 7431:             $changes{$item} = 1;
 7432:         }
 7433:         $domdefaults{$item} = $newvalues{$item};
 7434:     }
 7435:     my %defaults_hash = (
 7436:                          defaults => \%newvalues,
 7437:                         );
 7438:     my $title = &defaults_titles();
 7439:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 7440:                                              $dom);
 7441:     if ($putresult eq 'ok') {
 7442:         if (keys(%changes) > 0) {
 7443:             $resulttext = &mt('Changes made:').'<ul>';
 7444:             my $version = $r->dir_config('lonVersion');
 7445:             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";
 7446:             foreach my $item (sort(keys(%changes))) {
 7447:                 my $value = $env{'form.'.$item};
 7448:                 if ($value eq '') {
 7449:                     $value = &mt('none');
 7450:                 } elsif ($item eq 'auth_def') {
 7451:                     my %authnames = &authtype_names();
 7452:                     my %shortauth = (
 7453:                              internal => 'int',
 7454:                              krb4 => 'krb4',
 7455:                              krb5 => 'krb5',
 7456:                              localauth  => 'loc',
 7457:                     );
 7458:                     $value = $authnames{$shortauth{$value}};
 7459:                 }
 7460:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 7461:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
 7462:             }
 7463:             $resulttext .= '</ul>';
 7464:             $mailmsgtext .= "\n";
 7465:             my $cachetime = 24*60*60;
 7466:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 7467:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 7468:                 my $sysmail = $r->dir_config('lonSysEMail');
 7469:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
 7470:             }
 7471:         } else {
 7472:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 7473:         }
 7474:     } else {
 7475:         $resulttext = '<span class="LC_error">'.
 7476:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7477:     }
 7478:     if (@errors > 0) {
 7479:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 7480:         foreach my $item (@errors) {
 7481:             $resulttext .= ' "'.$title->{$item}.'",';
 7482:         }
 7483:         $resulttext =~ s/,$//;
 7484:     }
 7485:     return $resulttext;
 7486: }
 7487: 
 7488: sub modify_scantron {
 7489:     my ($r,$dom,$confname,%domconfig) = @_;
 7490:     my ($resulttext,%confhash,%changes,$errors);
 7491:     my $custom = 'custom.tab';
 7492:     my $default = 'default.tab';
 7493:     my $servadm = $r->dir_config('lonAdmEMail');
 7494:     my ($configuserok,$author_ok,$switchserver) = 
 7495:         &config_check($dom,$confname,$servadm);
 7496:     if ($env{'form.scantronformat.filename'} ne '') {
 7497:         my $error;
 7498:         if ($configuserok eq 'ok') {
 7499:             if ($switchserver) {
 7500:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
 7501:             } else {
 7502:                 if ($author_ok eq 'ok') {
 7503:                     my ($result,$scantronurl) =
 7504:                         &publishlogo($r,'upload','scantronformat',$dom,
 7505:                                      $confname,'scantron','','',$custom);
 7506:                     if ($result eq 'ok') {
 7507:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 7508:                         $changes{'scantronformat'} = 1;
 7509:                     } else {
 7510:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 7511:                     }
 7512:                 } else {
 7513:                     $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);
 7514:                 }
 7515:             }
 7516:         } else {
 7517:             $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);
 7518:         }
 7519:         if ($error) {
 7520:             &Apache::lonnet::logthis($error);
 7521:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 7522:         }
 7523:     }
 7524:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 7525:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 7526:             if ($env{'form.scantronformat_del'}) {
 7527:                 $confhash{'scantron'}{'scantronformat'} = '';
 7528:                 $changes{'scantronformat'} = 1;
 7529:             }
 7530:         }
 7531:     }
 7532:     if (keys(%confhash) > 0) {
 7533:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 7534:                                                  $dom);
 7535:         if ($putresult eq 'ok') {
 7536:             if (keys(%changes) > 0) {
 7537:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 7538:                     $resulttext = &mt('Changes made:').'<ul>';
 7539:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 7540:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 7541:                     } else {
 7542:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 7543:                     }
 7544:                     $resulttext .= '</ul>';
 7545:                 } else {
 7546:                     $resulttext = &mt('Changes made to bubblesheet format file.');
 7547:                 }
 7548:                 $resulttext .= '</ul>';
 7549:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 7550:             } else {
 7551:                 $resulttext = &mt('No changes made to bubblesheet format file');
 7552:             }
 7553:         } else {
 7554:             $resulttext = '<span class="LC_error">'.
 7555:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 7556:         }
 7557:     } else {
 7558:         $resulttext = &mt('No changes made to bubblesheet format file'); 
 7559:     }
 7560:     if ($errors) {
 7561:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 7562:                        $errors.'</ul>';
 7563:     }
 7564:     return $resulttext;
 7565: }
 7566: 
 7567: sub modify_coursecategories {
 7568:     my ($dom,%domconfig) = @_;
 7569:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 7570:         $cathash);
 7571:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 7572:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 7573:         $cathash = $domconfig{'coursecategories'}{'cats'};
 7574:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 7575:             $changes{'togglecats'} = 1;
 7576:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 7577:         }
 7578:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 7579:             $changes{'categorize'} = 1;
 7580:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 7581:         }
 7582:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
 7583:             $changes{'togglecatscomm'} = 1;
 7584:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
 7585:         }
 7586:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
 7587:             $changes{'categorizecomm'} = 1;
 7588:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
 7589:         }
 7590:     } else {
 7591:         $changes{'togglecats'} = 1;
 7592:         $changes{'categorize'} = 1;
 7593:         $changes{'togglecatscomm'} = 1;
 7594:         $changes{'categorizecomm'} = 1;
 7595:         $domconfig{'coursecategories'} = {
 7596:                                              togglecats => $env{'form.togglecats'},
 7597:                                              categorize => $env{'form.categorize'},
 7598:                                              togglecatscomm => $env{'form.togglecatscomm'},
 7599:                                              categorizecomm => $env{'form.categorizecomm'},
 7600:                                          };
 7601:     }
 7602:     if (ref($cathash) eq 'HASH') {
 7603:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 7604:             push (@deletecategory,'instcode::0');
 7605:         }
 7606:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
 7607:             push(@deletecategory,'communities::0');
 7608:         }
 7609:     }
 7610:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 7611:     if (ref($cathash) eq 'HASH') {
 7612:         if (@deletecategory > 0) {
 7613:             #FIXME Need to remove category from all courses using a deleted category 
 7614:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 7615:             foreach my $item (@deletecategory) {
 7616:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 7617:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 7618:                     $deletions{$item} = 1;
 7619:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 7620:                 }
 7621:             }
 7622:         }
 7623:         foreach my $item (keys(%{$cathash})) {
 7624:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 7625:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 7626:                 $reorderings{$item} = 1;
 7627:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 7628:             }
 7629:             if ($env{'form.addcategory_name_'.$item} ne '') {
 7630:                 my $newcat = $env{'form.addcategory_name_'.$item};
 7631:                 my $newdepth = $depth+1;
 7632:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 7633:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 7634:                 $adds{$newitem} = 1; 
 7635:             }
 7636:             if ($env{'form.subcat_'.$item} ne '') {
 7637:                 my $newcat = $env{'form.subcat_'.$item};
 7638:                 my $newdepth = $depth+1;
 7639:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 7640:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 7641:                 $adds{$newitem} = 1;
 7642:             }
 7643:         }
 7644:     }
 7645:     if ($env{'form.instcode'} eq '1') {
 7646:         if (ref($cathash) eq 'HASH') {
 7647:             my $newitem = 'instcode::0';
 7648:             if ($cathash->{$newitem} eq '') {  
 7649:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 7650:                 $adds{$newitem} = 1;
 7651:             }
 7652:         } else {
 7653:             my $newitem = 'instcode::0';
 7654:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 7655:             $adds{$newitem} = 1;
 7656:         }
 7657:     }
 7658:     if ($env{'form.communities'} eq '1') {
 7659:         if (ref($cathash) eq 'HASH') {
 7660:             my $newitem = 'communities::0';
 7661:             if ($cathash->{$newitem} eq '') {
 7662:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 7663:                 $adds{$newitem} = 1;
 7664:             }
 7665:         } else {
 7666:             my $newitem = 'communities::0';
 7667:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 7668:             $adds{$newitem} = 1;
 7669:         }
 7670:     }
 7671:     if ($env{'form.addcategory_name'} ne '') {
 7672:         if (($env{'form.addcategory_name'} ne 'instcode') &&
 7673:             ($env{'form.addcategory_name'} ne 'communities')) {
 7674:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 7675:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 7676:             $adds{$newitem} = 1;
 7677:         }
 7678:     }
 7679:     my $putresult;
 7680:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7681:         if (keys(%deletions) > 0) {
 7682:             foreach my $key (keys(%deletions)) {
 7683:                 if ($predelallitems{$key} ne '') {
 7684:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 7685:                 }
 7686:             }
 7687:         }
 7688:         my (@chkcats,@chktrails,%chkallitems);
 7689:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 7690:         if (ref($chkcats[0]) eq 'ARRAY') {
 7691:             my $depth = 0;
 7692:             my $chg = 0;
 7693:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 7694:                 my $name = $chkcats[0][$i];
 7695:                 my $item;
 7696:                 if ($name eq '') {
 7697:                     $chg ++;
 7698:                 } else {
 7699:                     $item = &escape($name).'::0';
 7700:                     if ($chg) {
 7701:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 7702:                     }
 7703:                     $depth ++; 
 7704:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 7705:                     $depth --;
 7706:                 }
 7707:             }
 7708:         }
 7709:     }
 7710:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7711:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 7712:         if ($putresult eq 'ok') {
 7713:             my %title = (
 7714:                          togglecats     => 'Show/Hide a course in catalog',
 7715:                          categorize     => 'Assign a category to a course',
 7716:                          togglecatscomm => 'Show/Hide a community in catalog',
 7717:                          categorizecomm => 'Assign a category to a community',
 7718:                         );
 7719:             my %level = (
 7720:                          dom  => 'set in Domain ("Modify Course/Community")',
 7721:                          crs  => 'set in Course ("Course Configuration")',
 7722:                          comm => 'set in Community ("Community Configuration")',
 7723:                         );
 7724:             $resulttext = &mt('Changes made:').'<ul>';
 7725:             if ($changes{'togglecats'}) {
 7726:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 7727:             }
 7728:             if ($changes{'categorize'}) {
 7729:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 7730:             }
 7731:             if ($changes{'togglecatscomm'}) {
 7732:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
 7733:             }
 7734:             if ($changes{'categorizecomm'}) {
 7735:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
 7736:             }
 7737:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7738:                 my $cathash;
 7739:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 7740:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 7741:                 } else {
 7742:                     $cathash = {};
 7743:                 } 
 7744:                 my (@cats,@trails,%allitems);
 7745:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 7746:                 if (keys(%deletions) > 0) {
 7747:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 7748:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 7749:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 7750:                     }
 7751:                     $resulttext .= '</ul></li>';
 7752:                 }
 7753:                 if (keys(%reorderings) > 0) {
 7754:                     my %sort_by_trail;
 7755:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 7756:                     foreach my $key (keys(%reorderings)) {
 7757:                         if ($allitems{$key} ne '') {
 7758:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 7759:                         }
 7760:                     }
 7761:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 7762:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 7763:                     }
 7764:                     $resulttext .= '</ul></li>';
 7765:                 }
 7766:                 if (keys(%adds) > 0) {
 7767:                     my %sort_by_trail;
 7768:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
 7769:                     foreach my $key (keys(%adds)) {
 7770:                         if ($allitems{$key} ne '') {
 7771:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 7772:                         }
 7773:                     }
 7774:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 7775:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 7776:                     }
 7777:                     $resulttext .= '</ul></li>';
 7778:                 }
 7779:             }
 7780:             $resulttext .= '</ul>';
 7781:         } else {
 7782:             $resulttext = '<span class="LC_error">'.
 7783:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 7784:         }
 7785:     } else {
 7786:         $resulttext = &mt('No changes made to course and community categories');
 7787:     }
 7788:     return $resulttext;
 7789: }
 7790: 
 7791: sub modify_serverstatuses {
 7792:     my ($dom,%domconfig) = @_;
 7793:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
 7794:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
 7795:         %currserverstatus = %{$domconfig{'serverstatuses'}};
 7796:     }
 7797:     my @pages = &serverstatus_pages();
 7798:     foreach my $type (@pages) {
 7799:         $newserverstatus{$type}{'namedusers'} = '';
 7800:         $newserverstatus{$type}{'machines'} = '';
 7801:         if (defined($env{'form.'.$type.'_namedusers'})) {
 7802:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
 7803:             my @okusers;
 7804:             foreach my $user (@users) {
 7805:                 my ($uname,$udom) = split(/:/,$user);
 7806:                 if (($udom =~ /^$match_domain$/) &&   
 7807:                     (&Apache::lonnet::domain($udom)) &&
 7808:                     ($uname =~ /^$match_username$/)) {
 7809:                     if (!grep(/^\Q$user\E/,@okusers)) {
 7810:                         push(@okusers,$user);
 7811:                     }
 7812:                 }
 7813:             }
 7814:             if (@okusers > 0) {
 7815:                  @okusers = sort(@okusers);
 7816:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
 7817:             }
 7818:         }
 7819:         if (defined($env{'form.'.$type.'_machines'})) {
 7820:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
 7821:             my @okmachines;
 7822:             foreach my $ip (@machines) {
 7823:                 my @parts = split(/\./,$ip);
 7824:                 next if (@parts < 4);
 7825:                 my $badip = 0;
 7826:                 for (my $i=0; $i<4; $i++) {
 7827:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
 7828:                         $badip = 1;
 7829:                         last;
 7830:                     }
 7831:                 }
 7832:                 if (!$badip) {
 7833:                     push(@okmachines,$ip);     
 7834:                 }
 7835:             }
 7836:             @okmachines = sort(@okmachines);
 7837:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
 7838:         }
 7839:     }
 7840:     my %serverstatushash =  (
 7841:                                 serverstatuses => \%newserverstatus,
 7842:                             );
 7843:     foreach my $type (@pages) {
 7844:         foreach my $setting ('namedusers','machines') {
 7845:             my (@current,@new);
 7846:             if (ref($currserverstatus{$type}) eq 'HASH') {
 7847:                 if ($currserverstatus{$type}{$setting} ne '') { 
 7848:                     @current = split(/,/,$currserverstatus{$type}{$setting});
 7849:                 }
 7850:             }
 7851:             if ($newserverstatus{$type}{$setting} ne '') {
 7852:                 @new = split(/,/,$newserverstatus{$type}{$setting});
 7853:             }
 7854:             if (@current > 0) {
 7855:                 if (@new > 0) {
 7856:                     foreach my $item (@current) {
 7857:                         if (!grep(/^\Q$item\E$/,@new)) {
 7858:                             $changes{$type}{$setting} = 1;
 7859:                             last;
 7860:                         }
 7861:                     }
 7862:                     foreach my $item (@new) {
 7863:                         if (!grep(/^\Q$item\E$/,@current)) {
 7864:                             $changes{$type}{$setting} = 1;
 7865:                             last;
 7866:                         }
 7867:                     }
 7868:                 } else {
 7869:                     $changes{$type}{$setting} = 1;
 7870:                 }
 7871:             } elsif (@new > 0) {
 7872:                 $changes{$type}{$setting} = 1;
 7873:             }
 7874:         }
 7875:     }
 7876:     if (keys(%changes) > 0) {
 7877:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 7878:         my $putresult = &Apache::lonnet::put_dom('configuration',
 7879:                                                  \%serverstatushash,$dom);
 7880:         if ($putresult eq 'ok') {
 7881:             $resulttext .= &mt('Changes made:').'<ul>';
 7882:             foreach my $type (@pages) {
 7883:                 if (ref($changes{$type}) eq 'HASH') {
 7884:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
 7885:                     if ($changes{$type}{'namedusers'}) {
 7886:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
 7887:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
 7888:                         } else {
 7889:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
 7890:                         }
 7891:                     }
 7892:                     if ($changes{$type}{'machines'}) {
 7893:                         if ($newserverstatus{$type}{'machines'} eq '') {
 7894:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
 7895:                         } else {
 7896:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
 7897:                         }
 7898: 
 7899:                     }
 7900:                     $resulttext .= '</ul></li>';
 7901:                 }
 7902:             }
 7903:             $resulttext .= '</ul>';
 7904:         } else {
 7905:             $resulttext = '<span class="LC_error">'.
 7906:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
 7907: 
 7908:         }
 7909:     } else {
 7910:         $resulttext = &mt('No changes made to access to server status pages');
 7911:     }
 7912:     return $resulttext;
 7913: }
 7914: 
 7915: sub modify_helpsettings {
 7916:     my ($r,$dom,$confname,%domconfig) = @_;
 7917:     my ($resulttext,$errors,%changes,%helphash);
 7918:     my %defaultchecked = ('submitbugs' => 'on');
 7919:     my @offon = ('off','on');
 7920:     my @toggles = ('submitbugs');
 7921:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
 7922:         foreach my $item (@toggles) {
 7923:             if ($defaultchecked{$item} eq 'on') { 
 7924:                 if ($domconfig{'helpsettings'}{$item} eq '') {
 7925:                     if ($env{'form.'.$item} eq '0') {
 7926:                         $changes{$item} = 1;
 7927:                     }
 7928:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 7929:                     $changes{$item} = 1;
 7930:                 }
 7931:             } elsif ($defaultchecked{$item} eq 'off') {
 7932:                 if ($domconfig{'helpsettings'}{$item} eq '') {
 7933:                     if ($env{'form.'.$item} eq '1') {
 7934:                         $changes{$item} = 1;
 7935:                     }
 7936:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 7937:                     $changes{$item} = 1;
 7938:                 }
 7939:             }
 7940:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { 
 7941:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
 7942:             }
 7943:         }
 7944:     }
 7945:     my $putresult;
 7946:     if (keys(%changes) > 0) {
 7947:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
 7948:         if ($putresult eq 'ok') {
 7949:             $resulttext = &mt('Changes made:').'<ul>';
 7950:             foreach my $item (sort(keys(%changes))) {
 7951:                 if ($item eq 'submitbugs') {
 7952:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
 7953:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
 7954:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
 7955:                 }
 7956:             }
 7957:             $resulttext .= '</ul>';
 7958:         } else {
 7959:             $resulttext = &mt('No changes made to help settings');
 7960:             $errors .= '<li><span class="LC_error">'.
 7961:                        &mt('An error occurred storing the settings: [_1]',
 7962:                            $putresult).'</span></li>';
 7963:         }
 7964:     }
 7965:     if ($errors) {
 7966:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 7967:                        $errors.'</ul>';
 7968:     }
 7969:     return $resulttext;
 7970: }
 7971: 
 7972: sub modify_coursedefaults {
 7973:     my ($dom,%domconfig) = @_;
 7974:     my ($resulttext,$errors,%changes,%defaultshash);
 7975:     my %defaultchecked = ('canuse_pdfforms' => 'off');
 7976:     my @toggles = ('canuse_pdfforms');
 7977:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
 7978:                    'uploadquota_community');
 7979:     my @types = ('official','unofficial','community');
 7980:     my %staticdefaults = (
 7981:                            anonsurvey_threshold => 10,
 7982:                            uploadquota          => 500,
 7983:                          );
 7984: 
 7985:     $defaultshash{'coursedefaults'} = {};
 7986: 
 7987:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
 7988:         if ($domconfig{'coursedefaults'} eq '') {
 7989:             $domconfig{'coursedefaults'} = {};
 7990:         }
 7991:     }
 7992: 
 7993:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
 7994:         foreach my $item (@toggles) {
 7995:             if ($defaultchecked{$item} eq 'on') {
 7996:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 7997:                     ($env{'form.'.$item} eq '0')) {
 7998:                     $changes{$item} = 1;
 7999:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 8000:                     $changes{$item} = 1;
 8001:                 }
 8002:             } elsif ($defaultchecked{$item} eq 'off') {
 8003:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 8004:                     ($env{'form.'.$item} eq '1')) {
 8005:                     $changes{$item} = 1;
 8006:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 8007:                     $changes{$item} = 1;
 8008:                 }
 8009:             }
 8010:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
 8011:         }
 8012:         foreach my $item (@numbers) {
 8013:             my ($currdef,$newdef);
 8014:             my $newdef = $env{'form.'.$item};
 8015:             if ($item eq 'anonsurvey_threshold') {
 8016:                 $currdef = $domconfig{'coursedefaults'}{$item};
 8017:                 $newdef =~ s/\D//g;
 8018:                 if ($newdef eq '' || $newdef < 1) {
 8019:                     $newdef = 1;
 8020:                 }
 8021:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
 8022:             } else {
 8023:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
 8024:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8025:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
 8026:                 }
 8027:                 $newdef =~ s/[^\w.\-]//g;
 8028:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
 8029:             }
 8030:             if ($currdef ne $newdef) {
 8031:                 my $staticdef;
 8032:                 if ($item eq 'anonsurvey_threshold') {
 8033:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
 8034:                         $changes{$item} = 1;
 8035:                     }
 8036:                 } else {
 8037:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
 8038:                         $changes{'uploadquota'} = 1;
 8039:                     }
 8040:                 }
 8041:             }
 8042:         }
 8043:         my $officialcreds = $env{'form.official_credits'};
 8044:         $officialcreds =~ s/^[^\d\.]//g;
 8045:         my $unofficialcreds = $env{'form.unofficial_credits'};
 8046:         $unofficialcreds =~ s/^[^\d\.]//g;
 8047:         if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
 8048:                 ($env{'form.coursecredits'} eq '1')) {
 8049:                 $changes{'coursecredits'} = 1;
 8050:         } else {
 8051:             if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
 8052:                 ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
 8053:                 $changes{'coursecredits'} = 1;
 8054:             }
 8055:         }
 8056:         $defaultshash{'coursedefaults'}{'coursecredits'} = {
 8057:             official   => $officialcreds,
 8058:             unofficial => $unofficialcreds,
 8059:         }
 8060:     }
 8061:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 8062:                                              $dom);
 8063:     if ($putresult eq 'ok') {
 8064:         my %domdefaults;
 8065:         if (keys(%changes) > 0) {
 8066:             if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
 8067:                 %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 8068:                 if ($changes{'canuse_pdfforms'}) {
 8069:                     $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
 8070:                 }
 8071:                 if ($changes{'coursecredits'}) {
 8072:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
 8073:                         $domdefaults{'officialcredits'} =
 8074:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
 8075:                         $domdefaults{'unofficialcredits'} =
 8076:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
 8077:                     }
 8078:                 }
 8079:                 if ($changes{'uploadquota'}) {
 8080:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8081:                         foreach my $type (@types) {
 8082:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
 8083:                         }
 8084:                     }
 8085:                 }
 8086:                 my $cachetime = 24*60*60;
 8087:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 8088:             }
 8089:             $resulttext = &mt('Changes made:').'<ul>';
 8090:             foreach my $item (sort(keys(%changes))) {
 8091:                 if ($item eq 'canuse_pdfforms') {
 8092:                     if ($env{'form.'.$item} eq '1') {
 8093:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
 8094:                     } else {
 8095:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
 8096:                     }
 8097:                 } elsif ($item eq 'anonsurvey_threshold') {
 8098:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
 8099:                 } elsif ($item eq 'uploadquota') {
 8100:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8101:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
 8102:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
 8103:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
 8104:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
 8105:                                        '</ul>'.
 8106:                                        '</li>';
 8107:                     } else {
 8108:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
 8109:                     }
 8110:                 } elsif ($item eq 'coursecredits') {
 8111:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
 8112:                         if (($domdefaults{'officialcredits'} eq '') &&
 8113:                             ($domdefaults{'unofficialcredits'} eq '')) {
 8114:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
 8115:                         } else {
 8116:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
 8117:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
 8118:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
 8119:                                            '</ul>'.
 8120:                                            '</li>';
 8121:                         }
 8122:                     } else {
 8123:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
 8124:                     }
 8125:                 }
 8126:             }
 8127:             $resulttext .= '</ul>';
 8128:         } else {
 8129:             $resulttext = &mt('No changes made to course defaults');
 8130:         }
 8131:     } else {
 8132:         $resulttext = '<span class="LC_error">'.
 8133:             &mt('An error occurred: [_1]',$putresult).'</span>';
 8134:     }
 8135:     return $resulttext;
 8136: }
 8137: 
 8138: sub modify_usersessions {
 8139:     my ($dom,%domconfig) = @_;
 8140:     my @hostingtypes = ('version','excludedomain','includedomain');
 8141:     my @offloadtypes = ('primary','default');
 8142:     my %types = (
 8143:                   remote => \@hostingtypes,
 8144:                   hosted => \@hostingtypes,
 8145:                   spares => \@offloadtypes,
 8146:                 );
 8147:     my @prefixes = ('remote','hosted','spares');
 8148:     my @lcversions = &Apache::lonnet::all_loncaparevs();
 8149:     my (%by_ip,%by_location,@intdoms);
 8150:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 8151:     my @locations = sort(keys(%by_location));
 8152:     my (%defaultshash,%changes);
 8153:     foreach my $prefix (@prefixes) {
 8154:         $defaultshash{'usersessions'}{$prefix} = {};
 8155:     }
 8156:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 8157:     my $resulttext;
 8158:     my %iphost = &Apache::lonnet::get_iphost();
 8159:     foreach my $prefix (@prefixes) {
 8160:         next if ($prefix eq 'spares');
 8161:         foreach my $type (@{$types{$prefix}}) {
 8162:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
 8163:             if ($type eq 'version') {
 8164:                 my $value = $env{'form.'.$prefix.'_'.$type};
 8165:                 my $okvalue;
 8166:                 if ($value ne '') {
 8167:                     if (grep(/^\Q$value\E$/,@lcversions)) {
 8168:                         $okvalue = $value;
 8169:                     }
 8170:                 }
 8171:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8172:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 8173:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
 8174:                             if ($inuse == 0) {
 8175:                                 $changes{$prefix}{$type} = 1;
 8176:                             } else {
 8177:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
 8178:                                     $changes{$prefix}{$type} = 1;
 8179:                                 }
 8180:                                 if ($okvalue ne '') {
 8181:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8182:                                 } 
 8183:                             }
 8184:                         } else {
 8185:                             if (($inuse == 1) && ($okvalue ne '')) {
 8186:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8187:                                 $changes{$prefix}{$type} = 1;
 8188:                             }
 8189:                         }
 8190:                     } else {
 8191:                         if (($inuse == 1) && ($okvalue ne '')) {
 8192:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8193:                             $changes{$prefix}{$type} = 1;
 8194:                         }
 8195:                     }
 8196:                 } else {
 8197:                     if (($inuse == 1) && ($okvalue ne '')) {
 8198:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8199:                         $changes{$prefix}{$type} = 1;
 8200:                     }
 8201:                 }
 8202:             } else {
 8203:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
 8204:                 my @okvals;
 8205:                 foreach my $val (@vals) {
 8206:                     if ($val =~ /:/) {
 8207:                         my @items = split(/:/,$val);
 8208:                         foreach my $item (@items) {
 8209:                             if (ref($by_location{$item}) eq 'ARRAY') {
 8210:                                 push(@okvals,$item);
 8211:                             }
 8212:                         }
 8213:                     } else {
 8214:                         if (ref($by_location{$val}) eq 'ARRAY') {
 8215:                             push(@okvals,$val);
 8216:                         }
 8217:                     }
 8218:                 }
 8219:                 @okvals = sort(@okvals);
 8220:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8221:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 8222:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 8223:                             if ($inuse == 0) {
 8224:                                 $changes{$prefix}{$type} = 1; 
 8225:                             } else {
 8226:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8227:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
 8228:                                 if (@changed > 0) {
 8229:                                     $changes{$prefix}{$type} = 1;
 8230:                                 }
 8231:                             }
 8232:                         } else {
 8233:                             if ($inuse == 1) {
 8234:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8235:                                 $changes{$prefix}{$type} = 1;
 8236:                             }
 8237:                         } 
 8238:                     } else {
 8239:                         if ($inuse == 1) {
 8240:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8241:                             $changes{$prefix}{$type} = 1;
 8242:                         }
 8243:                     }
 8244:                 } else {
 8245:                     if ($inuse == 1) {
 8246:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8247:                         $changes{$prefix}{$type} = 1;
 8248:                     }
 8249:                 }
 8250:             }
 8251:         }
 8252:     }
 8253: 
 8254:     my @alldoms = &Apache::lonnet::all_domains();
 8255:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 8256:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
 8257:     my $savespares;
 8258: 
 8259:     foreach my $lonhost (sort(keys(%servers))) {
 8260:         my $serverhomeID =
 8261:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
 8262:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
 8263:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
 8264:         my %spareschg;
 8265:         foreach my $type (@{$types{'spares'}}) {
 8266:             my @okspares;
 8267:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
 8268:             foreach my $server (@checked) {
 8269:                 if (&Apache::lonnet::hostname($server) ne '') {
 8270:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
 8271:                         unless (grep(/^\Q$server\E$/,@okspares)) {
 8272:                             push(@okspares,$server);
 8273:                         }
 8274:                     }
 8275:                 }
 8276:             }
 8277:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
 8278:             my $newspare;
 8279:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
 8280:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
 8281:                     $newspare = $new;
 8282:                 }
 8283:             }
 8284:             my @spares;
 8285:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
 8286:                 @spares = sort(@okspares,$newspare);
 8287:             } else {
 8288:                 @spares = sort(@okspares);
 8289:             }
 8290:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
 8291:             if (ref($spareid{$lonhost}) eq 'HASH') {
 8292:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
 8293:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
 8294:                     if (@diffs > 0) {
 8295:                         $spareschg{$type} = 1;
 8296:                     }
 8297:                 }
 8298:             }
 8299:         }
 8300:         if (keys(%spareschg) > 0) {
 8301:             $changes{'spares'}{$lonhost} = \%spareschg;
 8302:         }
 8303:     }
 8304: 
 8305:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8306:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
 8307:             if (ref($changes{'spares'}) eq 'HASH') {
 8308:                 if (keys(%{$changes{'spares'}}) > 0) {
 8309:                     $savespares = 1;
 8310:                 }
 8311:             }
 8312:         } else {
 8313:             $savespares = 1;
 8314:         }
 8315:     }
 8316: 
 8317:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
 8318:     if ((keys(%changes) > 0) || ($savespares)) {
 8319:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 8320:                                                  $dom);
 8321:         if ($putresult eq 'ok') {
 8322:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 8323:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
 8324:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
 8325:                 }
 8326:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
 8327:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
 8328:                 }
 8329:             }
 8330:             my $cachetime = 24*60*60;
 8331:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 8332:             if (keys(%changes) > 0) {
 8333:                 my %lt = &usersession_titles();
 8334:                 $resulttext = &mt('Changes made:').'<ul>';
 8335:                 foreach my $prefix (@prefixes) {
 8336:                     if (ref($changes{$prefix}) eq 'HASH') {
 8337:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
 8338:                         if ($prefix eq 'spares') {
 8339:                             if (ref($changes{$prefix}) eq 'HASH') {
 8340:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
 8341:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
 8342:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
 8343:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
 8344:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
 8345:                                         foreach my $type (@{$types{$prefix}}) {
 8346:                                             if ($changes{$prefix}{$lonhost}{$type}) {
 8347:                                                 my $offloadto = &mt('None');
 8348:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
 8349:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
 8350:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
 8351:                                                     }
 8352:                                                 }
 8353:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
 8354:                                             }
 8355:                                         }
 8356:                                     }
 8357:                                     $resulttext .= '</li>';
 8358:                                 }
 8359:                             }
 8360:                         } else {
 8361:                             foreach my $type (@{$types{$prefix}}) {
 8362:                                 if (defined($changes{$prefix}{$type})) {
 8363:                                     my $newvalue;
 8364:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 8365:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
 8366:                                             if ($type eq 'version') {
 8367:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
 8368:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 8369:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
 8370:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
 8371:                                                 }
 8372:                                             }
 8373:                                         }
 8374:                                     }
 8375:                                     if ($newvalue eq '') {
 8376:                                         if ($type eq 'version') {
 8377:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
 8378:                                         } else {
 8379:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
 8380:                                         }
 8381:                                     } else {
 8382:                                         if ($type eq 'version') {
 8383:                                             $newvalue .= ' '.&mt('(or later)'); 
 8384:                                         }
 8385:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
 8386:                                     }
 8387:                                 }
 8388:                             }
 8389:                         }
 8390:                         $resulttext .= '</ul>';
 8391:                     }
 8392:                 }
 8393:                 $resulttext .= '</ul>';
 8394:             } else {
 8395:                 $resulttext = $nochgmsg;
 8396:             }
 8397:         } else {
 8398:             $resulttext = '<span class="LC_error">'.
 8399:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 8400:         }
 8401:     } else {
 8402:         $resulttext = $nochgmsg;
 8403:     }
 8404:     return $resulttext;
 8405: }
 8406: 
 8407: sub modify_loadbalancing {
 8408:     my ($dom,%domconfig) = @_;
 8409:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
 8410:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
 8411:     my ($othertitle,$usertypes,$types) =
 8412:         &Apache::loncommon::sorted_inst_types($dom);
 8413:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 8414:     my @sparestypes = ('primary','default');
 8415:     my %typetitles = &sparestype_titles();
 8416:     my $resulttext;
 8417:     my (%currbalancer,%currtargets,%currrules,%existing);
 8418:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
 8419:         %existing = %{$domconfig{'loadbalancing'}};
 8420:     }
 8421:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
 8422:                               \%currtargets,\%currrules);
 8423:     my ($saveloadbalancing,%defaultshash,%changes);
 8424:     my ($alltypes,$othertypes,$titles) =
 8425:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
 8426:     my %ruletitles = &offloadtype_text();
 8427:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
 8428:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
 8429:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
 8430:         if ($balancer eq '') {
 8431:             next;
 8432:         }
 8433:         if (!exists($servers{$balancer})) { 
 8434:             if (exists($currbalancer{$balancer})) {
 8435:                 push(@{$changes{'delete'}},$balancer);
 8436:             }
 8437:             next;
 8438:         }
 8439:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
 8440:             push(@{$changes{'delete'}},$balancer);
 8441:             next;
 8442:         }
 8443:         if (!exists($currbalancer{$balancer})) {
 8444:             push(@{$changes{'add'}},$balancer);
 8445:         }
 8446:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
 8447:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
 8448:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
 8449:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
 8450:             $saveloadbalancing = 1;
 8451:         }
 8452:         foreach my $sparetype (@sparestypes) {
 8453:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
 8454:             my @offloadto;
 8455:             foreach my $target (@targets) {
 8456:                 if (($servers{$target}) && ($target ne $balancer)) {
 8457:                     if ($sparetype eq 'default') {
 8458:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
 8459:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
 8460:                         }
 8461:                     }
 8462:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
 8463:                         push(@offloadto,$target);
 8464:                     }
 8465:                 }
 8466:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
 8467:             }
 8468:         }
 8469:         if (ref($currtargets{$balancer}) eq 'HASH') {
 8470:             foreach my $sparetype (@sparestypes) {
 8471:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
 8472:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
 8473:                     if (@targetdiffs > 0) {
 8474:                         $changes{'curr'}{$balancer}{'targets'} = 1;
 8475:                     }
 8476:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8477:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8478:                         $changes{'curr'}{$balancer}{'targets'} = 1;
 8479:                     }
 8480:                 }
 8481:             }
 8482:         } else {
 8483:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
 8484:                 foreach my $sparetype (@sparestypes) { 
 8485:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8486:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8487:                             $changes{'curr'}{$balancer}{'targets'} = 1;
 8488:                         }
 8489:                     }
 8490:                 }
 8491:             }  
 8492:         }
 8493:         my $ishomedom;
 8494:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
 8495:             $ishomedom = 1;
 8496:         }
 8497:         if (ref($alltypes) eq 'ARRAY') {
 8498:             foreach my $type (@{$alltypes}) {
 8499:                 my $rule;
 8500:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
 8501:                          (!$ishomedom)) {
 8502:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
 8503:                 }
 8504:                 if ($rule eq 'specific') {
 8505:                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
 8506:                 }
 8507:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
 8508:                 if (ref($currrules{$balancer}) eq 'HASH') {
 8509:                     if ($rule ne $currrules{$balancer}{$type}) {
 8510:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
 8511:                     }
 8512:                 } elsif ($rule ne '') {
 8513:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
 8514:                 }
 8515:             }
 8516:         }
 8517:     }
 8518:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
 8519:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
 8520:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
 8521:             $defaultshash{'loadbalancing'} = {};
 8522:         }
 8523:         my $putresult = &Apache::lonnet::put_dom('configuration',
 8524:                                                  \%defaultshash,$dom);
 8525:  
 8526:         if ($putresult eq 'ok') {
 8527:             if (keys(%changes) > 0) {
 8528:                 if (ref($changes{'delete'}) eq 'ARRAY') {
 8529:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
 8530:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
 8531:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
 8532:                     }
 8533:                 }
 8534:                 if (ref($changes{'add'}) eq 'ARRAY') {
 8535:                     foreach my $balancer (sort(@{$changes{'add'}})) {   
 8536:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
 8537:                     }
 8538:                 }
 8539:                 if (ref($changes{'curr'}) eq 'HASH') {
 8540:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
 8541:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
 8542:                             if ($changes{'curr'}{$balancer}{'targets'}) {
 8543:                                 my %offloadstr;
 8544:                                 foreach my $sparetype (@sparestypes) {
 8545:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8546:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8547:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
 8548:                                         }
 8549:                                     }
 8550:                                 }
 8551:                                 if (keys(%offloadstr) == 0) {
 8552:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
 8553:                                 } else {
 8554:                                     my $showoffload;
 8555:                                     foreach my $sparetype (@sparestypes) {
 8556:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
 8557:                                         if (defined($offloadstr{$sparetype})) {
 8558:                                             $showoffload .= $offloadstr{$sparetype};
 8559:                                         } else {
 8560:                                             $showoffload .= &mt('None');
 8561:                                         }
 8562:                                         $showoffload .= ('&nbsp;'x3);
 8563:                                     }
 8564:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
 8565:                                 }
 8566:                             }
 8567:                         }
 8568:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
 8569:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
 8570:                                 foreach my $type (@{$alltypes}) {
 8571:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
 8572:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
 8573:                                         my $balancetext;
 8574:                                         if ($rule eq '') {
 8575:                                             $balancetext =  $ruletitles{'default'};
 8576:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
 8577:                                             $balancetext =  $ruletitles{$rule};
 8578:                                         } else {
 8579:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
 8580:                                         }
 8581:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';     
 8582:                                     }
 8583:                                 }
 8584:                             }
 8585:                         }
 8586:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
 8587:                     }
 8588:                 }
 8589:                 if ($resulttext ne '') {
 8590:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
 8591:                 } else {
 8592:                     $resulttext = $nochgmsg;
 8593:                 }
 8594:             } else {
 8595:                 $resulttext = $nochgmsg;
 8596:             }
 8597:         } else {
 8598:             $resulttext = '<span class="LC_error">'.
 8599:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 8600:         }
 8601:     } else {
 8602:         $resulttext = $nochgmsg;
 8603:     }
 8604:     return $resulttext;
 8605: }
 8606: 
 8607: sub recurse_check {
 8608:     my ($chkcats,$categories,$depth,$name) = @_;
 8609:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
 8610:         my $chg = 0;
 8611:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
 8612:             my $category = $chkcats->[$depth]{$name}[$j];
 8613:             my $item;
 8614:             if ($category eq '') {
 8615:                 $chg ++;
 8616:             } else {
 8617:                 my $deeper = $depth + 1;
 8618:                 $item = &escape($category).':'.&escape($name).':'.$depth;
 8619:                 if ($chg) {
 8620:                     $categories->{$item} -= $chg;
 8621:                 }
 8622:                 &recurse_check($chkcats,$categories,$deeper,$category);
 8623:                 $deeper --;
 8624:             }
 8625:         }
 8626:     }
 8627:     return;
 8628: }
 8629: 
 8630: sub recurse_cat_deletes {
 8631:     my ($item,$coursecategories,$deletions) = @_;
 8632:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 8633:     my $subdepth = $depth + 1;
 8634:     if (ref($coursecategories) eq 'HASH') {
 8635:         foreach my $subitem (keys(%{$coursecategories})) {
 8636:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
 8637:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
 8638:                 delete($coursecategories->{$subitem});
 8639:                 $deletions->{$subitem} = 1;
 8640:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
 8641:             }
 8642:         }
 8643:     }
 8644:     return;
 8645: }
 8646: 
 8647: sub get_active_dcs {
 8648:     my ($dom) = @_;
 8649:     my $now = time;
 8650:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
 8651:     my %domcoords;
 8652:     my $numdcs = 0;
 8653:     foreach my $server (keys(%dompersonnel)) {
 8654:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 8655:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 8656:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
 8657:         }
 8658:     }
 8659:     return %domcoords;
 8660: }
 8661: 
 8662: sub active_dc_picker {
 8663:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
 8664:     my %domcoords = &get_active_dcs($dom); 
 8665:     my @domcoord = keys(%domcoords);
 8666:     if (keys(%currhash)) {
 8667:         foreach my $dc (keys(%currhash)) {
 8668:             unless (exists($domcoords{$dc})) {
 8669:                 push(@domcoord,$dc);
 8670:             }
 8671:         }
 8672:     }
 8673:     @domcoord = sort(@domcoord);
 8674:     my $numdcs = scalar(@domcoord); 
 8675:     my $rows = 0;
 8676:     my $table;
 8677:     if ($numdcs > 1) {
 8678:         $table = '<table>';
 8679:         for (my $i=0; $i<@domcoord; $i++) {
 8680:             my $rem = $i%($numinrow);
 8681:             if ($rem == 0) {
 8682:                 if ($i > 0) {
 8683:                     $table .= '</tr>';
 8684:                 }
 8685:                 $table .= '<tr>';
 8686:                 $rows ++;
 8687:             }
 8688:             my $check = '';
 8689:             if ($inputtype eq 'radio') {
 8690:                 if (keys(%currhash) == 0) {
 8691:                     if (!$i) {
 8692:                         $check = ' checked="checked"';
 8693:                     }
 8694:                 } elsif (exists($currhash{$domcoord[$i]})) {
 8695:                     $check = ' checked="checked"';
 8696:                 }
 8697:             } else {
 8698:                 if (exists($currhash{$domcoord[$i]})) {
 8699:                     $check = ' checked="checked"';
 8700:                 }
 8701:             }
 8702:             if ($i == @domcoord - 1) {
 8703:                 my $colsleft = $numinrow - $rem;
 8704:                 if ($colsleft > 1) {
 8705:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
 8706:                 } else {
 8707:                     $table .= '<td class="LC_left_item">';
 8708:                 }
 8709:             } else {
 8710:                 $table .= '<td class="LC_left_item">';
 8711:             }
 8712:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
 8713:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
 8714:             $table .= '<span class="LC_nobreak"><label>'.
 8715:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
 8716:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
 8717:             if ($user ne $dcname.':'.$dcdom) {
 8718:                 $table .=  ' ('.$dcname.':'.$dcdom.')'.
 8719:                            '</label></span></td>';
 8720:             }
 8721:         }
 8722:         $table .= '</tr></table>';
 8723:     } elsif ($numdcs == 1) {
 8724:         if ($inputtype eq 'radio') {
 8725:             $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
 8726:         } else {
 8727:             my $check;
 8728:             if (exists($currhash{$domcoord[0]})) {
 8729:                 $check = ' checked="checked"';
 8730:             }
 8731:             $table .= '<input type="checkbox" name="'.$name.'" '.
 8732:                       'value="'.$domcoord[0].'"'.$check.' />';
 8733:             $rows ++;
 8734:         }
 8735:     }
 8736:     return ($numdcs,$table,$rows);
 8737: }
 8738: 
 8739: sub usersession_titles {
 8740:     return &Apache::lonlocal::texthash(
 8741:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
 8742:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
 8743:                spares => 'Servers offloaded to, when busy',
 8744:                version => 'LON-CAPA version requirement',
 8745:                excludedomain => 'Allow all, but exclude specific domains',
 8746:                includedomain => 'Deny all, but include specific domains',
 8747:                primary => 'Primary (checked first)',
 8748:                default => 'Default',
 8749:            );
 8750: }
 8751: 
 8752: sub id_for_thisdom {
 8753:     my (%servers) = @_;
 8754:     my %altids;
 8755:     foreach my $server (keys(%servers)) {
 8756:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
 8757:         if ($serverhome ne $server) {
 8758:             $altids{$serverhome} = $server;
 8759:         }
 8760:     }
 8761:     return %altids;
 8762: }
 8763: 
 8764: sub count_servers {
 8765:     my ($currbalancer,%servers) = @_;
 8766:     my (@spares,$numspares);
 8767:     foreach my $lonhost (sort(keys(%servers))) {
 8768:         next if ($currbalancer eq $lonhost);
 8769:         push(@spares,$lonhost);
 8770:     }
 8771:     if ($currbalancer) {
 8772:         $numspares = scalar(@spares);
 8773:     } else {
 8774:         $numspares = scalar(@spares) - 1;
 8775:     }
 8776:     return ($numspares,@spares);
 8777: }
 8778: 
 8779: sub lonbalance_targets_js {
 8780:     my ($dom,$types,$servers,$settings) = @_;
 8781:     my $select = &mt('Select');
 8782:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
 8783:     if (ref($servers) eq 'HASH') {
 8784:         $alltargets = join("','",sort(keys(%{$servers})));
 8785:         my @homedoms;
 8786:         foreach my $server (sort(keys(%{$servers}))) {
 8787:             if (&Apache::lonnet::host_domain($server) eq $dom) {
 8788:                 push(@homedoms,'1');
 8789:             } else {
 8790:                 push(@homedoms,'0');
 8791:             }
 8792:         }
 8793:         $allishome = join("','",@homedoms);
 8794:     }
 8795:     if (ref($types) eq 'ARRAY') {
 8796:         if (@{$types} > 0) {
 8797:             @alltypes = @{$types};
 8798:         }
 8799:     }
 8800:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
 8801:     $allinsttypes = join("','",@alltypes);
 8802:     my (%currbalancer,%currtargets,%currrules,%existing);
 8803:     if (ref($settings) eq 'HASH') {
 8804:         %existing = %{$settings};
 8805:     }
 8806:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
 8807:                               \%currtargets,\%currrules);
 8808:     my $balancers = join("','",sort(keys(%currbalancer))); 
 8809:     return <<"END";
 8810: 
 8811: <script type="text/javascript">
 8812: // <![CDATA[
 8813: 
 8814: currBalancers = new Array('$balancers');
 8815: 
 8816: function toggleTargets(balnum) {
 8817:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
 8818:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
 8819:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
 8820:     var prevbalancer = prevhostitem.value;
 8821:     var baltotal = document.getElementById('loadbalancing_total').value;
 8822:     prevhostitem.value = balancer;
 8823:     if (prevbalancer != '') {
 8824:         var prevIdx = currBalancers.indexOf(prevbalancer);
 8825:         if (prevIdx != -1) {
 8826:             currBalancers.splice(prevIdx,1);
 8827:         }
 8828:     }
 8829:     if (balancer == '') {
 8830:         hideSpares(balnum);
 8831:     } else {
 8832:         var currIdx = currBalancers.indexOf(balancer);
 8833:         if (currIdx == -1) {
 8834:             currBalancers.push(balancer);
 8835:         }
 8836:         var homedoms = new Array('$allishome');
 8837:         var ishomedom = homedoms[lonhostitem.selectedIndex];
 8838:         showSpares(balancer,ishomedom,balnum);
 8839:     }
 8840:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
 8841:     return;
 8842: }
 8843: 
 8844: function showSpares(balancer,ishomedom,balnum) {
 8845:     var alltargets = new Array('$alltargets');
 8846:     var insttypes = new Array('$allinsttypes');
 8847:     var offloadtypes = new Array('primary','default');
 8848: 
 8849:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
 8850:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
 8851:  
 8852:     for (var i=0; i<offloadtypes.length; i++) {
 8853:         var count = 0;
 8854:         for (var j=0; j<alltargets.length; j++) {
 8855:             if (alltargets[j] != balancer) {
 8856:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
 8857:                 item.value = alltargets[j];
 8858:                 item.style.textAlign='left';
 8859:                 item.style.textFace='normal';
 8860:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
 8861:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
 8862:                     item.disabled = '';
 8863:                 } else {
 8864:                     item.disabled = 'disabled';
 8865:                     item.checked = false;
 8866:                 }
 8867:                 count ++;
 8868:             }
 8869:         }
 8870:     }
 8871:     for (var k=0; k<insttypes.length; k++) {
 8872:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
 8873:             if (ishomedom == 1) {
 8874:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
 8875:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
 8876:             } else {
 8877:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
 8878:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
 8879: 
 8880:             }
 8881:         } else {
 8882:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
 8883:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
 8884:         }
 8885:         if ((insttypes[k] != '_LC_external') && 
 8886:             ((insttypes[k] != '_LC_internetdom') ||
 8887:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
 8888:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
 8889:             item.options.length = 0;
 8890:             item.options[0] = new Option("","",true,true);
 8891:             var idx = 0;  
 8892:             for (var m=0; m<alltargets.length; m++) {
 8893:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
 8894:                     idx ++;
 8895:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
 8896:                     
 8897:                 }
 8898:             }
 8899:         }
 8900:     }
 8901:     return;
 8902: }
 8903: 
 8904: function hideSpares(balnum) {
 8905:     var alltargets = new Array('$alltargets');
 8906:     var insttypes = new Array('$allinsttypes');
 8907:     var offloadtypes = new Array('primary','default');
 8908: 
 8909:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
 8910:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
 8911: 
 8912:     var total = alltargets.length - 1;
 8913:     for (var i=0; i<offloadtypes; i++) {
 8914:         for (var j=0; j<total; j++) {
 8915:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
 8916:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
 8917:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
 8918:         }
 8919:     }
 8920:     for (var k=0; k<insttypes.length; k++) {
 8921:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
 8922:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
 8923:         if (insttypes[k] != '_LC_external') {
 8924:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
 8925:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
 8926:         }
 8927:     }
 8928:     return;
 8929: }
 8930: 
 8931: function checkOffloads(item,balnum,type) {
 8932:     var alltargets = new Array('$alltargets');
 8933:     var offloadtypes = new Array('primary','default');
 8934:     if (item.checked) {
 8935:         var total = alltargets.length - 1;
 8936:         var other;
 8937:         if (type == offloadtypes[0]) {
 8938:             other = offloadtypes[1];
 8939:         } else {
 8940:             other = offloadtypes[0];
 8941:         }
 8942:         for (var i=0; i<total; i++) {
 8943:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
 8944:             if (server == item.value) {
 8945:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
 8946:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
 8947:                 }
 8948:             }
 8949:         }
 8950:     }
 8951:     return;
 8952: }
 8953: 
 8954: function singleServerToggle(balnum,type) {
 8955:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
 8956:     if (offloadtoSelIdx == 0) {
 8957:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
 8958:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
 8959: 
 8960:     } else {
 8961:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
 8962:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
 8963:     }
 8964:     return;
 8965: }
 8966: 
 8967: function balanceruleChange(formname,balnum,type) {
 8968:     if (type == '_LC_external') {
 8969:         return;
 8970:     }
 8971:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
 8972:     for (var i=0; i<typesRules.length; i++) {
 8973:         if (formname.elements[typesRules[i]].checked) {
 8974:             if (formname.elements[typesRules[i]].value != 'specific') {
 8975:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
 8976:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
 8977:             } else {
 8978:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
 8979:             }
 8980:         }
 8981:     }
 8982:     return;
 8983: }
 8984: 
 8985: function balancerDeleteChange(balnum) {
 8986:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
 8987:     var baltotal = document.getElementById('loadbalancing_total').value;
 8988:     var addtarget;
 8989:     var removetarget;
 8990:     var action = 'delete';
 8991:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
 8992:         var lonhost = hostitem.value;
 8993:         var currIdx = currBalancers.indexOf(lonhost);
 8994:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
 8995:             if (currIdx != -1) {
 8996:                 currBalancers.splice(currIdx,1);
 8997:             }
 8998:             addtarget = lonhost;
 8999:         } else {
 9000:             if (currIdx == -1) {
 9001:                 currBalancers.push(lonhost);
 9002:             }
 9003:             removetarget = lonhost;
 9004:             action = 'undelete';
 9005:         }
 9006:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
 9007:     }
 9008:     return;
 9009: }
 9010: 
 9011: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
 9012:     if (baltotal > 1) {
 9013:         var offloadtypes = new Array('primary','default');
 9014:         var alltargets = new Array('$alltargets');
 9015:         var insttypes = new Array('$allinsttypes');
 9016:         for (var i=0; i<baltotal; i++) {
 9017:             if (i != balnum) {
 9018:                 for (var j=0; j<offloadtypes.length; j++) {
 9019:                     var total = alltargets.length - 1;
 9020:                     for (var k=0; k<total; k++) {
 9021:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
 9022:                         var server = serveritem.value;
 9023:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
 9024:                             if (server == addtarget) {
 9025:                                 serveritem.disabled = '';
 9026:                             }
 9027:                         }
 9028:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
 9029:                             if (server == removetarget) {
 9030:                                 serveritem.disabled = 'disabled';
 9031:                                 serveritem.checked = false;
 9032:                             }
 9033:                         }
 9034:                     }
 9035:                 }
 9036:                 for (var j=0; j<insttypes.length; j++) {
 9037:                     if (insttypes[j] != '_LC_external') {
 9038:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
 9039:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
 9040:                             var currSel = singleserver.selectedIndex;
 9041:                             var currVal = singleserver.options[currSel].value;
 9042:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
 9043:                                 var numoptions = singleserver.options.length;
 9044:                                 var needsnew = 1;
 9045:                                 for (var k=0; k<numoptions; k++) {
 9046:                                     if (singleserver.options[k] == addtarget) {
 9047:                                         needsnew = 0;
 9048:                                         break;
 9049:                                     }
 9050:                                 }
 9051:                                 if (needsnew == 1) {
 9052:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
 9053:                                 }
 9054:                             }
 9055:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
 9056:                                 singleserver.options.length = 0;
 9057:                                 if ((currVal) && (currVal != removetarget)) {
 9058:                                     singleserver.options[0] = new Option("","",false,false);
 9059:                                 } else {
 9060:                                     singleserver.options[0] = new Option("","",true,true);
 9061:                                 }
 9062:                                 var idx = 0;
 9063:                                 for (var m=0; m<alltargets.length; m++) {
 9064:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
 9065:                                         idx ++;
 9066:                                         if (currVal == alltargets[m]) {
 9067:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
 9068:                                         } else {
 9069:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
 9070:                                         }
 9071:                                     }
 9072:                                 }
 9073:                             }
 9074:                         }
 9075:                     }
 9076:                 }
 9077:             }
 9078:         }
 9079:     }
 9080:     return;
 9081: }
 9082: 
 9083: // ]]>
 9084: </script>
 9085: 
 9086: END
 9087: }
 9088: 
 9089: sub new_spares_js {
 9090:     my @sparestypes = ('primary','default');
 9091:     my $types = join("','",@sparestypes);
 9092:     my $select = &mt('Select');
 9093:     return <<"END";
 9094: 
 9095: <script type="text/javascript">
 9096: // <![CDATA[
 9097: 
 9098: function updateNewSpares(formname,lonhost) {
 9099:     var types = new Array('$types');
 9100:     var include = new Array();
 9101:     var exclude = new Array();
 9102:     for (var i=0; i<types.length; i++) {
 9103:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
 9104:         for (var j=0; j<spareboxes.length; j++) {
 9105:             if (formname.elements[spareboxes[j]].checked) {
 9106:                 exclude.push(formname.elements[spareboxes[j]].value);
 9107:             } else {
 9108:                 include.push(formname.elements[spareboxes[j]].value);
 9109:             }
 9110:         }
 9111:     }
 9112:     for (var i=0; i<types.length; i++) {
 9113:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
 9114:         var selIdx = newSpare.selectedIndex;
 9115:         var currnew = newSpare.options[selIdx].value;
 9116:         var okSpares = new Array();
 9117:         for (var j=0; j<newSpare.options.length; j++) {
 9118:             var possible = newSpare.options[j].value;
 9119:             if (possible != '') {
 9120:                 if (exclude.indexOf(possible) == -1) {
 9121:                     okSpares.push(possible);
 9122:                 } else {
 9123:                     if (currnew == possible) {
 9124:                         selIdx = 0;
 9125:                     }
 9126:                 }
 9127:             }
 9128:         }
 9129:         for (var k=0; k<include.length; k++) {
 9130:             if (okSpares.indexOf(include[k]) == -1) {
 9131:                 okSpares.push(include[k]);
 9132:             }
 9133:         }
 9134:         okSpares.sort();
 9135:         newSpare.options.length = 0;
 9136:         if (selIdx == 0) {
 9137:             newSpare.options[0] = new Option("$select","",true,true);
 9138:         } else {
 9139:             newSpare.options[0] = new Option("$select","",false,false);
 9140:         }
 9141:         for (var m=0; m<okSpares.length; m++) {
 9142:             var idx = m+1;
 9143:             var selThis = 0;
 9144:             if (selIdx != 0) {
 9145:                 if (okSpares[m] == currnew) {
 9146:                     selThis = 1;
 9147:                 }
 9148:             }
 9149:             if (selThis == 1) {
 9150:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
 9151:             } else {
 9152:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
 9153:             }
 9154:         }
 9155:     }
 9156:     return;
 9157: }
 9158: 
 9159: function checkNewSpares(lonhost,type) {
 9160:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
 9161:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
 9162:     if (chosen != '') { 
 9163:         var othertype;
 9164:         var othernewSpare;
 9165:         if (type == 'primary') {
 9166:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
 9167:         }
 9168:         if (type == 'default') {
 9169:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
 9170:         }
 9171:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
 9172:             othernewSpare.selectedIndex = 0;
 9173:         }
 9174:     }
 9175:     return;
 9176: }
 9177: 
 9178: // ]]>
 9179: </script>
 9180: 
 9181: END
 9182: 
 9183: }
 9184: 
 9185: sub common_domprefs_js {
 9186:     return <<"END";
 9187: 
 9188: <script type="text/javascript">
 9189: // <![CDATA[
 9190: 
 9191: function getIndicesByName(formname,item) {
 9192:     var group = new Array();
 9193:     for (var i=0;i<formname.elements.length;i++) {
 9194:         if (formname.elements[i].name == item) {
 9195:             group.push(formname.elements[i].id);
 9196:         }
 9197:     }
 9198:     return group;
 9199: }
 9200: 
 9201: // ]]>
 9202: </script>
 9203: 
 9204: END
 9205: 
 9206: }
 9207: 
 9208: sub recaptcha_js {
 9209:     my %lt = &captcha_phrases();
 9210:     return <<"END";
 9211: 
 9212: <script type="text/javascript">
 9213: // <![CDATA[
 9214: 
 9215: function updateCaptcha(caller,context) {
 9216:     var privitem;
 9217:     var pubitem;
 9218:     var privtext;
 9219:     var pubtext;
 9220:     if (document.getElementById(context+'_recaptchapub')) {
 9221:         pubitem = document.getElementById(context+'_recaptchapub');
 9222:     } else {
 9223:         return;
 9224:     }
 9225:     if (document.getElementById(context+'_recaptchapriv')) {
 9226:         privitem = document.getElementById(context+'_recaptchapriv');
 9227:     } else {
 9228:         return;
 9229:     }
 9230:     if (document.getElementById(context+'_recaptchapubtxt')) {
 9231:         pubtext = document.getElementById(context+'_recaptchapubtxt');
 9232:     } else {
 9233:         return;
 9234:     }
 9235:     if (document.getElementById(context+'_recaptchaprivtxt')) {
 9236:         privtext = document.getElementById(context+'_recaptchaprivtxt');
 9237:     } else {
 9238:         return;
 9239:     }
 9240:     if (caller.checked) {
 9241:         if (caller.value == 'recaptcha') {
 9242:             pubitem.type = 'text';
 9243:             privitem.type = 'text';
 9244:             pubitem.size = '40';
 9245:             privitem.size = '40';
 9246:             pubtext.innerHTML = "$lt{'pub'}";
 9247:             privtext.innerHTML = "$lt{'priv'}";
 9248:         } else {
 9249:             pubitem.type = 'hidden';
 9250:             privitem.type = 'hidden';
 9251:             pubtext.innerHTML = '';
 9252:             privtext.innerHTML = '';
 9253:         }
 9254:     }
 9255:     return;
 9256: }
 9257: 
 9258: // ]]>
 9259: </script>
 9260: 
 9261: END
 9262: 
 9263: }
 9264: 
 9265: sub credits_js {
 9266:     return <<"END";
 9267: 
 9268: <script type="text/javascript">
 9269: // <![CDATA[
 9270: 
 9271: function toggleCredits(domForm) {
 9272:     if (document.getElementById('credits')) {
 9273:         creditsitem = document.getElementById('credits');
 9274:         var creditsLength = domForm.coursecredits.length;
 9275:         if (creditsLength) {
 9276:             var currval;
 9277:             for (var i=0; i<creditsLength; i++) {
 9278:                 if (domForm.coursecredits[i].checked) {
 9279:                    currval = domForm.coursecredits[i].value;
 9280:                 }
 9281:             }
 9282:             if (currval == 1) {
 9283:                 creditsitem.style.display = 'block';
 9284:             } else {
 9285:                 creditsitem.style.display = 'none';
 9286:             }
 9287:         }
 9288:     }
 9289:     return;
 9290: }
 9291: 
 9292: // ]]>
 9293: </script>
 9294: 
 9295: END
 9296: 
 9297: }
 9298: 
 9299: sub captcha_phrases {
 9300:     return &Apache::lonlocal::texthash (
 9301:                  priv => 'Private key',
 9302:                  pub  => 'Public key',
 9303:                  original  => 'original (CAPTCHA)',
 9304:                  recaptcha => 'successor (ReCAPTCHA)',
 9305:                  notused   => 'unused',
 9306:     );
 9307: }
 9308: 
 9309: 1;

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