File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.261: download - view: text, annotated - select for diffs
Wed Apr 1 23:22:10 2015 UTC (9 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6771
  Domain configuration to switch active users from a server in the domain.
  - When the page has loaded on the session hosting server, javascript will
    cause display of an alert and will switch user's session to another server
    in the domain, after 5s. Submit buttons for homewrk problems disabled for
    those 5s.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.261 2015/04/01 23:22:10 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','helpsettings',
  217:                 'coursedefaults','usersessions','loadbalancing',
  218:                 'requestauthor','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','helpsettings',
  224:                        'coursedefaults','selfenrollment','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:         'helpsettings' =>
  415:                  {text   => 'Help page settings',
  416:                   help   => 'Domain_Configuration_Help_Settings',
  417:                   header => [{col1 => 'Help Settings (logged-in users)',
  418:                               col2 => 'Value'}],
  419:                   print  => \&print_helpsettings,
  420:                   modify => \&modify_helpsettings,
  421:                  },
  422:         'coursedefaults' => 
  423:                  {text => 'Course/Community defaults',
  424:                   help => 'Domain_Configuration_Course_Defaults',
  425:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
  426:                               col2 => 'Value',},
  427:                              {col1 => 'Defaults which can be overridden for each course by a DC',
  428:                               col2 => 'Value',},],
  429:                   print => \&print_coursedefaults,
  430:                   modify => \&modify_coursedefaults,
  431:                  },
  432:         'selfenrollment' => 
  433:                  {text   => 'Self-enrollment in Course/Community',
  434:                   help   => 'Domain_Configuration_Selfenrollment',
  435:                   header => [{col1 => 'Configuration Rights',
  436:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
  437:                              {col1 => 'Defaults',
  438:                               col2 => 'Value'},
  439:                              {col1 => 'Self-enrollment validation (optional)',
  440:                               col2 => 'Value'},],
  441:                   print => \&print_selfenrollment,
  442:                   modify => \&modify_selfenrollment,
  443:                  },
  444:         'privacy' => 
  445:                  {text   => 'User Privacy',
  446:                   help   => 'Domain_Configuration_User_Privacy',
  447:                   header => [{col1 => 'Setting',
  448:                               col2 => 'Value',}],
  449:                   print => \&print_privacy,
  450:                   modify => \&modify_privacy,
  451:                  },
  452:         'usersessions' =>
  453:                  {text  => 'User session hosting/offloading',
  454:                   help  => 'Domain_Configuration_User_Sessions',
  455:                   header => [{col1 => 'Domain server',
  456:                               col2 => 'Servers to offload sessions to when busy'},
  457:                              {col1 => 'Hosting of users from other domains',
  458:                               col2 => 'Rules'},
  459:                              {col1 => "Hosting domain's own users elsewhere",
  460:                               col2 => 'Rules'}],
  461:                   print => \&print_usersessions,
  462:                   modify => \&modify_usersessions,
  463:                  },
  464:          'loadbalancing' =>
  465:                  {text  => 'Dedicated Load Balancer(s)',
  466:                   help  => 'Domain_Configuration_Load_Balancing',
  467:                   header => [{col1 => 'Balancers',
  468:                               col2 => 'Default destinations',
  469:                               col3 => 'User affiliation',
  470:                               col4 => 'Overrides'},
  471:                             ],
  472:                   print => \&print_loadbalancing,
  473:                   modify => \&modify_loadbalancing,
  474:                  },
  475:     );
  476:     if (keys(%servers) > 1) {
  477:         $prefs{'login'}  = { text   => 'Log-in page options',
  478:                              help   => 'Domain_Configuration_Login_Page',
  479:                             header => [{col1 => 'Log-in Service',
  480:                                         col2 => 'Server Setting',},
  481:                                        {col1 => 'Log-in Page Items',
  482:                                         col2 => ''},
  483:                                        {col1 => 'Log-in Help',
  484:                                         col2 => 'Value'},
  485:                                        {col1 => 'Custom HTML in document head',
  486:                                         col2 => 'Value'}],
  487:                             print => \&print_login,
  488:                             modify => \&modify_login,
  489:                            };
  490:     }
  491: 
  492:     my @roles = ('student','coordinator','author','admin');
  493:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  494:     &Apache::lonhtmlcommon::add_breadcrumb
  495:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  496:       text=>"Settings to display/modify"});
  497:     my $confname = $dom.'-domainconfig';
  498: 
  499:     if ($phase eq 'process') {
  500:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
  501:                                                               \%prefs,\%domconfig,$confname,\@roles);
  502:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
  503:             $r->rflush();
  504:             &devalidate_remote_domconfs($dom,$result);
  505:         }
  506:     } elsif ($phase eq 'display') {
  507:         my $js = &recaptcha_js().
  508:                  &toggle_display_js();
  509:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
  510:             my ($othertitle,$usertypes,$types) =
  511:                 &Apache::loncommon::sorted_inst_types($dom);
  512:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
  513:                                           $domconfig{'loadbalancing'}).
  514:                    &new_spares_js().
  515:                    &common_domprefs_js().
  516:                    &Apache::loncommon::javascript_array_indexof();
  517:         }
  518:         if (grep(/^requestcourses$/,@actions)) {
  519:             my $javascript_validations;
  520:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
  521:             $js .= <<END;
  522: <script type="text/javascript">
  523: $javascript_validations
  524: </script>
  525: $coursebrowserjs
  526: END
  527:         }
  528:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
  529:     } else {
  530: # check if domconfig user exists for the domain.
  531:         my $servadm = $r->dir_config('lonAdmEMail');
  532:         my ($configuserok,$author_ok,$switchserver) =
  533:             &config_check($dom,$confname,$servadm);
  534:         unless ($configuserok eq 'ok') {
  535:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
  536:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
  537:                           $confname).
  538:                       '<br />'
  539:             );
  540:             if ($switchserver) {
  541:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
  542:                           '<br />'.
  543:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
  544:                           '<br />'.
  545:                           &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).
  546:                           '<br />'.
  547:                           &mt('To do that now, use the following link: [_1]',$switchserver)
  548:                 );
  549:             } else {
  550:                 $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.').
  551:                           '<br />'.
  552:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
  553:                 );
  554:             }
  555:             $r->print(&Apache::loncommon::end_page());
  556:             return OK;
  557:         }
  558:         if (keys(%domconfig) == 0) {
  559:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  560:             my @ids=&Apache::lonnet::current_machine_ids();
  561:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  562:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  563:                 my @loginimages = ('img','logo','domlogo','login');
  564:                 my $custom_img_count = 0;
  565:                 foreach my $img (@loginimages) {
  566:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  567:                         $custom_img_count ++;
  568:                     }
  569:                 }
  570:                 foreach my $role (@roles) {
  571:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  572:                         $custom_img_count ++;
  573:                     }
  574:                 }
  575:                 if ($custom_img_count > 0) {
  576:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
  577:                     my $switch_server = &check_switchserver($dom,$confname);
  578:                     $r->print(
  579:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  580:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  581:     &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 />'.
  582:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  583:                     if ($switch_server) {
  584:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  585:                     }
  586:                     $r->print(&Apache::loncommon::end_page());
  587:                     return OK;
  588:                 }
  589:             }
  590:         }
  591:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
  592:     }
  593:     return OK;
  594: }
  595: 
  596: sub process_changes {
  597:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
  598:     my %domconfig;
  599:     if (ref($values) eq 'HASH') {
  600:         %domconfig = %{$values};
  601:     }
  602:     my $output;
  603:     if ($action eq 'login') {
  604:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
  605:     } elsif ($action eq 'rolecolors') {
  606:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  607:                                      $lastactref,%domconfig);
  608:     } elsif ($action eq 'quotas') {
  609:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
  610:     } elsif ($action eq 'autoenroll') {
  611:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
  612:     } elsif ($action eq 'autoupdate') {
  613:         $output = &modify_autoupdate($dom,%domconfig);
  614:     } elsif ($action eq 'autocreate') {
  615:         $output = &modify_autocreate($dom,%domconfig);
  616:     } elsif ($action eq 'directorysrch') {
  617:         $output = &modify_directorysrch($dom,%domconfig);
  618:     } elsif ($action eq 'usercreation') {
  619:         $output = &modify_usercreation($dom,%domconfig);
  620:     } elsif ($action eq 'selfcreation') {
  621:         $output = &modify_selfcreation($dom,%domconfig);
  622:     } elsif ($action eq 'usermodification') {
  623:         $output = &modify_usermodification($dom,%domconfig);
  624:     } elsif ($action eq 'contacts') {
  625:         $output = &modify_contacts($dom,$lastactref,%domconfig);
  626:     } elsif ($action eq 'defaults') {
  627:         $output = &modify_defaults($dom,$lastactref,%domconfig);
  628:     } elsif ($action eq 'scantron') {
  629:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
  630:     } elsif ($action eq 'coursecategories') {
  631:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
  632:     } elsif ($action eq 'serverstatuses') {
  633:         $output = &modify_serverstatuses($dom,%domconfig);
  634:     } elsif ($action eq 'requestcourses') {
  635:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
  636:     } elsif ($action eq 'requestauthor') {
  637:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
  638:     } elsif ($action eq 'helpsettings') {
  639:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
  640:     } elsif ($action eq 'coursedefaults') {
  641:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
  642:     } elsif ($action eq 'selfenrollment') {
  643:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
  644:     } elsif ($action eq 'usersessions') {
  645:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
  646:     } elsif ($action eq 'loadbalancing') {
  647:         $output = &modify_loadbalancing($dom,%domconfig);
  648:     }
  649:     return $output;
  650: }
  651: 
  652: sub print_config_box {
  653:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  654:     my $rowtotal = 0;
  655:     my $output;
  656:     if ($action eq 'coursecategories') {
  657:         $output = &coursecategories_javascript($settings);
  658:     } elsif ($action eq 'defaults') {
  659:         $output = &defaults_javascript($settings); 
  660:     }
  661:     $output .=
  662:          '<table class="LC_nested_outer">
  663:           <tr>
  664:            <th align="left" valign="middle"><span class="LC_nobreak">'.
  665:            &mt($item->{text}).'&nbsp;'.
  666:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
  667:           '</tr>';
  668:     $rowtotal ++;
  669:     my $numheaders = 1;
  670:     if (ref($item->{'header'}) eq 'ARRAY') {
  671:         $numheaders = scalar(@{$item->{'header'}});
  672:     }
  673:     if ($numheaders > 1) {
  674:         my $colspan = '';
  675:         my $rightcolspan = '';
  676:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
  677:             (($action eq 'login') && ($numheaders < 4))) {
  678:             $colspan = ' colspan="2"';
  679:         }
  680:         if ($action eq 'usersessions') {
  681:             $rightcolspan = ' colspan="3"'; 
  682:         }
  683:         $output .= '
  684:           <tr>
  685:            <td>
  686:             <table class="LC_nested">
  687:              <tr class="LC_info_row">
  688:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
  689:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  690:              </tr>';
  691:         $rowtotal ++;
  692:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
  693:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
  694:             ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
  695:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
  696:         } elsif ($action eq 'coursecategories') {
  697:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
  698:         } elsif ($action eq 'login') {
  699:             if ($numheaders == 4) {
  700:                 $colspan = ' colspan="2"';
  701:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
  702:             } else {
  703:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
  704:             }
  705:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
  706:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  707:         } elsif ($action eq 'rolecolors') {
  708:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  709:         }
  710:         $output .= '
  711:            </table>
  712:           </td>
  713:          </tr>
  714:          <tr>
  715:            <td>
  716:             <table class="LC_nested">
  717:              <tr class="LC_info_row">
  718:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
  719:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
  720:              </tr>';
  721:             $rowtotal ++;
  722:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
  723:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
  724:             ($action eq 'usersessions') || ($action eq 'coursecategories')) {
  725:             if ($action eq 'coursecategories') {
  726:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
  727:                 $colspan = ' colspan="2"';
  728:             } else {
  729:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
  730:             }
  731:             $output .= '
  732:            </table>
  733:           </td>
  734:          </tr>
  735:          <tr>
  736:            <td>
  737:             <table class="LC_nested">
  738:              <tr class="LC_info_row">
  739:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  740:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
  741:              </tr>'."\n";
  742:             if ($action eq 'coursecategories') {
  743:                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
  744:             } else {
  745:                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
  746:             }
  747:             $rowtotal ++;
  748:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
  749:                   ($action eq 'defaults')) {
  750:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
  751:         } elsif ($action eq 'login') {
  752:             if ($numheaders == 4) {
  753:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
  754:            </table>
  755:           </td>
  756:          </tr>
  757:          <tr>
  758:            <td>
  759:             <table class="LC_nested">
  760:              <tr class="LC_info_row">
  761:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  762:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
  763:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
  764:                 $rowtotal ++;
  765:             } else {
  766:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
  767:             }
  768:             $output .= '
  769:            </table>
  770:           </td>
  771:          </tr>
  772:          <tr>
  773:            <td>
  774:             <table class="LC_nested">
  775:              <tr class="LC_info_row">';
  776:             if ($numheaders == 4) {
  777:                 $output .= '
  778:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  779:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  780:              </tr>';
  781:             } else {
  782:                 $output .= '
  783:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  784:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
  785:              </tr>';
  786:             }
  787:             $rowtotal ++;
  788:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
  789:         } elsif ($action eq 'requestcourses') {
  790:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
  791:             $rowtotal ++;
  792:             $output .= &print_studentcode($settings,\$rowtotal).'
  793:            </table>
  794:           </td>
  795:          </tr>
  796:          <tr>
  797:            <td>
  798:             <table class="LC_nested">
  799:              <tr class="LC_info_row">
  800:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  801:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
  802:                        &textbookcourses_javascript($settings).
  803:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
  804:             </table>
  805:            </td>
  806:           </tr>
  807:          <tr>
  808:            <td>
  809:             <table class="LC_nested">
  810:              <tr class="LC_info_row">
  811:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  812:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
  813:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
  814:             </table>
  815:            </td>
  816:           </tr>
  817:           <tr>
  818:            <td>
  819:             <table class="LC_nested">
  820:              <tr class="LC_info_row">
  821:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
  822:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
  823:              </tr>'.
  824:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
  825:         } elsif ($action eq 'requestauthor') {
  826:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
  827:             $rowtotal ++;
  828:         } elsif ($action eq 'rolecolors') {
  829:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  830:            </table>
  831:           </td>
  832:          </tr>
  833:          <tr>
  834:            <td>
  835:             <table class="LC_nested">
  836:              <tr class="LC_info_row">
  837:               <td class="LC_left_item"'.$colspan.' valign="top">'.
  838:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
  839:               <td class="LC_right_item" valign="top">'.
  840:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
  841:              </tr>'.
  842:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  843:            </table>
  844:           </td>
  845:          </tr>
  846:          <tr>
  847:            <td>
  848:             <table class="LC_nested">
  849:              <tr class="LC_info_row">
  850:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  851:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  852:              </tr>'.
  853:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  854:             $rowtotal += 2;
  855:         }
  856:     } else {
  857:         $output .= '
  858:           <tr>
  859:            <td>
  860:             <table class="LC_nested">
  861:              <tr class="LC_info_row">';
  862:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  863:             $output .= '  
  864:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  865:         } elsif ($action eq 'serverstatuses') {
  866:             $output .= '
  867:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
  868:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
  869: 
  870:         } else {
  871:             $output .= '
  872:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  873:         }
  874:         if (defined($item->{'header'}->[0]->{'col3'})) {
  875:             $output .= '<td class="LC_left_item" valign="top">'.
  876:                        &mt($item->{'header'}->[0]->{'col2'});
  877:             if ($action eq 'serverstatuses') {
  878:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
  879:             } 
  880:         } else {
  881:             $output .= '<td class="LC_right_item" valign="top">'.
  882:                        &mt($item->{'header'}->[0]->{'col2'});
  883:         }
  884:         $output .= '</td>';
  885:         if ($item->{'header'}->[0]->{'col3'}) {
  886:             if (defined($item->{'header'}->[0]->{'col4'})) {
  887:                 $output .= '<td class="LC_left_item" valign="top">'.
  888:                             &mt($item->{'header'}->[0]->{'col3'});
  889:             } else {
  890:                 $output .= '<td class="LC_right_item" valign="top">'.
  891:                            &mt($item->{'header'}->[0]->{'col3'});
  892:             }
  893:             if ($action eq 'serverstatuses') {
  894:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
  895:             }
  896:             $output .= '</td>';
  897:         }
  898:         if ($item->{'header'}->[0]->{'col4'}) {
  899:             $output .= '<td class="LC_right_item" valign="top">'.
  900:                        &mt($item->{'header'}->[0]->{'col4'});
  901:         }
  902:         $output .= '</tr>';
  903:         $rowtotal ++;
  904:         if ($action eq 'quotas') {
  905:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  906:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
  907:                  ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
  908:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
  909:         } elsif ($action eq 'scantron') {
  910:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
  911:         } elsif ($action eq 'helpsettings') {
  912:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
  913:         }
  914:     }
  915:     $output .= '
  916:    </table>
  917:   </td>
  918:  </tr>
  919: </table><br />';
  920:     return ($output,$rowtotal);
  921: }
  922: 
  923: sub print_login {
  924:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
  925:     my ($css_class,$datatable);
  926:     my %choices = &login_choices();
  927: 
  928:     if ($caller eq 'service') {
  929:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
  930:         my $choice = $choices{'disallowlogin'};
  931:         $css_class = ' class="LC_odd_row"';
  932:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
  933:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
  934:                       '<th>'.$choices{'server'}.'</th>'.
  935:                       '<th>'.$choices{'serverpath'}.'</th>'.
  936:                       '<th>'.$choices{'custompath'}.'</th>'.
  937:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
  938:         my %disallowed;
  939:         if (ref($settings) eq 'HASH') {
  940:             if (ref($settings->{'loginvia'}) eq 'HASH') {
  941:                %disallowed = %{$settings->{'loginvia'}};
  942:             }
  943:         }
  944:         foreach my $lonhost (sort(keys(%servers))) {
  945:             my $direct = 'selected="selected"';
  946:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  947:                 if ($disallowed{$lonhost}{'server'} ne '') {
  948:                     $direct = '';
  949:                 }
  950:             }
  951:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
  952:                           '<td><select name="'.$lonhost.'_server">'.
  953:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
  954:                           '</option>';
  955:             foreach my $hostid (sort(keys(%servers))) {
  956:                 next if ($servers{$hostid} eq $servers{$lonhost});
  957:                 my $selected = '';
  958:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  959:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
  960:                         $selected = 'selected="selected"';
  961:                     }
  962:                 }
  963:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
  964:                               $servers{$hostid}.'</option>';
  965:             }
  966:             $datatable .= '</select></td>'.
  967:                           '<td><select name="'.$lonhost.'_serverpath">';
  968:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
  969:                 my $pathname = $path;
  970:                 if ($path eq 'custom') {
  971:                     $pathname = &mt('Custom Path').' ->';
  972:                 }
  973:                 my $selected = '';
  974:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  975:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
  976:                         $selected = 'selected="selected"';
  977:                     }
  978:                 } elsif ($path eq '') {
  979:                     $selected = 'selected="selected"';
  980:                 }
  981:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
  982:             }
  983:             $datatable .= '</select></td>';
  984:             my ($custom,$exempt);
  985:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  986:                 $custom = $disallowed{$lonhost}{'custompath'};
  987:                 $exempt = $disallowed{$lonhost}{'exempt'};
  988:             }
  989:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
  990:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
  991:                           '</tr>';
  992:         }
  993:         $datatable .= '</table></td></tr>';
  994:         return $datatable;
  995:     } elsif ($caller eq 'page') {
  996:         my %defaultchecked = ( 
  997:                                'coursecatalog' => 'on',
  998:                                'helpdesk'      => 'on',
  999:                                'adminmail'     => 'off',
 1000:                                'newuser'       => 'off',
 1001:                              );
 1002:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 1003:         my (%checkedon,%checkedoff);
 1004:         foreach my $item (@toggles) {
 1005:             if ($defaultchecked{$item} eq 'on') { 
 1006:                 $checkedon{$item} = ' checked="checked" ';
 1007:                 $checkedoff{$item} = ' ';
 1008:             } elsif ($defaultchecked{$item} eq 'off') {
 1009:                 $checkedoff{$item} = ' checked="checked" ';
 1010:                 $checkedon{$item} = ' ';
 1011:             }
 1012:         }
 1013:         my @images = ('img','logo','domlogo','login');
 1014:         my @logintext = ('textcol','bgcol');
 1015:         my @bgs = ('pgbg','mainbg','sidebg');
 1016:         my @links = ('link','alink','vlink');
 1017:         my %designhash = &Apache::loncommon::get_domainconf($dom);
 1018:         my %defaultdesign = %Apache::loncommon::defaultdesign;
 1019:         my (%is_custom,%designs);
 1020:         my %defaults = (
 1021:                        font => $defaultdesign{'login.font'},
 1022:                        );
 1023:         foreach my $item (@images) {
 1024:             $defaults{$item} = $defaultdesign{'login.'.$item};
 1025:             $defaults{'showlogo'}{$item} = 1;
 1026:         }
 1027:         foreach my $item (@bgs) {
 1028:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
 1029:         }
 1030:         foreach my $item (@logintext) {
 1031:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
 1032:         }
 1033:         foreach my $item (@links) {
 1034:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
 1035:         }
 1036:         if (ref($settings) eq 'HASH') {
 1037:             foreach my $item (@toggles) {
 1038:                 if ($settings->{$item} eq '1') {
 1039:                     $checkedon{$item} =  ' checked="checked" ';
 1040:                     $checkedoff{$item} = ' ';
 1041:                 } elsif ($settings->{$item} eq '0') {
 1042:                     $checkedoff{$item} =  ' checked="checked" ';
 1043:                     $checkedon{$item} = ' ';
 1044:                 }
 1045:             }
 1046:             foreach my $item (@images) {
 1047:                 if (defined($settings->{$item})) {
 1048:                     $designs{$item} = $settings->{$item};
 1049:                     $is_custom{$item} = 1;
 1050:                 }
 1051:                 if (defined($settings->{'showlogo'}{$item})) {
 1052:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
 1053:                 }
 1054:             }
 1055:             foreach my $item (@logintext) {
 1056:                 if ($settings->{$item} ne '') {
 1057:                     $designs{'logintext'}{$item} = $settings->{$item};
 1058:                     $is_custom{$item} = 1;
 1059:                 }
 1060:             }
 1061:             if ($settings->{'font'} ne '') {
 1062:                 $designs{'font'} = $settings->{'font'};
 1063:                 $is_custom{'font'} = 1;
 1064:             }
 1065:             foreach my $item (@bgs) {
 1066:                 if ($settings->{$item} ne '') {
 1067:                     $designs{'bgs'}{$item} = $settings->{$item};
 1068:                     $is_custom{$item} = 1;
 1069:                 }
 1070:             }
 1071:             foreach my $item (@links) {
 1072:                 if ($settings->{$item} ne '') {
 1073:                     $designs{'links'}{$item} = $settings->{$item};
 1074:                     $is_custom{$item} = 1;
 1075:                 }
 1076:             }
 1077:         } else {
 1078:             if ($designhash{$dom.'.login.font'} ne '') {
 1079:                 $designs{'font'} = $designhash{$dom.'.login.font'};
 1080:                 $is_custom{'font'} = 1;
 1081:             }
 1082:             foreach my $item (@images) {
 1083:                 if ($designhash{$dom.'.login.'.$item} ne '') {
 1084:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
 1085:                     $is_custom{$item} = 1;
 1086:                 }
 1087:             }
 1088:             foreach my $item (@bgs) {
 1089:                 if ($designhash{$dom.'.login.'.$item} ne '') {
 1090:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
 1091:                     $is_custom{$item} = 1;
 1092:                 }
 1093:             }
 1094:             foreach my $item (@links) {
 1095:                 if ($designhash{$dom.'.login.'.$item} ne '') {
 1096:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
 1097:                     $is_custom{$item} = 1;
 1098:                 }
 1099:             }
 1100:         }
 1101:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
 1102:                                                       logo => 'Institution Logo',
 1103:                                                       domlogo => 'Domain Logo',
 1104:                                                       login => 'Login box');
 1105:         my $itemcount = 1;
 1106:         foreach my $item (@toggles) {
 1107:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1108:             $datatable .=  
 1109:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
 1110:                 '</td><td>'.
 1111:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
 1112:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
 1113:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
 1114:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
 1115:                 '</tr>';
 1116:             $itemcount ++;
 1117:         }
 1118:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
 1119:         $datatable .= '</tr></table></td></tr>';
 1120:     } elsif ($caller eq 'help') {
 1121:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
 1122:         my $switchserver = &check_switchserver($dom,$confname);
 1123:         my $itemcount = 1;
 1124:         $defaulturl = '/adm/loginproblems.html';
 1125:         $defaulttype = 'default';
 1126:         %lt = &Apache::lonlocal::texthash (
 1127:                      del     => 'Delete?',
 1128:                      rep     => 'Replace:',
 1129:                      upl     => 'Upload:',
 1130:                      default => 'Default',
 1131:                      custom  => 'Custom',
 1132:                                              );
 1133:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 1134:         my @currlangs;
 1135:         if (ref($settings) eq 'HASH') {
 1136:             if (ref($settings->{'helpurl'}) eq 'HASH') {
 1137:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
 1138:                     next if ($settings->{'helpurl'}{$key} eq '');
 1139:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
 1140:                     $type{$key} = 'custom';
 1141:                     unless ($key eq 'nolang') {
 1142:                         push(@currlangs,$key);
 1143:                     }
 1144:                 }
 1145:             } elsif ($settings->{'helpurl'} ne '') {
 1146:                 $type{'nolang'} = 'custom';
 1147:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
 1148:             }
 1149:         }
 1150:         foreach my $lang ('nolang',sort(@currlangs)) {
 1151:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 1152:             $datatable .= '<tr'.$css_class.'>';
 1153:             if ($url{$lang} eq '') {
 1154:                 $url{$lang} = $defaulturl;
 1155:             }
 1156:             if ($type{$lang} eq '') {
 1157:                 $type{$lang} = $defaulttype;
 1158:             }
 1159:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
 1160:             if ($lang eq 'nolang') {
 1161:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
 1162:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
 1163:             } else {
 1164:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
 1165:                                   $langchoices{$lang},
 1166:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
 1167:             }
 1168:             $datatable .= '</span></td>'."\n".
 1169:                           '<td class="LC_left_item">';
 1170:             if ($type{$lang} eq 'custom') {
 1171:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1172:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
 1173:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
 1174:             } else {
 1175:                 $datatable .= $lt{'upl'};
 1176:             }
 1177:             $datatable .='<br />';
 1178:             if ($switchserver) {
 1179:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1180:             } else {
 1181:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
 1182:             }
 1183:             $datatable .= '</td></tr>';
 1184:             $itemcount ++;
 1185:         }
 1186:         my @addlangs;
 1187:         foreach my $lang (sort(keys(%langchoices))) {
 1188:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
 1189:             push(@addlangs,$lang);
 1190:         }
 1191:         if (@addlangs > 0) {
 1192:             my %toadd;
 1193:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
 1194:             $toadd{''} = &mt('Select');
 1195:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 1196:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
 1197:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
 1198:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
 1199:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
 1200:             if ($switchserver) {
 1201:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1202:             } else {
 1203:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
 1204:             }
 1205:             $datatable .= '</td></tr>';
 1206:             $itemcount ++;
 1207:         }
 1208:         $datatable .= &captcha_choice('login',$settings,$itemcount);
 1209:     } elsif ($caller eq 'headtag') {
 1210:         my %domservers = &Apache::lonnet::get_servers($dom);
 1211:         my $choice = $choices{'headtag'};
 1212:         $css_class = ' class="LC_odd_row"';
 1213:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
 1214:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
 1215:                       '<th>'.$choices{'current'}.'</th>'.
 1216:                       '<th>'.$choices{'action'}.'</th>'.
 1217:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
 1218:         my (%currurls,%currexempt);
 1219:         if (ref($settings) eq 'HASH') {
 1220:             if (ref($settings->{'headtag'}) eq 'HASH') {
 1221:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
 1222:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
 1223:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
 1224:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
 1225:                     }
 1226:                 }
 1227:             }
 1228:         }
 1229:         my %lt = &Apache::lonlocal::texthash(
 1230:                                                del  => 'Delete?',
 1231:                                                rep  => 'Replace:',
 1232:                                                upl  => 'Upload:',
 1233:                                                curr => 'View contents',
 1234:                                                none => 'None',
 1235:         );
 1236:         my $switchserver = &check_switchserver($dom,$confname);
 1237:         foreach my $lonhost (sort(keys(%domservers))) {
 1238:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
 1239:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
 1240:             if ($currurls{$lonhost}) {
 1241:                 $datatable .= '<td class="LC_right_item"><a href="'.
 1242:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
 1243:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
 1244:                               '">'.$lt{'curr'}.'</a></td>'.
 1245:                               '<td><span class="LC_nobreak"><label>'.
 1246:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
 1247:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
 1248:             } else {
 1249:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
 1250:             }
 1251:             $datatable .='<br />';
 1252:             if ($switchserver) {
 1253:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1254:             } else {
 1255:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
 1256:             }
 1257:             $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
 1258:         }
 1259:         $datatable .= '</table></td></tr>';
 1260:     }
 1261:     return $datatable;
 1262: }
 1263: 
 1264: sub login_choices {
 1265:     my %choices =
 1266:         &Apache::lonlocal::texthash (
 1267:             coursecatalog => 'Display Course/Community Catalog link?',
 1268:             adminmail     => "Display Administrator's E-mail Address?",
 1269:             helpdesk      => 'Display "Contact Helpdesk" link',
 1270:             disallowlogin => "Login page requests redirected",
 1271:             hostid        => "Server",
 1272:             server        => "Redirect to:",
 1273:             serverpath    => "Path",
 1274:             custompath    => "Custom", 
 1275:             exempt        => "Exempt IP(s)",
 1276:             directlogin   => "No redirect",
 1277:             newuser       => "Link to create a user account",
 1278:             img           => "Header",
 1279:             logo          => "Main Logo",
 1280:             domlogo       => "Domain Logo",
 1281:             login         => "Log-in Header", 
 1282:             textcol       => "Text color",
 1283:             bgcol         => "Box color",
 1284:             bgs           => "Background colors",
 1285:             links         => "Link colors",
 1286:             font          => "Font color",
 1287:             pgbg          => "Header",
 1288:             mainbg        => "Page",
 1289:             sidebg        => "Login box",
 1290:             link          => "Link",
 1291:             alink         => "Active link",
 1292:             vlink         => "Visited link",
 1293:             headtag       => "Custom markup",
 1294:             action        => "Action",
 1295:             current       => "Current",
 1296:         );
 1297:     return %choices;
 1298: }
 1299: 
 1300: sub print_rolecolors {
 1301:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
 1302:     my %choices = &color_font_choices();
 1303:     my @bgs = ('pgbg','tabbg','sidebg');
 1304:     my @links = ('link','alink','vlink');
 1305:     my @images = ('img');
 1306:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
 1307:     my %designhash = &Apache::loncommon::get_domainconf($dom);
 1308:     my %defaultdesign = %Apache::loncommon::defaultdesign;
 1309:     my (%is_custom,%designs);
 1310:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
 1311:     if (ref($settings) eq 'HASH') {
 1312:         if (ref($settings->{$role}) eq 'HASH') {
 1313:             if ($settings->{$role}->{'img'} ne '') {
 1314:                 $designs{'img'} = $settings->{$role}->{'img'};
 1315:                 $is_custom{'img'} = 1;
 1316:             }
 1317:             if ($settings->{$role}->{'font'} ne '') {
 1318:                 $designs{'font'} = $settings->{$role}->{'font'};
 1319:                 $is_custom{'font'} = 1;
 1320:             }
 1321:             if ($settings->{$role}->{'fontmenu'} ne '') {
 1322:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
 1323:                 $is_custom{'fontmenu'} = 1;
 1324:             }
 1325:             foreach my $item (@bgs) {
 1326:                 if ($settings->{$role}->{$item} ne '') {
 1327:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
 1328:                     $is_custom{$item} = 1;
 1329:                 }
 1330:             }
 1331:             foreach my $item (@links) {
 1332:                 if ($settings->{$role}->{$item} ne '') {
 1333:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
 1334:                     $is_custom{$item} = 1;
 1335:                 }
 1336:             }
 1337:         }
 1338:     } else {
 1339:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
 1340:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
 1341:             $is_custom{'img'} = 1;
 1342:         }
 1343:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
 1344:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
 1345:             $is_custom{'fontmenu'} = 1; 
 1346:         }
 1347:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
 1348:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
 1349:             $is_custom{'font'} = 1;
 1350:         }
 1351:         foreach my $item (@bgs) {
 1352:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1353:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1354:                 $is_custom{$item} = 1;
 1355:             
 1356:             }
 1357:         }
 1358:         foreach my $item (@links) {
 1359:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1360:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1361:                 $is_custom{$item} = 1;
 1362:             }
 1363:         }
 1364:     }
 1365:     my $itemcount = 1;
 1366:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
 1367:     $datatable .= '</tr></table></td></tr>';
 1368:     return $datatable;
 1369: }
 1370: 
 1371: sub role_defaults {
 1372:     my ($role,$bgs,$links,$images,$logintext) = @_;
 1373:     my %defaults;
 1374:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
 1375:         return %defaults;
 1376:     }
 1377:     my %defaultdesign = %Apache::loncommon::defaultdesign;
 1378:     if ($role eq 'login') {
 1379:         %defaults = (
 1380:                        font => $defaultdesign{$role.'.font'},
 1381:                     );
 1382:         if (ref($logintext) eq 'ARRAY') {
 1383:             foreach my $item (@{$logintext}) {
 1384:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
 1385:             }
 1386:         }
 1387:         foreach my $item (@{$images}) {
 1388:             $defaults{'showlogo'}{$item} = 1;
 1389:         }
 1390:     } else {
 1391:         %defaults = (
 1392:                        img => $defaultdesign{$role.'.img'},
 1393:                        font => $defaultdesign{$role.'.font'},
 1394:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
 1395:                     );
 1396:     }
 1397:     foreach my $item (@{$bgs}) {
 1398:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
 1399:     }
 1400:     foreach my $item (@{$links}) {
 1401:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
 1402:     }
 1403:     foreach my $item (@{$images}) {
 1404:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
 1405:     }
 1406:     return %defaults;
 1407: }
 1408: 
 1409: sub display_color_options {
 1410:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
 1411:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
 1412:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
 1413:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1414:     my $datatable = '<tr'.$css_class.'>'.
 1415:         '<td>'.$choices->{'font'}.'</td>';
 1416:     if (!$is_custom->{'font'}) {
 1417:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
 1418:     } else {
 1419:         $datatable .= '<td>&nbsp;</td>';
 1420:     }
 1421:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
 1422: 
 1423:     $datatable .= '<td><span class="LC_nobreak">'.
 1424:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
 1425:                   ' value="'.$current_color.'" />&nbsp;'.
 1426:                   '&nbsp;</td></tr>';
 1427:     unless ($role eq 'login') { 
 1428:         $datatable .= '<tr'.$css_class.'>'.
 1429:                       '<td>'.$choices->{'fontmenu'}.'</td>';
 1430:         if (!$is_custom->{'fontmenu'}) {
 1431:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
 1432:         } else {
 1433:             $datatable .= '<td>&nbsp;</td>';
 1434:         }
 1435: 	$current_color = $designs->{'fontmenu'} ?
 1436: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
 1437:         $datatable .= '<td><span class="LC_nobreak">'.
 1438:                       '<input class="colorchooser" type="text" size="10" name="'
 1439: 		      .$role.'_fontmenu"'.
 1440:                       ' value="'.$current_color.'" />&nbsp;'.
 1441:                       '&nbsp;</td></tr>';
 1442:     }
 1443:     my $switchserver = &check_switchserver($dom,$confname);
 1444:     foreach my $img (@{$images}) {
 1445: 	$itemcount ++;
 1446:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1447:         $datatable .= '<tr'.$css_class.'>'.
 1448:                       '<td>'.$choices->{$img};
 1449:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
 1450:         if ($role eq 'login') {
 1451:             if ($img eq 'login') {
 1452:                 $login_hdr_pick =
 1453:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
 1454:                 $logincolors =
 1455:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
 1456:                                        $designs,$defaults);
 1457:             } elsif ($img ne 'domlogo') {
 1458:                 $datatable.= &logo_display_options($img,$defaults,$designs);
 1459:             }
 1460:         }
 1461:         $datatable .= '</td>';
 1462:         if ($designs->{$img} ne '') {
 1463:             $imgfile = $designs->{$img};
 1464: 	    $img_import = ($imgfile =~ m{^/adm/});
 1465:         } else {
 1466:             $imgfile = $defaults->{$img};
 1467:         }
 1468:         if ($imgfile) {
 1469:             my ($showfile,$fullsize);
 1470:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1471:                 my $urldir = $1;
 1472:                 my $filename = $2;
 1473:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
 1474:                 if (@info) {
 1475:                     my $thumbfile = 'tn-'.$filename;
 1476:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
 1477:                     if (@thumb) {
 1478:                         $showfile = $urldir.'/'.$thumbfile;
 1479:                     } else {
 1480:                         $showfile = $imgfile;
 1481:                     }
 1482:                 } else {
 1483:                     $showfile = '';
 1484:                 }
 1485:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
 1486:                 $showfile = $imgfile;
 1487:                 my $imgdir = $1;
 1488:                 my $filename = $2;
 1489:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
 1490:                     $showfile = "/$imgdir/tn-".$filename;
 1491:                 } else {
 1492:                     my $input = $londocroot.$imgfile;
 1493:                     my $output = "$londocroot/$imgdir/tn-".$filename;
 1494:                     if (!-e $output) {
 1495:                         my ($width,$height) = &thumb_dimensions();
 1496:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
 1497:                         if ($fullwidth ne '' && $fullheight ne '') {
 1498:                             if ($fullwidth > $width && $fullheight > $height) { 
 1499:                                 my $size = $width.'x'.$height;
 1500:                                 system("convert -sample $size $input $output");
 1501:                                 $showfile = "/$imgdir/tn-".$filename;
 1502:                             }
 1503:                         }
 1504:                     }
 1505:                 }
 1506:             }
 1507:             if ($showfile) {
 1508:                 if ($showfile =~ m{^/(adm|res)/}) {
 1509:                     if ($showfile =~ m{^/res/}) {
 1510:                         my $local_showfile =
 1511:                             &Apache::lonnet::filelocation('',$showfile);
 1512:                         &Apache::lonnet::repcopy($local_showfile);
 1513:                     }
 1514:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
 1515:                 }
 1516:                 if ($imgfile) {
 1517:                     if ($imgfile  =~ m{^/(adm|res)/}) {
 1518:                         if ($imgfile =~ m{^/res/}) {
 1519:                             my $local_imgfile =
 1520:                                 &Apache::lonnet::filelocation('',$imgfile);
 1521:                             &Apache::lonnet::repcopy($local_imgfile);
 1522:                         }
 1523:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
 1524:                     } else {
 1525:                         $fullsize = $imgfile;
 1526:                     }
 1527:                 }
 1528:                 $datatable .= '<td>';
 1529:                 if ($img eq 'login') {
 1530:                     $datatable .= $login_hdr_pick;
 1531:                 } 
 1532:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
 1533:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
 1534:             } else {
 1535:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
 1536:                               &mt('Upload:').'<br />';
 1537:             }
 1538:         } else {
 1539:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
 1540:                           &mt('Upload:').'<br />';
 1541:         }
 1542:         if ($switchserver) {
 1543:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1544:         } else {
 1545:             if ($img ne 'login') { # suppress file selection for Log-in header
 1546:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
 1547:             }
 1548:         }
 1549:         $datatable .= '</td></tr>';
 1550:     }
 1551:     $itemcount ++;
 1552:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1553:     $datatable .= '<tr'.$css_class.'>'.
 1554:                   '<td>'.$choices->{'bgs'}.'</td>';
 1555:     my $bgs_def;
 1556:     foreach my $item (@{$bgs}) {
 1557:         if (!$is_custom->{$item}) {
 1558:             $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>';
 1559:         }
 1560:     }
 1561:     if ($bgs_def) {
 1562:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
 1563:     } else {
 1564:         $datatable .= '<td>&nbsp;</td>';
 1565:     }
 1566:     $datatable .= '<td class="LC_right_item">'.
 1567:                   '<table border="0"><tr>';
 1568: 
 1569:     foreach my $item (@{$bgs}) {
 1570:         $datatable .= '<td align="center">'.$choices->{$item};
 1571: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
 1572:         if ($designs->{'bgs'}{$item}) {
 1573:             $datatable .= '&nbsp;';
 1574:         }
 1575:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1576:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1577:     }
 1578:     $datatable .= '</tr></table></td></tr>';
 1579:     $itemcount ++;
 1580:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1581:     $datatable .= '<tr'.$css_class.'>'.
 1582:                   '<td>'.$choices->{'links'}.'</td>';
 1583:     my $links_def;
 1584:     foreach my $item (@{$links}) {
 1585:         if (!$is_custom->{$item}) {
 1586:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
 1587:         }
 1588:     }
 1589:     if ($links_def) {
 1590:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
 1591:     } else {
 1592:         $datatable .= '<td>&nbsp;</td>';
 1593:     }
 1594:     $datatable .= '<td class="LC_right_item">'.
 1595:                   '<table border="0"><tr>';
 1596:     foreach my $item (@{$links}) {
 1597: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
 1598:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
 1599:         if ($designs->{'links'}{$item}) {
 1600:             $datatable.='&nbsp;';
 1601:         }
 1602:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
 1603:                       '" /></td>';
 1604:     }
 1605:     $$rowtotal += $itemcount;
 1606:     return $datatable;
 1607: }
 1608: 
 1609: sub logo_display_options {
 1610:     my ($img,$defaults,$designs) = @_;
 1611:     my $checkedon;
 1612:     if (ref($defaults) eq 'HASH') {
 1613:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
 1614:             if ($defaults->{'showlogo'}{$img}) {
 1615:                 $checkedon = 'checked="checked" ';     
 1616:             }
 1617:         } 
 1618:     }
 1619:     if (ref($designs) eq 'HASH') {
 1620:         if (ref($designs->{'showlogo'}) eq 'HASH') {
 1621:             if (defined($designs->{'showlogo'}{$img})) {
 1622:                 if ($designs->{'showlogo'}{$img} == 0) {
 1623:                     $checkedon = '';
 1624:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
 1625:                     $checkedon = 'checked="checked" ';
 1626:                 }
 1627:             }
 1628:         }
 1629:     }
 1630:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
 1631:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
 1632:            &mt('show').'</label>'."\n";
 1633: }
 1634: 
 1635: sub login_header_options  {
 1636:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
 1637:     my $output = '';
 1638:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1639:         $output .= &mt('Text default(s):').'<br />';
 1640:         if (!$is_custom->{'textcol'}) {
 1641:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1642:                        '&nbsp;&nbsp;&nbsp;';
 1643:         }
 1644:         if (!$is_custom->{'bgcol'}) {
 1645:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1646:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1647:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1648:         }
 1649:         $output .= '<br />';
 1650:     }
 1651:     $output .='<br />';
 1652:     return $output;
 1653: }
 1654: 
 1655: sub login_text_colors {
 1656:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
 1657:     my $color_menu = '<table border="0"><tr>';
 1658:     foreach my $item (@{$logintext}) {
 1659:         $color_menu .= '<td align="center">'.$choices->{$item};
 1660:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
 1661:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1662:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1663:     }
 1664:     $color_menu .= '</tr></table><br />';
 1665:     return $color_menu;
 1666: }
 1667: 
 1668: sub image_changes {
 1669:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1670:     my $output;
 1671:     if ($img eq 'login') {
 1672:             # suppress image for Log-in header
 1673:     } elsif (!$is_custom) {
 1674:         if ($img ne 'domlogo') {
 1675:             $output .= &mt('Default image:').'<br />';
 1676:         } else {
 1677:             $output .= &mt('Default in use:').'<br />';
 1678:         }
 1679:     }
 1680:     if ($img eq 'login') { # suppress image for Log-in header
 1681:         $output .= '<td>'.$logincolors;
 1682:     } else {
 1683:         if ($img_import) {
 1684:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1685:         }
 1686:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1687:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1688:         if ($is_custom) {
 1689:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1690:                        '<input type="checkbox" name="'.
 1691:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1692:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1693:         } else {
 1694:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
 1695:         }
 1696:     }
 1697:     return $output;
 1698: }
 1699: 
 1700: sub print_quotas {
 1701:     my ($dom,$settings,$rowtotal,$action) = @_;
 1702:     my $context;
 1703:     if ($action eq 'quotas') {
 1704:         $context = 'tools';
 1705:     } else {
 1706:         $context = $action;
 1707:     }
 1708:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
 1709:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1710:     my $typecount = 0;
 1711:     my ($css_class,%titles);
 1712:     if ($context eq 'requestcourses') {
 1713:         @usertools = ('official','unofficial','community','textbook');
 1714:         @options =('norequest','approval','validate','autolimit');
 1715:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 1716:         %titles = &courserequest_titles();
 1717:     } elsif ($context eq 'requestauthor') {
 1718:         @usertools = ('author');
 1719:         @options = ('norequest','approval','automatic');
 1720:         %titles = &authorrequest_titles();
 1721:     } else {
 1722:         @usertools = ('aboutme','blog','webdav','portfolio');
 1723:         %titles = &tool_titles();
 1724:     }
 1725:     if (ref($types) eq 'ARRAY') {
 1726:         foreach my $type (@{$types}) {
 1727:             my ($currdefquota,$currauthorquota);
 1728:             unless (($context eq 'requestcourses') ||
 1729:                     ($context eq 'requestauthor')) {
 1730:                 if (ref($settings) eq 'HASH') {
 1731:                     if (ref($settings->{defaultquota}) eq 'HASH') {
 1732:                         $currdefquota = $settings->{defaultquota}->{$type};
 1733:                     } else {
 1734:                         $currdefquota = $settings->{$type};
 1735:                     }
 1736:                     if (ref($settings->{authorquota}) eq 'HASH') {
 1737:                         $currauthorquota = $settings->{authorquota}->{$type};
 1738:                     }
 1739:                 }
 1740:             }
 1741:             if (defined($usertypes->{$type})) {
 1742:                 $typecount ++;
 1743:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1744:                 $datatable .= '<tr'.$css_class.'>'.
 1745:                               '<td>'.$usertypes->{$type}.'</td>'.
 1746:                               '<td class="LC_left_item">';
 1747:                 if ($context eq 'requestcourses') {
 1748:                     $datatable .= '<table><tr>';
 1749:                 }
 1750:                 my %cell;  
 1751:                 foreach my $item (@usertools) {
 1752:                     if ($context eq 'requestcourses') {
 1753:                         my ($curroption,$currlimit);
 1754:                         if (ref($settings) eq 'HASH') {
 1755:                             if (ref($settings->{$item}) eq 'HASH') {
 1756:                                 $curroption = $settings->{$item}->{$type};
 1757:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
 1758:                                     $currlimit = $1; 
 1759:                                 }
 1760:                             }
 1761:                         }
 1762:                         if (!$curroption) {
 1763:                             $curroption = 'norequest';
 1764:                         }
 1765:                         $datatable .= '<th>'.$titles{$item}.'</th>';
 1766:                         foreach my $option (@options) {
 1767:                             my $val = $option;
 1768:                             if ($option eq 'norequest') {
 1769:                                 $val = 0;  
 1770:                             }
 1771:                             if ($option eq 'validate') {
 1772:                                 my $canvalidate = 0;
 1773:                                 if (ref($validations{$item}) eq 'HASH') { 
 1774:                                     if ($validations{$item}{$type}) {
 1775:                                         $canvalidate = 1;
 1776:                                     }
 1777:                                 }
 1778:                                 next if (!$canvalidate);
 1779:                             }
 1780:                             my $checked = '';
 1781:                             if ($option eq $curroption) {
 1782:                                 $checked = ' checked="checked"';
 1783:                             } elsif ($option eq 'autolimit') {
 1784:                                 if ($curroption =~ /^autolimit/) {
 1785:                                     $checked = ' checked="checked"';
 1786:                                 }                       
 1787:                             } 
 1788:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
 1789:                                   '<input type="radio" name="crsreq_'.$item.
 1790:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
 1791:                                   $titles{$option}.'</label>';
 1792:                             if ($option eq 'autolimit') {
 1793:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1794:                                                 $item.'_limit_'.$type.'" size="1" '.
 1795:                                                 'value="'.$currlimit.'" />';
 1796:                             }
 1797:                             $cell{$item} .= '</span> ';
 1798:                             if ($option eq 'autolimit') {
 1799:                                 $cell{$item} .= $titles{'unlimited'};
 1800:                             }
 1801:                         }
 1802:                     } elsif ($context eq 'requestauthor') {
 1803:                         my $curroption;
 1804:                         if (ref($settings) eq 'HASH') {
 1805:                             $curroption = $settings->{$type};
 1806:                         }
 1807:                         if (!$curroption) {
 1808:                             $curroption = 'norequest';
 1809:                         }
 1810:                         foreach my $option (@options) {
 1811:                             my $val = $option;
 1812:                             if ($option eq 'norequest') {
 1813:                                 $val = 0;
 1814:                             }
 1815:                             my $checked = '';
 1816:                             if ($option eq $curroption) {
 1817:                                 $checked = ' checked="checked"';
 1818:                             }
 1819:                             $datatable .= '<span class="LC_nobreak"><label>'.
 1820:                                   '<input type="radio" name="authorreq_'.$type.
 1821:                                   '" value="'.$val.'"'.$checked.' />'.
 1822:                                   $titles{$option}.'</label></span>&nbsp; ';
 1823:                         }
 1824:                     } else {
 1825:                         my $checked = 'checked="checked" ';
 1826:                         if (ref($settings) eq 'HASH') {
 1827:                             if (ref($settings->{$item}) eq 'HASH') {
 1828:                                 if ($settings->{$item}->{$type} == 0) {
 1829:                                     $checked = '';
 1830:                                 } elsif ($settings->{$item}->{$type} == 1) {
 1831:                                     $checked =  'checked="checked" ';
 1832:                                 }
 1833:                             }
 1834:                         }
 1835:                         $datatable .= '<span class="LC_nobreak"><label>'.
 1836:                                       '<input type="checkbox" name="'.$context.'_'.$item.
 1837:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1838:                                       '</label></span>&nbsp; ';
 1839:                     }
 1840:                 }
 1841:                 if ($context eq 'requestcourses') {
 1842:                     $datatable .= '</tr><tr>';
 1843:                     foreach my $item (@usertools) {
 1844:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
 1845:                     }
 1846:                     $datatable .= '</tr></table>';
 1847:                 }
 1848:                 $datatable .= '</td>';
 1849:                 unless (($context eq 'requestcourses') ||
 1850:                         ($context eq 'requestauthor')) {
 1851:                     $datatable .= 
 1852:                               '<td class="LC_right_item">'.
 1853:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1854:                               '<input type="text" name="quota_'.$type.
 1855:                               '" value="'.$currdefquota.
 1856:                               '" size="5" /></span>'.('&nbsp;' x 2).
 1857:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1858:                               '<input type="text" name="authorquota_'.$type.
 1859:                               '" value="'.$currauthorquota.
 1860:                               '" size="5" /></span></td>';
 1861:                 }
 1862:                 $datatable .= '</tr>';
 1863:             }
 1864:         }
 1865:     }
 1866:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1867:         $defaultquota = '20';
 1868:         $authorquota = '500';
 1869:         if (ref($settings) eq 'HASH') {
 1870:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1871:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
 1872:             } elsif (defined($settings->{'default'})) {
 1873:                 $defaultquota = $settings->{'default'};
 1874:             }
 1875:             if (ref($settings->{'authorquota'}) eq 'HASH') {
 1876:                 $authorquota = $settings->{'authorquota'}->{'default'};
 1877:             }
 1878:         }
 1879:     }
 1880:     $typecount ++;
 1881:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1882:     $datatable .= '<tr'.$css_class.'>'.
 1883:                   '<td>'.$othertitle.'</td>'.
 1884:                   '<td class="LC_left_item">';
 1885:     if ($context eq 'requestcourses') {
 1886:         $datatable .= '<table><tr>';
 1887:     }
 1888:     my %defcell;
 1889:     foreach my $item (@usertools) {
 1890:         if ($context eq 'requestcourses') {
 1891:             my ($curroption,$currlimit);
 1892:             if (ref($settings) eq 'HASH') {
 1893:                 if (ref($settings->{$item}) eq 'HASH') {
 1894:                     $curroption = $settings->{$item}->{'default'};
 1895:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1896:                         $currlimit = $1;
 1897:                     }
 1898:                 }
 1899:             }
 1900:             if (!$curroption) {
 1901:                 $curroption = 'norequest';
 1902:             }
 1903:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1904:             foreach my $option (@options) {
 1905:                 my $val = $option;
 1906:                 if ($option eq 'norequest') {
 1907:                     $val = 0;
 1908:                 }
 1909:                 if ($option eq 'validate') {
 1910:                     my $canvalidate = 0;
 1911:                     if (ref($validations{$item}) eq 'HASH') {
 1912:                         if ($validations{$item}{'default'}) {
 1913:                             $canvalidate = 1;
 1914:                         }
 1915:                     }
 1916:                     next if (!$canvalidate);
 1917:                 }
 1918:                 my $checked = '';
 1919:                 if ($option eq $curroption) {
 1920:                     $checked = ' checked="checked"';
 1921:                 } elsif ($option eq 'autolimit') {
 1922:                     if ($curroption =~ /^autolimit/) {
 1923:                         $checked = ' checked="checked"';
 1924:                     }
 1925:                 }
 1926:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
 1927:                                   '<input type="radio" name="crsreq_'.$item.
 1928:                                   '_default" value="'.$val.'"'.$checked.' />'.
 1929:                                   $titles{$option}.'</label>';
 1930:                 if ($option eq 'autolimit') {
 1931:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1932:                                        $item.'_limit_default" size="1" '.
 1933:                                        'value="'.$currlimit.'" />';
 1934:                 }
 1935:                 $defcell{$item} .= '</span> ';
 1936:                 if ($option eq 'autolimit') {
 1937:                     $defcell{$item} .= $titles{'unlimited'};
 1938:                 }
 1939:             }
 1940:         } elsif ($context eq 'requestauthor') {
 1941:             my $curroption;
 1942:             if (ref($settings) eq 'HASH') {
 1943:                 $curroption = $settings->{'default'};
 1944:             }
 1945:             if (!$curroption) {
 1946:                 $curroption = 'norequest';
 1947:             }
 1948:             foreach my $option (@options) {
 1949:                 my $val = $option;
 1950:                 if ($option eq 'norequest') {
 1951:                     $val = 0;
 1952:                 }
 1953:                 my $checked = '';
 1954:                 if ($option eq $curroption) {
 1955:                     $checked = ' checked="checked"';
 1956:                 }
 1957:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1958:                               '<input type="radio" name="authorreq_default"'.
 1959:                               ' value="'.$val.'"'.$checked.' />'.
 1960:                               $titles{$option}.'</label></span>&nbsp; ';
 1961:             }
 1962:         } else {
 1963:             my $checked = 'checked="checked" ';
 1964:             if (ref($settings) eq 'HASH') {
 1965:                 if (ref($settings->{$item}) eq 'HASH') {
 1966:                     if ($settings->{$item}->{'default'} == 0) {
 1967:                         $checked = '';
 1968:                     } elsif ($settings->{$item}->{'default'} == 1) {
 1969:                         $checked = 'checked="checked" ';
 1970:                     }
 1971:                 }
 1972:             }
 1973:             $datatable .= '<span class="LC_nobreak"><label>'.
 1974:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1975:                           '" value="default" '.$checked.'/>'.$titles{$item}.
 1976:                           '</label></span>&nbsp; ';
 1977:         }
 1978:     }
 1979:     if ($context eq 'requestcourses') {
 1980:         $datatable .= '</tr><tr>';
 1981:         foreach my $item (@usertools) {
 1982:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
 1983:         }
 1984:         $datatable .= '</tr></table>';
 1985:     }
 1986:     $datatable .= '</td>';
 1987:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1988:         $datatable .= '<td class="LC_right_item">'.
 1989:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1990:                       '<input type="text" name="defaultquota" value="'.
 1991:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
 1992:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1993:                       '<input type="text" name="authorquota" value="'.
 1994:                       $authorquota.'" size="5" /></span></td>';
 1995:     }
 1996:     $datatable .= '</tr>';
 1997:     $typecount ++;
 1998:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1999:     $datatable .= '<tr'.$css_class.'>'.
 2000:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
 2001:     if ($context eq 'requestcourses') {
 2002:         $datatable .= &mt('(overrides affiliation, if set)').
 2003:                       '</td>'.
 2004:                       '<td class="LC_left_item">'.
 2005:                       '<table><tr>';
 2006:     } else {
 2007:         $datatable .= &mt('(overrides affiliation, if checked)').
 2008:                       '</td>'.
 2009:                       '<td class="LC_left_item" colspan="2">'.
 2010:                       '<br />';
 2011:     }
 2012:     my %advcell;
 2013:     foreach my $item (@usertools) {
 2014:         if ($context eq 'requestcourses') {
 2015:             my ($curroption,$currlimit);
 2016:             if (ref($settings) eq 'HASH') {
 2017:                 if (ref($settings->{$item}) eq 'HASH') {
 2018:                     $curroption = $settings->{$item}->{'_LC_adv'};
 2019:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 2020:                         $currlimit = $1;
 2021:                     }
 2022:                 }
 2023:             }
 2024:             $datatable .= '<th>'.$titles{$item}.'</th>';
 2025:             my $checked = '';
 2026:             if ($curroption eq '') {
 2027:                 $checked = ' checked="checked"';
 2028:             }
 2029:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 2030:                                '<input type="radio" name="crsreq_'.$item.
 2031:                                '__LC_adv" value=""'.$checked.' />'.
 2032:                                &mt('No override set').'</label></span>&nbsp; ';
 2033:             foreach my $option (@options) {
 2034:                 my $val = $option;
 2035:                 if ($option eq 'norequest') {
 2036:                     $val = 0;
 2037:                 }
 2038:                 if ($option eq 'validate') {
 2039:                     my $canvalidate = 0;
 2040:                     if (ref($validations{$item}) eq 'HASH') {
 2041:                         if ($validations{$item}{'_LC_adv'}) {
 2042:                             $canvalidate = 1;
 2043:                         }
 2044:                     }
 2045:                     next if (!$canvalidate);
 2046:                 }
 2047:                 my $checked = '';
 2048:                 if ($val eq $curroption) {
 2049:                     $checked = ' checked="checked"';
 2050:                 } elsif ($option eq 'autolimit') {
 2051:                     if ($curroption =~ /^autolimit/) {
 2052:                         $checked = ' checked="checked"';
 2053:                     }
 2054:                 }
 2055:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 2056:                                   '<input type="radio" name="crsreq_'.$item.
 2057:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
 2058:                                   $titles{$option}.'</label>';
 2059:                 if ($option eq 'autolimit') {
 2060:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 2061:                                        $item.'_limit__LC_adv" size="1" '.
 2062:                                        'value="'.$currlimit.'" />';
 2063:                 }
 2064:                 $advcell{$item} .= '</span> ';
 2065:                 if ($option eq 'autolimit') {
 2066:                     $advcell{$item} .= $titles{'unlimited'};
 2067:                 }
 2068:             }
 2069:         } elsif ($context eq 'requestauthor') {
 2070:             my $curroption;
 2071:             if (ref($settings) eq 'HASH') {
 2072:                 $curroption = $settings->{'_LC_adv'};
 2073:             }
 2074:             my $checked = '';
 2075:             if ($curroption eq '') {
 2076:                 $checked = ' checked="checked"';
 2077:             }
 2078:             $datatable .= '<span class="LC_nobreak"><label>'.
 2079:                           '<input type="radio" name="authorreq__LC_adv"'.
 2080:                           ' value=""'.$checked.' />'.
 2081:                           &mt('No override set').'</label></span>&nbsp; ';
 2082:             foreach my $option (@options) {
 2083:                 my $val = $option;
 2084:                 if ($option eq 'norequest') {
 2085:                     $val = 0;
 2086:                 }
 2087:                 my $checked = '';
 2088:                 if ($val eq $curroption) {
 2089:                     $checked = ' checked="checked"';
 2090:                 }
 2091:                 $datatable .= '<span class="LC_nobreak"><label>'.
 2092:                               '<input type="radio" name="authorreq__LC_adv"'.
 2093:                               ' value="'.$val.'"'.$checked.' />'.
 2094:                               $titles{$option}.'</label></span>&nbsp; ';
 2095:             }
 2096:         } else {
 2097:             my $checked = 'checked="checked" ';
 2098:             if (ref($settings) eq 'HASH') {
 2099:                 if (ref($settings->{$item}) eq 'HASH') {
 2100:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
 2101:                         $checked = '';
 2102:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
 2103:                         $checked = 'checked="checked" ';
 2104:                     }
 2105:                 }
 2106:             }
 2107:             $datatable .= '<span class="LC_nobreak"><label>'.
 2108:                           '<input type="checkbox" name="'.$context.'_'.$item.
 2109:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 2110:                           '</label></span>&nbsp; ';
 2111:         }
 2112:     }
 2113:     if ($context eq 'requestcourses') {
 2114:         $datatable .= '</tr><tr>';
 2115:         foreach my $item (@usertools) {
 2116:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
 2117:         }
 2118:         $datatable .= '</tr></table>';
 2119:     }
 2120:     $datatable .= '</td></tr>';
 2121:     $$rowtotal += $typecount;
 2122:     return $datatable;
 2123: }
 2124: 
 2125: sub print_requestmail {
 2126:     my ($dom,$action,$settings,$rowtotal) = @_;
 2127:     my ($now,$datatable,%currapp);
 2128:     $now = time;
 2129:     if (ref($settings) eq 'HASH') {
 2130:         if (ref($settings->{'notify'}) eq 'HASH') {
 2131:             if ($settings->{'notify'}{'approval'} ne '') {
 2132:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
 2133:             }
 2134:         }
 2135:     }
 2136:     my $numinrow = 2;
 2137:     my $css_class;
 2138:     $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
 2139:     my $text;
 2140:     if ($action eq 'requestcourses') {
 2141:         $text = &mt('Receive notification of course requests requiring approval');
 2142:     } elsif ($action eq 'requestauthor') {
 2143:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
 2144:     } else {
 2145:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
 2146:     }
 2147:     $datatable = '<tr'.$css_class.'>'.
 2148:                  ' <td>'.$text.'</td>'.
 2149:                  ' <td class="LC_left_item">';
 2150:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
 2151:                                                  $action.'notifyapproval',%currapp);
 2152:     if ($numdc > 0) {
 2153:         $datatable .= $table;
 2154:     } else {
 2155:         $datatable .= &mt('There are no active Domain Coordinators');
 2156:     }
 2157:     $datatable .='</td></tr>';
 2158:     return $datatable;
 2159: }
 2160: 
 2161: sub print_studentcode {
 2162:     my ($settings,$rowtotal) = @_;
 2163:     my $rownum = 0; 
 2164:     my ($output,%current);
 2165:     my @crstypes = ('official','unofficial','community','textbook');
 2166:     if (ref($settings) eq 'HASH') {
 2167:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
 2168:             foreach my $type (@crstypes) {
 2169:                 $current{$type} = $settings->{'uniquecode'}{$type};
 2170:             }
 2171:         }
 2172:     }
 2173:     $output .= '<tr>'.
 2174:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
 2175:                '<td class="LC_left_item">';
 2176:     foreach my $type (@crstypes) {
 2177:         my $check = ' ';
 2178:         if ($current{$type}) {
 2179:             $check = ' checked="checked" ';
 2180:         }
 2181:         $output .= '<span class="LC_nobreak"><label>'.
 2182:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
 2183:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
 2184:     }
 2185:     $output .= '</td></tr>';
 2186:     $$rowtotal ++;
 2187:     return $output;
 2188: }
 2189: 
 2190: sub print_textbookcourses {
 2191:     my ($dom,$type,$settings,$rowtotal) = @_;
 2192:     my $rownum = 0;
 2193:     my $css_class;
 2194:     my $itemcount = 1;
 2195:     my $maxnum = 0;
 2196:     my $bookshash;
 2197:     if (ref($settings) eq 'HASH') {
 2198:         $bookshash = $settings->{$type};
 2199:     }
 2200:     my %ordered;
 2201:     if (ref($bookshash) eq 'HASH') {
 2202:         foreach my $item (keys(%{$bookshash})) {
 2203:             if (ref($bookshash->{$item}) eq 'HASH') {
 2204:                 my $num = $bookshash->{$item}{'order'};
 2205:                 $ordered{$num} = $item;
 2206:             }
 2207:         }
 2208:     }
 2209:     my $confname = $dom.'-domainconfig';
 2210:     my $switchserver = &check_switchserver($dom,$confname);
 2211:     my $maxnum = scalar(keys(%ordered));
 2212:     my $datatable;
 2213:     if (keys(%ordered)) {
 2214:         my @items = sort { $a <=> $b } keys(%ordered);
 2215:         for (my $i=0; $i<@items; $i++) {
 2216:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2217:             my $key = $ordered{$items[$i]};
 2218:             my %coursehash=&Apache::lonnet::coursedescription($key);
 2219:             my $coursetitle = $coursehash{'description'};
 2220:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
 2221:             if (ref($bookshash->{$key}) eq 'HASH') {
 2222:                 $subject = $bookshash->{$key}->{'subject'};
 2223:                 $title = $bookshash->{$key}->{'title'};
 2224:                 if ($type eq 'textbooks') {
 2225:                     $publisher = $bookshash->{$key}->{'publisher'};
 2226:                     $author = $bookshash->{$key}->{'author'};
 2227:                     $image = $bookshash->{$key}->{'image'};
 2228:                     if ($image ne '') {
 2229:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
 2230:                         my $imagethumb = "$path/tn-".$imagefile;
 2231:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
 2232:                     }
 2233:                 }
 2234:             }
 2235:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
 2236:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 2237:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
 2238:             for (my $k=0; $k<=$maxnum; $k++) {
 2239:                 my $vpos = $k+1;
 2240:                 my $selstr;
 2241:                 if ($k == $i) {
 2242:                     $selstr = ' selected="selected" ';
 2243:                 }
 2244:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2245:             }
 2246:             $datatable .= '</select>'.('&nbsp;'x2).
 2247:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
 2248:                 &mt('Delete?').'</label></span></td>'.
 2249:                 '<td colspan="2">'.
 2250:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
 2251:                 ('&nbsp;'x2).
 2252:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
 2253:             if ($type eq 'textbooks') {
 2254:                 $datatable .= ('&nbsp;'x2).
 2255:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
 2256:                               ('&nbsp;'x2).
 2257:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
 2258:                               ('&nbsp;'x2).
 2259:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
 2260:                 if ($image) {
 2261:                     $datatable .= '<span class="LC_nobreak">'.
 2262:                                   $imgsrc.
 2263:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
 2264:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
 2265:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
 2266:                 }
 2267:                 if ($switchserver) {
 2268:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2269:                 } else {
 2270:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
 2271:                 }
 2272:             }
 2273:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
 2274:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
 2275:                           $coursetitle.'</span></td></tr>'."\n";
 2276:             $itemcount ++;
 2277:         }
 2278:     }
 2279:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2280:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
 2281:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
 2282:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
 2283:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
 2284:     for (my $k=0; $k<$maxnum+1; $k++) {
 2285:         my $vpos = $k+1;
 2286:         my $selstr;
 2287:         if ($k == $maxnum) {
 2288:             $selstr = ' selected="selected" ';
 2289:         }
 2290:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2291:     }
 2292:     $datatable .= '</select>&nbsp;'."\n".
 2293:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
 2294:                   '<td colspan="2">'.
 2295:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
 2296:                   ('&nbsp;'x2).
 2297:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
 2298:                   ('&nbsp;'x2);
 2299:     if ($type eq 'textbooks') {
 2300:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
 2301:                       ('&nbsp;'x2).
 2302:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
 2303:                       ('&nbsp;'x2).
 2304:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
 2305:         if ($switchserver) {
 2306:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2307:         } else {
 2308:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
 2309:         }
 2310:     }
 2311:     $datatable .= '</span>'."\n".
 2312:                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
 2313:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
 2314:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
 2315:                   &Apache::loncommon::selectcourse_link
 2316:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
 2317:                   '</span></td>'."\n".
 2318:                   '</tr>'."\n";
 2319:     $itemcount ++;
 2320:     return $datatable;
 2321: }
 2322: 
 2323: sub textbookcourses_javascript {
 2324:     my ($settings) = @_;
 2325:     return unless(ref($settings) eq 'HASH');
 2326:     my (%ordered,%total,%jstext);
 2327:     foreach my $type ('textbooks','templates') {
 2328:         $total{$type} = 0;
 2329:         if (ref($settings->{$type}) eq 'HASH') {
 2330:             foreach my $item (keys(%{$settings->{$type}})) {
 2331:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
 2332:                     my $num = $settings->{$type}->{$item}{'order'};
 2333:                     $ordered{$type}{$num} = $item;
 2334:                 }
 2335:             }
 2336:             $total{$type} = scalar(keys(%{$settings->{$type}}));
 2337:         }
 2338:         my @jsarray = ();
 2339:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
 2340:             push(@jsarray,$ordered{$type}{$item});
 2341:         }
 2342:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
 2343:     }
 2344:     return <<"ENDSCRIPT";
 2345: <script type="text/javascript">
 2346: // <![CDATA[
 2347: function reorderBooks(form,item,caller) {
 2348:     var changedVal;
 2349: $jstext{'textbooks'};
 2350: $jstext{'templates'};
 2351:     var newpos;
 2352:     var maxh;
 2353:     if (caller == 'textbooks') {  
 2354:         newpos = 'textbooks_addbook_pos';
 2355:         maxh = 1 + $total{'textbooks'};
 2356:     } else {
 2357:         newpos = 'templates_addbook_pos';
 2358:         maxh = 1 + $total{'templates'};
 2359:     }
 2360:     var current = new Array;
 2361:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 2362:     if (item == newpos) {
 2363:         changedVal = newitemVal;
 2364:     } else {
 2365:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 2366:         current[newitemVal] = newpos;
 2367:     }
 2368:     if (caller == 'textbooks') {
 2369:         for (var i=0; i<textbooks.length; i++) {
 2370:             var elementName = 'textbooks_'+textbooks[i];
 2371:             if (elementName != item) {
 2372:                 if (form.elements[elementName]) {
 2373:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 2374:                     current[currVal] = elementName;
 2375:                 }
 2376:             }
 2377:         }
 2378:     }
 2379:     if (caller == 'templates') {
 2380:         for (var i=0; i<templates.length; i++) {
 2381:             var elementName = 'templates_'+templates[i];
 2382:             if (elementName != item) {
 2383:                 if (form.elements[elementName]) {
 2384:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 2385:                     current[currVal] = elementName;
 2386:                 }
 2387:             }
 2388:         }
 2389:     }
 2390:     var oldVal;
 2391:     for (var j=0; j<maxh; j++) {
 2392:         if (current[j] == undefined) {
 2393:             oldVal = j;
 2394:         }
 2395:     }
 2396:     if (oldVal < changedVal) {
 2397:         for (var k=oldVal+1; k<=changedVal ; k++) {
 2398:            var elementName = current[k];
 2399:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 2400:         }
 2401:     } else {
 2402:         for (var k=changedVal; k<oldVal; k++) {
 2403:             var elementName = current[k];
 2404:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 2405:         }
 2406:     }
 2407:     return;
 2408: }
 2409: 
 2410: // ]]>
 2411: </script>
 2412: 
 2413: ENDSCRIPT
 2414: }
 2415: 
 2416: sub print_autoenroll {
 2417:     my ($dom,$settings,$rowtotal) = @_;
 2418:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 2419:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
 2420:     if (ref($settings) eq 'HASH') {
 2421:         if (exists($settings->{'run'})) {
 2422:             if ($settings->{'run'} eq '0') {
 2423:                 $runoff = ' checked="checked" ';
 2424:                 $runon = ' ';
 2425:             } else {
 2426:                 $runon = ' checked="checked" ';
 2427:                 $runoff = ' ';
 2428:             }
 2429:         } else {
 2430:             if ($autorun) {
 2431:                 $runon = ' checked="checked" ';
 2432:                 $runoff = ' ';
 2433:             } else {
 2434:                 $runoff = ' checked="checked" ';
 2435:                 $runon = ' ';
 2436:             }
 2437:         }
 2438:         if (exists($settings->{'co-owners'})) {
 2439:             if ($settings->{'co-owners'} eq '0') {
 2440:                 $coownersoff = ' checked="checked" ';
 2441:                 $coownerson = ' ';
 2442:             } else {
 2443:                 $coownerson = ' checked="checked" ';
 2444:                 $coownersoff = ' ';
 2445:             }
 2446:         } else {
 2447:             $coownersoff = ' checked="checked" ';
 2448:             $coownerson = ' ';
 2449:         }
 2450:         if (exists($settings->{'sender_domain'})) {
 2451:             $defdom = $settings->{'sender_domain'};
 2452:         }
 2453:     } else {
 2454:         if ($autorun) {
 2455:             $runon = ' checked="checked" ';
 2456:             $runoff = ' ';
 2457:         } else {
 2458:             $runoff = ' checked="checked" ';
 2459:             $runon = ' ';
 2460:         }
 2461:     }
 2462:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 2463:     my $notif_sender;
 2464:     if (ref($settings) eq 'HASH') {
 2465:         $notif_sender = $settings->{'sender_uname'};
 2466:     }
 2467:     my $datatable='<tr class="LC_odd_row">'.
 2468:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 2469:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2470:                   '<input type="radio" name="autoenroll_run"'.
 2471:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2472:                   '<label><input type="radio" name="autoenroll_run"'.
 2473:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2474:                   '</tr><tr>'.
 2475:                   '<td>'.&mt('Notification messages - sender').
 2476:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 2477:                   &mt('username').':&nbsp;'.
 2478:                   '<input type="text" name="sender_uname" value="'.
 2479:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 2480:                   ':&nbsp;'.$domform.'</span></td></tr>'.
 2481:                   '<tr class="LC_odd_row">'.
 2482:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
 2483:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2484:                   '<input type="radio" name="autoassign_coowners"'.
 2485:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2486:                   '<label><input type="radio" name="autoassign_coowners"'.
 2487:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2488:                   '</tr>';
 2489:     $$rowtotal += 3;
 2490:     return $datatable;
 2491: }
 2492: 
 2493: sub print_autoupdate {
 2494:     my ($position,$dom,$settings,$rowtotal) = @_;
 2495:     my $datatable;
 2496:     if ($position eq 'top') {
 2497:         my $updateon = ' ';
 2498:         my $updateoff = ' checked="checked" ';
 2499:         my $classlistson = ' ';
 2500:         my $classlistsoff = ' checked="checked" ';
 2501:         if (ref($settings) eq 'HASH') {
 2502:             if ($settings->{'run'} eq '1') {
 2503:                 $updateon = $updateoff;
 2504:                 $updateoff = ' ';
 2505:             }
 2506:             if ($settings->{'classlists'} eq '1') {
 2507:                 $classlistson = $classlistsoff;
 2508:                 $classlistsoff = ' ';
 2509:             }
 2510:         }
 2511:         my %title = (
 2512:                    run => 'Auto-update active?',
 2513:                    classlists => 'Update information in classlists?',
 2514:                     );
 2515:         $datatable = '<tr class="LC_odd_row">'. 
 2516:                   '<td>'.&mt($title{'run'}).'</td>'.
 2517:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2518:                   '<input type="radio" name="autoupdate_run"'.
 2519:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2520:                   '<label><input type="radio" name="autoupdate_run"'.
 2521:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2522:                   '</tr><tr>'.
 2523:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 2524:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 2525:                   '<label><input type="radio" name="classlists"'.
 2526:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2527:                   '<label><input type="radio" name="classlists"'.
 2528:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2529:                   '</tr>';
 2530:         $$rowtotal += 2;
 2531:     } elsif ($position eq 'middle') {
 2532:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2533:         my $numinrow = 3;
 2534:         my $locknamesettings;
 2535:         $datatable .= &insttypes_row($settings,$types,$usertypes,
 2536:                                      $dom,$numinrow,$othertitle,
 2537:                                     'lockablenames');
 2538:         $$rowtotal ++;
 2539:     } else {
 2540:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2541:         my @fields = ('lastname','firstname','middlename','generation',
 2542:                       'permanentemail','id');
 2543:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 2544:         my $numrows = 0;
 2545:         if (ref($types) eq 'ARRAY') {
 2546:             if (@{$types} > 0) {
 2547:                 $datatable = 
 2548:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 2549:                                          \@fields,$types,\$numrows);
 2550:                     $$rowtotal += @{$types}; 
 2551:             }
 2552:         }
 2553:         $datatable .= 
 2554:             &usertype_update_row($settings,{'default' => $othertitle},
 2555:                                  \%fieldtitles,\@fields,['default'],
 2556:                                  \$numrows);
 2557:         $$rowtotal ++;     
 2558:     }
 2559:     return $datatable;
 2560: }
 2561: 
 2562: sub print_autocreate {
 2563:     my ($dom,$settings,$rowtotal) = @_;
 2564:     my (%createon,%createoff,%currhash);
 2565:     my @types = ('xml','req');
 2566:     if (ref($settings) eq 'HASH') {
 2567:         foreach my $item (@types) {
 2568:             $createoff{$item} = ' checked="checked" ';
 2569:             $createon{$item} = ' ';
 2570:             if (exists($settings->{$item})) {
 2571:                 if ($settings->{$item}) {
 2572:                     $createon{$item} = ' checked="checked" ';
 2573:                     $createoff{$item} = ' ';
 2574:                 }
 2575:             }
 2576:         }
 2577:         if ($settings->{'xmldc'} ne '') {
 2578:             $currhash{$settings->{'xmldc'}} = 1;
 2579:         }
 2580:     } else {
 2581:         foreach my $item (@types) {
 2582:             $createoff{$item} = ' checked="checked" ';
 2583:             $createon{$item} = ' ';
 2584:         }
 2585:     }
 2586:     $$rowtotal += 2;
 2587:     my $numinrow = 2;
 2588:     my $datatable='<tr class="LC_odd_row">'.
 2589:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
 2590:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2591:                   '<input type="radio" name="autocreate_xml"'.
 2592:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2593:                   '<label><input type="radio" name="autocreate_xml"'.
 2594:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
 2595:                   '</td></tr><tr>'.
 2596:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
 2597:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2598:                   '<input type="radio" name="autocreate_req"'.
 2599:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2600:                   '<label><input type="radio" name="autocreate_req"'.
 2601:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
 2602:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
 2603:                                                    'autocreate_xmldc',%currhash);
 2604:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
 2605:     if ($numdc > 1) {
 2606:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
 2607:                       '</td><td class="LC_left_item">';
 2608:     } else {
 2609:         $datatable .= &mt('Course creation processed as:').
 2610:                       '</td><td class="LC_right_item">';
 2611:     }
 2612:     $datatable .= $dctable.'</td></tr>';
 2613:     $$rowtotal += $rows;
 2614:     return $datatable;
 2615: }
 2616: 
 2617: sub print_directorysrch {
 2618:     my ($dom,$settings,$rowtotal) = @_;
 2619:     my $srchon = ' ';
 2620:     my $srchoff = ' checked="checked" ';
 2621:     my ($exacton,$containson,$beginson);
 2622:     my $localon = ' ';
 2623:     my $localoff = ' checked="checked" ';
 2624:     if (ref($settings) eq 'HASH') {
 2625:         if ($settings->{'available'} eq '1') {
 2626:             $srchon = $srchoff;
 2627:             $srchoff = ' ';
 2628:         }
 2629:         if ($settings->{'localonly'} eq '1') {
 2630:             $localon = $localoff;
 2631:             $localoff = ' ';
 2632:         }
 2633:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 2634:             foreach my $type (@{$settings->{'searchtypes'}}) {
 2635:                 if ($type eq 'exact') {
 2636:                     $exacton = ' checked="checked" ';
 2637:                 } elsif ($type eq 'contains') {
 2638:                     $containson = ' checked="checked" ';
 2639:                 } elsif ($type eq 'begins') {
 2640:                     $beginson = ' checked="checked" ';
 2641:                 }
 2642:             }
 2643:         } else {
 2644:             if ($settings->{'searchtypes'} eq 'exact') {
 2645:                 $exacton = ' checked="checked" ';
 2646:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 2647:                 $containson = ' checked="checked" ';
 2648:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 2649:                 $exacton = ' checked="checked" ';
 2650:                 $containson = ' checked="checked" ';
 2651:             }
 2652:         }
 2653:     }
 2654:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 2655:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2656: 
 2657:     my $numinrow = 4;
 2658:     my $cansrchrow = 0;
 2659:     my $datatable='<tr class="LC_odd_row">'.
 2660:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 2661:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2662:                   '<input type="radio" name="dirsrch_available"'.
 2663:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2664:                   '<label><input type="radio" name="dirsrch_available"'.
 2665:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2666:                   '</tr><tr>'.
 2667:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 2668:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2669:                   '<input type="radio" name="dirsrch_localonly"'.
 2670:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 2671:                   '<label><input type="radio" name="dirsrch_localonly"'.
 2672:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 2673:                   '</tr>';
 2674:     $$rowtotal += 2;
 2675:     if (ref($usertypes) eq 'HASH') {
 2676:         if (keys(%{$usertypes}) > 0) {
 2677:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
 2678:                                          $numinrow,$othertitle,'cansearch');
 2679:             $cansrchrow = 1;
 2680:         }
 2681:     }
 2682:     if ($cansrchrow) {
 2683:         $$rowtotal ++;
 2684:         $datatable .= '<tr>';
 2685:     } else {
 2686:         $datatable .= '<tr class="LC_odd_row">';
 2687:     }
 2688:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 2689:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 2690:     foreach my $title (@{$titleorder}) {
 2691:         if (defined($searchtitles->{$title})) {
 2692:             my $check = ' ';
 2693:             if (ref($settings) eq 'HASH') {
 2694:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 2695:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 2696:                         $check = ' checked="checked" ';
 2697:                     }
 2698:                 }
 2699:             }
 2700:             $datatable .= '<td class="LC_left_item">'.
 2701:                           '<span class="LC_nobreak"><label>'.
 2702:                           '<input type="checkbox" name="searchby" '.
 2703:                           'value="'.$title.'"'.$check.'/>'.
 2704:                           $searchtitles->{$title}.'</label></span></td>';
 2705:         }
 2706:     }
 2707:     $datatable .= '</tr></table></td></tr>';
 2708:     $$rowtotal ++;
 2709:     if ($cansrchrow) {
 2710:         $datatable .= '<tr class="LC_odd_row">';
 2711:     } else {
 2712:         $datatable .= '<tr>';
 2713:     }
 2714:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 2715:                   '<td class="LC_left_item" colspan="2">'.
 2716:                   '<span class="LC_nobreak"><label>'.
 2717:                   '<input type="checkbox" name="searchtypes" '.
 2718:                   $exacton.' value="exact" />'.&mt('Exact match').
 2719:                   '</label>&nbsp;'.
 2720:                   '<label><input type="checkbox" name="searchtypes" '.
 2721:                   $beginson.' value="begins" />'.&mt('Begins with').
 2722:                   '</label>&nbsp;'.
 2723:                   '<label><input type="checkbox" name="searchtypes" '.
 2724:                   $containson.' value="contains" />'.&mt('Contains').
 2725:                   '</label></span></td></tr>';
 2726:     $$rowtotal ++;
 2727:     return $datatable;
 2728: }
 2729: 
 2730: sub print_contacts {
 2731:     my ($dom,$settings,$rowtotal) = @_;
 2732:     my $datatable;
 2733:     my @contacts = ('adminemail','supportemail');
 2734:     my (%checked,%to,%otheremails,%bccemails);
 2735:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
 2736:                     'requestsmail','updatesmail','idconflictsmail');
 2737:     foreach my $type (@mailings) {
 2738:         $otheremails{$type} = '';
 2739:     }
 2740:     $bccemails{'helpdeskmail'} = '';
 2741:     if (ref($settings) eq 'HASH') {
 2742:         foreach my $item (@contacts) {
 2743:             if (exists($settings->{$item})) {
 2744:                 $to{$item} = $settings->{$item};
 2745:             }
 2746:         }
 2747:         foreach my $type (@mailings) {
 2748:             if (exists($settings->{$type})) {
 2749:                 if (ref($settings->{$type}) eq 'HASH') {
 2750:                     foreach my $item (@contacts) {
 2751:                         if ($settings->{$type}{$item}) {
 2752:                             $checked{$type}{$item} = ' checked="checked" ';
 2753:                         }
 2754:                     }
 2755:                     $otheremails{$type} = $settings->{$type}{'others'};
 2756:                     if ($type eq 'helpdeskmail') {
 2757:                         $bccemails{$type} = $settings->{$type}{'bcc'};
 2758:                     }
 2759:                 }
 2760:             } elsif ($type eq 'lonstatusmail') {
 2761:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
 2762:             }
 2763:         }
 2764:     } else {
 2765:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2766:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2767:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 2768:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 2769:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
 2770:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
 2771:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
 2772:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
 2773:         $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
 2774:     }
 2775:     my ($titles,$short_titles) = &contact_titles();
 2776:     my $rownum = 0;
 2777:     my $css_class;
 2778:     foreach my $item (@contacts) {
 2779:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2780:         $datatable .= '<tr'.$css_class.'>'. 
 2781:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2782:                   '</span></td><td class="LC_right_item">'.
 2783:                   '<input type="text" name="'.$item.'" value="'.
 2784:                   $to{$item}.'" /></td></tr>';
 2785:         $rownum ++;
 2786:     }
 2787:     foreach my $type (@mailings) {
 2788:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2789:         $datatable .= '<tr'.$css_class.'>'.
 2790:                       '<td><span class="LC_nobreak">'.
 2791:                       $titles->{$type}.': </span></td>'.
 2792:                       '<td class="LC_left_item">'.
 2793:                       '<span class="LC_nobreak">';
 2794:         foreach my $item (@contacts) {
 2795:             $datatable .= '<label>'.
 2796:                           '<input type="checkbox" name="'.$type.'"'.
 2797:                           $checked{$type}{$item}.
 2798:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 2799:                           '</label>&nbsp;';
 2800:         }
 2801:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 2802:                       '<input type="text" name="'.$type.'_others" '.
 2803:                       'value="'.$otheremails{$type}.'"  />';
 2804:         if ($type eq 'helpdeskmail') {
 2805:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
 2806:                           '<input type="text" name="'.$type.'_bcc" '.
 2807:                           'value="'.$bccemails{$type}.'"  />';
 2808:         }
 2809:         $datatable .= '</td></tr>'."\n";
 2810:         $rownum ++;
 2811:     }
 2812:     my %choices;
 2813:     $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
 2814:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 2815:                                    &mt('LON-CAPA core group - MSU'),600,500));
 2816:     $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
 2817:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 2818:                                     &mt('LON-CAPA core group - MSU'),600,500));
 2819:     my @toggles = ('reporterrors','reportupdates');
 2820:     my %defaultchecked = ('reporterrors'  => 'on',
 2821:                           'reportupdates' => 'on');
 2822:     (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2823:                                                \%choices,$rownum);
 2824:     $datatable .= $reports;
 2825:     $$rowtotal += $rownum;
 2826:     return $datatable;
 2827: }
 2828: 
 2829: sub print_helpsettings {
 2830:     my ($dom,$confname,$settings,$rowtotal) = @_;
 2831:     my ($datatable,$itemcount);
 2832:     $itemcount = 1;
 2833:     my (%choices,%defaultchecked,@toggles);
 2834:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
 2835:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
 2836:                                  &mt('LON-CAPA bug tracker'),600,500));
 2837:     %defaultchecked = ('submitbugs' => 'on');
 2838:     @toggles = ('submitbugs',);
 2839: 
 2840:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2841:                                                  \%choices,$itemcount);
 2842:     return $datatable;
 2843: }
 2844: 
 2845: sub radiobutton_prefs {
 2846:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
 2847:         $additional,$align) = @_;
 2848:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
 2849:                    (ref($choices) eq 'HASH'));
 2850: 
 2851:     my (%checkedon,%checkedoff,$datatable,$css_class);
 2852: 
 2853:     foreach my $item (@{$toggles}) {
 2854:         if ($defaultchecked->{$item} eq 'on') {
 2855:             $checkedon{$item} = ' checked="checked" ';
 2856:             $checkedoff{$item} = ' ';
 2857:         } elsif ($defaultchecked->{$item} eq 'off') {
 2858:             $checkedoff{$item} = ' checked="checked" ';
 2859:             $checkedon{$item} = ' ';
 2860:         }
 2861:     }
 2862:     if (ref($settings) eq 'HASH') {
 2863:         foreach my $item (@{$toggles}) {
 2864:             if ($settings->{$item} eq '1') {
 2865:                 $checkedon{$item} =  ' checked="checked" ';
 2866:                 $checkedoff{$item} = ' ';
 2867:             } elsif ($settings->{$item} eq '0') {
 2868:                 $checkedoff{$item} =  ' checked="checked" ';
 2869:                 $checkedon{$item} = ' ';
 2870:             }
 2871:         }
 2872:     }
 2873:     if ($onclick) {
 2874:         $onclick = ' onclick="'.$onclick.'"';
 2875:     }
 2876:     foreach my $item (@{$toggles}) {
 2877:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2878:         $datatable .=
 2879:             '<tr'.$css_class.'><td valign="top">'.
 2880:             '<span class="LC_nobreak">'.$choices->{$item}.
 2881:             '</span></td>';
 2882:         if ($align eq 'left') {
 2883:             $datatable .= '<td class="LC_left_item">';
 2884:         } else {
 2885:             $datatable .= '<td class="LC_right_item">';
 2886:         }
 2887:         $datatable .= 
 2888:             '<span class="LC_nobreak">'.
 2889:             '<label><input type="radio" name="'.
 2890:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
 2891:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
 2892:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
 2893:             '</span>'.$additional.
 2894:             '</td>'.
 2895:             '</tr>';
 2896:         $itemcount ++;
 2897:     }
 2898:     return ($datatable,$itemcount);
 2899: }
 2900: 
 2901: sub print_coursedefaults {
 2902:     my ($position,$dom,$settings,$rowtotal) = @_;
 2903:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
 2904:     my $itemcount = 1;
 2905:     my %choices =  &Apache::lonlocal::texthash (
 2906:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
 2907:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
 2908:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
 2909:         coursecredits        => 'Credits can be specified for courses',
 2910:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
 2911:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
 2912:         postsubmit           => 'Disable submit button/keypress following student submission',
 2913:     );
 2914:     my %staticdefaults = (
 2915:                            anonsurvey_threshold => 10,
 2916:                            uploadquota          => 500,
 2917:                            postsubmit           => 60,
 2918:                          );
 2919:     if ($position eq 'top') {
 2920:         %defaultchecked = (
 2921:                             'canuse_pdfforms' => 'off',
 2922:                             'uselcmath'       => 'on',
 2923:                             'usejsme'         => 'on',
 2924:                           );
 2925:         @toggles = ('canuse_pdfforms','uselcmath','usejsme');
 2926:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2927:                                                      \%choices,$itemcount);
 2928:     } else {
 2929:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2930:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
 2931:         my $currusecredits = 0;
 2932:         my $postsubmitclient = 1;
 2933:         my @types = ('official','unofficial','community','textbook');
 2934:         if (ref($settings) eq 'HASH') {
 2935:             $currdefresponder = $settings->{'anonsurvey_threshold'};
 2936:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
 2937:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
 2938:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
 2939:                 }
 2940:             }
 2941:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
 2942:                 foreach my $type (@types) {
 2943:                     next if ($type eq 'community');
 2944:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
 2945:                     if ($defcredits{$type} ne '') {
 2946:                         $currusecredits = 1;
 2947:                     }
 2948:                 }
 2949:             }
 2950:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
 2951:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
 2952:                     $postsubmitclient = 0;
 2953:                     foreach my $type (@types) {
 2954:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2955:                     }
 2956:                 } else {
 2957:                     foreach my $type (@types) {
 2958:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
 2959:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
 2960:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type}; 
 2961:                             } else {
 2962:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2963:                             }
 2964:                         } else {
 2965:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2966:                         }
 2967:                     }
 2968:                 }
 2969:             } else {
 2970:                 foreach my $type (@types) {
 2971:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2972:                 }
 2973:             }
 2974:         } else {
 2975:             foreach my $type (@types) {
 2976:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
 2977:             }
 2978:         }
 2979:         if (!$currdefresponder) {
 2980:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
 2981:         } elsif ($currdefresponder < 1) {
 2982:             $currdefresponder = 1;
 2983:         }
 2984:         foreach my $type (@types) {
 2985:             if ($curruploadquota{$type} eq '') {
 2986:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
 2987:             }
 2988:         }
 2989:         $datatable .=
 2990:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 2991:                 $choices{'anonsurvey_threshold'}.
 2992:                 '</span></td>'.
 2993:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
 2994:                 '<input type="text" name="anonsurvey_threshold"'.
 2995:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
 2996:                 '</td></tr>'."\n";
 2997:         $itemcount ++;
 2998:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2999:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 3000:                       $choices{'uploadquota'}.
 3001:                       '</span></td>'.
 3002:                       '<td align="right" class="LC_right_item">'.
 3003:                       '<table><tr>';
 3004:         foreach my $type (@types) {
 3005:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
 3006:                            '<input type="text" name="uploadquota_'.$type.'"'.
 3007:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
 3008:         }
 3009:         $datatable .= '</tr></table></td></tr>'."\n";
 3010:         $itemcount ++;
 3011:         my $onclick = "toggleDisplay(this.form,'credits');";
 3012:         my $display = 'none';
 3013:         if ($currusecredits) {
 3014:             $display = 'block';
 3015:         }
 3016:         my $additional = '<div id="credits" style="display: '.$display.'">'.
 3017:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
 3018:         foreach my $type (@types) {
 3019:             next if ($type eq 'community');
 3020:             $additional .= '<td align="center">'.&mt($type).'<br />'.
 3021:                            '<input type="text" name="'.$type.'_credits"'.
 3022:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
 3023:         }
 3024:         $additional .= '</tr></table></div>'."\n";
 3025:         %defaultchecked = ('coursecredits' => 'off');
 3026:         @toggles = ('coursecredits');
 3027:         my $current = {
 3028:                         'coursecredits' => $currusecredits,
 3029:                       };
 3030:         (my $table,$itemcount) =
 3031:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
 3032:                                \%choices,$itemcount,$onclick,$additional,'left');
 3033:         $datatable .= $table;
 3034:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
 3035:         my $display = 'none';
 3036:         if ($postsubmitclient) {
 3037:             $display = 'block';
 3038:         }
 3039:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
 3040:                       &mt('Number of seconds submit is disabled').'<br />'.
 3041:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
 3042:                       '<table><tr>';
 3043:         foreach my $type (@types) {
 3044:             $additional .= '<td align="center">'.&mt($type).'<br />'.
 3045:                            '<input type="text" name="'.$type.'_timeout" value="'.
 3046:                            $deftimeout{$type}.'" size="5" /></td>';
 3047:         }
 3048:         $additional .= '</tr></table></div>'."\n";
 3049:         %defaultchecked = ('postsubmit' => 'on');
 3050:         @toggles = ('postsubmit');
 3051:         my $current = {
 3052:                         'postsubmit' => $postsubmitclient,
 3053:                       };
 3054:         ($table,$itemcount) =
 3055:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
 3056:                                \%choices,$itemcount,$onclick,$additional,'left');
 3057:         $datatable .= $table;
 3058:     }
 3059:     $$rowtotal += $itemcount;
 3060:     return $datatable;
 3061: }
 3062: 
 3063: sub print_selfenrollment {
 3064:     my ($position,$dom,$settings,$rowtotal) = @_;
 3065:     my ($css_class,$datatable);
 3066:     my $itemcount = 1;
 3067:     my @types = ('official','unofficial','community','textbook');
 3068:     if (($position eq 'top') || ($position eq 'middle')) {
 3069:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
 3070:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
 3071:         my @rows;
 3072:         my $key;
 3073:         if ($position eq 'top') {
 3074:             $key = 'admin'; 
 3075:             if (ref($rowsref) eq 'ARRAY') {
 3076:                 @rows = @{$rowsref};
 3077:             }
 3078:         } elsif ($position eq 'middle') {
 3079:             $key = 'default';
 3080:             @rows = ('types','registered','approval','limit');
 3081:         }
 3082:         foreach my $row (@rows) {
 3083:             if (defined($titlesref->{$row})) {
 3084:                 $itemcount ++;
 3085:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3086:                 $datatable .= '<tr'.$css_class.'>'.
 3087:                               '<td>'.$titlesref->{$row}.'</td>'.
 3088:                               '<td class="LC_left_item">'.
 3089:                               '<table><tr>';
 3090:                 my (%current,%currentcap);
 3091:                 if (ref($settings) eq 'HASH') {
 3092:                     if (ref($settings->{$key}) eq 'HASH') {
 3093:                         foreach my $type (@types) {
 3094:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
 3095:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
 3096:                             }
 3097:                             if (($row eq 'limit') && ($key eq 'default')) {
 3098:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
 3099:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
 3100:                                 }
 3101:                             }
 3102:                         }
 3103:                     }
 3104:                 }
 3105:                 my %roles = (
 3106:                              '0' => &Apache::lonnet::plaintext('dc'),
 3107:                             ); 
 3108:             
 3109:                 foreach my $type (@types) {
 3110:                     unless (($row eq 'registered') && ($key eq 'default')) {
 3111:                         $datatable .= '<th>'.&mt($type).'</th>';
 3112:                     }
 3113:                 }
 3114:                 unless (($row eq 'registered') && ($key eq 'default')) {
 3115:                     $datatable .= '</tr><tr>';
 3116:                 }
 3117:                 foreach my $type (@types) {
 3118:                     if ($type eq 'community') {
 3119:                         $roles{'1'} = &mt('Community personnel');
 3120:                     } else {
 3121:                         $roles{'1'} = &mt('Course personnel');
 3122:                     }
 3123:                     $datatable .= '<td style="vertical-align: top">';
 3124:                     if ($position eq 'top') {
 3125:                         my %checked;
 3126:                         if ($current{$type} eq '0') {
 3127:                             $checked{'0'} = ' checked="checked"';
 3128:                         } else {
 3129:                             $checked{'1'} = ' checked="checked"';
 3130:                         }
 3131:                         foreach my $role ('1','0') {
 3132:                             $datatable .= '<span class="LC_nobreak"><label>'.
 3133:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
 3134:                                           'value="'.$role.'"'.$checked{$role}.' />'.
 3135:                                           $roles{$role}.'</label></span> ';
 3136:                         }
 3137:                     } else {
 3138:                         if ($row eq 'types') {
 3139:                             my %checked;
 3140:                             if ($current{$type} =~ /^(all|dom)$/) {
 3141:                                 $checked{$1} = ' checked="checked"';
 3142:                             } else {
 3143:                                 $checked{''} = ' checked="checked"';
 3144:                             }
 3145:                             foreach my $val ('','dom','all') {
 3146:                                 $datatable .= '<span class="LC_nobreak"><label>'.
 3147:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
 3148:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
 3149:                             }
 3150:                         } elsif ($row eq 'registered') {
 3151:                             my %checked;
 3152:                             if ($current{$type} eq '1') {
 3153:                                 $checked{'1'} = ' checked="checked"';
 3154:                             } else {
 3155:                                 $checked{'0'} = ' checked="checked"';
 3156:                             }
 3157:                             foreach my $val ('0','1') {
 3158:                                 $datatable .= '<span class="LC_nobreak"><label>'.
 3159:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
 3160:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
 3161:                             }
 3162:                         } elsif ($row eq 'approval') {
 3163:                             my %checked;
 3164:                             if ($current{$type} =~ /^([12])$/) {
 3165:                                 $checked{$1} = ' checked="checked"';
 3166:                             } else {
 3167:                                 $checked{'0'} = ' checked="checked"';
 3168:                             }
 3169:                             for my $val (0..2) {
 3170:                                 $datatable .= '<span class="LC_nobreak"><label>'.
 3171:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
 3172:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
 3173:                             }
 3174:                         } elsif ($row eq 'limit') {
 3175:                             my %checked;
 3176:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
 3177:                                 $checked{$1} = ' checked="checked"';
 3178:                             } else {
 3179:                                 $checked{'none'} = ' checked="checked"';
 3180:                             }
 3181:                             my $cap;
 3182:                             if ($currentcap{$type} =~ /^\d+$/) {
 3183:                                 $cap = $currentcap{$type};
 3184:                             }
 3185:                             foreach my $val ('none','allstudents','selfenrolled') {
 3186:                                 $datatable .= '<span class="LC_nobreak"><label>'.
 3187:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
 3188:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
 3189:                             }
 3190:                             $datatable .= '<br />'.
 3191:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
 3192:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
 3193:                                           '</span>'; 
 3194:                         }
 3195:                     }
 3196:                     $datatable .= '</td>';
 3197:                 }
 3198:                 $datatable .= '</tr>';
 3199:             }
 3200:             $datatable .= '</table></td></tr>';
 3201:         }
 3202:     } elsif ($position eq 'bottom') {
 3203:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
 3204:     }
 3205:     $$rowtotal += $itemcount;
 3206:     return $datatable;
 3207: }
 3208: 
 3209: sub print_validation_rows {
 3210:     my ($caller,$dom,$settings,$rowtotal) = @_;
 3211:     my ($itemsref,$namesref,$fieldsref);
 3212:     if ($caller eq 'selfenroll') { 
 3213:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
 3214:     } elsif ($caller eq 'requestcourses') {
 3215:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
 3216:     }
 3217:     my %currvalidation;
 3218:     if (ref($settings) eq 'HASH') {
 3219:         if (ref($settings->{'validation'}) eq 'HASH') {
 3220:             %currvalidation = %{$settings->{'validation'}};
 3221:         }
 3222:     }
 3223:     my $datatable;
 3224:     my $itemcount = 0;
 3225:     foreach my $item (@{$itemsref}) {
 3226:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 3227:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 3228:                       $namesref->{$item}.
 3229:                       '</span></td>'.
 3230:                       '<td class="LC_left_item">';
 3231:         if (($item eq 'url') || ($item eq 'button')) {
 3232:             $datatable .= '<span class="LC_nobreak">'.
 3233:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
 3234:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
 3235:         } elsif ($item eq 'fields') {
 3236:             my @currfields;
 3237:             if (ref($currvalidation{$item}) eq 'ARRAY') {
 3238:                 @currfields = @{$currvalidation{$item}};
 3239:             }
 3240:             foreach my $field (@{$fieldsref}) {
 3241:                 my $check = '';
 3242:                 if (grep(/^\Q$field\E$/,@currfields)) {
 3243:                     $check = ' checked="checked"';
 3244:                 }
 3245:                 $datatable .= '<span class="LC_nobreak"><label>'.
 3246:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
 3247:                               ' value="'.$field.'"'.$check.' />'.$field.
 3248:                               '</label></span> ';
 3249:             }
 3250:         } elsif ($item eq 'markup') {
 3251:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
 3252:                            $currvalidation{$item}.
 3253:                               '</textarea>';
 3254:         }
 3255:         $datatable .= '</td></tr>'."\n";
 3256:         if (ref($rowtotal)) {
 3257:             $itemcount ++;
 3258:         }
 3259:     }
 3260:     if ($caller eq 'requestcourses') {
 3261:         my %currhash;
 3262:         if (ref($settings) eq 'HASH') {
 3263:             if (ref($settings->{'validation'}) eq 'HASH') {
 3264:                 if ($settings->{'validation'}{'dc'} ne '') {
 3265:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
 3266:                 }
 3267:             }
 3268:         }
 3269:         my $numinrow = 2;
 3270:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
 3271:                                                        'validationdc',%currhash);
 3272:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 3273:         $datatable .= '</td></tr><tr'.$css_class.'><td>';
 3274:         if ($numdc > 1) {
 3275:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
 3276:         } else {
 3277:             $datatable .=  &mt('Course creation processed as: ');
 3278:         }
 3279:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
 3280:         $itemcount ++;
 3281:     }
 3282:     if (ref($rowtotal)) {
 3283:         $$rowtotal += $itemcount;
 3284:     }
 3285:     return $datatable;
 3286: }
 3287: 
 3288: sub print_usersessions {
 3289:     my ($position,$dom,$settings,$rowtotal) = @_;
 3290:     my ($css_class,$datatable,%checked,%choices);
 3291:     my (%by_ip,%by_location,@intdoms);
 3292:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 3293: 
 3294:     my @alldoms = &Apache::lonnet::all_domains();
 3295:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
 3296:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 3297:     my %altids = &id_for_thisdom(%servers);
 3298:     my $itemcount = 1;
 3299:     if ($position eq 'top') {
 3300:         if (keys(%serverhomes) > 1) {
 3301:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
 3302:             my $curroffloadnow;
 3303:             if (ref($settings) eq 'HASH') {
 3304:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
 3305:                     $curroffloadnow = $settings->{'offloadnow'};
 3306:                 }
 3307:             }
 3308:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
 3309:         } else {
 3310:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 3311:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
 3312:         }
 3313:     } else {
 3314:         if (keys(%by_location) == 0) {
 3315:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 3316:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
 3317:         } else {
 3318:             my %lt = &usersession_titles();
 3319:             my $numinrow = 5;
 3320:             my $prefix;
 3321:             my @types;
 3322:             if ($position eq 'bottom') {
 3323:                 $prefix = 'remote';
 3324:                 @types = ('version','excludedomain','includedomain');
 3325:             } else {
 3326:                 $prefix = 'hosted';
 3327:                 @types = ('excludedomain','includedomain');
 3328:             }
 3329:             my (%current,%checkedon,%checkedoff);
 3330:             my @lcversions = &Apache::lonnet::all_loncaparevs();
 3331:             my @locations = sort(keys(%by_location));
 3332:             foreach my $type (@types) {
 3333:                 $checkedon{$type} = '';
 3334:                 $checkedoff{$type} = ' checked="checked"';
 3335:             }
 3336:             if (ref($settings) eq 'HASH') {
 3337:                 if (ref($settings->{$prefix}) eq 'HASH') {
 3338:                     foreach my $key (keys(%{$settings->{$prefix}})) {
 3339:                         $current{$key} = $settings->{$prefix}{$key};
 3340:                         if ($key eq 'version') {
 3341:                             if ($current{$key} ne '') {
 3342:                                 $checkedon{$key} = ' checked="checked"';
 3343:                                 $checkedoff{$key} = '';
 3344:                             }
 3345:                         } elsif (ref($current{$key}) eq 'ARRAY') {
 3346:                             $checkedon{$key} = ' checked="checked"';
 3347:                             $checkedoff{$key} = '';
 3348:                         }
 3349:                     }
 3350:                 }
 3351:             }
 3352:             foreach my $type (@types) {
 3353:                 next if ($type ne 'version' && !@locations);
 3354:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 3355:                 $datatable .= '<tr'.$css_class.'>
 3356:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
 3357:                                <span class="LC_nobreak">&nbsp;
 3358:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
 3359:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
 3360:                 if ($type eq 'version') {
 3361:                     my $selector = '<select name="'.$prefix.'_version">';
 3362:                     foreach my $version (@lcversions) {
 3363:                         my $selected = '';
 3364:                         if ($current{'version'} eq $version) {
 3365:                             $selected = ' selected="selected"';
 3366:                         }
 3367:                         $selector .= ' <option value="'.$version.'"'.
 3368:                                      $selected.'>'.$version.'</option>';
 3369:                     }
 3370:                     $selector .= '</select> ';
 3371:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
 3372:                 } else {
 3373:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
 3374:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
 3375:                                  ' />'.('&nbsp;'x2).
 3376:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
 3377:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
 3378:                                  "\n".
 3379:                                  '</div><div><table>';
 3380:                     my $rem;
 3381:                     for (my $i=0; $i<@locations; $i++) {
 3382:                         my ($showloc,$value,$checkedtype);
 3383:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
 3384:                             my $ip = $by_location{$locations[$i]}->[0];
 3385:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
 3386:                                  $value = join(':',@{$by_ip{$ip}});
 3387:                                 $showloc = join(', ',@{$by_ip{$ip}});
 3388:                                 if (ref($current{$type}) eq 'ARRAY') {
 3389:                                     foreach my $loc (@{$by_ip{$ip}}) {  
 3390:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
 3391:                                             $checkedtype = ' checked="checked"';
 3392:                                             last;
 3393:                                         }
 3394:                                     }
 3395:                                 }
 3396:                             }
 3397:                         }
 3398:                         $rem = $i%($numinrow);
 3399:                         if ($rem == 0) {
 3400:                             if ($i > 0) {
 3401:                                 $datatable .= '</tr>';
 3402:                             }
 3403:                             $datatable .= '<tr>';
 3404:                         }
 3405:                         $datatable .= '<td class="LC_left_item">'.
 3406:                                       '<span class="LC_nobreak"><label>'.
 3407:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
 3408:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
 3409:                                       '</label></span></td>';
 3410:                     }
 3411:                     $rem = @locations%($numinrow);
 3412:                     my $colsleft = $numinrow - $rem;
 3413:                     if ($colsleft > 1 ) {
 3414:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3415:                                       '&nbsp;</td>';
 3416:                     } elsif ($colsleft == 1) {
 3417:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 3418:                     }
 3419:                     $datatable .= '</tr></table>';
 3420:                 }
 3421:                 $datatable .= '</td></tr>';
 3422:                 $itemcount ++;
 3423:             }
 3424:         }
 3425:     }
 3426:     $$rowtotal += $itemcount;
 3427:     return $datatable;
 3428: }
 3429: 
 3430: sub build_location_hashes {
 3431:     my ($intdoms,$by_ip,$by_location) = @_;
 3432:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
 3433:                   (ref($by_location) eq 'HASH')); 
 3434:     my %iphost = &Apache::lonnet::get_iphost();
 3435:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
 3436:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
 3437:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
 3438:         foreach my $id (@{$iphost{$primary_ip}}) {
 3439:             my $intdom = &Apache::lonnet::internet_dom($id);
 3440:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
 3441:                 push(@{$intdoms},$intdom);
 3442:             }
 3443:         }
 3444:     }
 3445:     foreach my $ip (keys(%iphost)) {
 3446:         if (ref($iphost{$ip}) eq 'ARRAY') {
 3447:             foreach my $id (@{$iphost{$ip}}) {
 3448:                 my $location = &Apache::lonnet::internet_dom($id);
 3449:                 if ($location) {
 3450:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
 3451:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
 3452:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
 3453:                             push(@{$by_ip->{$ip}},$location);
 3454:                         }
 3455:                     } else {
 3456:                         $by_ip->{$ip} = [$location];
 3457:                     }
 3458:                 }
 3459:             }
 3460:         }
 3461:     }
 3462:     foreach my $ip (sort(keys(%{$by_ip}))) {
 3463:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
 3464:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
 3465:             my $first = $by_ip->{$ip}->[0];
 3466:             if (ref($by_location->{$first}) eq 'ARRAY') {
 3467:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
 3468:                     push(@{$by_location->{$first}},$ip);
 3469:                 }
 3470:             } else {
 3471:                 $by_location->{$first} = [$ip];
 3472:             }
 3473:         }
 3474:     }
 3475:     return;
 3476: }
 3477: 
 3478: sub current_offloads_to {
 3479:     my ($dom,$settings,$servers) = @_;
 3480:     my (%spareid,%otherdomconfigs);
 3481:     if (ref($servers) eq 'HASH') {
 3482:         foreach my $lonhost (sort(keys(%{$servers}))) {
 3483:             my $gotspares;
 3484:             if (ref($settings) eq 'HASH') {
 3485:                 if (ref($settings->{'spares'}) eq 'HASH') {
 3486:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
 3487:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
 3488:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
 3489:                         $gotspares = 1;
 3490:                     }
 3491:                 }
 3492:             }
 3493:             unless ($gotspares) {
 3494:                 my $gotspares;
 3495:                 my $serverhomeID =
 3496:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
 3497:                 my $serverhomedom =
 3498:                     &Apache::lonnet::host_domain($serverhomeID);
 3499:                 if ($serverhomedom ne $dom) {
 3500:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
 3501:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 3502:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 3503:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 3504:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 3505:                                 $gotspares = 1;
 3506:                             }
 3507:                         }
 3508:                     } else {
 3509:                         $otherdomconfigs{$serverhomedom} =
 3510:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
 3511:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
 3512:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 3513:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 3514:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
 3515:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 3516:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 3517:                                         $gotspares = 1;
 3518:                                     }
 3519:                                 }
 3520:                             }
 3521:                         }
 3522:                     }
 3523:                 }
 3524:             }
 3525:             unless ($gotspares) {
 3526:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
 3527:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 3528:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 3529:                } else {
 3530:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
 3531:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
 3532:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
 3533:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 3534:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 3535:                     } else {
 3536:                         my %what = (
 3537:                              spareid => 1,
 3538:                         );
 3539:                         my ($result,$returnhash) = 
 3540:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
 3541:                         if ($result eq 'ok') { 
 3542:                             if (ref($returnhash) eq 'HASH') {
 3543:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
 3544:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
 3545:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
 3546:                                 }
 3547:                             }
 3548:                         }
 3549:                     }
 3550:                 }
 3551:             }
 3552:         }
 3553:     }
 3554:     return %spareid;
 3555: }
 3556: 
 3557: sub spares_row {
 3558:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
 3559:     my $css_class;
 3560:     my $numinrow = 4;
 3561:     my $itemcount = 1;
 3562:     my $datatable;
 3563:     my %typetitles = &sparestype_titles();
 3564:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
 3565:         foreach my $server (sort(keys(%{$servers}))) {
 3566:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
 3567:             my ($othercontrol,$serverdom);
 3568:             if ($serverhome ne $server) {
 3569:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
 3570:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 3571:             } else {
 3572:                 $serverdom = &Apache::lonnet::host_domain($server);
 3573:                 if ($serverdom ne $dom) {
 3574:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 3575:                 }
 3576:             }
 3577:             next unless (ref($spareid->{$server}) eq 'HASH');
 3578:             my $checkednow;
 3579:             if (ref($curroffloadnow) eq 'HASH') {
 3580:                 if ($curroffloadnow->{$server}) {
 3581:                     $checkednow = ' checked="checked"';
 3582:                 }
 3583:             }
 3584:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 3585:             $datatable .= '<tr'.$css_class.'>
 3586:                            <td rowspan="2">
 3587:                             <span class="LC_nobreak">'.
 3588:                           &mt('[_1] when busy, offloads to:'
 3589:                               ,'<b>'.$server.'</b>').'</span><br />'.
 3590:                           '<span class="LC_nobreak">'."\n". 
 3591:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
 3592:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
 3593:                           "\n";
 3594:             my (%current,%canselect);
 3595:             my @choices = 
 3596:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
 3597:             foreach my $type ('primary','default') {
 3598:                 if (ref($spareid->{$server}) eq 'HASH') {
 3599:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
 3600:                         my @spares = @{$spareid->{$server}{$type}};
 3601:                         if (@spares > 0) {
 3602:                             if ($othercontrol) {
 3603:                                 $current{$type} = join(', ',@spares);
 3604:                             } else {
 3605:                                 $current{$type} .= '<table>';
 3606:                                 my $numspares = scalar(@spares);
 3607:                                 for (my $i=0;  $i<@spares; $i++) {
 3608:                                     my $rem = $i%($numinrow);
 3609:                                     if ($rem == 0) {
 3610:                                         if ($i > 0) {
 3611:                                             $current{$type} .= '</tr>';
 3612:                                         }
 3613:                                         $current{$type} .= '<tr>';
 3614:                                     }
 3615:                                     $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;'.
 3616:                                                        $spareid->{$server}{$type}[$i].
 3617:                                                        '</label></td>'."\n";
 3618:                                 }
 3619:                                 my $rem = @spares%($numinrow);
 3620:                                 my $colsleft = $numinrow - $rem;
 3621:                                 if ($colsleft > 1 ) {
 3622:                                     $current{$type} .= '<td colspan="'.$colsleft.
 3623:                                                        '" class="LC_left_item">'.
 3624:                                                        '&nbsp;</td>';
 3625:                                 } elsif ($colsleft == 1) {
 3626:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
 3627:                                 }
 3628:                                 $current{$type} .= '</tr></table>';
 3629:                             }
 3630:                         }
 3631:                     }
 3632:                     if ($current{$type} eq '') {
 3633:                         $current{$type} = &mt('None specified');
 3634:                     }
 3635:                     if ($othercontrol) {
 3636:                         if ($type eq 'primary') {
 3637:                             $canselect{$type} = $othercontrol;
 3638:                         }
 3639:                     } else {
 3640:                         $canselect{$type} = 
 3641:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
 3642:                             '<select name="newspare_'.$type.'_'.$server.'" '.
 3643:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
 3644:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
 3645:                         if (@choices > 0) {
 3646:                             foreach my $lonhost (@choices) {
 3647:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
 3648:                             }
 3649:                         }
 3650:                         $canselect{$type} .= '</select>'."\n";
 3651:                     }
 3652:                 } else {
 3653:                     $current{$type} = &mt('Could not be determined');
 3654:                     if ($type eq 'primary') {
 3655:                         $canselect{$type} =  $othercontrol;
 3656:                     }
 3657:                 }
 3658:                 if ($type eq 'default') {
 3659:                     $datatable .= '<tr'.$css_class.'>';
 3660:                 }
 3661:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
 3662:                               '<td>'.$current{$type}.'</td>'."\n".
 3663:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
 3664:             }
 3665:             $itemcount ++;
 3666:         }
 3667:     }
 3668:     $$rowtotal += $itemcount;
 3669:     return $datatable;
 3670: }
 3671: 
 3672: sub possible_newspares {
 3673:     my ($server,$currspares,$serverhomes,$altids) = @_;
 3674:     my $serverhostname = &Apache::lonnet::hostname($server);
 3675:     my %excluded;
 3676:     if ($serverhostname ne '') {
 3677:         %excluded = (
 3678:                        $serverhostname => 1,
 3679:                     );
 3680:     }
 3681:     if (ref($currspares) eq 'HASH') {
 3682:         foreach my $type (keys(%{$currspares})) {
 3683:             if (ref($currspares->{$type}) eq 'ARRAY') {
 3684:                 if (@{$currspares->{$type}} > 0) {
 3685:                     foreach my $curr (@{$currspares->{$type}}) {
 3686:                         my $hostname = &Apache::lonnet::hostname($curr);
 3687:                         $excluded{$hostname} = 1;
 3688:                     }
 3689:                 }
 3690:             }
 3691:         }
 3692:     }
 3693:     my @choices;
 3694:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
 3695:         if (keys(%{$serverhomes}) > 1) {
 3696:             foreach my $name (sort(keys(%{$serverhomes}))) {
 3697:                 unless ($excluded{$name}) {
 3698:                     if (exists($altids->{$serverhomes->{$name}})) {
 3699:                         push(@choices,$altids->{$serverhomes->{$name}});
 3700:                     } else {
 3701:                         push(@choices,$serverhomes->{$name});
 3702:                     }
 3703:                 }
 3704:             }
 3705:         }
 3706:     }
 3707:     return sort(@choices);
 3708: }
 3709: 
 3710: sub print_loadbalancing {
 3711:     my ($dom,$settings,$rowtotal) = @_;
 3712:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
 3713:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
 3714:     my $numinrow = 1;
 3715:     my $datatable;
 3716:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 3717:     my (%currbalancer,%currtargets,%currrules,%existing);
 3718:     if (ref($settings) eq 'HASH') {
 3719:         %existing = %{$settings};
 3720:     }
 3721:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
 3722:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
 3723:                                   \%currtargets,\%currrules);
 3724:     } else {
 3725:         return;
 3726:     }
 3727:     my ($othertitle,$usertypes,$types) =
 3728:         &Apache::loncommon::sorted_inst_types($dom);
 3729:     my $rownum = 8;
 3730:     if (ref($types) eq 'ARRAY') {
 3731:         $rownum += scalar(@{$types});
 3732:     }
 3733:     my @css_class = ('LC_odd_row','LC_even_row');
 3734:     my $balnum = 0;
 3735:     my $islast;
 3736:     my (@toshow,$disabledtext);
 3737:     if (keys(%currbalancer) > 0) {
 3738:         @toshow = sort(keys(%currbalancer));
 3739:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
 3740:             push(@toshow,'');
 3741:         }
 3742:     } else {
 3743:         @toshow = ('');
 3744:         $disabledtext = &mt('No existing load balancer');
 3745:     }
 3746:     foreach my $lonhost (@toshow) {
 3747:         if ($balnum == scalar(@toshow)-1) {
 3748:             $islast = 1;
 3749:         } else {
 3750:             $islast = 0;
 3751:         }
 3752:         my $cssidx = $balnum%2;
 3753:         my $targets_div_style = 'display: none';
 3754:         my $disabled_div_style = 'display: block';
 3755:         my $homedom_div_style = 'display: none';
 3756:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
 3757:                       '<td rowspan="'.$rownum.'" valign="top">'.
 3758:                       '<p>';
 3759:         if ($lonhost eq '') {
 3760:             $datatable .= '<span class="LC_nobreak">';
 3761:             if (keys(%currbalancer) > 0) {
 3762:                 $datatable .= &mt('Add balancer:');
 3763:             } else {
 3764:                 $datatable .= &mt('Enable balancer:');
 3765:             }
 3766:             $datatable .= '&nbsp;'.
 3767:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
 3768:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
 3769:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
 3770:                           '<option value="" selected="selected">'.&mt('None').
 3771:                           '</option>'."\n";
 3772:             foreach my $server (sort(keys(%servers))) {
 3773:                 next if ($currbalancer{$server});
 3774:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
 3775:             }
 3776:             $datatable .=
 3777:                 '</select>'."\n".
 3778:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
 3779:         } else {
 3780:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
 3781:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
 3782:                            &mt('Stop balancing').'</label>'.
 3783:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
 3784:             $targets_div_style = 'display: block';
 3785:             $disabled_div_style = 'display: none';
 3786:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
 3787:                 $homedom_div_style = 'display: block';
 3788:             }
 3789:         }
 3790:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
 3791:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
 3792:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
 3793:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
 3794:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
 3795:         my @sparestypes = ('primary','default');
 3796:         my %typetitles = &sparestype_titles();
 3797:         foreach my $sparetype (@sparestypes) {
 3798:             my $targettable;
 3799:             for (my $i=0; $i<$numspares; $i++) {
 3800:                 my $checked;
 3801:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
 3802:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
 3803:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
 3804:                             $checked = ' checked="checked"';
 3805:                         }
 3806:                     }
 3807:                 }
 3808:                 my ($chkboxval,$disabled);
 3809:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
 3810:                     $chkboxval = $spares[$i];
 3811:                 }
 3812:                 if (exists($currbalancer{$spares[$i]})) {
 3813:                     $disabled = ' disabled="disabled"';
 3814:                 }
 3815:                 $targettable .=
 3816:                     '<td><span class="LC_nobreak"><label>'.
 3817:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
 3818:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
 3819:                     '</span></label></span></td>';
 3820:                 my $rem = $i%($numinrow);
 3821:                 if ($rem == 0) {
 3822:                     if (($i > 0) && ($i < $numspares-1)) {
 3823:                         $targettable .= '</tr>';
 3824:                     }
 3825:                     if ($i < $numspares-1) {
 3826:                         $targettable .= '<tr>';
 3827:                     }
 3828:                 }
 3829:             }
 3830:             if ($targettable ne '') {
 3831:                 my $rem = $numspares%($numinrow);
 3832:                 my $colsleft = $numinrow - $rem;
 3833:                 if ($colsleft > 1 ) {
 3834:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3835:                                     '&nbsp;</td>';
 3836:                 } elsif ($colsleft == 1) {
 3837:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
 3838:                 }
 3839:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
 3840:                                '<table><tr>'.$targettable.'</tr></table><br />';
 3841:             }
 3842:         }
 3843:         $datatable .= '</div></td></tr>'.
 3844:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
 3845:                                            $othertitle,$usertypes,$types,\%servers,
 3846:                                            \%currbalancer,$lonhost,
 3847:                                            $targets_div_style,$homedom_div_style,
 3848:                                            $css_class[$cssidx],$balnum,$islast);
 3849:         $$rowtotal += $rownum;
 3850:         $balnum ++;
 3851:     }
 3852:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
 3853:     return $datatable;
 3854: }
 3855: 
 3856: sub get_loadbalancers_config {
 3857:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
 3858:     return unless ((ref($servers) eq 'HASH') &&
 3859:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
 3860:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
 3861:     if (keys(%{$existing}) > 0) {
 3862:         my $oldlonhost;
 3863:         foreach my $key (sort(keys(%{$existing}))) {
 3864:             if ($key eq 'lonhost') {
 3865:                 $oldlonhost = $existing->{'lonhost'};
 3866:                 $currbalancer->{$oldlonhost} = 1;
 3867:             } elsif ($key eq 'targets') {
 3868:                 if ($oldlonhost) {
 3869:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
 3870:                 }
 3871:             } elsif ($key eq 'rules') {
 3872:                 if ($oldlonhost) {
 3873:                     $currrules->{$oldlonhost} = $existing->{'rules'};
 3874:                 }
 3875:             } elsif (ref($existing->{$key}) eq 'HASH') {
 3876:                 $currbalancer->{$key} = 1;
 3877:                 $currtargets->{$key} = $existing->{$key}{'targets'};
 3878:                 $currrules->{$key} = $existing->{$key}{'rules'};
 3879:             }
 3880:         }
 3881:     } else {
 3882:         my ($balancerref,$targetsref) =
 3883:                 &Apache::lonnet::get_lonbalancer_config($servers);
 3884:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
 3885:             foreach my $server (sort(keys(%{$balancerref}))) {
 3886:                 $currbalancer->{$server} = 1;
 3887:                 $currtargets->{$server} = $targetsref->{$server};
 3888:             }
 3889:         }
 3890:     }
 3891:     return;
 3892: }
 3893: 
 3894: sub loadbalancing_rules {
 3895:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
 3896:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
 3897:         $css_class,$balnum,$islast) = @_;
 3898:     my $output;
 3899:     my $num = 0;
 3900:     my ($alltypes,$othertypes,$titles) =
 3901:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
 3902:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
 3903:         foreach my $type (@{$alltypes}) {
 3904:             $num ++;
 3905:             my $current;
 3906:             if (ref($currrules) eq 'HASH') {
 3907:                 $current = $currrules->{$type};
 3908:             }
 3909:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3910:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
 3911:                     $current = '';
 3912:                 }
 3913:             }
 3914:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
 3915:                                              $servers,$currbalancer,$lonhost,$dom,
 3916:                                              $targets_div_style,$homedom_div_style,
 3917:                                              $css_class,$balnum,$num,$islast);
 3918:         }
 3919:     }
 3920:     return $output;
 3921: }
 3922: 
 3923: sub loadbalancing_titles {
 3924:     my ($dom,$intdom,$usertypes,$types) = @_;
 3925:     my %othertypes = (
 3926:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
 3927:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
 3928:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
 3929:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
 3930:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
 3931:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
 3932:                      );
 3933:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
 3934:     if (ref($types) eq 'ARRAY') {
 3935:         unshift(@alltypes,@{$types},'default');
 3936:     }
 3937:     my %titles;
 3938:     foreach my $type (@alltypes) {
 3939:         if ($type =~ /^_LC_/) {
 3940:             $titles{$type} = $othertypes{$type};
 3941:         } elsif ($type eq 'default') {
 3942:             $titles{$type} = &mt('All users from [_1]',$dom);
 3943:             if (ref($types) eq 'ARRAY') {
 3944:                 if (@{$types} > 0) {
 3945:                     $titles{$type} = &mt('Other users from [_1]',$dom);
 3946:                 }
 3947:             }
 3948:         } elsif (ref($usertypes) eq 'HASH') {
 3949:             $titles{$type} = $usertypes->{$type};
 3950:         }
 3951:     }
 3952:     return (\@alltypes,\%othertypes,\%titles);
 3953: }
 3954: 
 3955: sub loadbalance_rule_row {
 3956:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
 3957:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
 3958:     my @rulenames;
 3959:     my %ruletitles = &offloadtype_text();
 3960:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
 3961:         @rulenames = ('balancer','offloadedto','specific');
 3962:     } else {
 3963:         @rulenames = ('default','homeserver');
 3964:         if ($type eq '_LC_external') {
 3965:             push(@rulenames,'externalbalancer');
 3966:         } else {
 3967:             push(@rulenames,'specific');
 3968:         }
 3969:         push(@rulenames,'none');
 3970:     }
 3971:     my $style = $targets_div_style;
 3972:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3973:         $style = $homedom_div_style;
 3974:     }
 3975:     my $space;
 3976:     if ($islast && $num == 1) {
 3977:         $space = '<div display="inline-block">&nbsp;</div>';
 3978:     }
 3979:     my $output =
 3980:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
 3981:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
 3982:         '<td valaign="top">'.$space.
 3983:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
 3984:     for (my $i=0; $i<@rulenames; $i++) {
 3985:         my $rule = $rulenames[$i];
 3986:         my ($checked,$extra);
 3987:         if ($rulenames[$i] eq 'default') {
 3988:             $rule = '';
 3989:         }
 3990:         if ($rulenames[$i] eq 'specific') {
 3991:             if (ref($servers) eq 'HASH') {
 3992:                 my $default;
 3993:                 if (($current ne '') && (exists($servers->{$current}))) {
 3994:                     $checked = ' checked="checked"';
 3995:                 }
 3996:                 unless ($checked) {
 3997:                     $default = ' selected="selected"';
 3998:                 }
 3999:                 $extra =
 4000:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
 4001:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
 4002:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
 4003:                     '<option value=""'.$default.'></option>'."\n";
 4004:                 foreach my $server (sort(keys(%{$servers}))) {
 4005:                     if (ref($currbalancer) eq 'HASH') {
 4006:                         next if (exists($currbalancer->{$server}));
 4007:                     }
 4008:                     my $selected;
 4009:                     if ($server eq $current) {
 4010:                         $selected = ' selected="selected"';
 4011:                     }
 4012:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
 4013:                 }
 4014:                 $extra .= '</select>';
 4015:             }
 4016:         } elsif ($rule eq $current) {
 4017:             $checked = ' checked="checked"';
 4018:         }
 4019:         $output .= '<span class="LC_nobreak"><label>'.
 4020:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
 4021:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
 4022:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
 4023:                    ')"'.$checked.' />&nbsp;';
 4024:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
 4025:             $output .= $ruletitles{'particular'};
 4026:         } else {
 4027:             $output .= $ruletitles{$rulenames[$i]};
 4028:         }
 4029:         $output .= '</label>'.$extra.'</span><br />'."\n";
 4030:     }
 4031:     $output .= '</div></td></tr>'."\n";
 4032:     return $output;
 4033: }
 4034: 
 4035: sub offloadtype_text {
 4036:     my %ruletitles = &Apache::lonlocal::texthash (
 4037:            'default'          => 'Offloads to default destinations',
 4038:            'homeserver'       => "Offloads to user's home server",
 4039:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
 4040:            'specific'         => 'Offloads to specific server',
 4041:            'none'             => 'No offload',
 4042:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
 4043:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
 4044:            'particular'       => 'Session hosted (after re-auth) on server:',
 4045:     );
 4046:     return %ruletitles;
 4047: }
 4048: 
 4049: sub sparestype_titles {
 4050:     my %typestitles = &Apache::lonlocal::texthash (
 4051:                           'primary' => 'primary',
 4052:                           'default' => 'default',
 4053:                       );
 4054:     return %typestitles;
 4055: }
 4056: 
 4057: sub contact_titles {
 4058:     my %titles = &Apache::lonlocal::texthash (
 4059:                    'supportemail' => 'Support E-mail address',
 4060:                    'adminemail'   => 'Default Server Admin E-mail address',
 4061:                    'errormail'    => 'Error reports to be e-mailed to',
 4062:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 4063:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
 4064:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
 4065:                    'requestsmail' => 'E-mail from course requests requiring approval',
 4066:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
 4067:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
 4068:                  );
 4069:     my %short_titles = &Apache::lonlocal::texthash (
 4070:                            adminemail   => 'Admin E-mail address',
 4071:                            supportemail => 'Support E-mail',
 4072:                        );   
 4073:     return (\%titles,\%short_titles);
 4074: }
 4075: 
 4076: sub tool_titles {
 4077:     my %titles = &Apache::lonlocal::texthash (
 4078:                      aboutme    => 'Personal web page',
 4079:                      blog       => 'Blog',
 4080:                      webdav     => 'WebDAV',
 4081:                      portfolio  => 'Portfolio',
 4082:                      official   => 'Official courses (with institutional codes)',
 4083:                      unofficial => 'Unofficial courses',
 4084:                      community  => 'Communities',
 4085:                      textbook   => 'Textbook courses',
 4086:                  );
 4087:     return %titles;
 4088: }
 4089: 
 4090: sub courserequest_titles {
 4091:     my %titles = &Apache::lonlocal::texthash (
 4092:                                    official   => 'Official',
 4093:                                    unofficial => 'Unofficial',
 4094:                                    community  => 'Communities',
 4095:                                    textbook   => 'Textbook',
 4096:                                    norequest  => 'Not allowed',
 4097:                                    approval   => 'Approval by Dom. Coord.',
 4098:                                    validate   => 'With validation',
 4099:                                    autolimit  => 'Numerical limit',
 4100:                                    unlimited  => '(blank for unlimited)',
 4101:                  );
 4102:     return %titles;
 4103: }
 4104: 
 4105: sub authorrequest_titles {
 4106:     my %titles = &Apache::lonlocal::texthash (
 4107:                                    norequest  => 'Not allowed',
 4108:                                    approval   => 'Approval by Dom. Coord.',
 4109:                                    automatic  => 'Automatic approval',
 4110:                  );
 4111:     return %titles;
 4112: }
 4113: 
 4114: sub courserequest_conditions {
 4115:     my %conditions = &Apache::lonlocal::texthash (
 4116:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
 4117:        validate   => '(Processing of request subject to institutional validation).',
 4118:                  );
 4119:     return %conditions;
 4120: }
 4121: 
 4122: 
 4123: sub print_usercreation {
 4124:     my ($position,$dom,$settings,$rowtotal) = @_;
 4125:     my $numinrow = 4;
 4126:     my $datatable;
 4127:     if ($position eq 'top') {
 4128:         $$rowtotal ++;
 4129:         my $rowcount = 0;
 4130:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 4131:         if (ref($rules) eq 'HASH') {
 4132:             if (keys(%{$rules}) > 0) {
 4133:                 $datatable .= &user_formats_row('username',$settings,$rules,
 4134:                                                 $ruleorder,$numinrow,$rowcount);
 4135:                 $$rowtotal ++;
 4136:                 $rowcount ++;
 4137:             }
 4138:         }
 4139:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 4140:         if (ref($idrules) eq 'HASH') {
 4141:             if (keys(%{$idrules}) > 0) {
 4142:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 4143:                                                 $idruleorder,$numinrow,$rowcount);
 4144:                 $$rowtotal ++;
 4145:                 $rowcount ++;
 4146:             }
 4147:         }
 4148:         if ($rowcount == 0) {
 4149:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 4150:             $$rowtotal ++;
 4151:             $rowcount ++;
 4152:         }
 4153:     } elsif ($position eq 'middle') {
 4154:         my @creators = ('author','course','requestcrs');
 4155:         my ($rules,$ruleorder) =
 4156:             &Apache::lonnet::inst_userrules($dom,'username');
 4157:         my %lt = &usercreation_types();
 4158:         my %checked;
 4159:         if (ref($settings) eq 'HASH') {
 4160:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 4161:                 foreach my $item (@creators) {
 4162:                     $checked{$item} = $settings->{'cancreate'}{$item};
 4163:                 }
 4164:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 4165:                 foreach my $item (@creators) {
 4166:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 4167:                         $checked{$item} = 'none';
 4168:                     }
 4169:                 }
 4170:             }
 4171:         }
 4172:         my $rownum = 0;
 4173:         foreach my $item (@creators) {
 4174:             $rownum ++;
 4175:             if ($checked{$item} eq '') {
 4176:                 $checked{$item} = 'any';
 4177:             }
 4178:             my $css_class;
 4179:             if ($rownum%2) {
 4180:                 $css_class = '';
 4181:             } else {
 4182:                 $css_class = ' class="LC_odd_row" ';
 4183:             }
 4184:             $datatable .= '<tr'.$css_class.'>'.
 4185:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 4186:                          '</span></td><td align="right">';
 4187:             my @options = ('any');
 4188:             if (ref($rules) eq 'HASH') {
 4189:                 if (keys(%{$rules}) > 0) {
 4190:                     push(@options,('official','unofficial'));
 4191:                 }
 4192:             }
 4193:             push(@options,'none');
 4194:             foreach my $option (@options) {
 4195:                 my $type = 'radio';
 4196:                 my $check = ' ';
 4197:                 if ($checked{$item} eq $option) {
 4198:                     $check = ' checked="checked" ';
 4199:                 } 
 4200:                 $datatable .= '<span class="LC_nobreak"><label>'.
 4201:                               '<input type="'.$type.'" name="can_createuser_'.
 4202:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 4203:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 4204:             }
 4205:             $datatable .= '</td></tr>';
 4206:         }
 4207:     } else {
 4208:         my @contexts = ('author','course','domain');
 4209:         my @authtypes = ('int','krb4','krb5','loc');
 4210:         my %checked;
 4211:         if (ref($settings) eq 'HASH') {
 4212:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 4213:                 foreach my $item (@contexts) {
 4214:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 4215:                         foreach my $auth (@authtypes) {
 4216:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 4217:                                 $checked{$item}{$auth} = ' checked="checked" ';
 4218:                             }
 4219:                         }
 4220:                     }
 4221:                 }
 4222:             }
 4223:         } else {
 4224:             foreach my $item (@contexts) {
 4225:                 foreach my $auth (@authtypes) {
 4226:                     $checked{$item}{$auth} = ' checked="checked" ';
 4227:                 }
 4228:             }
 4229:         }
 4230:         my %title = &context_names();
 4231:         my %authname = &authtype_names();
 4232:         my $rownum = 0;
 4233:         my $css_class; 
 4234:         foreach my $item (@contexts) {
 4235:             if ($rownum%2) {
 4236:                 $css_class = '';
 4237:             } else {
 4238:                 $css_class = ' class="LC_odd_row" ';
 4239:             }
 4240:             $datatable .=   '<tr'.$css_class.'>'.
 4241:                             '<td>'.$title{$item}.
 4242:                             '</td><td class="LC_left_item">'.
 4243:                             '<span class="LC_nobreak">';
 4244:             foreach my $auth (@authtypes) {
 4245:                 $datatable .= '<label>'. 
 4246:                               '<input type="checkbox" name="'.$item.'_auth" '.
 4247:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 4248:                               $authname{$auth}.'</label>&nbsp;';
 4249:             }
 4250:             $datatable .= '</span></td></tr>';
 4251:             $rownum ++;
 4252:         }
 4253:         $$rowtotal += $rownum;
 4254:     }
 4255:     return $datatable;
 4256: }
 4257: 
 4258: sub print_selfcreation {
 4259:     my ($position,$dom,$settings,$rowtotal) = @_;
 4260:     my (@selfcreate,$createsettings,$processing,$datatable);
 4261:     if (ref($settings) eq 'HASH') {
 4262:         if (ref($settings->{'cancreate'}) eq 'HASH') {
 4263:             $createsettings = $settings->{'cancreate'};
 4264:             if (ref($createsettings) eq 'HASH') {
 4265:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
 4266:                     @selfcreate = @{$createsettings->{'selfcreate'}};
 4267:                 } elsif ($createsettings->{'selfcreate'} ne '') {
 4268:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 4269:                         @selfcreate = ('email','login','sso');
 4270:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
 4271:                         @selfcreate = ($createsettings->{'selfcreate'});
 4272:                     }
 4273:                 }
 4274:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
 4275:                     $processing = $createsettings->{'selfcreateprocessing'};
 4276:                 }
 4277:             }
 4278:         }
 4279:     }
 4280:     my %radiohash;
 4281:     my $numinrow = 4;
 4282:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
 4283:     if ($position eq 'top') {
 4284:         my %choices = &Apache::lonlocal::texthash (
 4285:                                                       cancreate_login      => 'Institutional Login',
 4286:                                                       cancreate_sso        => 'Institutional Single Sign On',
 4287:                                                   );
 4288:         my @toggles = sort(keys(%choices));
 4289:         my %defaultchecked = (
 4290:                                'cancreate_login' => 'off',
 4291:                                'cancreate_sso'   => 'off',
 4292:                              );
 4293:         my ($onclick,$itemcount);
 4294:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
 4295:                                                      \%choices,$itemcount,$onclick);
 4296:         $$rowtotal += $itemcount;
 4297:         
 4298:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4299: 
 4300:         if (ref($usertypes) eq 'HASH') {
 4301:             if (keys(%{$usertypes}) > 0) {
 4302:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
 4303:                                              $dom,$numinrow,$othertitle,
 4304:                                              'statustocreate',$$rowtotal);
 4305:                 $$rowtotal ++;
 4306:             }
 4307:         }
 4308:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
 4309:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 4310:         $fieldtitles{'inststatus'} = &mt('Institutional status');
 4311:         my $rem;
 4312:         my $numperrow = 2;
 4313:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
 4314:         $datatable .= '<tr'.$css_class.'>'.
 4315:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
 4316:                      '<td class="LC_left_item">'."\n".
 4317:                      '<table><tr><td>'."\n";
 4318:         for (my $i=0; $i<@fields; $i++) {
 4319:             $rem = $i%($numperrow);
 4320:             if ($rem == 0) {
 4321:                 if ($i > 0) {
 4322:                     $datatable .= '</tr>';
 4323:                 }
 4324:                 $datatable .= '<tr>';
 4325:             }
 4326:             my $currval;
 4327:             if (ref($createsettings) eq 'HASH') {
 4328:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
 4329:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
 4330:                 }
 4331:             }
 4332:             $datatable .= '<td class="LC_left_item">'.
 4333:                           '<span class="LC_nobreak">'.
 4334:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
 4335:                           'value="'.$currval.'" size="10" />&nbsp;'.
 4336:                           $fieldtitles{$fields[$i]}.'</span></td>';
 4337:         }
 4338:         my $colsleft = $numperrow - $rem;
 4339:         if ($colsleft > 1 ) {
 4340:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 4341:                          '&nbsp;</td>';
 4342:         } elsif ($colsleft == 1) {
 4343:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 4344:         }
 4345:         $datatable .= '</tr></table></td></tr>';
 4346:         $$rowtotal ++;
 4347:     } elsif ($position eq 'middle') {
 4348:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
 4349:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4350:         $usertypes->{'default'} = $othertitle;
 4351:         if (ref($types) eq 'ARRAY') {
 4352:             push(@{$types},'default');
 4353:             $usertypes->{'default'} = $othertitle;
 4354:             foreach my $status (@{$types}) {
 4355:                 $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
 4356:                                                        $numinrow,$$rowtotal,$usertypes);
 4357:                 $$rowtotal ++;
 4358:             }
 4359:         }
 4360:     } else {
 4361:         my %choices = &Apache::lonlocal::texthash (
 4362:                                                       cancreate_email => 'E-mail address as username',
 4363:                                                   );
 4364:         my @toggles = sort(keys(%choices));
 4365:         my %defaultchecked = (
 4366:                                'cancreate_email' => 'off',
 4367:                              );
 4368:         my $itemcount = 0;
 4369:         my $display = 'none';
 4370:         if (grep(/^\Qemail\E$/,@selfcreate)) {
 4371:             $display = 'block';
 4372:         }
 4373:         my $onclick = "toggleDisplay(this.form,'emailoptions');";
 4374:         my $additional = '<div id="emailoptions" style="display: '.$display.'">';
 4375:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 4376:         my $usertypes = {};
 4377:         my $order = [];
 4378:         if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
 4379:             $usertypes = $domdefaults{'inststatustypes'};
 4380:             $order = $domdefaults{'inststatusguest'};
 4381:         }
 4382:         if (ref($order) eq 'ARRAY') {
 4383:             push(@{$order},'default');
 4384:             if (@{$order} > 1) {
 4385:                 $usertypes->{'default'} = &mt('Other users');
 4386:                 $additional .= '<table><tr>';
 4387:                 foreach my $status (@{$order}) {
 4388:                     $additional .= '<th>'.$usertypes->{$status}.'</th>';
 4389:                 }
 4390:                 $additional .= '</tr><tr>';
 4391:                 foreach my $status (@{$order}) {
 4392:                     $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
 4393:                 }
 4394:                 $additional .= '</tr></table>';
 4395:             } else {
 4396:                 $usertypes->{'default'} = &mt('All users');
 4397:                 $additional .= &email_as_username($rowtotal,$processing);
 4398:             }
 4399:         }
 4400:         $additional .= '</div>'."\n";
 4401: 
 4402:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
 4403:                                                      \%choices,$$rowtotal,$onclick,$additional);
 4404:         $$rowtotal ++;
 4405:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
 4406:         $$rowtotal ++;
 4407:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
 4408:         $numinrow = 1;
 4409:         if (ref($order) eq 'ARRAY') {
 4410:             foreach my $status (@{$order}) {
 4411:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
 4412:                                                        $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
 4413:                 $$rowtotal ++;
 4414:             }
 4415:         }
 4416:         my ($emailrules,$emailruleorder) =
 4417:             &Apache::lonnet::inst_userrules($dom,'email');
 4418:         if (ref($emailrules) eq 'HASH') {
 4419:             if (keys(%{$emailrules}) > 0) {
 4420:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 4421:                                                 $emailruleorder,$numinrow,$$rowtotal);
 4422:                 $$rowtotal ++;
 4423:             }
 4424:         }
 4425:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
 4426:     }
 4427:     return $datatable;
 4428: }
 4429: 
 4430: sub email_as_username {
 4431:     my ($rowtotal,$processing,$type) = @_;
 4432:     my %choices =
 4433:         &Apache::lonlocal::texthash (
 4434:                                       automatic => 'Automatic approval',
 4435:                                       approval  => 'Queued for approval',
 4436:                                     );
 4437:     my $output;
 4438:     foreach my $option ('automatic','approval') {
 4439:         my $checked;
 4440:         if (ref($processing) eq 'HASH') {
 4441:             if ($type eq '') {   
 4442:                 if (!exists($processing->{'default'})) {
 4443:                     if ($option eq 'automatic') {
 4444:                         $checked = ' checked="checked"';
 4445:                     }
 4446:                 } else {
 4447:                     if ($processing->{'default'} eq $option) {
 4448:                         $checked = ' checked="checked"';
 4449:                     }
 4450:                 }
 4451:             } else {
 4452:                 if (!exists($processing->{$type})) {
 4453:                     if ($option eq 'automatic') {
 4454:                         $checked = ' checked="checked"';
 4455:                     }
 4456:                 } else {
 4457:                     if ($processing->{$type} eq $option) {
 4458:                         $checked = ' checked="checked"';
 4459:                     }
 4460:                 }
 4461:             }
 4462:         } elsif ($option eq 'automatic') {
 4463:             $checked = ' checked="checked"'; 
 4464:         }
 4465:         my $name = 'cancreate_emailprocess';
 4466:         if (($type ne '') && ($type ne 'default')) {
 4467:             $name .= '_'.$type;
 4468:         }
 4469:         $output .= '<span class="LC_nobreak"><label>'.
 4470:                    '<input type="radio" name="'.$name.'"'.
 4471:                    $checked.' value="'.$option.'" />'.
 4472:                    $choices{$option}.'</label></span>';
 4473:         if ($type eq '') {
 4474:             $output .= '&nbsp;';
 4475:         } else {
 4476:             $output .= '<br />';
 4477:         }
 4478:     }
 4479:     $$rowtotal ++;
 4480:     return $output;
 4481: }
 4482: 
 4483: sub captcha_choice {
 4484:     my ($context,$settings,$itemcount) = @_;
 4485:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
 4486:     my %lt = &captcha_phrases();
 4487:     $keyentry = 'hidden';
 4488:     if ($context eq 'cancreate') {
 4489:         $rowname = &mt('CAPTCHA validation');
 4490:     } elsif ($context eq 'login') {
 4491:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
 4492:     }
 4493:     if (ref($settings) eq 'HASH') {
 4494:         if ($settings->{'captcha'}) {
 4495:             $checked{$settings->{'captcha'}} = ' checked="checked"';
 4496:         } else {
 4497:             $checked{'original'} = ' checked="checked"';
 4498:         }
 4499:         if ($settings->{'captcha'} eq 'recaptcha') {
 4500:             $pubtext = $lt{'pub'};
 4501:             $privtext = $lt{'priv'};
 4502:             $keyentry = 'text';
 4503:         }
 4504:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
 4505:             $currpub = $settings->{'recaptchakeys'}{'public'};
 4506:             $currpriv = $settings->{'recaptchakeys'}{'private'};
 4507:         }
 4508:     } else {
 4509:         $checked{'original'} = ' checked="checked"';
 4510:     }
 4511:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4512:     my $output = '<tr'.$css_class.'>'.
 4513:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
 4514:                  '<table><tr><td>'."\n";
 4515:     foreach my $option ('original','recaptcha','notused') {
 4516:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
 4517:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
 4518:                    $lt{$option}.'</label></span>';
 4519:         unless ($option eq 'notused') {
 4520:             $output .= ('&nbsp;'x2)."\n";
 4521:         }
 4522:     }
 4523: #
 4524: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
 4525: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
 4526: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
 4527: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
 4528: #
 4529:     $output .= '</td></tr>'."\n".
 4530:                '<tr><td>'."\n".
 4531:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
 4532:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
 4533:                $currpub.'" size="40" /></span><br />'."\n".
 4534:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
 4535:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
 4536:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
 4537:                '</td></tr>';
 4538:     return $output;
 4539: }
 4540: 
 4541: sub user_formats_row {
 4542:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 4543:     my $output;
 4544:     my %text = (
 4545:                    'username' => 'new usernames',
 4546:                    'id'       => 'IDs',
 4547:                    'email'    => 'self-created accounts (e-mail)',
 4548:                );
 4549:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 4550:     $output = '<tr '.$css_class.'>'.
 4551:               '<td><span class="LC_nobreak">';
 4552:     if ($type eq 'email') {
 4553:         $output .= &mt("Formats disallowed for $text{$type}: ");
 4554:     } else {
 4555:         $output .= &mt("Format rules to check for $text{$type}: ");
 4556:     }
 4557:     $output .= '</span></td>'.
 4558:                '<td class="LC_left_item" colspan="2"><table>';
 4559:     my $rem;
 4560:     if (ref($ruleorder) eq 'ARRAY') {
 4561:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 4562:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 4563:                 my $rem = $i%($numinrow);
 4564:                 if ($rem == 0) {
 4565:                     if ($i > 0) {
 4566:                         $output .= '</tr>';
 4567:                     }
 4568:                     $output .= '<tr>';
 4569:                 }
 4570:                 my $check = ' ';
 4571:                 if (ref($settings) eq 'HASH') {
 4572:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 4573:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 4574:                             $check = ' checked="checked" ';
 4575:                         }
 4576:                     }
 4577:                 }
 4578:                 $output .= '<td class="LC_left_item">'.
 4579:                            '<span class="LC_nobreak"><label>'.
 4580:                            '<input type="checkbox" name="'.$type.'_rule" '.
 4581:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 4582:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 4583:             }
 4584:         }
 4585:         $rem = @{$ruleorder}%($numinrow);
 4586:     }
 4587:     my $colsleft = $numinrow - $rem;
 4588:     if ($colsleft > 1 ) {
 4589:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 4590:                    '&nbsp;</td>';
 4591:     } elsif ($colsleft == 1) {
 4592:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 4593:     }
 4594:     $output .= '</tr></table></td></tr>';
 4595:     return $output;
 4596: }
 4597: 
 4598: sub usercreation_types {
 4599:     my %lt = &Apache::lonlocal::texthash (
 4600:                     author     => 'When adding a co-author',
 4601:                     course     => 'When adding a user to a course',
 4602:                     requestcrs => 'When requesting a course',
 4603:                     any        => 'Any',
 4604:                     official   => 'Institutional only ',
 4605:                     unofficial => 'Non-institutional only',
 4606:                     none       => 'None',
 4607:     );
 4608:     return %lt;
 4609: }
 4610: 
 4611: sub selfcreation_types {
 4612:     my %lt = &Apache::lonlocal::texthash (
 4613:                     selfcreate => 'User creates own account',
 4614:                     any        => 'Any',
 4615:                     official   => 'Institutional only ',
 4616:                     unofficial => 'Non-institutional only',
 4617:                     email      => 'E-mail address',
 4618:                     login      => 'Institutional Login',
 4619:                     sso        => 'SSO',
 4620:              );
 4621: }
 4622: 
 4623: sub authtype_names {
 4624:     my %lt = &Apache::lonlocal::texthash(
 4625:                       int    => 'Internal',
 4626:                       krb4   => 'Kerberos 4',
 4627:                       krb5   => 'Kerberos 5',
 4628:                       loc    => 'Local',
 4629:                   );
 4630:     return %lt;
 4631: }
 4632: 
 4633: sub context_names {
 4634:     my %context_title = &Apache::lonlocal::texthash(
 4635:        author => 'Creating users when an Author',
 4636:        course => 'Creating users when in a course',
 4637:        domain => 'Creating users when a Domain Coordinator',
 4638:     );
 4639:     return %context_title;
 4640: }
 4641: 
 4642: sub print_usermodification {
 4643:     my ($position,$dom,$settings,$rowtotal) = @_;
 4644:     my $numinrow = 4;
 4645:     my ($context,$datatable,$rowcount);
 4646:     if ($position eq 'top') {
 4647:         $rowcount = 0;
 4648:         $context = 'author'; 
 4649:         foreach my $role ('ca','aa') {
 4650:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 4651:                                                    $numinrow,$rowcount);
 4652:             $$rowtotal ++;
 4653:             $rowcount ++;
 4654:         }
 4655:     } elsif ($position eq 'bottom') {
 4656:         $context = 'course';
 4657:         $rowcount = 0;
 4658:         foreach my $role ('st','ep','ta','in','cr') {
 4659:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 4660:                                                    $numinrow,$rowcount);
 4661:             $$rowtotal ++;
 4662:             $rowcount ++;
 4663:         }
 4664:     }
 4665:     return $datatable;
 4666: }
 4667: 
 4668: sub print_defaults {
 4669:     my ($position,$dom,$settings,$rowtotal) = @_;
 4670:     my $rownum = 0;
 4671:     my ($datatable,$css_class);
 4672:     if ($position eq 'top') {
 4673:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 4674:                      'datelocale_def','portal_def');
 4675:         my %defaults;
 4676:         if (ref($settings) eq 'HASH') {
 4677:             %defaults = %{$settings};
 4678:         } else {
 4679:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
 4680:             foreach my $item (@items) {
 4681:                 $defaults{$item} = $domdefaults{$item};
 4682:             }
 4683:         }
 4684:         my $titles = &defaults_titles($dom);
 4685:         foreach my $item (@items) {
 4686:             if ($rownum%2) {
 4687:                 $css_class = '';
 4688:             } else {
 4689:                 $css_class = ' class="LC_odd_row" ';
 4690:             }
 4691:             $datatable .= '<tr'.$css_class.'>'.
 4692:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
 4693:                           '</span></td><td class="LC_right_item" colspan="3">';
 4694:             if ($item eq 'auth_def') {
 4695:                 my @authtypes = ('internal','krb4','krb5','localauth');
 4696:                 my %shortauth = (
 4697:                                  internal => 'int',
 4698:                                  krb4 => 'krb4',
 4699:                                  krb5 => 'krb5',
 4700:                                  localauth  => 'loc'
 4701:                                 );
 4702:                 my %authnames = &authtype_names();
 4703:                 foreach my $auth (@authtypes) {
 4704:                     my $checked = ' ';
 4705:                     if ($defaults{$item} eq $auth) {
 4706:                         $checked = ' checked="checked" ';
 4707:                     }
 4708:                     $datatable .= '<label><input type="radio" name="'.$item.
 4709:                                   '" value="'.$auth.'"'.$checked.'/>'.
 4710:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 4711:                 }
 4712:             } elsif ($item eq 'timezone_def') {
 4713:                 my $includeempty = 1;
 4714:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
 4715:             } elsif ($item eq 'datelocale_def') {
 4716:                 my $includeempty = 1;
 4717:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
 4718:             } elsif ($item eq 'lang_def') {
 4719:                 my %langchoices = &get_languages_hash();
 4720:                 $langchoices{''} = 'No language preference';
 4721:                 %langchoices = &Apache::lonlocal::texthash(%langchoices);
 4722:                 $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
 4723:                                                               \%langchoices);
 4724:             } else {
 4725:                 my $size;
 4726:                 if ($item eq 'portal_def') {
 4727:                     $size = ' size="25"';
 4728:                 }
 4729:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
 4730:                               $defaults{$item}.'"'.$size.' />';
 4731:             }
 4732:             $datatable .= '</td></tr>';
 4733:             $rownum ++;
 4734:         }
 4735:     } else {
 4736:         my (%defaults);
 4737:         if (ref($settings) eq 'HASH') {
 4738:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
 4739:                 (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
 4740:                 my $maxnum = @{$settings->{'inststatusorder'}};
 4741:                 for (my $i=0; $i<$maxnum; $i++) {
 4742:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
 4743:                     my $item = $settings->{'inststatusorder'}->[$i];
 4744:                     my $title = $settings->{'inststatustypes'}->{$item};
 4745:                     my $guestok;
 4746:                     if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
 4747:                         $guestok = 1;
 4748:                     }
 4749:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
 4750:                     $datatable .= '<tr'.$css_class.'>'.
 4751:                                   '<td><span class="LC_nobreak">'.
 4752:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
 4753:                     for (my $k=0; $k<=$maxnum; $k++) {
 4754:                         my $vpos = $k+1;
 4755:                         my $selstr;
 4756:                         if ($k == $i) {
 4757:                             $selstr = ' selected="selected" ';
 4758:                         }
 4759:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4760:                     }
 4761:                     my ($checkedon,$checkedoff);
 4762:                     $checkedoff = ' checked="checked"';
 4763:                     if ($guestok) {
 4764:                         $checkedon = $checkedoff;
 4765:                         $checkedoff = ''; 
 4766:                     }
 4767:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
 4768:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
 4769:                                   &mt('delete').'</span></td>'.
 4770:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
 4771:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
 4772:                                   '</span></td>'.
 4773:                                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 4774:                                   '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
 4775:                                   &mt('Yes').'</label>'.('&nbsp;'x2).
 4776:                                   '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
 4777:                                   &mt('No').'</label></span></td></tr>';
 4778:                 }
 4779:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
 4780:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
 4781:                 $datatable .= '<tr '.$css_class.'>'.
 4782:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
 4783:                 for (my $k=0; $k<=$maxnum; $k++) {
 4784:                     my $vpos = $k+1;
 4785:                     my $selstr;
 4786:                     if ($k == $maxnum) {
 4787:                         $selstr = ' selected="selected" ';
 4788:                     }
 4789:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4790:                 }
 4791:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
 4792:                               '<input type="text" size="10" name="addinststatus" value="" /></span>'.
 4793:                               '&nbsp;'.&mt('(new)').
 4794:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
 4795:                               &mt('Name displayed:').
 4796:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
 4797:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
 4798:                               '<label><input type="radio" value="1" name="addinststatus_guest" />'.
 4799:                               &mt('Yes').'</label>'.('&nbsp;'x2).
 4800:                               '<label><input type="radio" value="0" name="addinststatus_guest" />'.
 4801:                               &mt('No').'</label></span></td></tr>';
 4802:                               '</tr>'."\n";
 4803:                 $rownum ++;
 4804:             }
 4805:         }
 4806:     }
 4807:     $$rowtotal += $rownum;
 4808:     return $datatable;
 4809: }
 4810: 
 4811: sub get_languages_hash {
 4812:     my %langchoices;
 4813:     foreach my $id (&Apache::loncommon::languageids()) {
 4814:         my $code = &Apache::loncommon::supportedlanguagecode($id);
 4815:         if ($code ne '') {
 4816:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
 4817:         }
 4818:     }
 4819:     return %langchoices;
 4820: }
 4821: 
 4822: sub defaults_titles {
 4823:     my ($dom) = @_;
 4824:     my %titles = &Apache::lonlocal::texthash (
 4825:                    'auth_def'      => 'Default authentication type',
 4826:                    'auth_arg_def'  => 'Default authentication argument',
 4827:                    'lang_def'      => 'Default language',
 4828:                    'timezone_def'  => 'Default timezone',
 4829:                    'datelocale_def' => 'Default locale for dates',
 4830:                    'portal_def'     => 'Portal/Default URL',
 4831:                  );
 4832:     if ($dom) {
 4833:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
 4834:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
 4835:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
 4836:         $protocol = 'http' if ($protocol ne 'https');
 4837:         if ($uint_dom) {
 4838:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
 4839:                                          $uint_dom);
 4840:         }
 4841:     }
 4842:     return (\%titles);
 4843: }
 4844: 
 4845: sub print_scantronformat {
 4846:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 4847:     my $itemcount = 1;
 4848:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 4849:         %confhash);
 4850:     my $switchserver = &check_switchserver($dom,$confname);
 4851:     my %lt = &Apache::lonlocal::texthash (
 4852:                 default => 'Default bubblesheet format file error',
 4853:                 custom  => 'Custom bubblesheet format file error',
 4854:              );
 4855:     my %scantronfiles = (
 4856:         default => 'default.tab',
 4857:         custom => 'custom.tab',
 4858:     );
 4859:     foreach my $key (keys(%scantronfiles)) {
 4860:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 4861:                               .$scantronfiles{$key};
 4862:     }
 4863:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 4864:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 4865:         if (!$switchserver) {
 4866:             my $servadm = $r->dir_config('lonAdmEMail');
 4867:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 4868:             if ($configuserok eq 'ok') {
 4869:                 if ($author_ok eq 'ok') {
 4870:                     my %legacyfile = (
 4871:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 4872:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 4873:                     );
 4874:                     my %md5chk;
 4875:                     foreach my $type (keys(%legacyfile)) {
 4876:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 4877:                         chomp($md5chk{$type});
 4878:                     }
 4879:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 4880:                         foreach my $type (keys(%legacyfile)) {
 4881:                             ($scantronurls{$type},my $error) = 
 4882:                                 &legacy_scantronformat($r,$dom,$confname,
 4883:                                                  $type,$legacyfile{$type},
 4884:                                                  $scantronurls{$type},
 4885:                                                  $scantronfiles{$type});
 4886:                             if ($error ne '') {
 4887:                                 $error{$type} = $error;
 4888:                             }
 4889:                         }
 4890:                         if (keys(%error) == 0) {
 4891:                             $is_custom = 1;
 4892:                             $confhash{'scantron'}{'scantronformat'} = 
 4893:                                 $scantronurls{'custom'};
 4894:                             my $putresult = 
 4895:                                 &Apache::lonnet::put_dom('configuration',
 4896:                                                          \%confhash,$dom);
 4897:                             if ($putresult ne 'ok') {
 4898:                                 $error{'custom'} = 
 4899:                                     '<span class="LC_error">'.
 4900:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 4901:                             }
 4902:                         }
 4903:                     } else {
 4904:                         ($scantronurls{'default'},my $error) =
 4905:                             &legacy_scantronformat($r,$dom,$confname,
 4906:                                           'default',$legacyfile{'default'},
 4907:                                           $scantronurls{'default'},
 4908:                                           $scantronfiles{'default'});
 4909:                         if ($error eq '') {
 4910:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 4911:                             my $putresult =
 4912:                                 &Apache::lonnet::put_dom('configuration',
 4913:                                                          \%confhash,$dom);
 4914:                             if ($putresult ne 'ok') {
 4915:                                 $error{'default'} =
 4916:                                     '<span class="LC_error">'.
 4917:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 4918:                             }
 4919:                         } else {
 4920:                             $error{'default'} = $error;
 4921:                         }
 4922:                     }
 4923:                 }
 4924:             }
 4925:         } else {
 4926:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
 4927:         }
 4928:     }
 4929:     if (ref($settings) eq 'HASH') {
 4930:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 4931:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 4932:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 4933:                 $scantronurl = '';
 4934:             } else {
 4935:                 $scantronurl = $settings->{'scantronformat'};
 4936:             }
 4937:             $is_custom = 1;
 4938:         } else {
 4939:             $scantronurl = $scantronurls{'default'};
 4940:         }
 4941:     } else {
 4942:         if ($is_custom) {
 4943:             $scantronurl = $scantronurls{'custom'};
 4944:         } else {
 4945:             $scantronurl = $scantronurls{'default'};
 4946:         }
 4947:     }
 4948:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4949:     $datatable .= '<tr'.$css_class.'>';
 4950:     if (!$is_custom) {
 4951:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 4952:                       '<span class="LC_nobreak">';
 4953:         if ($scantronurl) {
 4954:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
 4955:                                                          undef,undef,undef,undef,'background-color:#ffffff');
 4956:         } else {
 4957:             $datatable = &mt('File unavailable for display');
 4958:         }
 4959:         $datatable .= '</span></td>';
 4960:         if (keys(%error) == 0) { 
 4961:             $datatable .= '<td valign="bottom">';
 4962:             if (!$switchserver) {
 4963:                 $datatable .= &mt('Upload:').'<br />';
 4964:             }
 4965:         } else {
 4966:             my $errorstr;
 4967:             foreach my $key (sort(keys(%error))) {
 4968:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 4969:             }
 4970:             $datatable .= '<td>'.$errorstr;
 4971:         }
 4972:     } else {
 4973:         if (keys(%error) > 0) {
 4974:             my $errorstr;
 4975:             foreach my $key (sort(keys(%error))) {
 4976:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 4977:             } 
 4978:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 4979:         } elsif ($scantronurl) {
 4980:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
 4981:                                                        undef,undef,undef,undef,'background-color:#ffffff');
 4982:             $datatable .= '<td><span class="LC_nobreak">'.
 4983:                           $link.
 4984:                           '<label><input type="checkbox" name="scantronformat_del"'.
 4985:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
 4986:                           '<td><span class="LC_nobreak">&nbsp;'.
 4987:                           &mt('Replace:').'</span><br />';
 4988:         }
 4989:     }
 4990:     if (keys(%error) == 0) {
 4991:         if ($switchserver) {
 4992:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 4993:         } else {
 4994:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 4995:                          '<input type="file" name="scantronformat" /></span>';
 4996:         }
 4997:     }
 4998:     $datatable .= '</td></tr>';
 4999:     $$rowtotal ++;
 5000:     return $datatable;
 5001: }
 5002: 
 5003: sub legacy_scantronformat {
 5004:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 5005:     my ($url,$error);
 5006:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 5007:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 5008:         (my $result,$url) =
 5009:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 5010:                          '','',$newfile);
 5011:         if ($result ne 'ok') {
 5012:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
 5013:         }
 5014:     }
 5015:     return ($url,$error);
 5016: }
 5017: 
 5018: sub print_coursecategories {
 5019:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 5020:     my $datatable;
 5021:     if ($position eq 'top') {
 5022:         my (%checked);
 5023:         my @catitems = ('unauth','auth');
 5024:         my @cattypes = ('std','domonly','codesrch','none');
 5025:         $checked{'unauth'} = 'std';
 5026:         $checked{'auth'} = 'std';
 5027:         if (ref($settings) eq 'HASH') {
 5028:             foreach my $type (@cattypes) {
 5029:                 if ($type eq $settings->{'unauth'}) {
 5030:                     $checked{'unauth'} = $type;
 5031:                 }
 5032:                 if ($type eq $settings->{'auth'}) {
 5033:                     $checked{'auth'} = $type;
 5034:                 }
 5035:             }
 5036:         }
 5037:         my %lt = &Apache::lonlocal::texthash (
 5038:                                                unauth   => 'Catalog type for unauthenticated users',
 5039:                                                auth     => 'Catalog type for authenticated users',
 5040:                                                none     => 'No catalog',
 5041:                                                std      => 'Standard catalog',
 5042:                                                domonly  => 'Domain-only catalog',
 5043:                                                codesrch => "Code search form",
 5044:                                              );
 5045:        my $itemcount = 0;
 5046:        foreach my $item (@catitems) {
 5047:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
 5048:            $datatable .= '<tr '.$css_class.'>'.
 5049:                          '<td>'.$lt{$item}.'</td>'.
 5050:                          '<td class="LC_right_item"><span class="LC_nobreak">';
 5051:            foreach my $type (@cattypes) {
 5052:                my $ischecked;
 5053:                if ($checked{$item} eq $type) {
 5054:                    $ischecked=' checked="checked"';
 5055:                }
 5056:                $datatable .= '<label>'.
 5057:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
 5058:                              ' />'.$lt{$type}.'</label>&nbsp;';
 5059:            }
 5060:            $datatable .= '</td></tr>';
 5061:            $itemcount ++;
 5062:         }
 5063:         $$rowtotal += $itemcount;
 5064:     } elsif ($position eq 'middle') {
 5065:         my $toggle_cats_crs = ' ';
 5066:         my $toggle_cats_dom = ' checked="checked" ';
 5067:         my $can_cat_crs = ' ';
 5068:         my $can_cat_dom = ' checked="checked" ';
 5069:         my $toggle_catscomm_comm = ' ';
 5070:         my $toggle_catscomm_dom = ' checked="checked" ';
 5071:         my $can_catcomm_comm = ' ';
 5072:         my $can_catcomm_dom = ' checked="checked" ';
 5073: 
 5074:         if (ref($settings) eq 'HASH') {
 5075:             if ($settings->{'togglecats'} eq 'crs') {
 5076:                 $toggle_cats_crs = $toggle_cats_dom;
 5077:                 $toggle_cats_dom = ' ';
 5078:             }
 5079:             if ($settings->{'categorize'} eq 'crs') {
 5080:                 $can_cat_crs = $can_cat_dom;
 5081:                 $can_cat_dom = ' ';
 5082:             }
 5083:             if ($settings->{'togglecatscomm'} eq 'comm') {
 5084:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
 5085:                 $toggle_catscomm_dom = ' ';
 5086:             }
 5087:             if ($settings->{'categorizecomm'} eq 'comm') {
 5088:                 $can_catcomm_comm = $can_catcomm_dom;
 5089:                 $can_catcomm_dom = ' ';
 5090:             }
 5091:         }
 5092:         my %title = &Apache::lonlocal::texthash (
 5093:                      togglecats     => 'Show/Hide a course in catalog',
 5094:                      togglecatscomm => 'Show/Hide a community in catalog',
 5095:                      categorize     => 'Assign a category to a course',
 5096:                      categorizecomm => 'Assign a category to a community',
 5097:                     );
 5098:         my %level = &Apache::lonlocal::texthash (
 5099:                      dom  => 'Set in Domain',
 5100:                      crs  => 'Set in Course',
 5101:                      comm => 'Set in Community',
 5102:                     );
 5103:         $datatable = '<tr class="LC_odd_row">'.
 5104:                   '<td>'.$title{'togglecats'}.'</td>'.
 5105:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 5106:                   '<input type="radio" name="togglecats"'.
 5107:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 5108:                   '<label><input type="radio" name="togglecats"'.
 5109:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 5110:                   '</tr><tr>'.
 5111:                   '<td>'.$title{'categorize'}.'</td>'.
 5112:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 5113:                   '<label><input type="radio" name="categorize"'.
 5114:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 5115:                   '<label><input type="radio" name="categorize"'.
 5116:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 5117:                   '</tr><tr class="LC_odd_row">'.
 5118:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
 5119:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 5120:                   '<input type="radio" name="togglecatscomm"'.
 5121:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 5122:                   '<label><input type="radio" name="togglecatscomm"'.
 5123:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
 5124:                   '</tr><tr>'.
 5125:                   '<td>'.$title{'categorizecomm'}.'</td>'.
 5126:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 5127:                   '<label><input type="radio" name="categorizecomm"'.
 5128:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 5129:                   '<label><input type="radio" name="categorizecomm"'.
 5130:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
 5131:                   '</tr>';
 5132:         $$rowtotal += 4;
 5133:     } else {
 5134:         my $css_class;
 5135:         my $itemcount = 1;
 5136:         my $cathash; 
 5137:         if (ref($settings) eq 'HASH') {
 5138:             $cathash = $settings->{'cats'};
 5139:         }
 5140:         if (ref($cathash) eq 'HASH') {
 5141:             my (@cats,@trails,%allitems,%idx,@jsarray);
 5142:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 5143:                                                    \%allitems,\%idx,\@jsarray);
 5144:             my $maxdepth = scalar(@cats);
 5145:             my $colattrib = '';
 5146:             if ($maxdepth > 2) {
 5147:                 $colattrib = ' colspan="2" ';
 5148:             }
 5149:             my @path;
 5150:             if (@cats > 0) {
 5151:                 if (ref($cats[0]) eq 'ARRAY') {
 5152:                     my $numtop = @{$cats[0]};
 5153:                     my $maxnum = $numtop;
 5154:                     my %default_names = (
 5155:                           instcode    => &mt('Official courses'),
 5156:                           communities => &mt('Communities'),
 5157:                     );
 5158: 
 5159:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
 5160:                         ($cathash->{'instcode::0'} eq '') ||
 5161:                         (!grep(/^communities$/,@{$cats[0]})) || 
 5162:                         ($cathash->{'communities::0'} eq '')) {
 5163:                         $maxnum ++;
 5164:                     }
 5165:                     my $lastidx;
 5166:                     for (my $i=0; $i<$numtop; $i++) {
 5167:                         my $parent = $cats[0][$i];
 5168:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5169:                         my $item = &escape($parent).'::0';
 5170:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 5171:                         $lastidx = $idx{$item};
 5172:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 5173:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 5174:                         for (my $k=0; $k<=$maxnum; $k++) {
 5175:                             my $vpos = $k+1;
 5176:                             my $selstr;
 5177:                             if ($k == $i) {
 5178:                                 $selstr = ' selected="selected" ';
 5179:                             }
 5180:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 5181:                         }
 5182:                         $datatable .= '</select></span></td><td>';
 5183:                         if ($parent eq 'instcode' || $parent eq 'communities') {
 5184:                             $datatable .=  '<span class="LC_nobreak">'
 5185:                                            .$default_names{$parent}.'</span>';
 5186:                             if ($parent eq 'instcode') {
 5187:                                 $datatable .= '<br /><span class="LC_nobreak">('
 5188:                                               .&mt('with institutional codes')
 5189:                                               .')</span></td><td'.$colattrib.'>';
 5190:                             } else {
 5191:                                 $datatable .= '<table><tr><td>';
 5192:                             }
 5193:                             $datatable .= '<span class="LC_nobreak">'
 5194:                                           .'<label><input type="radio" name="'
 5195:                                           .$parent.'" value="1" checked="checked" />'
 5196:                                           .&mt('Display').'</label>';
 5197:                             if ($parent eq 'instcode') {
 5198:                                 $datatable .= '&nbsp;';
 5199:                             } else {
 5200:                                 $datatable .= '</span></td></tr><tr><td>'
 5201:                                               .'<span class="LC_nobreak">';
 5202:                             }
 5203:                             $datatable .= '<label><input type="radio" name="'
 5204:                                           .$parent.'" value="0" />'
 5205:                                           .&mt('Do not display').'</label></span>';
 5206:                             if ($parent eq 'communities') {
 5207:                                 $datatable .= '</td></tr></table>';
 5208:                             }
 5209:                             $datatable .= '</td>';
 5210:                         } else {
 5211:                             $datatable .= $parent
 5212:                                           .'&nbsp;<span class="LC_nobreak"><label>'
 5213:                                           .'<input type="checkbox" name="deletecategory" '
 5214:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 5215:                         }
 5216:                         my $depth = 1;
 5217:                         push(@path,$parent);
 5218:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 5219:                         pop(@path);
 5220:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 5221:                         $itemcount ++;
 5222:                     }
 5223:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5224:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 5225:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 5226:                     for (my $k=0; $k<=$maxnum; $k++) {
 5227:                         my $vpos = $k+1;
 5228:                         my $selstr;
 5229:                         if ($k == $numtop) {
 5230:                             $selstr = ' selected="selected" ';
 5231:                         }
 5232:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 5233:                     }
 5234:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 5235:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 5236:                                   .'</tr>'."\n";
 5237:                     $itemcount ++;
 5238:                     foreach my $default ('instcode','communities') {
 5239:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
 5240:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5241:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
 5242:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 5243:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
 5244:                             for (my $k=0; $k<=$maxnum; $k++) {
 5245:                                 my $vpos = $k+1;
 5246:                                 my $selstr;
 5247:                                 if ($k == $maxnum) {
 5248:                                     $selstr = ' selected="selected" ';
 5249:                                 }
 5250:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 5251:                             }
 5252:                             $datatable .= '</select></span></td>'.
 5253:                                           '<td><span class="LC_nobreak">'.
 5254:                                           $default_names{$default}.'</span>';
 5255:                             if ($default eq 'instcode') {
 5256:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
 5257:                                               .&mt('with institutional codes').')</span>';
 5258:                             }
 5259:                             $datatable .= '</td>'
 5260:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
 5261:                                           .&mt('Display').'</label>&nbsp;'
 5262:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
 5263:                                           .&mt('Do not display').'</label></span></td></tr>';
 5264:                         }
 5265:                     }
 5266:                 }
 5267:             } else {
 5268:                 $datatable .= &initialize_categories($itemcount);
 5269:             }
 5270:         } else {
 5271:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
 5272:                           .&initialize_categories($itemcount);
 5273:         }
 5274:         $$rowtotal += $itemcount;
 5275:     }
 5276:     return $datatable;
 5277: }
 5278: 
 5279: sub print_serverstatuses {
 5280:     my ($dom,$settings,$rowtotal) = @_;
 5281:     my $datatable;
 5282:     my @pages = &serverstatus_pages();
 5283:     my (%namedaccess,%machineaccess);
 5284:     foreach my $type (@pages) {
 5285:         $namedaccess{$type} = '';
 5286:         $machineaccess{$type}= '';
 5287:     }
 5288:     if (ref($settings) eq 'HASH') {
 5289:         foreach my $type (@pages) {
 5290:             if (exists($settings->{$type})) {
 5291:                 if (ref($settings->{$type}) eq 'HASH') {
 5292:                     foreach my $key (keys(%{$settings->{$type}})) {
 5293:                         if ($key eq 'namedusers') {
 5294:                             $namedaccess{$type} = $settings->{$type}->{$key};
 5295:                         } elsif ($key eq 'machines') {
 5296:                             $machineaccess{$type} = $settings->{$type}->{$key};
 5297:                         }
 5298:                     }
 5299:                 }
 5300:             }
 5301:         }
 5302:     }
 5303:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 5304:     my $rownum = 0;
 5305:     my $css_class;
 5306:     foreach my $type (@pages) {
 5307:         $rownum ++;
 5308:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 5309:         $datatable .= '<tr'.$css_class.'>'.
 5310:                       '<td><span class="LC_nobreak">'.
 5311:                       $titles->{$type}.'</span></td>'.
 5312:                       '<td class="LC_left_item">'.
 5313:                       '<input type="text" name="'.$type.'_namedusers" '.
 5314:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 5315:                       '<td class="LC_right_item">'.
 5316:                       '<span class="LC_nobreak">'.
 5317:                       '<input type="text" name="'.$type.'_machines" '.
 5318:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 5319:                       '</td></tr>'."\n";
 5320:     }
 5321:     $$rowtotal += $rownum;
 5322:     return $datatable;
 5323: }
 5324: 
 5325: sub serverstatus_pages {
 5326:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 5327:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
 5328:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
 5329:             'uniquecodes','diskusage');
 5330: }
 5331: 
 5332: sub defaults_javascript {
 5333:     my ($settings) = @_;
 5334:     return unless (ref($settings) eq 'HASH'); 
 5335:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
 5336:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
 5337:         if ($maxnum eq '') {
 5338:             $maxnum = 0;
 5339:         }
 5340:         $maxnum ++;
 5341:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
 5342:         return <<"ENDSCRIPT";
 5343: <script type="text/javascript">
 5344: // <![CDATA[
 5345: function reorderTypes(form,caller) {
 5346:     var changedVal;
 5347: $jstext 
 5348:     var newpos = 'addinststatus_pos';
 5349:     var current = new Array;
 5350:     var maxh = $maxnum;
 5351:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 5352:     var oldVal;
 5353:     if (caller == newpos) {
 5354:         changedVal = newitemVal;
 5355:     } else {
 5356:         var curritem = 'inststatus_pos_'+caller;
 5357:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
 5358:         current[newitemVal] = newpos;
 5359:     }
 5360:     for (var i=0; i<inststatuses.length; i++) {
 5361:         if (inststatuses[i] != caller) {
 5362:             var elementName = 'inststatus_pos_'+inststatuses[i];
 5363:             if (form.elements[elementName]) {
 5364:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 5365:                 current[currVal] = elementName;
 5366:             }
 5367:         }
 5368:     }
 5369:     for (var j=0; j<maxh; j++) {
 5370:         if (current[j] == undefined) {
 5371:             oldVal = j;
 5372:         }
 5373:     }
 5374:     if (oldVal < changedVal) {
 5375:         for (var k=oldVal+1; k<=changedVal ; k++) {
 5376:            var elementName = current[k];
 5377:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 5378:         }
 5379:     } else {
 5380:         for (var k=changedVal; k<oldVal; k++) {
 5381:             var elementName = current[k];
 5382:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 5383:         }
 5384:     }
 5385:     return;
 5386: }
 5387: 
 5388: // ]]>
 5389: </script>
 5390: 
 5391: ENDSCRIPT
 5392:     }
 5393: }
 5394: 
 5395: sub coursecategories_javascript {
 5396:     my ($settings) = @_;
 5397:     my ($output,$jstext,$cathash);
 5398:     if (ref($settings) eq 'HASH') {
 5399:         $cathash = $settings->{'cats'};
 5400:     }
 5401:     if (ref($cathash) eq 'HASH') {
 5402:         my (@cats,@jsarray,%idx);
 5403:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 5404:         if (@jsarray > 0) {
 5405:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 5406:             for (my $i=0; $i<@jsarray; $i++) {
 5407:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 5408:                     my $catstr = join('","',@{$jsarray[$i]});
 5409:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 5410:                 }
 5411:             }
 5412:         }
 5413:     } else {
 5414:         $jstext  = '    var categories = Array(1);'."\n".
 5415:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 5416:     }
 5417:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
 5418:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
 5419:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.'); 
 5420:     $output = <<"ENDSCRIPT";
 5421: <script type="text/javascript">
 5422: // <![CDATA[
 5423: function reorderCats(form,parent,item,idx) {
 5424:     var changedVal;
 5425: $jstext
 5426:     var newpos = 'addcategory_pos';
 5427:     if (parent == '') {
 5428:         var has_instcode = 0;
 5429:         var maxtop = categories[idx].length;
 5430:         for (var j=0; j<maxtop; j++) {
 5431:             if (categories[idx][j] == 'instcode::0') {
 5432:                 has_instcode == 1;
 5433:             }
 5434:         }
 5435:         if (has_instcode == 0) {
 5436:             categories[idx][maxtop] = 'instcode_pos';
 5437:         }
 5438:     } else {
 5439:         newpos += '_'+parent;
 5440:     }
 5441:     var maxh = 1 + categories[idx].length;
 5442:     var current = new Array;
 5443:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 5444:     if (item == newpos) {
 5445:         changedVal = newitemVal;
 5446:     } else {
 5447:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 5448:         current[newitemVal] = newpos;
 5449:     }
 5450:     for (var i=0; i<categories[idx].length; i++) {
 5451:         var elementName = categories[idx][i];
 5452:         if (elementName != item) {
 5453:             if (form.elements[elementName]) {
 5454:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 5455:                 current[currVal] = elementName;
 5456:             }
 5457:         }
 5458:     }
 5459:     var oldVal;
 5460:     for (var j=0; j<maxh; j++) {
 5461:         if (current[j] == undefined) {
 5462:             oldVal = j;
 5463:         }
 5464:     }
 5465:     if (oldVal < changedVal) {
 5466:         for (var k=oldVal+1; k<=changedVal ; k++) {
 5467:            var elementName = current[k];
 5468:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 5469:         }
 5470:     } else {
 5471:         for (var k=changedVal; k<oldVal; k++) {
 5472:             var elementName = current[k];
 5473:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 5474:         }
 5475:     }
 5476:     return;
 5477: }
 5478: 
 5479: function categoryCheck(form) {
 5480:     if (form.elements['addcategory_name'].value == 'instcode') {
 5481:         alert('$instcode_reserved\\n$choose_again');
 5482:         return false;
 5483:     }
 5484:     if (form.elements['addcategory_name'].value == 'communities') {
 5485:         alert('$communities_reserved\\n$choose_again');
 5486:         return false;
 5487:     }
 5488:     return true;
 5489: }
 5490: 
 5491: // ]]>
 5492: </script>
 5493: 
 5494: ENDSCRIPT
 5495:     return $output;
 5496: }
 5497: 
 5498: sub initialize_categories {
 5499:     my ($itemcount) = @_;
 5500:     my ($datatable,$css_class,$chgstr);
 5501:     my %default_names = (
 5502:                       instcode    => 'Official courses (with institutional codes)',
 5503:                       communities => 'Communities',
 5504:                         );
 5505:     my $select0 = ' selected="selected"';
 5506:     my $select1 = '';
 5507:     foreach my $default ('instcode','communities') {
 5508:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5509:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
 5510:         if ($default eq 'communities') {
 5511:             $select1 = $select0;
 5512:             $select0 = '';
 5513:         }
 5514:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 5515:                      .'<select name="'.$default.'_pos">'
 5516:                      .'<option value="0"'.$select0.'>1</option>'
 5517:                      .'<option value="1"'.$select1.'>2</option>'
 5518:                      .'<option value="2">3</option></select>&nbsp;'
 5519:                      .$default_names{$default}
 5520:                      .'</span></td><td><span class="LC_nobreak">'
 5521:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
 5522:                      .&mt('Display').'</label>&nbsp;<label>'
 5523:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
 5524:                  .'</label></span></td></tr>';
 5525:         $itemcount ++;
 5526:     }
 5527:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5528:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 5529:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 5530:                   .'<select name="addcategory_pos"'.$chgstr.'>'
 5531:                   .'<option value="0">1</option>'
 5532:                   .'<option value="1">2</option>'
 5533:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
 5534:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 5535:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 5536:     return $datatable;
 5537: }
 5538: 
 5539: sub build_category_rows {
 5540:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 5541:     my ($text,$name,$item,$chgstr);
 5542:     if (ref($cats) eq 'ARRAY') {
 5543:         my $maxdepth = scalar(@{$cats});
 5544:         if (ref($cats->[$depth]) eq 'HASH') {
 5545:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 5546:                 my $numchildren = @{$cats->[$depth]{$parent}};
 5547:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 5548:                 $text .= '<td><table class="LC_data_table">';
 5549:                 my ($idxnum,$parent_name,$parent_item);
 5550:                 my $higher = $depth - 1;
 5551:                 if ($higher == 0) {
 5552:                     $parent_name = &escape($parent).'::'.$higher;
 5553:                 } else {
 5554:                     if (ref($path) eq 'ARRAY') {
 5555:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 5556:                     }
 5557:                 }
 5558:                 $parent_item = 'addcategory_pos_'.$parent_name;
 5559:                 for (my $j=0; $j<=$numchildren; $j++) {
 5560:                     if ($j < $numchildren) {
 5561:                         $name = $cats->[$depth]{$parent}[$j];
 5562:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 5563:                         $idxnum = $idx->{$item};
 5564:                     } else {
 5565:                         $name = $parent_name;
 5566:                         $item = $parent_item;
 5567:                     }
 5568:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 5569:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 5570:                     for (my $i=0; $i<=$numchildren; $i++) {
 5571:                         my $vpos = $i+1;
 5572:                         my $selstr;
 5573:                         if ($j == $i) {
 5574:                             $selstr = ' selected="selected" ';
 5575:                         }
 5576:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 5577:                     }
 5578:                     $text .= '</select>&nbsp;';
 5579:                     if ($j < $numchildren) {
 5580:                         my $deeper = $depth+1;
 5581:                         $text .= $name.'&nbsp;'
 5582:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 5583:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 5584:                         if(ref($path) eq 'ARRAY') {
 5585:                             push(@{$path},$name);
 5586:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 5587:                             pop(@{$path});
 5588:                         }
 5589:                     } else {
 5590:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 5591:                         if ($j == $numchildren) {
 5592:                             $text .= $name;
 5593:                         } else {
 5594:                             $text .= $item;
 5595:                         }
 5596:                         $text .= '" value="" />';
 5597:                     }
 5598:                     $text .= '</td></tr>';
 5599:                 }
 5600:                 $text .= '</table></td>';
 5601:             } else {
 5602:                 my $higher = $depth-1;
 5603:                 if ($higher == 0) {
 5604:                     $name = &escape($parent).'::'.$higher;
 5605:                 } else {
 5606:                     if (ref($path) eq 'ARRAY') {
 5607:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 5608:                     }
 5609:                 }
 5610:                 my $colspan;
 5611:                 if ($parent ne 'instcode') {
 5612:                     $colspan = $maxdepth - $depth - 1;
 5613:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 5614:                 }
 5615:             }
 5616:         }
 5617:     }
 5618:     return $text;
 5619: }
 5620: 
 5621: sub modifiable_userdata_row {
 5622:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
 5623:     my ($role,$rolename,$statustype);
 5624:     $role = $item;
 5625:     if ($context eq 'cancreate') {
 5626:         if ($item =~ /^emailusername_(.+)$/) {
 5627:             $statustype = $1;
 5628:             $role = 'emailusername';
 5629:             if (ref($usertypes) eq 'HASH') {
 5630:                 if ($usertypes->{$statustype}) {
 5631:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
 5632:                 } else {
 5633:                     $rolename = &mt('Data provided by user');
 5634:                 }
 5635:             }
 5636:         }
 5637:     } elsif ($context eq 'selfcreate') {
 5638:         if (ref($usertypes) eq 'HASH') {
 5639:             $rolename = $usertypes->{$role};
 5640:         } else {
 5641:             $rolename = $role;
 5642:         }
 5643:     } else {
 5644:         if ($role eq 'cr') {
 5645:             $rolename = &mt('Custom role');
 5646:         } else {
 5647:             $rolename = &Apache::lonnet::plaintext($role);
 5648:         }
 5649:     }
 5650:     my (@fields,%fieldtitles);
 5651:     if (ref($fieldsref) eq 'ARRAY') {
 5652:         @fields = @{$fieldsref};
 5653:     } else {
 5654:         @fields = ('lastname','firstname','middlename','generation',
 5655:                    'permanentemail','id');
 5656:     }
 5657:     if ((ref($titlesref) eq 'HASH')) {
 5658:         %fieldtitles = %{$titlesref};
 5659:     } else {
 5660:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 5661:     }
 5662:     my $output;
 5663:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 5664:     $output = '<tr '.$css_class.'>'.
 5665:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 5666:               '<td class="LC_left_item" colspan="2"><table>';
 5667:     my $rem;
 5668:     my %checks;
 5669:     if (ref($settings) eq 'HASH') {
 5670:         if (ref($settings->{$context}) eq 'HASH') {
 5671:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 5672:                 my $hashref = $settings->{$context}->{$role};
 5673:                 if ($role eq 'emailusername') {
 5674:                     if ($statustype) {
 5675:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
 5676:                             $hashref = $settings->{$context}->{$role}->{$statustype};
 5677:                             if (ref($hashref) eq 'HASH') { 
 5678:                                 foreach my $field (@fields) {
 5679:                                     if ($hashref->{$field}) {
 5680:                                         $checks{$field} = $hashref->{$field};
 5681:                                     }
 5682:                                 }
 5683:                             }
 5684:                         }
 5685:                     }
 5686:                 } else {
 5687:                     if (ref($hashref) eq 'HASH') {
 5688:                         foreach my $field (@fields) {
 5689:                             if ($hashref->{$field}) {
 5690:                                 $checks{$field} = ' checked="checked" ';
 5691:                             }
 5692:                         }
 5693:                     }
 5694:                 }
 5695:             }
 5696:         }
 5697:     }
 5698:      
 5699:     for (my $i=0; $i<@fields; $i++) {
 5700:         my $rem = $i%($numinrow);
 5701:         if ($rem == 0) {
 5702:             if ($i > 0) {
 5703:                 $output .= '</tr>';
 5704:             }
 5705:             $output .= '<tr>';
 5706:         }
 5707:         my $check = ' ';
 5708:         unless ($role eq 'emailusername') {
 5709:             if (exists($checks{$fields[$i]})) {
 5710:                 $check = $checks{$fields[$i]}
 5711:             } else {
 5712:                 if ($role eq 'st') {
 5713:                     if (ref($settings) ne 'HASH') {
 5714:                         $check = ' checked="checked" '; 
 5715:                     }
 5716:                 }
 5717:             }
 5718:         }
 5719:         $output .= '<td class="LC_left_item">'.
 5720:                    '<span class="LC_nobreak">';
 5721:         if ($role eq 'emailusername') {
 5722:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
 5723:                 $checks{$fields[$i]} = 'omit';
 5724:             }
 5725:             foreach my $option ('required','optional','omit') {
 5726:                 my $checked='';
 5727:                 if ($checks{$fields[$i]} eq $option) {
 5728:                     $checked='checked="checked" ';
 5729:                 }
 5730:                 $output .= '<label>'.
 5731:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
 5732:                            &mt($option).'</label>'.('&nbsp;' x2);
 5733:             }
 5734:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
 5735:         } else {
 5736:             $output .= '<label>'.
 5737:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
 5738:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 5739:                        '</label>';
 5740:         }
 5741:         $output .= '</span></td>';
 5742:         $rem = @fields%($numinrow);
 5743:     }
 5744:     my $colsleft = $numinrow - $rem;
 5745:     if ($colsleft > 1 ) {
 5746:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 5747:                    '&nbsp;</td>';
 5748:     } elsif ($colsleft == 1) {
 5749:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 5750:     }
 5751:     $output .= '</tr></table></td></tr>';
 5752:     return $output;
 5753: }
 5754: 
 5755: sub insttypes_row {
 5756:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
 5757:     my %lt = &Apache::lonlocal::texthash (
 5758:                       cansearch => 'Users allowed to search',
 5759:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
 5760:                       lockablenames => 'User preference to lock name',
 5761:              );
 5762:     my $showdom;
 5763:     if ($context eq 'cansearch') {
 5764:         $showdom = ' ('.$dom.')';
 5765:     }
 5766:     my $class = 'LC_left_item';
 5767:     if ($context eq 'statustocreate') {
 5768:         $class = 'LC_right_item';
 5769:     }
 5770:     my $css_class = ' class="LC_odd_row"';
 5771:     if ($rownum ne '') { 
 5772:         $css_class = ($rownum%2? ' class="LC_odd_row"':'');
 5773:     }
 5774:     my $output = '<tr'.$css_class.'>'.
 5775:                  '<td>'.$lt{$context}.$showdom.
 5776:                  '</td><td class="'.$class.'" colspan="2"><table>';
 5777:     my $rem;
 5778:     if (ref($types) eq 'ARRAY') {
 5779:         for (my $i=0; $i<@{$types}; $i++) {
 5780:             if (defined($usertypes->{$types->[$i]})) {
 5781:                 my $rem = $i%($numinrow);
 5782:                 if ($rem == 0) {
 5783:                     if ($i > 0) {
 5784:                         $output .= '</tr>';
 5785:                     }
 5786:                     $output .= '<tr>';
 5787:                 }
 5788:                 my $check = ' ';
 5789:                 if (ref($settings) eq 'HASH') {
 5790:                     if (ref($settings->{$context}) eq 'ARRAY') {
 5791:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
 5792:                             $check = ' checked="checked" ';
 5793:                         }
 5794:                     } elsif ($context eq 'statustocreate') {
 5795:                         $check = ' checked="checked" ';
 5796:                     }
 5797:                 }
 5798:                 $output .= '<td class="LC_left_item">'.
 5799:                            '<span class="LC_nobreak"><label>'.
 5800:                            '<input type="checkbox" name="'.$context.'" '.
 5801:                            'value="'.$types->[$i].'"'.$check.'/>'.
 5802:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 5803:             }
 5804:         }
 5805:         $rem = @{$types}%($numinrow);
 5806:     }
 5807:     my $colsleft = $numinrow - $rem;
 5808:     if (($rem == 0) && (@{$types} > 0)) {
 5809:         $output .= '<tr>';
 5810:     }
 5811:     if ($colsleft > 1) {
 5812:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 5813:     } else {
 5814:         $output .= '<td class="LC_left_item">';
 5815:     }
 5816:     my $defcheck = ' ';
 5817:     if (ref($settings) eq 'HASH') {  
 5818:         if (ref($settings->{$context}) eq 'ARRAY') {
 5819:             if (grep(/^default$/,@{$settings->{$context}})) {
 5820:                 $defcheck = ' checked="checked" ';
 5821:             }
 5822:         } elsif ($context eq 'statustocreate') {
 5823:             $defcheck = ' checked="checked" ';
 5824:         }
 5825:     }
 5826:     $output .= '<span class="LC_nobreak"><label>'.
 5827:                '<input type="checkbox" name="'.$context.'" '.
 5828:                'value="default"'.$defcheck.'/>'.
 5829:                $othertitle.'</label></span></td>'.
 5830:                '</tr></table></td></tr>';
 5831:     return $output;
 5832: }
 5833: 
 5834: sub sorted_searchtitles {
 5835:     my %searchtitles = &Apache::lonlocal::texthash(
 5836:                          'uname' => 'username',
 5837:                          'lastname' => 'last name',
 5838:                          'lastfirst' => 'last name, first name',
 5839:                      );
 5840:     my @titleorder = ('uname','lastname','lastfirst');
 5841:     return (\%searchtitles,\@titleorder);
 5842: }
 5843: 
 5844: sub sorted_searchtypes {
 5845:     my %srchtypes_desc = (
 5846:                            exact    => 'is exact match',
 5847:                            contains => 'contains ..',
 5848:                            begins   => 'begins with ..',
 5849:                          );
 5850:     my @srchtypeorder = ('exact','begins','contains');
 5851:     return (\%srchtypes_desc,\@srchtypeorder);
 5852: }
 5853: 
 5854: sub usertype_update_row {
 5855:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 5856:     my $datatable;
 5857:     my $numinrow = 4;
 5858:     foreach my $type (@{$types}) {
 5859:         if (defined($usertypes->{$type})) {
 5860:             $$rownums ++;
 5861:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 5862:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 5863:                           '</td><td class="LC_left_item"><table>';
 5864:             for (my $i=0; $i<@{$fields}; $i++) {
 5865:                 my $rem = $i%($numinrow);
 5866:                 if ($rem == 0) {
 5867:                     if ($i > 0) {
 5868:                         $datatable .= '</tr>';
 5869:                     }
 5870:                     $datatable .= '<tr>';
 5871:                 }
 5872:                 my $check = ' ';
 5873:                 if (ref($settings) eq 'HASH') {
 5874:                     if (ref($settings->{'fields'}) eq 'HASH') {
 5875:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 5876:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 5877:                                 $check = ' checked="checked" ';
 5878:                             }
 5879:                         }
 5880:                     }
 5881:                 }
 5882: 
 5883:                 if ($i == @{$fields}-1) {
 5884:                     my $colsleft = $numinrow - $rem;
 5885:                     if ($colsleft > 1) {
 5886:                         $datatable .= '<td colspan="'.$colsleft.'">';
 5887:                     } else {
 5888:                         $datatable .= '<td>';
 5889:                     }
 5890:                 } else {
 5891:                     $datatable .= '<td>';
 5892:                 }
 5893:                 $datatable .= '<span class="LC_nobreak"><label>'.
 5894:                               '<input type="checkbox" name="updateable_'.$type.
 5895:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 5896:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 5897:             }
 5898:             $datatable .= '</tr></table></td></tr>';
 5899:         }
 5900:     }
 5901:     return $datatable;
 5902: }
 5903: 
 5904: sub modify_login {
 5905:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
 5906:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
 5907:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
 5908:     %title = ( coursecatalog => 'Display course catalog',
 5909:                adminmail => 'Display administrator E-mail address',
 5910:                helpdesk  => 'Display "Contact Helpdesk" link',
 5911:                newuser => 'Link for visitors to create a user account',
 5912:                loginheader => 'Log-in box header');
 5913:     @offon = ('off','on');
 5914:     if (ref($domconfig{login}) eq 'HASH') {
 5915:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
 5916:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
 5917:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
 5918:             }
 5919:         }
 5920:     }
 5921:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 5922:                                            \%domconfig,\%loginhash);
 5923:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 5924:     foreach my $item (@toggles) {
 5925:         $loginhash{login}{$item} = $env{'form.'.$item};
 5926:     }
 5927:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 5928:     if (ref($colchanges{'login'}) eq 'HASH') {  
 5929:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 5930:                                          \%loginhash);
 5931:     }
 5932: 
 5933:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 5934:     my %domservers = &Apache::lonnet::get_servers($dom);
 5935:     my @loginvia_attribs = ('serverpath','custompath','exempt');
 5936:     if (keys(%servers) > 1) {
 5937:         foreach my $lonhost (keys(%servers)) {
 5938:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
 5939:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
 5940:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
 5941:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
 5942:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
 5943:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 5944:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 5945:                         $changes{'loginvia'}{$lonhost} = 1;
 5946:                     } else {
 5947:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
 5948:                         $changes{'loginvia'}{$lonhost} = 1;
 5949:                     }
 5950:                 } else {
 5951:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 5952:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 5953:                         $changes{'loginvia'}{$lonhost} = 1;
 5954:                     }
 5955:                 }
 5956:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
 5957:                     foreach my $item (@loginvia_attribs) {
 5958:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
 5959:                     }
 5960:                 } else {
 5961:                     foreach my $item (@loginvia_attribs) {
 5962:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 5963:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 5964:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
 5965:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 5966:                                 $new = '/';
 5967:                             }
 5968:                         }
 5969:                         if (($item eq 'custompath') && 
 5970:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 5971:                             $new = '';
 5972:                         }
 5973:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
 5974:                             $changes{'loginvia'}{$lonhost} = 1;
 5975:                         }
 5976:                         if ($item eq 'exempt') {
 5977:                             $new = &check_exempt_addresses($new);
 5978:                         }
 5979:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 5980:                     }
 5981:                 }
 5982:             } else {
 5983:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 5984:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 5985:                     $changes{'loginvia'}{$lonhost} = 1;
 5986:                     foreach my $item (@loginvia_attribs) {
 5987:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 5988:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 5989:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 5990:                                 $new = '/';
 5991:                             }
 5992:                         }
 5993:                         if (($item eq 'custompath') && 
 5994:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 5995:                             $new = '';
 5996:                         }
 5997:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 5998:                     }
 5999:                 }
 6000:             }
 6001:         }
 6002:     }
 6003: 
 6004:     my $servadm = $r->dir_config('lonAdmEMail');
 6005:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 6006:     if (ref($domconfig{'login'}) eq 'HASH') {
 6007:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
 6008:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
 6009:                 if ($lang eq 'nolang') {
 6010:                     push(@currlangs,$lang);
 6011:                 } elsif (defined($langchoices{$lang})) {
 6012:                     push(@currlangs,$lang);
 6013:                 } else {
 6014:                     next;
 6015:                 }
 6016:             }
 6017:         }
 6018:     }
 6019:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
 6020:     if (@currlangs > 0) {
 6021:         foreach my $lang (@currlangs) {
 6022:             if (grep(/^\Q$lang\E$/,@delurls)) {
 6023:                 $changes{'helpurl'}{$lang} = 1;
 6024:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
 6025:                 $changes{'helpurl'}{$lang} = 1;
 6026:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
 6027:                 push(@newlangs,$lang);
 6028:             } else {
 6029:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 6030:             }
 6031:         }
 6032:     }
 6033:     unless (grep(/^nolang$/,@currlangs)) {
 6034:         if ($env{'form.loginhelpurl_nolang.filename'}) {
 6035:             $changes{'helpurl'}{'nolang'} = 1;
 6036:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
 6037:             push(@newlangs,'nolang');
 6038:         }
 6039:     }
 6040:     if ($env{'form.loginhelpurl_add_lang'}) {
 6041:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
 6042:             ($env{'form.loginhelpurl_add_file.filename'})) {
 6043:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
 6044:             $addedfile = $env{'form.loginhelpurl_add_lang'};
 6045:         }
 6046:     }
 6047:     if ((@newlangs > 0) || ($addedfile)) {
 6048:         my $error;
 6049:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 6050:         if ($configuserok eq 'ok') {
 6051:             if ($switchserver) {
 6052:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
 6053:             } elsif ($author_ok eq 'ok') {
 6054:                 my @allnew = @newlangs;
 6055:                 if ($addedfile ne '') {
 6056:                     push(@allnew,$addedfile);
 6057:                 }
 6058:                 foreach my $lang (@allnew) {
 6059:                     my $formelem = 'loginhelpurl_'.$lang;
 6060:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
 6061:                         $formelem = 'loginhelpurl_add_file';
 6062:                     }
 6063:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
 6064:                                                                "help/$lang",'','',$newfile{$lang});
 6065:                     if ($result eq 'ok') {
 6066:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
 6067:                         $changes{'helpurl'}{$lang} = 1;
 6068:                     } else {
 6069:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
 6070:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
 6071:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
 6072:                             (!grep(/^\Q$lang\E$/,@delurls))) {
 6073:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 6074:                         }
 6075:                     }
 6076:                 }
 6077:             } else {
 6078:                 $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);
 6079:             }
 6080:         } else {
 6081:             $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);
 6082:         }
 6083:         if ($error) {
 6084:             &Apache::lonnet::logthis($error);
 6085:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6086:         }
 6087:     }
 6088: 
 6089:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
 6090:     if (ref($domconfig{'login'}) eq 'HASH') {
 6091:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
 6092:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
 6093:                 if ($domservers{$lonhost}) {
 6094:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
 6095:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
 6096:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
 6097:                     }
 6098:                 }
 6099:             }
 6100:         }
 6101:     }
 6102:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
 6103:     foreach my $lonhost (sort(keys(%domservers))) {
 6104:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
 6105:             $changes{'headtag'}{$lonhost} = 1;
 6106:         } else {
 6107:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
 6108:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
 6109:             }
 6110:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
 6111:                 push(@newhosts,$lonhost);
 6112:             } elsif ($currheadtagurls{$lonhost}) {
 6113:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
 6114:                 if ($currexempt{$lonhost}) {
 6115:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) { 
 6116:                         $changes{'headtag'}{$lonhost} = 1;
 6117:                     }
 6118:                 } elsif ($possexempt{$lonhost}) {
 6119:                     $changes{'headtag'}{$lonhost} = 1;
 6120:                 }
 6121:                 if ($possexempt{$lonhost}) {
 6122:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
 6123:                 }
 6124:             }
 6125:         }
 6126:     }
 6127:     if (@newhosts) {
 6128:         my $error;
 6129:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 6130:         if ($configuserok eq 'ok') {
 6131:             if ($switchserver) {
 6132:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
 6133:             } elsif ($author_ok eq 'ok') {
 6134:                 foreach my $lonhost (@newhosts) {
 6135:                     my $formelem = 'loginheadtag_'.$lonhost;
 6136:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
 6137:                                                                           "login/headtag/$lonhost",'','',
 6138:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
 6139:                     if ($result eq 'ok') {
 6140:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
 6141:                         $changes{'headtag'}{$lonhost} = 1;
 6142:                         if ($possexempt{$lonhost}) {
 6143:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
 6144:                         }
 6145:                     } else {
 6146:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
 6147:                                            $newheadtagurls{$lonhost},$result);
 6148:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
 6149:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
 6150:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
 6151:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
 6152:                         }
 6153:                     }
 6154:                 }
 6155:             } else {
 6156:                 $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);
 6157:             }
 6158:         } else {
 6159:             $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);
 6160:         }
 6161:         if ($error) {
 6162:             &Apache::lonnet::logthis($error);
 6163:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6164:         }
 6165:     }
 6166:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
 6167: 
 6168:     my $defaulthelpfile = '/adm/loginproblems.html';
 6169:     my $defaulttext = &mt('Default in use');
 6170: 
 6171:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 6172:                                              $dom);
 6173:     if ($putresult eq 'ok') {
 6174:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 6175:         my %defaultchecked = (
 6176:                     'coursecatalog' => 'on',
 6177:                     'helpdesk'      => 'on',
 6178:                     'adminmail'     => 'off',
 6179:                     'newuser'       => 'off',
 6180:         );
 6181:         if (ref($domconfig{'login'}) eq 'HASH') {
 6182:             foreach my $item (@toggles) {
 6183:                 if ($defaultchecked{$item} eq 'on') { 
 6184:                     if (($domconfig{'login'}{$item} eq '0') &&
 6185:                         ($env{'form.'.$item} eq '1')) {
 6186:                         $changes{$item} = 1;
 6187:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 6188:                               $domconfig{'login'}{$item} eq '1') &&
 6189:                              ($env{'form.'.$item} eq '0')) {
 6190:                         $changes{$item} = 1;
 6191:                     }
 6192:                 } elsif ($defaultchecked{$item} eq 'off') {
 6193:                     if (($domconfig{'login'}{$item} eq '1') &&
 6194:                         ($env{'form.'.$item} eq '0')) {
 6195:                         $changes{$item} = 1;
 6196:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 6197:                               $domconfig{'login'}{$item} eq '0') &&
 6198:                              ($env{'form.'.$item} eq '1')) {
 6199:                         $changes{$item} = 1;
 6200:                     }
 6201:                 }
 6202:             }
 6203:         }
 6204:         if (keys(%changes) > 0 || $colchgtext) {
 6205:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 6206:             if (ref($lastactref) eq 'HASH') {
 6207:                 $lastactref->{'domainconfig'} = 1;
 6208:             }
 6209:             $resulttext = &mt('Changes made:').'<ul>';
 6210:             foreach my $item (sort(keys(%changes))) {
 6211:                 if ($item eq 'loginvia') {
 6212:                     if (ref($changes{$item}) eq 'HASH') {
 6213:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
 6214:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 6215:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
 6216:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
 6217:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
 6218:                                     $protocol = 'http' if ($protocol ne 'https');
 6219:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
 6220: 
 6221:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
 6222:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
 6223:                                     } else {
 6224:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
 6225:                                     }
 6226:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
 6227:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
 6228:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
 6229:                                     }
 6230:                                     $resulttext .= '</li>';
 6231:                                 } else {
 6232:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
 6233:                                 }
 6234:                             } else {
 6235:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
 6236:                             }
 6237:                         }
 6238:                         $resulttext .= '</ul></li>';
 6239:                     }
 6240:                 } elsif ($item eq 'helpurl') {
 6241:                     if (ref($changes{$item}) eq 'HASH') {
 6242:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
 6243:                             if (grep(/^\Q$lang\E$/,@delurls)) {
 6244:                                 my ($chg,$link);
 6245:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
 6246:                                 if ($lang eq 'nolang') {
 6247:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
 6248:                                 } else {
 6249:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
 6250:                                 }
 6251:                                 $resulttext .= '<li>'.$chg.'</li>';
 6252:                             } else {
 6253:                                 my $chg;
 6254:                                 if ($lang eq 'nolang') {
 6255:                                     $chg = &mt('custom log-in help file for no preferred language');
 6256:                                 } else {
 6257:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
 6258:                                 }
 6259:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
 6260:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
 6261:                                                       '?inhibitmenu=yes',$chg,600,500).
 6262:                                                '</li>';
 6263:                             }
 6264:                         }
 6265:                     }
 6266:                 } elsif ($item eq 'headtag') {
 6267:                     if (ref($changes{$item}) eq 'HASH') {
 6268:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 6269:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
 6270:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
 6271:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
 6272:                                 $resulttext .= '<li><a href="'.
 6273:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
 6274:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
 6275:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
 6276:                                 if ($possexempt{$lonhost}) {
 6277:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
 6278:                                 } else {
 6279:                                     $resulttext .= &mt('included for any client IP');
 6280:                                 }
 6281:                                 $resulttext .= '</li>';
 6282:                             }
 6283:                         }
 6284:                     }
 6285:                 } elsif ($item eq 'captcha') {
 6286:                     if (ref($loginhash{'login'}) eq 'HASH') {
 6287:                         my $chgtxt;
 6288:                         if ($loginhash{'login'}{$item} eq 'notused') {
 6289:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
 6290:                         } else {
 6291:                             my %captchas = &captcha_phrases();
 6292:                             if ($captchas{$loginhash{'login'}{$item}}) {
 6293:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
 6294:                             } else {
 6295:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
 6296:                             }
 6297:                         }
 6298:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 6299:                     }
 6300:                 } elsif ($item eq 'recaptchakeys') {
 6301:                     if (ref($loginhash{'login'}) eq 'HASH') {
 6302:                         my ($privkey,$pubkey);
 6303:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
 6304:                             $pubkey = $loginhash{'login'}{$item}{'public'};
 6305:                             $privkey = $loginhash{'login'}{$item}{'private'};
 6306:                         }
 6307:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
 6308:                         if (!$pubkey) {
 6309:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
 6310:                         } else {
 6311:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 6312:                         }
 6313:                         if (!$privkey) {
 6314:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
 6315:                         } else {
 6316:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
 6317:                         }
 6318:                         $chgtxt .= '</ul>';
 6319:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 6320:                     }
 6321:                 } else {
 6322:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 6323:                 }
 6324:             }
 6325:             $resulttext .= $colchgtext.'</ul>';
 6326:         } else {
 6327:             $resulttext = &mt('No changes made to log-in page settings');
 6328:         }
 6329:     } else {
 6330:         $resulttext = '<span class="LC_error">'.
 6331: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6332:     }
 6333:     if ($errors) {
 6334:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 6335:                        $errors.'</ul>';
 6336:     }
 6337:     return $resulttext;
 6338: }
 6339: 
 6340: 
 6341: sub check_exempt_addresses {
 6342:     my ($iplist) = @_;
 6343:     $iplist =~ s/^\s+//;
 6344:     $iplist =~ s/\s+$//;
 6345:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
 6346:     my (@okips,$new);
 6347:     foreach my $ip (@poss_ips) {
 6348:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
 6349:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
 6350:                 push(@okips,$ip);
 6351:             }
 6352:         }
 6353:     }
 6354:     if (@okips > 0) {
 6355:         $new = join(',',@okips);
 6356:     } else {
 6357:         $new = '';
 6358:     }
 6359:     return $new;
 6360: }
 6361: 
 6362: sub color_font_choices {
 6363:     my %choices =
 6364:         &Apache::lonlocal::texthash (
 6365:             img => "Header",
 6366:             bgs => "Background colors",
 6367:             links => "Link colors",
 6368:             images => "Images",
 6369:             font => "Font color",
 6370:             fontmenu => "Font menu",
 6371:             pgbg => "Page",
 6372:             tabbg => "Header",
 6373:             sidebg => "Border",
 6374:             link => "Link",
 6375:             alink => "Active link",
 6376:             vlink => "Visited link",
 6377:         );
 6378:     return %choices;
 6379: }
 6380: 
 6381: sub modify_rolecolors {
 6382:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
 6383:     my ($resulttext,%rolehash);
 6384:     $rolehash{'rolecolors'} = {};
 6385:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 6386:         if ($domconfig{'rolecolors'} eq '') {
 6387:             $domconfig{'rolecolors'} = {};
 6388:         }
 6389:     }
 6390:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 6391:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 6392:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 6393:                                              $dom);
 6394:     if ($putresult eq 'ok') {
 6395:         if (keys(%changes) > 0) {
 6396:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 6397:             if (ref($lastactref) eq 'HASH') {
 6398:                 $lastactref->{'domainconfig'} = 1;
 6399:             }
 6400:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 6401:                                              $rolehash{'rolecolors'});
 6402:         } else {
 6403:             $resulttext = &mt('No changes made to default color schemes');
 6404:         }
 6405:     } else {
 6406:         $resulttext = '<span class="LC_error">'.
 6407: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6408:     }
 6409:     if ($errors) {
 6410:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 6411:                        $errors.'</ul>';
 6412:     }
 6413:     return $resulttext;
 6414: }
 6415: 
 6416: sub modify_colors {
 6417:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 6418:     my (%changes,%choices);
 6419:     my @bgs;
 6420:     my @links = ('link','alink','vlink');
 6421:     my @logintext;
 6422:     my @images;
 6423:     my $servadm = $r->dir_config('lonAdmEMail');
 6424:     my $errors;
 6425:     my %defaults;
 6426:     foreach my $role (@{$roles}) {
 6427:         if ($role eq 'login') {
 6428:             %choices = &login_choices();
 6429:             @logintext = ('textcol','bgcol');
 6430:         } else {
 6431:             %choices = &color_font_choices();
 6432:         }
 6433:         if ($role eq 'login') {
 6434:             @images = ('img','logo','domlogo','login');
 6435:             @bgs = ('pgbg','mainbg','sidebg');
 6436:         } else {
 6437:             @images = ('img');
 6438:             @bgs = ('pgbg','tabbg','sidebg');
 6439:         }
 6440:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
 6441:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
 6442:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 6443:         }
 6444:         if ($role eq 'login') {
 6445:             foreach my $item (@logintext) {
 6446:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
 6447:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
 6448:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
 6449:                 }
 6450:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
 6451:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 6452:                 }
 6453:             }
 6454:         } else {
 6455:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
 6456:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
 6457:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
 6458:             }
 6459:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
 6460:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
 6461:             }
 6462:         }
 6463:         foreach my $item (@bgs) {
 6464:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
 6465:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
 6466:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
 6467:             }
 6468:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
 6469:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 6470:             }
 6471:         }
 6472:         foreach my $item (@links) {
 6473:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
 6474:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
 6475:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
 6476:             }
 6477:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
 6478:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 6479:             }
 6480:         }
 6481:         my ($configuserok,$author_ok,$switchserver) = 
 6482:             &config_check($dom,$confname,$servadm);
 6483:         my ($width,$height) = &thumb_dimensions();
 6484:         if (ref($domconfig->{$role}) ne 'HASH') {
 6485:             $domconfig->{$role} = {};
 6486:         }
 6487:         foreach my $img (@images) {
 6488:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 6489:                 if (defined($env{'form.login_showlogo_'.$img})) {
 6490:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 6491:                 } else { 
 6492:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 6493:                 }
 6494:             } 
 6495: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 6496: 		 && !defined($domconfig->{$role}{$img})
 6497: 		 && !$env{'form.'.$role.'_del_'.$img}
 6498: 		 && $env{'form.'.$role.'_import_'.$img}) {
 6499: 		# import the old configured image from the .tab setting
 6500: 		# if they haven't provided a new one 
 6501: 		$domconfig->{$role}{$img} = 
 6502: 		    $env{'form.'.$role.'_import_'.$img};
 6503: 	    }
 6504:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 6505:                 my $error;
 6506:                 if ($configuserok eq 'ok') {
 6507:                     if ($switchserver) {
 6508:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 6509:                     } else {
 6510:                         if ($author_ok eq 'ok') {
 6511:                             my ($result,$logourl) = 
 6512:                                 &publishlogo($r,'upload',$role.'_'.$img,
 6513:                                            $dom,$confname,$img,$width,$height);
 6514:                             if ($result eq 'ok') {
 6515:                                 $confhash->{$role}{$img} = $logourl;
 6516:                                 $changes{$role}{'images'}{$img} = 1;
 6517:                             } else {
 6518:                                 $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);
 6519:                             }
 6520:                         } else {
 6521:                             $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);
 6522:                         }
 6523:                     }
 6524:                 } else {
 6525:                     $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);
 6526:                 }
 6527:                 if ($error) {
 6528:                     &Apache::lonnet::logthis($error);
 6529:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6530:                 }
 6531:             } elsif ($domconfig->{$role}{$img} ne '') {
 6532:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 6533:                     my $error;
 6534:                     if ($configuserok eq 'ok') {
 6535: # is confname an author?
 6536:                         if ($switchserver eq '') {
 6537:                             if ($author_ok eq 'ok') {
 6538:                                 my ($result,$logourl) = 
 6539:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 6540:                                             $dom,$confname,$img,$width,$height);
 6541:                                 if ($result eq 'ok') {
 6542:                                     $confhash->{$role}{$img} = $logourl;
 6543: 				    $changes{$role}{'images'}{$img} = 1;
 6544:                                 }
 6545:                             }
 6546:                         }
 6547:                     }
 6548:                 }
 6549:             }
 6550:         }
 6551:         if (ref($domconfig) eq 'HASH') {
 6552:             if (ref($domconfig->{$role}) eq 'HASH') {
 6553:                 foreach my $img (@images) {
 6554:                     if ($domconfig->{$role}{$img} ne '') {
 6555:                         if ($env{'form.'.$role.'_del_'.$img}) {
 6556:                             $confhash->{$role}{$img} = '';
 6557:                             $changes{$role}{'images'}{$img} = 1;
 6558:                         } else {
 6559:                             if ($confhash->{$role}{$img} eq '') {
 6560:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 6561:                             }
 6562:                         }
 6563:                     } else {
 6564:                         if ($env{'form.'.$role.'_del_'.$img}) {
 6565:                             $confhash->{$role}{$img} = '';
 6566:                             $changes{$role}{'images'}{$img} = 1;
 6567:                         } 
 6568:                     }
 6569:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 6570:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 6571:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 6572:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 6573:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 6574:                             }
 6575:                         } else {
 6576:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 6577:                                 $changes{$role}{'showlogo'}{$img} = 1;
 6578:                             }
 6579:                         }
 6580:                     }
 6581:                 }
 6582:                 if ($domconfig->{$role}{'font'} ne '') {
 6583:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 6584:                         $changes{$role}{'font'} = 1;
 6585:                     }
 6586:                 } else {
 6587:                     if ($confhash->{$role}{'font'}) {
 6588:                         $changes{$role}{'font'} = 1;
 6589:                     }
 6590:                 }
 6591:                 if ($role ne 'login') {
 6592:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
 6593:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
 6594:                             $changes{$role}{'fontmenu'} = 1;
 6595:                         }
 6596:                     } else {
 6597:                         if ($confhash->{$role}{'fontmenu'}) {
 6598:                             $changes{$role}{'fontmenu'} = 1;
 6599:                         }
 6600:                     }
 6601:                 }
 6602:                 foreach my $item (@bgs) {
 6603:                     if ($domconfig->{$role}{$item} ne '') {
 6604:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 6605:                             $changes{$role}{'bgs'}{$item} = 1;
 6606:                         } 
 6607:                     } else {
 6608:                         if ($confhash->{$role}{$item}) {
 6609:                             $changes{$role}{'bgs'}{$item} = 1;
 6610:                         }
 6611:                     }
 6612:                 }
 6613:                 foreach my $item (@links) {
 6614:                     if ($domconfig->{$role}{$item} ne '') {
 6615:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 6616:                             $changes{$role}{'links'}{$item} = 1;
 6617:                         }
 6618:                     } else {
 6619:                         if ($confhash->{$role}{$item}) {
 6620:                             $changes{$role}{'links'}{$item} = 1;
 6621:                         }
 6622:                     }
 6623:                 }
 6624:                 foreach my $item (@logintext) {
 6625:                     if ($domconfig->{$role}{$item} ne '') {
 6626:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 6627:                             $changes{$role}{'logintext'}{$item} = 1;
 6628:                         }
 6629:                     } else {
 6630:                         if ($confhash->{$role}{$item}) {
 6631:                             $changes{$role}{'logintext'}{$item} = 1;
 6632:                         }
 6633:                     }
 6634:                 }
 6635:             } else {
 6636:                 &default_change_checker($role,\@images,\@links,\@bgs,
 6637:                                         \@logintext,$confhash,\%changes); 
 6638:             }
 6639:         } else {
 6640:             &default_change_checker($role,\@images,\@links,\@bgs,
 6641:                                     \@logintext,$confhash,\%changes); 
 6642:         }
 6643:     }
 6644:     return ($errors,%changes);
 6645: }
 6646: 
 6647: sub config_check {
 6648:     my ($dom,$confname,$servadm) = @_;
 6649:     my ($configuserok,$author_ok,$switchserver,%currroles);
 6650:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 6651:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 6652:                                                    $confname,$servadm);
 6653:     if ($configuserok eq 'ok') {
 6654:         $switchserver = &check_switchserver($dom,$confname);
 6655:         if ($switchserver eq '') {
 6656:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 6657:         }
 6658:     }
 6659:     return ($configuserok,$author_ok,$switchserver);
 6660: }
 6661: 
 6662: sub default_change_checker {
 6663:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 6664:     foreach my $item (@{$links}) {
 6665:         if ($confhash->{$role}{$item}) {
 6666:             $changes->{$role}{'links'}{$item} = 1;
 6667:         }
 6668:     }
 6669:     foreach my $item (@{$bgs}) {
 6670:         if ($confhash->{$role}{$item}) {
 6671:             $changes->{$role}{'bgs'}{$item} = 1;
 6672:         }
 6673:     }
 6674:     foreach my $item (@{$logintext}) {
 6675:         if ($confhash->{$role}{$item}) {
 6676:             $changes->{$role}{'logintext'}{$item} = 1;
 6677:         }
 6678:     }
 6679:     foreach my $img (@{$images}) {
 6680:         if ($env{'form.'.$role.'_del_'.$img}) {
 6681:             $confhash->{$role}{$img} = '';
 6682:             $changes->{$role}{'images'}{$img} = 1;
 6683:         }
 6684:         if ($role eq 'login') {
 6685:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 6686:                 $changes->{$role}{'showlogo'}{$img} = 1;
 6687:             }
 6688:         }
 6689:     }
 6690:     if ($confhash->{$role}{'font'}) {
 6691:         $changes->{$role}{'font'} = 1;
 6692:     }
 6693: }
 6694: 
 6695: sub display_colorchgs {
 6696:     my ($dom,$changes,$roles,$confhash) = @_;
 6697:     my (%choices,$resulttext);
 6698:     if (!grep(/^login$/,@{$roles})) {
 6699:         $resulttext = &mt('Changes made:').'<br />';
 6700:     }
 6701:     foreach my $role (@{$roles}) {
 6702:         if ($role eq 'login') {
 6703:             %choices = &login_choices();
 6704:         } else {
 6705:             %choices = &color_font_choices();
 6706:         }
 6707:         if (ref($changes->{$role}) eq 'HASH') {
 6708:             if ($role ne 'login') {
 6709:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 6710:             }
 6711:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 6712:                 if ($role ne 'login') {
 6713:                     $resulttext .= '<ul>';
 6714:                 }
 6715:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 6716:                     if ($role ne 'login') {
 6717:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 6718:                     }
 6719:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 6720:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 6721:                             if ($confhash->{$role}{$key}{$item}) {
 6722:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 6723:                             } else {
 6724:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 6725:                             }
 6726:                         } elsif ($confhash->{$role}{$item} eq '') {
 6727:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 6728:                         } else {
 6729:                             my $newitem = $confhash->{$role}{$item};
 6730:                             if ($key eq 'images') {
 6731:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 6732:                             }
 6733:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 6734:                         }
 6735:                     }
 6736:                     if ($role ne 'login') {
 6737:                         $resulttext .= '</ul></li>';
 6738:                     }
 6739:                 } else {
 6740:                     if ($confhash->{$role}{$key} eq '') {
 6741:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 6742:                     } else {
 6743:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 6744:                     }
 6745:                 }
 6746:                 if ($role ne 'login') {
 6747:                     $resulttext .= '</ul>';
 6748:                 }
 6749:             }
 6750:         }
 6751:     }
 6752:     return $resulttext;
 6753: }
 6754: 
 6755: sub thumb_dimensions {
 6756:     return ('200','50');
 6757: }
 6758: 
 6759: sub check_dimensions {
 6760:     my ($inputfile) = @_;
 6761:     my ($fullwidth,$fullheight);
 6762:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 6763:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 6764:             my $imageinfo = <PIPE>;
 6765:             if (!close(PIPE)) {
 6766:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 6767:             }
 6768:             chomp($imageinfo);
 6769:             my ($fullsize) = 
 6770:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 6771:             if ($fullsize) {
 6772:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 6773:             }
 6774:         }
 6775:     }
 6776:     return ($fullwidth,$fullheight);
 6777: }
 6778: 
 6779: sub check_configuser {
 6780:     my ($uhome,$dom,$confname,$servadm) = @_;
 6781:     my ($configuserok,%currroles);
 6782:     if ($uhome eq 'no_host') {
 6783:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 6784:         my $configpass = &LONCAPA::Enrollment::create_password();
 6785:         $configuserok = 
 6786:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 6787:                              $configpass,'','','','','',undef,$servadm);
 6788:     } else {
 6789:         $configuserok = 'ok';
 6790:         %currroles = 
 6791:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 6792:     }
 6793:     return ($configuserok,%currroles);
 6794: }
 6795: 
 6796: sub check_authorstatus {
 6797:     my ($dom,$confname,%currroles) = @_;
 6798:     my $author_ok;
 6799:     if (!$currroles{':'.$dom.':au'}) {
 6800:         my $start = time;
 6801:         my $end = 0;
 6802:         $author_ok = 
 6803:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 6804:                                         'au',$end,$start,'','','domconfig');
 6805:     } else {
 6806:         $author_ok = 'ok';
 6807:     }
 6808:     return $author_ok;
 6809: }
 6810: 
 6811: sub publishlogo {
 6812:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 6813:     my ($output,$fname,$logourl);
 6814:     if ($action eq 'upload') {
 6815:         $fname=$env{'form.'.$formname.'.filename'};
 6816:         chop($env{'form.'.$formname});
 6817:     } else {
 6818:         ($fname) = ($formname =~ /([^\/]+)$/);
 6819:     }
 6820:     if ($savefileas ne '') {
 6821:         $fname = $savefileas;
 6822:     }
 6823:     $fname=&Apache::lonnet::clean_filename($fname);
 6824: # See if there is anything left
 6825:     unless ($fname) { return ('error: no uploaded file'); }
 6826:     $fname="$subdir/$fname";
 6827:     my $docroot=$r->dir_config('lonDocRoot');
 6828:     my $filepath="$docroot/priv";
 6829:     my $relpath = "$dom/$confname";
 6830:     my ($fnamepath,$file,$fetchthumb);
 6831:     $file=$fname;
 6832:     if ($fname=~m|/|) {
 6833:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 6834:     }
 6835:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
 6836:     my $count;
 6837:     for ($count=5;$count<=$#parts;$count++) {
 6838:         $filepath.="/$parts[$count]";
 6839:         if ((-e $filepath)!=1) {
 6840:             mkdir($filepath,02770);
 6841:         }
 6842:     }
 6843:     # Check for bad extension and disallow upload
 6844:     if ($file=~/\.(\w+)$/ &&
 6845:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 6846:         $output = 
 6847:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
 6848:     } elsif ($file=~/\.(\w+)$/ &&
 6849:         !defined(&Apache::loncommon::fileembstyle($1))) {
 6850:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 6851:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 6852:         $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 6853:     } elsif (-d "$filepath/$file") {
 6854:         $output = &mt('Filename is a directory name - rename the file and re-upload');
 6855:     } else {
 6856:         my $source = $filepath.'/'.$file;
 6857:         my $logfile;
 6858:         if (!open($logfile,">>$source".'.log')) {
 6859:             return (&mt('No write permission to Authoring Space'));
 6860:         }
 6861:         print $logfile
 6862: "\n================= Publish ".localtime()." ================\n".
 6863: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 6864: # Save the file
 6865:         if (!open(FH,'>'.$source)) {
 6866:             &Apache::lonnet::logthis('Failed to create '.$source);
 6867:             return (&mt('Failed to create file'));
 6868:         }
 6869:         if ($action eq 'upload') {
 6870:             if (!print FH ($env{'form.'.$formname})) {
 6871:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 6872:                 return (&mt('Failed to write file'));
 6873:             }
 6874:         } else {
 6875:             my $original = &Apache::lonnet::filelocation('',$formname);
 6876:             if(!copy($original,$source)) {
 6877:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 6878:                 return (&mt('Failed to write file'));
 6879:             }
 6880:         }
 6881:         close(FH);
 6882:         chmod(0660, $source); # Permissions to rw-rw---.
 6883: 
 6884:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 6885:         my $copyfile=$targetdir.'/'.$file;
 6886: 
 6887:         my @parts=split(/\//,$targetdir);
 6888:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 6889:         for (my $count=5;$count<=$#parts;$count++) {
 6890:             $path.="/$parts[$count]";
 6891:             if (!-e $path) {
 6892:                 print $logfile "\nCreating directory ".$path;
 6893:                 mkdir($path,02770);
 6894:             }
 6895:         }
 6896:         my $versionresult;
 6897:         if (-e $copyfile) {
 6898:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 6899:         } else {
 6900:             $versionresult = 'ok';
 6901:         }
 6902:         if ($versionresult eq 'ok') {
 6903:             if (copy($source,$copyfile)) {
 6904:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 6905:                 $output = 'ok';
 6906:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 6907:                 push(@{$modified_urls},[$copyfile,$source]);
 6908:                 my $metaoutput = 
 6909:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 6910:                 unless ($registered_cleanup) {
 6911:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 6912:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 6913:                     $registered_cleanup=1;
 6914:                 }
 6915:             } else {
 6916:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 6917:                 $output = &mt('Failed to copy file to RES space').", $!";
 6918:             }
 6919:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 6920:                 my $inputfile = $filepath.'/'.$file;
 6921:                 my $outfile = $filepath.'/'.'tn-'.$file;
 6922:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 6923:                 if ($fullwidth ne '' && $fullheight ne '') { 
 6924:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 6925:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 6926:                         system("convert -sample $thumbsize $inputfile $outfile");
 6927:                         chmod(0660, $filepath.'/tn-'.$file);
 6928:                         if (-e $outfile) {
 6929:                             my $copyfile=$targetdir.'/tn-'.$file;
 6930:                             if (copy($outfile,$copyfile)) {
 6931:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 6932:                                 my $thumb_metaoutput = 
 6933:                                     &write_metadata($dom,$confname,$formname,
 6934:                                                     $targetdir,'tn-'.$file,$logfile);
 6935:                                 push(@{$modified_urls},[$copyfile,$outfile]);
 6936:                                 unless ($registered_cleanup) {
 6937:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 6938:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 6939:                                     $registered_cleanup=1;
 6940:                                 }
 6941:                             } else {
 6942:                                 print $logfile "\nUnable to write ".$copyfile.
 6943:                                                ':'.$!."\n";
 6944:                             }
 6945:                         }
 6946:                     }
 6947:                 }
 6948:             }
 6949:         } else {
 6950:             $output = $versionresult;
 6951:         }
 6952:     }
 6953:     return ($output,$logourl);
 6954: }
 6955: 
 6956: sub logo_versioning {
 6957:     my ($targetdir,$file,$logfile) = @_;
 6958:     my $target = $targetdir.'/'.$file;
 6959:     my ($maxversion,$fn,$extn,$output);
 6960:     $maxversion = 0;
 6961:     if ($file =~ /^(.+)\.(\w+)$/) {
 6962:         $fn=$1;
 6963:         $extn=$2;
 6964:     }
 6965:     opendir(DIR,$targetdir);
 6966:     while (my $filename=readdir(DIR)) {
 6967:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 6968:             $maxversion=($1>$maxversion)?$1:$maxversion;
 6969:         }
 6970:     }
 6971:     $maxversion++;
 6972:     print $logfile "\nCreating old version ".$maxversion."\n";
 6973:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 6974:     if (copy($target,$copyfile)) {
 6975:         print $logfile "Copied old target to ".$copyfile."\n";
 6976:         $copyfile=$copyfile.'.meta';
 6977:         if (copy($target.'.meta',$copyfile)) {
 6978:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 6979:             $output = 'ok';
 6980:         } else {
 6981:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 6982:             $output = &mt('Failed to copy old meta').", $!, ";
 6983:         }
 6984:     } else {
 6985:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 6986:         $output = &mt('Failed to copy old target').", $!, ";
 6987:     }
 6988:     return $output;
 6989: }
 6990: 
 6991: sub write_metadata {
 6992:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 6993:     my (%metadatafields,%metadatakeys,$output);
 6994:     $metadatafields{'title'}=$formname;
 6995:     $metadatafields{'creationdate'}=time;
 6996:     $metadatafields{'lastrevisiondate'}=time;
 6997:     $metadatafields{'copyright'}='public';
 6998:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 6999:                                          $env{'user.domain'};
 7000:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 7001:     $metadatafields{'domain'}=$dom;
 7002:     {
 7003:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 7004:         my $mfh;
 7005:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 7006:             foreach (sort(keys(%metadatafields))) {
 7007:                 unless ($_=~/\./) {
 7008:                     my $unikey=$_;
 7009:                     $unikey=~/^([A-Za-z]+)/;
 7010:                     my $tag=$1;
 7011:                     $tag=~tr/A-Z/a-z/;
 7012:                     print $mfh "\n\<$tag";
 7013:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
 7014:                         my $value=$metadatafields{$unikey.'.'.$_};
 7015:                         $value=~s/\"/\'\'/g;
 7016:                         print $mfh ' '.$_.'="'.$value.'"';
 7017:                     }
 7018:                     print $mfh '>'.
 7019:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 7020:                             .'</'.$tag.'>';
 7021:                 }
 7022:             }
 7023:             $output = 'ok';
 7024:             print $logfile "\nWrote metadata";
 7025:             close($mfh);
 7026:         } else {
 7027:             print $logfile "\nFailed to open metadata file";
 7028:             $output = &mt('Could not write metadata');
 7029:         }
 7030:     }
 7031:     return $output;
 7032: }
 7033: 
 7034: sub notifysubscribed {
 7035:     foreach my $targetsource (@{$modified_urls}){
 7036:         next unless (ref($targetsource) eq 'ARRAY');
 7037:         my ($target,$source)=@{$targetsource};
 7038:         if ($source ne '') {
 7039:             if (open(my $logfh,'>>'.$source.'.log')) {
 7040:                 print $logfh "\nCleanup phase: Notifications\n";
 7041:                 my @subscribed=&subscribed_hosts($target);
 7042:                 foreach my $subhost (@subscribed) {
 7043:                     print $logfh "\nNotifying host ".$subhost.':';
 7044:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
 7045:                     print $logfh $reply;
 7046:                 }
 7047:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
 7048:                 foreach my $subhost (@subscribedmeta) {
 7049:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
 7050:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
 7051:                                                         $subhost);
 7052:                     print $logfh $reply;
 7053:                 }
 7054:                 print $logfh "\n============ Done ============\n";
 7055:                 close($logfh);
 7056:             }
 7057:         }
 7058:     }
 7059:     return OK;
 7060: }
 7061: 
 7062: sub subscribed_hosts {
 7063:     my ($target) = @_;
 7064:     my @subscribed;
 7065:     if (open(my $fh,"<$target.subscription")) {
 7066:         while (my $subline=<$fh>) {
 7067:             if ($subline =~ /^($match_lonid):/) {
 7068:                 my $host = $1;
 7069:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
 7070:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
 7071:                         push(@subscribed,$host);
 7072:                     }
 7073:                 }
 7074:             }
 7075:         }
 7076:     }
 7077:     return @subscribed;
 7078: }
 7079: 
 7080: sub check_switchserver {
 7081:     my ($dom,$confname) = @_;
 7082:     my ($allowed,$switchserver);
 7083:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 7084:     if ($home eq 'no_host') {
 7085:         $home = &Apache::lonnet::domain($dom,'primary');
 7086:     }
 7087:     my @ids=&Apache::lonnet::current_machine_ids();
 7088:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 7089:     if (!$allowed) {
 7090: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
 7091:     }
 7092:     return $switchserver;
 7093: }
 7094: 
 7095: sub modify_quotas {
 7096:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
 7097:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
 7098:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
 7099:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
 7100:         $validationfieldsref);
 7101:     if ($action eq 'quotas') {
 7102:         $context = 'tools'; 
 7103:     } else {
 7104:         $context = $action;
 7105:     }
 7106:     if ($context eq 'requestcourses') {
 7107:         @usertools = ('official','unofficial','community','textbook');
 7108:         @options =('norequest','approval','validate','autolimit');
 7109:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 7110:         %titles = &courserequest_titles();
 7111:         $toolregexp = join('|',@usertools);
 7112:         %conditions = &courserequest_conditions();
 7113:         $confname = $dom.'-domainconfig';
 7114:         my $servadm = $r->dir_config('lonAdmEMail');
 7115:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 7116:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
 7117:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
 7118:     } elsif ($context eq 'requestauthor') {
 7119:         @usertools = ('author');
 7120:         %titles = &authorrequest_titles();
 7121:     } else {
 7122:         @usertools = ('aboutme','blog','webdav','portfolio');
 7123:         %titles = &tool_titles();
 7124:     }
 7125:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
 7126:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 7127:     foreach my $key (keys(%env)) {
 7128:         if ($context eq 'requestcourses') {
 7129:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
 7130:                 my $item = $1;
 7131:                 my $type = $2;
 7132:                 if ($type =~ /^limit_(.+)/) {
 7133:                     $limithash{$item}{$1} = $env{$key};
 7134:                 } else {
 7135:                     $confhash{$item}{$type} = $env{$key};
 7136:                 }
 7137:             }
 7138:         } elsif ($context eq 'requestauthor') {
 7139:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
 7140:                 $confhash{$1} = $env{$key};
 7141:             }
 7142:         } else {
 7143:             if ($key =~ /^form\.quota_(.+)$/) {
 7144:                 $confhash{'defaultquota'}{$1} = $env{$key};
 7145:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
 7146:                 $confhash{'authorquota'}{$1} = $env{$key};
 7147:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
 7148:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 7149:             }
 7150:         }
 7151:     }
 7152:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 7153:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
 7154:         @approvalnotify = sort(@approvalnotify);
 7155:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
 7156:         my @crstypes = ('official','unofficial','community','textbook');
 7157:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
 7158:         foreach my $type (@hasuniquecode) {
 7159:             if (grep(/^\Q$type\E$/,@crstypes)) {
 7160:                 $confhash{'uniquecode'}{$type} = 1;
 7161:             }
 7162:         }
 7163:         my (%newbook,%allpos);
 7164:         if ($context eq 'requestcourses') {
 7165:             foreach my $type ('textbooks','templates') {
 7166:                 @{$allpos{$type}} = (); 
 7167:                 my $invalid;
 7168:                 if ($type eq 'textbooks') {
 7169:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
 7170:                 } else {
 7171:                     $invalid = &mt('Invalid LON-CAPA course for template');
 7172:                 }
 7173:                 if ($env{'form.'.$type.'_addbook'}) {
 7174:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
 7175:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
 7176:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
 7177:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
 7178:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
 7179:                         } else {
 7180:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
 7181:                             my $position = $env{'form.'.$type.'_addbook_pos'};
 7182:                             $position =~ s/\D+//g;
 7183:                             if ($position ne '') {
 7184:                                 $allpos{$type}[$position] = $newbook{$type};
 7185:                             }
 7186:                         }
 7187:                     } else {
 7188:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
 7189:                     }
 7190:                 }
 7191:             } 
 7192:         }
 7193:         if (ref($domconfig{$action}) eq 'HASH') {
 7194:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
 7195:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
 7196:                     $changes{'notify'}{'approval'} = 1;
 7197:                 }
 7198:             } else {
 7199:                 if ($confhash{'notify'}{'approval'}) {
 7200:                     $changes{'notify'}{'approval'} = 1;
 7201:                 }
 7202:             }
 7203:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
 7204:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
 7205:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
 7206:                         unless ($confhash{'uniquecode'}{$crstype}) {
 7207:                             $changes{'uniquecode'} = 1;
 7208:                         }
 7209:                     }
 7210:                     unless ($changes{'uniquecode'}) {
 7211:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
 7212:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
 7213:                                 $changes{'uniquecode'} = 1;
 7214:                             }
 7215:                         }
 7216:                     }
 7217:                } else {
 7218:                    $changes{'uniquecode'} = 1;
 7219:                }
 7220:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
 7221:                 $changes{'uniquecode'} = 1;
 7222:             }
 7223:             if ($context eq 'requestcourses') {
 7224:                 foreach my $type ('textbooks','templates') {
 7225:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
 7226:                         my %deletions;
 7227:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
 7228:                         if (@todelete) {
 7229:                             map { $deletions{$_} = 1; } @todelete;
 7230:                         }
 7231:                         my %imgdeletions;
 7232:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
 7233:                         if (@todeleteimages) {
 7234:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
 7235:                         }
 7236:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
 7237:                         for (my $i=0; $i<=$maxnum; $i++) {
 7238:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
 7239:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
 7240:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
 7241:                                 if ($deletions{$key}) {
 7242:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
 7243:                                         #FIXME need to obsolete item in RES space
 7244:                                     }
 7245:                                     next;
 7246:                                 } else {
 7247:                                     my $newpos = $env{'form.'.$itemid};
 7248:                                     $newpos =~ s/\D+//g;
 7249:                                     foreach my $item ('subject','title','publisher','author') {
 7250:                                         next if ((($item eq 'author') || ($item eq 'publisher')) && 
 7251:                                                  ($type eq 'templates'));
 7252:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
 7253:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
 7254:                                             $changes{$type}{$key} = 1;
 7255:                                         }
 7256:                                     }
 7257:                                     $allpos{$type}[$newpos] = $key;
 7258:                                 }
 7259:                                 if ($imgdeletions{$key}) {
 7260:                                     $changes{$type}{$key} = 1;
 7261:                                     #FIXME need to obsolete item in RES space
 7262:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
 7263:                                     my ($cdom,$cnum) = split(/_/,$key);
 7264:                                     my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
 7265:                                                                                   $cdom,$cnum,$type,$configuserok,
 7266:                                                                                   $switchserver,$author_ok);
 7267:                                     if ($imgurl) {
 7268:                                         $confhash{$type}{$key}{'image'} = $imgurl;
 7269:                                         $changes{$type}{$key} = 1; 
 7270:                                     }
 7271:                                     if ($error) {
 7272:                                         &Apache::lonnet::logthis($error);
 7273:                                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 7274:                                     } 
 7275:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
 7276:                                     $confhash{$type}{$key}{'image'} = 
 7277:                                         $domconfig{$action}{$type}{$key}{'image'};
 7278:                                 }
 7279:                             }
 7280:                         }
 7281:                     }
 7282:                 }
 7283:             }
 7284:         } else {
 7285:             if ($confhash{'notify'}{'approval'}) {
 7286:                 $changes{'notify'}{'approval'} = 1;
 7287:             }
 7288:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
 7289:                 $changes{'uniquecode'} = 1;
 7290:             }
 7291:         }
 7292:         if ($context eq 'requestcourses') {
 7293:             foreach my $type ('textbooks','templates') {
 7294:                 if ($newbook{$type}) {
 7295:                     $changes{$type}{$newbook{$type}} = 1;
 7296:                     foreach my $item ('subject','title','publisher','author') {
 7297:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
 7298:                                  ($type eq 'template'));
 7299:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
 7300:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
 7301:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
 7302:                         }
 7303:                     }
 7304:                     if ($type eq 'textbooks') {
 7305:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
 7306:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
 7307:                             my ($imageurl,$error) =
 7308:                                 &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
 7309:                                                         $configuserok,$switchserver,$author_ok);
 7310:                             if ($imageurl) {
 7311:                                 $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
 7312:                             }
 7313:                             if ($error) {
 7314:                                 &Apache::lonnet::logthis($error);
 7315:                                 $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 7316:                             }
 7317:                         }
 7318:                     }
 7319:                 }
 7320:                 if (@{$allpos{$type}} > 0) {
 7321:                     my $idx = 0;
 7322:                     foreach my $item (@{$allpos{$type}}) {
 7323:                         if ($item ne '') {
 7324:                             $confhash{$type}{$item}{'order'} = $idx;
 7325:                             if (ref($domconfig{$action}) eq 'HASH') {
 7326:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
 7327:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
 7328:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
 7329:                                             $changes{$type}{$item} = 1;
 7330:                                         }
 7331:                                     }
 7332:                                 }
 7333:                             }
 7334:                             $idx ++;
 7335:                         }
 7336:                     }
 7337:                 }
 7338:             }
 7339:             if (ref($validationitemsref) eq 'ARRAY') {
 7340:                 foreach my $item (@{$validationitemsref}) {
 7341:                     if ($item eq 'fields') {
 7342:                         my @changed;
 7343:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
 7344:                         if (@{$confhash{'validation'}{$item}} > 0) {
 7345:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
 7346:                         }
 7347:                         if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
 7348:                             if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
 7349:                                 @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
 7350:                                                                               $domconfig{'requestcourses'}{'validation'}{$item});
 7351:                             } else {
 7352:                                 @changed = @{$confhash{'validation'}{$item}};
 7353:                             }
 7354:                         } else {
 7355:                             @changed = @{$confhash{'validation'}{$item}};
 7356:                         }
 7357:                         if (@changed) {
 7358:                             if ($confhash{'validation'}{$item}) {
 7359:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
 7360:                             } else {
 7361:                                 $changes{'validation'}{$item} = &mt('None');
 7362:                             }
 7363:                         }
 7364:                     } else {
 7365:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
 7366:                         if ($item eq 'markup') {
 7367:                             if ($env{'form.requestcourses_validation_'.$item}) {
 7368:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
 7369:                             }
 7370:                         }
 7371:                         if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
 7372:                             if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
 7373:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
 7374:                             }
 7375:                         } else {
 7376:                             if ($confhash{'validation'}{$item} ne '') {
 7377:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
 7378:                             }
 7379:                         }
 7380:                     }
 7381:                 }
 7382:             }
 7383:             if ($env{'form.validationdc'}) {
 7384:                 my $newval = $env{'form.validationdc'};
 7385:                 my %domcoords = &get_active_dcs($dom);
 7386:                 if (exists($domcoords{$newval})) {
 7387:                     $confhash{'validation'}{'dc'} = $newval;
 7388:                 }
 7389:             }
 7390:             if (ref($confhash{'validation'}) eq 'HASH') {
 7391:                 if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
 7392:                     if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
 7393:                         unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
 7394:                             if ($confhash{'validation'}{'dc'} eq '') {
 7395:                                 $changes{'validation'}{'dc'} = &mt('None');
 7396:                             } else {
 7397:                                 $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
 7398:                             }
 7399:                         }
 7400:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
 7401:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
 7402:                     }
 7403:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
 7404:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
 7405:                 }
 7406:             } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
 7407:                 if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
 7408:                     $changes{'validation'}{'dc'} = &mt('None');
 7409:                 }
 7410:             }
 7411:         }
 7412:     } else {
 7413:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 7414:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
 7415:     }
 7416:     foreach my $item (@usertools) {
 7417:         foreach my $type (@{$types},'default','_LC_adv') {
 7418:             my $unset; 
 7419:             if ($context eq 'requestcourses') {
 7420:                 $unset = '0';
 7421:                 if ($type eq '_LC_adv') {
 7422:                     $unset = '';
 7423:                 }
 7424:                 if ($confhash{$item}{$type} eq 'autolimit') {
 7425:                     $confhash{$item}{$type} .= '=';
 7426:                     unless ($limithash{$item}{$type} =~ /\D/) {
 7427:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
 7428:                     }
 7429:                 }
 7430:             } elsif ($context eq 'requestauthor') {
 7431:                 $unset = '0';
 7432:                 if ($type eq '_LC_adv') {
 7433:                     $unset = '';
 7434:                 }
 7435:             } else {
 7436:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 7437:                     $confhash{$item}{$type} = 1;
 7438:                 } else {
 7439:                     $confhash{$item}{$type} = 0;
 7440:                 }
 7441:             }
 7442:             if (ref($domconfig{$action}) eq 'HASH') {
 7443:                 if ($action eq 'requestauthor') {
 7444:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
 7445:                         $changes{$type} = 1;
 7446:                     }
 7447:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
 7448:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
 7449:                         $changes{$item}{$type} = 1;
 7450:                     }
 7451:                 } else {
 7452:                     if ($context eq 'requestcourses') {
 7453:                         if ($confhash{$item}{$type} ne $unset) {
 7454:                             $changes{$item}{$type} = 1;
 7455:                         }
 7456:                     } else {
 7457:                         if (!$confhash{$item}{$type}) {
 7458:                             $changes{$item}{$type} = 1;
 7459:                         }
 7460:                     }
 7461:                 }
 7462:             } else {
 7463:                 if ($context eq 'requestcourses') {
 7464:                     if ($confhash{$item}{$type} ne $unset) {
 7465:                         $changes{$item}{$type} = 1;
 7466:                     }
 7467:                 } elsif ($context eq 'requestauthor') {
 7468:                     if ($confhash{$type} ne $unset) {
 7469:                         $changes{$type} = 1;
 7470:                     }
 7471:                 } else {
 7472:                     if (!$confhash{$item}{$type}) {
 7473:                         $changes{$item}{$type} = 1;
 7474:                     }
 7475:                 }
 7476:             }
 7477:         }
 7478:     }
 7479:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 7480:         if (ref($domconfig{'quotas'}) eq 'HASH') {
 7481:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 7482:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 7483:                     if (exists($confhash{'defaultquota'}{$key})) {
 7484:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 7485:                             $changes{'defaultquota'}{$key} = 1;
 7486:                         }
 7487:                     } else {
 7488:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 7489:                     }
 7490:                 }
 7491:             } else {
 7492:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
 7493:                     if (exists($confhash{'defaultquota'}{$key})) {
 7494:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 7495:                             $changes{'defaultquota'}{$key} = 1;
 7496:                         }
 7497:                     } else {
 7498:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 7499:                     }
 7500:                 }
 7501:             }
 7502:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 7503:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
 7504:                     if (exists($confhash{'authorquota'}{$key})) {
 7505:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
 7506:                             $changes{'authorquota'}{$key} = 1;
 7507:                         }
 7508:                     } else {
 7509:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
 7510:                     }
 7511:                 }
 7512:             }
 7513:         }
 7514:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
 7515:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 7516:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 7517:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 7518:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 7519:                             $changes{'defaultquota'}{$key} = 1;
 7520:                         }
 7521:                     } else {
 7522:                         if (!exists($domconfig{'quotas'}{$key})) {
 7523:                             $changes{'defaultquota'}{$key} = 1;
 7524:                         }
 7525:                     }
 7526:                 } else {
 7527:                     $changes{'defaultquota'}{$key} = 1;
 7528:                 }
 7529:             }
 7530:         }
 7531:         if (ref($confhash{'authorquota'}) eq 'HASH') {
 7532:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
 7533:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 7534:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 7535:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
 7536:                             $changes{'authorquota'}{$key} = 1;
 7537:                         }
 7538:                     } else {
 7539:                         $changes{'authorquota'}{$key} = 1;
 7540:                     }
 7541:                 } else {
 7542:                     $changes{'authorquota'}{$key} = 1;
 7543:                 }
 7544:             }
 7545:         }
 7546:     }
 7547: 
 7548:     if ($context eq 'requestauthor') {
 7549:         $domdefaults{'requestauthor'} = \%confhash;
 7550:     } else {
 7551:         foreach my $key (keys(%confhash)) {
 7552:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
 7553:                 $domdefaults{$key} = $confhash{$key};
 7554:             }
 7555:         }
 7556:     }
 7557: 
 7558:     my %quotahash = (
 7559:                       $action => { %confhash }
 7560:                     );
 7561:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 7562:                                              $dom);
 7563:     if ($putresult eq 'ok') {
 7564:         if (keys(%changes) > 0) {
 7565:             my $cachetime = 24*60*60;
 7566:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 7567:             if (ref($lastactref) eq 'HASH') {
 7568:                 $lastactref->{'domdefaults'} = 1;
 7569:             }
 7570:             $resulttext = &mt('Changes made:').'<ul>';
 7571:             unless (($context eq 'requestcourses') ||
 7572:                     ($context eq 'requestauthor')) {
 7573:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
 7574:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 7575:                     foreach my $type (@{$types},'default') {
 7576:                         if (defined($changes{'defaultquota'}{$type})) {
 7577:                             my $typetitle = $usertypes->{$type};
 7578:                             if ($type eq 'default') {
 7579:                                 $typetitle = $othertitle;
 7580:                             }
 7581:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 7582:                         }
 7583:                     }
 7584:                     $resulttext .= '</ul></li>';
 7585:                 }
 7586:                 if (ref($changes{'authorquota'}) eq 'HASH') {
 7587:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
 7588:                     foreach my $type (@{$types},'default') {
 7589:                         if (defined($changes{'authorquota'}{$type})) {
 7590:                             my $typetitle = $usertypes->{$type};
 7591:                             if ($type eq 'default') {
 7592:                                 $typetitle = $othertitle;
 7593:                             }
 7594:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
 7595:                         }
 7596:                     }
 7597:                     $resulttext .= '</ul></li>';
 7598:                 }
 7599:             }
 7600:             my %newenv;
 7601:             foreach my $item (@usertools) {
 7602:                 my (%haschgs,%inconf);
 7603:                 if ($context eq 'requestauthor') {
 7604:                     %haschgs = %changes;
 7605:                     %inconf = %confhash;
 7606:                 } else {
 7607:                     if (ref($changes{$item}) eq 'HASH') {
 7608:                         %haschgs = %{$changes{$item}};
 7609:                     }
 7610:                     if (ref($confhash{$item}) eq 'HASH') {
 7611:                         %inconf = %{$confhash{$item}};
 7612:                     }
 7613:                 }
 7614:                 if (keys(%haschgs) > 0) {
 7615:                     my $newacc = 
 7616:                         &Apache::lonnet::usertools_access($env{'user.name'},
 7617:                                                           $env{'user.domain'},
 7618:                                                           $item,'reload',$context);
 7619:                     if (($context eq 'requestcourses') ||
 7620:                         ($context eq 'requestauthor')) {
 7621:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
 7622:                             $newenv{'environment.canrequest.'.$item} = $newacc;
 7623:                         }
 7624:                     } else {
 7625:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 7626:                             $newenv{'environment.availabletools.'.$item} = $newacc;
 7627:                         }
 7628:                     }
 7629:                     unless ($context eq 'requestauthor') {
 7630:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
 7631:                     }
 7632:                     foreach my $type (@{$types},'default','_LC_adv') {
 7633:                         if ($haschgs{$type}) {
 7634:                             my $typetitle = $usertypes->{$type};
 7635:                             if ($type eq 'default') {
 7636:                                 $typetitle = $othertitle;
 7637:                             } elsif ($type eq '_LC_adv') {
 7638:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 7639:                             }
 7640:                             if ($inconf{$type}) {
 7641:                                 if ($context eq 'requestcourses') {
 7642:                                     my $cond;
 7643:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
 7644:                                         if ($1 eq '') {
 7645:                                             $cond = &mt('(Automatic processing of any request).');
 7646:                                         } else {
 7647:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
 7648:                                         }
 7649:                                     } else { 
 7650:                                         $cond = $conditions{$inconf{$type}};
 7651:                                     }
 7652:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
 7653:                                 } elsif ($context eq 'requestauthor') {
 7654:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
 7655:                                                              $titles{$inconf{$type}},$typetitle);
 7656: 
 7657:                                 } else {
 7658:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 7659:                                 }
 7660:                             } else {
 7661:                                 if ($type eq '_LC_adv') {
 7662:                                     if ($inconf{$type} eq '0') {
 7663:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 7664:                                     } else { 
 7665:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
 7666:                                     }
 7667:                                 } else {
 7668:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 7669:                                 }
 7670:                             }
 7671:                         }
 7672:                     }
 7673:                     unless ($context eq 'requestauthor') {
 7674:                         $resulttext .= '</ul></li>';
 7675:                     }
 7676:                 }
 7677:             }
 7678:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
 7679:                 if (ref($changes{'notify'}) eq 'HASH') {
 7680:                     if ($changes{'notify'}{'approval'}) {
 7681:                         if (ref($confhash{'notify'}) eq 'HASH') {
 7682:                             if ($confhash{'notify'}{'approval'}) {
 7683:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
 7684:                             } else {
 7685:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
 7686:                             }
 7687:                         }
 7688:                     }
 7689:                 }
 7690:             }
 7691:             if ($action eq 'requestcourses') {
 7692:                 my @offon = ('off','on');
 7693:                 if ($changes{'uniquecode'}) {
 7694:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
 7695:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
 7696:                         $resulttext .= '<li>'.
 7697:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
 7698:                                        '</li>';
 7699:                     } else {
 7700:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
 7701:                                        '</li>';
 7702:                     }
 7703:                 }
 7704:                 foreach my $type ('textbooks','templates') {
 7705:                     if (ref($changes{$type}) eq 'HASH') {
 7706:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
 7707:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
 7708:                             my %coursehash = &Apache::lonnet::coursedescription($key);
 7709:                             my $coursetitle = $coursehash{'description'};
 7710:                             my $position = $confhash{$type}{$key}{'order'} + 1;
 7711:                             $resulttext .= '<li>';
 7712:                             foreach my $item ('subject','title','publisher','author') {
 7713:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
 7714:                                          ($type eq 'templates'));
 7715:                                 my $name = $item.':';
 7716:                                 $name =~ s/^(\w)/\U$1/;
 7717:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
 7718:                             }
 7719:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
 7720:                             if ($type eq 'textbooks') {
 7721:                                 if ($confhash{$type}{$key}{'image'}) {
 7722:                                     $resulttext .= ' '.&mt('Image: [_1]',
 7723:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
 7724:                                                    ' alt="Textbook cover" />').'<br />';
 7725:                                 }
 7726:                             }
 7727:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
 7728:                         }
 7729:                         $resulttext .= '</ul></li>';
 7730:                     }
 7731:                 }
 7732:                 if (ref($changes{'validation'}) eq 'HASH') {
 7733:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
 7734:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
 7735:                         foreach my $item (@{$validationitemsref}) {
 7736:                             if (exists($changes{'validation'}{$item})) {
 7737:                                 if ($item eq 'markup') {
 7738:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
 7739:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
 7740:                                 } else {
 7741:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
 7742:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
 7743:                                 }
 7744:                             }
 7745:                         }
 7746:                         if (exists($changes{'validation'}{'dc'})) {
 7747:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
 7748:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
 7749:                         }
 7750:                     }
 7751:                 }
 7752:             }
 7753:             $resulttext .= '</ul>';
 7754:             if (keys(%newenv)) {
 7755:                 &Apache::lonnet::appenv(\%newenv);
 7756:             }
 7757:         } else {
 7758:             if ($context eq 'requestcourses') {
 7759:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
 7760:             } elsif ($context eq 'requestauthor') {
 7761:                 $resulttext = &mt('No changes made to rights to request author space.');
 7762:             } else {
 7763:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
 7764:             }
 7765:         }
 7766:     } else {
 7767:         $resulttext = '<span class="LC_error">'.
 7768: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 7769:     }
 7770:     if ($errors) {
 7771:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
 7772:                        '<ul>'.$errors.'</ul></p>';
 7773:     }
 7774:     return $resulttext;
 7775: }
 7776: 
 7777: sub process_textbook_image {
 7778:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
 7779:     my $filename = $env{'form.'.$caller.'.filename'};
 7780:     my ($error,$url);
 7781:     my ($width,$height) = (50,50);
 7782:     if ($configuserok eq 'ok') {
 7783:         if ($switchserver) {
 7784:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
 7785:                          $switchserver);
 7786:         } elsif ($author_ok eq 'ok') {
 7787:             my ($result,$imageurl) =
 7788:                 &publishlogo($r,'upload',$caller,$dom,$confname,
 7789:                              "$type/$dom/$cnum/cover",$width,$height);
 7790:             if ($result eq 'ok') {
 7791:                 $url = $imageurl;
 7792:             } else {
 7793:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
 7794:             }
 7795:         } else {
 7796:             $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);
 7797:         }
 7798:     } else {
 7799:         $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);
 7800:     }
 7801:     return ($url,$error);
 7802: }
 7803: 
 7804: sub modify_autoenroll {
 7805:     my ($dom,$lastactref,%domconfig) = @_;
 7806:     my ($resulttext,%changes);
 7807:     my %currautoenroll;
 7808:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 7809:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 7810:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 7811:         }
 7812:     }
 7813:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 7814:     my %title = ( run => 'Auto-enrollment active',
 7815:                   sender => 'Sender for notification messages',
 7816:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
 7817:     my @offon = ('off','on');
 7818:     my $sender_uname = $env{'form.sender_uname'};
 7819:     my $sender_domain = $env{'form.sender_domain'};
 7820:     if ($sender_domain eq '') {
 7821:         $sender_uname = '';
 7822:     } elsif ($sender_uname eq '') {
 7823:         $sender_domain = '';
 7824:     }
 7825:     my $coowners = $env{'form.autoassign_coowners'};
 7826:     my %autoenrollhash =  (
 7827:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
 7828:                                        'sender_uname' => $sender_uname,
 7829:                                        'sender_domain' => $sender_domain,
 7830:                                        'co-owners' => $coowners,
 7831:                                 }
 7832:                      );
 7833:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 7834:                                              $dom);
 7835:     if ($putresult eq 'ok') {
 7836:         if (exists($currautoenroll{'run'})) {
 7837:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 7838:                  $changes{'run'} = 1;
 7839:              }
 7840:         } elsif ($autorun) {
 7841:             if ($env{'form.autoenroll_run'} ne '1') {
 7842:                  $changes{'run'} = 1;
 7843:             }
 7844:         }
 7845:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 7846:             $changes{'sender'} = 1;
 7847:         }
 7848:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 7849:             $changes{'sender'} = 1;
 7850:         }
 7851:         if ($currautoenroll{'co-owners'} ne '') {
 7852:             if ($currautoenroll{'co-owners'} ne $coowners) {
 7853:                 $changes{'coowners'} = 1;
 7854:             }
 7855:         } elsif ($coowners) {
 7856:             $changes{'coowners'} = 1;
 7857:         }      
 7858:         if (keys(%changes) > 0) {
 7859:             $resulttext = &mt('Changes made:').'<ul>';
 7860:             if ($changes{'run'}) {
 7861:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 7862:             }
 7863:             if ($changes{'sender'}) {
 7864:                 if ($sender_uname eq '' || $sender_domain eq '') {
 7865:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 7866:                 } else {
 7867:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 7868:                 }
 7869:             }
 7870:             if ($changes{'coowners'}) {
 7871:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
 7872:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 7873:                 if (ref($lastactref) eq 'HASH') {
 7874:                     $lastactref->{'domainconfig'} = 1;
 7875:                 }
 7876:             }
 7877:             $resulttext .= '</ul>';
 7878:         } else {
 7879:             $resulttext = &mt('No changes made to auto-enrollment settings');
 7880:         }
 7881:     } else {
 7882:         $resulttext = '<span class="LC_error">'.
 7883: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 7884:     }
 7885:     return $resulttext;
 7886: }
 7887: 
 7888: sub modify_autoupdate {
 7889:     my ($dom,%domconfig) = @_;
 7890:     my ($resulttext,%currautoupdate,%fields,%changes);
 7891:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 7892:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 7893:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 7894:         }
 7895:     }
 7896:     my @offon = ('off','on');
 7897:     my %title = &Apache::lonlocal::texthash (
 7898:                    run => 'Auto-update:',
 7899:                    classlists => 'Updates to user information in classlists?'
 7900:                 );
 7901:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 7902:     my %fieldtitles = &Apache::lonlocal::texthash (
 7903:                         id => 'Student/Employee ID',
 7904:                         permanentemail => 'E-mail address',
 7905:                         lastname => 'Last Name',
 7906:                         firstname => 'First Name',
 7907:                         middlename => 'Middle Name',
 7908:                         generation => 'Generation',
 7909:                       );
 7910:     $othertitle = &mt('All users');
 7911:     if (keys(%{$usertypes}) >  0) {
 7912:         $othertitle = &mt('Other users');
 7913:     }
 7914:     foreach my $key (keys(%env)) {
 7915:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 7916:             my ($usertype,$item) = ($1,$2);
 7917:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
 7918:                 if ($usertype eq 'default') {   
 7919:                     push(@{$fields{$1}},$2);
 7920:                 } elsif (ref($types) eq 'ARRAY') {
 7921:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
 7922:                         push(@{$fields{$1}},$2);
 7923:                     }
 7924:                 }
 7925:             }
 7926:         }
 7927:     }
 7928:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
 7929:     @lockablenames = sort(@lockablenames);
 7930:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
 7931:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 7932:         if (@changed) {
 7933:             $changes{'lockablenames'} = 1;
 7934:         }
 7935:     } else {
 7936:         if (@lockablenames) {
 7937:             $changes{'lockablenames'} = 1;
 7938:         }
 7939:     }
 7940:     my %updatehash = (
 7941:                       autoupdate => { run => $env{'form.autoupdate_run'},
 7942:                                       classlists => $env{'form.classlists'},
 7943:                                       fields => {%fields},
 7944:                                       lockablenames => \@lockablenames,
 7945:                                     }
 7946:                      );
 7947:     foreach my $key (keys(%currautoupdate)) {
 7948:         if (($key eq 'run') || ($key eq 'classlists')) {
 7949:             if (exists($updatehash{autoupdate}{$key})) {
 7950:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 7951:                     $changes{$key} = 1;
 7952:                 }
 7953:             }
 7954:         } elsif ($key eq 'fields') {
 7955:             if (ref($currautoupdate{$key}) eq 'HASH') {
 7956:                 foreach my $item (@{$types},'default') {
 7957:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 7958:                         my $change = 0;
 7959:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 7960:                             if (!exists($fields{$item})) {
 7961:                                 $change = 1;
 7962:                                 last;
 7963:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 7964:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 7965:                                     $change = 1;
 7966:                                     last;
 7967:                                 }
 7968:                             }
 7969:                         }
 7970:                         if ($change) {
 7971:                             push(@{$changes{$key}},$item);
 7972:                         }
 7973:                     } 
 7974:                 }
 7975:             }
 7976:         } elsif ($key eq 'lockablenames') {
 7977:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
 7978:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 7979:                 if (@changed) {
 7980:                     $changes{'lockablenames'} = 1;
 7981:                 }
 7982:             } else {
 7983:                 if (@lockablenames) {
 7984:                     $changes{'lockablenames'} = 1;
 7985:                 }
 7986:             }
 7987:         }
 7988:     }
 7989:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
 7990:         if (@lockablenames) {
 7991:             $changes{'lockablenames'} = 1;
 7992:         }
 7993:     }
 7994:     foreach my $item (@{$types},'default') {
 7995:         if (defined($fields{$item})) {
 7996:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 7997:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
 7998:                     my $change = 0;
 7999:                     if (ref($fields{$item}) eq 'ARRAY') {
 8000:                         foreach my $type (@{$fields{$item}}) {
 8001:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
 8002:                                 $change = 1;
 8003:                                 last;
 8004:                             }
 8005:                         }
 8006:                     }
 8007:                     if ($change) {
 8008:                         push(@{$changes{'fields'}},$item);
 8009:                     }
 8010:                 } else {
 8011:                     push(@{$changes{'fields'}},$item);
 8012:                 }
 8013:             } else {
 8014:                 push(@{$changes{'fields'}},$item);
 8015:             }
 8016:         }
 8017:     }
 8018:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 8019:                                              $dom);
 8020:     if ($putresult eq 'ok') {
 8021:         if (keys(%changes) > 0) {
 8022:             $resulttext = &mt('Changes made:').'<ul>';
 8023:             foreach my $key (sort(keys(%changes))) {
 8024:                 if ($key eq 'lockablenames') {
 8025:                     $resulttext .= '<li>';
 8026:                     if (@lockablenames) {
 8027:                         $usertypes->{'default'} = $othertitle;
 8028:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
 8029:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
 8030:                     } else {
 8031:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
 8032:                     }
 8033:                     $resulttext .= '</li>';
 8034:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
 8035:                     foreach my $item (@{$changes{$key}}) {
 8036:                         my @newvalues;
 8037:                         foreach my $type (@{$fields{$item}}) {
 8038:                             push(@newvalues,$fieldtitles{$type});
 8039:                         }
 8040:                         my $newvaluestr;
 8041:                         if (@newvalues > 0) {
 8042:                             $newvaluestr = join(', ',@newvalues);
 8043:                         } else {
 8044:                             $newvaluestr = &mt('none');
 8045:                         }
 8046:                         if ($item eq 'default') {
 8047:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 8048:                         } else {
 8049:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 8050:                         }
 8051:                     }
 8052:                 } else {
 8053:                     my $newvalue;
 8054:                     if ($key eq 'run') {
 8055:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 8056:                     } else {
 8057:                         $newvalue = $offon[$env{'form.'.$key}];
 8058:                     }
 8059:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 8060:                 }
 8061:             }
 8062:             $resulttext .= '</ul>';
 8063:         } else {
 8064:             $resulttext = &mt('No changes made to autoupdates');
 8065:         }
 8066:     } else {
 8067:         $resulttext = '<span class="LC_error">'.
 8068: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 8069:     }
 8070:     return $resulttext;
 8071: }
 8072: 
 8073: sub modify_autocreate {
 8074:     my ($dom,%domconfig) = @_;
 8075:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
 8076:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
 8077:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
 8078:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
 8079:         }
 8080:     }
 8081:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
 8082:                  req => 'Auto-creation of validated requests for official courses',
 8083:                  xmldc => 'Identity of course creator of courses from XML files',
 8084:                );
 8085:     my @types = ('xml','req');
 8086:     foreach my $item (@types) {
 8087:         $newvals{$item} = $env{'form.autocreate_'.$item};
 8088:         $newvals{$item} =~ s/\D//g;
 8089:         $newvals{$item} = 0 if ($newvals{$item} eq '');
 8090:     }
 8091:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
 8092:     my %domcoords = &get_active_dcs($dom);
 8093:     unless (exists($domcoords{$newvals{'xmldc'}})) {
 8094:         $newvals{'xmldc'} = '';
 8095:     } 
 8096:     %autocreatehash =  (
 8097:                         autocreate => { xml => $newvals{'xml'},
 8098:                                         req => $newvals{'req'},
 8099:                                       }
 8100:                        );
 8101:     if ($newvals{'xmldc'} ne '') {
 8102:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
 8103:     }
 8104:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
 8105:                                              $dom);
 8106:     if ($putresult eq 'ok') {
 8107:         my @items = @types;
 8108:         if ($newvals{'xml'}) {
 8109:             push(@items,'xmldc');
 8110:         }
 8111:         foreach my $item (@items) {
 8112:             if (exists($currautocreate{$item})) {
 8113:                 if ($currautocreate{$item} ne $newvals{$item}) {
 8114:                     $changes{$item} = 1;
 8115:                 }
 8116:             } elsif ($newvals{$item}) {
 8117:                 $changes{$item} = 1;
 8118:             }
 8119:         }
 8120:         if (keys(%changes) > 0) {
 8121:             my @offon = ('off','on'); 
 8122:             $resulttext = &mt('Changes made:').'<ul>';
 8123:             foreach my $item (@types) {
 8124:                 if ($changes{$item}) {
 8125:                     my $newtxt = $offon[$newvals{$item}];
 8126:                     $resulttext .= '<li>'.
 8127:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
 8128:                                        '<b>','</b>').
 8129:                                    '</li>';
 8130:                 }
 8131:             }
 8132:             if ($changes{'xmldc'}) {
 8133:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
 8134:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
 8135:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
 8136:             }
 8137:             $resulttext .= '</ul>';
 8138:         } else {
 8139:             $resulttext = &mt('No changes made to auto-creation settings');
 8140:         }
 8141:     } else {
 8142:         $resulttext = '<span class="LC_error">'.
 8143:             &mt('An error occurred: [_1]',$putresult).'</span>';
 8144:     }
 8145:     return $resulttext;
 8146: }
 8147: 
 8148: sub modify_directorysrch {
 8149:     my ($dom,%domconfig) = @_;
 8150:     my ($resulttext,%changes);
 8151:     my %currdirsrch;
 8152:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 8153:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 8154:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 8155:         }
 8156:     }
 8157:     my %title = ( available => 'Directory search available',
 8158:                   localonly => 'Other domains can search',
 8159:                   searchby => 'Search types',
 8160:                   searchtypes => 'Search latitude');
 8161:     my @offon = ('off','on');
 8162:     my @otherdoms = ('Yes','No');
 8163: 
 8164:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 8165:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 8166:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 8167: 
 8168:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 8169:     if (keys(%{$usertypes}) == 0) {
 8170:         @cansearch = ('default');
 8171:     } else {
 8172:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 8173:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 8174:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 8175:                     push(@{$changes{'cansearch'}},$type);
 8176:                 }
 8177:             }
 8178:             foreach my $type (@cansearch) {
 8179:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 8180:                     push(@{$changes{'cansearch'}},$type);
 8181:                 }
 8182:             }
 8183:         } else {
 8184:             push(@{$changes{'cansearch'}},@cansearch);
 8185:         }
 8186:     }
 8187: 
 8188:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 8189:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 8190:             if (!grep(/^\Q$by\E$/,@searchby)) {
 8191:                 push(@{$changes{'searchby'}},$by);
 8192:             }
 8193:         }
 8194:         foreach my $by (@searchby) {
 8195:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 8196:                 push(@{$changes{'searchby'}},$by);
 8197:             }
 8198:         }
 8199:     } else {
 8200:         push(@{$changes{'searchby'}},@searchby);
 8201:     }
 8202: 
 8203:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 8204:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 8205:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 8206:                 push(@{$changes{'searchtypes'}},$type);
 8207:             }
 8208:         }
 8209:         foreach my $type (@searchtypes) {
 8210:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 8211:                 push(@{$changes{'searchtypes'}},$type);
 8212:             }
 8213:         }
 8214:     } else {
 8215:         if (exists($currdirsrch{'searchtypes'})) {
 8216:             foreach my $type (@searchtypes) {  
 8217:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 8218:                     push(@{$changes{'searchtypes'}},$type);
 8219:                 }
 8220:             }
 8221:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 8222:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 8223:             }   
 8224:         } else {
 8225:             push(@{$changes{'searchtypes'}},@searchtypes); 
 8226:         }
 8227:     }
 8228: 
 8229:     my %dirsrch_hash =  (
 8230:             directorysrch => { available => $env{'form.dirsrch_available'},
 8231:                                cansearch => \@cansearch,
 8232:                                localonly => $env{'form.dirsrch_localonly'},
 8233:                                searchby => \@searchby,
 8234:                                searchtypes => \@searchtypes,
 8235:                              }
 8236:             );
 8237:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 8238:                                              $dom);
 8239:     if ($putresult eq 'ok') {
 8240:         if (exists($currdirsrch{'available'})) {
 8241:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 8242:                  $changes{'available'} = 1;
 8243:              }
 8244:         } else {
 8245:             if ($env{'form.dirsrch_available'} eq '1') {
 8246:                 $changes{'available'} = 1;
 8247:             }
 8248:         }
 8249:         if (exists($currdirsrch{'localonly'})) {
 8250:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 8251:                  $changes{'localonly'} = 1;
 8252:              }
 8253:         } else {
 8254:             if ($env{'form.dirsrch_localonly'} eq '1') {
 8255:                 $changes{'localonly'} = 1;
 8256:             }
 8257:         }
 8258:         if (keys(%changes) > 0) {
 8259:             $resulttext = &mt('Changes made:').'<ul>';
 8260:             if ($changes{'available'}) {
 8261:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 8262:             }
 8263:             if ($changes{'localonly'}) {
 8264:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 8265:             }
 8266: 
 8267:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 8268:                 my $chgtext;
 8269:                 if (ref($usertypes) eq 'HASH') {
 8270:                     if (keys(%{$usertypes}) > 0) {
 8271:                         foreach my $type (@{$types}) {
 8272:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 8273:                                 $chgtext .= $usertypes->{$type}.'; ';
 8274:                             }
 8275:                         }
 8276:                         if (grep(/^default$/,@cansearch)) {
 8277:                             $chgtext .= $othertitle;
 8278:                         } else {
 8279:                             $chgtext =~ s/\; $//;
 8280:                         }
 8281:                         $resulttext .=
 8282:                             '<li>'.
 8283:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
 8284:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
 8285:                             '</li>';
 8286:                     }
 8287:                 }
 8288:             }
 8289:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 8290:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 8291:                 my $chgtext;
 8292:                 foreach my $type (@{$titleorder}) {
 8293:                     if (grep(/^\Q$type\E$/,@searchby)) {
 8294:                         if (defined($searchtitles->{$type})) {
 8295:                             $chgtext .= $searchtitles->{$type}.'; ';
 8296:                         }
 8297:                     }
 8298:                 }
 8299:                 $chgtext =~ s/\; $//;
 8300:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 8301:             }
 8302:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 8303:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 8304:                 my $chgtext;
 8305:                 foreach my $type (@{$srchtypeorder}) {
 8306:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 8307:                         if (defined($srchtypes_desc->{$type})) {
 8308:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 8309:                         }
 8310:                     }
 8311:                 }
 8312:                 $chgtext =~ s/\; $//;
 8313:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
 8314:             }
 8315:             $resulttext .= '</ul>';
 8316:         } else {
 8317:             $resulttext = &mt('No changes made to institution directory search settings');
 8318:         }
 8319:     } else {
 8320:         $resulttext = '<span class="LC_error">'.
 8321:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 8322:     }
 8323:     return $resulttext;
 8324: }
 8325: 
 8326: sub modify_contacts {
 8327:     my ($dom,$lastactref,%domconfig) = @_;
 8328:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 8329:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 8330:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 8331:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 8332:         }
 8333:     }
 8334:     my (%others,%to,%bcc);
 8335:     my @contacts = ('supportemail','adminemail');
 8336:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
 8337:                     'requestsmail','updatesmail','idconflictsmail');
 8338:     my @toggles = ('reporterrors','reportupdates');
 8339:     foreach my $type (@mailings) {
 8340:         @{$newsetting{$type}} = 
 8341:             &Apache::loncommon::get_env_multiple('form.'.$type);
 8342:         foreach my $item (@contacts) {
 8343:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 8344:                 $contacts_hash{contacts}{$type}{$item} = 1;
 8345:             } else {
 8346:                 $contacts_hash{contacts}{$type}{$item} = 0;
 8347:             }
 8348:         }  
 8349:         $others{$type} = $env{'form.'.$type.'_others'};
 8350:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 8351:         if ($type eq 'helpdeskmail') {
 8352:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
 8353:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
 8354:         }
 8355:     }
 8356:     foreach my $item (@contacts) {
 8357:         $to{$item} = $env{'form.'.$item};
 8358:         $contacts_hash{'contacts'}{$item} = $to{$item};
 8359:     }
 8360:     foreach my $item (@toggles) {
 8361:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
 8362:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
 8363:         }
 8364:     }
 8365:     if (keys(%currsetting) > 0) {
 8366:         foreach my $item (@contacts) {
 8367:             if ($to{$item} ne $currsetting{$item}) {
 8368:                 $changes{$item} = 1;
 8369:             }
 8370:         }
 8371:         foreach my $type (@mailings) {
 8372:             foreach my $item (@contacts) {
 8373:                 if (ref($currsetting{$type}) eq 'HASH') {
 8374:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 8375:                         push(@{$changes{$type}},$item);
 8376:                     }
 8377:                 } else {
 8378:                     push(@{$changes{$type}},@{$newsetting{$type}});
 8379:                 }
 8380:             }
 8381:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 8382:                 push(@{$changes{$type}},'others');
 8383:             }
 8384:             if ($type eq 'helpdeskmail') {   
 8385:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
 8386:                     push(@{$changes{$type}},'bcc'); 
 8387:                 }
 8388:             }
 8389:         }
 8390:     } else {
 8391:         my %default;
 8392:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 8393:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 8394:         $default{'errormail'} = 'adminemail';
 8395:         $default{'packagesmail'} = 'adminemail';
 8396:         $default{'helpdeskmail'} = 'supportemail';
 8397:         $default{'lonstatusmail'} = 'adminemail';
 8398:         $default{'requestsmail'} = 'adminemail';
 8399:         $default{'updatesmail'} = 'adminemail';
 8400:         foreach my $item (@contacts) {
 8401:            if ($to{$item} ne $default{$item}) {
 8402:               $changes{$item} = 1;
 8403:            }
 8404:         }
 8405:         foreach my $type (@mailings) {
 8406:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 8407:                
 8408:                 push(@{$changes{$type}},@{$newsetting{$type}});
 8409:             }
 8410:             if ($others{$type} ne '') {
 8411:                 push(@{$changes{$type}},'others');
 8412:             }
 8413:             if ($type eq 'helpdeskmail') {
 8414:                 if ($bcc{$type} ne '') {
 8415:                     push(@{$changes{$type}},'bcc');
 8416:                 }
 8417:             }
 8418:         }
 8419:     }
 8420:     foreach my $item (@toggles) {
 8421:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
 8422:             $changes{$item} = 1;
 8423:         } elsif ((!$env{'form.'.$item}) &&
 8424:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
 8425:             $changes{$item} = 1;
 8426:         }
 8427:     }
 8428:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 8429:                                              $dom);
 8430:     if ($putresult eq 'ok') {
 8431:         if (keys(%changes) > 0) {
 8432:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 8433:             if (ref($lastactref) eq 'HASH') {
 8434:                 $lastactref->{'domainconfig'} = 1;
 8435:             }
 8436:             my ($titles,$short_titles)  = &contact_titles();
 8437:             $resulttext = &mt('Changes made:').'<ul>';
 8438:             foreach my $item (@contacts) {
 8439:                 if ($changes{$item}) {
 8440:                     $resulttext .= '<li>'.$titles->{$item}.
 8441:                                     &mt(' set to: ').
 8442:                                     '<span class="LC_cusr_emph">'.
 8443:                                     $to{$item}.'</span></li>';
 8444:                 }
 8445:             }
 8446:             foreach my $type (@mailings) {
 8447:                 if (ref($changes{$type}) eq 'ARRAY') {
 8448:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 8449:                     my @text;
 8450:                     foreach my $item (@{$newsetting{$type}}) {
 8451:                         push(@text,$short_titles->{$item});
 8452:                     }
 8453:                     if ($others{$type} ne '') {
 8454:                         push(@text,$others{$type});
 8455:                     }
 8456:                     $resulttext .= '<span class="LC_cusr_emph">'.
 8457:                                    join(', ',@text).'</span>';
 8458:                     if ($type eq 'helpdeskmail') {
 8459:                         if ($bcc{$type} ne '') {
 8460:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
 8461:                         }
 8462:                     }
 8463:                     $resulttext .= '</li>';
 8464:                 }
 8465:             }
 8466:             my @offon = ('off','on');
 8467:             if ($changes{'reporterrors'}) {
 8468:                 $resulttext .= '<li>'.
 8469:                                &mt('E-mail error reports to [_1] set to "'.
 8470:                                    $offon[$env{'form.reporterrors'}].'".',
 8471:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 8472:                                        &mt('LON-CAPA core group - MSU'),600,500)).
 8473:                                '</li>';
 8474:             }
 8475:             if ($changes{'reportupdates'}) {
 8476:                 $resulttext .= '<li>'.
 8477:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
 8478:                                     $offon[$env{'form.reportupdates'}].'".',
 8479:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
 8480:                                         &mt('LON-CAPA core group - MSU'),600,500)).
 8481:                                 '</li>';
 8482:             }
 8483:             $resulttext .= '</ul>';
 8484:         } else {
 8485:             $resulttext = &mt('No changes made to contact information');
 8486:         }
 8487:     } else {
 8488:         $resulttext = '<span class="LC_error">'.
 8489:             &mt('An error occurred: [_1].',$putresult).'</span>';
 8490:     }
 8491:     return $resulttext;
 8492: }
 8493: 
 8494: sub modify_usercreation {
 8495:     my ($dom,%domconfig) = @_;
 8496:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
 8497:     my $warningmsg;
 8498:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 8499:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 8500:             if ($key eq 'cancreate') {
 8501:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
 8502:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
 8503:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
 8504:                             ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
 8505:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
 8506:                         } else {
 8507:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
 8508:                         }
 8509:                     }
 8510:                 }
 8511:             } elsif ($key eq 'email_rule') {
 8512:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
 8513:             } else {
 8514:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 8515:             }
 8516:         }
 8517:     }
 8518:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 8519:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 8520:     my @contexts = ('author','course','requestcrs');
 8521:     foreach my $item(@contexts) {
 8522:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
 8523:     }
 8524:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 8525:         foreach my $item (@contexts) {
 8526:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 8527:                 push(@{$changes{'cancreate'}},$item);
 8528:             }
 8529:         }
 8530:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 8531:         foreach my $item (@contexts) {
 8532:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 8533:                 if ($cancreate{$item} ne 'any') {
 8534:                     push(@{$changes{'cancreate'}},$item);
 8535:                 }
 8536:             } else {
 8537:                 if ($cancreate{$item} ne 'none') {
 8538:                     push(@{$changes{'cancreate'}},$item);
 8539:                 }
 8540:             }
 8541:         }
 8542:     } else {
 8543:         foreach my $item (@contexts)  {
 8544:             push(@{$changes{'cancreate'}},$item);
 8545:         }
 8546:     }
 8547: 
 8548:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 8549:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 8550:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 8551:                 push(@{$changes{'username_rule'}},$type);
 8552:             }
 8553:         }
 8554:         foreach my $type (@username_rule) {
 8555:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 8556:                 push(@{$changes{'username_rule'}},$type);
 8557:             }
 8558:         }
 8559:     } else {
 8560:         push(@{$changes{'username_rule'}},@username_rule);
 8561:     }
 8562: 
 8563:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 8564:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 8565:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 8566:                 push(@{$changes{'id_rule'}},$type);
 8567:             }
 8568:         }
 8569:         foreach my $type (@id_rule) {
 8570:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 8571:                 push(@{$changes{'id_rule'}},$type);
 8572:             }
 8573:         }
 8574:     } else {
 8575:         push(@{$changes{'id_rule'}},@id_rule);
 8576:     }
 8577: 
 8578:     my @authen_contexts = ('author','course','domain');
 8579:     my @authtypes = ('int','krb4','krb5','loc');
 8580:     my %authhash;
 8581:     foreach my $item (@authen_contexts) {
 8582:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 8583:         foreach my $auth (@authtypes) {
 8584:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 8585:                 $authhash{$item}{$auth} = 1;
 8586:             } else {
 8587:                 $authhash{$item}{$auth} = 0;
 8588:             }
 8589:         }
 8590:     }
 8591:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 8592:         foreach my $item (@authen_contexts) {
 8593:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 8594:                 foreach my $auth (@authtypes) {
 8595:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 8596:                         push(@{$changes{'authtypes'}},$item);
 8597:                         last;
 8598:                     }
 8599:                 }
 8600:             }
 8601:         }
 8602:     } else {
 8603:         foreach my $item (@authen_contexts) {
 8604:             push(@{$changes{'authtypes'}},$item);
 8605:         }
 8606:     }
 8607: 
 8608:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
 8609:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
 8610:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
 8611:     $save_usercreate{'id_rule'} = \@id_rule;
 8612:     $save_usercreate{'username_rule'} = \@username_rule,
 8613:     $save_usercreate{'authtypes'} = \%authhash;
 8614: 
 8615:     my %usercreation_hash =  (
 8616:         usercreation     => \%save_usercreate,
 8617:     );
 8618: 
 8619:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 8620:                                              $dom);
 8621: 
 8622:     if ($putresult eq 'ok') {
 8623:         if (keys(%changes) > 0) {
 8624:             $resulttext = &mt('Changes made:').'<ul>';
 8625:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 8626:                 my %lt = &usercreation_types();
 8627:                 foreach my $type (@{$changes{'cancreate'}}) {
 8628:                     my $chgtext = $lt{$type}.', ';
 8629:                     if ($cancreate{$type} eq 'none') {
 8630:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 8631:                     } elsif ($cancreate{$type} eq 'any') {
 8632:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 8633:                     } elsif ($cancreate{$type} eq 'official') {
 8634:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 8635:                     } elsif ($cancreate{$type} eq 'unofficial') {
 8636:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 8637:                     }
 8638:                     $resulttext .= '<li>'.$chgtext.'</li>';
 8639:                 }
 8640:             }
 8641:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 8642:                 my ($rules,$ruleorder) = 
 8643:                     &Apache::lonnet::inst_userrules($dom,'username');
 8644:                 my $chgtext = '<ul>';
 8645:                 foreach my $type (@username_rule) {
 8646:                     if (ref($rules->{$type}) eq 'HASH') {
 8647:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 8648:                     }
 8649:                 }
 8650:                 $chgtext .= '</ul>';
 8651:                 if (@username_rule > 0) {
 8652:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 8653:                 } else {
 8654:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 8655:                 }
 8656:             }
 8657:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 8658:                 my ($idrules,$idruleorder) = 
 8659:                     &Apache::lonnet::inst_userrules($dom,'id');
 8660:                 my $chgtext = '<ul>';
 8661:                 foreach my $type (@id_rule) {
 8662:                     if (ref($idrules->{$type}) eq 'HASH') {
 8663:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 8664:                     }
 8665:                 }
 8666:                 $chgtext .= '</ul>';
 8667:                 if (@id_rule > 0) {
 8668:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 8669:                 } else {
 8670:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 8671:                 }
 8672:             }
 8673:             my %authname = &authtype_names();
 8674:             my %context_title = &context_names();
 8675:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 8676:                 my $chgtext = '<ul>';
 8677:                 foreach my $type (@{$changes{'authtypes'}}) {
 8678:                     my @allowed;
 8679:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 8680:                     foreach my $auth (@authtypes) {
 8681:                         if ($authhash{$type}{$auth}) {
 8682:                             push(@allowed,$authname{$auth});
 8683:                         }
 8684:                     }
 8685:                     if (@allowed > 0) {
 8686:                         $chgtext .= join(', ',@allowed).'</li>';
 8687:                     } else {
 8688:                         $chgtext .= &mt('none').'</li>';
 8689:                     }
 8690:                 }
 8691:                 $chgtext .= '</ul>';
 8692:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 8693:                 $resulttext .= '</li>';
 8694:             }
 8695:             $resulttext .= '</ul>';
 8696:         } else {
 8697:             $resulttext = &mt('No changes made to user creation settings');
 8698:         }
 8699:     } else {
 8700:         $resulttext = '<span class="LC_error">'.
 8701:             &mt('An error occurred: [_1]',$putresult).'</span>';
 8702:     }
 8703:     if ($warningmsg ne '') {
 8704:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 8705:     }
 8706:     return $resulttext;
 8707: }
 8708: 
 8709: sub modify_selfcreation {
 8710:     my ($dom,%domconfig) = @_;
 8711:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
 8712:     my (%save_usercreate,%save_usermodify);
 8713:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 8714:     if (ref($types) eq 'ARRAY') {
 8715:         $usertypes->{'default'} = $othertitle;
 8716:         push(@{$types},'default');
 8717:     }
 8718: #
 8719: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
 8720: #
 8721:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 8722:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 8723:             if ($key eq 'cancreate') {
 8724:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
 8725:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
 8726:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
 8727:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') || 
 8728:                             ($item eq 'emailusername') || ($item eq 'notify') ||
 8729:                             ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
 8730:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
 8731:                         } else {
 8732:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
 8733:                         }
 8734:                     }
 8735:                 }
 8736:             } elsif ($key eq 'email_rule') {
 8737:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 8738:             } else {
 8739:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
 8740:             }
 8741:         }
 8742:     }
 8743: #
 8744: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
 8745: #
 8746:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 8747:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 8748:             if ($key eq 'selfcreate') {
 8749:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
 8750:             } else {
 8751:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
 8752:             }
 8753:         }
 8754:     }
 8755: 
 8756:     my @contexts = ('selfcreate');
 8757:     @{$cancreate{'selfcreate'}} = ();
 8758:     %{$cancreate{'emailusername'}} = ();
 8759:     @{$cancreate{'statustocreate'}} = ();
 8760:     %{$cancreate{'selfcreateprocessing'}} = ();
 8761:     %{$cancreate{'shibenv'}} = ();
 8762:     my %selfcreatetypes = (
 8763:                              sso   => 'users authenticated by institutional single sign on',
 8764:                              login => 'users authenticated by institutional log-in',
 8765:                              email => 'users who provide a valid e-mail address for use as username',
 8766:                           );
 8767: #
 8768: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
 8769: # is permitted.
 8770: #
 8771: 
 8772:     my @statuses;
 8773:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
 8774:         if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
 8775:             @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
 8776:         }
 8777:     }
 8778:     push(@statuses,'default');
 8779: 
 8780:     foreach my $item ('login','sso','email') {
 8781:         if ($item eq 'email') {
 8782:             if ($env{'form.cancreate_email'}) {
 8783:                 push(@{$cancreate{'selfcreate'}},'email');
 8784:                 push(@contexts,'selfcreateprocessing');
 8785:                 foreach my $type (@statuses) {
 8786:                     if ($type eq 'default') {
 8787:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
 8788:                     } else { 
 8789:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
 8790:                     }
 8791:                 }
 8792:             }
 8793:         } else {
 8794:             if ($env{'form.cancreate_'.$item}) {
 8795:                 push(@{$cancreate{'selfcreate'}},$item);
 8796:             }
 8797:         }
 8798:     }
 8799:     my (@email_rule,%userinfo,%savecaptcha);
 8800:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
 8801: #
 8802: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
 8803: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
 8804: #
 8805: 
 8806:     if ($env{'form.cancreate_email'}) {
 8807:         push(@contexts,'emailusername');
 8808:         if (ref($types) eq 'ARRAY') {
 8809:             foreach my $type (@{$types}) {
 8810:                 if (ref($infofields) eq 'ARRAY') {
 8811:                     foreach my $field (@{$infofields}) {
 8812:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
 8813:                             $cancreate{'emailusername'}{$type}{$field} = $1;
 8814:                         }
 8815:                     }
 8816:                 }
 8817:             }
 8818:         }
 8819: #
 8820: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
 8821: # queued requests for self-creation of account using e-mail address as username
 8822: #
 8823: 
 8824:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
 8825:         @approvalnotify = sort(@approvalnotify);
 8826:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
 8827:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 8828:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
 8829:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
 8830:                     push(@{$changes{'cancreate'}},'notify');
 8831:                 }
 8832:             } else {
 8833:                 if ($cancreate{'notify'}{'approval'}) {
 8834:                     push(@{$changes{'cancreate'}},'notify');
 8835:                 }
 8836:             }
 8837:         } elsif ($cancreate{'notify'}{'approval'}) {
 8838:             push(@{$changes{'cancreate'}},'notify');
 8839:         }
 8840: 
 8841: #
 8842: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
 8843: #
 8844:         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 8845:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
 8846:         if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 8847:             if (@{$curr_usercreation{'email_rule'}} > 0) {
 8848:                 foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 8849:                     if (!grep(/^\Q$type\E$/,@email_rule)) {
 8850:                         push(@{$changes{'email_rule'}},$type);
 8851:                     }
 8852:                 }
 8853:             }
 8854:             if (@email_rule > 0) {
 8855:                 foreach my $type (@email_rule) {
 8856:                     if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 8857:                         push(@{$changes{'email_rule'}},$type);
 8858:                     }
 8859:                 }
 8860:             }
 8861:         } elsif (@email_rule > 0) {
 8862:             push(@{$changes{'email_rule'}},@email_rule);
 8863:         }
 8864:     }
 8865: #  
 8866: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
 8867: # institutional log-in.
 8868: #
 8869:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
 8870:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
 8871:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
 8872:                ($domdefaults{'auth_def'} eq 'localauth'))) {
 8873:             $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.').' '.
 8874:                           &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.');
 8875:         }
 8876:     }
 8877:     my @fields = ('lastname','firstname','middlename','generation',
 8878:                   'permanentemail','id');
 8879:     my @shibfields = (@fields,'inststatus');
 8880:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 8881: #
 8882: # Where usernames may created for institutional log-in and/or institutional single sign on:
 8883: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
 8884: # may self-create accounts 
 8885: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
 8886: # which the user may supply, if institutional data is unavailable.
 8887: #
 8888:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
 8889:         if (ref($types) eq 'ARRAY') {
 8890:             if (@{$types} > 1) {
 8891:                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
 8892:                 push(@contexts,'statustocreate');
 8893:             } else {
 8894:                 undef($cancreate{'statustocreate'});
 8895:             } 
 8896:             foreach my $type (@{$types}) {
 8897:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
 8898:                 foreach my $field (@fields) {
 8899:                     if (grep(/^\Q$field\E$/,@modifiable)) {
 8900:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
 8901:                     } else {
 8902:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
 8903:                     }
 8904:                 }
 8905:             }
 8906:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
 8907:                 foreach my $type (@{$types}) {
 8908:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
 8909:                         foreach my $field (@fields) {
 8910:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
 8911:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
 8912:                                 push(@{$changes{'selfcreate'}},$type);
 8913:                                 last;
 8914:                             }
 8915:                         }
 8916:                     }
 8917:                 }
 8918:             } else {
 8919:                 foreach my $type (@{$types}) {
 8920:                     push(@{$changes{'selfcreate'}},$type);
 8921:                 }
 8922:             }
 8923:         }
 8924:         foreach my $field (@shibfields) {
 8925:             if ($env{'form.shibenv_'.$field} ne '') {
 8926:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
 8927:             }
 8928:         }
 8929:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 8930:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
 8931:                 foreach my $field (@shibfields) {
 8932:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
 8933:                         push(@{$changes{'cancreate'}},'shibenv');
 8934:                     }
 8935:                 }
 8936:             } else {
 8937:                 foreach my $field (@shibfields) {
 8938:                     if ($env{'form.shibenv_'.$field}) {
 8939:                         push(@{$changes{'cancreate'}},'shibenv');
 8940:                         last;
 8941:                     }
 8942:                 }
 8943:             }
 8944:         }
 8945:     }
 8946:     foreach my $item (@contexts) {
 8947:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 8948:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 8949:                 if (ref($cancreate{$item}) eq 'ARRAY') {
 8950:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 8951:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8952:                             push(@{$changes{'cancreate'}},$item);
 8953:                         }
 8954:                     }
 8955:                 }
 8956:             }
 8957:             if (ref($cancreate{$item}) eq 'ARRAY') {
 8958:                 foreach my $type (@{$cancreate{$item}}) {
 8959:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 8960:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8961:                             push(@{$changes{'cancreate'}},$item);
 8962:                         }
 8963:                     }
 8964:                 }
 8965:             }
 8966:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
 8967:             if (ref($cancreate{$item}) eq 'HASH') {
 8968:                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
 8969:                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
 8970:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
 8971:                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
 8972:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8973:                                     push(@{$changes{'cancreate'}},$item);
 8974:                                 }
 8975:                             }
 8976:                         }
 8977:                     } elsif ($item eq 'selfcreateprocessing') {
 8978:                         if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
 8979:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8980:                                 push(@{$changes{'cancreate'}},$item);
 8981:                             }
 8982:                         }
 8983:                     } else {
 8984:                         if (!$cancreate{$item}{$curr}) {
 8985:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8986:                                 push(@{$changes{'cancreate'}},$item);
 8987:                             }
 8988:                         }
 8989:                     }
 8990:                 }
 8991:                 foreach my $field (keys(%{$cancreate{$item}})) {
 8992:                     if (ref($cancreate{$item}{$field}) eq 'HASH') {
 8993:                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
 8994:                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
 8995:                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
 8996:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 8997:                                         push(@{$changes{'cancreate'}},$item);
 8998:                                     }
 8999:                                 }
 9000:                             } else {
 9001:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9002:                                     push(@{$changes{'cancreate'}},$item);
 9003:                                 }
 9004:                             }
 9005:                         }
 9006:                     } elsif ($item eq 'selfcreateprocessing') {
 9007:                         if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
 9008:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9009:                                 push(@{$changes{'cancreate'}},$item);
 9010:                             }
 9011:                         }
 9012:                     } else {
 9013:                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
 9014:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9015:                                 push(@{$changes{'cancreate'}},$item);
 9016:                             }
 9017:                         }
 9018:                     }
 9019:                 }
 9020:             }
 9021:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
 9022:             if (ref($cancreate{$item}) eq 'ARRAY') {
 9023:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
 9024:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9025:                         push(@{$changes{'cancreate'}},$item);
 9026:                     }
 9027:                 }
 9028:             } elsif (ref($cancreate{$item}) eq 'HASH') {
 9029:                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
 9030:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9031:                         push(@{$changes{'cancreate'}},$item);
 9032:                     }
 9033:                 }
 9034:             }
 9035:         } elsif ($item eq 'emailusername') {
 9036:             if (ref($cancreate{$item}) eq 'HASH') {
 9037:                 foreach my $type (keys(%{$cancreate{$item}})) {
 9038:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
 9039:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
 9040:                             if ($cancreate{$item}{$type}{$field}) {
 9041:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 9042:                                     push(@{$changes{'cancreate'}},$item);
 9043:                                 }
 9044:                                 last;
 9045:                             }
 9046:                         }
 9047:                     }
 9048:                 }
 9049:             }
 9050:         }
 9051:     }
 9052: #
 9053: # Populate %save_usercreate hash with updates to self-creation configuration.
 9054: #
 9055:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
 9056:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
 9057:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
 9058:     if (ref($cancreate{'notify'}) eq 'HASH') {
 9059:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
 9060:     }
 9061:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
 9062:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
 9063:     }
 9064:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 9065:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
 9066:     }
 9067:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
 9068:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
 9069:     }
 9070:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
 9071:     $save_usercreate{'emailrule'} = \@email_rule;
 9072: 
 9073:     my %userconfig_hash = (
 9074:             usercreation     => \%save_usercreate,
 9075:             usermodification => \%save_usermodify,
 9076:     );
 9077:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
 9078:                                              $dom);
 9079: #
 9080: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
 9081: #
 9082:     if ($putresult eq 'ok') {
 9083:         if (keys(%changes) > 0) {
 9084:             $resulttext = &mt('Changes made:').'<ul>';
 9085:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 9086:                 my %lt = &selfcreation_types();
 9087:                 foreach my $type (@{$changes{'cancreate'}}) {
 9088:                     my $chgtext;
 9089:                     if ($type eq 'selfcreate') {
 9090:                         if (@{$cancreate{$type}} == 0) {
 9091:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
 9092:                         } else {
 9093:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
 9094:                                         '<ul>';
 9095:                             foreach my $case (@{$cancreate{$type}}) {
 9096:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 9097:                             }
 9098:                             $chgtext .= '</ul>';
 9099:                             if (ref($cancreate{$type}) eq 'ARRAY') {
 9100:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
 9101:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 9102:                                         if (@{$cancreate{'statustocreate'}} == 0) {
 9103:                                             $chgtext .= '<br />'.
 9104:                                                         '<span class="LC_warning">'.
 9105:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
 9106:                                                         '</span>';
 9107:                                         }
 9108:                                     }
 9109:                                 }
 9110:                             }
 9111:                         }
 9112:                     } elsif ($type eq 'shibenv') {
 9113:                         if (keys(%{$cancreate{$type}}) == 0) {
 9114:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information'); 
 9115:                         } else {
 9116:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
 9117:                                         '<ul>';
 9118:                             foreach my $field (@shibfields) {
 9119:                                 next if ($cancreate{$type}{$field} eq '');
 9120:                                 if ($field eq 'inststatus') {
 9121:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
 9122:                                 } else {
 9123:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
 9124:                                 }
 9125:                             }
 9126:                             $chgtext .= '</ul>';
 9127:                         }  
 9128:                     } elsif ($type eq 'statustocreate') {
 9129:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
 9130:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
 9131:                             if (@{$cancreate{'selfcreate'}} > 0) {
 9132:                                 if (@{$cancreate{'statustocreate'}} == 0) {
 9133:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
 9134:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
 9135:                                         $chgtext .= '<br />'.
 9136:                                                     '<span class="LC_warning">'.
 9137:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
 9138:                                                     '</span>';
 9139:                                     }
 9140:                                 } elsif (ref($usertypes) eq 'HASH') {
 9141:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 9142:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
 9143:                                     } else {
 9144:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
 9145:                                     }
 9146:                                     $chgtext .= '<ul>';
 9147:                                     foreach my $case (@{$cancreate{$type}}) {
 9148:                                         if ($case eq 'default') {
 9149:                                             $chgtext .= '<li>'.$othertitle.'</li>';
 9150:                                         } else {
 9151:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
 9152:                                         }
 9153:                                     }
 9154:                                     $chgtext .= '</ul>';
 9155:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 9156:                                         $chgtext .= '<br /><span class="LC_warning">'.
 9157:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
 9158:                                                     '</span>';
 9159:                                     }
 9160:                                 }
 9161:                             } else {
 9162:                                 if (@{$cancreate{$type}} == 0) {
 9163:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
 9164:                                 } else {
 9165:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
 9166:                                 }
 9167:                             }
 9168:                         }
 9169:                     } elsif ($type eq 'selfcreateprocessing') {
 9170:                         my %choices = &Apache::lonlocal::texthash (
 9171:                                                                     automatic => 'Automatic approval',
 9172:                                                                     approval  => 'Queued for approval',
 9173:                                                                   );
 9174:                         if (@statuses > 1) {
 9175:                             $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:'). 
 9176:                                         '<ul>';
 9177:                            foreach my $type (@statuses) {
 9178:                                if ($type eq 'default') {
 9179:                                    $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
 9180:                                } else {
 9181:                                    $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
 9182:                                }
 9183:                            }
 9184:                            $chgtext .= '</ul>';
 9185:                         } else {
 9186:                            $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
 9187:                                          $choices{$cancreate{'selfcreateprocessing'}{'default'}});
 9188:                         }
 9189:                     } elsif ($type eq 'captcha') {
 9190:                         if ($savecaptcha{$type} eq 'notused') {
 9191:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
 9192:                         } else {
 9193:                             my %captchas = &captcha_phrases();
 9194:                             if ($captchas{$savecaptcha{$type}}) {
 9195:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
 9196:                             } else {
 9197:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
 9198:                             }
 9199:                         }
 9200:                     } elsif ($type eq 'recaptchakeys') {
 9201:                         my ($privkey,$pubkey);
 9202:                         if (ref($savecaptcha{$type}) eq 'HASH') {
 9203:                             $pubkey = $savecaptcha{$type}{'public'};
 9204:                             $privkey = $savecaptcha{$type}{'private'};
 9205:                         }
 9206:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
 9207:                         if (!$pubkey) {
 9208:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
 9209:                         } else {
 9210:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 9211:                         }
 9212:                         if (!$privkey) {
 9213:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
 9214:                         } else {
 9215:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
 9216:                         }
 9217:                         $chgtext .= '</ul>';
 9218:                     } elsif ($type eq 'emailusername') {
 9219:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
 9220:                             if (ref($types) eq 'ARRAY') {
 9221:                                 foreach my $type (@{$types}) {
 9222:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
 9223:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
 9224:                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
 9225:                                                     '<ul>';
 9226:                                             foreach my $field (@{$infofields}) {
 9227:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
 9228:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
 9229:                                                 }
 9230:                                             }
 9231:                                             $chgtext .= '</ul>';
 9232:                                         } else {
 9233:                                             $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 />';
 9234:                                         }
 9235:                                     } else {
 9236:                                         $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 />';
 9237:                                     }
 9238:                                 }
 9239:                             }
 9240:                         }
 9241:                     } elsif ($type eq 'notify') {
 9242:                         $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
 9243:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
 9244:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
 9245:                                 if ($cancreate{'notify'}{'approval'}) {
 9246:                                     $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
 9247:                                 }
 9248:                             }
 9249:                         }
 9250:                     }
 9251:                     if ($chgtext) {
 9252:                         $resulttext .= '<li>'.$chgtext.'</li>';
 9253:                     }
 9254:                 }
 9255:             }
 9256:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 9257:                 my ($emailrules,$emailruleorder) =
 9258:                     &Apache::lonnet::inst_userrules($dom,'email');
 9259:                 my $chgtext = '<ul>';
 9260:                 foreach my $type (@email_rule) {
 9261:                     if (ref($emailrules->{$type}) eq 'HASH') {
 9262:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 9263:                     }
 9264:                 }
 9265:                 $chgtext .= '</ul>';
 9266:                 if (@email_rule > 0) {
 9267:                     $resulttext .= '<li>'.
 9268:                                    &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
 9269:                                        $chgtext.
 9270:                                    '</li>';
 9271:                 } else {
 9272:                     $resulttext .= '<li>'.
 9273:                                    &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
 9274:                                    '</li>';
 9275:                 }
 9276:             }
 9277:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
 9278:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
 9279:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 9280:                 foreach my $type (@{$changes{'selfcreate'}}) {
 9281:                     my $typename = $type;
 9282:                     if (ref($usertypes) eq 'HASH') {
 9283:                         if ($usertypes->{$type} ne '') {
 9284:                             $typename = $usertypes->{$type};
 9285:                         }
 9286:                     }
 9287:                     my @modifiable;
 9288:                     $resulttext .= '<li>'.
 9289:                                     &mt('Self-creation of account by users with status: [_1]',
 9290:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
 9291:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
 9292:                     foreach my $field (@fields) {
 9293:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
 9294:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
 9295:                         }
 9296:                     }
 9297:                     if (@modifiable > 0) {
 9298:                         $resulttext .= join(', ',@modifiable);
 9299:                     } else {
 9300:                         $resulttext .= &mt('none');
 9301:                     }
 9302:                     $resulttext .= '</li>';
 9303:                 }
 9304:                 $resulttext .= '</ul></li>';
 9305:             }
 9306:             $resulttext .= '</ul>';
 9307:         } else {
 9308:             $resulttext = &mt('No changes made to self-creation settings');
 9309:         }
 9310:     } else {
 9311:         $resulttext = '<span class="LC_error">'.
 9312:             &mt('An error occurred: [_1]',$putresult).'</span>';
 9313:     }
 9314:     if ($warningmsg ne '') {
 9315:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 9316:     }
 9317:     return $resulttext;
 9318: }
 9319: 
 9320: sub process_captcha {
 9321:     my ($container,$changes,$newsettings,$current) = @_;
 9322:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
 9323:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
 9324:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
 9325:         $newsettings->{'captcha'} = 'original';
 9326:     }
 9327:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
 9328:         if ($container eq 'cancreate') {
 9329:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 9330:                 push(@{$changes->{'cancreate'}},'captcha');
 9331:             } elsif (!defined($changes->{'cancreate'})) {
 9332:                 $changes->{'cancreate'} = ['captcha'];
 9333:             }
 9334:         } else {
 9335:             $changes->{'captcha'} = 1;
 9336:         }
 9337:     }
 9338:     my ($newpub,$newpriv,$currpub,$currpriv);
 9339:     if ($newsettings->{'captcha'} eq 'recaptcha') {
 9340:         $newpub = $env{'form.'.$container.'_recaptchapub'};
 9341:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
 9342:         $newpub =~ s/[^\w\-]//g;
 9343:         $newpriv =~ s/[^\w\-]//g;
 9344:         $newsettings->{'recaptchakeys'} = {
 9345:                                              public  => $newpub,
 9346:                                              private => $newpriv,
 9347:                                           };
 9348:     }
 9349:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
 9350:         $currpub = $current->{'recaptchakeys'}{'public'};
 9351:         $currpriv = $current->{'recaptchakeys'}{'private'};
 9352:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
 9353:             $newsettings->{'recaptchakeys'} = {
 9354:                                                  public  => '',
 9355:                                                  private => '',
 9356:                                               }
 9357:         }
 9358:     }
 9359:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
 9360:         if ($container eq 'cancreate') {
 9361:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 9362:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
 9363:             } elsif (!defined($changes->{'cancreate'})) {
 9364:                 $changes->{'cancreate'} = ['recaptchakeys'];
 9365:             }
 9366:         } else {
 9367:             $changes->{'recaptchakeys'} = 1;
 9368:         }
 9369:     }
 9370:     return;
 9371: }
 9372: 
 9373: sub modify_usermodification {
 9374:     my ($dom,%domconfig) = @_;
 9375:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
 9376:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 9377:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 9378:             if ($key eq 'selfcreate') {
 9379:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
 9380:             } else {  
 9381:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 9382:             }
 9383:         }
 9384:     }
 9385:     my @contexts = ('author','course');
 9386:     my %context_title = (
 9387:                            author => 'In author context',
 9388:                            course => 'In course context',
 9389:                         );
 9390:     my @fields = ('lastname','firstname','middlename','generation',
 9391:                   'permanentemail','id');
 9392:     my %roles = (
 9393:                   author => ['ca','aa'],
 9394:                   course => ['st','ep','ta','in','cr'],
 9395:                 );
 9396:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 9397:     foreach my $context (@contexts) {
 9398:         foreach my $role (@{$roles{$context}}) {
 9399:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 9400:             foreach my $item (@fields) {
 9401:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 9402:                     $modifyhash{$context}{$role}{$item} = 1;
 9403:                 } else {
 9404:                     $modifyhash{$context}{$role}{$item} = 0;
 9405:                 }
 9406:             }
 9407:         }
 9408:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 9409:             foreach my $role (@{$roles{$context}}) {
 9410:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 9411:                     foreach my $field (@fields) {
 9412:                         if ($modifyhash{$context}{$role}{$field} ne 
 9413:                                 $curr_usermodification{$context}{$role}{$field}) {
 9414:                             push(@{$changes{$context}},$role);
 9415:                             last;
 9416:                         }
 9417:                     }
 9418:                 }
 9419:             }
 9420:         } else {
 9421:             foreach my $context (@contexts) {
 9422:                 foreach my $role (@{$roles{$context}}) {
 9423:                     push(@{$changes{$context}},$role);
 9424:                 }
 9425:             }
 9426:         }
 9427:     }
 9428:     my %usermodification_hash =  (
 9429:                                    usermodification => \%modifyhash,
 9430:                                  );
 9431:     my $putresult = &Apache::lonnet::put_dom('configuration',
 9432:                                              \%usermodification_hash,$dom);
 9433:     if ($putresult eq 'ok') {
 9434:         if (keys(%changes) > 0) {
 9435:             $resulttext = &mt('Changes made: ').'<ul>';
 9436:             foreach my $context (@contexts) {
 9437:                 if (ref($changes{$context}) eq 'ARRAY') {
 9438:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 9439:                     if (ref($changes{$context}) eq 'ARRAY') {
 9440:                         foreach my $role (@{$changes{$context}}) {
 9441:                             my $rolename;
 9442:                             if ($role eq 'cr') {
 9443:                                 $rolename = &mt('Custom');
 9444:                             } else {
 9445:                                 $rolename = &Apache::lonnet::plaintext($role);
 9446:                             }
 9447:                             my @modifiable;
 9448:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 9449:                             foreach my $field (@fields) {
 9450:                                 if ($modifyhash{$context}{$role}{$field}) {
 9451:                                     push(@modifiable,$fieldtitles{$field});
 9452:                                 }
 9453:                             }
 9454:                             if (@modifiable > 0) {
 9455:                                 $resulttext .= join(', ',@modifiable);
 9456:                             } else {
 9457:                                 $resulttext .= &mt('none'); 
 9458:                             }
 9459:                             $resulttext .= '</li>';
 9460:                         }
 9461:                         $resulttext .= '</ul></li>';
 9462:                     }
 9463:                 }
 9464:             }
 9465:             $resulttext .= '</ul>';
 9466:         } else {
 9467:             $resulttext = &mt('No changes made to user modification settings');
 9468:         }
 9469:     } else {
 9470:         $resulttext = '<span class="LC_error">'.
 9471:             &mt('An error occurred: [_1]',$putresult).'</span>';
 9472:     }
 9473:     return $resulttext;
 9474: }
 9475: 
 9476: sub modify_defaults {
 9477:     my ($dom,$lastactref,%domconfig) = @_;
 9478:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 9479:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
 9480:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
 9481:     my @authtypes = ('internal','krb4','krb5','localauth');
 9482:     foreach my $item (@items) {
 9483:         $newvalues{$item} = $env{'form.'.$item};
 9484:         if ($item eq 'auth_def') {
 9485:             if ($newvalues{$item} ne '') {
 9486:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 9487:                     push(@errors,$item);
 9488:                 }
 9489:             }
 9490:         } elsif ($item eq 'lang_def') {
 9491:             if ($newvalues{$item} ne '') {
 9492:                 if ($newvalues{$item} =~ /^(\w+)/) {
 9493:                     my $langcode = $1;
 9494:                     if ($langcode ne 'x_chef') {
 9495:                         if (code2language($langcode) eq '') {
 9496:                             push(@errors,$item);
 9497:                         }
 9498:                     }
 9499:                 } else {
 9500:                     push(@errors,$item);
 9501:                 }
 9502:             }
 9503:         } elsif ($item eq 'timezone_def') {
 9504:             if ($newvalues{$item} ne '') {
 9505:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 9506:                     push(@errors,$item);   
 9507:                 }
 9508:             }
 9509:         } elsif ($item eq 'datelocale_def') {
 9510:             if ($newvalues{$item} ne '') {
 9511:                 my @datelocale_ids = DateTime::Locale->ids();
 9512:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 9513:                     push(@errors,$item);
 9514:                 }
 9515:             }
 9516:         } elsif ($item eq 'portal_def') {
 9517:             if ($newvalues{$item} ne '') {
 9518:                 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])\/?$/) {
 9519:                     push(@errors,$item);
 9520:                 }
 9521:             }
 9522:         }
 9523:         if (grep(/^\Q$item\E$/,@errors)) {
 9524:             $newvalues{$item} = $domdefaults{$item};
 9525:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 9526:             $changes{$item} = 1;
 9527:         }
 9528:         $domdefaults{$item} = $newvalues{$item};
 9529:     }
 9530:     my %defaults_hash = (
 9531:                          defaults => \%newvalues,
 9532:                         );
 9533:     my $title = &defaults_titles();
 9534: 
 9535:     my $currinststatus;
 9536:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
 9537:         $currinststatus = $domconfig{'inststatus'};
 9538:     } else {
 9539:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 9540:         $currinststatus = {
 9541:                              inststatustypes => $usertypes,
 9542:                              inststatusorder => $types,
 9543:                              inststatusguest => [],
 9544:                           };
 9545:     }
 9546:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
 9547:     my @allpos;
 9548:     my %guests;
 9549:     my %alltypes;
 9550:     my ($currtitles,$currguests,$currorder);
 9551:     if (ref($currinststatus) eq 'HASH') {
 9552:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
 9553:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
 9554:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
 9555:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
 9556:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
 9557:                     }
 9558:                 }
 9559:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
 9560:                     my $position = $env{'form.inststatus_pos_'.$type};
 9561:                     $position =~ s/\D+//g;
 9562:                     $allpos[$position] = $type;
 9563:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
 9564:                     $alltypes{$type} =~ s/`//g;
 9565:                     if ($env{'form.inststatus_guest_'.$type}) {
 9566:                         $guests{$type} = 1;
 9567:                     }
 9568:                 }
 9569:             }
 9570:             if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
 9571:                 $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
 9572:             }
 9573:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
 9574:             $currtitles =~ s/,$//;
 9575:         }
 9576:     }
 9577:     if ($env{'form.addinststatus'}) {
 9578:         my $newtype = $env{'form.addinststatus'};
 9579:         $newtype =~ s/\W//g;
 9580:         unless (exists($alltypes{$newtype})) {
 9581:             if ($env{'form.addinststatus_guest'}) {
 9582:                 $guests{$newtype} = 1;
 9583:             }
 9584:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
 9585:             $alltypes{$newtype} =~ s/`//g; 
 9586:             my $position = $env{'form.addinststatus_pos'};
 9587:             $position =~ s/\D+//g;
 9588:             if ($position ne '') {
 9589:                 $allpos[$position] = $newtype;
 9590:             }
 9591:         }
 9592:     }
 9593:     my (@orderedstatus,@orderedguests);
 9594:     foreach my $type (@allpos) {
 9595:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
 9596:             push(@orderedstatus,$type);
 9597:             if ($guests{$type}) {
 9598:                 push(@orderedguests,$type);
 9599:             }
 9600:         }
 9601:     }
 9602:     foreach my $type (keys(%alltypes)) {
 9603:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
 9604:             delete($alltypes{$type});
 9605:         }
 9606:     }
 9607:     $defaults_hash{'inststatus'} = {
 9608:                                      inststatustypes => \%alltypes,
 9609:                                      inststatusorder => \@orderedstatus,
 9610:                                      inststatusguest => \@orderedguests,
 9611:                                    };
 9612:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
 9613:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
 9614:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
 9615:         }
 9616:     }
 9617:     if ($currorder ne join(',',@orderedstatus)) {
 9618:         $changes{'inststatus'}{'inststatusorder'} = 1;
 9619:     }
 9620:     if ($currguests ne join(',',@orderedguests)) {
 9621:         $changes{'inststatus'}{'inststatusguest'} = 1;
 9622:     }
 9623:     my $newtitles;
 9624:     foreach my $item (@orderedstatus) {
 9625:         $newtitles .= $alltypes{$item}.',';
 9626:     }
 9627:     $newtitles =~ s/,$//;
 9628:     if ($currtitles ne $newtitles) {
 9629:         $changes{'inststatus'}{'inststatustypes'} = 1;
 9630:     }
 9631:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 9632:                                              $dom);
 9633:     if ($putresult eq 'ok') {
 9634:         if (keys(%changes) > 0) {
 9635:             $resulttext = &mt('Changes made:').'<ul>';
 9636:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
 9637:             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";
 9638:             foreach my $item (sort(keys(%changes))) {
 9639:                 if ($item eq 'inststatus') {
 9640:                     if (ref($changes{'inststatus'}) eq 'HASH') {
 9641:                         if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
 9642:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
 9643:                             foreach my $type (@orderedstatus) { 
 9644:                                 $resulttext .= $alltypes{$type}.', ';
 9645:                             }
 9646:                             $resulttext =~ s/, $//;
 9647:                             $resulttext .= '</li>';
 9648:                         }
 9649:                         if ($changes{'inststatus'}{'inststatusguest'}) {
 9650:                             $resulttext .= '<li>'; 
 9651:                             if (@orderedguests) {
 9652:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
 9653:                                 foreach my $type (@orderedguests) {
 9654:                                     $resulttext .= $alltypes{$type}.', ';
 9655:                                 }
 9656:                                 $resulttext =~ s/, $//;
 9657:                             } else {
 9658:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
 9659:                             }
 9660:                             $resulttext .= '</li>';
 9661:                         }
 9662:                     }
 9663:                 } else {
 9664:                     my $value = $env{'form.'.$item};
 9665:                     if ($value eq '') {
 9666:                         $value = &mt('none');
 9667:                     } elsif ($item eq 'auth_def') {
 9668:                         my %authnames = &authtype_names();
 9669:                         my %shortauth = (
 9670:                                           internal   => 'int',
 9671:                                           krb4       => 'krb4',
 9672:                                           krb5       => 'krb5',
 9673:                                           localauth  => 'loc',
 9674:                         );
 9675:                         $value = $authnames{$shortauth{$value}};
 9676:                     }
 9677:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 9678:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
 9679:                 }
 9680:             }
 9681:             $resulttext .= '</ul>';
 9682:             $mailmsgtext .= "\n";
 9683:             my $cachetime = 24*60*60;
 9684:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 9685:             if (ref($lastactref) eq 'HASH') {
 9686:                 $lastactref->{'domdefaults'} = 1;
 9687:             }
 9688:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 9689:                 my $notify = 1;
 9690:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
 9691:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
 9692:                         $notify = 0;
 9693:                     }
 9694:                 }
 9695:                 if ($notify) {
 9696:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
 9697:                                                "LON-CAPA Domain Settings Change - $dom",
 9698:                                                $mailmsgtext);
 9699:                 }
 9700:             }
 9701:         } else {
 9702:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 9703:         }
 9704:     } else {
 9705:         $resulttext = '<span class="LC_error">'.
 9706:             &mt('An error occurred: [_1]',$putresult).'</span>';
 9707:     }
 9708:     if (@errors > 0) {
 9709:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 9710:         foreach my $item (@errors) {
 9711:             $resulttext .= ' "'.$title->{$item}.'",';
 9712:         }
 9713:         $resulttext =~ s/,$//;
 9714:     }
 9715:     return $resulttext;
 9716: }
 9717: 
 9718: sub modify_scantron {
 9719:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
 9720:     my ($resulttext,%confhash,%changes,$errors);
 9721:     my $custom = 'custom.tab';
 9722:     my $default = 'default.tab';
 9723:     my $servadm = $r->dir_config('lonAdmEMail');
 9724:     my ($configuserok,$author_ok,$switchserver) = 
 9725:         &config_check($dom,$confname,$servadm);
 9726:     if ($env{'form.scantronformat.filename'} ne '') {
 9727:         my $error;
 9728:         if ($configuserok eq 'ok') {
 9729:             if ($switchserver) {
 9730:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
 9731:             } else {
 9732:                 if ($author_ok eq 'ok') {
 9733:                     my ($result,$scantronurl) =
 9734:                         &publishlogo($r,'upload','scantronformat',$dom,
 9735:                                      $confname,'scantron','','',$custom);
 9736:                     if ($result eq 'ok') {
 9737:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 9738:                         $changes{'scantronformat'} = 1;
 9739:                     } else {
 9740:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 9741:                     }
 9742:                 } else {
 9743:                     $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);
 9744:                 }
 9745:             }
 9746:         } else {
 9747:             $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);
 9748:         }
 9749:         if ($error) {
 9750:             &Apache::lonnet::logthis($error);
 9751:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 9752:         }
 9753:     }
 9754:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 9755:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 9756:             if ($env{'form.scantronformat_del'}) {
 9757:                 $confhash{'scantron'}{'scantronformat'} = '';
 9758:                 $changes{'scantronformat'} = 1;
 9759:             }
 9760:         }
 9761:     }
 9762:     if (keys(%confhash) > 0) {
 9763:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 9764:                                                  $dom);
 9765:         if ($putresult eq 'ok') {
 9766:             if (keys(%changes) > 0) {
 9767:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 9768:                     $resulttext = &mt('Changes made:').'<ul>';
 9769:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 9770:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 9771:                     } else {
 9772:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 9773:                     }
 9774:                     $resulttext .= '</ul>';
 9775:                 } else {
 9776:                     $resulttext = &mt('Changes made to bubblesheet format file.');
 9777:                 }
 9778:                 $resulttext .= '</ul>';
 9779:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 9780:                 if (ref($lastactref) eq 'HASH') {
 9781:                     $lastactref->{'domainconfig'} = 1;
 9782:                 }
 9783:             } else {
 9784:                 $resulttext = &mt('No changes made to bubblesheet format file');
 9785:             }
 9786:         } else {
 9787:             $resulttext = '<span class="LC_error">'.
 9788:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 9789:         }
 9790:     } else {
 9791:         $resulttext = &mt('No changes made to bubblesheet format file'); 
 9792:     }
 9793:     if ($errors) {
 9794:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 9795:                        $errors.'</ul>';
 9796:     }
 9797:     return $resulttext;
 9798: }
 9799: 
 9800: sub modify_coursecategories {
 9801:     my ($dom,$lastactref,%domconfig) = @_;
 9802:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 9803:         $cathash);
 9804:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 9805:     my @catitems = ('unauth','auth');
 9806:     my @cattypes = ('std','domonly','codesrch','none');
 9807:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 9808:         $cathash = $domconfig{'coursecategories'}{'cats'};
 9809:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 9810:             $changes{'togglecats'} = 1;
 9811:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 9812:         }
 9813:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 9814:             $changes{'categorize'} = 1;
 9815:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 9816:         }
 9817:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
 9818:             $changes{'togglecatscomm'} = 1;
 9819:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
 9820:         }
 9821:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
 9822:             $changes{'categorizecomm'} = 1;
 9823:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
 9824:         }
 9825:         foreach my $item (@catitems) {
 9826:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
 9827:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
 9828:                     $changes{$item} = 1;
 9829:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
 9830:                 }
 9831:             }
 9832:         }
 9833:     } else {
 9834:         $changes{'togglecats'} = 1;
 9835:         $changes{'categorize'} = 1;
 9836:         $changes{'togglecatscomm'} = 1;
 9837:         $changes{'categorizecomm'} = 1;
 9838:         $domconfig{'coursecategories'} = {
 9839:                                              togglecats => $env{'form.togglecats'},
 9840:                                              categorize => $env{'form.categorize'},
 9841:                                              togglecatscomm => $env{'form.togglecatscomm'},
 9842:                                              categorizecomm => $env{'form.categorizecomm'},
 9843:                                          };
 9844:         foreach my $item (@catitems) {
 9845:             if ($env{'form.coursecat_'.$item} ne 'std') {
 9846:                 $changes{$item} = 1;
 9847:             }
 9848:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
 9849:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
 9850:             }
 9851:         }
 9852:     }
 9853:     if (ref($cathash) eq 'HASH') {
 9854:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 9855:             push (@deletecategory,'instcode::0');
 9856:         }
 9857:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
 9858:             push(@deletecategory,'communities::0');
 9859:         }
 9860:     }
 9861:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 9862:     if (ref($cathash) eq 'HASH') {
 9863:         if (@deletecategory > 0) {
 9864:             #FIXME Need to remove category from all courses using a deleted category 
 9865:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 9866:             foreach my $item (@deletecategory) {
 9867:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 9868:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 9869:                     $deletions{$item} = 1;
 9870:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 9871:                 }
 9872:             }
 9873:         }
 9874:         foreach my $item (keys(%{$cathash})) {
 9875:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 9876:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 9877:                 $reorderings{$item} = 1;
 9878:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 9879:             }
 9880:             if ($env{'form.addcategory_name_'.$item} ne '') {
 9881:                 my $newcat = $env{'form.addcategory_name_'.$item};
 9882:                 my $newdepth = $depth+1;
 9883:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 9884:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 9885:                 $adds{$newitem} = 1; 
 9886:             }
 9887:             if ($env{'form.subcat_'.$item} ne '') {
 9888:                 my $newcat = $env{'form.subcat_'.$item};
 9889:                 my $newdepth = $depth+1;
 9890:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 9891:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 9892:                 $adds{$newitem} = 1;
 9893:             }
 9894:         }
 9895:     }
 9896:     if ($env{'form.instcode'} eq '1') {
 9897:         if (ref($cathash) eq 'HASH') {
 9898:             my $newitem = 'instcode::0';
 9899:             if ($cathash->{$newitem} eq '') {  
 9900:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 9901:                 $adds{$newitem} = 1;
 9902:             }
 9903:         } else {
 9904:             my $newitem = 'instcode::0';
 9905:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 9906:             $adds{$newitem} = 1;
 9907:         }
 9908:     }
 9909:     if ($env{'form.communities'} eq '1') {
 9910:         if (ref($cathash) eq 'HASH') {
 9911:             my $newitem = 'communities::0';
 9912:             if ($cathash->{$newitem} eq '') {
 9913:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 9914:                 $adds{$newitem} = 1;
 9915:             }
 9916:         } else {
 9917:             my $newitem = 'communities::0';
 9918:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 9919:             $adds{$newitem} = 1;
 9920:         }
 9921:     }
 9922:     if ($env{'form.addcategory_name'} ne '') {
 9923:         if (($env{'form.addcategory_name'} ne 'instcode') &&
 9924:             ($env{'form.addcategory_name'} ne 'communities')) {
 9925:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 9926:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 9927:             $adds{$newitem} = 1;
 9928:         }
 9929:     }
 9930:     my $putresult;
 9931:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 9932:         if (keys(%deletions) > 0) {
 9933:             foreach my $key (keys(%deletions)) {
 9934:                 if ($predelallitems{$key} ne '') {
 9935:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 9936:                 }
 9937:             }
 9938:         }
 9939:         my (@chkcats,@chktrails,%chkallitems);
 9940:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 9941:         if (ref($chkcats[0]) eq 'ARRAY') {
 9942:             my $depth = 0;
 9943:             my $chg = 0;
 9944:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 9945:                 my $name = $chkcats[0][$i];
 9946:                 my $item;
 9947:                 if ($name eq '') {
 9948:                     $chg ++;
 9949:                 } else {
 9950:                     $item = &escape($name).'::0';
 9951:                     if ($chg) {
 9952:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 9953:                     }
 9954:                     $depth ++; 
 9955:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 9956:                     $depth --;
 9957:                 }
 9958:             }
 9959:         }
 9960:     }
 9961:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 9962:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 9963:         if ($putresult eq 'ok') {
 9964:             my %title = (
 9965:                          togglecats     => 'Show/Hide a course in catalog',
 9966:                          categorize     => 'Assign a category to a course',
 9967:                          togglecatscomm => 'Show/Hide a community in catalog',
 9968:                          categorizecomm => 'Assign a category to a community',
 9969:                         );
 9970:             my %level = (
 9971:                          dom  => 'set in Domain ("Modify Course/Community")',
 9972:                          crs  => 'set in Course ("Course Configuration")',
 9973:                          comm => 'set in Community ("Community Configuration")',
 9974:                          none     => 'No catalog',
 9975:                          std      => 'Standard catalog',
 9976:                          domonly  => 'Domain-only catalog',
 9977:                          codesrch => 'Code search form',
 9978:                         );
 9979:             $resulttext = &mt('Changes made:').'<ul>';
 9980:             if ($changes{'togglecats'}) {
 9981:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 9982:             }
 9983:             if ($changes{'categorize'}) {
 9984:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 9985:             }
 9986:             if ($changes{'togglecatscomm'}) {
 9987:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
 9988:             }
 9989:             if ($changes{'categorizecomm'}) {
 9990:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
 9991:             }
 9992:             if ($changes{'unauth'}) {
 9993:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
 9994:             }
 9995:             if ($changes{'auth'}) {
 9996:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
 9997:             }
 9998:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 9999:                 my $cathash;
10000:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10001:                     $cathash = $domconfig{'coursecategories'}{'cats'};
10002:                 } else {
10003:                     $cathash = {};
10004:                 } 
10005:                 my (@cats,@trails,%allitems);
10006:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
10007:                 if (keys(%deletions) > 0) {
10008:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
10009:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
10010:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
10011:                     }
10012:                     $resulttext .= '</ul></li>';
10013:                 }
10014:                 if (keys(%reorderings) > 0) {
10015:                     my %sort_by_trail;
10016:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10017:                     foreach my $key (keys(%reorderings)) {
10018:                         if ($allitems{$key} ne '') {
10019:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10020:                         }
10021:                     }
10022:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10023:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
10024:                     }
10025:                     $resulttext .= '</ul></li>';
10026:                 }
10027:                 if (keys(%adds) > 0) {
10028:                     my %sort_by_trail;
10029:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10030:                     foreach my $key (keys(%adds)) {
10031:                         if ($allitems{$key} ne '') {
10032:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10033:                         }
10034:                     }
10035:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10036:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
10037:                     }
10038:                     $resulttext .= '</ul></li>';
10039:                 }
10040:             }
10041:             $resulttext .= '</ul>';
10042:             if ($changes{'unauth'} || $changes{'auth'}) {
10043:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10044:                 if ($changes{'auth'}) {
10045:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10046:                 }
10047:                 if ($changes{'unauth'}) {
10048:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10049:                 }
10050:                 my $cachetime = 24*60*60;
10051:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10052:                 if (ref($lastactref) eq 'HASH') {
10053:                     $lastactref->{'domdefaults'} = 1;
10054:                 }
10055:             }
10056:         } else {
10057:             $resulttext = '<span class="LC_error">'.
10058:                           &mt('An error occurred: [_1]',$putresult).'</span>';
10059:         }
10060:     } else {
10061:         $resulttext = &mt('No changes made to course and community categories');
10062:     }
10063:     return $resulttext;
10064: }
10065: 
10066: sub modify_serverstatuses {
10067:     my ($dom,%domconfig) = @_;
10068:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10069:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10070:         %currserverstatus = %{$domconfig{'serverstatuses'}};
10071:     }
10072:     my @pages = &serverstatus_pages();
10073:     foreach my $type (@pages) {
10074:         $newserverstatus{$type}{'namedusers'} = '';
10075:         $newserverstatus{$type}{'machines'} = '';
10076:         if (defined($env{'form.'.$type.'_namedusers'})) {
10077:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10078:             my @okusers;
10079:             foreach my $user (@users) {
10080:                 my ($uname,$udom) = split(/:/,$user);
10081:                 if (($udom =~ /^$match_domain$/) &&   
10082:                     (&Apache::lonnet::domain($udom)) &&
10083:                     ($uname =~ /^$match_username$/)) {
10084:                     if (!grep(/^\Q$user\E/,@okusers)) {
10085:                         push(@okusers,$user);
10086:                     }
10087:                 }
10088:             }
10089:             if (@okusers > 0) {
10090:                  @okusers = sort(@okusers);
10091:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10092:             }
10093:         }
10094:         if (defined($env{'form.'.$type.'_machines'})) {
10095:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10096:             my @okmachines;
10097:             foreach my $ip (@machines) {
10098:                 my @parts = split(/\./,$ip);
10099:                 next if (@parts < 4);
10100:                 my $badip = 0;
10101:                 for (my $i=0; $i<4; $i++) {
10102:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10103:                         $badip = 1;
10104:                         last;
10105:                     }
10106:                 }
10107:                 if (!$badip) {
10108:                     push(@okmachines,$ip);     
10109:                 }
10110:             }
10111:             @okmachines = sort(@okmachines);
10112:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10113:         }
10114:     }
10115:     my %serverstatushash =  (
10116:                                 serverstatuses => \%newserverstatus,
10117:                             );
10118:     foreach my $type (@pages) {
10119:         foreach my $setting ('namedusers','machines') {
10120:             my (@current,@new);
10121:             if (ref($currserverstatus{$type}) eq 'HASH') {
10122:                 if ($currserverstatus{$type}{$setting} ne '') { 
10123:                     @current = split(/,/,$currserverstatus{$type}{$setting});
10124:                 }
10125:             }
10126:             if ($newserverstatus{$type}{$setting} ne '') {
10127:                 @new = split(/,/,$newserverstatus{$type}{$setting});
10128:             }
10129:             if (@current > 0) {
10130:                 if (@new > 0) {
10131:                     foreach my $item (@current) {
10132:                         if (!grep(/^\Q$item\E$/,@new)) {
10133:                             $changes{$type}{$setting} = 1;
10134:                             last;
10135:                         }
10136:                     }
10137:                     foreach my $item (@new) {
10138:                         if (!grep(/^\Q$item\E$/,@current)) {
10139:                             $changes{$type}{$setting} = 1;
10140:                             last;
10141:                         }
10142:                     }
10143:                 } else {
10144:                     $changes{$type}{$setting} = 1;
10145:                 }
10146:             } elsif (@new > 0) {
10147:                 $changes{$type}{$setting} = 1;
10148:             }
10149:         }
10150:     }
10151:     if (keys(%changes) > 0) {
10152:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
10153:         my $putresult = &Apache::lonnet::put_dom('configuration',
10154:                                                  \%serverstatushash,$dom);
10155:         if ($putresult eq 'ok') {
10156:             $resulttext .= &mt('Changes made:').'<ul>';
10157:             foreach my $type (@pages) {
10158:                 if (ref($changes{$type}) eq 'HASH') {
10159:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
10160:                     if ($changes{$type}{'namedusers'}) {
10161:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
10162:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10163:                         } else {
10164:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10165:                         }
10166:                     }
10167:                     if ($changes{$type}{'machines'}) {
10168:                         if ($newserverstatus{$type}{'machines'} eq '') {
10169:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10170:                         } else {
10171:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10172:                         }
10173: 
10174:                     }
10175:                     $resulttext .= '</ul></li>';
10176:                 }
10177:             }
10178:             $resulttext .= '</ul>';
10179:         } else {
10180:             $resulttext = '<span class="LC_error">'.
10181:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10182: 
10183:         }
10184:     } else {
10185:         $resulttext = &mt('No changes made to access to server status pages');
10186:     }
10187:     return $resulttext;
10188: }
10189: 
10190: sub modify_helpsettings {
10191:     my ($r,$dom,$confname,%domconfig) = @_;
10192:     my ($resulttext,$errors,%changes,%helphash);
10193:     my %defaultchecked = ('submitbugs' => 'on');
10194:     my @offon = ('off','on');
10195:     my @toggles = ('submitbugs');
10196:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10197:         foreach my $item (@toggles) {
10198:             if ($defaultchecked{$item} eq 'on') { 
10199:                 if ($domconfig{'helpsettings'}{$item} eq '') {
10200:                     if ($env{'form.'.$item} eq '0') {
10201:                         $changes{$item} = 1;
10202:                     }
10203:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10204:                     $changes{$item} = 1;
10205:                 }
10206:             } elsif ($defaultchecked{$item} eq 'off') {
10207:                 if ($domconfig{'helpsettings'}{$item} eq '') {
10208:                     if ($env{'form.'.$item} eq '1') {
10209:                         $changes{$item} = 1;
10210:                     }
10211:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10212:                     $changes{$item} = 1;
10213:                 }
10214:             }
10215:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10216:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
10217:             }
10218:         }
10219:     }
10220:     my $putresult;
10221:     if (keys(%changes) > 0) {
10222:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10223:         if ($putresult eq 'ok') {
10224:             $resulttext = &mt('Changes made:').'<ul>';
10225:             foreach my $item (sort(keys(%changes))) {
10226:                 if ($item eq 'submitbugs') {
10227:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10228:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10229:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10230:                 }
10231:             }
10232:             $resulttext .= '</ul>';
10233:         } else {
10234:             $resulttext = &mt('No changes made to help settings');
10235:             $errors .= '<li><span class="LC_error">'.
10236:                        &mt('An error occurred storing the settings: [_1]',
10237:                            $putresult).'</span></li>';
10238:         }
10239:     }
10240:     if ($errors) {
10241:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
10242:                        $errors.'</ul>';
10243:     }
10244:     return $resulttext;
10245: }
10246: 
10247: sub modify_coursedefaults {
10248:     my ($dom,$lastactref,%domconfig) = @_;
10249:     my ($resulttext,$errors,%changes,%defaultshash);
10250:     my %defaultchecked = (
10251:                            'canuse_pdfforms' => 'off',
10252:                            'uselcmath'       => 'on',
10253:                            'usejsme'         => 'on'
10254:                          );
10255:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
10256:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
10257:                    'uploadquota_community','uploadquota_textbook');
10258:     my @types = ('official','unofficial','community','textbook');
10259:     my %staticdefaults = (
10260:                            anonsurvey_threshold => 10,
10261:                            uploadquota          => 500,
10262:                            postsubmit           => 60,
10263:                          );
10264: 
10265:     $defaultshash{'coursedefaults'} = {};
10266: 
10267:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10268:         if ($domconfig{'coursedefaults'} eq '') {
10269:             $domconfig{'coursedefaults'} = {};
10270:         }
10271:     }
10272: 
10273:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10274:         foreach my $item (@toggles) {
10275:             if ($defaultchecked{$item} eq 'on') {
10276:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
10277:                     ($env{'form.'.$item} eq '0')) {
10278:                     $changes{$item} = 1;
10279:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10280:                     $changes{$item} = 1;
10281:                 }
10282:             } elsif ($defaultchecked{$item} eq 'off') {
10283:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
10284:                     ($env{'form.'.$item} eq '1')) {
10285:                     $changes{$item} = 1;
10286:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10287:                     $changes{$item} = 1;
10288:                 }
10289:             }
10290:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10291:         }
10292:         foreach my $item (@numbers) {
10293:             my ($currdef,$newdef);
10294:             $newdef = $env{'form.'.$item};
10295:             if ($item eq 'anonsurvey_threshold') {
10296:                 $currdef = $domconfig{'coursedefaults'}{$item};
10297:                 $newdef =~ s/\D//g;
10298:                 if ($newdef eq '' || $newdef < 1) {
10299:                     $newdef = 1;
10300:                 }
10301:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
10302:             } else {
10303:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10304:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10305:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10306:                 }
10307:                 $newdef =~ s/[^\w.\-]//g;
10308:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10309:             }
10310:             if ($currdef ne $newdef) {
10311:                 my $staticdef;
10312:                 if ($item eq 'anonsurvey_threshold') {
10313:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10314:                         $changes{$item} = 1;
10315:                     }
10316:                 } else {
10317:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10318:                         $changes{'uploadquota'} = 1;
10319:                     }
10320:                 }
10321:             }
10322:         }
10323: 
10324:         my %credits;
10325:         foreach my $type (@types) {
10326:             unless ($type eq 'community') {
10327:                 $credits{$type} = $env{'form.'.$type.'_credits'};
10328:                 $credits{$type} =~ s/[^\d.]+//g;
10329:             }
10330:         }
10331:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10332:             ($env{'form.coursecredits'} eq '1')) {
10333:             $changes{'coursecredits'} = 1;
10334:             foreach my $type (keys(%credits)) {
10335:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10336:             }
10337:         } else {
10338:             if ($env{'form.coursecredits'} eq '1') { 
10339:                 foreach my $type (@types) {
10340:                     unless ($type eq 'community') {
10341:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {        
10342:                             $changes{'coursecredits'} = 1;
10343:                         }
10344:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10345:                     }
10346:                 }
10347:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10348:                 foreach my $type (@types) {
10349:                     unless ($type eq 'community') {
10350:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10351:                             $changes{'coursecredits'} = 1;
10352:                             last;
10353:                         }
10354:                     }
10355:                 }
10356:             }
10357:         }
10358:         if ($env{'form.postsubmit'} eq '1') {
10359:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10360:             my %currtimeout;
10361:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10362:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10363:                     $changes{'postsubmit'} = 1;
10364:                 }
10365:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10366:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10367:                 }
10368:             } else {
10369:                 $changes{'postsubmit'} = 1;
10370:             }
10371:             foreach my $type (@types) {
10372:                 my $timeout = $env{'form.'.$type.'_timeout'};
10373:                 $timeout =~ s/\D//g;
10374:                 if ($timeout == $staticdefaults{'postsubmit'}) {
10375:                     $timeout = '';
10376:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10377:                     $timeout = '0';
10378:                 }
10379:                 unless ($timeout eq '') {
10380:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10381:                 }
10382:                 if (exists($currtimeout{$type})) {
10383:                     if ($timeout ne $currtimeout{$type}) {
10384:                         $changes{'postsubmit'} = 1; 
10385:                     }
10386:                 } elsif ($timeout ne '') {
10387:                     $changes{'postsubmit'} = 1;
10388:                 }
10389:             }
10390:         } else {
10391:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10392:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10393:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10394:                     $changes{'postsubmit'} = 1;
10395:                 }
10396:             } else {
10397:                 $changes{'postsubmit'} = 1;
10398:             }
10399:         }
10400:     }
10401:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10402:                                              $dom);
10403:     if ($putresult eq 'ok') {
10404:         if (keys(%changes) > 0) {
10405:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10406:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
10407:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) { 
10408:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme') { 
10409:                     if ($changes{$item}) {
10410:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10411:                     }
10412:                 } 
10413:                 if ($changes{'coursecredits'}) {
10414:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10415:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10416:                             $domdefaults{$type.'credits'} =
10417:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10418:                         }
10419:                     }
10420:                 }
10421:                 if ($changes{'postsubmit'}) {
10422:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10423:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10424:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10425:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10426:                                 $domdefaults{$type.'postsubtimeout'} =
10427:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10428:                             }
10429:                         }
10430:                     }
10431:                 }
10432:                 if ($changes{'uploadquota'}) {
10433:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10434:                         foreach my $type (@types) {
10435:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10436:                         }
10437:                     }
10438:                 }
10439:                 my $cachetime = 24*60*60;
10440:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10441:                 if (ref($lastactref) eq 'HASH') {
10442:                     $lastactref->{'domdefaults'} = 1;
10443:                 }
10444:             }
10445:             $resulttext = &mt('Changes made:').'<ul>';
10446:             foreach my $item (sort(keys(%changes))) {
10447:                 if ($item eq 'canuse_pdfforms') {
10448:                     if ($env{'form.'.$item} eq '1') {
10449:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10450:                     } else {
10451:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10452:                     }
10453:                 } elsif ($item eq 'uselcmath') {
10454:                     if ($env{'form.'.$item} eq '1') {
10455:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
10456:                     } else {
10457:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10458:                     }
10459:                 } elsif ($item eq 'usejsme') {
10460:                     if ($env{'form.'.$item} eq '1') {
10461:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10462:                     } else {
10463:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>'; 
10464:                     }
10465:                 } elsif ($item eq 'anonsurvey_threshold') {
10466:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
10467:                 } elsif ($item eq 'uploadquota') {
10468:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10469:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10470:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10471:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
10472:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10473: 
10474:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10475:                                        '</ul>'.
10476:                                        '</li>';
10477:                     } else {
10478:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10479:                     }
10480:                 } elsif ($item eq 'postsubmit') {
10481:                     if ($domdefaults{'postsubmit'} eq 'off') {
10482:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10483:                     } else {
10484:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10485:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') { 
10486:                             $resulttext .= &mt('durations:').'<ul>';
10487:                             foreach my $type (@types) {
10488:                                 $resulttext .= '<li>';
10489:                                 my $timeout;
10490:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10491:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10492:                                 }
10493:                                 my $display;
10494:                                 if ($timeout eq '0') {
10495:                                     $display = &mt('unlimited');
10496:                                 } elsif ($timeout eq '') {
10497:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10498:                                 } else {
10499:                                     $display = &mt('[quant,_1,second]',$timeout);
10500:                                 }
10501:                                 if ($type eq 'community') {
10502:                                     $resulttext .= &mt('Communities');
10503:                                 } elsif ($type eq 'official') {
10504:                                     $resulttext .= &mt('Official courses');
10505:                                 } elsif ($type eq 'unofficial') {
10506:                                     $resulttext .= &mt('Unofficial courses');
10507:                                 } elsif ($type eq 'textbook') {
10508:                                     $resulttext .= &mt('Textbook courses');
10509:                                 }
10510:                                 $resulttext .= ' -- '.$display.'</li>';
10511:                             }
10512:                             $resulttext .= '</ul>';
10513:                         }
10514:                         $resulttext .= '</li>';    
10515:                     }
10516:                 } elsif ($item eq 'coursecredits') {
10517:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10518:                         if (($domdefaults{'officialcredits'} eq '') &&
10519:                             ($domdefaults{'unofficialcredits'} eq '') &&
10520:                             ($domdefaults{'textbookcredits'} eq '')) {
10521:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10522:                         } else {
10523:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10524:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10525:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
10526:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
10527:                                            '</ul>'.
10528:                                            '</li>';
10529:                         }
10530:                     } else {
10531:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10532:                     }
10533:                 }
10534:             }
10535:             $resulttext .= '</ul>';
10536:         } else {
10537:             $resulttext = &mt('No changes made to course defaults');
10538:         }
10539:     } else {
10540:         $resulttext = '<span class="LC_error">'.
10541:             &mt('An error occurred: [_1]',$putresult).'</span>';
10542:     }
10543:     return $resulttext;
10544: }
10545: 
10546: sub modify_selfenrollment {
10547:     my ($dom,$lastactref,%domconfig) = @_;
10548:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10549:     my @types = ('official','unofficial','community','textbook');
10550:     my %titles = &tool_titles();
10551:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10552:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10553:     $ordered{'default'} = ['types','registered','approval','limit'];
10554: 
10555:     my (%roles,%shown,%toplevel);
10556:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
10557: 
10558:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10559:         if ($domconfig{'selfenrollment'} eq '') {
10560:             $domconfig{'selfenrollment'} = {};
10561:         }
10562:     }
10563:     %toplevel = (
10564:                   admin      => 'Configuration Rights',
10565:                   default    => 'Default settings',
10566:                   validation => 'Validation of self-enrollment requests',
10567:                 );
10568:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10569: 
10570:     if (ref($ordered{'admin'}) eq 'ARRAY') {
10571:         foreach my $item (@{$ordered{'admin'}}) {
10572:             foreach my $type (@types) {
10573:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10574:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
10575:                 } else {
10576:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
10577:                 }
10578:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10579:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10580:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
10581:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
10582:                             push(@{$changes{'admin'}{$type}},$item);
10583:                         }
10584:                     } else {
10585:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
10586:                             push(@{$changes{'admin'}{$type}},$item);
10587:                         }
10588:                     }
10589:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10590:                     push(@{$changes{'admin'}{$type}},$item);
10591:                 }
10592:             }
10593:         }
10594:     }
10595: 
10596:     foreach my $item (@{$ordered{'default'}}) {
10597:         foreach my $type (@types) {
10598:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10599:             if ($item eq 'types') {
10600:                 unless (($value eq 'all') || ($value eq 'dom')) {
10601:                     $value = '';
10602:                 }
10603:             } elsif ($item eq 'registered') {
10604:                 unless ($value eq '1') {
10605:                     $value = 0;
10606:                 }
10607:             } elsif ($item eq 'approval') {
10608:                 unless ($value =~ /^[012]$/) {
10609:                     $value = 0;
10610:                 }
10611:             } else {
10612:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10613:                     $value = 'none';
10614:                 }
10615:             }
10616:             $selfenrollhash{'default'}{$type}{$item} = $value;
10617:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10618:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10619:                     if ($selfenrollhash{'default'}{$type}{$item} ne
10620:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
10621:                          push(@{$changes{'default'}{$type}},$item);
10622:                     }
10623:                 } else {
10624:                     push(@{$changes{'default'}{$type}},$item);
10625:                 }
10626:             } else {
10627:                 push(@{$changes{'default'}{$type}},$item);
10628:             }
10629:             if ($item eq 'limit') {
10630:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10631:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10632:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10633:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10634:                     }
10635:                 } else {
10636:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
10637:                 }
10638:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10639:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
10640:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
10641:                          push(@{$changes{'default'}{$type}},'cap');
10642:                     }
10643:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10644:                     push(@{$changes{'default'}{$type}},'cap');
10645:                 }
10646:             }
10647:         }
10648:     }
10649: 
10650:     foreach my $item (@{$itemsref}) {
10651:         if ($item eq 'fields') {
10652:             my @changed;
10653:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10654:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10655:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10656:             }
10657:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10658:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10659:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10660:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
10661:                 } else {
10662:                     @changed = @{$selfenrollhash{'validation'}{$item}};
10663:                 }
10664:             } else {
10665:                 @changed = @{$selfenrollhash{'validation'}{$item}};
10666:             }
10667:             if (@changed) {
10668:                 if ($selfenrollhash{'validation'}{$item}) { 
10669:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10670:                 } else {
10671:                     $changes{'validation'}{$item} = &mt('None');
10672:                 }
10673:             }
10674:         } else {
10675:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10676:             if ($item eq 'markup') {
10677:                if ($env{'form.selfenroll_validation_'.$item}) {
10678:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10679:                }
10680:             }
10681:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10682:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10683:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10684:                 }
10685:             }
10686:         }
10687:     }
10688: 
10689:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10690:                                              $dom);
10691:     if ($putresult eq 'ok') {
10692:         if (keys(%changes) > 0) {
10693:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10694:             $resulttext = &mt('Changes made:').'<ul>';
10695:             foreach my $key ('admin','default','validation') {
10696:                 if (ref($changes{$key}) eq 'HASH') {
10697:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10698:                     if ($key eq 'validation') {
10699:                         foreach my $item (@{$itemsref}) {
10700:                             if (exists($changes{$key}{$item})) {
10701:                                 if ($item eq 'markup') {
10702:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10703:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10704:                                 } else {  
10705:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10706:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10707:                                 }
10708:                             }
10709:                         }
10710:                     } else {
10711:                         foreach my $type (@types) {
10712:                             if ($type eq 'community') {
10713:                                 $roles{'1'} = &mt('Community personnel');
10714:                             } else {
10715:                                 $roles{'1'} = &mt('Course personnel');
10716:                             }
10717:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
10718:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10719:                                     if ($key eq 'admin') {
10720:                                         my @mgrdc = ();
10721:                                         if (ref($ordered{$key}) eq 'ARRAY') {
10722:                                             foreach my $item (@{$ordered{'admin'}}) {
10723:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
10724:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10725:                                                         push(@mgrdc,$item);
10726:                                                     }
10727:                                                 }
10728:                                             }
10729:                                             if (@mgrdc) {
10730:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10731:                                             } else {
10732:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
10733:                                             }
10734:                                         }
10735:                                     } else {
10736:                                         if (ref($ordered{$key}) eq 'ARRAY') {
10737:                                             foreach my $item (@{$ordered{$key}}) {
10738:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10739:                                                     $domdefaults{$type.'selfenroll'.$item} =
10740:                                                         $selfenrollhash{$key}{$type}{$item};
10741:                                                 }
10742:                                             }
10743:                                         }
10744:                                     }
10745:                                 }
10746:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
10747:                                 foreach my $item (@{$ordered{$key}}) {
10748:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10749:                                         $resulttext .= '<li>';
10750:                                         if ($key eq 'admin') {
10751:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10752:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10753:                                         } else {
10754:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10755:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10756:                                         }
10757:                                         $resulttext .= '</li>';
10758:                                     }
10759:                                 }
10760:                                 $resulttext .= '</ul></li>';
10761:                             }
10762:                         }
10763:                         $resulttext .= '</ul></li>'; 
10764:                     }
10765:                 }
10766:                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10767:                     my $cachetime = 24*60*60;
10768:                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10769:                     if (ref($lastactref) eq 'HASH') {
10770:                         $lastactref->{'domdefaults'} = 1;
10771:                     }
10772:                 }
10773:             }
10774:             $resulttext .= '</ul>';
10775:         } else {
10776:             $resulttext = &mt('No changes made to self-enrollment settings');
10777:         }
10778:     } else {
10779:         $resulttext = '<span class="LC_error">'.
10780:             &mt('An error occurred: [_1]',$putresult).'</span>';
10781:     }
10782:     return $resulttext;
10783: }
10784: 
10785: sub modify_usersessions {
10786:     my ($dom,$lastactref,%domconfig) = @_;
10787:     my @hostingtypes = ('version','excludedomain','includedomain');
10788:     my @offloadtypes = ('primary','default');
10789:     my %types = (
10790:                   remote => \@hostingtypes,
10791:                   hosted => \@hostingtypes,
10792:                   spares => \@offloadtypes,
10793:                 );
10794:     my @prefixes = ('remote','hosted','spares');
10795:     my @lcversions = &Apache::lonnet::all_loncaparevs();
10796:     my (%by_ip,%by_location,@intdoms);
10797:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10798:     my @locations = sort(keys(%by_location));
10799:     my (%defaultshash,%changes);
10800:     foreach my $prefix (@prefixes) {
10801:         $defaultshash{'usersessions'}{$prefix} = {};
10802:     }
10803:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10804:     my $resulttext;
10805:     my %iphost = &Apache::lonnet::get_iphost();
10806:     foreach my $prefix (@prefixes) {
10807:         next if ($prefix eq 'spares');
10808:         foreach my $type (@{$types{$prefix}}) {
10809:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10810:             if ($type eq 'version') {
10811:                 my $value = $env{'form.'.$prefix.'_'.$type};
10812:                 my $okvalue;
10813:                 if ($value ne '') {
10814:                     if (grep(/^\Q$value\E$/,@lcversions)) {
10815:                         $okvalue = $value;
10816:                     }
10817:                 }
10818:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
10819:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10820:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10821:                             if ($inuse == 0) {
10822:                                 $changes{$prefix}{$type} = 1;
10823:                             } else {
10824:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10825:                                     $changes{$prefix}{$type} = 1;
10826:                                 }
10827:                                 if ($okvalue ne '') {
10828:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10829:                                 } 
10830:                             }
10831:                         } else {
10832:                             if (($inuse == 1) && ($okvalue ne '')) {
10833:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10834:                                 $changes{$prefix}{$type} = 1;
10835:                             }
10836:                         }
10837:                     } else {
10838:                         if (($inuse == 1) && ($okvalue ne '')) {
10839:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10840:                             $changes{$prefix}{$type} = 1;
10841:                         }
10842:                     }
10843:                 } else {
10844:                     if (($inuse == 1) && ($okvalue ne '')) {
10845:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10846:                         $changes{$prefix}{$type} = 1;
10847:                     }
10848:                 }
10849:             } else {
10850:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10851:                 my @okvals;
10852:                 foreach my $val (@vals) {
10853:                     if ($val =~ /:/) {
10854:                         my @items = split(/:/,$val);
10855:                         foreach my $item (@items) {
10856:                             if (ref($by_location{$item}) eq 'ARRAY') {
10857:                                 push(@okvals,$item);
10858:                             }
10859:                         }
10860:                     } else {
10861:                         if (ref($by_location{$val}) eq 'ARRAY') {
10862:                             push(@okvals,$val);
10863:                         }
10864:                     }
10865:                 }
10866:                 @okvals = sort(@okvals);
10867:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
10868:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10869:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10870:                             if ($inuse == 0) {
10871:                                 $changes{$prefix}{$type} = 1; 
10872:                             } else {
10873:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10874:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10875:                                 if (@changed > 0) {
10876:                                     $changes{$prefix}{$type} = 1;
10877:                                 }
10878:                             }
10879:                         } else {
10880:                             if ($inuse == 1) {
10881:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10882:                                 $changes{$prefix}{$type} = 1;
10883:                             }
10884:                         } 
10885:                     } else {
10886:                         if ($inuse == 1) {
10887:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10888:                             $changes{$prefix}{$type} = 1;
10889:                         }
10890:                     }
10891:                 } else {
10892:                     if ($inuse == 1) {
10893:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10894:                         $changes{$prefix}{$type} = 1;
10895:                     }
10896:                 }
10897:             }
10898:         }
10899:     }
10900: 
10901:     my @alldoms = &Apache::lonnet::all_domains();
10902:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
10903:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10904:     my $savespares;
10905: 
10906:     foreach my $lonhost (sort(keys(%servers))) {
10907:         my $serverhomeID =
10908:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
10909:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
10910:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10911:         my %spareschg;
10912:         foreach my $type (@{$types{'spares'}}) {
10913:             my @okspares;
10914:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10915:             foreach my $server (@checked) {
10916:                 if (&Apache::lonnet::hostname($server) ne '') {
10917:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10918:                         unless (grep(/^\Q$server\E$/,@okspares)) {
10919:                             push(@okspares,$server);
10920:                         }
10921:                     }
10922:                 }
10923:             }
10924:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10925:             my $newspare;
10926:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10927:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
10928:                     $newspare = $new;
10929:                 }
10930:             }
10931:             my @spares;
10932:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10933:                 @spares = sort(@okspares,$newspare);
10934:             } else {
10935:                 @spares = sort(@okspares);
10936:             }
10937:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
10938:             if (ref($spareid{$lonhost}) eq 'HASH') {
10939:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
10940:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
10941:                     if (@diffs > 0) {
10942:                         $spareschg{$type} = 1;
10943:                     }
10944:                 }
10945:             }
10946:         }
10947:         if (keys(%spareschg) > 0) {
10948:             $changes{'spares'}{$lonhost} = \%spareschg;
10949:         }
10950:     }
10951:     $defaultshash{'usersessions'}{'offloadnow'} = {};
10952:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
10953:     my @okoffload;
10954:     if (@offloadnow) {
10955:         foreach my $server (@offloadnow) {
10956:             if (&Apache::lonnet::hostname($server) ne '') {
10957:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
10958:                     push(@okoffload,$server);
10959:                 }
10960:             }
10961:         }
10962:         if (@okoffload) {
10963:             foreach my $lonhost (@okoffload) {
10964:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
10965:             }
10966:         }
10967:     }
10968:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
10969:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10970:             if (ref($changes{'spares'}) eq 'HASH') {
10971:                 if (keys(%{$changes{'spares'}}) > 0) {
10972:                     $savespares = 1;
10973:                 }
10974:             }
10975:         } else {
10976:             $savespares = 1;
10977:         }
10978:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
10979:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
10980:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
10981:                     $changes{'offloadnow'} = 1;
10982:                     last;
10983:                 }
10984:             }
10985:             unless ($changes{'offloadnow'}) {
10986:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) { 
10987:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
10988:                         $changes{'offloadnow'} = 1;
10989:                         last;
10990:                     }
10991:                 }
10992:             }
10993:         } elsif (@okoffload) {
10994:             $changes{'offloadnow'} = 1;
10995:         }
10996:     } elsif (@okoffload) {
10997:         $changes{'offloadnow'} = 1;
10998:     }
10999:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
11000:     if ((keys(%changes) > 0) || ($savespares)) {
11001:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11002:                                                  $dom);
11003:         if ($putresult eq 'ok') {
11004:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11005:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
11006:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
11007:                 }
11008:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
11009:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
11010:                 }
11011:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11012:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
11013:                 }
11014:             }
11015:             my $cachetime = 24*60*60;
11016:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11017:             if (ref($lastactref) eq 'HASH') {
11018:                 $lastactref->{'domdefaults'} = 1;
11019:             }
11020:             if (keys(%changes) > 0) {
11021:                 my %lt = &usersession_titles();
11022:                 $resulttext = &mt('Changes made:').'<ul>';
11023:                 foreach my $prefix (@prefixes) {
11024:                     if (ref($changes{$prefix}) eq 'HASH') {
11025:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11026:                         if ($prefix eq 'spares') {
11027:                             if (ref($changes{$prefix}) eq 'HASH') {
11028:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11029:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
11030:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
11031:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11032:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11033:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11034:                                         foreach my $type (@{$types{$prefix}}) {
11035:                                             if ($changes{$prefix}{$lonhost}{$type}) {
11036:                                                 my $offloadto = &mt('None');
11037:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11038:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
11039:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11040:                                                     }
11041:                                                 }
11042:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
11043:                                             }
11044:                                         }
11045:                                     }
11046:                                     $resulttext .= '</li>';
11047:                                 }
11048:                             }
11049:                         } else {
11050:                             foreach my $type (@{$types{$prefix}}) {
11051:                                 if (defined($changes{$prefix}{$type})) {
11052:                                     my $newvalue;
11053:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11054:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
11055:                                             if ($type eq 'version') {
11056:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11057:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11058:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11059:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11060:                                                 }
11061:                                             }
11062:                                         }
11063:                                     }
11064:                                     if ($newvalue eq '') {
11065:                                         if ($type eq 'version') {
11066:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11067:                                         } else {
11068:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11069:                                         }
11070:                                     } else {
11071:                                         if ($type eq 'version') {
11072:                                             $newvalue .= ' '.&mt('(or later)'); 
11073:                                         }
11074:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
11075:                                     }
11076:                                 }
11077:                             }
11078:                         }
11079:                         $resulttext .= '</ul>';
11080:                     }
11081:                 }
11082:                 if ($changes{'offloadnow'}) {
11083:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11084:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11085:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11086:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11087:                                 $resulttext .= '<li>'.$lonhost.'</li>';
11088:                             }
11089:                             $resulttext .= '</ul>';
11090:                         } else {
11091:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11092:                         }
11093:                     } else {
11094:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11095:                     }
11096:                 }
11097:                 $resulttext .= '</ul>';
11098:             } else {
11099:                 $resulttext = $nochgmsg;
11100:             }
11101:         } else {
11102:             $resulttext = '<span class="LC_error">'.
11103:                           &mt('An error occurred: [_1]',$putresult).'</span>';
11104:         }
11105:     } else {
11106:         $resulttext = $nochgmsg;
11107:     }
11108:     return $resulttext;
11109: }
11110: 
11111: sub modify_loadbalancing {
11112:     my ($dom,%domconfig) = @_;
11113:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
11114:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
11115:     my ($othertitle,$usertypes,$types) =
11116:         &Apache::loncommon::sorted_inst_types($dom);
11117:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
11118:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
11119:     my @sparestypes = ('primary','default');
11120:     my %typetitles = &sparestype_titles();
11121:     my $resulttext;
11122:     my (%currbalancer,%currtargets,%currrules,%existing);
11123:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11124:         %existing = %{$domconfig{'loadbalancing'}};
11125:     }
11126:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11127:                               \%currtargets,\%currrules);
11128:     my ($saveloadbalancing,%defaultshash,%changes);
11129:     my ($alltypes,$othertypes,$titles) =
11130:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11131:     my %ruletitles = &offloadtype_text();
11132:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11133:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11134:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11135:         if ($balancer eq '') {
11136:             next;
11137:         }
11138:         if (!exists($servers{$balancer})) {
11139:             if (exists($currbalancer{$balancer})) {
11140:                 push(@{$changes{'delete'}},$balancer);
11141:             }
11142:             next;
11143:         }
11144:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11145:             push(@{$changes{'delete'}},$balancer);
11146:             next;
11147:         }
11148:         if (!exists($currbalancer{$balancer})) {
11149:             push(@{$changes{'add'}},$balancer);
11150:         }
11151:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11152:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11153:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11154:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11155:             $saveloadbalancing = 1;
11156:         }
11157:         foreach my $sparetype (@sparestypes) {
11158:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11159:             my @offloadto;
11160:             foreach my $target (@targets) {
11161:                 if (($servers{$target}) && ($target ne $balancer)) {
11162:                     if ($sparetype eq 'default') {
11163:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11164:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
11165:                         }
11166:                     }
11167:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
11168:                         push(@offloadto,$target);
11169:                     }
11170:                 }
11171:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
11172:             }
11173:         }
11174:         if (ref($currtargets{$balancer}) eq 'HASH') {
11175:             foreach my $sparetype (@sparestypes) {
11176:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11177:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
11178:                     if (@targetdiffs > 0) {
11179:                         $changes{'curr'}{$balancer}{'targets'} = 1;
11180:                     }
11181:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11182:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11183:                         $changes{'curr'}{$balancer}{'targets'} = 1;
11184:                     }
11185:                 }
11186:             }
11187:         } else {
11188:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11189:                 foreach my $sparetype (@sparestypes) {
11190:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11191:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11192:                             $changes{'curr'}{$balancer}{'targets'} = 1;
11193:                         }
11194:                     }
11195:                 }
11196:             }
11197:         }
11198:         my $ishomedom;
11199:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11200:             $ishomedom = 1;
11201:         }
11202:         if (ref($alltypes) eq 'ARRAY') {
11203:             foreach my $type (@{$alltypes}) {
11204:                 my $rule;
11205:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
11206:                          (!$ishomedom)) {
11207:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11208:                 }
11209:                 if ($rule eq 'specific') {
11210:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11211:                     if (exists($servers{$specifiedhost})) { 
11212:                         $rule = $specifiedhost;
11213:                     }
11214:                 }
11215:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11216:                 if (ref($currrules{$balancer}) eq 'HASH') {
11217:                     if ($rule ne $currrules{$balancer}{$type}) {
11218:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
11219:                     }
11220:                 } elsif ($rule ne '') {
11221:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
11222:                 }
11223:             }
11224:         }
11225:     }
11226:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11227:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11228:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11229:             $defaultshash{'loadbalancing'} = {};
11230:         }
11231:         my $putresult = &Apache::lonnet::put_dom('configuration',
11232:                                                  \%defaultshash,$dom);
11233:         if ($putresult eq 'ok') {
11234:             if (keys(%changes) > 0) {
11235:                 my %toupdate;
11236:                 if (ref($changes{'delete'}) eq 'ARRAY') {
11237:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
11238:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
11239:                         $toupdate{$balancer} = 1;
11240:                     }
11241:                 }
11242:                 if (ref($changes{'add'}) eq 'ARRAY') {
11243:                     foreach my $balancer (sort(@{$changes{'add'}})) {
11244:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
11245:                         $toupdate{$balancer} = 1;
11246:                     }
11247:                 }
11248:                 if (ref($changes{'curr'}) eq 'HASH') {
11249:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
11250:                         $toupdate{$balancer} = 1;
11251:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11252:                             if ($changes{'curr'}{$balancer}{'targets'}) {
11253:                                 my %offloadstr;
11254:                                 foreach my $sparetype (@sparestypes) {
11255:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11256:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11257:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11258:                                         }
11259:                                     }
11260:                                 }
11261:                                 if (keys(%offloadstr) == 0) {
11262:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
11263:                                 } else {
11264:                                     my $showoffload;
11265:                                     foreach my $sparetype (@sparestypes) {
11266:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
11267:                                         if (defined($offloadstr{$sparetype})) {
11268:                                             $showoffload .= $offloadstr{$sparetype};
11269:                                         } else {
11270:                                             $showoffload .= &mt('None');
11271:                                         }
11272:                                         $showoffload .= ('&nbsp;'x3);
11273:                                     }
11274:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
11275:                                 }
11276:                             }
11277:                         }
11278:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11279:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11280:                                 foreach my $type (@{$alltypes}) {
11281:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11282:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11283:                                         my $balancetext;
11284:                                         if ($rule eq '') {
11285:                                             $balancetext =  $ruletitles{'default'};
11286:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
11287:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) { 
11288:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11289:                                                 foreach my $sparetype (@sparestypes) {
11290:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11291:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11292:                                                     }
11293:                                                 }
11294:                                                 foreach my $item (@{$alltypes}) {
11295:                                                     next if ($item =~  /^_LC_ipchange/);
11296:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11297:                                                     if ($hasrule eq 'homeserver') {
11298:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
11299:                                                     } else {
11300:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11301:                                                             if ($servers{$hasrule}) {
11302:                                                                 $toupdate{$hasrule} = 1;
11303:                                                             }
11304:                                                         }
11305:                                                     }
11306:                                                 }
11307:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11308:                                                     $balancetext =  $ruletitles{$rule};
11309:                                                 } else {
11310:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11311:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
11312:                                                     if ($receiver) {
11313:                                                         $toupdate{$receiver};
11314:                                                     }
11315:                                                 }
11316:                                             } else {
11317:                                                 $balancetext =  $ruletitles{$rule};
11318:                                             }
11319:                                         } else {
11320:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11321:                                         }
11322:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
11323:                                     }
11324:                                 }
11325:                             }
11326:                         }
11327:                         if (keys(%toupdate)) {
11328:                             my %thismachine;
11329:                             my $updatedhere;
11330:                             my $cachetime = 60*60*24;
11331:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11332:                             foreach my $lonhost (keys(%toupdate)) {
11333:                                 if ($thismachine{$lonhost}) {
11334:                                     unless ($updatedhere) {
11335:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11336:                                                                       $defaultshash{'loadbalancing'},
11337:                                                                       $cachetime);
11338:                                         $updatedhere = 1;
11339:                                     }
11340:                                 } else {
11341:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11342:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11343:                                 }
11344:                             }
11345:                         }
11346:                     }
11347:                 }
11348:                 if ($resulttext ne '') {
11349:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
11350:                 } else {
11351:                     $resulttext = $nochgmsg;
11352:                 }
11353:             } else {
11354:                 $resulttext = $nochgmsg;
11355:             }
11356:         } else {
11357:             $resulttext = '<span class="LC_error">'.
11358:                           &mt('An error occurred: [_1]',$putresult).'</span>';
11359:         }
11360:     } else {
11361:         $resulttext = $nochgmsg;
11362:     }
11363:     return $resulttext;
11364: }
11365: 
11366: sub recurse_check {
11367:     my ($chkcats,$categories,$depth,$name) = @_;
11368:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11369:         my $chg = 0;
11370:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11371:             my $category = $chkcats->[$depth]{$name}[$j];
11372:             my $item;
11373:             if ($category eq '') {
11374:                 $chg ++;
11375:             } else {
11376:                 my $deeper = $depth + 1;
11377:                 $item = &escape($category).':'.&escape($name).':'.$depth;
11378:                 if ($chg) {
11379:                     $categories->{$item} -= $chg;
11380:                 }
11381:                 &recurse_check($chkcats,$categories,$deeper,$category);
11382:                 $deeper --;
11383:             }
11384:         }
11385:     }
11386:     return;
11387: }
11388: 
11389: sub recurse_cat_deletes {
11390:     my ($item,$coursecategories,$deletions) = @_;
11391:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11392:     my $subdepth = $depth + 1;
11393:     if (ref($coursecategories) eq 'HASH') {
11394:         foreach my $subitem (keys(%{$coursecategories})) {
11395:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11396:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11397:                 delete($coursecategories->{$subitem});
11398:                 $deletions->{$subitem} = 1;
11399:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
11400:             }
11401:         }
11402:     }
11403:     return;
11404: }
11405: 
11406: sub get_active_dcs {
11407:     my ($dom) = @_;
11408:     my $now = time;
11409:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
11410:     my %domcoords;
11411:     my $numdcs = 0;
11412:     foreach my $server (keys(%dompersonnel)) {
11413:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11414:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
11415:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
11416:         }
11417:     }
11418:     return %domcoords;
11419: }
11420: 
11421: sub active_dc_picker {
11422:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
11423:     my %domcoords = &get_active_dcs($dom);
11424:     my @domcoord = keys(%domcoords);
11425:     if (keys(%currhash)) {
11426:         foreach my $dc (keys(%currhash)) {
11427:             unless (exists($domcoords{$dc})) {
11428:                 push(@domcoord,$dc);
11429:             }
11430:         }
11431:     }
11432:     @domcoord = sort(@domcoord);
11433:     my $numdcs = scalar(@domcoord);
11434:     my $rows = 0;
11435:     my $table;
11436:     if ($numdcs > 1) {
11437:         $table = '<table>';
11438:         for (my $i=0; $i<@domcoord; $i++) {
11439:             my $rem = $i%($numinrow);
11440:             if ($rem == 0) {
11441:                 if ($i > 0) {
11442:                     $table .= '</tr>';
11443:                 }
11444:                 $table .= '<tr>';
11445:                 $rows ++;
11446:             }
11447:             my $check = '';
11448:             if ($inputtype eq 'radio') {
11449:                 if (keys(%currhash) == 0) {
11450:                     if (!$i) {
11451:                         $check = ' checked="checked"';
11452:                     }
11453:                 } elsif (exists($currhash{$domcoord[$i]})) {
11454:                     $check = ' checked="checked"';
11455:                 }
11456:             } else {
11457:                 if (exists($currhash{$domcoord[$i]})) {
11458:                     $check = ' checked="checked"';
11459:                 }
11460:             }
11461:             if ($i == @domcoord - 1) {
11462:                 my $colsleft = $numinrow - $rem;
11463:                 if ($colsleft > 1) {
11464:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
11465:                 } else {
11466:                     $table .= '<td class="LC_left_item">';
11467:                 }
11468:             } else {
11469:                 $table .= '<td class="LC_left_item">';
11470:             }
11471:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11472:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11473:             $table .= '<span class="LC_nobreak"><label>'.
11474:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
11475:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11476:             if ($user ne $dcname.':'.$dcdom) {
11477:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
11478:             }
11479:             $table .= '</label></span></td>';
11480:         }
11481:         $table .= '</tr></table>';
11482:     } elsif ($numdcs == 1) {
11483:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
11484:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11485:         if ($inputtype eq 'radio') {
11486:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
11487:             if ($user ne $dcname.':'.$dcdom) {
11488:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
11489:             }
11490:         } else {
11491:             my $check;
11492:             if (exists($currhash{$domcoord[0]})) {
11493:                 $check = ' checked="checked"';
11494:             }
11495:             $table = '<span class="LC_nobreak"><label>'.
11496:                      '<input type="checkbox" name="'.$name.'" '.
11497:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
11498:             if ($user ne $dcname.':'.$dcdom) {
11499:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
11500:             }
11501:             $table .= '</label></span>';
11502:             $rows ++;
11503:         }
11504:     }
11505:     return ($numdcs,$table,$rows);
11506: }
11507: 
11508: sub usersession_titles {
11509:     return &Apache::lonlocal::texthash(
11510:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11511:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
11512:                spares => 'Servers offloaded to, when busy',
11513:                version => 'LON-CAPA version requirement',
11514:                excludedomain => 'Allow all, but exclude specific domains',
11515:                includedomain => 'Deny all, but include specific domains',
11516:                primary => 'Primary (checked first)',
11517:                default => 'Default',
11518:            );
11519: }
11520: 
11521: sub id_for_thisdom {
11522:     my (%servers) = @_;
11523:     my %altids;
11524:     foreach my $server (keys(%servers)) {
11525:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11526:         if ($serverhome ne $server) {
11527:             $altids{$serverhome} = $server;
11528:         }
11529:     }
11530:     return %altids;
11531: }
11532: 
11533: sub count_servers {
11534:     my ($currbalancer,%servers) = @_;
11535:     my (@spares,$numspares);
11536:     foreach my $lonhost (sort(keys(%servers))) {
11537:         next if ($currbalancer eq $lonhost);
11538:         push(@spares,$lonhost);
11539:     }
11540:     if ($currbalancer) {
11541:         $numspares = scalar(@spares);
11542:     } else {
11543:         $numspares = scalar(@spares) - 1;
11544:     }
11545:     return ($numspares,@spares);
11546: }
11547: 
11548: sub lonbalance_targets_js {
11549:     my ($dom,$types,$servers,$settings) = @_;
11550:     my $select = &mt('Select');
11551:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
11552:     if (ref($servers) eq 'HASH') {
11553:         $alltargets = join("','",sort(keys(%{$servers})));
11554:         my @homedoms;
11555:         foreach my $server (sort(keys(%{$servers}))) {
11556:             if (&Apache::lonnet::host_domain($server) eq $dom) {
11557:                 push(@homedoms,'1');
11558:             } else {
11559:                 push(@homedoms,'0');
11560:             }
11561:         }
11562:         $allishome = join("','",@homedoms);
11563:     }
11564:     if (ref($types) eq 'ARRAY') {
11565:         if (@{$types} > 0) {
11566:             @alltypes = @{$types};
11567:         }
11568:     }
11569:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11570:     $allinsttypes = join("','",@alltypes);
11571:     my (%currbalancer,%currtargets,%currrules,%existing);
11572:     if (ref($settings) eq 'HASH') {
11573:         %existing = %{$settings};
11574:     }
11575:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11576:                               \%currtargets,\%currrules);
11577:     my $balancers = join("','",sort(keys(%currbalancer)));
11578:     return <<"END";
11579: 
11580: <script type="text/javascript">
11581: // <![CDATA[
11582: 
11583: currBalancers = new Array('$balancers');
11584: 
11585: function toggleTargets(balnum) {
11586:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11587:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11588:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11589:     var prevbalancer = prevhostitem.value;
11590:     var baltotal = document.getElementById('loadbalancing_total').value;
11591:     prevhostitem.value = balancer;
11592:     if (prevbalancer != '') {
11593:         var prevIdx = currBalancers.indexOf(prevbalancer);
11594:         if (prevIdx != -1) {
11595:             currBalancers.splice(prevIdx,1);
11596:         }
11597:     }
11598:     if (balancer == '') {
11599:         hideSpares(balnum);
11600:     } else {
11601:         var currIdx = currBalancers.indexOf(balancer);
11602:         if (currIdx == -1) {
11603:             currBalancers.push(balancer);
11604:         }
11605:         var homedoms = new Array('$allishome');
11606:         var ishomedom = homedoms[lonhostitem.selectedIndex];
11607:         showSpares(balancer,ishomedom,balnum);
11608:     }
11609:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
11610:     return;
11611: }
11612: 
11613: function showSpares(balancer,ishomedom,balnum) {
11614:     var alltargets = new Array('$alltargets');
11615:     var insttypes = new Array('$allinsttypes');
11616:     var offloadtypes = new Array('primary','default');
11617: 
11618:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11619:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
11620:  
11621:     for (var i=0; i<offloadtypes.length; i++) {
11622:         var count = 0;
11623:         for (var j=0; j<alltargets.length; j++) {
11624:             if (alltargets[j] != balancer) {
11625:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11626:                 item.value = alltargets[j];
11627:                 item.style.textAlign='left';
11628:                 item.style.textFace='normal';
11629:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11630:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
11631:                     item.disabled = '';
11632:                 } else {
11633:                     item.disabled = 'disabled';
11634:                     item.checked = false;
11635:                 }
11636:                 count ++;
11637:             }
11638:         }
11639:     }
11640:     for (var k=0; k<insttypes.length; k++) {
11641:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
11642:             if (ishomedom == 1) {
11643:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11644:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
11645:             } else {
11646:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11647:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
11648:             }
11649:         } else {
11650:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11651:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
11652:         }
11653:         if ((insttypes[k] != '_LC_external') && 
11654:             ((insttypes[k] != '_LC_internetdom') ||
11655:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
11656:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11657:             item.options.length = 0;
11658:             item.options[0] = new Option("","",true,true);
11659:             var idx = 0;
11660:             for (var m=0; m<alltargets.length; m++) {
11661:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11662:                     idx ++;
11663:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11664:                 }
11665:             }
11666:         }
11667:     }
11668:     return;
11669: }
11670: 
11671: function hideSpares(balnum) {
11672:     var alltargets = new Array('$alltargets');
11673:     var insttypes = new Array('$allinsttypes');
11674:     var offloadtypes = new Array('primary','default');
11675: 
11676:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11677:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
11678: 
11679:     var total = alltargets.length - 1;
11680:     for (var i=0; i<offloadtypes; i++) {
11681:         for (var j=0; j<total; j++) {
11682:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11683:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11684:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
11685:         }
11686:     }
11687:     for (var k=0; k<insttypes.length; k++) {
11688:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11689:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
11690:         if (insttypes[k] != '_LC_external') {
11691:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11692:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
11693:         }
11694:     }
11695:     return;
11696: }
11697: 
11698: function checkOffloads(item,balnum,type) {
11699:     var alltargets = new Array('$alltargets');
11700:     var offloadtypes = new Array('primary','default');
11701:     if (item.checked) {
11702:         var total = alltargets.length - 1;
11703:         var other;
11704:         if (type == offloadtypes[0]) {
11705:             other = offloadtypes[1];
11706:         } else {
11707:             other = offloadtypes[0];
11708:         }
11709:         for (var i=0; i<total; i++) {
11710:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
11711:             if (server == item.value) {
11712:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11713:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
11714:                 }
11715:             }
11716:         }
11717:     }
11718:     return;
11719: }
11720: 
11721: function singleServerToggle(balnum,type) {
11722:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
11723:     if (offloadtoSelIdx == 0) {
11724:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11725:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
11726: 
11727:     } else {
11728:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11729:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11730:     }
11731:     return;
11732: }
11733: 
11734: function balanceruleChange(formname,balnum,type) {
11735:     if (type == '_LC_external') {
11736:         return;
11737:     }
11738:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
11739:     for (var i=0; i<typesRules.length; i++) {
11740:         if (formname.elements[typesRules[i]].checked) {
11741:             if (formname.elements[typesRules[i]].value != 'specific') {
11742:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11743:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
11744:             } else {
11745:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11746:             }
11747:         }
11748:     }
11749:     return;
11750: }
11751: 
11752: function balancerDeleteChange(balnum) {
11753:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11754:     var baltotal = document.getElementById('loadbalancing_total').value;
11755:     var addtarget;
11756:     var removetarget;
11757:     var action = 'delete';
11758:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
11759:         var lonhost = hostitem.value;
11760:         var currIdx = currBalancers.indexOf(lonhost);
11761:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11762:             if (currIdx != -1) {
11763:                 currBalancers.splice(currIdx,1);
11764:             }
11765:             addtarget = lonhost;
11766:         } else {
11767:             if (currIdx == -1) {
11768:                 currBalancers.push(lonhost);
11769:             }
11770:             removetarget = lonhost;
11771:             action = 'undelete';
11772:         }
11773:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
11774:     }
11775:     return;
11776: }
11777: 
11778: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11779:     if (baltotal > 1) {
11780:         var offloadtypes = new Array('primary','default');
11781:         var alltargets = new Array('$alltargets');
11782:         var insttypes = new Array('$allinsttypes');
11783:         for (var i=0; i<baltotal; i++) {
11784:             if (i != balnum) {
11785:                 for (var j=0; j<offloadtypes.length; j++) {
11786:                     var total = alltargets.length - 1;
11787:                     for (var k=0; k<total; k++) {
11788:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11789:                         var server = serveritem.value;
11790:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
11791:                             if (server == addtarget) {
11792:                                 serveritem.disabled = '';
11793:                             }
11794:                         }
11795:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11796:                             if (server == removetarget) {
11797:                                 serveritem.disabled = 'disabled';
11798:                                 serveritem.checked = false;
11799:                             }
11800:                         }
11801:                     }
11802:                 }
11803:                 for (var j=0; j<insttypes.length; j++) {
11804:                     if (insttypes[j] != '_LC_external') {
11805:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11806:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11807:                             var currSel = singleserver.selectedIndex;
11808:                             var currVal = singleserver.options[currSel].value;
11809:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11810:                                 var numoptions = singleserver.options.length;
11811:                                 var needsnew = 1;
11812:                                 for (var k=0; k<numoptions; k++) {
11813:                                     if (singleserver.options[k] == addtarget) {
11814:                                         needsnew = 0;
11815:                                         break;
11816:                                     }
11817:                                 }
11818:                                 if (needsnew == 1) {
11819:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11820:                                 }
11821:                             }
11822:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11823:                                 singleserver.options.length = 0;
11824:                                 if ((currVal) && (currVal != removetarget)) {
11825:                                     singleserver.options[0] = new Option("","",false,false);
11826:                                 } else {
11827:                                     singleserver.options[0] = new Option("","",true,true);
11828:                                 }
11829:                                 var idx = 0;
11830:                                 for (var m=0; m<alltargets.length; m++) {
11831:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
11832:                                         idx ++;
11833:                                         if (currVal == alltargets[m]) {
11834:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11835:                                         } else {
11836:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11837:                                         }
11838:                                     }
11839:                                 }
11840:                             }
11841:                         }
11842:                     }
11843:                 }
11844:             }
11845:         }
11846:     }
11847:     return;
11848: }
11849: 
11850: // ]]>
11851: </script>
11852: 
11853: END
11854: }
11855: 
11856: sub new_spares_js {
11857:     my @sparestypes = ('primary','default');
11858:     my $types = join("','",@sparestypes);
11859:     my $select = &mt('Select');
11860:     return <<"END";
11861: 
11862: <script type="text/javascript">
11863: // <![CDATA[
11864: 
11865: function updateNewSpares(formname,lonhost) {
11866:     var types = new Array('$types');
11867:     var include = new Array();
11868:     var exclude = new Array();
11869:     for (var i=0; i<types.length; i++) {
11870:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11871:         for (var j=0; j<spareboxes.length; j++) {
11872:             if (formname.elements[spareboxes[j]].checked) {
11873:                 exclude.push(formname.elements[spareboxes[j]].value);
11874:             } else {
11875:                 include.push(formname.elements[spareboxes[j]].value);
11876:             }
11877:         }
11878:     }
11879:     for (var i=0; i<types.length; i++) {
11880:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11881:         var selIdx = newSpare.selectedIndex;
11882:         var currnew = newSpare.options[selIdx].value;
11883:         var okSpares = new Array();
11884:         for (var j=0; j<newSpare.options.length; j++) {
11885:             var possible = newSpare.options[j].value;
11886:             if (possible != '') {
11887:                 if (exclude.indexOf(possible) == -1) {
11888:                     okSpares.push(possible);
11889:                 } else {
11890:                     if (currnew == possible) {
11891:                         selIdx = 0;
11892:                     }
11893:                 }
11894:             }
11895:         }
11896:         for (var k=0; k<include.length; k++) {
11897:             if (okSpares.indexOf(include[k]) == -1) {
11898:                 okSpares.push(include[k]);
11899:             }
11900:         }
11901:         okSpares.sort();
11902:         newSpare.options.length = 0;
11903:         if (selIdx == 0) {
11904:             newSpare.options[0] = new Option("$select","",true,true);
11905:         } else {
11906:             newSpare.options[0] = new Option("$select","",false,false);
11907:         }
11908:         for (var m=0; m<okSpares.length; m++) {
11909:             var idx = m+1;
11910:             var selThis = 0;
11911:             if (selIdx != 0) {
11912:                 if (okSpares[m] == currnew) {
11913:                     selThis = 1;
11914:                 }
11915:             }
11916:             if (selThis == 1) {
11917:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11918:             } else {
11919:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11920:             }
11921:         }
11922:     }
11923:     return;
11924: }
11925: 
11926: function checkNewSpares(lonhost,type) {
11927:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11928:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
11929:     if (chosen != '') { 
11930:         var othertype;
11931:         var othernewSpare;
11932:         if (type == 'primary') {
11933:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
11934:         }
11935:         if (type == 'default') {
11936:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11937:         }
11938:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11939:             othernewSpare.selectedIndex = 0;
11940:         }
11941:     }
11942:     return;
11943: }
11944: 
11945: // ]]>
11946: </script>
11947: 
11948: END
11949: 
11950: }
11951: 
11952: sub common_domprefs_js {
11953:     return <<"END";
11954: 
11955: <script type="text/javascript">
11956: // <![CDATA[
11957: 
11958: function getIndicesByName(formname,item) {
11959:     var group = new Array();
11960:     for (var i=0;i<formname.elements.length;i++) {
11961:         if (formname.elements[i].name == item) {
11962:             group.push(formname.elements[i].id);
11963:         }
11964:     }
11965:     return group;
11966: }
11967: 
11968: // ]]>
11969: </script>
11970: 
11971: END
11972: 
11973: }
11974: 
11975: sub recaptcha_js {
11976:     my %lt = &captcha_phrases();
11977:     return <<"END";
11978: 
11979: <script type="text/javascript">
11980: // <![CDATA[
11981: 
11982: function updateCaptcha(caller,context) {
11983:     var privitem;
11984:     var pubitem;
11985:     var privtext;
11986:     var pubtext;
11987:     if (document.getElementById(context+'_recaptchapub')) {
11988:         pubitem = document.getElementById(context+'_recaptchapub');
11989:     } else {
11990:         return;
11991:     }
11992:     if (document.getElementById(context+'_recaptchapriv')) {
11993:         privitem = document.getElementById(context+'_recaptchapriv');
11994:     } else {
11995:         return;
11996:     }
11997:     if (document.getElementById(context+'_recaptchapubtxt')) {
11998:         pubtext = document.getElementById(context+'_recaptchapubtxt');
11999:     } else {
12000:         return;
12001:     }
12002:     if (document.getElementById(context+'_recaptchaprivtxt')) {
12003:         privtext = document.getElementById(context+'_recaptchaprivtxt');
12004:     } else {
12005:         return;
12006:     }
12007:     if (caller.checked) {
12008:         if (caller.value == 'recaptcha') {
12009:             pubitem.type = 'text';
12010:             privitem.type = 'text';
12011:             pubitem.size = '40';
12012:             privitem.size = '40';
12013:             pubtext.innerHTML = "$lt{'pub'}";
12014:             privtext.innerHTML = "$lt{'priv'}";
12015:         } else {
12016:             pubitem.type = 'hidden';
12017:             privitem.type = 'hidden';
12018:             pubtext.innerHTML = '';
12019:             privtext.innerHTML = '';
12020:         }
12021:     }
12022:     return;
12023: }
12024: 
12025: // ]]>
12026: </script>
12027: 
12028: END
12029: 
12030: }
12031: 
12032: sub toggle_display_js {
12033:     return <<"END";
12034: 
12035: <script type="text/javascript">
12036: // <![CDATA[
12037: 
12038: function toggleDisplay(domForm,caller) {
12039:     if (document.getElementById(caller)) {
12040:         var divitem = document.getElementById(caller);
12041:         var optionsElement = domForm.coursecredits;
12042:         if (caller == 'emailoptions') {
12043:             optionsElement = domForm.cancreate_email; 
12044:         }
12045:         if (caller == 'studentsubmission') {
12046:             optionsElement = domForm.postsubmit;
12047:         }
12048:         if (optionsElement.length) {
12049:             var currval;
12050:             for (var i=0; i<optionsElement.length; i++) {
12051:                 if (optionsElement[i].checked) {
12052:                    currval = optionsElement[i].value;
12053:                 }
12054:             }
12055:             if (currval == 1) {
12056:                 divitem.style.display = 'block';
12057:             } else {
12058:                 divitem.style.display = 'none';
12059:             }
12060:         }
12061:     }
12062:     return;
12063: }
12064: 
12065: // ]]>
12066: </script>
12067: 
12068: END
12069: 
12070: }
12071: 
12072: sub captcha_phrases {
12073:     return &Apache::lonlocal::texthash (
12074:                  priv => 'Private key',
12075:                  pub  => 'Public key',
12076:                  original  => 'original (CAPTCHA)',
12077:                  recaptcha => 'successor (ReCAPTCHA)',
12078:                  notused   => 'unused',
12079:     );
12080: }
12081: 
12082: sub devalidate_remote_domconfs {
12083:     my ($dom,$cachekeys) = @_;
12084:     return unless (ref($cachekeys) eq 'HASH');
12085:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
12086:     my %thismachine;
12087:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12088:     my @posscached = ('domainconfig','domdefaults');
12089:     if (keys(%servers)) {
12090:         foreach my $server (keys(%servers)) {
12091:             next if ($thismachine{$server});
12092:             my @cached;
12093:             foreach my $name (@posscached) {
12094:                 if ($cachekeys->{$name}) {
12095:                     push(@cached,&escape($name).':'.&escape($dom));
12096:                 }
12097:             }
12098:             if (@cached) {
12099:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12100:             }
12101:         }
12102:     }
12103:     return;
12104: }
12105: 
12106: 1;

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