File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.160.6.61: download - view: text, annotated - select for diffs
Wed Apr 1 23:41:14 2015 UTC (9 years, 1 month ago) by raeburn
Branches: version_2_11_X
Diff to branchpoint 1.160: preferred, unified
- For 2.11
  - Backport 1.260, 1.261

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.160.6.61 2015/04/01 23:41:14 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, community, and textbook).  In each case the radio buttons 
  107: allow the 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 Apache::lonuserutils();
  168: use Apache::loncoursequeueadmin();
  169: use LONCAPA qw(:DEFAULT :match);
  170: use LONCAPA::Enrollment;
  171: use LONCAPA::lonauthcgi();
  172: use File::Copy;
  173: use Locale::Language;
  174: use DateTime::TimeZone;
  175: use DateTime::Locale;
  176: 
  177: my $registered_cleanup;
  178: my $modified_urls;
  179: 
  180: sub handler {
  181:     my $r=shift;
  182:     if ($r->header_only) {
  183:         &Apache::loncommon::content_type($r,'text/html');
  184:         $r->send_http_header;
  185:         return OK;
  186:     }
  187: 
  188:     my $context = 'domain';
  189:     my $dom = $env{'request.role.domain'};
  190:     my $domdesc = &Apache::lonnet::domain($dom,'description');
  191:     if (&Apache::lonnet::allowed('mau',$dom)) {
  192:         &Apache::loncommon::content_type($r,'text/html');
  193:         $r->send_http_header;
  194:     } else {
  195:         $env{'user.error.msg'}=
  196:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
  197:         return HTTP_NOT_ACCEPTABLE;
  198:     }
  199: 
  200:     $registered_cleanup=0;
  201:     @{$modified_urls}=();
  202: 
  203:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  204:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  205:                                             ['phase','actions']);
  206:     my $phase = 'pickactions';
  207:     if ( exists($env{'form.phase'}) ) {
  208:         $phase = $env{'form.phase'};
  209:     }
  210:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
  211:     my %domconfig =
  212:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
  213:                 'quotas','autoenroll','autoupdate','autocreate',
  214:                 'directorysrch','usercreation','usermodification',
  215:                 'contacts','defaults','scantron','coursecategories',
  216:                 'serverstatuses','requestcourses','coursedefaults',
  217:                 'usersessions','loadbalancing','requestauthor',
  218:                 'selfenrollment','inststatus'],$dom);
  219:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
  220:                        'autoupdate','autocreate','directorysrch','contacts',
  221:                        'usercreation','selfcreation','usermodification','scantron',
  222:                        'requestcourses','requestauthor','coursecategories',
  223:                        'serverstatuses','coursedefaults','selfenrollment',
  224:                        'usersessions');
  225:     my %existing;
  226:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
  227:         %existing = %{$domconfig{'loadbalancing'}};
  228:     }
  229:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
  230:         push(@prefs_order,'loadbalancing');
  231:     }
  232:     my %prefs = (
  233:         'rolecolors' =>
  234:                    { text => 'Default color schemes',
  235:                      help => 'Domain_Configuration_Color_Schemes',
  236:                      header => [{col1 => 'Student Settings',
  237:                                  col2 => '',},
  238:                                 {col1 => 'Coordinator Settings',
  239:                                  col2 => '',},
  240:                                 {col1 => 'Author Settings',
  241:                                  col2 => '',},
  242:                                 {col1 => 'Administrator Settings',
  243:                                  col2 => '',}],
  244:                       print => \&print_rolecolors,
  245:                       modify => \&modify_rolecolors,
  246:                     },
  247:         'login' =>
  248:                     { text => 'Log-in page options',
  249:                       help => 'Domain_Configuration_Login_Page',
  250:                       header => [{col1 => 'Log-in Page Items',
  251:                                   col2 => '',},
  252:                                  {col1 => 'Log-in Help',
  253:                                   col2 => 'Value'},
  254:                                  {col1 => 'Custom HTML in document head',
  255:                                   col2 => 'Value'}],
  256:                       print => \&print_login,
  257:                       modify => \&modify_login,
  258:                     },
  259:         'defaults' => 
  260:                     { text => 'Default authentication/language/timezone/portal/types',
  261:                       help => 'Domain_Configuration_LangTZAuth',
  262:                       header => [{col1 => 'Setting',
  263:                                   col2 => 'Value'},
  264:                                  {col1 => 'Institutional user types',
  265:                                   col2 => 'Assignable to e-mail usernames'}],
  266:                       print => \&print_defaults,
  267:                       modify => \&modify_defaults,
  268:                     },
  269:         'quotas' => 
  270:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
  271:                       help => 'Domain_Configuration_Quotas',
  272:                       header => [{col1 => 'User affiliation',
  273:                                   col2 => 'Available tools',
  274:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
  275:                       print => \&print_quotas,
  276:                       modify => \&modify_quotas,
  277:                     },
  278:         'autoenroll' =>
  279:                    { text => 'Auto-enrollment settings',
  280:                      help => 'Domain_Configuration_Auto_Enrollment',
  281:                      header => [{col1 => 'Configuration setting',
  282:                                  col2 => 'Value(s)'}],
  283:                      print => \&print_autoenroll,
  284:                      modify => \&modify_autoenroll,
  285:                    },
  286:         'autoupdate' => 
  287:                    { text => 'Auto-update settings',
  288:                      help => 'Domain_Configuration_Auto_Updates',
  289:                      header => [{col1 => 'Setting',
  290:                                  col2 => 'Value',},
  291:                                 {col1 => 'Setting',
  292:                                  col2 => 'Affiliation'},
  293:                                 {col1 => 'User population',
  294:                                  col2 => 'Updatable user data'}],
  295:                      print => \&print_autoupdate,
  296:                      modify => \&modify_autoupdate,
  297:                   },
  298:         'autocreate' => 
  299:                   { text => 'Auto-course creation settings',
  300:                      help => 'Domain_Configuration_Auto_Creation',
  301:                      header => [{col1 => 'Configuration Setting',
  302:                                  col2 => 'Value',}],
  303:                      print => \&print_autocreate,
  304:                      modify => \&modify_autocreate,
  305:                   },
  306:         'directorysrch' => 
  307:                   { text => 'Institutional directory searches',
  308:                     help => 'Domain_Configuration_InstDirectory_Search',
  309:                     header => [{col1 => 'Setting',
  310:                                 col2 => 'Value',}],
  311:                     print => \&print_directorysrch,
  312:                     modify => \&modify_directorysrch,
  313:                   },
  314:         'contacts' =>
  315:                   { text => 'Contact Information',
  316:                     help => 'Domain_Configuration_Contact_Info',
  317:                     header => [{col1 => 'Setting',
  318:                                 col2 => 'Value',}],
  319:                     print => \&print_contacts,
  320:                     modify => \&modify_contacts,
  321:                   },
  322:         'usercreation' => 
  323:                   { text => 'User creation',
  324:                     help => 'Domain_Configuration_User_Creation',
  325:                     header => [{col1 => 'Format rule type',
  326:                                 col2 => 'Format rules in force'},
  327:                                {col1 => 'User account creation',
  328:                                 col2 => 'Usernames which may be created',},
  329:                                {col1 => 'Context',
  330:                                 col2 => 'Assignable authentication types'}],
  331:                     print => \&print_usercreation,
  332:                     modify => \&modify_usercreation,
  333:                   },
  334:         'selfcreation' => 
  335:                   { text => 'Users self-creating accounts',
  336:                     help => 'Domain_Configuration_Self_Creation', 
  337:                     header => [{col1 => 'Self-creation with institutional username',
  338:                                 col2 => 'Enabled?'},
  339:                                {col1 => 'Institutional user type (login/SSO self-creation)',
  340:                                 col2 => 'Information user can enter'},
  341:                                {col1 => 'Self-creation with e-mail as username',
  342:                                 col2 => 'Settings'}],
  343:                     print => \&print_selfcreation,
  344:                     modify => \&modify_selfcreation,
  345:                   },
  346:         'usermodification' =>
  347:                   { text => 'User modification',
  348:                     help => 'Domain_Configuration_User_Modification',
  349:                     header => [{col1 => 'Target user has role',
  350:                                 col2 => 'User information updatable in author context'},
  351:                                {col1 => 'Target user has role',
  352:                                 col2 => 'User information updatable in course context'}],
  353:                     print => \&print_usermodification,
  354:                     modify => \&modify_usermodification,
  355:                   },
  356:         'scantron' =>
  357:                   { text => 'Bubblesheet format file',
  358:                     help => 'Domain_Configuration_Scantron_Format',
  359:                     header => [ {col1 => 'Item',
  360:                                  col2 => '',
  361:                               }],
  362:                     print => \&print_scantron,
  363:                     modify => \&modify_scantron,
  364:                   },
  365:         'requestcourses' => 
  366:                  {text => 'Request creation of courses',
  367:                   help => 'Domain_Configuration_Request_Courses',
  368:                   header => [{col1 => 'User affiliation',
  369:                               col2 => 'Availability/Processing of requests',},
  370:                              {col1 => 'Setting',
  371:                               col2 => 'Value'},
  372:                              {col1 => 'Available textbooks',
  373:                               col2 => ''},
  374:                              {col1 => 'Available templates',
  375:                               col2 => ''},
  376:                              {col1 => 'Validation (not official courses)',
  377:                               col2 => 'Value'},],
  378:                   print => \&print_quotas,
  379:                   modify => \&modify_quotas,
  380:                  },
  381:         'requestauthor' =>
  382:                  {text => 'Request Authoring Space',
  383:                   help => 'Domain_Configuration_Request_Author',
  384:                   header => [{col1 => 'User affiliation',
  385:                               col2 => 'Availability/Processing of requests',},
  386:                              {col1 => 'Setting',
  387:                               col2 => 'Value'}],
  388:                   print => \&print_quotas,
  389:                   modify => \&modify_quotas,
  390:                  },
  391:         'coursecategories' =>
  392:                   { text => 'Cataloging of courses/communities',
  393:                     help => 'Domain_Configuration_Cataloging_Courses',
  394:                     header => [{col1 => 'Catalog type/availability',
  395:                                 col2 => '',},
  396:                                {col1 => 'Category settings for standard catalog',
  397:                                 col2 => '',},
  398:                                {col1 => 'Categories',
  399:                                 col2 => '',
  400:                                }],
  401:                     print => \&print_coursecategories,
  402:                     modify => \&modify_coursecategories,
  403:                   },
  404:         'serverstatuses' =>
  405:                  {text   => 'Access to server status pages',
  406:                   help   => 'Domain_Configuration_Server_Status',
  407:                   header => [{col1 => 'Status Page',
  408:                               col2 => 'Other named users',
  409:                               col3 => 'Specific IPs',
  410:                             }],
  411:                   print => \&print_serverstatuses,
  412:                   modify => \&modify_serverstatuses,
  413:                  },
  414:         'coursedefaults' => 
  415:                  {text => 'Course/Community defaults',
  416:                   help => 'Domain_Configuration_Course_Defaults',
  417:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
  418:                               col2 => 'Value',},
  419:                              {col1 => 'Defaults which can be overridden for each course by a DC',
  420:                               col2 => 'Value',},],
  421:                   print => \&print_coursedefaults,
  422:                   modify => \&modify_coursedefaults,
  423:                  },
  424:         'selfenrollment' => 
  425:                  {text   => 'Self-enrollment in Course/Community',
  426:                   help   => 'Domain_Configuration_Selfenrollment',
  427:                   header => [{col1 => 'Configuration Rights',
  428:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
  429:                              {col1 => 'Defaults',
  430:                               col2 => 'Value'},
  431:                              {col1 => 'Self-enrollment validation (optional)',
  432:                               col2 => 'Value'},],
  433:                   print => \&print_selfenrollment,
  434:                   modify => \&modify_selfenrollment,
  435:                  },
  436:         'usersessions' =>
  437:                  {text  => 'User session hosting/offloading',
  438:                   help  => 'Domain_Configuration_User_Sessions',
  439:                   header => [{col1 => 'Domain server',
  440:                               col2 => 'Servers to offload sessions to when busy'},
  441:                              {col1 => 'Hosting of users from other domains',
  442:                               col2 => 'Rules'},
  443:                              {col1 => "Hosting domain's own users elsewhere",
  444:                               col2 => 'Rules'}],
  445:                   print => \&print_usersessions,
  446:                   modify => \&modify_usersessions,
  447:                  },
  448:          'loadbalancing' =>
  449:                  {text  => 'Dedicated Load Balancer(s)',
  450:                   help  => 'Domain_Configuration_Load_Balancing',
  451:                   header => [{col1 => 'Balancers',
  452:                               col2 => 'Default destinations',
  453:                               col3 => 'User affiliation',
  454:                               col4 => 'Overrides'},
  455:                             ],
  456:                   print => \&print_loadbalancing,
  457:                   modify => \&modify_loadbalancing,
  458:                  },
  459:     );
  460:     if (keys(%servers) > 1) {
  461:         $prefs{'login'}  = { text   => 'Log-in page options',
  462:                              help   => 'Domain_Configuration_Login_Page',
  463:                             header => [{col1 => 'Log-in Service',
  464:                                         col2 => 'Server Setting',},
  465:                                        {col1 => 'Log-in Page Items',
  466:                                         col2 => ''},
  467:                                        {col1 => 'Log-in Help',
  468:                                         col2 => 'Value'},
  469:                                        {col1 => 'Custom HTML in document head',
  470:                                         col2 => 'Value'}],
  471:                             print => \&print_login,
  472:                             modify => \&modify_login,
  473:                            };
  474:     }
  475: 
  476:     my @roles = ('student','coordinator','author','admin');
  477:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  478:     &Apache::lonhtmlcommon::add_breadcrumb
  479:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  480:       text=>"Settings to display/modify"});
  481:     my $confname = $dom.'-domainconfig';
  482: 
  483:     if ($phase eq 'process') {
  484:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
  485:                                                               \%prefs,\%domconfig,$confname,\@roles);
  486:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
  487:             $r->rflush();
  488:             &devalidate_remote_domconfs($dom,$result);
  489:         }
  490:     } elsif ($phase eq 'display') {
  491:         my $js = &recaptcha_js().
  492:                  &toggle_display_js();
  493:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
  494:             my ($othertitle,$usertypes,$types) =
  495:                 &Apache::loncommon::sorted_inst_types($dom);
  496:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
  497:                                           $domconfig{'loadbalancing'}).
  498:                    &new_spares_js().
  499:                    &common_domprefs_js().
  500:                    &Apache::loncommon::javascript_array_indexof();
  501:         }
  502:         if (grep(/^requestcourses$/,@actions)) {
  503:             my $javascript_validations;
  504:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
  505:             $js .= <<END;
  506: <script type="text/javascript">
  507: $javascript_validations
  508: </script>
  509: $coursebrowserjs
  510: END
  511:         }
  512:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
  513:     } else {
  514: # check if domconfig user exists for the domain.
  515:         my $servadm = $r->dir_config('lonAdmEMail');
  516:         my ($configuserok,$author_ok,$switchserver) =
  517:             &config_check($dom,$confname,$servadm);
  518:         unless ($configuserok eq 'ok') {
  519:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
  520:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
  521:                           $confname).
  522:                       '<br />'
  523:             );
  524:             if ($switchserver) {
  525:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
  526:                           '<br />'.
  527:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
  528:                           '<br />'.
  529:                           &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).
  530:                           '<br />'.
  531:                           &mt('To do that now, use the following link: [_1]',$switchserver)
  532:                 );
  533:             } else {
  534:                 $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.').
  535:                           '<br />'.
  536:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
  537:                 );
  538:             }
  539:             $r->print(&Apache::loncommon::end_page());
  540:             return OK;
  541:         }
  542:         if (keys(%domconfig) == 0) {
  543:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  544:             my @ids=&Apache::lonnet::current_machine_ids();
  545:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  546:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  547:                 my @loginimages = ('img','logo','domlogo','login');
  548:                 my $custom_img_count = 0;
  549:                 foreach my $img (@loginimages) {
  550:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  551:                         $custom_img_count ++;
  552:                     }
  553:                 }
  554:                 foreach my $role (@roles) {
  555:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  556:                         $custom_img_count ++;
  557:                     }
  558:                 }
  559:                 if ($custom_img_count > 0) {
  560:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
  561:                     my $switch_server = &check_switchserver($dom,$confname);
  562:                     $r->print(
  563:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  564:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  565:     &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 />'.
  566:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  567:                     if ($switch_server) {
  568:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  569:                     }
  570:                     $r->print(&Apache::loncommon::end_page());
  571:                     return OK;
  572:                 }
  573:             }
  574:         }
  575:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
  576:     }
  577:     return OK;
  578: }
  579: 
  580: sub process_changes {
  581:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
  582:     my %domconfig;
  583:     if (ref($values) eq 'HASH') {
  584:         %domconfig = %{$values};
  585:     }
  586:     my $output;
  587:     if ($action eq 'login') {
  588:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
  589:     } elsif ($action eq 'rolecolors') {
  590:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  591:                                      $lastactref,%domconfig);
  592:     } elsif ($action eq 'quotas') {
  593:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
  594:     } elsif ($action eq 'autoenroll') {
  595:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
  596:     } elsif ($action eq 'autoupdate') {
  597:         $output = &modify_autoupdate($dom,%domconfig);
  598:     } elsif ($action eq 'autocreate') {
  599:         $output = &modify_autocreate($dom,%domconfig);
  600:     } elsif ($action eq 'directorysrch') {
  601:         $output = &modify_directorysrch($dom,%domconfig);
  602:     } elsif ($action eq 'usercreation') {
  603:         $output = &modify_usercreation($dom,%domconfig);
  604:     } elsif ($action eq 'selfcreation') {
  605:         $output = &modify_selfcreation($dom,%domconfig);
  606:     } elsif ($action eq 'usermodification') {
  607:         $output = &modify_usermodification($dom,%domconfig);
  608:     } elsif ($action eq 'contacts') {
  609:         $output = &modify_contacts($dom,$lastactref,%domconfig);
  610:     } elsif ($action eq 'defaults') {
  611:         $output = &modify_defaults($dom,$lastactref,%domconfig);
  612:     } elsif ($action eq 'scantron') {
  613:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
  614:     } elsif ($action eq 'coursecategories') {
  615:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
  616:     } elsif ($action eq 'serverstatuses') {
  617:         $output = &modify_serverstatuses($dom,%domconfig);
  618:     } elsif ($action eq 'requestcourses') {
  619:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
  620:     } elsif ($action eq 'requestauthor') {
  621:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
  622:     } elsif ($action eq 'coursedefaults') {
  623:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
  624:     } elsif ($action eq 'selfenrollment') {
  625:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
  626:     } elsif ($action eq 'usersessions') {
  627:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
  628:     } elsif ($action eq 'loadbalancing') {
  629:         $output = &modify_loadbalancing($dom,%domconfig);
  630:     }
  631:     return $output;
  632: }
  633: 
  634: sub print_config_box {
  635:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  636:     my $rowtotal = 0;
  637:     my $output;
  638:     if ($action eq 'coursecategories') {
  639:         $output = &coursecategories_javascript($settings);
  640:     } elsif ($action eq 'defaults') {
  641:         $output = &defaults_javascript($settings); 
  642:     }
  643:     $output .=
  644:          '<table class="LC_nested_outer">
  645:           <tr>
  646:            <th align="left" valign="middle"><span class="LC_nobreak">'.
  647:            &mt($item->{text}).'&nbsp;'.
  648:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
  649:           '</tr>';
  650:     $rowtotal ++;
  651:     my $numheaders = 1;
  652:     if (ref($item->{'header'}) eq 'ARRAY') {
  653:         $numheaders = scalar(@{$item->{'header'}});
  654:     }
  655:     if ($numheaders > 1) {
  656:         my $colspan = '';
  657:         my $rightcolspan = '';
  658:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
  659:             (($action eq 'login') && ($numheaders < 4))) {
  660:             $colspan = ' colspan="2"';
  661:         }
  662:         if ($action eq 'usersessions') {
  663:             $rightcolspan = ' colspan="3"'; 
  664:         }
  665:         $output .= '
  666:           <tr>
  667:            <td>
  668:             <table class="LC_nested">
  669:              <tr class="LC_info_row">
  670:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
  671:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  672:              </tr>';
  673:         $rowtotal ++;
  674:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
  675:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
  676:             ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
  677:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
  678:         } elsif ($action eq 'coursecategories') {
  679:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
  680:         } elsif ($action eq 'login') {
  681:             if ($numheaders == 4) {
  682:                 $colspan = ' colspan="2"';
  683:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
  684:             } else {
  685:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
  686:             }
  687:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
  688:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  689:         } elsif ($action eq 'rolecolors') {
  690:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  691:         }
  692:         $output .= '
  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'}->[1]->{'col1'}).'</td>
  701:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
  702:              </tr>';
  703:             $rowtotal ++;
  704:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
  705:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
  706:             ($action eq 'usersessions') || ($action eq 'coursecategories')) {
  707:             if ($action eq 'coursecategories') {
  708:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
  709:                 $colspan = ' colspan="2"';
  710:             } else {
  711:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
  712:             }
  713:             $output .= '
  714:            </table>
  715:           </td>
  716:          </tr>
  717:          <tr>
  718:            <td>
  719:             <table class="LC_nested">
  720:              <tr class="LC_info_row">
  721:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  722:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
  723:              </tr>'."\n";
  724:             if ($action eq 'coursecategories') {
  725:                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
  726:             } else {
  727:                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
  728:             }
  729:             $rowtotal ++;
  730:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
  731:                   ($action eq 'defaults')) {
  732:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
  733:         } elsif ($action eq 'login') {
  734:             if ($numheaders == 4) {
  735:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
  736:            </table>
  737:           </td>
  738:          </tr>
  739:          <tr>
  740:            <td>
  741:             <table class="LC_nested">
  742:              <tr class="LC_info_row">
  743:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  744:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
  745:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
  746:                 $rowtotal ++;
  747:             } else {
  748:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
  749:             }
  750:             $output .= '
  751:            </table>
  752:           </td>
  753:          </tr>
  754:          <tr>
  755:            <td>
  756:             <table class="LC_nested">
  757:              <tr class="LC_info_row">';
  758:             if ($numheaders == 4) {
  759:                 $output .= '
  760:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  761:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  762:              </tr>';
  763:             } else {
  764:                 $output .= '
  765:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  766:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
  767:              </tr>';
  768:             }
  769:             $rowtotal ++;
  770:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
  771:         } elsif ($action eq 'requestcourses') {
  772:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
  773:             $rowtotal ++;
  774:             $output .= &print_studentcode($settings,\$rowtotal).'
  775:            </table>
  776:           </td>
  777:          </tr>
  778:          <tr>
  779:            <td>
  780:             <table class="LC_nested">
  781:              <tr class="LC_info_row">
  782:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  783:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
  784:                        &textbookcourses_javascript($settings).
  785:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
  786:             </table>
  787:            </td>
  788:           </tr>
  789:          <tr>
  790:            <td>
  791:             <table class="LC_nested">
  792:              <tr class="LC_info_row">
  793:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  794:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
  795:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
  796:             </table>
  797:            </td>
  798:           </tr>
  799:           <tr>
  800:            <td>
  801:             <table class="LC_nested">
  802:              <tr class="LC_info_row">
  803:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
  804:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
  805:              </tr>'.
  806:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
  807:         } elsif ($action eq 'requestauthor') {
  808:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
  809:             $rowtotal ++;
  810:         } elsif ($action eq 'rolecolors') {
  811:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  812:            </table>
  813:           </td>
  814:          </tr>
  815:          <tr>
  816:            <td>
  817:             <table class="LC_nested">
  818:              <tr class="LC_info_row">
  819:               <td class="LC_left_item"'.$colspan.' valign="top">'.
  820:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
  821:               <td class="LC_right_item" valign="top">'.
  822:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
  823:              </tr>'.
  824:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  825:            </table>
  826:           </td>
  827:          </tr>
  828:          <tr>
  829:            <td>
  830:             <table class="LC_nested">
  831:              <tr class="LC_info_row">
  832:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  833:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  834:              </tr>'.
  835:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  836:             $rowtotal += 2;
  837:         }
  838:     } else {
  839:         $output .= '
  840:           <tr>
  841:            <td>
  842:             <table class="LC_nested">
  843:              <tr class="LC_info_row">';
  844:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  845:             $output .= '  
  846:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  847:         } elsif ($action eq 'serverstatuses') {
  848:             $output .= '
  849:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
  850:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
  851: 
  852:         } else {
  853:             $output .= '
  854:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  855:         }
  856:         if (defined($item->{'header'}->[0]->{'col3'})) {
  857:             $output .= '<td class="LC_left_item" valign="top">'.
  858:                        &mt($item->{'header'}->[0]->{'col2'});
  859:             if ($action eq 'serverstatuses') {
  860:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
  861:             } 
  862:         } else {
  863:             $output .= '<td class="LC_right_item" valign="top">'.
  864:                        &mt($item->{'header'}->[0]->{'col2'});
  865:         }
  866:         $output .= '</td>';
  867:         if ($item->{'header'}->[0]->{'col3'}) {
  868:             if (defined($item->{'header'}->[0]->{'col4'})) {
  869:                 $output .= '<td class="LC_left_item" valign="top">'.
  870:                             &mt($item->{'header'}->[0]->{'col3'});
  871:             } else {
  872:                 $output .= '<td class="LC_right_item" valign="top">'.
  873:                            &mt($item->{'header'}->[0]->{'col3'});
  874:             }
  875:             if ($action eq 'serverstatuses') {
  876:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
  877:             }
  878:             $output .= '</td>';
  879:         }
  880:         if ($item->{'header'}->[0]->{'col4'}) {
  881:             $output .= '<td class="LC_right_item" valign="top">'.
  882:                        &mt($item->{'header'}->[0]->{'col4'});
  883:         }
  884:         $output .= '</tr>';
  885:         $rowtotal ++;
  886:         if ($action eq 'quotas') {
  887:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  888:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
  889:                  ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
  890:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
  891:         } elsif ($action eq 'scantron') {
  892:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
  893:         } elsif ($action eq 'helpsettings') {
  894:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
  895:         }
  896:     }
  897:     $output .= '
  898:    </table>
  899:   </td>
  900:  </tr>
  901: </table><br />';
  902:     return ($output,$rowtotal);
  903: }
  904: 
  905: sub print_login {
  906:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
  907:     my ($css_class,$datatable);
  908:     my %choices = &login_choices();
  909: 
  910:     if ($caller eq 'service') {
  911:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
  912:         my $choice = $choices{'disallowlogin'};
  913:         $css_class = ' class="LC_odd_row"';
  914:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
  915:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
  916:                       '<th>'.$choices{'server'}.'</th>'.
  917:                       '<th>'.$choices{'serverpath'}.'</th>'.
  918:                       '<th>'.$choices{'custompath'}.'</th>'.
  919:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
  920:         my %disallowed;
  921:         if (ref($settings) eq 'HASH') {
  922:             if (ref($settings->{'loginvia'}) eq 'HASH') {
  923:                %disallowed = %{$settings->{'loginvia'}};
  924:             }
  925:         }
  926:         foreach my $lonhost (sort(keys(%servers))) {
  927:             my $direct = 'selected="selected"';
  928:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  929:                 if ($disallowed{$lonhost}{'server'} ne '') {
  930:                     $direct = '';
  931:                 }
  932:             }
  933:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
  934:                           '<td><select name="'.$lonhost.'_server">'.
  935:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
  936:                           '</option>';
  937:             foreach my $hostid (sort(keys(%servers))) {
  938:                 next if ($servers{$hostid} eq $servers{$lonhost});
  939:                 my $selected = '';
  940:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  941:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
  942:                         $selected = 'selected="selected"';
  943:                     }
  944:                 }
  945:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
  946:                               $servers{$hostid}.'</option>';
  947:             }
  948:             $datatable .= '</select></td>'.
  949:                           '<td><select name="'.$lonhost.'_serverpath">';
  950:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
  951:                 my $pathname = $path;
  952:                 if ($path eq 'custom') {
  953:                     $pathname = &mt('Custom Path').' ->';
  954:                 }
  955:                 my $selected = '';
  956:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  957:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
  958:                         $selected = 'selected="selected"';
  959:                     }
  960:                 } elsif ($path eq '') {
  961:                     $selected = 'selected="selected"';
  962:                 }
  963:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
  964:             }
  965:             $datatable .= '</select></td>';
  966:             my ($custom,$exempt);
  967:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  968:                 $custom = $disallowed{$lonhost}{'custompath'};
  969:                 $exempt = $disallowed{$lonhost}{'exempt'};
  970:             }
  971:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
  972:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
  973:                           '</tr>';
  974:         }
  975:         $datatable .= '</table></td></tr>';
  976:         return $datatable;
  977:     } elsif ($caller eq 'page') {
  978:         my %defaultchecked = ( 
  979:                                'coursecatalog' => 'on',
  980:                                'helpdesk'      => 'on',
  981:                                'adminmail'     => 'off',
  982:                                'newuser'       => 'off',
  983:                              );
  984:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
  985:         my (%checkedon,%checkedoff);
  986:         foreach my $item (@toggles) {
  987:             if ($defaultchecked{$item} eq 'on') { 
  988:                 $checkedon{$item} = ' checked="checked" ';
  989:                 $checkedoff{$item} = ' ';
  990:             } elsif ($defaultchecked{$item} eq 'off') {
  991:                 $checkedoff{$item} = ' checked="checked" ';
  992:                 $checkedon{$item} = ' ';
  993:             }
  994:         }
  995:         my @images = ('img','logo','domlogo','login');
  996:         my @logintext = ('textcol','bgcol');
  997:         my @bgs = ('pgbg','mainbg','sidebg');
  998:         my @links = ('link','alink','vlink');
  999:         my %designhash = &Apache::loncommon::get_domainconf($dom);
 1000:         my %defaultdesign = %Apache::loncommon::defaultdesign;
 1001:         my (%is_custom,%designs);
 1002:         my %defaults = (
 1003:                        font => $defaultdesign{'login.font'},
 1004:                        );
 1005:         foreach my $item (@images) {
 1006:             $defaults{$item} = $defaultdesign{'login.'.$item};
 1007:             $defaults{'showlogo'}{$item} = 1;
 1008:         }
 1009:         foreach my $item (@bgs) {
 1010:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
 1011:         }
 1012:         foreach my $item (@logintext) {
 1013:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
 1014:         }
 1015:         foreach my $item (@links) {
 1016:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
 1017:         }
 1018:         if (ref($settings) eq 'HASH') {
 1019:             foreach my $item (@toggles) {
 1020:                 if ($settings->{$item} eq '1') {
 1021:                     $checkedon{$item} =  ' checked="checked" ';
 1022:                     $checkedoff{$item} = ' ';
 1023:                 } elsif ($settings->{$item} eq '0') {
 1024:                     $checkedoff{$item} =  ' checked="checked" ';
 1025:                     $checkedon{$item} = ' ';
 1026:                 }
 1027:             }
 1028:             foreach my $item (@images) {
 1029:                 if (defined($settings->{$item})) {
 1030:                     $designs{$item} = $settings->{$item};
 1031:                     $is_custom{$item} = 1;
 1032:                 }
 1033:                 if (defined($settings->{'showlogo'}{$item})) {
 1034:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
 1035:                 }
 1036:             }
 1037:             foreach my $item (@logintext) {
 1038:                 if ($settings->{$item} ne '') {
 1039:                     $designs{'logintext'}{$item} = $settings->{$item};
 1040:                     $is_custom{$item} = 1;
 1041:                 }
 1042:             }
 1043:             if ($settings->{'font'} ne '') {
 1044:                 $designs{'font'} = $settings->{'font'};
 1045:                 $is_custom{'font'} = 1;
 1046:             }
 1047:             foreach my $item (@bgs) {
 1048:                 if ($settings->{$item} ne '') {
 1049:                     $designs{'bgs'}{$item} = $settings->{$item};
 1050:                     $is_custom{$item} = 1;
 1051:                 }
 1052:             }
 1053:             foreach my $item (@links) {
 1054:                 if ($settings->{$item} ne '') {
 1055:                     $designs{'links'}{$item} = $settings->{$item};
 1056:                     $is_custom{$item} = 1;
 1057:                 }
 1058:             }
 1059:         } else {
 1060:             if ($designhash{$dom.'.login.font'} ne '') {
 1061:                 $designs{'font'} = $designhash{$dom.'.login.font'};
 1062:                 $is_custom{'font'} = 1;
 1063:             }
 1064:             foreach my $item (@images) {
 1065:                 if ($designhash{$dom.'.login.'.$item} ne '') {
 1066:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
 1067:                     $is_custom{$item} = 1;
 1068:                 }
 1069:             }
 1070:             foreach my $item (@bgs) {
 1071:                 if ($designhash{$dom.'.login.'.$item} ne '') {
 1072:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
 1073:                     $is_custom{$item} = 1;
 1074:                 }
 1075:             }
 1076:             foreach my $item (@links) {
 1077:                 if ($designhash{$dom.'.login.'.$item} ne '') {
 1078:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
 1079:                     $is_custom{$item} = 1;
 1080:                 }
 1081:             }
 1082:         }
 1083:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
 1084:                                                       logo => 'Institution Logo',
 1085:                                                       domlogo => 'Domain Logo',
 1086:                                                       login => 'Login box');
 1087:         my $itemcount = 1;
 1088:         foreach my $item (@toggles) {
 1089:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1090:             $datatable .=  
 1091:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
 1092:                 '</td><td>'.
 1093:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
 1094:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
 1095:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
 1096:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
 1097:                 '</tr>';
 1098:             $itemcount ++;
 1099:         }
 1100:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
 1101:         $datatable .= '</tr></table></td></tr>';
 1102:     } elsif ($caller eq 'help') {
 1103:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
 1104:         my $switchserver = &check_switchserver($dom,$confname);
 1105:         my $itemcount = 1;
 1106:         $defaulturl = '/adm/loginproblems.html';
 1107:         $defaulttype = 'default';
 1108:         %lt = &Apache::lonlocal::texthash (
 1109:                      del     => 'Delete?',
 1110:                      rep     => 'Replace:',
 1111:                      upl     => 'Upload:',
 1112:                      default => 'Default',
 1113:                      custom  => 'Custom',
 1114:                                              );
 1115:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 1116:         my @currlangs;
 1117:         if (ref($settings) eq 'HASH') {
 1118:             if (ref($settings->{'helpurl'}) eq 'HASH') {
 1119:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
 1120:                     next if ($settings->{'helpurl'}{$key} eq '');
 1121:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
 1122:                     $type{$key} = 'custom';
 1123:                     unless ($key eq 'nolang') {
 1124:                         push(@currlangs,$key);
 1125:                     }
 1126:                 }
 1127:             } elsif ($settings->{'helpurl'} ne '') {
 1128:                 $type{'nolang'} = 'custom';
 1129:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
 1130:             }
 1131:         }
 1132:         foreach my $lang ('nolang',sort(@currlangs)) {
 1133:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 1134:             $datatable .= '<tr'.$css_class.'>';
 1135:             if ($url{$lang} eq '') {
 1136:                 $url{$lang} = $defaulturl;
 1137:             }
 1138:             if ($type{$lang} eq '') {
 1139:                 $type{$lang} = $defaulttype;
 1140:             }
 1141:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
 1142:             if ($lang eq 'nolang') {
 1143:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
 1144:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
 1145:             } else {
 1146:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
 1147:                                   $langchoices{$lang},
 1148:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
 1149:             }
 1150:             $datatable .= '</span></td>'."\n".
 1151:                           '<td class="LC_left_item">';
 1152:             if ($type{$lang} eq 'custom') {
 1153:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1154:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
 1155:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
 1156:             } else {
 1157:                 $datatable .= $lt{'upl'};
 1158:             }
 1159:             $datatable .='<br />';
 1160:             if ($switchserver) {
 1161:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1162:             } else {
 1163:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
 1164:             }
 1165:             $datatable .= '</td></tr>';
 1166:             $itemcount ++;
 1167:         }
 1168:         my @addlangs;
 1169:         foreach my $lang (sort(keys(%langchoices))) {
 1170:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
 1171:             push(@addlangs,$lang);
 1172:         }
 1173:         if (@addlangs > 0) {
 1174:             my %toadd;
 1175:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
 1176:             $toadd{''} = &mt('Select');
 1177:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 1178:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
 1179:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
 1180:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
 1181:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
 1182:             if ($switchserver) {
 1183:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1184:             } else {
 1185:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
 1186:             }
 1187:             $datatable .= '</td></tr>';
 1188:             $itemcount ++;
 1189:         }
 1190:         $datatable .= &captcha_choice('login',$settings,$itemcount);
 1191:     } elsif ($caller eq 'headtag') {
 1192:         my %domservers = &Apache::lonnet::get_servers($dom);
 1193:         my $choice = $choices{'headtag'};
 1194:         $css_class = ' class="LC_odd_row"';
 1195:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
 1196:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
 1197:                       '<th>'.$choices{'current'}.'</th>'.
 1198:                       '<th>'.$choices{'action'}.'</th>'.
 1199:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
 1200:         my (%currurls,%currexempt);
 1201:         if (ref($settings) eq 'HASH') {
 1202:             if (ref($settings->{'headtag'}) eq 'HASH') {
 1203:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
 1204:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
 1205:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
 1206:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
 1207:                     }
 1208:                 }
 1209:             }
 1210:         }
 1211:         my %lt = &Apache::lonlocal::texthash(
 1212:                                                del  => 'Delete?',
 1213:                                                rep  => 'Replace:',
 1214:                                                upl  => 'Upload:',
 1215:                                                curr => 'View contents',
 1216:                                                none => 'None',
 1217:         );
 1218:         my $switchserver = &check_switchserver($dom,$confname);
 1219:         foreach my $lonhost (sort(keys(%domservers))) {
 1220:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
 1221:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
 1222:             if ($currurls{$lonhost}) {
 1223:                 $datatable .= '<td class="LC_right_item"><a href="'.
 1224:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
 1225:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
 1226:                               '">'.$lt{'curr'}.'</a></td>'.
 1227:                               '<td><span class="LC_nobreak"><label>'.
 1228:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
 1229:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
 1230:             } else {
 1231:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
 1232:             }
 1233:             $datatable .='<br />';
 1234:             if ($switchserver) {
 1235:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1236:             } else {
 1237:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
 1238:             }
 1239:             $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
 1240:         }
 1241:         $datatable .= '</table></td></tr>';
 1242:     }
 1243:     return $datatable;
 1244: }
 1245: 
 1246: sub login_choices {
 1247:     my %choices =
 1248:         &Apache::lonlocal::texthash (
 1249:             coursecatalog => 'Display Course/Community Catalog link?',
 1250:             adminmail     => "Display Administrator's E-mail Address?",
 1251:             helpdesk      => 'Display "Contact Helpdesk" link',
 1252:             disallowlogin => "Login page requests redirected",
 1253:             hostid        => "Server",
 1254:             server        => "Redirect to:",
 1255:             serverpath    => "Path",
 1256:             custompath    => "Custom", 
 1257:             exempt        => "Exempt IP(s)",
 1258:             directlogin   => "No redirect",
 1259:             newuser       => "Link to create a user account",
 1260:             img           => "Header",
 1261:             logo          => "Main Logo",
 1262:             domlogo       => "Domain Logo",
 1263:             login         => "Log-in Header", 
 1264:             textcol       => "Text color",
 1265:             bgcol         => "Box color",
 1266:             bgs           => "Background colors",
 1267:             links         => "Link colors",
 1268:             font          => "Font color",
 1269:             pgbg          => "Header",
 1270:             mainbg        => "Page",
 1271:             sidebg        => "Login box",
 1272:             link          => "Link",
 1273:             alink         => "Active link",
 1274:             vlink         => "Visited link",
 1275:             headtag       => "Custom markup",
 1276:             action        => "Action",
 1277:             current       => "Current",
 1278:         );
 1279:     return %choices;
 1280: }
 1281: 
 1282: sub print_rolecolors {
 1283:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
 1284:     my %choices = &color_font_choices();
 1285:     my @bgs = ('pgbg','tabbg','sidebg');
 1286:     my @links = ('link','alink','vlink');
 1287:     my @images = ('img');
 1288:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
 1289:     my %designhash = &Apache::loncommon::get_domainconf($dom);
 1290:     my %defaultdesign = %Apache::loncommon::defaultdesign;
 1291:     my (%is_custom,%designs);
 1292:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
 1293:     if (ref($settings) eq 'HASH') {
 1294:         if (ref($settings->{$role}) eq 'HASH') {
 1295:             if ($settings->{$role}->{'img'} ne '') {
 1296:                 $designs{'img'} = $settings->{$role}->{'img'};
 1297:                 $is_custom{'img'} = 1;
 1298:             }
 1299:             if ($settings->{$role}->{'font'} ne '') {
 1300:                 $designs{'font'} = $settings->{$role}->{'font'};
 1301:                 $is_custom{'font'} = 1;
 1302:             }
 1303:             if ($settings->{$role}->{'fontmenu'} ne '') {
 1304:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
 1305:                 $is_custom{'fontmenu'} = 1;
 1306:             }
 1307:             foreach my $item (@bgs) {
 1308:                 if ($settings->{$role}->{$item} ne '') {
 1309:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
 1310:                     $is_custom{$item} = 1;
 1311:                 }
 1312:             }
 1313:             foreach my $item (@links) {
 1314:                 if ($settings->{$role}->{$item} ne '') {
 1315:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
 1316:                     $is_custom{$item} = 1;
 1317:                 }
 1318:             }
 1319:         }
 1320:     } else {
 1321:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
 1322:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
 1323:             $is_custom{'img'} = 1;
 1324:         }
 1325:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
 1326:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
 1327:             $is_custom{'fontmenu'} = 1; 
 1328:         }
 1329:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
 1330:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
 1331:             $is_custom{'font'} = 1;
 1332:         }
 1333:         foreach my $item (@bgs) {
 1334:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1335:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1336:                 $is_custom{$item} = 1;
 1337:             
 1338:             }
 1339:         }
 1340:         foreach my $item (@links) {
 1341:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1342:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1343:                 $is_custom{$item} = 1;
 1344:             }
 1345:         }
 1346:     }
 1347:     my $itemcount = 1;
 1348:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
 1349:     $datatable .= '</tr></table></td></tr>';
 1350:     return $datatable;
 1351: }
 1352: 
 1353: sub role_defaults {
 1354:     my ($role,$bgs,$links,$images,$logintext) = @_;
 1355:     my %defaults;
 1356:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
 1357:         return %defaults;
 1358:     }
 1359:     my %defaultdesign = %Apache::loncommon::defaultdesign;
 1360:     if ($role eq 'login') {
 1361:         %defaults = (
 1362:                        font => $defaultdesign{$role.'.font'},
 1363:                     );
 1364:         if (ref($logintext) eq 'ARRAY') {
 1365:             foreach my $item (@{$logintext}) {
 1366:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
 1367:             }
 1368:         }
 1369:         foreach my $item (@{$images}) {
 1370:             $defaults{'showlogo'}{$item} = 1;
 1371:         }
 1372:     } else {
 1373:         %defaults = (
 1374:                        img => $defaultdesign{$role.'.img'},
 1375:                        font => $defaultdesign{$role.'.font'},
 1376:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
 1377:                     );
 1378:     }
 1379:     foreach my $item (@{$bgs}) {
 1380:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
 1381:     }
 1382:     foreach my $item (@{$links}) {
 1383:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
 1384:     }
 1385:     foreach my $item (@{$images}) {
 1386:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
 1387:     }
 1388:     return %defaults;
 1389: }
 1390: 
 1391: sub display_color_options {
 1392:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
 1393:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
 1394:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
 1395:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1396:     my $datatable = '<tr'.$css_class.'>'.
 1397:         '<td>'.$choices->{'font'}.'</td>';
 1398:     if (!$is_custom->{'font'}) {
 1399:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
 1400:     } else {
 1401:         $datatable .= '<td>&nbsp;</td>';
 1402:     }
 1403:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
 1404: 
 1405:     $datatable .= '<td><span class="LC_nobreak">'.
 1406:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
 1407:                   ' value="'.$current_color.'" />&nbsp;'.
 1408:                   '&nbsp;</td></tr>';
 1409:     unless ($role eq 'login') { 
 1410:         $datatable .= '<tr'.$css_class.'>'.
 1411:                       '<td>'.$choices->{'fontmenu'}.'</td>';
 1412:         if (!$is_custom->{'fontmenu'}) {
 1413:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
 1414:         } else {
 1415:             $datatable .= '<td>&nbsp;</td>';
 1416:         }
 1417: 	$current_color = $designs->{'fontmenu'} ?
 1418: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
 1419:         $datatable .= '<td><span class="LC_nobreak">'.
 1420:                       '<input class="colorchooser" type="text" size="10" name="'
 1421: 		      .$role.'_fontmenu"'.
 1422:                       ' value="'.$current_color.'" />&nbsp;'.
 1423:                       '&nbsp;</td></tr>';
 1424:     }
 1425:     my $switchserver = &check_switchserver($dom,$confname);
 1426:     foreach my $img (@{$images}) {
 1427: 	$itemcount ++;
 1428:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1429:         $datatable .= '<tr'.$css_class.'>'.
 1430:                       '<td>'.$choices->{$img};
 1431:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
 1432:         if ($role eq 'login') {
 1433:             if ($img eq 'login') {
 1434:                 $login_hdr_pick =
 1435:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
 1436:                 $logincolors =
 1437:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
 1438:                                        $designs,$defaults);
 1439:             } elsif ($img ne 'domlogo') {
 1440:                 $datatable.= &logo_display_options($img,$defaults,$designs);
 1441:             }
 1442:         }
 1443:         $datatable .= '</td>';
 1444:         if ($designs->{$img} ne '') {
 1445:             $imgfile = $designs->{$img};
 1446: 	    $img_import = ($imgfile =~ m{^/adm/});
 1447:         } else {
 1448:             $imgfile = $defaults->{$img};
 1449:         }
 1450:         if ($imgfile) {
 1451:             my ($showfile,$fullsize);
 1452:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1453:                 my $urldir = $1;
 1454:                 my $filename = $2;
 1455:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
 1456:                 if (@info) {
 1457:                     my $thumbfile = 'tn-'.$filename;
 1458:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
 1459:                     if (@thumb) {
 1460:                         $showfile = $urldir.'/'.$thumbfile;
 1461:                     } else {
 1462:                         $showfile = $imgfile;
 1463:                     }
 1464:                 } else {
 1465:                     $showfile = '';
 1466:                 }
 1467:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
 1468:                 $showfile = $imgfile;
 1469:                 my $imgdir = $1;
 1470:                 my $filename = $2;
 1471:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
 1472:                     $showfile = "/$imgdir/tn-".$filename;
 1473:                 } else {
 1474:                     my $input = $londocroot.$imgfile;
 1475:                     my $output = "$londocroot/$imgdir/tn-".$filename;
 1476:                     if (!-e $output) {
 1477:                         my ($width,$height) = &thumb_dimensions();
 1478:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
 1479:                         if ($fullwidth ne '' && $fullheight ne '') {
 1480:                             if ($fullwidth > $width && $fullheight > $height) { 
 1481:                                 my $size = $width.'x'.$height;
 1482:                                 system("convert -sample $size $input $output");
 1483:                                 $showfile = "/$imgdir/tn-".$filename;
 1484:                             }
 1485:                         }
 1486:                     }
 1487:                 }
 1488:             }
 1489:             if ($showfile) {
 1490:                 if ($showfile =~ m{^/(adm|res)/}) {
 1491:                     if ($showfile =~ m{^/res/}) {
 1492:                         my $local_showfile =
 1493:                             &Apache::lonnet::filelocation('',$showfile);
 1494:                         &Apache::lonnet::repcopy($local_showfile);
 1495:                     }
 1496:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
 1497:                 }
 1498:                 if ($imgfile) {
 1499:                     if ($imgfile  =~ m{^/(adm|res)/}) {
 1500:                         if ($imgfile =~ m{^/res/}) {
 1501:                             my $local_imgfile =
 1502:                                 &Apache::lonnet::filelocation('',$imgfile);
 1503:                             &Apache::lonnet::repcopy($local_imgfile);
 1504:                         }
 1505:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
 1506:                     } else {
 1507:                         $fullsize = $imgfile;
 1508:                     }
 1509:                 }
 1510:                 $datatable .= '<td>';
 1511:                 if ($img eq 'login') {
 1512:                     $datatable .= $login_hdr_pick;
 1513:                 } 
 1514:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
 1515:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
 1516:             } else {
 1517:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
 1518:                               &mt('Upload:').'<br />';
 1519:             }
 1520:         } else {
 1521:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
 1522:                           &mt('Upload:').'<br />';
 1523:         }
 1524:         if ($switchserver) {
 1525:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1526:         } else {
 1527:             if ($img ne 'login') { # suppress file selection for Log-in header
 1528:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
 1529:             }
 1530:         }
 1531:         $datatable .= '</td></tr>';
 1532:     }
 1533:     $itemcount ++;
 1534:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1535:     $datatable .= '<tr'.$css_class.'>'.
 1536:                   '<td>'.$choices->{'bgs'}.'</td>';
 1537:     my $bgs_def;
 1538:     foreach my $item (@{$bgs}) {
 1539:         if (!$is_custom->{$item}) {
 1540:             $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>';
 1541:         }
 1542:     }
 1543:     if ($bgs_def) {
 1544:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
 1545:     } else {
 1546:         $datatable .= '<td>&nbsp;</td>';
 1547:     }
 1548:     $datatable .= '<td class="LC_right_item">'.
 1549:                   '<table border="0"><tr>';
 1550: 
 1551:     foreach my $item (@{$bgs}) {
 1552:         $datatable .= '<td align="center">'.$choices->{$item};
 1553: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
 1554:         if ($designs->{'bgs'}{$item}) {
 1555:             $datatable .= '&nbsp;';
 1556:         }
 1557:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1558:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1559:     }
 1560:     $datatable .= '</tr></table></td></tr>';
 1561:     $itemcount ++;
 1562:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1563:     $datatable .= '<tr'.$css_class.'>'.
 1564:                   '<td>'.$choices->{'links'}.'</td>';
 1565:     my $links_def;
 1566:     foreach my $item (@{$links}) {
 1567:         if (!$is_custom->{$item}) {
 1568:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
 1569:         }
 1570:     }
 1571:     if ($links_def) {
 1572:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
 1573:     } else {
 1574:         $datatable .= '<td>&nbsp;</td>';
 1575:     }
 1576:     $datatable .= '<td class="LC_right_item">'.
 1577:                   '<table border="0"><tr>';
 1578:     foreach my $item (@{$links}) {
 1579: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
 1580:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
 1581:         if ($designs->{'links'}{$item}) {
 1582:             $datatable.='&nbsp;';
 1583:         }
 1584:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
 1585:                       '" /></td>';
 1586:     }
 1587:     $$rowtotal += $itemcount;
 1588:     return $datatable;
 1589: }
 1590: 
 1591: sub logo_display_options {
 1592:     my ($img,$defaults,$designs) = @_;
 1593:     my $checkedon;
 1594:     if (ref($defaults) eq 'HASH') {
 1595:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
 1596:             if ($defaults->{'showlogo'}{$img}) {
 1597:                 $checkedon = 'checked="checked" ';     
 1598:             }
 1599:         } 
 1600:     }
 1601:     if (ref($designs) eq 'HASH') {
 1602:         if (ref($designs->{'showlogo'}) eq 'HASH') {
 1603:             if (defined($designs->{'showlogo'}{$img})) {
 1604:                 if ($designs->{'showlogo'}{$img} == 0) {
 1605:                     $checkedon = '';
 1606:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
 1607:                     $checkedon = 'checked="checked" ';
 1608:                 }
 1609:             }
 1610:         }
 1611:     }
 1612:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
 1613:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
 1614:            &mt('show').'</label>'."\n";
 1615: }
 1616: 
 1617: sub login_header_options  {
 1618:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
 1619:     my $output = '';
 1620:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1621:         $output .= &mt('Text default(s):').'<br />';
 1622:         if (!$is_custom->{'textcol'}) {
 1623:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1624:                        '&nbsp;&nbsp;&nbsp;';
 1625:         }
 1626:         if (!$is_custom->{'bgcol'}) {
 1627:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1628:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1629:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1630:         }
 1631:         $output .= '<br />';
 1632:     }
 1633:     $output .='<br />';
 1634:     return $output;
 1635: }
 1636: 
 1637: sub login_text_colors {
 1638:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
 1639:     my $color_menu = '<table border="0"><tr>';
 1640:     foreach my $item (@{$logintext}) {
 1641:         $color_menu .= '<td align="center">'.$choices->{$item};
 1642:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
 1643:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1644:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1645:     }
 1646:     $color_menu .= '</tr></table><br />';
 1647:     return $color_menu;
 1648: }
 1649: 
 1650: sub image_changes {
 1651:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1652:     my $output;
 1653:     if ($img eq 'login') {
 1654:             # suppress image for Log-in header
 1655:     } elsif (!$is_custom) {
 1656:         if ($img ne 'domlogo') {
 1657:             $output .= &mt('Default image:').'<br />';
 1658:         } else {
 1659:             $output .= &mt('Default in use:').'<br />';
 1660:         }
 1661:     }
 1662:     if ($img eq 'login') { # suppress image for Log-in header
 1663:         $output .= '<td>'.$logincolors;
 1664:     } else {
 1665:         if ($img_import) {
 1666:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1667:         }
 1668:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1669:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1670:         if ($is_custom) {
 1671:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1672:                        '<input type="checkbox" name="'.
 1673:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1674:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1675:         } else {
 1676:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
 1677:         }
 1678:     }
 1679:     return $output;
 1680: }
 1681: 
 1682: sub print_quotas {
 1683:     my ($dom,$settings,$rowtotal,$action) = @_;
 1684:     my $context;
 1685:     if ($action eq 'quotas') {
 1686:         $context = 'tools';
 1687:     } else {
 1688:         $context = $action;
 1689:     }
 1690:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
 1691:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1692:     my $typecount = 0;
 1693:     my ($css_class,%titles);
 1694:     if ($context eq 'requestcourses') {
 1695:         @usertools = ('official','unofficial','community','textbook');
 1696:         @options =('norequest','approval','validate','autolimit');
 1697:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 1698:         %titles = &courserequest_titles();
 1699:     } elsif ($context eq 'requestauthor') {
 1700:         @usertools = ('author');
 1701:         @options = ('norequest','approval','automatic');
 1702:         %titles = &authorrequest_titles();
 1703:     } else {
 1704:         @usertools = ('aboutme','blog','webdav','portfolio');
 1705:         %titles = &tool_titles();
 1706:     }
 1707:     if (ref($types) eq 'ARRAY') {
 1708:         foreach my $type (@{$types}) {
 1709:             my ($currdefquota,$currauthorquota);
 1710:             unless (($context eq 'requestcourses') ||
 1711:                     ($context eq 'requestauthor')) {
 1712:                 if (ref($settings) eq 'HASH') {
 1713:                     if (ref($settings->{defaultquota}) eq 'HASH') {
 1714:                         $currdefquota = $settings->{defaultquota}->{$type};
 1715:                     } else {
 1716:                         $currdefquota = $settings->{$type};
 1717:                     }
 1718:                     if (ref($settings->{authorquota}) eq 'HASH') {
 1719:                         $currauthorquota = $settings->{authorquota}->{$type};
 1720:                     }
 1721:                 }
 1722:             }
 1723:             if (defined($usertypes->{$type})) {
 1724:                 $typecount ++;
 1725:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1726:                 $datatable .= '<tr'.$css_class.'>'.
 1727:                               '<td>'.$usertypes->{$type}.'</td>'.
 1728:                               '<td class="LC_left_item">';
 1729:                 if ($context eq 'requestcourses') {
 1730:                     $datatable .= '<table><tr>';
 1731:                 }
 1732:                 my %cell;  
 1733:                 foreach my $item (@usertools) {
 1734:                     if ($context eq 'requestcourses') {
 1735:                         my ($curroption,$currlimit);
 1736:                         if (ref($settings) eq 'HASH') {
 1737:                             if (ref($settings->{$item}) eq 'HASH') {
 1738:                                 $curroption = $settings->{$item}->{$type};
 1739:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
 1740:                                     $currlimit = $1; 
 1741:                                 }
 1742:                             }
 1743:                         }
 1744:                         if (!$curroption) {
 1745:                             $curroption = 'norequest';
 1746:                         }
 1747:                         $datatable .= '<th>'.$titles{$item}.'</th>';
 1748:                         foreach my $option (@options) {
 1749:                             my $val = $option;
 1750:                             if ($option eq 'norequest') {
 1751:                                 $val = 0;  
 1752:                             }
 1753:                             if ($option eq 'validate') {
 1754:                                 my $canvalidate = 0;
 1755:                                 if (ref($validations{$item}) eq 'HASH') { 
 1756:                                     if ($validations{$item}{$type}) {
 1757:                                         $canvalidate = 1;
 1758:                                     }
 1759:                                 }
 1760:                                 next if (!$canvalidate);
 1761:                             }
 1762:                             my $checked = '';
 1763:                             if ($option eq $curroption) {
 1764:                                 $checked = ' checked="checked"';
 1765:                             } elsif ($option eq 'autolimit') {
 1766:                                 if ($curroption =~ /^autolimit/) {
 1767:                                     $checked = ' checked="checked"';
 1768:                                 }                       
 1769:                             } 
 1770:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
 1771:                                   '<input type="radio" name="crsreq_'.$item.
 1772:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
 1773:                                   $titles{$option}.'</label>';
 1774:                             if ($option eq 'autolimit') {
 1775:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1776:                                                 $item.'_limit_'.$type.'" size="1" '.
 1777:                                                 'value="'.$currlimit.'" />';
 1778:                             }
 1779:                             $cell{$item} .= '</span> ';
 1780:                             if ($option eq 'autolimit') {
 1781:                                 $cell{$item} .= $titles{'unlimited'};
 1782:                             }
 1783:                         }
 1784:                     } elsif ($context eq 'requestauthor') {
 1785:                         my $curroption;
 1786:                         if (ref($settings) eq 'HASH') {
 1787:                             $curroption = $settings->{$type};
 1788:                         }
 1789:                         if (!$curroption) {
 1790:                             $curroption = 'norequest';
 1791:                         }
 1792:                         foreach my $option (@options) {
 1793:                             my $val = $option;
 1794:                             if ($option eq 'norequest') {
 1795:                                 $val = 0;
 1796:                             }
 1797:                             my $checked = '';
 1798:                             if ($option eq $curroption) {
 1799:                                 $checked = ' checked="checked"';
 1800:                             }
 1801:                             $datatable .= '<span class="LC_nobreak"><label>'.
 1802:                                   '<input type="radio" name="authorreq_'.$type.
 1803:                                   '" value="'.$val.'"'.$checked.' />'.
 1804:                                   $titles{$option}.'</label></span>&nbsp; ';
 1805:                         }
 1806:                     } else {
 1807:                         my $checked = 'checked="checked" ';
 1808:                         if (ref($settings) eq 'HASH') {
 1809:                             if (ref($settings->{$item}) eq 'HASH') {
 1810:                                 if ($settings->{$item}->{$type} == 0) {
 1811:                                     $checked = '';
 1812:                                 } elsif ($settings->{$item}->{$type} == 1) {
 1813:                                     $checked =  'checked="checked" ';
 1814:                                 }
 1815:                             }
 1816:                         }
 1817:                         $datatable .= '<span class="LC_nobreak"><label>'.
 1818:                                       '<input type="checkbox" name="'.$context.'_'.$item.
 1819:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1820:                                       '</label></span>&nbsp; ';
 1821:                     }
 1822:                 }
 1823:                 if ($context eq 'requestcourses') {
 1824:                     $datatable .= '</tr><tr>';
 1825:                     foreach my $item (@usertools) {
 1826:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
 1827:                     }
 1828:                     $datatable .= '</tr></table>';
 1829:                 }
 1830:                 $datatable .= '</td>';
 1831:                 unless (($context eq 'requestcourses') ||
 1832:                         ($context eq 'requestauthor')) {
 1833:                     $datatable .= 
 1834:                               '<td class="LC_right_item">'.
 1835:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1836:                               '<input type="text" name="quota_'.$type.
 1837:                               '" value="'.$currdefquota.
 1838:                               '" size="5" /></span>'.('&nbsp;' x 2).
 1839:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1840:                               '<input type="text" name="authorquota_'.$type.
 1841:                               '" value="'.$currauthorquota.
 1842:                               '" size="5" /></span></td>';
 1843:                 }
 1844:                 $datatable .= '</tr>';
 1845:             }
 1846:         }
 1847:     }
 1848:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1849:         $defaultquota = '20';
 1850:         $authorquota = '500';
 1851:         if (ref($settings) eq 'HASH') {
 1852:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1853:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
 1854:             } elsif (defined($settings->{'default'})) {
 1855:                 $defaultquota = $settings->{'default'};
 1856:             }
 1857:             if (ref($settings->{'authorquota'}) eq 'HASH') {
 1858:                 $authorquota = $settings->{'authorquota'}->{'default'};
 1859:             }
 1860:         }
 1861:     }
 1862:     $typecount ++;
 1863:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1864:     $datatable .= '<tr'.$css_class.'>'.
 1865:                   '<td>'.$othertitle.'</td>'.
 1866:                   '<td class="LC_left_item">';
 1867:     if ($context eq 'requestcourses') {
 1868:         $datatable .= '<table><tr>';
 1869:     }
 1870:     my %defcell;
 1871:     foreach my $item (@usertools) {
 1872:         if ($context eq 'requestcourses') {
 1873:             my ($curroption,$currlimit);
 1874:             if (ref($settings) eq 'HASH') {
 1875:                 if (ref($settings->{$item}) eq 'HASH') {
 1876:                     $curroption = $settings->{$item}->{'default'};
 1877:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1878:                         $currlimit = $1;
 1879:                     }
 1880:                 }
 1881:             }
 1882:             if (!$curroption) {
 1883:                 $curroption = 'norequest';
 1884:             }
 1885:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1886:             foreach my $option (@options) {
 1887:                 my $val = $option;
 1888:                 if ($option eq 'norequest') {
 1889:                     $val = 0;
 1890:                 }
 1891:                 if ($option eq 'validate') {
 1892:                     my $canvalidate = 0;
 1893:                     if (ref($validations{$item}) eq 'HASH') {
 1894:                         if ($validations{$item}{'default'}) {
 1895:                             $canvalidate = 1;
 1896:                         }
 1897:                     }
 1898:                     next if (!$canvalidate);
 1899:                 }
 1900:                 my $checked = '';
 1901:                 if ($option eq $curroption) {
 1902:                     $checked = ' checked="checked"';
 1903:                 } elsif ($option eq 'autolimit') {
 1904:                     if ($curroption =~ /^autolimit/) {
 1905:                         $checked = ' checked="checked"';
 1906:                     }
 1907:                 }
 1908:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
 1909:                                   '<input type="radio" name="crsreq_'.$item.
 1910:                                   '_default" value="'.$val.'"'.$checked.' />'.
 1911:                                   $titles{$option}.'</label>';
 1912:                 if ($option eq 'autolimit') {
 1913:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1914:                                        $item.'_limit_default" size="1" '.
 1915:                                        'value="'.$currlimit.'" />';
 1916:                 }
 1917:                 $defcell{$item} .= '</span> ';
 1918:                 if ($option eq 'autolimit') {
 1919:                     $defcell{$item} .= $titles{'unlimited'};
 1920:                 }
 1921:             }
 1922:         } elsif ($context eq 'requestauthor') {
 1923:             my $curroption;
 1924:             if (ref($settings) eq 'HASH') {
 1925:                 $curroption = $settings->{'default'};
 1926:             }
 1927:             if (!$curroption) {
 1928:                 $curroption = 'norequest';
 1929:             }
 1930:             foreach my $option (@options) {
 1931:                 my $val = $option;
 1932:                 if ($option eq 'norequest') {
 1933:                     $val = 0;
 1934:                 }
 1935:                 my $checked = '';
 1936:                 if ($option eq $curroption) {
 1937:                     $checked = ' checked="checked"';
 1938:                 }
 1939:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1940:                               '<input type="radio" name="authorreq_default"'.
 1941:                               ' value="'.$val.'"'.$checked.' />'.
 1942:                               $titles{$option}.'</label></span>&nbsp; ';
 1943:             }
 1944:         } else {
 1945:             my $checked = 'checked="checked" ';
 1946:             if (ref($settings) eq 'HASH') {
 1947:                 if (ref($settings->{$item}) eq 'HASH') {
 1948:                     if ($settings->{$item}->{'default'} == 0) {
 1949:                         $checked = '';
 1950:                     } elsif ($settings->{$item}->{'default'} == 1) {
 1951:                         $checked = 'checked="checked" ';
 1952:                     }
 1953:                 }
 1954:             }
 1955:             $datatable .= '<span class="LC_nobreak"><label>'.
 1956:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1957:                           '" value="default" '.$checked.'/>'.$titles{$item}.
 1958:                           '</label></span>&nbsp; ';
 1959:         }
 1960:     }
 1961:     if ($context eq 'requestcourses') {
 1962:         $datatable .= '</tr><tr>';
 1963:         foreach my $item (@usertools) {
 1964:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
 1965:         }
 1966:         $datatable .= '</tr></table>';
 1967:     }
 1968:     $datatable .= '</td>';
 1969:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1970:         $datatable .= '<td class="LC_right_item">'.
 1971:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1972:                       '<input type="text" name="defaultquota" value="'.
 1973:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
 1974:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1975:                       '<input type="text" name="authorquota" value="'.
 1976:                       $authorquota.'" size="5" /></span></td>';
 1977:     }
 1978:     $datatable .= '</tr>';
 1979:     $typecount ++;
 1980:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1981:     $datatable .= '<tr'.$css_class.'>'.
 1982:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
 1983:     if ($context eq 'requestcourses') {
 1984:         $datatable .= &mt('(overrides affiliation, if set)').
 1985:                       '</td>'.
 1986:                       '<td class="LC_left_item">'.
 1987:                       '<table><tr>';
 1988:     } else {
 1989:         $datatable .= &mt('(overrides affiliation, if checked)').
 1990:                       '</td>'.
 1991:                       '<td class="LC_left_item" colspan="2">'.
 1992:                       '<br />';
 1993:     }
 1994:     my %advcell;
 1995:     foreach my $item (@usertools) {
 1996:         if ($context eq 'requestcourses') {
 1997:             my ($curroption,$currlimit);
 1998:             if (ref($settings) eq 'HASH') {
 1999:                 if (ref($settings->{$item}) eq 'HASH') {
 2000:                     $curroption = $settings->{$item}->{'_LC_adv'};
 2001:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 2002:                         $currlimit = $1;
 2003:                     }
 2004:                 }
 2005:             }
 2006:             $datatable .= '<th>'.$titles{$item}.'</th>';
 2007:             my $checked = '';
 2008:             if ($curroption eq '') {
 2009:                 $checked = ' checked="checked"';
 2010:             }
 2011:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 2012:                                '<input type="radio" name="crsreq_'.$item.
 2013:                                '__LC_adv" value=""'.$checked.' />'.
 2014:                                &mt('No override set').'</label></span>&nbsp; ';
 2015:             foreach my $option (@options) {
 2016:                 my $val = $option;
 2017:                 if ($option eq 'norequest') {
 2018:                     $val = 0;
 2019:                 }
 2020:                 if ($option eq 'validate') {
 2021:                     my $canvalidate = 0;
 2022:                     if (ref($validations{$item}) eq 'HASH') {
 2023:                         if ($validations{$item}{'_LC_adv'}) {
 2024:                             $canvalidate = 1;
 2025:                         }
 2026:                     }
 2027:                     next if (!$canvalidate);
 2028:                 }
 2029:                 my $checked = '';
 2030:                 if ($val eq $curroption) {
 2031:                     $checked = ' checked="checked"';
 2032:                 } elsif ($option eq 'autolimit') {
 2033:                     if ($curroption =~ /^autolimit/) {
 2034:                         $checked = ' checked="checked"';
 2035:                     }
 2036:                 }
 2037:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 2038:                                   '<input type="radio" name="crsreq_'.$item.
 2039:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
 2040:                                   $titles{$option}.'</label>';
 2041:                 if ($option eq 'autolimit') {
 2042:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 2043:                                        $item.'_limit__LC_adv" size="1" '.
 2044:                                        'value="'.$currlimit.'" />';
 2045:                 }
 2046:                 $advcell{$item} .= '</span> ';
 2047:                 if ($option eq 'autolimit') {
 2048:                     $advcell{$item} .= $titles{'unlimited'};
 2049:                 }
 2050:             }
 2051:         } elsif ($context eq 'requestauthor') {
 2052:             my $curroption;
 2053:             if (ref($settings) eq 'HASH') {
 2054:                 $curroption = $settings->{'_LC_adv'};
 2055:             }
 2056:             my $checked = '';
 2057:             if ($curroption eq '') {
 2058:                 $checked = ' checked="checked"';
 2059:             }
 2060:             $datatable .= '<span class="LC_nobreak"><label>'.
 2061:                           '<input type="radio" name="authorreq__LC_adv"'.
 2062:                           ' value=""'.$checked.' />'.
 2063:                           &mt('No override set').'</label></span>&nbsp; ';
 2064:             foreach my $option (@options) {
 2065:                 my $val = $option;
 2066:                 if ($option eq 'norequest') {
 2067:                     $val = 0;
 2068:                 }
 2069:                 my $checked = '';
 2070:                 if ($val eq $curroption) {
 2071:                     $checked = ' checked="checked"';
 2072:                 }
 2073:                 $datatable .= '<span class="LC_nobreak"><label>'.
 2074:                               '<input type="radio" name="authorreq__LC_adv"'.
 2075:                               ' value="'.$val.'"'.$checked.' />'.
 2076:                               $titles{$option}.'</label></span>&nbsp; ';
 2077:             }
 2078:         } else {
 2079:             my $checked = 'checked="checked" ';
 2080:             if (ref($settings) eq 'HASH') {
 2081:                 if (ref($settings->{$item}) eq 'HASH') {
 2082:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
 2083:                         $checked = '';
 2084:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
 2085:                         $checked = 'checked="checked" ';
 2086:                     }
 2087:                 }
 2088:             }
 2089:             $datatable .= '<span class="LC_nobreak"><label>'.
 2090:                           '<input type="checkbox" name="'.$context.'_'.$item.
 2091:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 2092:                           '</label></span>&nbsp; ';
 2093:         }
 2094:     }
 2095:     if ($context eq 'requestcourses') {
 2096:         $datatable .= '</tr><tr>';
 2097:         foreach my $item (@usertools) {
 2098:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
 2099:         }
 2100:         $datatable .= '</tr></table>';
 2101:     }
 2102:     $datatable .= '</td></tr>';
 2103:     $$rowtotal += $typecount;
 2104:     return $datatable;
 2105: }
 2106: 
 2107: sub print_requestmail {
 2108:     my ($dom,$action,$settings,$rowtotal) = @_;
 2109:     my ($now,$datatable,%currapp);
 2110:     $now = time;
 2111:     if (ref($settings) eq 'HASH') {
 2112:         if (ref($settings->{'notify'}) eq 'HASH') {
 2113:             if ($settings->{'notify'}{'approval'} ne '') {
 2114:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
 2115:             }
 2116:         }
 2117:     }
 2118:     my $numinrow = 2;
 2119:     my $css_class;
 2120:     $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
 2121:     my $text;
 2122:     if ($action eq 'requestcourses') {
 2123:         $text = &mt('Receive notification of course requests requiring approval');
 2124:     } elsif ($action eq 'requestauthor') {
 2125:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
 2126:     } else {
 2127:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
 2128:     }
 2129:     $datatable = '<tr'.$css_class.'>'.
 2130:                  ' <td>'.$text.'</td>'.
 2131:                  ' <td class="LC_left_item">';
 2132:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
 2133:                                                  $action.'notifyapproval',%currapp);
 2134:     if ($numdc > 0) {
 2135:         $datatable .= $table;
 2136:     } else {
 2137:         $datatable .= &mt('There are no active Domain Coordinators');
 2138:     }
 2139:     $datatable .='</td></tr>';
 2140:     return $datatable;
 2141: }
 2142: 
 2143: sub print_studentcode {
 2144:     my ($settings,$rowtotal) = @_;
 2145:     my $rownum = 0; 
 2146:     my ($output,%current);
 2147:     my @crstypes = ('official','unofficial','community','textbook');
 2148:     if (ref($settings) eq 'HASH') {
 2149:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
 2150:             foreach my $type (@crstypes) {
 2151:                 $current{$type} = $settings->{'uniquecode'}{$type};
 2152:             }
 2153:         }
 2154:     }
 2155:     $output .= '<tr>'.
 2156:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
 2157:                '<td class="LC_left_item">';
 2158:     foreach my $type (@crstypes) {
 2159:         my $check = ' ';
 2160:         if ($current{$type}) {
 2161:             $check = ' checked="checked" ';
 2162:         }
 2163:         $output .= '<span class="LC_nobreak"><label>'.
 2164:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
 2165:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
 2166:     }
 2167:     $output .= '</td></tr>';
 2168:     $$rowtotal ++;
 2169:     return $output;
 2170: }
 2171: 
 2172: sub print_textbookcourses {
 2173:     my ($dom,$type,$settings,$rowtotal) = @_;
 2174:     my $rownum = 0;
 2175:     my $css_class;
 2176:     my $itemcount = 1;
 2177:     my $maxnum = 0;
 2178:     my $bookshash;
 2179:     if (ref($settings) eq 'HASH') {
 2180:         $bookshash = $settings->{$type};
 2181:     }
 2182:     my %ordered;
 2183:     if (ref($bookshash) eq 'HASH') {
 2184:         foreach my $item (keys(%{$bookshash})) {
 2185:             if (ref($bookshash->{$item}) eq 'HASH') {
 2186:                 my $num = $bookshash->{$item}{'order'};
 2187:                 $ordered{$num} = $item;
 2188:             }
 2189:         }
 2190:     }
 2191:     my $confname = $dom.'-domainconfig';
 2192:     my $switchserver = &check_switchserver($dom,$confname);
 2193:     my $maxnum = scalar(keys(%ordered));
 2194:     my $datatable;
 2195:     if (keys(%ordered)) {
 2196:         my @items = sort { $a <=> $b } keys(%ordered);
 2197:         for (my $i=0; $i<@items; $i++) {
 2198:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2199:             my $key = $ordered{$items[$i]};
 2200:             my %coursehash=&Apache::lonnet::coursedescription($key);
 2201:             my $coursetitle = $coursehash{'description'};
 2202:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
 2203:             if (ref($bookshash->{$key}) eq 'HASH') {
 2204:                 $subject = $bookshash->{$key}->{'subject'};
 2205:                 $title = $bookshash->{$key}->{'title'};
 2206:                 if ($type eq 'textbooks') {
 2207:                     $publisher = $bookshash->{$key}->{'publisher'};
 2208:                     $author = $bookshash->{$key}->{'author'};
 2209:                     $image = $bookshash->{$key}->{'image'};
 2210:                     if ($image ne '') {
 2211:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
 2212:                         my $imagethumb = "$path/tn-".$imagefile;
 2213:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
 2214:                     }
 2215:                 }
 2216:             }
 2217:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
 2218:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 2219:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
 2220:             for (my $k=0; $k<=$maxnum; $k++) {
 2221:                 my $vpos = $k+1;
 2222:                 my $selstr;
 2223:                 if ($k == $i) {
 2224:                     $selstr = ' selected="selected" ';
 2225:                 }
 2226:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2227:             }
 2228:             $datatable .= '</select>'.('&nbsp;'x2).
 2229:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
 2230:                 &mt('Delete?').'</label></span></td>'.
 2231:                 '<td colspan="2">'.
 2232:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
 2233:                 ('&nbsp;'x2).
 2234:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
 2235:             if ($type eq 'textbooks') {
 2236:                 $datatable .= ('&nbsp;'x2).
 2237:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
 2238:                               ('&nbsp;'x2).
 2239:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
 2240:                               ('&nbsp;'x2).
 2241:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
 2242:                 if ($image) {
 2243:                     $datatable .= '<span class="LC_nobreak">'.
 2244:                                   $imgsrc.
 2245:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
 2246:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
 2247:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
 2248:                 }
 2249:                 if ($switchserver) {
 2250:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2251:                 } else {
 2252:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
 2253:                 }
 2254:             }
 2255:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
 2256:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
 2257:                           $coursetitle.'</span></td></tr>'."\n";
 2258:             $itemcount ++;
 2259:         }
 2260:     }
 2261:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2262:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
 2263:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
 2264:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
 2265:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
 2266:     for (my $k=0; $k<$maxnum+1; $k++) {
 2267:         my $vpos = $k+1;
 2268:         my $selstr;
 2269:         if ($k == $maxnum) {
 2270:             $selstr = ' selected="selected" ';
 2271:         }
 2272:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2273:     }
 2274:     $datatable .= '</select>&nbsp;'."\n".
 2275:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
 2276:                   '<td colspan="2">'.
 2277:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
 2278:                   ('&nbsp;'x2).
 2279:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
 2280:                   ('&nbsp;'x2);
 2281:     if ($type eq 'textbooks') {
 2282:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
 2283:                       ('&nbsp;'x2).
 2284:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
 2285:                       ('&nbsp;'x2).
 2286:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
 2287:         if ($switchserver) {
 2288:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2289:         } else {
 2290:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
 2291:         }
 2292:     }
 2293:     $datatable .= '</span>'."\n".
 2294:                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
 2295:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
 2296:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
 2297:                   &Apache::loncommon::selectcourse_link
 2298:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
 2299:                   '</span></td>'."\n".
 2300:                   '</tr>'."\n";
 2301:     $itemcount ++;
 2302:     return $datatable;
 2303: }
 2304: 
 2305: sub textbookcourses_javascript {
 2306:     my ($settings) = @_;
 2307:     return unless(ref($settings) eq 'HASH');
 2308:     my (%ordered,%total,%jstext);
 2309:     foreach my $type ('textbooks','templates') {
 2310:         $total{$type} = 0;
 2311:         if (ref($settings->{$type}) eq 'HASH') {
 2312:             foreach my $item (keys(%{$settings->{$type}})) {
 2313:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
 2314:                     my $num = $settings->{$type}->{$item}{'order'};
 2315:                     $ordered{$type}{$num} = $item;
 2316:                 }
 2317:             }
 2318:             $total{$type} = scalar(keys(%{$settings->{$type}}));
 2319:         }
 2320:         my @jsarray = ();
 2321:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
 2322:             push(@jsarray,$ordered{$type}{$item});
 2323:         }
 2324:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
 2325:     }
 2326:     return <<"ENDSCRIPT";
 2327: <script type="text/javascript">
 2328: // <![CDATA[
 2329: function reorderBooks(form,item,caller) {
 2330:     var changedVal;
 2331: $jstext{'textbooks'};
 2332: $jstext{'templates'};
 2333:     var newpos;
 2334:     var maxh;
 2335:     if (caller == 'textbooks') {  
 2336:         newpos = 'textbooks_addbook_pos';
 2337:         maxh = 1 + $total{'textbooks'};
 2338:     } else {
 2339:         newpos = 'templates_addbook_pos';
 2340:         maxh = 1 + $total{'templates'};
 2341:     }
 2342:     var current = new Array;
 2343:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 2344:     if (item == newpos) {
 2345:         changedVal = newitemVal;
 2346:     } else {
 2347:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 2348:         current[newitemVal] = newpos;
 2349:     }
 2350:     if (caller == 'textbooks') {
 2351:         for (var i=0; i<textbooks.length; i++) {
 2352:             var elementName = 'textbooks_'+textbooks[i];
 2353:             if (elementName != item) {
 2354:                 if (form.elements[elementName]) {
 2355:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 2356:                     current[currVal] = elementName;
 2357:                 }
 2358:             }
 2359:         }
 2360:     }
 2361:     if (caller == 'templates') {
 2362:         for (var i=0; i<templates.length; i++) {
 2363:             var elementName = 'templates_'+templates[i];
 2364:             if (elementName != item) {
 2365:                 if (form.elements[elementName]) {
 2366:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 2367:                     current[currVal] = elementName;
 2368:                 }
 2369:             }
 2370:         }
 2371:     }
 2372:     var oldVal;
 2373:     for (var j=0; j<maxh; j++) {
 2374:         if (current[j] == undefined) {
 2375:             oldVal = j;
 2376:         }
 2377:     }
 2378:     if (oldVal < changedVal) {
 2379:         for (var k=oldVal+1; k<=changedVal ; k++) {
 2380:            var elementName = current[k];
 2381:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 2382:         }
 2383:     } else {
 2384:         for (var k=changedVal; k<oldVal; k++) {
 2385:             var elementName = current[k];
 2386:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 2387:         }
 2388:     }
 2389:     return;
 2390: }
 2391: 
 2392: // ]]>
 2393: </script>
 2394: 
 2395: ENDSCRIPT
 2396: }
 2397: 
 2398: sub print_autoenroll {
 2399:     my ($dom,$settings,$rowtotal) = @_;
 2400:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 2401:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
 2402:     if (ref($settings) eq 'HASH') {
 2403:         if (exists($settings->{'run'})) {
 2404:             if ($settings->{'run'} eq '0') {
 2405:                 $runoff = ' checked="checked" ';
 2406:                 $runon = ' ';
 2407:             } else {
 2408:                 $runon = ' checked="checked" ';
 2409:                 $runoff = ' ';
 2410:             }
 2411:         } else {
 2412:             if ($autorun) {
 2413:                 $runon = ' checked="checked" ';
 2414:                 $runoff = ' ';
 2415:             } else {
 2416:                 $runoff = ' checked="checked" ';
 2417:                 $runon = ' ';
 2418:             }
 2419:         }
 2420:         if (exists($settings->{'co-owners'})) {
 2421:             if ($settings->{'co-owners'} eq '0') {
 2422:                 $coownersoff = ' checked="checked" ';
 2423:                 $coownerson = ' ';
 2424:             } else {
 2425:                 $coownerson = ' checked="checked" ';
 2426:                 $coownersoff = ' ';
 2427:             }
 2428:         } else {
 2429:             $coownersoff = ' checked="checked" ';
 2430:             $coownerson = ' ';
 2431:         }
 2432:         if (exists($settings->{'sender_domain'})) {
 2433:             $defdom = $settings->{'sender_domain'};
 2434:         }
 2435:     } else {
 2436:         if ($autorun) {
 2437:             $runon = ' checked="checked" ';
 2438:             $runoff = ' ';
 2439:         } else {
 2440:             $runoff = ' checked="checked" ';
 2441:             $runon = ' ';
 2442:         }
 2443:     }
 2444:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 2445:     my $notif_sender;
 2446:     if (ref($settings) eq 'HASH') {
 2447:         $notif_sender = $settings->{'sender_uname'};
 2448:     }
 2449:     my $datatable='<tr class="LC_odd_row">'.
 2450:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 2451:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2452:                   '<input type="radio" name="autoenroll_run"'.
 2453:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2454:                   '<label><input type="radio" name="autoenroll_run"'.
 2455:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2456:                   '</tr><tr>'.
 2457:                   '<td>'.&mt('Notification messages - sender').
 2458:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 2459:                   &mt('username').':&nbsp;'.
 2460:                   '<input type="text" name="sender_uname" value="'.
 2461:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 2462:                   ':&nbsp;'.$domform.'</span></td></tr>'.
 2463:                   '<tr class="LC_odd_row">'.
 2464:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
 2465:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2466:                   '<input type="radio" name="autoassign_coowners"'.
 2467:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2468:                   '<label><input type="radio" name="autoassign_coowners"'.
 2469:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2470:                   '</tr>';
 2471:     $$rowtotal += 3;
 2472:     return $datatable;
 2473: }
 2474: 
 2475: sub print_autoupdate {
 2476:     my ($position,$dom,$settings,$rowtotal) = @_;
 2477:     my $datatable;
 2478:     if ($position eq 'top') {
 2479:         my $updateon = ' ';
 2480:         my $updateoff = ' checked="checked" ';
 2481:         my $classlistson = ' ';
 2482:         my $classlistsoff = ' checked="checked" ';
 2483:         if (ref($settings) eq 'HASH') {
 2484:             if ($settings->{'run'} eq '1') {
 2485:                 $updateon = $updateoff;
 2486:                 $updateoff = ' ';
 2487:             }
 2488:             if ($settings->{'classlists'} eq '1') {
 2489:                 $classlistson = $classlistsoff;
 2490:                 $classlistsoff = ' ';
 2491:             }
 2492:         }
 2493:         my %title = (
 2494:                    run => 'Auto-update active?',
 2495:                    classlists => 'Update information in classlists?',
 2496:                     );
 2497:         $datatable = '<tr class="LC_odd_row">'. 
 2498:                   '<td>'.&mt($title{'run'}).'</td>'.
 2499:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2500:                   '<input type="radio" name="autoupdate_run"'.
 2501:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2502:                   '<label><input type="radio" name="autoupdate_run"'.
 2503:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2504:                   '</tr><tr>'.
 2505:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 2506:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 2507:                   '<label><input type="radio" name="classlists"'.
 2508:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2509:                   '<label><input type="radio" name="classlists"'.
 2510:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2511:                   '</tr>';
 2512:         $$rowtotal += 2;
 2513:     } elsif ($position eq 'middle') {
 2514:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2515:         my $numinrow = 3;
 2516:         my $locknamesettings;
 2517:         $datatable .= &insttypes_row($settings,$types,$usertypes,
 2518:                                      $dom,$numinrow,$othertitle,
 2519:                                     'lockablenames');
 2520:         $$rowtotal ++;
 2521:     } else {
 2522:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2523:         my @fields = ('lastname','firstname','middlename','generation',
 2524:                       'permanentemail','id');
 2525:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 2526:         my $numrows = 0;
 2527:         if (ref($types) eq 'ARRAY') {
 2528:             if (@{$types} > 0) {
 2529:                 $datatable = 
 2530:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 2531:                                          \@fields,$types,\$numrows);
 2532:                     $$rowtotal += @{$types}; 
 2533:             }
 2534:         }
 2535:         $datatable .= 
 2536:             &usertype_update_row($settings,{'default' => $othertitle},
 2537:                                  \%fieldtitles,\@fields,['default'],
 2538:                                  \$numrows);
 2539:         $$rowtotal ++;     
 2540:     }
 2541:     return $datatable;
 2542: }
 2543: 
 2544: sub print_autocreate {
 2545:     my ($dom,$settings,$rowtotal) = @_;
 2546:     my (%createon,%createoff,%currhash);
 2547:     my @types = ('xml','req');
 2548:     if (ref($settings) eq 'HASH') {
 2549:         foreach my $item (@types) {
 2550:             $createoff{$item} = ' checked="checked" ';
 2551:             $createon{$item} = ' ';
 2552:             if (exists($settings->{$item})) {
 2553:                 if ($settings->{$item}) {
 2554:                     $createon{$item} = ' checked="checked" ';
 2555:                     $createoff{$item} = ' ';
 2556:                 }
 2557:             }
 2558:         }
 2559:         if ($settings->{'xmldc'} ne '') {
 2560:             $currhash{$settings->{'xmldc'}} = 1;
 2561:         }
 2562:     } else {
 2563:         foreach my $item (@types) {
 2564:             $createoff{$item} = ' checked="checked" ';
 2565:             $createon{$item} = ' ';
 2566:         }
 2567:     }
 2568:     $$rowtotal += 2;
 2569:     my $numinrow = 2;
 2570:     my $datatable='<tr class="LC_odd_row">'.
 2571:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
 2572:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2573:                   '<input type="radio" name="autocreate_xml"'.
 2574:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2575:                   '<label><input type="radio" name="autocreate_xml"'.
 2576:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
 2577:                   '</td></tr><tr>'.
 2578:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
 2579:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2580:                   '<input type="radio" name="autocreate_req"'.
 2581:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2582:                   '<label><input type="radio" name="autocreate_req"'.
 2583:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
 2584:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
 2585:                                                    'autocreate_xmldc',%currhash);
 2586:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
 2587:     if ($numdc > 1) {
 2588:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
 2589:                       '</td><td class="LC_left_item">';
 2590:     } else {
 2591:         $datatable .= &mt('Course creation processed as:').
 2592:                       '</td><td class="LC_right_item">';
 2593:     }
 2594:     $datatable .= $dctable.'</td></tr>';
 2595:     $$rowtotal += $rows;
 2596:     return $datatable;
 2597: }
 2598: 
 2599: sub print_directorysrch {
 2600:     my ($dom,$settings,$rowtotal) = @_;
 2601:     my $srchon = ' ';
 2602:     my $srchoff = ' checked="checked" ';
 2603:     my ($exacton,$containson,$beginson);
 2604:     my $localon = ' ';
 2605:     my $localoff = ' checked="checked" ';
 2606:     if (ref($settings) eq 'HASH') {
 2607:         if ($settings->{'available'} eq '1') {
 2608:             $srchon = $srchoff;
 2609:             $srchoff = ' ';
 2610:         }
 2611:         if ($settings->{'localonly'} eq '1') {
 2612:             $localon = $localoff;
 2613:             $localoff = ' ';
 2614:         }
 2615:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 2616:             foreach my $type (@{$settings->{'searchtypes'}}) {
 2617:                 if ($type eq 'exact') {
 2618:                     $exacton = ' checked="checked" ';
 2619:                 } elsif ($type eq 'contains') {
 2620:                     $containson = ' checked="checked" ';
 2621:                 } elsif ($type eq 'begins') {
 2622:                     $beginson = ' checked="checked" ';
 2623:                 }
 2624:             }
 2625:         } else {
 2626:             if ($settings->{'searchtypes'} eq 'exact') {
 2627:                 $exacton = ' checked="checked" ';
 2628:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 2629:                 $containson = ' checked="checked" ';
 2630:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 2631:                 $exacton = ' checked="checked" ';
 2632:                 $containson = ' checked="checked" ';
 2633:             }
 2634:         }
 2635:     }
 2636:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 2637:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2638: 
 2639:     my $numinrow = 4;
 2640:     my $cansrchrow = 0;
 2641:     my $datatable='<tr class="LC_odd_row">'.
 2642:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 2643:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2644:                   '<input type="radio" name="dirsrch_available"'.
 2645:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2646:                   '<label><input type="radio" name="dirsrch_available"'.
 2647:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2648:                   '</tr><tr>'.
 2649:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 2650:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2651:                   '<input type="radio" name="dirsrch_localonly"'.
 2652:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 2653:                   '<label><input type="radio" name="dirsrch_localonly"'.
 2654:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 2655:                   '</tr>';
 2656:     $$rowtotal += 2;
 2657:     if (ref($usertypes) eq 'HASH') {
 2658:         if (keys(%{$usertypes}) > 0) {
 2659:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
 2660:                                          $numinrow,$othertitle,'cansearch');
 2661:             $cansrchrow = 1;
 2662:         }
 2663:     }
 2664:     if ($cansrchrow) {
 2665:         $$rowtotal ++;
 2666:         $datatable .= '<tr>';
 2667:     } else {
 2668:         $datatable .= '<tr class="LC_odd_row">';
 2669:     }
 2670:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 2671:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 2672:     foreach my $title (@{$titleorder}) {
 2673:         if (defined($searchtitles->{$title})) {
 2674:             my $check = ' ';
 2675:             if (ref($settings) eq 'HASH') {
 2676:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 2677:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 2678:                         $check = ' checked="checked" ';
 2679:                     }
 2680:                 }
 2681:             }
 2682:             $datatable .= '<td class="LC_left_item">'.
 2683:                           '<span class="LC_nobreak"><label>'.
 2684:                           '<input type="checkbox" name="searchby" '.
 2685:                           'value="'.$title.'"'.$check.'/>'.
 2686:                           $searchtitles->{$title}.'</label></span></td>';
 2687:         }
 2688:     }
 2689:     $datatable .= '</tr></table></td></tr>';
 2690:     $$rowtotal ++;
 2691:     if ($cansrchrow) {
 2692:         $datatable .= '<tr class="LC_odd_row">';
 2693:     } else {
 2694:         $datatable .= '<tr>';
 2695:     }
 2696:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 2697:                   '<td class="LC_left_item" colspan="2">'.
 2698:                   '<span class="LC_nobreak"><label>'.
 2699:                   '<input type="checkbox" name="searchtypes" '.
 2700:                   $exacton.' value="exact" />'.&mt('Exact match').
 2701:                   '</label>&nbsp;'.
 2702:                   '<label><input type="checkbox" name="searchtypes" '.
 2703:                   $beginson.' value="begins" />'.&mt('Begins with').
 2704:                   '</label>&nbsp;'.
 2705:                   '<label><input type="checkbox" name="searchtypes" '.
 2706:                   $containson.' value="contains" />'.&mt('Contains').
 2707:                   '</label></span></td></tr>';
 2708:     $$rowtotal ++;
 2709:     return $datatable;
 2710: }
 2711: 
 2712: sub print_contacts {
 2713:     my ($dom,$settings,$rowtotal) = @_;
 2714:     my $datatable;
 2715:     my @contacts = ('adminemail','supportemail');
 2716:     my (%checked,%to,%otheremails,%bccemails);
 2717:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
 2718:                     'requestsmail','updatesmail','idconflictsmail');
 2719:     foreach my $type (@mailings) {
 2720:         $otheremails{$type} = '';
 2721:     }
 2722:     $bccemails{'helpdeskmail'} = '';
 2723:     if (ref($settings) eq 'HASH') {
 2724:         foreach my $item (@contacts) {
 2725:             if (exists($settings->{$item})) {
 2726:                 $to{$item} = $settings->{$item};
 2727:             }
 2728:         }
 2729:         foreach my $type (@mailings) {
 2730:             if (exists($settings->{$type})) {
 2731:                 if (ref($settings->{$type}) eq 'HASH') {
 2732:                     foreach my $item (@contacts) {
 2733:                         if ($settings->{$type}{$item}) {
 2734:                             $checked{$type}{$item} = ' checked="checked" ';
 2735:                         }
 2736:                     }
 2737:                     $otheremails{$type} = $settings->{$type}{'others'};
 2738:                     if ($type eq 'helpdeskmail') {
 2739:                         $bccemails{$type} = $settings->{$type}{'bcc'};
 2740:                     }
 2741:                 }
 2742:             } elsif ($type eq 'lonstatusmail') {
 2743:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
 2744:             }
 2745:         }
 2746:     } else {
 2747:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2748:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2749:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 2750:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 2751:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
 2752:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
 2753:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
 2754:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
 2755:         $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
 2756:     }
 2757:     my ($titles,$short_titles) = &contact_titles();
 2758:     my $rownum = 0;
 2759:     my $css_class;
 2760:     foreach my $item (@contacts) {
 2761:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2762:         $datatable .= '<tr'.$css_class.'>'. 
 2763:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2764:                   '</span></td><td class="LC_right_item">'.
 2765:                   '<input type="text" name="'.$item.'" value="'.
 2766:                   $to{$item}.'" /></td></tr>';
 2767:         $rownum ++;
 2768:     }
 2769:     foreach my $type (@mailings) {
 2770:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2771:         $datatable .= '<tr'.$css_class.'>'.
 2772:                       '<td><span class="LC_nobreak">'.
 2773:                       $titles->{$type}.': </span></td>'.
 2774:                       '<td class="LC_left_item">'.
 2775:                       '<span class="LC_nobreak">';
 2776:         foreach my $item (@contacts) {
 2777:             $datatable .= '<label>'.
 2778:                           '<input type="checkbox" name="'.$type.'"'.
 2779:                           $checked{$type}{$item}.
 2780:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 2781:                           '</label>&nbsp;';
 2782:         }
 2783:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 2784:                       '<input type="text" name="'.$type.'_others" '.
 2785:                       'value="'.$otheremails{$type}.'"  />';
 2786:         if ($type eq 'helpdeskmail') {
 2787:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
 2788:                           '<input type="text" name="'.$type.'_bcc" '.
 2789:                           'value="'.$bccemails{$type}.'"  />';
 2790:         }
 2791:         $datatable .= '</td></tr>'."\n";
 2792:         $rownum ++;
 2793:     }
 2794:     my %choices;
 2795:     $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
 2796:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 2797:                                    &mt('LON-CAPA core group - MSU'),600,500));
 2798:     $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
 2799:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 2800:                                     &mt('LON-CAPA core group - MSU'),600,500));
 2801:     my @toggles = ('reporterrors','reportupdates');
 2802:     my %defaultchecked = ('reporterrors'  => 'on',
 2803:                           'reportupdates' => 'on');
 2804:     (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2805:                                                \%choices,$rownum);
 2806:     $datatable .= $reports;
 2807:     $$rowtotal += $rownum;
 2808:     return $datatable;
 2809: }
 2810: 
 2811: sub print_helpsettings {
 2812:     my ($dom,$confname,$settings,$rowtotal) = @_;
 2813:     my ($datatable,$itemcount);
 2814:     $itemcount = 1;
 2815:     my (%choices,%defaultchecked,@toggles);
 2816:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
 2817:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
 2818:                                  &mt('LON-CAPA bug tracker'),600,500));
 2819:     %defaultchecked = ('submitbugs' => 'on');
 2820:     @toggles = ('submitbugs',);
 2821: 
 2822:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2823:                                                  \%choices,$itemcount);
 2824:     return $datatable;
 2825: }
 2826: 
 2827: sub radiobutton_prefs {
 2828:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
 2829:         $additional,$align) = @_;
 2830:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
 2831:                    (ref($choices) eq 'HASH'));
 2832: 
 2833:     my (%checkedon,%checkedoff,$datatable,$css_class);
 2834: 
 2835:     foreach my $item (@{$toggles}) {
 2836:         if ($defaultchecked->{$item} eq 'on') {
 2837:             $checkedon{$item} = ' checked="checked" ';
 2838:             $checkedoff{$item} = ' ';
 2839:         } elsif ($defaultchecked->{$item} eq 'off') {
 2840:             $checkedoff{$item} = ' checked="checked" ';
 2841:             $checkedon{$item} = ' ';
 2842:         }
 2843:     }
 2844:     if (ref($settings) eq 'HASH') {
 2845:         foreach my $item (@{$toggles}) {
 2846:             if ($settings->{$item} eq '1') {
 2847:                 $checkedon{$item} =  ' checked="checked" ';
 2848:                 $checkedoff{$item} = ' ';
 2849:             } elsif ($settings->{$item} eq '0') {
 2850:                 $checkedoff{$item} =  ' checked="checked" ';
 2851:                 $checkedon{$item} = ' ';
 2852:             }
 2853:         }
 2854:     }
 2855:     if ($onclick) {
 2856:         $onclick = ' onclick="'.$onclick.'"';
 2857:     }
 2858:     foreach my $item (@{$toggles}) {
 2859:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2860:         $datatable .=
 2861:             '<tr'.$css_class.'><td valign="top">'.
 2862:             '<span class="LC_nobreak">'.$choices->{$item}.
 2863:             '</span></td>';
 2864:         if ($align eq 'left') {
 2865:             $datatable .= '<td class="LC_left_item">';
 2866:         } else {
 2867:             $datatable .= '<td class="LC_right_item">';
 2868:         }
 2869:         $datatable .=
 2870:             '<span class="LC_nobreak">'.
 2871:             '<label><input type="radio" name="'.
 2872:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
 2873:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
 2874:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
 2875:             '</span>'.$additional.
 2876:             '</td>'.
 2877:             '</tr>';
 2878:         $itemcount ++;
 2879:     }
 2880:     return ($datatable,$itemcount);
 2881: }
 2882: 
 2883: sub print_coursedefaults {
 2884:     my ($position,$dom,$settings,$rowtotal) = @_;
 2885:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
 2886:     my $itemcount = 1;
 2887:     my %choices =  &Apache::lonlocal::texthash (
 2888:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
 2889:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
 2890:         coursecredits        => 'Credits can be specified for courses',
 2891:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
 2892:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
 2893:         postsubmit           => 'Disable submit button/keypress following student submission',
 2894:     );
 2895:     my %staticdefaults = (
 2896:                            anonsurvey_threshold => 10,
 2897:                            uploadquota          => 500,
 2898:                            postsubmit           => 60,
 2899:                          );
 2900:     if ($position eq 'top') {
 2901:         %defaultchecked = (
 2902:                             'uselcmath'       => 'on',
 2903:                             'usejsme'         => 'on',
 2904:                           );
 2905:         @toggles = ('uselcmath','usejsme');
 2906:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2907:                                                      \%choices,$itemcount);
 2908:     } else {
 2909:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2910:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
 2911:         my $currusecredits = 0;
 2912:         my $postsubmitclient = 1;
 2913:         my @types = ('official','unofficial','community','textbook');
 2914:         if (ref($settings) eq 'HASH') {
 2915:             $currdefresponder = $settings->{'anonsurvey_threshold'};
 2916:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
 2917:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
 2918:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
 2919:                 }
 2920:             }
 2921:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
 2922:                 foreach my $type (@types) {
 2923:                     next if ($type eq 'community');
 2924:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
 2925:                     if ($defcredits{$type} ne '') {
 2926:                         $currusecredits = 1;
 2927:                     }
 2928:                 }
 2929:             }
 2930:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
 2931:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
 2932:                     $postsubmitclient = 0;
 2933:                     foreach my $type (@types) {
 2934:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2935:                     }
 2936:                 } else {
 2937:                     foreach my $type (@types) {
 2938:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
 2939:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
 2940:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
 2941:                             } else {
 2942:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2943:                             }
 2944:                         } else {
 2945:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2946:                         }
 2947:                     }
 2948:                 }
 2949:             } else {
 2950:                 foreach my $type (@types) {
 2951:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2952:                 }
 2953:             }
 2954:         } else {
 2955:             foreach my $type (@types) {
 2956:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2957:             }
 2958:         }
 2959:         if (!$currdefresponder) {
 2960:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
 2961:         } elsif ($currdefresponder < 1) {
 2962:             $currdefresponder = 1;
 2963:         }
 2964:         foreach my $type (@types) {
 2965:             if ($curruploadquota{$type} eq '') {
 2966:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
 2967:             }
 2968:         }
 2969:         $datatable .=
 2970:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 2971:                 $choices{'anonsurvey_threshold'}.
 2972:                 '</span></td>'.
 2973:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
 2974:                 '<input type="text" name="anonsurvey_threshold"'.
 2975:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
 2976:                 '</td></tr>'."\n";
 2977:         $itemcount ++;
 2978:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2979:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 2980:                       $choices{'uploadquota'}.
 2981:                       '</span></td>'.
 2982:                       '<td align="right" class="LC_right_item">'.
 2983:                       '<table><tr>';
 2984:         foreach my $type (@types) {
 2985:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
 2986:                            '<input type="text" name="uploadquota_'.$type.'"'.
 2987:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
 2988:         }
 2989:         $datatable .= '</tr></table></td></tr>'."\n";
 2990:         $itemcount ++;
 2991:         my $onclick = "toggleDisplay(this.form,'credits');";
 2992:         my $display = 'none';
 2993:         if ($currusecredits) {
 2994:             $display = 'block';
 2995:         }
 2996:         my $additional = '<div id="credits" style="display: '.$display.'">'.
 2997:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
 2998:         foreach my $type (@types) {
 2999:             next if ($type eq 'community');
 3000:             $additional .= '<td align="center">'.&mt($type).'<br />'.
 3001:                            '<input type="text" name="'.$type.'_credits"'.
 3002:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
 3003:         }
 3004:         $additional .= '</tr></table></div>'."\n";
 3005:         %defaultchecked = ('coursecredits' => 'off');
 3006:         @toggles = ('coursecredits');
 3007:         my $current = {
 3008:                         'coursecredits' => $currusecredits,
 3009:                       };
 3010:         (my $table,$itemcount) =
 3011:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
 3012:                                \%choices,$itemcount,$onclick,$additional,'left');
 3013:         $datatable .= $table;
 3014:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
 3015:         my $display = 'none';
 3016:         if ($postsubmitclient) {
 3017:             $display = 'block';
 3018:         }
 3019:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
 3020:                       &mt('Number of seconds submit is disabled').'<br />'.
 3021:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
 3022:                       '<table><tr>';
 3023:         foreach my $type (@types) {
 3024:             $additional .= '<td align="center">'.&mt($type).'<br />'.
 3025:                            '<input type="text" name="'.$type.'_timeout" value="'.
 3026:                            $deftimeout{$type}.'" size="5" /></td>';
 3027:         }
 3028:         $additional .= '</tr></table></div>'."\n";
 3029:         %defaultchecked = ('postsubmit' => 'on');
 3030:         @toggles = ('postsubmit');
 3031:         my $current = {
 3032:                         'postsubmit' => $postsubmitclient,
 3033:                       };
 3034:         ($table,$itemcount) =
 3035:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
 3036:                                \%choices,$itemcount,$onclick,$additional,'left');
 3037:         $datatable .= $table;
 3038:     }
 3039:     $$rowtotal += $itemcount;
 3040:     return $datatable;
 3041: }
 3042: 
 3043: sub print_selfenrollment {
 3044:     my ($position,$dom,$settings,$rowtotal) = @_;
 3045:     my ($css_class,$datatable);
 3046:     my $itemcount = 1;
 3047:     my @types = ('official','unofficial','community','textbook');
 3048:     if (($position eq 'top') || ($position eq 'middle')) {
 3049:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
 3050:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
 3051:         my @rows;
 3052:         my $key;
 3053:         if ($position eq 'top') {
 3054:             $key = 'admin'; 
 3055:             if (ref($rowsref) eq 'ARRAY') {
 3056:                 @rows = @{$rowsref};
 3057:             }
 3058:         } elsif ($position eq 'middle') {
 3059:             $key = 'default';
 3060:             @rows = ('types','registered','approval','limit');
 3061:         }
 3062:         foreach my $row (@rows) {
 3063:             if (defined($titlesref->{$row})) {
 3064:                 $itemcount ++;
 3065:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3066:                 $datatable .= '<tr'.$css_class.'>'.
 3067:                               '<td>'.$titlesref->{$row}.'</td>'.
 3068:                               '<td class="LC_left_item">'.
 3069:                               '<table><tr>';
 3070:                 my (%current,%currentcap);
 3071:                 if (ref($settings) eq 'HASH') {
 3072:                     if (ref($settings->{$key}) eq 'HASH') {
 3073:                         foreach my $type (@types) {
 3074:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
 3075:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
 3076:                             }
 3077:                             if (($row eq 'limit') && ($key eq 'default')) {
 3078:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
 3079:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
 3080:                                 }
 3081:                             }
 3082:                         }
 3083:                     }
 3084:                 }
 3085:                 my %roles = (
 3086:                              '0' => &Apache::lonnet::plaintext('dc'),
 3087:                             ); 
 3088:             
 3089:                 foreach my $type (@types) {
 3090:                     unless (($row eq 'registered') && ($key eq 'default')) {
 3091:                         $datatable .= '<th>'.&mt($type).'</th>';
 3092:                     }
 3093:                 }
 3094:                 unless (($row eq 'registered') && ($key eq 'default')) {
 3095:                     $datatable .= '</tr><tr>';
 3096:                 }
 3097:                 foreach my $type (@types) {
 3098:                     if ($type eq 'community') {
 3099:                         $roles{'1'} = &mt('Community personnel');
 3100:                     } else {
 3101:                         $roles{'1'} = &mt('Course personnel');
 3102:                     }
 3103:                     $datatable .= '<td style="vertical-align: top">';
 3104:                     if ($position eq 'top') {
 3105:                         my %checked;
 3106:                         if ($current{$type} eq '0') {
 3107:                             $checked{'0'} = ' checked="checked"';
 3108:                         } else {
 3109:                             $checked{'1'} = ' checked="checked"';
 3110:                         }
 3111:                         foreach my $role ('1','0') {
 3112:                             $datatable .= '<span class="LC_nobreak"><label>'.
 3113:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
 3114:                                           'value="'.$role.'"'.$checked{$role}.' />'.
 3115:                                           $roles{$role}.'</label></span> ';
 3116:                         }
 3117:                     } else {
 3118:                         if ($row eq 'types') {
 3119:                             my %checked;
 3120:                             if ($current{$type} =~ /^(all|dom)$/) {
 3121:                                 $checked{$1} = ' checked="checked"';
 3122:                             } else {
 3123:                                 $checked{''} = ' checked="checked"';
 3124:                             }
 3125:                             foreach my $val ('','dom','all') {
 3126:                                 $datatable .= '<span class="LC_nobreak"><label>'.
 3127:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
 3128:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
 3129:                             }
 3130:                         } elsif ($row eq 'registered') {
 3131:                             my %checked;
 3132:                             if ($current{$type} eq '1') {
 3133:                                 $checked{'1'} = ' checked="checked"';
 3134:                             } else {
 3135:                                 $checked{'0'} = ' checked="checked"';
 3136:                             }
 3137:                             foreach my $val ('0','1') {
 3138:                                 $datatable .= '<span class="LC_nobreak"><label>'.
 3139:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
 3140:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
 3141:                             }
 3142:                         } elsif ($row eq 'approval') {
 3143:                             my %checked;
 3144:                             if ($current{$type} =~ /^([12])$/) {
 3145:                                 $checked{$1} = ' checked="checked"';
 3146:                             } else {
 3147:                                 $checked{'0'} = ' checked="checked"';
 3148:                             }
 3149:                             for my $val (0..2) {
 3150:                                 $datatable .= '<span class="LC_nobreak"><label>'.
 3151:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
 3152:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
 3153:                             }
 3154:                         } elsif ($row eq 'limit') {
 3155:                             my %checked;
 3156:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
 3157:                                 $checked{$1} = ' checked="checked"';
 3158:                             } else {
 3159:                                 $checked{'none'} = ' checked="checked"';
 3160:                             }
 3161:                             my $cap;
 3162:                             if ($currentcap{$type} =~ /^\d+$/) {
 3163:                                 $cap = $currentcap{$type};
 3164:                             }
 3165:                             foreach my $val ('none','allstudents','selfenrolled') {
 3166:                                 $datatable .= '<span class="LC_nobreak"><label>'.
 3167:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
 3168:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
 3169:                             }
 3170:                             $datatable .= '<br />'.
 3171:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
 3172:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
 3173:                                           '</span>'; 
 3174:                         }
 3175:                     }
 3176:                     $datatable .= '</td>';
 3177:                 }
 3178:                 $datatable .= '</tr>';
 3179:             }
 3180:             $datatable .= '</table></td></tr>';
 3181:         }
 3182:     } elsif ($position eq 'bottom') {
 3183:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
 3184:     }
 3185:     $$rowtotal += $itemcount;
 3186:     return $datatable;
 3187: }
 3188: 
 3189: sub print_validation_rows {
 3190:     my ($caller,$dom,$settings,$rowtotal) = @_;
 3191:     my ($itemsref,$namesref,$fieldsref);
 3192:     if ($caller eq 'selfenroll') { 
 3193:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
 3194:     } elsif ($caller eq 'requestcourses') {
 3195:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
 3196:     }
 3197:     my %currvalidation;
 3198:     if (ref($settings) eq 'HASH') {
 3199:         if (ref($settings->{'validation'}) eq 'HASH') {
 3200:             %currvalidation = %{$settings->{'validation'}};
 3201:         }
 3202:     }
 3203:     my $datatable;
 3204:     my $itemcount = 0;
 3205:     foreach my $item (@{$itemsref}) {
 3206:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 3207:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 3208:                       $namesref->{$item}.
 3209:                       '</span></td>'.
 3210:                       '<td class="LC_left_item">';
 3211:         if (($item eq 'url') || ($item eq 'button')) {
 3212:             $datatable .= '<span class="LC_nobreak">'.
 3213:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
 3214:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
 3215:         } elsif ($item eq 'fields') {
 3216:             my @currfields;
 3217:             if (ref($currvalidation{$item}) eq 'ARRAY') {
 3218:                 @currfields = @{$currvalidation{$item}};
 3219:             }
 3220:             foreach my $field (@{$fieldsref}) {
 3221:                 my $check = '';
 3222:                 if (grep(/^\Q$field\E$/,@currfields)) {
 3223:                     $check = ' checked="checked"';
 3224:                 }
 3225:                 $datatable .= '<span class="LC_nobreak"><label>'.
 3226:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
 3227:                               ' value="'.$field.'"'.$check.' />'.$field.
 3228:                               '</label></span> ';
 3229:             }
 3230:         } elsif ($item eq 'markup') {
 3231:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
 3232:                            $currvalidation{$item}.
 3233:                               '</textarea>';
 3234:         }
 3235:         $datatable .= '</td></tr>'."\n";
 3236:         if (ref($rowtotal)) {
 3237:             $itemcount ++;
 3238:         }
 3239:     }
 3240:     if ($caller eq 'requestcourses') {
 3241:         my %currhash;
 3242:         if (ref($settings) eq 'HASH') {
 3243:             if (ref($settings->{'validation'}) eq 'HASH') {
 3244:                 if ($settings->{'validation'}{'dc'} ne '') {
 3245:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
 3246:                 }
 3247:             }
 3248:         }
 3249:         my $numinrow = 2;
 3250:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
 3251:                                                        'validationdc',%currhash);
 3252:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 3253:         $datatable .= '</td></tr><tr'.$css_class.'><td>';
 3254:         if ($numdc > 1) {
 3255:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
 3256:         } else {
 3257:             $datatable .=  &mt('Course creation processed as: ');
 3258:         }
 3259:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
 3260:         $itemcount ++;
 3261:     }
 3262:     if (ref($rowtotal)) {
 3263:         $$rowtotal += $itemcount;
 3264:     }
 3265:     return $datatable;
 3266: }
 3267: 
 3268: sub print_usersessions {
 3269:     my ($position,$dom,$settings,$rowtotal) = @_;
 3270:     my ($css_class,$datatable,%checked,%choices);
 3271:     my (%by_ip,%by_location,@intdoms);
 3272:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 3273: 
 3274:     my @alldoms = &Apache::lonnet::all_domains();
 3275:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
 3276:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 3277:     my %altids = &id_for_thisdom(%servers);
 3278:     my $itemcount = 1;
 3279:     if ($position eq 'top') {
 3280:         if (keys(%serverhomes) > 1) {
 3281:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
 3282:             my $curroffloadnow;
 3283:             if (ref($settings) eq 'HASH') {
 3284:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
 3285:                     $curroffloadnow = $settings->{'offloadnow'};
 3286:                 }
 3287:             }
 3288:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
 3289:         } else {
 3290:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 3291:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
 3292:         }
 3293:     } else {
 3294:         if (keys(%by_location) == 0) {
 3295:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 3296:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
 3297:         } else {
 3298:             my %lt = &usersession_titles();
 3299:             my $numinrow = 5;
 3300:             my $prefix;
 3301:             my @types;
 3302:             if ($position eq 'bottom') {
 3303:                 $prefix = 'remote';
 3304:                 @types = ('version','excludedomain','includedomain');
 3305:             } else {
 3306:                 $prefix = 'hosted';
 3307:                 @types = ('excludedomain','includedomain');
 3308:             }
 3309:             my (%current,%checkedon,%checkedoff);
 3310:             my @lcversions = &Apache::lonnet::all_loncaparevs();
 3311:             my @locations = sort(keys(%by_location));
 3312:             foreach my $type (@types) {
 3313:                 $checkedon{$type} = '';
 3314:                 $checkedoff{$type} = ' checked="checked"';
 3315:             }
 3316:             if (ref($settings) eq 'HASH') {
 3317:                 if (ref($settings->{$prefix}) eq 'HASH') {
 3318:                     foreach my $key (keys(%{$settings->{$prefix}})) {
 3319:                         $current{$key} = $settings->{$prefix}{$key};
 3320:                         if ($key eq 'version') {
 3321:                             if ($current{$key} ne '') {
 3322:                                 $checkedon{$key} = ' checked="checked"';
 3323:                                 $checkedoff{$key} = '';
 3324:                             }
 3325:                         } elsif (ref($current{$key}) eq 'ARRAY') {
 3326:                             $checkedon{$key} = ' checked="checked"';
 3327:                             $checkedoff{$key} = '';
 3328:                         }
 3329:                     }
 3330:                 }
 3331:             }
 3332:             foreach my $type (@types) {
 3333:                 next if ($type ne 'version' && !@locations);
 3334:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 3335:                 $datatable .= '<tr'.$css_class.'>
 3336:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
 3337:                                <span class="LC_nobreak">&nbsp;
 3338:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
 3339:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
 3340:                 if ($type eq 'version') {
 3341:                     my $selector = '<select name="'.$prefix.'_version">';
 3342:                     foreach my $version (@lcversions) {
 3343:                         my $selected = '';
 3344:                         if ($current{'version'} eq $version) {
 3345:                             $selected = ' selected="selected"';
 3346:                         }
 3347:                         $selector .= ' <option value="'.$version.'"'.
 3348:                                      $selected.'>'.$version.'</option>';
 3349:                     }
 3350:                     $selector .= '</select> ';
 3351:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
 3352:                 } else {
 3353:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
 3354:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
 3355:                                  ' />'.('&nbsp;'x2).
 3356:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
 3357:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
 3358:                                  "\n".
 3359:                                  '</div><div><table>';
 3360:                     my $rem;
 3361:                     for (my $i=0; $i<@locations; $i++) {
 3362:                         my ($showloc,$value,$checkedtype);
 3363:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
 3364:                             my $ip = $by_location{$locations[$i]}->[0];
 3365:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
 3366:                                  $value = join(':',@{$by_ip{$ip}});
 3367:                                 $showloc = join(', ',@{$by_ip{$ip}});
 3368:                                 if (ref($current{$type}) eq 'ARRAY') {
 3369:                                     foreach my $loc (@{$by_ip{$ip}}) {  
 3370:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
 3371:                                             $checkedtype = ' checked="checked"';
 3372:                                             last;
 3373:                                         }
 3374:                                     }
 3375:                                 }
 3376:                             }
 3377:                         }
 3378:                         $rem = $i%($numinrow);
 3379:                         if ($rem == 0) {
 3380:                             if ($i > 0) {
 3381:                                 $datatable .= '</tr>';
 3382:                             }
 3383:                             $datatable .= '<tr>';
 3384:                         }
 3385:                         $datatable .= '<td class="LC_left_item">'.
 3386:                                       '<span class="LC_nobreak"><label>'.
 3387:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
 3388:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
 3389:                                       '</label></span></td>';
 3390:                     }
 3391:                     $rem = @locations%($numinrow);
 3392:                     my $colsleft = $numinrow - $rem;
 3393:                     if ($colsleft > 1 ) {
 3394:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3395:                                       '&nbsp;</td>';
 3396:                     } elsif ($colsleft == 1) {
 3397:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 3398:                     }
 3399:                     $datatable .= '</tr></table>';
 3400:                 }
 3401:                 $datatable .= '</td></tr>';
 3402:                 $itemcount ++;
 3403:             }
 3404:         }
 3405:     }
 3406:     $$rowtotal += $itemcount;
 3407:     return $datatable;
 3408: }
 3409: 
 3410: sub build_location_hashes {
 3411:     my ($intdoms,$by_ip,$by_location) = @_;
 3412:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
 3413:                   (ref($by_location) eq 'HASH')); 
 3414:     my %iphost = &Apache::lonnet::get_iphost();
 3415:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
 3416:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
 3417:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
 3418:         foreach my $id (@{$iphost{$primary_ip}}) {
 3419:             my $intdom = &Apache::lonnet::internet_dom($id);
 3420:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
 3421:                 push(@{$intdoms},$intdom);
 3422:             }
 3423:         }
 3424:     }
 3425:     foreach my $ip (keys(%iphost)) {
 3426:         if (ref($iphost{$ip}) eq 'ARRAY') {
 3427:             foreach my $id (@{$iphost{$ip}}) {
 3428:                 my $location = &Apache::lonnet::internet_dom($id);
 3429:                 if ($location) {
 3430:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
 3431:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
 3432:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
 3433:                             push(@{$by_ip->{$ip}},$location);
 3434:                         }
 3435:                     } else {
 3436:                         $by_ip->{$ip} = [$location];
 3437:                     }
 3438:                 }
 3439:             }
 3440:         }
 3441:     }
 3442:     foreach my $ip (sort(keys(%{$by_ip}))) {
 3443:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
 3444:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
 3445:             my $first = $by_ip->{$ip}->[0];
 3446:             if (ref($by_location->{$first}) eq 'ARRAY') {
 3447:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
 3448:                     push(@{$by_location->{$first}},$ip);
 3449:                 }
 3450:             } else {
 3451:                 $by_location->{$first} = [$ip];
 3452:             }
 3453:         }
 3454:     }
 3455:     return;
 3456: }
 3457: 
 3458: sub current_offloads_to {
 3459:     my ($dom,$settings,$servers) = @_;
 3460:     my (%spareid,%otherdomconfigs);
 3461:     if (ref($servers) eq 'HASH') {
 3462:         foreach my $lonhost (sort(keys(%{$servers}))) {
 3463:             my $gotspares;
 3464:             if (ref($settings) eq 'HASH') {
 3465:                 if (ref($settings->{'spares'}) eq 'HASH') {
 3466:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
 3467:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
 3468:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
 3469:                         $gotspares = 1;
 3470:                     }
 3471:                 }
 3472:             }
 3473:             unless ($gotspares) {
 3474:                 my $gotspares;
 3475:                 my $serverhomeID =
 3476:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
 3477:                 my $serverhomedom =
 3478:                     &Apache::lonnet::host_domain($serverhomeID);
 3479:                 if ($serverhomedom ne $dom) {
 3480:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
 3481:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 3482:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 3483:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 3484:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 3485:                                 $gotspares = 1;
 3486:                             }
 3487:                         }
 3488:                     } else {
 3489:                         $otherdomconfigs{$serverhomedom} =
 3490:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
 3491:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
 3492:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 3493:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 3494:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
 3495:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 3496:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 3497:                                         $gotspares = 1;
 3498:                                     }
 3499:                                 }
 3500:                             }
 3501:                         }
 3502:                     }
 3503:                 }
 3504:             }
 3505:             unless ($gotspares) {
 3506:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
 3507:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 3508:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 3509:                } else {
 3510:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
 3511:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
 3512:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
 3513:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 3514:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 3515:                     } else {
 3516:                         my %what = (
 3517:                              spareid => 1,
 3518:                         );
 3519:                         my ($result,$returnhash) = 
 3520:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
 3521:                         if ($result eq 'ok') { 
 3522:                             if (ref($returnhash) eq 'HASH') {
 3523:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
 3524:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
 3525:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
 3526:                                 }
 3527:                             }
 3528:                         }
 3529:                     }
 3530:                 }
 3531:             }
 3532:         }
 3533:     }
 3534:     return %spareid;
 3535: }
 3536: 
 3537: sub spares_row {
 3538:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
 3539:     my $css_class;
 3540:     my $numinrow = 4;
 3541:     my $itemcount = 1;
 3542:     my $datatable;
 3543:     my %typetitles = &sparestype_titles();
 3544:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
 3545:         foreach my $server (sort(keys(%{$servers}))) {
 3546:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
 3547:             my ($othercontrol,$serverdom);
 3548:             if ($serverhome ne $server) {
 3549:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
 3550:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 3551:             } else {
 3552:                 $serverdom = &Apache::lonnet::host_domain($server);
 3553:                 if ($serverdom ne $dom) {
 3554:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 3555:                 }
 3556:             }
 3557:             next unless (ref($spareid->{$server}) eq 'HASH');
 3558:             my $checkednow;
 3559:             if (ref($curroffloadnow) eq 'HASH') {
 3560:                 if ($curroffloadnow->{$server}) {
 3561:                     $checkednow = ' checked="checked"';
 3562:                 }
 3563:             }
 3564:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 3565:             $datatable .= '<tr'.$css_class.'>
 3566:                            <td rowspan="2">
 3567:                             <span class="LC_nobreak">'.
 3568:                           &mt('[_1] when busy, offloads to:'
 3569:                               ,'<b>'.$server.'</b>').'</span><br />'.
 3570:                           '<span class="LC_nobreak">'."\n".
 3571:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
 3572:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
 3573:                           "\n";
 3574:             my (%current,%canselect);
 3575:             my @choices = 
 3576:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
 3577:             foreach my $type ('primary','default') {
 3578:                 if (ref($spareid->{$server}) eq 'HASH') {
 3579:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
 3580:                         my @spares = @{$spareid->{$server}{$type}};
 3581:                         if (@spares > 0) {
 3582:                             if ($othercontrol) {
 3583:                                 $current{$type} = join(', ',@spares);
 3584:                             } else {
 3585:                                 $current{$type} .= '<table>';
 3586:                                 my $numspares = scalar(@spares);
 3587:                                 for (my $i=0;  $i<@spares; $i++) {
 3588:                                     my $rem = $i%($numinrow);
 3589:                                     if ($rem == 0) {
 3590:                                         if ($i > 0) {
 3591:                                             $current{$type} .= '</tr>';
 3592:                                         }
 3593:                                         $current{$type} .= '<tr>';
 3594:                                     }
 3595:                                     $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;'.
 3596:                                                        $spareid->{$server}{$type}[$i].
 3597:                                                        '</label></td>'."\n";
 3598:                                 }
 3599:                                 my $rem = @spares%($numinrow);
 3600:                                 my $colsleft = $numinrow - $rem;
 3601:                                 if ($colsleft > 1 ) {
 3602:                                     $current{$type} .= '<td colspan="'.$colsleft.
 3603:                                                        '" class="LC_left_item">'.
 3604:                                                        '&nbsp;</td>';
 3605:                                 } elsif ($colsleft == 1) {
 3606:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
 3607:                                 }
 3608:                                 $current{$type} .= '</tr></table>';
 3609:                             }
 3610:                         }
 3611:                     }
 3612:                     if ($current{$type} eq '') {
 3613:                         $current{$type} = &mt('None specified');
 3614:                     }
 3615:                     if ($othercontrol) {
 3616:                         if ($type eq 'primary') {
 3617:                             $canselect{$type} = $othercontrol;
 3618:                         }
 3619:                     } else {
 3620:                         $canselect{$type} = 
 3621:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
 3622:                             '<select name="newspare_'.$type.'_'.$server.'" '.
 3623:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
 3624:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
 3625:                         if (@choices > 0) {
 3626:                             foreach my $lonhost (@choices) {
 3627:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
 3628:                             }
 3629:                         }
 3630:                         $canselect{$type} .= '</select>'."\n";
 3631:                     }
 3632:                 } else {
 3633:                     $current{$type} = &mt('Could not be determined');
 3634:                     if ($type eq 'primary') {
 3635:                         $canselect{$type} =  $othercontrol;
 3636:                     }
 3637:                 }
 3638:                 if ($type eq 'default') {
 3639:                     $datatable .= '<tr'.$css_class.'>';
 3640:                 }
 3641:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
 3642:                               '<td>'.$current{$type}.'</td>'."\n".
 3643:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
 3644:             }
 3645:             $itemcount ++;
 3646:         }
 3647:     }
 3648:     $$rowtotal += $itemcount;
 3649:     return $datatable;
 3650: }
 3651: 
 3652: sub possible_newspares {
 3653:     my ($server,$currspares,$serverhomes,$altids) = @_;
 3654:     my $serverhostname = &Apache::lonnet::hostname($server);
 3655:     my %excluded;
 3656:     if ($serverhostname ne '') {
 3657:         %excluded = (
 3658:                        $serverhostname => 1,
 3659:                     );
 3660:     }
 3661:     if (ref($currspares) eq 'HASH') {
 3662:         foreach my $type (keys(%{$currspares})) {
 3663:             if (ref($currspares->{$type}) eq 'ARRAY') {
 3664:                 if (@{$currspares->{$type}} > 0) {
 3665:                     foreach my $curr (@{$currspares->{$type}}) {
 3666:                         my $hostname = &Apache::lonnet::hostname($curr);
 3667:                         $excluded{$hostname} = 1;
 3668:                     }
 3669:                 }
 3670:             }
 3671:         }
 3672:     }
 3673:     my @choices;
 3674:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
 3675:         if (keys(%{$serverhomes}) > 1) {
 3676:             foreach my $name (sort(keys(%{$serverhomes}))) {
 3677:                 unless ($excluded{$name}) {
 3678:                     if (exists($altids->{$serverhomes->{$name}})) {
 3679:                         push(@choices,$altids->{$serverhomes->{$name}});
 3680:                     } else {
 3681:                         push(@choices,$serverhomes->{$name});
 3682:                     }
 3683:                 }
 3684:             }
 3685:         }
 3686:     }
 3687:     return sort(@choices);
 3688: }
 3689: 
 3690: sub print_loadbalancing {
 3691:     my ($dom,$settings,$rowtotal) = @_;
 3692:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
 3693:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
 3694:     my $numinrow = 1;
 3695:     my $datatable;
 3696:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 3697:     my (%currbalancer,%currtargets,%currrules,%existing);
 3698:     if (ref($settings) eq 'HASH') {
 3699:         %existing = %{$settings};
 3700:     }
 3701:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
 3702:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
 3703:                                   \%currtargets,\%currrules);
 3704:     } else {
 3705:         return;
 3706:     }
 3707:     my ($othertitle,$usertypes,$types) =
 3708:         &Apache::loncommon::sorted_inst_types($dom);
 3709:     my $rownum = 8;
 3710:     if (ref($types) eq 'ARRAY') {
 3711:         $rownum += scalar(@{$types});
 3712:     }
 3713:     my @css_class = ('LC_odd_row','LC_even_row');
 3714:     my $balnum = 0;
 3715:     my $islast;
 3716:     my (@toshow,$disabledtext);
 3717:     if (keys(%currbalancer) > 0) {
 3718:         @toshow = sort(keys(%currbalancer));
 3719:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
 3720:             push(@toshow,'');
 3721:         }
 3722:     } else {
 3723:         @toshow = ('');
 3724:         $disabledtext = &mt('No existing load balancer');
 3725:     }
 3726:     foreach my $lonhost (@toshow) {
 3727:         if ($balnum == scalar(@toshow)-1) {
 3728:             $islast = 1;
 3729:         } else {
 3730:             $islast = 0;
 3731:         }
 3732:         my $cssidx = $balnum%2;
 3733:         my $targets_div_style = 'display: none';
 3734:         my $disabled_div_style = 'display: block';
 3735:         my $homedom_div_style = 'display: none';
 3736:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
 3737:                       '<td rowspan="'.$rownum.'" valign="top">'.
 3738:                       '<p>';
 3739:         if ($lonhost eq '') {
 3740:             $datatable .= '<span class="LC_nobreak">';
 3741:             if (keys(%currbalancer) > 0) {
 3742:                 $datatable .= &mt('Add balancer:');
 3743:             } else {
 3744:                 $datatable .= &mt('Enable balancer:');
 3745:             }
 3746:             $datatable .= '&nbsp;'.
 3747:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
 3748:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
 3749:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
 3750:                           '<option value="" selected="selected">'.&mt('None').
 3751:                           '</option>'."\n";
 3752:             foreach my $server (sort(keys(%servers))) {
 3753:                 next if ($currbalancer{$server});
 3754:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
 3755:             }
 3756:             $datatable .=
 3757:                 '</select>'."\n".
 3758:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
 3759:         } else {
 3760:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
 3761:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
 3762:                            &mt('Stop balancing').'</label>'.
 3763:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
 3764:             $targets_div_style = 'display: block';
 3765:             $disabled_div_style = 'display: none';
 3766:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
 3767:                 $homedom_div_style = 'display: block';
 3768:             }
 3769:         }
 3770:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
 3771:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
 3772:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
 3773:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
 3774:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
 3775:         my @sparestypes = ('primary','default');
 3776:         my %typetitles = &sparestype_titles();
 3777:         foreach my $sparetype (@sparestypes) {
 3778:             my $targettable;
 3779:             for (my $i=0; $i<$numspares; $i++) {
 3780:                 my $checked;
 3781:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
 3782:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
 3783:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
 3784:                             $checked = ' checked="checked"';
 3785:                         }
 3786:                     }
 3787:                 }
 3788:                 my ($chkboxval,$disabled);
 3789:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
 3790:                     $chkboxval = $spares[$i];
 3791:                 }
 3792:                 if (exists($currbalancer{$spares[$i]})) {
 3793:                     $disabled = ' disabled="disabled"';
 3794:                 }
 3795:                 $targettable .=
 3796:                     '<td><span class="LC_nobreak"><label>'.
 3797:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
 3798:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
 3799:                     '</span></label></span></td>';
 3800:                 my $rem = $i%($numinrow);
 3801:                 if ($rem == 0) {
 3802:                     if (($i > 0) && ($i < $numspares-1)) {
 3803:                         $targettable .= '</tr>';
 3804:                     }
 3805:                     if ($i < $numspares-1) {
 3806:                         $targettable .= '<tr>';
 3807:                     }
 3808:                 }
 3809:             }
 3810:             if ($targettable ne '') {
 3811:                 my $rem = $numspares%($numinrow);
 3812:                 my $colsleft = $numinrow - $rem;
 3813:                 if ($colsleft > 1 ) {
 3814:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3815:                                     '&nbsp;</td>';
 3816:                 } elsif ($colsleft == 1) {
 3817:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
 3818:                 }
 3819:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
 3820:                                '<table><tr>'.$targettable.'</tr></table><br />';
 3821:             }
 3822:         }
 3823:         $datatable .= '</div></td></tr>'.
 3824:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
 3825:                                            $othertitle,$usertypes,$types,\%servers,
 3826:                                            \%currbalancer,$lonhost,
 3827:                                            $targets_div_style,$homedom_div_style,
 3828:                                            $css_class[$cssidx],$balnum,$islast);
 3829:         $$rowtotal += $rownum;
 3830:         $balnum ++;
 3831:     }
 3832:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
 3833:     return $datatable;
 3834: }
 3835: 
 3836: sub get_loadbalancers_config {
 3837:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
 3838:     return unless ((ref($servers) eq 'HASH') &&
 3839:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
 3840:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
 3841:     if (keys(%{$existing}) > 0) {
 3842:         my $oldlonhost;
 3843:         foreach my $key (sort(keys(%{$existing}))) {
 3844:             if ($key eq 'lonhost') {
 3845:                 $oldlonhost = $existing->{'lonhost'};
 3846:                 $currbalancer->{$oldlonhost} = 1;
 3847:             } elsif ($key eq 'targets') {
 3848:                 if ($oldlonhost) {
 3849:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
 3850:                 }
 3851:             } elsif ($key eq 'rules') {
 3852:                 if ($oldlonhost) {
 3853:                     $currrules->{$oldlonhost} = $existing->{'rules'};
 3854:                 }
 3855:             } elsif (ref($existing->{$key}) eq 'HASH') {
 3856:                 $currbalancer->{$key} = 1;
 3857:                 $currtargets->{$key} = $existing->{$key}{'targets'};
 3858:                 $currrules->{$key} = $existing->{$key}{'rules'};
 3859:             }
 3860:         }
 3861:     } else {
 3862:         my ($balancerref,$targetsref) =
 3863:                 &Apache::lonnet::get_lonbalancer_config($servers);
 3864:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
 3865:             foreach my $server (sort(keys(%{$balancerref}))) {
 3866:                 $currbalancer->{$server} = 1;
 3867:                 $currtargets->{$server} = $targetsref->{$server};
 3868:             }
 3869:         }
 3870:     }
 3871:     return;
 3872: }
 3873: 
 3874: sub loadbalancing_rules {
 3875:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
 3876:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
 3877:         $css_class,$balnum,$islast) = @_;
 3878:     my $output;
 3879:     my $num = 0;
 3880:     my ($alltypes,$othertypes,$titles) =
 3881:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
 3882:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
 3883:         foreach my $type (@{$alltypes}) {
 3884:             $num ++;
 3885:             my $current;
 3886:             if (ref($currrules) eq 'HASH') {
 3887:                 $current = $currrules->{$type};
 3888:             }
 3889:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3890:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
 3891:                     $current = '';
 3892:                 }
 3893:             }
 3894:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
 3895:                                              $servers,$currbalancer,$lonhost,$dom,
 3896:                                              $targets_div_style,$homedom_div_style,
 3897:                                              $css_class,$balnum,$num,$islast);
 3898:         }
 3899:     }
 3900:     return $output;
 3901: }
 3902: 
 3903: sub loadbalancing_titles {
 3904:     my ($dom,$intdom,$usertypes,$types) = @_;
 3905:     my %othertypes = (
 3906:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
 3907:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
 3908:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
 3909:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
 3910:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
 3911:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
 3912:                      );
 3913:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
 3914:     if (ref($types) eq 'ARRAY') {
 3915:         unshift(@alltypes,@{$types},'default');
 3916:     }
 3917:     my %titles;
 3918:     foreach my $type (@alltypes) {
 3919:         if ($type =~ /^_LC_/) {
 3920:             $titles{$type} = $othertypes{$type};
 3921:         } elsif ($type eq 'default') {
 3922:             $titles{$type} = &mt('All users from [_1]',$dom);
 3923:             if (ref($types) eq 'ARRAY') {
 3924:                 if (@{$types} > 0) {
 3925:                     $titles{$type} = &mt('Other users from [_1]',$dom);
 3926:                 }
 3927:             }
 3928:         } elsif (ref($usertypes) eq 'HASH') {
 3929:             $titles{$type} = $usertypes->{$type};
 3930:         }
 3931:     }
 3932:     return (\@alltypes,\%othertypes,\%titles);
 3933: }
 3934: 
 3935: sub loadbalance_rule_row {
 3936:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
 3937:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
 3938:     my @rulenames;
 3939:     my %ruletitles = &offloadtype_text();
 3940:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
 3941:         @rulenames = ('balancer','offloadedto','specific');
 3942:     } else {
 3943:         @rulenames = ('default','homeserver');
 3944:         if ($type eq '_LC_external') {
 3945:             push(@rulenames,'externalbalancer');
 3946:         } else {
 3947:             push(@rulenames,'specific');
 3948:         }
 3949:         push(@rulenames,'none');
 3950:     }
 3951:     my $style = $targets_div_style;
 3952:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3953:         $style = $homedom_div_style;
 3954:     }
 3955:     my $space;
 3956:     if ($islast && $num == 1) {
 3957:         $space = '<div display="inline-block">&nbsp;</div>';
 3958:     }
 3959:     my $output =
 3960:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
 3961:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
 3962:         '<td valaign="top">'.$space.
 3963:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
 3964:     for (my $i=0; $i<@rulenames; $i++) {
 3965:         my $rule = $rulenames[$i];
 3966:         my ($checked,$extra);
 3967:         if ($rulenames[$i] eq 'default') {
 3968:             $rule = '';
 3969:         }
 3970:         if ($rulenames[$i] eq 'specific') {
 3971:             if (ref($servers) eq 'HASH') {
 3972:                 my $default;
 3973:                 if (($current ne '') && (exists($servers->{$current}))) {
 3974:                     $checked = ' checked="checked"';
 3975:                 }
 3976:                 unless ($checked) {
 3977:                     $default = ' selected="selected"';
 3978:                 }
 3979:                 $extra =
 3980:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
 3981:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
 3982:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
 3983:                     '<option value=""'.$default.'></option>'."\n";
 3984:                 foreach my $server (sort(keys(%{$servers}))) {
 3985:                     if (ref($currbalancer) eq 'HASH') {
 3986:                         next if (exists($currbalancer->{$server}));
 3987:                     }
 3988:                     my $selected;
 3989:                     if ($server eq $current) {
 3990:                         $selected = ' selected="selected"';
 3991:                     }
 3992:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
 3993:                 }
 3994:                 $extra .= '</select>';
 3995:             }
 3996:         } elsif ($rule eq $current) {
 3997:             $checked = ' checked="checked"';
 3998:         }
 3999:         $output .= '<span class="LC_nobreak"><label>'.
 4000:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
 4001:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
 4002:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
 4003:                    ')"'.$checked.' />&nbsp;';
 4004:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
 4005:             $output .= $ruletitles{'particular'};
 4006:         } else {
 4007:             $output .= $ruletitles{$rulenames[$i]};
 4008:         }
 4009:         $output .= '</label>'.$extra.'</span><br />'."\n";
 4010:     }
 4011:     $output .= '</div></td></tr>'."\n";
 4012:     return $output;
 4013: }
 4014: 
 4015: sub offloadtype_text {
 4016:     my %ruletitles = &Apache::lonlocal::texthash (
 4017:            'default'          => 'Offloads to default destinations',
 4018:            'homeserver'       => "Offloads to user's home server",
 4019:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
 4020:            'specific'         => 'Offloads to specific server',
 4021:            'none'             => 'No offload',
 4022:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
 4023:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
 4024:            'particular'       => 'Session hosted (after re-auth) on server:',
 4025:     );
 4026:     return %ruletitles;
 4027: }
 4028: 
 4029: sub sparestype_titles {
 4030:     my %typestitles = &Apache::lonlocal::texthash (
 4031:                           'primary' => 'primary',
 4032:                           'default' => 'default',
 4033:                       );
 4034:     return %typestitles;
 4035: }
 4036: 
 4037: sub contact_titles {
 4038:     my %titles = &Apache::lonlocal::texthash (
 4039:                    'supportemail' => 'Support E-mail address',
 4040:                    'adminemail'   => 'Default Server Admin E-mail address',
 4041:                    'errormail'    => 'Error reports to be e-mailed to',
 4042:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 4043:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
 4044:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
 4045:                    'requestsmail' => 'E-mail from course requests requiring approval',
 4046:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
 4047:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
 4048:                  );
 4049:     my %short_titles = &Apache::lonlocal::texthash (
 4050:                            adminemail   => 'Admin E-mail address',
 4051:                            supportemail => 'Support E-mail',
 4052:                        );   
 4053:     return (\%titles,\%short_titles);
 4054: }
 4055: 
 4056: sub tool_titles {
 4057:     my %titles = &Apache::lonlocal::texthash (
 4058:                      aboutme    => 'Personal web page',
 4059:                      blog       => 'Blog',
 4060:                      webdav     => 'WebDAV',
 4061:                      portfolio  => 'Portfolio',
 4062:                      official   => 'Official courses (with institutional codes)',
 4063:                      unofficial => 'Unofficial courses',
 4064:                      community  => 'Communities',
 4065:                      textbook   => 'Textbook courses',
 4066:                  );
 4067:     return %titles;
 4068: }
 4069: 
 4070: sub courserequest_titles {
 4071:     my %titles = &Apache::lonlocal::texthash (
 4072:                                    official   => 'Official',
 4073:                                    unofficial => 'Unofficial',
 4074:                                    community  => 'Communities',
 4075:                                    textbook   => 'Textbook',
 4076:                                    norequest  => 'Not allowed',
 4077:                                    approval   => 'Approval by Dom. Coord.',
 4078:                                    validate   => 'With validation',
 4079:                                    autolimit  => 'Numerical limit',
 4080:                                    unlimited  => '(blank for unlimited)',
 4081:                  );
 4082:     return %titles;
 4083: }
 4084: 
 4085: sub authorrequest_titles {
 4086:     my %titles = &Apache::lonlocal::texthash (
 4087:                                    norequest  => 'Not allowed',
 4088:                                    approval   => 'Approval by Dom. Coord.',
 4089:                                    automatic  => 'Automatic approval',
 4090:                  );
 4091:     return %titles;
 4092: }
 4093: 
 4094: sub courserequest_conditions {
 4095:     my %conditions = &Apache::lonlocal::texthash (
 4096:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
 4097:        validate   => '(Processing of request subject to institutional validation).',
 4098:                  );
 4099:     return %conditions;
 4100: }
 4101: 
 4102: 
 4103: sub print_usercreation {
 4104:     my ($position,$dom,$settings,$rowtotal) = @_;
 4105:     my $numinrow = 4;
 4106:     my $datatable;
 4107:     if ($position eq 'top') {
 4108:         $$rowtotal ++;
 4109:         my $rowcount = 0;
 4110:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 4111:         if (ref($rules) eq 'HASH') {
 4112:             if (keys(%{$rules}) > 0) {
 4113:                 $datatable .= &user_formats_row('username',$settings,$rules,
 4114:                                                 $ruleorder,$numinrow,$rowcount);
 4115:                 $$rowtotal ++;
 4116:                 $rowcount ++;
 4117:             }
 4118:         }
 4119:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 4120:         if (ref($idrules) eq 'HASH') {
 4121:             if (keys(%{$idrules}) > 0) {
 4122:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 4123:                                                 $idruleorder,$numinrow,$rowcount);
 4124:                 $$rowtotal ++;
 4125:                 $rowcount ++;
 4126:             }
 4127:         }
 4128:         if ($rowcount == 0) {
 4129:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 4130:             $$rowtotal ++;
 4131:             $rowcount ++;
 4132:         }
 4133:     } elsif ($position eq 'middle') {
 4134:         my @creators = ('author','course','requestcrs');
 4135:         my ($rules,$ruleorder) =
 4136:             &Apache::lonnet::inst_userrules($dom,'username');
 4137:         my %lt = &usercreation_types();
 4138:         my %checked;
 4139:         if (ref($settings) eq 'HASH') {
 4140:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 4141:                 foreach my $item (@creators) {
 4142:                     $checked{$item} = $settings->{'cancreate'}{$item};
 4143:                 }
 4144:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 4145:                 foreach my $item (@creators) {
 4146:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 4147:                         $checked{$item} = 'none';
 4148:                     }
 4149:                 }
 4150:             }
 4151:         }
 4152:         my $rownum = 0;
 4153:         foreach my $item (@creators) {
 4154:             $rownum ++;
 4155:             if ($checked{$item} eq '') {
 4156:                 $checked{$item} = 'any';
 4157:             }
 4158:             my $css_class;
 4159:             if ($rownum%2) {
 4160:                 $css_class = '';
 4161:             } else {
 4162:                 $css_class = ' class="LC_odd_row" ';
 4163:             }
 4164:             $datatable .= '<tr'.$css_class.'>'.
 4165:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 4166:                          '</span></td><td align="right">';
 4167:             my @options = ('any');
 4168:             if (ref($rules) eq 'HASH') {
 4169:                 if (keys(%{$rules}) > 0) {
 4170:                     push(@options,('official','unofficial'));
 4171:                 }
 4172:             }
 4173:             push(@options,'none');
 4174:             foreach my $option (@options) {
 4175:                 my $type = 'radio';
 4176:                 my $check = ' ';
 4177:                 if ($checked{$item} eq $option) {
 4178:                     $check = ' checked="checked" ';
 4179:                 } 
 4180:                 $datatable .= '<span class="LC_nobreak"><label>'.
 4181:                               '<input type="'.$type.'" name="can_createuser_'.
 4182:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 4183:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 4184:             }
 4185:             $datatable .= '</td></tr>';
 4186:         }
 4187:     } else {
 4188:         my @contexts = ('author','course','domain');
 4189:         my @authtypes = ('int','krb4','krb5','loc');
 4190:         my %checked;
 4191:         if (ref($settings) eq 'HASH') {
 4192:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 4193:                 foreach my $item (@contexts) {
 4194:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 4195:                         foreach my $auth (@authtypes) {
 4196:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 4197:                                 $checked{$item}{$auth} = ' checked="checked" ';
 4198:                             }
 4199:                         }
 4200:                     }
 4201:                 }
 4202:             }
 4203:         } else {
 4204:             foreach my $item (@contexts) {
 4205:                 foreach my $auth (@authtypes) {
 4206:                     $checked{$item}{$auth} = ' checked="checked" ';
 4207:                 }
 4208:             }
 4209:         }
 4210:         my %title = &context_names();
 4211:         my %authname = &authtype_names();
 4212:         my $rownum = 0;
 4213:         my $css_class; 
 4214:         foreach my $item (@contexts) {
 4215:             if ($rownum%2) {
 4216:                 $css_class = '';
 4217:             } else {
 4218:                 $css_class = ' class="LC_odd_row" ';
 4219:             }
 4220:             $datatable .=   '<tr'.$css_class.'>'.
 4221:                             '<td>'.$title{$item}.
 4222:                             '</td><td class="LC_left_item">'.
 4223:                             '<span class="LC_nobreak">';
 4224:             foreach my $auth (@authtypes) {
 4225:                 $datatable .= '<label>'. 
 4226:                               '<input type="checkbox" name="'.$item.'_auth" '.
 4227:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 4228:                               $authname{$auth}.'</label>&nbsp;';
 4229:             }
 4230:             $datatable .= '</span></td></tr>';
 4231:             $rownum ++;
 4232:         }
 4233:         $$rowtotal += $rownum;
 4234:     }
 4235:     return $datatable;
 4236: }
 4237: 
 4238: sub print_selfcreation {
 4239:     my ($position,$dom,$settings,$rowtotal) = @_;
 4240:     my (@selfcreate,$createsettings,$processing,$datatable);
 4241:     if (ref($settings) eq 'HASH') {
 4242:         if (ref($settings->{'cancreate'}) eq 'HASH') {
 4243:             $createsettings = $settings->{'cancreate'};
 4244:             if (ref($createsettings) eq 'HASH') {
 4245:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
 4246:                     @selfcreate = @{$createsettings->{'selfcreate'}};
 4247:                 } elsif ($createsettings->{'selfcreate'} ne '') {
 4248:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 4249:                         @selfcreate = ('email','login','sso');
 4250:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
 4251:                         @selfcreate = ($createsettings->{'selfcreate'});
 4252:                     }
 4253:                 }
 4254:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
 4255:                     $processing = $createsettings->{'selfcreateprocessing'};
 4256:                 }
 4257:             }
 4258:         }
 4259:     }
 4260:     my %radiohash;
 4261:     my $numinrow = 4;
 4262:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
 4263:     if ($position eq 'top') {
 4264:         my %choices = &Apache::lonlocal::texthash (
 4265:                                                       cancreate_login      => 'Institutional Login',
 4266:                                                       cancreate_sso        => 'Institutional Single Sign On',
 4267:                                                   );
 4268:         my @toggles = sort(keys(%choices));
 4269:         my %defaultchecked = (
 4270:                                'cancreate_login' => 'off',
 4271:                                'cancreate_sso'   => 'off',
 4272:                              );
 4273:         my ($onclick,$itemcount);
 4274:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
 4275:                                                      \%choices,$itemcount,$onclick);
 4276:         $$rowtotal += $itemcount;
 4277:         
 4278:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4279: 
 4280:         if (ref($usertypes) eq 'HASH') {
 4281:             if (keys(%{$usertypes}) > 0) {
 4282:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
 4283:                                              $dom,$numinrow,$othertitle,
 4284:                                              'statustocreate',$$rowtotal);
 4285:                 $$rowtotal ++;
 4286:             }
 4287:         }
 4288:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
 4289:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 4290:         $fieldtitles{'inststatus'} = &mt('Institutional status');
 4291:         my $rem;
 4292:         my $numperrow = 2;
 4293:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
 4294:         $datatable .= '<tr'.$css_class.'>'.
 4295:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
 4296:                      '<td class="LC_left_item">'."\n".
 4297:                      '<table><tr><td>'."\n";
 4298:         for (my $i=0; $i<@fields; $i++) {
 4299:             $rem = $i%($numperrow);
 4300:             if ($rem == 0) {
 4301:                 if ($i > 0) {
 4302:                     $datatable .= '</tr>';
 4303:                 }
 4304:                 $datatable .= '<tr>';
 4305:             }
 4306:             my $currval;
 4307:             if (ref($createsettings) eq 'HASH') {
 4308:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
 4309:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
 4310:                 }
 4311:             }
 4312:             $datatable .= '<td class="LC_left_item">'.
 4313:                           '<span class="LC_nobreak">'.
 4314:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
 4315:                           'value="'.$currval.'" size="10" />&nbsp;'.
 4316:                           $fieldtitles{$fields[$i]}.'</span></td>';
 4317:         }
 4318:         my $colsleft = $numperrow - $rem;
 4319:         if ($colsleft > 1 ) {
 4320:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 4321:                          '&nbsp;</td>';
 4322:         } elsif ($colsleft == 1) {
 4323:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 4324:         }
 4325:         $datatable .= '</tr></table></td></tr>';
 4326:         $$rowtotal ++;
 4327:     } elsif ($position eq 'middle') {
 4328:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
 4329:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4330:         $usertypes->{'default'} = $othertitle;
 4331:         if (ref($types) eq 'ARRAY') {
 4332:             push(@{$types},'default');
 4333:             $usertypes->{'default'} = $othertitle;
 4334:             foreach my $status (@{$types}) {
 4335:                 $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
 4336:                                                        $numinrow,$$rowtotal,$usertypes);
 4337:                 $$rowtotal ++;
 4338:             }
 4339:         }
 4340:     } else {
 4341:         my %choices = &Apache::lonlocal::texthash (
 4342:                                                       cancreate_email => 'E-mail address as username',
 4343:                                                   );
 4344:         my @toggles = sort(keys(%choices));
 4345:         my %defaultchecked = (
 4346:                                'cancreate_email' => 'off',
 4347:                              );
 4348:         my $itemcount = 0;
 4349:         my $display = 'none';
 4350:         if (grep(/^\Qemail\E$/,@selfcreate)) {
 4351:             $display = 'block';
 4352:         }
 4353:         my $onclick = "toggleDisplay(this.form,'emailoptions');";
 4354:         my $additional = '<div id="emailoptions" style="display: '.$display.'">';
 4355:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 4356:         my $usertypes = {};
 4357:         my $order = [];
 4358:         if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
 4359:             $usertypes = $domdefaults{'inststatustypes'};
 4360:             $order = $domdefaults{'inststatusguest'};
 4361:         }
 4362:         if (ref($order) eq 'ARRAY') {
 4363:             push(@{$order},'default');
 4364:             if (@{$order} > 1) {
 4365:                 $usertypes->{'default'} = &mt('Other users');
 4366:                 $additional .= '<table><tr>';
 4367:                 foreach my $status (@{$order}) {
 4368:                     $additional .= '<th>'.$usertypes->{$status}.'</th>';
 4369:                 }
 4370:                 $additional .= '</tr><tr>';
 4371:                 foreach my $status (@{$order}) {
 4372:                     $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
 4373:                 }
 4374:                 $additional .= '</tr></table>';
 4375:             } else {
 4376:                 $usertypes->{'default'} = &mt('All users');
 4377:                 $additional .= &email_as_username($rowtotal,$processing);
 4378:             }
 4379:         }
 4380:         $additional .= '</div>'."\n";
 4381: 
 4382:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
 4383:                                                      \%choices,$$rowtotal,$onclick,$additional);
 4384:         $$rowtotal ++;
 4385:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
 4386:         $$rowtotal ++;
 4387:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
 4388:         $numinrow = 1;
 4389:         if (ref($order) eq 'ARRAY') {
 4390:             foreach my $status (@{$order}) {
 4391:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
 4392:                                                        $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
 4393:                 $$rowtotal ++;
 4394:             }
 4395:         }
 4396:         my ($emailrules,$emailruleorder) =
 4397:             &Apache::lonnet::inst_userrules($dom,'email');
 4398:         if (ref($emailrules) eq 'HASH') {
 4399:             if (keys(%{$emailrules}) > 0) {
 4400:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 4401:                                                 $emailruleorder,$numinrow,$$rowtotal);
 4402:                 $$rowtotal ++;
 4403:             }
 4404:         }
 4405:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
 4406:     }
 4407:     return $datatable;
 4408: }
 4409: 
 4410: sub email_as_username {
 4411:     my ($rowtotal,$processing,$type) = @_;
 4412:     my %choices =
 4413:         &Apache::lonlocal::texthash (
 4414:                                       automatic => 'Automatic approval',
 4415:                                       approval  => 'Queued for approval',
 4416:                                     );
 4417:     my $output;
 4418:     foreach my $option ('automatic','approval') {
 4419:         my $checked;
 4420:         if (ref($processing) eq 'HASH') {
 4421:             if ($type eq '') {   
 4422:                 if (!exists($processing->{'default'})) {
 4423:                     if ($option eq 'automatic') {
 4424:                         $checked = ' checked="checked"';
 4425:                     }
 4426:                 } else {
 4427:                     if ($processing->{'default'} eq $option) {
 4428:                         $checked = ' checked="checked"';
 4429:                     }
 4430:                 }
 4431:             } else {
 4432:                 if (!exists($processing->{$type})) {
 4433:                     if ($option eq 'automatic') {
 4434:                         $checked = ' checked="checked"';
 4435:                     }
 4436:                 } else {
 4437:                     if ($processing->{$type} eq $option) {
 4438:                         $checked = ' checked="checked"';
 4439:                     }
 4440:                 }
 4441:             }
 4442:         } elsif ($option eq 'automatic') {
 4443:             $checked = ' checked="checked"'; 
 4444:         }
 4445:         my $name = 'cancreate_emailprocess';
 4446:         if (($type ne '') && ($type ne 'default')) {
 4447:             $name .= '_'.$type;
 4448:         }
 4449:         $output .= '<span class="LC_nobreak"><label>'.
 4450:                    '<input type="radio" name="'.$name.'"'.
 4451:                    $checked.' value="'.$option.'" />'.
 4452:                    $choices{$option}.'</label></span>';
 4453:         if ($type eq '') {
 4454:             $output .= '&nbsp;';
 4455:         } else {
 4456:             $output .= '<br />';
 4457:         }
 4458:     }
 4459:     $$rowtotal ++;
 4460:     return $output;
 4461: }
 4462: 
 4463: sub captcha_choice {
 4464:     my ($context,$settings,$itemcount) = @_;
 4465:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
 4466:     my %lt = &captcha_phrases();
 4467:     $keyentry = 'hidden';
 4468:     if ($context eq 'cancreate') {
 4469:         $rowname = &mt('CAPTCHA validation');
 4470:     } elsif ($context eq 'login') {
 4471:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
 4472:     }
 4473:     if (ref($settings) eq 'HASH') {
 4474:         if ($settings->{'captcha'}) {
 4475:             $checked{$settings->{'captcha'}} = ' checked="checked"';
 4476:         } else {
 4477:             $checked{'original'} = ' checked="checked"';
 4478:         }
 4479:         if ($settings->{'captcha'} eq 'recaptcha') {
 4480:             $pubtext = $lt{'pub'};
 4481:             $privtext = $lt{'priv'};
 4482:             $keyentry = 'text';
 4483:         }
 4484:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
 4485:             $currpub = $settings->{'recaptchakeys'}{'public'};
 4486:             $currpriv = $settings->{'recaptchakeys'}{'private'};
 4487:         }
 4488:     } else {
 4489:         $checked{'original'} = ' checked="checked"';
 4490:     }
 4491:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4492:     my $output = '<tr'.$css_class.'>'.
 4493:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
 4494:                  '<table><tr><td>'."\n";
 4495:     foreach my $option ('original','recaptcha','notused') {
 4496:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
 4497:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
 4498:                    $lt{$option}.'</label></span>';
 4499:         unless ($option eq 'notused') {
 4500:             $output .= ('&nbsp;'x2)."\n";
 4501:         }
 4502:     }
 4503: #
 4504: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
 4505: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
 4506: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
 4507: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
 4508: #
 4509:     $output .= '</td></tr>'."\n".
 4510:                '<tr><td>'."\n".
 4511:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
 4512:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
 4513:                $currpub.'" size="40" /></span><br />'."\n".
 4514:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
 4515:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
 4516:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
 4517:                '</td></tr>';
 4518:     return $output;
 4519: }
 4520: 
 4521: sub user_formats_row {
 4522:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 4523:     my $output;
 4524:     my %text = (
 4525:                    'username' => 'new usernames',
 4526:                    'id'       => 'IDs',
 4527:                    'email'    => 'self-created accounts (e-mail)',
 4528:                );
 4529:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 4530:     $output = '<tr '.$css_class.'>'.
 4531:               '<td><span class="LC_nobreak">';
 4532:     if ($type eq 'email') {
 4533:         $output .= &mt("Formats disallowed for $text{$type}: ");
 4534:     } else {
 4535:         $output .= &mt("Format rules to check for $text{$type}: ");
 4536:     }
 4537:     $output .= '</span></td>'.
 4538:                '<td class="LC_left_item" colspan="2"><table>';
 4539:     my $rem;
 4540:     if (ref($ruleorder) eq 'ARRAY') {
 4541:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 4542:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 4543:                 my $rem = $i%($numinrow);
 4544:                 if ($rem == 0) {
 4545:                     if ($i > 0) {
 4546:                         $output .= '</tr>';
 4547:                     }
 4548:                     $output .= '<tr>';
 4549:                 }
 4550:                 my $check = ' ';
 4551:                 if (ref($settings) eq 'HASH') {
 4552:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 4553:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 4554:                             $check = ' checked="checked" ';
 4555:                         }
 4556:                     }
 4557:                 }
 4558:                 $output .= '<td class="LC_left_item">'.
 4559:                            '<span class="LC_nobreak"><label>'.
 4560:                            '<input type="checkbox" name="'.$type.'_rule" '.
 4561:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 4562:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 4563:             }
 4564:         }
 4565:         $rem = @{$ruleorder}%($numinrow);
 4566:     }
 4567:     my $colsleft = $numinrow - $rem;
 4568:     if ($colsleft > 1 ) {
 4569:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 4570:                    '&nbsp;</td>';
 4571:     } elsif ($colsleft == 1) {
 4572:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 4573:     }
 4574:     $output .= '</tr></table></td></tr>';
 4575:     return $output;
 4576: }
 4577: 
 4578: sub usercreation_types {
 4579:     my %lt = &Apache::lonlocal::texthash (
 4580:                     author     => 'When adding a co-author',
 4581:                     course     => 'When adding a user to a course',
 4582:                     requestcrs => 'When requesting a course',
 4583:                     any        => 'Any',
 4584:                     official   => 'Institutional only ',
 4585:                     unofficial => 'Non-institutional only',
 4586:                     none       => 'None',
 4587:     );
 4588:     return %lt;
 4589: }
 4590: 
 4591: sub selfcreation_types {
 4592:     my %lt = &Apache::lonlocal::texthash (
 4593:                     selfcreate => 'User creates own account',
 4594:                     any        => 'Any',
 4595:                     official   => 'Institutional only ',
 4596:                     unofficial => 'Non-institutional only',
 4597:                     email      => 'E-mail address',
 4598:                     login      => 'Institutional Login',
 4599:                     sso        => 'SSO',
 4600:              );
 4601: }
 4602: 
 4603: sub authtype_names {
 4604:     my %lt = &Apache::lonlocal::texthash(
 4605:                       int    => 'Internal',
 4606:                       krb4   => 'Kerberos 4',
 4607:                       krb5   => 'Kerberos 5',
 4608:                       loc    => 'Local',
 4609:                   );
 4610:     return %lt;
 4611: }
 4612: 
 4613: sub context_names {
 4614:     my %context_title = &Apache::lonlocal::texthash(
 4615:        author => 'Creating users when an Author',
 4616:        course => 'Creating users when in a course',
 4617:        domain => 'Creating users when a Domain Coordinator',
 4618:     );
 4619:     return %context_title;
 4620: }
 4621: 
 4622: sub print_usermodification {
 4623:     my ($position,$dom,$settings,$rowtotal) = @_;
 4624:     my $numinrow = 4;
 4625:     my ($context,$datatable,$rowcount);
 4626:     if ($position eq 'top') {
 4627:         $rowcount = 0;
 4628:         $context = 'author'; 
 4629:         foreach my $role ('ca','aa') {
 4630:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 4631:                                                    $numinrow,$rowcount);
 4632:             $$rowtotal ++;
 4633:             $rowcount ++;
 4634:         }
 4635:     } elsif ($position eq 'bottom') {
 4636:         $context = 'course';
 4637:         $rowcount = 0;
 4638:         foreach my $role ('st','ep','ta','in','cr') {
 4639:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 4640:                                                    $numinrow,$rowcount);
 4641:             $$rowtotal ++;
 4642:             $rowcount ++;
 4643:         }
 4644:     }
 4645:     return $datatable;
 4646: }
 4647: 
 4648: sub print_defaults {
 4649:     my ($position,$dom,$settings,$rowtotal) = @_;
 4650:     my $rownum = 0;
 4651:     my ($datatable,$css_class);
 4652:     if ($position eq 'top') {
 4653:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 4654:                      'datelocale_def','portal_def');
 4655:         my %defaults;
 4656:         if (ref($settings) eq 'HASH') {
 4657:             %defaults = %{$settings};
 4658:         } else {
 4659:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
 4660:             foreach my $item (@items) {
 4661:                 $defaults{$item} = $domdefaults{$item};
 4662:             }
 4663:         }
 4664:         my $titles = &defaults_titles($dom);
 4665:         foreach my $item (@items) {
 4666:             if ($rownum%2) {
 4667:                 $css_class = '';
 4668:             } else {
 4669:                 $css_class = ' class="LC_odd_row" ';
 4670:             }
 4671:             $datatable .= '<tr'.$css_class.'>'.
 4672:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
 4673:                           '</span></td><td class="LC_right_item" colspan="3">';
 4674:             if ($item eq 'auth_def') {
 4675:                 my @authtypes = ('internal','krb4','krb5','localauth');
 4676:                 my %shortauth = (
 4677:                                  internal => 'int',
 4678:                                  krb4 => 'krb4',
 4679:                                  krb5 => 'krb5',
 4680:                                  localauth  => 'loc'
 4681:                                 );
 4682:                 my %authnames = &authtype_names();
 4683:                 foreach my $auth (@authtypes) {
 4684:                     my $checked = ' ';
 4685:                     if ($defaults{$item} eq $auth) {
 4686:                         $checked = ' checked="checked" ';
 4687:                     }
 4688:                     $datatable .= '<label><input type="radio" name="'.$item.
 4689:                                   '" value="'.$auth.'"'.$checked.'/>'.
 4690:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 4691:                 }
 4692:             } elsif ($item eq 'timezone_def') {
 4693:                 my $includeempty = 1;
 4694:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
 4695:             } elsif ($item eq 'datelocale_def') {
 4696:                 my $includeempty = 1;
 4697:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
 4698:             } elsif ($item eq 'lang_def') {
 4699:                 my %langchoices = &get_languages_hash();
 4700:                 $langchoices{''} = 'No language preference';
 4701:                 %langchoices = &Apache::lonlocal::texthash(%langchoices);
 4702:                 $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
 4703:                                                               \%langchoices);
 4704:             } else {
 4705:                 my $size;
 4706:                 if ($item eq 'portal_def') {
 4707:                     $size = ' size="25"';
 4708:                 }
 4709:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
 4710:                               $defaults{$item}.'"'.$size.' />';
 4711:             }
 4712:             $datatable .= '</td></tr>';
 4713:             $rownum ++;
 4714:         }
 4715:     } else {
 4716:         my (%defaults);
 4717:         if (ref($settings) eq 'HASH') {
 4718:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
 4719:                 (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
 4720:                 my $maxnum = @{$settings->{'inststatusorder'}};
 4721:                 for (my $i=0; $i<$maxnum; $i++) {
 4722:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
 4723:                     my $item = $settings->{'inststatusorder'}->[$i];
 4724:                     my $title = $settings->{'inststatustypes'}->{$item};
 4725:                     my $guestok;
 4726:                     if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
 4727:                         $guestok = 1;
 4728:                     }
 4729:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
 4730:                     $datatable .= '<tr'.$css_class.'>'.
 4731:                                   '<td><span class="LC_nobreak">'.
 4732:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
 4733:                     for (my $k=0; $k<=$maxnum; $k++) {
 4734:                         my $vpos = $k+1;
 4735:                         my $selstr;
 4736:                         if ($k == $i) {
 4737:                             $selstr = ' selected="selected" ';
 4738:                         }
 4739:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4740:                     }
 4741:                     my ($checkedon,$checkedoff);
 4742:                     $checkedoff = ' checked="checked"';
 4743:                     if ($guestok) {
 4744:                         $checkedon = $checkedoff;
 4745:                         $checkedoff = ''; 
 4746:                     }
 4747:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
 4748:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
 4749:                                   &mt('delete').'</span></td>'.
 4750:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
 4751:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
 4752:                                   '</span></td>'.
 4753:                                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 4754:                                   '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
 4755:                                   &mt('Yes').'</label>'.('&nbsp;'x2).
 4756:                                   '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
 4757:                                   &mt('No').'</label></span></td></tr>';
 4758:                 }
 4759:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
 4760:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
 4761:                 $datatable .= '<tr '.$css_class.'>'.
 4762:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
 4763:                 for (my $k=0; $k<=$maxnum; $k++) {
 4764:                     my $vpos = $k+1;
 4765:                     my $selstr;
 4766:                     if ($k == $maxnum) {
 4767:                         $selstr = ' selected="selected" ';
 4768:                     }
 4769:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4770:                 }
 4771:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
 4772:                               '<input type="text" size="10" name="addinststatus" value="" /></span>'.
 4773:                               '&nbsp;'.&mt('(new)').
 4774:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
 4775:                               &mt('Name displayed:').
 4776:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
 4777:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
 4778:                               '<label><input type="radio" value="1" name="addinststatus_guest" />'.
 4779:                               &mt('Yes').'</label>'.('&nbsp;'x2).
 4780:                               '<label><input type="radio" value="0" name="addinststatus_guest" />'.
 4781:                               &mt('No').'</label></span></td></tr>';
 4782:                               '</tr>'."\n";
 4783:                 $rownum ++;
 4784:             }
 4785:         }
 4786:     }
 4787:     $$rowtotal += $rownum;
 4788:     return $datatable;
 4789: }
 4790: 
 4791: sub get_languages_hash {
 4792:     my %langchoices;
 4793:     foreach my $id (&Apache::loncommon::languageids()) {
 4794:         my $code = &Apache::loncommon::supportedlanguagecode($id);
 4795:         if ($code ne '') {
 4796:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
 4797:         }
 4798:     }
 4799:     return %langchoices;
 4800: }
 4801: 
 4802: sub defaults_titles {
 4803:     my ($dom) = @_;
 4804:     my %titles = &Apache::lonlocal::texthash (
 4805:                    'auth_def'      => 'Default authentication type',
 4806:                    'auth_arg_def'  => 'Default authentication argument',
 4807:                    'lang_def'      => 'Default language',
 4808:                    'timezone_def'  => 'Default timezone',
 4809:                    'datelocale_def' => 'Default locale for dates',
 4810:                    'portal_def'     => 'Portal/Default URL',
 4811:                  );
 4812:     if ($dom) {
 4813:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
 4814:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
 4815:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
 4816:         $protocol = 'http' if ($protocol ne 'https');
 4817:         if ($uint_dom) {
 4818:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
 4819:                                          $uint_dom);
 4820:         }
 4821:     }
 4822:     return (\%titles);
 4823: }
 4824: 
 4825: sub print_scantronformat {
 4826:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 4827:     my $itemcount = 1;
 4828:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 4829:         %confhash);
 4830:     my $switchserver = &check_switchserver($dom,$confname);
 4831:     my %lt = &Apache::lonlocal::texthash (
 4832:                 default => 'Default bubblesheet format file error',
 4833:                 custom  => 'Custom bubblesheet format file error',
 4834:              );
 4835:     my %scantronfiles = (
 4836:         default => 'default.tab',
 4837:         custom => 'custom.tab',
 4838:     );
 4839:     foreach my $key (keys(%scantronfiles)) {
 4840:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 4841:                               .$scantronfiles{$key};
 4842:     }
 4843:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 4844:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 4845:         if (!$switchserver) {
 4846:             my $servadm = $r->dir_config('lonAdmEMail');
 4847:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 4848:             if ($configuserok eq 'ok') {
 4849:                 if ($author_ok eq 'ok') {
 4850:                     my %legacyfile = (
 4851:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 4852:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 4853:                     );
 4854:                     my %md5chk;
 4855:                     foreach my $type (keys(%legacyfile)) {
 4856:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 4857:                         chomp($md5chk{$type});
 4858:                     }
 4859:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 4860:                         foreach my $type (keys(%legacyfile)) {
 4861:                             ($scantronurls{$type},my $error) = 
 4862:                                 &legacy_scantronformat($r,$dom,$confname,
 4863:                                                  $type,$legacyfile{$type},
 4864:                                                  $scantronurls{$type},
 4865:                                                  $scantronfiles{$type});
 4866:                             if ($error ne '') {
 4867:                                 $error{$type} = $error;
 4868:                             }
 4869:                         }
 4870:                         if (keys(%error) == 0) {
 4871:                             $is_custom = 1;
 4872:                             $confhash{'scantron'}{'scantronformat'} = 
 4873:                                 $scantronurls{'custom'};
 4874:                             my $putresult = 
 4875:                                 &Apache::lonnet::put_dom('configuration',
 4876:                                                          \%confhash,$dom);
 4877:                             if ($putresult ne 'ok') {
 4878:                                 $error{'custom'} = 
 4879:                                     '<span class="LC_error">'.
 4880:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 4881:                             }
 4882:                         }
 4883:                     } else {
 4884:                         ($scantronurls{'default'},my $error) =
 4885:                             &legacy_scantronformat($r,$dom,$confname,
 4886:                                           'default',$legacyfile{'default'},
 4887:                                           $scantronurls{'default'},
 4888:                                           $scantronfiles{'default'});
 4889:                         if ($error eq '') {
 4890:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 4891:                             my $putresult =
 4892:                                 &Apache::lonnet::put_dom('configuration',
 4893:                                                          \%confhash,$dom);
 4894:                             if ($putresult ne 'ok') {
 4895:                                 $error{'default'} =
 4896:                                     '<span class="LC_error">'.
 4897:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 4898:                             }
 4899:                         } else {
 4900:                             $error{'default'} = $error;
 4901:                         }
 4902:                     }
 4903:                 }
 4904:             }
 4905:         } else {
 4906:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
 4907:         }
 4908:     }
 4909:     if (ref($settings) eq 'HASH') {
 4910:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 4911:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 4912:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 4913:                 $scantronurl = '';
 4914:             } else {
 4915:                 $scantronurl = $settings->{'scantronformat'};
 4916:             }
 4917:             $is_custom = 1;
 4918:         } else {
 4919:             $scantronurl = $scantronurls{'default'};
 4920:         }
 4921:     } else {
 4922:         if ($is_custom) {
 4923:             $scantronurl = $scantronurls{'custom'};
 4924:         } else {
 4925:             $scantronurl = $scantronurls{'default'};
 4926:         }
 4927:     }
 4928:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4929:     $datatable .= '<tr'.$css_class.'>';
 4930:     if (!$is_custom) {
 4931:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 4932:                       '<span class="LC_nobreak">';
 4933:         if ($scantronurl) {
 4934:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
 4935:                                                          undef,undef,undef,undef,'background-color:#ffffff');
 4936:         } else {
 4937:             $datatable = &mt('File unavailable for display');
 4938:         }
 4939:         $datatable .= '</span></td>';
 4940:         if (keys(%error) == 0) { 
 4941:             $datatable .= '<td valign="bottom">';
 4942:             if (!$switchserver) {
 4943:                 $datatable .= &mt('Upload:').'<br />';
 4944:             }
 4945:         } else {
 4946:             my $errorstr;
 4947:             foreach my $key (sort(keys(%error))) {
 4948:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 4949:             }
 4950:             $datatable .= '<td>'.$errorstr;
 4951:         }
 4952:     } else {
 4953:         if (keys(%error) > 0) {
 4954:             my $errorstr;
 4955:             foreach my $key (sort(keys(%error))) {
 4956:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 4957:             } 
 4958:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 4959:         } elsif ($scantronurl) {
 4960:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
 4961:                                                        undef,undef,undef,undef,'background-color:#ffffff');
 4962:             $datatable .= '<td><span class="LC_nobreak">'.
 4963:                           $link.
 4964:                           '<label><input type="checkbox" name="scantronformat_del"'.
 4965:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
 4966:                           '<td><span class="LC_nobreak">&nbsp;'.
 4967:                           &mt('Replace:').'</span><br />';
 4968:         }
 4969:     }
 4970:     if (keys(%error) == 0) {
 4971:         if ($switchserver) {
 4972:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 4973:         } else {
 4974:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 4975:                          '<input type="file" name="scantronformat" /></span>';
 4976:         }
 4977:     }
 4978:     $datatable .= '</td></tr>';
 4979:     $$rowtotal ++;
 4980:     return $datatable;
 4981: }
 4982: 
 4983: sub legacy_scantronformat {
 4984:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 4985:     my ($url,$error);
 4986:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 4987:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 4988:         (my $result,$url) =
 4989:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 4990:                          '','',$newfile);
 4991:         if ($result ne 'ok') {
 4992:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
 4993:         }
 4994:     }
 4995:     return ($url,$error);
 4996: }
 4997: 
 4998: sub print_coursecategories {
 4999:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 5000:     my $datatable;
 5001:     if ($position eq 'top') {
 5002:         my (%checked);
 5003:         my @catitems = ('unauth','auth');
 5004:         my @cattypes = ('std','domonly','codesrch','none');
 5005:         $checked{'unauth'} = 'std';
 5006:         $checked{'auth'} = 'std';
 5007:         if (ref($settings) eq 'HASH') {
 5008:             foreach my $type (@cattypes) {
 5009:                 if ($type eq $settings->{'unauth'}) {
 5010:                     $checked{'unauth'} = $type;
 5011:                 }
 5012:                 if ($type eq $settings->{'auth'}) {
 5013:                     $checked{'auth'} = $type;
 5014:                 }
 5015:             }
 5016:         }
 5017:         my %lt = &Apache::lonlocal::texthash (
 5018:                                                unauth   => 'Catalog type for unauthenticated users',
 5019:                                                auth     => 'Catalog type for authenticated users',
 5020:                                                none     => 'No catalog',
 5021:                                                std      => 'Standard catalog',
 5022:                                                domonly  => 'Domain-only catalog',
 5023:                                                codesrch => "Code search form",
 5024:                                              );
 5025:        my $itemcount = 0;
 5026:        foreach my $item (@catitems) {
 5027:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
 5028:            $datatable .= '<tr '.$css_class.'>'.
 5029:                          '<td>'.$lt{$item}.'</td>'.
 5030:                          '<td class="LC_right_item"><span class="LC_nobreak">';
 5031:            foreach my $type (@cattypes) {
 5032:                my $ischecked;
 5033:                if ($checked{$item} eq $type) {
 5034:                    $ischecked=' checked="checked"';
 5035:                }
 5036:                $datatable .= '<label>'.
 5037:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
 5038:                              ' />'.$lt{$type}.'</label>&nbsp;';
 5039:            }
 5040:            $datatable .= '</td></tr>';
 5041:            $itemcount ++;
 5042:         }
 5043:         $$rowtotal += $itemcount;
 5044:     } elsif ($position eq 'middle') {
 5045:         my $toggle_cats_crs = ' ';
 5046:         my $toggle_cats_dom = ' checked="checked" ';
 5047:         my $can_cat_crs = ' ';
 5048:         my $can_cat_dom = ' checked="checked" ';
 5049:         my $toggle_catscomm_comm = ' ';
 5050:         my $toggle_catscomm_dom = ' checked="checked" ';
 5051:         my $can_catcomm_comm = ' ';
 5052:         my $can_catcomm_dom = ' checked="checked" ';
 5053: 
 5054:         if (ref($settings) eq 'HASH') {
 5055:             if ($settings->{'togglecats'} eq 'crs') {
 5056:                 $toggle_cats_crs = $toggle_cats_dom;
 5057:                 $toggle_cats_dom = ' ';
 5058:             }
 5059:             if ($settings->{'categorize'} eq 'crs') {
 5060:                 $can_cat_crs = $can_cat_dom;
 5061:                 $can_cat_dom = ' ';
 5062:             }
 5063:             if ($settings->{'togglecatscomm'} eq 'comm') {
 5064:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
 5065:                 $toggle_catscomm_dom = ' ';
 5066:             }
 5067:             if ($settings->{'categorizecomm'} eq 'comm') {
 5068:                 $can_catcomm_comm = $can_catcomm_dom;
 5069:                 $can_catcomm_dom = ' ';
 5070:             }
 5071:         }
 5072:         my %title = &Apache::lonlocal::texthash (
 5073:                      togglecats     => 'Show/Hide a course in catalog',
 5074:                      togglecatscomm => 'Show/Hide a community in catalog',
 5075:                      categorize     => 'Assign a category to a course',
 5076:                      categorizecomm => 'Assign a category to a community',
 5077:                     );
 5078:         my %level = &Apache::lonlocal::texthash (
 5079:                      dom  => 'Set in Domain',
 5080:                      crs  => 'Set in Course',
 5081:                      comm => 'Set in Community',
 5082:                     );
 5083:         $datatable = '<tr class="LC_odd_row">'.
 5084:                   '<td>'.$title{'togglecats'}.'</td>'.
 5085:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 5086:                   '<input type="radio" name="togglecats"'.
 5087:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 5088:                   '<label><input type="radio" name="togglecats"'.
 5089:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 5090:                   '</tr><tr>'.
 5091:                   '<td>'.$title{'categorize'}.'</td>'.
 5092:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 5093:                   '<label><input type="radio" name="categorize"'.
 5094:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 5095:                   '<label><input type="radio" name="categorize"'.
 5096:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 5097:                   '</tr><tr class="LC_odd_row">'.
 5098:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
 5099:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 5100:                   '<input type="radio" name="togglecatscomm"'.
 5101:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 5102:                   '<label><input type="radio" name="togglecatscomm"'.
 5103:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
 5104:                   '</tr><tr>'.
 5105:                   '<td>'.$title{'categorizecomm'}.'</td>'.
 5106:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 5107:                   '<label><input type="radio" name="categorizecomm"'.
 5108:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 5109:                   '<label><input type="radio" name="categorizecomm"'.
 5110:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
 5111:                   '</tr>';
 5112:         $$rowtotal += 4;
 5113:     } else {
 5114:         my $css_class;
 5115:         my $itemcount = 1;
 5116:         my $cathash; 
 5117:         if (ref($settings) eq 'HASH') {
 5118:             $cathash = $settings->{'cats'};
 5119:         }
 5120:         if (ref($cathash) eq 'HASH') {
 5121:             my (@cats,@trails,%allitems,%idx,@jsarray);
 5122:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 5123:                                                    \%allitems,\%idx,\@jsarray);
 5124:             my $maxdepth = scalar(@cats);
 5125:             my $colattrib = '';
 5126:             if ($maxdepth > 2) {
 5127:                 $colattrib = ' colspan="2" ';
 5128:             }
 5129:             my @path;
 5130:             if (@cats > 0) {
 5131:                 if (ref($cats[0]) eq 'ARRAY') {
 5132:                     my $numtop = @{$cats[0]};
 5133:                     my $maxnum = $numtop;
 5134:                     my %default_names = (
 5135:                           instcode    => &mt('Official courses'),
 5136:                           communities => &mt('Communities'),
 5137:                     );
 5138: 
 5139:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
 5140:                         ($cathash->{'instcode::0'} eq '') ||
 5141:                         (!grep(/^communities$/,@{$cats[0]})) || 
 5142:                         ($cathash->{'communities::0'} eq '')) {
 5143:                         $maxnum ++;
 5144:                     }
 5145:                     my $lastidx;
 5146:                     for (my $i=0; $i<$numtop; $i++) {
 5147:                         my $parent = $cats[0][$i];
 5148:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5149:                         my $item = &escape($parent).'::0';
 5150:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 5151:                         $lastidx = $idx{$item};
 5152:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 5153:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 5154:                         for (my $k=0; $k<=$maxnum; $k++) {
 5155:                             my $vpos = $k+1;
 5156:                             my $selstr;
 5157:                             if ($k == $i) {
 5158:                                 $selstr = ' selected="selected" ';
 5159:                             }
 5160:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 5161:                         }
 5162:                         $datatable .= '</select></span></td><td>';
 5163:                         if ($parent eq 'instcode' || $parent eq 'communities') {
 5164:                             $datatable .=  '<span class="LC_nobreak">'
 5165:                                            .$default_names{$parent}.'</span>';
 5166:                             if ($parent eq 'instcode') {
 5167:                                 $datatable .= '<br /><span class="LC_nobreak">('
 5168:                                               .&mt('with institutional codes')
 5169:                                               .')</span></td><td'.$colattrib.'>';
 5170:                             } else {
 5171:                                 $datatable .= '<table><tr><td>';
 5172:                             }
 5173:                             $datatable .= '<span class="LC_nobreak">'
 5174:                                           .'<label><input type="radio" name="'
 5175:                                           .$parent.'" value="1" checked="checked" />'
 5176:                                           .&mt('Display').'</label>';
 5177:                             if ($parent eq 'instcode') {
 5178:                                 $datatable .= '&nbsp;';
 5179:                             } else {
 5180:                                 $datatable .= '</span></td></tr><tr><td>'
 5181:                                               .'<span class="LC_nobreak">';
 5182:                             }
 5183:                             $datatable .= '<label><input type="radio" name="'
 5184:                                           .$parent.'" value="0" />'
 5185:                                           .&mt('Do not display').'</label></span>';
 5186:                             if ($parent eq 'communities') {
 5187:                                 $datatable .= '</td></tr></table>';
 5188:                             }
 5189:                             $datatable .= '</td>';
 5190:                         } else {
 5191:                             $datatable .= $parent
 5192:                                           .'&nbsp;<span class="LC_nobreak"><label>'
 5193:                                           .'<input type="checkbox" name="deletecategory" '
 5194:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 5195:                         }
 5196:                         my $depth = 1;
 5197:                         push(@path,$parent);
 5198:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 5199:                         pop(@path);
 5200:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 5201:                         $itemcount ++;
 5202:                     }
 5203:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5204:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 5205:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 5206:                     for (my $k=0; $k<=$maxnum; $k++) {
 5207:                         my $vpos = $k+1;
 5208:                         my $selstr;
 5209:                         if ($k == $numtop) {
 5210:                             $selstr = ' selected="selected" ';
 5211:                         }
 5212:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 5213:                     }
 5214:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 5215:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 5216:                                   .'</tr>'."\n";
 5217:                     $itemcount ++;
 5218:                     foreach my $default ('instcode','communities') {
 5219:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
 5220:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5221:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
 5222:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 5223:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
 5224:                             for (my $k=0; $k<=$maxnum; $k++) {
 5225:                                 my $vpos = $k+1;
 5226:                                 my $selstr;
 5227:                                 if ($k == $maxnum) {
 5228:                                     $selstr = ' selected="selected" ';
 5229:                                 }
 5230:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 5231:                             }
 5232:                             $datatable .= '</select></span></td>'.
 5233:                                           '<td><span class="LC_nobreak">'.
 5234:                                           $default_names{$default}.'</span>';
 5235:                             if ($default eq 'instcode') {
 5236:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
 5237:                                               .&mt('with institutional codes').')</span>';
 5238:                             }
 5239:                             $datatable .= '</td>'
 5240:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
 5241:                                           .&mt('Display').'</label>&nbsp;'
 5242:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
 5243:                                           .&mt('Do not display').'</label></span></td></tr>';
 5244:                         }
 5245:                     }
 5246:                 }
 5247:             } else {
 5248:                 $datatable .= &initialize_categories($itemcount);
 5249:             }
 5250:         } else {
 5251:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
 5252:                           .&initialize_categories($itemcount);
 5253:         }
 5254:         $$rowtotal += $itemcount;
 5255:     }
 5256:     return $datatable;
 5257: }
 5258: 
 5259: sub print_serverstatuses {
 5260:     my ($dom,$settings,$rowtotal) = @_;
 5261:     my $datatable;
 5262:     my @pages = &serverstatus_pages();
 5263:     my (%namedaccess,%machineaccess);
 5264:     foreach my $type (@pages) {
 5265:         $namedaccess{$type} = '';
 5266:         $machineaccess{$type}= '';
 5267:     }
 5268:     if (ref($settings) eq 'HASH') {
 5269:         foreach my $type (@pages) {
 5270:             if (exists($settings->{$type})) {
 5271:                 if (ref($settings->{$type}) eq 'HASH') {
 5272:                     foreach my $key (keys(%{$settings->{$type}})) {
 5273:                         if ($key eq 'namedusers') {
 5274:                             $namedaccess{$type} = $settings->{$type}->{$key};
 5275:                         } elsif ($key eq 'machines') {
 5276:                             $machineaccess{$type} = $settings->{$type}->{$key};
 5277:                         }
 5278:                     }
 5279:                 }
 5280:             }
 5281:         }
 5282:     }
 5283:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 5284:     my $rownum = 0;
 5285:     my $css_class;
 5286:     foreach my $type (@pages) {
 5287:         $rownum ++;
 5288:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 5289:         $datatable .= '<tr'.$css_class.'>'.
 5290:                       '<td><span class="LC_nobreak">'.
 5291:                       $titles->{$type}.'</span></td>'.
 5292:                       '<td class="LC_left_item">'.
 5293:                       '<input type="text" name="'.$type.'_namedusers" '.
 5294:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 5295:                       '<td class="LC_right_item">'.
 5296:                       '<span class="LC_nobreak">'.
 5297:                       '<input type="text" name="'.$type.'_machines" '.
 5298:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 5299:                       '</td></tr>'."\n";
 5300:     }
 5301:     $$rowtotal += $rownum;
 5302:     return $datatable;
 5303: }
 5304: 
 5305: sub serverstatus_pages {
 5306:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 5307:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
 5308:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
 5309:             'uniquecodes','diskusage');
 5310: }
 5311: 
 5312: sub defaults_javascript {
 5313:     my ($settings) = @_;
 5314:     return unless (ref($settings) eq 'HASH');
 5315:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
 5316:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
 5317:         if ($maxnum eq '') {
 5318:             $maxnum = 0;
 5319:         }
 5320:         $maxnum ++;
 5321:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
 5322:         return <<"ENDSCRIPT";
 5323: <script type="text/javascript">
 5324: // <![CDATA[
 5325: function reorderTypes(form,caller) {
 5326:     var changedVal;
 5327: $jstext 
 5328:     var newpos = 'addinststatus_pos';
 5329:     var current = new Array;
 5330:     var maxh = $maxnum;
 5331:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 5332:     var oldVal;
 5333:     if (caller == newpos) {
 5334:         changedVal = newitemVal;
 5335:     } else {
 5336:         var curritem = 'inststatus_pos_'+caller;
 5337:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
 5338:         current[newitemVal] = newpos;
 5339:     }
 5340:     for (var i=0; i<inststatuses.length; i++) {
 5341:         if (inststatuses[i] != caller) {
 5342:             var elementName = 'inststatus_pos_'+inststatuses[i];
 5343:             if (form.elements[elementName]) {
 5344:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 5345:                 current[currVal] = elementName;
 5346:             }
 5347:         }
 5348:     }
 5349:     for (var j=0; j<maxh; j++) {
 5350:         if (current[j] == undefined) {
 5351:             oldVal = j;
 5352:         }
 5353:     }
 5354:     if (oldVal < changedVal) {
 5355:         for (var k=oldVal+1; k<=changedVal ; k++) {
 5356:            var elementName = current[k];
 5357:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 5358:         }
 5359:     } else {
 5360:         for (var k=changedVal; k<oldVal; k++) {
 5361:             var elementName = current[k];
 5362:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 5363:         }
 5364:     }
 5365:     return;
 5366: }
 5367: 
 5368: // ]]>
 5369: </script>
 5370: 
 5371: ENDSCRIPT
 5372:     }
 5373: }
 5374: 
 5375: sub coursecategories_javascript {
 5376:     my ($settings) = @_;
 5377:     my ($output,$jstext,$cathash);
 5378:     if (ref($settings) eq 'HASH') {
 5379:         $cathash = $settings->{'cats'};
 5380:     }
 5381:     if (ref($cathash) eq 'HASH') {
 5382:         my (@cats,@jsarray,%idx);
 5383:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 5384:         if (@jsarray > 0) {
 5385:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 5386:             for (my $i=0; $i<@jsarray; $i++) {
 5387:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 5388:                     my $catstr = join('","',@{$jsarray[$i]});
 5389:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 5390:                 }
 5391:             }
 5392:         }
 5393:     } else {
 5394:         $jstext  = '    var categories = Array(1);'."\n".
 5395:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 5396:     }
 5397:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
 5398:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
 5399:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.'); 
 5400:     $output = <<"ENDSCRIPT";
 5401: <script type="text/javascript">
 5402: // <![CDATA[
 5403: function reorderCats(form,parent,item,idx) {
 5404:     var changedVal;
 5405: $jstext
 5406:     var newpos = 'addcategory_pos';
 5407:     if (parent == '') {
 5408:         var has_instcode = 0;
 5409:         var maxtop = categories[idx].length;
 5410:         for (var j=0; j<maxtop; j++) {
 5411:             if (categories[idx][j] == 'instcode::0') {
 5412:                 has_instcode == 1;
 5413:             }
 5414:         }
 5415:         if (has_instcode == 0) {
 5416:             categories[idx][maxtop] = 'instcode_pos';
 5417:         }
 5418:     } else {
 5419:         newpos += '_'+parent;
 5420:     }
 5421:     var maxh = 1 + categories[idx].length;
 5422:     var current = new Array;
 5423:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 5424:     if (item == newpos) {
 5425:         changedVal = newitemVal;
 5426:     } else {
 5427:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 5428:         current[newitemVal] = newpos;
 5429:     }
 5430:     for (var i=0; i<categories[idx].length; i++) {
 5431:         var elementName = categories[idx][i];
 5432:         if (elementName != item) {
 5433:             if (form.elements[elementName]) {
 5434:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 5435:                 current[currVal] = elementName;
 5436:             }
 5437:         }
 5438:     }
 5439:     var oldVal;
 5440:     for (var j=0; j<maxh; j++) {
 5441:         if (current[j] == undefined) {
 5442:             oldVal = j;
 5443:         }
 5444:     }
 5445:     if (oldVal < changedVal) {
 5446:         for (var k=oldVal+1; k<=changedVal ; k++) {
 5447:            var elementName = current[k];
 5448:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 5449:         }
 5450:     } else {
 5451:         for (var k=changedVal; k<oldVal; k++) {
 5452:             var elementName = current[k];
 5453:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 5454:         }
 5455:     }
 5456:     return;
 5457: }
 5458: 
 5459: function categoryCheck(form) {
 5460:     if (form.elements['addcategory_name'].value == 'instcode') {
 5461:         alert('$instcode_reserved\\n$choose_again');
 5462:         return false;
 5463:     }
 5464:     if (form.elements['addcategory_name'].value == 'communities') {
 5465:         alert('$communities_reserved\\n$choose_again');
 5466:         return false;
 5467:     }
 5468:     return true;
 5469: }
 5470: 
 5471: // ]]>
 5472: </script>
 5473: 
 5474: ENDSCRIPT
 5475:     return $output;
 5476: }
 5477: 
 5478: sub initialize_categories {
 5479:     my ($itemcount) = @_;
 5480:     my ($datatable,$css_class,$chgstr);
 5481:     my %default_names = (
 5482:                       instcode    => 'Official courses (with institutional codes)',
 5483:                       communities => 'Communities',
 5484:                         );
 5485:     my $select0 = ' selected="selected"';
 5486:     my $select1 = '';
 5487:     foreach my $default ('instcode','communities') {
 5488:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5489:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
 5490:         if ($default eq 'communities') {
 5491:             $select1 = $select0;
 5492:             $select0 = '';
 5493:         }
 5494:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 5495:                      .'<select name="'.$default.'_pos">'
 5496:                      .'<option value="0"'.$select0.'>1</option>'
 5497:                      .'<option value="1"'.$select1.'>2</option>'
 5498:                      .'<option value="2">3</option></select>&nbsp;'
 5499:                      .$default_names{$default}
 5500:                      .'</span></td><td><span class="LC_nobreak">'
 5501:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
 5502:                      .&mt('Display').'</label>&nbsp;<label>'
 5503:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
 5504:                  .'</label></span></td></tr>';
 5505:         $itemcount ++;
 5506:     }
 5507:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5508:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 5509:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 5510:                   .'<select name="addcategory_pos"'.$chgstr.'>'
 5511:                   .'<option value="0">1</option>'
 5512:                   .'<option value="1">2</option>'
 5513:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
 5514:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 5515:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 5516:     return $datatable;
 5517: }
 5518: 
 5519: sub build_category_rows {
 5520:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 5521:     my ($text,$name,$item,$chgstr);
 5522:     if (ref($cats) eq 'ARRAY') {
 5523:         my $maxdepth = scalar(@{$cats});
 5524:         if (ref($cats->[$depth]) eq 'HASH') {
 5525:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 5526:                 my $numchildren = @{$cats->[$depth]{$parent}};
 5527:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5528:                 $text .= '<td><table class="LC_data_table">';
 5529:                 my ($idxnum,$parent_name,$parent_item);
 5530:                 my $higher = $depth - 1;
 5531:                 if ($higher == 0) {
 5532:                     $parent_name = &escape($parent).'::'.$higher;
 5533:                 } else {
 5534:                     if (ref($path) eq 'ARRAY') {
 5535:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 5536:                     }
 5537:                 }
 5538:                 $parent_item = 'addcategory_pos_'.$parent_name;
 5539:                 for (my $j=0; $j<=$numchildren; $j++) {
 5540:                     if ($j < $numchildren) {
 5541:                         $name = $cats->[$depth]{$parent}[$j];
 5542:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 5543:                         $idxnum = $idx->{$item};
 5544:                     } else {
 5545:                         $name = $parent_name;
 5546:                         $item = $parent_item;
 5547:                     }
 5548:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 5549:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 5550:                     for (my $i=0; $i<=$numchildren; $i++) {
 5551:                         my $vpos = $i+1;
 5552:                         my $selstr;
 5553:                         if ($j == $i) {
 5554:                             $selstr = ' selected="selected" ';
 5555:                         }
 5556:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 5557:                     }
 5558:                     $text .= '</select>&nbsp;';
 5559:                     if ($j < $numchildren) {
 5560:                         my $deeper = $depth+1;
 5561:                         $text .= $name.'&nbsp;'
 5562:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 5563:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 5564:                         if(ref($path) eq 'ARRAY') {
 5565:                             push(@{$path},$name);
 5566:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 5567:                             pop(@{$path});
 5568:                         }
 5569:                     } else {
 5570:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 5571:                         if ($j == $numchildren) {
 5572:                             $text .= $name;
 5573:                         } else {
 5574:                             $text .= $item;
 5575:                         }
 5576:                         $text .= '" value="" />';
 5577:                     }
 5578:                     $text .= '</td></tr>';
 5579:                 }
 5580:                 $text .= '</table></td>';
 5581:             } else {
 5582:                 my $higher = $depth-1;
 5583:                 if ($higher == 0) {
 5584:                     $name = &escape($parent).'::'.$higher;
 5585:                 } else {
 5586:                     if (ref($path) eq 'ARRAY') {
 5587:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 5588:                     }
 5589:                 }
 5590:                 my $colspan;
 5591:                 if ($parent ne 'instcode') {
 5592:                     $colspan = $maxdepth - $depth - 1;
 5593:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 5594:                 }
 5595:             }
 5596:         }
 5597:     }
 5598:     return $text;
 5599: }
 5600: 
 5601: sub modifiable_userdata_row {
 5602:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
 5603:     my ($role,$rolename,$statustype);
 5604:     $role = $item;
 5605:     if ($context eq 'cancreate') {
 5606:         if ($item =~ /^emailusername_(.+)$/) {
 5607:             $statustype = $1;
 5608:             $role = 'emailusername';
 5609:             if (ref($usertypes) eq 'HASH') {
 5610:                 if ($usertypes->{$statustype}) {
 5611:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
 5612:                 } else {
 5613:                     $rolename = &mt('Data provided by user');
 5614:                 }
 5615:             }
 5616:         }
 5617:     } elsif ($context eq 'selfcreate') {
 5618:         if (ref($usertypes) eq 'HASH') {
 5619:             $rolename = $usertypes->{$role};
 5620:         } else {
 5621:             $rolename = $role;
 5622:         }
 5623:     } else {
 5624:         if ($role eq 'cr') {
 5625:             $rolename = &mt('Custom role');
 5626:         } else {
 5627:             $rolename = &Apache::lonnet::plaintext($role);
 5628:         }
 5629:     }
 5630:     my (@fields,%fieldtitles);
 5631:     if (ref($fieldsref) eq 'ARRAY') {
 5632:         @fields = @{$fieldsref};
 5633:     } else {
 5634:         @fields = ('lastname','firstname','middlename','generation',
 5635:                    'permanentemail','id');
 5636:     }
 5637:     if ((ref($titlesref) eq 'HASH')) {
 5638:         %fieldtitles = %{$titlesref};
 5639:     } else {
 5640:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 5641:     }
 5642:     my $output;
 5643:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 5644:     $output = '<tr '.$css_class.'>'.
 5645:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 5646:               '<td class="LC_left_item" colspan="2"><table>';
 5647:     my $rem;
 5648:     my %checks;
 5649:     if (ref($settings) eq 'HASH') {
 5650:         if (ref($settings->{$context}) eq 'HASH') {
 5651:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 5652:                 my $hashref = $settings->{$context}->{$role};
 5653:                 if ($role eq 'emailusername') {
 5654:                     if ($statustype) {
 5655:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
 5656:                             $hashref = $settings->{$context}->{$role}->{$statustype};
 5657:                             if (ref($hashref) eq 'HASH') { 
 5658:                                 foreach my $field (@fields) {
 5659:                                     if ($hashref->{$field}) {
 5660:                                         $checks{$field} = $hashref->{$field};
 5661:                                     }
 5662:                                 }
 5663:                             }
 5664:                         }
 5665:                     }
 5666:                 } else {
 5667:                     if (ref($hashref) eq 'HASH') {
 5668:                         foreach my $field (@fields) {
 5669:                             if ($hashref->{$field}) {
 5670:                                 $checks{$field} = ' checked="checked" ';
 5671:                             }
 5672:                         }
 5673:                     }
 5674:                 }
 5675:             }
 5676:         }
 5677:     }
 5678:      
 5679:     for (my $i=0; $i<@fields; $i++) {
 5680:         my $rem = $i%($numinrow);
 5681:         if ($rem == 0) {
 5682:             if ($i > 0) {
 5683:                 $output .= '</tr>';
 5684:             }
 5685:             $output .= '<tr>';
 5686:         }
 5687:         my $check = ' ';
 5688:         unless ($role eq 'emailusername') {
 5689:             if (exists($checks{$fields[$i]})) {
 5690:                 $check = $checks{$fields[$i]}
 5691:             } else {
 5692:                 if ($role eq 'st') {
 5693:                     if (ref($settings) ne 'HASH') {
 5694:                         $check = ' checked="checked" '; 
 5695:                     }
 5696:                 }
 5697:             }
 5698:         }
 5699:         $output .= '<td class="LC_left_item">'.
 5700:                    '<span class="LC_nobreak">';
 5701:         if ($role eq 'emailusername') {
 5702:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
 5703:                 $checks{$fields[$i]} = 'omit';
 5704:             }
 5705:             foreach my $option ('required','optional','omit') {
 5706:                 my $checked='';
 5707:                 if ($checks{$fields[$i]} eq $option) {
 5708:                     $checked='checked="checked" ';
 5709:                 }
 5710:                 $output .= '<label>'.
 5711:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
 5712:                            &mt($option).'</label>'.('&nbsp;' x2);
 5713:             }
 5714:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
 5715:         } else {
 5716:             $output .= '<label>'.
 5717:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
 5718:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 5719:                        '</label>';
 5720:         }
 5721:         $output .= '</span></td>';
 5722:         $rem = @fields%($numinrow);
 5723:     }
 5724:     my $colsleft = $numinrow - $rem;
 5725:     if ($colsleft > 1 ) {
 5726:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 5727:                    '&nbsp;</td>';
 5728:     } elsif ($colsleft == 1) {
 5729:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 5730:     }
 5731:     $output .= '</tr></table></td></tr>';
 5732:     return $output;
 5733: }
 5734: 
 5735: sub insttypes_row {
 5736:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
 5737:     my %lt = &Apache::lonlocal::texthash (
 5738:                       cansearch => 'Users allowed to search',
 5739:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
 5740:                       lockablenames => 'User preference to lock name',
 5741:              );
 5742:     my $showdom;
 5743:     if ($context eq 'cansearch') {
 5744:         $showdom = ' ('.$dom.')';
 5745:     }
 5746:     my $class = 'LC_left_item';
 5747:     if ($context eq 'statustocreate') {
 5748:         $class = 'LC_right_item';
 5749:     }
 5750:     my $css_class = ' class="LC_odd_row"';
 5751:     if ($rownum ne '') { 
 5752:         $css_class = ($rownum%2? ' class="LC_odd_row"':'');
 5753:     }
 5754:     my $output = '<tr'.$css_class.'>'.
 5755:                  '<td>'.$lt{$context}.$showdom.
 5756:                  '</td><td class="'.$class.'" colspan="2"><table>';
 5757:     my $rem;
 5758:     if (ref($types) eq 'ARRAY') {
 5759:         for (my $i=0; $i<@{$types}; $i++) {
 5760:             if (defined($usertypes->{$types->[$i]})) {
 5761:                 my $rem = $i%($numinrow);
 5762:                 if ($rem == 0) {
 5763:                     if ($i > 0) {
 5764:                         $output .= '</tr>';
 5765:                     }
 5766:                     $output .= '<tr>';
 5767:                 }
 5768:                 my $check = ' ';
 5769:                 if (ref($settings) eq 'HASH') {
 5770:                     if (ref($settings->{$context}) eq 'ARRAY') {
 5771:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
 5772:                             $check = ' checked="checked" ';
 5773:                         }
 5774:                     } elsif ($context eq 'statustocreate') {
 5775:                         $check = ' checked="checked" ';
 5776:                     }
 5777:                 }
 5778:                 $output .= '<td class="LC_left_item">'.
 5779:                            '<span class="LC_nobreak"><label>'.
 5780:                            '<input type="checkbox" name="'.$context.'" '.
 5781:                            'value="'.$types->[$i].'"'.$check.'/>'.
 5782:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 5783:             }
 5784:         }
 5785:         $rem = @{$types}%($numinrow);
 5786:     }
 5787:     my $colsleft = $numinrow - $rem;
 5788:     if (($rem == 0) && (@{$types} > 0)) {
 5789:         $output .= '<tr>';
 5790:     }
 5791:     if ($colsleft > 1) {
 5792:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 5793:     } else {
 5794:         $output .= '<td class="LC_left_item">';
 5795:     }
 5796:     my $defcheck = ' ';
 5797:     if (ref($settings) eq 'HASH') {  
 5798:         if (ref($settings->{$context}) eq 'ARRAY') {
 5799:             if (grep(/^default$/,@{$settings->{$context}})) {
 5800:                 $defcheck = ' checked="checked" ';
 5801:             }
 5802:         } elsif ($context eq 'statustocreate') {
 5803:             $defcheck = ' checked="checked" ';
 5804:         }
 5805:     }
 5806:     $output .= '<span class="LC_nobreak"><label>'.
 5807:                '<input type="checkbox" name="'.$context.'" '.
 5808:                'value="default"'.$defcheck.'/>'.
 5809:                $othertitle.'</label></span></td>'.
 5810:                '</tr></table></td></tr>';
 5811:     return $output;
 5812: }
 5813: 
 5814: sub sorted_searchtitles {
 5815:     my %searchtitles = &Apache::lonlocal::texthash(
 5816:                          'uname' => 'username',
 5817:                          'lastname' => 'last name',
 5818:                          'lastfirst' => 'last name, first name',
 5819:                      );
 5820:     my @titleorder = ('uname','lastname','lastfirst');
 5821:     return (\%searchtitles,\@titleorder);
 5822: }
 5823: 
 5824: sub sorted_searchtypes {
 5825:     my %srchtypes_desc = (
 5826:                            exact    => 'is exact match',
 5827:                            contains => 'contains ..',
 5828:                            begins   => 'begins with ..',
 5829:                          );
 5830:     my @srchtypeorder = ('exact','begins','contains');
 5831:     return (\%srchtypes_desc,\@srchtypeorder);
 5832: }
 5833: 
 5834: sub usertype_update_row {
 5835:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 5836:     my $datatable;
 5837:     my $numinrow = 4;
 5838:     foreach my $type (@{$types}) {
 5839:         if (defined($usertypes->{$type})) {
 5840:             $$rownums ++;
 5841:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 5842:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 5843:                           '</td><td class="LC_left_item"><table>';
 5844:             for (my $i=0; $i<@{$fields}; $i++) {
 5845:                 my $rem = $i%($numinrow);
 5846:                 if ($rem == 0) {
 5847:                     if ($i > 0) {
 5848:                         $datatable .= '</tr>';
 5849:                     }
 5850:                     $datatable .= '<tr>';
 5851:                 }
 5852:                 my $check = ' ';
 5853:                 if (ref($settings) eq 'HASH') {
 5854:                     if (ref($settings->{'fields'}) eq 'HASH') {
 5855:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 5856:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 5857:                                 $check = ' checked="checked" ';
 5858:                             }
 5859:                         }
 5860:                     }
 5861:                 }
 5862: 
 5863:                 if ($i == @{$fields}-1) {
 5864:                     my $colsleft = $numinrow - $rem;
 5865:                     if ($colsleft > 1) {
 5866:                         $datatable .= '<td colspan="'.$colsleft.'">';
 5867:                     } else {
 5868:                         $datatable .= '<td>';
 5869:                     }
 5870:                 } else {
 5871:                     $datatable .= '<td>';
 5872:                 }
 5873:                 $datatable .= '<span class="LC_nobreak"><label>'.
 5874:                               '<input type="checkbox" name="updateable_'.$type.
 5875:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 5876:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 5877:             }
 5878:             $datatable .= '</tr></table></td></tr>';
 5879:         }
 5880:     }
 5881:     return $datatable;
 5882: }
 5883: 
 5884: sub modify_login {
 5885:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
 5886:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
 5887:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
 5888:     %title = ( coursecatalog => 'Display course catalog',
 5889:                adminmail => 'Display administrator E-mail address',
 5890:                helpdesk  => 'Display "Contact Helpdesk" link',
 5891:                newuser => 'Link for visitors to create a user account',
 5892:                loginheader => 'Log-in box header');
 5893:     @offon = ('off','on');
 5894:     if (ref($domconfig{login}) eq 'HASH') {
 5895:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
 5896:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
 5897:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
 5898:             }
 5899:         }
 5900:     }
 5901:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 5902:                                            \%domconfig,\%loginhash);
 5903:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 5904:     foreach my $item (@toggles) {
 5905:         $loginhash{login}{$item} = $env{'form.'.$item};
 5906:     }
 5907:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 5908:     if (ref($colchanges{'login'}) eq 'HASH') {  
 5909:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 5910:                                          \%loginhash);
 5911:     }
 5912: 
 5913:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 5914:     my %domservers = &Apache::lonnet::get_servers($dom);
 5915:     my @loginvia_attribs = ('serverpath','custompath','exempt');
 5916:     if (keys(%servers) > 1) {
 5917:         foreach my $lonhost (keys(%servers)) {
 5918:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
 5919:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
 5920:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
 5921:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
 5922:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
 5923:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 5924:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 5925:                         $changes{'loginvia'}{$lonhost} = 1;
 5926:                     } else {
 5927:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
 5928:                         $changes{'loginvia'}{$lonhost} = 1;
 5929:                     }
 5930:                 } else {
 5931:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 5932:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 5933:                         $changes{'loginvia'}{$lonhost} = 1;
 5934:                     }
 5935:                 }
 5936:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
 5937:                     foreach my $item (@loginvia_attribs) {
 5938:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
 5939:                     }
 5940:                 } else {
 5941:                     foreach my $item (@loginvia_attribs) {
 5942:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 5943:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 5944:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
 5945:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 5946:                                 $new = '/';
 5947:                             }
 5948:                         }
 5949:                         if (($item eq 'custompath') && 
 5950:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 5951:                             $new = '';
 5952:                         }
 5953:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
 5954:                             $changes{'loginvia'}{$lonhost} = 1;
 5955:                         }
 5956:                         if ($item eq 'exempt') {
 5957:                             $new = &check_exempt_addresses($new);
 5958:                         }
 5959:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 5960:                     }
 5961:                 }
 5962:             } else {
 5963:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 5964:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 5965:                     $changes{'loginvia'}{$lonhost} = 1;
 5966:                     foreach my $item (@loginvia_attribs) {
 5967:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 5968:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 5969:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 5970:                                 $new = '/';
 5971:                             }
 5972:                         }
 5973:                         if (($item eq 'custompath') && 
 5974:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 5975:                             $new = '';
 5976:                         }
 5977:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 5978:                     }
 5979:                 }
 5980:             }
 5981:         }
 5982:     }
 5983: 
 5984:     my $servadm = $r->dir_config('lonAdmEMail');
 5985:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 5986:     if (ref($domconfig{'login'}) eq 'HASH') {
 5987:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
 5988:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
 5989:                 if ($lang eq 'nolang') {
 5990:                     push(@currlangs,$lang);
 5991:                 } elsif (defined($langchoices{$lang})) {
 5992:                     push(@currlangs,$lang);
 5993:                 } else {
 5994:                     next;
 5995:                 }
 5996:             }
 5997:         }
 5998:     }
 5999:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
 6000:     if (@currlangs > 0) {
 6001:         foreach my $lang (@currlangs) {
 6002:             if (grep(/^\Q$lang\E$/,@delurls)) {
 6003:                 $changes{'helpurl'}{$lang} = 1;
 6004:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
 6005:                 $changes{'helpurl'}{$lang} = 1;
 6006:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
 6007:                 push(@newlangs,$lang);
 6008:             } else {
 6009:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 6010:             }
 6011:         }
 6012:     }
 6013:     unless (grep(/^nolang$/,@currlangs)) {
 6014:         if ($env{'form.loginhelpurl_nolang.filename'}) {
 6015:             $changes{'helpurl'}{'nolang'} = 1;
 6016:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
 6017:             push(@newlangs,'nolang');
 6018:         }
 6019:     }
 6020:     if ($env{'form.loginhelpurl_add_lang'}) {
 6021:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
 6022:             ($env{'form.loginhelpurl_add_file.filename'})) {
 6023:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
 6024:             $addedfile = $env{'form.loginhelpurl_add_lang'};
 6025:         }
 6026:     }
 6027:     if ((@newlangs > 0) || ($addedfile)) {
 6028:         my $error;
 6029:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 6030:         if ($configuserok eq 'ok') {
 6031:             if ($switchserver) {
 6032:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
 6033:             } elsif ($author_ok eq 'ok') {
 6034:                 my @allnew = @newlangs;
 6035:                 if ($addedfile ne '') {
 6036:                     push(@allnew,$addedfile);
 6037:                 }
 6038:                 foreach my $lang (@allnew) {
 6039:                     my $formelem = 'loginhelpurl_'.$lang;
 6040:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
 6041:                         $formelem = 'loginhelpurl_add_file';
 6042:                     }
 6043:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
 6044:                                                                "help/$lang",'','',$newfile{$lang});
 6045:                     if ($result eq 'ok') {
 6046:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
 6047:                         $changes{'helpurl'}{$lang} = 1;
 6048:                     } else {
 6049:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
 6050:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
 6051:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
 6052:                             (!grep(/^\Q$lang\E$/,@delurls))) {
 6053: 
 6054:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 6055:                         }
 6056:                     }
 6057:                 }
 6058:             } else {
 6059:                 $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);
 6060:             }
 6061:         } else {
 6062:             $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);
 6063:         }
 6064:         if ($error) {
 6065:             &Apache::lonnet::logthis($error);
 6066:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6067:         }
 6068:     }
 6069: 
 6070:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
 6071:     if (ref($domconfig{'login'}) eq 'HASH') {
 6072:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
 6073:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
 6074:                 if ($domservers{$lonhost}) {
 6075:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
 6076:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
 6077:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
 6078:                     }
 6079:                 }
 6080:             }
 6081:         }
 6082:     }
 6083:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
 6084:     foreach my $lonhost (sort(keys(%domservers))) {
 6085:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
 6086:             $changes{'headtag'}{$lonhost} = 1;
 6087:         } else {
 6088:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
 6089:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
 6090:             }
 6091:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
 6092:                 push(@newhosts,$lonhost);
 6093:             } elsif ($currheadtagurls{$lonhost}) {
 6094:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
 6095:                 if ($currexempt{$lonhost}) {
 6096:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
 6097:                         $changes{'headtag'}{$lonhost} = 1;
 6098:                     }
 6099:                 } elsif ($possexempt{$lonhost}) {
 6100:                     $changes{'headtag'}{$lonhost} = 1;
 6101:                 }
 6102:                 if ($possexempt{$lonhost}) {
 6103:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
 6104:                 }
 6105:             }
 6106:         }
 6107:     }
 6108:     if (@newhosts) {
 6109:         my $error;
 6110:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 6111:         if ($configuserok eq 'ok') {
 6112:             if ($switchserver) {
 6113:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
 6114:             } elsif ($author_ok eq 'ok') {
 6115:                 foreach my $lonhost (@newhosts) {
 6116:                     my $formelem = 'loginheadtag_'.$lonhost;
 6117:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
 6118:                                                                           "login/headtag/$lonhost",'','',
 6119:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
 6120:                     if ($result eq 'ok') {
 6121:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
 6122:                         $changes{'headtag'}{$lonhost} = 1;
 6123:                         if ($possexempt{$lonhost}) {
 6124:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
 6125:                         }
 6126:                     } else {
 6127:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
 6128:                                            $newheadtagurls{$lonhost},$result);
 6129:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
 6130:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
 6131:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
 6132:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
 6133:                         }
 6134:                     }
 6135:                 }
 6136:             } else {
 6137:                 $error = &mt("Upload of custom markup 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);
 6138:             }
 6139:         } else {
 6140:             $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
 6141:         }
 6142:         if ($error) {
 6143:             &Apache::lonnet::logthis($error);
 6144:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6145:         }
 6146:     }
 6147: 
 6148:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
 6149: 
 6150:     my $defaulthelpfile = '/adm/loginproblems.html';
 6151:     my $defaulttext = &mt('Default in use');
 6152: 
 6153:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 6154:                                              $dom);
 6155:     if ($putresult eq 'ok') {
 6156:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 6157:         my %defaultchecked = (
 6158:                     'coursecatalog' => 'on',
 6159:                     'helpdesk'      => 'on',
 6160:                     'adminmail'     => 'off',
 6161:                     'newuser'       => 'off',
 6162:         );
 6163:         if (ref($domconfig{'login'}) eq 'HASH') {
 6164:             foreach my $item (@toggles) {
 6165:                 if ($defaultchecked{$item} eq 'on') { 
 6166:                     if (($domconfig{'login'}{$item} eq '0') &&
 6167:                         ($env{'form.'.$item} eq '1')) {
 6168:                         $changes{$item} = 1;
 6169:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 6170:                               $domconfig{'login'}{$item} eq '1') &&
 6171:                              ($env{'form.'.$item} eq '0')) {
 6172:                         $changes{$item} = 1;
 6173:                     }
 6174:                 } elsif ($defaultchecked{$item} eq 'off') {
 6175:                     if (($domconfig{'login'}{$item} eq '1') &&
 6176:                         ($env{'form.'.$item} eq '0')) {
 6177:                         $changes{$item} = 1;
 6178:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 6179:                               $domconfig{'login'}{$item} eq '0') &&
 6180:                              ($env{'form.'.$item} eq '1')) {
 6181:                         $changes{$item} = 1;
 6182:                     }
 6183:                 }
 6184:             }
 6185:         }
 6186:         if (keys(%changes) > 0 || $colchgtext) {
 6187:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 6188:             if (ref($lastactref) eq 'HASH') {
 6189:                 $lastactref->{'domainconfig'} = 1;
 6190:             }
 6191:             $resulttext = &mt('Changes made:').'<ul>';
 6192:             foreach my $item (sort(keys(%changes))) {
 6193:                 if ($item eq 'loginvia') {
 6194:                     if (ref($changes{$item}) eq 'HASH') {
 6195:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
 6196:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 6197:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
 6198:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
 6199:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
 6200:                                     $protocol = 'http' if ($protocol ne 'https');
 6201:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
 6202: 
 6203:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
 6204:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
 6205:                                     } else {
 6206:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
 6207:                                     }
 6208:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
 6209:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
 6210:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
 6211:                                     }
 6212:                                     $resulttext .= '</li>';
 6213:                                 } else {
 6214:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
 6215:                                 }
 6216:                             } else {
 6217:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
 6218:                             }
 6219:                         }
 6220:                         $resulttext .= '</ul></li>';
 6221:                     }
 6222:                 } elsif ($item eq 'helpurl') {
 6223:                     if (ref($changes{$item}) eq 'HASH') {
 6224:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
 6225:                             if (grep(/^\Q$lang\E$/,@delurls)) {
 6226:                                 my ($chg,$link);
 6227:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
 6228:                                 if ($lang eq 'nolang') {
 6229:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
 6230:                                 } else {
 6231:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
 6232:                                 }
 6233:                                 $resulttext .= '<li>'.$chg.'</li>';
 6234:                             } else {
 6235:                                 my $chg;
 6236:                                 if ($lang eq 'nolang') {
 6237:                                     $chg = &mt('custom log-in help file for no preferred language');
 6238:                                 } else {
 6239:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
 6240:                                 }
 6241:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
 6242:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
 6243:                                                       '?inhibitmenu=yes',$chg,600,500).
 6244:                                                '</li>';
 6245:                             }
 6246:                         }
 6247:                     }
 6248:                 } elsif ($item eq 'headtag') {
 6249:                     if (ref($changes{$item}) eq 'HASH') {
 6250:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 6251:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
 6252:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
 6253:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
 6254:                                 $resulttext .= '<li><a href="'.
 6255:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
 6256:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
 6257:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
 6258:                                 if ($possexempt{$lonhost}) {
 6259:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
 6260:                                 } else {
 6261:                                     $resulttext .= &mt('included for any client IP');
 6262:                                 }
 6263:                                 $resulttext .= '</li>';
 6264:                             }
 6265:                         }
 6266:                     }
 6267:                 } elsif ($item eq 'captcha') {
 6268:                     if (ref($loginhash{'login'}) eq 'HASH') {
 6269:                         my $chgtxt;
 6270:                         if ($loginhash{'login'}{$item} eq 'notused') {
 6271:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
 6272:                         } else {
 6273:                             my %captchas = &captcha_phrases();
 6274:                             if ($captchas{$loginhash{'login'}{$item}}) {
 6275:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
 6276:                             } else {
 6277:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
 6278:                             }
 6279:                         }
 6280:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 6281:                     }
 6282:                 } elsif ($item eq 'recaptchakeys') {
 6283:                     if (ref($loginhash{'login'}) eq 'HASH') {
 6284:                         my ($privkey,$pubkey);
 6285:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
 6286:                             $pubkey = $loginhash{'login'}{$item}{'public'};
 6287:                             $privkey = $loginhash{'login'}{$item}{'private'};
 6288:                         }
 6289:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
 6290:                         if (!$pubkey) {
 6291:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
 6292:                         } else {
 6293:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 6294:                         }
 6295:                         if (!$privkey) {
 6296:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
 6297:                         } else {
 6298:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
 6299:                         }
 6300:                         $chgtxt .= '</ul>';
 6301:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 6302:                     }
 6303:                 } else {
 6304:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 6305:                 }
 6306:             }
 6307:             $resulttext .= $colchgtext.'</ul>';
 6308:         } else {
 6309:             $resulttext = &mt('No changes made to log-in page settings');
 6310:         }
 6311:     } else {
 6312:         $resulttext = '<span class="LC_error">'.
 6313: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6314:     }
 6315:     if ($errors) {
 6316:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 6317:                        $errors.'</ul>';
 6318:     }
 6319:     return $resulttext;
 6320: }
 6321: 
 6322: sub check_exempt_addresses {
 6323:     my ($iplist) = @_;
 6324:     $iplist =~ s/^\s+//;
 6325:     $iplist =~ s/\s+$//;
 6326:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
 6327:     my (@okips,$new);
 6328:     foreach my $ip (@poss_ips) {
 6329:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
 6330:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
 6331:                 push(@okips,$ip);
 6332:             }
 6333:         }
 6334:     }
 6335:     if (@okips > 0) {
 6336:         $new = join(',',@okips);
 6337:     } else {
 6338:         $new = '';
 6339:     }
 6340:     return $new;
 6341: }
 6342: 
 6343: sub color_font_choices {
 6344:     my %choices =
 6345:         &Apache::lonlocal::texthash (
 6346:             img => "Header",
 6347:             bgs => "Background colors",
 6348:             links => "Link colors",
 6349:             images => "Images",
 6350:             font => "Font color",
 6351:             fontmenu => "Font menu",
 6352:             pgbg => "Page",
 6353:             tabbg => "Header",
 6354:             sidebg => "Border",
 6355:             link => "Link",
 6356:             alink => "Active link",
 6357:             vlink => "Visited link",
 6358:         );
 6359:     return %choices;
 6360: }
 6361: 
 6362: sub modify_rolecolors {
 6363:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
 6364:     my ($resulttext,%rolehash);
 6365:     $rolehash{'rolecolors'} = {};
 6366:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 6367:         if ($domconfig{'rolecolors'} eq '') {
 6368:             $domconfig{'rolecolors'} = {};
 6369:         }
 6370:     }
 6371:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 6372:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 6373:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 6374:                                              $dom);
 6375:     if ($putresult eq 'ok') {
 6376:         if (keys(%changes) > 0) {
 6377:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 6378:             if (ref($lastactref) eq 'HASH') {
 6379:                 $lastactref->{'domainconfig'} = 1;
 6380:             }
 6381:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 6382:                                              $rolehash{'rolecolors'});
 6383:         } else {
 6384:             $resulttext = &mt('No changes made to default color schemes');
 6385:         }
 6386:     } else {
 6387:         $resulttext = '<span class="LC_error">'.
 6388: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6389:     }
 6390:     if ($errors) {
 6391:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 6392:                        $errors.'</ul>';
 6393:     }
 6394:     return $resulttext;
 6395: }
 6396: 
 6397: sub modify_colors {
 6398:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 6399:     my (%changes,%choices);
 6400:     my @bgs;
 6401:     my @links = ('link','alink','vlink');
 6402:     my @logintext;
 6403:     my @images;
 6404:     my $servadm = $r->dir_config('lonAdmEMail');
 6405:     my $errors;
 6406:     my %defaults;
 6407:     foreach my $role (@{$roles}) {
 6408:         if ($role eq 'login') {
 6409:             %choices = &login_choices();
 6410:             @logintext = ('textcol','bgcol');
 6411:         } else {
 6412:             %choices = &color_font_choices();
 6413:         }
 6414:         if ($role eq 'login') {
 6415:             @images = ('img','logo','domlogo','login');
 6416:             @bgs = ('pgbg','mainbg','sidebg');
 6417:         } else {
 6418:             @images = ('img');
 6419:             @bgs = ('pgbg','tabbg','sidebg');
 6420:         }
 6421:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
 6422:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
 6423:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 6424:         }
 6425:         if ($role eq 'login') {
 6426:             foreach my $item (@logintext) {
 6427:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
 6428:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
 6429:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
 6430:                 }
 6431:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
 6432:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 6433:                 }
 6434:             }
 6435:         } else {
 6436:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
 6437:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
 6438:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
 6439:             }
 6440:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
 6441:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
 6442:             }
 6443:         }
 6444:         foreach my $item (@bgs) {
 6445:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
 6446:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
 6447:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
 6448:             }
 6449:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
 6450:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 6451:             }
 6452:         }
 6453:         foreach my $item (@links) {
 6454:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
 6455:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
 6456:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
 6457:             }
 6458:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
 6459:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 6460:             }
 6461:         }
 6462:         my ($configuserok,$author_ok,$switchserver) = 
 6463:             &config_check($dom,$confname,$servadm);
 6464:         my ($width,$height) = &thumb_dimensions();
 6465:         if (ref($domconfig->{$role}) ne 'HASH') {
 6466:             $domconfig->{$role} = {};
 6467:         }
 6468:         foreach my $img (@images) {
 6469:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 6470:                 if (defined($env{'form.login_showlogo_'.$img})) {
 6471:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 6472:                 } else { 
 6473:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 6474:                 }
 6475:             } 
 6476: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 6477: 		 && !defined($domconfig->{$role}{$img})
 6478: 		 && !$env{'form.'.$role.'_del_'.$img}
 6479: 		 && $env{'form.'.$role.'_import_'.$img}) {
 6480: 		# import the old configured image from the .tab setting
 6481: 		# if they haven't provided a new one 
 6482: 		$domconfig->{$role}{$img} = 
 6483: 		    $env{'form.'.$role.'_import_'.$img};
 6484: 	    }
 6485:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 6486:                 my $error;
 6487:                 if ($configuserok eq 'ok') {
 6488:                     if ($switchserver) {
 6489:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 6490:                     } else {
 6491:                         if ($author_ok eq 'ok') {
 6492:                             my ($result,$logourl) = 
 6493:                                 &publishlogo($r,'upload',$role.'_'.$img,
 6494:                                            $dom,$confname,$img,$width,$height);
 6495:                             if ($result eq 'ok') {
 6496:                                 $confhash->{$role}{$img} = $logourl;
 6497:                                 $changes{$role}{'images'}{$img} = 1;
 6498:                             } else {
 6499:                                 $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);
 6500:                             }
 6501:                         } else {
 6502:                             $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);
 6503:                         }
 6504:                     }
 6505:                 } else {
 6506:                     $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);
 6507:                 }
 6508:                 if ($error) {
 6509:                     &Apache::lonnet::logthis($error);
 6510:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6511:                 }
 6512:             } elsif ($domconfig->{$role}{$img} ne '') {
 6513:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 6514:                     my $error;
 6515:                     if ($configuserok eq 'ok') {
 6516: # is confname an author?
 6517:                         if ($switchserver eq '') {
 6518:                             if ($author_ok eq 'ok') {
 6519:                                 my ($result,$logourl) = 
 6520:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 6521:                                             $dom,$confname,$img,$width,$height);
 6522:                                 if ($result eq 'ok') {
 6523:                                     $confhash->{$role}{$img} = $logourl;
 6524: 				    $changes{$role}{'images'}{$img} = 1;
 6525:                                 }
 6526:                             }
 6527:                         }
 6528:                     }
 6529:                 }
 6530:             }
 6531:         }
 6532:         if (ref($domconfig) eq 'HASH') {
 6533:             if (ref($domconfig->{$role}) eq 'HASH') {
 6534:                 foreach my $img (@images) {
 6535:                     if ($domconfig->{$role}{$img} ne '') {
 6536:                         if ($env{'form.'.$role.'_del_'.$img}) {
 6537:                             $confhash->{$role}{$img} = '';
 6538:                             $changes{$role}{'images'}{$img} = 1;
 6539:                         } else {
 6540:                             if ($confhash->{$role}{$img} eq '') {
 6541:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 6542:                             }
 6543:                         }
 6544:                     } else {
 6545:                         if ($env{'form.'.$role.'_del_'.$img}) {
 6546:                             $confhash->{$role}{$img} = '';
 6547:                             $changes{$role}{'images'}{$img} = 1;
 6548:                         } 
 6549:                     }
 6550:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 6551:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 6552:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 6553:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 6554:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 6555:                             }
 6556:                         } else {
 6557:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 6558:                                 $changes{$role}{'showlogo'}{$img} = 1;
 6559:                             }
 6560:                         }
 6561:                     }
 6562:                 }
 6563:                 if ($domconfig->{$role}{'font'} ne '') {
 6564:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 6565:                         $changes{$role}{'font'} = 1;
 6566:                     }
 6567:                 } else {
 6568:                     if ($confhash->{$role}{'font'}) {
 6569:                         $changes{$role}{'font'} = 1;
 6570:                     }
 6571:                 }
 6572:                 if ($role ne 'login') {
 6573:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
 6574:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
 6575:                             $changes{$role}{'fontmenu'} = 1;
 6576:                         }
 6577:                     } else {
 6578:                         if ($confhash->{$role}{'fontmenu'}) {
 6579:                             $changes{$role}{'fontmenu'} = 1;
 6580:                         }
 6581:                     }
 6582:                 }
 6583:                 foreach my $item (@bgs) {
 6584:                     if ($domconfig->{$role}{$item} ne '') {
 6585:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 6586:                             $changes{$role}{'bgs'}{$item} = 1;
 6587:                         } 
 6588:                     } else {
 6589:                         if ($confhash->{$role}{$item}) {
 6590:                             $changes{$role}{'bgs'}{$item} = 1;
 6591:                         }
 6592:                     }
 6593:                 }
 6594:                 foreach my $item (@links) {
 6595:                     if ($domconfig->{$role}{$item} ne '') {
 6596:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 6597:                             $changes{$role}{'links'}{$item} = 1;
 6598:                         }
 6599:                     } else {
 6600:                         if ($confhash->{$role}{$item}) {
 6601:                             $changes{$role}{'links'}{$item} = 1;
 6602:                         }
 6603:                     }
 6604:                 }
 6605:                 foreach my $item (@logintext) {
 6606:                     if ($domconfig->{$role}{$item} ne '') {
 6607:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 6608:                             $changes{$role}{'logintext'}{$item} = 1;
 6609:                         }
 6610:                     } else {
 6611:                         if ($confhash->{$role}{$item}) {
 6612:                             $changes{$role}{'logintext'}{$item} = 1;
 6613:                         }
 6614:                     }
 6615:                 }
 6616:             } else {
 6617:                 &default_change_checker($role,\@images,\@links,\@bgs,
 6618:                                         \@logintext,$confhash,\%changes); 
 6619:             }
 6620:         } else {
 6621:             &default_change_checker($role,\@images,\@links,\@bgs,
 6622:                                     \@logintext,$confhash,\%changes); 
 6623:         }
 6624:     }
 6625:     return ($errors,%changes);
 6626: }
 6627: 
 6628: sub config_check {
 6629:     my ($dom,$confname,$servadm) = @_;
 6630:     my ($configuserok,$author_ok,$switchserver,%currroles);
 6631:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 6632:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 6633:                                                    $confname,$servadm);
 6634:     if ($configuserok eq 'ok') {
 6635:         $switchserver = &check_switchserver($dom,$confname);
 6636:         if ($switchserver eq '') {
 6637:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 6638:         }
 6639:     }
 6640:     return ($configuserok,$author_ok,$switchserver);
 6641: }
 6642: 
 6643: sub default_change_checker {
 6644:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 6645:     foreach my $item (@{$links}) {
 6646:         if ($confhash->{$role}{$item}) {
 6647:             $changes->{$role}{'links'}{$item} = 1;
 6648:         }
 6649:     }
 6650:     foreach my $item (@{$bgs}) {
 6651:         if ($confhash->{$role}{$item}) {
 6652:             $changes->{$role}{'bgs'}{$item} = 1;
 6653:         }
 6654:     }
 6655:     foreach my $item (@{$logintext}) {
 6656:         if ($confhash->{$role}{$item}) {
 6657:             $changes->{$role}{'logintext'}{$item} = 1;
 6658:         }
 6659:     }
 6660:     foreach my $img (@{$images}) {
 6661:         if ($env{'form.'.$role.'_del_'.$img}) {
 6662:             $confhash->{$role}{$img} = '';
 6663:             $changes->{$role}{'images'}{$img} = 1;
 6664:         }
 6665:         if ($role eq 'login') {
 6666:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 6667:                 $changes->{$role}{'showlogo'}{$img} = 1;
 6668:             }
 6669:         }
 6670:     }
 6671:     if ($confhash->{$role}{'font'}) {
 6672:         $changes->{$role}{'font'} = 1;
 6673:     }
 6674: }
 6675: 
 6676: sub display_colorchgs {
 6677:     my ($dom,$changes,$roles,$confhash) = @_;
 6678:     my (%choices,$resulttext);
 6679:     if (!grep(/^login$/,@{$roles})) {
 6680:         $resulttext = &mt('Changes made:').'<br />';
 6681:     }
 6682:     foreach my $role (@{$roles}) {
 6683:         if ($role eq 'login') {
 6684:             %choices = &login_choices();
 6685:         } else {
 6686:             %choices = &color_font_choices();
 6687:         }
 6688:         if (ref($changes->{$role}) eq 'HASH') {
 6689:             if ($role ne 'login') {
 6690:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 6691:             }
 6692:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 6693:                 if ($role ne 'login') {
 6694:                     $resulttext .= '<ul>';
 6695:                 }
 6696:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 6697:                     if ($role ne 'login') {
 6698:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 6699:                     }
 6700:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 6701:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 6702:                             if ($confhash->{$role}{$key}{$item}) {
 6703:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 6704:                             } else {
 6705:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 6706:                             }
 6707:                         } elsif ($confhash->{$role}{$item} eq '') {
 6708:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 6709:                         } else {
 6710:                             my $newitem = $confhash->{$role}{$item};
 6711:                             if ($key eq 'images') {
 6712:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 6713:                             }
 6714:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 6715:                         }
 6716:                     }
 6717:                     if ($role ne 'login') {
 6718:                         $resulttext .= '</ul></li>';
 6719:                     }
 6720:                 } else {
 6721:                     if ($confhash->{$role}{$key} eq '') {
 6722:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 6723:                     } else {
 6724:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 6725:                     }
 6726:                 }
 6727:                 if ($role ne 'login') {
 6728:                     $resulttext .= '</ul>';
 6729:                 }
 6730:             }
 6731:         }
 6732:     }
 6733:     return $resulttext;
 6734: }
 6735: 
 6736: sub thumb_dimensions {
 6737:     return ('200','50');
 6738: }
 6739: 
 6740: sub check_dimensions {
 6741:     my ($inputfile) = @_;
 6742:     my ($fullwidth,$fullheight);
 6743:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 6744:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 6745:             my $imageinfo = <PIPE>;
 6746:             if (!close(PIPE)) {
 6747:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 6748:             }
 6749:             chomp($imageinfo);
 6750:             my ($fullsize) = 
 6751:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 6752:             if ($fullsize) {
 6753:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 6754:             }
 6755:         }
 6756:     }
 6757:     return ($fullwidth,$fullheight);
 6758: }
 6759: 
 6760: sub check_configuser {
 6761:     my ($uhome,$dom,$confname,$servadm) = @_;
 6762:     my ($configuserok,%currroles);
 6763:     if ($uhome eq 'no_host') {
 6764:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 6765:         my $configpass = &LONCAPA::Enrollment::create_password();
 6766:         $configuserok = 
 6767:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 6768:                              $configpass,'','','','','',undef,$servadm);
 6769:     } else {
 6770:         $configuserok = 'ok';
 6771:         %currroles = 
 6772:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 6773:     }
 6774:     return ($configuserok,%currroles);
 6775: }
 6776: 
 6777: sub check_authorstatus {
 6778:     my ($dom,$confname,%currroles) = @_;
 6779:     my $author_ok;
 6780:     if (!$currroles{':'.$dom.':au'}) {
 6781:         my $start = time;
 6782:         my $end = 0;
 6783:         $author_ok = 
 6784:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 6785:                                         'au',$end,$start,'','','domconfig');
 6786:     } else {
 6787:         $author_ok = 'ok';
 6788:     }
 6789:     return $author_ok;
 6790: }
 6791: 
 6792: sub publishlogo {
 6793:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 6794:     my ($output,$fname,$logourl);
 6795:     if ($action eq 'upload') {
 6796:         $fname=$env{'form.'.$formname.'.filename'};
 6797:         chop($env{'form.'.$formname});
 6798:     } else {
 6799:         ($fname) = ($formname =~ /([^\/]+)$/);
 6800:     }
 6801:     if ($savefileas ne '') {
 6802:         $fname = $savefileas;
 6803:     }
 6804:     $fname=&Apache::lonnet::clean_filename($fname);
 6805: # See if there is anything left
 6806:     unless ($fname) { return ('error: no uploaded file'); }
 6807:     $fname="$subdir/$fname";
 6808:     my $docroot=$r->dir_config('lonDocRoot');
 6809:     my $filepath="$docroot/priv";
 6810:     my $relpath = "$dom/$confname";
 6811:     my ($fnamepath,$file,$fetchthumb);
 6812:     $file=$fname;
 6813:     if ($fname=~m|/|) {
 6814:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 6815:     }
 6816:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
 6817:     my $count;
 6818:     for ($count=5;$count<=$#parts;$count++) {
 6819:         $filepath.="/$parts[$count]";
 6820:         if ((-e $filepath)!=1) {
 6821:             mkdir($filepath,02770);
 6822:         }
 6823:     }
 6824:     # Check for bad extension and disallow upload
 6825:     if ($file=~/\.(\w+)$/ &&
 6826:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 6827:         $output = 
 6828:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
 6829:     } elsif ($file=~/\.(\w+)$/ &&
 6830:         !defined(&Apache::loncommon::fileembstyle($1))) {
 6831:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 6832:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 6833:         $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 6834:     } elsif (-d "$filepath/$file") {
 6835:         $output = &mt('Filename is a directory name - rename the file and re-upload');
 6836:     } else {
 6837:         my $source = $filepath.'/'.$file;
 6838:         my $logfile;
 6839:         if (!open($logfile,">>$source".'.log')) {
 6840:             return (&mt('No write permission to Authoring Space'));
 6841:         }
 6842:         print $logfile
 6843: "\n================= Publish ".localtime()." ================\n".
 6844: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 6845: # Save the file
 6846:         if (!open(FH,'>'.$source)) {
 6847:             &Apache::lonnet::logthis('Failed to create '.$source);
 6848:             return (&mt('Failed to create file'));
 6849:         }
 6850:         if ($action eq 'upload') {
 6851:             if (!print FH ($env{'form.'.$formname})) {
 6852:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 6853:                 return (&mt('Failed to write file'));
 6854:             }
 6855:         } else {
 6856:             my $original = &Apache::lonnet::filelocation('',$formname);
 6857:             if(!copy($original,$source)) {
 6858:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 6859:                 return (&mt('Failed to write file'));
 6860:             }
 6861:         }
 6862:         close(FH);
 6863:         chmod(0660, $source); # Permissions to rw-rw---.
 6864: 
 6865:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 6866:         my $copyfile=$targetdir.'/'.$file;
 6867: 
 6868:         my @parts=split(/\//,$targetdir);
 6869:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 6870:         for (my $count=5;$count<=$#parts;$count++) {
 6871:             $path.="/$parts[$count]";
 6872:             if (!-e $path) {
 6873:                 print $logfile "\nCreating directory ".$path;
 6874:                 mkdir($path,02770);
 6875:             }
 6876:         }
 6877:         my $versionresult;
 6878:         if (-e $copyfile) {
 6879:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 6880:         } else {
 6881:             $versionresult = 'ok';
 6882:         }
 6883:         if ($versionresult eq 'ok') {
 6884:             if (copy($source,$copyfile)) {
 6885:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 6886:                 $output = 'ok';
 6887:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 6888:                 push(@{$modified_urls},[$copyfile,$source]);
 6889:                 my $metaoutput = 
 6890:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 6891:                 unless ($registered_cleanup) {
 6892:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 6893:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 6894:                     $registered_cleanup=1;
 6895:                 }
 6896:             } else {
 6897:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 6898:                 $output = &mt('Failed to copy file to RES space').", $!";
 6899:             }
 6900:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 6901:                 my $inputfile = $filepath.'/'.$file;
 6902:                 my $outfile = $filepath.'/'.'tn-'.$file;
 6903:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 6904:                 if ($fullwidth ne '' && $fullheight ne '') { 
 6905:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 6906:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 6907:                         system("convert -sample $thumbsize $inputfile $outfile");
 6908:                         chmod(0660, $filepath.'/tn-'.$file);
 6909:                         if (-e $outfile) {
 6910:                             my $copyfile=$targetdir.'/tn-'.$file;
 6911:                             if (copy($outfile,$copyfile)) {
 6912:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 6913:                                 my $thumb_metaoutput = 
 6914:                                     &write_metadata($dom,$confname,$formname,
 6915:                                                     $targetdir,'tn-'.$file,$logfile);
 6916:                                 push(@{$modified_urls},[$copyfile,$outfile]);
 6917:                                 unless ($registered_cleanup) {
 6918:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 6919:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 6920:                                     $registered_cleanup=1;
 6921:                                 }
 6922:                             } else {
 6923:                                 print $logfile "\nUnable to write ".$copyfile.
 6924:                                                ':'.$!."\n";
 6925:                             }
 6926:                         }
 6927:                     }
 6928:                 }
 6929:             }
 6930:         } else {
 6931:             $output = $versionresult;
 6932:         }
 6933:     }
 6934:     return ($output,$logourl);
 6935: }
 6936: 
 6937: sub logo_versioning {
 6938:     my ($targetdir,$file,$logfile) = @_;
 6939:     my $target = $targetdir.'/'.$file;
 6940:     my ($maxversion,$fn,$extn,$output);
 6941:     $maxversion = 0;
 6942:     if ($file =~ /^(.+)\.(\w+)$/) {
 6943:         $fn=$1;
 6944:         $extn=$2;
 6945:     }
 6946:     opendir(DIR,$targetdir);
 6947:     while (my $filename=readdir(DIR)) {
 6948:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 6949:             $maxversion=($1>$maxversion)?$1:$maxversion;
 6950:         }
 6951:     }
 6952:     $maxversion++;
 6953:     print $logfile "\nCreating old version ".$maxversion."\n";
 6954:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 6955:     if (copy($target,$copyfile)) {
 6956:         print $logfile "Copied old target to ".$copyfile."\n";
 6957:         $copyfile=$copyfile.'.meta';
 6958:         if (copy($target.'.meta',$copyfile)) {
 6959:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 6960:             $output = 'ok';
 6961:         } else {
 6962:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 6963:             $output = &mt('Failed to copy old meta').", $!, ";
 6964:         }
 6965:     } else {
 6966:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 6967:         $output = &mt('Failed to copy old target').", $!, ";
 6968:     }
 6969:     return $output;
 6970: }
 6971: 
 6972: sub write_metadata {
 6973:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 6974:     my (%metadatafields,%metadatakeys,$output);
 6975:     $metadatafields{'title'}=$formname;
 6976:     $metadatafields{'creationdate'}=time;
 6977:     $metadatafields{'lastrevisiondate'}=time;
 6978:     $metadatafields{'copyright'}='public';
 6979:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 6980:                                          $env{'user.domain'};
 6981:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 6982:     $metadatafields{'domain'}=$dom;
 6983:     {
 6984:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 6985:         my $mfh;
 6986:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 6987:             foreach (sort(keys(%metadatafields))) {
 6988:                 unless ($_=~/\./) {
 6989:                     my $unikey=$_;
 6990:                     $unikey=~/^([A-Za-z]+)/;
 6991:                     my $tag=$1;
 6992:                     $tag=~tr/A-Z/a-z/;
 6993:                     print $mfh "\n\<$tag";
 6994:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
 6995:                         my $value=$metadatafields{$unikey.'.'.$_};
 6996:                         $value=~s/\"/\'\'/g;
 6997:                         print $mfh ' '.$_.'="'.$value.'"';
 6998:                     }
 6999:                     print $mfh '>'.
 7000:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 7001:                             .'</'.$tag.'>';
 7002:                 }
 7003:             }
 7004:             $output = 'ok';
 7005:             print $logfile "\nWrote metadata";
 7006:             close($mfh);
 7007:         } else {
 7008:             print $logfile "\nFailed to open metadata file";
 7009:             $output = &mt('Could not write metadata');
 7010:         }
 7011:     }
 7012:     return $output;
 7013: }
 7014: 
 7015: sub notifysubscribed {
 7016:     foreach my $targetsource (@{$modified_urls}){
 7017:         next unless (ref($targetsource) eq 'ARRAY');
 7018:         my ($target,$source)=@{$targetsource};
 7019:         if ($source ne '') {
 7020:             if (open(my $logfh,'>>'.$source.'.log')) {
 7021:                 print $logfh "\nCleanup phase: Notifications\n";
 7022:                 my @subscribed=&subscribed_hosts($target);
 7023:                 foreach my $subhost (@subscribed) {
 7024:                     print $logfh "\nNotifying host ".$subhost.':';
 7025:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
 7026:                     print $logfh $reply;
 7027:                 }
 7028:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
 7029:                 foreach my $subhost (@subscribedmeta) {
 7030:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
 7031:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
 7032:                                                         $subhost);
 7033:                     print $logfh $reply;
 7034:                 }
 7035:                 print $logfh "\n============ Done ============\n";
 7036:                 close($logfh);
 7037:             }
 7038:         }
 7039:     }
 7040:     return OK;
 7041: }
 7042: 
 7043: sub subscribed_hosts {
 7044:     my ($target) = @_;
 7045:     my @subscribed;
 7046:     if (open(my $fh,"<$target.subscription")) {
 7047:         while (my $subline=<$fh>) {
 7048:             if ($subline =~ /^($match_lonid):/) {
 7049:                 my $host = $1;
 7050:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
 7051:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
 7052:                         push(@subscribed,$host);
 7053:                     }
 7054:                 }
 7055:             }
 7056:         }
 7057:     }
 7058:     return @subscribed;
 7059: }
 7060: 
 7061: sub check_switchserver {
 7062:     my ($dom,$confname) = @_;
 7063:     my ($allowed,$switchserver);
 7064:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 7065:     if ($home eq 'no_host') {
 7066:         $home = &Apache::lonnet::domain($dom,'primary');
 7067:     }
 7068:     my @ids=&Apache::lonnet::current_machine_ids();
 7069:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 7070:     if (!$allowed) {
 7071: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
 7072:     }
 7073:     return $switchserver;
 7074: }
 7075: 
 7076: sub modify_quotas {
 7077:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
 7078:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
 7079:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
 7080:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
 7081:         $validationfieldsref);
 7082:     if ($action eq 'quotas') {
 7083:         $context = 'tools'; 
 7084:     } else {
 7085:         $context = $action;
 7086:     }
 7087:     if ($context eq 'requestcourses') {
 7088:         @usertools = ('official','unofficial','community','textbook');
 7089:         @options =('norequest','approval','validate','autolimit');
 7090:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 7091:         %titles = &courserequest_titles();
 7092:         $toolregexp = join('|',@usertools);
 7093:         %conditions = &courserequest_conditions();
 7094:         $confname = $dom.'-domainconfig';
 7095:         my $servadm = $r->dir_config('lonAdmEMail');
 7096:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 7097:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
 7098:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
 7099:     } elsif ($context eq 'requestauthor') {
 7100:         @usertools = ('author');
 7101:         %titles = &authorrequest_titles();
 7102:     } else {
 7103:         @usertools = ('aboutme','blog','webdav','portfolio');
 7104:         %titles = &tool_titles();
 7105:     }
 7106:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
 7107:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 7108:     foreach my $key (keys(%env)) {
 7109:         if ($context eq 'requestcourses') {
 7110:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
 7111:                 my $item = $1;
 7112:                 my $type = $2;
 7113:                 if ($type =~ /^limit_(.+)/) {
 7114:                     $limithash{$item}{$1} = $env{$key};
 7115:                 } else {
 7116:                     $confhash{$item}{$type} = $env{$key};
 7117:                 }
 7118:             }
 7119:         } elsif ($context eq 'requestauthor') {
 7120:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
 7121:                 $confhash{$1} = $env{$key};
 7122:             }
 7123:         } else {
 7124:             if ($key =~ /^form\.quota_(.+)$/) {
 7125:                 $confhash{'defaultquota'}{$1} = $env{$key};
 7126:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
 7127:                 $confhash{'authorquota'}{$1} = $env{$key};
 7128:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
 7129:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 7130:             }
 7131:         }
 7132:     }
 7133:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 7134:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
 7135:         @approvalnotify = sort(@approvalnotify);
 7136:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
 7137:         my @crstypes = ('official','unofficial','community','textbook');
 7138:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
 7139:         foreach my $type (@hasuniquecode) {
 7140:             if (grep(/^\Q$type\E$/,@crstypes)) {
 7141:                 $confhash{'uniquecode'}{$type} = 1;
 7142:             }
 7143:         }
 7144:         my (%newbook,%allpos);
 7145:         if ($context eq 'requestcourses') {
 7146:             foreach my $type ('textbooks','templates') {
 7147:                 @{$allpos{$type}} = (); 
 7148:                 my $invalid;
 7149:                 if ($type eq 'textbooks') {
 7150:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
 7151:                 } else {
 7152:                     $invalid = &mt('Invalid LON-CAPA course for template');
 7153:                 }
 7154:                 if ($env{'form.'.$type.'_addbook'}) {
 7155:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
 7156:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
 7157:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
 7158:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
 7159:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
 7160:                         } else {
 7161:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
 7162:                             my $position = $env{'form.'.$type.'_addbook_pos'};
 7163:                             $position =~ s/\D+//g;
 7164:                             if ($position ne '') {
 7165:                                 $allpos{$type}[$position] = $newbook{$type};
 7166:                             }
 7167:                         }
 7168:                     } else {
 7169:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
 7170:                     }
 7171:                 }
 7172:             } 
 7173:         }
 7174:         if (ref($domconfig{$action}) eq 'HASH') {
 7175:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
 7176:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
 7177:                     $changes{'notify'}{'approval'} = 1;
 7178:                 }
 7179:             } else {
 7180:                 if ($confhash{'notify'}{'approval'}) {
 7181:                     $changes{'notify'}{'approval'} = 1;
 7182:                 }
 7183:             }
 7184:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
 7185:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
 7186:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
 7187:                         unless ($confhash{'uniquecode'}{$crstype}) {
 7188:                             $changes{'uniquecode'} = 1;
 7189:                         }
 7190:                     }
 7191:                     unless ($changes{'uniquecode'}) {
 7192:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
 7193:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
 7194:                                 $changes{'uniquecode'} = 1;
 7195:                             }
 7196:                         }
 7197:                     }
 7198:                } else {
 7199:                    $changes{'uniquecode'} = 1;
 7200:                }
 7201:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
 7202:                 $changes{'uniquecode'} = 1;
 7203:             }
 7204:             if ($context eq 'requestcourses') {
 7205:                 foreach my $type ('textbooks','templates') {
 7206:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
 7207:                         my %deletions;
 7208:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
 7209:                         if (@todelete) {
 7210:                             map { $deletions{$_} = 1; } @todelete;
 7211:                         }
 7212:                         my %imgdeletions;
 7213:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
 7214:                         if (@todeleteimages) {
 7215:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
 7216:                         }
 7217:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
 7218:                         for (my $i=0; $i<=$maxnum; $i++) {
 7219:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
 7220:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
 7221:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
 7222:                                 if ($deletions{$key}) {
 7223:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
 7224:                                         #FIXME need to obsolete item in RES space
 7225:                                     }
 7226:                                     next;
 7227:                                 } else {
 7228:                                     my $newpos = $env{'form.'.$itemid};
 7229:                                     $newpos =~ s/\D+//g;
 7230:                                     foreach my $item ('subject','title','publisher','author') {
 7231:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
 7232:                                                  ($type eq 'templates'));
 7233:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
 7234:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
 7235:                                             $changes{$type}{$key} = 1;
 7236:                                         }
 7237:                                     }
 7238:                                     $allpos{$type}[$newpos] = $key;
 7239:                                 }
 7240:                                 if ($imgdeletions{$key}) {
 7241:                                     $changes{$type}{$key} = 1;
 7242:                                     #FIXME need to obsolete item in RES space
 7243:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
 7244:                                     my ($cdom,$cnum) = split(/_/,$key);
 7245:                                     my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
 7246:                                                                                   $cdom,$cnum,$type,$configuserok,
 7247:                                                                                   $switchserver,$author_ok);
 7248:                                     if ($imgurl) {
 7249:                                         $confhash{$type}{$key}{'image'} = $imgurl;
 7250:                                         $changes{$type}{$key} = 1; 
 7251:                                     }
 7252:                                     if ($error) {
 7253:                                         &Apache::lonnet::logthis($error);
 7254:                                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 7255:                                     } 
 7256:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
 7257:                                     $confhash{$type}{$key}{'image'} = 
 7258:                                         $domconfig{$action}{$type}{$key}{'image'};
 7259:                                 }
 7260:                             }
 7261:                         }
 7262:                     }
 7263:                 }
 7264:             }
 7265:         } else {
 7266:             if ($confhash{'notify'}{'approval'}) {
 7267:                 $changes{'notify'}{'approval'} = 1;
 7268:             }
 7269:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
 7270:                 $changes{'uniquecode'} = 1;
 7271:             }
 7272:         }
 7273:         if ($context eq 'requestcourses') {
 7274:             foreach my $type ('textbooks','templates') {
 7275:                 if ($newbook{$type}) {
 7276:                     $changes{$type}{$newbook{$type}} = 1;
 7277:                     foreach my $item ('subject','title','publisher','author') {
 7278:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
 7279:                                  ($type eq 'template'));
 7280:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
 7281:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
 7282:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
 7283:                         }
 7284:                     }
 7285:                     if ($type eq 'textbooks') {
 7286:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
 7287:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
 7288:                             my ($imageurl,$error) =
 7289:                                 &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
 7290:                                                         $configuserok,$switchserver,$author_ok);
 7291:                             if ($imageurl) {
 7292:                                 $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
 7293:                             }
 7294:                             if ($error) {
 7295:                                 &Apache::lonnet::logthis($error);
 7296:                                 $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 7297:                             }
 7298:                         }
 7299:                     }
 7300:                 }
 7301:                 if (@{$allpos{$type}} > 0) {
 7302:                     my $idx = 0;
 7303:                     foreach my $item (@{$allpos{$type}}) {
 7304:                         if ($item ne '') {
 7305:                             $confhash{$type}{$item}{'order'} = $idx;
 7306:                             if (ref($domconfig{$action}) eq 'HASH') {
 7307:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
 7308:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
 7309:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
 7310:                                             $changes{$type}{$item} = 1;
 7311:                                         }
 7312:                                     }
 7313:                                 }
 7314:                             }
 7315:                             $idx ++;
 7316:                         }
 7317:                     }
 7318:                 }
 7319:             }
 7320:             if (ref($validationitemsref) eq 'ARRAY') {
 7321:                 foreach my $item (@{$validationitemsref}) {
 7322:                     if ($item eq 'fields') {
 7323:                         my @changed;
 7324:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
 7325:                         if (@{$confhash{'validation'}{$item}} > 0) {
 7326:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
 7327:                         }
 7328:                         if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
 7329:                             if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
 7330:                                 @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
 7331:                                                                               $domconfig{'requestcourses'}{'validation'}{$item});
 7332:                             } else {
 7333:                                 @changed = @{$confhash{'validation'}{$item}};
 7334:                             }
 7335:                         } else {
 7336:                             @changed = @{$confhash{'validation'}{$item}};
 7337:                         }
 7338:                         if (@changed) {
 7339:                             if ($confhash{'validation'}{$item}) {
 7340:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
 7341:                             } else {
 7342:                                 $changes{'validation'}{$item} = &mt('None');
 7343:                             }
 7344:                         }
 7345:                     } else {
 7346:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
 7347:                         if ($item eq 'markup') {
 7348:                             if ($env{'form.requestcourses_validation_'.$item}) {
 7349:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
 7350:                             }
 7351:                         }
 7352:                         if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
 7353:                             if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
 7354:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
 7355:                             }
 7356:                         } else {
 7357:                             if ($confhash{'validation'}{$item} ne '') {
 7358:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
 7359:                             }
 7360:                         }
 7361:                     }
 7362:                 }
 7363:             }
 7364:             if ($env{'form.validationdc'}) {
 7365:                 my $newval = $env{'form.validationdc'};
 7366:                 my %domcoords = &get_active_dcs($dom);
 7367:                 if (exists($domcoords{$newval})) {
 7368:                     $confhash{'validation'}{'dc'} = $newval;
 7369:                 }
 7370:             }
 7371:             if (ref($confhash{'validation'}) eq 'HASH') {
 7372:                 if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
 7373:                     if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
 7374:                         unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
 7375:                             if ($confhash{'validation'}{'dc'} eq '') {
 7376:                                 $changes{'validation'}{'dc'} = &mt('None');
 7377:                             } else {
 7378:                                 $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
 7379:                             }
 7380:                         }
 7381:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
 7382:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
 7383:                     }
 7384:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
 7385:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
 7386:                 }
 7387:             } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
 7388:                 if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
 7389:                     $changes{'validation'}{'dc'} = &mt('None');
 7390:                 }
 7391:             }
 7392:         }
 7393:     } else {
 7394:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 7395:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
 7396:     }
 7397:     foreach my $item (@usertools) {
 7398:         foreach my $type (@{$types},'default','_LC_adv') {
 7399:             my $unset; 
 7400:             if ($context eq 'requestcourses') {
 7401:                 $unset = '0';
 7402:                 if ($type eq '_LC_adv') {
 7403:                     $unset = '';
 7404:                 }
 7405:                 if ($confhash{$item}{$type} eq 'autolimit') {
 7406:                     $confhash{$item}{$type} .= '=';
 7407:                     unless ($limithash{$item}{$type} =~ /\D/) {
 7408:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
 7409:                     }
 7410:                 }
 7411:             } elsif ($context eq 'requestauthor') {
 7412:                 $unset = '0';
 7413:                 if ($type eq '_LC_adv') {
 7414:                     $unset = '';
 7415:                 }
 7416:             } else {
 7417:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 7418:                     $confhash{$item}{$type} = 1;
 7419:                 } else {
 7420:                     $confhash{$item}{$type} = 0;
 7421:                 }
 7422:             }
 7423:             if (ref($domconfig{$action}) eq 'HASH') {
 7424:                 if ($action eq 'requestauthor') {
 7425:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
 7426:                         $changes{$type} = 1;
 7427:                     }
 7428:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
 7429:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
 7430:                         $changes{$item}{$type} = 1;
 7431:                     }
 7432:                 } else {
 7433:                     if ($context eq 'requestcourses') {
 7434:                         if ($confhash{$item}{$type} ne $unset) {
 7435:                             $changes{$item}{$type} = 1;
 7436:                         }
 7437:                     } else {
 7438:                         if (!$confhash{$item}{$type}) {
 7439:                             $changes{$item}{$type} = 1;
 7440:                         }
 7441:                     }
 7442:                 }
 7443:             } else {
 7444:                 if ($context eq 'requestcourses') {
 7445:                     if ($confhash{$item}{$type} ne $unset) {
 7446:                         $changes{$item}{$type} = 1;
 7447:                     }
 7448:                 } elsif ($context eq 'requestauthor') {
 7449:                     if ($confhash{$type} ne $unset) {
 7450:                         $changes{$type} = 1;
 7451:                     }
 7452:                 } else {
 7453:                     if (!$confhash{$item}{$type}) {
 7454:                         $changes{$item}{$type} = 1;
 7455:                     }
 7456:                 }
 7457:             }
 7458:         }
 7459:     }
 7460:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 7461:         if (ref($domconfig{'quotas'}) eq 'HASH') {
 7462:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 7463:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 7464:                     if (exists($confhash{'defaultquota'}{$key})) {
 7465:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 7466:                             $changes{'defaultquota'}{$key} = 1;
 7467:                         }
 7468:                     } else {
 7469:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 7470:                     }
 7471:                 }
 7472:             } else {
 7473:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
 7474:                     if (exists($confhash{'defaultquota'}{$key})) {
 7475:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 7476:                             $changes{'defaultquota'}{$key} = 1;
 7477:                         }
 7478:                     } else {
 7479:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 7480:                     }
 7481:                 }
 7482:             }
 7483:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 7484:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
 7485:                     if (exists($confhash{'authorquota'}{$key})) {
 7486:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
 7487:                             $changes{'authorquota'}{$key} = 1;
 7488:                         }
 7489:                     } else {
 7490:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
 7491:                     }
 7492:                 }
 7493:             }
 7494:         }
 7495:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
 7496:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 7497:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 7498:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 7499:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 7500:                             $changes{'defaultquota'}{$key} = 1;
 7501:                         }
 7502:                     } else {
 7503:                         if (!exists($domconfig{'quotas'}{$key})) {
 7504:                             $changes{'defaultquota'}{$key} = 1;
 7505:                         }
 7506:                     }
 7507:                 } else {
 7508:                     $changes{'defaultquota'}{$key} = 1;
 7509:                 }
 7510:             }
 7511:         }
 7512:         if (ref($confhash{'authorquota'}) eq 'HASH') {
 7513:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
 7514:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 7515:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 7516:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
 7517:                             $changes{'authorquota'}{$key} = 1;
 7518:                         }
 7519:                     } else {
 7520:                         $changes{'authorquota'}{$key} = 1;
 7521:                     }
 7522:                 } else {
 7523:                     $changes{'authorquota'}{$key} = 1;
 7524:                 }
 7525:             }
 7526:         }
 7527:     }
 7528: 
 7529:     if ($context eq 'requestauthor') {
 7530:         $domdefaults{'requestauthor'} = \%confhash;
 7531:     } else {
 7532:         foreach my $key (keys(%confhash)) {
 7533:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
 7534:                 $domdefaults{$key} = $confhash{$key};
 7535:             }
 7536:         }
 7537:     }
 7538: 
 7539:     my %quotahash = (
 7540:                       $action => { %confhash }
 7541:                     );
 7542:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 7543:                                              $dom);
 7544:     if ($putresult eq 'ok') {
 7545:         if (keys(%changes) > 0) {
 7546:             my $cachetime = 24*60*60;
 7547:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 7548:             if (ref($lastactref) eq 'HASH') {
 7549:                 $lastactref->{'domdefaults'} = 1;
 7550:             }
 7551:             $resulttext = &mt('Changes made:').'<ul>';
 7552:             unless (($context eq 'requestcourses') ||
 7553:                     ($context eq 'requestauthor')) {
 7554:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
 7555:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 7556:                     foreach my $type (@{$types},'default') {
 7557:                         if (defined($changes{'defaultquota'}{$type})) {
 7558:                             my $typetitle = $usertypes->{$type};
 7559:                             if ($type eq 'default') {
 7560:                                 $typetitle = $othertitle;
 7561:                             }
 7562:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 7563:                         }
 7564:                     }
 7565:                     $resulttext .= '</ul></li>';
 7566:                 }
 7567:                 if (ref($changes{'authorquota'}) eq 'HASH') {
 7568:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
 7569:                     foreach my $type (@{$types},'default') {
 7570:                         if (defined($changes{'authorquota'}{$type})) {
 7571:                             my $typetitle = $usertypes->{$type};
 7572:                             if ($type eq 'default') {
 7573:                                 $typetitle = $othertitle;
 7574:                             }
 7575:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
 7576:                         }
 7577:                     }
 7578:                     $resulttext .= '</ul></li>';
 7579:                 }
 7580:             }
 7581:             my %newenv;
 7582:             foreach my $item (@usertools) {
 7583:                 my (%haschgs,%inconf);
 7584:                 if ($context eq 'requestauthor') {
 7585:                     %haschgs = %changes;
 7586:                     %inconf = %confhash;
 7587:                 } else {
 7588:                     if (ref($changes{$item}) eq 'HASH') {
 7589:                         %haschgs = %{$changes{$item}};
 7590:                     }
 7591:                     if (ref($confhash{$item}) eq 'HASH') {
 7592:                         %inconf = %{$confhash{$item}};
 7593:                     }
 7594:                 }
 7595:                 if (keys(%haschgs) > 0) {
 7596:                     my $newacc = 
 7597:                         &Apache::lonnet::usertools_access($env{'user.name'},
 7598:                                                           $env{'user.domain'},
 7599:                                                           $item,'reload',$context);
 7600:                     if (($context eq 'requestcourses') ||
 7601:                         ($context eq 'requestauthor')) {
 7602:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
 7603:                             $newenv{'environment.canrequest.'.$item} = $newacc;
 7604:                         }
 7605:                     } else {
 7606:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 7607:                             $newenv{'environment.availabletools.'.$item} = $newacc;
 7608:                         }
 7609:                     }
 7610:                     unless ($context eq 'requestauthor') {
 7611:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
 7612:                     }
 7613:                     foreach my $type (@{$types},'default','_LC_adv') {
 7614:                         if ($haschgs{$type}) {
 7615:                             my $typetitle = $usertypes->{$type};
 7616:                             if ($type eq 'default') {
 7617:                                 $typetitle = $othertitle;
 7618:                             } elsif ($type eq '_LC_adv') {
 7619:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 7620:                             }
 7621:                             if ($inconf{$type}) {
 7622:                                 if ($context eq 'requestcourses') {
 7623:                                     my $cond;
 7624:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
 7625:                                         if ($1 eq '') {
 7626:                                             $cond = &mt('(Automatic processing of any request).');
 7627:                                         } else {
 7628:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
 7629:                                         }
 7630:                                     } else { 
 7631:                                         $cond = $conditions{$inconf{$type}};
 7632:                                     }
 7633:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
 7634:                                 } elsif ($context eq 'requestauthor') {
 7635:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
 7636:                                                              $titles{$inconf{$type}},$typetitle);
 7637: 
 7638:                                 } else {
 7639:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 7640:                                 }
 7641:                             } else {
 7642:                                 if ($type eq '_LC_adv') {
 7643:                                     if ($inconf{$type} eq '0') {
 7644:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 7645:                                     } else { 
 7646:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
 7647:                                     }
 7648:                                 } else {
 7649:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 7650:                                 }
 7651:                             }
 7652:                         }
 7653:                     }
 7654:                     unless ($context eq 'requestauthor') {
 7655:                         $resulttext .= '</ul></li>';
 7656:                     }
 7657:                 }
 7658:             }
 7659:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
 7660:                 if (ref($changes{'notify'}) eq 'HASH') {
 7661:                     if ($changes{'notify'}{'approval'}) {
 7662:                         if (ref($confhash{'notify'}) eq 'HASH') {
 7663:                             if ($confhash{'notify'}{'approval'}) {
 7664:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
 7665:                             } else {
 7666:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
 7667:                             }
 7668:                         }
 7669:                     }
 7670:                 }
 7671:             }
 7672:             if ($action eq 'requestcourses') {
 7673:                 my @offon = ('off','on');
 7674:                 if ($changes{'uniquecode'}) {
 7675:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
 7676:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
 7677:                         $resulttext .= '<li>'.
 7678:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
 7679:                                        '</li>';
 7680:                     } else {
 7681:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
 7682:                                        '</li>';
 7683:                     }
 7684:                 }
 7685:                 foreach my $type ('textbooks','templates') {
 7686:                     if (ref($changes{$type}) eq 'HASH') {
 7687:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
 7688:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
 7689:                             my %coursehash = &Apache::lonnet::coursedescription($key);
 7690:                             my $coursetitle = $coursehash{'description'};
 7691:                             my $position = $confhash{$type}{$key}{'order'} + 1;
 7692:                             $resulttext .= '<li>';
 7693:                             foreach my $item ('subject','title','publisher','author') {
 7694:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
 7695:                                          ($type eq 'templates'));
 7696:                                 my $name = $item.':';
 7697:                                 $name =~ s/^(\w)/\U$1/;
 7698:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
 7699:                             }
 7700:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
 7701:                             if ($type eq 'textbooks') {
 7702:                                 if ($confhash{$type}{$key}{'image'}) {
 7703:                                     $resulttext .= ' '.&mt('Image: [_1]',
 7704:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
 7705:                                                    ' alt="Textbook cover" />').'<br />';
 7706:                                 }
 7707:                             }
 7708:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
 7709:                         }
 7710:                         $resulttext .= '</ul></li>';
 7711:                     }
 7712:                 }
 7713:                 if (ref($changes{'validation'}) eq 'HASH') {
 7714:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
 7715:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
 7716:                         foreach my $item (@{$validationitemsref}) {
 7717:                             if (exists($changes{'validation'}{$item})) {
 7718:                                 if ($item eq 'markup') {
 7719:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
 7720:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
 7721:                                 } else {
 7722:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
 7723:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
 7724:                                 }
 7725:                             }
 7726:                         }
 7727:                         if (exists($changes{'validation'}{'dc'})) {
 7728:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
 7729:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
 7730:                         }
 7731:                     }
 7732:                 }
 7733:             }
 7734:             $resulttext .= '</ul>';
 7735:             if (keys(%newenv)) {
 7736:                 &Apache::lonnet::appenv(\%newenv);
 7737:             }
 7738:         } else {
 7739:             if ($context eq 'requestcourses') {
 7740:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
 7741:             } elsif ($context eq 'requestauthor') {
 7742:                 $resulttext = &mt('No changes made to rights to request author space.');
 7743:             } else {
 7744:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
 7745:             }
 7746:         }
 7747:     } else {
 7748:         $resulttext = '<span class="LC_error">'.
 7749: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 7750:     }
 7751:     if ($errors) {
 7752:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
 7753:                        '<ul>'.$errors.'</ul></p>';
 7754:     }
 7755:     return $resulttext;
 7756: }
 7757: 
 7758: sub process_textbook_image {
 7759:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
 7760:     my $filename = $env{'form.'.$caller.'.filename'};
 7761:     my ($error,$url);
 7762:     my ($width,$height) = (50,50);
 7763:     if ($configuserok eq 'ok') {
 7764:         if ($switchserver) {
 7765:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
 7766:                          $switchserver);
 7767:         } elsif ($author_ok eq 'ok') {
 7768:             my ($result,$imageurl) =
 7769:                 &publishlogo($r,'upload',$caller,$dom,$confname,
 7770:                              "$type/$dom/$cnum/cover",$width,$height);
 7771:             if ($result eq 'ok') {
 7772:                 $url = $imageurl;
 7773:             } else {
 7774:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
 7775:             }
 7776:         } else {
 7777:             $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$author_ok);
 7778:         }
 7779:     } else {
 7780:         $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$filename,$confname,$dom,$configuserok);
 7781:     }
 7782:     return ($url,$error);
 7783: }
 7784: 
 7785: sub modify_autoenroll {
 7786:     my ($dom,$lastactref,%domconfig) = @_;
 7787:     my ($resulttext,%changes);
 7788:     my %currautoenroll;
 7789:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 7790:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 7791:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 7792:         }
 7793:     }
 7794:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 7795:     my %title = ( run => 'Auto-enrollment active',
 7796:                   sender => 'Sender for notification messages',
 7797:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
 7798:     my @offon = ('off','on');
 7799:     my $sender_uname = $env{'form.sender_uname'};
 7800:     my $sender_domain = $env{'form.sender_domain'};
 7801:     if ($sender_domain eq '') {
 7802:         $sender_uname = '';
 7803:     } elsif ($sender_uname eq '') {
 7804:         $sender_domain = '';
 7805:     }
 7806:     my $coowners = $env{'form.autoassign_coowners'};
 7807:     my %autoenrollhash =  (
 7808:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
 7809:                                        'sender_uname' => $sender_uname,
 7810:                                        'sender_domain' => $sender_domain,
 7811:                                        'co-owners' => $coowners,
 7812:                                 }
 7813:                      );
 7814:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 7815:                                              $dom);
 7816:     if ($putresult eq 'ok') {
 7817:         if (exists($currautoenroll{'run'})) {
 7818:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 7819:                  $changes{'run'} = 1;
 7820:              }
 7821:         } elsif ($autorun) {
 7822:             if ($env{'form.autoenroll_run'} ne '1') {
 7823:                  $changes{'run'} = 1;
 7824:             }
 7825:         }
 7826:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 7827:             $changes{'sender'} = 1;
 7828:         }
 7829:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 7830:             $changes{'sender'} = 1;
 7831:         }
 7832:         if ($currautoenroll{'co-owners'} ne '') {
 7833:             if ($currautoenroll{'co-owners'} ne $coowners) {
 7834:                 $changes{'coowners'} = 1;
 7835:             }
 7836:         } elsif ($coowners) {
 7837:             $changes{'coowners'} = 1;
 7838:         }      
 7839:         if (keys(%changes) > 0) {
 7840:             $resulttext = &mt('Changes made:').'<ul>';
 7841:             if ($changes{'run'}) {
 7842:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 7843:             }
 7844:             if ($changes{'sender'}) {
 7845:                 if ($sender_uname eq '' || $sender_domain eq '') {
 7846:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 7847:                 } else {
 7848:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 7849:                 }
 7850:             }
 7851:             if ($changes{'coowners'}) {
 7852:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
 7853:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 7854:                 if (ref($lastactref) eq 'HASH') {
 7855:                     $lastactref->{'domainconfig'} = 1;
 7856:                 }
 7857:             }
 7858:             $resulttext .= '</ul>';
 7859:         } else {
 7860:             $resulttext = &mt('No changes made to auto-enrollment settings');
 7861:         }
 7862:     } else {
 7863:         $resulttext = '<span class="LC_error">'.
 7864: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 7865:     }
 7866:     return $resulttext;
 7867: }
 7868: 
 7869: sub modify_autoupdate {
 7870:     my ($dom,%domconfig) = @_;
 7871:     my ($resulttext,%currautoupdate,%fields,%changes);
 7872:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 7873:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 7874:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 7875:         }
 7876:     }
 7877:     my @offon = ('off','on');
 7878:     my %title = &Apache::lonlocal::texthash (
 7879:                    run => 'Auto-update:',
 7880:                    classlists => 'Updates to user information in classlists?'
 7881:                 );
 7882:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 7883:     my %fieldtitles = &Apache::lonlocal::texthash (
 7884:                         id => 'Student/Employee ID',
 7885:                         permanentemail => 'E-mail address',
 7886:                         lastname => 'Last Name',
 7887:                         firstname => 'First Name',
 7888:                         middlename => 'Middle Name',
 7889:                         generation => 'Generation',
 7890:                       );
 7891:     $othertitle = &mt('All users');
 7892:     if (keys(%{$usertypes}) >  0) {
 7893:         $othertitle = &mt('Other users');
 7894:     }
 7895:     foreach my $key (keys(%env)) {
 7896:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 7897:             my ($usertype,$item) = ($1,$2);
 7898:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
 7899:                 if ($usertype eq 'default') {   
 7900:                     push(@{$fields{$1}},$2);
 7901:                 } elsif (ref($types) eq 'ARRAY') {
 7902:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
 7903:                         push(@{$fields{$1}},$2);
 7904:                     }
 7905:                 }
 7906:             }
 7907:         }
 7908:     }
 7909:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
 7910:     @lockablenames = sort(@lockablenames);
 7911:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
 7912:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 7913:         if (@changed) {
 7914:             $changes{'lockablenames'} = 1;
 7915:         }
 7916:     } else {
 7917:         if (@lockablenames) {
 7918:             $changes{'lockablenames'} = 1;
 7919:         }
 7920:     }
 7921:     my %updatehash = (
 7922:                       autoupdate => { run => $env{'form.autoupdate_run'},
 7923:                                       classlists => $env{'form.classlists'},
 7924:                                       fields => {%fields},
 7925:                                       lockablenames => \@lockablenames,
 7926:                                     }
 7927:                      );
 7928:     foreach my $key (keys(%currautoupdate)) {
 7929:         if (($key eq 'run') || ($key eq 'classlists')) {
 7930:             if (exists($updatehash{autoupdate}{$key})) {
 7931:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 7932:                     $changes{$key} = 1;
 7933:                 }
 7934:             }
 7935:         } elsif ($key eq 'fields') {
 7936:             if (ref($currautoupdate{$key}) eq 'HASH') {
 7937:                 foreach my $item (@{$types},'default') {
 7938:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 7939:                         my $change = 0;
 7940:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 7941:                             if (!exists($fields{$item})) {
 7942:                                 $change = 1;
 7943:                                 last;
 7944:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 7945:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 7946:                                     $change = 1;
 7947:                                     last;
 7948:                                 }
 7949:                             }
 7950:                         }
 7951:                         if ($change) {
 7952:                             push(@{$changes{$key}},$item);
 7953:                         }
 7954:                     } 
 7955:                 }
 7956:             }
 7957:         } elsif ($key eq 'lockablenames') {
 7958:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
 7959:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 7960:                 if (@changed) {
 7961:                     $changes{'lockablenames'} = 1;
 7962:                 }
 7963:             } else {
 7964:                 if (@lockablenames) {
 7965:                     $changes{'lockablenames'} = 1;
 7966:                 }
 7967:             }
 7968:         }
 7969:     }
 7970:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
 7971:         if (@lockablenames) {
 7972:             $changes{'lockablenames'} = 1;
 7973:         }
 7974:     }
 7975:     foreach my $item (@{$types},'default') {
 7976:         if (defined($fields{$item})) {
 7977:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 7978:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
 7979:                     my $change = 0;
 7980:                     if (ref($fields{$item}) eq 'ARRAY') {
 7981:                         foreach my $type (@{$fields{$item}}) {
 7982:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
 7983:                                 $change = 1;
 7984:                                 last;
 7985:                             }
 7986:                         }
 7987:                     }
 7988:                     if ($change) {
 7989:                         push(@{$changes{'fields'}},$item);
 7990:                     }
 7991:                 } else {
 7992:                     push(@{$changes{'fields'}},$item);
 7993:                 }
 7994:             } else {
 7995:                 push(@{$changes{'fields'}},$item);
 7996:             }
 7997:         }
 7998:     }
 7999:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 8000:                                              $dom);
 8001:     if ($putresult eq 'ok') {
 8002:         if (keys(%changes) > 0) {
 8003:             $resulttext = &mt('Changes made:').'<ul>';
 8004:             foreach my $key (sort(keys(%changes))) {
 8005:                 if ($key eq 'lockablenames') {
 8006:                     $resulttext .= '<li>';
 8007:                     if (@lockablenames) {
 8008:                         $usertypes->{'default'} = $othertitle;
 8009:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
 8010:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
 8011:                     } else {
 8012:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
 8013:                     }
 8014:                     $resulttext .= '</li>';
 8015:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
 8016:                     foreach my $item (@{$changes{$key}}) {
 8017:                         my @newvalues;
 8018:                         foreach my $type (@{$fields{$item}}) {
 8019:                             push(@newvalues,$fieldtitles{$type});
 8020:                         }
 8021:                         my $newvaluestr;
 8022:                         if (@newvalues > 0) {
 8023:                             $newvaluestr = join(', ',@newvalues);
 8024:                         } else {
 8025:                             $newvaluestr = &mt('none');
 8026:                         }
 8027:                         if ($item eq 'default') {
 8028:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 8029:                         } else {
 8030:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 8031:                         }
 8032:                     }
 8033:                 } else {
 8034:                     my $newvalue;
 8035:                     if ($key eq 'run') {
 8036:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 8037:                     } else {
 8038:                         $newvalue = $offon[$env{'form.'.$key}];
 8039:                     }
 8040:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 8041:                 }
 8042:             }
 8043:             $resulttext .= '</ul>';
 8044:         } else {
 8045:             $resulttext = &mt('No changes made to autoupdates');
 8046:         }
 8047:     } else {
 8048:         $resulttext = '<span class="LC_error">'.
 8049: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 8050:     }
 8051:     return $resulttext;
 8052: }
 8053: 
 8054: sub modify_autocreate {
 8055:     my ($dom,%domconfig) = @_;
 8056:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
 8057:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
 8058:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
 8059:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
 8060:         }
 8061:     }
 8062:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
 8063:                  req => 'Auto-creation of validated requests for official courses',
 8064:                  xmldc => 'Identity of course creator of courses from XML files',
 8065:                );
 8066:     my @types = ('xml','req');
 8067:     foreach my $item (@types) {
 8068:         $newvals{$item} = $env{'form.autocreate_'.$item};
 8069:         $newvals{$item} =~ s/\D//g;
 8070:         $newvals{$item} = 0 if ($newvals{$item} eq '');
 8071:     }
 8072:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
 8073:     my %domcoords = &get_active_dcs($dom);
 8074:     unless (exists($domcoords{$newvals{'xmldc'}})) {
 8075:         $newvals{'xmldc'} = '';
 8076:     } 
 8077:     %autocreatehash =  (
 8078:                         autocreate => { xml => $newvals{'xml'},
 8079:                                         req => $newvals{'req'},
 8080:                                       }
 8081:                        );
 8082:     if ($newvals{'xmldc'} ne '') {
 8083:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
 8084:     }
 8085:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
 8086:                                              $dom);
 8087:     if ($putresult eq 'ok') {
 8088:         my @items = @types;
 8089:         if ($newvals{'xml'}) {
 8090:             push(@items,'xmldc');
 8091:         }
 8092:         foreach my $item (@items) {
 8093:             if (exists($currautocreate{$item})) {
 8094:                 if ($currautocreate{$item} ne $newvals{$item}) {
 8095:                     $changes{$item} = 1;
 8096:                 }
 8097:             } elsif ($newvals{$item}) {
 8098:                 $changes{$item} = 1;
 8099:             }
 8100:         }
 8101:         if (keys(%changes) > 0) {
 8102:             my @offon = ('off','on'); 
 8103:             $resulttext = &mt('Changes made:').'<ul>';
 8104:             foreach my $item (@types) {
 8105:                 if ($changes{$item}) {
 8106:                     my $newtxt = $offon[$newvals{$item}];
 8107:                     $resulttext .= '<li>'.
 8108:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
 8109:                                        '<b>','</b>').
 8110:                                    '</li>';
 8111:                 }
 8112:             }
 8113:             if ($changes{'xmldc'}) {
 8114:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
 8115:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
 8116:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
 8117:             }
 8118:             $resulttext .= '</ul>';
 8119:         } else {
 8120:             $resulttext = &mt('No changes made to auto-creation settings');
 8121:         }
 8122:     } else {
 8123:         $resulttext = '<span class="LC_error">'.
 8124:             &mt('An error occurred: [_1]',$putresult).'</span>';
 8125:     }
 8126:     return $resulttext;
 8127: }
 8128: 
 8129: sub modify_directorysrch {
 8130:     my ($dom,%domconfig) = @_;
 8131:     my ($resulttext,%changes);
 8132:     my %currdirsrch;
 8133:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 8134:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 8135:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 8136:         }
 8137:     }
 8138:     my %title = ( available => 'Directory search available',
 8139:                   localonly => 'Other domains can search',
 8140:                   searchby => 'Search types',
 8141:                   searchtypes => 'Search latitude');
 8142:     my @offon = ('off','on');
 8143:     my @otherdoms = ('Yes','No');
 8144: 
 8145:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 8146:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 8147:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 8148: 
 8149:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 8150:     if (keys(%{$usertypes}) == 0) {
 8151:         @cansearch = ('default');
 8152:     } else {
 8153:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 8154:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 8155:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 8156:                     push(@{$changes{'cansearch'}},$type);
 8157:                 }
 8158:             }
 8159:             foreach my $type (@cansearch) {
 8160:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 8161:                     push(@{$changes{'cansearch'}},$type);
 8162:                 }
 8163:             }
 8164:         } else {
 8165:             push(@{$changes{'cansearch'}},@cansearch);
 8166:         }
 8167:     }
 8168: 
 8169:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 8170:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 8171:             if (!grep(/^\Q$by\E$/,@searchby)) {
 8172:                 push(@{$changes{'searchby'}},$by);
 8173:             }
 8174:         }
 8175:         foreach my $by (@searchby) {
 8176:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 8177:                 push(@{$changes{'searchby'}},$by);
 8178:             }
 8179:         }
 8180:     } else {
 8181:         push(@{$changes{'searchby'}},@searchby);
 8182:     }
 8183: 
 8184:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 8185:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 8186:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 8187:                 push(@{$changes{'searchtypes'}},$type);
 8188:             }
 8189:         }
 8190:         foreach my $type (@searchtypes) {
 8191:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 8192:                 push(@{$changes{'searchtypes'}},$type);
 8193:             }
 8194:         }
 8195:     } else {
 8196:         if (exists($currdirsrch{'searchtypes'})) {
 8197:             foreach my $type (@searchtypes) {  
 8198:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 8199:                     push(@{$changes{'searchtypes'}},$type);
 8200:                 }
 8201:             }
 8202:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 8203:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 8204:             }   
 8205:         } else {
 8206:             push(@{$changes{'searchtypes'}},@searchtypes); 
 8207:         }
 8208:     }
 8209: 
 8210:     my %dirsrch_hash =  (
 8211:             directorysrch => { available => $env{'form.dirsrch_available'},
 8212:                                cansearch => \@cansearch,
 8213:                                localonly => $env{'form.dirsrch_localonly'},
 8214:                                searchby => \@searchby,
 8215:                                searchtypes => \@searchtypes,
 8216:                              }
 8217:             );
 8218:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 8219:                                              $dom);
 8220:     if ($putresult eq 'ok') {
 8221:         if (exists($currdirsrch{'available'})) {
 8222:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 8223:                  $changes{'available'} = 1;
 8224:              }
 8225:         } else {
 8226:             if ($env{'form.dirsrch_available'} eq '1') {
 8227:                 $changes{'available'} = 1;
 8228:             }
 8229:         }
 8230:         if (exists($currdirsrch{'localonly'})) {
 8231:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 8232:                  $changes{'localonly'} = 1;
 8233:              }
 8234:         } else {
 8235:             if ($env{'form.dirsrch_localonly'} eq '1') {
 8236:                 $changes{'localonly'} = 1;
 8237:             }
 8238:         }
 8239:         if (keys(%changes) > 0) {
 8240:             $resulttext = &mt('Changes made:').'<ul>';
 8241:             if ($changes{'available'}) {
 8242:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 8243:             }
 8244:             if ($changes{'localonly'}) {
 8245:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 8246:             }
 8247: 
 8248:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 8249:                 my $chgtext;
 8250:                 if (ref($usertypes) eq 'HASH') {
 8251:                     if (keys(%{$usertypes}) > 0) {
 8252:                         foreach my $type (@{$types}) {
 8253:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 8254:                                 $chgtext .= $usertypes->{$type}.'; ';
 8255:                             }
 8256:                         }
 8257:                         if (grep(/^default$/,@cansearch)) {
 8258:                             $chgtext .= $othertitle;
 8259:                         } else {
 8260:                             $chgtext =~ s/\; $//;
 8261:                         }
 8262:                         $resulttext .=
 8263:                             '<li>'.
 8264:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
 8265:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
 8266:                             '</li>';
 8267:                     }
 8268:                 }
 8269:             }
 8270:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 8271:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 8272:                 my $chgtext;
 8273:                 foreach my $type (@{$titleorder}) {
 8274:                     if (grep(/^\Q$type\E$/,@searchby)) {
 8275:                         if (defined($searchtitles->{$type})) {
 8276:                             $chgtext .= $searchtitles->{$type}.'; ';
 8277:                         }
 8278:                     }
 8279:                 }
 8280:                 $chgtext =~ s/\; $//;
 8281:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 8282:             }
 8283:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 8284:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 8285:                 my $chgtext;
 8286:                 foreach my $type (@{$srchtypeorder}) {
 8287:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 8288:                         if (defined($srchtypes_desc->{$type})) {
 8289:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 8290:                         }
 8291:                     }
 8292:                 }
 8293:                 $chgtext =~ s/\; $//;
 8294:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
 8295:             }
 8296:             $resulttext .= '</ul>';
 8297:         } else {
 8298:             $resulttext = &mt('No changes made to institution directory search settings');
 8299:         }
 8300:     } else {
 8301:         $resulttext = '<span class="LC_error">'.
 8302:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 8303:     }
 8304:     return $resulttext;
 8305: }
 8306: 
 8307: sub modify_contacts {
 8308:     my ($dom,$lastactref,%domconfig) = @_;
 8309:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 8310:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 8311:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 8312:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 8313:         }
 8314:     }
 8315:     my (%others,%to,%bcc);
 8316:     my @contacts = ('supportemail','adminemail');
 8317:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
 8318:                     'requestsmail','updatesmail','idconflictsmail');
 8319:     my @toggles = ('reporterrors','reportupdates');
 8320:     foreach my $type (@mailings) {
 8321:         @{$newsetting{$type}} = 
 8322:             &Apache::loncommon::get_env_multiple('form.'.$type);
 8323:         foreach my $item (@contacts) {
 8324:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 8325:                 $contacts_hash{contacts}{$type}{$item} = 1;
 8326:             } else {
 8327:                 $contacts_hash{contacts}{$type}{$item} = 0;
 8328:             }
 8329:         }  
 8330:         $others{$type} = $env{'form.'.$type.'_others'};
 8331:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 8332:         if ($type eq 'helpdeskmail') {
 8333:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
 8334:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
 8335:         }
 8336:     }
 8337:     foreach my $item (@contacts) {
 8338:         $to{$item} = $env{'form.'.$item};
 8339:         $contacts_hash{'contacts'}{$item} = $to{$item};
 8340:     }
 8341:     foreach my $item (@toggles) {
 8342:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
 8343:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
 8344:         }
 8345:     }
 8346:     if (keys(%currsetting) > 0) {
 8347:         foreach my $item (@contacts) {
 8348:             if ($to{$item} ne $currsetting{$item}) {
 8349:                 $changes{$item} = 1;
 8350:             }
 8351:         }
 8352:         foreach my $type (@mailings) {
 8353:             foreach my $item (@contacts) {
 8354:                 if (ref($currsetting{$type}) eq 'HASH') {
 8355:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 8356:                         push(@{$changes{$type}},$item);
 8357:                     }
 8358:                 } else {
 8359:                     push(@{$changes{$type}},@{$newsetting{$type}});
 8360:                 }
 8361:             }
 8362:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 8363:                 push(@{$changes{$type}},'others');
 8364:             }
 8365:             if ($type eq 'helpdeskmail') {   
 8366:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
 8367:                     push(@{$changes{$type}},'bcc'); 
 8368:                 }
 8369:             }
 8370:         }
 8371:     } else {
 8372:         my %default;
 8373:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 8374:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 8375:         $default{'errormail'} = 'adminemail';
 8376:         $default{'packagesmail'} = 'adminemail';
 8377:         $default{'helpdeskmail'} = 'supportemail';
 8378:         $default{'lonstatusmail'} = 'adminemail';
 8379:         $default{'requestsmail'} = 'adminemail';
 8380:         $default{'updatesmail'} = 'adminemail';
 8381:         foreach my $item (@contacts) {
 8382:            if ($to{$item} ne $default{$item}) {
 8383:               $changes{$item} = 1;
 8384:            }
 8385:         }
 8386:         foreach my $type (@mailings) {
 8387:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 8388:                
 8389:                 push(@{$changes{$type}},@{$newsetting{$type}});
 8390:             }
 8391:             if ($others{$type} ne '') {
 8392:                 push(@{$changes{$type}},'others');
 8393:             }
 8394:             if ($type eq 'helpdeskmail') {
 8395:                 if ($bcc{$type} ne '') {
 8396:                     push(@{$changes{$type}},'bcc');
 8397:                 }
 8398:             }
 8399:         }
 8400:     }
 8401:     foreach my $item (@toggles) {
 8402:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
 8403:             $changes{$item} = 1;
 8404:         } elsif ((!$env{'form.'.$item}) &&
 8405:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
 8406:             $changes{$item} = 1;
 8407:         }
 8408:     }
 8409:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 8410:                                              $dom);
 8411:     if ($putresult eq 'ok') {
 8412:         if (keys(%changes) > 0) {
 8413:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 8414:             if (ref($lastactref) eq 'HASH') {
 8415:                 $lastactref->{'domainconfig'} = 1;
 8416:             }
 8417:             my ($titles,$short_titles)  = &contact_titles();
 8418:             $resulttext = &mt('Changes made:').'<ul>';
 8419:             foreach my $item (@contacts) {
 8420:                 if ($changes{$item}) {
 8421:                     $resulttext .= '<li>'.$titles->{$item}.
 8422:                                     &mt(' set to: ').
 8423:                                     '<span class="LC_cusr_emph">'.
 8424:                                     $to{$item}.'</span></li>';
 8425:                 }
 8426:             }
 8427:             foreach my $type (@mailings) {
 8428:                 if (ref($changes{$type}) eq 'ARRAY') {
 8429:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 8430:                     my @text;
 8431:                     foreach my $item (@{$newsetting{$type}}) {
 8432:                         push(@text,$short_titles->{$item});
 8433:                     }
 8434:                     if ($others{$type} ne '') {
 8435:                         push(@text,$others{$type});
 8436:                     }
 8437:                     $resulttext .= '<span class="LC_cusr_emph">'.
 8438:                                    join(', ',@text).'</span>';
 8439:                     if ($type eq 'helpdeskmail') {
 8440:                         if ($bcc{$type} ne '') {
 8441:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
 8442:                         }
 8443:                     }
 8444:                     $resulttext .= '</li>';
 8445:                 }
 8446:             }
 8447:             my @offon = ('off','on');
 8448:             if ($changes{'reporterrors'}) {
 8449:                 $resulttext .= '<li>'.
 8450:                                &mt('E-mail error reports to [_1] set to "'.
 8451:                                    $offon[$env{'form.reporterrors'}].'".',
 8452:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 8453:                                        &mt('LON-CAPA core group - MSU'),600,500)).
 8454:                                '</li>';
 8455:             }
 8456:             if ($changes{'reportupdates'}) {
 8457:                 $resulttext .= '<li>'.
 8458:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
 8459:                                     $offon[$env{'form.reportupdates'}].'".',
 8460:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 8461:                                         &mt('LON-CAPA core group - MSU'),600,500)).
 8462:                                 '</li>';
 8463:             }
 8464:             $resulttext .= '</ul>';
 8465:         } else {
 8466:             $resulttext = &mt('No changes made to contact information');
 8467:         }
 8468:     } else {
 8469:         $resulttext = '<span class="LC_error">'.
 8470:             &mt('An error occurred: [_1].',$putresult).'</span>';
 8471:     }
 8472:     return $resulttext;
 8473: }
 8474: 
 8475: sub modify_usercreation {
 8476:     my ($dom,%domconfig) = @_;
 8477:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
 8478:     my $warningmsg;
 8479:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 8480:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 8481:             if ($key eq 'cancreate') {
 8482:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
 8483:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
 8484:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
 8485:                             ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
 8486:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
 8487:                         } else {
 8488:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
 8489:                         }
 8490:                     }
 8491:                 }
 8492:             } elsif ($key eq 'email_rule') {
 8493:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
 8494:             } else {
 8495:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 8496:             }
 8497:         }
 8498:     }
 8499:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 8500:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 8501:     my @contexts = ('author','course','requestcrs');
 8502:     foreach my $item(@contexts) {
 8503:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
 8504:     }
 8505:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 8506:         foreach my $item (@contexts) {
 8507:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 8508:                 push(@{$changes{'cancreate'}},$item);
 8509:             }
 8510:         }
 8511:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 8512:         foreach my $item (@contexts) {
 8513:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 8514:                 if ($cancreate{$item} ne 'any') {
 8515:                     push(@{$changes{'cancreate'}},$item);
 8516:                 }
 8517:             } else {
 8518:                 if ($cancreate{$item} ne 'none') {
 8519:                     push(@{$changes{'cancreate'}},$item);
 8520:                 }
 8521:             }
 8522:         }
 8523:     } else {
 8524:         foreach my $item (@contexts)  {
 8525:             push(@{$changes{'cancreate'}},$item);
 8526:         }
 8527:     }
 8528: 
 8529:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 8530:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 8531:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 8532:                 push(@{$changes{'username_rule'}},$type);
 8533:             }
 8534:         }
 8535:         foreach my $type (@username_rule) {
 8536:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 8537:                 push(@{$changes{'username_rule'}},$type);
 8538:             }
 8539:         }
 8540:     } else {
 8541:         push(@{$changes{'username_rule'}},@username_rule);
 8542:     }
 8543: 
 8544:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 8545:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 8546:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 8547:                 push(@{$changes{'id_rule'}},$type);
 8548:             }
 8549:         }
 8550:         foreach my $type (@id_rule) {
 8551:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 8552:                 push(@{$changes{'id_rule'}},$type);
 8553:             }
 8554:         }
 8555:     } else {
 8556:         push(@{$changes{'id_rule'}},@id_rule);
 8557:     }
 8558: 
 8559:     my @authen_contexts = ('author','course','domain');
 8560:     my @authtypes = ('int','krb4','krb5','loc');
 8561:     my %authhash;
 8562:     foreach my $item (@authen_contexts) {
 8563:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 8564:         foreach my $auth (@authtypes) {
 8565:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 8566:                 $authhash{$item}{$auth} = 1;
 8567:             } else {
 8568:                 $authhash{$item}{$auth} = 0;
 8569:             }
 8570:         }
 8571:     }
 8572:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 8573:         foreach my $item (@authen_contexts) {
 8574:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 8575:                 foreach my $auth (@authtypes) {
 8576:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 8577:                         push(@{$changes{'authtypes'}},$item);
 8578:                         last;
 8579:                     }
 8580:                 }
 8581:             }
 8582:         }
 8583:     } else {
 8584:         foreach my $item (@authen_contexts) {
 8585:             push(@{$changes{'authtypes'}},$item);
 8586:         }
 8587:     }
 8588: 
 8589:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
 8590:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
 8591:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
 8592:     $save_usercreate{'id_rule'} = \@id_rule;
 8593:     $save_usercreate{'username_rule'} = \@username_rule,
 8594:     $save_usercreate{'authtypes'} = \%authhash;
 8595: 
 8596:     my %usercreation_hash =  (
 8597:         usercreation     => \%save_usercreate,
 8598:     );
 8599: 
 8600:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 8601:                                              $dom);
 8602: 
 8603:     if ($putresult eq 'ok') {
 8604:         if (keys(%changes) > 0) {
 8605:             $resulttext = &mt('Changes made:').'<ul>';
 8606:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 8607:                 my %lt = &usercreation_types();
 8608:                 foreach my $type (@{$changes{'cancreate'}}) {
 8609:                     my $chgtext = $lt{$type}.', ';
 8610:                     if ($cancreate{$type} eq 'none') {
 8611:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 8612:                     } elsif ($cancreate{$type} eq 'any') {
 8613:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 8614:                     } elsif ($cancreate{$type} eq 'official') {
 8615:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 8616:                     } elsif ($cancreate{$type} eq 'unofficial') {
 8617:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 8618:                     }
 8619:                     $resulttext .= '<li>'.$chgtext.'</li>';
 8620:                 }
 8621:             }
 8622:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 8623:                 my ($rules,$ruleorder) = 
 8624:                     &Apache::lonnet::inst_userrules($dom,'username');
 8625:                 my $chgtext = '<ul>';
 8626:                 foreach my $type (@username_rule) {
 8627:                     if (ref($rules->{$type}) eq 'HASH') {
 8628:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 8629:                     }
 8630:                 }
 8631:                 $chgtext .= '</ul>';
 8632:                 if (@username_rule > 0) {
 8633:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 8634:                 } else {
 8635:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 8636:                 }
 8637:             }
 8638:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 8639:                 my ($idrules,$idruleorder) = 
 8640:                     &Apache::lonnet::inst_userrules($dom,'id');
 8641:                 my $chgtext = '<ul>';
 8642:                 foreach my $type (@id_rule) {
 8643:                     if (ref($idrules->{$type}) eq 'HASH') {
 8644:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 8645:                     }
 8646:                 }
 8647:                 $chgtext .= '</ul>';
 8648:                 if (@id_rule > 0) {
 8649:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 8650:                 } else {
 8651:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 8652:                 }
 8653:             }
 8654:             my %authname = &authtype_names();
 8655:             my %context_title = &context_names();
 8656:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 8657:                 my $chgtext = '<ul>';
 8658:                 foreach my $type (@{$changes{'authtypes'}}) {
 8659:                     my @allowed;
 8660:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 8661:                     foreach my $auth (@authtypes) {
 8662:                         if ($authhash{$type}{$auth}) {
 8663:                             push(@allowed,$authname{$auth});
 8664:                         }
 8665:                     }
 8666:                     if (@allowed > 0) {
 8667:                         $chgtext .= join(', ',@allowed).'</li>';
 8668:                     } else {
 8669:                         $chgtext .= &mt('none').'</li>';
 8670:                     }
 8671:                 }
 8672:                 $chgtext .= '</ul>';
 8673:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 8674:                 $resulttext .= '</li>';
 8675:             }
 8676:             $resulttext .= '</ul>';
 8677:         } else {
 8678:             $resulttext = &mt('No changes made to user creation settings');
 8679:         }
 8680:     } else {
 8681:         $resulttext = '<span class="LC_error">'.
 8682:             &mt('An error occurred: [_1]',$putresult).'</span>';
 8683:     }
 8684:     if ($warningmsg ne '') {
 8685:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 8686:     }
 8687:     return $resulttext;
 8688: }
 8689: 
 8690: sub modify_selfcreation {
 8691:     my ($dom,%domconfig) = @_;
 8692:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
 8693:     my (%save_usercreate,%save_usermodify);
 8694:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 8695:     if (ref($types) eq 'ARRAY') {
 8696:         $usertypes->{'default'} = $othertitle;
 8697:         push(@{$types},'default');
 8698:     }
 8699: #
 8700: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
 8701: #
 8702:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 8703:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 8704:             if ($key eq 'cancreate') {
 8705:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
 8706:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
 8707:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
 8708:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') || 
 8709:                             ($item eq 'emailusername') || ($item eq 'notify') ||
 8710:                             ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
 8711:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
 8712:                         } else {
 8713:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
 8714:                         }
 8715:                     }
 8716:                 }
 8717:             } elsif ($key eq 'email_rule') {
 8718:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 8719:             } else {
 8720:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
 8721:             }
 8722:         }
 8723:     }
 8724: #
 8725: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
 8726: #
 8727:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 8728:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 8729:             if ($key eq 'selfcreate') {
 8730:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
 8731:             } else {
 8732:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
 8733:             }
 8734:         }
 8735:     }
 8736: 
 8737:     my @contexts = ('selfcreate');
 8738:     @{$cancreate{'selfcreate'}} = ();
 8739:     %{$cancreate{'emailusername'}} = ();
 8740:     @{$cancreate{'statustocreate'}} = ();
 8741:     %{$cancreate{'selfcreateprocessing'}} = ();
 8742:     %{$cancreate{'shibenv'}} = ();
 8743:     my %selfcreatetypes = (
 8744:                              sso   => 'users authenticated by institutional single sign on',
 8745:                              login => 'users authenticated by institutional log-in',
 8746:                              email => 'users who provide a valid e-mail address for use as username',
 8747:                           );
 8748: #
 8749: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
 8750: # is permitted.
 8751: #
 8752: 
 8753:     my @statuses;
 8754:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
 8755:         if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
 8756:             @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
 8757:         }
 8758:     }
 8759:     push(@statuses,'default');
 8760: 
 8761:     foreach my $item ('login','sso','email') {
 8762:         if ($item eq 'email') {
 8763:             if ($env{'form.cancreate_email'}) {
 8764:                 push(@{$cancreate{'selfcreate'}},'email');
 8765:                 push(@contexts,'selfcreateprocessing');
 8766:                 foreach my $type (@statuses) {
 8767:                     if ($type eq 'default') {
 8768:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
 8769:                     } else { 
 8770:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
 8771:                     }
 8772:                 }
 8773:             }
 8774:         } else {
 8775:             if ($env{'form.cancreate_'.$item}) {
 8776:                 push(@{$cancreate{'selfcreate'}},$item);
 8777:             }
 8778:         }
 8779:     }
 8780:     my (@email_rule,%userinfo,%savecaptcha);
 8781:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
 8782: #
 8783: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
 8784: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
 8785: #
 8786: 
 8787:     if ($env{'form.cancreate_email'}) {
 8788:         push(@contexts,'emailusername');
 8789:         if (ref($types) eq 'ARRAY') {
 8790:             foreach my $type (@{$types}) {
 8791:                 if (ref($infofields) eq 'ARRAY') {
 8792:                     foreach my $field (@{$infofields}) {
 8793:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
 8794:                             $cancreate{'emailusername'}{$type}{$field} = $1;
 8795:                         }
 8796:                     }
 8797:                 }
 8798:             }
 8799:         }
 8800: #
 8801: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
 8802: # queued requests for self-creation of account using e-mail address as username
 8803: #
 8804: 
 8805:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
 8806:         @approvalnotify = sort(@approvalnotify);
 8807:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
 8808:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 8809:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
 8810:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
 8811:                     push(@{$changes{'cancreate'}},'notify');
 8812:                 }
 8813:             } else {
 8814:                 if ($cancreate{'notify'}{'approval'}) {
 8815:                     push(@{$changes{'cancreate'}},'notify');
 8816:                 }
 8817:             }
 8818:         } elsif ($cancreate{'notify'}{'approval'}) {
 8819:             push(@{$changes{'cancreate'}},'notify');
 8820:         }
 8821: 
 8822: #
 8823: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
 8824: #
 8825:         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 8826:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
 8827:         if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 8828:             if (@{$curr_usercreation{'email_rule'}} > 0) {
 8829:                 foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 8830:                     if (!grep(/^\Q$type\E$/,@email_rule)) {
 8831:                         push(@{$changes{'email_rule'}},$type);
 8832:                     }
 8833:                 }
 8834:             }
 8835:             if (@email_rule > 0) {
 8836:                 foreach my $type (@email_rule) {
 8837:                     if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 8838:                         push(@{$changes{'email_rule'}},$type);
 8839:                     }
 8840:                 }
 8841:             }
 8842:         } elsif (@email_rule > 0) {
 8843:             push(@{$changes{'email_rule'}},@email_rule);
 8844:         }
 8845:     }
 8846: #  
 8847: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
 8848: # institutional log-in.
 8849: #
 8850:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
 8851:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
 8852:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
 8853:                ($domdefaults{'auth_def'} eq 'localauth'))) {
 8854:             $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.').' '.
 8855:                           &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.');
 8856:         }
 8857:     }
 8858:     my @fields = ('lastname','firstname','middlename','generation',
 8859:                   'permanentemail','id');
 8860:     my @shibfields = (@fields,'inststatus');
 8861:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 8862: #
 8863: # Where usernames may created for institutional log-in and/or institutional single sign on:
 8864: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
 8865: # may self-create accounts 
 8866: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
 8867: # which the user may supply, if institutional data is unavailable.
 8868: #
 8869:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
 8870:         if (ref($types) eq 'ARRAY') {
 8871:             if (@{$types} > 1) {
 8872:                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
 8873:                 push(@contexts,'statustocreate');
 8874:             } else {
 8875:                 undef($cancreate{'statustocreate'});
 8876:             } 
 8877:             foreach my $type (@{$types}) {
 8878:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
 8879:                 foreach my $field (@fields) {
 8880:                     if (grep(/^\Q$field\E$/,@modifiable)) {
 8881:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
 8882:                     } else {
 8883:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
 8884:                     }
 8885:                 }
 8886:             }
 8887:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
 8888:                 foreach my $type (@{$types}) {
 8889:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
 8890:                         foreach my $field (@fields) {
 8891:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
 8892:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
 8893:                                 push(@{$changes{'selfcreate'}},$type);
 8894:                                 last;
 8895:                             }
 8896:                         }
 8897:                     }
 8898:                 }
 8899:             } else {
 8900:                 foreach my $type (@{$types}) {
 8901:                     push(@{$changes{'selfcreate'}},$type);
 8902:                 }
 8903:             }
 8904:         }
 8905:         foreach my $field (@shibfields) {
 8906:             if ($env{'form.shibenv_'.$field} ne '') {
 8907:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
 8908:             }
 8909:         }
 8910:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 8911:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
 8912:                 foreach my $field (@shibfields) {
 8913:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
 8914:                         push(@{$changes{'cancreate'}},'shibenv');
 8915:                     }
 8916:                 }
 8917:             } else {
 8918:                 foreach my $field (@shibfields) {
 8919:                     if ($env{'form.shibenv_'.$field}) {
 8920:                         push(@{$changes{'cancreate'}},'shibenv');
 8921:                         last;
 8922:                     }
 8923:                 }
 8924:             }
 8925:         }
 8926:     }
 8927:     foreach my $item (@contexts) {
 8928:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 8929:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 8930:                 if (ref($cancreate{$item}) eq 'ARRAY') {
 8931:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 8932:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8933:                             push(@{$changes{'cancreate'}},$item);
 8934:                         }
 8935:                     }
 8936:                 }
 8937:             }
 8938:             if (ref($cancreate{$item}) eq 'ARRAY') {
 8939:                 foreach my $type (@{$cancreate{$item}}) {
 8940:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 8941:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8942:                             push(@{$changes{'cancreate'}},$item);
 8943:                         }
 8944:                     }
 8945:                 }
 8946:             }
 8947:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
 8948:             if (ref($cancreate{$item}) eq 'HASH') {
 8949:                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
 8950:                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
 8951:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
 8952:                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
 8953:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8954:                                     push(@{$changes{'cancreate'}},$item);
 8955:                                 }
 8956:                             }
 8957:                         }
 8958:                     } elsif ($item eq 'selfcreateprocessing') {
 8959:                         if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
 8960:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8961:                                 push(@{$changes{'cancreate'}},$item);
 8962:                             }
 8963:                         }
 8964:                     } else {
 8965:                         if (!$cancreate{$item}{$curr}) {
 8966:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8967:                                 push(@{$changes{'cancreate'}},$item);
 8968:                             }
 8969:                         }
 8970:                     }
 8971:                 }
 8972:                 foreach my $field (keys(%{$cancreate{$item}})) {
 8973:                     if (ref($cancreate{$item}{$field}) eq 'HASH') {
 8974:                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
 8975:                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
 8976:                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
 8977:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8978:                                         push(@{$changes{'cancreate'}},$item);
 8979:                                     }
 8980:                                 }
 8981:                             } else {
 8982:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8983:                                     push(@{$changes{'cancreate'}},$item);
 8984:                                 }
 8985:                             }
 8986:                         }
 8987:                     } elsif ($item eq 'selfcreateprocessing') {
 8988:                         if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
 8989:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8990:                                 push(@{$changes{'cancreate'}},$item);
 8991:                             }
 8992:                         }
 8993:                     } else {
 8994:                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
 8995:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8996:                                 push(@{$changes{'cancreate'}},$item);
 8997:                             }
 8998:                         }
 8999:                     }
 9000:                 }
 9001:             }
 9002:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
 9003:             if (ref($cancreate{$item}) eq 'ARRAY') {
 9004:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
 9005:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9006:                         push(@{$changes{'cancreate'}},$item);
 9007:                     }
 9008:                 }
 9009:             } elsif (ref($cancreate{$item}) eq 'HASH') {
 9010:                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
 9011:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9012:                         push(@{$changes{'cancreate'}},$item);
 9013:                     }
 9014:                 }
 9015:             }
 9016:         } elsif ($item eq 'emailusername') {
 9017:             if (ref($cancreate{$item}) eq 'HASH') {
 9018:                 foreach my $type (keys(%{$cancreate{$item}})) {
 9019:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
 9020:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
 9021:                             if ($cancreate{$item}{$type}{$field}) {
 9022:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9023:                                     push(@{$changes{'cancreate'}},$item);
 9024:                                 }
 9025:                                 last;
 9026:                             }
 9027:                         }
 9028:                     }
 9029:                 }
 9030:             }
 9031:         }
 9032:     }
 9033: #
 9034: # Populate %save_usercreate hash with updates to self-creation configuration.
 9035: #
 9036:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
 9037:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
 9038:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
 9039:     if (ref($cancreate{'notify'}) eq 'HASH') {
 9040:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
 9041:     }
 9042:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
 9043:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
 9044:     }
 9045:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 9046:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
 9047:     }
 9048:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
 9049:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
 9050:     }
 9051:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
 9052:     $save_usercreate{'emailrule'} = \@email_rule;
 9053: 
 9054:     my %userconfig_hash = (
 9055:             usercreation     => \%save_usercreate,
 9056:             usermodification => \%save_usermodify,
 9057:     );
 9058:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
 9059:                                              $dom);
 9060: #
 9061: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
 9062: #
 9063:     if ($putresult eq 'ok') {
 9064:         if (keys(%changes) > 0) {
 9065:             $resulttext = &mt('Changes made:').'<ul>';
 9066:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 9067:                 my %lt = &selfcreation_types();
 9068:                 foreach my $type (@{$changes{'cancreate'}}) {
 9069:                     my $chgtext;
 9070:                     if ($type eq 'selfcreate') {
 9071:                         if (@{$cancreate{$type}} == 0) {
 9072:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
 9073:                         } else {
 9074:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
 9075:                                         '<ul>';
 9076:                             foreach my $case (@{$cancreate{$type}}) {
 9077:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 9078:                             }
 9079:                             $chgtext .= '</ul>';
 9080:                             if (ref($cancreate{$type}) eq 'ARRAY') {
 9081:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
 9082:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 9083:                                         if (@{$cancreate{'statustocreate'}} == 0) {
 9084:                                             $chgtext .= '<br />'.
 9085:                                                         '<span class="LC_warning">'.
 9086:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
 9087:                                                         '</span>';
 9088:                                         }
 9089:                                     }
 9090:                                 }
 9091:                             }
 9092:                         }
 9093:                     } elsif ($type eq 'shibenv') {
 9094:                         if (keys(%{$cancreate{$type}}) == 0) {
 9095:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information'); 
 9096:                         } else {
 9097:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
 9098:                                         '<ul>';
 9099:                             foreach my $field (@shibfields) {
 9100:                                 next if ($cancreate{$type}{$field} eq '');
 9101:                                 if ($field eq 'inststatus') {
 9102:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
 9103:                                 } else {
 9104:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
 9105:                                 }
 9106:                             }
 9107:                             $chgtext .= '</ul>';
 9108:                         }  
 9109:                     } elsif ($type eq 'statustocreate') {
 9110:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
 9111:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
 9112:                             if (@{$cancreate{'selfcreate'}} > 0) {
 9113:                                 if (@{$cancreate{'statustocreate'}} == 0) {
 9114:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
 9115:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
 9116:                                         $chgtext .= '<br />'.
 9117:                                                     '<span class="LC_warning">'.
 9118:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
 9119:                                                     '</span>';
 9120:                                     }
 9121:                                 } elsif (ref($usertypes) eq 'HASH') {
 9122:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 9123:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
 9124:                                     } else {
 9125:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
 9126:                                     }
 9127:                                     $chgtext .= '<ul>';
 9128:                                     foreach my $case (@{$cancreate{$type}}) {
 9129:                                         if ($case eq 'default') {
 9130:                                             $chgtext .= '<li>'.$othertitle.'</li>';
 9131:                                         } else {
 9132:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
 9133:                                         }
 9134:                                     }
 9135:                                     $chgtext .= '</ul>';
 9136:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 9137:                                         $chgtext .= '<br /><span class="LC_warning">'.
 9138:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
 9139:                                                     '</span>';
 9140:                                     }
 9141:                                 }
 9142:                             } else {
 9143:                                 if (@{$cancreate{$type}} == 0) {
 9144:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
 9145:                                 } else {
 9146:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
 9147:                                 }
 9148:                             }
 9149:                         }
 9150:                     } elsif ($type eq 'selfcreateprocessing') {
 9151:                         my %choices = &Apache::lonlocal::texthash (
 9152:                                                                     automatic => 'Automatic approval',
 9153:                                                                     approval  => 'Queued for approval',
 9154:                                                                   );
 9155:                         if (@statuses > 1) {
 9156:                             $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:'). 
 9157:                                         '<ul>';
 9158:                            foreach my $type (@statuses) {
 9159:                                if ($type eq 'default') {
 9160:                                    $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
 9161:                                } else {
 9162:                                    $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
 9163:                                }
 9164:                            }
 9165:                            $chgtext .= '</ul>';
 9166:                         } else {
 9167:                            $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
 9168:                                          $choices{$cancreate{'selfcreateprocessing'}{'default'}});
 9169:                         }
 9170:                     } elsif ($type eq 'captcha') {
 9171:                         if ($savecaptcha{$type} eq 'notused') {
 9172:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
 9173:                         } else {
 9174:                             my %captchas = &captcha_phrases();
 9175:                             if ($captchas{$savecaptcha{$type}}) {
 9176:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
 9177:                             } else {
 9178:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
 9179:                             }
 9180:                         }
 9181:                     } elsif ($type eq 'recaptchakeys') {
 9182:                         my ($privkey,$pubkey);
 9183:                         if (ref($savecaptcha{$type}) eq 'HASH') {
 9184:                             $pubkey = $savecaptcha{$type}{'public'};
 9185:                             $privkey = $savecaptcha{$type}{'private'};
 9186:                         }
 9187:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
 9188:                         if (!$pubkey) {
 9189:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
 9190:                         } else {
 9191:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 9192:                         }
 9193:                         if (!$privkey) {
 9194:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
 9195:                         } else {
 9196:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
 9197:                         }
 9198:                         $chgtext .= '</ul>';
 9199:                     } elsif ($type eq 'emailusername') {
 9200:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
 9201:                             if (ref($types) eq 'ARRAY') {
 9202:                                 foreach my $type (@{$types}) {
 9203:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
 9204:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
 9205:                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
 9206:                                                     '<ul>';
 9207:                                             foreach my $field (@{$infofields}) {
 9208:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
 9209:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
 9210:                                                 }
 9211:                                             }
 9212:                                             $chgtext .= '</ul>';
 9213:                                         } else {
 9214:                                             $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
 9215:                                         }
 9216:                                     } else {
 9217:                                         $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
 9218:                                     }
 9219:                                 }
 9220:                             }
 9221:                         }
 9222:                     } elsif ($type eq 'notify') {
 9223:                         $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
 9224:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
 9225:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
 9226:                                 if ($cancreate{'notify'}{'approval'}) {
 9227:                                     $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
 9228:                                 }
 9229:                             }
 9230:                         }
 9231:                     }
 9232:                     if ($chgtext) {
 9233:                         $resulttext .= '<li>'.$chgtext.'</li>';
 9234:                     }
 9235:                 }
 9236:             }
 9237:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 9238:                 my ($emailrules,$emailruleorder) =
 9239:                     &Apache::lonnet::inst_userrules($dom,'email');
 9240:                 my $chgtext = '<ul>';
 9241:                 foreach my $type (@email_rule) {
 9242:                     if (ref($emailrules->{$type}) eq 'HASH') {
 9243:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 9244:                     }
 9245:                 }
 9246:                 $chgtext .= '</ul>';
 9247:                 if (@email_rule > 0) {
 9248:                     $resulttext .= '<li>'.
 9249:                                    &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
 9250:                                        $chgtext.
 9251:                                    '</li>';
 9252:                 } else {
 9253:                     $resulttext .= '<li>'.
 9254:                                    &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
 9255:                                    '</li>';
 9256:                 }
 9257:             }
 9258:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
 9259:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
 9260:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 9261:                 foreach my $type (@{$changes{'selfcreate'}}) {
 9262:                     my $typename = $type;
 9263:                     if (ref($usertypes) eq 'HASH') {
 9264:                         if ($usertypes->{$type} ne '') {
 9265:                             $typename = $usertypes->{$type};
 9266:                         }
 9267:                     }
 9268:                     my @modifiable;
 9269:                     $resulttext .= '<li>'.
 9270:                                     &mt('Self-creation of account by users with status: [_1]',
 9271:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
 9272:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
 9273:                     foreach my $field (@fields) {
 9274:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
 9275:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
 9276:                         }
 9277:                     }
 9278:                     if (@modifiable > 0) {
 9279:                         $resulttext .= join(', ',@modifiable);
 9280:                     } else {
 9281:                         $resulttext .= &mt('none');
 9282:                     }
 9283:                     $resulttext .= '</li>';
 9284:                 }
 9285:                 $resulttext .= '</ul></li>';
 9286:             }
 9287:             $resulttext .= '</ul>';
 9288:         } else {
 9289:             $resulttext = &mt('No changes made to self-creation settings');
 9290:         }
 9291:     } else {
 9292:         $resulttext = '<span class="LC_error">'.
 9293:             &mt('An error occurred: [_1]',$putresult).'</span>';
 9294:     }
 9295:     if ($warningmsg ne '') {
 9296:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 9297:     }
 9298:     return $resulttext;
 9299: }
 9300: 
 9301: sub process_captcha {
 9302:     my ($container,$changes,$newsettings,$current) = @_;
 9303:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
 9304:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
 9305:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
 9306:         $newsettings->{'captcha'} = 'original';
 9307:     }
 9308:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
 9309:         if ($container eq 'cancreate') {
 9310:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 9311:                 push(@{$changes->{'cancreate'}},'captcha');
 9312:             } elsif (!defined($changes->{'cancreate'})) {
 9313:                 $changes->{'cancreate'} = ['captcha'];
 9314:             }
 9315:         } else {
 9316:             $changes->{'captcha'} = 1;
 9317:         }
 9318:     }
 9319:     my ($newpub,$newpriv,$currpub,$currpriv);
 9320:     if ($newsettings->{'captcha'} eq 'recaptcha') {
 9321:         $newpub = $env{'form.'.$container.'_recaptchapub'};
 9322:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
 9323:         $newpub =~ s/[^\w\-]//g;
 9324:         $newpriv =~ s/[^\w\-]//g;
 9325:         $newsettings->{'recaptchakeys'} = {
 9326:                                              public  => $newpub,
 9327:                                              private => $newpriv,
 9328:                                           };
 9329:     }
 9330:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
 9331:         $currpub = $current->{'recaptchakeys'}{'public'};
 9332:         $currpriv = $current->{'recaptchakeys'}{'private'};
 9333:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
 9334:             $newsettings->{'recaptchakeys'} = {
 9335:                                                  public  => '',
 9336:                                                  private => '',
 9337:                                               }
 9338:         }
 9339:     }
 9340:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
 9341:         if ($container eq 'cancreate') {
 9342:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 9343:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
 9344:             } elsif (!defined($changes->{'cancreate'})) {
 9345:                 $changes->{'cancreate'} = ['recaptchakeys'];
 9346:             }
 9347:         } else {
 9348:             $changes->{'recaptchakeys'} = 1;
 9349:         }
 9350:     }
 9351:     return;
 9352: }
 9353: 
 9354: sub modify_usermodification {
 9355:     my ($dom,%domconfig) = @_;
 9356:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
 9357:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 9358:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 9359:             if ($key eq 'selfcreate') {
 9360:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
 9361:             } else {  
 9362:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 9363:             }
 9364:         }
 9365:     }
 9366:     my @contexts = ('author','course');
 9367:     my %context_title = (
 9368:                            author => 'In author context',
 9369:                            course => 'In course context',
 9370:                         );
 9371:     my @fields = ('lastname','firstname','middlename','generation',
 9372:                   'permanentemail','id');
 9373:     my %roles = (
 9374:                   author => ['ca','aa'],
 9375:                   course => ['st','ep','ta','in','cr'],
 9376:                 );
 9377:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 9378:     foreach my $context (@contexts) {
 9379:         foreach my $role (@{$roles{$context}}) {
 9380:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 9381:             foreach my $item (@fields) {
 9382:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 9383:                     $modifyhash{$context}{$role}{$item} = 1;
 9384:                 } else {
 9385:                     $modifyhash{$context}{$role}{$item} = 0;
 9386:                 }
 9387:             }
 9388:         }
 9389:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 9390:             foreach my $role (@{$roles{$context}}) {
 9391:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 9392:                     foreach my $field (@fields) {
 9393:                         if ($modifyhash{$context}{$role}{$field} ne 
 9394:                                 $curr_usermodification{$context}{$role}{$field}) {
 9395:                             push(@{$changes{$context}},$role);
 9396:                             last;
 9397:                         }
 9398:                     }
 9399:                 }
 9400:             }
 9401:         } else {
 9402:             foreach my $context (@contexts) {
 9403:                 foreach my $role (@{$roles{$context}}) {
 9404:                     push(@{$changes{$context}},$role);
 9405:                 }
 9406:             }
 9407:         }
 9408:     }
 9409:     my %usermodification_hash =  (
 9410:                                    usermodification => \%modifyhash,
 9411:                                  );
 9412:     my $putresult = &Apache::lonnet::put_dom('configuration',
 9413:                                              \%usermodification_hash,$dom);
 9414:     if ($putresult eq 'ok') {
 9415:         if (keys(%changes) > 0) {
 9416:             $resulttext = &mt('Changes made: ').'<ul>';
 9417:             foreach my $context (@contexts) {
 9418:                 if (ref($changes{$context}) eq 'ARRAY') {
 9419:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 9420:                     if (ref($changes{$context}) eq 'ARRAY') {
 9421:                         foreach my $role (@{$changes{$context}}) {
 9422:                             my $rolename;
 9423:                             if ($role eq 'cr') {
 9424:                                 $rolename = &mt('Custom');
 9425:                             } else {
 9426:                                 $rolename = &Apache::lonnet::plaintext($role);
 9427:                             }
 9428:                             my @modifiable;
 9429:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 9430:                             foreach my $field (@fields) {
 9431:                                 if ($modifyhash{$context}{$role}{$field}) {
 9432:                                     push(@modifiable,$fieldtitles{$field});
 9433:                                 }
 9434:                             }
 9435:                             if (@modifiable > 0) {
 9436:                                 $resulttext .= join(', ',@modifiable);
 9437:                             } else {
 9438:                                 $resulttext .= &mt('none'); 
 9439:                             }
 9440:                             $resulttext .= '</li>';
 9441:                         }
 9442:                         $resulttext .= '</ul></li>';
 9443:                     }
 9444:                 }
 9445:             }
 9446:             $resulttext .= '</ul>';
 9447:         } else {
 9448:             $resulttext = &mt('No changes made to user modification settings');
 9449:         }
 9450:     } else {
 9451:         $resulttext = '<span class="LC_error">'.
 9452:             &mt('An error occurred: [_1]',$putresult).'</span>';
 9453:     }
 9454:     return $resulttext;
 9455: }
 9456: 
 9457: sub modify_defaults {
 9458:     my ($dom,$lastactref,%domconfig) = @_;
 9459:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 9460:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
 9461:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
 9462:     my @authtypes = ('internal','krb4','krb5','localauth');
 9463:     foreach my $item (@items) {
 9464:         $newvalues{$item} = $env{'form.'.$item};
 9465:         if ($item eq 'auth_def') {
 9466:             if ($newvalues{$item} ne '') {
 9467:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 9468:                     push(@errors,$item);
 9469:                 }
 9470:             }
 9471:         } elsif ($item eq 'lang_def') {
 9472:             if ($newvalues{$item} ne '') {
 9473:                 if ($newvalues{$item} =~ /^(\w+)/) {
 9474:                     my $langcode = $1;
 9475:                     if ($langcode ne 'x_chef') {
 9476:                         if (code2language($langcode) eq '') {
 9477:                             push(@errors,$item);
 9478:                         }
 9479:                     }
 9480:                 } else {
 9481:                     push(@errors,$item);
 9482:                 }
 9483:             }
 9484:         } elsif ($item eq 'timezone_def') {
 9485:             if ($newvalues{$item} ne '') {
 9486:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 9487:                     push(@errors,$item);   
 9488:                 }
 9489:             }
 9490:         } elsif ($item eq 'datelocale_def') {
 9491:             if ($newvalues{$item} ne '') {
 9492:                 my @datelocale_ids = DateTime::Locale->ids();
 9493:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 9494:                     push(@errors,$item);
 9495:                 }
 9496:             }
 9497:         } elsif ($item eq 'portal_def') {
 9498:             if ($newvalues{$item} ne '') {
 9499:                 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])\/?$/) {
 9500:                     push(@errors,$item);
 9501:                 }
 9502:             }
 9503:         }
 9504:         if (grep(/^\Q$item\E$/,@errors)) {
 9505:             $newvalues{$item} = $domdefaults{$item};
 9506:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 9507:             $changes{$item} = 1;
 9508:         }
 9509:         $domdefaults{$item} = $newvalues{$item};
 9510:     }
 9511:     my %defaults_hash = (
 9512:                          defaults => \%newvalues,
 9513:                         );
 9514:     my $title = &defaults_titles();
 9515: 
 9516:     my $currinststatus;
 9517:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
 9518:         $currinststatus = $domconfig{'inststatus'};
 9519:     } else {
 9520:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 9521:         $currinststatus = {
 9522:                              inststatustypes => $usertypes,
 9523:                              inststatusorder => $types,
 9524:                              inststatusguest => [],
 9525:                           };
 9526:     }
 9527:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
 9528:     my @allpos;
 9529:     my %guests;
 9530:     my %alltypes;
 9531:     my ($currtitles,$currguests,$currorder);
 9532:     if (ref($currinststatus) eq 'HASH') {
 9533:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
 9534:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
 9535:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
 9536:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
 9537:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
 9538:                     }
 9539:                 }
 9540:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
 9541:                     my $position = $env{'form.inststatus_pos_'.$type};
 9542:                     $position =~ s/\D+//g;
 9543:                     $allpos[$position] = $type;
 9544:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
 9545:                     $alltypes{$type} =~ s/`//g;
 9546:                     if ($env{'form.inststatus_guest_'.$type}) {
 9547:                         $guests{$type} = 1;
 9548:                     }
 9549:                 }
 9550:             }
 9551:             if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
 9552:                 $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
 9553:             }
 9554:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
 9555:             $currtitles =~ s/,$//;
 9556:         }
 9557:     }
 9558:     if ($env{'form.addinststatus'}) {
 9559:         my $newtype = $env{'form.addinststatus'};
 9560:         $newtype =~ s/\W//g;
 9561:         unless (exists($alltypes{$newtype})) {
 9562:             if ($env{'form.addinststatus_guest'}) {
 9563:                 $guests{$newtype} = 1;
 9564:             }
 9565:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
 9566:             $alltypes{$newtype} =~ s/`//g; 
 9567:             my $position = $env{'form.addinststatus_pos'};
 9568:             $position =~ s/\D+//g;
 9569:             if ($position ne '') {
 9570:                 $allpos[$position] = $newtype;
 9571:             }
 9572:         }
 9573:     }
 9574:     my (@orderedstatus,@orderedguests);
 9575:     foreach my $type (@allpos) {
 9576:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
 9577:             push(@orderedstatus,$type);
 9578:             if ($guests{$type}) {
 9579:                 push(@orderedguests,$type);
 9580:             }
 9581:         }
 9582:     }
 9583:     foreach my $type (keys(%alltypes)) {
 9584:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
 9585:             delete($alltypes{$type});
 9586:         }
 9587:     }
 9588:     $defaults_hash{'inststatus'} = {
 9589:                                      inststatustypes => \%alltypes,
 9590:                                      inststatusorder => \@orderedstatus,
 9591:                                      inststatusguest => \@orderedguests,
 9592:                                    };
 9593:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
 9594:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
 9595:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
 9596:         }
 9597:     }
 9598:     if ($currorder ne join(',',@orderedstatus)) {
 9599:         $changes{'inststatus'}{'inststatusorder'} = 1;
 9600:     }
 9601:     if ($currguests ne join(',',@orderedguests)) {
 9602:         $changes{'inststatus'}{'inststatusguest'} = 1;
 9603:     }
 9604:     my $newtitles;
 9605:     foreach my $item (@orderedstatus) {
 9606:         $newtitles .= $alltypes{$item}.',';
 9607:     }
 9608:     $newtitles =~ s/,$//;
 9609:     if ($currtitles ne $newtitles) {
 9610:         $changes{'inststatus'}{'inststatustypes'} = 1;
 9611:     }
 9612:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 9613:                                              $dom);
 9614:     if ($putresult eq 'ok') {
 9615:         if (keys(%changes) > 0) {
 9616:             $resulttext = &mt('Changes made:').'<ul>';
 9617:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
 9618:             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";
 9619:             foreach my $item (sort(keys(%changes))) {
 9620:                 if ($item eq 'inststatus') {
 9621:                     if (ref($changes{'inststatus'}) eq 'HASH') {
 9622:                         if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
 9623:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
 9624:                             foreach my $type (@orderedstatus) { 
 9625:                                 $resulttext .= $alltypes{$type}.', ';
 9626:                             }
 9627:                             $resulttext =~ s/, $//;
 9628:                             $resulttext .= '</li>';
 9629:                         }
 9630:                         if ($changes{'inststatus'}{'inststatusguest'}) {
 9631:                             $resulttext .= '<li>'; 
 9632:                             if (@orderedguests) {
 9633:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
 9634:                                 foreach my $type (@orderedguests) {
 9635:                                     $resulttext .= $alltypes{$type}.', ';
 9636:                                 }
 9637:                                 $resulttext =~ s/, $//;
 9638:                             } else {
 9639:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
 9640:                             }
 9641:                             $resulttext .= '</li>';
 9642:                         }
 9643:                     }
 9644:                 } else {
 9645:                     my $value = $env{'form.'.$item};
 9646:                     if ($value eq '') {
 9647:                         $value = &mt('none');
 9648:                     } elsif ($item eq 'auth_def') {
 9649:                         my %authnames = &authtype_names();
 9650:                         my %shortauth = (
 9651:                                           internal   => 'int',
 9652:                                           krb4       => 'krb4',
 9653:                                           krb5       => 'krb5',
 9654:                                           localauth  => 'loc',
 9655:                         );
 9656:                         $value = $authnames{$shortauth{$value}};
 9657:                     }
 9658:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 9659:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
 9660:                 }
 9661:             }
 9662:             $resulttext .= '</ul>';
 9663:             $mailmsgtext .= "\n";
 9664:             my $cachetime = 24*60*60;
 9665:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 9666:             if (ref($lastactref) eq 'HASH') {
 9667:                 $lastactref->{'domdefaults'} = 1;
 9668:             }
 9669:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 9670:                 my $notify = 1;
 9671:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
 9672:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
 9673:                         $notify = 0;
 9674:                     }
 9675:                 }
 9676:                 if ($notify) {
 9677:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
 9678:                                                "LON-CAPA Domain Settings Change - $dom",
 9679:                                                $mailmsgtext);
 9680:                 }
 9681:             }
 9682:         } else {
 9683:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 9684:         }
 9685:     } else {
 9686:         $resulttext = '<span class="LC_error">'.
 9687:             &mt('An error occurred: [_1]',$putresult).'</span>';
 9688:     }
 9689:     if (@errors > 0) {
 9690:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 9691:         foreach my $item (@errors) {
 9692:             $resulttext .= ' "'.$title->{$item}.'",';
 9693:         }
 9694:         $resulttext =~ s/,$//;
 9695:     }
 9696:     return $resulttext;
 9697: }
 9698: 
 9699: sub modify_scantron {
 9700:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
 9701:     my ($resulttext,%confhash,%changes,$errors);
 9702:     my $custom = 'custom.tab';
 9703:     my $default = 'default.tab';
 9704:     my $servadm = $r->dir_config('lonAdmEMail');
 9705:     my ($configuserok,$author_ok,$switchserver) = 
 9706:         &config_check($dom,$confname,$servadm);
 9707:     if ($env{'form.scantronformat.filename'} ne '') {
 9708:         my $error;
 9709:         if ($configuserok eq 'ok') {
 9710:             if ($switchserver) {
 9711:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
 9712:             } else {
 9713:                 if ($author_ok eq 'ok') {
 9714:                     my ($result,$scantronurl) =
 9715:                         &publishlogo($r,'upload','scantronformat',$dom,
 9716:                                      $confname,'scantron','','',$custom);
 9717:                     if ($result eq 'ok') {
 9718:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 9719:                         $changes{'scantronformat'} = 1;
 9720:                     } else {
 9721:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 9722:                     }
 9723:                 } else {
 9724:                     $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);
 9725:                 }
 9726:             }
 9727:         } else {
 9728:             $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);
 9729:         }
 9730:         if ($error) {
 9731:             &Apache::lonnet::logthis($error);
 9732:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 9733:         }
 9734:     }
 9735:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 9736:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 9737:             if ($env{'form.scantronformat_del'}) {
 9738:                 $confhash{'scantron'}{'scantronformat'} = '';
 9739:                 $changes{'scantronformat'} = 1;
 9740:             }
 9741:         }
 9742:     }
 9743:     if (keys(%confhash) > 0) {
 9744:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 9745:                                                  $dom);
 9746:         if ($putresult eq 'ok') {
 9747:             if (keys(%changes) > 0) {
 9748:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 9749:                     $resulttext = &mt('Changes made:').'<ul>';
 9750:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 9751:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 9752:                     } else {
 9753:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 9754:                     }
 9755:                     $resulttext .= '</ul>';
 9756:                 } else {
 9757:                     $resulttext = &mt('Changes made to bubblesheet format file.');
 9758:                 }
 9759:                 $resulttext .= '</ul>';
 9760:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 9761:                 if (ref($lastactref) eq 'HASH') {
 9762:                     $lastactref->{'domainconfig'} = 1;
 9763:                 }
 9764:             } else {
 9765:                 $resulttext = &mt('No changes made to bubblesheet format file');
 9766:             }
 9767:         } else {
 9768:             $resulttext = '<span class="LC_error">'.
 9769:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 9770:         }
 9771:     } else {
 9772:         $resulttext = &mt('No changes made to bubblesheet format file'); 
 9773:     }
 9774:     if ($errors) {
 9775:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 9776:                        $errors.'</ul>';
 9777:     }
 9778:     return $resulttext;
 9779: }
 9780: 
 9781: sub modify_coursecategories {
 9782:     my ($dom,$lastactref,%domconfig) = @_;
 9783:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 9784:         $cathash);
 9785:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 9786:     my @catitems = ('unauth','auth');
 9787:     my @cattypes = ('std','domonly','codesrch','none');
 9788:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 9789:         $cathash = $domconfig{'coursecategories'}{'cats'};
 9790:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 9791:             $changes{'togglecats'} = 1;
 9792:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 9793:         }
 9794:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 9795:             $changes{'categorize'} = 1;
 9796:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 9797:         }
 9798:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
 9799:             $changes{'togglecatscomm'} = 1;
 9800:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
 9801:         }
 9802:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
 9803:             $changes{'categorizecomm'} = 1;
 9804:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
 9805:         }
 9806:         foreach my $item (@catitems) {
 9807:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
 9808:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
 9809:                     $changes{$item} = 1;
 9810:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
 9811:                 }
 9812:             }
 9813:         }
 9814:     } else {
 9815:         $changes{'togglecats'} = 1;
 9816:         $changes{'categorize'} = 1;
 9817:         $changes{'togglecatscomm'} = 1;
 9818:         $changes{'categorizecomm'} = 1;
 9819:         $domconfig{'coursecategories'} = {
 9820:                                              togglecats => $env{'form.togglecats'},
 9821:                                              categorize => $env{'form.categorize'},
 9822:                                              togglecatscomm => $env{'form.togglecatscomm'},
 9823:                                              categorizecomm => $env{'form.categorizecomm'},
 9824:                                          };
 9825:         foreach my $item (@catitems) {
 9826:             if ($env{'form.coursecat_'.$item} ne 'std') {
 9827:                 $changes{$item} = 1;
 9828:             }
 9829:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
 9830:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
 9831:             }
 9832:         }
 9833:     }
 9834:     if (ref($cathash) eq 'HASH') {
 9835:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 9836:             push (@deletecategory,'instcode::0');
 9837:         }
 9838:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
 9839:             push(@deletecategory,'communities::0');
 9840:         }
 9841:     }
 9842:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 9843:     if (ref($cathash) eq 'HASH') {
 9844:         if (@deletecategory > 0) {
 9845:             #FIXME Need to remove category from all courses using a deleted category 
 9846:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 9847:             foreach my $item (@deletecategory) {
 9848:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 9849:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 9850:                     $deletions{$item} = 1;
 9851:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 9852:                 }
 9853:             }
 9854:         }
 9855:         foreach my $item (keys(%{$cathash})) {
 9856:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 9857:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 9858:                 $reorderings{$item} = 1;
 9859:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 9860:             }
 9861:             if ($env{'form.addcategory_name_'.$item} ne '') {
 9862:                 my $newcat = $env{'form.addcategory_name_'.$item};
 9863:                 my $newdepth = $depth+1;
 9864:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 9865:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 9866:                 $adds{$newitem} = 1; 
 9867:             }
 9868:             if ($env{'form.subcat_'.$item} ne '') {
 9869:                 my $newcat = $env{'form.subcat_'.$item};
 9870:                 my $newdepth = $depth+1;
 9871:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 9872:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 9873:                 $adds{$newitem} = 1;
 9874:             }
 9875:         }
 9876:     }
 9877:     if ($env{'form.instcode'} eq '1') {
 9878:         if (ref($cathash) eq 'HASH') {
 9879:             my $newitem = 'instcode::0';
 9880:             if ($cathash->{$newitem} eq '') {  
 9881:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 9882:                 $adds{$newitem} = 1;
 9883:             }
 9884:         } else {
 9885:             my $newitem = 'instcode::0';
 9886:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 9887:             $adds{$newitem} = 1;
 9888:         }
 9889:     }
 9890:     if ($env{'form.communities'} eq '1') {
 9891:         if (ref($cathash) eq 'HASH') {
 9892:             my $newitem = 'communities::0';
 9893:             if ($cathash->{$newitem} eq '') {
 9894:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 9895:                 $adds{$newitem} = 1;
 9896:             }
 9897:         } else {
 9898:             my $newitem = 'communities::0';
 9899:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 9900:             $adds{$newitem} = 1;
 9901:         }
 9902:     }
 9903:     if ($env{'form.addcategory_name'} ne '') {
 9904:         if (($env{'form.addcategory_name'} ne 'instcode') &&
 9905:             ($env{'form.addcategory_name'} ne 'communities')) {
 9906:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 9907:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 9908:             $adds{$newitem} = 1;
 9909:         }
 9910:     }
 9911:     my $putresult;
 9912:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 9913:         if (keys(%deletions) > 0) {
 9914:             foreach my $key (keys(%deletions)) {
 9915:                 if ($predelallitems{$key} ne '') {
 9916:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 9917:                 }
 9918:             }
 9919:         }
 9920:         my (@chkcats,@chktrails,%chkallitems);
 9921:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 9922:         if (ref($chkcats[0]) eq 'ARRAY') {
 9923:             my $depth = 0;
 9924:             my $chg = 0;
 9925:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 9926:                 my $name = $chkcats[0][$i];
 9927:                 my $item;
 9928:                 if ($name eq '') {
 9929:                     $chg ++;
 9930:                 } else {
 9931:                     $item = &escape($name).'::0';
 9932:                     if ($chg) {
 9933:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 9934:                     }
 9935:                     $depth ++; 
 9936:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 9937:                     $depth --;
 9938:                 }
 9939:             }
 9940:         }
 9941:     }
 9942:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 9943:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 9944:         if ($putresult eq 'ok') {
 9945:             my %title = (
 9946:                          togglecats     => 'Show/Hide a course in catalog',
 9947:                          categorize     => 'Assign a category to a course',
 9948:                          togglecatscomm => 'Show/Hide a community in catalog',
 9949:                          categorizecomm => 'Assign a category to a community',
 9950:                         );
 9951:             my %level = (
 9952:                          dom  => 'set in Domain ("Modify Course/Community")',
 9953:                          crs  => 'set in Course ("Course Configuration")',
 9954:                          comm => 'set in Community ("Community Configuration")',
 9955:                          none     => 'No catalog',
 9956:                          std      => 'Standard catalog',
 9957:                          domonly  => 'Domain-only catalog',
 9958:                          codesrch => 'Code search form',
 9959:                         );
 9960:             $resulttext = &mt('Changes made:').'<ul>';
 9961:             if ($changes{'togglecats'}) {
 9962:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 9963:             }
 9964:             if ($changes{'categorize'}) {
 9965:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 9966:             }
 9967:             if ($changes{'togglecatscomm'}) {
 9968:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
 9969:             }
 9970:             if ($changes{'categorizecomm'}) {
 9971:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
 9972:             }
 9973:             if ($changes{'unauth'}) {
 9974:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
 9975:             }
 9976:             if ($changes{'auth'}) {
 9977:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
 9978:             }
 9979:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 9980:                 my $cathash;
 9981:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 9982:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 9983:                 } else {
 9984:                     $cathash = {};
 9985:                 } 
 9986:                 my (@cats,@trails,%allitems);
 9987:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 9988:                 if (keys(%deletions) > 0) {
 9989:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 9990:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 9991:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 9992:                     }
 9993:                     $resulttext .= '</ul></li>';
 9994:                 }
 9995:                 if (keys(%reorderings) > 0) {
 9996:                     my %sort_by_trail;
 9997:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 9998:                     foreach my $key (keys(%reorderings)) {
 9999:                         if ($allitems{$key} ne '') {
10000:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10001:                         }
10002:                     }
10003:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10004:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
10005:                     }
10006:                     $resulttext .= '</ul></li>';
10007:                 }
10008:                 if (keys(%adds) > 0) {
10009:                     my %sort_by_trail;
10010:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10011:                     foreach my $key (keys(%adds)) {
10012:                         if ($allitems{$key} ne '') {
10013:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10014:                         }
10015:                     }
10016:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10017:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
10018:                     }
10019:                     $resulttext .= '</ul></li>';
10020:                 }
10021:             }
10022:             $resulttext .= '</ul>';
10023:             if ($changes{'unauth'} || $changes{'auth'}) {
10024:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10025:                 if ($changes{'auth'}) {
10026:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10027:                 }
10028:                 if ($changes{'unauth'}) {
10029:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10030:                 }
10031:                 my $cachetime = 24*60*60;
10032:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10033:                 if (ref($lastactref) eq 'HASH') {
10034:                     $lastactref->{'domdefaults'} = 1;
10035:                 }
10036:             }
10037:         } else {
10038:             $resulttext = '<span class="LC_error">'.
10039:                           &mt('An error occurred: [_1]',$putresult).'</span>';
10040:         }
10041:     } else {
10042:         $resulttext = &mt('No changes made to course and community categories');
10043:     }
10044:     return $resulttext;
10045: }
10046: 
10047: sub modify_serverstatuses {
10048:     my ($dom,%domconfig) = @_;
10049:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10050:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10051:         %currserverstatus = %{$domconfig{'serverstatuses'}};
10052:     }
10053:     my @pages = &serverstatus_pages();
10054:     foreach my $type (@pages) {
10055:         $newserverstatus{$type}{'namedusers'} = '';
10056:         $newserverstatus{$type}{'machines'} = '';
10057:         if (defined($env{'form.'.$type.'_namedusers'})) {
10058:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10059:             my @okusers;
10060:             foreach my $user (@users) {
10061:                 my ($uname,$udom) = split(/:/,$user);
10062:                 if (($udom =~ /^$match_domain$/) &&   
10063:                     (&Apache::lonnet::domain($udom)) &&
10064:                     ($uname =~ /^$match_username$/)) {
10065:                     if (!grep(/^\Q$user\E/,@okusers)) {
10066:                         push(@okusers,$user);
10067:                     }
10068:                 }
10069:             }
10070:             if (@okusers > 0) {
10071:                  @okusers = sort(@okusers);
10072:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10073:             }
10074:         }
10075:         if (defined($env{'form.'.$type.'_machines'})) {
10076:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10077:             my @okmachines;
10078:             foreach my $ip (@machines) {
10079:                 my @parts = split(/\./,$ip);
10080:                 next if (@parts < 4);
10081:                 my $badip = 0;
10082:                 for (my $i=0; $i<4; $i++) {
10083:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10084:                         $badip = 1;
10085:                         last;
10086:                     }
10087:                 }
10088:                 if (!$badip) {
10089:                     push(@okmachines,$ip);     
10090:                 }
10091:             }
10092:             @okmachines = sort(@okmachines);
10093:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10094:         }
10095:     }
10096:     my %serverstatushash =  (
10097:                                 serverstatuses => \%newserverstatus,
10098:                             );
10099:     foreach my $type (@pages) {
10100:         foreach my $setting ('namedusers','machines') {
10101:             my (@current,@new);
10102:             if (ref($currserverstatus{$type}) eq 'HASH') {
10103:                 if ($currserverstatus{$type}{$setting} ne '') { 
10104:                     @current = split(/,/,$currserverstatus{$type}{$setting});
10105:                 }
10106:             }
10107:             if ($newserverstatus{$type}{$setting} ne '') {
10108:                 @new = split(/,/,$newserverstatus{$type}{$setting});
10109:             }
10110:             if (@current > 0) {
10111:                 if (@new > 0) {
10112:                     foreach my $item (@current) {
10113:                         if (!grep(/^\Q$item\E$/,@new)) {
10114:                             $changes{$type}{$setting} = 1;
10115:                             last;
10116:                         }
10117:                     }
10118:                     foreach my $item (@new) {
10119:                         if (!grep(/^\Q$item\E$/,@current)) {
10120:                             $changes{$type}{$setting} = 1;
10121:                             last;
10122:                         }
10123:                     }
10124:                 } else {
10125:                     $changes{$type}{$setting} = 1;
10126:                 }
10127:             } elsif (@new > 0) {
10128:                 $changes{$type}{$setting} = 1;
10129:             }
10130:         }
10131:     }
10132:     if (keys(%changes) > 0) {
10133:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
10134:         my $putresult = &Apache::lonnet::put_dom('configuration',
10135:                                                  \%serverstatushash,$dom);
10136:         if ($putresult eq 'ok') {
10137:             $resulttext .= &mt('Changes made:').'<ul>';
10138:             foreach my $type (@pages) {
10139:                 if (ref($changes{$type}) eq 'HASH') {
10140:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
10141:                     if ($changes{$type}{'namedusers'}) {
10142:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
10143:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10144:                         } else {
10145:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10146:                         }
10147:                     }
10148:                     if ($changes{$type}{'machines'}) {
10149:                         if ($newserverstatus{$type}{'machines'} eq '') {
10150:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10151:                         } else {
10152:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10153:                         }
10154: 
10155:                     }
10156:                     $resulttext .= '</ul></li>';
10157:                 }
10158:             }
10159:             $resulttext .= '</ul>';
10160:         } else {
10161:             $resulttext = '<span class="LC_error">'.
10162:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10163: 
10164:         }
10165:     } else {
10166:         $resulttext = &mt('No changes made to access to server status pages');
10167:     }
10168:     return $resulttext;
10169: }
10170: 
10171: sub modify_helpsettings {
10172:     my ($r,$dom,$confname,%domconfig) = @_;
10173:     my ($resulttext,$errors,%changes,%helphash);
10174:     my %defaultchecked = ('submitbugs' => 'on');
10175:     my @offon = ('off','on');
10176:     my @toggles = ('submitbugs');
10177:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10178:         foreach my $item (@toggles) {
10179:             if ($defaultchecked{$item} eq 'on') { 
10180:                 if ($domconfig{'helpsettings'}{$item} eq '') {
10181:                     if ($env{'form.'.$item} eq '0') {
10182:                         $changes{$item} = 1;
10183:                     }
10184:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10185:                     $changes{$item} = 1;
10186:                 }
10187:             } elsif ($defaultchecked{$item} eq 'off') {
10188:                 if ($domconfig{'helpsettings'}{$item} eq '') {
10189:                     if ($env{'form.'.$item} eq '1') {
10190:                         $changes{$item} = 1;
10191:                     }
10192:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10193:                     $changes{$item} = 1;
10194:                 }
10195:             }
10196:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10197:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
10198:             }
10199:         }
10200:     }
10201:     my $putresult;
10202:     if (keys(%changes) > 0) {
10203:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10204:         if ($putresult eq 'ok') {
10205:             $resulttext = &mt('Changes made:').'<ul>';
10206:             foreach my $item (sort(keys(%changes))) {
10207:                 if ($item eq 'submitbugs') {
10208:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10209:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10210:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10211:                 }
10212:             }
10213:             $resulttext .= '</ul>';
10214:         } else {
10215:             $resulttext = &mt('No changes made to help settings');
10216:             $errors .= '<li><span class="LC_error">'.
10217:                        &mt('An error occurred storing the settings: [_1]',
10218:                            $putresult).'</span></li>';
10219:         }
10220:     }
10221:     if ($errors) {
10222:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
10223:                        $errors.'</ul>';
10224:     }
10225:     return $resulttext;
10226: }
10227: 
10228: sub modify_coursedefaults {
10229:     my ($dom,$lastactref,%domconfig) = @_;
10230:     my ($resulttext,$errors,%changes,%defaultshash);
10231:     my %defaultchecked = (
10232:                            'uselcmath'       => 'on',
10233:                            'usejsme'         => 'on'
10234:                          );
10235:     my @toggles = ('uselcmath','usejsme');
10236:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
10237:                    'uploadquota_community','uploadquota_textbook');
10238:     my @types = ('official','unofficial','community','textbook');
10239:     my %staticdefaults = (
10240:                            anonsurvey_threshold => 10,
10241:                            uploadquota          => 500,
10242:                            postsubmit           => 60,
10243:                          );
10244: 
10245:     $defaultshash{'coursedefaults'} = {};
10246: 
10247:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10248:         if ($domconfig{'coursedefaults'} eq '') {
10249:             $domconfig{'coursedefaults'} = {};
10250:         }
10251:     }
10252: 
10253:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10254:         foreach my $item (@toggles) {
10255:             if ($defaultchecked{$item} eq 'on') {
10256:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
10257:                     ($env{'form.'.$item} eq '0')) {
10258:                     $changes{$item} = 1;
10259:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10260:                     $changes{$item} = 1;
10261:                 }
10262:             } elsif ($defaultchecked{$item} eq 'off') {
10263:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
10264:                     ($env{'form.'.$item} eq '1')) {
10265:                     $changes{$item} = 1;
10266:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10267:                     $changes{$item} = 1;
10268:                 }
10269:             }
10270:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10271:         }
10272:         foreach my $item (@numbers) {
10273:             my ($currdef,$newdef);
10274:             $newdef = $env{'form.'.$item};
10275:             if ($item eq 'anonsurvey_threshold') {
10276:                 $currdef = $domconfig{'coursedefaults'}{$item};
10277:                 $newdef =~ s/\D//g;
10278:                 if ($newdef eq '' || $newdef < 1) {
10279:                     $newdef = 1;
10280:                 }
10281:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
10282:             } else {
10283:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10284:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10285:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10286:                 }
10287:                 $newdef =~ s/[^\w.\-]//g;
10288:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10289:             }
10290:             if ($currdef ne $newdef) {
10291:                 my $staticdef;
10292:                 if ($item eq 'anonsurvey_threshold') {
10293:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10294:                         $changes{$item} = 1;
10295:                     }
10296:                 } else {
10297:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10298:                         $changes{'uploadquota'} = 1;
10299:                     }
10300:                 }
10301:             }
10302:         }
10303: 
10304:         my %credits;
10305:         foreach my $type (@types) {
10306:             unless ($type eq 'community') {
10307:                 $credits{$type} = $env{'form.'.$type.'_credits'};
10308:                 $credits{$type} =~ s/[^\d.]+//g;
10309:             }
10310:         }
10311:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10312:             ($env{'form.coursecredits'} eq '1')) {
10313:             $changes{'coursecredits'} = 1;
10314:             foreach my $type (keys(%credits)) {
10315:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10316:             }
10317:         } else {
10318:             if ($env{'form.coursecredits'} eq '1') {
10319:                 foreach my $type (@types) {
10320:                     unless ($type eq 'community') {
10321:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10322:                             $changes{'coursecredits'} = 1;
10323:                         }
10324:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10325:                     }
10326:                 }
10327:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10328:                 foreach my $type (@types) {
10329:                     unless ($type eq 'community') {
10330:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10331:                             $changes{'coursecredits'} = 1;
10332:                             last;
10333:                         }
10334:                     }
10335:                 }
10336:             }
10337:         }
10338:         if ($env{'form.postsubmit'} eq '1') {
10339:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10340:             my %currtimeout;
10341:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10342:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10343:                     $changes{'postsubmit'} = 1;
10344:                 }
10345:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10346:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10347:                 }
10348:             } else {
10349:                 $changes{'postsubmit'} = 1;
10350:             }
10351:             foreach my $type (@types) {
10352:                 my $timeout = $env{'form.'.$type.'_timeout'};
10353:                 $timeout =~ s/\D//g;
10354:                 if ($timeout == $staticdefaults{'postsubmit'}) {
10355:                     $timeout = '';
10356:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10357:                     $timeout = '0';
10358:                 }
10359:                 unless ($timeout eq '') {
10360:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10361:                 }
10362:                 if (exists($currtimeout{$type})) {
10363:                     if ($timeout ne $currtimeout{$type}) {
10364:                         $changes{'postsubmit'} = 1;
10365:                     }
10366:                 } elsif ($timeout ne '') {
10367:                     $changes{'postsubmit'} = 1;
10368:                 }
10369:             }
10370:         } else {
10371:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10372:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10373:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10374:                     $changes{'postsubmit'} = 1;
10375:                 }
10376:             } else {
10377:                 $changes{'postsubmit'} = 1;
10378:             }
10379:         }
10380:     }
10381:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10382:                                              $dom);
10383:     if ($putresult eq 'ok') {
10384:         if (keys(%changes) > 0) {
10385:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10386:             if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
10387:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) {
10388:                 foreach my $item ('uselcmath','usejsme') {
10389:                     if ($changes{$item}) {
10390:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10391:                     }
10392:                 }
10393:                 if ($changes{'coursecredits'}) {
10394:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10395:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10396:                             $domdefaults{$type.'credits'} =
10397:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10398:                         }
10399:                     }
10400:                 }
10401:                 if ($changes{'postsubmit'}) {
10402:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10403:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10404:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10405:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10406:                                 $domdefaults{$type.'postsubtimeout'} =
10407:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10408:                             }
10409:                         }
10410:                     }
10411:                 }
10412:                 if ($changes{'uploadquota'}) {
10413:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10414:                         foreach my $type (@types) {
10415:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10416:                         }
10417:                     }
10418:                 }
10419:                 my $cachetime = 24*60*60;
10420:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10421:                 if (ref($lastactref) eq 'HASH') {
10422:                     $lastactref->{'domdefaults'} = 1;
10423:                 }
10424:             }
10425:             $resulttext = &mt('Changes made:').'<ul>';
10426:             foreach my $item (sort(keys(%changes))) {
10427:                 if ($item eq 'uselcmath') {
10428:                     if ($env{'form.'.$item} eq '1') {
10429:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
10430:                     } else {
10431:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10432:                     }
10433:                 } elsif ($item eq 'usejsme') {
10434:                     if ($env{'form.'.$item} eq '1') {
10435:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10436:                     } else {
10437:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
10438:                     }
10439:                 } elsif ($item eq 'anonsurvey_threshold') {
10440:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
10441:                 } elsif ($item eq 'uploadquota') {
10442:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10443:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10444:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10445:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
10446:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10447: 
10448:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10449:                                        '</ul>'.
10450:                                        '</li>';
10451:                     } else {
10452:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10453:                     }
10454:                 } elsif ($item eq 'postsubmit') {
10455:                     if ($domdefaults{'postsubmit'} eq 'off') {
10456:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10457:                     } else {
10458:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10459:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10460:                             $resulttext .= &mt('durations:').'<ul>';
10461:                             foreach my $type (@types) {
10462:                                 $resulttext .= '<li>';
10463:                                 my $timeout;
10464:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10465:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10466:                                 }
10467:                                 my $display;
10468:                                 if ($timeout eq '0') {
10469:                                     $display = &mt('unlimited');
10470:                                 } elsif ($timeout eq '') {
10471:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10472:                                 } else {
10473:                                     $display = &mt('[quant,_1,second]',$timeout);
10474:                                 }
10475:                                 if ($type eq 'community') {
10476:                                     $resulttext .= &mt('Communities');
10477:                                 } elsif ($type eq 'official') {
10478:                                     $resulttext .= &mt('Official courses');
10479:                                 } elsif ($type eq 'unofficial') {
10480:                                     $resulttext .= &mt('Unofficial courses');
10481:                                 } elsif ($type eq 'textbook') {
10482:                                     $resulttext .= &mt('Textbook courses');
10483:                                 }
10484:                                 $resulttext .= ' -- '.$display.'</li>';
10485:                             }
10486:                             $resulttext .= '</ul>';
10487:                         }
10488:                         $resulttext .= '</li>';
10489:                     }
10490:                 } elsif ($item eq 'coursecredits') {
10491:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10492:                         if (($domdefaults{'officialcredits'} eq '') &&
10493:                             ($domdefaults{'unofficialcredits'} eq '') &&
10494:                             ($domdefaults{'textbookcredits'} eq '')) {
10495:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10496:                         } else {
10497:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10498:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10499:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
10500:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
10501:                                            '</ul>'.
10502:                                            '</li>';
10503:                         }
10504:                     } else {
10505:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10506:                     }
10507:                 }
10508:             }
10509:             $resulttext .= '</ul>';
10510:         } else {
10511:             $resulttext = &mt('No changes made to course defaults');
10512:         }
10513:     } else {
10514:         $resulttext = '<span class="LC_error">'.
10515:             &mt('An error occurred: [_1]',$putresult).'</span>';
10516:     }
10517:     return $resulttext;
10518: }
10519: 
10520: sub modify_selfenrollment {
10521:     my ($dom,$lastactref,%domconfig) = @_;
10522:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10523:     my @types = ('official','unofficial','community','textbook');
10524:     my %titles = &tool_titles();
10525:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10526:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10527:     $ordered{'default'} = ['types','registered','approval','limit'];
10528: 
10529:     my (%roles,%shown,%toplevel);
10530:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
10531: 
10532:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10533:         if ($domconfig{'selfenrollment'} eq '') {
10534:             $domconfig{'selfenrollment'} = {};
10535:         }
10536:     }
10537:     %toplevel = (
10538:                   admin      => 'Configuration Rights',
10539:                   default    => 'Default settings',
10540:                   validation => 'Validation of self-enrollment requests',
10541:                 );
10542:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10543: 
10544:     if (ref($ordered{'admin'}) eq 'ARRAY') {
10545:         foreach my $item (@{$ordered{'admin'}}) {
10546:             foreach my $type (@types) {
10547:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10548:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
10549:                 } else {
10550:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
10551:                 }
10552:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10553:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10554:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
10555:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
10556:                             push(@{$changes{'admin'}{$type}},$item);
10557:                         }
10558:                     } else {
10559:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
10560:                             push(@{$changes{'admin'}{$type}},$item);
10561:                         }
10562:                     }
10563:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10564:                     push(@{$changes{'admin'}{$type}},$item);
10565:                 }
10566:             }
10567:         }
10568:     }
10569: 
10570:     foreach my $item (@{$ordered{'default'}}) {
10571:         foreach my $type (@types) {
10572:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10573:             if ($item eq 'types') {
10574:                 unless (($value eq 'all') || ($value eq 'dom')) {
10575:                     $value = '';
10576:                 }
10577:             } elsif ($item eq 'registered') {
10578:                 unless ($value eq '1') {
10579:                     $value = 0;
10580:                 }
10581:             } elsif ($item eq 'approval') {
10582:                 unless ($value =~ /^[012]$/) {
10583:                     $value = 0;
10584:                 }
10585:             } else {
10586:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10587:                     $value = 'none';
10588:                 }
10589:             }
10590:             $selfenrollhash{'default'}{$type}{$item} = $value;
10591:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10592:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10593:                     if ($selfenrollhash{'default'}{$type}{$item} ne
10594:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
10595:                          push(@{$changes{'default'}{$type}},$item);
10596:                     }
10597:                 } else {
10598:                     push(@{$changes{'default'}{$type}},$item);
10599:                 }
10600:             } else {
10601:                 push(@{$changes{'default'}{$type}},$item);
10602:             }
10603:             if ($item eq 'limit') {
10604:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10605:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10606:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10607:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10608:                     }
10609:                 } else {
10610:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
10611:                 }
10612:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10613:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
10614:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
10615:                          push(@{$changes{'default'}{$type}},'cap');
10616:                     }
10617:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10618:                     push(@{$changes{'default'}{$type}},'cap');
10619:                 }
10620:             }
10621:         }
10622:     }
10623: 
10624:     foreach my $item (@{$itemsref}) {
10625:         if ($item eq 'fields') {
10626:             my @changed;
10627:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10628:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10629:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10630:             }
10631:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10632:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10633:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10634:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
10635:                 } else {
10636:                     @changed = @{$selfenrollhash{'validation'}{$item}};
10637:                 }
10638:             } else {
10639:                 @changed = @{$selfenrollhash{'validation'}{$item}};
10640:             }
10641:             if (@changed) {
10642:                 if ($selfenrollhash{'validation'}{$item}) { 
10643:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10644:                 } else {
10645:                     $changes{'validation'}{$item} = &mt('None');
10646:                 }
10647:             }
10648:         } else {
10649:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10650:             if ($item eq 'markup') {
10651:                if ($env{'form.selfenroll_validation_'.$item}) {
10652:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10653:                }
10654:             }
10655:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10656:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10657:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10658:                 }
10659:             }
10660:         }
10661:     }
10662: 
10663:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10664:                                              $dom);
10665:     if ($putresult eq 'ok') {
10666:         if (keys(%changes) > 0) {
10667:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10668:             $resulttext = &mt('Changes made:').'<ul>';
10669:             foreach my $key ('admin','default','validation') {
10670:                 if (ref($changes{$key}) eq 'HASH') {
10671:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10672:                     if ($key eq 'validation') {
10673:                         foreach my $item (@{$itemsref}) {
10674:                             if (exists($changes{$key}{$item})) {
10675:                                 if ($item eq 'markup') {
10676:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10677:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10678:                                 } else {  
10679:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10680:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10681:                                 }
10682:                             }
10683:                         }
10684:                     } else {
10685:                         foreach my $type (@types) {
10686:                             if ($type eq 'community') {
10687:                                 $roles{'1'} = &mt('Community personnel');
10688:                             } else {
10689:                                 $roles{'1'} = &mt('Course personnel');
10690:                             }
10691:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
10692:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10693:                                     if ($key eq 'admin') {
10694:                                         my @mgrdc = ();
10695:                                         if (ref($ordered{$key}) eq 'ARRAY') {
10696:                                             foreach my $item (@{$ordered{'admin'}}) {
10697:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
10698:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10699:                                                         push(@mgrdc,$item);
10700:                                                     }
10701:                                                 }
10702:                                             }
10703:                                             if (@mgrdc) {
10704:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10705:                                             } else {
10706:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
10707:                                             }
10708:                                         }
10709:                                     } else {
10710:                                         if (ref($ordered{$key}) eq 'ARRAY') {
10711:                                             foreach my $item (@{$ordered{$key}}) {
10712:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10713:                                                     $domdefaults{$type.'selfenroll'.$item} =
10714:                                                         $selfenrollhash{$key}{$type}{$item};
10715:                                                 }
10716:                                             }
10717:                                         }
10718:                                     }
10719:                                 }
10720:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
10721:                                 foreach my $item (@{$ordered{$key}}) {
10722:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10723:                                         $resulttext .= '<li>';
10724:                                         if ($key eq 'admin') {
10725:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10726:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10727:                                         } else {
10728:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10729:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10730:                                         }
10731:                                         $resulttext .= '</li>';
10732:                                     }
10733:                                 }
10734:                                 $resulttext .= '</ul></li>';
10735:                             }
10736:                         }
10737:                         $resulttext .= '</ul></li>'; 
10738:                     }
10739:                 }
10740:                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10741:                     my $cachetime = 24*60*60;
10742:                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10743:                     if (ref($lastactref) eq 'HASH') {
10744:                         $lastactref->{'domdefaults'} = 1;
10745:                     }
10746:                 }
10747:             }
10748:             $resulttext .= '</ul>';
10749:         } else {
10750:             $resulttext = &mt('No changes made to self-enrollment settings');
10751:         }
10752:     } else {
10753:         $resulttext = '<span class="LC_error">'.
10754:             &mt('An error occurred: [_1]',$putresult).'</span>';
10755:     }
10756:     return $resulttext;
10757: }
10758: 
10759: sub modify_usersessions {
10760:     my ($dom,$lastactref,%domconfig) = @_;
10761:     my @hostingtypes = ('version','excludedomain','includedomain');
10762:     my @offloadtypes = ('primary','default');
10763:     my %types = (
10764:                   remote => \@hostingtypes,
10765:                   hosted => \@hostingtypes,
10766:                   spares => \@offloadtypes,
10767:                 );
10768:     my @prefixes = ('remote','hosted','spares');
10769:     my @lcversions = &Apache::lonnet::all_loncaparevs();
10770:     my (%by_ip,%by_location,@intdoms);
10771:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10772:     my @locations = sort(keys(%by_location));
10773:     my (%defaultshash,%changes);
10774:     foreach my $prefix (@prefixes) {
10775:         $defaultshash{'usersessions'}{$prefix} = {};
10776:     }
10777:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10778:     my $resulttext;
10779:     my %iphost = &Apache::lonnet::get_iphost();
10780:     foreach my $prefix (@prefixes) {
10781:         next if ($prefix eq 'spares');
10782:         foreach my $type (@{$types{$prefix}}) {
10783:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10784:             if ($type eq 'version') {
10785:                 my $value = $env{'form.'.$prefix.'_'.$type};
10786:                 my $okvalue;
10787:                 if ($value ne '') {
10788:                     if (grep(/^\Q$value\E$/,@lcversions)) {
10789:                         $okvalue = $value;
10790:                     }
10791:                 }
10792:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
10793:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10794:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10795:                             if ($inuse == 0) {
10796:                                 $changes{$prefix}{$type} = 1;
10797:                             } else {
10798:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10799:                                     $changes{$prefix}{$type} = 1;
10800:                                 }
10801:                                 if ($okvalue ne '') {
10802:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10803:                                 } 
10804:                             }
10805:                         } else {
10806:                             if (($inuse == 1) && ($okvalue ne '')) {
10807:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10808:                                 $changes{$prefix}{$type} = 1;
10809:                             }
10810:                         }
10811:                     } else {
10812:                         if (($inuse == 1) && ($okvalue ne '')) {
10813:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10814:                             $changes{$prefix}{$type} = 1;
10815:                         }
10816:                     }
10817:                 } else {
10818:                     if (($inuse == 1) && ($okvalue ne '')) {
10819:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10820:                         $changes{$prefix}{$type} = 1;
10821:                     }
10822:                 }
10823:             } else {
10824:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10825:                 my @okvals;
10826:                 foreach my $val (@vals) {
10827:                     if ($val =~ /:/) {
10828:                         my @items = split(/:/,$val);
10829:                         foreach my $item (@items) {
10830:                             if (ref($by_location{$item}) eq 'ARRAY') {
10831:                                 push(@okvals,$item);
10832:                             }
10833:                         }
10834:                     } else {
10835:                         if (ref($by_location{$val}) eq 'ARRAY') {
10836:                             push(@okvals,$val);
10837:                         }
10838:                     }
10839:                 }
10840:                 @okvals = sort(@okvals);
10841:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
10842:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10843:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10844:                             if ($inuse == 0) {
10845:                                 $changes{$prefix}{$type} = 1; 
10846:                             } else {
10847:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10848:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10849:                                 if (@changed > 0) {
10850:                                     $changes{$prefix}{$type} = 1;
10851:                                 }
10852:                             }
10853:                         } else {
10854:                             if ($inuse == 1) {
10855:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10856:                                 $changes{$prefix}{$type} = 1;
10857:                             }
10858:                         } 
10859:                     } else {
10860:                         if ($inuse == 1) {
10861:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10862:                             $changes{$prefix}{$type} = 1;
10863:                         }
10864:                     }
10865:                 } else {
10866:                     if ($inuse == 1) {
10867:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10868:                         $changes{$prefix}{$type} = 1;
10869:                     }
10870:                 }
10871:             }
10872:         }
10873:     }
10874: 
10875:     my @alldoms = &Apache::lonnet::all_domains();
10876:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
10877:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10878:     my $savespares;
10879: 
10880:     foreach my $lonhost (sort(keys(%servers))) {
10881:         my $serverhomeID =
10882:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
10883:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
10884:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10885:         my %spareschg;
10886:         foreach my $type (@{$types{'spares'}}) {
10887:             my @okspares;
10888:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10889:             foreach my $server (@checked) {
10890:                 if (&Apache::lonnet::hostname($server) ne '') {
10891:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10892:                         unless (grep(/^\Q$server\E$/,@okspares)) {
10893:                             push(@okspares,$server);
10894:                         }
10895:                     }
10896:                 }
10897:             }
10898:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10899:             my $newspare;
10900:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10901:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
10902:                     $newspare = $new;
10903:                 }
10904:             }
10905:             my @spares;
10906:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10907:                 @spares = sort(@okspares,$newspare);
10908:             } else {
10909:                 @spares = sort(@okspares);
10910:             }
10911:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
10912:             if (ref($spareid{$lonhost}) eq 'HASH') {
10913:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
10914:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
10915:                     if (@diffs > 0) {
10916:                         $spareschg{$type} = 1;
10917:                     }
10918:                 }
10919:             }
10920:         }
10921:         if (keys(%spareschg) > 0) {
10922:             $changes{'spares'}{$lonhost} = \%spareschg;
10923:         }
10924:     }
10925:     $defaultshash{'usersessions'}{'offloadnow'} = {};
10926:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
10927:     my @okoffload;
10928:     if (@offloadnow) {
10929:         foreach my $server (@offloadnow) {
10930:             if (&Apache::lonnet::hostname($server) ne '') {
10931:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
10932:                     push(@okoffload,$server);
10933:                 }
10934:             }
10935:         }
10936:         if (@okoffload) {
10937:             foreach my $lonhost (@okoffload) {
10938:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
10939:             }
10940:         }
10941:     }
10942:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
10943:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10944:             if (ref($changes{'spares'}) eq 'HASH') {
10945:                 if (keys(%{$changes{'spares'}}) > 0) {
10946:                     $savespares = 1;
10947:                 }
10948:             }
10949:         } else {
10950:             $savespares = 1;
10951:         }
10952:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
10953:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
10954:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
10955:                     $changes{'offloadnow'} = 1;
10956:                     last;
10957:                 }
10958:             }
10959:             unless ($changes{'offloadnow'}) {
10960:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
10961:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
10962:                         $changes{'offloadnow'} = 1;
10963:                         last;
10964:                     }
10965:                 }
10966:             }
10967:         } elsif (@okoffload) {
10968:             $changes{'offloadnow'} = 1;
10969:         }
10970:     } elsif (@okoffload) {
10971:         $changes{'offloadnow'} = 1;
10972:     }
10973:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10974:     if ((keys(%changes) > 0) || ($savespares)) {
10975:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10976:                                                  $dom);
10977:         if ($putresult eq 'ok') {
10978:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10979:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10980:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10981:                 }
10982:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10983:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10984:                 }
10985:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
10986:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
10987:                 }
10988:             }
10989:             my $cachetime = 24*60*60;
10990:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10991:             if (ref($lastactref) eq 'HASH') {
10992:                 $lastactref->{'domdefaults'} = 1;
10993:             }
10994:             if (keys(%changes) > 0) {
10995:                 my %lt = &usersession_titles();
10996:                 $resulttext = &mt('Changes made:').'<ul>';
10997:                 foreach my $prefix (@prefixes) {
10998:                     if (ref($changes{$prefix}) eq 'HASH') {
10999:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11000:                         if ($prefix eq 'spares') {
11001:                             if (ref($changes{$prefix}) eq 'HASH') {
11002:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11003:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
11004:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
11005:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11006:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11007:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11008:                                         foreach my $type (@{$types{$prefix}}) {
11009:                                             if ($changes{$prefix}{$lonhost}{$type}) {
11010:                                                 my $offloadto = &mt('None');
11011:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11012:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
11013:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11014:                                                     }
11015:                                                 }
11016:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
11017:                                             }
11018:                                         }
11019:                                     }
11020:                                     $resulttext .= '</li>';
11021:                                 }
11022:                             }
11023:                         } else {
11024:                             foreach my $type (@{$types{$prefix}}) {
11025:                                 if (defined($changes{$prefix}{$type})) {
11026:                                     my $newvalue;
11027:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11028:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
11029:                                             if ($type eq 'version') {
11030:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11031:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11032:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11033:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11034:                                                 }
11035:                                             }
11036:                                         }
11037:                                     }
11038:                                     if ($newvalue eq '') {
11039:                                         if ($type eq 'version') {
11040:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11041:                                         } else {
11042:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11043:                                         }
11044:                                     } else {
11045:                                         if ($type eq 'version') {
11046:                                             $newvalue .= ' '.&mt('(or later)'); 
11047:                                         }
11048:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
11049:                                     }
11050:                                 }
11051:                             }
11052:                         }
11053:                         $resulttext .= '</ul>';
11054:                     }
11055:                 }
11056:                 if ($changes{'offloadnow'}) {
11057:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11058:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11059:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11060:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11061:                                 $resulttext .= '<li>'.$lonhost.'</li>';
11062:                             }
11063:                             $resulttext .= '</ul>';
11064:                         } else {
11065:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11066:                         }
11067:                     } else {
11068:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11069:                     }
11070:                 }
11071:                 $resulttext .= '</ul>';
11072:             } else {
11073:                 $resulttext = $nochgmsg;
11074:             }
11075:         } else {
11076:             $resulttext = '<span class="LC_error">'.
11077:                           &mt('An error occurred: [_1]',$putresult).'</span>';
11078:         }
11079:     } else {
11080:         $resulttext = $nochgmsg;
11081:     }
11082:     return $resulttext;
11083: }
11084: 
11085: sub modify_loadbalancing {
11086:     my ($dom,%domconfig) = @_;
11087:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
11088:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
11089:     my ($othertitle,$usertypes,$types) =
11090:         &Apache::loncommon::sorted_inst_types($dom);
11091:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
11092:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
11093:     my @sparestypes = ('primary','default');
11094:     my %typetitles = &sparestype_titles();
11095:     my $resulttext;
11096:     my (%currbalancer,%currtargets,%currrules,%existing);
11097:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11098:         %existing = %{$domconfig{'loadbalancing'}};
11099:     }
11100:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11101:                               \%currtargets,\%currrules);
11102:     my ($saveloadbalancing,%defaultshash,%changes);
11103:     my ($alltypes,$othertypes,$titles) =
11104:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11105:     my %ruletitles = &offloadtype_text();
11106:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11107:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11108:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11109:         if ($balancer eq '') {
11110:             next;
11111:         }
11112:         if (!exists($servers{$balancer})) {
11113:             if (exists($currbalancer{$balancer})) {
11114:                 push(@{$changes{'delete'}},$balancer);
11115:             }
11116:             next;
11117:         }
11118:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11119:             push(@{$changes{'delete'}},$balancer);
11120:             next;
11121:         }
11122:         if (!exists($currbalancer{$balancer})) {
11123:             push(@{$changes{'add'}},$balancer);
11124:         }
11125:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11126:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11127:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11128:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11129:             $saveloadbalancing = 1;
11130:         }
11131:         foreach my $sparetype (@sparestypes) {
11132:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11133:             my @offloadto;
11134:             foreach my $target (@targets) {
11135:                 if (($servers{$target}) && ($target ne $balancer)) {
11136:                     if ($sparetype eq 'default') {
11137:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11138:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
11139:                         }
11140:                     }
11141:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
11142:                         push(@offloadto,$target);
11143:                     }
11144:                 }
11145:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
11146:             }
11147:         }
11148:         if (ref($currtargets{$balancer}) eq 'HASH') {
11149:             foreach my $sparetype (@sparestypes) {
11150:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11151:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
11152:                     if (@targetdiffs > 0) {
11153:                         $changes{'curr'}{$balancer}{'targets'} = 1;
11154:                     }
11155:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11156:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11157:                         $changes{'curr'}{$balancer}{'targets'} = 1;
11158:                     }
11159:                 }
11160:             }
11161:         } else {
11162:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11163:                 foreach my $sparetype (@sparestypes) {
11164:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11165:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11166:                             $changes{'curr'}{$balancer}{'targets'} = 1;
11167:                         }
11168:                     }
11169:                 }
11170:             }
11171:         }
11172:         my $ishomedom;
11173:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11174:             $ishomedom = 1;
11175:         }
11176:         if (ref($alltypes) eq 'ARRAY') {
11177:             foreach my $type (@{$alltypes}) {
11178:                 my $rule;
11179:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
11180:                          (!$ishomedom)) {
11181:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11182:                 }
11183:                 if ($rule eq 'specific') {
11184:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11185:                     if (exists($servers{$specifiedhost})) {
11186:                         $rule = $specifiedhost;
11187:                     }
11188:                 }
11189:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11190:                 if (ref($currrules{$balancer}) eq 'HASH') {
11191:                     if ($rule ne $currrules{$balancer}{$type}) {
11192:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
11193:                     }
11194:                 } elsif ($rule ne '') {
11195:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
11196:                 }
11197:             }
11198:         }
11199:     }
11200:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11201:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11202:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11203:             $defaultshash{'loadbalancing'} = {};
11204:         }
11205:         my $putresult = &Apache::lonnet::put_dom('configuration',
11206:                                                  \%defaultshash,$dom);
11207:         if ($putresult eq 'ok') {
11208:             if (keys(%changes) > 0) {
11209:                 my %toupdate;
11210:                 if (ref($changes{'delete'}) eq 'ARRAY') {
11211:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
11212:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
11213:                         $toupdate{$balancer} = 1;
11214:                     }
11215:                 }
11216:                 if (ref($changes{'add'}) eq 'ARRAY') {
11217:                     foreach my $balancer (sort(@{$changes{'add'}})) {
11218:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
11219:                         $toupdate{$balancer} = 1;
11220:                     }
11221:                 }
11222:                 if (ref($changes{'curr'}) eq 'HASH') {
11223:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
11224:                         $toupdate{$balancer} = 1;
11225:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11226:                             if ($changes{'curr'}{$balancer}{'targets'}) {
11227:                                 my %offloadstr;
11228:                                 foreach my $sparetype (@sparestypes) {
11229:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11230:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11231:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11232:                                         }
11233:                                     }
11234:                                 }
11235:                                 if (keys(%offloadstr) == 0) {
11236:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
11237:                                 } else {
11238:                                     my $showoffload;
11239:                                     foreach my $sparetype (@sparestypes) {
11240:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
11241:                                         if (defined($offloadstr{$sparetype})) {
11242:                                             $showoffload .= $offloadstr{$sparetype};
11243:                                         } else {
11244:                                             $showoffload .= &mt('None');
11245:                                         }
11246:                                         $showoffload .= ('&nbsp;'x3);
11247:                                     }
11248:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
11249:                                 }
11250:                             }
11251:                         }
11252:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11253:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11254:                                 foreach my $type (@{$alltypes}) {
11255:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11256:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11257:                                         my $balancetext;
11258:                                         if ($rule eq '') {
11259:                                             $balancetext =  $ruletitles{'default'};
11260:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
11261:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11262:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11263:                                                 foreach my $sparetype (@sparestypes) {
11264:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11265:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11266:                                                     }
11267:                                                 }
11268:                                                 foreach my $item (@{$alltypes}) {
11269:                                                     next if ($item =~  /^_LC_ipchange/);
11270:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11271:                                                     if ($hasrule eq 'homeserver') {
11272:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
11273:                                                     } else {
11274:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11275:                                                             if ($servers{$hasrule}) {
11276:                                                                 $toupdate{$hasrule} = 1;
11277:                                                             }
11278:                                                         }
11279:                                                     }
11280:                                                 }
11281:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11282:                                                     $balancetext =  $ruletitles{$rule};
11283:                                                 } else {
11284:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11285:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
11286:                                                     if ($receiver) {
11287:                                                         $toupdate{$receiver};
11288:                                                     }
11289:                                                 }
11290:                                             } else {
11291:                                                 $balancetext =  $ruletitles{$rule};
11292:                                             }
11293:                                         } else {
11294:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11295:                                         }
11296:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
11297:                                     }
11298:                                 }
11299:                             }
11300:                         }
11301:                         if (keys(%toupdate)) {
11302:                             my %thismachine;
11303:                             my $updatedhere;
11304:                             my $cachetime = 60*60*24;
11305:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11306:                             foreach my $lonhost (keys(%toupdate)) {
11307:                                 if ($thismachine{$lonhost}) {
11308:                                     unless ($updatedhere) {
11309:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11310:                                                                       $defaultshash{'loadbalancing'},
11311:                                                                       $cachetime);
11312:                                         $updatedhere = 1;
11313:                                     }
11314:                                 } else {
11315:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11316:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11317:                                 }
11318:                             }
11319:                         }
11320:                     }
11321:                 }
11322:                 if ($resulttext ne '') {
11323:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
11324:                 } else {
11325:                     $resulttext = $nochgmsg;
11326:                 }
11327:             } else {
11328:                 $resulttext = $nochgmsg;
11329:             }
11330:         } else {
11331:             $resulttext = '<span class="LC_error">'.
11332:                           &mt('An error occurred: [_1]',$putresult).'</span>';
11333:         }
11334:     } else {
11335:         $resulttext = $nochgmsg;
11336:     }
11337:     return $resulttext;
11338: }
11339: 
11340: sub recurse_check {
11341:     my ($chkcats,$categories,$depth,$name) = @_;
11342:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11343:         my $chg = 0;
11344:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11345:             my $category = $chkcats->[$depth]{$name}[$j];
11346:             my $item;
11347:             if ($category eq '') {
11348:                 $chg ++;
11349:             } else {
11350:                 my $deeper = $depth + 1;
11351:                 $item = &escape($category).':'.&escape($name).':'.$depth;
11352:                 if ($chg) {
11353:                     $categories->{$item} -= $chg;
11354:                 }
11355:                 &recurse_check($chkcats,$categories,$deeper,$category);
11356:                 $deeper --;
11357:             }
11358:         }
11359:     }
11360:     return;
11361: }
11362: 
11363: sub recurse_cat_deletes {
11364:     my ($item,$coursecategories,$deletions) = @_;
11365:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11366:     my $subdepth = $depth + 1;
11367:     if (ref($coursecategories) eq 'HASH') {
11368:         foreach my $subitem (keys(%{$coursecategories})) {
11369:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11370:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11371:                 delete($coursecategories->{$subitem});
11372:                 $deletions->{$subitem} = 1;
11373:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
11374:             }
11375:         }
11376:     }
11377:     return;
11378: }
11379: 
11380: sub get_active_dcs {
11381:     my ($dom) = @_;
11382:     my $now = time;
11383:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
11384:     my %domcoords;
11385:     my $numdcs = 0;
11386:     foreach my $server (keys(%dompersonnel)) {
11387:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11388:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
11389:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
11390:         }
11391:     }
11392:     return %domcoords;
11393: }
11394: 
11395: sub active_dc_picker {
11396:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
11397:     my %domcoords = &get_active_dcs($dom);
11398:     my @domcoord = keys(%domcoords);
11399:     if (keys(%currhash)) {
11400:         foreach my $dc (keys(%currhash)) {
11401:             unless (exists($domcoords{$dc})) {
11402:                 push(@domcoord,$dc);
11403:             }
11404:         }
11405:     }
11406:     @domcoord = sort(@domcoord);
11407:     my $numdcs = scalar(@domcoord);
11408:     my $rows = 0;
11409:     my $table;
11410:     if ($numdcs > 1) {
11411:         $table = '<table>';
11412:         for (my $i=0; $i<@domcoord; $i++) {
11413:             my $rem = $i%($numinrow);
11414:             if ($rem == 0) {
11415:                 if ($i > 0) {
11416:                     $table .= '</tr>';
11417:                 }
11418:                 $table .= '<tr>';
11419:                 $rows ++;
11420:             }
11421:             my $check = '';
11422:             if ($inputtype eq 'radio') {
11423:                 if (keys(%currhash) == 0) {
11424:                     if (!$i) {
11425:                         $check = ' checked="checked"';
11426:                     }
11427:                 } elsif (exists($currhash{$domcoord[$i]})) {
11428:                     $check = ' checked="checked"';
11429:                 }
11430:             } else {
11431:                 if (exists($currhash{$domcoord[$i]})) {
11432:                     $check = ' checked="checked"';
11433:                 }
11434:             }
11435:             if ($i == @domcoord - 1) {
11436:                 my $colsleft = $numinrow - $rem;
11437:                 if ($colsleft > 1) {
11438:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
11439:                 } else {
11440:                     $table .= '<td class="LC_left_item">';
11441:                 }
11442:             } else {
11443:                 $table .= '<td class="LC_left_item">';
11444:             }
11445:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11446:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11447:             $table .= '<span class="LC_nobreak"><label>'.
11448:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
11449:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11450:             if ($user ne $dcname.':'.$dcdom) {
11451:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
11452:             }
11453:             $table .= '</label></span></td>';
11454:         }
11455:         $table .= '</tr></table>';
11456:     } elsif ($numdcs == 1) {
11457:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
11458:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11459:         if ($inputtype eq 'radio') {
11460:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
11461:             if ($user ne $dcname.':'.$dcdom) {
11462:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
11463:             }
11464:         } else {
11465:             my $check;
11466:             if (exists($currhash{$domcoord[0]})) {
11467:                 $check = ' checked="checked"';
11468:             }
11469:             $table = '<span class="LC_nobreak"><label>'.
11470:                      '<input type="checkbox" name="'.$name.'" '.
11471:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
11472:             if ($user ne $dcname.':'.$dcdom) {
11473:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
11474:             }
11475:             $table .= '</label></span>';
11476:             $rows ++;
11477:         }
11478:     }
11479:     return ($numdcs,$table,$rows);
11480: }
11481: 
11482: sub usersession_titles {
11483:     return &Apache::lonlocal::texthash(
11484:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11485:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
11486:                spares => 'Servers offloaded to, when busy',
11487:                version => 'LON-CAPA version requirement',
11488:                excludedomain => 'Allow all, but exclude specific domains',
11489:                includedomain => 'Deny all, but include specific domains',
11490:                primary => 'Primary (checked first)',
11491:                default => 'Default',
11492:            );
11493: }
11494: 
11495: sub id_for_thisdom {
11496:     my (%servers) = @_;
11497:     my %altids;
11498:     foreach my $server (keys(%servers)) {
11499:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11500:         if ($serverhome ne $server) {
11501:             $altids{$serverhome} = $server;
11502:         }
11503:     }
11504:     return %altids;
11505: }
11506: 
11507: sub count_servers {
11508:     my ($currbalancer,%servers) = @_;
11509:     my (@spares,$numspares);
11510:     foreach my $lonhost (sort(keys(%servers))) {
11511:         next if ($currbalancer eq $lonhost);
11512:         push(@spares,$lonhost);
11513:     }
11514:     if ($currbalancer) {
11515:         $numspares = scalar(@spares);
11516:     } else {
11517:         $numspares = scalar(@spares) - 1;
11518:     }
11519:     return ($numspares,@spares);
11520: }
11521: 
11522: sub lonbalance_targets_js {
11523:     my ($dom,$types,$servers,$settings) = @_;
11524:     my $select = &mt('Select');
11525:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
11526:     if (ref($servers) eq 'HASH') {
11527:         $alltargets = join("','",sort(keys(%{$servers})));
11528:         my @homedoms;
11529:         foreach my $server (sort(keys(%{$servers}))) {
11530:             if (&Apache::lonnet::host_domain($server) eq $dom) {
11531:                 push(@homedoms,'1');
11532:             } else {
11533:                 push(@homedoms,'0');
11534:             }
11535:         }
11536:         $allishome = join("','",@homedoms);
11537:     }
11538:     if (ref($types) eq 'ARRAY') {
11539:         if (@{$types} > 0) {
11540:             @alltypes = @{$types};
11541:         }
11542:     }
11543:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11544:     $allinsttypes = join("','",@alltypes);
11545:     my (%currbalancer,%currtargets,%currrules,%existing);
11546:     if (ref($settings) eq 'HASH') {
11547:         %existing = %{$settings};
11548:     }
11549:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11550:                               \%currtargets,\%currrules);
11551:     my $balancers = join("','",sort(keys(%currbalancer)));
11552:     return <<"END";
11553: 
11554: <script type="text/javascript">
11555: // <![CDATA[
11556: 
11557: currBalancers = new Array('$balancers');
11558: 
11559: function toggleTargets(balnum) {
11560:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11561:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11562:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11563:     var prevbalancer = prevhostitem.value;
11564:     var baltotal = document.getElementById('loadbalancing_total').value;
11565:     prevhostitem.value = balancer;
11566:     if (prevbalancer != '') {
11567:         var prevIdx = currBalancers.indexOf(prevbalancer);
11568:         if (prevIdx != -1) {
11569:             currBalancers.splice(prevIdx,1);
11570:         }
11571:     }
11572:     if (balancer == '') {
11573:         hideSpares(balnum);
11574:     } else {
11575:         var currIdx = currBalancers.indexOf(balancer);
11576:         if (currIdx == -1) {
11577:             currBalancers.push(balancer);
11578:         }
11579:         var homedoms = new Array('$allishome');
11580:         var ishomedom = homedoms[lonhostitem.selectedIndex];
11581:         showSpares(balancer,ishomedom,balnum);
11582:     }
11583:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
11584:     return;
11585: }
11586: 
11587: function showSpares(balancer,ishomedom,balnum) {
11588:     var alltargets = new Array('$alltargets');
11589:     var insttypes = new Array('$allinsttypes');
11590:     var offloadtypes = new Array('primary','default');
11591: 
11592:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11593:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
11594:  
11595:     for (var i=0; i<offloadtypes.length; i++) {
11596:         var count = 0;
11597:         for (var j=0; j<alltargets.length; j++) {
11598:             if (alltargets[j] != balancer) {
11599:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11600:                 item.value = alltargets[j];
11601:                 item.style.textAlign='left';
11602:                 item.style.textFace='normal';
11603:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11604:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
11605:                     item.disabled = '';
11606:                 } else {
11607:                     item.disabled = 'disabled';
11608:                     item.checked = false;
11609:                 }
11610:                 count ++;
11611:             }
11612:         }
11613:     }
11614:     for (var k=0; k<insttypes.length; k++) {
11615:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
11616:             if (ishomedom == 1) {
11617:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11618:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
11619:             } else {
11620:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11621:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
11622:             }
11623:         } else {
11624:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11625:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
11626:         }
11627:         if ((insttypes[k] != '_LC_external') && 
11628:             ((insttypes[k] != '_LC_internetdom') ||
11629:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
11630:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11631:             item.options.length = 0;
11632:             item.options[0] = new Option("","",true,true);
11633:             var idx = 0;
11634:             for (var m=0; m<alltargets.length; m++) {
11635:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11636:                     idx ++;
11637:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11638:                 }
11639:             }
11640:         }
11641:     }
11642:     return;
11643: }
11644: 
11645: function hideSpares(balnum) {
11646:     var alltargets = new Array('$alltargets');
11647:     var insttypes = new Array('$allinsttypes');
11648:     var offloadtypes = new Array('primary','default');
11649: 
11650:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11651:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
11652: 
11653:     var total = alltargets.length - 1;
11654:     for (var i=0; i<offloadtypes; i++) {
11655:         for (var j=0; j<total; j++) {
11656:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11657:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11658:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
11659:         }
11660:     }
11661:     for (var k=0; k<insttypes.length; k++) {
11662:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11663:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
11664:         if (insttypes[k] != '_LC_external') {
11665:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11666:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
11667:         }
11668:     }
11669:     return;
11670: }
11671: 
11672: function checkOffloads(item,balnum,type) {
11673:     var alltargets = new Array('$alltargets');
11674:     var offloadtypes = new Array('primary','default');
11675:     if (item.checked) {
11676:         var total = alltargets.length - 1;
11677:         var other;
11678:         if (type == offloadtypes[0]) {
11679:             other = offloadtypes[1];
11680:         } else {
11681:             other = offloadtypes[0];
11682:         }
11683:         for (var i=0; i<total; i++) {
11684:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
11685:             if (server == item.value) {
11686:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11687:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
11688:                 }
11689:             }
11690:         }
11691:     }
11692:     return;
11693: }
11694: 
11695: function singleServerToggle(balnum,type) {
11696:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
11697:     if (offloadtoSelIdx == 0) {
11698:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11699:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
11700: 
11701:     } else {
11702:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11703:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11704:     }
11705:     return;
11706: }
11707: 
11708: function balanceruleChange(formname,balnum,type) {
11709:     if (type == '_LC_external') {
11710:         return;
11711:     }
11712:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
11713:     for (var i=0; i<typesRules.length; i++) {
11714:         if (formname.elements[typesRules[i]].checked) {
11715:             if (formname.elements[typesRules[i]].value != 'specific') {
11716:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11717:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
11718:             } else {
11719:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11720:             }
11721:         }
11722:     }
11723:     return;
11724: }
11725: 
11726: function balancerDeleteChange(balnum) {
11727:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11728:     var baltotal = document.getElementById('loadbalancing_total').value;
11729:     var addtarget;
11730:     var removetarget;
11731:     var action = 'delete';
11732:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
11733:         var lonhost = hostitem.value;
11734:         var currIdx = currBalancers.indexOf(lonhost);
11735:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11736:             if (currIdx != -1) {
11737:                 currBalancers.splice(currIdx,1);
11738:             }
11739:             addtarget = lonhost;
11740:         } else {
11741:             if (currIdx == -1) {
11742:                 currBalancers.push(lonhost);
11743:             }
11744:             removetarget = lonhost;
11745:             action = 'undelete';
11746:         }
11747:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
11748:     }
11749:     return;
11750: }
11751: 
11752: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11753:     if (baltotal > 1) {
11754:         var offloadtypes = new Array('primary','default');
11755:         var alltargets = new Array('$alltargets');
11756:         var insttypes = new Array('$allinsttypes');
11757:         for (var i=0; i<baltotal; i++) {
11758:             if (i != balnum) {
11759:                 for (var j=0; j<offloadtypes.length; j++) {
11760:                     var total = alltargets.length - 1;
11761:                     for (var k=0; k<total; k++) {
11762:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11763:                         var server = serveritem.value;
11764:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
11765:                             if (server == addtarget) {
11766:                                 serveritem.disabled = '';
11767:                             }
11768:                         }
11769:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11770:                             if (server == removetarget) {
11771:                                 serveritem.disabled = 'disabled';
11772:                                 serveritem.checked = false;
11773:                             }
11774:                         }
11775:                     }
11776:                 }
11777:                 for (var j=0; j<insttypes.length; j++) {
11778:                     if (insttypes[j] != '_LC_external') {
11779:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11780:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11781:                             var currSel = singleserver.selectedIndex;
11782:                             var currVal = singleserver.options[currSel].value;
11783:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11784:                                 var numoptions = singleserver.options.length;
11785:                                 var needsnew = 1;
11786:                                 for (var k=0; k<numoptions; k++) {
11787:                                     if (singleserver.options[k] == addtarget) {
11788:                                         needsnew = 0;
11789:                                         break;
11790:                                     }
11791:                                 }
11792:                                 if (needsnew == 1) {
11793:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11794:                                 }
11795:                             }
11796:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11797:                                 singleserver.options.length = 0;
11798:                                 if ((currVal) && (currVal != removetarget)) {
11799:                                     singleserver.options[0] = new Option("","",false,false);
11800:                                 } else {
11801:                                     singleserver.options[0] = new Option("","",true,true);
11802:                                 }
11803:                                 var idx = 0;
11804:                                 for (var m=0; m<alltargets.length; m++) {
11805:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
11806:                                         idx ++;
11807:                                         if (currVal == alltargets[m]) {
11808:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11809:                                         } else {
11810:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11811:                                         }
11812:                                     }
11813:                                 }
11814:                             }
11815:                         }
11816:                     }
11817:                 }
11818:             }
11819:         }
11820:     }
11821:     return;
11822: }
11823: 
11824: // ]]>
11825: </script>
11826: 
11827: END
11828: }
11829: 
11830: sub new_spares_js {
11831:     my @sparestypes = ('primary','default');
11832:     my $types = join("','",@sparestypes);
11833:     my $select = &mt('Select');
11834:     return <<"END";
11835: 
11836: <script type="text/javascript">
11837: // <![CDATA[
11838: 
11839: function updateNewSpares(formname,lonhost) {
11840:     var types = new Array('$types');
11841:     var include = new Array();
11842:     var exclude = new Array();
11843:     for (var i=0; i<types.length; i++) {
11844:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11845:         for (var j=0; j<spareboxes.length; j++) {
11846:             if (formname.elements[spareboxes[j]].checked) {
11847:                 exclude.push(formname.elements[spareboxes[j]].value);
11848:             } else {
11849:                 include.push(formname.elements[spareboxes[j]].value);
11850:             }
11851:         }
11852:     }
11853:     for (var i=0; i<types.length; i++) {
11854:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11855:         var selIdx = newSpare.selectedIndex;
11856:         var currnew = newSpare.options[selIdx].value;
11857:         var okSpares = new Array();
11858:         for (var j=0; j<newSpare.options.length; j++) {
11859:             var possible = newSpare.options[j].value;
11860:             if (possible != '') {
11861:                 if (exclude.indexOf(possible) == -1) {
11862:                     okSpares.push(possible);
11863:                 } else {
11864:                     if (currnew == possible) {
11865:                         selIdx = 0;
11866:                     }
11867:                 }
11868:             }
11869:         }
11870:         for (var k=0; k<include.length; k++) {
11871:             if (okSpares.indexOf(include[k]) == -1) {
11872:                 okSpares.push(include[k]);
11873:             }
11874:         }
11875:         okSpares.sort();
11876:         newSpare.options.length = 0;
11877:         if (selIdx == 0) {
11878:             newSpare.options[0] = new Option("$select","",true,true);
11879:         } else {
11880:             newSpare.options[0] = new Option("$select","",false,false);
11881:         }
11882:         for (var m=0; m<okSpares.length; m++) {
11883:             var idx = m+1;
11884:             var selThis = 0;
11885:             if (selIdx != 0) {
11886:                 if (okSpares[m] == currnew) {
11887:                     selThis = 1;
11888:                 }
11889:             }
11890:             if (selThis == 1) {
11891:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11892:             } else {
11893:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11894:             }
11895:         }
11896:     }
11897:     return;
11898: }
11899: 
11900: function checkNewSpares(lonhost,type) {
11901:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11902:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
11903:     if (chosen != '') { 
11904:         var othertype;
11905:         var othernewSpare;
11906:         if (type == 'primary') {
11907:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
11908:         }
11909:         if (type == 'default') {
11910:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11911:         }
11912:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11913:             othernewSpare.selectedIndex = 0;
11914:         }
11915:     }
11916:     return;
11917: }
11918: 
11919: // ]]>
11920: </script>
11921: 
11922: END
11923: 
11924: }
11925: 
11926: sub common_domprefs_js {
11927:     return <<"END";
11928: 
11929: <script type="text/javascript">
11930: // <![CDATA[
11931: 
11932: function getIndicesByName(formname,item) {
11933:     var group = new Array();
11934:     for (var i=0;i<formname.elements.length;i++) {
11935:         if (formname.elements[i].name == item) {
11936:             group.push(formname.elements[i].id);
11937:         }
11938:     }
11939:     return group;
11940: }
11941: 
11942: // ]]>
11943: </script>
11944: 
11945: END
11946: 
11947: }
11948: 
11949: sub recaptcha_js {
11950:     my %lt = &captcha_phrases();
11951:     return <<"END";
11952: 
11953: <script type="text/javascript">
11954: // <![CDATA[
11955: 
11956: function updateCaptcha(caller,context) {
11957:     var privitem;
11958:     var pubitem;
11959:     var privtext;
11960:     var pubtext;
11961:     if (document.getElementById(context+'_recaptchapub')) {
11962:         pubitem = document.getElementById(context+'_recaptchapub');
11963:     } else {
11964:         return;
11965:     }
11966:     if (document.getElementById(context+'_recaptchapriv')) {
11967:         privitem = document.getElementById(context+'_recaptchapriv');
11968:     } else {
11969:         return;
11970:     }
11971:     if (document.getElementById(context+'_recaptchapubtxt')) {
11972:         pubtext = document.getElementById(context+'_recaptchapubtxt');
11973:     } else {
11974:         return;
11975:     }
11976:     if (document.getElementById(context+'_recaptchaprivtxt')) {
11977:         privtext = document.getElementById(context+'_recaptchaprivtxt');
11978:     } else {
11979:         return;
11980:     }
11981:     if (caller.checked) {
11982:         if (caller.value == 'recaptcha') {
11983:             pubitem.type = 'text';
11984:             privitem.type = 'text';
11985:             pubitem.size = '40';
11986:             privitem.size = '40';
11987:             pubtext.innerHTML = "$lt{'pub'}";
11988:             privtext.innerHTML = "$lt{'priv'}";
11989:         } else {
11990:             pubitem.type = 'hidden';
11991:             privitem.type = 'hidden';
11992:             pubtext.innerHTML = '';
11993:             privtext.innerHTML = '';
11994:         }
11995:     }
11996:     return;
11997: }
11998: 
11999: // ]]>
12000: </script>
12001: 
12002: END
12003: 
12004: }
12005: 
12006: sub toggle_display_js {
12007:     return <<"END";
12008: 
12009: <script type="text/javascript">
12010: // <![CDATA[
12011: 
12012: function toggleDisplay(domForm,caller) {
12013:     if (document.getElementById(caller)) {
12014:         var divitem = document.getElementById(caller);
12015:         var optionsElement = domForm.coursecredits;
12016:         if (caller == 'emailoptions') {
12017:             optionsElement = domForm.cancreate_email; 
12018:         }
12019:         if (caller == 'studentsubmission') {
12020:             optionsElement = domForm.postsubmit;
12021:         }
12022:         if (optionsElement.length) {
12023:             var currval;
12024:             for (var i=0; i<optionsElement.length; i++) {
12025:                 if (optionsElement[i].checked) {
12026:                    currval = optionsElement[i].value;
12027:                 }
12028:             }
12029:             if (currval == 1) {
12030:                 divitem.style.display = 'block';
12031:             } else {
12032:                 divitem.style.display = 'none';
12033:             }
12034:         }
12035:     }
12036:     return;
12037: }
12038: 
12039: // ]]>
12040: </script>
12041: 
12042: END
12043: 
12044: }
12045: 
12046: sub captcha_phrases {
12047:     return &Apache::lonlocal::texthash (
12048:                  priv => 'Private key',
12049:                  pub  => 'Public key',
12050:                  original  => 'original (CAPTCHA)',
12051:                  recaptcha => 'successor (ReCAPTCHA)',
12052:                  notused   => 'unused',
12053:     );
12054: }
12055: 
12056: sub devalidate_remote_domconfs {
12057:     my ($dom,$cachekeys) = @_;
12058:     return unless (ref($cachekeys) eq 'HASH');
12059:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
12060:     my %thismachine;
12061:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12062:     my @posscached = ('domainconfig','domdefaults');
12063:     if (keys(%servers)) {
12064:         foreach my $server (keys(%servers)) {
12065:             next if ($thismachine{$server});
12066:             my @cached;
12067:             foreach my $name (@posscached) {
12068:                 if ($cachekeys->{$name}) {
12069:                     push(@cached,&escape($name).':'.&escape($dom));
12070:                 }
12071:             }
12072:             if (@cached) {
12073:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12074:             }
12075:         }
12076:     }
12077:     return;
12078: }
12079: 
12080: 1;

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