File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.160.6.22: download - view: text, annotated - select for diffs
Thu Aug 8 00:54:47 2013 UTC (10 years, 10 months ago) by raeburn
Branches: version_2_11_X
Diff to branchpoint 1.160: preferred, unified
- For 2.11
  - Backport 1.200, 1.201, 1.202.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.160.6.22 2013/08/08 00:54:47 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: 
  101: Outputs: 1
  102: 
  103: $datatable  - HTML containing form elements which allow settings to be changed. 
  104: 
  105: In the case of course requests, radio buttons are displayed for each institutional
  106: affiliate type (and also default, and _LC_adv) for each of the course types 
  107: (official, unofficial and community).  In each case the radio buttons allow the 
  108: selection of one of four values:
  109: 
  110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
  111: which have the following effects:
  112: 
  113: 0
  114: 
  115: =over
  116: 
  117: - course requests are not allowed for this course types/affiliation
  118: 
  119: =back
  120: 
  121: approval 
  122: 
  123: =over 
  124: 
  125: - course requests must be approved by a Doman Coordinator in the 
  126: course's domain
  127: 
  128: =back
  129: 
  130: validate 
  131: 
  132: =over
  133: 
  134: - an institutional validation (e.g., check requestor is instructor
  135: of record) needs to be passed before the course will be created.  The required
  136: validation is in localenroll.pm on the primary library server for the course 
  137: domain.
  138: 
  139: =back
  140: 
  141: autolimit 
  142: 
  143: =over
  144:  
  145: - course requests will be processed automatically up to a limit of
  146: N requests for the course type for the particular requestor.
  147: If N is undefined, there is no limit to the number of course requests
  148: which a course owner may submit and have processed automatically. 
  149: 
  150: =back
  151: 
  152: =item modify_quotas() 
  153: 
  154: =back
  155: 
  156: =cut
  157: 
  158: package Apache::domainprefs;
  159: 
  160: use strict;
  161: use Apache::Constants qw(:common :http);
  162: use Apache::lonnet;
  163: use Apache::loncommon();
  164: use Apache::lonhtmlcommon();
  165: use Apache::lonlocal;
  166: use Apache::lonmsg();
  167: use Apache::lonconfigsettings;
  168: use LONCAPA qw(:DEFAULT :match);
  169: use LONCAPA::Enrollment;
  170: use LONCAPA::lonauthcgi();
  171: use File::Copy;
  172: use Locale::Language;
  173: use DateTime::TimeZone;
  174: use DateTime::Locale;
  175: 
  176: my $registered_cleanup;
  177: my $modified_urls;
  178: 
  179: sub handler {
  180:     my $r=shift;
  181:     if ($r->header_only) {
  182:         &Apache::loncommon::content_type($r,'text/html');
  183:         $r->send_http_header;
  184:         return OK;
  185:     }
  186: 
  187:     my $context = 'domain';
  188:     my $dom = $env{'request.role.domain'};
  189:     my $domdesc = &Apache::lonnet::domain($dom,'description');
  190:     if (&Apache::lonnet::allowed('mau',$dom)) {
  191:         &Apache::loncommon::content_type($r,'text/html');
  192:         $r->send_http_header;
  193:     } else {
  194:         $env{'user.error.msg'}=
  195:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
  196:         return HTTP_NOT_ACCEPTABLE;
  197:     }
  198: 
  199:     $registered_cleanup=0;
  200:     @{$modified_urls}=();
  201: 
  202:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  203:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  204:                                             ['phase','actions']);
  205:     my $phase = 'pickactions';
  206:     if ( exists($env{'form.phase'}) ) {
  207:         $phase = $env{'form.phase'};
  208:     }
  209:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
  210:     my %domconfig =
  211:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
  212:                 'quotas','autoenroll','autoupdate','autocreate',
  213:                 'directorysrch','usercreation','usermodification',
  214:                 'contacts','defaults','scantron','coursecategories',
  215:                 'serverstatuses','requestcourses','coursedefaults',
  216:                 'usersessions','loadbalancing','requestauthor'],$dom);
  217:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
  218:                        'autoupdate','autocreate','directorysrch','contacts',
  219:                        'usercreation','usermodification','scantron',
  220:                        'requestcourses','requestauthor','coursecategories',
  221:                        'serverstatuses','coursedefaults','usersessions');
  222:     my %existing;
  223:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
  224:         %existing = %{$domconfig{'loadbalancing'}};
  225:     }
  226:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
  227:         push(@prefs_order,'loadbalancing');
  228:     }
  229:     my %prefs = (
  230:         'rolecolors' =>
  231:                    { text => 'Default color schemes',
  232:                      help => 'Domain_Configuration_Color_Schemes',
  233:                      header => [{col1 => 'Student Settings',
  234:                                  col2 => '',},
  235:                                 {col1 => 'Coordinator Settings',
  236:                                  col2 => '',},
  237:                                 {col1 => 'Author Settings',
  238:                                  col2 => '',},
  239:                                 {col1 => 'Administrator Settings',
  240:                                  col2 => '',}],
  241:                     },
  242:         'login' =>
  243:                     { text => 'Log-in page options',
  244:                       help => 'Domain_Configuration_Login_Page',
  245:                       header => [{col1 => 'Log-in Page Items',
  246:                                   col2 => '',},
  247:                                  {col1 => 'Log-in Help',
  248:                                   col2 => 'Value'}],
  249:                     },
  250:         'defaults' => 
  251:                     { text => 'Default authentication/language/timezone/portal',
  252:                       help => 'Domain_Configuration_LangTZAuth',
  253:                       header => [{col1 => 'Setting',
  254:                                   col2 => 'Value'}],
  255:                     },
  256:         'quotas' => 
  257:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
  258:                       help => 'Domain_Configuration_Quotas',
  259:                       header => [{col1 => 'User affiliation',
  260:                                   col2 => 'Available tools',
  261:                                   col3 => 'Quotas, Mb; (Authoring requires role)',}],
  262:                     },
  263:         'autoenroll' =>
  264:                    { text => 'Auto-enrollment settings',
  265:                      help => 'Domain_Configuration_Auto_Enrollment',
  266:                      header => [{col1 => 'Configuration setting',
  267:                                  col2 => 'Value(s)'}],
  268:                    },
  269:         'autoupdate' => 
  270:                    { text => 'Auto-update settings',
  271:                      help => 'Domain_Configuration_Auto_Updates',
  272:                      header => [{col1 => 'Setting',
  273:                                  col2 => 'Value',},
  274:                                 {col1 => 'Setting',
  275:                                  col2 => 'Affiliation'},
  276:                                 {col1 => 'User population',
  277:                                  col2 => 'Updateable user data'}],
  278:                   },
  279:         'autocreate' => 
  280:                   { text => 'Auto-course creation settings',
  281:                      help => 'Domain_Configuration_Auto_Creation',
  282:                      header => [{col1 => 'Configuration Setting',
  283:                                  col2 => 'Value',}],
  284:                   },
  285:         'directorysrch' => 
  286:                   { text => 'Institutional directory searches',
  287:                     help => 'Domain_Configuration_InstDirectory_Search',
  288:                     header => [{col1 => 'Setting',
  289:                                 col2 => 'Value',}],
  290:                   },
  291:         'contacts' =>
  292:                   { text => 'Contact Information',
  293:                     help => 'Domain_Configuration_Contact_Info',
  294:                     header => [{col1 => 'Setting',
  295:                                 col2 => 'Value',}],
  296:                   },
  297: 
  298:         'usercreation' => 
  299:                   { text => 'User creation',
  300:                     help => 'Domain_Configuration_User_Creation',
  301:                     header => [{col1 => 'Format rule type',
  302:                                 col2 => 'Format rules in force'},
  303:                                {col1 => 'User account creation',
  304:                                 col2 => 'Usernames which may be created',},
  305:                                {col1 => 'Context',
  306:                                 col2 => 'Assignable authentication types'}],
  307:                   },
  308:         'usermodification' =>
  309:                   { text => 'User modification',
  310:                     help => 'Domain_Configuration_User_Modification',
  311:                     header => [{col1 => 'Target user has role',
  312:                                 col2 => 'User information updateable in author context'},
  313:                                {col1 => 'Target user has role',
  314:                                 col2 => 'User information updateable in course context'},
  315:                                {col1 => "Status of user",
  316:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
  317:                   },
  318:         'scantron' =>
  319:                   { text => 'Bubblesheet format file',
  320:                     help => 'Domain_Configuration_Scantron_Format',
  321:                     header => [ {col1 => 'Item',
  322:                                  col2 => '',
  323:                               }],
  324:                   },
  325:         'requestcourses' => 
  326:                  {text => 'Request creation of courses',
  327:                   help => 'Domain_Configuration_Request_Courses',
  328:                   header => [{col1 => 'User affiliation',
  329:                               col2 => 'Availability/Processing of requests',},
  330:                              {col1 => 'Setting',
  331:                               col2 => 'Value'}],
  332:                  },
  333:         'requestauthor' =>
  334:                  {text => 'Request authoring space',
  335:                   help => 'Domain_Configuration_Request_Author',
  336:                   header => [{col1 => 'User affiliation',
  337:                               col2 => 'Availability/Processing of requests',},
  338:                              {col1 => 'Setting',
  339:                               col2 => 'Value'}],
  340:                  },
  341:         'coursecategories' =>
  342:                   { text => 'Cataloging of courses/communities',
  343:                     help => 'Domain_Configuration_Cataloging_Courses',
  344:                     header => [{col1 => 'Category settings',
  345:                                 col2 => '',},
  346:                                {col1 => 'Categories',
  347:                                 col2 => '',
  348:                                }],
  349:                   },
  350:         'serverstatuses' =>
  351:                  {text   => 'Access to server status pages',
  352:                   help   => 'Domain_Configuration_Server_Status',
  353:                   header => [{col1 => 'Status Page',
  354:                               col2 => 'Other named users',
  355:                               col3 => 'Specific IPs',
  356:                             }],
  357:                  },
  358:         'coursedefaults' =>
  359:                  {text => 'Course/Community defaults',
  360:                   help => 'Domain_Configuration_Course_Defaults',
  361:                   header => [{col1 => 'Defaults which can be overridden for each course by a DC',
  362:                               col2 => 'Value',},],
  363:                  },
  364:         'usersessions' =>
  365:                  {text  => 'User session hosting/offloading',
  366:                   help  => 'Domain_Configuration_User_Sessions',
  367:                   header => [{col1 => 'Domain server',
  368:                               col2 => 'Servers to offload sessions to when busy'},
  369:                              {col1 => 'Hosting of users from other domains',
  370:                               col2 => 'Rules'},
  371:                              {col1 => "Hosting domain's own users elsewhere",
  372:                               col2 => 'Rules'}],
  373:                  },
  374:          'loadbalancing' =>
  375:                  {text  => 'Dedicated Load Balancer(s)',
  376:                   help  => 'Domain_Configuration_Load_Balancing',
  377:                   header => [{col1 => 'Balancers',
  378:                               col2 => 'Default destinations',
  379:                               col3 => 'User affiliation',
  380:                               col4 => 'Overrides'},
  381:                             ],
  382:                  },
  383:     );
  384:     if (keys(%servers) > 1) {
  385:         $prefs{'login'}  = { text   => 'Log-in page options',
  386:                              help   => 'Domain_Configuration_Login_Page',
  387:                             header => [{col1 => 'Log-in Service',
  388:                                         col2 => 'Server Setting',},
  389:                                        {col1 => 'Log-in Page Items',
  390:                                         col2 => ''},
  391:                                        {col1 => 'Log-in Help',
  392:                                         col2 => 'Value'}],
  393:                            };
  394:     }
  395: 
  396:     my @roles = ('student','coordinator','author','admin');
  397:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  398:     &Apache::lonhtmlcommon::add_breadcrumb
  399:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  400:       text=>"Settings to display/modify"});
  401:     my $confname = $dom.'-domainconfig';
  402: 
  403:     if ($phase eq 'process') {
  404:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
  405:     } elsif ($phase eq 'display') {
  406:         my $js = &recaptcha_js().
  407:                  &credits_js(); 
  408:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
  409:             my ($othertitle,$usertypes,$types) =
  410:                 &Apache::loncommon::sorted_inst_types($dom);
  411:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
  412:                                           $domconfig{'loadbalancing'}).
  413:                    &new_spares_js().
  414:                    &common_domprefs_js().
  415:                    &Apache::loncommon::javascript_array_indexof();
  416:         }
  417:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
  418:     } else {
  419: # check if domconfig user exists for the domain.
  420:         my $servadm = $r->dir_config('lonAdmEMail');
  421:         my ($configuserok,$author_ok,$switchserver) = 
  422:             &config_check($dom,$confname,$servadm);
  423:         unless ($configuserok eq 'ok') {
  424:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
  425:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
  426:                           $confname).
  427:                       '<br />'
  428:             );
  429:             if ($switchserver) {
  430:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
  431:                           '<br />'.
  432:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
  433:                           '<br />'.
  434:                           &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).
  435:                           '<br />'.
  436:                           &mt('To do that now, use the following link: [_1]',$switchserver)
  437:                 );
  438:             } else {
  439:                 $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.').
  440:                           '<br />'.
  441:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
  442:                 );
  443:             }
  444:             $r->print(&Apache::loncommon::end_page());
  445:             return OK;
  446:         }
  447:         if (keys(%domconfig) == 0) {
  448:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  449:             my @ids=&Apache::lonnet::current_machine_ids();
  450:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  451:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  452:                 my @loginimages = ('img','logo','domlogo','login');
  453:                 my $custom_img_count = 0;
  454:                 foreach my $img (@loginimages) {
  455:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  456:                         $custom_img_count ++;
  457:                     }
  458:                 }
  459:                 foreach my $role (@roles) {
  460:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  461:                         $custom_img_count ++;
  462:                     }
  463:                 }
  464:                 if ($custom_img_count > 0) {
  465:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
  466:                     my $switch_server = &check_switchserver($dom,$confname);
  467:                     $r->print(
  468:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  469:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  470:     &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 />'.
  471:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  472:                     if ($switch_server) {
  473:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  474:                     }
  475:                     $r->print(&Apache::loncommon::end_page());
  476:                     return OK;
  477:                 }
  478:             }
  479:         }
  480:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
  481:     }
  482:     return OK;
  483: }
  484: 
  485: sub process_changes {
  486:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
  487:     my %domconfig;
  488:     if (ref($values) eq 'HASH') {
  489:         %domconfig = %{$values};
  490:     }
  491:     my $output;
  492:     if ($action eq 'login') {
  493:         $output = &modify_login($r,$dom,$confname,%domconfig);
  494:     } elsif ($action eq 'rolecolors') {
  495:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  496:                                      %domconfig);
  497:     } elsif ($action eq 'quotas') {
  498:         $output = &modify_quotas($dom,$action,%domconfig);
  499:     } elsif ($action eq 'autoenroll') {
  500:         $output = &modify_autoenroll($dom,%domconfig);
  501:     } elsif ($action eq 'autoupdate') {
  502:         $output = &modify_autoupdate($dom,%domconfig);
  503:     } elsif ($action eq 'autocreate') {
  504:         $output = &modify_autocreate($dom,%domconfig);
  505:     } elsif ($action eq 'directorysrch') {
  506:         $output = &modify_directorysrch($dom,%domconfig);
  507:     } elsif ($action eq 'usercreation') {
  508:         $output = &modify_usercreation($dom,%domconfig);
  509:     } elsif ($action eq 'usermodification') {
  510:         $output = &modify_usermodification($dom,%domconfig);
  511:     } elsif ($action eq 'contacts') {
  512:         $output = &modify_contacts($dom,%domconfig);
  513:     } elsif ($action eq 'defaults') {
  514:         $output = &modify_defaults($dom,$r);
  515:     } elsif ($action eq 'scantron') {
  516:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
  517:     } elsif ($action eq 'coursecategories') {
  518:         $output = &modify_coursecategories($dom,%domconfig);
  519:     } elsif ($action eq 'serverstatuses') {
  520:         $output = &modify_serverstatuses($dom,%domconfig);
  521:     } elsif ($action eq 'requestcourses') {
  522:         $output = &modify_quotas($dom,$action,%domconfig);
  523:     } elsif ($action eq 'requestauthor') {
  524:         $output = &modify_quotas($dom,$action,%domconfig);
  525:     } elsif ($action eq 'coursedefaults') {
  526:         $output = &modify_coursedefaults($dom,%domconfig);
  527:     } elsif ($action eq 'usersessions') {
  528:         $output = &modify_usersessions($dom,%domconfig);
  529:     } elsif ($action eq 'loadbalancing') {
  530:         $output = &modify_loadbalancing($dom,%domconfig);
  531:     }
  532:     return $output;
  533: }
  534: 
  535: sub print_config_box {
  536:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  537:     my $rowtotal = 0;
  538:     my $output;
  539:     if ($action eq 'coursecategories') {
  540:         $output = &coursecategories_javascript($settings);
  541:     }
  542:     $output .= 
  543:          '<table class="LC_nested_outer">
  544:           <tr>
  545:            <th align="left" valign="middle"><span class="LC_nobreak">'.
  546:            &mt($item->{text}).'&nbsp;'.
  547:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
  548:           '</tr>';
  549:     $rowtotal ++;
  550:     my $numheaders = 1;
  551:     if (ref($item->{'header'}) eq 'ARRAY') {
  552:         $numheaders = scalar(@{$item->{'header'}});
  553:     }
  554:     if ($numheaders > 1) {
  555:         my $colspan = '';
  556:         my $rightcolspan = '';
  557:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
  558:             (($action eq 'login') && ($numheaders < 3))) {
  559:             $colspan = ' colspan="2"';
  560:         }
  561:         if ($action eq 'usersessions') {
  562:             $rightcolspan = ' colspan="3"'; 
  563:         }
  564:         $output .= '
  565:           <tr>
  566:            <td>
  567:             <table class="LC_nested">
  568:              <tr class="LC_info_row">
  569:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
  570:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  571:              </tr>';
  572:         $rowtotal ++;
  573:         if ($action eq 'autoupdate') {
  574:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
  575:         } elsif ($action eq 'usercreation') {
  576:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
  577:         } elsif ($action eq 'usermodification') {
  578:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
  579:         } elsif ($action eq 'coursecategories') {
  580:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
  581:         } elsif ($action eq 'login') {
  582:             if ($numheaders == 3) {
  583:                 $colspan = ' colspan="2"';
  584:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
  585:             } else {
  586:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
  587:             }
  588:         } elsif ($action eq 'requestcourses') {
  589:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  590:         } elsif ($action eq 'requestauthor') {
  591:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  592:         } elsif ($action eq 'usersessions') {
  593:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
  594:         } elsif ($action eq 'rolecolors') {
  595:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  596:         }
  597:         $output .= '
  598:            </table>
  599:           </td>
  600:          </tr>
  601:          <tr>
  602:            <td>
  603:             <table class="LC_nested">
  604:              <tr class="LC_info_row">
  605:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
  606:         $output .= '
  607:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
  608:              </tr>';
  609:             $rowtotal ++;
  610:         if ($action eq 'autoupdate') {
  611:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
  612:            </table>
  613:           </td>
  614:          </tr>
  615:          <tr>
  616:            <td>
  617:             <table class="LC_nested">
  618:              <tr class="LC_info_row">
  619:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  620:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  621:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
  622:             $rowtotal ++;
  623:         } elsif ($action eq 'usercreation') {
  624:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
  625:            </table>
  626:           </td>
  627:          </tr>
  628:          <tr>
  629:            <td>
  630:             <table class="LC_nested">
  631:              <tr class="LC_info_row">
  632:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  633:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
  634:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
  635:             $rowtotal ++;
  636:         } elsif ($action eq 'usermodification') {
  637:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
  638:            </table>
  639:           </td>
  640:          </tr>
  641:          <tr>
  642:            <td>
  643:             <table class="LC_nested">
  644:              <tr class="LC_info_row">
  645:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  646:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  647:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
  648:             $rowtotal ++;
  649:         } elsif ($action eq 'coursecategories') {
  650:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
  651:         } elsif ($action eq 'login') {
  652:             if ($numheaders == 3) {
  653:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
  654:            </table>
  655:           </td>
  656:          </tr>
  657:          <tr>
  658:            <td>
  659:             <table class="LC_nested">
  660:              <tr class="LC_info_row">
  661:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  662:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  663:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
  664:                 $rowtotal ++;
  665:             } else {
  666:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
  667:             }
  668:         } elsif ($action eq 'requestcourses') {
  669:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
  670:         } elsif ($action eq 'requestauthor') {
  671:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
  672:         } elsif ($action eq 'usersessions') {
  673:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
  674:            </table>
  675:           </td>
  676:          </tr>
  677:          <tr>
  678:            <td>
  679:             <table class="LC_nested">
  680:              <tr class="LC_info_row">
  681:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  682:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  683:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
  684:             $rowtotal ++;
  685:         } elsif ($action eq 'rolecolors') {
  686:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  687:            </table>
  688:           </td>
  689:          </tr>
  690:          <tr>
  691:            <td>
  692:             <table class="LC_nested">
  693:              <tr class="LC_info_row">
  694:               <td class="LC_left_item"'.$colspan.' valign="top">'.
  695:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
  696:               <td class="LC_right_item" valign="top">'.
  697:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
  698:              </tr>'.
  699:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  700:            </table>
  701:           </td>
  702:          </tr>
  703:          <tr>
  704:            <td>
  705:             <table class="LC_nested">
  706:              <tr class="LC_info_row">
  707:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  708:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  709:              </tr>'.
  710:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  711:             $rowtotal += 2;
  712:         }
  713:     } else {
  714:         $output .= '
  715:           <tr>
  716:            <td>
  717:             <table class="LC_nested">
  718:              <tr class="LC_info_row">';
  719:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  720:             $output .= '  
  721:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  722:         } elsif ($action eq 'serverstatuses') {
  723:             $output .= '
  724:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
  725:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
  726: 
  727:         } else {
  728:             $output .= '
  729:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  730:         }
  731:         if (defined($item->{'header'}->[0]->{'col3'})) {
  732:             $output .= '<td class="LC_left_item" valign="top">'.
  733:                        &mt($item->{'header'}->[0]->{'col2'});
  734:             if ($action eq 'serverstatuses') {
  735:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
  736:             } 
  737:         } else {
  738:             $output .= '<td class="LC_right_item" valign="top">'.
  739:                        &mt($item->{'header'}->[0]->{'col2'});
  740:         }
  741:         $output .= '</td>';
  742:         if ($item->{'header'}->[0]->{'col3'}) {
  743:             if (defined($item->{'header'}->[0]->{'col4'})) {
  744:                 $output .= '<td class="LC_left_item" valign="top">'.
  745:                             &mt($item->{'header'}->[0]->{'col3'});
  746:             } else {
  747:                 $output .= '<td class="LC_right_item" valign="top">'.
  748:                            &mt($item->{'header'}->[0]->{'col3'});
  749:             }
  750:             if ($action eq 'serverstatuses') {
  751:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
  752:             }
  753:             $output .= '</td>';
  754:         }
  755:         if ($item->{'header'}->[0]->{'col4'}) {
  756:             $output .= '<td class="LC_right_item" valign="top">'.
  757:                        &mt($item->{'header'}->[0]->{'col4'});
  758:         }
  759:         $output .= '</tr>';
  760:         $rowtotal ++;
  761:         if ($action eq 'quotas') {
  762:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  763:         } elsif ($action eq 'autoenroll') {
  764:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
  765:         } elsif ($action eq 'autocreate') {
  766:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
  767:         } elsif ($action eq 'directorysrch') {
  768:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
  769:         } elsif ($action eq 'contacts') {
  770:             $output .= &print_contacts($dom,$settings,\$rowtotal);
  771:         } elsif ($action eq 'defaults') {
  772:             $output .= &print_defaults($dom,\$rowtotal);
  773:         } elsif ($action eq 'scantron') {
  774:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
  775:         } elsif ($action eq 'serverstatuses') {
  776:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
  777:         } elsif ($action eq 'helpsettings') {
  778:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
  779:         } elsif ($action eq 'loadbalancing') {
  780:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
  781:         } elsif ($action eq 'coursedefaults') {
  782:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
  783:         }
  784:     }
  785:     $output .= '
  786:    </table>
  787:   </td>
  788:  </tr>
  789: </table><br />';
  790:     return ($output,$rowtotal);
  791: }
  792: 
  793: sub print_login {
  794:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
  795:     my ($css_class,$datatable);
  796:     my %choices = &login_choices();
  797: 
  798:     if ($caller eq 'service') {
  799:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
  800:         my $choice = $choices{'disallowlogin'};
  801:         $css_class = ' class="LC_odd_row"';
  802:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
  803:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
  804:                       '<th>'.$choices{'server'}.'</th>'.
  805:                       '<th>'.$choices{'serverpath'}.'</th>'.
  806:                       '<th>'.$choices{'custompath'}.'</th>'.
  807:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
  808:         my %disallowed;
  809:         if (ref($settings) eq 'HASH') {
  810:             if (ref($settings->{'loginvia'}) eq 'HASH') {
  811:                %disallowed = %{$settings->{'loginvia'}};
  812:             }
  813:         }
  814:         foreach my $lonhost (sort(keys(%servers))) {
  815:             my $direct = 'selected="selected"';
  816:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  817:                 if ($disallowed{$lonhost}{'server'} ne '') {
  818:                     $direct = '';
  819:                 }
  820:             }
  821:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
  822:                           '<td><select name="'.$lonhost.'_server">'.
  823:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
  824:                           '</option>';
  825:             foreach my $hostid (sort(keys(%servers))) {
  826:                 next if ($servers{$hostid} eq $servers{$lonhost});
  827:                 my $selected = '';
  828:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  829:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
  830:                         $selected = 'selected="selected"';
  831:                     }
  832:                 }
  833:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
  834:                               $servers{$hostid}.'</option>';
  835:             }
  836:             $datatable .= '</select></td>'.
  837:                           '<td><select name="'.$lonhost.'_serverpath">';
  838:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
  839:                 my $pathname = $path;
  840:                 if ($path eq 'custom') {
  841:                     $pathname = &mt('Custom Path').' ->';
  842:                 }
  843:                 my $selected = '';
  844:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  845:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
  846:                         $selected = 'selected="selected"';
  847:                     }
  848:                 } elsif ($path eq '') {
  849:                     $selected = 'selected="selected"';
  850:                 }
  851:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
  852:             }
  853:             $datatable .= '</select></td>';
  854:             my ($custom,$exempt);
  855:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  856:                 $custom = $disallowed{$lonhost}{'custompath'};
  857:                 $exempt = $disallowed{$lonhost}{'exempt'};
  858:             }
  859:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
  860:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
  861:                           '</tr>';
  862:         }
  863:         $datatable .= '</table></td></tr>';
  864:         return $datatable;
  865:     } elsif ($caller eq 'page') {
  866:         my %defaultchecked = ( 
  867:                                'coursecatalog' => 'on',
  868:                                'helpdesk'      => 'on',
  869:                                'adminmail'     => 'off',
  870:                                'newuser'       => 'off',
  871:                              );
  872:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
  873:         my (%checkedon,%checkedoff);
  874:         foreach my $item (@toggles) {
  875:             if ($defaultchecked{$item} eq 'on') { 
  876:                 $checkedon{$item} = ' checked="checked" ';
  877:                 $checkedoff{$item} = ' ';
  878:             } elsif ($defaultchecked{$item} eq 'off') {
  879:                 $checkedoff{$item} = ' checked="checked" ';
  880:                 $checkedon{$item} = ' ';
  881:             }
  882:         }
  883:         my @images = ('img','logo','domlogo','login');
  884:         my @logintext = ('textcol','bgcol');
  885:         my @bgs = ('pgbg','mainbg','sidebg');
  886:         my @links = ('link','alink','vlink');
  887:         my %designhash = &Apache::loncommon::get_domainconf($dom);
  888:         my %defaultdesign = %Apache::loncommon::defaultdesign;
  889:         my (%is_custom,%designs);
  890:         my %defaults = (
  891:                        font => $defaultdesign{'login.font'},
  892:                        );
  893:         foreach my $item (@images) {
  894:             $defaults{$item} = $defaultdesign{'login.'.$item};
  895:             $defaults{'showlogo'}{$item} = 1;
  896:         }
  897:         foreach my $item (@bgs) {
  898:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  899:         }
  900:         foreach my $item (@logintext) {
  901:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
  902:         }
  903:         foreach my $item (@links) {
  904:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  905:         }
  906:         if (ref($settings) eq 'HASH') {
  907:             foreach my $item (@toggles) {
  908:                 if ($settings->{$item} eq '1') {
  909:                     $checkedon{$item} =  ' checked="checked" ';
  910:                     $checkedoff{$item} = ' ';
  911:                 } elsif ($settings->{$item} eq '0') {
  912:                     $checkedoff{$item} =  ' checked="checked" ';
  913:                     $checkedon{$item} = ' ';
  914:                 }
  915:             }
  916:             foreach my $item (@images) {
  917:                 if (defined($settings->{$item})) {
  918:                     $designs{$item} = $settings->{$item};
  919:                     $is_custom{$item} = 1;
  920:                 }
  921:                 if (defined($settings->{'showlogo'}{$item})) {
  922:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
  923:                 }
  924:             }
  925:             foreach my $item (@logintext) {
  926:                 if ($settings->{$item} ne '') {
  927:                     $designs{'logintext'}{$item} = $settings->{$item};
  928:                     $is_custom{$item} = 1;
  929:                 }
  930:             }
  931:             if ($settings->{'font'} ne '') {
  932:                 $designs{'font'} = $settings->{'font'};
  933:                 $is_custom{'font'} = 1;
  934:             }
  935:             foreach my $item (@bgs) {
  936:                 if ($settings->{$item} ne '') {
  937:                     $designs{'bgs'}{$item} = $settings->{$item};
  938:                     $is_custom{$item} = 1;
  939:                 }
  940:             }
  941:             foreach my $item (@links) {
  942:                 if ($settings->{$item} ne '') {
  943:                     $designs{'links'}{$item} = $settings->{$item};
  944:                     $is_custom{$item} = 1;
  945:                 }
  946:             }
  947:         } else {
  948:             if ($designhash{$dom.'.login.font'} ne '') {
  949:                 $designs{'font'} = $designhash{$dom.'.login.font'};
  950:                 $is_custom{'font'} = 1;
  951:             }
  952:             foreach my $item (@images) {
  953:                 if ($designhash{$dom.'.login.'.$item} ne '') {
  954:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
  955:                     $is_custom{$item} = 1;
  956:                 }
  957:             }
  958:             foreach my $item (@bgs) {
  959:                 if ($designhash{$dom.'.login.'.$item} ne '') {
  960:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  961:                     $is_custom{$item} = 1;
  962:                 }
  963:             }
  964:             foreach my $item (@links) {
  965:                 if ($designhash{$dom.'.login.'.$item} ne '') {
  966:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  967:                     $is_custom{$item} = 1;
  968:                 }
  969:             }
  970:         }
  971:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  972:                                                       logo => 'Institution Logo',
  973:                                                       domlogo => 'Domain Logo',
  974:                                                       login => 'Login box');
  975:         my $itemcount = 1;
  976:         foreach my $item (@toggles) {
  977:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
  978:             $datatable .=  
  979:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
  980:                 '</td><td>'.
  981:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
  982:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
  983:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
  984:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
  985:                 '</tr>';
  986:             $itemcount ++;
  987:         }
  988:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
  989:         $datatable .= '</tr></table></td></tr>';
  990:     } elsif ($caller eq 'help') {
  991:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
  992:         my $switchserver = &check_switchserver($dom,$confname);
  993:         my $itemcount = 1;
  994:         $defaulturl = '/adm/loginproblems.html';
  995:         $defaulttype = 'default';
  996:         %lt = &Apache::lonlocal::texthash (
  997:                      del     => 'Delete?',
  998:                      rep     => 'Replace:',
  999:                      upl     => 'Upload:',
 1000:                      default => 'Default',
 1001:                      custom  => 'Custom',
 1002:                                              );
 1003:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 1004:         my @currlangs;
 1005:         if (ref($settings) eq 'HASH') {
 1006:             if (ref($settings->{'helpurl'}) eq 'HASH') {
 1007:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
 1008:                     next if ($settings->{'helpurl'}{$key} eq '');
 1009:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
 1010:                     $type{$key} = 'custom';
 1011:                     unless ($key eq 'nolang') {
 1012:                         push(@currlangs,$key);
 1013:                     }
 1014:                 }
 1015:             } elsif ($settings->{'helpurl'} ne '') {
 1016:                 $type{'nolang'} = 'custom';
 1017:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
 1018:             }
 1019:         }
 1020:         foreach my $lang ('nolang',sort(@currlangs)) {
 1021:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 1022:             $datatable .= '<tr'.$css_class.'>';
 1023:             if ($url{$lang} eq '') {
 1024:                 $url{$lang} = $defaulturl;
 1025:             }
 1026:             if ($type{$lang} eq '') {
 1027:                 $type{$lang} = $defaulttype;
 1028:             }
 1029:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
 1030:             if ($lang eq 'nolang') {
 1031:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
 1032:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
 1033:             } else {
 1034:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
 1035:                                   $langchoices{$lang},
 1036:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
 1037:             }
 1038:             $datatable .= '</span></td>'."\n".
 1039:                           '<td class="LC_left_item">';
 1040:             if ($type{$lang} eq 'custom') {
 1041:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1042:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
 1043:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
 1044:             } else {
 1045:                 $datatable .= $lt{'upl'};
 1046:             }
 1047:             $datatable .='<br />';
 1048:             if ($switchserver) {
 1049:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1050:             } else {
 1051:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
 1052:             }
 1053:             $datatable .= '</td></tr>';
 1054:             $itemcount ++;
 1055:         }
 1056:         my @addlangs;
 1057:         foreach my $lang (sort(keys(%langchoices))) {
 1058:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
 1059:             push(@addlangs,$lang);
 1060:         }
 1061:         if (@addlangs > 0) {
 1062:             my %toadd;
 1063:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
 1064:             $toadd{''} = &mt('Select');
 1065:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 1066:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
 1067:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
 1068:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
 1069:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
 1070:             if ($switchserver) {
 1071:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1072:             } else {
 1073:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
 1074:             }
 1075:             $datatable .= '</td></tr>';
 1076:             $itemcount ++;
 1077:         }
 1078:         $datatable .= &captcha_choice('login',$settings,$itemcount);
 1079:     }
 1080:     return $datatable;
 1081: }
 1082: 
 1083: sub login_choices {
 1084:     my %choices =
 1085:         &Apache::lonlocal::texthash (
 1086:             coursecatalog => 'Display Course/Community Catalog link?',
 1087:             adminmail     => "Display Administrator's E-mail Address?",
 1088:             helpdesk      => 'Display "Contact Helpdesk" link',
 1089:             disallowlogin => "Login page requests redirected",
 1090:             hostid        => "Server",
 1091:             server        => "Redirect to:",
 1092:             serverpath    => "Path",
 1093:             custompath    => "Custom", 
 1094:             exempt        => "Exempt IP(s)",
 1095:             directlogin   => "No redirect",
 1096:             newuser       => "Link to create a user account",
 1097:             img           => "Header",
 1098:             logo          => "Main Logo",
 1099:             domlogo       => "Domain Logo",
 1100:             login         => "Log-in Header", 
 1101:             textcol       => "Text color",
 1102:             bgcol         => "Box color",
 1103:             bgs           => "Background colors",
 1104:             links         => "Link colors",
 1105:             font          => "Font color",
 1106:             pgbg          => "Header",
 1107:             mainbg        => "Page",
 1108:             sidebg        => "Login box",
 1109:             link          => "Link",
 1110:             alink         => "Active link",
 1111:             vlink         => "Visited link",
 1112:         );
 1113:     return %choices;
 1114: }
 1115: 
 1116: sub print_rolecolors {
 1117:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
 1118:     my %choices = &color_font_choices();
 1119:     my @bgs = ('pgbg','tabbg','sidebg');
 1120:     my @links = ('link','alink','vlink');
 1121:     my @images = ('img');
 1122:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
 1123:     my %designhash = &Apache::loncommon::get_domainconf($dom);
 1124:     my %defaultdesign = %Apache::loncommon::defaultdesign;
 1125:     my (%is_custom,%designs);
 1126:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
 1127:     if (ref($settings) eq 'HASH') {
 1128:         if (ref($settings->{$role}) eq 'HASH') {
 1129:             if ($settings->{$role}->{'img'} ne '') {
 1130:                 $designs{'img'} = $settings->{$role}->{'img'};
 1131:                 $is_custom{'img'} = 1;
 1132:             }
 1133:             if ($settings->{$role}->{'font'} ne '') {
 1134:                 $designs{'font'} = $settings->{$role}->{'font'};
 1135:                 $is_custom{'font'} = 1;
 1136:             }
 1137:             if ($settings->{$role}->{'fontmenu'} ne '') {
 1138:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
 1139:                 $is_custom{'fontmenu'} = 1;
 1140:             }
 1141:             foreach my $item (@bgs) {
 1142:                 if ($settings->{$role}->{$item} ne '') {
 1143:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
 1144:                     $is_custom{$item} = 1;
 1145:                 }
 1146:             }
 1147:             foreach my $item (@links) {
 1148:                 if ($settings->{$role}->{$item} ne '') {
 1149:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
 1150:                     $is_custom{$item} = 1;
 1151:                 }
 1152:             }
 1153:         }
 1154:     } else {
 1155:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
 1156:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
 1157:             $is_custom{'img'} = 1;
 1158:         }
 1159:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
 1160:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
 1161:             $is_custom{'fontmenu'} = 1; 
 1162:         }
 1163:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
 1164:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
 1165:             $is_custom{'font'} = 1;
 1166:         }
 1167:         foreach my $item (@bgs) {
 1168:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1169:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1170:                 $is_custom{$item} = 1;
 1171:             
 1172:             }
 1173:         }
 1174:         foreach my $item (@links) {
 1175:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
 1176:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
 1177:                 $is_custom{$item} = 1;
 1178:             }
 1179:         }
 1180:     }
 1181:     my $itemcount = 1;
 1182:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
 1183:     $datatable .= '</tr></table></td></tr>';
 1184:     return $datatable;
 1185: }
 1186: 
 1187: sub role_defaults {
 1188:     my ($role,$bgs,$links,$images,$logintext) = @_;
 1189:     my %defaults;
 1190:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
 1191:         return %defaults;
 1192:     }
 1193:     my %defaultdesign = %Apache::loncommon::defaultdesign;
 1194:     if ($role eq 'login') {
 1195:         %defaults = (
 1196:                        font => $defaultdesign{$role.'.font'},
 1197:                     );
 1198:         if (ref($logintext) eq 'ARRAY') {
 1199:             foreach my $item (@{$logintext}) {
 1200:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
 1201:             }
 1202:         }
 1203:         foreach my $item (@{$images}) {
 1204:             $defaults{'showlogo'}{$item} = 1;
 1205:         }
 1206:     } else {
 1207:         %defaults = (
 1208:                        img => $defaultdesign{$role.'.img'},
 1209:                        font => $defaultdesign{$role.'.font'},
 1210:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
 1211:                     );
 1212:     }
 1213:     foreach my $item (@{$bgs}) {
 1214:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
 1215:     }
 1216:     foreach my $item (@{$links}) {
 1217:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
 1218:     }
 1219:     foreach my $item (@{$images}) {
 1220:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
 1221:     }
 1222:     return %defaults;
 1223: }
 1224: 
 1225: sub display_color_options {
 1226:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
 1227:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
 1228:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
 1229:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1230:     my $datatable = '<tr'.$css_class.'>'.
 1231:         '<td>'.$choices->{'font'}.'</td>';
 1232:     if (!$is_custom->{'font'}) {
 1233:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
 1234:     } else {
 1235:         $datatable .= '<td>&nbsp;</td>';
 1236:     }
 1237:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
 1238: 
 1239:     $datatable .= '<td><span class="LC_nobreak">'.
 1240:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
 1241:                   ' value="'.$current_color.'" />&nbsp;'.
 1242:                   '&nbsp;</td></tr>';
 1243:     unless ($role eq 'login') { 
 1244:         $datatable .= '<tr'.$css_class.'>'.
 1245:                       '<td>'.$choices->{'fontmenu'}.'</td>';
 1246:         if (!$is_custom->{'fontmenu'}) {
 1247:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
 1248:         } else {
 1249:             $datatable .= '<td>&nbsp;</td>';
 1250:         }
 1251: 	$current_color = $designs->{'fontmenu'} ?
 1252: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
 1253:         $datatable .= '<td><span class="LC_nobreak">'.
 1254:                       '<input class="colorchooser" type="text" size="10" name="'
 1255: 		      .$role.'_fontmenu"'.
 1256:                       ' value="'.$current_color.'" />&nbsp;'.
 1257:                       '&nbsp;</td></tr>';
 1258:     }
 1259:     my $switchserver = &check_switchserver($dom,$confname);
 1260:     foreach my $img (@{$images}) {
 1261: 	$itemcount ++;
 1262:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1263:         $datatable .= '<tr'.$css_class.'>'.
 1264:                       '<td>'.$choices->{$img};
 1265:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
 1266:         if ($role eq 'login') {
 1267:             if ($img eq 'login') {
 1268:                 $login_hdr_pick =
 1269:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
 1270:                 $logincolors =
 1271:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
 1272:                                        $designs,$defaults);
 1273:             } elsif ($img ne 'domlogo') {
 1274:                 $datatable.= &logo_display_options($img,$defaults,$designs);
 1275:             }
 1276:         }
 1277:         $datatable .= '</td>';
 1278:         if ($designs->{$img} ne '') {
 1279:             $imgfile = $designs->{$img};
 1280: 	    $img_import = ($imgfile =~ m{^/adm/});
 1281:         } else {
 1282:             $imgfile = $defaults->{$img};
 1283:         }
 1284:         if ($imgfile) {
 1285:             my ($showfile,$fullsize);
 1286:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1287:                 my $urldir = $1;
 1288:                 my $filename = $2;
 1289:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
 1290:                 if (@info) {
 1291:                     my $thumbfile = 'tn-'.$filename;
 1292:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
 1293:                     if (@thumb) {
 1294:                         $showfile = $urldir.'/'.$thumbfile;
 1295:                     } else {
 1296:                         $showfile = $imgfile;
 1297:                     }
 1298:                 } else {
 1299:                     $showfile = '';
 1300:                 }
 1301:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
 1302:                 $showfile = $imgfile;
 1303:                 my $imgdir = $1;
 1304:                 my $filename = $2;
 1305:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
 1306:                     $showfile = "/$imgdir/tn-".$filename;
 1307:                 } else {
 1308:                     my $input = $londocroot.$imgfile;
 1309:                     my $output = "$londocroot/$imgdir/tn-".$filename;
 1310:                     if (!-e $output) {
 1311:                         my ($width,$height) = &thumb_dimensions();
 1312:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
 1313:                         if ($fullwidth ne '' && $fullheight ne '') {
 1314:                             if ($fullwidth > $width && $fullheight > $height) { 
 1315:                                 my $size = $width.'x'.$height;
 1316:                                 system("convert -sample $size $input $output");
 1317:                                 $showfile = "/$imgdir/tn-".$filename;
 1318:                             }
 1319:                         }
 1320:                     }
 1321:                 }
 1322:             }
 1323:             if ($showfile) {
 1324:                 if ($showfile =~ m{^/(adm|res)/}) {
 1325:                     if ($showfile =~ m{^/res/}) {
 1326:                         my $local_showfile =
 1327:                             &Apache::lonnet::filelocation('',$showfile);
 1328:                         &Apache::lonnet::repcopy($local_showfile);
 1329:                     }
 1330:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
 1331:                 }
 1332:                 if ($imgfile) {
 1333:                     if ($imgfile  =~ m{^/(adm|res)/}) {
 1334:                         if ($imgfile =~ m{^/res/}) {
 1335:                             my $local_imgfile =
 1336:                                 &Apache::lonnet::filelocation('',$imgfile);
 1337:                             &Apache::lonnet::repcopy($local_imgfile);
 1338:                         }
 1339:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
 1340:                     } else {
 1341:                         $fullsize = $imgfile;
 1342:                     }
 1343:                 }
 1344:                 $datatable .= '<td>';
 1345:                 if ($img eq 'login') {
 1346:                     $datatable .= $login_hdr_pick;
 1347:                 } 
 1348:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
 1349:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
 1350:             } else {
 1351:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
 1352:                               &mt('Upload:').'<br />';
 1353:             }
 1354:         } else {
 1355:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
 1356:                           &mt('Upload:').'<br />';
 1357:         }
 1358:         if ($switchserver) {
 1359:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1360:         } else {
 1361:             if ($img ne 'login') { # suppress file selection for Log-in header
 1362:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
 1363:             }
 1364:         }
 1365:         $datatable .= '</td></tr>';
 1366:     }
 1367:     $itemcount ++;
 1368:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1369:     $datatable .= '<tr'.$css_class.'>'.
 1370:                   '<td>'.$choices->{'bgs'}.'</td>';
 1371:     my $bgs_def;
 1372:     foreach my $item (@{$bgs}) {
 1373:         if (!$is_custom->{$item}) {
 1374:             $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>';
 1375:         }
 1376:     }
 1377:     if ($bgs_def) {
 1378:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
 1379:     } else {
 1380:         $datatable .= '<td>&nbsp;</td>';
 1381:     }
 1382:     $datatable .= '<td class="LC_right_item">'.
 1383:                   '<table border="0"><tr>';
 1384: 
 1385:     foreach my $item (@{$bgs}) {
 1386:         $datatable .= '<td align="center">'.$choices->{$item};
 1387: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
 1388:         if ($designs->{'bgs'}{$item}) {
 1389:             $datatable .= '&nbsp;';
 1390:         }
 1391:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1392:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1393:     }
 1394:     $datatable .= '</tr></table></td></tr>';
 1395:     $itemcount ++;
 1396:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1397:     $datatable .= '<tr'.$css_class.'>'.
 1398:                   '<td>'.$choices->{'links'}.'</td>';
 1399:     my $links_def;
 1400:     foreach my $item (@{$links}) {
 1401:         if (!$is_custom->{$item}) {
 1402:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
 1403:         }
 1404:     }
 1405:     if ($links_def) {
 1406:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
 1407:     } else {
 1408:         $datatable .= '<td>&nbsp;</td>';
 1409:     }
 1410:     $datatable .= '<td class="LC_right_item">'.
 1411:                   '<table border="0"><tr>';
 1412:     foreach my $item (@{$links}) {
 1413: 	my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
 1414:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
 1415:         if ($designs->{'links'}{$item}) {
 1416:             $datatable.='&nbsp;';
 1417:         }
 1418:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
 1419:                       '" /></td>';
 1420:     }
 1421:     $$rowtotal += $itemcount;
 1422:     return $datatable;
 1423: }
 1424: 
 1425: sub logo_display_options {
 1426:     my ($img,$defaults,$designs) = @_;
 1427:     my $checkedon;
 1428:     if (ref($defaults) eq 'HASH') {
 1429:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
 1430:             if ($defaults->{'showlogo'}{$img}) {
 1431:                 $checkedon = 'checked="checked" ';     
 1432:             }
 1433:         } 
 1434:     }
 1435:     if (ref($designs) eq 'HASH') {
 1436:         if (ref($designs->{'showlogo'}) eq 'HASH') {
 1437:             if (defined($designs->{'showlogo'}{$img})) {
 1438:                 if ($designs->{'showlogo'}{$img} == 0) {
 1439:                     $checkedon = '';
 1440:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
 1441:                     $checkedon = 'checked="checked" ';
 1442:                 }
 1443:             }
 1444:         }
 1445:     }
 1446:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
 1447:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
 1448:            &mt('show').'</label>'."\n";
 1449: }
 1450: 
 1451: sub login_header_options  {
 1452:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
 1453:     my $output = '';
 1454:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1455:         $output .= &mt('Text default(s):').'<br />';
 1456:         if (!$is_custom->{'textcol'}) {
 1457:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1458:                        '&nbsp;&nbsp;&nbsp;';
 1459:         }
 1460:         if (!$is_custom->{'bgcol'}) {
 1461:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1462:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1463:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1464:         }
 1465:         $output .= '<br />';
 1466:     }
 1467:     $output .='<br />';
 1468:     return $output;
 1469: }
 1470: 
 1471: sub login_text_colors {
 1472:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
 1473:     my $color_menu = '<table border="0"><tr>';
 1474:     foreach my $item (@{$logintext}) {
 1475:         $color_menu .= '<td align="center">'.$choices->{$item};
 1476:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
 1477:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
 1478:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1479:     }
 1480:     $color_menu .= '</tr></table><br />';
 1481:     return $color_menu;
 1482: }
 1483: 
 1484: sub image_changes {
 1485:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1486:     my $output;
 1487:     if ($img eq 'login') {
 1488:             # suppress image for Log-in header
 1489:     } elsif (!$is_custom) {
 1490:         if ($img ne 'domlogo') {
 1491:             $output .= &mt('Default image:').'<br />';
 1492:         } else {
 1493:             $output .= &mt('Default in use:').'<br />';
 1494:         }
 1495:     }
 1496:     if ($img eq 'login') { # suppress image for Log-in header
 1497:         $output .= '<td>'.$logincolors;
 1498:     } else {
 1499:         if ($img_import) {
 1500:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1501:         }
 1502:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1503:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1504:         if ($is_custom) {
 1505:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1506:                        '<input type="checkbox" name="'.
 1507:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1508:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1509:         } else {
 1510:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
 1511:         }
 1512:     }
 1513:     return $output;
 1514: }
 1515: 
 1516: sub print_quotas {
 1517:     my ($dom,$settings,$rowtotal,$action) = @_;
 1518:     my $context;
 1519:     if ($action eq 'quotas') {
 1520:         $context = 'tools';
 1521:     } else {
 1522:         $context = $action;
 1523:     }
 1524:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
 1525:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1526:     my $typecount = 0;
 1527:     my ($css_class,%titles);
 1528:     if ($context eq 'requestcourses') {
 1529:         @usertools = ('official','unofficial','community');
 1530:         @options =('norequest','approval','validate','autolimit');
 1531:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 1532:         %titles = &courserequest_titles();
 1533:     } elsif ($context eq 'requestauthor') {
 1534:         @usertools = ('author');
 1535:         @options = ('norequest','approval','automatic');
 1536:         %titles = &authorrequest_titles();
 1537:     } else {
 1538:         @usertools = ('aboutme','blog','webdav','portfolio');
 1539:         %titles = &tool_titles();
 1540:     }
 1541:     if (ref($types) eq 'ARRAY') {
 1542:         foreach my $type (@{$types}) {
 1543:             my ($currdefquota,$currauthorquota);
 1544:             unless (($context eq 'requestcourses') ||
 1545:                     ($context eq 'requestauthor')) {
 1546:                 if (ref($settings) eq 'HASH') {
 1547:                     if (ref($settings->{defaultquota}) eq 'HASH') {
 1548:                         $currdefquota = $settings->{defaultquota}->{$type};
 1549:                     } else {
 1550:                         $currdefquota = $settings->{$type};
 1551:                     }
 1552:                     if (ref($settings->{authorquota}) eq 'HASH') {
 1553:                         $currauthorquota = $settings->{authorquota}->{$type};
 1554:                     }
 1555:                 }
 1556:             }
 1557:             if (defined($usertypes->{$type})) {
 1558:                 $typecount ++;
 1559:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1560:                 $datatable .= '<tr'.$css_class.'>'.
 1561:                               '<td>'.$usertypes->{$type}.'</td>'.
 1562:                               '<td class="LC_left_item">';
 1563:                 if ($context eq 'requestcourses') {
 1564:                     $datatable .= '<table><tr>';
 1565:                 }
 1566:                 my %cell;  
 1567:                 foreach my $item (@usertools) {
 1568:                     if ($context eq 'requestcourses') {
 1569:                         my ($curroption,$currlimit);
 1570:                         if (ref($settings) eq 'HASH') {
 1571:                             if (ref($settings->{$item}) eq 'HASH') {
 1572:                                 $curroption = $settings->{$item}->{$type};
 1573:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
 1574:                                     $currlimit = $1; 
 1575:                                 }
 1576:                             }
 1577:                         }
 1578:                         if (!$curroption) {
 1579:                             $curroption = 'norequest';
 1580:                         }
 1581:                         $datatable .= '<th>'.$titles{$item}.'</th>';
 1582:                         foreach my $option (@options) {
 1583:                             my $val = $option;
 1584:                             if ($option eq 'norequest') {
 1585:                                 $val = 0;  
 1586:                             }
 1587:                             if ($option eq 'validate') {
 1588:                                 my $canvalidate = 0;
 1589:                                 if (ref($validations{$item}) eq 'HASH') { 
 1590:                                     if ($validations{$item}{$type}) {
 1591:                                         $canvalidate = 1;
 1592:                                     }
 1593:                                 }
 1594:                                 next if (!$canvalidate);
 1595:                             }
 1596:                             my $checked = '';
 1597:                             if ($option eq $curroption) {
 1598:                                 $checked = ' checked="checked"';
 1599:                             } elsif ($option eq 'autolimit') {
 1600:                                 if ($curroption =~ /^autolimit/) {
 1601:                                     $checked = ' checked="checked"';
 1602:                                 }                       
 1603:                             } 
 1604:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
 1605:                                   '<input type="radio" name="crsreq_'.$item.
 1606:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
 1607:                                   $titles{$option}.'</label>';
 1608:                             if ($option eq 'autolimit') {
 1609:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1610:                                                 $item.'_limit_'.$type.'" size="1" '.
 1611:                                                 'value="'.$currlimit.'" />';
 1612:                             }
 1613:                             $cell{$item} .= '</span> ';
 1614:                             if ($option eq 'autolimit') {
 1615:                                 $cell{$item} .= $titles{'unlimited'};
 1616:                             }
 1617:                         }
 1618:                     } elsif ($context eq 'requestauthor') {
 1619:                         my $curroption;
 1620:                         if (ref($settings) eq 'HASH') {
 1621:                             $curroption = $settings->{$type};
 1622:                         }
 1623:                         if (!$curroption) {
 1624:                             $curroption = 'norequest';
 1625:                         }
 1626:                         foreach my $option (@options) {
 1627:                             my $val = $option;
 1628:                             if ($option eq 'norequest') {
 1629:                                 $val = 0;
 1630:                             }
 1631:                             my $checked = '';
 1632:                             if ($option eq $curroption) {
 1633:                                 $checked = ' checked="checked"';
 1634:                             }
 1635:                             $datatable .= '<span class="LC_nobreak"><label>'.
 1636:                                   '<input type="radio" name="authorreq_'.$type.
 1637:                                   '" value="'.$val.'"'.$checked.' />'.
 1638:                                   $titles{$option}.'</label></span>&nbsp; ';
 1639:                         }
 1640:                     } else {
 1641:                         my $checked = 'checked="checked" ';
 1642:                         if (ref($settings) eq 'HASH') {
 1643:                             if (ref($settings->{$item}) eq 'HASH') {
 1644:                                 if ($settings->{$item}->{$type} == 0) {
 1645:                                     $checked = '';
 1646:                                 } elsif ($settings->{$item}->{$type} == 1) {
 1647:                                     $checked =  'checked="checked" ';
 1648:                                 }
 1649:                             }
 1650:                         }
 1651:                         $datatable .= '<span class="LC_nobreak"><label>'.
 1652:                                       '<input type="checkbox" name="'.$context.'_'.$item.
 1653:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1654:                                       '</label></span>&nbsp; ';
 1655:                     }
 1656:                 }
 1657:                 if ($context eq 'requestcourses') {
 1658:                     $datatable .= '</tr><tr>';
 1659:                     foreach my $item (@usertools) {
 1660:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
 1661:                     }
 1662:                     $datatable .= '</tr></table>';
 1663:                 }
 1664:                 $datatable .= '</td>';
 1665:                 unless (($context eq 'requestcourses') ||
 1666:                         ($context eq 'requestauthor')) {
 1667:                     $datatable .= 
 1668:                               '<td class="LC_right_item">'.
 1669:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1670:                               '<input type="text" name="quota_'.$type.
 1671:                               '" value="'.$currdefquota.
 1672:                               '" size="5" /></span>'.('&nbsp;' x 2).
 1673:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1674:                               '<input type="text" name="authorquota_'.$type.
 1675:                               '" value="'.$currauthorquota.
 1676:                               '" size="5" /></span></td>';
 1677:                 }
 1678:                 $datatable .= '</tr>';
 1679:             }
 1680:         }
 1681:     }
 1682:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1683:         $defaultquota = '20';
 1684:         $authorquota = '500';
 1685:         if (ref($settings) eq 'HASH') {
 1686:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1687:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
 1688:             } elsif (defined($settings->{'default'})) {
 1689:                 $defaultquota = $settings->{'default'};
 1690:             }
 1691:             if (ref($settings->{'authorquota'}) eq 'HASH') {
 1692:                 $authorquota = $settings->{'authorquota'}->{'default'};
 1693:             }
 1694:         }
 1695:     }
 1696:     $typecount ++;
 1697:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1698:     $datatable .= '<tr'.$css_class.'>'.
 1699:                   '<td>'.$othertitle.'</td>'.
 1700:                   '<td class="LC_left_item">';
 1701:     if ($context eq 'requestcourses') {
 1702:         $datatable .= '<table><tr>';
 1703:     }
 1704:     my %defcell;
 1705:     foreach my $item (@usertools) {
 1706:         if ($context eq 'requestcourses') {
 1707:             my ($curroption,$currlimit);
 1708:             if (ref($settings) eq 'HASH') {
 1709:                 if (ref($settings->{$item}) eq 'HASH') {
 1710:                     $curroption = $settings->{$item}->{'default'};
 1711:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1712:                         $currlimit = $1;
 1713:                     }
 1714:                 }
 1715:             }
 1716:             if (!$curroption) {
 1717:                 $curroption = 'norequest';
 1718:             }
 1719:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1720:             foreach my $option (@options) {
 1721:                 my $val = $option;
 1722:                 if ($option eq 'norequest') {
 1723:                     $val = 0;
 1724:                 }
 1725:                 if ($option eq 'validate') {
 1726:                     my $canvalidate = 0;
 1727:                     if (ref($validations{$item}) eq 'HASH') {
 1728:                         if ($validations{$item}{'default'}) {
 1729:                             $canvalidate = 1;
 1730:                         }
 1731:                     }
 1732:                     next if (!$canvalidate);
 1733:                 }
 1734:                 my $checked = '';
 1735:                 if ($option eq $curroption) {
 1736:                     $checked = ' checked="checked"';
 1737:                 } elsif ($option eq 'autolimit') {
 1738:                     if ($curroption =~ /^autolimit/) {
 1739:                         $checked = ' checked="checked"';
 1740:                     }
 1741:                 }
 1742:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
 1743:                                   '<input type="radio" name="crsreq_'.$item.
 1744:                                   '_default" value="'.$val.'"'.$checked.' />'.
 1745:                                   $titles{$option}.'</label>';
 1746:                 if ($option eq 'autolimit') {
 1747:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1748:                                        $item.'_limit_default" size="1" '.
 1749:                                        'value="'.$currlimit.'" />';
 1750:                 }
 1751:                 $defcell{$item} .= '</span> ';
 1752:                 if ($option eq 'autolimit') {
 1753:                     $defcell{$item} .= $titles{'unlimited'};
 1754:                 }
 1755:             }
 1756:         } elsif ($context eq 'requestauthor') {
 1757:             my $curroption;
 1758:             if (ref($settings) eq 'HASH') {
 1759:                 $curroption = $settings->{'default'};
 1760:             }
 1761:             if (!$curroption) {
 1762:                 $curroption = 'norequest';
 1763:             }
 1764:             foreach my $option (@options) {
 1765:                 my $val = $option;
 1766:                 if ($option eq 'norequest') {
 1767:                     $val = 0;
 1768:                 }
 1769:                 my $checked = '';
 1770:                 if ($option eq $curroption) {
 1771:                     $checked = ' checked="checked"';
 1772:                 }
 1773:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1774:                               '<input type="radio" name="authorreq_default"'.
 1775:                               ' value="'.$val.'"'.$checked.' />'.
 1776:                               $titles{$option}.'</label></span>&nbsp; ';
 1777:             }
 1778:         } else {
 1779:             my $checked = 'checked="checked" ';
 1780:             if (ref($settings) eq 'HASH') {
 1781:                 if (ref($settings->{$item}) eq 'HASH') {
 1782:                     if ($settings->{$item}->{'default'} == 0) {
 1783:                         $checked = '';
 1784:                     } elsif ($settings->{$item}->{'default'} == 1) {
 1785:                         $checked = 'checked="checked" ';
 1786:                     }
 1787:                 }
 1788:             }
 1789:             $datatable .= '<span class="LC_nobreak"><label>'.
 1790:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1791:                           '" value="default" '.$checked.'/>'.$titles{$item}.
 1792:                           '</label></span>&nbsp; ';
 1793:         }
 1794:     }
 1795:     if ($context eq 'requestcourses') {
 1796:         $datatable .= '</tr><tr>';
 1797:         foreach my $item (@usertools) {
 1798:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
 1799:         }
 1800:         $datatable .= '</tr></table>';
 1801:     }
 1802:     $datatable .= '</td>';
 1803:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 1804:         $datatable .= '<td class="LC_right_item">'.
 1805:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
 1806:                       '<input type="text" name="defaultquota" value="'.
 1807:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
 1808:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
 1809:                       '<input type="text" name="authorquota" value="'.
 1810:                       $authorquota.'" size="5" /></span></td>';
 1811:     }
 1812:     $datatable .= '</tr>';
 1813:     $typecount ++;
 1814:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1815:     $datatable .= '<tr'.$css_class.'>'.
 1816:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
 1817:     if ($context eq 'requestcourses') {
 1818:         $datatable .= &mt('(overrides affiliation, if set)').
 1819:                       '</td>'.
 1820:                       '<td class="LC_left_item">'.
 1821:                       '<table><tr>';
 1822:     } else {
 1823:         $datatable .= &mt('(overrides affiliation, if checked)').
 1824:                       '</td>'.
 1825:                       '<td class="LC_left_item" colspan="2">'.
 1826:                       '<br />';
 1827:     }
 1828:     my %advcell;
 1829:     foreach my $item (@usertools) {
 1830:         if ($context eq 'requestcourses') {
 1831:             my ($curroption,$currlimit);
 1832:             if (ref($settings) eq 'HASH') {
 1833:                 if (ref($settings->{$item}) eq 'HASH') {
 1834:                     $curroption = $settings->{$item}->{'_LC_adv'};
 1835:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1836:                         $currlimit = $1;
 1837:                     }
 1838:                 }
 1839:             }
 1840:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1841:             my $checked = '';
 1842:             if ($curroption eq '') {
 1843:                 $checked = ' checked="checked"';
 1844:             }
 1845:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1846:                                '<input type="radio" name="crsreq_'.$item.
 1847:                                '__LC_adv" value=""'.$checked.' />'.
 1848:                                &mt('No override set').'</label></span>&nbsp; ';
 1849:             foreach my $option (@options) {
 1850:                 my $val = $option;
 1851:                 if ($option eq 'norequest') {
 1852:                     $val = 0;
 1853:                 }
 1854:                 if ($option eq 'validate') {
 1855:                     my $canvalidate = 0;
 1856:                     if (ref($validations{$item}) eq 'HASH') {
 1857:                         if ($validations{$item}{'_LC_adv'}) {
 1858:                             $canvalidate = 1;
 1859:                         }
 1860:                     }
 1861:                     next if (!$canvalidate);
 1862:                 }
 1863:                 my $checked = '';
 1864:                 if ($val eq $curroption) {
 1865:                     $checked = ' checked="checked"';
 1866:                 } elsif ($option eq 'autolimit') {
 1867:                     if ($curroption =~ /^autolimit/) {
 1868:                         $checked = ' checked="checked"';
 1869:                     }
 1870:                 }
 1871:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1872:                                   '<input type="radio" name="crsreq_'.$item.
 1873:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
 1874:                                   $titles{$option}.'</label>';
 1875:                 if ($option eq 'autolimit') {
 1876:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1877:                                        $item.'_limit__LC_adv" size="1" '.
 1878:                                        'value="'.$currlimit.'" />';
 1879:                 }
 1880:                 $advcell{$item} .= '</span> ';
 1881:                 if ($option eq 'autolimit') {
 1882:                     $advcell{$item} .= $titles{'unlimited'};
 1883:                 }
 1884:             }
 1885:         } elsif ($context eq 'requestauthor') {
 1886:             my $curroption;
 1887:             if (ref($settings) eq 'HASH') {
 1888:                 $curroption = $settings->{'_LC_adv'};
 1889:             }
 1890:             my $checked = '';
 1891:             if ($curroption eq '') {
 1892:                 $checked = ' checked="checked"';
 1893:             }
 1894:             $datatable .= '<span class="LC_nobreak"><label>'.
 1895:                           '<input type="radio" name="authorreq__LC_adv"'.
 1896:                           ' value=""'.$checked.' />'.
 1897:                           &mt('No override set').'</label></span>&nbsp; ';
 1898:             foreach my $option (@options) {
 1899:                 my $val = $option;
 1900:                 if ($option eq 'norequest') {
 1901:                     $val = 0;
 1902:                 }
 1903:                 my $checked = '';
 1904:                 if ($val eq $curroption) {
 1905:                     $checked = ' checked="checked"';
 1906:                 }
 1907:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1908:                               '<input type="radio" name="authorreq__LC_adv"'.
 1909:                               ' value="'.$val.'"'.$checked.' />'.
 1910:                               $titles{$option}.'</label></span>&nbsp; ';
 1911:             }
 1912:         } else {
 1913:             my $checked = 'checked="checked" ';
 1914:             if (ref($settings) eq 'HASH') {
 1915:                 if (ref($settings->{$item}) eq 'HASH') {
 1916:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
 1917:                         $checked = '';
 1918:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
 1919:                         $checked = 'checked="checked" ';
 1920:                     }
 1921:                 }
 1922:             }
 1923:             $datatable .= '<span class="LC_nobreak"><label>'.
 1924:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1925:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 1926:                           '</label></span>&nbsp; ';
 1927:         }
 1928:     }
 1929:     if ($context eq 'requestcourses') {
 1930:         $datatable .= '</tr><tr>';
 1931:         foreach my $item (@usertools) {
 1932:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
 1933:         }
 1934:         $datatable .= '</tr></table>';
 1935:     }
 1936:     $datatable .= '</td></tr>';
 1937:     $$rowtotal += $typecount;
 1938:     return $datatable;
 1939: }
 1940: 
 1941: sub print_requestmail {
 1942:     my ($dom,$action,$settings,$rowtotal) = @_;
 1943:     my ($now,$datatable,%currapp,$rows);
 1944:     $now = time;
 1945:     if (ref($settings) eq 'HASH') {
 1946:         if (ref($settings->{'notify'}) eq 'HASH') {
 1947:             if ($settings->{'notify'}{'approval'} ne '') {
 1948:                map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
 1949:             }
 1950:         }
 1951:     }
 1952:     my $numinrow = 2;
 1953:     my $css_class = 'class="LC_odd_row"';
 1954:     my $text;
 1955:     if ($action eq 'requestcourses') {
 1956:         $text = &mt('Receive notification of course requests requiring approval');
 1957:     } else {
 1958:         $text = &mt('Receive notification of authoring space requests requiring approval')
 1959:     }
 1960:     $datatable = '<tr '.$css_class.'>'.
 1961:                  ' <td>'.$text.'</td>'.
 1962:                  ' <td class="LC_left_item">';
 1963:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
 1964:                                                  'reqapprovalnotify',%currapp);
 1965:     if ($numdc > 0) {
 1966:         $datatable .= $table;
 1967:     } else {
 1968:         $datatable .= &mt('There are no active Domain Coordinators');
 1969:     }
 1970:     $datatable .='</td></tr>';
 1971:     $$rowtotal += $rows;
 1972:     return $datatable;
 1973: }
 1974: 
 1975: sub print_autoenroll {
 1976:     my ($dom,$settings,$rowtotal) = @_;
 1977:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1978:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
 1979:     if (ref($settings) eq 'HASH') {
 1980:         if (exists($settings->{'run'})) {
 1981:             if ($settings->{'run'} eq '0') {
 1982:                 $runoff = ' checked="checked" ';
 1983:                 $runon = ' ';
 1984:             } else {
 1985:                 $runon = ' checked="checked" ';
 1986:                 $runoff = ' ';
 1987:             }
 1988:         } else {
 1989:             if ($autorun) {
 1990:                 $runon = ' checked="checked" ';
 1991:                 $runoff = ' ';
 1992:             } else {
 1993:                 $runoff = ' checked="checked" ';
 1994:                 $runon = ' ';
 1995:             }
 1996:         }
 1997:         if (exists($settings->{'co-owners'})) {
 1998:             if ($settings->{'co-owners'} eq '0') {
 1999:                 $coownersoff = ' checked="checked" ';
 2000:                 $coownerson = ' ';
 2001:             } else {
 2002:                 $coownerson = ' checked="checked" ';
 2003:                 $coownersoff = ' ';
 2004:             }
 2005:         } else {
 2006:             $coownersoff = ' checked="checked" ';
 2007:             $coownerson = ' ';
 2008:         }
 2009:         if (exists($settings->{'sender_domain'})) {
 2010:             $defdom = $settings->{'sender_domain'};
 2011:         }
 2012:     } else {
 2013:         if ($autorun) {
 2014:             $runon = ' checked="checked" ';
 2015:             $runoff = ' ';
 2016:         } else {
 2017:             $runoff = ' checked="checked" ';
 2018:             $runon = ' ';
 2019:         }
 2020:     }
 2021:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 2022:     my $notif_sender;
 2023:     if (ref($settings) eq 'HASH') {
 2024:         $notif_sender = $settings->{'sender_uname'};
 2025:     }
 2026:     my $datatable='<tr class="LC_odd_row">'.
 2027:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 2028:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2029:                   '<input type="radio" name="autoenroll_run"'.
 2030:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2031:                   '<label><input type="radio" name="autoenroll_run"'.
 2032:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2033:                   '</tr><tr>'.
 2034:                   '<td>'.&mt('Notification messages - sender').
 2035:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 2036:                   &mt('username').':&nbsp;'.
 2037:                   '<input type="text" name="sender_uname" value="'.
 2038:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 2039:                   ':&nbsp;'.$domform.'</span></td></tr>'.
 2040:                   '<tr class="LC_odd_row">'.
 2041:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
 2042:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2043:                   '<input type="radio" name="autoassign_coowners"'.
 2044:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2045:                   '<label><input type="radio" name="autoassign_coowners"'.
 2046:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2047:                   '</tr>';
 2048:     $$rowtotal += 3;
 2049:     return $datatable;
 2050: }
 2051: 
 2052: sub print_autoupdate {
 2053:     my ($position,$dom,$settings,$rowtotal) = @_;
 2054:     my $datatable;
 2055:     if ($position eq 'top') {
 2056:         my $updateon = ' ';
 2057:         my $updateoff = ' checked="checked" ';
 2058:         my $classlistson = ' ';
 2059:         my $classlistsoff = ' checked="checked" ';
 2060:         if (ref($settings) eq 'HASH') {
 2061:             if ($settings->{'run'} eq '1') {
 2062:                 $updateon = $updateoff;
 2063:                 $updateoff = ' ';
 2064:             }
 2065:             if ($settings->{'classlists'} eq '1') {
 2066:                 $classlistson = $classlistsoff;
 2067:                 $classlistsoff = ' ';
 2068:             }
 2069:         }
 2070:         my %title = (
 2071:                    run => 'Auto-update active?',
 2072:                    classlists => 'Update information in classlists?',
 2073:                     );
 2074:         $datatable = '<tr class="LC_odd_row">'. 
 2075:                   '<td>'.&mt($title{'run'}).'</td>'.
 2076:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2077:                   '<input type="radio" name="autoupdate_run"'.
 2078:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2079:                   '<label><input type="radio" name="autoupdate_run"'.
 2080:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2081:                   '</tr><tr>'.
 2082:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 2083:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 2084:                   '<label><input type="radio" name="classlists"'.
 2085:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2086:                   '<label><input type="radio" name="classlists"'.
 2087:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 2088:                   '</tr>';
 2089:         $$rowtotal += 2;
 2090:     } elsif ($position eq 'middle') {
 2091:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2092:         my $numinrow = 3;
 2093:         my $locknamesettings;
 2094:         $datatable .= &insttypes_row($settings,$types,$usertypes,
 2095:                                      $dom,$numinrow,$othertitle,
 2096:                                     'lockablenames');
 2097:         $$rowtotal ++;
 2098:     } else {
 2099:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2100:         my @fields = ('lastname','firstname','middlename','generation',
 2101:                       'permanentemail','id');
 2102:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 2103:         my $numrows = 0;
 2104:         if (ref($types) eq 'ARRAY') {
 2105:             if (@{$types} > 0) {
 2106:                 $datatable = 
 2107:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 2108:                                          \@fields,$types,\$numrows);
 2109:                     $$rowtotal += @{$types}; 
 2110:             }
 2111:         }
 2112:         $datatable .= 
 2113:             &usertype_update_row($settings,{'default' => $othertitle},
 2114:                                  \%fieldtitles,\@fields,['default'],
 2115:                                  \$numrows);
 2116:         $$rowtotal ++;     
 2117:     }
 2118:     return $datatable;
 2119: }
 2120: 
 2121: sub print_autocreate {
 2122:     my ($dom,$settings,$rowtotal) = @_;
 2123:     my (%createon,%createoff,%currhash);
 2124:     my @types = ('xml','req');
 2125:     if (ref($settings) eq 'HASH') {
 2126:         foreach my $item (@types) {
 2127:             $createoff{$item} = ' checked="checked" ';
 2128:             $createon{$item} = ' ';
 2129:             if (exists($settings->{$item})) {
 2130:                 if ($settings->{$item}) {
 2131:                     $createon{$item} = ' checked="checked" ';
 2132:                     $createoff{$item} = ' ';
 2133:                 }
 2134:             }
 2135:         }
 2136:         if ($settings->{'xmldc'} ne '') {
 2137:             $currhash{$settings->{'xmldc'}} = 1;
 2138:         }
 2139:     } else {
 2140:         foreach my $item (@types) {
 2141:             $createoff{$item} = ' checked="checked" ';
 2142:             $createon{$item} = ' ';
 2143:         }
 2144:     }
 2145:     $$rowtotal += 2;
 2146:     my $numinrow = 2;
 2147:     my $datatable='<tr class="LC_odd_row">'.
 2148:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
 2149:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2150:                   '<input type="radio" name="autocreate_xml"'.
 2151:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2152:                   '<label><input type="radio" name="autocreate_xml"'.
 2153:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
 2154:                   '</td></tr><tr>'.
 2155:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
 2156:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2157:                   '<input type="radio" name="autocreate_req"'.
 2158:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2159:                   '<label><input type="radio" name="autocreate_req"'.
 2160:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
 2161:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
 2162:                                                    'autocreate_xmldc',%currhash);
 2163:     if ($numdc > 1) {
 2164:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
 2165:                       &mt('Course creation processed as: (choose Dom. Coord.)').
 2166:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
 2167:     } else {
 2168:         $datatable .= $dctable.'</td></tr>';
 2169:     }
 2170:     $$rowtotal += $rows;
 2171:     return $datatable;
 2172: }
 2173: 
 2174: sub print_directorysrch {
 2175:     my ($dom,$settings,$rowtotal) = @_;
 2176:     my $srchon = ' ';
 2177:     my $srchoff = ' checked="checked" ';
 2178:     my ($exacton,$containson,$beginson);
 2179:     my $localon = ' ';
 2180:     my $localoff = ' checked="checked" ';
 2181:     if (ref($settings) eq 'HASH') {
 2182:         if ($settings->{'available'} eq '1') {
 2183:             $srchon = $srchoff;
 2184:             $srchoff = ' ';
 2185:         }
 2186:         if ($settings->{'localonly'} eq '1') {
 2187:             $localon = $localoff;
 2188:             $localoff = ' ';
 2189:         }
 2190:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 2191:             foreach my $type (@{$settings->{'searchtypes'}}) {
 2192:                 if ($type eq 'exact') {
 2193:                     $exacton = ' checked="checked" ';
 2194:                 } elsif ($type eq 'contains') {
 2195:                     $containson = ' checked="checked" ';
 2196:                 } elsif ($type eq 'begins') {
 2197:                     $beginson = ' checked="checked" ';
 2198:                 }
 2199:             }
 2200:         } else {
 2201:             if ($settings->{'searchtypes'} eq 'exact') {
 2202:                 $exacton = ' checked="checked" ';
 2203:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 2204:                 $containson = ' checked="checked" ';
 2205:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 2206:                 $exacton = ' checked="checked" ';
 2207:                 $containson = ' checked="checked" ';
 2208:             }
 2209:         }
 2210:     }
 2211:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 2212:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2213: 
 2214:     my $numinrow = 4;
 2215:     my $cansrchrow = 0;
 2216:     my $datatable='<tr class="LC_odd_row">'.
 2217:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 2218:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2219:                   '<input type="radio" name="dirsrch_available"'.
 2220:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 2221:                   '<label><input type="radio" name="dirsrch_available"'.
 2222:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 2223:                   '</tr><tr>'.
 2224:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 2225:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2226:                   '<input type="radio" name="dirsrch_localonly"'.
 2227:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 2228:                   '<label><input type="radio" name="dirsrch_localonly"'.
 2229:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 2230:                   '</tr>';
 2231:     $$rowtotal += 2;
 2232:     if (ref($usertypes) eq 'HASH') {
 2233:         if (keys(%{$usertypes}) > 0) {
 2234:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
 2235:                                          $numinrow,$othertitle,'cansearch');
 2236:             $cansrchrow = 1;
 2237:         }
 2238:     }
 2239:     if ($cansrchrow) {
 2240:         $$rowtotal ++;
 2241:         $datatable .= '<tr>';
 2242:     } else {
 2243:         $datatable .= '<tr class="LC_odd_row">';
 2244:     }
 2245:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 2246:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 2247:     foreach my $title (@{$titleorder}) {
 2248:         if (defined($searchtitles->{$title})) {
 2249:             my $check = ' ';
 2250:             if (ref($settings) eq 'HASH') {
 2251:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 2252:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 2253:                         $check = ' checked="checked" ';
 2254:                     }
 2255:                 }
 2256:             }
 2257:             $datatable .= '<td class="LC_left_item">'.
 2258:                           '<span class="LC_nobreak"><label>'.
 2259:                           '<input type="checkbox" name="searchby" '.
 2260:                           'value="'.$title.'"'.$check.'/>'.
 2261:                           $searchtitles->{$title}.'</label></span></td>';
 2262:         }
 2263:     }
 2264:     $datatable .= '</tr></table></td></tr>';
 2265:     $$rowtotal ++;
 2266:     if ($cansrchrow) {
 2267:         $datatable .= '<tr class="LC_odd_row">';
 2268:     } else {
 2269:         $datatable .= '<tr>';
 2270:     }
 2271:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 2272:                   '<td class="LC_left_item" colspan="2">'.
 2273:                   '<span class="LC_nobreak"><label>'.
 2274:                   '<input type="checkbox" name="searchtypes" '.
 2275:                   $exacton.' value="exact" />'.&mt('Exact match').
 2276:                   '</label>&nbsp;'.
 2277:                   '<label><input type="checkbox" name="searchtypes" '.
 2278:                   $beginson.' value="begins" />'.&mt('Begins with').
 2279:                   '</label>&nbsp;'.
 2280:                   '<label><input type="checkbox" name="searchtypes" '.
 2281:                   $containson.' value="contains" />'.&mt('Contains').
 2282:                   '</label></span></td></tr>';
 2283:     $$rowtotal ++;
 2284:     return $datatable;
 2285: }
 2286: 
 2287: sub print_contacts {
 2288:     my ($dom,$settings,$rowtotal) = @_;
 2289:     my $datatable;
 2290:     my @contacts = ('adminemail','supportemail');
 2291:     my (%checked,%to,%otheremails,%bccemails);
 2292:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
 2293:                     'requestsmail','updatesmail');
 2294:     foreach my $type (@mailings) {
 2295:         $otheremails{$type} = '';
 2296:     }
 2297:     $bccemails{'helpdeskmail'} = '';
 2298:     if (ref($settings) eq 'HASH') {
 2299:         foreach my $item (@contacts) {
 2300:             if (exists($settings->{$item})) {
 2301:                 $to{$item} = $settings->{$item};
 2302:             }
 2303:         }
 2304:         foreach my $type (@mailings) {
 2305:             if (exists($settings->{$type})) {
 2306:                 if (ref($settings->{$type}) eq 'HASH') {
 2307:                     foreach my $item (@contacts) {
 2308:                         if ($settings->{$type}{$item}) {
 2309:                             $checked{$type}{$item} = ' checked="checked" ';
 2310:                         }
 2311:                     }
 2312:                     $otheremails{$type} = $settings->{$type}{'others'};
 2313:                     if ($type eq 'helpdeskmail') {
 2314:                         $bccemails{$type} = $settings->{$type}{'bcc'};
 2315:                     }
 2316:                 }
 2317:             } elsif ($type eq 'lonstatusmail') {
 2318:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
 2319:             }
 2320:         }
 2321:     } else {
 2322:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2323:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2324:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 2325:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 2326:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
 2327:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
 2328:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
 2329:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" '; 
 2330:     }
 2331:     my ($titles,$short_titles) = &contact_titles();
 2332:     my $rownum = 0;
 2333:     my $css_class;
 2334:     foreach my $item (@contacts) {
 2335:         $rownum ++;
 2336:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2337:         $datatable .= '<tr'.$css_class.'>'. 
 2338:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2339:                   '</span></td><td class="LC_right_item">'.
 2340:                   '<input type="text" name="'.$item.'" value="'.
 2341:                   $to{$item}.'" /></td></tr>';
 2342:     }
 2343:     foreach my $type (@mailings) {
 2344:         $rownum ++;
 2345:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2346:         $datatable .= '<tr'.$css_class.'>'.
 2347:                       '<td><span class="LC_nobreak">'.
 2348:                       $titles->{$type}.': </span></td>'.
 2349:                       '<td class="LC_left_item">'.
 2350:                       '<span class="LC_nobreak">';
 2351:         foreach my $item (@contacts) {
 2352:             $datatable .= '<label>'.
 2353:                           '<input type="checkbox" name="'.$type.'"'.
 2354:                           $checked{$type}{$item}.
 2355:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 2356:                           '</label>&nbsp;';
 2357:         }
 2358:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 2359:                       '<input type="text" name="'.$type.'_others" '.
 2360:                       'value="'.$otheremails{$type}.'"  />';
 2361:         if ($type eq 'helpdeskmail') {
 2362:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
 2363:                           '<input type="text" name="'.$type.'_bcc" '.
 2364:                           'value="'.$bccemails{$type}.'"  />';
 2365:         }
 2366:         $datatable .= '</td></tr>'."\n";
 2367:     }
 2368:     $$rowtotal += $rownum;
 2369:     return $datatable;
 2370: }
 2371: 
 2372: sub print_helpsettings {
 2373:     my ($dom,$confname,$settings,$rowtotal) = @_;
 2374:     my ($datatable,$itemcount);
 2375:     $itemcount = 1;
 2376:     my (%choices,%defaultchecked,@toggles);
 2377:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
 2378:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
 2379:                                  &mt('LON-CAPA bug tracker'),600,500));
 2380:     %defaultchecked = ('submitbugs' => 'on');
 2381:     @toggles = ('submitbugs',);
 2382: 
 2383:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2384:                                                  \%choices,$itemcount);
 2385:     return $datatable;
 2386: }
 2387: 
 2388: sub radiobutton_prefs {
 2389:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
 2390:         $additional) = @_;
 2391:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
 2392:                    (ref($choices) eq 'HASH'));
 2393: 
 2394:     my (%checkedon,%checkedoff,$datatable,$css_class);
 2395: 
 2396:     foreach my $item (@{$toggles}) {
 2397:         if ($defaultchecked->{$item} eq 'on') {
 2398:             $checkedon{$item} = ' checked="checked" ';
 2399:             $checkedoff{$item} = ' ';
 2400:         } elsif ($defaultchecked->{$item} eq 'off') {
 2401:             $checkedoff{$item} = ' checked="checked" ';
 2402:             $checkedon{$item} = ' ';
 2403:         }
 2404:     }
 2405:     if (ref($settings) eq 'HASH') {
 2406:         foreach my $item (@{$toggles}) {
 2407:             if ($settings->{$item} eq '1') {
 2408:                 $checkedon{$item} =  ' checked="checked" ';
 2409:                 $checkedoff{$item} = ' ';
 2410:             } elsif ($settings->{$item} eq '0') {
 2411:                 $checkedoff{$item} =  ' checked="checked" ';
 2412:                 $checkedon{$item} = ' ';
 2413:             }
 2414:         }
 2415:     }
 2416:     if ($onclick) {
 2417:         $onclick = ' onclick="'.$onclick.'"';
 2418:     }
 2419:     foreach my $item (@{$toggles}) {
 2420:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2421:         $datatable .=
 2422:             '<tr'.$css_class.'><td valign="top">'.
 2423:             '<span class="LC_nobreak">'.$choices->{$item}.
 2424:             '</span></td>'.
 2425:             '<td class="LC_right_item"><span class="LC_nobreak">'.
 2426:             '<label><input type="radio" name="'.
 2427:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
 2428:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
 2429:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
 2430:             '</span>'.$additional.
 2431:             '</td>'.
 2432:             '</tr>';
 2433:         $itemcount ++;
 2434:     }
 2435:     return ($datatable,$itemcount);
 2436: }
 2437: 
 2438: sub print_coursedefaults {
 2439:     my ($position,$dom,$settings,$rowtotal) = @_;
 2440:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
 2441:     my $itemcount = 1;
 2442:     my %choices =  &Apache::lonlocal::texthash (
 2443:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
 2444:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
 2445:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
 2446:         coursecredits        => 'Credits can be specified for courses',
 2447:     );
 2448:     my %staticdefaults = (
 2449:                            anonsurvey_threshold => 10,
 2450:                            uploadquota          => 500,
 2451:                          );
 2452:     if ($position eq 'top') {
 2453:         %defaultchecked = ('canuse_pdfforms' => 'off');
 2454:         @toggles = ('canuse_pdfforms');
 2455:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2456:                                                  \%choices,$itemcount);
 2457:     } else {
 2458:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2459:         my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
 2460:         my $currusecredits = 0;
 2461:         my @types = ('official','unofficial','community');
 2462:         if (ref($settings) eq 'HASH') {
 2463:             $currdefresponder = $settings->{'anonsurvey_threshold'};
 2464:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
 2465:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
 2466:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
 2467:                 }
 2468:             }
 2469:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
 2470:                 $def_official_credits = $settings->{'coursecredits'}->{'official'};
 2471:                 $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
 2472:                 if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
 2473:                     $currusecredits = 1;
 2474:                 }
 2475:             }
 2476:         }
 2477:         if (!$currdefresponder) {
 2478:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
 2479:         } elsif ($currdefresponder < 1) {
 2480:             $currdefresponder = 1;
 2481:         }
 2482:         foreach my $type (@types) {
 2483:             if ($curruploadquota{$type} eq '') {
 2484:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
 2485:             }
 2486:         }
 2487:         $datatable .=
 2488:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
 2489:                 $choices{'anonsurvey_threshold'}.
 2490:                 '</span></td>'.
 2491:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
 2492:                 '<input type="text" name="anonsurvey_threshold"'.
 2493:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
 2494:                 '</td></tr>'."\n".
 2495:                 '<tr><td><span class="LC_nobreak">'.
 2496:                 $choices{'uploadquota'}.
 2497:                 '</span></td>'.
 2498:                 '<td align="right" class="LC_right_item">'.
 2499:                 '<table><tr>';
 2500:         foreach my $type (@types) {
 2501:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
 2502:                            '<input type="text" name="uploadquota_'.$type.'"'.
 2503:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
 2504:         }
 2505:         $datatable .= '</tr></table></td></tr>'."\n";
 2506:         $itemcount += 2;
 2507:         my $onclick = 'toggleCredits(this.form);';
 2508:         my $display = 'none';
 2509:         if ($currusecredits) {
 2510:             $display = 'block';
 2511:         }
 2512:         my $additional = '<div id="credits" style="display: '.$display.'">'.
 2513:                          '<span class="LC_nobreak">'.
 2514:                          &mt('Default credits for official courses [_1]',
 2515:                          '<input type="text" name="official_credits" value="'.
 2516:                          $def_official_credits.'" size="3" />').
 2517:                          '</span><br />'.
 2518:                          '<span class="LC_nobreak">'.
 2519:                          &mt('Default credits for unofficial courses [_1]',
 2520:                          '<input type="text" name="unofficial_credits" value="'.
 2521:                          $def_unofficial_credits.'" size="3" />').
 2522:                          '</span></div>'."\n";
 2523:         %defaultchecked = ('coursecredits' => 'off');
 2524:         @toggles = ('coursecredits');
 2525:         my $current = {
 2526:                         'coursecredits' => $currusecredits,
 2527:                       };
 2528:         (my $table,$itemcount) =
 2529:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
 2530:                                \%choices,$itemcount,$onclick,$additional);
 2531:         $datatable .= $table;
 2532:     }
 2533:     $$rowtotal += $itemcount;
 2534:     return $datatable;
 2535: }
 2536: 
 2537: sub print_usersessions {
 2538:     my ($position,$dom,$settings,$rowtotal) = @_;
 2539:     my ($css_class,$datatable,%checked,%choices);
 2540:     my (%by_ip,%by_location,@intdoms);
 2541:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 2542: 
 2543:     my @alldoms = &Apache::lonnet::all_domains();
 2544:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
 2545:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 2546:     my %altids = &id_for_thisdom(%servers);
 2547:     my $itemcount = 1;
 2548:     if ($position eq 'top') {
 2549:         if (keys(%serverhomes) > 1) {
 2550:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
 2551:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
 2552:         } else {
 2553:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 2554:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
 2555:         }
 2556:     } else {
 2557:         if (keys(%by_location) == 0) {
 2558:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
 2559:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
 2560:         } else {
 2561:             my %lt = &usersession_titles();
 2562:             my $numinrow = 5;
 2563:             my $prefix;
 2564:             my @types;
 2565:             if ($position eq 'bottom') {
 2566:                 $prefix = 'remote';
 2567:                 @types = ('version','excludedomain','includedomain');
 2568:             } else {
 2569:                 $prefix = 'hosted';
 2570:                 @types = ('excludedomain','includedomain');
 2571:             }
 2572:             my (%current,%checkedon,%checkedoff);
 2573:             my @lcversions = &Apache::lonnet::all_loncaparevs();
 2574:             my @locations = sort(keys(%by_location));
 2575:             foreach my $type (@types) {
 2576:                 $checkedon{$type} = '';
 2577:                 $checkedoff{$type} = ' checked="checked"';
 2578:             }
 2579:             if (ref($settings) eq 'HASH') {
 2580:                 if (ref($settings->{$prefix}) eq 'HASH') {
 2581:                     foreach my $key (keys(%{$settings->{$prefix}})) {
 2582:                         $current{$key} = $settings->{$prefix}{$key};
 2583:                         if ($key eq 'version') {
 2584:                             if ($current{$key} ne '') {
 2585:                                 $checkedon{$key} = ' checked="checked"';
 2586:                                 $checkedoff{$key} = '';
 2587:                             }
 2588:                         } elsif (ref($current{$key}) eq 'ARRAY') {
 2589:                             $checkedon{$key} = ' checked="checked"';
 2590:                             $checkedoff{$key} = '';
 2591:                         }
 2592:                     }
 2593:                 }
 2594:             }
 2595:             foreach my $type (@types) {
 2596:                 next if ($type ne 'version' && !@locations);
 2597:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2598:                 $datatable .= '<tr'.$css_class.'>
 2599:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
 2600:                                <span class="LC_nobreak">&nbsp;
 2601:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
 2602:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
 2603:                 if ($type eq 'version') {
 2604:                     my $selector = '<select name="'.$prefix.'_version">';
 2605:                     foreach my $version (@lcversions) {
 2606:                         my $selected = '';
 2607:                         if ($current{'version'} eq $version) {
 2608:                             $selected = ' selected="selected"';
 2609:                         }
 2610:                         $selector .= ' <option value="'.$version.'"'.
 2611:                                      $selected.'>'.$version.'</option>';
 2612:                     }
 2613:                     $selector .= '</select> ';
 2614:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
 2615:                 } else {
 2616:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
 2617:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
 2618:                                  ' />'.('&nbsp;'x2).
 2619:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
 2620:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
 2621:                                  "\n".
 2622:                                  '</div><div><table>';
 2623:                     my $rem;
 2624:                     for (my $i=0; $i<@locations; $i++) {
 2625:                         my ($showloc,$value,$checkedtype);
 2626:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
 2627:                             my $ip = $by_location{$locations[$i]}->[0];
 2628:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
 2629:                                  $value = join(':',@{$by_ip{$ip}});
 2630:                                 $showloc = join(', ',@{$by_ip{$ip}});
 2631:                                 if (ref($current{$type}) eq 'ARRAY') {
 2632:                                     foreach my $loc (@{$by_ip{$ip}}) {  
 2633:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
 2634:                                             $checkedtype = ' checked="checked"';
 2635:                                             last;
 2636:                                         }
 2637:                                     }
 2638:                                 }
 2639:                             }
 2640:                         }
 2641:                         $rem = $i%($numinrow);
 2642:                         if ($rem == 0) {
 2643:                             if ($i > 0) {
 2644:                                 $datatable .= '</tr>';
 2645:                             }
 2646:                             $datatable .= '<tr>';
 2647:                         }
 2648:                         $datatable .= '<td class="LC_left_item">'.
 2649:                                       '<span class="LC_nobreak"><label>'.
 2650:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
 2651:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
 2652:                                       '</label></span></td>';
 2653:                     }
 2654:                     $rem = @locations%($numinrow);
 2655:                     my $colsleft = $numinrow - $rem;
 2656:                     if ($colsleft > 1 ) {
 2657:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2658:                                       '&nbsp;</td>';
 2659:                     } elsif ($colsleft == 1) {
 2660:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 2661:                     }
 2662:                     $datatable .= '</tr></table>';
 2663:                 }
 2664:                 $datatable .= '</td></tr>';
 2665:                 $itemcount ++;
 2666:             }
 2667:         }
 2668:     }
 2669:     $$rowtotal += $itemcount;
 2670:     return $datatable;
 2671: }
 2672: 
 2673: sub build_location_hashes {
 2674:     my ($intdoms,$by_ip,$by_location) = @_;
 2675:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
 2676:                   (ref($by_location) eq 'HASH')); 
 2677:     my %iphost = &Apache::lonnet::get_iphost();
 2678:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
 2679:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
 2680:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
 2681:         foreach my $id (@{$iphost{$primary_ip}}) {
 2682:             my $intdom = &Apache::lonnet::internet_dom($id);
 2683:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
 2684:                 push(@{$intdoms},$intdom);
 2685:             }
 2686:         }
 2687:     }
 2688:     foreach my $ip (keys(%iphost)) {
 2689:         if (ref($iphost{$ip}) eq 'ARRAY') {
 2690:             foreach my $id (@{$iphost{$ip}}) {
 2691:                 my $location = &Apache::lonnet::internet_dom($id);
 2692:                 if ($location) {
 2693:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
 2694:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2695:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
 2696:                             push(@{$by_ip->{$ip}},$location);
 2697:                         }
 2698:                     } else {
 2699:                         $by_ip->{$ip} = [$location];
 2700:                     }
 2701:                 }
 2702:             }
 2703:         }
 2704:     }
 2705:     foreach my $ip (sort(keys(%{$by_ip}))) {
 2706:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2707:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
 2708:             my $first = $by_ip->{$ip}->[0];
 2709:             if (ref($by_location->{$first}) eq 'ARRAY') {
 2710:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
 2711:                     push(@{$by_location->{$first}},$ip);
 2712:                 }
 2713:             } else {
 2714:                 $by_location->{$first} = [$ip];
 2715:             }
 2716:         }
 2717:     }
 2718:     return;
 2719: }
 2720: 
 2721: sub current_offloads_to {
 2722:     my ($dom,$settings,$servers) = @_;
 2723:     my (%spareid,%otherdomconfigs);
 2724:     if (ref($servers) eq 'HASH') {
 2725:         foreach my $lonhost (sort(keys(%{$servers}))) {
 2726:             my $gotspares;
 2727:             if (ref($settings) eq 'HASH') {
 2728:                 if (ref($settings->{'spares'}) eq 'HASH') {
 2729:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
 2730:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
 2731:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
 2732:                         $gotspares = 1;
 2733:                     }
 2734:                 }
 2735:             }
 2736:             unless ($gotspares) {
 2737:                 my $gotspares;
 2738:                 my $serverhomeID =
 2739:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
 2740:                 my $serverhomedom =
 2741:                     &Apache::lonnet::host_domain($serverhomeID);
 2742:                 if ($serverhomedom ne $dom) {
 2743:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
 2744:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 2745:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 2746:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 2747:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 2748:                                 $gotspares = 1;
 2749:                             }
 2750:                         }
 2751:                     } else {
 2752:                         $otherdomconfigs{$serverhomedom} =
 2753:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
 2754:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
 2755:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
 2756:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
 2757:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
 2758:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
 2759:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
 2760:                                         $gotspares = 1;
 2761:                                     }
 2762:                                 }
 2763:                             }
 2764:                         }
 2765:                     }
 2766:                 }
 2767:             }
 2768:             unless ($gotspares) {
 2769:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
 2770:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 2771:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 2772:                } else {
 2773:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
 2774:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
 2775:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
 2776:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
 2777:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
 2778:                     } else {
 2779:                         my %what = (
 2780:                              spareid => 1,
 2781:                         );
 2782:                         my ($result,$returnhash) = 
 2783:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
 2784:                         if ($result eq 'ok') { 
 2785:                             if (ref($returnhash) eq 'HASH') {
 2786:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
 2787:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
 2788:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
 2789:                                 }
 2790:                             }
 2791:                         }
 2792:                     }
 2793:                 }
 2794:             }
 2795:         }
 2796:     }
 2797:     return %spareid;
 2798: }
 2799: 
 2800: sub spares_row {
 2801:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
 2802:     my $css_class;
 2803:     my $numinrow = 4;
 2804:     my $itemcount = 1;
 2805:     my $datatable;
 2806:     my %typetitles = &sparestype_titles();
 2807:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
 2808:         foreach my $server (sort(keys(%{$servers}))) {
 2809:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
 2810:             my ($othercontrol,$serverdom);
 2811:             if ($serverhome ne $server) {
 2812:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
 2813:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 2814:             } else {
 2815:                 $serverdom = &Apache::lonnet::host_domain($server);
 2816:                 if ($serverdom ne $dom) {
 2817:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
 2818:                 }
 2819:             }
 2820:             next unless (ref($spareid->{$server}) eq 'HASH');
 2821:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2822:             $datatable .= '<tr'.$css_class.'>
 2823:                            <td rowspan="2">
 2824:                             <span class="LC_nobreak">'.
 2825:                           &mt('[_1] when busy, offloads to:'
 2826:                               ,'<b>'.$server.'</b>').
 2827:                           "\n";
 2828:             my (%current,%canselect);
 2829:             my @choices = 
 2830:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
 2831:             foreach my $type ('primary','default') {
 2832:                 if (ref($spareid->{$server}) eq 'HASH') {
 2833:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
 2834:                         my @spares = @{$spareid->{$server}{$type}};
 2835:                         if (@spares > 0) {
 2836:                             if ($othercontrol) {
 2837:                                 $current{$type} = join(', ',@spares);
 2838:                             } else {
 2839:                                 $current{$type} .= '<table>';
 2840:                                 my $numspares = scalar(@spares);
 2841:                                 for (my $i=0;  $i<@spares; $i++) {
 2842:                                     my $rem = $i%($numinrow);
 2843:                                     if ($rem == 0) {
 2844:                                         if ($i > 0) {
 2845:                                             $current{$type} .= '</tr>';
 2846:                                         }
 2847:                                         $current{$type} .= '<tr>';
 2848:                                     }
 2849:                                     $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;'.
 2850:                                                        $spareid->{$server}{$type}[$i].
 2851:                                                        '</label></td>'."\n";
 2852:                                 }
 2853:                                 my $rem = @spares%($numinrow);
 2854:                                 my $colsleft = $numinrow - $rem;
 2855:                                 if ($colsleft > 1 ) {
 2856:                                     $current{$type} .= '<td colspan="'.$colsleft.
 2857:                                                        '" class="LC_left_item">'.
 2858:                                                        '&nbsp;</td>';
 2859:                                 } elsif ($colsleft == 1) {
 2860:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
 2861:                                 }
 2862:                                 $current{$type} .= '</tr></table>';
 2863:                             }
 2864:                         }
 2865:                     }
 2866:                     if ($current{$type} eq '') {
 2867:                         $current{$type} = &mt('None specified');
 2868:                     }
 2869:                     if ($othercontrol) {
 2870:                         if ($type eq 'primary') {
 2871:                             $canselect{$type} = $othercontrol;
 2872:                         }
 2873:                     } else {
 2874:                         $canselect{$type} = 
 2875:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
 2876:                             '<select name="newspare_'.$type.'_'.$server.'" '.
 2877:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
 2878:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
 2879:                         if (@choices > 0) {
 2880:                             foreach my $lonhost (@choices) {
 2881:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
 2882:                             }
 2883:                         }
 2884:                         $canselect{$type} .= '</select>'."\n";
 2885:                     }
 2886:                 } else {
 2887:                     $current{$type} = &mt('Could not be determined');
 2888:                     if ($type eq 'primary') {
 2889:                         $canselect{$type} =  $othercontrol;
 2890:                     }
 2891:                 }
 2892:                 if ($type eq 'default') {
 2893:                     $datatable .= '<tr'.$css_class.'>';
 2894:                 }
 2895:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
 2896:                               '<td>'.$current{$type}.'</td>'."\n".
 2897:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
 2898:             }
 2899:             $itemcount ++;
 2900:         }
 2901:     }
 2902:     $$rowtotal += $itemcount;
 2903:     return $datatable;
 2904: }
 2905: 
 2906: sub possible_newspares {
 2907:     my ($server,$currspares,$serverhomes,$altids) = @_;
 2908:     my $serverhostname = &Apache::lonnet::hostname($server);
 2909:     my %excluded;
 2910:     if ($serverhostname ne '') {
 2911:         %excluded = (
 2912:                        $serverhostname => 1,
 2913:                     );
 2914:     }
 2915:     if (ref($currspares) eq 'HASH') {
 2916:         foreach my $type (keys(%{$currspares})) {
 2917:             if (ref($currspares->{$type}) eq 'ARRAY') {
 2918:                 if (@{$currspares->{$type}} > 0) {
 2919:                     foreach my $curr (@{$currspares->{$type}}) {
 2920:                         my $hostname = &Apache::lonnet::hostname($curr);
 2921:                         $excluded{$hostname} = 1;
 2922:                     }
 2923:                 }
 2924:             }
 2925:         }
 2926:     }
 2927:     my @choices;
 2928:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
 2929:         if (keys(%{$serverhomes}) > 1) {
 2930:             foreach my $name (sort(keys(%{$serverhomes}))) {
 2931:                 unless ($excluded{$name}) {
 2932:                     if (exists($altids->{$serverhomes->{$name}})) {
 2933:                         push(@choices,$altids->{$serverhomes->{$name}});
 2934:                     } else {
 2935:                         push(@choices,$serverhomes->{$name});
 2936:                     }
 2937:                 }
 2938:             }
 2939:         }
 2940:     }
 2941:     return sort(@choices);
 2942: }
 2943: 
 2944: sub print_loadbalancing {
 2945:     my ($dom,$settings,$rowtotal) = @_;
 2946:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
 2947:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
 2948:     my $numinrow = 1;
 2949:     my $datatable;
 2950:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 2951:     my (%currbalancer,%currtargets,%currrules,%existing);
 2952:     if (ref($settings) eq 'HASH') {
 2953:         %existing = %{$settings};
 2954:     }
 2955:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
 2956:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
 2957:                                   \%currtargets,\%currrules);
 2958:     } else {
 2959:         return;
 2960:     }
 2961:     my ($othertitle,$usertypes,$types) =
 2962:         &Apache::loncommon::sorted_inst_types($dom);
 2963:     my $rownum = 6;
 2964:     if (ref($types) eq 'ARRAY') {
 2965:         $rownum += scalar(@{$types});
 2966:     }
 2967:     my @css_class = ('LC_odd_row','LC_even_row');
 2968:     my $balnum = 0;
 2969:     my $islast;
 2970:     my (@toshow,$disabledtext);
 2971:     if (keys(%currbalancer) > 0) {
 2972:         @toshow = sort(keys(%currbalancer));
 2973:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
 2974:             push(@toshow,'');
 2975:         }
 2976:     } else {
 2977:         @toshow = ('');
 2978:         $disabledtext = &mt('No existing load balancer');
 2979:     }
 2980:     foreach my $lonhost (@toshow) {
 2981:         if ($balnum == scalar(@toshow)-1) {
 2982:             $islast = 1;
 2983:         } else {
 2984:             $islast = 0;
 2985:         }
 2986:         my $cssidx = $balnum%2;
 2987:         my $targets_div_style = 'display: none';
 2988:         my $disabled_div_style = 'display: block';
 2989:         my $homedom_div_style = 'display: none';
 2990:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
 2991:                       '<td rowspan="'.$rownum.'" valign="top">'.
 2992:                       '<p>';
 2993:         if ($lonhost eq '') {
 2994:             $datatable .= '<span class="LC_nobreak">';
 2995:             if (keys(%currbalancer) > 0) {
 2996:                 $datatable .= &mt('Add balancer:');
 2997:             } else {
 2998:                 $datatable .= &mt('Enable balancer:');
 2999:             }
 3000:             $datatable .= '&nbsp;'.
 3001:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
 3002:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
 3003:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
 3004:                           '<option value="" selected="selected">'.&mt('None').
 3005:                           '</option>'."\n";
 3006:             foreach my $server (sort(keys(%servers))) {
 3007:                 next if ($currbalancer{$server});
 3008:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
 3009:             }
 3010:             $datatable .=
 3011:                 '</select>'."\n".
 3012:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
 3013:         } else {
 3014:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
 3015:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
 3016:                            &mt('Stop balancing').'</label>'.
 3017:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
 3018:             $targets_div_style = 'display: block';
 3019:             $disabled_div_style = 'display: none';
 3020:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
 3021:                 $homedom_div_style = 'display: block';
 3022:             }
 3023:         }
 3024:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
 3025:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
 3026:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
 3027:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
 3028:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
 3029:         my @sparestypes = ('primary','default');
 3030:         my %typetitles = &sparestype_titles();
 3031:         foreach my $sparetype (@sparestypes) {
 3032:             my $targettable;
 3033:             for (my $i=0; $i<$numspares; $i++) {
 3034:                 my $checked;
 3035:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
 3036:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
 3037:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
 3038:                             $checked = ' checked="checked"';
 3039:                         }
 3040:                     }
 3041:                 }
 3042:                 my ($chkboxval,$disabled);
 3043:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
 3044:                     $chkboxval = $spares[$i];
 3045:                 }
 3046:                 if (exists($currbalancer{$spares[$i]})) {
 3047:                     $disabled = ' disabled="disabled"';
 3048:                 }
 3049:                 $targettable .=
 3050:                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
 3051:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
 3052:                     '</span></label></td>';
 3053:                 my $rem = $i%($numinrow);
 3054:                 if ($rem == 0) {
 3055:                     if (($i > 0) && ($i < $numspares-1)) {
 3056:                         $targettable .= '</tr>';
 3057:                     }
 3058:                     if ($i < $numspares-1) {
 3059:                         $targettable .= '<tr>';
 3060:                     }
 3061:                 }
 3062:             }
 3063:             if ($targettable ne '') {
 3064:                 my $rem = $numspares%($numinrow);
 3065:                 my $colsleft = $numinrow - $rem;
 3066:                 if ($colsleft > 1 ) {
 3067:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3068:                                     '&nbsp;</td>';
 3069:                 } elsif ($colsleft == 1) {
 3070:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
 3071:                 }
 3072:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
 3073:                                '<table><tr>'.$targettable.'</tr></table><br />';
 3074:             }
 3075:         }
 3076:         $datatable .= '</div></td></tr>'.
 3077:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
 3078:                                            $othertitle,$usertypes,$types,\%servers,
 3079:                                            \%currbalancer,$lonhost,
 3080:                                            $targets_div_style,$homedom_div_style,
 3081:                                            $css_class[$cssidx],$balnum,$islast);
 3082:         $$rowtotal += $rownum;
 3083:         $balnum ++;
 3084:     }
 3085:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
 3086:     return $datatable;
 3087: }
 3088: 
 3089: sub get_loadbalancers_config {
 3090:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
 3091:     return unless ((ref($servers) eq 'HASH') &&
 3092:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
 3093:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
 3094:     if (keys(%{$existing}) > 0) {
 3095:         my $oldlonhost;
 3096:         foreach my $key (sort(keys(%{$existing}))) {
 3097:             if ($key eq 'lonhost') {
 3098:                 $oldlonhost = $existing->{'lonhost'};
 3099:                 $currbalancer->{$oldlonhost} = 1;
 3100:             } elsif ($key eq 'targets') {
 3101:                 if ($oldlonhost) {
 3102:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
 3103:                 }
 3104:             } elsif ($key eq 'rules') {
 3105:                 if ($oldlonhost) {
 3106:                     $currrules->{$oldlonhost} = $existing->{'rules'};
 3107:                 }
 3108:             } elsif (ref($existing->{$key}) eq 'HASH') {
 3109:                 $currbalancer->{$key} = 1;
 3110:                 $currtargets->{$key} = $existing->{$key}{'targets'};
 3111:                 $currrules->{$key} = $existing->{$key}{'rules'};
 3112:             }
 3113:         }
 3114:     } else {
 3115:         my ($balancerref,$targetsref) =
 3116:                 &Apache::lonnet::get_lonbalancer_config($servers);
 3117:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
 3118:             foreach my $server (sort(keys(%{$balancerref}))) {
 3119:                 $currbalancer->{$server} = 1;
 3120:                 $currtargets->{$server} = $targetsref->{$server};
 3121:             }
 3122:         }
 3123:     }
 3124:     return;
 3125: }
 3126: 
 3127: sub loadbalancing_rules {
 3128:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
 3129:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
 3130:         $css_class,$balnum,$islast) = @_;
 3131:     my $output;
 3132:     my $num = 0;
 3133:     my ($alltypes,$othertypes,$titles) =
 3134:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
 3135:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
 3136:         foreach my $type (@{$alltypes}) {
 3137:             $num ++;
 3138:             my $current;
 3139:             if (ref($currrules) eq 'HASH') {
 3140:                 $current = $currrules->{$type};
 3141:             }
 3142:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3143:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
 3144:                     $current = '';
 3145:                 }
 3146:             }
 3147:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
 3148:                                              $servers,$currbalancer,$lonhost,$dom,
 3149:                                              $targets_div_style,$homedom_div_style,
 3150:                                              $css_class,$balnum,$num,$islast);
 3151:         }
 3152:     }
 3153:     return $output;
 3154: }
 3155: 
 3156: sub loadbalancing_titles {
 3157:     my ($dom,$intdom,$usertypes,$types) = @_;
 3158:     my %othertypes = (
 3159:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
 3160:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
 3161:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
 3162:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
 3163:                      );
 3164:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
 3165:     if (ref($types) eq 'ARRAY') {
 3166:         unshift(@alltypes,@{$types},'default');
 3167:     }
 3168:     my %titles;
 3169:     foreach my $type (@alltypes) {
 3170:         if ($type =~ /^_LC_/) {
 3171:             $titles{$type} = $othertypes{$type};
 3172:         } elsif ($type eq 'default') {
 3173:             $titles{$type} = &mt('All users from [_1]',$dom);
 3174:             if (ref($types) eq 'ARRAY') {
 3175:                 if (@{$types} > 0) {
 3176:                     $titles{$type} = &mt('Other users from [_1]',$dom);
 3177:                 }
 3178:             }
 3179:         } elsif (ref($usertypes) eq 'HASH') {
 3180:             $titles{$type} = $usertypes->{$type};
 3181:         }
 3182:     }
 3183:     return (\@alltypes,\%othertypes,\%titles);
 3184: }
 3185: 
 3186: sub loadbalance_rule_row {
 3187:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
 3188:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
 3189:     my @rulenames = ('default','homeserver');
 3190:     my %ruletitles = &offloadtype_text();
 3191:     if ($type eq '_LC_external') {
 3192:         push(@rulenames,'externalbalancer');
 3193:     } else {
 3194:         push(@rulenames,'specific');
 3195:     }
 3196:     push(@rulenames,'none');
 3197:     my $style = $targets_div_style;
 3198:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
 3199:         $style = $homedom_div_style;
 3200:     }
 3201:     my $space;
 3202:     if ($islast && $num == 1) {
 3203:         $space = '<div display="inline-block">&nbsp;</div>';
 3204:     }
 3205:     my $output =
 3206:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
 3207:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
 3208:         '<td valaign="top">'.$space.
 3209:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
 3210:     for (my $i=0; $i<@rulenames; $i++) {
 3211:         my $rule = $rulenames[$i];
 3212:         my ($checked,$extra);
 3213:         if ($rulenames[$i] eq 'default') {
 3214:             $rule = '';
 3215:         }
 3216:         if ($rulenames[$i] eq 'specific') {
 3217:             if (ref($servers) eq 'HASH') {
 3218:                 my $default;
 3219:                 if (($current ne '') && (exists($servers->{$current}))) {
 3220:                     $checked = ' checked="checked"';
 3221:                 }
 3222:                 unless ($checked) {
 3223:                     $default = ' selected="selected"';
 3224:                 }
 3225:                 $extra =
 3226:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
 3227:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
 3228:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
 3229:                     '<option value=""'.$default.'></option>'."\n";
 3230:                 foreach my $server (sort(keys(%{$servers}))) {
 3231:                     if (ref($currbalancer) eq 'HASH') {
 3232:                         next if (exists($currbalancer->{$server}));
 3233:                     }
 3234:                     my $selected;
 3235:                     if ($server eq $current) {
 3236:                         $selected = ' selected="selected"';
 3237:                     }
 3238:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
 3239:                 }
 3240:                 $extra .= '</select>';
 3241:             }
 3242:         } elsif ($rule eq $current) {
 3243:             $checked = ' checked="checked"';
 3244:         }
 3245:         $output .= '<span class="LC_nobreak"><label>'.
 3246:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
 3247:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
 3248:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
 3249:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
 3250:                    '</label>'.$extra.'</span><br />'."\n";
 3251:     }
 3252:     $output .= '</div></td></tr>'."\n";
 3253:     return $output;
 3254: }
 3255: 
 3256: sub offloadtype_text {
 3257:     my %ruletitles = &Apache::lonlocal::texthash (
 3258:            'default'          => 'Offloads to default destinations',
 3259:            'homeserver'       => "Offloads to user's home server",
 3260:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
 3261:            'specific'         => 'Offloads to specific server',
 3262:            'none'             => 'No offload',
 3263:     );
 3264:     return %ruletitles;
 3265: }
 3266: 
 3267: sub sparestype_titles {
 3268:     my %typestitles = &Apache::lonlocal::texthash (
 3269:                           'primary' => 'primary',
 3270:                           'default' => 'default',
 3271:                       );
 3272:     return %typestitles;
 3273: }
 3274: 
 3275: sub contact_titles {
 3276:     my %titles = &Apache::lonlocal::texthash (
 3277:                    'supportemail' => 'Support E-mail address',
 3278:                    'adminemail'   => 'Default Server Admin E-mail address',
 3279:                    'errormail'    => 'Error reports to be e-mailed to',
 3280:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 3281:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
 3282:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
 3283:                    'requestsmail' => 'E-mail from course requests requiring approval',
 3284:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
 3285:                  );
 3286:     my %short_titles = &Apache::lonlocal::texthash (
 3287:                            adminemail   => 'Admin E-mail address',
 3288:                            supportemail => 'Support E-mail',
 3289:                        );   
 3290:     return (\%titles,\%short_titles);
 3291: }
 3292: 
 3293: sub tool_titles {
 3294:     my %titles = &Apache::lonlocal::texthash (
 3295:                      aboutme    => 'Personal web page',
 3296:                      blog       => 'Blog',
 3297:                      webdav     => 'WebDAV',
 3298:                      portfolio  => 'Portfolio',
 3299:                      official   => 'Official courses (with institutional codes)',
 3300:                      unofficial => 'Unofficial courses',
 3301:                      community  => 'Communities',
 3302:                  );
 3303:     return %titles;
 3304: }
 3305: 
 3306: sub courserequest_titles {
 3307:     my %titles = &Apache::lonlocal::texthash (
 3308:                                    official   => 'Official',
 3309:                                    unofficial => 'Unofficial',
 3310:                                    community  => 'Communities',
 3311:                                    norequest  => 'Not allowed',
 3312:                                    approval   => 'Approval by Dom. Coord.',
 3313:                                    validate   => 'With validation',
 3314:                                    autolimit  => 'Numerical limit',
 3315:                                    unlimited  => '(blank for unlimited)',
 3316:                  );
 3317:     return %titles;
 3318: }
 3319: 
 3320: sub authorrequest_titles {
 3321:     my %titles = &Apache::lonlocal::texthash (
 3322:                                    norequest  => 'Not allowed',
 3323:                                    approval   => 'Approval by Dom. Coord.',
 3324:                                    automatic  => 'Automatic approval',
 3325:                  );
 3326:     return %titles;
 3327: }
 3328: 
 3329: sub courserequest_conditions {
 3330:     my %conditions = &Apache::lonlocal::texthash (
 3331:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
 3332:        validate   => '(Processing of request subject to institutional validation).',
 3333:                  );
 3334:     return %conditions;
 3335: }
 3336: 
 3337: 
 3338: sub print_usercreation {
 3339:     my ($position,$dom,$settings,$rowtotal) = @_;
 3340:     my $numinrow = 4;
 3341:     my $datatable;
 3342:     if ($position eq 'top') {
 3343:         $$rowtotal ++;
 3344:         my $rowcount = 0;
 3345:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 3346:         if (ref($rules) eq 'HASH') {
 3347:             if (keys(%{$rules}) > 0) {
 3348:                 $datatable .= &user_formats_row('username',$settings,$rules,
 3349:                                                 $ruleorder,$numinrow,$rowcount);
 3350:                 $$rowtotal ++;
 3351:                 $rowcount ++;
 3352:             }
 3353:         }
 3354:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 3355:         if (ref($idrules) eq 'HASH') {
 3356:             if (keys(%{$idrules}) > 0) {
 3357:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 3358:                                                 $idruleorder,$numinrow,$rowcount);
 3359:                 $$rowtotal ++;
 3360:                 $rowcount ++;
 3361:             }
 3362:         }
 3363:         my ($emailrules,$emailruleorder) = 
 3364:             &Apache::lonnet::inst_userrules($dom,'email');
 3365:         if (ref($emailrules) eq 'HASH') {
 3366:             if (keys(%{$emailrules}) > 0) {
 3367:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 3368:                                                 $emailruleorder,$numinrow,$rowcount);
 3369:                 $$rowtotal ++;
 3370:                 $rowcount ++;
 3371:             }
 3372:         }
 3373:         if ($rowcount == 0) {
 3374:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 3375:             $$rowtotal ++;
 3376:             $rowcount ++;
 3377:         }
 3378:     } elsif ($position eq 'middle') {
 3379:         my @creators = ('author','course','requestcrs','selfcreate');
 3380:         my ($rules,$ruleorder) =
 3381:             &Apache::lonnet::inst_userrules($dom,'username');
 3382:         my %lt = &usercreation_types();
 3383:         my %checked;
 3384:         my @selfcreate; 
 3385:         if (ref($settings) eq 'HASH') {
 3386:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 3387:                 foreach my $item (@creators) {
 3388:                     $checked{$item} = $settings->{'cancreate'}{$item};
 3389:                 }
 3390:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
 3391:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
 3392:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
 3393:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 3394:                         @selfcreate = ('email','login','sso');
 3395:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
 3396:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
 3397:                     }
 3398:                 }
 3399:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 3400:                 foreach my $item (@creators) {
 3401:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 3402:                         $checked{$item} = 'none';
 3403:                     }
 3404:                 }
 3405:             }
 3406:         }
 3407:         my $rownum = 0;
 3408:         foreach my $item (@creators) {
 3409:             $rownum ++;
 3410:             if ($item ne 'selfcreate') {  
 3411:                 if ($checked{$item} eq '') {
 3412:                     $checked{$item} = 'any';
 3413:                 }
 3414:             }
 3415:             my $css_class;
 3416:             if ($rownum%2) {
 3417:                 $css_class = '';
 3418:             } else {
 3419:                 $css_class = ' class="LC_odd_row" ';
 3420:             }
 3421:             $datatable .= '<tr'.$css_class.'>'.
 3422:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 3423:                          '</span></td><td align="right">';
 3424:             my @options;
 3425:             if ($item eq 'selfcreate') {
 3426:                 push(@options,('email','login','sso'));
 3427:             } else {
 3428:                 @options = ('any');
 3429:                 if (ref($rules) eq 'HASH') {
 3430:                     if (keys(%{$rules}) > 0) {
 3431:                         push(@options,('official','unofficial'));
 3432:                     }
 3433:                 }
 3434:                 push(@options,'none');
 3435:             }
 3436:             foreach my $option (@options) {
 3437:                 my $type = 'radio';
 3438:                 my $check = ' ';
 3439:                 if ($item eq 'selfcreate') {
 3440:                     $type = 'checkbox';
 3441:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
 3442:                         $check = ' checked="checked" ';
 3443:                     }
 3444:                 } else {
 3445:                     if ($checked{$item} eq $option) {
 3446:                         $check = ' checked="checked" ';
 3447:                     }
 3448:                 } 
 3449:                 $datatable .= '<span class="LC_nobreak"><label>'.
 3450:                               '<input type="'.$type.'" name="can_createuser_'.
 3451:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 3452:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 3453:             }
 3454:             $datatable .= '</td></tr>';
 3455:         }
 3456:         my ($othertitle,$usertypes,$types) =
 3457:             &Apache::loncommon::sorted_inst_types($dom);
 3458:         my $createsettings;
 3459:         if (ref($settings) eq 'HASH') {
 3460:             $createsettings = $settings->{cancreate};
 3461:         }
 3462:         if (ref($usertypes) eq 'HASH') {
 3463:             if (keys(%{$usertypes}) > 0) {
 3464:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
 3465:                                              $dom,$numinrow,$othertitle,
 3466:                                              'statustocreate');
 3467:                 $$rowtotal ++;
 3468:                 $rownum ++;
 3469:             }
 3470:         }
 3471:         $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
 3472:     } else {
 3473:         my @contexts = ('author','course','domain');
 3474:         my @authtypes = ('int','krb4','krb5','loc');
 3475:         my %checked;
 3476:         if (ref($settings) eq 'HASH') {
 3477:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 3478:                 foreach my $item (@contexts) {
 3479:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 3480:                         foreach my $auth (@authtypes) {
 3481:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 3482:                                 $checked{$item}{$auth} = ' checked="checked" ';
 3483:                             }
 3484:                         }
 3485:                     }
 3486:                 }
 3487:             }
 3488:         } else {
 3489:             foreach my $item (@contexts) {
 3490:                 foreach my $auth (@authtypes) {
 3491:                     $checked{$item}{$auth} = ' checked="checked" ';
 3492:                 }
 3493:             }
 3494:         }
 3495:         my %title = &context_names();
 3496:         my %authname = &authtype_names();
 3497:         my $rownum = 0;
 3498:         my $css_class; 
 3499:         foreach my $item (@contexts) {
 3500:             if ($rownum%2) {
 3501:                 $css_class = '';
 3502:             } else {
 3503:                 $css_class = ' class="LC_odd_row" ';
 3504:             }
 3505:             $datatable .=   '<tr'.$css_class.'>'.
 3506:                             '<td>'.$title{$item}.
 3507:                             '</td><td class="LC_left_item">'.
 3508:                             '<span class="LC_nobreak">';
 3509:             foreach my $auth (@authtypes) {
 3510:                 $datatable .= '<label>'. 
 3511:                               '<input type="checkbox" name="'.$item.'_auth" '.
 3512:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 3513:                               $authname{$auth}.'</label>&nbsp;';
 3514:             }
 3515:             $datatable .= '</span></td></tr>';
 3516:             $rownum ++;
 3517:         }
 3518:         $$rowtotal += $rownum;
 3519:     }
 3520:     return $datatable;
 3521: }
 3522: 
 3523: sub captcha_choice {
 3524:     my ($context,$settings,$itemcount) = @_;
 3525:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
 3526:     my %lt = &captcha_phrases();
 3527:     $keyentry = 'hidden';
 3528:     if ($context eq 'cancreate') {
 3529:         $rowname = &mt('CAPTCHA validation (e-mail as username)');
 3530:     } elsif ($context eq 'login') {
 3531:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
 3532:     }
 3533:     if (ref($settings) eq 'HASH') {
 3534:         if ($settings->{'captcha'}) {
 3535:             $checked{$settings->{'captcha'}} = ' checked="checked"';
 3536:         } else {
 3537:             $checked{'original'} = ' checked="checked"';
 3538:         }
 3539:         if ($settings->{'captcha'} eq 'recaptcha') {
 3540:             $pubtext = $lt{'pub'};
 3541:             $privtext = $lt{'priv'};
 3542:             $keyentry = 'text';
 3543:         }
 3544:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
 3545:             $currpub = $settings->{'recaptchakeys'}{'public'};
 3546:             $currpriv = $settings->{'recaptchakeys'}{'private'};
 3547:         }
 3548:     } else {
 3549:         $checked{'original'} = ' checked="checked"';
 3550:     }
 3551:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3552:     my $output = '<tr'.$css_class.'>'.
 3553:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
 3554:                  '<table><tr><td>'."\n";
 3555:     foreach my $option ('original','recaptcha','notused') {
 3556:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
 3557:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
 3558:                    $lt{$option}.'</label></span>';
 3559:         unless ($option eq 'notused') {
 3560:             $output .= ('&nbsp;'x2)."\n";
 3561:         }
 3562:     }
 3563: #
 3564: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
 3565: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
 3566: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
 3567: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
 3568: #
 3569:     $output .= '</td></tr>'."\n".
 3570:                '<tr><td>'."\n".
 3571:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
 3572:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
 3573:                $currpub.'" size="40" /></span><br />'."\n".
 3574:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
 3575:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
 3576:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
 3577:                '</td></tr>';
 3578:     return $output;
 3579: }
 3580: 
 3581: sub user_formats_row {
 3582:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 3583:     my $output;
 3584:     my %text = (
 3585:                    'username' => 'new usernames',
 3586:                    'id'       => 'IDs',
 3587:                    'email'    => 'self-created accounts (e-mail)',
 3588:                );
 3589:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 3590:     $output = '<tr '.$css_class.'>'.
 3591:               '<td><span class="LC_nobreak">';
 3592:     if ($type eq 'email') {
 3593:         $output .= &mt("Formats disallowed for $text{$type}: ");
 3594:     } else {
 3595:         $output .= &mt("Format rules to check for $text{$type}: ");
 3596:     }
 3597:     $output .= '</span></td>'.
 3598:                '<td class="LC_left_item" colspan="2"><table>';
 3599:     my $rem;
 3600:     if (ref($ruleorder) eq 'ARRAY') {
 3601:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 3602:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 3603:                 my $rem = $i%($numinrow);
 3604:                 if ($rem == 0) {
 3605:                     if ($i > 0) {
 3606:                         $output .= '</tr>';
 3607:                     }
 3608:                     $output .= '<tr>';
 3609:                 }
 3610:                 my $check = ' ';
 3611:                 if (ref($settings) eq 'HASH') {
 3612:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 3613:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 3614:                             $check = ' checked="checked" ';
 3615:                         }
 3616:                     }
 3617:                 }
 3618:                 $output .= '<td class="LC_left_item">'.
 3619:                            '<span class="LC_nobreak"><label>'.
 3620:                            '<input type="checkbox" name="'.$type.'_rule" '.
 3621:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 3622:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 3623:             }
 3624:         }
 3625:         $rem = @{$ruleorder}%($numinrow);
 3626:     }
 3627:     my $colsleft = $numinrow - $rem;
 3628:     if ($colsleft > 1 ) {
 3629:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3630:                    '&nbsp;</td>';
 3631:     } elsif ($colsleft == 1) {
 3632:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 3633:     }
 3634:     $output .= '</tr></table></td></tr>';
 3635:     return $output;
 3636: }
 3637: 
 3638: sub usercreation_types {
 3639:     my %lt = &Apache::lonlocal::texthash (
 3640:                     author     => 'When adding a co-author',
 3641:                     course     => 'When adding a user to a course',
 3642:                     requestcrs => 'When requesting a course',
 3643:                     selfcreate => 'User creates own account', 
 3644:                     any        => 'Any',
 3645:                     official   => 'Institutional only ',
 3646:                     unofficial => 'Non-institutional only',
 3647:                     email      => 'E-mail address',
 3648:                     login      => 'Institutional Login',
 3649:                     sso        => 'SSO', 
 3650:                     none       => 'None',
 3651:     );
 3652:     return %lt;
 3653: }
 3654: 
 3655: sub authtype_names {
 3656:     my %lt = &Apache::lonlocal::texthash(
 3657:                       int    => 'Internal',
 3658:                       krb4   => 'Kerberos 4',
 3659:                       krb5   => 'Kerberos 5',
 3660:                       loc    => 'Local',
 3661:                   );
 3662:     return %lt;
 3663: }
 3664: 
 3665: sub context_names {
 3666:     my %context_title = &Apache::lonlocal::texthash(
 3667:        author => 'Creating users when an Author',
 3668:        course => 'Creating users when in a course',
 3669:        domain => 'Creating users when a Domain Coordinator',
 3670:     );
 3671:     return %context_title;
 3672: }
 3673: 
 3674: sub print_usermodification {
 3675:     my ($position,$dom,$settings,$rowtotal) = @_;
 3676:     my $numinrow = 4;
 3677:     my ($context,$datatable,$rowcount);
 3678:     if ($position eq 'top') {
 3679:         $rowcount = 0;
 3680:         $context = 'author'; 
 3681:         foreach my $role ('ca','aa') {
 3682:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 3683:                                                    $numinrow,$rowcount);
 3684:             $$rowtotal ++;
 3685:             $rowcount ++;
 3686:         }
 3687:     } elsif ($position eq 'middle') {
 3688:         $context = 'course';
 3689:         $rowcount = 0;
 3690:         foreach my $role ('st','ep','ta','in','cr') {
 3691:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 3692:                                                    $numinrow,$rowcount);
 3693:             $$rowtotal ++;
 3694:             $rowcount ++;
 3695:         }
 3696:     } elsif ($position eq 'bottom') {
 3697:         $context = 'selfcreate';
 3698:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3699:         $usertypes->{'default'} = $othertitle;
 3700:         if (ref($types) eq 'ARRAY') {
 3701:             push(@{$types},'default');
 3702:             $usertypes->{'default'} = $othertitle;
 3703:             foreach my $status (@{$types}) {
 3704:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
 3705:                                                        $numinrow,$rowcount,$usertypes);
 3706:                 $$rowtotal ++;
 3707:                 $rowcount ++;
 3708:             }
 3709:         }
 3710:     }
 3711:     return $datatable;
 3712: }
 3713: 
 3714: sub print_defaults {
 3715:     my ($dom,$rowtotal) = @_;
 3716:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 3717:                  'datelocale_def','portal_def');
 3718:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 3719:     my $titles = &defaults_titles($dom);
 3720:     my $rownum = 0;
 3721:     my ($datatable,$css_class);
 3722:     foreach my $item (@items) {
 3723:         if ($rownum%2) {
 3724:             $css_class = '';
 3725:         } else {
 3726:             $css_class = ' class="LC_odd_row" ';
 3727:         }
 3728:         $datatable .= '<tr'.$css_class.'>'.
 3729:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 3730:                   '</span></td><td class="LC_right_item">';
 3731:         if ($item eq 'auth_def') {
 3732:             my @authtypes = ('internal','krb4','krb5','localauth');
 3733:             my %shortauth = (
 3734:                              internal => 'int',
 3735:                              krb4 => 'krb4',
 3736:                              krb5 => 'krb5',
 3737:                              localauth  => 'loc'
 3738:                            );
 3739:             my %authnames = &authtype_names();
 3740:             foreach my $auth (@authtypes) {
 3741:                 my $checked = ' ';
 3742:                 if ($domdefaults{$item} eq $auth) {
 3743:                     $checked = ' checked="checked" ';
 3744:                 }
 3745:                 $datatable .= '<label><input type="radio" name="'.$item.
 3746:                               '" value="'.$auth.'"'.$checked.'/>'.
 3747:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 3748:             }
 3749:         } elsif ($item eq 'timezone_def') {
 3750:             my $includeempty = 1;
 3751:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
 3752:         } elsif ($item eq 'datelocale_def') {
 3753:             my $includeempty = 1;
 3754:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
 3755:         } elsif ($item eq 'lang_def') {
 3756:             my %langchoices = &get_languages_hash();
 3757:             $langchoices{''} = 'No language preference';
 3758:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
 3759:             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
 3760:                                                           \%langchoices);
 3761:         } else {
 3762:             my $size;
 3763:             if ($item eq 'portal_def') {
 3764:                 $size = ' size="25"';
 3765:             }
 3766:             $datatable .= '<input type="text" name="'.$item.'" value="'.
 3767:                           $domdefaults{$item}.'"'.$size.' />';
 3768:         }
 3769:         $datatable .= '</td></tr>';
 3770:         $rownum ++;
 3771:     }
 3772:     $$rowtotal += $rownum;
 3773:     return $datatable;
 3774: }
 3775: 
 3776: sub get_languages_hash {
 3777:     my %langchoices;
 3778:     foreach my $id (&Apache::loncommon::languageids()) {
 3779:         my $code = &Apache::loncommon::supportedlanguagecode($id);
 3780:         if ($code ne '') {
 3781:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
 3782:         }
 3783:     }
 3784:     return %langchoices;
 3785: }
 3786: 
 3787: sub defaults_titles {
 3788:     my ($dom) = @_;
 3789:     my %titles = &Apache::lonlocal::texthash (
 3790:                    'auth_def'      => 'Default authentication type',
 3791:                    'auth_arg_def'  => 'Default authentication argument',
 3792:                    'lang_def'      => 'Default language',
 3793:                    'timezone_def'  => 'Default timezone',
 3794:                    'datelocale_def' => 'Default locale for dates',
 3795:                    'portal_def'     => 'Portal/Default URL',
 3796:                  );
 3797:     if ($dom) {
 3798:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
 3799:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
 3800:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
 3801:         $protocol = 'http' if ($protocol ne 'https');
 3802:         if ($uint_dom) {
 3803:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
 3804:                                          $uint_dom);
 3805:         }
 3806:     }
 3807:     return (\%titles);
 3808: }
 3809: 
 3810: sub print_scantronformat {
 3811:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 3812:     my $itemcount = 1;
 3813:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 3814:         %confhash);
 3815:     my $switchserver = &check_switchserver($dom,$confname);
 3816:     my %lt = &Apache::lonlocal::texthash (
 3817:                 default => 'Default bubblesheet format file error',
 3818:                 custom  => 'Custom bubblesheet format file error',
 3819:              );
 3820:     my %scantronfiles = (
 3821:         default => 'default.tab',
 3822:         custom => 'custom.tab',
 3823:     );
 3824:     foreach my $key (keys(%scantronfiles)) {
 3825:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 3826:                               .$scantronfiles{$key};
 3827:     }
 3828:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 3829:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 3830:         if (!$switchserver) {
 3831:             my $servadm = $r->dir_config('lonAdmEMail');
 3832:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 3833:             if ($configuserok eq 'ok') {
 3834:                 if ($author_ok eq 'ok') {
 3835:                     my %legacyfile = (
 3836:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 3837:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 3838:                     );
 3839:                     my %md5chk;
 3840:                     foreach my $type (keys(%legacyfile)) {
 3841:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 3842:                         chomp($md5chk{$type});
 3843:                     }
 3844:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 3845:                         foreach my $type (keys(%legacyfile)) {
 3846:                             ($scantronurls{$type},my $error) = 
 3847:                                 &legacy_scantronformat($r,$dom,$confname,
 3848:                                                  $type,$legacyfile{$type},
 3849:                                                  $scantronurls{$type},
 3850:                                                  $scantronfiles{$type});
 3851:                             if ($error ne '') {
 3852:                                 $error{$type} = $error;
 3853:                             }
 3854:                         }
 3855:                         if (keys(%error) == 0) {
 3856:                             $is_custom = 1;
 3857:                             $confhash{'scantron'}{'scantronformat'} = 
 3858:                                 $scantronurls{'custom'};
 3859:                             my $putresult = 
 3860:                                 &Apache::lonnet::put_dom('configuration',
 3861:                                                          \%confhash,$dom);
 3862:                             if ($putresult ne 'ok') {
 3863:                                 $error{'custom'} = 
 3864:                                     '<span class="LC_error">'.
 3865:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 3866:                             }
 3867:                         }
 3868:                     } else {
 3869:                         ($scantronurls{'default'},my $error) =
 3870:                             &legacy_scantronformat($r,$dom,$confname,
 3871:                                           'default',$legacyfile{'default'},
 3872:                                           $scantronurls{'default'},
 3873:                                           $scantronfiles{'default'});
 3874:                         if ($error eq '') {
 3875:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 3876:                             my $putresult =
 3877:                                 &Apache::lonnet::put_dom('configuration',
 3878:                                                          \%confhash,$dom);
 3879:                             if ($putresult ne 'ok') {
 3880:                                 $error{'default'} =
 3881:                                     '<span class="LC_error">'.
 3882:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 3883:                             }
 3884:                         } else {
 3885:                             $error{'default'} = $error;
 3886:                         }
 3887:                     }
 3888:                 }
 3889:             }
 3890:         } else {
 3891:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
 3892:         }
 3893:     }
 3894:     if (ref($settings) eq 'HASH') {
 3895:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 3896:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 3897:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 3898:                 $scantronurl = '';
 3899:             } else {
 3900:                 $scantronurl = $settings->{'scantronformat'};
 3901:             }
 3902:             $is_custom = 1;
 3903:         } else {
 3904:             $scantronurl = $scantronurls{'default'};
 3905:         }
 3906:     } else {
 3907:         if ($is_custom) {
 3908:             $scantronurl = $scantronurls{'custom'};
 3909:         } else {
 3910:             $scantronurl = $scantronurls{'default'};
 3911:         }
 3912:     }
 3913:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3914:     $datatable .= '<tr'.$css_class.'>';
 3915:     if (!$is_custom) {
 3916:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 3917:                       '<span class="LC_nobreak">';
 3918:         if ($scantronurl) {
 3919:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
 3920:                                                          undef,undef,undef,undef,'background-color:#ffffff');
 3921:         } else {
 3922:             $datatable = &mt('File unavailable for display');
 3923:         }
 3924:         $datatable .= '</span></td>';
 3925:         if (keys(%error) == 0) { 
 3926:             $datatable .= '<td valign="bottom">';
 3927:             if (!$switchserver) {
 3928:                 $datatable .= &mt('Upload:').'<br />';
 3929:             }
 3930:         } else {
 3931:             my $errorstr;
 3932:             foreach my $key (sort(keys(%error))) {
 3933:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 3934:             }
 3935:             $datatable .= '<td>'.$errorstr;
 3936:         }
 3937:     } else {
 3938:         if (keys(%error) > 0) {
 3939:             my $errorstr;
 3940:             foreach my $key (sort(keys(%error))) {
 3941:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 3942:             } 
 3943:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 3944:         } elsif ($scantronurl) {
 3945:            my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
 3946:                                                        undef,undef,undef,undef,'background-color:#ffffff');
 3947:             $datatable .= '<td><span class="LC_nobreak">'.
 3948:                           $link.
 3949:                           '<label><input type="checkbox" name="scantronformat_del"'.
 3950:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
 3951:                           '<td><span class="LC_nobreak">&nbsp;'.
 3952:                           &mt('Replace:').'</span><br />';
 3953:         }
 3954:     }
 3955:     if (keys(%error) == 0) {
 3956:         if ($switchserver) {
 3957:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 3958:         } else {
 3959:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 3960:                          '<input type="file" name="scantronformat" /></span>';
 3961:         }
 3962:     }
 3963:     $datatable .= '</td></tr>';
 3964:     $$rowtotal ++;
 3965:     return $datatable;
 3966: }
 3967: 
 3968: sub legacy_scantronformat {
 3969:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 3970:     my ($url,$error);
 3971:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 3972:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 3973:         (my $result,$url) =
 3974:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 3975:                          '','',$newfile);
 3976:         if ($result ne 'ok') {
 3977:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
 3978:         }
 3979:     }
 3980:     return ($url,$error);
 3981: }
 3982: 
 3983: sub print_coursecategories {
 3984:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 3985:     my $datatable;
 3986:     if ($position eq 'top') {
 3987:         my $toggle_cats_crs = ' ';
 3988:         my $toggle_cats_dom = ' checked="checked" ';
 3989:         my $can_cat_crs = ' ';
 3990:         my $can_cat_dom = ' checked="checked" ';
 3991:         my $toggle_catscomm_comm = ' ';
 3992:         my $toggle_catscomm_dom = ' checked="checked" ';
 3993:         my $can_catcomm_comm = ' ';
 3994:         my $can_catcomm_dom = ' checked="checked" ';
 3995: 
 3996:         if (ref($settings) eq 'HASH') {
 3997:             if ($settings->{'togglecats'} eq 'crs') {
 3998:                 $toggle_cats_crs = $toggle_cats_dom;
 3999:                 $toggle_cats_dom = ' ';
 4000:             }
 4001:             if ($settings->{'categorize'} eq 'crs') {
 4002:                 $can_cat_crs = $can_cat_dom;
 4003:                 $can_cat_dom = ' ';
 4004:             }
 4005:             if ($settings->{'togglecatscomm'} eq 'comm') {
 4006:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
 4007:                 $toggle_catscomm_dom = ' ';
 4008:             }
 4009:             if ($settings->{'categorizecomm'} eq 'comm') {
 4010:                 $can_catcomm_comm = $can_catcomm_dom;
 4011:                 $can_catcomm_dom = ' ';
 4012:             }
 4013:         }
 4014:         my %title = &Apache::lonlocal::texthash (
 4015:                      togglecats     => 'Show/Hide a course in catalog',
 4016:                      togglecatscomm => 'Show/Hide a community in catalog',
 4017:                      categorize     => 'Assign a category to a course',
 4018:                      categorizecomm => 'Assign a category to a community',
 4019:                     );
 4020:         my %level = &Apache::lonlocal::texthash (
 4021:                      dom  => 'Set in Domain',
 4022:                      crs  => 'Set in Course',
 4023:                      comm => 'Set in Community',
 4024:                     );
 4025:         $datatable = '<tr class="LC_odd_row">'.
 4026:                   '<td>'.$title{'togglecats'}.'</td>'.
 4027:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 4028:                   '<input type="radio" name="togglecats"'.
 4029:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4030:                   '<label><input type="radio" name="togglecats"'.
 4031:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 4032:                   '</tr><tr>'.
 4033:                   '<td>'.$title{'categorize'}.'</td>'.
 4034:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 4035:                   '<label><input type="radio" name="categorize"'.
 4036:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4037:                   '<label><input type="radio" name="categorize"'.
 4038:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 4039:                   '</tr><tr class="LC_odd_row">'.
 4040:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
 4041:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 4042:                   '<input type="radio" name="togglecatscomm"'.
 4043:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4044:                   '<label><input type="radio" name="togglecatscomm"'.
 4045:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
 4046:                   '</tr><tr>'.
 4047:                   '<td>'.$title{'categorizecomm'}.'</td>'.
 4048:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 4049:                   '<label><input type="radio" name="categorizecomm"'.
 4050:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 4051:                   '<label><input type="radio" name="categorizecomm"'.
 4052:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
 4053:                   '</tr>';
 4054:         $$rowtotal += 4;
 4055:     } else {
 4056:         my $css_class;
 4057:         my $itemcount = 1;
 4058:         my $cathash; 
 4059:         if (ref($settings) eq 'HASH') {
 4060:             $cathash = $settings->{'cats'};
 4061:         }
 4062:         if (ref($cathash) eq 'HASH') {
 4063:             my (@cats,@trails,%allitems,%idx,@jsarray);
 4064:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 4065:                                                    \%allitems,\%idx,\@jsarray);
 4066:             my $maxdepth = scalar(@cats);
 4067:             my $colattrib = '';
 4068:             if ($maxdepth > 2) {
 4069:                 $colattrib = ' colspan="2" ';
 4070:             }
 4071:             my @path;
 4072:             if (@cats > 0) {
 4073:                 if (ref($cats[0]) eq 'ARRAY') {
 4074:                     my $numtop = @{$cats[0]};
 4075:                     my $maxnum = $numtop;
 4076:                     my %default_names = (
 4077:                           instcode    => &mt('Official courses'),
 4078:                           communities => &mt('Communities'),
 4079:                     );
 4080: 
 4081:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
 4082:                         ($cathash->{'instcode::0'} eq '') ||
 4083:                         (!grep(/^communities$/,@{$cats[0]})) || 
 4084:                         ($cathash->{'communities::0'} eq '')) {
 4085:                         $maxnum ++;
 4086:                     }
 4087:                     my $lastidx;
 4088:                     for (my $i=0; $i<$numtop; $i++) {
 4089:                         my $parent = $cats[0][$i];
 4090:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4091:                         my $item = &escape($parent).'::0';
 4092:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 4093:                         $lastidx = $idx{$item};
 4094:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4095:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 4096:                         for (my $k=0; $k<=$maxnum; $k++) {
 4097:                             my $vpos = $k+1;
 4098:                             my $selstr;
 4099:                             if ($k == $i) {
 4100:                                 $selstr = ' selected="selected" ';
 4101:                             }
 4102:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4103:                         }
 4104:                         $datatable .= '</select></td><td>';
 4105:                         if ($parent eq 'instcode' || $parent eq 'communities') {
 4106:                             $datatable .=  '<span class="LC_nobreak">'
 4107:                                            .$default_names{$parent}.'</span>';
 4108:                             if ($parent eq 'instcode') {
 4109:                                 $datatable .= '<br /><span class="LC_nobreak">('
 4110:                                               .&mt('with institutional codes')
 4111:                                               .')</span></td><td'.$colattrib.'>';
 4112:                             } else {
 4113:                                 $datatable .= '<table><tr><td>';
 4114:                             }
 4115:                             $datatable .= '<span class="LC_nobreak">'
 4116:                                           .'<label><input type="radio" name="'
 4117:                                           .$parent.'" value="1" checked="checked" />'
 4118:                                           .&mt('Display').'</label>';
 4119:                             if ($parent eq 'instcode') {
 4120:                                 $datatable .= '&nbsp;';
 4121:                             } else {
 4122:                                 $datatable .= '</span></td></tr><tr><td>'
 4123:                                               .'<span class="LC_nobreak">';
 4124:                             }
 4125:                             $datatable .= '<label><input type="radio" name="'
 4126:                                           .$parent.'" value="0" />'
 4127:                                           .&mt('Do not display').'</label></span>';
 4128:                             if ($parent eq 'communities') {
 4129:                                 $datatable .= '</td></tr></table>';
 4130:                             }
 4131:                             $datatable .= '</td>';
 4132:                         } else {
 4133:                             $datatable .= $parent
 4134:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
 4135:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 4136:                         }
 4137:                         my $depth = 1;
 4138:                         push(@path,$parent);
 4139:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 4140:                         pop(@path);
 4141:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 4142:                         $itemcount ++;
 4143:                     }
 4144:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4145:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 4146:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 4147:                     for (my $k=0; $k<=$maxnum; $k++) {
 4148:                         my $vpos = $k+1;
 4149:                         my $selstr;
 4150:                         if ($k == $numtop) {
 4151:                             $selstr = ' selected="selected" ';
 4152:                         }
 4153:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4154:                     }
 4155:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 4156:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 4157:                                   .'</tr>'."\n";
 4158:                     $itemcount ++;
 4159:                     foreach my $default ('instcode','communities') {
 4160:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
 4161:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4162:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
 4163:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 4164:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
 4165:                             for (my $k=0; $k<=$maxnum; $k++) {
 4166:                                 my $vpos = $k+1;
 4167:                                 my $selstr;
 4168:                                 if ($k == $maxnum) {
 4169:                                     $selstr = ' selected="selected" ';
 4170:                                 }
 4171:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 4172:                             }
 4173:                             $datatable .= '</select></span></td>'.
 4174:                                           '<td><span class="LC_nobreak">'.
 4175:                                           $default_names{$default}.'</span>';
 4176:                             if ($default eq 'instcode') {
 4177:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
 4178:                                               .&mt('with institutional codes').')</span>';
 4179:                             }
 4180:                             $datatable .= '</td>'
 4181:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
 4182:                                           .&mt('Display').'</label>&nbsp;'
 4183:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
 4184:                                           .&mt('Do not display').'</label></span></td></tr>';
 4185:                         }
 4186:                     }
 4187:                 }
 4188:             } else {
 4189:                 $datatable .= &initialize_categories($itemcount);
 4190:             }
 4191:         } else {
 4192:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
 4193:                           .&initialize_categories($itemcount);
 4194:         }
 4195:         $$rowtotal += $itemcount;
 4196:     }
 4197:     return $datatable;
 4198: }
 4199: 
 4200: sub print_serverstatuses {
 4201:     my ($dom,$settings,$rowtotal) = @_;
 4202:     my $datatable;
 4203:     my @pages = &serverstatus_pages();
 4204:     my (%namedaccess,%machineaccess);
 4205:     foreach my $type (@pages) {
 4206:         $namedaccess{$type} = '';
 4207:         $machineaccess{$type}= '';
 4208:     }
 4209:     if (ref($settings) eq 'HASH') {
 4210:         foreach my $type (@pages) {
 4211:             if (exists($settings->{$type})) {
 4212:                 if (ref($settings->{$type}) eq 'HASH') {
 4213:                     foreach my $key (keys(%{$settings->{$type}})) {
 4214:                         if ($key eq 'namedusers') {
 4215:                             $namedaccess{$type} = $settings->{$type}->{$key};
 4216:                         } elsif ($key eq 'machines') {
 4217:                             $machineaccess{$type} = $settings->{$type}->{$key};
 4218:                         }
 4219:                     }
 4220:                 }
 4221:             }
 4222:         }
 4223:     }
 4224:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 4225:     my $rownum = 0;
 4226:     my $css_class;
 4227:     foreach my $type (@pages) {
 4228:         $rownum ++;
 4229:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 4230:         $datatable .= '<tr'.$css_class.'>'.
 4231:                       '<td><span class="LC_nobreak">'.
 4232:                       $titles->{$type}.'</span></td>'.
 4233:                       '<td class="LC_left_item">'.
 4234:                       '<input type="text" name="'.$type.'_namedusers" '.
 4235:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 4236:                       '<td class="LC_right_item">'.
 4237:                       '<span class="LC_nobreak">'.
 4238:                       '<input type="text" name="'.$type.'_machines" '.
 4239:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 4240:                       '</td></tr>'."\n";
 4241:     }
 4242:     $$rowtotal += $rownum;
 4243:     return $datatable;
 4244: }
 4245: 
 4246: sub serverstatus_pages {
 4247:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 4248:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
 4249:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
 4250: }
 4251: 
 4252: sub coursecategories_javascript {
 4253:     my ($settings) = @_;
 4254:     my ($output,$jstext,$cathash);
 4255:     if (ref($settings) eq 'HASH') {
 4256:         $cathash = $settings->{'cats'};
 4257:     }
 4258:     if (ref($cathash) eq 'HASH') {
 4259:         my (@cats,@jsarray,%idx);
 4260:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 4261:         if (@jsarray > 0) {
 4262:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 4263:             for (my $i=0; $i<@jsarray; $i++) {
 4264:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 4265:                     my $catstr = join('","',@{$jsarray[$i]});
 4266:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 4267:                 }
 4268:             }
 4269:         }
 4270:     } else {
 4271:         $jstext  = '    var categories = Array(1);'."\n".
 4272:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 4273:     }
 4274:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
 4275:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
 4276:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
 4277:     $output = <<"ENDSCRIPT";
 4278: <script type="text/javascript">
 4279: // <![CDATA[
 4280: function reorderCats(form,parent,item,idx) {
 4281:     var changedVal;
 4282: $jstext
 4283:     var newpos = 'addcategory_pos';
 4284:     var current = new Array;
 4285:     if (parent == '') {
 4286:         var has_instcode = 0;
 4287:         var maxtop = categories[idx].length;
 4288:         for (var j=0; j<maxtop; j++) {
 4289:             if (categories[idx][j] == 'instcode::0') {
 4290:                 has_instcode == 1;
 4291:             }
 4292:         }
 4293:         if (has_instcode == 0) {
 4294:             categories[idx][maxtop] = 'instcode_pos';
 4295:         }
 4296:     } else {
 4297:         newpos += '_'+parent;
 4298:     }
 4299:     var maxh = 1 + categories[idx].length;
 4300:     var current = new Array;
 4301:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 4302:     if (item == newpos) {
 4303:         changedVal = newitemVal;
 4304:     } else {
 4305:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 4306:         current[newitemVal] = newpos;
 4307:     }
 4308:     for (var i=0; i<categories[idx].length; i++) {
 4309:         var elementName = categories[idx][i];
 4310:         if (elementName != item) {
 4311:             if (form.elements[elementName]) {
 4312:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 4313:                 current[currVal] = elementName;
 4314:             }
 4315:         }
 4316:     }
 4317:     var oldVal;
 4318:     for (var j=0; j<maxh; j++) {
 4319:         if (current[j] == undefined) {
 4320:             oldVal = j;
 4321:         }
 4322:     }
 4323:     if (oldVal < changedVal) {
 4324:         for (var k=oldVal+1; k<=changedVal ; k++) {
 4325:            var elementName = current[k];
 4326:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 4327:         }
 4328:     } else {
 4329:         for (var k=changedVal; k<oldVal; k++) {
 4330:             var elementName = current[k];
 4331:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 4332:         }
 4333:     }
 4334:     return;
 4335: }
 4336: 
 4337: function categoryCheck(form) {
 4338:     if (form.elements['addcategory_name'].value == 'instcode') {
 4339:         alert('$instcode_reserved\\n$choose_again');
 4340:         return false;
 4341:     }
 4342:     if (form.elements['addcategory_name'].value == 'communities') {
 4343:         alert('$communities_reserved\\n$choose_again');
 4344:         return false;
 4345:     }
 4346:     return true;
 4347: }
 4348: 
 4349: // ]]>
 4350: </script>
 4351: 
 4352: ENDSCRIPT
 4353:     return $output;
 4354: }
 4355: 
 4356: sub initialize_categories {
 4357:     my ($itemcount) = @_;
 4358:     my ($datatable,$css_class,$chgstr);
 4359:     my %default_names = (
 4360:                       instcode    => 'Official courses (with institutional codes)',
 4361:                       communities => 'Communities',
 4362:                         );
 4363:     my $select0 = ' selected="selected"';
 4364:     my $select1 = '';
 4365:     foreach my $default ('instcode','communities') {
 4366:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4367:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
 4368:         if ($default eq 'communities') {
 4369:             $select1 = $select0;
 4370:             $select0 = '';
 4371:         }
 4372:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4373:                      .'<select name="'.$default.'_pos">'
 4374:                      .'<option value="0"'.$select0.'>1</option>'
 4375:                      .'<option value="1"'.$select1.'>2</option>'
 4376:                      .'<option value="2">3</option></select>&nbsp;'
 4377:                      .$default_names{$default}
 4378:                      .'</span></td><td><span class="LC_nobreak">'
 4379:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
 4380:                      .&mt('Display').'</label>&nbsp;<label>'
 4381:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
 4382:                  .'</label></span></td></tr>';
 4383:         $itemcount ++;
 4384:     }
 4385:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4386:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 4387:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 4388:                   .'<select name="addcategory_pos"'.$chgstr.'>'
 4389:                   .'<option value="0">1</option>'
 4390:                   .'<option value="1">2</option>'
 4391:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
 4392:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 4393:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 4394:     return $datatable;
 4395: }
 4396: 
 4397: sub build_category_rows {
 4398:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 4399:     my ($text,$name,$item,$chgstr);
 4400:     if (ref($cats) eq 'ARRAY') {
 4401:         my $maxdepth = scalar(@{$cats});
 4402:         if (ref($cats->[$depth]) eq 'HASH') {
 4403:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 4404:                 my $numchildren = @{$cats->[$depth]{$parent}};
 4405:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 4406:                 $text .= '<td><table class="LC_datatable">';
 4407:                 my ($idxnum,$parent_name,$parent_item);
 4408:                 my $higher = $depth - 1;
 4409:                 if ($higher == 0) {
 4410:                     $parent_name = &escape($parent).'::'.$higher;
 4411:                 } else {
 4412:                     if (ref($path) eq 'ARRAY') {
 4413:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 4414:                     }
 4415:                 }
 4416:                 $parent_item = 'addcategory_pos_'.$parent_name;
 4417:                 for (my $j=0; $j<=$numchildren; $j++) {
 4418:                     if ($j < $numchildren) {
 4419:                         $name = $cats->[$depth]{$parent}[$j];
 4420:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 4421:                         $idxnum = $idx->{$item};
 4422:                     } else {
 4423:                         $name = $parent_name;
 4424:                         $item = $parent_item;
 4425:                     }
 4426:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 4427:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 4428:                     for (my $i=0; $i<=$numchildren; $i++) {
 4429:                         my $vpos = $i+1;
 4430:                         my $selstr;
 4431:                         if ($j == $i) {
 4432:                             $selstr = ' selected="selected" ';
 4433:                         }
 4434:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 4435:                     }
 4436:                     $text .= '</select>&nbsp;';
 4437:                     if ($j < $numchildren) {
 4438:                         my $deeper = $depth+1;
 4439:                         $text .= $name.'&nbsp;'
 4440:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 4441:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 4442:                         if(ref($path) eq 'ARRAY') {
 4443:                             push(@{$path},$name);
 4444:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 4445:                             pop(@{$path});
 4446:                         }
 4447:                     } else {
 4448:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 4449:                         if ($j == $numchildren) {
 4450:                             $text .= $name;
 4451:                         } else {
 4452:                             $text .= $item;
 4453:                         }
 4454:                         $text .= '" value="" />';
 4455:                     }
 4456:                     $text .= '</td></tr>';
 4457:                 }
 4458:                 $text .= '</table></td>';
 4459:             } else {
 4460:                 my $higher = $depth-1;
 4461:                 if ($higher == 0) {
 4462:                     $name = &escape($parent).'::'.$higher;
 4463:                 } else {
 4464:                     if (ref($path) eq 'ARRAY') {
 4465:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 4466:                     }
 4467:                 }
 4468:                 my $colspan;
 4469:                 if ($parent ne 'instcode') {
 4470:                     $colspan = $maxdepth - $depth - 1;
 4471:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 4472:                 }
 4473:             }
 4474:         }
 4475:     }
 4476:     return $text;
 4477: }
 4478: 
 4479: sub modifiable_userdata_row {
 4480:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
 4481:     my $rolename;
 4482:     if ($context eq 'selfcreate') {
 4483:         if (ref($usertypes) eq 'HASH') {
 4484:             $rolename = $usertypes->{$role};
 4485:         } else {
 4486:             $rolename = $role;
 4487:         }
 4488:     } else {
 4489:         if ($role eq 'cr') {
 4490:             $rolename = &mt('Custom role');
 4491:         } else {
 4492:             $rolename = &Apache::lonnet::plaintext($role);
 4493:         }
 4494:     }
 4495:     my @fields = ('lastname','firstname','middlename','generation',
 4496:                   'permanentemail','id');
 4497:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 4498:     my $output;
 4499:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 4500:     $output = '<tr '.$css_class.'>'.
 4501:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 4502:               '<td class="LC_left_item" colspan="2"><table>';
 4503:     my $rem;
 4504:     my %checks;
 4505:     if (ref($settings) eq 'HASH') {
 4506:         if (ref($settings->{$context}) eq 'HASH') {
 4507:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 4508:                 foreach my $field (@fields) {
 4509:                     if ($settings->{$context}->{$role}->{$field}) {
 4510:                         $checks{$field} = ' checked="checked" ';
 4511:                     }
 4512:                 }
 4513:             }
 4514:         }
 4515:     }
 4516:     for (my $i=0; $i<@fields; $i++) {
 4517:         my $rem = $i%($numinrow);
 4518:         if ($rem == 0) {
 4519:             if ($i > 0) {
 4520:                 $output .= '</tr>';
 4521:             }
 4522:             $output .= '<tr>';
 4523:         }
 4524:         my $check = ' ';
 4525:         if (exists($checks{$fields[$i]})) {
 4526:             $check = $checks{$fields[$i]}
 4527:         } else {
 4528:             if ($role eq 'st') {
 4529:                 if (ref($settings) ne 'HASH') {
 4530:                     $check = ' checked="checked" '; 
 4531:                 }
 4532:             }
 4533:         }
 4534:         $output .= '<td class="LC_left_item">'.
 4535:                    '<span class="LC_nobreak"><label>'.
 4536:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 4537:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 4538:                    '</label></span></td>';
 4539:         $rem = @fields%($numinrow);
 4540:     }
 4541:     my $colsleft = $numinrow - $rem;
 4542:     if ($colsleft > 1 ) {
 4543:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 4544:                    '&nbsp;</td>';
 4545:     } elsif ($colsleft == 1) {
 4546:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 4547:     }
 4548:     $output .= '</tr></table></td></tr>';
 4549:     return $output;
 4550: }
 4551: 
 4552: sub insttypes_row {
 4553:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
 4554:     my %lt = &Apache::lonlocal::texthash (
 4555:                       cansearch => 'Users allowed to search',
 4556:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
 4557:                       lockablenames => 'User preference to lock name',
 4558:              );
 4559:     my $showdom;
 4560:     if ($context eq 'cansearch') {
 4561:         $showdom = ' ('.$dom.')';
 4562:     }
 4563:     my $class = 'LC_left_item';
 4564:     if ($context eq 'statustocreate') {
 4565:         $class = 'LC_right_item';
 4566:     }
 4567:     my $output =  '<tr class="LC_odd_row">'.
 4568:                   '<td>'.$lt{$context}.$showdom.
 4569:                   '</td><td class="'.$class.'" colspan="2"><table>';
 4570:     my $rem;
 4571:     if (ref($types) eq 'ARRAY') {
 4572:         for (my $i=0; $i<@{$types}; $i++) {
 4573:             if (defined($usertypes->{$types->[$i]})) {
 4574:                 my $rem = $i%($numinrow);
 4575:                 if ($rem == 0) {
 4576:                     if ($i > 0) {
 4577:                         $output .= '</tr>';
 4578:                     }
 4579:                     $output .= '<tr>';
 4580:                 }
 4581:                 my $check = ' ';
 4582:                 if (ref($settings) eq 'HASH') {
 4583:                     if (ref($settings->{$context}) eq 'ARRAY') {
 4584:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
 4585:                             $check = ' checked="checked" ';
 4586:                         }
 4587:                     } elsif ($context eq 'statustocreate') {
 4588:                         $check = ' checked="checked" ';
 4589:                     }
 4590:                 }
 4591:                 $output .= '<td class="LC_left_item">'.
 4592:                            '<span class="LC_nobreak"><label>'.
 4593:                            '<input type="checkbox" name="'.$context.'" '.
 4594:                            'value="'.$types->[$i].'"'.$check.'/>'.
 4595:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 4596:             }
 4597:         }
 4598:         $rem = @{$types}%($numinrow);
 4599:     }
 4600:     my $colsleft = $numinrow - $rem;
 4601:     if (($rem == 0) && (@{$types} > 0)) {
 4602:         $output .= '<tr>';
 4603:     }
 4604:     if ($colsleft > 1) {
 4605:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 4606:     } else {
 4607:         $output .= '<td class="LC_left_item">';
 4608:     }
 4609:     my $defcheck = ' ';
 4610:     if (ref($settings) eq 'HASH') {  
 4611:         if (ref($settings->{$context}) eq 'ARRAY') {
 4612:             if (grep(/^default$/,@{$settings->{$context}})) {
 4613:                 $defcheck = ' checked="checked" ';
 4614:             }
 4615:         } elsif ($context eq 'statustocreate') {
 4616:             $defcheck = ' checked="checked" ';
 4617:         }
 4618:     }
 4619:     $output .= '<span class="LC_nobreak"><label>'.
 4620:                '<input type="checkbox" name="'.$context.'" '.
 4621:                'value="default"'.$defcheck.'/>'.
 4622:                $othertitle.'</label></span></td>'.
 4623:                '</tr></table></td></tr>';
 4624:     return $output;
 4625: }
 4626: 
 4627: sub sorted_searchtitles {
 4628:     my %searchtitles = &Apache::lonlocal::texthash(
 4629:                          'uname' => 'username',
 4630:                          'lastname' => 'last name',
 4631:                          'lastfirst' => 'last name, first name',
 4632:                      );
 4633:     my @titleorder = ('uname','lastname','lastfirst');
 4634:     return (\%searchtitles,\@titleorder);
 4635: }
 4636: 
 4637: sub sorted_searchtypes {
 4638:     my %srchtypes_desc = (
 4639:                            exact    => 'is exact match',
 4640:                            contains => 'contains ..',
 4641:                            begins   => 'begins with ..',
 4642:                          );
 4643:     my @srchtypeorder = ('exact','begins','contains');
 4644:     return (\%srchtypes_desc,\@srchtypeorder);
 4645: }
 4646: 
 4647: sub usertype_update_row {
 4648:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 4649:     my $datatable;
 4650:     my $numinrow = 4;
 4651:     foreach my $type (@{$types}) {
 4652:         if (defined($usertypes->{$type})) {
 4653:             $$rownums ++;
 4654:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 4655:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 4656:                           '</td><td class="LC_left_item"><table>';
 4657:             for (my $i=0; $i<@{$fields}; $i++) {
 4658:                 my $rem = $i%($numinrow);
 4659:                 if ($rem == 0) {
 4660:                     if ($i > 0) {
 4661:                         $datatable .= '</tr>';
 4662:                     }
 4663:                     $datatable .= '<tr>';
 4664:                 }
 4665:                 my $check = ' ';
 4666:                 if (ref($settings) eq 'HASH') {
 4667:                     if (ref($settings->{'fields'}) eq 'HASH') {
 4668:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 4669:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 4670:                                 $check = ' checked="checked" ';
 4671:                             }
 4672:                         }
 4673:                     }
 4674:                 }
 4675: 
 4676:                 if ($i == @{$fields}-1) {
 4677:                     my $colsleft = $numinrow - $rem;
 4678:                     if ($colsleft > 1) {
 4679:                         $datatable .= '<td colspan="'.$colsleft.'">';
 4680:                     } else {
 4681:                         $datatable .= '<td>';
 4682:                     }
 4683:                 } else {
 4684:                     $datatable .= '<td>';
 4685:                 }
 4686:                 $datatable .= '<span class="LC_nobreak"><label>'.
 4687:                               '<input type="checkbox" name="updateable_'.$type.
 4688:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 4689:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 4690:             }
 4691:             $datatable .= '</tr></table></td></tr>';
 4692:         }
 4693:     }
 4694:     return $datatable;
 4695: }
 4696: 
 4697: sub modify_login {
 4698:     my ($r,$dom,$confname,%domconfig) = @_;
 4699:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
 4700:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
 4701:     %title = ( coursecatalog => 'Display course catalog',
 4702:                adminmail => 'Display administrator E-mail address',
 4703:                helpdesk  => 'Display "Contact Helpdesk" link',
 4704:                newuser => 'Link for visitors to create a user account',
 4705:                loginheader => 'Log-in box header');
 4706:     @offon = ('off','on');
 4707:     if (ref($domconfig{login}) eq 'HASH') {
 4708:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
 4709:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
 4710:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
 4711:             }
 4712:         }
 4713:     }
 4714:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 4715:                                            \%domconfig,\%loginhash);
 4716:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 4717:     foreach my $item (@toggles) {
 4718:         $loginhash{login}{$item} = $env{'form.'.$item};
 4719:     }
 4720:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 4721:     if (ref($colchanges{'login'}) eq 'HASH') {  
 4722:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 4723:                                          \%loginhash);
 4724:     }
 4725: 
 4726:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 4727:     my @loginvia_attribs = ('serverpath','custompath','exempt');
 4728:     if (keys(%servers) > 1) {
 4729:         foreach my $lonhost (keys(%servers)) {
 4730:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
 4731:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
 4732:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
 4733:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
 4734:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
 4735:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4736:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4737:                         $changes{'loginvia'}{$lonhost} = 1;
 4738:                     } else {
 4739:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
 4740:                         $changes{'loginvia'}{$lonhost} = 1;
 4741:                     }
 4742:                 } else {
 4743:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4744:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4745:                         $changes{'loginvia'}{$lonhost} = 1;
 4746:                     }
 4747:                 }
 4748:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
 4749:                     foreach my $item (@loginvia_attribs) {
 4750:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
 4751:                     }
 4752:                 } else {
 4753:                     foreach my $item (@loginvia_attribs) {
 4754:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 4755:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 4756:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
 4757:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 4758:                                 $new = '/';
 4759:                             }
 4760:                         }
 4761:                         if (($item eq 'custompath') && 
 4762:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 4763:                             $new = '';
 4764:                         }
 4765:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
 4766:                             $changes{'loginvia'}{$lonhost} = 1;
 4767:                         }
 4768:                         if ($item eq 'exempt') {
 4769:                             $new =~ s/^\s+//;
 4770:                             $new =~ s/\s+$//;
 4771:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
 4772:                             my @okips;
 4773:                             foreach my $ip (@poss_ips) {
 4774:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
 4775:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
 4776:                                         push(@okips,$ip); 
 4777:                                     }
 4778:                                 }
 4779:                             }
 4780:                             if (@okips > 0) {
 4781:                                 $new = join(',',@okips); 
 4782:                             } else {
 4783:                                 $new = ''; 
 4784:                             }
 4785:                         }
 4786:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 4787:                     }
 4788:                 }
 4789:             } else {
 4790:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 4791:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 4792:                     $changes{'loginvia'}{$lonhost} = 1;
 4793:                     foreach my $item (@loginvia_attribs) {
 4794:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 4795:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 4796:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 4797:                                 $new = '/';
 4798:                             }
 4799:                         }
 4800:                         if (($item eq 'custompath') && 
 4801:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 4802:                             $new = '';
 4803:                         }
 4804:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 4805:                     }
 4806:                 }
 4807:             }
 4808:         }
 4809:     }
 4810: 
 4811:     my $servadm = $r->dir_config('lonAdmEMail');
 4812:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
 4813:     if (ref($domconfig{'login'}) eq 'HASH') {
 4814:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
 4815:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
 4816:                 if ($lang eq 'nolang') {
 4817:                     push(@currlangs,$lang);
 4818:                 } elsif (defined($langchoices{$lang})) {
 4819:                     push(@currlangs,$lang);
 4820:                 } else {
 4821:                     next;
 4822:                 }
 4823:             }
 4824:         }
 4825:     }
 4826:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
 4827:     if (@currlangs > 0) {
 4828:         foreach my $lang (@currlangs) {
 4829:             if (grep(/^\Q$lang\E$/,@delurls)) {
 4830:                 $changes{'helpurl'}{$lang} = 1;
 4831:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
 4832:                 $changes{'helpurl'}{$lang} = 1;
 4833:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
 4834:                 push(@newlangs,$lang);
 4835:             } else {
 4836:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 4837:             }
 4838:         }
 4839:     }
 4840:     unless (grep(/^nolang$/,@currlangs)) {
 4841:         if ($env{'form.loginhelpurl_nolang.filename'}) {
 4842:             $changes{'helpurl'}{'nolang'} = 1;
 4843:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
 4844:             push(@newlangs,'nolang');
 4845:         }
 4846:     }
 4847:     if ($env{'form.loginhelpurl_add_lang'}) {
 4848:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
 4849:             ($env{'form.loginhelpurl_add_file.filename'})) {
 4850:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
 4851:             $addedfile = $env{'form.loginhelpurl_add_lang'};
 4852:         }
 4853:     }
 4854:     if ((@newlangs > 0) || ($addedfile)) {
 4855:         my $error;
 4856:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
 4857:         if ($configuserok eq 'ok') {
 4858:             if ($switchserver) {
 4859:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
 4860:             } elsif ($author_ok eq 'ok') {
 4861:                 my @allnew = @newlangs;
 4862:                 if ($addedfile ne '') {
 4863:                     push(@allnew,$addedfile);
 4864:                 }
 4865:                 foreach my $lang (@allnew) {
 4866:                     my $formelem = 'loginhelpurl_'.$lang;
 4867:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
 4868:                         $formelem = 'loginhelpurl_add_file';
 4869:                     }
 4870:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
 4871:                                                                "help/$lang",'','',$newfile{$lang});
 4872:                     if ($result eq 'ok') {
 4873:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
 4874:                         $changes{'helpurl'}{$lang} = 1;
 4875:                     } else {
 4876:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
 4877:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
 4878:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
 4879:                             (!grep(/^\Q$lang\E$/,@delurls))) {
 4880: 
 4881:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
 4882:                         }
 4883:                     }
 4884:                 }
 4885:             } else {
 4886:                 $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);
 4887:             }
 4888:         } else {
 4889:             $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);
 4890:         }
 4891:         if ($error) {
 4892:             &Apache::lonnet::logthis($error);
 4893:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 4894:         }
 4895:     }
 4896:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
 4897: 
 4898:     my $defaulthelpfile = '/adm/loginproblems.html';
 4899:     my $defaulttext = &mt('Default in use');
 4900: 
 4901:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 4902:                                              $dom);
 4903:     if ($putresult eq 'ok') {
 4904:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
 4905:         my %defaultchecked = (
 4906:                     'coursecatalog' => 'on',
 4907:                     'helpdesk'      => 'on',
 4908:                     'adminmail'     => 'off',
 4909:                     'newuser'       => 'off',
 4910:         );
 4911:         if (ref($domconfig{'login'}) eq 'HASH') {
 4912:             foreach my $item (@toggles) {
 4913:                 if ($defaultchecked{$item} eq 'on') { 
 4914:                     if (($domconfig{'login'}{$item} eq '0') &&
 4915:                         ($env{'form.'.$item} eq '1')) {
 4916:                         $changes{$item} = 1;
 4917:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 4918:                               $domconfig{'login'}{$item} eq '1') &&
 4919:                              ($env{'form.'.$item} eq '0')) {
 4920:                         $changes{$item} = 1;
 4921:                     }
 4922:                 } elsif ($defaultchecked{$item} eq 'off') {
 4923:                     if (($domconfig{'login'}{$item} eq '1') &&
 4924:                         ($env{'form.'.$item} eq '0')) {
 4925:                         $changes{$item} = 1;
 4926:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 4927:                               $domconfig{'login'}{$item} eq '0') &&
 4928:                              ($env{'form.'.$item} eq '1')) {
 4929:                         $changes{$item} = 1;
 4930:                     }
 4931:                 }
 4932:             }
 4933:         }
 4934:         if (keys(%changes) > 0 || $colchgtext) {
 4935:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 4936:             $resulttext = &mt('Changes made:').'<ul>';
 4937:             foreach my $item (sort(keys(%changes))) {
 4938:                 if ($item eq 'loginvia') {
 4939:                     if (ref($changes{$item}) eq 'HASH') {
 4940:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
 4941:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 4942:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
 4943:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
 4944:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
 4945:                                     $protocol = 'http' if ($protocol ne 'https');
 4946:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
 4947: 
 4948:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
 4949:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
 4950:                                     } else {
 4951:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
 4952:                                     }
 4953:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
 4954:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
 4955:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
 4956:                                     }
 4957:                                     $resulttext .= '</li>';
 4958:                                 } else {
 4959:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
 4960:                                 }
 4961:                             } else {
 4962:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
 4963:                             }
 4964:                         }
 4965:                         $resulttext .= '</ul></li>';
 4966:                     }
 4967:                 } elsif ($item eq 'helpurl') {
 4968:                     if (ref($changes{$item}) eq 'HASH') {
 4969:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
 4970:                             if (grep(/^\Q$lang\E$/,@delurls)) {
 4971:                                 my ($chg,$link);
 4972:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
 4973:                                 if ($lang eq 'nolang') {
 4974:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
 4975:                                 } else {
 4976:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
 4977:                                 }
 4978:                                 $resulttext .= '<li>'.$chg.'</li>';
 4979:                             } else {
 4980:                                 my $chg;
 4981:                                 if ($lang eq 'nolang') {
 4982:                                     $chg = &mt('custom log-in help file for no preferred language');
 4983:                                 } else {
 4984:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
 4985:                                 }
 4986:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
 4987:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
 4988:                                                       '?inhibitmenu=yes',$chg,600,500).
 4989:                                                '</li>';
 4990:                             }
 4991:                         }
 4992:                     }
 4993:                 } elsif ($item eq 'captcha') {
 4994:                     if (ref($loginhash{'login'}) eq 'HASH') {
 4995:                         my $chgtxt;
 4996:                         if ($loginhash{'login'}{$item} eq 'notused') {
 4997:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
 4998:                         } else {
 4999:                             my %captchas = &captcha_phrases();
 5000:                             if ($captchas{$loginhash{'login'}{$item}}) {
 5001:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
 5002:                             } else {
 5003:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
 5004:                             }
 5005:                         }
 5006:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 5007:                     }
 5008:                 } elsif ($item eq 'recaptchakeys') {
 5009:                     if (ref($loginhash{'login'}) eq 'HASH') {
 5010:                         my ($privkey,$pubkey);
 5011:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
 5012:                             $pubkey = $loginhash{'login'}{$item}{'public'};
 5013:                             $privkey = $loginhash{'login'}{$item}{'private'};
 5014:                         }
 5015:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
 5016:                         if (!$pubkey) {
 5017:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
 5018:                         } else {
 5019:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 5020:                         }
 5021:                         if (!$privkey) {
 5022:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
 5023:                         } else {
 5024:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
 5025:                         }
 5026:                         $chgtxt .= '</ul>';
 5027:                         $resulttext .= '<li>'.$chgtxt.'</li>';
 5028:                     }
 5029:                 } else {
 5030:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 5031:                 }
 5032:             }
 5033:             $resulttext .= $colchgtext.'</ul>';
 5034:         } else {
 5035:             $resulttext = &mt('No changes made to log-in page settings');
 5036:         }
 5037:     } else {
 5038:         $resulttext = '<span class="LC_error">'.
 5039: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5040:     }
 5041:     if ($errors) {
 5042:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 5043:                        $errors.'</ul>';
 5044:     }
 5045:     return $resulttext;
 5046: }
 5047: 
 5048: sub color_font_choices {
 5049:     my %choices =
 5050:         &Apache::lonlocal::texthash (
 5051:             img => "Header",
 5052:             bgs => "Background colors",
 5053:             links => "Link colors",
 5054:             images => "Images",
 5055:             font => "Font color",
 5056:             fontmenu => "Font menu",
 5057:             pgbg => "Page",
 5058:             tabbg => "Header",
 5059:             sidebg => "Border",
 5060:             link => "Link",
 5061:             alink => "Active link",
 5062:             vlink => "Visited link",
 5063:         );
 5064:     return %choices;
 5065: }
 5066: 
 5067: sub modify_rolecolors {
 5068:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 5069:     my ($resulttext,%rolehash);
 5070:     $rolehash{'rolecolors'} = {};
 5071:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 5072:         if ($domconfig{'rolecolors'} eq '') {
 5073:             $domconfig{'rolecolors'} = {};
 5074:         }
 5075:     }
 5076:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 5077:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 5078:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 5079:                                              $dom);
 5080:     if ($putresult eq 'ok') {
 5081:         if (keys(%changes) > 0) {
 5082:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 5083:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 5084:                                              $rolehash{'rolecolors'});
 5085:         } else {
 5086:             $resulttext = &mt('No changes made to default color schemes');
 5087:         }
 5088:     } else {
 5089:         $resulttext = '<span class="LC_error">'.
 5090: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5091:     }
 5092:     if ($errors) {
 5093:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 5094:                        $errors.'</ul>';
 5095:     }
 5096:     return $resulttext;
 5097: }
 5098: 
 5099: sub modify_colors {
 5100:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 5101:     my (%changes,%choices);
 5102:     my @bgs;
 5103:     my @links = ('link','alink','vlink');
 5104:     my @logintext;
 5105:     my @images;
 5106:     my $servadm = $r->dir_config('lonAdmEMail');
 5107:     my $errors;
 5108:     my %defaults;
 5109:     foreach my $role (@{$roles}) {
 5110:         if ($role eq 'login') {
 5111:             %choices = &login_choices();
 5112:             @logintext = ('textcol','bgcol');
 5113:         } else {
 5114:             %choices = &color_font_choices();
 5115:         }
 5116:         if ($role eq 'login') {
 5117:             @images = ('img','logo','domlogo','login');
 5118:             @bgs = ('pgbg','mainbg','sidebg');
 5119:         } else {
 5120:             @images = ('img');
 5121:             @bgs = ('pgbg','tabbg','sidebg');
 5122:         }
 5123:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
 5124:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
 5125:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 5126:         }
 5127:         if ($role eq 'login') {
 5128:             foreach my $item (@logintext) {
 5129:                 unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'logintext'}{$item}) {
 5130:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5131:                 }
 5132:             }
 5133:         } else {
 5134:             unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
 5135:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
 5136:             }
 5137:         }
 5138:         foreach my $item (@bgs) {
 5139:             unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
 5140:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5141:             }
 5142:         }
 5143:         foreach my $item (@links) {
 5144:             unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'links'}{$item}) {
 5145:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 5146:             }
 5147:         }
 5148:         my ($configuserok,$author_ok,$switchserver) = 
 5149:             &config_check($dom,$confname,$servadm);
 5150:         my ($width,$height) = &thumb_dimensions();
 5151:         if (ref($domconfig->{$role}) ne 'HASH') {
 5152:             $domconfig->{$role} = {};
 5153:         }
 5154:         foreach my $img (@images) {
 5155:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 5156:                 if (defined($env{'form.login_showlogo_'.$img})) {
 5157:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 5158:                 } else { 
 5159:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 5160:                 }
 5161:             } 
 5162: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 5163: 		 && !defined($domconfig->{$role}{$img})
 5164: 		 && !$env{'form.'.$role.'_del_'.$img}
 5165: 		 && $env{'form.'.$role.'_import_'.$img}) {
 5166: 		# import the old configured image from the .tab setting
 5167: 		# if they haven't provided a new one 
 5168: 		$domconfig->{$role}{$img} = 
 5169: 		    $env{'form.'.$role.'_import_'.$img};
 5170: 	    }
 5171:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 5172:                 my $error;
 5173:                 if ($configuserok eq 'ok') {
 5174:                     if ($switchserver) {
 5175:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 5176:                     } else {
 5177:                         if ($author_ok eq 'ok') {
 5178:                             my ($result,$logourl) = 
 5179:                                 &publishlogo($r,'upload',$role.'_'.$img,
 5180:                                            $dom,$confname,$img,$width,$height);
 5181:                             if ($result eq 'ok') {
 5182:                                 $confhash->{$role}{$img} = $logourl;
 5183:                                 $changes{$role}{'images'}{$img} = 1;
 5184:                             } else {
 5185:                                 $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);
 5186:                             }
 5187:                         } else {
 5188:                             $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);
 5189:                         }
 5190:                     }
 5191:                 } else {
 5192:                     $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);
 5193:                 }
 5194:                 if ($error) {
 5195:                     &Apache::lonnet::logthis($error);
 5196:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 5197:                 }
 5198:             } elsif ($domconfig->{$role}{$img} ne '') {
 5199:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 5200:                     my $error;
 5201:                     if ($configuserok eq 'ok') {
 5202: # is confname an author?
 5203:                         if ($switchserver eq '') {
 5204:                             if ($author_ok eq 'ok') {
 5205:                                 my ($result,$logourl) = 
 5206:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 5207:                                             $dom,$confname,$img,$width,$height);
 5208:                                 if ($result eq 'ok') {
 5209:                                     $confhash->{$role}{$img} = $logourl;
 5210: 				    $changes{$role}{'images'}{$img} = 1;
 5211:                                 }
 5212:                             }
 5213:                         }
 5214:                     }
 5215:                 }
 5216:             }
 5217:         }
 5218:         if (ref($domconfig) eq 'HASH') {
 5219:             if (ref($domconfig->{$role}) eq 'HASH') {
 5220:                 foreach my $img (@images) {
 5221:                     if ($domconfig->{$role}{$img} ne '') {
 5222:                         if ($env{'form.'.$role.'_del_'.$img}) {
 5223:                             $confhash->{$role}{$img} = '';
 5224:                             $changes{$role}{'images'}{$img} = 1;
 5225:                         } else {
 5226:                             if ($confhash->{$role}{$img} eq '') {
 5227:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 5228:                             }
 5229:                         }
 5230:                     } else {
 5231:                         if ($env{'form.'.$role.'_del_'.$img}) {
 5232:                             $confhash->{$role}{$img} = '';
 5233:                             $changes{$role}{'images'}{$img} = 1;
 5234:                         } 
 5235:                     }
 5236:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 5237:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 5238:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 5239:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 5240:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 5241:                             }
 5242:                         } else {
 5243:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 5244:                                 $changes{$role}{'showlogo'}{$img} = 1;
 5245:                             }
 5246:                         }
 5247:                     }
 5248:                 }
 5249:                 if ($domconfig->{$role}{'font'} ne '') {
 5250:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 5251:                         $changes{$role}{'font'} = 1;
 5252:                     }
 5253:                 } else {
 5254:                     if ($confhash->{$role}{'font'}) {
 5255:                         $changes{$role}{'font'} = 1;
 5256:                     }
 5257:                 }
 5258:                 if ($role ne 'login') {
 5259:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
 5260:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
 5261:                             $changes{$role}{'fontmenu'} = 1;
 5262:                         }
 5263:                     } else {
 5264:                         if ($confhash->{$role}{'fontmenu'}) {
 5265:                             $changes{$role}{'fontmenu'} = 1;
 5266:                         }
 5267:                     }
 5268:                 }
 5269:                 foreach my $item (@bgs) {
 5270:                     if ($domconfig->{$role}{$item} ne '') {
 5271:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5272:                             $changes{$role}{'bgs'}{$item} = 1;
 5273:                         } 
 5274:                     } else {
 5275:                         if ($confhash->{$role}{$item}) {
 5276:                             $changes{$role}{'bgs'}{$item} = 1;
 5277:                         }
 5278:                     }
 5279:                 }
 5280:                 foreach my $item (@links) {
 5281:                     if ($domconfig->{$role}{$item} ne '') {
 5282:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5283:                             $changes{$role}{'links'}{$item} = 1;
 5284:                         }
 5285:                     } else {
 5286:                         if ($confhash->{$role}{$item}) {
 5287:                             $changes{$role}{'links'}{$item} = 1;
 5288:                         }
 5289:                     }
 5290:                 }
 5291:                 foreach my $item (@logintext) {
 5292:                     if ($domconfig->{$role}{$item} ne '') {
 5293:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 5294:                             $changes{$role}{'logintext'}{$item} = 1;
 5295:                         }
 5296:                     } else {
 5297:                         if ($confhash->{$role}{$item}) {
 5298:                             $changes{$role}{'logintext'}{$item} = 1;
 5299:                         }
 5300:                     }
 5301:                 }
 5302:             } else {
 5303:                 &default_change_checker($role,\@images,\@links,\@bgs,
 5304:                                         \@logintext,$confhash,\%changes); 
 5305:             }
 5306:         } else {
 5307:             &default_change_checker($role,\@images,\@links,\@bgs,
 5308:                                     \@logintext,$confhash,\%changes); 
 5309:         }
 5310:     }
 5311:     return ($errors,%changes);
 5312: }
 5313: 
 5314: sub config_check {
 5315:     my ($dom,$confname,$servadm) = @_;
 5316:     my ($configuserok,$author_ok,$switchserver,%currroles);
 5317:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 5318:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 5319:                                                    $confname,$servadm);
 5320:     if ($configuserok eq 'ok') {
 5321:         $switchserver = &check_switchserver($dom,$confname);
 5322:         if ($switchserver eq '') {
 5323:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 5324:         }
 5325:     }
 5326:     return ($configuserok,$author_ok,$switchserver);
 5327: }
 5328: 
 5329: sub default_change_checker {
 5330:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 5331:     foreach my $item (@{$links}) {
 5332:         if ($confhash->{$role}{$item}) {
 5333:             $changes->{$role}{'links'}{$item} = 1;
 5334:         }
 5335:     }
 5336:     foreach my $item (@{$bgs}) {
 5337:         if ($confhash->{$role}{$item}) {
 5338:             $changes->{$role}{'bgs'}{$item} = 1;
 5339:         }
 5340:     }
 5341:     foreach my $item (@{$logintext}) {
 5342:         if ($confhash->{$role}{$item}) {
 5343:             $changes->{$role}{'logintext'}{$item} = 1;
 5344:         }
 5345:     }
 5346:     foreach my $img (@{$images}) {
 5347:         if ($env{'form.'.$role.'_del_'.$img}) {
 5348:             $confhash->{$role}{$img} = '';
 5349:             $changes->{$role}{'images'}{$img} = 1;
 5350:         }
 5351:         if ($role eq 'login') {
 5352:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 5353:                 $changes->{$role}{'showlogo'}{$img} = 1;
 5354:             }
 5355:         }
 5356:     }
 5357:     if ($confhash->{$role}{'font'}) {
 5358:         $changes->{$role}{'font'} = 1;
 5359:     }
 5360: }
 5361: 
 5362: sub display_colorchgs {
 5363:     my ($dom,$changes,$roles,$confhash) = @_;
 5364:     my (%choices,$resulttext);
 5365:     if (!grep(/^login$/,@{$roles})) {
 5366:         $resulttext = &mt('Changes made:').'<br />';
 5367:     }
 5368:     foreach my $role (@{$roles}) {
 5369:         if ($role eq 'login') {
 5370:             %choices = &login_choices();
 5371:         } else {
 5372:             %choices = &color_font_choices();
 5373:         }
 5374:         if (ref($changes->{$role}) eq 'HASH') {
 5375:             if ($role ne 'login') {
 5376:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 5377:             }
 5378:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 5379:                 if ($role ne 'login') {
 5380:                     $resulttext .= '<ul>';
 5381:                 }
 5382:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 5383:                     if ($role ne 'login') {
 5384:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 5385:                     }
 5386:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 5387:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 5388:                             if ($confhash->{$role}{$key}{$item}) {
 5389:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 5390:                             } else {
 5391:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 5392:                             }
 5393:                         } elsif ($confhash->{$role}{$item} eq '') {
 5394:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 5395:                         } else {
 5396:                             my $newitem = $confhash->{$role}{$item};
 5397:                             if ($key eq 'images') {
 5398:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 5399:                             }
 5400:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 5401:                         }
 5402:                     }
 5403:                     if ($role ne 'login') {
 5404:                         $resulttext .= '</ul></li>';
 5405:                     }
 5406:                 } else {
 5407:                     if ($confhash->{$role}{$key} eq '') {
 5408:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 5409:                     } else {
 5410:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 5411:                     }
 5412:                 }
 5413:                 if ($role ne 'login') {
 5414:                     $resulttext .= '</ul>';
 5415:                 }
 5416:             }
 5417:         }
 5418:     }
 5419:     return $resulttext;
 5420: }
 5421: 
 5422: sub thumb_dimensions {
 5423:     return ('200','50');
 5424: }
 5425: 
 5426: sub check_dimensions {
 5427:     my ($inputfile) = @_;
 5428:     my ($fullwidth,$fullheight);
 5429:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 5430:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 5431:             my $imageinfo = <PIPE>;
 5432:             if (!close(PIPE)) {
 5433:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 5434:             }
 5435:             chomp($imageinfo);
 5436:             my ($fullsize) = 
 5437:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 5438:             if ($fullsize) {
 5439:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 5440:             }
 5441:         }
 5442:     }
 5443:     return ($fullwidth,$fullheight);
 5444: }
 5445: 
 5446: sub check_configuser {
 5447:     my ($uhome,$dom,$confname,$servadm) = @_;
 5448:     my ($configuserok,%currroles);
 5449:     if ($uhome eq 'no_host') {
 5450:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 5451:         my $configpass = &LONCAPA::Enrollment::create_password();
 5452:         $configuserok = 
 5453:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 5454:                              $configpass,'','','','','',undef,$servadm);
 5455:     } else {
 5456:         $configuserok = 'ok';
 5457:         %currroles = 
 5458:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 5459:     }
 5460:     return ($configuserok,%currroles);
 5461: }
 5462: 
 5463: sub check_authorstatus {
 5464:     my ($dom,$confname,%currroles) = @_;
 5465:     my $author_ok;
 5466:     if (!$currroles{':'.$dom.':au'}) {
 5467:         my $start = time;
 5468:         my $end = 0;
 5469:         $author_ok = 
 5470:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 5471:                                         'au',$end,$start,'','','domconfig');
 5472:     } else {
 5473:         $author_ok = 'ok';
 5474:     }
 5475:     return $author_ok;
 5476: }
 5477: 
 5478: sub publishlogo {
 5479:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 5480:     my ($output,$fname,$logourl);
 5481:     if ($action eq 'upload') {
 5482:         $fname=$env{'form.'.$formname.'.filename'};
 5483:         chop($env{'form.'.$formname});
 5484:     } else {
 5485:         ($fname) = ($formname =~ /([^\/]+)$/);
 5486:     }
 5487:     if ($savefileas ne '') {
 5488:         $fname = $savefileas;
 5489:     }
 5490:     $fname=&Apache::lonnet::clean_filename($fname);
 5491: # See if there is anything left
 5492:     unless ($fname) { return ('error: no uploaded file'); }
 5493:     $fname="$subdir/$fname";
 5494:     my $docroot=$r->dir_config('lonDocRoot');
 5495:     my $filepath="$docroot/priv";
 5496:     my $relpath = "$dom/$confname";
 5497:     my ($fnamepath,$file,$fetchthumb);
 5498:     $file=$fname;
 5499:     if ($fname=~m|/|) {
 5500:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 5501:     }
 5502:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");  
 5503:     my $count;
 5504:     for ($count=5;$count<=$#parts;$count++) {
 5505:         $filepath.="/$parts[$count]";
 5506:         if ((-e $filepath)!=1) {
 5507:             mkdir($filepath,02770);
 5508:         }
 5509:     }
 5510:     # Check for bad extension and disallow upload
 5511:     if ($file=~/\.(\w+)$/ &&
 5512:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 5513:         $output = 
 5514:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 5515:     } elsif ($file=~/\.(\w+)$/ &&
 5516:         !defined(&Apache::loncommon::fileembstyle($1))) {
 5517:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 5518:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 5519:         $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 5520:     } elsif (-d "$filepath/$file") {
 5521:         $output = &mt('Filename is a directory name - rename the file and re-upload');
 5522:     } else {
 5523:         my $source = $filepath.'/'.$file;
 5524:         my $logfile;
 5525:         if (!open($logfile,">>$source".'.log')) {
 5526:             return (&mt('No write permission to Authoring Space'));
 5527:         }
 5528:         print $logfile
 5529: "\n================= Publish ".localtime()." ================\n".
 5530: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 5531: # Save the file
 5532:         if (!open(FH,'>'.$source)) {
 5533:             &Apache::lonnet::logthis('Failed to create '.$source);
 5534:             return (&mt('Failed to create file'));
 5535:         }
 5536:         if ($action eq 'upload') {
 5537:             if (!print FH ($env{'form.'.$formname})) {
 5538:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 5539:                 return (&mt('Failed to write file'));
 5540:             }
 5541:         } else {
 5542:             my $original = &Apache::lonnet::filelocation('',$formname);
 5543:             if(!copy($original,$source)) {
 5544:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 5545:                 return (&mt('Failed to write file'));
 5546:             }
 5547:         }
 5548:         close(FH);
 5549:         chmod(0660, $source); # Permissions to rw-rw---.
 5550: 
 5551:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 5552:         my $copyfile=$targetdir.'/'.$file;
 5553: 
 5554:         my @parts=split(/\//,$targetdir);
 5555:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 5556:         for (my $count=5;$count<=$#parts;$count++) {
 5557:             $path.="/$parts[$count]";
 5558:             if (!-e $path) {
 5559:                 print $logfile "\nCreating directory ".$path;
 5560:                 mkdir($path,02770);
 5561:             }
 5562:         }
 5563:         my $versionresult;
 5564:         if (-e $copyfile) {
 5565:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 5566:         } else {
 5567:             $versionresult = 'ok';
 5568:         }
 5569:         if ($versionresult eq 'ok') {
 5570:             if (copy($source,$copyfile)) {
 5571:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 5572:                 $output = 'ok';
 5573:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 5574:                 push(@{$modified_urls},[$copyfile,$source]);
 5575:                 my $metaoutput = 
 5576:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 5577:                 unless ($registered_cleanup) {
 5578:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 5579:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 5580:                     $registered_cleanup=1;
 5581:                 }
 5582:             } else {
 5583:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 5584:                 $output = &mt('Failed to copy file to RES space').", $!";
 5585:             }
 5586:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 5587:                 my $inputfile = $filepath.'/'.$file;
 5588:                 my $outfile = $filepath.'/'.'tn-'.$file;
 5589:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 5590:                 if ($fullwidth ne '' && $fullheight ne '') { 
 5591:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 5592:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 5593:                         system("convert -sample $thumbsize $inputfile $outfile");
 5594:                         chmod(0660, $filepath.'/tn-'.$file);
 5595:                         if (-e $outfile) {
 5596:                             my $copyfile=$targetdir.'/tn-'.$file;
 5597:                             if (copy($outfile,$copyfile)) {
 5598:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 5599:                                 my $thumb_metaoutput = 
 5600:                                     &write_metadata($dom,$confname,$formname,
 5601:                                                     $targetdir,'tn-'.$file,$logfile);
 5602:                                 push(@{$modified_urls},[$copyfile,$outfile]);
 5603:                                 unless ($registered_cleanup) {
 5604:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
 5605:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
 5606:                                     $registered_cleanup=1;
 5607:                                 }
 5608:                             } else {
 5609:                                 print $logfile "\nUnable to write ".$copyfile.
 5610:                                                ':'.$!."\n";
 5611:                             }
 5612:                         }
 5613:                     }
 5614:                 }
 5615:             }
 5616:         } else {
 5617:             $output = $versionresult;
 5618:         }
 5619:     }
 5620:     return ($output,$logourl);
 5621: }
 5622: 
 5623: sub logo_versioning {
 5624:     my ($targetdir,$file,$logfile) = @_;
 5625:     my $target = $targetdir.'/'.$file;
 5626:     my ($maxversion,$fn,$extn,$output);
 5627:     $maxversion = 0;
 5628:     if ($file =~ /^(.+)\.(\w+)$/) {
 5629:         $fn=$1;
 5630:         $extn=$2;
 5631:     }
 5632:     opendir(DIR,$targetdir);
 5633:     while (my $filename=readdir(DIR)) {
 5634:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 5635:             $maxversion=($1>$maxversion)?$1:$maxversion;
 5636:         }
 5637:     }
 5638:     $maxversion++;
 5639:     print $logfile "\nCreating old version ".$maxversion."\n";
 5640:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 5641:     if (copy($target,$copyfile)) {
 5642:         print $logfile "Copied old target to ".$copyfile."\n";
 5643:         $copyfile=$copyfile.'.meta';
 5644:         if (copy($target.'.meta',$copyfile)) {
 5645:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 5646:             $output = 'ok';
 5647:         } else {
 5648:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 5649:             $output = &mt('Failed to copy old meta').", $!, ";
 5650:         }
 5651:     } else {
 5652:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 5653:         $output = &mt('Failed to copy old target').", $!, ";
 5654:     }
 5655:     return $output;
 5656: }
 5657: 
 5658: sub write_metadata {
 5659:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 5660:     my (%metadatafields,%metadatakeys,$output);
 5661:     $metadatafields{'title'}=$formname;
 5662:     $metadatafields{'creationdate'}=time;
 5663:     $metadatafields{'lastrevisiondate'}=time;
 5664:     $metadatafields{'copyright'}='public';
 5665:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 5666:                                          $env{'user.domain'};
 5667:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 5668:     $metadatafields{'domain'}=$dom;
 5669:     {
 5670:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 5671:         my $mfh;
 5672:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 5673:             foreach (sort(keys(%metadatafields))) {
 5674:                 unless ($_=~/\./) {
 5675:                     my $unikey=$_;
 5676:                     $unikey=~/^([A-Za-z]+)/;
 5677:                     my $tag=$1;
 5678:                     $tag=~tr/A-Z/a-z/;
 5679:                     print $mfh "\n\<$tag";
 5680:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
 5681:                         my $value=$metadatafields{$unikey.'.'.$_};
 5682:                         $value=~s/\"/\'\'/g;
 5683:                         print $mfh ' '.$_.'="'.$value.'"';
 5684:                     }
 5685:                     print $mfh '>'.
 5686:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 5687:                             .'</'.$tag.'>';
 5688:                 }
 5689:             }
 5690:             $output = 'ok';
 5691:             print $logfile "\nWrote metadata";
 5692:             close($mfh);
 5693:         } else {
 5694:             print $logfile "\nFailed to open metadata file";
 5695:             $output = &mt('Could not write metadata');
 5696:         }
 5697:     }
 5698:     return $output;
 5699: }
 5700: 
 5701: sub notifysubscribed {
 5702:     foreach my $targetsource (@{$modified_urls}){
 5703:         next unless (ref($targetsource) eq 'ARRAY');
 5704:         my ($target,$source)=@{$targetsource};
 5705:         if ($source ne '') {
 5706:             if (open(my $logfh,'>>'.$source.'.log')) {
 5707:                 print $logfh "\nCleanup phase: Notifications\n";
 5708:                 my @subscribed=&subscribed_hosts($target);
 5709:                 foreach my $subhost (@subscribed) {
 5710:                     print $logfh "\nNotifying host ".$subhost.':';
 5711:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
 5712:                     print $logfh $reply;
 5713:                 }
 5714:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
 5715:                 foreach my $subhost (@subscribedmeta) {
 5716:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
 5717:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
 5718:                                                         $subhost);
 5719:                     print $logfh $reply;
 5720:                 }
 5721:                 print $logfh "\n============ Done ============\n";
 5722:                 close($logfh);
 5723:             }
 5724:         }
 5725:     }
 5726:     return OK;
 5727: }
 5728: 
 5729: sub subscribed_hosts {
 5730:     my ($target) = @_;
 5731:     my @subscribed;
 5732:     if (open(my $fh,"<$target.subscription")) {
 5733:         while (my $subline=<$fh>) {
 5734:             if ($subline =~ /^($match_lonid):/) {
 5735:                 my $host = $1;
 5736:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
 5737:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
 5738:                         push(@subscribed,$host);
 5739:                     }
 5740:                 }
 5741:             }
 5742:         }
 5743:     }
 5744:     return @subscribed;
 5745: }
 5746: 
 5747: sub check_switchserver {
 5748:     my ($dom,$confname) = @_;
 5749:     my ($allowed,$switchserver);
 5750:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 5751:     if ($home eq 'no_host') {
 5752:         $home = &Apache::lonnet::domain($dom,'primary');
 5753:     }
 5754:     my @ids=&Apache::lonnet::current_machine_ids();
 5755:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 5756:     if (!$allowed) {
 5757: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
 5758:     }
 5759:     return $switchserver;
 5760: }
 5761: 
 5762: sub modify_quotas {
 5763:     my ($dom,$action,%domconfig) = @_;
 5764:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
 5765:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
 5766:     if ($action eq 'quotas') {
 5767:         $context = 'tools'; 
 5768:     } else { 
 5769:         $context = $action;
 5770:     }
 5771:     if ($context eq 'requestcourses') {
 5772:         @usertools = ('official','unofficial','community');
 5773:         @options =('norequest','approval','validate','autolimit');
 5774:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 5775:         %titles = &courserequest_titles();
 5776:         $toolregexp = join('|',@usertools);
 5777:         %conditions = &courserequest_conditions();
 5778:     } elsif ($context eq 'requestauthor') {
 5779:         @usertools = ('author');
 5780:         %titles = &authorrequest_titles();
 5781:     } else {
 5782:         @usertools = ('aboutme','blog','webdav','portfolio');
 5783:         %titles = &tool_titles();
 5784:     }
 5785:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 5786:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5787:     foreach my $key (keys(%env)) {
 5788:         if ($context eq 'requestcourses') {
 5789:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
 5790:                 my $item = $1;
 5791:                 my $type = $2;
 5792:                 if ($type =~ /^limit_(.+)/) {
 5793:                     $limithash{$item}{$1} = $env{$key};
 5794:                 } else {
 5795:                     $confhash{$item}{$type} = $env{$key};
 5796:                 }
 5797:             }
 5798:         } elsif ($context eq 'requestauthor') {
 5799:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
 5800:                 $confhash{$1} = $env{$key};
 5801:             }
 5802:         } else {
 5803:             if ($key =~ /^form\.quota_(.+)$/) {
 5804:                 $confhash{'defaultquota'}{$1} = $env{$key};
 5805:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
 5806:                 $confhash{'authorquota'}{$1} = $env{$key};
 5807:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
 5808:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 5809:             }
 5810:         }
 5811:     }
 5812:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 5813:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
 5814:         @approvalnotify = sort(@approvalnotify);
 5815:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
 5816:         if (ref($domconfig{$action}) eq 'HASH') {
 5817:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
 5818:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
 5819:                     $changes{'notify'}{'approval'} = 1;
 5820:                 }
 5821:             } else {
 5822:                 if ($confhash{'notify'}{'approval'}) {
 5823:                     $changes{'notify'}{'approval'} = 1;
 5824:                 }
 5825:             }
 5826:         } else {
 5827:             if ($confhash{'notify'}{'approval'}) {
 5828:                 $changes{'notify'}{'approval'} = 1;
 5829:             }
 5830:         }
 5831:     } else {
 5832:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 5833:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
 5834:     }
 5835:     foreach my $item (@usertools) {
 5836:         foreach my $type (@{$types},'default','_LC_adv') {
 5837:             my $unset; 
 5838:             if ($context eq 'requestcourses') {
 5839:                 $unset = '0';
 5840:                 if ($type eq '_LC_adv') {
 5841:                     $unset = '';
 5842:                 }
 5843:                 if ($confhash{$item}{$type} eq 'autolimit') {
 5844:                     $confhash{$item}{$type} .= '=';
 5845:                     unless ($limithash{$item}{$type} =~ /\D/) {
 5846:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
 5847:                     }
 5848:                 }
 5849:             } elsif ($context eq 'requestauthor') {
 5850:                 $unset = '0';
 5851:                 if ($type eq '_LC_adv') {
 5852:                     $unset = '';
 5853:                 }
 5854:             } else {
 5855:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 5856:                     $confhash{$item}{$type} = 1;
 5857:                 } else {
 5858:                     $confhash{$item}{$type} = 0;
 5859:                 }
 5860:             }
 5861:             if (ref($domconfig{$action}) eq 'HASH') {
 5862:                 if ($action eq 'requestauthor') {
 5863:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
 5864:                         $changes{$type} = 1;
 5865:                     }
 5866:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
 5867:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
 5868:                         $changes{$item}{$type} = 1;
 5869:                     }
 5870:                 } else {
 5871:                     if ($context eq 'requestcourses') {
 5872:                         if ($confhash{$item}{$type} ne $unset) {
 5873:                             $changes{$item}{$type} = 1;
 5874:                         }
 5875:                     } else {
 5876:                         if (!$confhash{$item}{$type}) {
 5877:                             $changes{$item}{$type} = 1;
 5878:                         }
 5879:                     }
 5880:                 }
 5881:             } else {
 5882:                 if ($context eq 'requestcourses') {
 5883:                     if ($confhash{$item}{$type} ne $unset) {
 5884:                         $changes{$item}{$type} = 1;
 5885:                     }
 5886:                 } elsif ($context eq 'requestauthor') {
 5887:                     if ($confhash{$type} ne $unset) {
 5888:                         $changes{$type} = 1;
 5889:                     }
 5890:                 } else {
 5891:                     if (!$confhash{$item}{$type}) {
 5892:                         $changes{$item}{$type} = 1;
 5893:                     }
 5894:                 }
 5895:             }
 5896:         }
 5897:     }
 5898:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
 5899:         if (ref($domconfig{'quotas'}) eq 'HASH') {
 5900:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 5901:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 5902:                     if (exists($confhash{'defaultquota'}{$key})) {
 5903:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 5904:                             $changes{'defaultquota'}{$key} = 1;
 5905:                         }
 5906:                     } else {
 5907:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 5908:                     }
 5909:                 }
 5910:             } else {
 5911:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
 5912:                     if (exists($confhash{'defaultquota'}{$key})) {
 5913:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 5914:                             $changes{'defaultquota'}{$key} = 1;
 5915:                         }
 5916:                     } else {
 5917:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 5918:                     }
 5919:                 }
 5920:             }
 5921:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 5922:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
 5923:                     if (exists($confhash{'authorquota'}{$key})) {
 5924:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
 5925:                             $changes{'authorquota'}{$key} = 1;
 5926:                         }
 5927:                     } else {
 5928:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
 5929:                     }
 5930:                 }
 5931:             }
 5932:         }
 5933:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
 5934:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 5935:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 5936:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 5937:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 5938:                             $changes{'defaultquota'}{$key} = 1;
 5939:                         }
 5940:                     } else {
 5941:                         if (!exists($domconfig{'quotas'}{$key})) {
 5942:                             $changes{'defaultquota'}{$key} = 1;
 5943:                         }
 5944:                     }
 5945:                 } else {
 5946:                     $changes{'defaultquota'}{$key} = 1;
 5947:                 }
 5948:             }
 5949:         }
 5950:         if (ref($confhash{'authorquota'}) eq 'HASH') {
 5951:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
 5952:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 5953:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
 5954:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
 5955:                             $changes{'authorquota'}{$key} = 1;
 5956:                         }
 5957:                     } else {
 5958:                         $changes{'authorquota'}{$key} = 1;
 5959:                     }
 5960:                 } else {
 5961:                     $changes{'authorquota'}{$key} = 1;
 5962:                 }
 5963:             }
 5964:         }
 5965:     }
 5966: 
 5967:     if ($context eq 'requestauthor') {
 5968:         $domdefaults{'requestauthor'} = \%confhash;
 5969:     } else {
 5970:         foreach my $key (keys(%confhash)) {
 5971:             $domdefaults{$key} = $confhash{$key};
 5972:         }
 5973:     }
 5974: 
 5975:     my %quotahash = (
 5976:                       $action => { %confhash }
 5977:                     );
 5978:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 5979:                                              $dom);
 5980:     if ($putresult eq 'ok') {
 5981:         if (keys(%changes) > 0) {
 5982:             my $cachetime = 24*60*60;
 5983:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 5984: 
 5985:             $resulttext = &mt('Changes made:').'<ul>';
 5986:             unless (($context eq 'requestcourses') ||
 5987:                     ($context eq 'requestauthor')) {
 5988:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
 5989:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 5990:                     foreach my $type (@{$types},'default') {
 5991:                         if (defined($changes{'defaultquota'}{$type})) {
 5992:                             my $typetitle = $usertypes->{$type};
 5993:                             if ($type eq 'default') {
 5994:                                 $typetitle = $othertitle;
 5995:                             }
 5996:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 5997:                         }
 5998:                     }
 5999:                     $resulttext .= '</ul></li>';
 6000:                 }
 6001:                 if (ref($changes{'authorquota'}) eq 'HASH') {
 6002:                     $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
 6003:                     foreach my $type (@{$types},'default') {
 6004:                         if (defined($changes{'authorquota'}{$type})) {
 6005:                             my $typetitle = $usertypes->{$type};
 6006:                             if ($type eq 'default') {
 6007:                                 $typetitle = $othertitle;
 6008:                             }
 6009:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
 6010:                         }
 6011:                     }
 6012:                     $resulttext .= '</ul></li>';
 6013:                 }
 6014:             }
 6015:             my %newenv;
 6016:             foreach my $item (@usertools) {
 6017:                 my (%haschgs,%inconf);
 6018:                 if ($context eq 'requestauthor') {
 6019:                     %haschgs = %changes;
 6020:                     %inconf = %confhash;
 6021:                 } else {
 6022:                     if (ref($changes{$item}) eq 'HASH') {
 6023:                         %haschgs = %{$changes{$item}};
 6024:                     }
 6025:                     if (ref($confhash{$item}) eq 'HASH') {
 6026:                         %inconf = %{$confhash{$item}};
 6027:                     }
 6028:                 }
 6029:                 if (keys(%haschgs) > 0) {
 6030:                     my $newacc = 
 6031:                         &Apache::lonnet::usertools_access($env{'user.name'},
 6032:                                                           $env{'user.domain'},
 6033:                                                           $item,'reload',$context);
 6034:                     if (($context eq 'requestcourses') ||
 6035:                         ($context eq 'requestauthor')) {
 6036:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
 6037:                             $newenv{'environment.canrequest.'.$item} = $newacc;
 6038:                         }
 6039:                     } else {
 6040:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 6041:                             $newenv{'environment.availabletools.'.$item} = $newacc;
 6042:                         }
 6043:                     }
 6044:                     unless ($context eq 'requestauthor') {
 6045:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
 6046:                     }
 6047:                     foreach my $type (@{$types},'default','_LC_adv') {
 6048:                         if ($haschgs{$type}) {
 6049:                             my $typetitle = $usertypes->{$type};
 6050:                             if ($type eq 'default') {
 6051:                                 $typetitle = $othertitle;
 6052:                             } elsif ($type eq '_LC_adv') {
 6053:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 6054:                             }
 6055:                             if ($inconf{$type}) {
 6056:                                 if ($context eq 'requestcourses') {
 6057:                                     my $cond;
 6058:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
 6059:                                         if ($1 eq '') {
 6060:                                             $cond = &mt('(Automatic processing of any request).');
 6061:                                         } else {
 6062:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
 6063:                                         }
 6064:                                     } else { 
 6065:                                         $cond = $conditions{$inconf{$type}};
 6066:                                     }
 6067:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
 6068:                                 } elsif ($context eq 'requestauthor') {
 6069:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
 6070:                                                              $titles{$inconf{$type}},$typetitle);
 6071: 
 6072:                                 } else {
 6073:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 6074:                                 }
 6075:                             } else {
 6076:                                 if ($type eq '_LC_adv') {
 6077:                                     if ($inconf{$type} eq '0') {
 6078:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 6079:                                     } else { 
 6080:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
 6081:                                     }
 6082:                                 } else {
 6083:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 6084:                                 }
 6085:                             }
 6086:                         }
 6087:                     }
 6088:                     unless ($context eq 'requestauthor') {
 6089:                         $resulttext .= '</ul></li>';
 6090:                     }
 6091:                 }
 6092:             }
 6093:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
 6094:                 if (ref($changes{'notify'}) eq 'HASH') {
 6095:                     if ($changes{'notify'}{'approval'}) {
 6096:                         if (ref($confhash{'notify'}) eq 'HASH') {
 6097:                             if ($confhash{'notify'}{'approval'}) {
 6098:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
 6099:                             } else {
 6100:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
 6101:                             }
 6102:                         }
 6103:                     }
 6104:                 }
 6105:             }
 6106:             $resulttext .= '</ul>';
 6107:             if (keys(%newenv)) {
 6108:                 &Apache::lonnet::appenv(\%newenv);
 6109:             }
 6110:         } else {
 6111:             if ($context eq 'requestcourses') {
 6112:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
 6113:             } elsif ($context eq 'requestauthor') {
 6114:                 $resulttext = &mt('No changes made to rights to request author space.');
 6115:             } else {
 6116:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
 6117:             }
 6118:         }
 6119:     } else {
 6120:         $resulttext = '<span class="LC_error">'.
 6121: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6122:     }
 6123:     return $resulttext;
 6124: }
 6125: 
 6126: sub modify_autoenroll {
 6127:     my ($dom,%domconfig) = @_;
 6128:     my ($resulttext,%changes);
 6129:     my %currautoenroll;
 6130:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 6131:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 6132:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 6133:         }
 6134:     }
 6135:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 6136:     my %title = ( run => 'Auto-enrollment active',
 6137:                   sender => 'Sender for notification messages',
 6138:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
 6139:     my @offon = ('off','on');
 6140:     my $sender_uname = $env{'form.sender_uname'};
 6141:     my $sender_domain = $env{'form.sender_domain'};
 6142:     if ($sender_domain eq '') {
 6143:         $sender_uname = '';
 6144:     } elsif ($sender_uname eq '') {
 6145:         $sender_domain = '';
 6146:     }
 6147:     my $coowners = $env{'form.autoassign_coowners'};
 6148:     my %autoenrollhash =  (
 6149:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
 6150:                                        'sender_uname' => $sender_uname,
 6151:                                        'sender_domain' => $sender_domain,
 6152:                                        'co-owners' => $coowners,
 6153:                                 }
 6154:                      );
 6155:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 6156:                                              $dom);
 6157:     if ($putresult eq 'ok') {
 6158:         if (exists($currautoenroll{'run'})) {
 6159:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 6160:                  $changes{'run'} = 1;
 6161:              }
 6162:         } elsif ($autorun) {
 6163:             if ($env{'form.autoenroll_run'} ne '1') {
 6164:                  $changes{'run'} = 1;
 6165:             }
 6166:         }
 6167:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 6168:             $changes{'sender'} = 1;
 6169:         }
 6170:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 6171:             $changes{'sender'} = 1;
 6172:         }
 6173:         if ($currautoenroll{'co-owners'} ne '') {
 6174:             if ($currautoenroll{'co-owners'} ne $coowners) {
 6175:                 $changes{'coowners'} = 1;
 6176:             }
 6177:         } elsif ($coowners) {
 6178:             $changes{'coowners'} = 1;
 6179:         }      
 6180:         if (keys(%changes) > 0) {
 6181:             $resulttext = &mt('Changes made:').'<ul>';
 6182:             if ($changes{'run'}) {
 6183:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 6184:             }
 6185:             if ($changes{'sender'}) {
 6186:                 if ($sender_uname eq '' || $sender_domain eq '') {
 6187:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 6188:                 } else {
 6189:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 6190:                 }
 6191:             }
 6192:             if ($changes{'coowners'}) {
 6193:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
 6194:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 6195:             }
 6196:             $resulttext .= '</ul>';
 6197:         } else {
 6198:             $resulttext = &mt('No changes made to auto-enrollment settings');
 6199:         }
 6200:     } else {
 6201:         $resulttext = '<span class="LC_error">'.
 6202: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6203:     }
 6204:     return $resulttext;
 6205: }
 6206: 
 6207: sub modify_autoupdate {
 6208:     my ($dom,%domconfig) = @_;
 6209:     my ($resulttext,%currautoupdate,%fields,%changes);
 6210:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 6211:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 6212:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 6213:         }
 6214:     }
 6215:     my @offon = ('off','on');
 6216:     my %title = &Apache::lonlocal::texthash (
 6217:                    run => 'Auto-update:',
 6218:                    classlists => 'Updates to user information in classlists?'
 6219:                 );
 6220:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 6221:     my %fieldtitles = &Apache::lonlocal::texthash (
 6222:                         id => 'Student/Employee ID',
 6223:                         permanentemail => 'E-mail address',
 6224:                         lastname => 'Last Name',
 6225:                         firstname => 'First Name',
 6226:                         middlename => 'Middle Name',
 6227:                         generation => 'Generation',
 6228:                       );
 6229:     $othertitle = &mt('All users');
 6230:     if (keys(%{$usertypes}) >  0) {
 6231:         $othertitle = &mt('Other users');
 6232:     }
 6233:     foreach my $key (keys(%env)) {
 6234:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 6235:             my ($usertype,$item) = ($1,$2);
 6236:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
 6237:                 if ($usertype eq 'default') {   
 6238:                     push(@{$fields{$1}},$2);
 6239:                 } elsif (ref($types) eq 'ARRAY') {
 6240:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
 6241:                         push(@{$fields{$1}},$2);
 6242:                     }
 6243:                 }
 6244:             }
 6245:         }
 6246:     }
 6247:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
 6248:     @lockablenames = sort(@lockablenames);
 6249:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
 6250:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 6251:         if (@changed) {
 6252:             $changes{'lockablenames'} = 1;
 6253:         }
 6254:     } else {
 6255:         if (@lockablenames) {
 6256:             $changes{'lockablenames'} = 1;
 6257:         }
 6258:     }
 6259:     my %updatehash = (
 6260:                       autoupdate => { run => $env{'form.autoupdate_run'},
 6261:                                       classlists => $env{'form.classlists'},
 6262:                                       fields => {%fields},
 6263:                                       lockablenames => \@lockablenames,
 6264:                                     }
 6265:                      );
 6266:     foreach my $key (keys(%currautoupdate)) {
 6267:         if (($key eq 'run') || ($key eq 'classlists')) {
 6268:             if (exists($updatehash{autoupdate}{$key})) {
 6269:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 6270:                     $changes{$key} = 1;
 6271:                 }
 6272:             }
 6273:         } elsif ($key eq 'fields') {
 6274:             if (ref($currautoupdate{$key}) eq 'HASH') {
 6275:                 foreach my $item (@{$types},'default') {
 6276:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 6277:                         my $change = 0;
 6278:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 6279:                             if (!exists($fields{$item})) {
 6280:                                 $change = 1;
 6281:                                 last;
 6282:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 6283:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 6284:                                     $change = 1;
 6285:                                     last;
 6286:                                 }
 6287:                             }
 6288:                         }
 6289:                         if ($change) {
 6290:                             push(@{$changes{$key}},$item);
 6291:                         }
 6292:                     } 
 6293:                 }
 6294:             }
 6295:         } elsif ($key eq 'lockablenames') {
 6296:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
 6297:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 6298:                 if (@changed) {
 6299:                     $changes{'lockablenames'} = 1;
 6300:                 }
 6301:             } else {
 6302:                 if (@lockablenames) {
 6303:                     $changes{'lockablenames'} = 1;
 6304:                 }
 6305:             }
 6306:         }
 6307:     }
 6308:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
 6309:         if (@lockablenames) {
 6310:             $changes{'lockablenames'} = 1;
 6311:         }
 6312:     }
 6313:     foreach my $item (@{$types},'default') {
 6314:         if (defined($fields{$item})) {
 6315:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 6316:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
 6317:                     my $change = 0;
 6318:                     if (ref($fields{$item}) eq 'ARRAY') {
 6319:                         foreach my $type (@{$fields{$item}}) {
 6320:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
 6321:                                 $change = 1;
 6322:                                 last;
 6323:                             }
 6324:                         }
 6325:                     }
 6326:                     if ($change) {
 6327:                         push(@{$changes{'fields'}},$item);
 6328:                     }
 6329:                 } else {
 6330:                     push(@{$changes{'fields'}},$item);
 6331:                 }
 6332:             } else {
 6333:                 push(@{$changes{'fields'}},$item);
 6334:             }
 6335:         }
 6336:     }
 6337:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 6338:                                              $dom);
 6339:     if ($putresult eq 'ok') {
 6340:         if (keys(%changes) > 0) {
 6341:             $resulttext = &mt('Changes made:').'<ul>';
 6342:             foreach my $key (sort(keys(%changes))) {
 6343:                 if ($key eq 'lockablenames') {
 6344:                     $resulttext .= '<li>';
 6345:                     if (@lockablenames) {
 6346:                         $usertypes->{'default'} = $othertitle;
 6347:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
 6348:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
 6349:                     } else {
 6350:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
 6351:                     }
 6352:                     $resulttext .= '</li>';
 6353:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
 6354:                     foreach my $item (@{$changes{$key}}) {
 6355:                         my @newvalues;
 6356:                         foreach my $type (@{$fields{$item}}) {
 6357:                             push(@newvalues,$fieldtitles{$type});
 6358:                         }
 6359:                         my $newvaluestr;
 6360:                         if (@newvalues > 0) {
 6361:                             $newvaluestr = join(', ',@newvalues);
 6362:                         } else {
 6363:                             $newvaluestr = &mt('none');
 6364:                         }
 6365:                         if ($item eq 'default') {
 6366:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 6367:                         } else {
 6368:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 6369:                         }
 6370:                     }
 6371:                 } else {
 6372:                     my $newvalue;
 6373:                     if ($key eq 'run') {
 6374:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 6375:                     } else {
 6376:                         $newvalue = $offon[$env{'form.'.$key}];
 6377:                     }
 6378:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 6379:                 }
 6380:             }
 6381:             $resulttext .= '</ul>';
 6382:         } else {
 6383:             $resulttext = &mt('No changes made to autoupdates');
 6384:         }
 6385:     } else {
 6386:         $resulttext = '<span class="LC_error">'.
 6387: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6388:     }
 6389:     return $resulttext;
 6390: }
 6391: 
 6392: sub modify_autocreate {
 6393:     my ($dom,%domconfig) = @_;
 6394:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
 6395:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
 6396:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
 6397:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
 6398:         }
 6399:     }
 6400:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
 6401:                  req => 'Auto-creation of validated requests for official courses',
 6402:                  xmldc => 'Identity of course creator of courses from XML files',
 6403:                );
 6404:     my @types = ('xml','req');
 6405:     foreach my $item (@types) {
 6406:         $newvals{$item} = $env{'form.autocreate_'.$item};
 6407:         $newvals{$item} =~ s/\D//g;
 6408:         $newvals{$item} = 0 if ($newvals{$item} eq '');
 6409:     }
 6410:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
 6411:     my %domcoords = &get_active_dcs($dom);
 6412:     unless (exists($domcoords{$newvals{'xmldc'}})) {
 6413:         $newvals{'xmldc'} = '';
 6414:     } 
 6415:     %autocreatehash =  (
 6416:                         autocreate => { xml => $newvals{'xml'},
 6417:                                         req => $newvals{'req'},
 6418:                                       }
 6419:                        );
 6420:     if ($newvals{'xmldc'} ne '') {
 6421:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
 6422:     }
 6423:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
 6424:                                              $dom);
 6425:     if ($putresult eq 'ok') {
 6426:         my @items = @types;
 6427:         if ($newvals{'xml'}) {
 6428:             push(@items,'xmldc');
 6429:         }
 6430:         foreach my $item (@items) {
 6431:             if (exists($currautocreate{$item})) {
 6432:                 if ($currautocreate{$item} ne $newvals{$item}) {
 6433:                     $changes{$item} = 1;
 6434:                 }
 6435:             } elsif ($newvals{$item}) {
 6436:                 $changes{$item} = 1;
 6437:             }
 6438:         }
 6439:         if (keys(%changes) > 0) {
 6440:             my @offon = ('off','on'); 
 6441:             $resulttext = &mt('Changes made:').'<ul>';
 6442:             foreach my $item (@types) {
 6443:                 if ($changes{$item}) {
 6444:                     my $newtxt = $offon[$newvals{$item}];
 6445:                     $resulttext .= '<li>'.
 6446:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
 6447:                                        '<b>','</b>').
 6448:                                    '</li>';
 6449:                 }
 6450:             }
 6451:             if ($changes{'xmldc'}) {
 6452:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
 6453:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
 6454:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
 6455:             }
 6456:             $resulttext .= '</ul>';
 6457:         } else {
 6458:             $resulttext = &mt('No changes made to auto-creation settings');
 6459:         }
 6460:     } else {
 6461:         $resulttext = '<span class="LC_error">'.
 6462:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6463:     }
 6464:     return $resulttext;
 6465: }
 6466: 
 6467: sub modify_directorysrch {
 6468:     my ($dom,%domconfig) = @_;
 6469:     my ($resulttext,%changes);
 6470:     my %currdirsrch;
 6471:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 6472:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 6473:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 6474:         }
 6475:     }
 6476:     my %title = ( available => 'Directory search available',
 6477:                   localonly => 'Other domains can search',
 6478:                   searchby => 'Search types',
 6479:                   searchtypes => 'Search latitude');
 6480:     my @offon = ('off','on');
 6481:     my @otherdoms = ('Yes','No');
 6482: 
 6483:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 6484:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 6485:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 6486: 
 6487:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 6488:     if (keys(%{$usertypes}) == 0) {
 6489:         @cansearch = ('default');
 6490:     } else {
 6491:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 6492:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 6493:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 6494:                     push(@{$changes{'cansearch'}},$type);
 6495:                 }
 6496:             }
 6497:             foreach my $type (@cansearch) {
 6498:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 6499:                     push(@{$changes{'cansearch'}},$type);
 6500:                 }
 6501:             }
 6502:         } else {
 6503:             push(@{$changes{'cansearch'}},@cansearch);
 6504:         }
 6505:     }
 6506: 
 6507:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 6508:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 6509:             if (!grep(/^\Q$by\E$/,@searchby)) {
 6510:                 push(@{$changes{'searchby'}},$by);
 6511:             }
 6512:         }
 6513:         foreach my $by (@searchby) {
 6514:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 6515:                 push(@{$changes{'searchby'}},$by);
 6516:             }
 6517:         }
 6518:     } else {
 6519:         push(@{$changes{'searchby'}},@searchby);
 6520:     }
 6521: 
 6522:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 6523:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 6524:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 6525:                 push(@{$changes{'searchtypes'}},$type);
 6526:             }
 6527:         }
 6528:         foreach my $type (@searchtypes) {
 6529:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 6530:                 push(@{$changes{'searchtypes'}},$type);
 6531:             }
 6532:         }
 6533:     } else {
 6534:         if (exists($currdirsrch{'searchtypes'})) {
 6535:             foreach my $type (@searchtypes) {  
 6536:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 6537:                     push(@{$changes{'searchtypes'}},$type);
 6538:                 }
 6539:             }
 6540:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 6541:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 6542:             }   
 6543:         } else {
 6544:             push(@{$changes{'searchtypes'}},@searchtypes); 
 6545:         }
 6546:     }
 6547: 
 6548:     my %dirsrch_hash =  (
 6549:             directorysrch => { available => $env{'form.dirsrch_available'},
 6550:                                cansearch => \@cansearch,
 6551:                                localonly => $env{'form.dirsrch_localonly'},
 6552:                                searchby => \@searchby,
 6553:                                searchtypes => \@searchtypes,
 6554:                              }
 6555:             );
 6556:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 6557:                                              $dom);
 6558:     if ($putresult eq 'ok') {
 6559:         if (exists($currdirsrch{'available'})) {
 6560:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 6561:                  $changes{'available'} = 1;
 6562:              }
 6563:         } else {
 6564:             if ($env{'form.dirsrch_available'} eq '1') {
 6565:                 $changes{'available'} = 1;
 6566:             }
 6567:         }
 6568:         if (exists($currdirsrch{'localonly'})) {
 6569:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 6570:                  $changes{'localonly'} = 1;
 6571:              }
 6572:         } else {
 6573:             if ($env{'form.dirsrch_localonly'} eq '1') {
 6574:                 $changes{'localonly'} = 1;
 6575:             }
 6576:         }
 6577:         if (keys(%changes) > 0) {
 6578:             $resulttext = &mt('Changes made:').'<ul>';
 6579:             if ($changes{'available'}) {
 6580:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 6581:             }
 6582:             if ($changes{'localonly'}) {
 6583:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 6584:             }
 6585: 
 6586:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 6587:                 my $chgtext;
 6588:                 if (ref($usertypes) eq 'HASH') {
 6589:                     if (keys(%{$usertypes}) > 0) {
 6590:                         foreach my $type (@{$types}) {
 6591:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 6592:                                 $chgtext .= $usertypes->{$type}.'; ';
 6593:                             }
 6594:                         }
 6595:                         if (grep(/^default$/,@cansearch)) {
 6596:                             $chgtext .= $othertitle;
 6597:                         } else {
 6598:                             $chgtext =~ s/\; $//;
 6599:                         }
 6600:                         $resulttext .=
 6601:                             '<li>'.
 6602:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
 6603:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
 6604:                             '</li>';
 6605:                     }
 6606:                 }
 6607:             }
 6608:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 6609:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 6610:                 my $chgtext;
 6611:                 foreach my $type (@{$titleorder}) {
 6612:                     if (grep(/^\Q$type\E$/,@searchby)) {
 6613:                         if (defined($searchtitles->{$type})) {
 6614:                             $chgtext .= $searchtitles->{$type}.'; ';
 6615:                         }
 6616:                     }
 6617:                 }
 6618:                 $chgtext =~ s/\; $//;
 6619:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 6620:             }
 6621:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 6622:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 6623:                 my $chgtext;
 6624:                 foreach my $type (@{$srchtypeorder}) {
 6625:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 6626:                         if (defined($srchtypes_desc->{$type})) {
 6627:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 6628:                         }
 6629:                     }
 6630:                 }
 6631:                 $chgtext =~ s/\; $//;
 6632:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
 6633:             }
 6634:             $resulttext .= '</ul>';
 6635:         } else {
 6636:             $resulttext = &mt('No changes made to institution directory search settings');
 6637:         }
 6638:     } else {
 6639:         $resulttext = '<span class="LC_error">'.
 6640:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 6641:     }
 6642:     return $resulttext;
 6643: }
 6644: 
 6645: sub modify_contacts {
 6646:     my ($dom,%domconfig) = @_;
 6647:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 6648:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 6649:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 6650:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 6651:         }
 6652:     }
 6653:     my (%others,%to,%bcc);
 6654:     my @contacts = ('supportemail','adminemail');
 6655:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
 6656:                     'requestsmail','updatesmail');
 6657:     foreach my $type (@mailings) {
 6658:         @{$newsetting{$type}} = 
 6659:             &Apache::loncommon::get_env_multiple('form.'.$type);
 6660:         foreach my $item (@contacts) {
 6661:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 6662:                 $contacts_hash{contacts}{$type}{$item} = 1;
 6663:             } else {
 6664:                 $contacts_hash{contacts}{$type}{$item} = 0;
 6665:             }
 6666:         }  
 6667:         $others{$type} = $env{'form.'.$type.'_others'};
 6668:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 6669:         if ($type eq 'helpdeskmail') {
 6670:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
 6671:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
 6672:         }
 6673:     }
 6674:     foreach my $item (@contacts) {
 6675:         $to{$item} = $env{'form.'.$item};
 6676:         $contacts_hash{'contacts'}{$item} = $to{$item};
 6677:     }
 6678:     if (keys(%currsetting) > 0) {
 6679:         foreach my $item (@contacts) {
 6680:             if ($to{$item} ne $currsetting{$item}) {
 6681:                 $changes{$item} = 1;
 6682:             }
 6683:         }
 6684:         foreach my $type (@mailings) {
 6685:             foreach my $item (@contacts) {
 6686:                 if (ref($currsetting{$type}) eq 'HASH') {
 6687:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 6688:                         push(@{$changes{$type}},$item);
 6689:                     }
 6690:                 } else {
 6691:                     push(@{$changes{$type}},@{$newsetting{$type}});
 6692:                 }
 6693:             }
 6694:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 6695:                 push(@{$changes{$type}},'others');
 6696:             }
 6697:             if ($type eq 'helpdeskmail') {   
 6698:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
 6699:                     push(@{$changes{$type}},'bcc'); 
 6700:                 }
 6701:             }
 6702:         }
 6703:     } else {
 6704:         my %default;
 6705:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 6706:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 6707:         $default{'errormail'} = 'adminemail';
 6708:         $default{'packagesmail'} = 'adminemail';
 6709:         $default{'helpdeskmail'} = 'supportemail';
 6710:         $default{'lonstatusmail'} = 'adminemail';
 6711:         $default{'requestsmail'} = 'adminemail';
 6712:         $default{'updatesmail'} = 'adminemail';
 6713:         foreach my $item (@contacts) {
 6714:            if ($to{$item} ne $default{$item}) {
 6715:               $changes{$item} = 1;
 6716:            } 
 6717:         }
 6718:         foreach my $type (@mailings) {
 6719:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 6720:                
 6721:                 push(@{$changes{$type}},@{$newsetting{$type}});
 6722:             }
 6723:             if ($others{$type} ne '') {
 6724:                 push(@{$changes{$type}},'others');
 6725:             }
 6726:             if ($type eq 'helpdeskmail') {
 6727:                 if ($bcc{$type} ne '') {
 6728:                     push(@{$changes{$type}},'bcc');
 6729:                 }
 6730:             }
 6731:         }
 6732:     }
 6733:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 6734:                                              $dom);
 6735:     if ($putresult eq 'ok') {
 6736:         if (keys(%changes) > 0) {
 6737:             my ($titles,$short_titles)  = &contact_titles();
 6738:             $resulttext = &mt('Changes made:').'<ul>';
 6739:             foreach my $item (@contacts) {
 6740:                 if ($changes{$item}) {
 6741:                     $resulttext .= '<li>'.$titles->{$item}.
 6742:                                     &mt(' set to: ').
 6743:                                     '<span class="LC_cusr_emph">'.
 6744:                                     $to{$item}.'</span></li>';
 6745:                 }
 6746:             }
 6747:             foreach my $type (@mailings) {
 6748:                 if (ref($changes{$type}) eq 'ARRAY') {
 6749:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 6750:                     my @text;
 6751:                     foreach my $item (@{$newsetting{$type}}) {
 6752:                         push(@text,$short_titles->{$item});
 6753:                     }
 6754:                     if ($others{$type} ne '') {
 6755:                         push(@text,$others{$type});
 6756:                     }
 6757:                     $resulttext .= '<span class="LC_cusr_emph">'.
 6758:                                    join(', ',@text).'</span>';
 6759:                     if ($type eq 'helpdeskmail') {
 6760:                         if ($bcc{$type} ne '') {
 6761:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
 6762:                         }
 6763:                     }
 6764:                     $resulttext .= '</li>';
 6765:                 }
 6766:             }
 6767:             $resulttext .= '</ul>';
 6768:         } else {
 6769:             $resulttext = &mt('No changes made to contact information');
 6770:         }
 6771:     } else {
 6772:         $resulttext = '<span class="LC_error">'.
 6773:             &mt('An error occurred: [_1].',$putresult).'</span>';
 6774:     }
 6775:     return $resulttext;
 6776: }
 6777: 
 6778: sub modify_usercreation {
 6779:     my ($dom,%domconfig) = @_;
 6780:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 6781:     my $warningmsg;
 6782:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 6783:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 6784:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 6785:         }
 6786:     }
 6787:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 6788:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 6789:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 6790:     my @contexts = ('author','course','requestcrs','selfcreate');
 6791:     foreach my $item(@contexts) {
 6792:         if ($item eq 'selfcreate') {
 6793:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
 6794:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6795:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
 6796:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
 6797:                     if (grep(/^login$/,@{$cancreate{$item}})) {
 6798:                         $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');   
 6799:                     }
 6800:                 }
 6801:             }
 6802:         } else {
 6803:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
 6804:         }
 6805:     }
 6806:     my ($othertitle,$usertypes,$types) = 
 6807:         &Apache::loncommon::sorted_inst_types($dom);
 6808:     if (ref($types) eq 'ARRAY') {
 6809:         if (@{$types} > 0) {
 6810:             @{$cancreate{'statustocreate'}} = 
 6811:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
 6812:         } else {
 6813:             @{$cancreate{'statustocreate'}} = ();
 6814:         }
 6815:         push(@contexts,'statustocreate');
 6816:     }
 6817:     &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
 6818:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 6819:         foreach my $item (@contexts) {
 6820:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
 6821:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 6822:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 6823:                         if (ref($cancreate{$item}) eq 'ARRAY') {
 6824:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 6825:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6826:                                     push(@{$changes{'cancreate'}},$item);
 6827:                                 }
 6828:                             }
 6829:                         }
 6830:                     }
 6831:                 } else {
 6832:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
 6833:                         if (@{$cancreate{$item}} > 0) {
 6834:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6835:                                 push(@{$changes{'cancreate'}},$item);
 6836:                             }
 6837:                         }
 6838:                     } else {
 6839:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
 6840:                             if (@{$cancreate{$item}} < 3) {
 6841:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6842:                                     push(@{$changes{'cancreate'}},$item);
 6843:                                 }
 6844:                             }
 6845:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
 6846:                             if (@{$cancreate{$item}} > 0) {
 6847:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6848:                                     push(@{$changes{'cancreate'}},$item);
 6849:                                 }
 6850:                             }
 6851:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
 6852:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6853:                                 push(@{$changes{'cancreate'}},$item);
 6854:                             }
 6855:                         }
 6856:                     }
 6857:                 }
 6858:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6859:                     foreach my $type (@{$cancreate{$item}}) {
 6860:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 6861:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 6862:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6863:                                     push(@{$changes{'cancreate'}},$item);
 6864:                                 }
 6865:                             }
 6866:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
 6867:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
 6868:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
 6869:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 6870:                                     push(@{$changes{'cancreate'}},$item);
 6871:                                 }
 6872:                             }
 6873:                         }
 6874:                     }
 6875:                 }
 6876:             } else {
 6877:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 6878:                     push(@{$changes{'cancreate'}},$item);
 6879:                 }
 6880:             }
 6881:         }
 6882:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 6883:         foreach my $item (@contexts) {
 6884:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 6885:                 if ($cancreate{$item} ne 'any') {
 6886:                     push(@{$changes{'cancreate'}},$item);
 6887:                 }
 6888:             } else {
 6889:                 if ($cancreate{$item} ne 'none') {
 6890:                     push(@{$changes{'cancreate'}},$item);
 6891:                 }
 6892:             }
 6893:         }
 6894:     } else {
 6895:         foreach my $item (@contexts)  {
 6896:             push(@{$changes{'cancreate'}},$item);
 6897:         }
 6898:     }
 6899: 
 6900:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 6901:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 6902:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 6903:                 push(@{$changes{'username_rule'}},$type);
 6904:             }
 6905:         }
 6906:         foreach my $type (@username_rule) {
 6907:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 6908:                 push(@{$changes{'username_rule'}},$type);
 6909:             }
 6910:         }
 6911:     } else {
 6912:         push(@{$changes{'username_rule'}},@username_rule);
 6913:     }
 6914: 
 6915:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 6916:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 6917:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 6918:                 push(@{$changes{'id_rule'}},$type);
 6919:             }
 6920:         }
 6921:         foreach my $type (@id_rule) {
 6922:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 6923:                 push(@{$changes{'id_rule'}},$type);
 6924:             }
 6925:         }
 6926:     } else {
 6927:         push(@{$changes{'id_rule'}},@id_rule);
 6928:     }
 6929: 
 6930:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 6931:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 6932:             if (!grep(/^\Q$type\E$/,@email_rule)) {
 6933:                 push(@{$changes{'email_rule'}},$type);
 6934:             }
 6935:         }
 6936:         foreach my $type (@email_rule) {
 6937:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 6938:                 push(@{$changes{'email_rule'}},$type);
 6939:             }
 6940:         }
 6941:     } else {
 6942:         push(@{$changes{'email_rule'}},@email_rule);
 6943:     }
 6944: 
 6945:     my @authen_contexts = ('author','course','domain');
 6946:     my @authtypes = ('int','krb4','krb5','loc');
 6947:     my %authhash;
 6948:     foreach my $item (@authen_contexts) {
 6949:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 6950:         foreach my $auth (@authtypes) {
 6951:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 6952:                 $authhash{$item}{$auth} = 1;
 6953:             } else {
 6954:                 $authhash{$item}{$auth} = 0;
 6955:             }
 6956:         }
 6957:     }
 6958:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 6959:         foreach my $item (@authen_contexts) {
 6960:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 6961:                 foreach my $auth (@authtypes) {
 6962:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 6963:                         push(@{$changes{'authtypes'}},$item);
 6964:                         last;
 6965:                     }
 6966:                 }
 6967:             }
 6968:         }
 6969:     } else {
 6970:         foreach my $item (@authen_contexts) {
 6971:             push(@{$changes{'authtypes'}},$item);
 6972:         }
 6973:     }
 6974: 
 6975:     my %usercreation_hash =  (
 6976:             usercreation => {
 6977:                               cancreate     => \%cancreate,
 6978:                               username_rule => \@username_rule,
 6979:                               id_rule       => \@id_rule,
 6980:                               email_rule    => \@email_rule,
 6981:                               authtypes     => \%authhash,
 6982:                             }
 6983:             );
 6984: 
 6985:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 6986:                                              $dom);
 6987: 
 6988:     my %selfcreatetypes = (
 6989:                              sso   => 'users authenticated by institutional single sign on',
 6990:                              login => 'users authenticated by institutional log-in',
 6991:                              email => 'users who provide a valid e-mail address for use as the username',
 6992:                           );
 6993:     if ($putresult eq 'ok') {
 6994:         if (keys(%changes) > 0) {
 6995:             $resulttext = &mt('Changes made:').'<ul>';
 6996:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 6997:                 my %lt = &usercreation_types();
 6998:                 foreach my $type (@{$changes{'cancreate'}}) {
 6999:                     my $chgtext;
 7000:                     unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
 7001:                         $chgtext = $lt{$type}.', ';
 7002:                     }
 7003:                     if ($type eq 'selfcreate') {
 7004:                         if (@{$cancreate{$type}} == 0) {
 7005:                             $chgtext .= &mt('creation of a new user account is not permitted.');
 7006:                         } else {
 7007:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
 7008:                             foreach my $case (@{$cancreate{$type}}) {
 7009:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 7010:                             }
 7011:                             $chgtext .= '</ul>';
 7012:                             if (ref($cancreate{$type}) eq 'ARRAY') {
 7013:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
 7014:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 7015:                                         if (@{$cancreate{'statustocreate'}} == 0) {
 7016:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 7017:                                         }
 7018:                                     }
 7019:                                 }
 7020:                             }
 7021:                         }
 7022:                     } elsif ($type eq 'statustocreate') {
 7023:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
 7024:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
 7025:                             if (@{$cancreate{'selfcreate'}} > 0) {
 7026:                                 if (@{$cancreate{'statustocreate'}} == 0) {
 7027: 
 7028:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
 7029:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
 7030:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 7031:                                     } 
 7032:                                 } elsif (ref($usertypes) eq 'HASH') {
 7033:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 7034:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
 7035:                                     } else {
 7036:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
 7037:                                     }
 7038:                                     $chgtext .= '<ul>';
 7039:                                     foreach my $case (@{$cancreate{$type}}) {
 7040:                                         if ($case eq 'default') {
 7041:                                             $chgtext .= '<li>'.$othertitle.'</li>';
 7042:                                         } else {
 7043:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
 7044:                                         }
 7045:                                     }
 7046:                                     $chgtext .= '</ul>';
 7047:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 7048:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
 7049:                                     }
 7050:                                 }
 7051:                             } else {
 7052:                                 if (@{$cancreate{$type}} == 0) {
 7053:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
 7054:                                 } else {
 7055:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
 7056:                                 }
 7057:                             }
 7058:                         }
 7059:                     } elsif ($type eq 'captcha') {
 7060:                         if ($cancreate{$type} eq 'notused') {
 7061:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
 7062:                         } else {
 7063:                             my %captchas = &captcha_phrases();
 7064:                             if ($captchas{$cancreate{$type}}) {
 7065:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
 7066:                             } else {
 7067:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
 7068:                             }
 7069:                         }
 7070:                     } elsif ($type eq 'recaptchakeys') {
 7071:                         my ($privkey,$pubkey);
 7072:                         if (ref($cancreate{$type}) eq 'HASH') {
 7073:                             $pubkey = $cancreate{$type}{'public'};
 7074:                             $privkey = $cancreate{$type}{'private'};
 7075:                         }
 7076:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
 7077:                         if (!$pubkey) {
 7078:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
 7079:                         } else {
 7080:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
 7081:                         }
 7082:                         if (!$privkey) {
 7083:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
 7084:                         } else {
 7085:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
 7086:                         }
 7087:                         $chgtext .= '</ul>';
 7088:                     } else {
 7089:                         if ($cancreate{$type} eq 'none') {
 7090:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 7091:                         } elsif ($cancreate{$type} eq 'any') {
 7092:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 7093:                         } elsif ($cancreate{$type} eq 'official') {
 7094:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 7095:                         } elsif ($cancreate{$type} eq 'unofficial') {
 7096:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 7097:                         }
 7098:                     }
 7099:                     $resulttext .= '<li>'.$chgtext.'</li>';
 7100:                 }
 7101:             }
 7102:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 7103:                 my ($rules,$ruleorder) = 
 7104:                     &Apache::lonnet::inst_userrules($dom,'username');
 7105:                 my $chgtext = '<ul>';
 7106:                 foreach my $type (@username_rule) {
 7107:                     if (ref($rules->{$type}) eq 'HASH') {
 7108:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 7109:                     }
 7110:                 }
 7111:                 $chgtext .= '</ul>';
 7112:                 if (@username_rule > 0) {
 7113:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 7114:                 } else {
 7115:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 7116:                 }
 7117:             }
 7118:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 7119:                 my ($idrules,$idruleorder) = 
 7120:                     &Apache::lonnet::inst_userrules($dom,'id');
 7121:                 my $chgtext = '<ul>';
 7122:                 foreach my $type (@id_rule) {
 7123:                     if (ref($idrules->{$type}) eq 'HASH') {
 7124:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 7125:                     }
 7126:                 }
 7127:                 $chgtext .= '</ul>';
 7128:                 if (@id_rule > 0) {
 7129:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 7130:                 } else {
 7131:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 7132:                 }
 7133:             }
 7134:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 7135:                 my ($emailrules,$emailruleorder) =
 7136:                     &Apache::lonnet::inst_userrules($dom,'email');
 7137:                 my $chgtext = '<ul>';
 7138:                 foreach my $type (@email_rule) {
 7139:                     if (ref($emailrules->{$type}) eq 'HASH') {
 7140:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 7141:                     }
 7142:                 }
 7143:                 $chgtext .= '</ul>';
 7144:                 if (@email_rule > 0) {
 7145:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
 7146:                 } else {
 7147:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
 7148:                 }
 7149:             }
 7150: 
 7151:             my %authname = &authtype_names();
 7152:             my %context_title = &context_names();
 7153:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 7154:                 my $chgtext = '<ul>';
 7155:                 foreach my $type (@{$changes{'authtypes'}}) {
 7156:                     my @allowed;
 7157:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 7158:                     foreach my $auth (@authtypes) {
 7159:                         if ($authhash{$type}{$auth}) {
 7160:                             push(@allowed,$authname{$auth});
 7161:                         }
 7162:                     }
 7163:                     if (@allowed > 0) {
 7164:                         $chgtext .= join(', ',@allowed).'</li>';
 7165:                     } else {
 7166:                         $chgtext .= &mt('none').'</li>';
 7167:                     }
 7168:                 }
 7169:                 $chgtext .= '</ul>';
 7170:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 7171:                 $resulttext .= '</li>';
 7172:             }
 7173:             $resulttext .= '</ul>';
 7174:         } else {
 7175:             $resulttext = &mt('No changes made to user creation settings');
 7176:         }
 7177:     } else {
 7178:         $resulttext = '<span class="LC_error">'.
 7179:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7180:     }
 7181:     if ($warningmsg ne '') {
 7182:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 7183:     }
 7184:     return $resulttext;
 7185: }
 7186: 
 7187: sub process_captcha {
 7188:     my ($container,$changes,$newsettings,$current) = @_;
 7189:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
 7190:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
 7191:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
 7192:         $newsettings->{'captcha'} = 'original';
 7193:     }
 7194:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
 7195:         if ($container eq 'cancreate') {
 7196:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 7197:                 push(@{$changes->{'cancreate'}},'captcha');
 7198:             } elsif (!defined($changes->{'cancreate'})) {
 7199:                 $changes->{'cancreate'} = ['captcha'];
 7200:             }
 7201:         } else {
 7202:             $changes->{'captcha'} = 1;
 7203:         }
 7204:     }
 7205:     my ($newpub,$newpriv,$currpub,$currpriv);
 7206:     if ($newsettings->{'captcha'} eq 'recaptcha') {
 7207:         $newpub = $env{'form.'.$container.'_recaptchapub'};
 7208:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
 7209:         $newpub =~ s/\W//g;
 7210:         $newpriv =~ s/\W//g;
 7211:         $newsettings->{'recaptchakeys'} = {
 7212:                                              public  => $newpub,
 7213:                                              private => $newpriv,
 7214:                                           };
 7215:     }
 7216:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
 7217:         $currpub = $current->{'recaptchakeys'}{'public'};
 7218:         $currpriv = $current->{'recaptchakeys'}{'private'};
 7219:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
 7220:             $newsettings->{'recaptchakeys'} = {
 7221:                                                  public  => '',
 7222:                                                  private => '',
 7223:                                               }
 7224:         }
 7225:     }
 7226:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
 7227:         if ($container eq 'cancreate') {
 7228:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
 7229:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
 7230:             } elsif (!defined($changes->{'cancreate'})) {
 7231:                 $changes->{'cancreate'} = ['recaptchakeys'];
 7232:             }
 7233:         } else {
 7234:             $changes->{'recaptchakeys'} = 1;
 7235:         }
 7236:     }
 7237:     return;
 7238: }
 7239: 
 7240: sub modify_usermodification {
 7241:     my ($dom,%domconfig) = @_;
 7242:     my ($resulttext,%curr_usermodification,%changes);
 7243:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 7244:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 7245:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 7246:         }
 7247:     }
 7248:     my @contexts = ('author','course','selfcreate');
 7249:     my %context_title = (
 7250:                            author => 'In author context',
 7251:                            course => 'In course context',
 7252:                            selfcreate => 'When self creating account', 
 7253:                         );
 7254:     my @fields = ('lastname','firstname','middlename','generation',
 7255:                   'permanentemail','id');
 7256:     my %roles = (
 7257:                   author => ['ca','aa'],
 7258:                   course => ['st','ep','ta','in','cr'],
 7259:                 );
 7260:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 7261:     if (ref($types) eq 'ARRAY') {
 7262:         push(@{$types},'default');
 7263:         $usertypes->{'default'} = $othertitle;
 7264:     }
 7265:     $roles{'selfcreate'} = $types;  
 7266:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 7267:     my %modifyhash;
 7268:     foreach my $context (@contexts) {
 7269:         foreach my $role (@{$roles{$context}}) {
 7270:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 7271:             foreach my $item (@fields) {
 7272:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 7273:                     $modifyhash{$context}{$role}{$item} = 1;
 7274:                 } else {
 7275:                     $modifyhash{$context}{$role}{$item} = 0;
 7276:                 }
 7277:             }
 7278:         }
 7279:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 7280:             foreach my $role (@{$roles{$context}}) {
 7281:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 7282:                     foreach my $field (@fields) {
 7283:                         if ($modifyhash{$context}{$role}{$field} ne 
 7284:                                 $curr_usermodification{$context}{$role}{$field}) {
 7285:                             push(@{$changes{$context}},$role);
 7286:                             last;
 7287:                         }
 7288:                     }
 7289:                 }
 7290:             }
 7291:         } else {
 7292:             foreach my $context (@contexts) {
 7293:                 foreach my $role (@{$roles{$context}}) {
 7294:                     push(@{$changes{$context}},$role);
 7295:                 }
 7296:             }
 7297:         }
 7298:     }
 7299:     my %usermodification_hash =  (
 7300:                                    usermodification => \%modifyhash,
 7301:                                  );
 7302:     my $putresult = &Apache::lonnet::put_dom('configuration',
 7303:                                              \%usermodification_hash,$dom);
 7304:     if ($putresult eq 'ok') {
 7305:         if (keys(%changes) > 0) {
 7306:             $resulttext = &mt('Changes made: ').'<ul>';
 7307:             foreach my $context (@contexts) {
 7308:                 if (ref($changes{$context}) eq 'ARRAY') {
 7309:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 7310:                     if (ref($changes{$context}) eq 'ARRAY') {
 7311:                         foreach my $role (@{$changes{$context}}) {
 7312:                             my $rolename;
 7313:                             if ($context eq 'selfcreate') {
 7314:                                 $rolename = $role;
 7315:                                 if (ref($usertypes) eq 'HASH') {
 7316:                                     if ($usertypes->{$role} ne '') {
 7317:                                         $rolename = $usertypes->{$role};
 7318:                                     }
 7319:                                 }
 7320:                             } else {
 7321:                                 if ($role eq 'cr') {
 7322:                                     $rolename = &mt('Custom');
 7323:                                 } else {
 7324:                                     $rolename = &Apache::lonnet::plaintext($role);
 7325:                                 }
 7326:                             }
 7327:                             my @modifiable;
 7328:                             if ($context eq 'selfcreate') {
 7329:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
 7330:                             } else {
 7331:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 7332:                             }
 7333:                             foreach my $field (@fields) {
 7334:                                 if ($modifyhash{$context}{$role}{$field}) {
 7335:                                     push(@modifiable,$fieldtitles{$field});
 7336:                                 }
 7337:                             }
 7338:                             if (@modifiable > 0) {
 7339:                                 $resulttext .= join(', ',@modifiable);
 7340:                             } else {
 7341:                                 $resulttext .= &mt('none'); 
 7342:                             }
 7343:                             $resulttext .= '</li>';
 7344:                         }
 7345:                         $resulttext .= '</ul></li>';
 7346:                     }
 7347:                 }
 7348:             }
 7349:             $resulttext .= '</ul>';
 7350:         } else {
 7351:             $resulttext = &mt('No changes made to user modification settings');
 7352:         }
 7353:     } else {
 7354:         $resulttext = '<span class="LC_error">'.
 7355:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7356:     }
 7357:     return $resulttext;
 7358: }
 7359: 
 7360: sub modify_defaults {
 7361:     my ($dom,$r) = @_;
 7362:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 7363:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 7364:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
 7365:     my @authtypes = ('internal','krb4','krb5','localauth');
 7366:     foreach my $item (@items) {
 7367:         $newvalues{$item} = $env{'form.'.$item};
 7368:         if ($item eq 'auth_def') {
 7369:             if ($newvalues{$item} ne '') {
 7370:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 7371:                     push(@errors,$item);
 7372:                 }
 7373:             }
 7374:         } elsif ($item eq 'lang_def') {
 7375:             if ($newvalues{$item} ne '') {
 7376:                 if ($newvalues{$item} =~ /^(\w+)/) {
 7377:                     my $langcode = $1;
 7378:                     if ($langcode ne 'x_chef') {
 7379:                         if (code2language($langcode) eq '') {
 7380:                             push(@errors,$item);
 7381:                         }
 7382:                     }
 7383:                 } else {
 7384:                     push(@errors,$item);
 7385:                 }
 7386:             }
 7387:         } elsif ($item eq 'timezone_def') {
 7388:             if ($newvalues{$item} ne '') {
 7389:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 7390:                     push(@errors,$item);   
 7391:                 }
 7392:             }
 7393:         } elsif ($item eq 'datelocale_def') {
 7394:             if ($newvalues{$item} ne '') {
 7395:                 my @datelocale_ids = DateTime::Locale->ids();
 7396:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 7397:                     push(@errors,$item);
 7398:                 }
 7399:             }
 7400:         } elsif ($item eq 'portal_def') {
 7401:             if ($newvalues{$item} ne '') {
 7402:                 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])\/?$/) {
 7403:                     push(@errors,$item);
 7404:                 }
 7405:             }
 7406:         }
 7407:         if (grep(/^\Q$item\E$/,@errors)) {
 7408:             $newvalues{$item} = $domdefaults{$item};
 7409:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 7410:             $changes{$item} = 1;
 7411:         }
 7412:         $domdefaults{$item} = $newvalues{$item};
 7413:     }
 7414:     my %defaults_hash = (
 7415:                          defaults => \%newvalues,
 7416:                         );
 7417:     my $title = &defaults_titles();
 7418:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 7419:                                              $dom);
 7420:     if ($putresult eq 'ok') {
 7421:         if (keys(%changes) > 0) {
 7422:             $resulttext = &mt('Changes made:').'<ul>';
 7423:             my $version = $r->dir_config('lonVersion');
 7424:             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";
 7425:             foreach my $item (sort(keys(%changes))) {
 7426:                 my $value = $env{'form.'.$item};
 7427:                 if ($value eq '') {
 7428:                     $value = &mt('none');
 7429:                 } elsif ($item eq 'auth_def') {
 7430:                     my %authnames = &authtype_names();
 7431:                     my %shortauth = (
 7432:                              internal => 'int',
 7433:                              krb4 => 'krb4',
 7434:                              krb5 => 'krb5',
 7435:                              localauth  => 'loc',
 7436:                     );
 7437:                     $value = $authnames{$shortauth{$value}};
 7438:                 }
 7439:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 7440:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
 7441:             }
 7442:             $resulttext .= '</ul>';
 7443:             $mailmsgtext .= "\n";
 7444:             my $cachetime = 24*60*60;
 7445:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 7446:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 7447:                 my $sysmail = $r->dir_config('lonSysEMail');
 7448:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
 7449:             }
 7450:         } else {
 7451:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 7452:         }
 7453:     } else {
 7454:         $resulttext = '<span class="LC_error">'.
 7455:             &mt('An error occurred: [_1]',$putresult).'</span>';
 7456:     }
 7457:     if (@errors > 0) {
 7458:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 7459:         foreach my $item (@errors) {
 7460:             $resulttext .= ' "'.$title->{$item}.'",';
 7461:         }
 7462:         $resulttext =~ s/,$//;
 7463:     }
 7464:     return $resulttext;
 7465: }
 7466: 
 7467: sub modify_scantron {
 7468:     my ($r,$dom,$confname,%domconfig) = @_;
 7469:     my ($resulttext,%confhash,%changes,$errors);
 7470:     my $custom = 'custom.tab';
 7471:     my $default = 'default.tab';
 7472:     my $servadm = $r->dir_config('lonAdmEMail');
 7473:     my ($configuserok,$author_ok,$switchserver) = 
 7474:         &config_check($dom,$confname,$servadm);
 7475:     if ($env{'form.scantronformat.filename'} ne '') {
 7476:         my $error;
 7477:         if ($configuserok eq 'ok') {
 7478:             if ($switchserver) {
 7479:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
 7480:             } else {
 7481:                 if ($author_ok eq 'ok') {
 7482:                     my ($result,$scantronurl) =
 7483:                         &publishlogo($r,'upload','scantronformat',$dom,
 7484:                                      $confname,'scantron','','',$custom);
 7485:                     if ($result eq 'ok') {
 7486:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 7487:                         $changes{'scantronformat'} = 1;
 7488:                     } else {
 7489:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 7490:                     }
 7491:                 } else {
 7492:                     $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);
 7493:                 }
 7494:             }
 7495:         } else {
 7496:             $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);
 7497:         }
 7498:         if ($error) {
 7499:             &Apache::lonnet::logthis($error);
 7500:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 7501:         }
 7502:     }
 7503:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 7504:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 7505:             if ($env{'form.scantronformat_del'}) {
 7506:                 $confhash{'scantron'}{'scantronformat'} = '';
 7507:                 $changes{'scantronformat'} = 1;
 7508:             }
 7509:         }
 7510:     }
 7511:     if (keys(%confhash) > 0) {
 7512:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 7513:                                                  $dom);
 7514:         if ($putresult eq 'ok') {
 7515:             if (keys(%changes) > 0) {
 7516:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 7517:                     $resulttext = &mt('Changes made:').'<ul>';
 7518:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 7519:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 7520:                     } else {
 7521:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 7522:                     }
 7523:                     $resulttext .= '</ul>';
 7524:                 } else {
 7525:                     $resulttext = &mt('Changes made to bubblesheet format file.');
 7526:                 }
 7527:                 $resulttext .= '</ul>';
 7528:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 7529:             } else {
 7530:                 $resulttext = &mt('No changes made to bubblesheet format file');
 7531:             }
 7532:         } else {
 7533:             $resulttext = '<span class="LC_error">'.
 7534:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 7535:         }
 7536:     } else {
 7537:         $resulttext = &mt('No changes made to bubblesheet format file'); 
 7538:     }
 7539:     if ($errors) {
 7540:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 7541:                        $errors.'</ul>';
 7542:     }
 7543:     return $resulttext;
 7544: }
 7545: 
 7546: sub modify_coursecategories {
 7547:     my ($dom,%domconfig) = @_;
 7548:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 7549:         $cathash);
 7550:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 7551:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 7552:         $cathash = $domconfig{'coursecategories'}{'cats'};
 7553:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 7554:             $changes{'togglecats'} = 1;
 7555:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 7556:         }
 7557:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 7558:             $changes{'categorize'} = 1;
 7559:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 7560:         }
 7561:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
 7562:             $changes{'togglecatscomm'} = 1;
 7563:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
 7564:         }
 7565:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
 7566:             $changes{'categorizecomm'} = 1;
 7567:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
 7568:         }
 7569:     } else {
 7570:         $changes{'togglecats'} = 1;
 7571:         $changes{'categorize'} = 1;
 7572:         $changes{'togglecatscomm'} = 1;
 7573:         $changes{'categorizecomm'} = 1;
 7574:         $domconfig{'coursecategories'} = {
 7575:                                              togglecats => $env{'form.togglecats'},
 7576:                                              categorize => $env{'form.categorize'},
 7577:                                              togglecatscomm => $env{'form.togglecatscomm'},
 7578:                                              categorizecomm => $env{'form.categorizecomm'},
 7579:                                          };
 7580:     }
 7581:     if (ref($cathash) eq 'HASH') {
 7582:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 7583:             push (@deletecategory,'instcode::0');
 7584:         }
 7585:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
 7586:             push(@deletecategory,'communities::0');
 7587:         }
 7588:     }
 7589:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 7590:     if (ref($cathash) eq 'HASH') {
 7591:         if (@deletecategory > 0) {
 7592:             #FIXME Need to remove category from all courses using a deleted category 
 7593:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 7594:             foreach my $item (@deletecategory) {
 7595:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 7596:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 7597:                     $deletions{$item} = 1;
 7598:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 7599:                 }
 7600:             }
 7601:         }
 7602:         foreach my $item (keys(%{$cathash})) {
 7603:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 7604:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 7605:                 $reorderings{$item} = 1;
 7606:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 7607:             }
 7608:             if ($env{'form.addcategory_name_'.$item} ne '') {
 7609:                 my $newcat = $env{'form.addcategory_name_'.$item};
 7610:                 my $newdepth = $depth+1;
 7611:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 7612:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 7613:                 $adds{$newitem} = 1; 
 7614:             }
 7615:             if ($env{'form.subcat_'.$item} ne '') {
 7616:                 my $newcat = $env{'form.subcat_'.$item};
 7617:                 my $newdepth = $depth+1;
 7618:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 7619:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 7620:                 $adds{$newitem} = 1;
 7621:             }
 7622:         }
 7623:     }
 7624:     if ($env{'form.instcode'} eq '1') {
 7625:         if (ref($cathash) eq 'HASH') {
 7626:             my $newitem = 'instcode::0';
 7627:             if ($cathash->{$newitem} eq '') {  
 7628:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 7629:                 $adds{$newitem} = 1;
 7630:             }
 7631:         } else {
 7632:             my $newitem = 'instcode::0';
 7633:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 7634:             $adds{$newitem} = 1;
 7635:         }
 7636:     }
 7637:     if ($env{'form.communities'} eq '1') {
 7638:         if (ref($cathash) eq 'HASH') {
 7639:             my $newitem = 'communities::0';
 7640:             if ($cathash->{$newitem} eq '') {
 7641:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 7642:                 $adds{$newitem} = 1;
 7643:             }
 7644:         } else {
 7645:             my $newitem = 'communities::0';
 7646:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 7647:             $adds{$newitem} = 1;
 7648:         }
 7649:     }
 7650:     if ($env{'form.addcategory_name'} ne '') {
 7651:         if (($env{'form.addcategory_name'} ne 'instcode') &&
 7652:             ($env{'form.addcategory_name'} ne 'communities')) {
 7653:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 7654:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 7655:             $adds{$newitem} = 1;
 7656:         }
 7657:     }
 7658:     my $putresult;
 7659:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7660:         if (keys(%deletions) > 0) {
 7661:             foreach my $key (keys(%deletions)) {
 7662:                 if ($predelallitems{$key} ne '') {
 7663:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 7664:                 }
 7665:             }
 7666:         }
 7667:         my (@chkcats,@chktrails,%chkallitems);
 7668:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 7669:         if (ref($chkcats[0]) eq 'ARRAY') {
 7670:             my $depth = 0;
 7671:             my $chg = 0;
 7672:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 7673:                 my $name = $chkcats[0][$i];
 7674:                 my $item;
 7675:                 if ($name eq '') {
 7676:                     $chg ++;
 7677:                 } else {
 7678:                     $item = &escape($name).'::0';
 7679:                     if ($chg) {
 7680:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 7681:                     }
 7682:                     $depth ++; 
 7683:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 7684:                     $depth --;
 7685:                 }
 7686:             }
 7687:         }
 7688:     }
 7689:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7690:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 7691:         if ($putresult eq 'ok') {
 7692:             my %title = (
 7693:                          togglecats     => 'Show/Hide a course in catalog',
 7694:                          categorize     => 'Assign a category to a course',
 7695:                          togglecatscomm => 'Show/Hide a community in catalog',
 7696:                          categorizecomm => 'Assign a category to a community',
 7697:                         );
 7698:             my %level = (
 7699:                          dom  => 'set in Domain ("Modify Course/Community")',
 7700:                          crs  => 'set in Course ("Course Configuration")',
 7701:                          comm => 'set in Community ("Community Configuration")',
 7702:                         );
 7703:             $resulttext = &mt('Changes made:').'<ul>';
 7704:             if ($changes{'togglecats'}) {
 7705:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 7706:             }
 7707:             if ($changes{'categorize'}) {
 7708:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 7709:             }
 7710:             if ($changes{'togglecatscomm'}) {
 7711:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
 7712:             }
 7713:             if ($changes{'categorizecomm'}) {
 7714:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
 7715:             }
 7716:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 7717:                 my $cathash;
 7718:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 7719:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 7720:                 } else {
 7721:                     $cathash = {};
 7722:                 } 
 7723:                 my (@cats,@trails,%allitems);
 7724:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 7725:                 if (keys(%deletions) > 0) {
 7726:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 7727:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 7728:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 7729:                     }
 7730:                     $resulttext .= '</ul></li>';
 7731:                 }
 7732:                 if (keys(%reorderings) > 0) {
 7733:                     my %sort_by_trail;
 7734:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 7735:                     foreach my $key (keys(%reorderings)) {
 7736:                         if ($allitems{$key} ne '') {
 7737:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 7738:                         }
 7739:                     }
 7740:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 7741:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 7742:                     }
 7743:                     $resulttext .= '</ul></li>';
 7744:                 }
 7745:                 if (keys(%adds) > 0) {
 7746:                     my %sort_by_trail;
 7747:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
 7748:                     foreach my $key (keys(%adds)) {
 7749:                         if ($allitems{$key} ne '') {
 7750:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 7751:                         }
 7752:                     }
 7753:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 7754:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 7755:                     }
 7756:                     $resulttext .= '</ul></li>';
 7757:                 }
 7758:             }
 7759:             $resulttext .= '</ul>';
 7760:         } else {
 7761:             $resulttext = '<span class="LC_error">'.
 7762:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 7763:         }
 7764:     } else {
 7765:         $resulttext = &mt('No changes made to course and community categories');
 7766:     }
 7767:     return $resulttext;
 7768: }
 7769: 
 7770: sub modify_serverstatuses {
 7771:     my ($dom,%domconfig) = @_;
 7772:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
 7773:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
 7774:         %currserverstatus = %{$domconfig{'serverstatuses'}};
 7775:     }
 7776:     my @pages = &serverstatus_pages();
 7777:     foreach my $type (@pages) {
 7778:         $newserverstatus{$type}{'namedusers'} = '';
 7779:         $newserverstatus{$type}{'machines'} = '';
 7780:         if (defined($env{'form.'.$type.'_namedusers'})) {
 7781:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
 7782:             my @okusers;
 7783:             foreach my $user (@users) {
 7784:                 my ($uname,$udom) = split(/:/,$user);
 7785:                 if (($udom =~ /^$match_domain$/) &&   
 7786:                     (&Apache::lonnet::domain($udom)) &&
 7787:                     ($uname =~ /^$match_username$/)) {
 7788:                     if (!grep(/^\Q$user\E/,@okusers)) {
 7789:                         push(@okusers,$user);
 7790:                     }
 7791:                 }
 7792:             }
 7793:             if (@okusers > 0) {
 7794:                  @okusers = sort(@okusers);
 7795:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
 7796:             }
 7797:         }
 7798:         if (defined($env{'form.'.$type.'_machines'})) {
 7799:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
 7800:             my @okmachines;
 7801:             foreach my $ip (@machines) {
 7802:                 my @parts = split(/\./,$ip);
 7803:                 next if (@parts < 4);
 7804:                 my $badip = 0;
 7805:                 for (my $i=0; $i<4; $i++) {
 7806:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
 7807:                         $badip = 1;
 7808:                         last;
 7809:                     }
 7810:                 }
 7811:                 if (!$badip) {
 7812:                     push(@okmachines,$ip);     
 7813:                 }
 7814:             }
 7815:             @okmachines = sort(@okmachines);
 7816:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
 7817:         }
 7818:     }
 7819:     my %serverstatushash =  (
 7820:                                 serverstatuses => \%newserverstatus,
 7821:                             );
 7822:     foreach my $type (@pages) {
 7823:         foreach my $setting ('namedusers','machines') {
 7824:             my (@current,@new);
 7825:             if (ref($currserverstatus{$type}) eq 'HASH') {
 7826:                 if ($currserverstatus{$type}{$setting} ne '') { 
 7827:                     @current = split(/,/,$currserverstatus{$type}{$setting});
 7828:                 }
 7829:             }
 7830:             if ($newserverstatus{$type}{$setting} ne '') {
 7831:                 @new = split(/,/,$newserverstatus{$type}{$setting});
 7832:             }
 7833:             if (@current > 0) {
 7834:                 if (@new > 0) {
 7835:                     foreach my $item (@current) {
 7836:                         if (!grep(/^\Q$item\E$/,@new)) {
 7837:                             $changes{$type}{$setting} = 1;
 7838:                             last;
 7839:                         }
 7840:                     }
 7841:                     foreach my $item (@new) {
 7842:                         if (!grep(/^\Q$item\E$/,@current)) {
 7843:                             $changes{$type}{$setting} = 1;
 7844:                             last;
 7845:                         }
 7846:                     }
 7847:                 } else {
 7848:                     $changes{$type}{$setting} = 1;
 7849:                 }
 7850:             } elsif (@new > 0) {
 7851:                 $changes{$type}{$setting} = 1;
 7852:             }
 7853:         }
 7854:     }
 7855:     if (keys(%changes) > 0) {
 7856:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 7857:         my $putresult = &Apache::lonnet::put_dom('configuration',
 7858:                                                  \%serverstatushash,$dom);
 7859:         if ($putresult eq 'ok') {
 7860:             $resulttext .= &mt('Changes made:').'<ul>';
 7861:             foreach my $type (@pages) {
 7862:                 if (ref($changes{$type}) eq 'HASH') {
 7863:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
 7864:                     if ($changes{$type}{'namedusers'}) {
 7865:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
 7866:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
 7867:                         } else {
 7868:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
 7869:                         }
 7870:                     }
 7871:                     if ($changes{$type}{'machines'}) {
 7872:                         if ($newserverstatus{$type}{'machines'} eq '') {
 7873:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
 7874:                         } else {
 7875:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
 7876:                         }
 7877: 
 7878:                     }
 7879:                     $resulttext .= '</ul></li>';
 7880:                 }
 7881:             }
 7882:             $resulttext .= '</ul>';
 7883:         } else {
 7884:             $resulttext = '<span class="LC_error">'.
 7885:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
 7886: 
 7887:         }
 7888:     } else {
 7889:         $resulttext = &mt('No changes made to access to server status pages');
 7890:     }
 7891:     return $resulttext;
 7892: }
 7893: 
 7894: sub modify_helpsettings {
 7895:     my ($r,$dom,$confname,%domconfig) = @_;
 7896:     my ($resulttext,$errors,%changes,%helphash);
 7897:     my %defaultchecked = ('submitbugs' => 'on');
 7898:     my @offon = ('off','on');
 7899:     my @toggles = ('submitbugs');
 7900:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
 7901:         foreach my $item (@toggles) {
 7902:             if ($defaultchecked{$item} eq 'on') { 
 7903:                 if ($domconfig{'helpsettings'}{$item} eq '') {
 7904:                     if ($env{'form.'.$item} eq '0') {
 7905:                         $changes{$item} = 1;
 7906:                     }
 7907:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 7908:                     $changes{$item} = 1;
 7909:                 }
 7910:             } elsif ($defaultchecked{$item} eq 'off') {
 7911:                 if ($domconfig{'helpsettings'}{$item} eq '') {
 7912:                     if ($env{'form.'.$item} eq '1') {
 7913:                         $changes{$item} = 1;
 7914:                     }
 7915:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 7916:                     $changes{$item} = 1;
 7917:                 }
 7918: 	    }
 7919:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
 7920:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
 7921:             }
 7922:         }
 7923:     }
 7924:     my $putresult;
 7925:     if (keys(%changes) > 0) {
 7926:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
 7927:         if ($putresult eq 'ok') {
 7928:             $resulttext = &mt('Changes made:').'<ul>';
 7929:             foreach my $item (sort(keys(%changes))) {
 7930:                 if ($item eq 'submitbugs') {
 7931:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
 7932:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
 7933:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
 7934:                 }
 7935:             }
 7936:             $resulttext .= '</ul>';
 7937:         } else {
 7938:             $resulttext = &mt('No changes made to help settings');
 7939:             $errors .= '<li><span class="LC_error">'.
 7940:                        &mt('An error occurred storing the settings: [_1]',
 7941:                            $putresult).'</span></li>';
 7942:         }
 7943:     }
 7944:     if ($errors) {
 7945:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 7946:                        $errors.'</ul>';
 7947:     }
 7948:     return $resulttext;
 7949: }
 7950: 
 7951: sub modify_coursedefaults {
 7952:     my ($dom,%domconfig) = @_;
 7953:     my ($resulttext,$errors,%changes,%defaultshash);
 7954:     my %defaultchecked = ('canuse_pdfforms' => 'off');
 7955:     my @toggles = ('canuse_pdfforms');
 7956:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
 7957:                    'uploadquota_community');
 7958:     my @types = ('official','unofficial','community');
 7959:     my %staticdefaults = (
 7960:                            anonsurvey_threshold => 10,
 7961:                            uploadquota          => 500,
 7962:                          );
 7963: 
 7964:     $defaultshash{'coursedefaults'} = {};
 7965: 
 7966:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
 7967:         if ($domconfig{'coursedefaults'} eq '') {
 7968:             $domconfig{'coursedefaults'} = {};
 7969:         }
 7970:     }
 7971: 
 7972:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
 7973:         foreach my $item (@toggles) {
 7974:             if ($defaultchecked{$item} eq 'on') {
 7975:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 7976:                     ($env{'form.'.$item} eq '0')) {
 7977:                     $changes{$item} = 1;
 7978:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 7979:                     $changes{$item} = 1;
 7980:                 }
 7981:             } elsif ($defaultchecked{$item} eq 'off') {
 7982:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 7983:                     ($env{'form.'.$item} eq '1')) {
 7984:                     $changes{$item} = 1;
 7985:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 7986:                     $changes{$item} = 1;
 7987:                 }
 7988:             }
 7989:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
 7990:         }
 7991:         foreach my $item (@numbers) {
 7992:             my ($currdef,$newdef);
 7993:             my $newdef = $env{'form.'.$item};
 7994:             if ($item eq 'anonsurvey_threshold') {
 7995:                 $currdef = $domconfig{'coursedefaults'}{$item};
 7996:                 $newdef =~ s/\D//g;
 7997:                 if ($newdef eq '' || $newdef < 1) {
 7998:                     $newdef = 1;
 7999:                 }
 8000:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
 8001:             } else {
 8002:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
 8003:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8004:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
 8005:                 }
 8006:                 $newdef =~ s/[^\w.\-]//g;
 8007:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
 8008:             }
 8009:             if ($currdef ne $newdef) {
 8010:                 my $staticdef;
 8011:                 if ($item eq 'anonsurvey_threshold') {
 8012:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
 8013:                         $changes{$item} = 1;
 8014:                     }
 8015:                 } else {
 8016:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
 8017:                         $changes{'uploadquota'} = 1;
 8018:                     }
 8019:                 }
 8020:             }
 8021:         }
 8022:         my $officialcreds = $env{'form.official_credits'};
 8023:         $officialcreds =~ s/^[^\d\.]//g;
 8024:         my $unofficialcreds = $env{'form.unofficial_credits'};
 8025:         $unofficialcreds =~ s/^[^\d\.]//g;
 8026:         if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
 8027:                 ($env{'form.coursecredits'} eq '1')) {
 8028:                 $changes{'coursecredits'} = 1;
 8029:         } else {
 8030:             if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
 8031:                 ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
 8032:                 $changes{'coursecredits'} = 1;
 8033:             }
 8034:         }
 8035:         $defaultshash{'coursedefaults'}{'coursecredits'} = {
 8036:             official   => $officialcreds,
 8037:             unofficial => $unofficialcreds,
 8038:         }
 8039:     }
 8040:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 8041:                                              $dom);
 8042:     if ($putresult eq 'ok') {
 8043:         my %domdefaults;
 8044:         if (keys(%changes) > 0) {
 8045:             if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
 8046:                 %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 8047:                 if ($changes{'canuse_pdfforms'}) {
 8048:                     $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
 8049:                 }
 8050:                 if ($changes{'coursecredits'}) {
 8051:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
 8052:                         $domdefaults{'officialcredits'} =
 8053:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
 8054:                         $domdefaults{'unofficialcredits'} =
 8055:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
 8056:                     }
 8057:                 }
 8058:                 if ($changes{'uploadquota'}) {
 8059:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8060:                         foreach my $type (@types) {
 8061:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
 8062:                         }
 8063:                     }
 8064:                 }
 8065:                 my $cachetime = 24*60*60;
 8066:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 8067:             }
 8068:             $resulttext = &mt('Changes made:').'<ul>';
 8069:             foreach my $item (sort(keys(%changes))) {
 8070:                 if ($item eq 'canuse_pdfforms') {
 8071:                     if ($env{'form.'.$item} eq '1') {
 8072:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
 8073:                     } else {
 8074:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
 8075:                     }
 8076:                 } elsif ($item eq 'anonsurvey_threshold') {
 8077:                         $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
 8078:                 } elsif ($item eq 'uploadquota') {
 8079:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
 8080:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
 8081:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
 8082:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
 8083:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
 8084:                                        '</ul>'.
 8085:                                        '</li>';
 8086:                     } else {
 8087:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
 8088:                     }
 8089:                 } elsif ($item eq 'coursecredits') {
 8090:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
 8091:                         if (($domdefaults{'officialcredits'} eq '') &&
 8092:                             ($domdefaults{'unofficialcredits'} eq '')) {
 8093:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
 8094:                         } else {
 8095:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
 8096:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
 8097:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
 8098:                                            '</ul>'.
 8099:                                            '</li>';
 8100:                         }
 8101:                     } else {
 8102:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
 8103:                     }
 8104:                 }
 8105:             }
 8106:             $resulttext .= '</ul>';
 8107:         } else {
 8108:             $resulttext = &mt('No changes made to course defaults');
 8109:         }
 8110:     } else {
 8111:         $resulttext = '<span class="LC_error">'.
 8112:             &mt('An error occurred: [_1]',$putresult).'</span>';
 8113:     }
 8114:     return $resulttext;
 8115: }
 8116: 
 8117: sub modify_usersessions {
 8118:     my ($dom,%domconfig) = @_;
 8119:     my @hostingtypes = ('version','excludedomain','includedomain');
 8120:     my @offloadtypes = ('primary','default');
 8121:     my %types = (
 8122:                   remote => \@hostingtypes,
 8123:                   hosted => \@hostingtypes,
 8124:                   spares => \@offloadtypes,
 8125:                 );
 8126:     my @prefixes = ('remote','hosted','spares');
 8127:     my @lcversions = &Apache::lonnet::all_loncaparevs();
 8128:     my (%by_ip,%by_location,@intdoms);
 8129:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 8130:     my @locations = sort(keys(%by_location));
 8131:     my (%defaultshash,%changes);
 8132:     foreach my $prefix (@prefixes) {
 8133:         $defaultshash{'usersessions'}{$prefix} = {};
 8134:     }
 8135:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 8136:     my $resulttext;
 8137:     my %iphost = &Apache::lonnet::get_iphost();
 8138:     foreach my $prefix (@prefixes) {
 8139:         next if ($prefix eq 'spares');
 8140:         foreach my $type (@{$types{$prefix}}) {
 8141:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
 8142:             if ($type eq 'version') {
 8143:                 my $value = $env{'form.'.$prefix.'_'.$type};
 8144:                 my $okvalue;
 8145:                 if ($value ne '') {
 8146:                     if (grep(/^\Q$value\E$/,@lcversions)) {
 8147:                         $okvalue = $value;
 8148:                     }
 8149:                 }
 8150:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8151:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 8152:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
 8153:                             if ($inuse == 0) {
 8154:                                 $changes{$prefix}{$type} = 1;
 8155:                             } else {
 8156:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
 8157:                                     $changes{$prefix}{$type} = 1;
 8158:                                 }
 8159:                                 if ($okvalue ne '') {
 8160:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8161:                                 } 
 8162:                             }
 8163:                         } else {
 8164:                             if (($inuse == 1) && ($okvalue ne '')) {
 8165:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8166:                                 $changes{$prefix}{$type} = 1;
 8167:                             }
 8168:                         }
 8169:                     } else {
 8170:                         if (($inuse == 1) && ($okvalue ne '')) {
 8171:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8172:                             $changes{$prefix}{$type} = 1;
 8173:                         }
 8174:                     }
 8175:                 } else {
 8176:                     if (($inuse == 1) && ($okvalue ne '')) {
 8177:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 8178:                         $changes{$prefix}{$type} = 1;
 8179:                     }
 8180:                 }
 8181:             } else {
 8182:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
 8183:                 my @okvals;
 8184:                 foreach my $val (@vals) {
 8185:                     if ($val =~ /:/) {
 8186:                         my @items = split(/:/,$val);
 8187:                         foreach my $item (@items) {
 8188:                             if (ref($by_location{$item}) eq 'ARRAY') {
 8189:                                 push(@okvals,$item);
 8190:                             }
 8191:                         }
 8192:                     } else {
 8193:                         if (ref($by_location{$val}) eq 'ARRAY') {
 8194:                             push(@okvals,$val);
 8195:                         }
 8196:                     }
 8197:                 }
 8198:                 @okvals = sort(@okvals);
 8199:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8200:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 8201:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 8202:                             if ($inuse == 0) {
 8203:                                 $changes{$prefix}{$type} = 1; 
 8204:                             } else {
 8205:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8206:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
 8207:                                 if (@changed > 0) {
 8208:                                     $changes{$prefix}{$type} = 1;
 8209:                                 }
 8210:                             }
 8211:                         } else {
 8212:                             if ($inuse == 1) {
 8213:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8214:                                 $changes{$prefix}{$type} = 1;
 8215:                             }
 8216:                         } 
 8217:                     } else {
 8218:                         if ($inuse == 1) {
 8219:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8220:                             $changes{$prefix}{$type} = 1;
 8221:                         }
 8222:                     }
 8223:                 } else {
 8224:                     if ($inuse == 1) {
 8225:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 8226:                         $changes{$prefix}{$type} = 1;
 8227:                     }
 8228:                 }
 8229:             }
 8230:         }
 8231:     }
 8232: 
 8233:     my @alldoms = &Apache::lonnet::all_domains();
 8234:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 8235:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
 8236:     my $savespares;
 8237: 
 8238:     foreach my $lonhost (sort(keys(%servers))) {
 8239:         my $serverhomeID =
 8240:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
 8241:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
 8242:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
 8243:         my %spareschg;
 8244:         foreach my $type (@{$types{'spares'}}) {
 8245:             my @okspares;
 8246:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
 8247:             foreach my $server (@checked) {
 8248:                 if (&Apache::lonnet::hostname($server) ne '') {
 8249:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
 8250:                         unless (grep(/^\Q$server\E$/,@okspares)) {
 8251:                             push(@okspares,$server);
 8252:                         }
 8253:                     }
 8254:                 }
 8255:             }
 8256:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
 8257:             my $newspare;
 8258:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
 8259:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
 8260:                     $newspare = $new;
 8261:                 }
 8262:             }
 8263:             my @spares;
 8264:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
 8265:                 @spares = sort(@okspares,$newspare);
 8266:             } else {
 8267:                 @spares = sort(@okspares);
 8268:             }
 8269:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
 8270:             if (ref($spareid{$lonhost}) eq 'HASH') {
 8271:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
 8272:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
 8273:                     if (@diffs > 0) {
 8274:                         $spareschg{$type} = 1;
 8275:                     }
 8276:                 }
 8277:             }
 8278:         }
 8279:         if (keys(%spareschg) > 0) {
 8280:             $changes{'spares'}{$lonhost} = \%spareschg;
 8281:         }
 8282:     }
 8283: 
 8284:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
 8285:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
 8286:             if (ref($changes{'spares'}) eq 'HASH') {
 8287:                 if (keys(%{$changes{'spares'}}) > 0) {
 8288:                     $savespares = 1;
 8289:                 }
 8290:             }
 8291:         } else {
 8292:             $savespares = 1;
 8293:         }
 8294:     }
 8295: 
 8296:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
 8297:     if ((keys(%changes) > 0) || ($savespares)) {
 8298:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 8299:                                                  $dom);
 8300:         if ($putresult eq 'ok') {
 8301:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 8302:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
 8303:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
 8304:                 }
 8305:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
 8306:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
 8307:                 }
 8308:             }
 8309:             my $cachetime = 24*60*60;
 8310:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 8311:             if (keys(%changes) > 0) {
 8312:                 my %lt = &usersession_titles();
 8313:                 $resulttext = &mt('Changes made:').'<ul>';
 8314:                 foreach my $prefix (@prefixes) {
 8315:                     if (ref($changes{$prefix}) eq 'HASH') {
 8316:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
 8317:                         if ($prefix eq 'spares') {
 8318:                             if (ref($changes{$prefix}) eq 'HASH') {
 8319:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
 8320:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
 8321:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
 8322:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
 8323:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
 8324:                                         foreach my $type (@{$types{$prefix}}) {
 8325:                                             if ($changes{$prefix}{$lonhost}{$type}) {
 8326:                                                 my $offloadto = &mt('None');
 8327:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
 8328:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
 8329:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
 8330:                                                     }
 8331:                                                 }
 8332:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
 8333:                                             }
 8334:                                         }
 8335:                                     }
 8336:                                     $resulttext .= '</li>';
 8337:                                 }
 8338:                             }
 8339:                         } else {
 8340:                             foreach my $type (@{$types{$prefix}}) {
 8341:                                 if (defined($changes{$prefix}{$type})) {
 8342:                                     my $newvalue;
 8343:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 8344:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
 8345:                                             if ($type eq 'version') {
 8346:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
 8347:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 8348:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
 8349:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
 8350:                                                 }
 8351:                                             }
 8352:                                         }
 8353:                                     }
 8354:                                     if ($newvalue eq '') {
 8355:                                         if ($type eq 'version') {
 8356:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
 8357:                                         } else {
 8358:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
 8359:                                         }
 8360:                                     } else {
 8361:                                         if ($type eq 'version') {
 8362:                                             $newvalue .= ' '.&mt('(or later)'); 
 8363:                                         }
 8364:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
 8365:                                     }
 8366:                                 }
 8367:                             }
 8368:                         }
 8369:                         $resulttext .= '</ul>';
 8370:                     }
 8371:                 }
 8372:                 $resulttext .= '</ul>';
 8373:             } else {
 8374:                 $resulttext = $nochgmsg;
 8375:             }
 8376:         } else {
 8377:             $resulttext = '<span class="LC_error">'.
 8378:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 8379:         }
 8380:     } else {
 8381:         $resulttext = $nochgmsg;
 8382:     }
 8383:     return $resulttext;
 8384: }
 8385: 
 8386: sub modify_loadbalancing {
 8387:     my ($dom,%domconfig) = @_;
 8388:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
 8389:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
 8390:     my ($othertitle,$usertypes,$types) =
 8391:         &Apache::loncommon::sorted_inst_types($dom);
 8392:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
 8393:     my @sparestypes = ('primary','default');
 8394:     my %typetitles = &sparestype_titles();
 8395:     my $resulttext;
 8396:     my (%currbalancer,%currtargets,%currrules,%existing);
 8397:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
 8398:         %existing = %{$domconfig{'loadbalancing'}};
 8399:     }
 8400:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
 8401:                               \%currtargets,\%currrules);
 8402:     my ($saveloadbalancing,%defaultshash,%changes);
 8403:     my ($alltypes,$othertypes,$titles) =
 8404:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
 8405:     my %ruletitles = &offloadtype_text();
 8406:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
 8407:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
 8408:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
 8409:         if ($balancer eq '') {
 8410:             next;
 8411:         }
 8412:         if (!exists($servers{$balancer})) {
 8413:             if (exists($currbalancer{$balancer})) {
 8414:                 push(@{$changes{'delete'}},$balancer);
 8415:             }
 8416:             next;
 8417:         }
 8418:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
 8419:             push(@{$changes{'delete'}},$balancer);
 8420:             next;
 8421:         }
 8422:         if (!exists($currbalancer{$balancer})) {
 8423:             push(@{$changes{'add'}},$balancer);
 8424:         }
 8425:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
 8426:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
 8427:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
 8428:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
 8429:             $saveloadbalancing = 1;
 8430:         }
 8431:         foreach my $sparetype (@sparestypes) {
 8432:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
 8433:             my @offloadto;
 8434:             foreach my $target (@targets) {
 8435:                 if (($servers{$target}) && ($target ne $balancer)) {
 8436:                     if ($sparetype eq 'default') {
 8437:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
 8438:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
 8439:                         }
 8440:                     }
 8441:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
 8442:                         push(@offloadto,$target);
 8443:                     }
 8444:                 }
 8445:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
 8446:             }
 8447:         }
 8448:         if (ref($currtargets{$balancer}) eq 'HASH') {
 8449:             foreach my $sparetype (@sparestypes) {
 8450:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
 8451:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
 8452:                     if (@targetdiffs > 0) {
 8453:                         $changes{'curr'}{$balancer}{'targets'} = 1;
 8454:                     }
 8455:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8456:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8457:                         $changes{'curr'}{$balancer}{'targets'} = 1;
 8458:                     }
 8459:                 }
 8460:             }
 8461:         } else {
 8462:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
 8463:                 foreach my $sparetype (@sparestypes) {
 8464:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8465:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8466:                             $changes{'curr'}{$balancer}{'targets'} = 1;
 8467:                         }
 8468:                     }
 8469:                 }
 8470:             }
 8471:         }
 8472:         my $ishomedom;
 8473:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
 8474:             $ishomedom = 1;
 8475:         }
 8476:         if (ref($alltypes) eq 'ARRAY') {
 8477:             foreach my $type (@{$alltypes}) {
 8478:                 my $rule;
 8479:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
 8480:                          (!$ishomedom)) {
 8481:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
 8482:                 }
 8483:                 if ($rule eq 'specific') {
 8484:                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
 8485:                 }
 8486:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
 8487:                 if (ref($currrules{$balancer}) eq 'HASH') {
 8488:                     if ($rule ne $currrules{$balancer}{$type}) {
 8489:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
 8490:                     }
 8491:                 } elsif ($rule ne '') {
 8492:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
 8493:                 }
 8494:             }
 8495:         }
 8496:     }
 8497:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
 8498:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
 8499:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
 8500:             $defaultshash{'loadbalancing'} = {};
 8501:         }
 8502:         my $putresult = &Apache::lonnet::put_dom('configuration',
 8503:                                                  \%defaultshash,$dom);
 8504: 
 8505:         if ($putresult eq 'ok') {
 8506:             if (keys(%changes) > 0) {
 8507:                 if (ref($changes{'delete'}) eq 'ARRAY') {
 8508:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
 8509:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
 8510:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
 8511:                     }
 8512:                 }
 8513:                 if (ref($changes{'add'}) eq 'ARRAY') {
 8514:                     foreach my $balancer (sort(@{$changes{'add'}})) {
 8515:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
 8516:                     }
 8517:                 }
 8518:                 if (ref($changes{'curr'}) eq 'HASH') {
 8519:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
 8520:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
 8521:                             if ($changes{'curr'}{$balancer}{'targets'}) {
 8522:                                 my %offloadstr;
 8523:                                 foreach my $sparetype (@sparestypes) {
 8524:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
 8525:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
 8526:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
 8527:                                         }
 8528:                                     }
 8529:                                 }
 8530:                                 if (keys(%offloadstr) == 0) {
 8531:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
 8532:                                 } else {
 8533:                                     my $showoffload;
 8534:                                     foreach my $sparetype (@sparestypes) {
 8535:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
 8536:                                         if (defined($offloadstr{$sparetype})) {
 8537:                                             $showoffload .= $offloadstr{$sparetype};
 8538:                                         } else {
 8539:                                             $showoffload .= &mt('None');
 8540:                                         }
 8541:                                         $showoffload .= ('&nbsp;'x3);
 8542:                                     }
 8543:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
 8544:                                 }
 8545:                             }
 8546:                         }
 8547:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
 8548:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
 8549:                                 foreach my $type (@{$alltypes}) {
 8550:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
 8551:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
 8552:                                         my $balancetext;
 8553:                                         if ($rule eq '') {
 8554:                                             $balancetext =  $ruletitles{'default'};
 8555:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
 8556:                                             $balancetext =  $ruletitles{$rule};
 8557:                                         } else {
 8558:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
 8559:                                         }
 8560:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>'; 
 8561:                                     }
 8562:                                 }
 8563:                             }
 8564:                         }
 8565:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
 8566:                     }
 8567:                 }
 8568:                 if ($resulttext ne '') {
 8569:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
 8570:                 } else {
 8571:                     $resulttext = $nochgmsg;
 8572:                 }
 8573:             } else {
 8574:                 $resulttext = $nochgmsg;
 8575:             }
 8576:         } else {
 8577:             $resulttext = '<span class="LC_error">'.
 8578:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 8579:         }
 8580:     } else {
 8581:         $resulttext = $nochgmsg;
 8582:     }
 8583:     return $resulttext;
 8584: }
 8585: 
 8586: sub recurse_check {
 8587:     my ($chkcats,$categories,$depth,$name) = @_;
 8588:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
 8589:         my $chg = 0;
 8590:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
 8591:             my $category = $chkcats->[$depth]{$name}[$j];
 8592:             my $item;
 8593:             if ($category eq '') {
 8594:                 $chg ++;
 8595:             } else {
 8596:                 my $deeper = $depth + 1;
 8597:                 $item = &escape($category).':'.&escape($name).':'.$depth;
 8598:                 if ($chg) {
 8599:                     $categories->{$item} -= $chg;
 8600:                 }
 8601:                 &recurse_check($chkcats,$categories,$deeper,$category);
 8602:                 $deeper --;
 8603:             }
 8604:         }
 8605:     }
 8606:     return;
 8607: }
 8608: 
 8609: sub recurse_cat_deletes {
 8610:     my ($item,$coursecategories,$deletions) = @_;
 8611:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 8612:     my $subdepth = $depth + 1;
 8613:     if (ref($coursecategories) eq 'HASH') {
 8614:         foreach my $subitem (keys(%{$coursecategories})) {
 8615:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
 8616:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
 8617:                 delete($coursecategories->{$subitem});
 8618:                 $deletions->{$subitem} = 1;
 8619:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
 8620:             }  
 8621:         }
 8622:     }
 8623:     return;
 8624: }
 8625: 
 8626: sub get_active_dcs {
 8627:     my ($dom) = @_;
 8628:     my $now = time;
 8629:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
 8630:     my %domcoords;
 8631:     my $numdcs = 0;
 8632:     foreach my $server (keys(%dompersonnel)) {
 8633:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 8634:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 8635:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
 8636:         }
 8637:     }
 8638:     return %domcoords;
 8639: }
 8640: 
 8641: sub active_dc_picker {
 8642:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
 8643:     my %domcoords = &get_active_dcs($dom); 
 8644:     my @domcoord = keys(%domcoords);
 8645:     if (keys(%currhash)) {
 8646:         foreach my $dc (keys(%currhash)) {
 8647:             unless (exists($domcoords{$dc})) {
 8648:                 push(@domcoord,$dc);
 8649:             }
 8650:         }
 8651:     }
 8652:     @domcoord = sort(@domcoord);
 8653:     my $numdcs = scalar(@domcoord);
 8654:     my $rows = 0;
 8655:     my $table;
 8656:     if ($numdcs > 1) {
 8657:         $table = '<table>';
 8658:         for (my $i=0; $i<@domcoord; $i++) {
 8659:             my $rem = $i%($numinrow);
 8660:             if ($rem == 0) {
 8661:                 if ($i > 0) {
 8662:                     $table .= '</tr>';
 8663:                 }
 8664:                 $table .= '<tr>';
 8665:                 $rows ++;
 8666:             }
 8667:             my $check = '';
 8668:             if ($inputtype eq 'radio') {
 8669:                 if (keys(%currhash) == 0) {
 8670:                     if (!$i) {
 8671:                         $check = ' checked="checked"';
 8672:                     }
 8673:                 } elsif (exists($currhash{$domcoord[$i]})) {
 8674:                     $check = ' checked="checked"';
 8675:                 }
 8676:             } else {
 8677:                 if (exists($currhash{$domcoord[$i]})) {
 8678:                     $check = ' checked="checked"';
 8679:                 }
 8680:             }
 8681:             if ($i == @domcoord - 1) {
 8682:                 my $colsleft = $numinrow - $rem;
 8683:                 if ($colsleft > 1) {
 8684:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
 8685:                 } else {
 8686:                     $table .= '<td class="LC_left_item">';
 8687:                 }
 8688:             } else {
 8689:                 $table .= '<td class="LC_left_item">';
 8690:             }
 8691:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
 8692:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
 8693:             $table .= '<span class="LC_nobreak"><label>'.
 8694:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
 8695:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
 8696:             if ($user ne $dcname.':'.$dcdom) {
 8697:                 $table .=  ' ('.$dcname.':'.$dcdom.')'.
 8698:                            '</label></span></td>';
 8699:             }
 8700:         }
 8701:         $table .= '</tr></table>';
 8702:     } elsif ($numdcs == 1) {
 8703:         if ($inputtype eq 'radio') {
 8704:             $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
 8705:         } else {
 8706:             my $check;
 8707:             if (exists($currhash{$domcoord[0]})) {
 8708:                 $check = ' checked="checked"';
 8709:             }
 8710:             $table .= '<input type="checkbox" name="'.$name.'" '.
 8711:                       'value="'.$domcoord[0].'"'.$check.' />';
 8712:             $rows ++;
 8713:         }
 8714:     }
 8715:     return ($numdcs,$table,$rows);
 8716: }
 8717: 
 8718: sub usersession_titles {
 8719:     return &Apache::lonlocal::texthash(
 8720:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
 8721:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
 8722:                spares => 'Servers offloaded to, when busy',
 8723:                version => 'LON-CAPA version requirement',
 8724:                excludedomain => 'Allow all, but exclude specific domains',
 8725:                includedomain => 'Deny all, but include specific domains',
 8726:                primary => 'Primary (checked first)',
 8727:                default => 'Default',
 8728:            );
 8729: }
 8730: 
 8731: sub id_for_thisdom {
 8732:     my (%servers) = @_;
 8733:     my %altids;
 8734:     foreach my $server (keys(%servers)) {
 8735:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
 8736:         if ($serverhome ne $server) {
 8737:             $altids{$serverhome} = $server;
 8738:         }
 8739:     }
 8740:     return %altids;
 8741: }
 8742: 
 8743: sub count_servers {
 8744:     my ($currbalancer,%servers) = @_;
 8745:     my (@spares,$numspares);
 8746:     foreach my $lonhost (sort(keys(%servers))) {
 8747:         next if ($currbalancer eq $lonhost);
 8748:         push(@spares,$lonhost);
 8749:     }
 8750:     if ($currbalancer) {
 8751:         $numspares = scalar(@spares);
 8752:     } else {
 8753:         $numspares = scalar(@spares) - 1;
 8754:     }
 8755:     return ($numspares,@spares);
 8756: }
 8757: 
 8758: sub lonbalance_targets_js {
 8759:     my ($dom,$types,$servers,$settings) = @_;
 8760:     my $select = &mt('Select');
 8761:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
 8762:     if (ref($servers) eq 'HASH') {
 8763:         $alltargets = join("','",sort(keys(%{$servers})));
 8764:         my @homedoms;
 8765:         foreach my $server (sort(keys(%{$servers}))) {
 8766:             if (&Apache::lonnet::host_domain($server) eq $dom) {
 8767:                 push(@homedoms,'1');
 8768:             } else {
 8769:                 push(@homedoms,'0');
 8770:             }
 8771:         }
 8772:         $allishome = join("','",@homedoms);
 8773:     }
 8774:     if (ref($types) eq 'ARRAY') {
 8775:         if (@{$types} > 0) {
 8776:             @alltypes = @{$types};
 8777:         }
 8778:     }
 8779:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
 8780:     $allinsttypes = join("','",@alltypes);
 8781:     my (%currbalancer,%currtargets,%currrules,%existing);
 8782:     if (ref($settings) eq 'HASH') {
 8783:         %existing = %{$settings};
 8784:     }
 8785:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
 8786:                               \%currtargets,\%currrules);
 8787:     my $balancers = join("','",sort(keys(%currbalancer)));
 8788:     return <<"END";
 8789: 
 8790: <script type="text/javascript">
 8791: // <![CDATA[
 8792: 
 8793: currBalancers = new Array('$balancers');
 8794: 
 8795: function toggleTargets(balnum) {
 8796:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
 8797:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
 8798:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
 8799:     var prevbalancer = prevhostitem.value;
 8800:     var baltotal = document.getElementById('loadbalancing_total').value;
 8801:     prevhostitem.value = balancer;
 8802:     if (prevbalancer != '') {
 8803:         var prevIdx = currBalancers.indexOf(prevbalancer);
 8804:         if (prevIdx != -1) {
 8805:             currBalancers.splice(prevIdx,1);
 8806:         }
 8807:     }
 8808:     if (balancer == '') {
 8809:         hideSpares(balnum);
 8810:     } else {
 8811:         var currIdx = currBalancers.indexOf(balancer);
 8812:         if (currIdx == -1) {
 8813:             currBalancers.push(balancer);
 8814:         }
 8815:         var homedoms = new Array('$allishome');
 8816:         var ishomedom = homedoms[lonhostitem.selectedIndex];
 8817:         showSpares(balancer,ishomedom,balnum);
 8818:     }
 8819:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
 8820:     return;
 8821: }
 8822: 
 8823: function showSpares(balancer,ishomedom,balnum) {
 8824:     var alltargets = new Array('$alltargets');
 8825:     var insttypes = new Array('$allinsttypes');
 8826:     var offloadtypes = new Array('primary','default');
 8827: 
 8828:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
 8829:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
 8830:  
 8831:     for (var i=0; i<offloadtypes.length; i++) {
 8832:         var count = 0;
 8833:         for (var j=0; j<alltargets.length; j++) {
 8834:             if (alltargets[j] != balancer) {
 8835:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
 8836:                 item.value = alltargets[j];
 8837:                 item.style.textAlign='left';
 8838:                 item.style.textFace='normal';
 8839:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
 8840:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
 8841:                     item.disabled = '';
 8842:                 } else {
 8843:                     item.disabled = 'disabled';
 8844:                     item.checked = false;
 8845:                 }
 8846:                 count ++;
 8847:             }
 8848:         }
 8849:     }
 8850:     for (var k=0; k<insttypes.length; k++) {
 8851:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
 8852:             if (ishomedom == 1) {
 8853:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
 8854:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
 8855:             } else {
 8856:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
 8857:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
 8858: 
 8859:             }
 8860:         } else {
 8861:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
 8862:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
 8863:         }
 8864:         if ((insttypes[k] != '_LC_external') && 
 8865:             ((insttypes[k] != '_LC_internetdom') ||
 8866:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
 8867:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
 8868:             item.options.length = 0;
 8869:             item.options[0] = new Option("","",true,true);
 8870:             var idx = 0;
 8871:             for (var m=0; m<alltargets.length; m++) {
 8872:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
 8873:                     idx ++;
 8874:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
 8875: 
 8876:                 }
 8877:             }
 8878:         }
 8879:     }
 8880:     return;
 8881: }
 8882: 
 8883: function hideSpares(balnum) {
 8884:     var alltargets = new Array('$alltargets');
 8885:     var insttypes = new Array('$allinsttypes');
 8886:     var offloadtypes = new Array('primary','default');
 8887: 
 8888:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
 8889:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
 8890: 
 8891:     var total = alltargets.length - 1;
 8892:     for (var i=0; i<offloadtypes; i++) {
 8893:         for (var j=0; j<total; j++) {
 8894:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
 8895:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
 8896:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
 8897:         }
 8898:     }
 8899:     for (var k=0; k<insttypes.length; k++) {
 8900:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
 8901:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
 8902:         if (insttypes[k] != '_LC_external') {
 8903:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
 8904:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
 8905:         }
 8906:     }
 8907:     return;
 8908: }
 8909: 
 8910: function checkOffloads(item,balnum,type) {
 8911:     var alltargets = new Array('$alltargets');
 8912:     var offloadtypes = new Array('primary','default');
 8913:     if (item.checked) {
 8914:         var total = alltargets.length - 1;
 8915:         var other;
 8916:         if (type == offloadtypes[0]) {
 8917:             other = offloadtypes[1];
 8918:         } else {
 8919:             other = offloadtypes[0];
 8920:         }
 8921:         for (var i=0; i<total; i++) {
 8922:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
 8923:             if (server == item.value) {
 8924:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
 8925:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
 8926:                 }
 8927:             }
 8928:         }
 8929:     }
 8930:     return;
 8931: }
 8932: 
 8933: function singleServerToggle(balnum,type) {
 8934:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
 8935:     if (offloadtoSelIdx == 0) {
 8936:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
 8937:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
 8938: 
 8939:     } else {
 8940:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
 8941:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
 8942:     }
 8943:     return;
 8944: }
 8945: 
 8946: function balanceruleChange(formname,balnum,type) {
 8947:     if (type == '_LC_external') {
 8948:         return; 
 8949:     }
 8950:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
 8951:     for (var i=0; i<typesRules.length; i++) {
 8952:         if (formname.elements[typesRules[i]].checked) {
 8953:             if (formname.elements[typesRules[i]].value != 'specific') {
 8954:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
 8955:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
 8956:             } else {
 8957:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
 8958:             }
 8959:         }
 8960:     }
 8961:     return;
 8962: }
 8963: 
 8964: function balancerDeleteChange(balnum) {
 8965:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
 8966:     var baltotal = document.getElementById('loadbalancing_total').value;
 8967:     var addtarget;
 8968:     var removetarget;
 8969:     var action = 'delete';
 8970:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
 8971:         var lonhost = hostitem.value;
 8972:         var currIdx = currBalancers.indexOf(lonhost);
 8973:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
 8974:             if (currIdx != -1) {
 8975:                 currBalancers.splice(currIdx,1);
 8976:             }
 8977:             addtarget = lonhost;
 8978:         } else {
 8979:             if (currIdx == -1) {
 8980:                 currBalancers.push(lonhost);
 8981:             }
 8982:             removetarget = lonhost;
 8983:             action = 'undelete';
 8984:         }
 8985:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
 8986:     }
 8987:     return;
 8988: }
 8989: 
 8990: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
 8991:     if (baltotal > 1) {
 8992:         var offloadtypes = new Array('primary','default');
 8993:         var alltargets = new Array('$alltargets');
 8994:         var insttypes = new Array('$allinsttypes');
 8995:         for (var i=0; i<baltotal; i++) {
 8996:             if (i != balnum) {
 8997:                 for (var j=0; j<offloadtypes.length; j++) {
 8998:                     var total = alltargets.length - 1;
 8999:                     for (var k=0; k<total; k++) {
 9000:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
 9001:                         var server = serveritem.value;
 9002:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
 9003:                             if (server == addtarget) {
 9004:                                 serveritem.disabled = '';
 9005:                             }
 9006:                         }
 9007:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
 9008:                             if (server == removetarget) {
 9009:                                 serveritem.disabled = 'disabled';
 9010:                                 serveritem.checked = false;
 9011:                             }
 9012:                         }
 9013:                     }
 9014:                 }
 9015:                 for (var j=0; j<insttypes.length; j++) {
 9016:                     if (insttypes[j] != '_LC_external') {
 9017:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
 9018:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
 9019:                             var currSel = singleserver.selectedIndex;
 9020:                             var currVal = singleserver.options[currSel].value;
 9021:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
 9022:                                 var numoptions = singleserver.options.length;
 9023:                                 var needsnew = 1;
 9024:                                 for (var k=0; k<numoptions; k++) {
 9025:                                     if (singleserver.options[k] == addtarget) {
 9026:                                         needsnew = 0;
 9027:                                         break;
 9028:                                     }
 9029:                                 }
 9030:                                 if (needsnew == 1) {
 9031:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
 9032:                                 }
 9033:                             }
 9034:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
 9035:                                 singleserver.options.length = 0;
 9036:                                 if ((currVal) && (currVal != removetarget)) {
 9037:                                     singleserver.options[0] = new Option("","",false,false);
 9038:                                 } else {
 9039:                                     singleserver.options[0] = new Option("","",true,true);
 9040:                                 }
 9041:                                 var idx = 0;
 9042:                                 for (var m=0; m<alltargets.length; m++) {
 9043:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
 9044:                                         idx ++;
 9045:                                         if (currVal == alltargets[m]) {
 9046:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
 9047:                                         } else {
 9048:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
 9049:                                         }
 9050:                                     }
 9051:                                 }
 9052:                             }
 9053:                         }
 9054:                     }
 9055:                 }
 9056:             }
 9057:         }
 9058:     }
 9059:     return;
 9060: }
 9061: 
 9062: // ]]>
 9063: </script>
 9064: 
 9065: END
 9066: }
 9067: 
 9068: sub new_spares_js {
 9069:     my @sparestypes = ('primary','default');
 9070:     my $types = join("','",@sparestypes);
 9071:     my $select = &mt('Select');
 9072:     return <<"END";
 9073: 
 9074: <script type="text/javascript">
 9075: // <![CDATA[
 9076: 
 9077: function updateNewSpares(formname,lonhost) {
 9078:     var types = new Array('$types');
 9079:     var include = new Array();
 9080:     var exclude = new Array();
 9081:     for (var i=0; i<types.length; i++) {
 9082:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
 9083:         for (var j=0; j<spareboxes.length; j++) {
 9084:             if (formname.elements[spareboxes[j]].checked) {
 9085:                 exclude.push(formname.elements[spareboxes[j]].value);
 9086:             } else {
 9087:                 include.push(formname.elements[spareboxes[j]].value);
 9088:             }
 9089:         }
 9090:     }
 9091:     for (var i=0; i<types.length; i++) {
 9092:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
 9093:         var selIdx = newSpare.selectedIndex;
 9094:         var currnew = newSpare.options[selIdx].value;
 9095:         var okSpares = new Array();
 9096:         for (var j=0; j<newSpare.options.length; j++) {
 9097:             var possible = newSpare.options[j].value;
 9098:             if (possible != '') {
 9099:                 if (exclude.indexOf(possible) == -1) {
 9100:                     okSpares.push(possible);
 9101:                 } else {
 9102:                     if (currnew == possible) {
 9103:                         selIdx = 0;
 9104:                     }
 9105:                 }
 9106:             }
 9107:         }
 9108:         for (var k=0; k<include.length; k++) {
 9109:             if (okSpares.indexOf(include[k]) == -1) {
 9110:                 okSpares.push(include[k]);
 9111:             }
 9112:         }
 9113:         okSpares.sort();
 9114:         newSpare.options.length = 0;
 9115:         if (selIdx == 0) {
 9116:             newSpare.options[0] = new Option("$select","",true,true);
 9117:         } else {
 9118:             newSpare.options[0] = new Option("$select","",false,false);
 9119:         }
 9120:         for (var m=0; m<okSpares.length; m++) {
 9121:             var idx = m+1;
 9122:             var selThis = 0;
 9123:             if (selIdx != 0) {
 9124:                 if (okSpares[m] == currnew) {
 9125:                     selThis = 1;
 9126:                 }
 9127:             }
 9128:             if (selThis == 1) {
 9129:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
 9130:             } else {
 9131:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
 9132:             }
 9133:         }
 9134:     }
 9135:     return;
 9136: }
 9137: 
 9138: function checkNewSpares(lonhost,type) {
 9139:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
 9140:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
 9141:     if (chosen != '') { 
 9142:         var othertype;
 9143:         var othernewSpare;
 9144:         if (type == 'primary') {
 9145:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
 9146:         }
 9147:         if (type == 'default') {
 9148:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
 9149:         }
 9150:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
 9151:             othernewSpare.selectedIndex = 0;
 9152:         }
 9153:     }
 9154:     return;
 9155: }
 9156: 
 9157: // ]]>
 9158: </script>
 9159: 
 9160: END
 9161: 
 9162: }
 9163: 
 9164: sub common_domprefs_js {
 9165:     return <<"END";
 9166: 
 9167: <script type="text/javascript">
 9168: // <![CDATA[
 9169: 
 9170: function getIndicesByName(formname,item) {
 9171:     var group = new Array();
 9172:     for (var i=0;i<formname.elements.length;i++) {
 9173:         if (formname.elements[i].name == item) {
 9174:             group.push(formname.elements[i].id);
 9175:         }
 9176:     }
 9177:     return group;
 9178: }
 9179: 
 9180: // ]]>
 9181: </script>
 9182: 
 9183: END
 9184: 
 9185: }
 9186: 
 9187: sub recaptcha_js {
 9188:     my %lt = &captcha_phrases();
 9189:     return <<"END";
 9190: 
 9191: <script type="text/javascript">
 9192: // <![CDATA[
 9193: 
 9194: function updateCaptcha(caller,context) {
 9195:     var privitem;
 9196:     var pubitem;
 9197:     var privtext;
 9198:     var pubtext;
 9199:     if (document.getElementById(context+'_recaptchapub')) {
 9200:         pubitem = document.getElementById(context+'_recaptchapub');
 9201:     } else {
 9202:         return;
 9203:     }
 9204:     if (document.getElementById(context+'_recaptchapriv')) {
 9205:         privitem = document.getElementById(context+'_recaptchapriv');
 9206:     } else {
 9207:         return;
 9208:     }
 9209:     if (document.getElementById(context+'_recaptchapubtxt')) {
 9210:         pubtext = document.getElementById(context+'_recaptchapubtxt');
 9211:     } else {
 9212:         return;
 9213:     }
 9214:     if (document.getElementById(context+'_recaptchaprivtxt')) {
 9215:         privtext = document.getElementById(context+'_recaptchaprivtxt');
 9216:     } else {
 9217:         return;
 9218:     }
 9219:     if (caller.checked) {
 9220:         if (caller.value == 'recaptcha') {
 9221:             pubitem.type = 'text';
 9222:             privitem.type = 'text';
 9223:             pubitem.size = '40';
 9224:             privitem.size = '40';
 9225:             pubtext.innerHTML = "$lt{'pub'}";
 9226:             privtext.innerHTML = "$lt{'priv'}";
 9227:         } else {
 9228:             pubitem.type = 'hidden';
 9229:             privitem.type = 'hidden';
 9230:             pubtext.innerHTML = '';
 9231:             privtext.innerHTML = '';
 9232:         }
 9233:     }
 9234:     return;
 9235: }
 9236: 
 9237: // ]]>
 9238: </script>
 9239: 
 9240: END
 9241: 
 9242: }
 9243: 
 9244: sub credits_js {
 9245:     return <<"END";
 9246: 
 9247: <script type="text/javascript">
 9248: // <![CDATA[
 9249: 
 9250: function toggleCredits(domForm) {
 9251:     if (document.getElementById('credits')) {
 9252:         creditsitem = document.getElementById('credits');
 9253:         var creditsLength = domForm.coursecredits.length;
 9254:         if (creditsLength) {
 9255:             var currval;
 9256:             for (var i=0; i<creditsLength; i++) {
 9257:                 if (domForm.coursecredits[i].checked) {
 9258:                    currval = domForm.coursecredits[i].value;
 9259:                 }
 9260:             }
 9261:             if (currval == 1) {
 9262:                 creditsitem.style.display = 'block';
 9263:             } else {
 9264:                 creditsitem.style.display = 'none';
 9265:             }
 9266:         }
 9267:     }
 9268:     return;
 9269: }
 9270: 
 9271: // ]]>
 9272: </script>
 9273: 
 9274: END
 9275: 
 9276: }
 9277: 
 9278: sub captcha_phrases {
 9279:     return &Apache::lonlocal::texthash (
 9280:                  priv => 'Private key',
 9281:                  pub  => 'Public key',
 9282:                  original  => 'original (CAPTCHA)',
 9283:                  recaptcha => 'successor (ReCAPTCHA)',
 9284:                  notused   => 'unused',
 9285:     );
 9286: }
 9287: 
 9288: 1;

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