Annotation of loncom/interface/domainprefs.pm, revision 1.163

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.163   ! raeburn     4: # $Id: domainprefs.pm,v 1.162 2012/06/01 11:39:24 raeburn Exp $
1.2       albertel    5: #
1.1       raeburn     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: 
1.101     raeburn    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 affliated 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 
1.163   ! raeburn    89: number of rows displayed on the page, and $action is the context (quotas,  
        !            90: requestcourses or requestauthor).
1.101     raeburn    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.
                     98: 
                     99: Outputs: 1
                    100: 
                    101: $datatable  - HTML containing form elements which allow settings to be changed. 
                    102: 
                    103: In the case of course requests, radio buttons are displayed for each institutional
                    104: affiliate type (and also default, and _LC_adv) for each of the course types 
                    105: (official, unofficial and community).  In each case the radio buttons allow the 
                    106: selection of one of four values:
                    107: 
1.104     raeburn   108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   109: which have the following effects:
                    110: 
                    111: 0
                    112: 
                    113: =over
                    114: 
                    115: - course requests are not allowed for this course types/affiliation
                    116: 
                    117: =back
                    118: 
1.104     raeburn   119: approval 
1.101     raeburn   120: 
                    121: =over 
                    122: 
                    123: - course requests must be approved by a Doman Coordinator in the 
                    124: course's domain
                    125: 
                    126: =back
                    127: 
                    128: validate 
                    129: 
                    130: =over
                    131: 
                    132: - an institutional validation (e.g., check requestor is instructor
                    133: of record) needs to be passed before the course will be created.  The required
                    134: validation is in localenroll.pm on the primary library server for the course 
                    135: domain.
                    136: 
                    137: =back
                    138: 
                    139: autolimit 
                    140: 
                    141: =over
                    142:  
1.143     raeburn   143: - course requests will be processed automatically up to a limit of
1.101     raeburn   144: N requests for the course type for the particular requestor.
                    145: If N is undefined, there is no limit to the number of course requests
                    146: which a course owner may submit and have processed automatically. 
                    147: 
                    148: =back
                    149: 
                    150: =item modify_quotas() 
                    151: 
                    152: =back
                    153: 
                    154: =cut
                    155: 
1.1       raeburn   156: package Apache::domainprefs;
                    157: 
                    158: use strict;
                    159: use Apache::Constants qw(:common :http);
                    160: use Apache::lonnet;
                    161: use Apache::loncommon();
                    162: use Apache::lonhtmlcommon();
                    163: use Apache::lonlocal;
1.43      raeburn   164: use Apache::lonmsg();
1.91      raeburn   165: use Apache::lonconfigsettings;
1.69      raeburn   166: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   167: use LONCAPA::Enrollment;
1.81      raeburn   168: use LONCAPA::lonauthcgi();
1.9       raeburn   169: use File::Copy;
1.43      raeburn   170: use Locale::Language;
1.62      raeburn   171: use DateTime::TimeZone;
1.68      raeburn   172: use DateTime::Locale;
1.1       raeburn   173: 
1.155     raeburn   174: my $registered_cleanup;
                    175: my $modified_urls;
                    176: 
1.1       raeburn   177: sub handler {
                    178:     my $r=shift;
                    179:     if ($r->header_only) {
                    180:         &Apache::loncommon::content_type($r,'text/html');
                    181:         $r->send_http_header;
                    182:         return OK;
                    183:     }
                    184: 
1.91      raeburn   185:     my $context = 'domain';
1.1       raeburn   186:     my $dom = $env{'request.role.domain'};
1.5       albertel  187:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   188:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    189:         &Apache::loncommon::content_type($r,'text/html');
                    190:         $r->send_http_header;
                    191:     } else {
                    192:         $env{'user.error.msg'}=
                    193:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    194:         return HTTP_NOT_ACCEPTABLE;
                    195:     }
1.155     raeburn   196: 
                    197:     $registered_cleanup=0;
                    198:     @{$modified_urls}=();
                    199: 
1.1       raeburn   200:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    201:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   202:                                             ['phase','actions']);
1.30      raeburn   203:     my $phase = 'pickactions';
1.3       raeburn   204:     if ( exists($env{'form.phase'}) ) {
                    205:         $phase = $env{'form.phase'};
                    206:     }
1.150     raeburn   207:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   208:     my %domconfig =
1.6       raeburn   209:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   210:                 'quotas','autoenroll','autoupdate','autocreate',
                    211:                 'directorysrch','usercreation','usermodification',
                    212:                 'contacts','defaults','scantron','coursecategories',
                    213:                 'serverstatuses','requestcourses','helpsettings',
1.163   ! raeburn   214:                 'coursedefaults','usersessions','loadbalancing',
        !           215:                 'requestauthor'],$dom);
1.43      raeburn   216:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   217:                        'autoupdate','autocreate','directorysrch','contacts',
1.48      raeburn   218:                        'usercreation','usermodification','scantron',
1.163   ! raeburn   219:                        'requestcourses','requestauthor','coursecategories',
        !           220:                        'serverstatuses','helpsettings',
1.137     raeburn   221:                        'coursedefaults','usersessions');
1.150     raeburn   222:     if (keys(%servers) > 1) {
                    223:         push(@prefs_order,'loadbalancing');
                    224:     }
1.30      raeburn   225:     my %prefs = (
                    226:         'rolecolors' =>
                    227:                    { text => 'Default color schemes',
1.67      raeburn   228:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   229:                      header => [{col1 => 'Student Settings',
                    230:                                  col2 => '',},
                    231:                                 {col1 => 'Coordinator Settings',
                    232:                                  col2 => '',},
                    233:                                 {col1 => 'Author Settings',
                    234:                                  col2 => '',},
                    235:                                 {col1 => 'Administrator Settings',
                    236:                                  col2 => '',}],
                    237:                     },
1.110     raeburn   238:         'login' =>
1.30      raeburn   239:                     { text => 'Log-in page options',
1.67      raeburn   240:                       help => 'Domain_Configuration_Login_Page',
1.30      raeburn   241:                       header => [{col1 => 'Item',
                    242:                                   col2 => '',}],
                    243:                     },
1.110     raeburn   244: 
1.43      raeburn   245:         'defaults' => 
1.141     raeburn   246:                     { text => 'Default authentication/language/timezone/portal',
1.67      raeburn   247:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   248:                       header => [{col1 => 'Setting',
                    249:                                   col2 => 'Value'}],
                    250:                     },
1.30      raeburn   251:         'quotas' => 
1.162     raeburn   252:                     { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67      raeburn   253:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   254:                       header => [{col1 => 'User affiliation',
1.72      raeburn   255:                                   col2 => 'Available tools',
                    256:                                   col3 => 'Portfolio quota',}],
1.30      raeburn   257:                     },
                    258:         'autoenroll' =>
                    259:                    { text => 'Auto-enrollment settings',
1.67      raeburn   260:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   261:                      header => [{col1 => 'Configuration setting',
                    262:                                  col2 => 'Value(s)'}],
                    263:                    },
                    264:         'autoupdate' => 
                    265:                    { text => 'Auto-update settings',
1.67      raeburn   266:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   267:                      header => [{col1 => 'Setting',
                    268:                                  col2 => 'Value',},
1.131     raeburn   269:                                 {col1 => 'Setting',
                    270:                                  col2 => 'Affiliation'},
1.43      raeburn   271:                                 {col1 => 'User population',
1.131     raeburn   272:                                  col2 => 'Updateable user data'}],
1.30      raeburn   273:                   },
1.125     raeburn   274:         'autocreate' => 
                    275:                   { text => 'Auto-course creation settings',
                    276:                      help => 'Domain_Configuration_Auto_Creation',
                    277:                      header => [{col1 => 'Configuration Setting',
                    278:                                  col2 => 'Value',}],
                    279:                   },
1.30      raeburn   280:         'directorysrch' => 
                    281:                   { text => 'Institutional directory searches',
1.67      raeburn   282:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   283:                     header => [{col1 => 'Setting',
                    284:                                 col2 => 'Value',}],
                    285:                   },
                    286:         'contacts' =>
                    287:                   { text => 'Contact Information',
1.67      raeburn   288:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   289:                     header => [{col1 => 'Setting',
                    290:                                 col2 => 'Value',}],
                    291:                   },
                    292: 
                    293:         'usercreation' => 
                    294:                   { text => 'User creation',
1.67      raeburn   295:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   296:                     header => [{col1 => 'Format rule type',
                    297:                                 col2 => 'Format rules in force'},
1.34      raeburn   298:                                {col1 => 'User account creation',
                    299:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   300:                                {col1 => 'Context',
1.43      raeburn   301:                                 col2 => 'Assignable authentication types'}],
1.30      raeburn   302:                   },
1.69      raeburn   303:         'usermodification' =>
1.33      raeburn   304:                   { text => 'User modification',
1.67      raeburn   305:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   306:                     header => [{col1 => 'Target user has role',
                    307:                                 col2 => 'User information updateable in author context'},
                    308:                                {col1 => 'Target user has role',
1.63      raeburn   309:                                 col2 => 'User information updateable in course context'},
                    310:                                {col1 => "Status of user",
                    311:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33      raeburn   312:                   },
1.69      raeburn   313:         'scantron' =>
1.95      www       314:                   { text => 'Bubblesheet format file',
1.67      raeburn   315:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   316:                     header => [ {col1 => 'Item',
                    317:                                  col2 => '',
                    318:                               }],
                    319:                   },
1.86      raeburn   320:         'requestcourses' => 
                    321:                  {text => 'Request creation of courses',
                    322:                   help => 'Domain_Configuration_Request_Courses',
                    323:                   header => [{col1 => 'User affiliation',
1.102     raeburn   324:                               col2 => 'Availability/Processing of requests',},
                    325:                              {col1 => 'Setting',
                    326:                               col2 => 'Value'}],
1.86      raeburn   327:                  },
1.163   ! raeburn   328:         'requestauthor' =>
        !           329:                  {text => 'Request authoring space',
        !           330:                   help => 'Domain_Configuration_Request_Author',
        !           331:                   header => [{col1 => 'User affiliation',
        !           332:                               col2 => 'Availability/Processing of requests',},
        !           333:                              {col1 => 'Setting',
        !           334:                               col2 => 'Value'}],
        !           335:                  },
1.69      raeburn   336:         'coursecategories' =>
1.120     raeburn   337:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   338:                     help => 'Domain_Configuration_Cataloging_Courses',
1.69      raeburn   339:                     header => [{col1 => 'Category settings',
1.57      raeburn   340:                                 col2 => '',},
                    341:                                {col1 => 'Categories',
                    342:                                 col2 => '',
                    343:                                }],
1.69      raeburn   344:                   },
                    345:         'serverstatuses' =>
1.77      raeburn   346:                  {text   => 'Access to server status pages',
1.69      raeburn   347:                   help   => 'Domain_Configuration_Server_Status',
                    348:                   header => [{col1 => 'Status Page',
                    349:                               col2 => 'Other named users',
                    350:                               col3 => 'Specific IPs',
                    351:                             }],
                    352:                  },
1.118     jms       353:         'helpsettings' =>
                    354:                  {text   => 'Help page settings',
                    355:                   help   => 'Domain_Configuration_Help_Settings',
1.122     jms       356:                   header => [{col1 => 'Authenticated Help Settings',
                    357:                               col2 => ''},
                    358:                              {col1 => 'Unauthenticated Help Settings',
                    359:                               col2 => ''}],
1.118     jms       360:                  },
1.121     raeburn   361:         'coursedefaults' => 
                    362:                  {text => 'Course/Community defaults',
                    363:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   364:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    365:                               col2 => 'Value',},
                    366:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    367:                               col2 => 'Value',},],
1.121     raeburn   368:                  },
1.120     raeburn   369:         'privacy' => 
                    370:                  {text   => 'User Privacy',
                    371:                   help   => 'Domain_Configuration_User_Privacy',
                    372:                   header => [{col1 => 'Setting',
                    373:                               col2 => 'Value',}],
                    374:                  },
1.141     raeburn   375:         'usersessions' =>
1.145     raeburn   376:                  {text  => 'User session hosting/offloading',
1.137     raeburn   377:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   378:                   header => [{col1 => 'Domain server',
                    379:                               col2 => 'Servers to offload sessions to when busy'},
                    380:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   381:                               col2 => 'Rules'},
                    382:                              {col1 => "Hosting domain's own users elsewhere",
                    383:                               col2 => 'Rules'}],
                    384:                  },
1.150     raeburn   385:          'loadbalancing' =>
                    386:                  {text  => 'Dedicated Load Balancer',
                    387:                   help  => 'Domain_Configuration_Load_Balancing',
                    388:                   header => [{col1 => 'Server',
                    389:                               col2 => 'Default destinations',
                    390:                               col3 => 'User affliation',
                    391:                               col4 => 'Overrides'},
                    392:                             ],
                    393:                  },
1.3       raeburn   394:     );
1.110     raeburn   395:     if (keys(%servers) > 1) {
                    396:         $prefs{'login'}  = { text   => 'Log-in page options',
                    397:                              help   => 'Domain_Configuration_Login_Page',
                    398:                             header => [{col1 => 'Log-in Service',
                    399:                                         col2 => 'Server Setting',},
                    400:                                        {col1 => 'Log-in Page Items',
                    401:                                         col2 => ''}],
                    402:                            };
                    403:     }
1.6       raeburn   404:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   405:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   406:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   407:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   408:       text=>"Settings to display/modify"});
1.9       raeburn   409:     my $confname = $dom.'-domainconfig';
1.3       raeburn   410:     if ($phase eq 'process') {
1.91      raeburn   411:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30      raeburn   412:     } elsif ($phase eq 'display') {
1.152     raeburn   413:         my $js;
                    414:         if (keys(%servers) > 1) {
                    415:             my ($othertitle,$usertypes,$types) =
                    416:                 &Apache::loncommon::sorted_inst_types($dom);
                    417:             $js = &lonbalance_targets_js($dom,$types,\%servers).
                    418:                   &new_spares_js().
1.153     raeburn   419:                   &common_domprefs_js().
                    420:                   &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   421:         }
1.150     raeburn   422:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   423:     } else {
1.21      raeburn   424:         if (keys(%domconfig) == 0) {
                    425:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   426:             my @ids=&Apache::lonnet::current_machine_ids();
                    427:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   428:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   429:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   430:                 my $custom_img_count = 0;
                    431:                 foreach my $img (@loginimages) {
                    432:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    433:                         $custom_img_count ++;
                    434:                     }
                    435:                 }
                    436:                 foreach my $role (@roles) {
                    437:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    438:                         $custom_img_count ++;
                    439:                     }
                    440:                 }
                    441:                 if ($custom_img_count > 0) {
1.94      raeburn   442:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   443:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   444:                     $r->print(
                    445:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    446:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    447:     &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 />'.
                    448:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    449:                     if ($switch_server) {
1.30      raeburn   450:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   451:                     }
1.91      raeburn   452:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   453:                     return OK;
                    454:                 }
                    455:             }
                    456:         }
1.91      raeburn   457:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   458:     }
                    459:     return OK;
                    460: }
                    461: 
                    462: sub process_changes {
1.92      raeburn   463:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
                    464:     my %domconfig;
                    465:     if (ref($values) eq 'HASH') {
                    466:         %domconfig = %{$values};
                    467:     }
1.3       raeburn   468:     my $output;
                    469:     if ($action eq 'login') {
1.9       raeburn   470:         $output = &modify_login($r,$dom,$confname,%domconfig);
1.6       raeburn   471:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   472:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
                    473:                                      %domconfig);
1.3       raeburn   474:     } elsif ($action eq 'quotas') {
1.86      raeburn   475:         $output = &modify_quotas($dom,$action,%domconfig);
1.3       raeburn   476:     } elsif ($action eq 'autoenroll') {
                    477:         $output = &modify_autoenroll($dom,%domconfig);
                    478:     } elsif ($action eq 'autoupdate') {
                    479:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   480:     } elsif ($action eq 'autocreate') {
                    481:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   482:     } elsif ($action eq 'directorysrch') {
                    483:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   484:     } elsif ($action eq 'usercreation') {
1.28      raeburn   485:         $output = &modify_usercreation($dom,%domconfig);
1.33      raeburn   486:     } elsif ($action eq 'usermodification') {
                    487:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   488:     } elsif ($action eq 'contacts') {
                    489:         $output = &modify_contacts($dom,%domconfig);
1.43      raeburn   490:     } elsif ($action eq 'defaults') {
                    491:         $output = &modify_defaults($dom,$r);
1.46      raeburn   492:     } elsif ($action eq 'scantron') {
1.48      raeburn   493:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
                    494:     } elsif ($action eq 'coursecategories') {
                    495:         $output = &modify_coursecategories($dom,%domconfig);
1.69      raeburn   496:     } elsif ($action eq 'serverstatuses') {
                    497:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   498:     } elsif ($action eq 'requestcourses') {
                    499:         $output = &modify_quotas($dom,$action,%domconfig);
1.163   ! raeburn   500:     } elsif ($action eq 'requestauthor') {
        !           501:         $output = &modify_quotas($dom,$action,%domconfig);
1.118     jms       502:     } elsif ($action eq 'helpsettings') {
1.122     jms       503:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   504:     } elsif ($action eq 'coursedefaults') {
                    505:         $output = &modify_coursedefaults($dom,%domconfig);
1.137     raeburn   506:     } elsif ($action eq 'usersessions') {
                    507:         $output = &modify_usersessions($dom,%domconfig);
1.150     raeburn   508:     } elsif ($action eq 'loadbalancing') {
                    509:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   510:     }
                    511:     return $output;
                    512: }
                    513: 
                    514: sub print_config_box {
1.9       raeburn   515:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   516:     my $rowtotal = 0;
1.49      raeburn   517:     my $output;
                    518:     if ($action eq 'coursecategories') {
                    519:         $output = &coursecategories_javascript($settings);
1.91      raeburn   520:     }
1.49      raeburn   521:     $output .= 
1.30      raeburn   522:          '<table class="LC_nested_outer">
1.3       raeburn   523:           <tr>
1.66      raeburn   524:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    525:            &mt($item->{text}).'&nbsp;'.
                    526:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    527:           '</tr>';
1.30      raeburn   528:     $rowtotal ++;
1.110     raeburn   529:     my $numheaders = 1;
                    530:     if (ref($item->{'header'}) eq 'ARRAY') {
                    531:         $numheaders = scalar(@{$item->{'header'}});
                    532:     }
                    533:     if ($numheaders > 1) {
1.64      raeburn   534:         my $colspan = '';
1.145     raeburn   535:         my $rightcolspan = '';
1.122     jms       536:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64      raeburn   537:             $colspan = ' colspan="2"';
                    538:         }
1.145     raeburn   539:         if ($action eq 'usersessions') {
                    540:             $rightcolspan = ' colspan="3"'; 
                    541:         }
1.30      raeburn   542:         $output .= '
1.3       raeburn   543:           <tr>
                    544:            <td>
                    545:             <table class="LC_nested">
                    546:              <tr class="LC_info_row">
1.59      bisitz    547:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   548:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   549:              </tr>';
1.69      raeburn   550:         $rowtotal ++;
1.6       raeburn   551:         if ($action eq 'autoupdate') {
1.30      raeburn   552:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28      raeburn   553:         } elsif ($action eq 'usercreation') {
1.33      raeburn   554:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
                    555:         } elsif ($action eq 'usermodification') {
                    556:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57      raeburn   557:         } elsif ($action eq 'coursecategories') {
                    558:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   559:         } elsif ($action eq 'login') {
                    560:             $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
                    561:             $colspan = ' colspan="2"';
1.102     raeburn   562:         } elsif ($action eq 'requestcourses') {
                    563:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163   ! raeburn   564:         } elsif ($action eq 'requestauthor') {
        !           565:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118     jms       566:         } elsif ($action eq 'helpsettings') {
1.122     jms       567:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137     raeburn   568:         } elsif ($action eq 'usersessions') {
                    569:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
1.122     jms       570:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   571:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139     raeburn   572:         } elsif ($action eq 'coursedefaults') {
                    573:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6       raeburn   574:         }
1.30      raeburn   575:         $output .= '
1.6       raeburn   576:            </table>
                    577:           </td>
                    578:          </tr>
                    579:          <tr>
                    580:            <td>
                    581:             <table class="LC_nested">
                    582:              <tr class="LC_info_row">
1.59      bisitz    583:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57      raeburn   584:         $output .= '
1.59      bisitz    585:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   586:              </tr>';
                    587:             $rowtotal ++;
1.6       raeburn   588:         if ($action eq 'autoupdate') {
1.131     raeburn   589:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
                    590:            </table>
                    591:           </td>
                    592:          </tr>
                    593:          <tr>
                    594:            <td>
                    595:             <table class="LC_nested">
                    596:              <tr class="LC_info_row">
                    597:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    598:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    599:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
                    600:             $rowtotal ++;
1.28      raeburn   601:         } elsif ($action eq 'usercreation') {
1.34      raeburn   602:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                    603:            </table>
                    604:           </td>
                    605:          </tr>
                    606:          <tr>
                    607:            <td>
                    608:             <table class="LC_nested">
                    609:              <tr class="LC_info_row">
1.59      bisitz    610:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    611:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
1.34      raeburn   612:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
                    613:             $rowtotal ++;
1.33      raeburn   614:         } elsif ($action eq 'usermodification') {
1.63      raeburn   615:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
                    616:            </table>
                    617:           </td>
                    618:          </tr>
                    619:          <tr>
                    620:            <td>
                    621:             <table class="LC_nested">
                    622:              <tr class="LC_info_row">
                    623:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    624:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    625:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
                    626:             $rowtotal ++;
1.57      raeburn   627:         } elsif ($action eq 'coursecategories') {
                    628:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   629:         } elsif ($action eq 'login') {
                    630:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   631:         } elsif ($action eq 'requestcourses') {
1.163   ! raeburn   632:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
        !           633:         } elsif ($action eq 'requestauthor') {
        !           634:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122     jms       635:         } elsif ($action eq 'helpsettings') {
                    636:             $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137     raeburn   637:         } elsif ($action eq 'usersessions') {
1.145     raeburn   638:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
                    639:            </table>
                    640:           </td>
                    641:          </tr>
                    642:          <tr>
                    643:            <td>
                    644:             <table class="LC_nested">
                    645:              <tr class="LC_info_row">
                    646:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    647:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    648:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
                    649:             $rowtotal ++;
1.139     raeburn   650:         } elsif ($action eq 'coursedefaults') {
                    651:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122     jms       652:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   653:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   654:            </table>
                    655:           </td>
                    656:          </tr>
                    657:          <tr>
                    658:            <td>
                    659:             <table class="LC_nested">
                    660:              <tr class="LC_info_row">
1.69      raeburn   661:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    662:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    663:               <td class="LC_right_item" valign="top">'.
                    664:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   665:              </tr>'.
1.30      raeburn   666:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   667:            </table>
                    668:           </td>
                    669:          </tr>
                    670:          <tr>
                    671:            <td>
                    672:             <table class="LC_nested">
                    673:              <tr class="LC_info_row">
1.59      bisitz    674:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    675:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   676:              </tr>'.
1.30      raeburn   677:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    678:             $rowtotal += 2;
1.6       raeburn   679:         }
1.3       raeburn   680:     } else {
1.30      raeburn   681:         $output .= '
1.3       raeburn   682:           <tr>
                    683:            <td>
                    684:             <table class="LC_nested">
1.30      raeburn   685:              <tr class="LC_info_row">';
1.24      raeburn   686:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   687:             $output .= '  
1.59      bisitz    688:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   689:         } elsif ($action eq 'serverstatuses') {
                    690:             $output .= '
                    691:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    692:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    693: 
1.6       raeburn   694:         } else {
1.30      raeburn   695:             $output .= '
1.69      raeburn   696:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    697:         }
1.72      raeburn   698:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    699:             $output .= '<td class="LC_left_item" valign="top">'.
                    700:                        &mt($item->{'header'}->[0]->{'col2'});
                    701:             if ($action eq 'serverstatuses') {
                    702:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    703:             } 
1.69      raeburn   704:         } else {
                    705:             $output .= '<td class="LC_right_item" valign="top">'.
                    706:                        &mt($item->{'header'}->[0]->{'col2'});
                    707:         }
                    708:         $output .= '</td>';
                    709:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   710:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    711:                 $output .= '<td class="LC_left_item" valign="top">'.
                    712:                             &mt($item->{'header'}->[0]->{'col3'});
                    713:             } else {
                    714:                 $output .= '<td class="LC_right_item" valign="top">'.
                    715:                            &mt($item->{'header'}->[0]->{'col3'});
                    716:             }
1.69      raeburn   717:             if ($action eq 'serverstatuses') {
                    718:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    719:             }
                    720:             $output .= '</td>';
1.6       raeburn   721:         }
1.150     raeburn   722:         if ($item->{'header'}->[0]->{'col4'}) {
                    723:             $output .= '<td class="LC_right_item" valign="top">'.
                    724:                        &mt($item->{'header'}->[0]->{'col4'});
                    725:         }
1.69      raeburn   726:         $output .= '</tr>';
1.48      raeburn   727:         $rowtotal ++;
1.3       raeburn   728:         if ($action eq 'login') {
1.110     raeburn   729:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
                    730:                                     \$rowtotal);
1.3       raeburn   731:         } elsif ($action eq 'quotas') {
1.86      raeburn   732:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3       raeburn   733:         } elsif ($action eq 'autoenroll') {
1.30      raeburn   734:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125     raeburn   735:         } elsif ($action eq 'autocreate') {
                    736:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23      raeburn   737:         } elsif ($action eq 'directorysrch') {
1.30      raeburn   738:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28      raeburn   739:         } elsif ($action eq 'contacts') {
1.30      raeburn   740:             $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43      raeburn   741:         } elsif ($action eq 'defaults') {
                    742:             $output .= &print_defaults($dom,\$rowtotal);
1.46      raeburn   743:         } elsif ($action eq 'scantron') {
                    744:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69      raeburn   745:         } elsif ($action eq 'serverstatuses') {
                    746:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118     jms       747:         } elsif ($action eq 'helpsettings') {
1.122     jms       748:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150     raeburn   749:         } elsif ($action eq 'loadbalancing') {
                    750:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121     raeburn   751:         }
1.3       raeburn   752:     }
1.30      raeburn   753:     $output .= '
1.3       raeburn   754:    </table>
                    755:   </td>
                    756:  </tr>
1.30      raeburn   757: </table><br />';
                    758:     return ($output,$rowtotal);
1.1       raeburn   759: }
                    760: 
1.3       raeburn   761: sub print_login {
1.110     raeburn   762:     my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
                    763:     my ($css_class,$datatable);
1.6       raeburn   764:     my %choices = &login_choices();
1.110     raeburn   765: 
                    766:     if ($position eq 'top') {
1.149     raeburn   767:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   768:         my $choice = $choices{'disallowlogin'};
                    769:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   770:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   771:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   772:                       '<th>'.$choices{'server'}.'</th>'.
                    773:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    774:                       '<th>'.$choices{'custompath'}.'</th>'.
                    775:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   776:         my %disallowed;
                    777:         if (ref($settings) eq 'HASH') {
                    778:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    779:                %disallowed = %{$settings->{'loginvia'}};
                    780:             }
                    781:         }
                    782:         foreach my $lonhost (sort(keys(%servers))) {
                    783:             my $direct = 'selected="selected"';
1.128     raeburn   784:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    785:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    786:                     $direct = '';
                    787:                 }
1.110     raeburn   788:             }
1.115     raeburn   789:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   790:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   791:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    792:                           '</option>';
                    793:             foreach my $hostid (keys(%servers)) {
1.115     raeburn   794:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   795:                 my $selected = '';
1.128     raeburn   796:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    797:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    798:                         $selected = 'selected="selected"';
                    799:                     }
1.110     raeburn   800:                 }
                    801:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    802:                               $servers{$hostid}.'</option>';
                    803:             }
1.128     raeburn   804:             $datatable .= '</select></td>'.
                    805:                           '<td><select name="'.$lonhost.'_serverpath">';
                    806:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    807:                 my $pathname = $path;
                    808:                 if ($path eq 'custom') {
                    809:                     $pathname = &mt('Custom Path').' ->';
                    810:                 }
                    811:                 my $selected = '';
                    812:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    813:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    814:                         $selected = 'selected="selected"';
                    815:                     }
                    816:                 } elsif ($path eq '') {
                    817:                     $selected = 'selected="selected"';
                    818:                 }
                    819:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    820:             }
                    821:             $datatable .= '</select></td>';
                    822:             my ($custom,$exempt);
                    823:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    824:                 $custom = $disallowed{$lonhost}{'custompath'};
                    825:                 $exempt = $disallowed{$lonhost}{'exempt'};
                    826:             }
                    827:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                    828:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                    829:                           '</tr>';
1.110     raeburn   830:         }
                    831:         $datatable .= '</table></td></tr>';
                    832:         return $datatable;
                    833:     }
                    834: 
1.42      raeburn   835:     my %defaultchecked = ( 
1.43      raeburn   836:                            'coursecatalog' => 'on',
                    837:                            'adminmail'     => 'off',
                    838:                            'newuser'       => 'off',
                    839:                          );
1.118     jms       840:     my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn   841:     my (%checkedon,%checkedoff);
                    842:     foreach my $item (@toggles) {
                    843:         if ($defaultchecked{$item} eq 'on') { 
                    844:             $checkedon{$item} = ' checked="checked" ';
                    845:             $checkedoff{$item} = ' ';
                    846:         } elsif ($defaultchecked{$item} eq 'off') {
                    847:             $checkedoff{$item} = ' checked="checked" ';
                    848:             $checkedon{$item} = ' ';
                    849:         }
                    850:     }
1.41      raeburn   851:     my @images = ('img','logo','domlogo','login');
                    852:     my @logintext = ('textcol','bgcol');
1.6       raeburn   853:     my @bgs = ('pgbg','mainbg','sidebg');
                    854:     my @links = ('link','alink','vlink');
1.7       albertel  855:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn   856:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                    857:     my (%is_custom,%designs);
                    858:     my %defaults = (
                    859:                    font => $defaultdesign{'login.font'},
                    860:                    );
                    861:     foreach my $item (@images) {
                    862:         $defaults{$item} = $defaultdesign{'login.'.$item};
1.70      raeburn   863:         $defaults{'showlogo'}{$item} = 1;
1.6       raeburn   864:     }
                    865:     foreach my $item (@bgs) {
                    866:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
                    867:     }
1.41      raeburn   868:     foreach my $item (@logintext) {
                    869:         $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
                    870:     }
1.6       raeburn   871:     foreach my $item (@links) {
                    872:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
                    873:     }
1.3       raeburn   874:     if (ref($settings) eq 'HASH') {
1.42      raeburn   875:         foreach my $item (@toggles) {
                    876:             if ($settings->{$item} eq '1') {
                    877:                 $checkedon{$item} =  ' checked="checked" ';
                    878:                 $checkedoff{$item} = ' ';
                    879:             } elsif ($settings->{$item} eq '0') {
                    880:                 $checkedoff{$item} =  ' checked="checked" ';
                    881:                 $checkedon{$item} = ' ';
                    882:             }
1.1       raeburn   883:         }
1.6       raeburn   884:         foreach my $item (@images) {
1.70      raeburn   885:             if (defined($settings->{$item})) {
1.6       raeburn   886:                 $designs{$item} = $settings->{$item};
                    887:                 $is_custom{$item} = 1;
                    888:             }
1.70      raeburn   889:             if (defined($settings->{'showlogo'}{$item})) {
                    890:                 $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                    891:             }
1.6       raeburn   892:         }
1.41      raeburn   893:         foreach my $item (@logintext) {
                    894:             if ($settings->{$item} ne '') {
                    895:                 $designs{'logintext'}{$item} = $settings->{$item};
                    896:                 $is_custom{$item} = 1;
                    897:             }
                    898:         }
1.6       raeburn   899:         if ($settings->{'font'} ne '') {
                    900:             $designs{'font'} = $settings->{'font'};
                    901:             $is_custom{'font'} = 1;
                    902:         }
                    903:         foreach my $item (@bgs) {
                    904:             if ($settings->{$item} ne '') {
                    905:                 $designs{'bgs'}{$item} = $settings->{$item};
                    906:                 $is_custom{$item} = 1;
                    907:             }
                    908:         }
                    909:         foreach my $item (@links) {
                    910:             if ($settings->{$item} ne '') {
                    911:                 $designs{'links'}{$item} = $settings->{$item};
                    912:                 $is_custom{$item} = 1;
                    913:             }
                    914:         }
                    915:     } else {
                    916:         if ($designhash{$dom.'.login.font'} ne '') {
                    917:             $designs{'font'} = $designhash{$dom.'.login.font'};
                    918:             $is_custom{'font'} = 1;
                    919:         }
1.8       raeburn   920:         foreach my $item (@images) {
                    921:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    922:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
                    923:                 $is_custom{$item} = 1;
                    924:             }
                    925:         }
1.6       raeburn   926:         foreach my $item (@bgs) {
                    927:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    928:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                    929:                 $is_custom{$item} = 1;
                    930:             }
                    931:         }
                    932:         foreach my $item (@links) {
                    933:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    934:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                    935:                 $is_custom{$item} = 1;
                    936:             }
                    937:         }
1.1       raeburn   938:     }
1.6       raeburn   939:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                    940:                                                   logo => 'Institution Logo',
1.41      raeburn   941:                                                   domlogo => 'Domain Logo',
                    942:                                                   login => 'Login box');
1.6       raeburn   943:     my $itemcount = 1;
1.42      raeburn   944:     foreach my $item (@toggles) {
                    945:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    946:         $datatable .=  
                    947:             '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                    948:             '</td><td>'.
                    949:             '<span class="LC_nobreak"><label><input type="radio" name="'.
                    950:             $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                    951:             '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                    952:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                    953:             '</tr>';
                    954:         $itemcount ++;
                    955:     }
1.135     bisitz    956:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6       raeburn   957:     $datatable .= '</tr></table></td></tr>';
                    958:     return $datatable;
                    959: }
                    960: 
                    961: sub login_choices {
                    962:     my %choices =
                    963:         &Apache::lonlocal::texthash (
1.116     bisitz    964:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn   965:             adminmail     => "Display Administrator's E-mail Address?",
                    966:             disallowlogin => "Login page requests redirected",
                    967:             hostid        => "Server",
1.128     raeburn   968:             server        => "Redirect to:",
                    969:             serverpath    => "Path",
                    970:             custompath    => "Custom", 
                    971:             exempt        => "Exempt IP(s)",
1.110     raeburn   972:             directlogin   => "No redirect",
                    973:             newuser       => "Link to create a user account",
                    974:             img           => "Header",
                    975:             logo          => "Main Logo",
                    976:             domlogo       => "Domain Logo",
                    977:             login         => "Log-in Header", 
                    978:             textcol       => "Text color",
                    979:             bgcol         => "Box color",
                    980:             bgs           => "Background colors",
                    981:             links         => "Link colors",
                    982:             font          => "Font color",
                    983:             pgbg          => "Header",
                    984:             mainbg        => "Page",
                    985:             sidebg        => "Login box",
                    986:             link          => "Link",
                    987:             alink         => "Active link",
                    988:             vlink         => "Visited link",
1.6       raeburn   989:         );
                    990:     return %choices;
                    991: }
                    992: 
                    993: sub print_rolecolors {
1.30      raeburn   994:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn   995:     my %choices = &color_font_choices();
                    996:     my @bgs = ('pgbg','tabbg','sidebg');
                    997:     my @links = ('link','alink','vlink');
                    998:     my @images = ('img');
                    999:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1000:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1001:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1002:     my (%is_custom,%designs);
                   1003:     my %defaults = (
                   1004:                    img => $defaultdesign{$role.'.img'},
                   1005:                    font => $defaultdesign{$role.'.font'},
1.97      tempelho 1006: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6       raeburn  1007:                    );
                   1008:     foreach my $item (@bgs) {
                   1009:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1010:     }
                   1011:     foreach my $item (@links) {
                   1012:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1013:     }
                   1014:     if (ref($settings) eq 'HASH') {
                   1015:         if (ref($settings->{$role}) eq 'HASH') {
                   1016:             if ($settings->{$role}->{'img'} ne '') {
                   1017:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1018:                 $is_custom{'img'} = 1;
                   1019:             }
                   1020:             if ($settings->{$role}->{'font'} ne '') {
                   1021:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1022:                 $is_custom{'font'} = 1;
                   1023:             }
1.97      tempelho 1024:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1025:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1026:                 $is_custom{'fontmenu'} = 1;
                   1027:             }
1.6       raeburn  1028:             foreach my $item (@bgs) {
                   1029:                 if ($settings->{$role}->{$item} ne '') {
                   1030:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1031:                     $is_custom{$item} = 1;
                   1032:                 }
                   1033:             }
                   1034:             foreach my $item (@links) {
                   1035:                 if ($settings->{$role}->{$item} ne '') {
                   1036:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1037:                     $is_custom{$item} = 1;
                   1038:                 }
                   1039:             }
                   1040:         }
                   1041:     } else {
                   1042:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1043:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1044:             $is_custom{'img'} = 1;
                   1045:         }
1.97      tempelho 1046:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1047:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1048:             $is_custom{'fontmenu'} = 1; 
                   1049:         }
1.6       raeburn  1050:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1051:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1052:             $is_custom{'font'} = 1;
                   1053:         }
                   1054:         foreach my $item (@bgs) {
                   1055:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1056:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1057:                 $is_custom{$item} = 1;
                   1058:             
                   1059:             }
                   1060:         }
                   1061:         foreach my $item (@links) {
                   1062:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1063:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1064:                 $is_custom{$item} = 1;
                   1065:             }
                   1066:         }
                   1067:     }
                   1068:     my $itemcount = 1;
1.30      raeburn  1069:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1070:     $datatable .= '</tr></table></td></tr>';
                   1071:     return $datatable;
                   1072: }
                   1073: 
                   1074: sub display_color_options {
1.9       raeburn  1075:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1076:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1077:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1078:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1079:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1080:         '<td>'.$choices->{'font'}.'</td>';
                   1081:     if (!$is_custom->{'font'}) {
1.30      raeburn  1082:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1083:     } else {
                   1084:         $datatable .= '<td>&nbsp;</td>';
                   1085:     }
                   1086:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8       raeburn  1087:     $datatable .= '<td><span class="LC_nobreak">'.
1.6       raeburn  1088:                   '<input type="text" size="10" name="'.$role.'_font"'.
1.8       raeburn  1089:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
1.30      raeburn  1090:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
                   1091:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
1.8       raeburn  1092:                   '</span></td></tr>';
1.107     raeburn  1093:     unless ($role eq 'login') { 
                   1094:         $datatable .= '<tr'.$css_class.'>'.
                   1095:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1096:         if (!$is_custom->{'fontmenu'}) {
                   1097:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1098:         } else {
                   1099:             $datatable .= '<td>&nbsp;</td>';
                   1100:         }
                   1101:         $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
                   1102:         $datatable .= '<td><span class="LC_nobreak">'.
                   1103:                       '<input type="text" size="10" name="'.$role.'_fontmenu"'.
                   1104:                       ' value="'.$designs->{'fontmenu'}.'" />&nbsp;'.$fontlink.
                   1105:                       '&nbsp;<span id="css_'.$role.'_fontmenu" style="background-color: '.
                   1106:                       $designs->{'fontmenu'}.';">&nbsp;&nbsp;&nbsp;</span>'.
                   1107:                       '</span></td></tr>';
1.97      tempelho 1108:     }
1.9       raeburn  1109:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1110:     foreach my $img (@{$images}) {
1.18      albertel 1111: 	$itemcount ++;
1.6       raeburn  1112:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1113:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1114:                       '<td>'.$choices->{$img};
1.41      raeburn  1115:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1116:         if ($role eq 'login') {
                   1117:             if ($img eq 'login') {
                   1118:                 $login_hdr_pick =
1.135     bisitz   1119:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1120:                 $logincolors =
                   1121:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
                   1122:                                             $designs);
                   1123:             } elsif ($img ne 'domlogo') {
                   1124:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1125:             }
                   1126:         }
                   1127:         $datatable .= '</td>';
1.6       raeburn  1128:         if ($designs->{$img} ne '') {
                   1129:             $imgfile = $designs->{$img};
1.18      albertel 1130: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1131:         } else {
                   1132:             $imgfile = $defaults->{$img};
                   1133:         }
                   1134:         if ($imgfile) {
1.9       raeburn  1135:             my ($showfile,$fullsize);
                   1136:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1137:                 my $urldir = $1;
                   1138:                 my $filename = $2;
                   1139:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1140:                 if (@info) {
                   1141:                     my $thumbfile = 'tn-'.$filename;
                   1142:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1143:                     if (@thumb) {
                   1144:                         $showfile = $urldir.'/'.$thumbfile;
                   1145:                     } else {
                   1146:                         $showfile = $imgfile;
                   1147:                     }
                   1148:                 } else {
                   1149:                     $showfile = '';
                   1150:                 }
                   1151:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1152:                 $showfile = $imgfile;
1.6       raeburn  1153:                 my $imgdir = $1;
                   1154:                 my $filename = $2;
1.159     raeburn  1155:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1156:                     $showfile = "/$imgdir/tn-".$filename;
                   1157:                 } else {
1.159     raeburn  1158:                     my $input = $londocroot.$imgfile;
                   1159:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1160:                     if (!-e $output) {
1.9       raeburn  1161:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1162:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1163:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1164:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1165:                                 my $size = $width.'x'.$height;
                   1166:                                 system("convert -sample $size $input $output");
1.159     raeburn  1167:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1168:                             }
                   1169:                         }
1.6       raeburn  1170:                     }
                   1171:                 }
1.16      raeburn  1172:             }
1.6       raeburn  1173:             if ($showfile) {
1.40      raeburn  1174:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1175:                     if ($showfile =~ m{^/res/}) {
                   1176:                         my $local_showfile =
                   1177:                             &Apache::lonnet::filelocation('',$showfile);
                   1178:                         &Apache::lonnet::repcopy($local_showfile);
                   1179:                     }
                   1180:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1181:                 }
                   1182:                 if ($imgfile) {
                   1183:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1184:                         if ($imgfile =~ m{^/res/}) {
                   1185:                             my $local_imgfile =
                   1186:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1187:                             &Apache::lonnet::repcopy($local_imgfile);
                   1188:                         }
                   1189:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1190:                     } else {
                   1191:                         $fullsize = $imgfile;
                   1192:                     }
                   1193:                 }
1.41      raeburn  1194:                 $datatable .= '<td>';
                   1195:                 if ($img eq 'login') {
1.135     bisitz   1196:                     $datatable .= $login_hdr_pick;
                   1197:                 } 
1.41      raeburn  1198:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1199:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1200:             } else {
                   1201:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1202:                               &mt('Upload:');
                   1203:             }
                   1204:         } else {
                   1205:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1206:                           &mt('Upload:');
                   1207:         }
1.9       raeburn  1208:         if ($switchserver) {
                   1209:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1210:         } else {
1.135     bisitz   1211:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1212:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1213:             }
1.9       raeburn  1214:         }
                   1215:         $datatable .= '</td></tr>';
1.6       raeburn  1216:     }
                   1217:     $itemcount ++;
                   1218:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1219:     $datatable .= '<tr'.$css_class.'>'.
                   1220:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1221:     my $bgs_def;
                   1222:     foreach my $item (@{$bgs}) {
                   1223:         if (!$is_custom->{$item}) {
1.70      raeburn  1224:             $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>';
1.6       raeburn  1225:         }
                   1226:     }
                   1227:     if ($bgs_def) {
1.8       raeburn  1228:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1229:     } else {
                   1230:         $datatable .= '<td>&nbsp;</td>';
                   1231:     }
                   1232:     $datatable .= '<td class="LC_right_item">'.
                   1233:                   '<table border="0"><tr>';
                   1234:     foreach my $item (@{$bgs}) {
                   1235:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
                   1236:         $datatable .= '<td align="center">'.$link;
                   1237:         if ($designs->{'bgs'}{$item}) {
1.30      raeburn  1238:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn  1239:         }
                   1240:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41      raeburn  1241:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1242:     }
                   1243:     $datatable .= '</tr></table></td></tr>';
                   1244:     $itemcount ++;
                   1245:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1246:     $datatable .= '<tr'.$css_class.'>'.
                   1247:                   '<td>'.$choices->{'links'}.'</td>';
                   1248:     my $links_def;
                   1249:     foreach my $item (@{$links}) {
                   1250:         if (!$is_custom->{$item}) {
1.30      raeburn  1251:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6       raeburn  1252:         }
                   1253:     }
                   1254:     if ($links_def) {
1.8       raeburn  1255:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1256:     } else {
                   1257:         $datatable .= '<td>&nbsp;</td>';
                   1258:     }
                   1259:     $datatable .= '<td class="LC_right_item">'.
                   1260:                   '<table border="0"><tr>';
                   1261:     foreach my $item (@{$links}) {
1.30      raeburn  1262:         $datatable .= '<td align="center">'."\n".
                   1263:                       &color_pick($phase,$role,$item,$choices->{$item},
                   1264:                                   $designs->{'links'}{$item});
1.6       raeburn  1265:         if ($designs->{'links'}{$item}) {
1.30      raeburn  1266:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn  1267:         }
                   1268:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
                   1269:                       '" /></td>';
                   1270:     }
1.30      raeburn  1271:     $$rowtotal += $itemcount;
1.3       raeburn  1272:     return $datatable;
                   1273: }
                   1274: 
1.70      raeburn  1275: sub logo_display_options {
                   1276:     my ($img,$defaults,$designs) = @_;
                   1277:     my $checkedon;
                   1278:     if (ref($defaults) eq 'HASH') {
                   1279:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1280:             if ($defaults->{'showlogo'}{$img}) {
                   1281:                 $checkedon = 'checked="checked" ';     
                   1282:             }
                   1283:         } 
                   1284:     }
                   1285:     if (ref($designs) eq 'HASH') {
                   1286:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1287:             if (defined($designs->{'showlogo'}{$img})) {
                   1288:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1289:                     $checkedon = '';
                   1290:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1291:                     $checkedon = 'checked="checked" ';
                   1292:                 }
                   1293:             }
                   1294:         }
                   1295:     }
                   1296:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1297:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1298:            &mt('show').'</label>'."\n";
                   1299: }
                   1300: 
1.41      raeburn  1301: sub login_header_options  {
1.135     bisitz   1302:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1303:     my $output = '';
1.41      raeburn  1304:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1305:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1306:         if (!$is_custom->{'textcol'}) {
                   1307:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1308:                        '&nbsp;&nbsp;&nbsp;';
                   1309:         }
                   1310:         if (!$is_custom->{'bgcol'}) {
                   1311:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1312:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1313:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1314:         }
                   1315:         $output .= '<br />';
                   1316:     }
                   1317:     $output .='<br />';
                   1318:     return $output;
                   1319: }
                   1320: 
                   1321: sub login_text_colors {
                   1322:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
                   1323:     my $color_menu = '<table border="0"><tr>';
                   1324:     foreach my $item (@{$logintext}) {
                   1325:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
                   1326:         $color_menu .= '<td align="center">'.$link;
                   1327:         if ($designs->{'logintext'}{$item}) {
                   1328:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1329:         }
                   1330:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
                   1331:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
                   1332:                        '<td>&nbsp;</td>';
                   1333:     }
                   1334:     $color_menu .= '</tr></table><br />';
                   1335:     return $color_menu;
                   1336: }
                   1337: 
                   1338: sub image_changes {
                   1339:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1340:     my $output;
1.135     bisitz   1341:     if ($img eq 'login') {
                   1342:             # suppress image for Log-in header
                   1343:     } elsif (!$is_custom) {
1.70      raeburn  1344:         if ($img ne 'domlogo') {
1.41      raeburn  1345:             $output .= &mt('Default image:').'<br />';
                   1346:         } else {
                   1347:             $output .= &mt('Default in use:').'<br />';
                   1348:         }
                   1349:     }
1.135     bisitz   1350:     if ($img eq 'login') { # suppress image for Log-in header
                   1351:         $output .= '<td>'.$logincolors;
1.41      raeburn  1352:     } else {
1.135     bisitz   1353:         if ($img_import) {
                   1354:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1355:         }
                   1356:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1357:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1358:         if ($is_custom) {
                   1359:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1360:                        '<input type="checkbox" name="'.
                   1361:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1362:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1363:         } else {
                   1364:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
                   1365:         }
1.41      raeburn  1366:     }
                   1367:     return $output;
                   1368: }
                   1369: 
1.6       raeburn  1370: sub color_pick {
                   1371:     my ($phase,$role,$item,$desc,$curcol) = @_;
                   1372:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
                   1373:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
                   1374:                ');">'.$desc.'</a>';
                   1375:     return $link;
                   1376: }
                   1377: 
1.3       raeburn  1378: sub print_quotas {
1.86      raeburn  1379:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1380:     my $context;
                   1381:     if ($action eq 'quotas') {
                   1382:         $context = 'tools';
                   1383:     } else {
                   1384:         $context = $action;
                   1385:     }
1.101     raeburn  1386:     my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44      raeburn  1387:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1388:     my $typecount = 0;
1.101     raeburn  1389:     my ($css_class,%titles);
1.86      raeburn  1390:     if ($context eq 'requestcourses') {
1.98      raeburn  1391:         @usertools = ('official','unofficial','community');
1.106     raeburn  1392:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1393:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1394:         %titles = &courserequest_titles();
1.163   ! raeburn  1395:     } elsif ($context eq 'requestauthor') {
        !          1396:         @usertools = ('author');
        !          1397:         @options = ('norequest','approval','automatic');
        !          1398:         %titles = &authorrequest_titles(); 
1.86      raeburn  1399:     } else {
1.162     raeburn  1400:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1401:         %titles = &tool_titles();
1.86      raeburn  1402:     }
1.26      raeburn  1403:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1404:         foreach my $type (@{$types}) {
1.72      raeburn  1405:             my $currdefquota;
1.163   ! raeburn  1406:             unless (($context eq 'requestcourses') ||
        !          1407:                     ($context eq 'requestauthor')) {
1.86      raeburn  1408:                 if (ref($settings) eq 'HASH') {
                   1409:                     if (ref($settings->{defaultquota}) eq 'HASH') {
                   1410:                         $currdefquota = $settings->{defaultquota}->{$type}; 
                   1411:                     } else {
                   1412:                         $currdefquota = $settings->{$type};
                   1413:                     }
1.78      raeburn  1414:                 }
1.72      raeburn  1415:             }
1.3       raeburn  1416:             if (defined($usertypes->{$type})) {
                   1417:                 $typecount ++;
                   1418:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1419:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1420:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1421:                               '<td class="LC_left_item">';
1.101     raeburn  1422:                 if ($context eq 'requestcourses') {
                   1423:                     $datatable .= '<table><tr>';
                   1424:                 }
                   1425:                 my %cell;  
1.72      raeburn  1426:                 foreach my $item (@usertools) {
1.101     raeburn  1427:                     if ($context eq 'requestcourses') {
                   1428:                         my ($curroption,$currlimit);
                   1429:                         if (ref($settings) eq 'HASH') {
                   1430:                             if (ref($settings->{$item}) eq 'HASH') {
                   1431:                                 $curroption = $settings->{$item}->{$type};
                   1432:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1433:                                     $currlimit = $1; 
                   1434:                                 }
                   1435:                             }
                   1436:                         }
                   1437:                         if (!$curroption) {
                   1438:                             $curroption = 'norequest';
                   1439:                         }
                   1440:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1441:                         foreach my $option (@options) {
                   1442:                             my $val = $option;
                   1443:                             if ($option eq 'norequest') {
                   1444:                                 $val = 0;  
                   1445:                             }
                   1446:                             if ($option eq 'validate') {
                   1447:                                 my $canvalidate = 0;
                   1448:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1449:                                     if ($validations{$item}{$type}) {
                   1450:                                         $canvalidate = 1;
                   1451:                                     }
                   1452:                                 }
                   1453:                                 next if (!$canvalidate);
                   1454:                             }
                   1455:                             my $checked = '';
                   1456:                             if ($option eq $curroption) {
                   1457:                                 $checked = ' checked="checked"';
                   1458:                             } elsif ($option eq 'autolimit') {
                   1459:                                 if ($curroption =~ /^autolimit/) {
                   1460:                                     $checked = ' checked="checked"';
                   1461:                                 }                       
                   1462:                             } 
                   1463:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1464:                                   '<input type="radio" name="crsreq_'.$item.
                   1465:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1466:                                   $titles{$option}.'</label>';
1.101     raeburn  1467:                             if ($option eq 'autolimit') {
1.127     raeburn  1468:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1469:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1470:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1471:                             }
1.127     raeburn  1472:                             $cell{$item} .= '</span> ';
1.103     raeburn  1473:                             if ($option eq 'autolimit') {
1.127     raeburn  1474:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1475:                             }
1.101     raeburn  1476:                         }
1.163   ! raeburn  1477:                     } elsif ($context eq 'requestauthor') {
        !          1478:                         my $curroption;
        !          1479:                         if (ref($settings) eq 'HASH') {
        !          1480:                             $curroption = $settings->{$type};
        !          1481:                         }
        !          1482:                         if (!$curroption) {
        !          1483:                             $curroption = 'norequest';
        !          1484:                         }
        !          1485:                         foreach my $option (@options) {
        !          1486:                             my $val = $option;
        !          1487:                             if ($option eq 'norequest') {
        !          1488:                                 $val = 0;
        !          1489:                             }
        !          1490:                             my $checked = '';
        !          1491:                             if ($option eq $curroption) {
        !          1492:                                 $checked = ' checked="checked"';
        !          1493:                             }
        !          1494:                             $datatable .= '<span class="LC_nobreak"><label>'.
        !          1495:                                   '<input type="radio" name="authorreq_'.$type.
        !          1496:                                   '" value="'.$val.'"'.$checked.' />'.
        !          1497:                                   $titles{$option}.'</label></span>&nbsp; ';
        !          1498:                         }
1.101     raeburn  1499:                     } else {
                   1500:                         my $checked = 'checked="checked" ';
                   1501:                         if (ref($settings) eq 'HASH') {
                   1502:                             if (ref($settings->{$item}) eq 'HASH') {
                   1503:                                 if ($settings->{$item}->{$type} == 0) {
                   1504:                                     $checked = '';
                   1505:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1506:                                     $checked =  'checked="checked" ';
                   1507:                                 }
1.78      raeburn  1508:                             }
1.72      raeburn  1509:                         }
1.101     raeburn  1510:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1511:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1512:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1513:                                       '</label></span>&nbsp; ';
1.72      raeburn  1514:                     }
1.101     raeburn  1515:                 }
                   1516:                 if ($context eq 'requestcourses') {
                   1517:                     $datatable .= '</tr><tr>';
                   1518:                     foreach my $item (@usertools) {
1.106     raeburn  1519:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1520:                     }
                   1521:                     $datatable .= '</tr></table>';
1.72      raeburn  1522:                 }
1.86      raeburn  1523:                 $datatable .= '</td>';
1.163   ! raeburn  1524:                 unless (($context eq 'requestcourses') ||
        !          1525:                         ($context eq 'requestauthor')) {
1.86      raeburn  1526:                     $datatable .= 
                   1527:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1528:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1529:                               '" value="'.$currdefquota.
1.86      raeburn  1530:                               '" size="5" /> Mb</span></td>';
                   1531:                 }
                   1532:                 $datatable .= '</tr>';
1.3       raeburn  1533:             }
                   1534:         }
                   1535:     }
1.163   ! raeburn  1536:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1537:         $defaultquota = '20';
                   1538:         if (ref($settings) eq 'HASH') {
                   1539:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1540:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1541:             } elsif (defined($settings->{'default'})) {
                   1542:                 $defaultquota = $settings->{'default'};
                   1543:             }
1.3       raeburn  1544:         }
                   1545:     }
                   1546:     $typecount ++;
                   1547:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1548:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1549:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1550:                   '<td class="LC_left_item">';
1.101     raeburn  1551:     if ($context eq 'requestcourses') {
                   1552:         $datatable .= '<table><tr>';
                   1553:     }
                   1554:     my %defcell;
1.72      raeburn  1555:     foreach my $item (@usertools) {
1.101     raeburn  1556:         if ($context eq 'requestcourses') {
                   1557:             my ($curroption,$currlimit);
                   1558:             if (ref($settings) eq 'HASH') {
                   1559:                 if (ref($settings->{$item}) eq 'HASH') {
                   1560:                     $curroption = $settings->{$item}->{'default'};
                   1561:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1562:                         $currlimit = $1;
                   1563:                     }
                   1564:                 }
                   1565:             }
                   1566:             if (!$curroption) {
                   1567:                 $curroption = 'norequest';
                   1568:             }
                   1569:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1570:             foreach my $option (@options) {
                   1571:                 my $val = $option;
                   1572:                 if ($option eq 'norequest') {
                   1573:                     $val = 0;
                   1574:                 }
                   1575:                 if ($option eq 'validate') {
                   1576:                     my $canvalidate = 0;
                   1577:                     if (ref($validations{$item}) eq 'HASH') {
                   1578:                         if ($validations{$item}{'default'}) {
                   1579:                             $canvalidate = 1;
                   1580:                         }
                   1581:                     }
                   1582:                     next if (!$canvalidate);
                   1583:                 }
                   1584:                 my $checked = '';
                   1585:                 if ($option eq $curroption) {
                   1586:                     $checked = ' checked="checked"';
                   1587:                 } elsif ($option eq 'autolimit') {
                   1588:                     if ($curroption =~ /^autolimit/) {
                   1589:                         $checked = ' checked="checked"';
                   1590:                     }
                   1591:                 }
                   1592:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1593:                                   '<input type="radio" name="crsreq_'.$item.
                   1594:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1595:                                   $titles{$option}.'</label>';
                   1596:                 if ($option eq 'autolimit') {
1.127     raeburn  1597:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1598:                                        $item.'_limit_default" size="1" '.
                   1599:                                        'value="'.$currlimit.'" />';
                   1600:                 }
1.127     raeburn  1601:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1602:                 if ($option eq 'autolimit') {
1.127     raeburn  1603:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1604:                 }
1.101     raeburn  1605:             }
1.163   ! raeburn  1606:         } elsif ($context eq 'requestauthor') {
        !          1607:             my $curroption;
        !          1608:             if (ref($settings) eq 'HASH') {
        !          1609:                 if (ref($settings->{'requestauthor'}) eq 'HASH') {
        !          1610:                     $curroption = $settings->{'requestauthor'};
        !          1611:                 }
        !          1612:             }
        !          1613:             if (!$curroption) {
        !          1614:                 $curroption = 'norequest';
        !          1615:             }
        !          1616:             foreach my $option (@options) {
        !          1617:                 my $val = $option;
        !          1618:                 if ($option eq 'norequest') {
        !          1619:                     $val = 0;
        !          1620:                 }
        !          1621:                 my $checked = '';
        !          1622:                 if ($option eq $curroption) {
        !          1623:                     $checked = ' checked="checked"';
        !          1624:                 }
        !          1625:                 $datatable .= '<span class="LC_nobreak"><label>'.
        !          1626:                               '<input type="radio" name="authorreq_default"'.
        !          1627:                               ' value="'.$val.'"'.$checked.' />'.
        !          1628:                               $titles{$option}.'</label></span>&nbsp; ';
        !          1629:             }
1.101     raeburn  1630:         } else {
                   1631:             my $checked = 'checked="checked" ';
                   1632:             if (ref($settings) eq 'HASH') {
                   1633:                 if (ref($settings->{$item}) eq 'HASH') {
                   1634:                     if ($settings->{$item}->{'default'} == 0) {
                   1635:                         $checked = '';
                   1636:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1637:                         $checked = 'checked="checked" ';
                   1638:                     }
1.78      raeburn  1639:                 }
1.72      raeburn  1640:             }
1.101     raeburn  1641:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1642:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1643:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1644:                           '</label></span>&nbsp; ';
                   1645:         }
                   1646:     }
                   1647:     if ($context eq 'requestcourses') {
                   1648:         $datatable .= '</tr><tr>';
                   1649:         foreach my $item (@usertools) {
1.106     raeburn  1650:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1651:         }
1.101     raeburn  1652:         $datatable .= '</tr></table>';
1.72      raeburn  1653:     }
1.86      raeburn  1654:     $datatable .= '</td>';
1.163   ! raeburn  1655:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1656:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1657:                       '<input type="text" name="defaultquota" value="'.
                   1658:                       $defaultquota.'" size="5" /> Mb</span></td>';
                   1659:     }
                   1660:     $datatable .= '</tr>';
1.72      raeburn  1661:     $typecount ++;
                   1662:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1663:     $datatable .= '<tr'.$css_class.'>'.
1.104     raeburn  1664:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
                   1665:     if ($context eq 'requestcourses') {
1.109     raeburn  1666:         $datatable .= &mt('(overrides affiliation, if set)').
                   1667:                       '</td>'.
                   1668:                       '<td class="LC_left_item">'.
                   1669:                       '<table><tr>';
1.101     raeburn  1670:     } else {
1.109     raeburn  1671:         $datatable .= &mt('(overrides affiliation, if checked)').
                   1672:                       '</td>'.
                   1673:                       '<td class="LC_left_item" colspan="2">'.
                   1674:                       '<br />';
1.101     raeburn  1675:     }
                   1676:     my %advcell;
1.72      raeburn  1677:     foreach my $item (@usertools) {
1.101     raeburn  1678:         if ($context eq 'requestcourses') {
                   1679:             my ($curroption,$currlimit);
                   1680:             if (ref($settings) eq 'HASH') {
                   1681:                 if (ref($settings->{$item}) eq 'HASH') {
                   1682:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   1683:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1684:                         $currlimit = $1;
                   1685:                     }
                   1686:                 }
                   1687:             }
                   1688:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  1689:             my $checked = '';
                   1690:             if ($curroption eq '') {
                   1691:                 $checked = ' checked="checked"';
                   1692:             }
                   1693:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1694:                                '<input type="radio" name="crsreq_'.$item.
                   1695:                                '__LC_adv" value=""'.$checked.' />'.
                   1696:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  1697:             foreach my $option (@options) {
                   1698:                 my $val = $option;
                   1699:                 if ($option eq 'norequest') {
                   1700:                     $val = 0;
                   1701:                 }
                   1702:                 if ($option eq 'validate') {
                   1703:                     my $canvalidate = 0;
                   1704:                     if (ref($validations{$item}) eq 'HASH') {
                   1705:                         if ($validations{$item}{'_LC_adv'}) {
                   1706:                             $canvalidate = 1;
                   1707:                         }
                   1708:                     }
                   1709:                     next if (!$canvalidate);
                   1710:                 }
                   1711:                 my $checked = '';
1.104     raeburn  1712:                 if ($val eq $curroption) {
1.101     raeburn  1713:                     $checked = ' checked="checked"';
                   1714:                 } elsif ($option eq 'autolimit') {
                   1715:                     if ($curroption =~ /^autolimit/) {
                   1716:                         $checked = ' checked="checked"';
                   1717:                     }
                   1718:                 }
                   1719:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1720:                                   '<input type="radio" name="crsreq_'.$item.
                   1721:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1722:                                   $titles{$option}.'</label>';
                   1723:                 if ($option eq 'autolimit') {
1.127     raeburn  1724:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1725:                                        $item.'_limit__LC_adv" size="1" '.
                   1726:                                        'value="'.$currlimit.'" />';
                   1727:                 }
1.127     raeburn  1728:                 $advcell{$item} .= '</span> ';
1.104     raeburn  1729:                 if ($option eq 'autolimit') {
1.127     raeburn  1730:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1731:                 }
1.101     raeburn  1732:             }
1.163   ! raeburn  1733:         } elsif ($context eq 'requestauthor') {
        !          1734:             my $curroption;
        !          1735:             if (ref($settings) eq 'HASH') {
        !          1736:                 $curroption = $settings->{'_LC_adv'};
        !          1737:             }
        !          1738:             my $checked = '';
        !          1739:             if ($curroption eq '') {
        !          1740:                 $checked = ' checked="checked"';
        !          1741:             }
        !          1742:             $datatable .= '<span class="LC_nobreak"><label>'.
        !          1743:                           '<input type="radio" name="authorreq__LC_adv"'.
        !          1744:                           ' value=""'.$checked.' />'.
        !          1745:                           &mt('No override set').'</label></span>&nbsp; ';
        !          1746:             foreach my $option (@options) {
        !          1747:                 my $val = $option;
        !          1748:                 if ($option eq 'norequest') {
        !          1749:                     $val = 0;
        !          1750:                 }
        !          1751:                 my $checked = '';
        !          1752:                 if ($val eq $curroption) {
        !          1753:                     $checked = ' checked="checked"';
        !          1754:                 }
        !          1755:                 $datatable .= '<span class="LC_nobreak"><label>'.
        !          1756:                               '<input type="radio" name="crsreq_'.$item.
        !          1757:                               '__LC_adv" value="'.$val.'"'.$checked.' />'.
        !          1758:                               $titles{$option}.'</label></span>&nbsp; ';
        !          1759:             }
1.101     raeburn  1760:         } else {
                   1761:             my $checked = 'checked="checked" ';
                   1762:             if (ref($settings) eq 'HASH') {
                   1763:                 if (ref($settings->{$item}) eq 'HASH') {
                   1764:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   1765:                         $checked = '';
                   1766:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   1767:                         $checked = 'checked="checked" ';
                   1768:                     }
1.79      raeburn  1769:                 }
1.72      raeburn  1770:             }
1.101     raeburn  1771:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1772:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1773:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   1774:                           '</label></span>&nbsp; ';
                   1775:         }
                   1776:     }
                   1777:     if ($context eq 'requestcourses') {
                   1778:         $datatable .= '</tr><tr>';
                   1779:         foreach my $item (@usertools) {
1.106     raeburn  1780:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  1781:         }
1.101     raeburn  1782:         $datatable .= '</tr></table>';
1.72      raeburn  1783:     }
1.98      raeburn  1784:     $datatable .= '</td></tr>';
1.30      raeburn  1785:     $$rowtotal += $typecount;
1.3       raeburn  1786:     return $datatable;
                   1787: }
                   1788: 
1.163   ! raeburn  1789: sub print_requestmail {
        !          1790:     my ($dom,$action,$settings,$rowtotal) = @_;
1.104     raeburn  1791:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102     raeburn  1792:     $now = time;
                   1793:     $rows = 0;
                   1794:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
                   1795:     foreach my $server (keys(%dompersonnel)) {
                   1796:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   1797:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   1798:             if (!grep(/^$uname:$udom$/,@domcoord)) {
                   1799:                 push(@domcoord,$uname.':'.$udom);
                   1800:             }
                   1801:         }
                   1802:     }
                   1803:     if (ref($settings) eq 'HASH') {
                   1804:         if (ref($settings->{'notify'}) eq 'HASH') {
                   1805:             if ($settings->{'notify'}{'approval'} ne '') {
1.104     raeburn  1806:                @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102     raeburn  1807:             }
                   1808:         }
                   1809:     }
1.104     raeburn  1810:     if (@currapproval) {
                   1811:         foreach my $dc (@currapproval) {
1.102     raeburn  1812:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
                   1813:                 push(@domcoord,$dc);
                   1814:             }
                   1815:         }
                   1816:     }
                   1817:     @domcoord = sort(@domcoord);
                   1818:     my $numinrow = 4;
                   1819:     my $numdc = @domcoord;
                   1820:     my $css_class = 'class="LC_odd_row"';
1.163   ! raeburn  1821:     my $text;
        !          1822:     if ($action eq 'requestcourses') {
        !          1823:         $text = &mt('Receive notification of course requests requiring approval');
        !          1824:     } else {
        !          1825:         $text = &mt('Receive notification of authoring space requests requiring approval')
        !          1826:     }
        !          1827:     $datatable = '<tr '.$css_class.'>'.
        !          1828:                  ' <td>'.$text.'</td>'.
1.102     raeburn  1829:                  ' <td class="LC_left_item">';
                   1830:     if (@domcoord > 0) {
                   1831:         $datatable .= '<table>';
                   1832:         for (my $i=0; $i<$numdc; $i++) {
                   1833:             my $rem = $i%($numinrow);
                   1834:             if ($rem == 0) {
                   1835:                 if ($i > 0) {
                   1836:                     $datatable .= '</tr>';
                   1837:                 }
                   1838:                 $datatable .= '<tr>';
                   1839:                 $rows ++;
                   1840:             }
                   1841:             my $check = ' ';
1.104     raeburn  1842:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102     raeburn  1843:                 $check = ' checked="checked" ';
                   1844:             }
                   1845:             my ($uname,$udom) = split(':',$domcoord[$i]);
                   1846:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
                   1847:             if ($i == $numdc-1) {
                   1848:                 my $colsleft = $numinrow-$rem;
                   1849:                 if ($colsleft > 1) {
                   1850:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   1851:                 } else {
                   1852:                     $datatable .= '<td class="LC_left_item">';
                   1853:                 }
                   1854:             } else {
                   1855:                 $datatable .= '<td class="LC_left_item">';
                   1856:             }
                   1857:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1858:                           '<input type="checkbox" name="reqapprovalnotify" '.
                   1859:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
                   1860:                           $fullname.'</label></span></td>';
                   1861:         }
                   1862:         $datatable .= '</tr></table>';
                   1863:     } else {
                   1864:         $datatable .= &mt('There are no active Domain Coordinators');
                   1865:         $rows ++;
                   1866:     }
                   1867:     $datatable .='</td></tr>';
                   1868:     $$rowtotal += $rows;
                   1869:     return $datatable;
                   1870: }
                   1871: 
1.3       raeburn  1872: sub print_autoenroll {
1.30      raeburn  1873:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  1874:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  1875:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  1876:     if (ref($settings) eq 'HASH') {
                   1877:         if (exists($settings->{'run'})) {
                   1878:             if ($settings->{'run'} eq '0') {
                   1879:                 $runoff = ' checked="checked" ';
                   1880:                 $runon = ' ';
                   1881:             } else {
                   1882:                 $runon = ' checked="checked" ';
                   1883:                 $runoff = ' ';
                   1884:             }
                   1885:         } else {
                   1886:             if ($autorun) {
                   1887:                 $runon = ' checked="checked" ';
                   1888:                 $runoff = ' ';
                   1889:             } else {
                   1890:                 $runoff = ' checked="checked" ';
                   1891:                 $runon = ' ';
                   1892:             }
                   1893:         }
1.129     raeburn  1894:         if (exists($settings->{'co-owners'})) {
                   1895:             if ($settings->{'co-owners'} eq '0') {
                   1896:                 $coownersoff = ' checked="checked" ';
                   1897:                 $coownerson = ' ';
                   1898:             } else {
                   1899:                 $coownerson = ' checked="checked" ';
                   1900:                 $coownersoff = ' ';
                   1901:             }
                   1902:         } else {
                   1903:             $coownersoff = ' checked="checked" ';
                   1904:             $coownerson = ' ';
                   1905:         }
1.3       raeburn  1906:         if (exists($settings->{'sender_domain'})) {
                   1907:             $defdom = $settings->{'sender_domain'};
                   1908:         }
1.14      raeburn  1909:     } else {
                   1910:         if ($autorun) {
                   1911:             $runon = ' checked="checked" ';
                   1912:             $runoff = ' ';
                   1913:         } else {
                   1914:             $runoff = ' checked="checked" ';
                   1915:             $runon = ' ';
                   1916:         }
1.3       raeburn  1917:     }
                   1918:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  1919:     my $notif_sender;
                   1920:     if (ref($settings) eq 'HASH') {
                   1921:         $notif_sender = $settings->{'sender_uname'};
                   1922:     }
1.3       raeburn  1923:     my $datatable='<tr class="LC_odd_row">'.
                   1924:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  1925:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  1926:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  1927:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1928:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  1929:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1930:                   '</tr><tr>'.
                   1931:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  1932:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1933:                   &mt('username').':&nbsp;'.
                   1934:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  1935:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  1936:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   1937:                   '<tr class="LC_odd_row">'.
                   1938:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   1939:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1940:                   '<input type="radio" name="autoassign_coowners"'.
                   1941:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1942:                   '<label><input type="radio" name="autoassign_coowners"'.
                   1943:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   1944:                   '</tr>';
                   1945:     $$rowtotal += 3;
1.3       raeburn  1946:     return $datatable;
                   1947: }
                   1948: 
                   1949: sub print_autoupdate {
1.30      raeburn  1950:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  1951:     my $datatable;
                   1952:     if ($position eq 'top') {
                   1953:         my $updateon = ' ';
                   1954:         my $updateoff = ' checked="checked" ';
                   1955:         my $classlistson = ' ';
                   1956:         my $classlistsoff = ' checked="checked" ';
                   1957:         if (ref($settings) eq 'HASH') {
                   1958:             if ($settings->{'run'} eq '1') {
                   1959:                 $updateon = $updateoff;
                   1960:                 $updateoff = ' ';
                   1961:             }
                   1962:             if ($settings->{'classlists'} eq '1') {
                   1963:                 $classlistson = $classlistsoff;
                   1964:                 $classlistsoff = ' ';
                   1965:             }
                   1966:         }
                   1967:         my %title = (
                   1968:                    run => 'Auto-update active?',
                   1969:                    classlists => 'Update information in classlists?',
                   1970:                     );
                   1971:         $datatable = '<tr class="LC_odd_row">'. 
                   1972:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  1973:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  1974:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  1975:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1976:                   '<label><input type="radio" name="autoupdate_run"'.
                   1977:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1978:                   '</tr><tr>'.
                   1979:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  1980:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1981:                   '<label><input type="radio" name="classlists"'.
                   1982:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1983:                   '<label><input type="radio" name="classlists"'.
                   1984:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1985:                   '</tr>';
1.30      raeburn  1986:         $$rowtotal += 2;
1.131     raeburn  1987:     } elsif ($position eq 'middle') {
                   1988:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   1989:         my $numinrow = 3;
                   1990:         my $locknamesettings;
                   1991:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   1992:                                      $dom,$numinrow,$othertitle,
                   1993:                                     'lockablenames');
                   1994:         $$rowtotal ++;
1.3       raeburn  1995:     } else {
1.44      raeburn  1996:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  1997:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  1998:                       'permanentemail','id');
1.33      raeburn  1999:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2000:         my $numrows = 0;
1.26      raeburn  2001:         if (ref($types) eq 'ARRAY') {
                   2002:             if (@{$types} > 0) {
                   2003:                 $datatable = 
                   2004:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2005:                                          \@fields,$types,\$numrows);
1.30      raeburn  2006:                     $$rowtotal += @{$types}; 
1.26      raeburn  2007:             }
1.3       raeburn  2008:         }
                   2009:         $datatable .= 
                   2010:             &usertype_update_row($settings,{'default' => $othertitle},
                   2011:                                  \%fieldtitles,\@fields,['default'],
                   2012:                                  \$numrows);
1.30      raeburn  2013:         $$rowtotal ++;     
1.3       raeburn  2014:     }
                   2015:     return $datatable;
                   2016: }
                   2017: 
1.125     raeburn  2018: sub print_autocreate {
                   2019:     my ($dom,$settings,$rowtotal) = @_;
                   2020:     my (%createon,%createoff);
                   2021:     my $curr_dc;
                   2022:     my @types = ('xml','req');
                   2023:     if (ref($settings) eq 'HASH') {
                   2024:         foreach my $item (@types) {
                   2025:             $createoff{$item} = ' checked="checked" ';
                   2026:             $createon{$item} = ' ';
                   2027:             if (exists($settings->{$item})) {
                   2028:                 if ($settings->{$item}) {
                   2029:                     $createon{$item} = ' checked="checked" ';
                   2030:                     $createoff{$item} = ' ';
                   2031:                 }
                   2032:             }
                   2033:         }
                   2034:         $curr_dc = $settings->{'xmldc'};
                   2035:     } else {
                   2036:         foreach my $item (@types) {
                   2037:             $createoff{$item} = ' checked="checked" ';
                   2038:             $createon{$item} = ' ';
                   2039:         }
                   2040:     }
                   2041:     $$rowtotal += 2;
                   2042:     my $datatable='<tr class="LC_odd_row">'.
                   2043:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2044:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2045:                   '<input type="radio" name="autocreate_xml"'.
                   2046:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2047:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2048:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2049:                   '</td></tr><tr>'.
                   2050:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2051:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2052:                   '<input type="radio" name="autocreate_req"'.
                   2053:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2054:                   '<label><input type="radio" name="autocreate_req"'.
                   2055:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125     raeburn  2056:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
                   2057:     if ($numdc > 1) {
1.143     raeburn  2058:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                   2059:                       &mt('Course creation processed as: (choose Dom. Coord.)').
                   2060:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125     raeburn  2061:         $$rowtotal ++ ;
                   2062:     } else {
1.143     raeburn  2063:         $datatable .= $dctable.'</td></tr>';
1.125     raeburn  2064:     }
                   2065:     return $datatable;
                   2066: }
                   2067: 
1.23      raeburn  2068: sub print_directorysrch {
1.30      raeburn  2069:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  2070:     my $srchon = ' ';
                   2071:     my $srchoff = ' checked="checked" ';
1.25      raeburn  2072:     my ($exacton,$containson,$beginson);
1.24      raeburn  2073:     my $localon = ' ';
                   2074:     my $localoff = ' checked="checked" ';
1.23      raeburn  2075:     if (ref($settings) eq 'HASH') {
                   2076:         if ($settings->{'available'} eq '1') {
                   2077:             $srchon = $srchoff;
                   2078:             $srchoff = ' ';
                   2079:         }
1.24      raeburn  2080:         if ($settings->{'localonly'} eq '1') {
                   2081:             $localon = $localoff;
                   2082:             $localoff = ' ';
                   2083:         }
1.25      raeburn  2084:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2085:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   2086:                 if ($type eq 'exact') {
                   2087:                     $exacton = ' checked="checked" ';
                   2088:                 } elsif ($type eq 'contains') {
                   2089:                     $containson = ' checked="checked" ';
                   2090:                 } elsif ($type eq 'begins') {
                   2091:                     $beginson = ' checked="checked" ';
                   2092:                 }
                   2093:             }
                   2094:         } else {
                   2095:             if ($settings->{'searchtypes'} eq 'exact') {
                   2096:                 $exacton = ' checked="checked" ';
                   2097:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2098:                 $containson = ' checked="checked" ';
                   2099:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   2100:                 $exacton = ' checked="checked" ';
                   2101:                 $containson = ' checked="checked" ';
                   2102:             }
1.23      raeburn  2103:         }
                   2104:     }
                   2105:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  2106:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2107: 
                   2108:     my $numinrow = 4;
1.26      raeburn  2109:     my $cansrchrow = 0;
1.23      raeburn  2110:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2111:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2112:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2113:                   '<input type="radio" name="dirsrch_available"'.
                   2114:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2115:                   '<label><input type="radio" name="dirsrch_available"'.
                   2116:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2117:                   '</tr><tr>'.
1.30      raeburn  2118:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2119:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2120:                   '<input type="radio" name="dirsrch_localonly"'.
                   2121:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2122:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2123:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2124:                   '</tr>';
1.30      raeburn  2125:     $$rowtotal += 2;
1.26      raeburn  2126:     if (ref($usertypes) eq 'HASH') {
                   2127:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2128:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2129:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2130:             $cansrchrow = 1;
                   2131:         }
                   2132:     }
                   2133:     if ($cansrchrow) {
1.30      raeburn  2134:         $$rowtotal ++;
1.26      raeburn  2135:         $datatable .= '<tr>';
                   2136:     } else {
                   2137:         $datatable .= '<tr class="LC_odd_row">';
                   2138:     }
1.30      raeburn  2139:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2140:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2141:     foreach my $title (@{$titleorder}) {
                   2142:         if (defined($searchtitles->{$title})) {
                   2143:             my $check = ' ';
1.93      raeburn  2144:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2145:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2146:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2147:                         $check = ' checked="checked" ';
                   2148:                     }
1.25      raeburn  2149:                 }
                   2150:             }
                   2151:             $datatable .= '<td class="LC_left_item">'.
                   2152:                           '<span class="LC_nobreak"><label>'.
                   2153:                           '<input type="checkbox" name="searchby" '.
                   2154:                           'value="'.$title.'"'.$check.'/>'.
                   2155:                           $searchtitles->{$title}.'</label></span></td>';
                   2156:         }
                   2157:     }
1.26      raeburn  2158:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2159:     $$rowtotal ++;
1.26      raeburn  2160:     if ($cansrchrow) {
                   2161:         $datatable .= '<tr class="LC_odd_row">';
                   2162:     } else {
                   2163:         $datatable .= '<tr>';
                   2164:     }
1.30      raeburn  2165:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2166:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2167:                   '<span class="LC_nobreak"><label>'.
                   2168:                   '<input type="checkbox" name="searchtypes" '.
                   2169:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2170:                   '</label>&nbsp;'.
                   2171:                   '<label><input type="checkbox" name="searchtypes" '.
                   2172:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2173:                   '</label>&nbsp;'.
                   2174:                   '<label><input type="checkbox" name="searchtypes" '.
                   2175:                   $containson.' value="contains" />'.&mt('Contains').
                   2176:                   '</label></span></td></tr>';
1.30      raeburn  2177:     $$rowtotal ++;
1.25      raeburn  2178:     return $datatable;
                   2179: }
                   2180: 
1.28      raeburn  2181: sub print_contacts {
1.30      raeburn  2182:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2183:     my $datatable;
                   2184:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2185:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2186:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
                   2187:                     'requestsmail');
1.28      raeburn  2188:     foreach my $type (@mailings) {
                   2189:         $otheremails{$type} = '';
                   2190:     }
1.134     raeburn  2191:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2192:     if (ref($settings) eq 'HASH') {
                   2193:         foreach my $item (@contacts) {
                   2194:             if (exists($settings->{$item})) {
                   2195:                 $to{$item} = $settings->{$item};
                   2196:             }
                   2197:         }
                   2198:         foreach my $type (@mailings) {
                   2199:             if (exists($settings->{$type})) {
                   2200:                 if (ref($settings->{$type}) eq 'HASH') {
                   2201:                     foreach my $item (@contacts) {
                   2202:                         if ($settings->{$type}{$item}) {
                   2203:                             $checked{$type}{$item} = ' checked="checked" ';
                   2204:                         }
                   2205:                     }
                   2206:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2207:                     if ($type eq 'helpdeskmail') {
                   2208:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2209:                     }
1.28      raeburn  2210:                 }
1.89      raeburn  2211:             } elsif ($type eq 'lonstatusmail') {
                   2212:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2213:             }
                   2214:         }
                   2215:     } else {
                   2216:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2217:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2218:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2219:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2220:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2221:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2222:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2223:     }
                   2224:     my ($titles,$short_titles) = &contact_titles();
                   2225:     my $rownum = 0;
                   2226:     my $css_class;
                   2227:     foreach my $item (@contacts) {
1.69      raeburn  2228:         $rownum ++;
                   2229:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2230:         $datatable .= '<tr'.$css_class.'>'. 
                   2231:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2232:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2233:                   '<input type="text" name="'.$item.'" value="'.
                   2234:                   $to{$item}.'" /></td></tr>';
                   2235:     }
                   2236:     foreach my $type (@mailings) {
1.69      raeburn  2237:         $rownum ++;
                   2238:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2239:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2240:                       '<td><span class="LC_nobreak">'.
                   2241:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2242:                       '<td class="LC_left_item">'.
                   2243:                       '<span class="LC_nobreak">';
                   2244:         foreach my $item (@contacts) {
                   2245:             $datatable .= '<label>'.
                   2246:                           '<input type="checkbox" name="'.$type.'"'.
                   2247:                           $checked{$type}{$item}.
                   2248:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2249:                           '</label>&nbsp;';
                   2250:         }
                   2251:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2252:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2253:                       'value="'.$otheremails{$type}.'"  />';
                   2254:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2255:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2256:                           '<input type="text" name="'.$type.'_bcc" '.
                   2257:                           'value="'.$bccemails{$type}.'"  />';
                   2258:         }
                   2259:         $datatable .= '</td></tr>'."\n";
1.28      raeburn  2260:     }
1.30      raeburn  2261:     $$rowtotal += $rownum;
1.28      raeburn  2262:     return $datatable;
                   2263: }
                   2264: 
1.118     jms      2265: sub print_helpsettings {
1.122     jms      2266: 
                   2267: 	my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   2268: 	my ($css_class,$datatable);
                   2269: 	
                   2270: 	my $switchserver = &check_switchserver($dom,$confname);
                   2271: 	
                   2272: 	my $itemcount = 1;
                   2273: 	
                   2274: 	if ($position eq 'top') {
                   2275: 		
                   2276: 		my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2277: 		
                   2278: 		%choices =
                   2279: 			&Apache::lonlocal::texthash (
                   2280: 				submitbugs => 'Display &quot;Submit a bug&quot; link?',
                   2281: 		);
                   2282: 		
                   2283: 		%defaultchecked = ('submitbugs' => 'on');
                   2284: 		
                   2285: 		@toggles = ('submitbugs',);
                   2286: 		
                   2287: 		foreach my $item (@toggles) {
                   2288: 			if ($defaultchecked{$item} eq 'on') { 
                   2289: 				$checkedon{$item} = ' checked="checked" ';
                   2290: 				$checkedoff{$item} = ' ';
                   2291: 			} elsif ($defaultchecked{$item} eq 'off') {
                   2292: 				$checkedoff{$item} = ' checked="checked" ';
                   2293: 				$checkedon{$item} = ' ';
                   2294: 			}
                   2295: 		}
                   2296: 		
                   2297: 		if (ref($settings) eq 'HASH') {
                   2298: 			foreach my $item (@toggles) {
                   2299: 				if ($settings->{$item} eq '1') {
                   2300: 					$checkedon{$item} =  ' checked="checked" ';
                   2301: 					$checkedoff{$item} = ' ';
                   2302: 				} elsif ($settings->{$item} eq '0') {
                   2303: 					$checkedoff{$item} =  ' checked="checked" ';
                   2304: 					$checkedon{$item} = ' ';
                   2305: 				}
                   2306: 			}
                   2307: 		 }
                   2308: 		
                   2309: 		 foreach my $item (@toggles) {
                   2310: 			$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2311: 			$datatable .=  
                   2312: 				'<tr'.$css_class.'>
                   2313: 				<td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
                   2314: 				<td><span class="LC_nobreak">&nbsp;</span></td>
                   2315: 				<td class="LC_right_item"><span class="LC_nobreak">
                   2316: 				<label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>&nbsp;
                   2317: 				<label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2318: 				'</span></td>'.
                   2319: 				'</tr>';
                   2320: 			$itemcount ++;
                   2321: 		 }
                   2322:      
                   2323:      } else {
                   2324:      
                   2325:      	$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2326:      	
                   2327:      	$datatable .= '<tr'.$css_class.'>';
                   2328:      	
                   2329:      	if (ref($settings) eq 'HASH') {
                   2330: 			if ($settings->{'loginhelpurl'} ne '') {
                   2331: 				my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
                   2332: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
                   2333: 				$datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
                   2334: 			} else {
                   2335: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
                   2336: 				$datatable .= '<td width="33%"><span class="LC_right_item">&nbsp;</span></td>';
                   2337: 			}
                   2338: 		} else {
                   2339: 			$datatable .= '<td><span class="LC_left_item">&nbsp;</span></td>';
                   2340: 			$datatable .= '<td><span class="LC_right_item">&nbsp;</span></td>';
                   2341: 		}
                   2342:     	
                   2343:      	$datatable .= '<td width="33%"><span class="LC_right_item">';
                   2344:      	if ($switchserver) {
                   2345:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2346:         } else {
                   2347:         	$datatable .= &mt('Upload Custom Login Page Help File:');
                   2348:             $datatable .='<input type="file" name="loginhelpurl" />';
                   2349:         }
                   2350:         $datatable .= '</span></td></tr>';
                   2351:         
                   2352:      }
                   2353:      
                   2354:      return $datatable;
                   2355: 	
1.121     raeburn  2356: }
                   2357: 
1.122     jms      2358: 
1.121     raeburn  2359: sub radiobutton_prefs {
                   2360:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
                   2361:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2362:                    (ref($choices) eq 'HASH'));
                   2363: 
                   2364:     my (%checkedon,%checkedoff,$datatable,$css_class);
                   2365: 
                   2366:     foreach my $item (@{$toggles}) {
                   2367:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2368:             $checkedon{$item} = ' checked="checked" ';
                   2369:             $checkedoff{$item} = ' ';
1.121     raeburn  2370:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2371:             $checkedoff{$item} = ' checked="checked" ';
                   2372:             $checkedon{$item} = ' ';
                   2373:         }
                   2374:     }
                   2375:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2376:         foreach my $item (@{$toggles}) {
1.118     jms      2377:             if ($settings->{$item} eq '1') {
                   2378:                 $checkedon{$item} =  ' checked="checked" ';
                   2379:                 $checkedoff{$item} = ' ';
                   2380:             } elsif ($settings->{$item} eq '0') {
                   2381:                 $checkedoff{$item} =  ' checked="checked" ';
                   2382:                 $checkedon{$item} = ' ';
                   2383:             }
                   2384:         }
1.121     raeburn  2385:     }
                   2386:     foreach my $item (@{$toggles}) {
1.118     jms      2387:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2388:         $datatable .=
                   2389:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118     jms      2390:             '</span></td>'.
                   2391:             '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2392:             '<label><input type="radio" name="'.
                   2393:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   2394:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   2395:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2396:             '</span></td>'.
                   2397:             '</tr>';
                   2398:         $itemcount ++;
1.121     raeburn  2399:     }
                   2400:     return ($datatable,$itemcount);
                   2401: }
                   2402: 
                   2403: sub print_coursedefaults {
1.139     raeburn  2404:     my ($position,$dom,$settings,$rowtotal) = @_;
1.121     raeburn  2405:     my ($css_class,$datatable);
                   2406:     my $itemcount = 1;
1.139     raeburn  2407:     if ($position eq 'top') {
                   2408:         my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2409:         %choices =
                   2410:             &Apache::lonlocal::texthash (
                   2411:                 canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
                   2412:         );
                   2413:         %defaultchecked = ('canuse_pdfforms' => 'off');
                   2414:         @toggles = ('canuse_pdfforms',);
                   2415:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121     raeburn  2416:                                                  \%choices,$itemcount);
1.139     raeburn  2417:         $$rowtotal += $itemcount;
                   2418:     } else {
                   2419:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2420:         my %choices =
                   2421:             &Apache::lonlocal::texthash (
                   2422:                 anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   2423:         );
                   2424:         my $currdefresponder;
                   2425:         if (ref($settings) eq 'HASH') {
                   2426:             $currdefresponder = $settings->{'anonsurvey_threshold'};
                   2427:         }
                   2428:         if (!$currdefresponder) {
                   2429:             $currdefresponder = 10;
                   2430:         } elsif ($currdefresponder < 1) {
                   2431:             $currdefresponder = 1;
                   2432:         }
                   2433:         $datatable .=
                   2434:                '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
                   2435:                 '</span></td>'.
                   2436:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2437:                 '<input type="text" name="anonsurvey_threshold"'.
                   2438:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
                   2439:                 '</td></tr>';
                   2440:     }
1.121     raeburn  2441:     return $datatable;
1.118     jms      2442: }
                   2443: 
1.137     raeburn  2444: sub print_usersessions {
                   2445:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2446:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  2447:     my (%by_ip,%by_location,@intdoms);
                   2448:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  2449: 
                   2450:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  2451:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  2452:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  2453:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  2454:     my $itemcount = 1;
                   2455:     if ($position eq 'top') {
1.152     raeburn  2456:         if (keys(%serverhomes) > 1) {
1.145     raeburn  2457:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.152     raeburn  2458:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145     raeburn  2459:         } else {
1.140     raeburn  2460:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2461:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  2462:         }
1.137     raeburn  2463:     } else {
1.145     raeburn  2464:         if (keys(%by_location) == 0) {
                   2465:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2466:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  2467:         } else {
                   2468:             my %lt = &usersession_titles();
                   2469:             my $numinrow = 5;
                   2470:             my $prefix;
                   2471:             my @types;
                   2472:             if ($position eq 'bottom') {
                   2473:                 $prefix = 'remote';
                   2474:                 @types = ('version','excludedomain','includedomain');
                   2475:             } else {
                   2476:                 $prefix = 'hosted';
                   2477:                 @types = ('excludedomain','includedomain');
                   2478:             }
                   2479:             my (%current,%checkedon,%checkedoff);
                   2480:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   2481:             my @locations = sort(keys(%by_location));
                   2482:             foreach my $type (@types) {
                   2483:                 $checkedon{$type} = '';
                   2484:                 $checkedoff{$type} = ' checked="checked"';
                   2485:             }
                   2486:             if (ref($settings) eq 'HASH') {
                   2487:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   2488:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   2489:                         $current{$key} = $settings->{$prefix}{$key};
                   2490:                         if ($key eq 'version') {
                   2491:                             if ($current{$key} ne '') {
                   2492:                                 $checkedon{$key} = ' checked="checked"';
                   2493:                                 $checkedoff{$key} = '';
                   2494:                             }
                   2495:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   2496:                             $checkedon{$key} = ' checked="checked"';
                   2497:                             $checkedoff{$key} = '';
                   2498:                         }
1.137     raeburn  2499:                     }
                   2500:                 }
                   2501:             }
1.145     raeburn  2502:             foreach my $type (@types) {
                   2503:                 next if ($type ne 'version' && !@locations);
                   2504:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2505:                 $datatable .= '<tr'.$css_class.'>
                   2506:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   2507:                                <span class="LC_nobreak">&nbsp;
                   2508:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   2509:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   2510:                 if ($type eq 'version') {
                   2511:                     my $selector = '<select name="'.$prefix.'_version">';
                   2512:                     foreach my $version (@lcversions) {
                   2513:                         my $selected = '';
                   2514:                         if ($current{'version'} eq $version) {
                   2515:                             $selected = ' selected="selected"';
                   2516:                         }
                   2517:                         $selector .= ' <option value="'.$version.'"'.
                   2518:                                      $selected.'>'.$version.'</option>';
                   2519:                     }
                   2520:                     $selector .= '</select> ';
                   2521:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   2522:                 } else {
                   2523:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   2524:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   2525:                                  ' />'.('&nbsp;'x2).
                   2526:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   2527:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   2528:                                  "\n".
                   2529:                                  '</div><div><table>';
                   2530:                     my $rem;
                   2531:                     for (my $i=0; $i<@locations; $i++) {
                   2532:                         my ($showloc,$value,$checkedtype);
                   2533:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   2534:                             my $ip = $by_location{$locations[$i]}->[0];
                   2535:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   2536:                                  $value = join(':',@{$by_ip{$ip}});
                   2537:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   2538:                                 if (ref($current{$type}) eq 'ARRAY') {
                   2539:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   2540:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   2541:                                             $checkedtype = ' checked="checked"';
                   2542:                                             last;
                   2543:                                         }
                   2544:                                     }
1.138     raeburn  2545:                                 }
                   2546:                             }
                   2547:                         }
1.145     raeburn  2548:                         $rem = $i%($numinrow);
                   2549:                         if ($rem == 0) {
                   2550:                             if ($i > 0) {
                   2551:                                 $datatable .= '</tr>';
                   2552:                             }
                   2553:                             $datatable .= '<tr>';
                   2554:                         }
                   2555:                         $datatable .= '<td class="LC_left_item">'.
                   2556:                                       '<span class="LC_nobreak"><label>'.
                   2557:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   2558:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   2559:                                       '</label></span></td>';
1.137     raeburn  2560:                     }
1.145     raeburn  2561:                     $rem = @locations%($numinrow);
                   2562:                     my $colsleft = $numinrow - $rem;
                   2563:                     if ($colsleft > 1 ) {
                   2564:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2565:                                       '&nbsp;</td>';
                   2566:                     } elsif ($colsleft == 1) {
                   2567:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  2568:                     }
1.145     raeburn  2569:                     $datatable .= '</tr></table>';
1.137     raeburn  2570:                 }
1.145     raeburn  2571:                 $datatable .= '</td></tr>';
                   2572:                 $itemcount ++;
1.137     raeburn  2573:             }
                   2574:         }
                   2575:     }
                   2576:     $$rowtotal += $itemcount;
                   2577:     return $datatable;
                   2578: }
                   2579: 
1.138     raeburn  2580: sub build_location_hashes {
                   2581:     my ($intdoms,$by_ip,$by_location) = @_;
                   2582:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   2583:                   (ref($by_location) eq 'HASH')); 
                   2584:     my %iphost = &Apache::lonnet::get_iphost();
                   2585:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   2586:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   2587:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   2588:         foreach my $id (@{$iphost{$primary_ip}}) {
                   2589:             my $intdom = &Apache::lonnet::internet_dom($id);
                   2590:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   2591:                 push(@{$intdoms},$intdom);
                   2592:             }
                   2593:         }
                   2594:     }
                   2595:     foreach my $ip (keys(%iphost)) {
                   2596:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   2597:             foreach my $id (@{$iphost{$ip}}) {
                   2598:                 my $location = &Apache::lonnet::internet_dom($id);
                   2599:                 if ($location) {
                   2600:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   2601:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2602:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   2603:                             push(@{$by_ip->{$ip}},$location);
                   2604:                         }
                   2605:                     } else {
                   2606:                         $by_ip->{$ip} = [$location];
                   2607:                     }
                   2608:                 }
                   2609:             }
                   2610:         }
                   2611:     }
                   2612:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   2613:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2614:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   2615:             my $first = $by_ip->{$ip}->[0];
                   2616:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   2617:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   2618:                     push(@{$by_location->{$first}},$ip);
                   2619:                 }
                   2620:             } else {
                   2621:                 $by_location->{$first} = [$ip];
                   2622:             }
                   2623:         }
                   2624:     }
                   2625:     return;
                   2626: }
                   2627: 
1.145     raeburn  2628: sub current_offloads_to {
                   2629:     my ($dom,$settings,$servers) = @_;
                   2630:     my (%spareid,%otherdomconfigs);
1.152     raeburn  2631:     if (ref($servers) eq 'HASH') {
1.145     raeburn  2632:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   2633:             my $gotspares;
1.152     raeburn  2634:             if (ref($settings) eq 'HASH') {
                   2635:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   2636:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   2637:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   2638:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   2639:                         $gotspares = 1;
                   2640:                     }
1.145     raeburn  2641:                 }
                   2642:             }
                   2643:             unless ($gotspares) {
                   2644:                 my $gotspares;
                   2645:                 my $serverhomeID =
                   2646:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   2647:                 my $serverhomedom =
                   2648:                     &Apache::lonnet::host_domain($serverhomeID);
                   2649:                 if ($serverhomedom ne $dom) {
                   2650:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   2651:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2652:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2653:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2654:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2655:                                 $gotspares = 1;
                   2656:                             }
                   2657:                         }
                   2658:                     } else {
                   2659:                         $otherdomconfigs{$serverhomedom} =
                   2660:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   2661:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   2662:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2663:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2664:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   2665:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2666:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2667:                                         $gotspares = 1;
                   2668:                                     }
                   2669:                                 }
                   2670:                             }
                   2671:                         }
                   2672:                     }
                   2673:                 }
                   2674:             }
                   2675:             unless ($gotspares) {
                   2676:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2677:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2678:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2679:                } else {
                   2680:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   2681:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   2682:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2683:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2684:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2685:                     } else {
1.150     raeburn  2686:                         my %what = (
                   2687:                              spareid => 1,
                   2688:                         );
                   2689:                         my ($result,$returnhash) = 
                   2690:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   2691:                         if ($result eq 'ok') { 
                   2692:                             if (ref($returnhash) eq 'HASH') {
                   2693:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   2694:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   2695:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   2696:                                 }
                   2697:                             }
1.145     raeburn  2698:                         }
                   2699:                     }
                   2700:                 }
                   2701:             }
                   2702:         }
                   2703:     }
                   2704:     return %spareid;
                   2705: }
                   2706: 
                   2707: sub spares_row {
1.152     raeburn  2708:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145     raeburn  2709:     my $css_class;
                   2710:     my $numinrow = 4;
                   2711:     my $itemcount = 1;
                   2712:     my $datatable;
1.152     raeburn  2713:     my %typetitles = &sparestype_titles();
                   2714:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  2715:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  2716:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   2717:             my ($othercontrol,$serverdom);
                   2718:             if ($serverhome ne $server) {
                   2719:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   2720:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2721:             } else {
                   2722:                 $serverdom = &Apache::lonnet::host_domain($server);
                   2723:                 if ($serverdom ne $dom) {
                   2724:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2725:                 }
                   2726:             }
                   2727:             next unless (ref($spareid->{$server}) eq 'HASH');
1.145     raeburn  2728:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2729:             $datatable .= '<tr'.$css_class.'>
                   2730:                            <td rowspan="2">
1.152     raeburn  2731:                             <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145     raeburn  2732:             my (%current,%canselect);
1.152     raeburn  2733:             my @choices = 
                   2734:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   2735:             foreach my $type ('primary','default') {
                   2736:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  2737:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   2738:                         my @spares = @{$spareid->{$server}{$type}};
                   2739:                         if (@spares > 0) {
1.152     raeburn  2740:                             if ($othercontrol) {
                   2741:                                 $current{$type} = join(', ',@spares);
                   2742:                             } else {
                   2743:                                 $current{$type} .= '<table>';
                   2744:                                 my $numspares = scalar(@spares);
                   2745:                                 for (my $i=0;  $i<@spares; $i++) {
                   2746:                                     my $rem = $i%($numinrow);
                   2747:                                     if ($rem == 0) {
                   2748:                                         if ($i > 0) {
                   2749:                                             $current{$type} .= '</tr>';
                   2750:                                         }
                   2751:                                         $current{$type} .= '<tr>';
1.145     raeburn  2752:                                     }
1.152     raeburn  2753:                                     $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;'.
                   2754:                                                        $spareid->{$server}{$type}[$i].
                   2755:                                                        '</label></td>'."\n";
                   2756:                                 }
                   2757:                                 my $rem = @spares%($numinrow);
                   2758:                                 my $colsleft = $numinrow - $rem;
                   2759:                                 if ($colsleft > 1 ) {
                   2760:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   2761:                                                        '" class="LC_left_item">'.
                   2762:                                                        '&nbsp;</td>';
                   2763:                                 } elsif ($colsleft == 1) {
                   2764:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  2765:                                 }
1.152     raeburn  2766:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  2767:                             }
1.145     raeburn  2768:                         }
                   2769:                     }
                   2770:                     if ($current{$type} eq '') {
                   2771:                         $current{$type} = &mt('None specified');
                   2772:                     }
1.152     raeburn  2773:                     if ($othercontrol) {
                   2774:                         if ($type eq 'primary') {
                   2775:                             $canselect{$type} = $othercontrol;
                   2776:                         }
                   2777:                     } else {
                   2778:                         $canselect{$type} = 
                   2779:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   2780:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   2781:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   2782:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   2783:                         if (@choices > 0) {
                   2784:                             foreach my $lonhost (@choices) {
                   2785:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   2786:                             }
                   2787:                         }
                   2788:                         $canselect{$type} .= '</select>'."\n";
                   2789:                     }
                   2790:                 } else {
                   2791:                     $current{$type} = &mt('Could not be determined');
                   2792:                     if ($type eq 'primary') {
                   2793:                         $canselect{$type} =  $othercontrol;
                   2794:                     }
1.145     raeburn  2795:                 }
1.152     raeburn  2796:                 if ($type eq 'default') {
                   2797:                     $datatable .= '<tr'.$css_class.'>';
                   2798:                 }
                   2799:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   2800:                               '<td>'.$current{$type}.'</td>'."\n".
                   2801:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  2802:             }
                   2803:             $itemcount ++;
                   2804:         }
                   2805:     }
                   2806:     $$rowtotal += $itemcount;
                   2807:     return $datatable;
                   2808: }
                   2809: 
1.152     raeburn  2810: sub possible_newspares {
                   2811:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   2812:     my $serverhostname = &Apache::lonnet::hostname($server);
                   2813:     my %excluded;
                   2814:     if ($serverhostname ne '') {
                   2815:         %excluded = (
                   2816:                        $serverhostname => 1,
                   2817:                     );
                   2818:     }
                   2819:     if (ref($currspares) eq 'HASH') {
                   2820:         foreach my $type (keys(%{$currspares})) {
                   2821:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   2822:                 if (@{$currspares->{$type}} > 0) {
                   2823:                     foreach my $curr (@{$currspares->{$type}}) {
                   2824:                         my $hostname = &Apache::lonnet::hostname($curr);
                   2825:                         $excluded{$hostname} = 1;
                   2826:                     }
                   2827:                 }
                   2828:             }
                   2829:         }
                   2830:     }
                   2831:     my @choices;
                   2832:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   2833:         if (keys(%{$serverhomes}) > 1) {
                   2834:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   2835:                 unless ($excluded{$name}) {
                   2836:                     if (exists($altids->{$serverhomes->{$name}})) {
                   2837:                         push(@choices,$altids->{$serverhomes->{$name}});
                   2838:                     } else {
                   2839:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  2840:                     }
                   2841:                 }
                   2842:             }
                   2843:         }
                   2844:     }
1.152     raeburn  2845:     return sort(@choices);
1.145     raeburn  2846: }
                   2847: 
1.150     raeburn  2848: sub print_loadbalancing {
                   2849:     my ($dom,$settings,$rowtotal) = @_;
                   2850:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   2851:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2852:     my $numinrow = 1;
                   2853:     my $datatable;
                   2854:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   2855:     my ($currbalancer,$currtargets,$currrules);
                   2856:     if (keys(%servers) > 1) {
                   2857:         if (ref($settings) eq 'HASH') {
                   2858:             $currbalancer = $settings->{'lonhost'};
                   2859:             $currtargets = $settings->{'targets'};
                   2860:             $currrules = $settings->{'rules'};
                   2861:         } else {
                   2862:             ($currbalancer,$currtargets) = 
                   2863:                 &Apache::lonnet::get_lonbalancer_config(\%servers);
                   2864:         }
                   2865:     } else {
                   2866:         return;
                   2867:     }
                   2868:     my ($othertitle,$usertypes,$types) =
                   2869:         &Apache::loncommon::sorted_inst_types($dom);
                   2870:     my $rownum = 6;
                   2871:     if (ref($types) eq 'ARRAY') {
                   2872:         $rownum += scalar(@{$types});
                   2873:     }
1.153     raeburn  2874:     my $css_class = ' class="LC_odd_row"';
1.150     raeburn  2875:     my $targets_div_style = 'display: none';
                   2876:     my $disabled_div_style = 'display: block';
                   2877:     my $homedom_div_style = 'display: none';
                   2878:     $datatable = '<tr'.$css_class.'>'.
                   2879:                  '<td rowspan="'.$rownum.'" valign="top">'.
                   2880:                  '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
                   2881:                  '<option value=""';
                   2882:     if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
                   2883:         $datatable .= ' selected="selected"';
                   2884:     } else {
                   2885:         $targets_div_style = 'display: block';
                   2886:         $disabled_div_style = 'display: none';
                   2887:         if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
                   2888:             $homedom_div_style = 'display: block'; 
                   2889:         }
                   2890:     }
                   2891:     $datatable .= '>'.&mt('None').'</option>'."\n";
                   2892:     foreach my $lonhost (sort(keys(%servers))) {
                   2893:         my $selected;
                   2894:         if ($lonhost eq $currbalancer) {
                   2895:             $selected .= ' selected="selected"';
                   2896:         }
                   2897:         $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
                   2898:     }
                   2899:     $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
                   2900:                   '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
                   2901:                   '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   2902:     my ($numspares,@spares) = &count_servers($currbalancer,%servers);
                   2903:     my @sparestypes = ('primary','default');
                   2904:     my %typetitles = &sparestype_titles();
                   2905:     foreach my $sparetype (@sparestypes) {
                   2906:         my $targettable;
                   2907:         for (my $i=0; $i<$numspares; $i++) {
                   2908:             my $checked;
                   2909:             if (ref($currtargets) eq 'HASH') {
                   2910:                 if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
                   2911:                     if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
                   2912:                         $checked = ' checked="checked"';
                   2913:                     }
                   2914:                 }
                   2915:             }
                   2916:             my $chkboxval;
                   2917:             if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
                   2918:                 $chkboxval = $spares[$i];
                   2919:             }
                   2920:             $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
                   2921:                       $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                   2922:                       '</span></label></td>';
                   2923:             my $rem = $i%($numinrow);
                   2924:             if ($rem == 0) {
                   2925:                 if ($i > 0) {
                   2926:                     $targettable .= '</tr>';
                   2927:                 }
                   2928:                 $targettable .= '<tr>';
                   2929:             }
                   2930:         }
                   2931:         if ($targettable ne '') {
                   2932:             my $rem = $numspares%($numinrow);
                   2933:             my $colsleft = $numinrow - $rem;
                   2934:             if ($colsleft > 1 ) {
                   2935:                 $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2936:                                 '&nbsp;</td>';
                   2937:             } elsif ($colsleft == 1) {
                   2938:                 $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   2939:             }
                   2940:             $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   2941:                            '<table><tr>'.$targettable.'</table><br />';
                   2942:         }
                   2943:     }
                   2944:     $datatable .= '</div></td></tr>'.
                   2945:                   &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
                   2946:                                        $usertypes,$types,\%servers,$currbalancer,
1.153     raeburn  2947:                                        $targets_div_style,$homedom_div_style,$css_class);
1.150     raeburn  2948:     $$rowtotal += $rownum;
                   2949:     return $datatable;
                   2950: }
                   2951: 
                   2952: sub loadbalancing_rules {
                   2953:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.153     raeburn  2954:         $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
1.150     raeburn  2955:     my $output;
                   2956:     my ($alltypes,$othertypes,$titles) = 
                   2957:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   2958:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   2959:         foreach my $type (@{$alltypes}) {
                   2960:             my $current;
                   2961:             if (ref($currrules) eq 'HASH') {
                   2962:                 $current = $currrules->{$type};
                   2963:             }
                   2964:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   2965:                 if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
                   2966:                     $current = '';
                   2967:                 }
                   2968:             }
                   2969:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
                   2970:                                              $servers,$currbalancer,$dom,
1.153     raeburn  2971:                                              $targets_div_style,$homedom_div_style,$css_class);
1.150     raeburn  2972:         }
                   2973:     }
                   2974:     return $output;
                   2975: }
                   2976: 
                   2977: sub loadbalancing_titles {
                   2978:     my ($dom,$intdom,$usertypes,$types) = @_;
                   2979:     my %othertypes = (
                   2980:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   2981:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   2982:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   2983:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
                   2984:                      );
                   2985:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   2986:     if (ref($types) eq 'ARRAY') {
                   2987:         unshift(@alltypes,@{$types},'default');
                   2988:     }
                   2989:     my %titles;
                   2990:     foreach my $type (@alltypes) {
                   2991:         if ($type =~ /^_LC_/) {
                   2992:             $titles{$type} = $othertypes{$type};
                   2993:         } elsif ($type eq 'default') {
                   2994:             $titles{$type} = &mt('All users from [_1]',$dom);
                   2995:             if (ref($types) eq 'ARRAY') {
                   2996:                 if (@{$types} > 0) {
                   2997:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   2998:                 }
                   2999:             }
                   3000:         } elsif (ref($usertypes) eq 'HASH') {
                   3001:             $titles{$type} = $usertypes->{$type};
                   3002:         }
                   3003:     }
                   3004:     return (\@alltypes,\%othertypes,\%titles);
                   3005: }
                   3006: 
                   3007: sub loadbalance_rule_row {
                   3008:     my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
1.153     raeburn  3009:         $homedom_div_style,$css_class) = @_;
1.150     raeburn  3010:     my @rulenames = ('default','homeserver');
                   3011:     my %ruletitles = &offloadtype_text();
                   3012:     if ($type eq '_LC_external') {
                   3013:         push(@rulenames,'externalbalancer');
                   3014:     } else {
                   3015:         push(@rulenames,'specific');
                   3016:     }
1.161     raeburn  3017:     push(@rulenames,'none');
1.150     raeburn  3018:     my $style = $targets_div_style;
                   3019:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   3020:         $style = $homedom_div_style;
                   3021:     }
                   3022:     my $output = 
1.153     raeburn  3023:         '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
1.150     raeburn  3024:         '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
                   3025:     for (my $i=0; $i<@rulenames; $i++) {
                   3026:         my $rule = $rulenames[$i];
                   3027:         my ($checked,$extra);
                   3028:         if ($rulenames[$i] eq 'default') {
                   3029:             $rule = '';
                   3030:         }
                   3031:         if ($rulenames[$i] eq 'specific') {
                   3032:             if (ref($servers) eq 'HASH') {
                   3033:                 my $default;
                   3034:                 if (($current ne '') && (exists($servers->{$current}))) {
                   3035:                     $checked = ' checked="checked"';
                   3036:                 }
                   3037:                 unless ($checked) {
                   3038:                     $default = ' selected="selected"';
                   3039:                 }
                   3040:                 $extra = ':&nbsp;<select name="loadbalancing_singleserver_'.$type.
                   3041:                          '" id="loadbalancing_singleserver_'.$type.
                   3042:                          '" onchange="singleServerToggle('."'$type'".')">'."\n".
                   3043:                          '<option value=""'.$default.'></option>'."\n";
                   3044:                 foreach my $lonhost (sort(keys(%{$servers}))) {
                   3045:                     next if ($lonhost eq $currbalancer);
                   3046:                     my $selected;
                   3047:                     if ($lonhost eq $current) {
                   3048:                         $selected = ' selected="selected"';
                   3049:                     }
                   3050:                     $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
                   3051:                 }
                   3052:                 $extra .= '</select>';
                   3053:             }
                   3054:         } elsif ($rule eq $current) {
                   3055:             $checked = ' checked="checked"';
                   3056:         }
                   3057:         $output .= '<span class="LC_nobreak"><label>'.
                   3058:                    '<input type="radio" name="loadbalancing_rules_'.$type.
                   3059:                    '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
                   3060:                    $rule.'" onclick="balanceruleChange('."this.form,'$type'".
                   3061:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   3062:                    '</label>'.$extra.'</span><br />'."\n";
                   3063:     }
                   3064:     $output .= '</div></td></tr>'."\n";
                   3065:     return $output;
                   3066: }
                   3067: 
                   3068: sub offloadtype_text {
                   3069:     my %ruletitles = &Apache::lonlocal::texthash (
                   3070:            'default'          => 'Offloads to default destinations',
                   3071:            'homeserver'       => "Offloads to user's home server",
                   3072:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   3073:            'specific'         => 'Offloads to specific server',
1.161     raeburn  3074:            'none'             => 'No offload',
1.150     raeburn  3075:     );
                   3076:     return %ruletitles;
                   3077: }
                   3078: 
                   3079: sub sparestype_titles {
                   3080:     my %typestitles = &Apache::lonlocal::texthash (
                   3081:                           'primary' => 'primary',
                   3082:                           'default' => 'default',
                   3083:                       );
                   3084:     return %typestitles;
                   3085: }
                   3086: 
1.28      raeburn  3087: sub contact_titles {
                   3088:     my %titles = &Apache::lonlocal::texthash (
                   3089:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  3090:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  3091:                    'errormail'    => 'Error reports to be e-mailed to',
                   3092:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  3093:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   3094:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  3095:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.28      raeburn  3096:                  );
                   3097:     my %short_titles = &Apache::lonlocal::texthash (
                   3098:                            adminemail   => 'Admin E-mail address',
                   3099:                            supportemail => 'Support E-mail',
                   3100:                        );   
                   3101:     return (\%titles,\%short_titles);
                   3102: }
                   3103: 
1.72      raeburn  3104: sub tool_titles {
                   3105:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  3106:                      aboutme    => 'Personal web page',
1.86      raeburn  3107:                      blog       => 'Blog',
1.162     raeburn  3108:                      webdav     => 'WebDAV',
1.86      raeburn  3109:                      portfolio  => 'Portfolio',
1.88      bisitz   3110:                      official   => 'Official courses (with institutional codes)',
                   3111:                      unofficial => 'Unofficial courses',
1.98      raeburn  3112:                      community  => 'Communities',
1.86      raeburn  3113:                  );
1.72      raeburn  3114:     return %titles;
                   3115: }
                   3116: 
1.101     raeburn  3117: sub courserequest_titles {
                   3118:     my %titles = &Apache::lonlocal::texthash (
                   3119:                                    official   => 'Official',
                   3120:                                    unofficial => 'Unofficial',
                   3121:                                    community  => 'Communities',
                   3122:                                    norequest  => 'Not allowed',
1.104     raeburn  3123:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3124:                                    validate   => 'With validation',
                   3125:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3126:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3127:                  );
                   3128:     return %titles;
                   3129: }
                   3130: 
1.163   ! raeburn  3131: sub authorrequest_titles {
        !          3132:     my %titles = &Apache::lonlocal::texthash (
        !          3133:                                    norequest  => 'Not allowed',
        !          3134:                                    approval   => 'Approval by Dom. Coord.',
        !          3135:                                    automatic  => 'Automatic approval',
        !          3136:                  );
        !          3137:     return %titles;
        !          3138: } 
        !          3139: 
1.101     raeburn  3140: sub courserequest_conditions {
                   3141:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3142:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.101     raeburn  3143:        validate   => '(Processing of request subject to instittutional validation).',
                   3144:                  );
                   3145:     return %conditions;
                   3146: }
                   3147: 
                   3148: 
1.27      raeburn  3149: sub print_usercreation {
1.30      raeburn  3150:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3151:     my $numinrow = 4;
1.28      raeburn  3152:     my $datatable;
                   3153:     if ($position eq 'top') {
1.30      raeburn  3154:         $$rowtotal ++;
1.34      raeburn  3155:         my $rowcount = 0;
1.32      raeburn  3156:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3157:         if (ref($rules) eq 'HASH') {
                   3158:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3159:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3160:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3161:                 $$rowtotal ++;
1.32      raeburn  3162:                 $rowcount ++;
                   3163:             }
                   3164:         }
                   3165:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3166:         if (ref($idrules) eq 'HASH') {
                   3167:             if (keys(%{$idrules}) > 0) {
                   3168:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3169:                                                 $idruleorder,$numinrow,$rowcount);
                   3170:                 $$rowtotal ++;
                   3171:                 $rowcount ++;
1.28      raeburn  3172:             }
                   3173:         }
1.43      raeburn  3174:         my ($emailrules,$emailruleorder) = 
                   3175:             &Apache::lonnet::inst_userrules($dom,'email');
                   3176:         if (ref($emailrules) eq 'HASH') {
                   3177:             if (keys(%{$emailrules}) > 0) {
                   3178:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
                   3179:                                                 $emailruleorder,$numinrow,$rowcount);
                   3180:                 $$rowtotal ++;
                   3181:                 $rowcount ++;
                   3182:             }
                   3183:         }
1.39      raeburn  3184:         if ($rowcount == 0) {
                   3185:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3186:             $$rowtotal ++;
                   3187:             $rowcount ++;
                   3188:         }
1.34      raeburn  3189:     } elsif ($position eq 'middle') {
1.100     raeburn  3190:         my @creators = ('author','course','requestcrs','selfcreate');
1.37      raeburn  3191:         my ($rules,$ruleorder) =
                   3192:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3193:         my %lt = &usercreation_types();
                   3194:         my %checked;
1.50      raeburn  3195:         my @selfcreate; 
1.34      raeburn  3196:         if (ref($settings) eq 'HASH') {
                   3197:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3198:                 foreach my $item (@creators) {
                   3199:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3200:                 }
1.50      raeburn  3201:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3202:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3203:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3204:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3205:                         @selfcreate = ('email','login','sso');
                   3206:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3207:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3208:                     }
                   3209:                 }
1.34      raeburn  3210:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3211:                 foreach my $item (@creators) {
                   3212:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3213:                         $checked{$item} = 'none';
                   3214:                     }
                   3215:                 }
                   3216:             }
                   3217:         }
                   3218:         my $rownum = 0;
                   3219:         foreach my $item (@creators) {
                   3220:             $rownum ++;
1.50      raeburn  3221:             if ($item ne 'selfcreate') {  
                   3222:                 if ($checked{$item} eq '') {
1.43      raeburn  3223:                     $checked{$item} = 'any';
                   3224:                 }
1.34      raeburn  3225:             }
                   3226:             my $css_class;
                   3227:             if ($rownum%2) {
                   3228:                 $css_class = '';
                   3229:             } else {
                   3230:                 $css_class = ' class="LC_odd_row" ';
                   3231:             }
                   3232:             $datatable .= '<tr'.$css_class.'>'.
                   3233:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3234:                          '</span></td><td align="right">';
1.50      raeburn  3235:             my @options;
1.45      raeburn  3236:             if ($item eq 'selfcreate') {
1.43      raeburn  3237:                 push(@options,('email','login','sso'));
                   3238:             } else {
1.50      raeburn  3239:                 @options = ('any');
1.43      raeburn  3240:                 if (ref($rules) eq 'HASH') {
                   3241:                     if (keys(%{$rules}) > 0) {
                   3242:                         push(@options,('official','unofficial'));
                   3243:                     }
1.37      raeburn  3244:                 }
1.50      raeburn  3245:                 push(@options,'none');
1.37      raeburn  3246:             }
                   3247:             foreach my $option (@options) {
1.50      raeburn  3248:                 my $type = 'radio';
1.34      raeburn  3249:                 my $check = ' ';
1.50      raeburn  3250:                 if ($item eq 'selfcreate') {
                   3251:                     $type = 'checkbox';
                   3252:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
                   3253:                         $check = ' checked="checked" ';
                   3254:                     }
                   3255:                 } else {
                   3256:                     if ($checked{$item} eq $option) {
                   3257:                         $check = ' checked="checked" ';
                   3258:                     }
1.34      raeburn  3259:                 } 
                   3260:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3261:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3262:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3263:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3264:             }
                   3265:             $datatable .= '</td></tr>';
                   3266:         }
1.93      raeburn  3267:         my ($othertitle,$usertypes,$types) =
                   3268:             &Apache::loncommon::sorted_inst_types($dom);
                   3269:         if (ref($usertypes) eq 'HASH') {
                   3270:             if (keys(%{$usertypes}) > 0) {
1.99      raeburn  3271:                 my $createsettings;
                   3272:                 if (ref($settings) eq 'HASH') {
                   3273:                     $createsettings = $settings->{cancreate};
                   3274:                 }
                   3275:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93      raeburn  3276:                                              $dom,$numinrow,$othertitle,
                   3277:                                              'statustocreate');
                   3278:                 $$rowtotal ++;
                   3279:             }
                   3280:         }
1.28      raeburn  3281:     } else {
                   3282:         my @contexts = ('author','course','domain');
                   3283:         my @authtypes = ('int','krb4','krb5','loc');
                   3284:         my %checked;
                   3285:         if (ref($settings) eq 'HASH') {
                   3286:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3287:                 foreach my $item (@contexts) {
                   3288:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3289:                         foreach my $auth (@authtypes) {
                   3290:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3291:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3292:                             }
                   3293:                         }
                   3294:                     }
                   3295:                 }
1.27      raeburn  3296:             }
1.35      raeburn  3297:         } else {
                   3298:             foreach my $item (@contexts) {
1.36      raeburn  3299:                 foreach my $auth (@authtypes) {
1.35      raeburn  3300:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3301:                 }
                   3302:             }
1.27      raeburn  3303:         }
1.28      raeburn  3304:         my %title = &context_names();
                   3305:         my %authname = &authtype_names();
                   3306:         my $rownum = 0;
                   3307:         my $css_class; 
                   3308:         foreach my $item (@contexts) {
                   3309:             if ($rownum%2) {
                   3310:                 $css_class = '';
                   3311:             } else {
                   3312:                 $css_class = ' class="LC_odd_row" ';
                   3313:             }
1.30      raeburn  3314:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3315:                             '<td>'.$title{$item}.
                   3316:                             '</td><td class="LC_left_item">'.
                   3317:                             '<span class="LC_nobreak">';
                   3318:             foreach my $auth (@authtypes) {
                   3319:                 $datatable .= '<label>'. 
                   3320:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3321:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3322:                               $authname{$auth}.'</label>&nbsp;';
                   3323:             }
                   3324:             $datatable .= '</span></td></tr>';
                   3325:             $rownum ++;
1.27      raeburn  3326:         }
1.30      raeburn  3327:         $$rowtotal += $rownum;
1.27      raeburn  3328:     }
                   3329:     return $datatable;
                   3330: }
                   3331: 
1.32      raeburn  3332: sub user_formats_row {
                   3333:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   3334:     my $output;
                   3335:     my %text = (
                   3336:                    'username' => 'new usernames',
                   3337:                    'id'       => 'IDs',
1.45      raeburn  3338:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  3339:                );
                   3340:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   3341:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  3342:               '<td><span class="LC_nobreak">';
                   3343:     if ($type eq 'email') {
                   3344:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   3345:     } else {
                   3346:         $output .= &mt("Format rules to check for $text{$type}: ");
                   3347:     }
                   3348:     $output .= '</span></td>'.
                   3349:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  3350:     my $rem;
                   3351:     if (ref($ruleorder) eq 'ARRAY') {
                   3352:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   3353:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   3354:                 my $rem = $i%($numinrow);
                   3355:                 if ($rem == 0) {
                   3356:                     if ($i > 0) {
                   3357:                         $output .= '</tr>';
                   3358:                     }
                   3359:                     $output .= '<tr>';
                   3360:                 }
                   3361:                 my $check = ' ';
1.39      raeburn  3362:                 if (ref($settings) eq 'HASH') {
                   3363:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   3364:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   3365:                             $check = ' checked="checked" ';
                   3366:                         }
1.27      raeburn  3367:                     }
                   3368:                 }
                   3369:                 $output .= '<td class="LC_left_item">'.
                   3370:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  3371:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  3372:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   3373:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   3374:             }
                   3375:         }
                   3376:         $rem = @{$ruleorder}%($numinrow);
                   3377:     }
                   3378:     my $colsleft = $numinrow - $rem;
                   3379:     if ($colsleft > 1 ) {
                   3380:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3381:                    '&nbsp;</td>';
                   3382:     } elsif ($colsleft == 1) {
                   3383:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   3384:     }
                   3385:     $output .= '</tr></table></td></tr>';
                   3386:     return $output;
                   3387: }
                   3388: 
1.34      raeburn  3389: sub usercreation_types {
                   3390:     my %lt = &Apache::lonlocal::texthash (
                   3391:                     author     => 'When adding a co-author',
                   3392:                     course     => 'When adding a user to a course',
1.100     raeburn  3393:                     requestcrs => 'When requesting a course',
1.45      raeburn  3394:                     selfcreate => 'User creates own account', 
1.34      raeburn  3395:                     any        => 'Any',
                   3396:                     official   => 'Institutional only ',
                   3397:                     unofficial => 'Non-institutional only',
1.85      schafran 3398:                     email      => 'E-mail address',
1.43      raeburn  3399:                     login      => 'Institutional Login',
                   3400:                     sso        => 'SSO', 
1.34      raeburn  3401:                     none       => 'None',
                   3402:     );
                   3403:     return %lt;
1.48      raeburn  3404: }
1.34      raeburn  3405: 
1.28      raeburn  3406: sub authtype_names {
                   3407:     my %lt = &Apache::lonlocal::texthash(
                   3408:                       int    => 'Internal',
                   3409:                       krb4   => 'Kerberos 4',
                   3410:                       krb5   => 'Kerberos 5',
                   3411:                       loc    => 'Local',
                   3412:                   );
                   3413:     return %lt;
                   3414: }
                   3415: 
                   3416: sub context_names {
                   3417:     my %context_title = &Apache::lonlocal::texthash(
                   3418:        author => 'Creating users when an Author',
                   3419:        course => 'Creating users when in a course',
                   3420:        domain => 'Creating users when a Domain Coordinator',
                   3421:     );
                   3422:     return %context_title;
                   3423: }
                   3424: 
1.33      raeburn  3425: sub print_usermodification {
                   3426:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3427:     my $numinrow = 4;
                   3428:     my ($context,$datatable,$rowcount);
                   3429:     if ($position eq 'top') {
                   3430:         $rowcount = 0;
                   3431:         $context = 'author'; 
                   3432:         foreach my $role ('ca','aa') {
                   3433:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3434:                                                    $numinrow,$rowcount);
                   3435:             $$rowtotal ++;
                   3436:             $rowcount ++;
                   3437:         }
1.63      raeburn  3438:     } elsif ($position eq 'middle') {
1.33      raeburn  3439:         $context = 'course';
                   3440:         $rowcount = 0;
                   3441:         foreach my $role ('st','ep','ta','in','cr') {
                   3442:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3443:                                                    $numinrow,$rowcount);
                   3444:             $$rowtotal ++;
                   3445:             $rowcount ++;
                   3446:         }
1.63      raeburn  3447:     } elsif ($position eq 'bottom') {
                   3448:         $context = 'selfcreate';
                   3449:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3450:         $usertypes->{'default'} = $othertitle;
                   3451:         if (ref($types) eq 'ARRAY') {
                   3452:             push(@{$types},'default');
                   3453:             $usertypes->{'default'} = $othertitle;
                   3454:             foreach my $status (@{$types}) {
                   3455:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
                   3456:                                                        $numinrow,$rowcount,$usertypes);
                   3457:                 $$rowtotal ++;
                   3458:                 $rowcount ++;
                   3459:             }
                   3460:         }
1.33      raeburn  3461:     }
                   3462:     return $datatable;
                   3463: }
                   3464: 
1.43      raeburn  3465: sub print_defaults {
                   3466:     my ($dom,$rowtotal) = @_;
1.68      raeburn  3467:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  3468:                  'datelocale_def','portal_def');
1.43      raeburn  3469:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  3470:     my $titles = &defaults_titles($dom);
1.43      raeburn  3471:     my $rownum = 0;
                   3472:     my ($datatable,$css_class);
                   3473:     foreach my $item (@items) {
                   3474:         if ($rownum%2) {
                   3475:             $css_class = '';
                   3476:         } else {
                   3477:             $css_class = ' class="LC_odd_row" ';
                   3478:         }
                   3479:         $datatable .= '<tr'.$css_class.'>'.
                   3480:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3481:                   '</span></td><td class="LC_right_item">';
                   3482:         if ($item eq 'auth_def') {
                   3483:             my @authtypes = ('internal','krb4','krb5','localauth');
                   3484:             my %shortauth = (
                   3485:                              internal => 'int',
                   3486:                              krb4 => 'krb4',
                   3487:                              krb5 => 'krb5',
                   3488:                              localauth  => 'loc'
                   3489:                            );
                   3490:             my %authnames = &authtype_names();
                   3491:             foreach my $auth (@authtypes) {
                   3492:                 my $checked = ' ';
                   3493:                 if ($domdefaults{$item} eq $auth) {
                   3494:                     $checked = ' checked="checked" ';
                   3495:                 }
                   3496:                 $datatable .= '<label><input type="radio" name="'.$item.
                   3497:                               '" value="'.$auth.'"'.$checked.'/>'.
                   3498:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   3499:             }
1.54      raeburn  3500:         } elsif ($item eq 'timezone_def') {
                   3501:             my $includeempty = 1;
                   3502:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68      raeburn  3503:         } elsif ($item eq 'datelocale_def') {
                   3504:             my $includeempty = 1;
                   3505:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43      raeburn  3506:         } else {
1.141     raeburn  3507:             my $size;
                   3508:             if ($item eq 'portal_def') {
                   3509:                 $size = ' size="25"';
                   3510:             }
1.43      raeburn  3511:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141     raeburn  3512:                           $domdefaults{$item}.'"'.$size.' />';
1.43      raeburn  3513:         }
                   3514:         $datatable .= '</td></tr>';
                   3515:         $rownum ++;
                   3516:     }
                   3517:     $$rowtotal += $rownum;
                   3518:     return $datatable;
                   3519: }
                   3520: 
                   3521: sub defaults_titles {
1.141     raeburn  3522:     my ($dom) = @_;
1.43      raeburn  3523:     my %titles = &Apache::lonlocal::texthash (
                   3524:                    'auth_def'      => 'Default authentication type',
                   3525:                    'auth_arg_def'  => 'Default authentication argument',
                   3526:                    'lang_def'      => 'Default language',
1.54      raeburn  3527:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  3528:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  3529:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  3530:                  );
1.141     raeburn  3531:     if ($dom) {
                   3532:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   3533:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   3534:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   3535:         $protocol = 'http' if ($protocol ne 'https');
                   3536:         if ($uint_dom) {
                   3537:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   3538:                                          $uint_dom);
                   3539:         }
                   3540:     }
1.43      raeburn  3541:     return (\%titles);
                   3542: }
                   3543: 
1.46      raeburn  3544: sub print_scantronformat {
                   3545:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   3546:     my $itemcount = 1;
1.60      raeburn  3547:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   3548:         %confhash);
1.46      raeburn  3549:     my $switchserver = &check_switchserver($dom,$confname);
                   3550:     my %lt = &Apache::lonlocal::texthash (
1.95      www      3551:                 default => 'Default bubblesheet format file error',
                   3552:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  3553:              );
                   3554:     my %scantronfiles = (
                   3555:         default => 'default.tab',
                   3556:         custom => 'custom.tab',
                   3557:     );
                   3558:     foreach my $key (keys(%scantronfiles)) {
                   3559:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   3560:                               .$scantronfiles{$key};
                   3561:     }
                   3562:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   3563:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   3564:         if (!$switchserver) {
                   3565:             my $servadm = $r->dir_config('lonAdmEMail');
                   3566:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   3567:             if ($configuserok eq 'ok') {
                   3568:                 if ($author_ok eq 'ok') {
                   3569:                     my %legacyfile = (
                   3570:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   3571:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   3572:                     );
                   3573:                     my %md5chk;
                   3574:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3575:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   3576:                         chomp($md5chk{$type});
1.46      raeburn  3577:                     }
                   3578:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   3579:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3580:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  3581:                                 &legacy_scantronformat($r,$dom,$confname,
                   3582:                                                  $type,$legacyfile{$type},
                   3583:                                                  $scantronurls{$type},
                   3584:                                                  $scantronfiles{$type});
1.60      raeburn  3585:                             if ($error ne '') {
                   3586:                                 $error{$type} = $error;
                   3587:                             }
                   3588:                         }
                   3589:                         if (keys(%error) == 0) {
                   3590:                             $is_custom = 1;
                   3591:                             $confhash{'scantron'}{'scantronformat'} = 
                   3592:                                 $scantronurls{'custom'};
                   3593:                             my $putresult = 
                   3594:                                 &Apache::lonnet::put_dom('configuration',
                   3595:                                                          \%confhash,$dom);
                   3596:                             if ($putresult ne 'ok') {
                   3597:                                 $error{'custom'} = 
                   3598:                                     '<span class="LC_error">'.
                   3599:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3600:                             }
1.46      raeburn  3601:                         }
                   3602:                     } else {
1.60      raeburn  3603:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  3604:                             &legacy_scantronformat($r,$dom,$confname,
                   3605:                                           'default',$legacyfile{'default'},
                   3606:                                           $scantronurls{'default'},
                   3607:                                           $scantronfiles{'default'});
1.60      raeburn  3608:                         if ($error eq '') {
                   3609:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   3610:                             my $putresult =
                   3611:                                 &Apache::lonnet::put_dom('configuration',
                   3612:                                                          \%confhash,$dom);
                   3613:                             if ($putresult ne 'ok') {
                   3614:                                 $error{'default'} =
                   3615:                                     '<span class="LC_error">'.
                   3616:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3617:                             }
                   3618:                         } else {
                   3619:                             $error{'default'} = $error;
                   3620:                         }
1.46      raeburn  3621:                     }
                   3622:                 }
                   3623:             }
                   3624:         } else {
1.95      www      3625:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  3626:         }
                   3627:     }
                   3628:     if (ref($settings) eq 'HASH') {
                   3629:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   3630:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   3631:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   3632:                 $scantronurl = '';
                   3633:             } else {
                   3634:                 $scantronurl = $settings->{'scantronformat'};
                   3635:             }
                   3636:             $is_custom = 1;
                   3637:         } else {
                   3638:             $scantronurl = $scantronurls{'default'};
                   3639:         }
                   3640:     } else {
1.60      raeburn  3641:         if ($is_custom) {
                   3642:             $scantronurl = $scantronurls{'custom'};
                   3643:         } else {
                   3644:             $scantronurl = $scantronurls{'default'};
                   3645:         }
1.46      raeburn  3646:     }
                   3647:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3648:     $datatable .= '<tr'.$css_class.'>';
                   3649:     if (!$is_custom) {
1.65      raeburn  3650:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   3651:                       '<span class="LC_nobreak">';
1.46      raeburn  3652:         if ($scantronurl) {
                   3653:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3654:                           &mt('Default bubblesheet format file').'</a>';
1.46      raeburn  3655:         } else {
                   3656:             $datatable = &mt('File unavailable for display');
                   3657:         }
1.65      raeburn  3658:         $datatable .= '</span></td>';
1.60      raeburn  3659:         if (keys(%error) == 0) { 
                   3660:             $datatable .= '<td valign="bottom">';
                   3661:             if (!$switchserver) {
                   3662:                 $datatable .= &mt('Upload:').'<br />';
                   3663:             }
                   3664:         } else {
                   3665:             my $errorstr;
                   3666:             foreach my $key (sort(keys(%error))) {
                   3667:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3668:             }
                   3669:             $datatable .= '<td>'.$errorstr;
                   3670:         }
1.46      raeburn  3671:     } else {
                   3672:         if (keys(%error) > 0) {
                   3673:             my $errorstr;
                   3674:             foreach my $key (sort(keys(%error))) {
                   3675:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3676:             } 
1.60      raeburn  3677:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  3678:         } elsif ($scantronurl) {
1.65      raeburn  3679:             $datatable .= '<td><span class="LC_nobreak">'.
                   3680:                           '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3681:                           &mt('Custom bubblesheet format file').'</a><label>'.
1.65      raeburn  3682:                           '<input type="checkbox" name="scantronformat_del"'.
                   3683:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
                   3684:                           '<td><span class="LC_nobreak">&nbsp;'.
                   3685:                           &mt('Replace:').'</span><br />';
1.46      raeburn  3686:         }
                   3687:     }
                   3688:     if (keys(%error) == 0) {
                   3689:         if ($switchserver) {
                   3690:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3691:         } else {
1.65      raeburn  3692:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   3693:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  3694:         }
                   3695:     }
                   3696:     $datatable .= '</td></tr>';
                   3697:     $$rowtotal ++;
                   3698:     return $datatable;
                   3699: }
                   3700: 
                   3701: sub legacy_scantronformat {
                   3702:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   3703:     my ($url,$error);
                   3704:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   3705:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   3706:         (my $result,$url) =
                   3707:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   3708:                          '','',$newfile);
                   3709:         if ($result ne 'ok') {
1.130     raeburn  3710:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  3711:         }
                   3712:     }
                   3713:     return ($url,$error);
                   3714: }
1.43      raeburn  3715: 
1.49      raeburn  3716: sub print_coursecategories {
1.57      raeburn  3717:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   3718:     my $datatable;
                   3719:     if ($position eq 'top') {
                   3720:         my $toggle_cats_crs = ' ';
                   3721:         my $toggle_cats_dom = ' checked="checked" ';
                   3722:         my $can_cat_crs = ' ';
                   3723:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  3724:         my $toggle_catscomm_comm = ' ';
                   3725:         my $toggle_catscomm_dom = ' checked="checked" ';
                   3726:         my $can_catcomm_comm = ' ';
                   3727:         my $can_catcomm_dom = ' checked="checked" ';
                   3728: 
1.57      raeburn  3729:         if (ref($settings) eq 'HASH') {
                   3730:             if ($settings->{'togglecats'} eq 'crs') {
                   3731:                 $toggle_cats_crs = $toggle_cats_dom;
                   3732:                 $toggle_cats_dom = ' ';
                   3733:             }
                   3734:             if ($settings->{'categorize'} eq 'crs') {
                   3735:                 $can_cat_crs = $can_cat_dom;
                   3736:                 $can_cat_dom = ' ';
                   3737:             }
1.120     raeburn  3738:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   3739:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   3740:                 $toggle_catscomm_dom = ' ';
                   3741:             }
                   3742:             if ($settings->{'categorizecomm'} eq 'comm') {
                   3743:                 $can_catcomm_comm = $can_catcomm_dom;
                   3744:                 $can_catcomm_dom = ' ';
                   3745:             }
1.57      raeburn  3746:         }
                   3747:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  3748:                      togglecats     => 'Show/Hide a course in catalog',
                   3749:                      togglecatscomm => 'Show/Hide a community in catalog',
                   3750:                      categorize     => 'Assign a category to a course',
                   3751:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  3752:                     );
                   3753:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  3754:                      dom  => 'Set in Domain',
                   3755:                      crs  => 'Set in Course',
                   3756:                      comm => 'Set in Community',
1.57      raeburn  3757:                     );
                   3758:         $datatable = '<tr class="LC_odd_row">'.
                   3759:                   '<td>'.$title{'togglecats'}.'</td>'.
                   3760:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3761:                   '<input type="radio" name="togglecats"'.
                   3762:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3763:                   '<label><input type="radio" name="togglecats"'.
                   3764:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   3765:                   '</tr><tr>'.
                   3766:                   '<td>'.$title{'categorize'}.'</td>'.
                   3767:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3768:                   '<label><input type="radio" name="categorize"'.
                   3769:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3770:                   '<label><input type="radio" name="categorize"'.
                   3771:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  3772:                   '</tr><tr class="LC_odd_row">'.
                   3773:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   3774:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3775:                   '<input type="radio" name="togglecatscomm"'.
                   3776:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3777:                   '<label><input type="radio" name="togglecatscomm"'.
                   3778:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   3779:                   '</tr><tr>'.
                   3780:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   3781:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3782:                   '<label><input type="radio" name="categorizecomm"'.
                   3783:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3784:                   '<label><input type="radio" name="categorizecomm"'.
                   3785:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  3786:                   '</tr>';
1.120     raeburn  3787:         $$rowtotal += 4;
1.57      raeburn  3788:     } else {
                   3789:         my $css_class;
                   3790:         my $itemcount = 1;
                   3791:         my $cathash; 
                   3792:         if (ref($settings) eq 'HASH') {
                   3793:             $cathash = $settings->{'cats'};
                   3794:         }
                   3795:         if (ref($cathash) eq 'HASH') {
                   3796:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   3797:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   3798:                                                    \%allitems,\%idx,\@jsarray);
                   3799:             my $maxdepth = scalar(@cats);
                   3800:             my $colattrib = '';
                   3801:             if ($maxdepth > 2) {
                   3802:                 $colattrib = ' colspan="2" ';
                   3803:             }
                   3804:             my @path;
                   3805:             if (@cats > 0) {
                   3806:                 if (ref($cats[0]) eq 'ARRAY') {
                   3807:                     my $numtop = @{$cats[0]};
                   3808:                     my $maxnum = $numtop;
1.120     raeburn  3809:                     my %default_names = (
                   3810:                           instcode    => &mt('Official courses'),
                   3811:                           communities => &mt('Communities'),
                   3812:                     );
                   3813: 
                   3814:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   3815:                         ($cathash->{'instcode::0'} eq '') ||
                   3816:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   3817:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  3818:                         $maxnum ++;
                   3819:                     }
                   3820:                     my $lastidx;
                   3821:                     for (my $i=0; $i<$numtop; $i++) {
                   3822:                         my $parent = $cats[0][$i];
                   3823:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3824:                         my $item = &escape($parent).'::0';
                   3825:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   3826:                         $lastidx = $idx{$item};
                   3827:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3828:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   3829:                         for (my $k=0; $k<=$maxnum; $k++) {
                   3830:                             my $vpos = $k+1;
                   3831:                             my $selstr;
                   3832:                             if ($k == $i) {
                   3833:                                 $selstr = ' selected="selected" ';
                   3834:                             }
                   3835:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3836:                         }
                   3837:                         $datatable .= '</select></td><td>';
1.120     raeburn  3838:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   3839:                             $datatable .=  '<span class="LC_nobreak">'
                   3840:                                            .$default_names{$parent}.'</span>';
                   3841:                             if ($parent eq 'instcode') {
                   3842:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   3843:                                               .&mt('with institutional codes')
                   3844:                                               .')</span></td><td'.$colattrib.'>';
                   3845:                             } else {
                   3846:                                 $datatable .= '<table><tr><td>';
                   3847:                             }
                   3848:                             $datatable .= '<span class="LC_nobreak">'
                   3849:                                           .'<label><input type="radio" name="'
                   3850:                                           .$parent.'" value="1" checked="checked" />'
                   3851:                                           .&mt('Display').'</label>';
                   3852:                             if ($parent eq 'instcode') {
                   3853:                                 $datatable .= '&nbsp;';
                   3854:                             } else {
                   3855:                                 $datatable .= '</span></td></tr><tr><td>'
                   3856:                                               .'<span class="LC_nobreak">';
                   3857:                             }
                   3858:                             $datatable .= '<label><input type="radio" name="'
                   3859:                                           .$parent.'" value="0" />'
                   3860:                                           .&mt('Do not display').'</label></span>';
                   3861:                             if ($parent eq 'communities') {
                   3862:                                 $datatable .= '</td></tr></table>';
                   3863:                             }
                   3864:                             $datatable .= '</td>';
1.57      raeburn  3865:                         } else {
                   3866:                             $datatable .= $parent
                   3867:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                   3868:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   3869:                         }
                   3870:                         my $depth = 1;
                   3871:                         push(@path,$parent);
                   3872:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   3873:                         pop(@path);
                   3874:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   3875:                         $itemcount ++;
                   3876:                     }
1.48      raeburn  3877:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  3878:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   3879:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  3880:                     for (my $k=0; $k<=$maxnum; $k++) {
                   3881:                         my $vpos = $k+1;
                   3882:                         my $selstr;
1.57      raeburn  3883:                         if ($k == $numtop) {
1.48      raeburn  3884:                             $selstr = ' selected="selected" ';
                   3885:                         }
                   3886:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3887:                     }
1.59      bisitz   3888:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  3889:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   3890:                                   .'</tr>'."\n";
1.48      raeburn  3891:                     $itemcount ++;
1.120     raeburn  3892:                     foreach my $default ('instcode','communities') {
                   3893:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   3894:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3895:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   3896:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   3897:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   3898:                             for (my $k=0; $k<=$maxnum; $k++) {
                   3899:                                 my $vpos = $k+1;
                   3900:                                 my $selstr;
                   3901:                                 if ($k == $maxnum) {
                   3902:                                     $selstr = ' selected="selected" ';
                   3903:                                 }
                   3904:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  3905:                             }
1.120     raeburn  3906:                             $datatable .= '</select></span></td>'.
                   3907:                                           '<td><span class="LC_nobreak">'.
                   3908:                                           $default_names{$default}.'</span>';
                   3909:                             if ($default eq 'instcode') {
                   3910:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   3911:                                               .&mt('with institutional codes').')</span>';
                   3912:                             }
                   3913:                             $datatable .= '</td>'
                   3914:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   3915:                                           .&mt('Display').'</label>&nbsp;'
                   3916:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   3917:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  3918:                         }
                   3919:                     }
                   3920:                 }
1.57      raeburn  3921:             } else {
                   3922:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  3923:             }
                   3924:         } else {
1.57      raeburn  3925:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   3926:                           .&initialize_categories($itemcount);
1.48      raeburn  3927:         }
1.57      raeburn  3928:         $$rowtotal += $itemcount;
1.48      raeburn  3929:     }
                   3930:     return $datatable;
                   3931: }
                   3932: 
1.69      raeburn  3933: sub print_serverstatuses {
                   3934:     my ($dom,$settings,$rowtotal) = @_;
                   3935:     my $datatable;
                   3936:     my @pages = &serverstatus_pages();
                   3937:     my (%namedaccess,%machineaccess);
                   3938:     foreach my $type (@pages) {
                   3939:         $namedaccess{$type} = '';
                   3940:         $machineaccess{$type}= '';
                   3941:     }
                   3942:     if (ref($settings) eq 'HASH') {
                   3943:         foreach my $type (@pages) {
                   3944:             if (exists($settings->{$type})) {
                   3945:                 if (ref($settings->{$type}) eq 'HASH') {
                   3946:                     foreach my $key (keys(%{$settings->{$type}})) {
                   3947:                         if ($key eq 'namedusers') {
                   3948:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   3949:                         } elsif ($key eq 'machines') {
                   3950:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   3951:                         }
                   3952:                     }
                   3953:                 }
                   3954:             }
                   3955:         }
                   3956:     }
1.81      raeburn  3957:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  3958:     my $rownum = 0;
                   3959:     my $css_class;
                   3960:     foreach my $type (@pages) {
                   3961:         $rownum ++;
                   3962:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3963:         $datatable .= '<tr'.$css_class.'>'.
                   3964:                       '<td><span class="LC_nobreak">'.
                   3965:                       $titles->{$type}.'</span></td>'.
                   3966:                       '<td class="LC_left_item">'.
                   3967:                       '<input type="text" name="'.$type.'_namedusers" '.
                   3968:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   3969:                       '<td class="LC_right_item">'.
                   3970:                       '<span class="LC_nobreak">'.
                   3971:                       '<input type="text" name="'.$type.'_machines" '.
                   3972:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   3973:                       '</td></tr>'."\n";
                   3974:     }
                   3975:     $$rowtotal += $rownum;
                   3976:     return $datatable;
                   3977: }
                   3978: 
                   3979: sub serverstatus_pages {
                   3980:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
                   3981:             'clusterstatus','metadata_keywords','metadata_harvest',
1.156     raeburn  3982:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69      raeburn  3983: }
                   3984: 
1.49      raeburn  3985: sub coursecategories_javascript {
                   3986:     my ($settings) = @_;
1.57      raeburn  3987:     my ($output,$jstext,$cathash);
1.49      raeburn  3988:     if (ref($settings) eq 'HASH') {
1.57      raeburn  3989:         $cathash = $settings->{'cats'};
                   3990:     }
                   3991:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  3992:         my (@cats,@jsarray,%idx);
1.57      raeburn  3993:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  3994:         if (@jsarray > 0) {
                   3995:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   3996:             for (my $i=0; $i<@jsarray; $i++) {
                   3997:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   3998:                     my $catstr = join('","',@{$jsarray[$i]});
                   3999:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   4000:                 }
                   4001:             }
                   4002:         }
                   4003:     } else {
                   4004:         $jstext  = '    var categories = Array(1);'."\n".
                   4005:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   4006:     }
1.120     raeburn  4007:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   4008:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   4009:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  4010:     $output = <<"ENDSCRIPT";
                   4011: <script type="text/javascript">
1.109     raeburn  4012: // <![CDATA[
1.49      raeburn  4013: function reorderCats(form,parent,item,idx) {
                   4014:     var changedVal;
                   4015: $jstext
                   4016:     var newpos = 'addcategory_pos';
                   4017:     var current = new Array;
                   4018:     if (parent == '') {
                   4019:         var has_instcode = 0;
                   4020:         var maxtop = categories[idx].length;
                   4021:         for (var j=0; j<maxtop; j++) {
                   4022:             if (categories[idx][j] == 'instcode::0') {
                   4023:                 has_instcode == 1;
                   4024:             }
                   4025:         }
                   4026:         if (has_instcode == 0) {
                   4027:             categories[idx][maxtop] = 'instcode_pos';
                   4028:         }
                   4029:     } else {
                   4030:         newpos += '_'+parent;
                   4031:     }
                   4032:     var maxh = 1 + categories[idx].length;
                   4033:     var current = new Array;
                   4034:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4035:     if (item == newpos) {
                   4036:         changedVal = newitemVal;
                   4037:     } else {
                   4038:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4039:         current[newitemVal] = newpos;
                   4040:     }
                   4041:     for (var i=0; i<categories[idx].length; i++) {
                   4042:         var elementName = categories[idx][i];
                   4043:         if (elementName != item) {
                   4044:             if (form.elements[elementName]) {
                   4045:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4046:                 current[currVal] = elementName;
                   4047:             }
                   4048:         }
                   4049:     }
                   4050:     var oldVal;
                   4051:     for (var j=0; j<maxh; j++) {
                   4052:         if (current[j] == undefined) {
                   4053:             oldVal = j;
                   4054:         }
                   4055:     }
                   4056:     if (oldVal < changedVal) {
                   4057:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4058:            var elementName = current[k];
                   4059:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4060:         }
                   4061:     } else {
                   4062:         for (var k=changedVal; k<oldVal; k++) {
                   4063:             var elementName = current[k];
                   4064:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4065:         }
                   4066:     }
                   4067:     return;
                   4068: }
1.120     raeburn  4069: 
                   4070: function categoryCheck(form) {
                   4071:     if (form.elements['addcategory_name'].value == 'instcode') {
                   4072:         alert('$instcode_reserved\\n$choose_again');
                   4073:         return false;
                   4074:     }
                   4075:     if (form.elements['addcategory_name'].value == 'communities') {
                   4076:         alert('$communities_reserved\\n$choose_again');
                   4077:         return false;
                   4078:     }
                   4079:     return true;
                   4080: }
                   4081: 
1.109     raeburn  4082: // ]]>
1.49      raeburn  4083: </script>
                   4084: 
                   4085: ENDSCRIPT
                   4086:     return $output;
                   4087: }
                   4088: 
1.48      raeburn  4089: sub initialize_categories {
                   4090:     my ($itemcount) = @_;
1.120     raeburn  4091:     my ($datatable,$css_class,$chgstr);
                   4092:     my %default_names = (
                   4093:                       instcode    => 'Official courses (with institutional codes)',
                   4094:                       communities => 'Communities',
                   4095:                         );
                   4096:     my $select0 = ' selected="selected"';
                   4097:     my $select1 = '';
                   4098:     foreach my $default ('instcode','communities') {
                   4099:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4100:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   4101:         if ($default eq 'communities') {
                   4102:             $select1 = $select0;
                   4103:             $select0 = '';
                   4104:         }
                   4105:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4106:                      .'<select name="'.$default.'_pos">'
                   4107:                      .'<option value="0"'.$select0.'>1</option>'
                   4108:                      .'<option value="1"'.$select1.'>2</option>'
                   4109:                      .'<option value="2">3</option></select>&nbsp;'
                   4110:                      .$default_names{$default}
                   4111:                      .'</span></td><td><span class="LC_nobreak">'
                   4112:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   4113:                      .&mt('Display').'</label>&nbsp;<label>'
                   4114:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  4115:                  .'</label></span></td></tr>';
1.120     raeburn  4116:         $itemcount ++;
                   4117:     }
1.48      raeburn  4118:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  4119:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4120:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4121:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4122:                   .'<option value="0">1</option>'
                   4123:                   .'<option value="1">2</option>'
                   4124:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4125:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4126:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4127:     return $datatable;
                   4128: }
                   4129: 
                   4130: sub build_category_rows {
1.49      raeburn  4131:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4132:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4133:     if (ref($cats) eq 'ARRAY') {
                   4134:         my $maxdepth = scalar(@{$cats});
                   4135:         if (ref($cats->[$depth]) eq 'HASH') {
                   4136:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4137:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4138:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4139:                 $text .= '<td><table class="LC_datatable">';
1.49      raeburn  4140:                 my ($idxnum,$parent_name,$parent_item);
                   4141:                 my $higher = $depth - 1;
                   4142:                 if ($higher == 0) {
                   4143:                     $parent_name = &escape($parent).'::'.$higher;
                   4144:                 } else {
                   4145:                     if (ref($path) eq 'ARRAY') {
                   4146:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4147:                     }
                   4148:                 }
                   4149:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4150:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4151:                     if ($j < $numchildren) {
1.48      raeburn  4152:                         $name = $cats->[$depth]{$parent}[$j];
                   4153:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4154:                         $idxnum = $idx->{$item};
                   4155:                     } else {
                   4156:                         $name = $parent_name;
                   4157:                         $item = $parent_item;
1.48      raeburn  4158:                     }
1.49      raeburn  4159:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4160:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  4161:                     for (my $i=0; $i<=$numchildren; $i++) {
                   4162:                         my $vpos = $i+1;
                   4163:                         my $selstr;
                   4164:                         if ($j == $i) {
                   4165:                             $selstr = ' selected="selected" ';
                   4166:                         }
                   4167:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   4168:                     }
                   4169:                     $text .= '</select>&nbsp;';
                   4170:                     if ($j < $numchildren) {
                   4171:                         my $deeper = $depth+1;
                   4172:                         $text .= $name.'&nbsp;'
                   4173:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   4174:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   4175:                         if(ref($path) eq 'ARRAY') {
                   4176:                             push(@{$path},$name);
1.49      raeburn  4177:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  4178:                             pop(@{$path});
                   4179:                         }
                   4180:                     } else {
1.59      bisitz   4181:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  4182:                         if ($j == $numchildren) {
                   4183:                             $text .= $name;
                   4184:                         } else {
                   4185:                             $text .= $item;
                   4186:                         }
                   4187:                         $text .= '" value="" />';
                   4188:                     }
                   4189:                     $text .= '</td></tr>';
                   4190:                 }
                   4191:                 $text .= '</table></td>';
                   4192:             } else {
                   4193:                 my $higher = $depth-1;
                   4194:                 if ($higher == 0) {
                   4195:                     $name = &escape($parent).'::'.$higher;
                   4196:                 } else {
                   4197:                     if (ref($path) eq 'ARRAY') {
                   4198:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4199:                     }
                   4200:                 }
                   4201:                 my $colspan;
                   4202:                 if ($parent ne 'instcode') {
                   4203:                     $colspan = $maxdepth - $depth - 1;
                   4204:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   4205:                 }
                   4206:             }
                   4207:         }
                   4208:     }
                   4209:     return $text;
                   4210: }
                   4211: 
1.33      raeburn  4212: sub modifiable_userdata_row {
1.63      raeburn  4213:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33      raeburn  4214:     my $rolename;
1.63      raeburn  4215:     if ($context eq 'selfcreate') {
                   4216:         if (ref($usertypes) eq 'HASH') {
                   4217:             $rolename = $usertypes->{$role};
                   4218:         } else {
                   4219:             $rolename = $role;
                   4220:         }
1.33      raeburn  4221:     } else {
1.63      raeburn  4222:         if ($role eq 'cr') {
                   4223:             $rolename = &mt('Custom role');
                   4224:         } else {
                   4225:             $rolename = &Apache::lonnet::plaintext($role);
                   4226:         }
1.33      raeburn  4227:     }
                   4228:     my @fields = ('lastname','firstname','middlename','generation',
                   4229:                   'permanentemail','id');
                   4230:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4231:     my $output;
                   4232:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4233:     $output = '<tr '.$css_class.'>'.
                   4234:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   4235:               '<td class="LC_left_item" colspan="2"><table>';
                   4236:     my $rem;
                   4237:     my %checks;
                   4238:     if (ref($settings) eq 'HASH') {
                   4239:         if (ref($settings->{$context}) eq 'HASH') {
                   4240:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   4241:                 foreach my $field (@fields) {
                   4242:                     if ($settings->{$context}->{$role}->{$field}) {
                   4243:                         $checks{$field} = ' checked="checked" ';
                   4244:                     }
                   4245:                 }
                   4246:             }
                   4247:         }
                   4248:     }
                   4249:     for (my $i=0; $i<@fields; $i++) {
                   4250:         my $rem = $i%($numinrow);
                   4251:         if ($rem == 0) {
                   4252:             if ($i > 0) {
                   4253:                 $output .= '</tr>';
                   4254:             }
                   4255:             $output .= '<tr>';
                   4256:         }
                   4257:         my $check = ' ';
                   4258:         if (exists($checks{$fields[$i]})) {
                   4259:             $check = $checks{$fields[$i]}
                   4260:         } else {
                   4261:             if ($role eq 'st') {
                   4262:                 if (ref($settings) ne 'HASH') {
                   4263:                     $check = ' checked="checked" '; 
                   4264:                 }
                   4265:             }
                   4266:         }
                   4267:         $output .= '<td class="LC_left_item">'.
                   4268:                    '<span class="LC_nobreak"><label>'.
                   4269:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   4270:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   4271:                    '</label></span></td>';
                   4272:         $rem = @fields%($numinrow);
                   4273:     }
                   4274:     my $colsleft = $numinrow - $rem;
                   4275:     if ($colsleft > 1 ) {
                   4276:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4277:                    '&nbsp;</td>';
                   4278:     } elsif ($colsleft == 1) {
                   4279:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4280:     }
                   4281:     $output .= '</tr></table></td></tr>';
                   4282:     return $output;
                   4283: }
1.28      raeburn  4284: 
1.93      raeburn  4285: sub insttypes_row {
                   4286:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
                   4287:     my %lt = &Apache::lonlocal::texthash (
                   4288:                       cansearch => 'Users allowed to search',
                   4289:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  4290:                       lockablenames => 'User preference to lock name',
1.93      raeburn  4291:              );
                   4292:     my $showdom;
                   4293:     if ($context eq 'cansearch') {
                   4294:         $showdom = ' ('.$dom.')';
                   4295:     }
1.25      raeburn  4296:     my $output =  '<tr class="LC_odd_row">'.
1.93      raeburn  4297:                   '<td>'.$lt{$context}.$showdom.
1.24      raeburn  4298:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.26      raeburn  4299:     my $rem;
                   4300:     if (ref($types) eq 'ARRAY') {
                   4301:         for (my $i=0; $i<@{$types}; $i++) {
                   4302:             if (defined($usertypes->{$types->[$i]})) {
                   4303:                 my $rem = $i%($numinrow);
                   4304:                 if ($rem == 0) {
                   4305:                     if ($i > 0) {
                   4306:                         $output .= '</tr>';
                   4307:                     }
                   4308:                     $output .= '<tr>';
1.23      raeburn  4309:                 }
1.26      raeburn  4310:                 my $check = ' ';
1.99      raeburn  4311:                 if (ref($settings) eq 'HASH') {
                   4312:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   4313:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   4314:                             $check = ' checked="checked" ';
                   4315:                         }
                   4316:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  4317:                         $check = ' checked="checked" ';
                   4318:                     }
1.23      raeburn  4319:                 }
1.26      raeburn  4320:                 $output .= '<td class="LC_left_item">'.
                   4321:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  4322:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  4323:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   4324:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  4325:             }
                   4326:         }
1.26      raeburn  4327:         $rem = @{$types}%($numinrow);
1.23      raeburn  4328:     }
                   4329:     my $colsleft = $numinrow - $rem;
1.131     raeburn  4330:     if (($rem == 0) && (@{$types} > 0)) {
                   4331:         $output .= '<tr>';
                   4332:     }
1.23      raeburn  4333:     if ($colsleft > 1) {
1.25      raeburn  4334:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  4335:     } else {
1.25      raeburn  4336:         $output .= '<td class="LC_left_item">';
1.23      raeburn  4337:     }
                   4338:     my $defcheck = ' ';
1.99      raeburn  4339:     if (ref($settings) eq 'HASH') {  
                   4340:         if (ref($settings->{$context}) eq 'ARRAY') {
                   4341:             if (grep(/^default$/,@{$settings->{$context}})) {
                   4342:                 $defcheck = ' checked="checked" ';
                   4343:             }
                   4344:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  4345:             $defcheck = ' checked="checked" ';
                   4346:         }
1.23      raeburn  4347:     }
1.25      raeburn  4348:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  4349:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  4350:                'value="default"'.$defcheck.'/>'.
                   4351:                $othertitle.'</label></span></td>'.
                   4352:                '</tr></table></td></tr>';
                   4353:     return $output;
1.23      raeburn  4354: }
                   4355: 
                   4356: sub sorted_searchtitles {
                   4357:     my %searchtitles = &Apache::lonlocal::texthash(
                   4358:                          'uname' => 'username',
                   4359:                          'lastname' => 'last name',
                   4360:                          'lastfirst' => 'last name, first name',
                   4361:                      );
                   4362:     my @titleorder = ('uname','lastname','lastfirst');
                   4363:     return (\%searchtitles,\@titleorder);
                   4364: }
                   4365: 
1.25      raeburn  4366: sub sorted_searchtypes {
                   4367:     my %srchtypes_desc = (
                   4368:                            exact    => 'is exact match',
                   4369:                            contains => 'contains ..',
                   4370:                            begins   => 'begins with ..',
                   4371:                          );
                   4372:     my @srchtypeorder = ('exact','begins','contains');
                   4373:     return (\%srchtypes_desc,\@srchtypeorder);
                   4374: }
                   4375: 
1.3       raeburn  4376: sub usertype_update_row {
                   4377:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   4378:     my $datatable;
                   4379:     my $numinrow = 4;
                   4380:     foreach my $type (@{$types}) {
                   4381:         if (defined($usertypes->{$type})) {
                   4382:             $$rownums ++;
                   4383:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   4384:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   4385:                           '</td><td class="LC_left_item"><table>';
                   4386:             for (my $i=0; $i<@{$fields}; $i++) {
                   4387:                 my $rem = $i%($numinrow);
                   4388:                 if ($rem == 0) {
                   4389:                     if ($i > 0) {
                   4390:                         $datatable .= '</tr>';
                   4391:                     }
                   4392:                     $datatable .= '<tr>';
                   4393:                 }
                   4394:                 my $check = ' ';
1.39      raeburn  4395:                 if (ref($settings) eq 'HASH') {
                   4396:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   4397:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   4398:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   4399:                                 $check = ' checked="checked" ';
                   4400:                             }
1.3       raeburn  4401:                         }
                   4402:                     }
                   4403:                 }
                   4404: 
                   4405:                 if ($i == @{$fields}-1) {
                   4406:                     my $colsleft = $numinrow - $rem;
                   4407:                     if ($colsleft > 1) {
                   4408:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   4409:                     } else {
                   4410:                         $datatable .= '<td>';
                   4411:                     }
                   4412:                 } else {
                   4413:                     $datatable .= '<td>';
                   4414:                 }
1.8       raeburn  4415:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4416:                               '<input type="checkbox" name="updateable_'.$type.
                   4417:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   4418:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  4419:             }
                   4420:             $datatable .= '</tr></table></td></tr>';
                   4421:         }
                   4422:     }
                   4423:     return $datatable;
1.1       raeburn  4424: }
                   4425: 
                   4426: sub modify_login {
1.9       raeburn  4427:     my ($r,$dom,$confname,%domconfig) = @_;
1.6       raeburn  4428:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1       raeburn  4429:     my %title = ( coursecatalog => 'Display course catalog',
1.41      raeburn  4430:                   adminmail => 'Display administrator E-mail address',
1.43      raeburn  4431:                   newuser => 'Link for visitors to create a user account',
1.41      raeburn  4432:                   loginheader => 'Log-in box header');
1.3       raeburn  4433:     my @offon = ('off','on');
1.112     raeburn  4434:     my %curr_loginvia;
                   4435:     if (ref($domconfig{login}) eq 'HASH') {
                   4436:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   4437:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   4438:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   4439:             }
                   4440:         }
                   4441:     }
1.6       raeburn  4442:     my %loginhash;
1.9       raeburn  4443:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   4444:                                            \%domconfig,\%loginhash);
1.118     jms      4445:     my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4446:     foreach my $item (@toggles) {
                   4447:         $loginhash{login}{$item} = $env{'form.'.$item};
                   4448:     }
1.41      raeburn  4449:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  4450:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   4451:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   4452:                                          \%loginhash);
                   4453:     }
1.110     raeburn  4454: 
1.149     raeburn  4455:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  4456:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  4457:     if (keys(%servers) > 1) {
                   4458:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  4459:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   4460:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   4461:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   4462:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   4463:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   4464:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4465:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4466:                         $changes{'loginvia'}{$lonhost} = 1;
                   4467:                     } else {
                   4468:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   4469:                         $changes{'loginvia'}{$lonhost} = 1;
                   4470:                     }
                   4471:                 } else {
                   4472:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4473:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4474:                         $changes{'loginvia'}{$lonhost} = 1;
                   4475:                     }
                   4476:                 }
                   4477:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   4478:                     foreach my $item (@loginvia_attribs) {
                   4479:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   4480:                     }
                   4481:                 } else {
                   4482:                     foreach my $item (@loginvia_attribs) {
                   4483:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4484:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4485:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   4486:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4487:                                 $new = '/';
                   4488:                             }
                   4489:                         }
                   4490:                         if (($item eq 'custompath') && 
                   4491:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4492:                             $new = '';
                   4493:                         }
                   4494:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   4495:                             $changes{'loginvia'}{$lonhost} = 1;
                   4496:                         }
                   4497:                         if ($item eq 'exempt') {
                   4498:                             $new =~ s/^\s+//;
                   4499:                             $new =~ s/\s+$//;
                   4500:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   4501:                             my @okips;
                   4502:                             foreach my $ip (@poss_ips) {
                   4503:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   4504:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   4505:                                         push(@okips,$ip); 
                   4506:                                     }
                   4507:                                 }
                   4508:                             }
                   4509:                             if (@okips > 0) {
                   4510:                                 $new = join(',',@okips); 
                   4511:                             } else {
                   4512:                                 $new = ''; 
                   4513:                             }
                   4514:                         }
                   4515: 
                   4516:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4517:                     }
                   4518:                 }
1.112     raeburn  4519:             } else {
1.128     raeburn  4520:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4521:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  4522:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  4523:                     foreach my $item (@loginvia_attribs) {
                   4524:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4525:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4526:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4527:                                 $new = '/';
                   4528:                             }
                   4529:                         }
                   4530:                         if (($item eq 'custompath') && 
                   4531:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4532:                             $new = '';
                   4533:                         }
                   4534:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4535:                     }
1.110     raeburn  4536:                 }
                   4537:             }
                   4538:         }
                   4539:     }
1.119     raeburn  4540: 
1.1       raeburn  4541:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   4542:                                              $dom);
                   4543:     if ($putresult eq 'ok') {
1.118     jms      4544:         my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4545:         my %defaultchecked = (
                   4546:                     'coursecatalog' => 'on',
                   4547:                     'adminmail'     => 'off',
1.43      raeburn  4548:                     'newuser'       => 'off',
1.42      raeburn  4549:         );
1.55      raeburn  4550:         if (ref($domconfig{'login'}) eq 'HASH') {
                   4551:             foreach my $item (@toggles) {
                   4552:                 if ($defaultchecked{$item} eq 'on') { 
                   4553:                     if (($domconfig{'login'}{$item} eq '0') &&
                   4554:                         ($env{'form.'.$item} eq '1')) {
                   4555:                         $changes{$item} = 1;
                   4556:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4557:                               $domconfig{'login'}{$item} eq '1') &&
                   4558:                              ($env{'form.'.$item} eq '0')) {
                   4559:                         $changes{$item} = 1;
                   4560:                     }
                   4561:                 } elsif ($defaultchecked{$item} eq 'off') {
                   4562:                     if (($domconfig{'login'}{$item} eq '1') &&
                   4563:                         ($env{'form.'.$item} eq '0')) {
                   4564:                         $changes{$item} = 1;
                   4565:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4566:                               $domconfig{'login'}{$item} eq '0') &&
                   4567:                              ($env{'form.'.$item} eq '1')) {
                   4568:                         $changes{$item} = 1;
                   4569:                     }
1.42      raeburn  4570:                 }
                   4571:             }
1.41      raeburn  4572:         }
1.6       raeburn  4573:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  4574:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1       raeburn  4575:             $resulttext = &mt('Changes made:').'<ul>';
                   4576:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   4577:                 if ($item eq 'loginvia') {
1.112     raeburn  4578:                     if (ref($changes{$item}) eq 'HASH') {
                   4579:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   4580:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  4581:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   4582:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   4583:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   4584:                                     $protocol = 'http' if ($protocol ne 'https');
                   4585:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   4586: 
                   4587:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   4588:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   4589:                                     } else {
                   4590:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   4591:                                     }
                   4592:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   4593:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   4594:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   4595:                                     }
                   4596:                                     $resulttext .= '</li>';
                   4597:                                 } else {
                   4598:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   4599:                                 }
1.112     raeburn  4600:                             } else {
1.128     raeburn  4601:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  4602:                             }
                   4603:                         }
1.128     raeburn  4604:                         $resulttext .= '</ul></li>';
1.112     raeburn  4605:                     }
1.41      raeburn  4606:                 } else {
                   4607:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   4608:                 }
1.1       raeburn  4609:             }
1.6       raeburn  4610:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  4611:         } else {
                   4612:             $resulttext = &mt('No changes made to log-in page settings');
                   4613:         }
                   4614:     } else {
1.11      albertel 4615:         $resulttext = '<span class="LC_error">'.
                   4616: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  4617:     }
1.6       raeburn  4618:     if ($errors) {
1.9       raeburn  4619:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  4620:                        $errors.'</ul>';
                   4621:     }
                   4622:     return $resulttext;
                   4623: }
                   4624: 
                   4625: sub color_font_choices {
                   4626:     my %choices =
                   4627:         &Apache::lonlocal::texthash (
                   4628:             img => "Header",
                   4629:             bgs => "Background colors",
                   4630:             links => "Link colors",
1.55      raeburn  4631:             images => "Images",
1.6       raeburn  4632:             font => "Font color",
1.97      tempelho 4633:             fontmenu => "Font Menu",
1.76      raeburn  4634:             pgbg => "Page",
1.6       raeburn  4635:             tabbg => "Header",
                   4636:             sidebg => "Border",
                   4637:             link => "Link",
                   4638:             alink => "Active link",
                   4639:             vlink => "Visited link",
                   4640:         );
                   4641:     return %choices;
                   4642: }
                   4643: 
                   4644: sub modify_rolecolors {
1.9       raeburn  4645:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6       raeburn  4646:     my ($resulttext,%rolehash);
                   4647:     $rolehash{'rolecolors'} = {};
1.55      raeburn  4648:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   4649:         if ($domconfig{'rolecolors'} eq '') {
                   4650:             $domconfig{'rolecolors'} = {};
                   4651:         }
                   4652:     }
1.9       raeburn  4653:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  4654:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   4655:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   4656:                                              $dom);
                   4657:     if ($putresult eq 'ok') {
                   4658:         if (keys(%changes) > 0) {
1.41      raeburn  4659:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6       raeburn  4660:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   4661:                                              $rolehash{'rolecolors'});
                   4662:         } else {
                   4663:             $resulttext = &mt('No changes made to default color schemes');
                   4664:         }
                   4665:     } else {
1.11      albertel 4666:         $resulttext = '<span class="LC_error">'.
                   4667: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  4668:     }
                   4669:     if ($errors) {
                   4670:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   4671:                        $errors.'</ul>';
                   4672:     }
                   4673:     return $resulttext;
                   4674: }
                   4675: 
                   4676: sub modify_colors {
1.9       raeburn  4677:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  4678:     my (%changes,%choices);
1.51      raeburn  4679:     my @bgs;
1.6       raeburn  4680:     my @links = ('link','alink','vlink');
1.41      raeburn  4681:     my @logintext;
1.6       raeburn  4682:     my @images;
                   4683:     my $servadm = $r->dir_config('lonAdmEMail');
                   4684:     my $errors;
                   4685:     foreach my $role (@{$roles}) {
                   4686:         if ($role eq 'login') {
1.12      raeburn  4687:             %choices = &login_choices();
1.41      raeburn  4688:             @logintext = ('textcol','bgcol');
1.12      raeburn  4689:         } else {
                   4690:             %choices = &color_font_choices();
1.107     raeburn  4691:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12      raeburn  4692:         }
                   4693:         if ($role eq 'login') {
1.41      raeburn  4694:             @images = ('img','logo','domlogo','login');
1.51      raeburn  4695:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  4696:         } else {
                   4697:             @images = ('img');
1.51      raeburn  4698:             @bgs = ('pgbg','tabbg','sidebg'); 
1.6       raeburn  4699:         }
                   4700:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41      raeburn  4701:         foreach my $item (@bgs,@links,@logintext) {
1.6       raeburn  4702:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   4703:         }
1.46      raeburn  4704:         my ($configuserok,$author_ok,$switchserver) = 
                   4705:             &config_check($dom,$confname,$servadm);
1.9       raeburn  4706:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  4707:         if (ref($domconfig->{$role}) ne 'HASH') {
                   4708:             $domconfig->{$role} = {};
                   4709:         }
1.8       raeburn  4710:         foreach my $img (@images) {
1.70      raeburn  4711:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   4712:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   4713:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   4714:                 } else { 
                   4715:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   4716:                 }
                   4717:             } 
1.18      albertel 4718: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   4719: 		 && !defined($domconfig->{$role}{$img})
                   4720: 		 && !$env{'form.'.$role.'_del_'.$img}
                   4721: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   4722: 		# import the old configured image from the .tab setting
                   4723: 		# if they haven't provided a new one 
                   4724: 		$domconfig->{$role}{$img} = 
                   4725: 		    $env{'form.'.$role.'_import_'.$img};
                   4726: 	    }
1.6       raeburn  4727:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  4728:                 my $error;
1.6       raeburn  4729:                 if ($configuserok eq 'ok') {
1.9       raeburn  4730:                     if ($switchserver) {
1.12      raeburn  4731:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  4732:                     } else {
                   4733:                         if ($author_ok eq 'ok') {
                   4734:                             my ($result,$logourl) = 
                   4735:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   4736:                                            $dom,$confname,$img,$width,$height);
                   4737:                             if ($result eq 'ok') {
                   4738:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  4739:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  4740:                             } else {
1.12      raeburn  4741:                                 $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);
1.9       raeburn  4742:                             }
                   4743:                         } else {
1.46      raeburn  4744:                             $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);
1.6       raeburn  4745:                         }
                   4746:                     }
                   4747:                 } else {
1.46      raeburn  4748:                     $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);
1.9       raeburn  4749:                 }
                   4750:                 if ($error) {
1.8       raeburn  4751:                     &Apache::lonnet::logthis($error);
1.11      albertel 4752:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  4753:                 }
                   4754:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  4755:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   4756:                     my $error;
                   4757:                     if ($configuserok eq 'ok') {
                   4758: # is confname an author?
                   4759:                         if ($switchserver eq '') {
                   4760:                             if ($author_ok eq 'ok') {
                   4761:                                 my ($result,$logourl) = 
                   4762:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   4763:                                             $dom,$confname,$img,$width,$height);
                   4764:                                 if ($result eq 'ok') {
                   4765:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 4766: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  4767:                                 }
                   4768:                             }
                   4769:                         }
                   4770:                     }
1.6       raeburn  4771:                 }
                   4772:             }
                   4773:         }
                   4774:         if (ref($domconfig) eq 'HASH') {
                   4775:             if (ref($domconfig->{$role}) eq 'HASH') {
                   4776:                 foreach my $img (@images) {
                   4777:                     if ($domconfig->{$role}{$img} ne '') {
                   4778:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   4779:                             $confhash->{$role}{$img} = '';
1.12      raeburn  4780:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  4781:                         } else {
1.9       raeburn  4782:                             if ($confhash->{$role}{$img} eq '') {
                   4783:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   4784:                             }
1.6       raeburn  4785:                         }
                   4786:                     } else {
                   4787:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   4788:                             $confhash->{$role}{$img} = '';
1.12      raeburn  4789:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  4790:                         } 
                   4791:                     }
1.70      raeburn  4792:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   4793:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   4794:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   4795:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   4796:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   4797:                             }
                   4798:                         } else {
                   4799:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   4800:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   4801:                             }
                   4802:                         }
                   4803:                     }
                   4804:                 }
1.6       raeburn  4805:                 if ($domconfig->{$role}{'font'} ne '') {
                   4806:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   4807:                         $changes{$role}{'font'} = 1;
                   4808:                     }
                   4809:                 } else {
                   4810:                     if ($confhash->{$role}{'font'}) {
                   4811:                         $changes{$role}{'font'} = 1;
                   4812:                     }
                   4813:                 }
1.107     raeburn  4814:                 if ($role ne 'login') {
                   4815:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   4816:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   4817:                             $changes{$role}{'fontmenu'} = 1;
                   4818:                         }
                   4819:                     } else {
                   4820:                         if ($confhash->{$role}{'fontmenu'}) {
                   4821:                             $changes{$role}{'fontmenu'} = 1;
                   4822:                         }
1.97      tempelho 4823:                     }
                   4824:                 }
1.6       raeburn  4825:                 foreach my $item (@bgs) {
                   4826:                     if ($domconfig->{$role}{$item} ne '') {
                   4827:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4828:                             $changes{$role}{'bgs'}{$item} = 1;
                   4829:                         } 
                   4830:                     } else {
                   4831:                         if ($confhash->{$role}{$item}) {
                   4832:                             $changes{$role}{'bgs'}{$item} = 1;
                   4833:                         }
                   4834:                     }
                   4835:                 }
                   4836:                 foreach my $item (@links) {
                   4837:                     if ($domconfig->{$role}{$item} ne '') {
                   4838:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4839:                             $changes{$role}{'links'}{$item} = 1;
                   4840:                         }
                   4841:                     } else {
                   4842:                         if ($confhash->{$role}{$item}) {
                   4843:                             $changes{$role}{'links'}{$item} = 1;
                   4844:                         }
                   4845:                     }
                   4846:                 }
1.41      raeburn  4847:                 foreach my $item (@logintext) {
                   4848:                     if ($domconfig->{$role}{$item} ne '') {
                   4849:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4850:                             $changes{$role}{'logintext'}{$item} = 1;
                   4851:                         }
                   4852:                     } else {
                   4853:                         if ($confhash->{$role}{$item}) {
                   4854:                             $changes{$role}{'logintext'}{$item} = 1;
                   4855:                         }
                   4856:                     }
                   4857:                 }
1.6       raeburn  4858:             } else {
                   4859:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  4860:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  4861:             }
                   4862:         } else {
                   4863:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  4864:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  4865:         }
                   4866:     }
                   4867:     return ($errors,%changes);
                   4868: }
                   4869: 
1.46      raeburn  4870: sub config_check {
                   4871:     my ($dom,$confname,$servadm) = @_;
                   4872:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   4873:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   4874:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   4875:                                                    $confname,$servadm);
                   4876:     if ($configuserok eq 'ok') {
                   4877:         $switchserver = &check_switchserver($dom,$confname);
                   4878:         if ($switchserver eq '') {
                   4879:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   4880:         }
                   4881:     }
                   4882:     return ($configuserok,$author_ok,$switchserver);
                   4883: }
                   4884: 
1.6       raeburn  4885: sub default_change_checker {
1.41      raeburn  4886:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  4887:     foreach my $item (@{$links}) {
                   4888:         if ($confhash->{$role}{$item}) {
                   4889:             $changes->{$role}{'links'}{$item} = 1;
                   4890:         }
                   4891:     }
                   4892:     foreach my $item (@{$bgs}) {
                   4893:         if ($confhash->{$role}{$item}) {
                   4894:             $changes->{$role}{'bgs'}{$item} = 1;
                   4895:         }
                   4896:     }
1.41      raeburn  4897:     foreach my $item (@{$logintext}) {
                   4898:         if ($confhash->{$role}{$item}) {
                   4899:             $changes->{$role}{'logintext'}{$item} = 1;
                   4900:         }
                   4901:     }
1.6       raeburn  4902:     foreach my $img (@{$images}) {
                   4903:         if ($env{'form.'.$role.'_del_'.$img}) {
                   4904:             $confhash->{$role}{$img} = '';
1.12      raeburn  4905:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  4906:         }
1.70      raeburn  4907:         if ($role eq 'login') {
                   4908:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   4909:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   4910:             }
                   4911:         }
1.6       raeburn  4912:     }
                   4913:     if ($confhash->{$role}{'font'}) {
                   4914:         $changes->{$role}{'font'} = 1;
                   4915:     }
1.48      raeburn  4916: }
1.6       raeburn  4917: 
                   4918: sub display_colorchgs {
                   4919:     my ($dom,$changes,$roles,$confhash) = @_;
                   4920:     my (%choices,$resulttext);
                   4921:     if (!grep(/^login$/,@{$roles})) {
                   4922:         $resulttext = &mt('Changes made:').'<br />';
                   4923:     }
                   4924:     foreach my $role (@{$roles}) {
                   4925:         if ($role eq 'login') {
                   4926:             %choices = &login_choices();
                   4927:         } else {
                   4928:             %choices = &color_font_choices();
                   4929:         }
                   4930:         if (ref($changes->{$role}) eq 'HASH') {
                   4931:             if ($role ne 'login') {
                   4932:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   4933:             }
                   4934:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   4935:                 if ($role ne 'login') {
                   4936:                     $resulttext .= '<ul>';
                   4937:                 }
                   4938:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   4939:                     if ($role ne 'login') {
                   4940:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   4941:                     }
                   4942:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  4943:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   4944:                             if ($confhash->{$role}{$key}{$item}) {
                   4945:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   4946:                             } else {
                   4947:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   4948:                             }
                   4949:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  4950:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   4951:                         } else {
1.12      raeburn  4952:                             my $newitem = $confhash->{$role}{$item};
                   4953:                             if ($key eq 'images') {
                   4954:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   4955:                             }
                   4956:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  4957:                         }
                   4958:                     }
                   4959:                     if ($role ne 'login') {
                   4960:                         $resulttext .= '</ul></li>';
                   4961:                     }
                   4962:                 } else {
                   4963:                     if ($confhash->{$role}{$key} eq '') {
                   4964:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   4965:                     } else {
                   4966:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   4967:                     }
                   4968:                 }
                   4969:                 if ($role ne 'login') {
                   4970:                     $resulttext .= '</ul>';
                   4971:                 }
                   4972:             }
                   4973:         }
                   4974:     }
1.3       raeburn  4975:     return $resulttext;
1.1       raeburn  4976: }
                   4977: 
1.9       raeburn  4978: sub thumb_dimensions {
                   4979:     return ('200','50');
                   4980: }
                   4981: 
1.16      raeburn  4982: sub check_dimensions {
                   4983:     my ($inputfile) = @_;
                   4984:     my ($fullwidth,$fullheight);
                   4985:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   4986:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   4987:             my $imageinfo = <PIPE>;
                   4988:             if (!close(PIPE)) {
                   4989:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   4990:             }
                   4991:             chomp($imageinfo);
                   4992:             my ($fullsize) = 
1.21      raeburn  4993:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  4994:             if ($fullsize) {
                   4995:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   4996:             }
                   4997:         }
                   4998:     }
                   4999:     return ($fullwidth,$fullheight);
                   5000: }
                   5001: 
1.9       raeburn  5002: sub check_configuser {
                   5003:     my ($uhome,$dom,$confname,$servadm) = @_;
                   5004:     my ($configuserok,%currroles);
                   5005:     if ($uhome eq 'no_host') {
                   5006:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   5007:         my $configpass = &LONCAPA::Enrollment::create_password();
                   5008:         $configuserok = 
                   5009:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   5010:                              $configpass,'','','','','',undef,$servadm);
                   5011:     } else {
                   5012:         $configuserok = 'ok';
                   5013:         %currroles = 
                   5014:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   5015:     }
                   5016:     return ($configuserok,%currroles);
                   5017: }
                   5018: 
                   5019: sub check_authorstatus {
                   5020:     my ($dom,$confname,%currroles) = @_;
                   5021:     my $author_ok;
1.40      raeburn  5022:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  5023:         my $start = time;
                   5024:         my $end = 0;
                   5025:         $author_ok = 
                   5026:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  5027:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  5028:     } else {
                   5029:         $author_ok = 'ok';
                   5030:     }
                   5031:     return $author_ok;
                   5032: }
                   5033: 
                   5034: sub publishlogo {
1.46      raeburn  5035:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  5036:     my ($output,$fname,$logourl);
                   5037:     if ($action eq 'upload') {
                   5038:         $fname=$env{'form.'.$formname.'.filename'};
                   5039:         chop($env{'form.'.$formname});
                   5040:     } else {
                   5041:         ($fname) = ($formname =~ /([^\/]+)$/);
                   5042:     }
1.46      raeburn  5043:     if ($savefileas ne '') {
                   5044:         $fname = $savefileas;
                   5045:     }
1.9       raeburn  5046:     $fname=&Apache::lonnet::clean_filename($fname);
                   5047: # See if there is anything left
                   5048:     unless ($fname) { return ('error: no uploaded file'); }
                   5049:     $fname="$subdir/$fname";
1.158     raeburn  5050:     my $filepath=$r->dir_config('lonDocRoot')."/priv/$dom/$confname";
1.9       raeburn  5051:     my ($fnamepath,$file,$fetchthumb);
                   5052:     $file=$fname;
                   5053:     if ($fname=~m|/|) {
                   5054:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   5055:     }
                   5056:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
                   5057:     my $count;
                   5058:     for ($count=4;$count<=$#parts;$count++) {
                   5059:         $filepath.="/$parts[$count]";
                   5060:         if ((-e $filepath)!=1) {
                   5061:             mkdir($filepath,02770);
                   5062:         }
                   5063:     }
                   5064:     # Check for bad extension and disallow upload
                   5065:     if ($file=~/\.(\w+)$/ &&
                   5066:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   5067:         $output = 
                   5068:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
                   5069:     } elsif ($file=~/\.(\w+)$/ &&
                   5070:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   5071:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   5072:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46      raeburn  5073:         $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9       raeburn  5074:     } elsif (-d "$filepath/$file") {
                   5075:         $output = &mt('File name is a directory name - rename the file and re-upload');
                   5076:     } else {
                   5077:         my $source = $filepath.'/'.$file;
                   5078:         my $logfile;
                   5079:         if (!open($logfile,">>$source".'.log')) {
                   5080:             return (&mt('No write permission to Construction Space'));
                   5081:         }
                   5082:         print $logfile
                   5083: "\n================= Publish ".localtime()." ================\n".
                   5084: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   5085: # Save the file
                   5086:         if (!open(FH,'>'.$source)) {
                   5087:             &Apache::lonnet::logthis('Failed to create '.$source);
                   5088:             return (&mt('Failed to create file'));
                   5089:         }
                   5090:         if ($action eq 'upload') {
                   5091:             if (!print FH ($env{'form.'.$formname})) {
                   5092:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   5093:                 return (&mt('Failed to write file'));
                   5094:             }
                   5095:         } else {
                   5096:             my $original = &Apache::lonnet::filelocation('',$formname);
                   5097:             if(!copy($original,$source)) {
                   5098:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   5099:                 return (&mt('Failed to write file'));
                   5100:             }
                   5101:         }
                   5102:         close(FH);
                   5103:         chmod(0660, $source); # Permissions to rw-rw---.
                   5104: 
                   5105:         my $docroot=$r->dir_config('lonDocRoot');
                   5106:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   5107:         my $copyfile=$targetdir.'/'.$file;
                   5108: 
                   5109:         my @parts=split(/\//,$targetdir);
                   5110:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   5111:         for (my $count=5;$count<=$#parts;$count++) {
                   5112:             $path.="/$parts[$count]";
                   5113:             if (!-e $path) {
                   5114:                 print $logfile "\nCreating directory ".$path;
                   5115:                 mkdir($path,02770);
                   5116:             }
                   5117:         }
                   5118:         my $versionresult;
                   5119:         if (-e $copyfile) {
                   5120:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   5121:         } else {
                   5122:             $versionresult = 'ok';
                   5123:         }
                   5124:         if ($versionresult eq 'ok') {
                   5125:             if (copy($source,$copyfile)) {
                   5126:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   5127:                 $output = 'ok';
                   5128:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  5129:                 push(@{$modified_urls},[$copyfile,$source]);
                   5130:                 my $metaoutput = 
                   5131:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   5132:                 unless ($registered_cleanup) {
                   5133:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5134:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5135:                     $registered_cleanup=1;
                   5136:                 }
1.9       raeburn  5137:             } else {
                   5138:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   5139:                 $output = &mt('Failed to copy file to RES space').", $!";
                   5140:             }
                   5141:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   5142:                 my $inputfile = $filepath.'/'.$file;
                   5143:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  5144:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   5145:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   5146:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   5147:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   5148:                         system("convert -sample $thumbsize $inputfile $outfile");
                   5149:                         chmod(0660, $filepath.'/tn-'.$file);
                   5150:                         if (-e $outfile) {
                   5151:                             my $copyfile=$targetdir.'/tn-'.$file;
                   5152:                             if (copy($outfile,$copyfile)) {
                   5153:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  5154:                                 my $thumb_metaoutput = 
                   5155:                                     &write_metadata($dom,$confname,$formname,
                   5156:                                                     $targetdir,'tn-'.$file,$logfile);
                   5157:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   5158:                                 unless ($registered_cleanup) {
                   5159:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5160:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5161:                                     $registered_cleanup=1;
                   5162:                                 }
1.16      raeburn  5163:                             } else {
                   5164:                                 print $logfile "\nUnable to write ".$copyfile.
                   5165:                                                ':'.$!."\n";
                   5166:                             }
                   5167:                         }
1.9       raeburn  5168:                     }
                   5169:                 }
                   5170:             }
                   5171:         } else {
                   5172:             $output = $versionresult;
                   5173:         }
                   5174:     }
                   5175:     return ($output,$logourl);
                   5176: }
                   5177: 
                   5178: sub logo_versioning {
                   5179:     my ($targetdir,$file,$logfile) = @_;
                   5180:     my $target = $targetdir.'/'.$file;
                   5181:     my ($maxversion,$fn,$extn,$output);
                   5182:     $maxversion = 0;
                   5183:     if ($file =~ /^(.+)\.(\w+)$/) {
                   5184:         $fn=$1;
                   5185:         $extn=$2;
                   5186:     }
                   5187:     opendir(DIR,$targetdir);
                   5188:     while (my $filename=readdir(DIR)) {
                   5189:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   5190:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   5191:         }
                   5192:     }
                   5193:     $maxversion++;
                   5194:     print $logfile "\nCreating old version ".$maxversion."\n";
                   5195:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   5196:     if (copy($target,$copyfile)) {
                   5197:         print $logfile "Copied old target to ".$copyfile."\n";
                   5198:         $copyfile=$copyfile.'.meta';
                   5199:         if (copy($target.'.meta',$copyfile)) {
                   5200:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   5201:             $output = 'ok';
                   5202:         } else {
                   5203:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   5204:             $output = &mt('Failed to copy old meta').", $!, ";
                   5205:         }
                   5206:     } else {
                   5207:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   5208:         $output = &mt('Failed to copy old target').", $!, ";
                   5209:     }
                   5210:     return $output;
                   5211: }
                   5212: 
                   5213: sub write_metadata {
                   5214:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   5215:     my (%metadatafields,%metadatakeys,$output);
                   5216:     $metadatafields{'title'}=$formname;
                   5217:     $metadatafields{'creationdate'}=time;
                   5218:     $metadatafields{'lastrevisiondate'}=time;
                   5219:     $metadatafields{'copyright'}='public';
                   5220:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   5221:                                          $env{'user.domain'};
                   5222:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   5223:     $metadatafields{'domain'}=$dom;
                   5224:     {
                   5225:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   5226:         my $mfh;
1.155     raeburn  5227:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
                   5228:             foreach (sort keys %metadatafields) {
                   5229:                 unless ($_=~/\./) {
                   5230:                     my $unikey=$_;
                   5231:                     $unikey=~/^([A-Za-z]+)/;
                   5232:                     my $tag=$1;
                   5233:                     $tag=~tr/A-Z/a-z/;
                   5234:                     print $mfh "\n\<$tag";
                   5235:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   5236:                         my $value=$metadatafields{$unikey.'.'.$_};
                   5237:                         $value=~s/\"/\'\'/g;
                   5238:                         print $mfh ' '.$_.'="'.$value.'"';
                   5239:                     }
                   5240:                     print $mfh '>'.
                   5241:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   5242:                             .'</'.$tag.'>';
                   5243:                 }
                   5244:             }
                   5245:             $output = 'ok';
                   5246:             print $logfile "\nWrote metadata";
                   5247:             close($mfh);
                   5248:         } else {
                   5249:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  5250:             $output = &mt('Could not write metadata');
                   5251:         }
                   5252:     }
1.155     raeburn  5253:     return $output;
                   5254: }
                   5255: 
                   5256: sub notifysubscribed {
                   5257:     foreach my $targetsource (@{$modified_urls}){
                   5258:         next unless (ref($targetsource) eq 'ARRAY');
                   5259:         my ($target,$source)=@{$targetsource};
                   5260:         if ($source ne '') {
                   5261:             if (open(my $logfh,'>>'.$source.'.log')) {
                   5262:                 print $logfh "\nCleanup phase: Notifications\n";
                   5263:                 my @subscribed=&subscribed_hosts($target);
                   5264:                 foreach my $subhost (@subscribed) {
                   5265:                     print $logfh "\nNotifying host ".$subhost.':';
                   5266:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   5267:                     print $logfh $reply;
                   5268:                 }
                   5269:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   5270:                 foreach my $subhost (@subscribedmeta) {
                   5271:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   5272:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   5273:                                                         $subhost);
                   5274:                     print $logfh $reply;
                   5275:                 }
                   5276:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  5277:                 close($logfh);
1.155     raeburn  5278:             }
                   5279:         }
                   5280:     }
                   5281:     return OK;
                   5282: }
                   5283: 
                   5284: sub subscribed_hosts {
                   5285:     my ($target) = @_;
                   5286:     my @subscribed;
                   5287:     if (open(my $fh,"<$target.subscription")) {
                   5288:         while (my $subline=<$fh>) {
                   5289:             if ($subline =~ /^($match_lonid):/) {
                   5290:                 my $host = $1;
                   5291:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   5292:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   5293:                         push(@subscribed,$host);
                   5294:                     }
                   5295:                 }
                   5296:             }
                   5297:         }
                   5298:     }
                   5299:     return @subscribed;
1.9       raeburn  5300: }
                   5301: 
                   5302: sub check_switchserver {
                   5303:     my ($dom,$confname) = @_;
                   5304:     my ($allowed,$switchserver);
                   5305:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   5306:     if ($home eq 'no_host') {
                   5307:         $home = &Apache::lonnet::domain($dom,'primary');
                   5308:     }
                   5309:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 5310:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   5311:     if (!$allowed) {
                   5312: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9       raeburn  5313:     }
                   5314:     return $switchserver;
                   5315: }
                   5316: 
1.1       raeburn  5317: sub modify_quotas {
1.86      raeburn  5318:     my ($dom,$action,%domconfig) = @_;
1.101     raeburn  5319:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
                   5320:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86      raeburn  5321:     if ($action eq 'quotas') {
                   5322:         $context = 'tools'; 
1.163   ! raeburn  5323:     } else {
1.86      raeburn  5324:         $context = $action;
                   5325:     }
                   5326:     if ($context eq 'requestcourses') {
1.98      raeburn  5327:         @usertools = ('official','unofficial','community');
1.106     raeburn  5328:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  5329:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   5330:         %titles = &courserequest_titles();
                   5331:         $toolregexp = join('|',@usertools);
                   5332:         %conditions = &courserequest_conditions();
1.163   ! raeburn  5333:     } elsif ($context eq 'requestauthor') {
        !          5334:         @usertools = ('author');
        !          5335:         %titles = &authorrequest_titles();
1.86      raeburn  5336:     } else {
1.162     raeburn  5337:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  5338:         %titles = &tool_titles();
1.86      raeburn  5339:     }
1.72      raeburn  5340:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44      raeburn  5341:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5342:     foreach my $key (keys(%env)) {
1.101     raeburn  5343:         if ($context eq 'requestcourses') {
                   5344:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   5345:                 my $item = $1;
                   5346:                 my $type = $2;
                   5347:                 if ($type =~ /^limit_(.+)/) {
                   5348:                     $limithash{$item}{$1} = $env{$key};
                   5349:                 } else {
                   5350:                     $confhash{$item}{$type} = $env{$key};
                   5351:                 }
                   5352:             }
1.163   ! raeburn  5353:         } elsif ($context eq 'requestauthor') {
        !          5354:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
        !          5355:                 $confhash{$1} = $env{$key};
        !          5356:             }
1.101     raeburn  5357:         } else {
1.86      raeburn  5358:             if ($key =~ /^form\.quota_(.+)$/) {
                   5359:                 $confhash{'defaultquota'}{$1} = $env{$key};
                   5360:             }
1.101     raeburn  5361:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
                   5362:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   5363:             }
1.72      raeburn  5364:         }
                   5365:     }
1.163   ! raeburn  5366:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102     raeburn  5367:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
                   5368:         @approvalnotify = sort(@approvalnotify);
                   5369:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
                   5370:         if (ref($domconfig{$action}) eq 'HASH') {
                   5371:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   5372:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   5373:                     $changes{'notify'}{'approval'} = 1;
                   5374:                 }
                   5375:             } else {
1.144     raeburn  5376:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5377:                     $changes{'notify'}{'approval'} = 1;
                   5378:                 }
                   5379:             }
                   5380:         } else {
1.144     raeburn  5381:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5382:                 $changes{'notify'}{'approval'} = 1;
                   5383:             }
                   5384:         }
                   5385:     } else {
1.86      raeburn  5386:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
                   5387:     }
1.72      raeburn  5388:     foreach my $item (@usertools) {
                   5389:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  5390:             my $unset; 
1.101     raeburn  5391:             if ($context eq 'requestcourses') {
1.104     raeburn  5392:                 $unset = '0';
                   5393:                 if ($type eq '_LC_adv') {
                   5394:                     $unset = '';
                   5395:                 }
1.101     raeburn  5396:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   5397:                     $confhash{$item}{$type} .= '=';
                   5398:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   5399:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   5400:                     }
                   5401:                 }
1.163   ! raeburn  5402:             } elsif ($context eq 'requestauthor') {
        !          5403:                 $unset = '0';
        !          5404:                 if ($type eq '_LC_adv') {
        !          5405:                     $unset = '';
        !          5406:                 }
1.72      raeburn  5407:             } else {
1.101     raeburn  5408:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   5409:                     $confhash{$item}{$type} = 1;
                   5410:                 } else {
                   5411:                     $confhash{$item}{$type} = 0;
                   5412:                 }
1.72      raeburn  5413:             }
1.86      raeburn  5414:             if (ref($domconfig{$action}) eq 'HASH') {
1.163   ! raeburn  5415:                 if ($action eq 'requestauthor') {
        !          5416:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
        !          5417:                         $changes{$type} = 1;
        !          5418:                     }
        !          5419:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  5420:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   5421:                         $changes{$item}{$type} = 1;
                   5422:                     }
                   5423:                 } else {
                   5424:                     if ($context eq 'requestcourses') {
1.104     raeburn  5425:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  5426:                             $changes{$item}{$type} = 1;
                   5427:                         }
                   5428:                     } else {
                   5429:                         if (!$confhash{$item}{$type}) {
                   5430:                             $changes{$item}{$type} = 1;
                   5431:                         }
                   5432:                     }
                   5433:                 }
                   5434:             } else {
                   5435:                 if ($context eq 'requestcourses') {
1.104     raeburn  5436:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  5437:                         $changes{$item}{$type} = 1;
                   5438:                     }
1.163   ! raeburn  5439:                 } elsif ($context eq 'requestauthor') {
        !          5440:                     if ($confhash{$type} ne $unset) {
        !          5441:                         $changes{$type} = 1;
        !          5442:                     }
1.72      raeburn  5443:                 } else {
                   5444:                     if (!$confhash{$item}{$type}) {
                   5445:                         $changes{$item}{$type} = 1;
                   5446:                     }
                   5447:                 }
                   5448:             }
1.1       raeburn  5449:         }
                   5450:     }
1.163   ! raeburn  5451:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  5452:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5453:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5454:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   5455:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5456:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   5457:                             $changes{'defaultquota'}{$key} = 1;
                   5458:                         }
                   5459:                     } else {
                   5460:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  5461:                     }
                   5462:                 }
1.86      raeburn  5463:             } else {
                   5464:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   5465:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5466:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   5467:                             $changes{'defaultquota'}{$key} = 1;
                   5468:                         }
                   5469:                     } else {
                   5470:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  5471:                     }
1.1       raeburn  5472:                 }
                   5473:             }
                   5474:         }
1.86      raeburn  5475:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   5476:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   5477:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5478:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5479:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   5480:                             $changes{'defaultquota'}{$key} = 1;
                   5481:                         }
                   5482:                     } else {
                   5483:                         if (!exists($domconfig{'quotas'}{$key})) {
                   5484:                             $changes{'defaultquota'}{$key} = 1;
                   5485:                         }
1.72      raeburn  5486:                     }
                   5487:                 } else {
1.86      raeburn  5488:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  5489:                 }
1.1       raeburn  5490:             }
                   5491:         }
                   5492:     }
1.72      raeburn  5493: 
1.163   ! raeburn  5494:     if ($context eq 'requestauthor') {
        !          5495:         $domdefaults{'requestauthor'} = \%confhash;
        !          5496:     } else {
        !          5497:         foreach my $key (keys(%confhash)) {
        !          5498:             $domdefaults{$key} = $confhash{$key};
        !          5499:         }
1.72      raeburn  5500:     }
1.163   ! raeburn  5501: 
1.1       raeburn  5502:     my %quotahash = (
1.86      raeburn  5503:                       $action => { %confhash }
1.1       raeburn  5504:                     );
                   5505:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   5506:                                              $dom);
                   5507:     if ($putresult eq 'ok') {
                   5508:         if (keys(%changes) > 0) {
1.72      raeburn  5509:             my $cachetime = 24*60*60;
                   5510:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   5511: 
1.1       raeburn  5512:             $resulttext = &mt('Changes made:').'<ul>';
1.163   ! raeburn  5513:             unless (($context eq 'requestcourses') || 
        !          5514:                     ($context eq 'requestauthor')) {
1.86      raeburn  5515:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   5516:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   5517:                     foreach my $type (@{$types},'default') {
                   5518:                         if (defined($changes{'defaultquota'}{$type})) {
                   5519:                             my $typetitle = $usertypes->{$type};
                   5520:                             if ($type eq 'default') {
                   5521:                                 $typetitle = $othertitle;
                   5522:                             }
                   5523:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  5524:                         }
                   5525:                     }
1.86      raeburn  5526:                     $resulttext .= '</ul></li>';
1.72      raeburn  5527:                 }
                   5528:             }
1.80      raeburn  5529:             my %newenv;
1.72      raeburn  5530:             foreach my $item (@usertools) {
1.163   ! raeburn  5531:                 my (%haschgs,%inconf);
        !          5532:                 if ($context eq 'requestauthor') {
        !          5533:                     %haschgs = %changes;
        !          5534:                     %inconf = %confhash; 
        !          5535:                 } else {
        !          5536:                     if (ref($changes{$item}) eq 'HASH') {
        !          5537:                         %haschgs = %{$changes{$item}};
        !          5538:                     }
        !          5539:                     if (ref($confhash{$item}) eq 'HASH') {
        !          5540:                         %inconf = %{$confhash{$item}};
        !          5541:                     }
        !          5542:                 }
        !          5543:                 if (keys(%haschgs) > 0) {
1.80      raeburn  5544:                     my $newacc = 
                   5545:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   5546:                                                           $env{'user.domain'},
1.86      raeburn  5547:                                                           $item,'reload',$context);
1.163   ! raeburn  5548:                     if (($context eq 'requestcourses') || 
        !          5549:                         ($context eq 'requestauthor')) {
1.108     raeburn  5550:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   5551:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  5552:                         }
                   5553:                     } else {
                   5554:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   5555:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   5556:                         }
1.80      raeburn  5557:                     }
1.163   ! raeburn  5558:                     unless ($context eq 'requestauthor') {
        !          5559:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
        !          5560:                     }
1.72      raeburn  5561:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163   ! raeburn  5562:                         if ($haschgs{$type}) {
1.72      raeburn  5563:                             my $typetitle = $usertypes->{$type};
                   5564:                             if ($type eq 'default') {
                   5565:                                 $typetitle = $othertitle;
                   5566:                             } elsif ($type eq '_LC_adv') {
                   5567:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   5568:                             }
1.163   ! raeburn  5569:                             if ($inconf{$type}) {
1.101     raeburn  5570:                                 if ($context eq 'requestcourses') {
                   5571:                                     my $cond;
1.163   ! raeburn  5572:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  5573:                                         if ($1 eq '') {
                   5574:                                             $cond = &mt('(Automatic processing of any request).');
                   5575:                                         } else {
                   5576:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   5577:                                         }
                   5578:                                     } else { 
1.163   ! raeburn  5579:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  5580:                                     }
                   5581:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
                   5582:                                 } else {
                   5583:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   5584:                                 }
1.72      raeburn  5585:                             } else {
1.104     raeburn  5586:                                 if ($type eq '_LC_adv') {
1.163   ! raeburn  5587:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  5588:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5589:                                     } else { 
                   5590:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   5591:                                     }
                   5592:                                 } else {
                   5593:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5594:                                 }
1.72      raeburn  5595:                             }
                   5596:                         }
1.26      raeburn  5597:                     }
1.163   ! raeburn  5598:                     unless ($context eq 'requestauthor') {
        !          5599:                         $resulttext .= '</ul></li>';
        !          5600:                     }
1.26      raeburn  5601:                 }
1.1       raeburn  5602:             }
1.163   ! raeburn  5603:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  5604:                 if (ref($changes{'notify'}) eq 'HASH') {
                   5605:                     if ($changes{'notify'}{'approval'}) {
                   5606:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   5607:                             if ($confhash{'notify'}{'approval'}) {
                   5608:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   5609:                             } else {
1.163   ! raeburn  5610:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  5611:                             }
                   5612:                         }
                   5613:                     }
                   5614:                 }
                   5615:             }
1.1       raeburn  5616:             $resulttext .= '</ul>';
1.80      raeburn  5617:             if (keys(%newenv)) {
                   5618:                 &Apache::lonnet::appenv(\%newenv);
                   5619:             }
1.1       raeburn  5620:         } else {
1.86      raeburn  5621:             if ($context eq 'requestcourses') {
                   5622:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163   ! raeburn  5623:             } elsif ($context eq 'requestauthor') {
        !          5624:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  5625:             } else {
1.90      weissno  5626:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  5627:             }
1.1       raeburn  5628:         }
                   5629:     } else {
1.11      albertel 5630:         $resulttext = '<span class="LC_error">'.
                   5631: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5632:     }
1.3       raeburn  5633:     return $resulttext;
1.1       raeburn  5634: }
                   5635: 
1.3       raeburn  5636: sub modify_autoenroll {
                   5637:     my ($dom,%domconfig) = @_;
1.1       raeburn  5638:     my ($resulttext,%changes);
                   5639:     my %currautoenroll;
                   5640:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   5641:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   5642:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   5643:         }
                   5644:     }
                   5645:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   5646:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  5647:                   sender => 'Sender for notification messages',
                   5648:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  5649:     my @offon = ('off','on');
1.17      raeburn  5650:     my $sender_uname = $env{'form.sender_uname'};
                   5651:     my $sender_domain = $env{'form.sender_domain'};
                   5652:     if ($sender_domain eq '') {
                   5653:         $sender_uname = '';
                   5654:     } elsif ($sender_uname eq '') {
                   5655:         $sender_domain = '';
                   5656:     }
1.129     raeburn  5657:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  5658:     my %autoenrollhash =  (
1.129     raeburn  5659:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   5660:                                        'sender_uname' => $sender_uname,
                   5661:                                        'sender_domain' => $sender_domain,
                   5662:                                        'co-owners' => $coowners,
1.1       raeburn  5663:                                 }
                   5664:                      );
1.4       raeburn  5665:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   5666:                                              $dom);
1.1       raeburn  5667:     if ($putresult eq 'ok') {
                   5668:         if (exists($currautoenroll{'run'})) {
                   5669:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   5670:                  $changes{'run'} = 1;
                   5671:              }
                   5672:         } elsif ($autorun) {
                   5673:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  5674:                  $changes{'run'} = 1;
1.1       raeburn  5675:             }
                   5676:         }
1.17      raeburn  5677:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  5678:             $changes{'sender'} = 1;
                   5679:         }
1.17      raeburn  5680:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  5681:             $changes{'sender'} = 1;
                   5682:         }
1.129     raeburn  5683:         if ($currautoenroll{'co-owners'} ne '') {
                   5684:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   5685:                 $changes{'coowners'} = 1;
                   5686:             }
                   5687:         } elsif ($coowners) {
                   5688:             $changes{'coowners'} = 1;
                   5689:         }      
1.1       raeburn  5690:         if (keys(%changes) > 0) {
                   5691:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  5692:             if ($changes{'run'}) {
1.1       raeburn  5693:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   5694:             }
                   5695:             if ($changes{'sender'}) {
1.17      raeburn  5696:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   5697:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   5698:                 } else {
                   5699:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   5700:                 }
1.1       raeburn  5701:             }
1.129     raeburn  5702:             if ($changes{'coowners'}) {
                   5703:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   5704:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   5705:             }
1.1       raeburn  5706:             $resulttext .= '</ul>';
                   5707:         } else {
                   5708:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   5709:         }
                   5710:     } else {
1.11      albertel 5711:         $resulttext = '<span class="LC_error">'.
                   5712: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5713:     }
1.3       raeburn  5714:     return $resulttext;
1.1       raeburn  5715: }
                   5716: 
                   5717: sub modify_autoupdate {
1.3       raeburn  5718:     my ($dom,%domconfig) = @_;
1.1       raeburn  5719:     my ($resulttext,%currautoupdate,%fields,%changes);
                   5720:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   5721:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   5722:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   5723:         }
                   5724:     }
                   5725:     my @offon = ('off','on');
                   5726:     my %title = &Apache::lonlocal::texthash (
                   5727:                    run => 'Auto-update:',
                   5728:                    classlists => 'Updates to user information in classlists?'
                   5729:                 );
1.44      raeburn  5730:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5731:     my %fieldtitles = &Apache::lonlocal::texthash (
                   5732:                         id => 'Student/Employee ID',
1.20      raeburn  5733:                         permanentemail => 'E-mail address',
1.1       raeburn  5734:                         lastname => 'Last Name',
                   5735:                         firstname => 'First Name',
                   5736:                         middlename => 'Middle Name',
1.132     raeburn  5737:                         generation => 'Generation',
1.1       raeburn  5738:                       );
1.142     raeburn  5739:     $othertitle = &mt('All users');
1.1       raeburn  5740:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  5741:         $othertitle = &mt('Other users');
1.1       raeburn  5742:     }
                   5743:     foreach my $key (keys(%env)) {
                   5744:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  5745:             my ($usertype,$item) = ($1,$2);
                   5746:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   5747:                 if ($usertype eq 'default') {   
                   5748:                     push(@{$fields{$1}},$2);
                   5749:                 } elsif (ref($types) eq 'ARRAY') {
                   5750:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   5751:                         push(@{$fields{$1}},$2);
                   5752:                     }
                   5753:                 }
                   5754:             }
1.1       raeburn  5755:         }
                   5756:     }
1.131     raeburn  5757:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   5758:     @lockablenames = sort(@lockablenames);
                   5759:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   5760:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   5761:         if (@changed) {
                   5762:             $changes{'lockablenames'} = 1;
                   5763:         }
                   5764:     } else {
                   5765:         if (@lockablenames) {
                   5766:             $changes{'lockablenames'} = 1;
                   5767:         }
                   5768:     }
1.1       raeburn  5769:     my %updatehash = (
                   5770:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   5771:                                       classlists => $env{'form.classlists'},
                   5772:                                       fields => {%fields},
1.131     raeburn  5773:                                       lockablenames => \@lockablenames,
1.1       raeburn  5774:                                     }
                   5775:                      );
                   5776:     foreach my $key (keys(%currautoupdate)) {
                   5777:         if (($key eq 'run') || ($key eq 'classlists')) {
                   5778:             if (exists($updatehash{autoupdate}{$key})) {
                   5779:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   5780:                     $changes{$key} = 1;
                   5781:                 }
                   5782:             }
                   5783:         } elsif ($key eq 'fields') {
                   5784:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  5785:                 foreach my $item (@{$types},'default') {
1.1       raeburn  5786:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   5787:                         my $change = 0;
                   5788:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   5789:                             if (!exists($fields{$item})) {
                   5790:                                 $change = 1;
1.132     raeburn  5791:                                 last;
1.1       raeburn  5792:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  5793:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  5794:                                     $change = 1;
1.132     raeburn  5795:                                     last;
1.1       raeburn  5796:                                 }
                   5797:                             }
                   5798:                         }
                   5799:                         if ($change) {
                   5800:                             push(@{$changes{$key}},$item);
                   5801:                         }
1.26      raeburn  5802:                     } 
1.1       raeburn  5803:                 }
                   5804:             }
1.131     raeburn  5805:         } elsif ($key eq 'lockablenames') {
                   5806:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   5807:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   5808:                 if (@changed) {
                   5809:                     $changes{'lockablenames'} = 1;
                   5810:                 }
                   5811:             } else {
                   5812:                 if (@lockablenames) {
                   5813:                     $changes{'lockablenames'} = 1;
                   5814:                 }
                   5815:             }
                   5816:         }
                   5817:     }
                   5818:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   5819:         if (@lockablenames) {
                   5820:             $changes{'lockablenames'} = 1;
1.1       raeburn  5821:         }
                   5822:     }
1.26      raeburn  5823:     foreach my $item (@{$types},'default') {
                   5824:         if (defined($fields{$item})) {
                   5825:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  5826:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   5827:                     my $change = 0;
                   5828:                     if (ref($fields{$item}) eq 'ARRAY') {
                   5829:                         foreach my $type (@{$fields{$item}}) {
                   5830:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   5831:                                 $change = 1;
                   5832:                                 last;
                   5833:                             }
                   5834:                         }
                   5835:                     }
                   5836:                     if ($change) {
                   5837:                         push(@{$changes{'fields'}},$item);
                   5838:                     }
                   5839:                 } else {
1.26      raeburn  5840:                     push(@{$changes{'fields'}},$item);
                   5841:                 }
                   5842:             } else {
                   5843:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  5844:             }
                   5845:         }
                   5846:     }
                   5847:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   5848:                                              $dom);
                   5849:     if ($putresult eq 'ok') {
                   5850:         if (keys(%changes) > 0) {
                   5851:             $resulttext = &mt('Changes made:').'<ul>';
                   5852:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  5853:                 if ($key eq 'lockablenames') {
                   5854:                     $resulttext .= '<li>';
                   5855:                     if (@lockablenames) {
                   5856:                         $usertypes->{'default'} = $othertitle;
                   5857:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   5858:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   5859:                     } else {
                   5860:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   5861:                     }
                   5862:                     $resulttext .= '</li>';
                   5863:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  5864:                     foreach my $item (@{$changes{$key}}) {
                   5865:                         my @newvalues;
                   5866:                         foreach my $type (@{$fields{$item}}) {
                   5867:                             push(@newvalues,$fieldtitles{$type});
                   5868:                         }
1.3       raeburn  5869:                         my $newvaluestr;
                   5870:                         if (@newvalues > 0) {
                   5871:                             $newvaluestr = join(', ',@newvalues);
                   5872:                         } else {
                   5873:                             $newvaluestr = &mt('none');
1.6       raeburn  5874:                         }
1.1       raeburn  5875:                         if ($item eq 'default') {
1.26      raeburn  5876:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  5877:                         } else {
1.26      raeburn  5878:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  5879:                         }
                   5880:                     }
                   5881:                 } else {
                   5882:                     my $newvalue;
                   5883:                     if ($key eq 'run') {
                   5884:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   5885:                     } else {
                   5886:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  5887:                     }
1.1       raeburn  5888:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   5889:                 }
                   5890:             }
                   5891:             $resulttext .= '</ul>';
                   5892:         } else {
1.3       raeburn  5893:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  5894:         }
                   5895:     } else {
1.11      albertel 5896:         $resulttext = '<span class="LC_error">'.
                   5897: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5898:     }
1.3       raeburn  5899:     return $resulttext;
1.1       raeburn  5900: }
                   5901: 
1.125     raeburn  5902: sub modify_autocreate {
                   5903:     my ($dom,%domconfig) = @_;
                   5904:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   5905:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   5906:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   5907:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   5908:         }
                   5909:     }
                   5910:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   5911:                  req => 'Auto-creation of validated requests for official courses',
                   5912:                  xmldc => 'Identity of course creator of courses from XML files',
                   5913:                );
                   5914:     my @types = ('xml','req');
                   5915:     foreach my $item (@types) {
                   5916:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   5917:         $newvals{$item} =~ s/\D//g;
                   5918:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   5919:     }
                   5920:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   5921:     my %domcoords = &get_active_dcs($dom);
                   5922:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   5923:         $newvals{'xmldc'} = '';
                   5924:     } 
                   5925:     %autocreatehash =  (
                   5926:                         autocreate => { xml => $newvals{'xml'},
                   5927:                                         req => $newvals{'req'},
                   5928:                                       }
                   5929:                        );
                   5930:     if ($newvals{'xmldc'} ne '') {
                   5931:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   5932:     }
                   5933:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   5934:                                              $dom);
                   5935:     if ($putresult eq 'ok') {
                   5936:         my @items = @types;
                   5937:         if ($newvals{'xml'}) {
                   5938:             push(@items,'xmldc');
                   5939:         }
                   5940:         foreach my $item (@items) {
                   5941:             if (exists($currautocreate{$item})) {
                   5942:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   5943:                     $changes{$item} = 1;
                   5944:                 }
                   5945:             } elsif ($newvals{$item}) {
                   5946:                 $changes{$item} = 1;
                   5947:             }
                   5948:         }
                   5949:         if (keys(%changes) > 0) {
                   5950:             my @offon = ('off','on'); 
                   5951:             $resulttext = &mt('Changes made:').'<ul>';
                   5952:             foreach my $item (@types) {
                   5953:                 if ($changes{$item}) {
                   5954:                     my $newtxt = $offon[$newvals{$item}];
                   5955:                     $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
                   5956:                 }
                   5957:             }
                   5958:             if ($changes{'xmldc'}) {
                   5959:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   5960:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
                   5961:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
                   5962:             }
                   5963:             $resulttext .= '</ul>';
                   5964:         } else {
                   5965:             $resulttext = &mt('No changes made to auto-creation settings');
                   5966:         }
                   5967:     } else {
                   5968:         $resulttext = '<span class="LC_error">'.
                   5969:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   5970:     }
                   5971:     return $resulttext;
                   5972: }
                   5973: 
1.23      raeburn  5974: sub modify_directorysrch {
                   5975:     my ($dom,%domconfig) = @_;
                   5976:     my ($resulttext,%changes);
                   5977:     my %currdirsrch;
                   5978:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   5979:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   5980:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   5981:         }
                   5982:     }
                   5983:     my %title = ( available => 'Directory search available',
1.24      raeburn  5984:                   localonly => 'Other domains can search',
1.23      raeburn  5985:                   searchby => 'Search types',
                   5986:                   searchtypes => 'Search latitude');
                   5987:     my @offon = ('off','on');
1.24      raeburn  5988:     my @otherdoms = ('Yes','No');
1.23      raeburn  5989: 
1.25      raeburn  5990:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  5991:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   5992:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   5993: 
1.44      raeburn  5994:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  5995:     if (keys(%{$usertypes}) == 0) {
                   5996:         @cansearch = ('default');
                   5997:     } else {
                   5998:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   5999:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   6000:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   6001:                     push(@{$changes{'cansearch'}},$type);
                   6002:                 }
1.23      raeburn  6003:             }
1.26      raeburn  6004:             foreach my $type (@cansearch) {
                   6005:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   6006:                     push(@{$changes{'cansearch'}},$type);
                   6007:                 }
1.23      raeburn  6008:             }
1.26      raeburn  6009:         } else {
                   6010:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  6011:         }
                   6012:     }
                   6013: 
                   6014:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   6015:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   6016:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   6017:                 push(@{$changes{'searchby'}},$by);
                   6018:             }
                   6019:         }
                   6020:         foreach my $by (@searchby) {
                   6021:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   6022:                 push(@{$changes{'searchby'}},$by);
                   6023:             }
                   6024:         }
                   6025:     } else {
                   6026:         push(@{$changes{'searchby'}},@searchby);
                   6027:     }
1.25      raeburn  6028: 
                   6029:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   6030:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   6031:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   6032:                 push(@{$changes{'searchtypes'}},$type);
                   6033:             }
                   6034:         }
                   6035:         foreach my $type (@searchtypes) {
                   6036:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   6037:                 push(@{$changes{'searchtypes'}},$type);
                   6038:             }
                   6039:         }
                   6040:     } else {
                   6041:         if (exists($currdirsrch{'searchtypes'})) {
                   6042:             foreach my $type (@searchtypes) {  
                   6043:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   6044:                     push(@{$changes{'searchtypes'}},$type);
                   6045:                 }
                   6046:             }
                   6047:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   6048:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   6049:             }   
                   6050:         } else {
                   6051:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   6052:         }
                   6053:     }
                   6054: 
1.23      raeburn  6055:     my %dirsrch_hash =  (
                   6056:             directorysrch => { available => $env{'form.dirsrch_available'},
                   6057:                                cansearch => \@cansearch,
1.24      raeburn  6058:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  6059:                                searchby => \@searchby,
1.25      raeburn  6060:                                searchtypes => \@searchtypes,
1.23      raeburn  6061:                              }
                   6062:             );
                   6063:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   6064:                                              $dom);
                   6065:     if ($putresult eq 'ok') {
                   6066:         if (exists($currdirsrch{'available'})) {
                   6067:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   6068:                  $changes{'available'} = 1;
                   6069:              }
                   6070:         } else {
                   6071:             if ($env{'form.dirsrch_available'} eq '1') {
                   6072:                 $changes{'available'} = 1;
                   6073:             }
                   6074:         }
1.24      raeburn  6075:         if (exists($currdirsrch{'localonly'})) {
                   6076:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   6077:                  $changes{'localonly'} = 1;
                   6078:              }
                   6079:         } else {
                   6080:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   6081:                 $changes{'localonly'} = 1;
                   6082:             }
                   6083:         }
1.23      raeburn  6084:         if (keys(%changes) > 0) {
                   6085:             $resulttext = &mt('Changes made:').'<ul>';
                   6086:             if ($changes{'available'}) {
                   6087:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   6088:             }
1.24      raeburn  6089:             if ($changes{'localonly'}) {
                   6090:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   6091:             }
                   6092: 
1.23      raeburn  6093:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   6094:                 my $chgtext;
1.26      raeburn  6095:                 if (ref($usertypes) eq 'HASH') {
                   6096:                     if (keys(%{$usertypes}) > 0) {
                   6097:                         foreach my $type (@{$types}) {
                   6098:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   6099:                                 $chgtext .= $usertypes->{$type}.'; ';
                   6100:                             }
                   6101:                         }
                   6102:                         if (grep(/^default$/,@cansearch)) {
                   6103:                             $chgtext .= $othertitle;
                   6104:                         } else {
                   6105:                             $chgtext =~ s/\; $//;
                   6106:                         }
                   6107:                         $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23      raeburn  6108:                     }
                   6109:                 }
                   6110:             }
                   6111:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   6112:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   6113:                 my $chgtext;
                   6114:                 foreach my $type (@{$titleorder}) {
                   6115:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   6116:                         if (defined($searchtitles->{$type})) {
                   6117:                             $chgtext .= $searchtitles->{$type}.'; ';
                   6118:                         }
                   6119:                     }
                   6120:                 }
                   6121:                 $chgtext =~ s/\; $//;
                   6122:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   6123:             }
1.25      raeburn  6124:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   6125:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   6126:                 my $chgtext;
                   6127:                 foreach my $type (@{$srchtypeorder}) {
                   6128:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   6129:                         if (defined($srchtypes_desc->{$type})) {
                   6130:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   6131:                         }
                   6132:                     }
                   6133:                 }
                   6134:                 $chgtext =~ s/\; $//;
                   6135:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23      raeburn  6136:             }
                   6137:             $resulttext .= '</ul>';
                   6138:         } else {
                   6139:             $resulttext = &mt('No changes made to institution directory search settings');
                   6140:         }
                   6141:     } else {
                   6142:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  6143:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   6144:     }
                   6145:     return $resulttext;
                   6146: }
                   6147: 
1.28      raeburn  6148: sub modify_contacts {
                   6149:     my ($dom,%domconfig) = @_;
                   6150:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   6151:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   6152:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   6153:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   6154:         }
                   6155:     }
1.134     raeburn  6156:     my (%others,%to,%bcc);
1.28      raeburn  6157:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  6158:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
                   6159:                     'requestsmail');
1.28      raeburn  6160:     foreach my $type (@mailings) {
                   6161:         @{$newsetting{$type}} = 
                   6162:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   6163:         foreach my $item (@contacts) {
                   6164:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   6165:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   6166:             } else {
                   6167:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   6168:             }
                   6169:         }  
                   6170:         $others{$type} = $env{'form.'.$type.'_others'};
                   6171:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  6172:         if ($type eq 'helpdeskmail') {
                   6173:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   6174:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   6175:         }
1.28      raeburn  6176:     }
                   6177:     foreach my $item (@contacts) {
                   6178:         $to{$item} = $env{'form.'.$item};
                   6179:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   6180:     }
                   6181:     if (keys(%currsetting) > 0) {
                   6182:         foreach my $item (@contacts) {
                   6183:             if ($to{$item} ne $currsetting{$item}) {
                   6184:                 $changes{$item} = 1;
                   6185:             }
                   6186:         }
                   6187:         foreach my $type (@mailings) {
                   6188:             foreach my $item (@contacts) {
                   6189:                 if (ref($currsetting{$type}) eq 'HASH') {
                   6190:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   6191:                         push(@{$changes{$type}},$item);
                   6192:                     }
                   6193:                 } else {
                   6194:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   6195:                 }
                   6196:             }
                   6197:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   6198:                 push(@{$changes{$type}},'others');
                   6199:             }
1.134     raeburn  6200:             if ($type eq 'helpdeskmail') {   
                   6201:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   6202:                     push(@{$changes{$type}},'bcc'); 
                   6203:                 }
                   6204:             }
1.28      raeburn  6205:         }
                   6206:     } else {
                   6207:         my %default;
                   6208:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   6209:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   6210:         $default{'errormail'} = 'adminemail';
                   6211:         $default{'packagesmail'} = 'adminemail';
                   6212:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  6213:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  6214:         $default{'requestsmail'} = 'adminemail';
1.28      raeburn  6215:         foreach my $item (@contacts) {
                   6216:            if ($to{$item} ne $default{$item}) {
                   6217:               $changes{$item} = 1;
                   6218:            } 
                   6219:         }
                   6220:         foreach my $type (@mailings) {
                   6221:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   6222:                
                   6223:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   6224:             }
                   6225:             if ($others{$type} ne '') {
                   6226:                 push(@{$changes{$type}},'others');
1.134     raeburn  6227:             }
                   6228:             if ($type eq 'helpdeskmail') {
                   6229:                 if ($bcc{$type} ne '') {
                   6230:                     push(@{$changes{$type}},'bcc');
                   6231:                 }
                   6232:             }
1.28      raeburn  6233:         }
                   6234:     }
                   6235:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   6236:                                              $dom);
                   6237:     if ($putresult eq 'ok') {
                   6238:         if (keys(%changes) > 0) {
                   6239:             my ($titles,$short_titles)  = &contact_titles();
                   6240:             $resulttext = &mt('Changes made:').'<ul>';
                   6241:             foreach my $item (@contacts) {
                   6242:                 if ($changes{$item}) {
                   6243:                     $resulttext .= '<li>'.$titles->{$item}.
                   6244:                                     &mt(' set to: ').
                   6245:                                     '<span class="LC_cusr_emph">'.
                   6246:                                     $to{$item}.'</span></li>';
                   6247:                 }
                   6248:             }
                   6249:             foreach my $type (@mailings) {
                   6250:                 if (ref($changes{$type}) eq 'ARRAY') {
                   6251:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   6252:                     my @text;
                   6253:                     foreach my $item (@{$newsetting{$type}}) {
                   6254:                         push(@text,$short_titles->{$item});
                   6255:                     }
                   6256:                     if ($others{$type} ne '') {
                   6257:                         push(@text,$others{$type});
                   6258:                     }
                   6259:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  6260:                                    join(', ',@text).'</span>';
                   6261:                     if ($type eq 'helpdeskmail') {
                   6262:                         if ($bcc{$type} ne '') {
                   6263:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   6264:                         }
                   6265:                     }
                   6266:                     $resulttext .= '</li>';
1.28      raeburn  6267:                 }
                   6268:             }
                   6269:             $resulttext .= '</ul>';
                   6270:         } else {
1.34      raeburn  6271:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  6272:         }
                   6273:     } else {
                   6274:         $resulttext = '<span class="LC_error">'.
                   6275:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   6276:     }
                   6277:     return $resulttext;
                   6278: }
                   6279: 
                   6280: sub modify_usercreation {
1.27      raeburn  6281:     my ($dom,%domconfig) = @_;
1.34      raeburn  6282:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43      raeburn  6283:     my $warningmsg;
1.27      raeburn  6284:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   6285:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   6286:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   6287:         }
                   6288:     }
                   6289:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  6290:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43      raeburn  6291:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100     raeburn  6292:     my @contexts = ('author','course','requestcrs','selfcreate');
1.34      raeburn  6293:     foreach my $item(@contexts) {
1.45      raeburn  6294:         if ($item eq 'selfcreate') {
1.50      raeburn  6295:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43      raeburn  6296:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   6297:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50      raeburn  6298:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                   6299:                     if (grep(/^login$/,@{$cancreate{$item}})) {
                   6300:                         $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.');   
                   6301:                     }
1.43      raeburn  6302:                 }
                   6303:             }
1.50      raeburn  6304:         } else {
                   6305:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43      raeburn  6306:         }
1.34      raeburn  6307:     }
1.93      raeburn  6308:     my ($othertitle,$usertypes,$types) = 
                   6309:         &Apache::loncommon::sorted_inst_types($dom);
                   6310:     if (ref($types) eq 'ARRAY') {
                   6311:         if (@{$types} > 0) {
                   6312:             @{$cancreate{'statustocreate'}} = 
                   6313:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103     raeburn  6314:         } else {
                   6315:             @{$cancreate{'statustocreate'}} = ();
1.93      raeburn  6316:         }
                   6317:         push(@contexts,'statustocreate');
                   6318:     }
1.34      raeburn  6319:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   6320:         foreach my $item (@contexts) {
1.93      raeburn  6321:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                   6322:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50      raeburn  6323:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103     raeburn  6324:                         if (ref($cancreate{$item}) eq 'ARRAY') {
                   6325:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   6326:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6327:                                     push(@{$changes{'cancreate'}},$item);
                   6328:                                 }
1.50      raeburn  6329:                             }
                   6330:                         }
                   6331:                     }
                   6332:                 } else {
                   6333:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
                   6334:                         if (@{$cancreate{$item}} > 0) {
                   6335:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6336:                                 push(@{$changes{'cancreate'}},$item);
                   6337:                             }
                   6338:                         }
                   6339:                     } else {
                   6340:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                   6341:                             if (@{$cancreate{$item}} < 3) {
                   6342:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6343:                                     push(@{$changes{'cancreate'}},$item);
                   6344:                                 }
                   6345:                             }
                   6346:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                   6347:                             if (@{$cancreate{$item}} > 0) {
                   6348:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6349:                                     push(@{$changes{'cancreate'}},$item);
                   6350:                                 }
                   6351:                             }
                   6352:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                   6353:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6354:                                 push(@{$changes{'cancreate'}},$item);
                   6355:                             }
                   6356:                         }
                   6357:                     }
                   6358:                 }
                   6359:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6360:                     foreach my $type (@{$cancreate{$item}}) {
                   6361:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   6362:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   6363:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6364:                                     push(@{$changes{'cancreate'}},$item);
                   6365:                                 }
                   6366:                             }
                   6367:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                   6368:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                   6369:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                   6370:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6371:                                     push(@{$changes{'cancreate'}},$item);
                   6372:                                 }
                   6373:                             }
                   6374:                         }
                   6375:                     }
                   6376:                 }
                   6377:             } else {
                   6378:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   6379:                     push(@{$changes{'cancreate'}},$item);
                   6380:                 }
                   6381:             }
1.27      raeburn  6382:         }
1.34      raeburn  6383:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   6384:         foreach my $item (@contexts) {
1.43      raeburn  6385:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  6386:                 if ($cancreate{$item} ne 'any') {
                   6387:                     push(@{$changes{'cancreate'}},$item);
                   6388:                 }
                   6389:             } else {
                   6390:                 if ($cancreate{$item} ne 'none') {
                   6391:                     push(@{$changes{'cancreate'}},$item);
                   6392:                 }
1.27      raeburn  6393:             }
                   6394:         }
                   6395:     } else {
1.43      raeburn  6396:         foreach my $item (@contexts)  {
1.34      raeburn  6397:             push(@{$changes{'cancreate'}},$item);
                   6398:         }
1.27      raeburn  6399:     }
1.34      raeburn  6400: 
1.27      raeburn  6401:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   6402:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   6403:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   6404:                 push(@{$changes{'username_rule'}},$type);
                   6405:             }
                   6406:         }
                   6407:         foreach my $type (@username_rule) {
                   6408:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   6409:                 push(@{$changes{'username_rule'}},$type);
                   6410:             }
                   6411:         }
                   6412:     } else {
                   6413:         push(@{$changes{'username_rule'}},@username_rule);
                   6414:     }
                   6415: 
1.32      raeburn  6416:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   6417:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   6418:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   6419:                 push(@{$changes{'id_rule'}},$type);
                   6420:             }
                   6421:         }
                   6422:         foreach my $type (@id_rule) {
                   6423:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   6424:                 push(@{$changes{'id_rule'}},$type);
                   6425:             }
                   6426:         }
                   6427:     } else {
                   6428:         push(@{$changes{'id_rule'}},@id_rule);
                   6429:     }
                   6430: 
1.43      raeburn  6431:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   6432:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   6433:             if (!grep(/^\Q$type\E$/,@email_rule)) {
                   6434:                 push(@{$changes{'email_rule'}},$type);
                   6435:             }
                   6436:         }
                   6437:         foreach my $type (@email_rule) {
                   6438:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   6439:                 push(@{$changes{'email_rule'}},$type);
                   6440:             }
                   6441:         }
                   6442:     } else {
                   6443:         push(@{$changes{'email_rule'}},@email_rule);
                   6444:     }
                   6445: 
                   6446:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  6447:     my @authtypes = ('int','krb4','krb5','loc');
                   6448:     my %authhash;
1.43      raeburn  6449:     foreach my $item (@authen_contexts) {
1.28      raeburn  6450:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   6451:         foreach my $auth (@authtypes) {
                   6452:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   6453:                 $authhash{$item}{$auth} = 1;
                   6454:             } else {
                   6455:                 $authhash{$item}{$auth} = 0;
                   6456:             }
                   6457:         }
                   6458:     }
                   6459:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  6460:         foreach my $item (@authen_contexts) {
1.28      raeburn  6461:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   6462:                 foreach my $auth (@authtypes) {
                   6463:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   6464:                         push(@{$changes{'authtypes'}},$item);
                   6465:                         last;
                   6466:                     }
                   6467:                 }
                   6468:             }
                   6469:         }
                   6470:     } else {
1.43      raeburn  6471:         foreach my $item (@authen_contexts) {
1.28      raeburn  6472:             push(@{$changes{'authtypes'}},$item);
                   6473:         }
                   6474:     }
                   6475: 
1.27      raeburn  6476:     my %usercreation_hash =  (
1.28      raeburn  6477:             usercreation => {
1.34      raeburn  6478:                               cancreate     => \%cancreate,
1.27      raeburn  6479:                               username_rule => \@username_rule,
1.32      raeburn  6480:                               id_rule       => \@id_rule,
1.43      raeburn  6481:                               email_rule    => \@email_rule,
1.32      raeburn  6482:                               authtypes     => \%authhash,
1.27      raeburn  6483:                             }
                   6484:             );
                   6485: 
                   6486:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   6487:                                              $dom);
1.50      raeburn  6488: 
                   6489:     my %selfcreatetypes = (
                   6490:                              sso   => 'users authenticated by institutional single sign on',
                   6491:                              login => 'users authenticated by institutional log-in',
                   6492:                              email => 'users who provide a valid e-mail address for use as the username',
                   6493:                           );
1.27      raeburn  6494:     if ($putresult eq 'ok') {
                   6495:         if (keys(%changes) > 0) {
                   6496:             $resulttext = &mt('Changes made:').'<ul>';
                   6497:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  6498:                 my %lt = &usercreation_types();
                   6499:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  6500:                     my $chgtext;
                   6501:                     unless ($type eq 'statustocreate') {
                   6502:                         $chgtext = $lt{$type}.', ';
                   6503:                     }
1.45      raeburn  6504:                     if ($type eq 'selfcreate') {
1.50      raeburn  6505:                         if (@{$cancreate{$type}} == 0) {
1.43      raeburn  6506:                             $chgtext .= &mt('creation of a new user account is not permitted.');
1.50      raeburn  6507:                         } else {
1.100     raeburn  6508:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50      raeburn  6509:                             foreach my $case (@{$cancreate{$type}}) {
                   6510:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   6511:                             }
                   6512:                             $chgtext .= '</ul>';
1.100     raeburn  6513:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   6514:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   6515:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   6516:                                         if (@{$cancreate{'statustocreate'}} == 0) {
                   6517:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6518:                                         }
                   6519:                                     }
                   6520:                                 }
                   6521:                             }
1.43      raeburn  6522:                         }
1.93      raeburn  6523:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  6524:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   6525:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   6526:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   6527:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  6528: 
                   6529:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  6530:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6531:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6532:                                     } 
1.96      raeburn  6533:                                 } elsif (ref($usertypes) eq 'HASH') {
                   6534:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6535:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   6536:                                     } else {
                   6537:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   6538:                                     }
                   6539:                                     $chgtext .= '<ul>';
                   6540:                                     foreach my $case (@{$cancreate{$type}}) {
                   6541:                                         if ($case eq 'default') {
                   6542:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   6543:                                         } else {
                   6544:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  6545:                                         }
                   6546:                                     }
1.100     raeburn  6547:                                     $chgtext .= '</ul>';
                   6548:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                   6549:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                   6550:                                     }
                   6551:                                 }
                   6552:                             } else {
                   6553:                                 if (@{$cancreate{$type}} == 0) {
                   6554:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   6555:                                 } else {
                   6556:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
1.93      raeburn  6557:                                 }
                   6558:                             }
                   6559:                         }
1.43      raeburn  6560:                     } else {
                   6561:                         if ($cancreate{$type} eq 'none') {
                   6562:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   6563:                         } elsif ($cancreate{$type} eq 'any') {
                   6564:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   6565:                         } elsif ($cancreate{$type} eq 'official') {
                   6566:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   6567:                         } elsif ($cancreate{$type} eq 'unofficial') {
                   6568:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   6569:                         }
1.34      raeburn  6570:                     }
                   6571:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  6572:                 }
                   6573:             }
                   6574:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  6575:                 my ($rules,$ruleorder) = 
                   6576:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  6577:                 my $chgtext = '<ul>';
                   6578:                 foreach my $type (@username_rule) {
                   6579:                     if (ref($rules->{$type}) eq 'HASH') {
                   6580:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   6581:                     }
                   6582:                 }
                   6583:                 $chgtext .= '</ul>';
                   6584:                 if (@username_rule > 0) {
                   6585:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   6586:                 } else {
1.28      raeburn  6587:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  6588:                 }
                   6589:             }
1.32      raeburn  6590:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   6591:                 my ($idrules,$idruleorder) = 
                   6592:                     &Apache::lonnet::inst_userrules($dom,'id');
                   6593:                 my $chgtext = '<ul>';
                   6594:                 foreach my $type (@id_rule) {
                   6595:                     if (ref($idrules->{$type}) eq 'HASH') {
                   6596:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   6597:                     }
                   6598:                 }
                   6599:                 $chgtext .= '</ul>';
                   6600:                 if (@id_rule > 0) {
                   6601:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   6602:                 } else {
                   6603:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   6604:                 }
                   6605:             }
1.43      raeburn  6606:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   6607:                 my ($emailrules,$emailruleorder) =
                   6608:                     &Apache::lonnet::inst_userrules($dom,'email');
                   6609:                 my $chgtext = '<ul>';
                   6610:                 foreach my $type (@email_rule) {
                   6611:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   6612:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   6613:                     }
                   6614:                 }
                   6615:                 $chgtext .= '</ul>';
                   6616:                 if (@email_rule > 0) {
                   6617:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                   6618:                 } else {
                   6619:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                   6620:                 }
                   6621:             }
                   6622: 
1.28      raeburn  6623:             my %authname = &authtype_names();
                   6624:             my %context_title = &context_names();
                   6625:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   6626:                 my $chgtext = '<ul>';
                   6627:                 foreach my $type (@{$changes{'authtypes'}}) {
                   6628:                     my @allowed;
                   6629:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   6630:                     foreach my $auth (@authtypes) {
                   6631:                         if ($authhash{$type}{$auth}) {
                   6632:                             push(@allowed,$authname{$auth});
                   6633:                         }
                   6634:                     }
1.43      raeburn  6635:                     if (@allowed > 0) {
                   6636:                         $chgtext .= join(', ',@allowed).'</li>';
                   6637:                     } else {
                   6638:                         $chgtext .= &mt('none').'</li>';
                   6639:                     }
1.28      raeburn  6640:                 }
                   6641:                 $chgtext .= '</ul>';
                   6642:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   6643:                 $resulttext .= '</li>';
                   6644:             }
1.27      raeburn  6645:             $resulttext .= '</ul>';
                   6646:         } else {
1.28      raeburn  6647:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  6648:         }
                   6649:     } else {
                   6650:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  6651:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6652:     }
1.43      raeburn  6653:     if ($warningmsg ne '') {
                   6654:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   6655:     }
1.23      raeburn  6656:     return $resulttext;
                   6657: }
                   6658: 
1.33      raeburn  6659: sub modify_usermodification {
                   6660:     my ($dom,%domconfig) = @_;
                   6661:     my ($resulttext,%curr_usermodification,%changes);
                   6662:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   6663:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   6664:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   6665:         }
                   6666:     }
1.63      raeburn  6667:     my @contexts = ('author','course','selfcreate');
1.33      raeburn  6668:     my %context_title = (
                   6669:                            author => 'In author context',
                   6670:                            course => 'In course context',
1.63      raeburn  6671:                            selfcreate => 'When self creating account', 
1.33      raeburn  6672:                         );
                   6673:     my @fields = ('lastname','firstname','middlename','generation',
                   6674:                   'permanentemail','id');
                   6675:     my %roles = (
                   6676:                   author => ['ca','aa'],
                   6677:                   course => ['st','ep','ta','in','cr'],
                   6678:                 );
1.63      raeburn  6679:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   6680:     if (ref($types) eq 'ARRAY') {
                   6681:         push(@{$types},'default');
                   6682:         $usertypes->{'default'} = $othertitle;
                   6683:     }
                   6684:     $roles{'selfcreate'} = $types;  
1.33      raeburn  6685:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6686:     my %modifyhash;
                   6687:     foreach my $context (@contexts) {
                   6688:         foreach my $role (@{$roles{$context}}) {
                   6689:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   6690:             foreach my $item (@fields) {
                   6691:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   6692:                     $modifyhash{$context}{$role}{$item} = 1;
                   6693:                 } else {
                   6694:                     $modifyhash{$context}{$role}{$item} = 0;
                   6695:                 }
                   6696:             }
                   6697:         }
                   6698:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   6699:             foreach my $role (@{$roles{$context}}) {
                   6700:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   6701:                     foreach my $field (@fields) {
                   6702:                         if ($modifyhash{$context}{$role}{$field} ne 
                   6703:                                 $curr_usermodification{$context}{$role}{$field}) {
                   6704:                             push(@{$changes{$context}},$role);
                   6705:                             last;
                   6706:                         }
                   6707:                     }
                   6708:                 }
                   6709:             }
                   6710:         } else {
                   6711:             foreach my $context (@contexts) {
                   6712:                 foreach my $role (@{$roles{$context}}) {
                   6713:                     push(@{$changes{$context}},$role);
                   6714:                 }
                   6715:             }
                   6716:         }
                   6717:     }
                   6718:     my %usermodification_hash =  (
                   6719:                                    usermodification => \%modifyhash,
                   6720:                                  );
                   6721:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   6722:                                              \%usermodification_hash,$dom);
                   6723:     if ($putresult eq 'ok') {
                   6724:         if (keys(%changes) > 0) {
                   6725:             $resulttext = &mt('Changes made: ').'<ul>';
                   6726:             foreach my $context (@contexts) {
                   6727:                 if (ref($changes{$context}) eq 'ARRAY') {
                   6728:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   6729:                     if (ref($changes{$context}) eq 'ARRAY') {
                   6730:                         foreach my $role (@{$changes{$context}}) {
                   6731:                             my $rolename;
1.63      raeburn  6732:                             if ($context eq 'selfcreate') {
                   6733:                                 $rolename = $role;
                   6734:                                 if (ref($usertypes) eq 'HASH') {
                   6735:                                     if ($usertypes->{$role} ne '') {
                   6736:                                         $rolename = $usertypes->{$role};
                   6737:                                     }
                   6738:                                 }
1.33      raeburn  6739:                             } else {
1.63      raeburn  6740:                                 if ($role eq 'cr') {
                   6741:                                     $rolename = &mt('Custom');
                   6742:                                 } else {
                   6743:                                     $rolename = &Apache::lonnet::plaintext($role);
                   6744:                                 }
1.33      raeburn  6745:                             }
                   6746:                             my @modifiable;
1.63      raeburn  6747:                             if ($context eq 'selfcreate') {
1.126     bisitz   6748:                                 $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): ');
1.63      raeburn  6749:                             } else {
                   6750:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   6751:                             }
1.33      raeburn  6752:                             foreach my $field (@fields) {
                   6753:                                 if ($modifyhash{$context}{$role}{$field}) {
                   6754:                                     push(@modifiable,$fieldtitles{$field});
                   6755:                                 }
                   6756:                             }
                   6757:                             if (@modifiable > 0) {
                   6758:                                 $resulttext .= join(', ',@modifiable);
                   6759:                             } else {
                   6760:                                 $resulttext .= &mt('none'); 
                   6761:                             }
                   6762:                             $resulttext .= '</li>';
                   6763:                         }
                   6764:                         $resulttext .= '</ul></li>';
                   6765:                     }
                   6766:                 }
                   6767:             }
                   6768:             $resulttext .= '</ul>';
                   6769:         } else {
                   6770:             $resulttext = &mt('No changes made to user modification settings');
                   6771:         }
                   6772:     } else {
                   6773:         $resulttext = '<span class="LC_error">'.
                   6774:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6775:     }
                   6776:     return $resulttext;
                   6777: }
                   6778: 
1.43      raeburn  6779: sub modify_defaults {
                   6780:     my ($dom,$r) = @_;
                   6781:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
                   6782:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  6783:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  6784:     my @authtypes = ('internal','krb4','krb5','localauth');
                   6785:     foreach my $item (@items) {
                   6786:         $newvalues{$item} = $env{'form.'.$item};
                   6787:         if ($item eq 'auth_def') {
                   6788:             if ($newvalues{$item} ne '') {
                   6789:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   6790:                     push(@errors,$item);
                   6791:                 }
                   6792:             }
                   6793:         } elsif ($item eq 'lang_def') {
                   6794:             if ($newvalues{$item} ne '') {
                   6795:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   6796:                     my $langcode = $1;
1.103     raeburn  6797:                     if ($langcode ne 'x_chef') {
                   6798:                         if (code2language($langcode) eq '') {
                   6799:                             push(@errors,$item);
                   6800:                         }
1.43      raeburn  6801:                     }
                   6802:                 } else {
                   6803:                     push(@errors,$item);
                   6804:                 }
                   6805:             }
1.54      raeburn  6806:         } elsif ($item eq 'timezone_def') {
                   6807:             if ($newvalues{$item} ne '') {
1.62      raeburn  6808:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  6809:                     push(@errors,$item);   
                   6810:                 }
                   6811:             }
1.68      raeburn  6812:         } elsif ($item eq 'datelocale_def') {
                   6813:             if ($newvalues{$item} ne '') {
                   6814:                 my @datelocale_ids = DateTime::Locale->ids();
                   6815:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   6816:                     push(@errors,$item);
                   6817:                 }
                   6818:             }
1.141     raeburn  6819:         } elsif ($item eq 'portal_def') {
                   6820:             if ($newvalues{$item} ne '') {
                   6821:                 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])\/?$/) {
                   6822:                     push(@errors,$item);
                   6823:                 }
                   6824:             }
1.43      raeburn  6825:         }
                   6826:         if (grep(/^\Q$item\E$/,@errors)) {
                   6827:             $newvalues{$item} = $domdefaults{$item};
                   6828:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   6829:             $changes{$item} = 1;
                   6830:         }
1.72      raeburn  6831:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  6832:     }
                   6833:     my %defaults_hash = (
1.72      raeburn  6834:                          defaults => \%newvalues,
                   6835:                         );
1.43      raeburn  6836:     my $title = &defaults_titles();
                   6837:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   6838:                                              $dom);
                   6839:     if ($putresult eq 'ok') {
                   6840:         if (keys(%changes) > 0) {
                   6841:             $resulttext = &mt('Changes made:').'<ul>';
                   6842:             my $version = $r->dir_config('lonVersion');
                   6843:             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";
                   6844:             foreach my $item (sort(keys(%changes))) {
                   6845:                 my $value = $env{'form.'.$item};
                   6846:                 if ($value eq '') {
                   6847:                     $value = &mt('none');
                   6848:                 } elsif ($item eq 'auth_def') {
                   6849:                     my %authnames = &authtype_names();
                   6850:                     my %shortauth = (
                   6851:                              internal => 'int',
                   6852:                              krb4 => 'krb4',
                   6853:                              krb5 => 'krb5',
                   6854:                              localauth  => 'loc',
                   6855:                     );
                   6856:                     $value = $authnames{$shortauth{$value}};
                   6857:                 }
                   6858:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   6859:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   6860:             }
                   6861:             $resulttext .= '</ul>';
                   6862:             $mailmsgtext .= "\n";
                   6863:             my $cachetime = 24*60*60;
1.72      raeburn  6864:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68      raeburn  6865:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54      raeburn  6866:                 my $sysmail = $r->dir_config('lonSysEMail');
                   6867:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
                   6868:             }
1.43      raeburn  6869:         } else {
1.54      raeburn  6870:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  6871:         }
                   6872:     } else {
                   6873:         $resulttext = '<span class="LC_error">'.
                   6874:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6875:     }
                   6876:     if (@errors > 0) {
                   6877:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   6878:         foreach my $item (@errors) {
                   6879:             $resulttext .= ' "'.$title->{$item}.'",';
                   6880:         }
                   6881:         $resulttext =~ s/,$//;
                   6882:     }
                   6883:     return $resulttext;
                   6884: }
                   6885: 
1.46      raeburn  6886: sub modify_scantron {
1.48      raeburn  6887:     my ($r,$dom,$confname,%domconfig) = @_;
1.46      raeburn  6888:     my ($resulttext,%confhash,%changes,$errors);
                   6889:     my $custom = 'custom.tab';
                   6890:     my $default = 'default.tab';
                   6891:     my $servadm = $r->dir_config('lonAdmEMail');
                   6892:     my ($configuserok,$author_ok,$switchserver) = 
                   6893:         &config_check($dom,$confname,$servadm);
                   6894:     if ($env{'form.scantronformat.filename'} ne '') {
                   6895:         my $error;
                   6896:         if ($configuserok eq 'ok') {
                   6897:             if ($switchserver) {
1.130     raeburn  6898:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  6899:             } else {
                   6900:                 if ($author_ok eq 'ok') {
                   6901:                     my ($result,$scantronurl) =
                   6902:                         &publishlogo($r,'upload','scantronformat',$dom,
                   6903:                                      $confname,'scantron','','',$custom);
                   6904:                     if ($result eq 'ok') {
                   6905:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  6906:                         $changes{'scantronformat'} = 1;
1.46      raeburn  6907:                     } else {
                   6908:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   6909:                     }
                   6910:                 } else {
                   6911:                     $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);
                   6912:                 }
                   6913:             }
                   6914:         } else {
                   6915:             $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);
                   6916:         }
                   6917:         if ($error) {
                   6918:             &Apache::lonnet::logthis($error);
                   6919:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   6920:         }
                   6921:     }
1.48      raeburn  6922:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   6923:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   6924:             if ($env{'form.scantronformat_del'}) {
                   6925:                 $confhash{'scantron'}{'scantronformat'} = '';
                   6926:                 $changes{'scantronformat'} = 1;
1.46      raeburn  6927:             }
                   6928:         }
                   6929:     }
                   6930:     if (keys(%confhash) > 0) {
                   6931:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   6932:                                                  $dom);
                   6933:         if ($putresult eq 'ok') {
                   6934:             if (keys(%changes) > 0) {
1.48      raeburn  6935:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   6936:                     $resulttext = &mt('Changes made:').'<ul>';
                   6937:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  6938:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  6939:                     } else {
1.130     raeburn  6940:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  6941:                     }
1.48      raeburn  6942:                     $resulttext .= '</ul>';
                   6943:                 } else {
1.130     raeburn  6944:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  6945:                 }
                   6946:                 $resulttext .= '</ul>';
                   6947:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   6948:             } else {
1.130     raeburn  6949:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  6950:             }
                   6951:         } else {
                   6952:             $resulttext = '<span class="LC_error">'.
                   6953:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   6954:         }
                   6955:     } else {
1.130     raeburn  6956:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  6957:     }
                   6958:     if ($errors) {
                   6959:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   6960:                        $errors.'</ul>';
                   6961:     }
                   6962:     return $resulttext;
                   6963: }
                   6964: 
1.48      raeburn  6965: sub modify_coursecategories {
                   6966:     my ($dom,%domconfig) = @_;
1.57      raeburn  6967:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   6968:         $cathash);
1.48      raeburn  6969:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  6970:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  6971:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   6972:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   6973:             $changes{'togglecats'} = 1;
                   6974:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   6975:         }
                   6976:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   6977:             $changes{'categorize'} = 1;
                   6978:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   6979:         }
1.120     raeburn  6980:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   6981:             $changes{'togglecatscomm'} = 1;
                   6982:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   6983:         }
                   6984:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   6985:             $changes{'categorizecomm'} = 1;
                   6986:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   6987:         }
1.57      raeburn  6988:     } else {
                   6989:         $changes{'togglecats'} = 1;
                   6990:         $changes{'categorize'} = 1;
1.124     raeburn  6991:         $changes{'togglecatscomm'} = 1;
                   6992:         $changes{'categorizecomm'} = 1;
1.87      raeburn  6993:         $domconfig{'coursecategories'} = {
                   6994:                                              togglecats => $env{'form.togglecats'},
                   6995:                                              categorize => $env{'form.categorize'},
1.124     raeburn  6996:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   6997:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  6998:                                          };
1.57      raeburn  6999:     }
                   7000:     if (ref($cathash) eq 'HASH') {
                   7001:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  7002:             push (@deletecategory,'instcode::0');
                   7003:         }
1.120     raeburn  7004:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   7005:             push(@deletecategory,'communities::0');
                   7006:         }
1.48      raeburn  7007:     }
1.57      raeburn  7008:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   7009:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  7010:         if (@deletecategory > 0) {
                   7011:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  7012:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  7013:             foreach my $item (@deletecategory) {
1.57      raeburn  7014:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   7015:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  7016:                     $deletions{$item} = 1;
1.57      raeburn  7017:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  7018:                 }
                   7019:             }
                   7020:         }
1.57      raeburn  7021:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  7022:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  7023:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  7024:                 $reorderings{$item} = 1;
1.57      raeburn  7025:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  7026:             }
                   7027:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   7028:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   7029:                 my $newdepth = $depth+1;
                   7030:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7031:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  7032:                 $adds{$newitem} = 1; 
                   7033:             }
                   7034:             if ($env{'form.subcat_'.$item} ne '') {
                   7035:                 my $newcat = $env{'form.subcat_'.$item};
                   7036:                 my $newdepth = $depth+1;
                   7037:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7038:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  7039:                 $adds{$newitem} = 1;
                   7040:             }
                   7041:         }
                   7042:     }
                   7043:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  7044:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  7045:             my $newitem = 'instcode::0';
1.57      raeburn  7046:             if ($cathash->{$newitem} eq '') {  
                   7047:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7048:                 $adds{$newitem} = 1;
                   7049:             }
                   7050:         } else {
                   7051:             my $newitem = 'instcode::0';
1.57      raeburn  7052:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7053:             $adds{$newitem} = 1;
                   7054:         }
                   7055:     }
1.120     raeburn  7056:     if ($env{'form.communities'} eq '1') {
                   7057:         if (ref($cathash) eq 'HASH') {
                   7058:             my $newitem = 'communities::0';
                   7059:             if ($cathash->{$newitem} eq '') {
                   7060:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7061:                 $adds{$newitem} = 1;
                   7062:             }
                   7063:         } else {
                   7064:             my $newitem = 'communities::0';
                   7065:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7066:             $adds{$newitem} = 1;
                   7067:         }
                   7068:     }
1.48      raeburn  7069:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  7070:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   7071:             ($env{'form.addcategory_name'} ne 'communities')) {
                   7072:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   7073:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   7074:             $adds{$newitem} = 1;
                   7075:         }
1.48      raeburn  7076:     }
1.57      raeburn  7077:     my $putresult;
1.48      raeburn  7078:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7079:         if (keys(%deletions) > 0) {
                   7080:             foreach my $key (keys(%deletions)) {
                   7081:                 if ($predelallitems{$key} ne '') {
                   7082:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   7083:                 }
                   7084:             }
                   7085:         }
                   7086:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  7087:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  7088:         if (ref($chkcats[0]) eq 'ARRAY') {
                   7089:             my $depth = 0;
                   7090:             my $chg = 0;
                   7091:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   7092:                 my $name = $chkcats[0][$i];
                   7093:                 my $item;
                   7094:                 if ($name eq '') {
                   7095:                     $chg ++;
                   7096:                 } else {
                   7097:                     $item = &escape($name).'::0';
                   7098:                     if ($chg) {
1.57      raeburn  7099:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  7100:                     }
                   7101:                     $depth ++; 
1.57      raeburn  7102:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  7103:                     $depth --;
                   7104:                 }
                   7105:             }
                   7106:         }
1.57      raeburn  7107:     }
                   7108:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7109:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  7110:         if ($putresult eq 'ok') {
1.57      raeburn  7111:             my %title = (
1.120     raeburn  7112:                          togglecats     => 'Show/Hide a course in catalog',
                   7113:                          categorize     => 'Assign a category to a course',
                   7114:                          togglecatscomm => 'Show/Hide a community in catalog',
                   7115:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  7116:                         );
                   7117:             my %level = (
1.120     raeburn  7118:                          dom  => 'set in Domain ("Modify Course/Community")',
                   7119:                          crs  => 'set in Course ("Course Configuration")',
                   7120:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  7121:                         );
1.48      raeburn  7122:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  7123:             if ($changes{'togglecats'}) {
                   7124:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   7125:             }
                   7126:             if ($changes{'categorize'}) {
                   7127:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  7128:             }
1.120     raeburn  7129:             if ($changes{'togglecatscomm'}) {
                   7130:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   7131:             }
                   7132:             if ($changes{'categorizecomm'}) {
                   7133:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   7134:             }
1.57      raeburn  7135:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7136:                 my $cathash;
                   7137:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   7138:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   7139:                 } else {
                   7140:                     $cathash = {};
                   7141:                 } 
                   7142:                 my (@cats,@trails,%allitems);
                   7143:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   7144:                 if (keys(%deletions) > 0) {
                   7145:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   7146:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   7147:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   7148:                     }
                   7149:                     $resulttext .= '</ul></li>';
                   7150:                 }
                   7151:                 if (keys(%reorderings) > 0) {
                   7152:                     my %sort_by_trail;
                   7153:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   7154:                     foreach my $key (keys(%reorderings)) {
                   7155:                         if ($allitems{$key} ne '') {
                   7156:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7157:                         }
1.48      raeburn  7158:                     }
1.57      raeburn  7159:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7160:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   7161:                     }
                   7162:                     $resulttext .= '</ul></li>';
1.48      raeburn  7163:                 }
1.57      raeburn  7164:                 if (keys(%adds) > 0) {
                   7165:                     my %sort_by_trail;
                   7166:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   7167:                     foreach my $key (keys(%adds)) {
                   7168:                         if ($allitems{$key} ne '') {
                   7169:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7170:                         }
                   7171:                     }
                   7172:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7173:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  7174:                     }
1.57      raeburn  7175:                     $resulttext .= '</ul></li>';
1.48      raeburn  7176:                 }
                   7177:             }
                   7178:             $resulttext .= '</ul>';
                   7179:         } else {
                   7180:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  7181:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  7182:         }
                   7183:     } else {
1.120     raeburn  7184:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  7185:     }
                   7186:     return $resulttext;
                   7187: }
                   7188: 
1.69      raeburn  7189: sub modify_serverstatuses {
                   7190:     my ($dom,%domconfig) = @_;
                   7191:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   7192:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   7193:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   7194:     }
                   7195:     my @pages = &serverstatus_pages();
                   7196:     foreach my $type (@pages) {
                   7197:         $newserverstatus{$type}{'namedusers'} = '';
                   7198:         $newserverstatus{$type}{'machines'} = '';
                   7199:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   7200:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   7201:             my @okusers;
                   7202:             foreach my $user (@users) {
                   7203:                 my ($uname,$udom) = split(/:/,$user);
                   7204:                 if (($udom =~ /^$match_domain$/) &&   
                   7205:                     (&Apache::lonnet::domain($udom)) &&
                   7206:                     ($uname =~ /^$match_username$/)) {
                   7207:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   7208:                         push(@okusers,$user);
                   7209:                     }
                   7210:                 }
                   7211:             }
                   7212:             if (@okusers > 0) {
                   7213:                  @okusers = sort(@okusers);
                   7214:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   7215:             }
                   7216:         }
                   7217:         if (defined($env{'form.'.$type.'_machines'})) {
                   7218:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   7219:             my @okmachines;
                   7220:             foreach my $ip (@machines) {
                   7221:                 my @parts = split(/\./,$ip);
                   7222:                 next if (@parts < 4);
                   7223:                 my $badip = 0;
                   7224:                 for (my $i=0; $i<4; $i++) {
                   7225:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   7226:                         $badip = 1;
                   7227:                         last;
                   7228:                     }
                   7229:                 }
                   7230:                 if (!$badip) {
                   7231:                     push(@okmachines,$ip);     
                   7232:                 }
                   7233:             }
                   7234:             @okmachines = sort(@okmachines);
                   7235:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   7236:         }
                   7237:     }
                   7238:     my %serverstatushash =  (
                   7239:                                 serverstatuses => \%newserverstatus,
                   7240:                             );
                   7241:     foreach my $type (@pages) {
1.83      raeburn  7242:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  7243:             my (@current,@new);
1.83      raeburn  7244:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  7245:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   7246:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   7247:                 }
                   7248:             }
                   7249:             if ($newserverstatus{$type}{$setting} ne '') {
                   7250:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  7251:             }
                   7252:             if (@current > 0) {
                   7253:                 if (@new > 0) {
                   7254:                     foreach my $item (@current) {
                   7255:                         if (!grep(/^\Q$item\E$/,@new)) {
                   7256:                             $changes{$type}{$setting} = 1;
1.82      raeburn  7257:                             last;
                   7258:                         }
                   7259:                     }
1.84      raeburn  7260:                     foreach my $item (@new) {
                   7261:                         if (!grep(/^\Q$item\E$/,@current)) {
                   7262:                             $changes{$type}{$setting} = 1;
                   7263:                             last;
1.82      raeburn  7264:                         }
                   7265:                     }
                   7266:                 } else {
1.83      raeburn  7267:                     $changes{$type}{$setting} = 1;
1.69      raeburn  7268:                 }
1.83      raeburn  7269:             } elsif (@new > 0) {
                   7270:                 $changes{$type}{$setting} = 1;
1.69      raeburn  7271:             }
                   7272:         }
                   7273:     }
                   7274:     if (keys(%changes) > 0) {
1.81      raeburn  7275:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7276:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   7277:                                                  \%serverstatushash,$dom);
                   7278:         if ($putresult eq 'ok') {
                   7279:             $resulttext .= &mt('Changes made:').'<ul>';
                   7280:             foreach my $type (@pages) {
1.84      raeburn  7281:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  7282:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  7283:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  7284:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   7285:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   7286:                         } else {
                   7287:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   7288:                         }
1.84      raeburn  7289:                     }
                   7290:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  7291:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   7292:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   7293:                         } else {
                   7294:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   7295:                         }
                   7296: 
                   7297:                     }
                   7298:                     $resulttext .= '</ul></li>';
                   7299:                 }
                   7300:             }
                   7301:             $resulttext .= '</ul>';
                   7302:         } else {
                   7303:             $resulttext = '<span class="LC_error">'.
                   7304:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   7305: 
                   7306:         }
                   7307:     } else {
                   7308:         $resulttext = &mt('No changes made to access to server status pages');
                   7309:     }
                   7310:     return $resulttext;
                   7311: }
                   7312: 
1.118     jms      7313: sub modify_helpsettings {
1.122     jms      7314:     my ($r,$dom,$confname,%domconfig) = @_;
1.118     jms      7315:  	my ($resulttext,$errors,%changes,%helphash);
                   7316:  	
1.122     jms      7317:  	my $customhelpfile  = $env{'form.loginhelpurl.filename'};
                   7318:     my $defaulthelpfile = 'defaulthelp.html';
                   7319:  	my $servadm = $r->dir_config('lonAdmEMail');
                   7320:     my ($configuserok,$author_ok,$switchserver) = 
                   7321:         &config_check($dom,$confname,$servadm);
                   7322:  	
1.118     jms      7323:  	my %defaultchecked = ('submitbugs'	=> 'on');
                   7324:  	my @offon = ('off','on');
1.122     jms      7325:     my %title = ( submitbugs     => 'Display link for users to submit a bug', 
                   7326:     			  loginhelpurl  => 'Unauthenticated login help page set to custom file');
                   7327:     			  
1.118     jms      7328:     my @toggles = ('submitbugs');
                   7329: 
                   7330:     $helphash{'helpsettings'} = {};
                   7331:     
                   7332:     if (ref($domconfig{'helpsettings'}) ne 'HASH') {
                   7333:         if ($domconfig{'helpsettings'} eq '') {
                   7334:             $domconfig{'helpsettings'} = {};
                   7335:         }
                   7336:     }
                   7337:     
                   7338:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   7339:     	
                   7340:         foreach my $item (@toggles) {
                   7341:         	
                   7342: 			if ($defaultchecked{$item} eq 'on') { 
                   7343: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
                   7344: 					 ($env{'form.'.$item} eq '0')) {
                   7345: 					$changes{$item} = 1;
                   7346: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7347: 					$changes{$item} = 1;
                   7348: 				}
                   7349: 			} elsif ($defaultchecked{$item} eq 'off') {
                   7350: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
                   7351: 					 ($env{'form.'.$item} eq '1')) {
                   7352: 					$changes{$item} = 1;
                   7353: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7354: 					$changes{$item} = 1;
                   7355: 				}
                   7356: 			}
                   7357: 			$helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122     jms      7358: 		}
                   7359: 		
                   7360: 		if ($customhelpfile ne '') {
                   7361: 			my $error;
                   7362: 			if ($configuserok eq 'ok') {
                   7363: 				if ($switchserver) {
                   7364: 					$error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   7365: 				} else {
                   7366: 					if ($author_ok eq 'ok') {
                   7367: 						my ($result,$loginhelpurl) =
                   7368: 							&publishlogo($r,'upload','loginhelpurl',$dom,
                   7369: 										 $confname,'help','','',$customhelpfile);
                   7370: 						if ($result eq 'ok') {
                   7371: 							$helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
                   7372: 							$changes{'loginhelpurl'} = 1;
                   7373: 						} else {
                   7374: 							$error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
                   7375: 						}
                   7376: 					} else {
                   7377: 						$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].",$customhelpfile,$confname,$dom,$author_ok);
                   7378: 					}
                   7379: 				}
                   7380: 			} else {
                   7381: 				$error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
                   7382: 			}
                   7383: 			if ($error) {
                   7384: 				&Apache::lonnet::logthis($error);
                   7385: 				$errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7386: 			}
                   7387: 		}
                   7388: 		
                   7389:         if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
                   7390:             if ($env{'form.loginhelpurl_del'}) {
                   7391:                 $helphash{'helpsettings'}{'loginhelpurl'} = '';
                   7392:                 $changes{'loginhelpurl'} = 1;
                   7393:             }
                   7394:         }
1.118     jms      7395:     }
                   7396:     
1.123     jms      7397:     
                   7398:     my $putresult;
                   7399:     
                   7400:     if (keys(%changes) > 0) {
                   7401:     	$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
                   7402:     } else {
                   7403:     	$putresult = 'ok';
                   7404:     }
1.118     jms      7405:                                              
                   7406:     if ($putresult eq 'ok') {
                   7407:         if (keys(%changes) > 0) {
                   7408: 			$resulttext = &mt('Changes made:').'<ul>';
                   7409: 			foreach my $item (sort(keys(%changes))) {
                   7410: 				if ($item eq 'submitbugs') {
                   7411: 					$resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   7412: 				}
1.122     jms      7413: 				if ($item eq 'loginhelpurl') {
                   7414: 					if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
                   7415:                         $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
                   7416:                     } else {
                   7417:                         $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
                   7418:                     }
                   7419: 				}
1.118     jms      7420: 			}
                   7421: 			$resulttext .= '</ul>';
                   7422: 		} else {
                   7423: 			$resulttext = &mt('No changes made to help settings');
                   7424: 		}
                   7425:     } else {
                   7426:         $resulttext = '<span class="LC_error">'.
                   7427: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
                   7428:     }
                   7429:     if ($errors) {
                   7430:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7431:                        $errors.'</ul>';
                   7432:     }
                   7433:     return $resulttext;
                   7434: }
                   7435: 
1.121     raeburn  7436: sub modify_coursedefaults {
                   7437:     my ($dom,%domconfig) = @_;
                   7438:     my ($resulttext,$errors,%changes,%defaultshash);
                   7439:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   7440:     my @offon = ('off','on');
                   7441:     my @toggles = ('canuse_pdfforms');
                   7442: 
                   7443:     $defaultshash{'coursedefaults'} = {};
                   7444: 
                   7445:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   7446:         if ($domconfig{'coursedefaults'} eq '') {
                   7447:             $domconfig{'coursedefaults'} = {};
                   7448:         }
                   7449:     }
                   7450: 
                   7451:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   7452:         foreach my $item (@toggles) {
                   7453:             if ($defaultchecked{$item} eq 'on') {
                   7454:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7455:                     ($env{'form.'.$item} eq '0')) {
                   7456:                     $changes{$item} = 1;
                   7457:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
                   7458:                     $changes{$item} = 1;
                   7459:                 }
                   7460:             } elsif ($defaultchecked{$item} eq 'off') {
                   7461:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7462:                     ($env{'form.'.$item} eq '1')) {
                   7463:                     $changes{$item} = 1;
                   7464:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   7465:                     $changes{$item} = 1;
                   7466:                 }
                   7467:             }
                   7468:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   7469:         }
1.139     raeburn  7470:         my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
                   7471:         my $newdefresponder = $env{'form.anonsurvey_threshold'};
                   7472:         $newdefresponder =~ s/\D//g;
                   7473:         if ($newdefresponder eq '' || $newdefresponder < 1) {
                   7474:             $newdefresponder = 1;
                   7475:         }
                   7476:         $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
                   7477:         if ($currdefresponder ne $newdefresponder) {
                   7478:             unless ($currdefresponder eq '' && $newdefresponder == 10) {
                   7479:                 $changes{'anonsurvey_threshold'} = 1;
                   7480:             }
                   7481:         }
1.121     raeburn  7482:     }
                   7483:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7484:                                              $dom);
                   7485:     if ($putresult eq 'ok') {
                   7486:         if (keys(%changes) > 0) {
                   7487:             if ($changes{'canuse_pdfforms'}) {
                   7488:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7489:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   7490:                 my $cachetime = 24*60*60;
                   7491:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   7492:             }
                   7493:             $resulttext = &mt('Changes made:').'<ul>';
                   7494:             foreach my $item (sort(keys(%changes))) {
                   7495:                 if ($item eq 'canuse_pdfforms') {
                   7496:                     if ($env{'form.'.$item} eq '1') {
                   7497:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   7498:                     } else {
                   7499:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   7500:                     }
1.139     raeburn  7501:                 } elsif ($item eq 'anonsurvey_threshold') {
                   7502:                         $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140     raeburn  7503:                 }
1.121     raeburn  7504:             }
                   7505:             $resulttext .= '</ul>';
                   7506:         } else {
                   7507:             $resulttext = &mt('No changes made to course defaults');
                   7508:         }
                   7509:     } else {
                   7510:         $resulttext = '<span class="LC_error">'.
                   7511:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7512:     }
                   7513:     return $resulttext;
                   7514: }
                   7515: 
1.137     raeburn  7516: sub modify_usersessions {
                   7517:     my ($dom,%domconfig) = @_;
1.145     raeburn  7518:     my @hostingtypes = ('version','excludedomain','includedomain');
                   7519:     my @offloadtypes = ('primary','default');
                   7520:     my %types = (
                   7521:                   remote => \@hostingtypes,
                   7522:                   hosted => \@hostingtypes,
                   7523:                   spares => \@offloadtypes,
                   7524:                 );
                   7525:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  7526:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  7527:     my (%by_ip,%by_location,@intdoms);
                   7528:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   7529:     my @locations = sort(keys(%by_location));
1.137     raeburn  7530:     my (%defaultshash,%changes);
                   7531:     foreach my $prefix (@prefixes) {
                   7532:         $defaultshash{'usersessions'}{$prefix} = {};
                   7533:     }
                   7534:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7535:     my $resulttext;
1.138     raeburn  7536:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  7537:     foreach my $prefix (@prefixes) {
1.145     raeburn  7538:         next if ($prefix eq 'spares');
                   7539:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  7540:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   7541:             if ($type eq 'version') {
                   7542:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   7543:                 my $okvalue;
                   7544:                 if ($value ne '') {
                   7545:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   7546:                         $okvalue = $value;
                   7547:                     }
                   7548:                 }
                   7549:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7550:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7551:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   7552:                             if ($inuse == 0) {
                   7553:                                 $changes{$prefix}{$type} = 1;
                   7554:                             } else {
                   7555:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   7556:                                     $changes{$prefix}{$type} = 1;
                   7557:                                 }
                   7558:                                 if ($okvalue ne '') {
                   7559:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7560:                                 } 
                   7561:                             }
                   7562:                         } else {
                   7563:                             if (($inuse == 1) && ($okvalue ne '')) {
                   7564:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7565:                                 $changes{$prefix}{$type} = 1;
                   7566:                             }
                   7567:                         }
                   7568:                     } else {
                   7569:                         if (($inuse == 1) && ($okvalue ne '')) {
                   7570:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7571:                             $changes{$prefix}{$type} = 1;
                   7572:                         }
                   7573:                     }
                   7574:                 } else {
                   7575:                     if (($inuse == 1) && ($okvalue ne '')) {
                   7576:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7577:                         $changes{$prefix}{$type} = 1;
                   7578:                     }
                   7579:                 }
                   7580:             } else {
                   7581:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   7582:                 my @okvals;
                   7583:                 foreach my $val (@vals) {
1.138     raeburn  7584:                     if ($val =~ /:/) {
                   7585:                         my @items = split(/:/,$val);
                   7586:                         foreach my $item (@items) {
                   7587:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   7588:                                 push(@okvals,$item);
                   7589:                             }
                   7590:                         }
                   7591:                     } else {
                   7592:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   7593:                             push(@okvals,$val);
                   7594:                         }
1.137     raeburn  7595:                     }
                   7596:                 }
                   7597:                 @okvals = sort(@okvals);
                   7598:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7599:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7600:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   7601:                             if ($inuse == 0) {
                   7602:                                 $changes{$prefix}{$type} = 1; 
                   7603:                             } else {
                   7604:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7605:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   7606:                                 if (@changed > 0) {
                   7607:                                     $changes{$prefix}{$type} = 1;
                   7608:                                 }
                   7609:                             }
                   7610:                         } else {
                   7611:                             if ($inuse == 1) {
                   7612:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7613:                                 $changes{$prefix}{$type} = 1;
                   7614:                             }
                   7615:                         } 
                   7616:                     } else {
                   7617:                         if ($inuse == 1) {
                   7618:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7619:                             $changes{$prefix}{$type} = 1;
                   7620:                         }
                   7621:                     }
                   7622:                 } else {
                   7623:                     if ($inuse == 1) {
                   7624:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7625:                         $changes{$prefix}{$type} = 1;
                   7626:                     }
                   7627:                 }
                   7628:             }
                   7629:         }
                   7630:     }
1.145     raeburn  7631: 
                   7632:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  7633:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  7634:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   7635:     my $savespares;
                   7636: 
                   7637:     foreach my $lonhost (sort(keys(%servers))) {
                   7638:         my $serverhomeID =
                   7639:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  7640:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  7641:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   7642:         my %spareschg;
                   7643:         foreach my $type (@{$types{'spares'}}) {
                   7644:             my @okspares;
                   7645:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   7646:             foreach my $server (@checked) {
1.152     raeburn  7647:                 if (&Apache::lonnet::hostname($server) ne '') {
                   7648:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   7649:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   7650:                             push(@okspares,$server);
                   7651:                         }
1.145     raeburn  7652:                     }
                   7653:                 }
                   7654:             }
                   7655:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   7656:             my $newspare;
1.152     raeburn  7657:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   7658:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  7659:                     $newspare = $new;
                   7660:                 }
                   7661:             }
1.152     raeburn  7662:             my @spares;
                   7663:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   7664:                 @spares = sort(@okspares,$newspare);
                   7665:             } else {
                   7666:                 @spares = sort(@okspares);
                   7667:             }
                   7668:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  7669:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   7670:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  7671:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  7672:                     if (@diffs > 0) {
                   7673:                         $spareschg{$type} = 1;
                   7674:                     }
                   7675:                 }
                   7676:             }
                   7677:         }
                   7678:         if (keys(%spareschg) > 0) {
                   7679:             $changes{'spares'}{$lonhost} = \%spareschg;
                   7680:         }
                   7681:     }
                   7682: 
                   7683:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7684:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   7685:             if (ref($changes{'spares'}) eq 'HASH') {
                   7686:                 if (keys(%{$changes{'spares'}}) > 0) {
                   7687:                     $savespares = 1;
                   7688:                 }
                   7689:             }
                   7690:         } else {
                   7691:             $savespares = 1;
                   7692:         }
                   7693:     }
                   7694: 
1.147     raeburn  7695:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   7696:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  7697:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7698:                                                  $dom);
                   7699:         if ($putresult eq 'ok') {
                   7700:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   7701:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   7702:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   7703:                 }
                   7704:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   7705:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   7706:                 }
                   7707:             }
                   7708:             my $cachetime = 24*60*60;
                   7709:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147     raeburn  7710:             if (keys(%changes) > 0) {
                   7711:                 my %lt = &usersession_titles();
                   7712:                 $resulttext = &mt('Changes made:').'<ul>';
                   7713:                 foreach my $prefix (@prefixes) {
                   7714:                     if (ref($changes{$prefix}) eq 'HASH') {
                   7715:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   7716:                         if ($prefix eq 'spares') {
                   7717:                             if (ref($changes{$prefix}) eq 'HASH') {
                   7718:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   7719:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  7720:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
                   7721:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147     raeburn  7722:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   7723:                                         foreach my $type (@{$types{$prefix}}) {
                   7724:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   7725:                                                 my $offloadto = &mt('None');
                   7726:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   7727:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   7728:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   7729:                                                     }
1.145     raeburn  7730:                                                 }
1.147     raeburn  7731:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  7732:                                             }
1.137     raeburn  7733:                                         }
                   7734:                                     }
1.147     raeburn  7735:                                     $resulttext .= '</li>';
1.137     raeburn  7736:                                 }
                   7737:                             }
1.147     raeburn  7738:                         } else {
                   7739:                             foreach my $type (@{$types{$prefix}}) {
                   7740:                                 if (defined($changes{$prefix}{$type})) {
                   7741:                                     my $newvalue;
                   7742:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   7743:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   7744:                                             if ($type eq 'version') {
                   7745:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   7746:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   7747:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   7748:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   7749:                                                 }
1.145     raeburn  7750:                                             }
                   7751:                                         }
                   7752:                                     }
1.147     raeburn  7753:                                     if ($newvalue eq '') {
                   7754:                                         if ($type eq 'version') {
                   7755:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   7756:                                         } else {
                   7757:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   7758:                                         }
1.145     raeburn  7759:                                     } else {
1.147     raeburn  7760:                                         if ($type eq 'version') {
                   7761:                                             $newvalue .= ' '.&mt('(or later)'); 
                   7762:                                         }
                   7763:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  7764:                                     }
1.137     raeburn  7765:                                 }
                   7766:                             }
                   7767:                         }
1.147     raeburn  7768:                         $resulttext .= '</ul>';
1.137     raeburn  7769:                     }
                   7770:                 }
1.147     raeburn  7771:                 $resulttext .= '</ul>';
                   7772:             } else {
                   7773:                 $resulttext = $nochgmsg;
1.137     raeburn  7774:             }
                   7775:         } else {
                   7776:             $resulttext = '<span class="LC_error">'.
                   7777:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   7778:         }
                   7779:     } else {
1.147     raeburn  7780:         $resulttext = $nochgmsg;
1.137     raeburn  7781:     }
                   7782:     return $resulttext;
                   7783: }
                   7784: 
1.150     raeburn  7785: sub modify_loadbalancing {
                   7786:     my ($dom,%domconfig) = @_;
                   7787:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7788:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7789:     my ($othertitle,$usertypes,$types) =
                   7790:         &Apache::loncommon::sorted_inst_types($dom);
                   7791:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   7792:     my @sparestypes = ('primary','default');
                   7793:     my %typetitles = &sparestype_titles();
                   7794:     my $resulttext;
                   7795:     if (keys(%servers) > 1) {
                   7796:         my ($currbalancer,$currtargets,$currrules);
                   7797:         if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   7798:             $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
                   7799:             $currtargets = $domconfig{'loadbalancing'}{'targets'};
                   7800:             $currrules = $domconfig{'loadbalancing'}{'rules'};
                   7801:         } else {
                   7802:             ($currbalancer,$currtargets) = 
                   7803:                 &Apache::lonnet::get_lonbalancer_config(\%servers);
                   7804:         }
                   7805:         my ($saveloadbalancing,%defaultshash,%changes);
                   7806:         my ($alltypes,$othertypes,$titles) =
                   7807:             &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   7808:         my %ruletitles = &offloadtype_text();
                   7809:         my $balancer = $env{'form.loadbalancing_lonhost'};
                   7810:         if (!$servers{$balancer}) {
                   7811:             undef($balancer);
                   7812:         }
                   7813:         if ($currbalancer ne $balancer) {
                   7814:             $changes{'lonhost'} = 1;
                   7815:         }
                   7816:         $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
                   7817:         if ($balancer ne '') {
                   7818:             unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   7819:                 $saveloadbalancing = 1;
                   7820:             }
                   7821:             foreach my $sparetype (@sparestypes) {
                   7822:                 my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151     raeburn  7823:                 my @offloadto;
1.150     raeburn  7824:                 foreach my $target (@targets) {
                   7825:                     if (($servers{$target}) && ($target ne $balancer)) {
                   7826:                         if ($sparetype eq 'default') {
                   7827:                             if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
                   7828:                                 next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
                   7829:                             }
                   7830:                         }
                   7831:                         unless(grep(/^\Q$target\E$/,@offloadto)) {
                   7832:                             push(@offloadto,$target);
                   7833:                         }
                   7834:                     }
                   7835:                     $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
                   7836:                 }
                   7837:             }
                   7838:         } else {
                   7839:             foreach my $sparetype (@sparestypes) {
                   7840:                 $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
                   7841:             }
                   7842:         }
                   7843:         if (ref($currtargets) eq 'HASH') {
                   7844:             foreach my $sparetype (@sparestypes) {
                   7845:                 if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
                   7846:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
                   7847:                     if (@targetdiffs > 0) {
                   7848:                         $changes{'targets'} = 1;
                   7849:                     }
                   7850:                 } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7851:                     if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7852:                         $changes{'targets'} = 1;
                   7853:                     }
                   7854:                 }
                   7855:             }
                   7856:         } else {
                   7857:             foreach my $sparetype (@sparestypes) {
                   7858:                 if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7859:                     if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7860:                         $changes{'targets'} = 1;  
                   7861:                     }
                   7862:                 }
                   7863:             }  
                   7864:         }
                   7865:         my $ishomedom;
                   7866:         if ($balancer ne '') {
                   7867:             if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   7868:                 $ishomedom = 1;
                   7869:             }
                   7870:         }
                   7871:         if (ref($alltypes) eq 'ARRAY') {
                   7872:             foreach my $type (@{$alltypes}) {
                   7873:                 my $rule;
                   7874:                 if ($balancer ne '') {
                   7875:                     unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
                   7876:                          (!$ishomedom)) {
                   7877:                         $rule = $env{'form.loadbalancing_rules_'.$type};
                   7878:                     }
                   7879:                     if ($rule eq 'specific') {
                   7880:                         $rule = $env{'form.loadbalancing_singleserver_'.$type};
                   7881:                     }
                   7882:                 }
                   7883:                 $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
                   7884:                 if (ref($currrules) eq 'HASH') {
                   7885:                     if ($rule ne $currrules->{$type}) {
                   7886:                         $changes{'rules'}{$type} = 1;
                   7887:                     }
                   7888:                 } elsif ($rule ne '') {
                   7889:                     $changes{'rules'}{$type} = 1;
                   7890:                 }
                   7891:             }
                   7892:         }
                   7893:         my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   7894:         if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   7895:             my $putresult = &Apache::lonnet::put_dom('configuration',
                   7896:                                                      \%defaultshash,$dom);
                   7897:             if ($putresult eq 'ok') {
                   7898:                 if (keys(%changes) > 0) {
                   7899:                     if ($changes{'lonhost'}) {
                   7900:                         if ($currbalancer ne '') {
                   7901:                             &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
                   7902:                         }
                   7903:                         if ($balancer eq '') {
                   7904:                             $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>'; 
                   7905:                         } else {
                   7906:                             &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7907:                             $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
                   7908:                         }
                   7909:                     } else {
                   7910:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7911:                     }
                   7912:                     if (($changes{'targets'}) && ($balancer ne '')) {
                   7913:                         my %offloadstr;
                   7914:                         foreach my $sparetype (@sparestypes) {
                   7915:                             if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7916:                                 if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7917:                                     $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
                   7918:                                 }
                   7919:                             }
                   7920:                         }
                   7921:                         if (keys(%offloadstr) == 0) {
                   7922:                             $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
                   7923:                         } else {
                   7924:                             my $showoffload;
                   7925:                             foreach my $sparetype (@sparestypes) {
                   7926:                                 $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   7927:                                 if (defined($offloadstr{$sparetype})) {
                   7928:                                     $showoffload .= $offloadstr{$sparetype};
                   7929:                                 } else {
                   7930:                                     $showoffload .= &mt('None');
                   7931:                                 }
                   7932:                                 $showoffload .= ('&nbsp;'x3);
                   7933:                             }
                   7934:                             $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
                   7935:                         }
                   7936:                     }
                   7937:                     if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
                   7938:                         if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   7939:                             foreach my $type (@{$alltypes}) {
                   7940:                                 if ($changes{'rules'}{$type}) {
                   7941:                                     my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
                   7942:                                     my $balancetext;
                   7943:                                     if ($rule eq '') {
                   7944:                                         $balancetext =  $ruletitles{'default'};
                   7945:                                     } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
                   7946:                                         $balancetext =  $ruletitles{$rule};
                   7947:                                     } else {
                   7948:                                         $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
                   7949:                                     }
                   7950:                                     $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';     
                   7951:                                 }
                   7952:                             }
                   7953:                         }
                   7954:                     }
                   7955:                     if ($resulttext ne '') {
                   7956:                         $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
                   7957:                     } else {
                   7958:                         $resulttext = $nochgmsg;
                   7959:                     }
                   7960:                 } else {
                   7961:                     $resulttext = $nochgmsg;
                   7962:                     if ($balancer ne '') {
                   7963:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7964:                     }
                   7965:                 }
                   7966:             } else {
                   7967:                 $resulttext = '<span class="LC_error">'.
                   7968:                               &mt('An error occurred: [_1]',$putresult).'</span>';
                   7969:             }
                   7970:         } else {
                   7971:             $resulttext = $nochgmsg;
                   7972:         }
                   7973:     } else {
                   7974:         $resulttext =  &mt('Load Balancing unavailable as this domain only has one server.');
                   7975:     }
                   7976:     return $resulttext;
                   7977: }
                   7978: 
1.48      raeburn  7979: sub recurse_check {
                   7980:     my ($chkcats,$categories,$depth,$name) = @_;
                   7981:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   7982:         my $chg = 0;
                   7983:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   7984:             my $category = $chkcats->[$depth]{$name}[$j];
                   7985:             my $item;
                   7986:             if ($category eq '') {
                   7987:                 $chg ++;
                   7988:             } else {
                   7989:                 my $deeper = $depth + 1;
                   7990:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   7991:                 if ($chg) {
                   7992:                     $categories->{$item} -= $chg;
                   7993:                 }
                   7994:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   7995:                 $deeper --;
                   7996:             }
                   7997:         }
                   7998:     }
                   7999:     return;
                   8000: }
                   8001: 
                   8002: sub recurse_cat_deletes {
                   8003:     my ($item,$coursecategories,$deletions) = @_;
                   8004:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8005:     my $subdepth = $depth + 1;
                   8006:     if (ref($coursecategories) eq 'HASH') {
                   8007:         foreach my $subitem (keys(%{$coursecategories})) {
                   8008:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   8009:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   8010:                 delete($coursecategories->{$subitem});
                   8011:                 $deletions->{$subitem} = 1;
                   8012:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
                   8013:             }  
                   8014:         }
                   8015:     }
                   8016:     return;
                   8017: }
                   8018: 
1.125     raeburn  8019: sub get_active_dcs {
                   8020:     my ($dom) = @_;
                   8021:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
                   8022:     my %domcoords;
                   8023:     my $numdcs = 0;
                   8024:     my $now = time;
                   8025:     foreach my $server (keys(%dompersonnel)) {
                   8026:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   8027:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   8028:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
                   8029:             if (($end eq '') || ($end == 0) || ($end > $now)) {
                   8030:                 if ($start <= $now) {
                   8031:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
                   8032:                 }
                   8033:             }
                   8034:         }
                   8035:     }
                   8036:     return %domcoords;
                   8037: }
                   8038: 
                   8039: sub active_dc_picker {
                   8040:     my ($dom,$curr_dc) = @_;
                   8041:     my %domcoords = &get_active_dcs($dom); 
                   8042:     my @dcs = sort(keys(%domcoords));
                   8043:     my $numdcs = scalar(@dcs); 
                   8044:     my $datatable;
                   8045:     my $numinrow = 2;
                   8046:     if ($numdcs > 1) {
                   8047:         $datatable = '<table>';
                   8048:         for (my $i=0; $i<@dcs; $i++) {
                   8049:             my $rem = $i%($numinrow);
                   8050:             if ($rem == 0) {
                   8051:                 if ($i > 0) {
                   8052:                     $datatable .= '</tr>';
                   8053:                 }
                   8054:                 $datatable .= '<tr>';
                   8055:             }
                   8056:             my $check = ' ';
                   8057:             if ($curr_dc eq '') {
                   8058:                 if (!$i) { 
                   8059:                     $check = ' checked="checked" ';
                   8060:                 }
                   8061:             } elsif ($dcs[$i] eq $curr_dc) {
                   8062:                 $check = ' checked="checked" ';
                   8063:             }
                   8064:             if ($i == @dcs - 1) {
                   8065:                 my $colsleft = $numinrow - $rem;
                   8066:                 if ($colsleft > 1) {
                   8067:                     $datatable .= '<td colspan="'.$colsleft.'">';
                   8068:                 } else {
                   8069:                     $datatable .= '<td>';
                   8070:                 }
                   8071:             } else {
                   8072:                 $datatable .= '<td>';
                   8073:             }
                   8074:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
                   8075:             $datatable .= '<span class="LC_nobreak"><label>'.
                   8076:                           '<input type="radio" name="autocreate_xmldc"'.
                   8077:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
                   8078:                           &Apache::loncommon::plainname($dcname,$dcdom).
                   8079:                           '</label></span></td>';
                   8080:         }
                   8081:         $datatable .= '</tr></table>';
                   8082:     } elsif (@dcs) {
                   8083:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
                   8084:                       $dcs[0].'" />';
                   8085:     }
                   8086:     return ($numdcs,$datatable);
                   8087: }
                   8088: 
1.137     raeburn  8089: sub usersession_titles {
                   8090:     return &Apache::lonlocal::texthash(
                   8091:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   8092:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  8093:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  8094:                version => 'LON-CAPA version requirement',
1.138     raeburn  8095:                excludedomain => 'Allow all, but exclude specific domains',
                   8096:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  8097:                primary => 'Primary (checked first)',
1.154     raeburn  8098:                default => 'Default',
1.137     raeburn  8099:            );
                   8100: }
                   8101: 
1.152     raeburn  8102: sub id_for_thisdom {
                   8103:     my (%servers) = @_;
                   8104:     my %altids;
                   8105:     foreach my $server (keys(%servers)) {
                   8106:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   8107:         if ($serverhome ne $server) {
                   8108:             $altids{$serverhome} = $server;
                   8109:         }
                   8110:     }
                   8111:     return %altids;
                   8112: }
                   8113: 
1.150     raeburn  8114: sub count_servers {
                   8115:     my ($currbalancer,%servers) = @_;
                   8116:     my (@spares,$numspares);
                   8117:     foreach my $lonhost (sort(keys(%servers))) {
                   8118:         next if ($currbalancer eq $lonhost);
                   8119:         push(@spares,$lonhost);
                   8120:     }
                   8121:     if ($currbalancer) {
                   8122:         $numspares = scalar(@spares);
                   8123:     } else {
                   8124:         $numspares = scalar(@spares) - 1;
                   8125:     }
                   8126:     return ($numspares,@spares);
                   8127: }
                   8128: 
                   8129: sub lonbalance_targets_js {
                   8130:     my ($dom,$types,$servers) = @_;
                   8131:     my $select = &mt('Select');
                   8132:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   8133:     if (ref($servers) eq 'HASH') {
                   8134:         $alltargets = join("','",sort(keys(%{$servers})));
                   8135:         my @homedoms;
                   8136:         foreach my $server (sort(keys(%{$servers}))) {
                   8137:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   8138:                 push(@homedoms,'1');
                   8139:             } else {
                   8140:                 push(@homedoms,'0');
                   8141:             }
                   8142:         }
                   8143:         $allishome = join("','",@homedoms);
                   8144:     }
                   8145:     if (ref($types) eq 'ARRAY') {
                   8146:         if (@{$types} > 0) {
                   8147:             @alltypes = @{$types};
                   8148:         }
                   8149:     }
                   8150:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   8151:     $allinsttypes = join("','",@alltypes);
                   8152:     return <<"END";
                   8153: 
                   8154: <script type="text/javascript">
                   8155: // <![CDATA[
                   8156: 
                   8157: function toggleTargets() {
                   8158:     var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
                   8159:     if (balancer == '') {
                   8160:         hideSpares();
                   8161:     } else {
                   8162:         var homedoms = new Array('$allishome');
                   8163:         var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
                   8164:         showSpares(balancer,ishomedom);
                   8165:     }
                   8166:     return;
                   8167: }
                   8168: 
                   8169: function showSpares(balancer,ishomedom) {
                   8170:     var alltargets = new Array('$alltargets');
                   8171:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  8172:     var offloadtypes = new Array('primary','default');
                   8173: 
1.150     raeburn  8174:     document.getElementById('loadbalancing_targets').style.display='block';
                   8175:     document.getElementById('loadbalancing_disabled').style.display='none';
1.152     raeburn  8176:  
1.151     raeburn  8177:     for (var i=0; i<offloadtypes.length; i++) {
                   8178:         var count = 0;
                   8179:         for (var j=0; j<alltargets.length; j++) {
                   8180:             if (alltargets[j] != balancer) {
                   8181:                 document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
                   8182:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
                   8183:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
                   8184:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   8185:                 count ++;
                   8186:             }
1.150     raeburn  8187:         }
                   8188:     }
1.151     raeburn  8189:     for (var k=0; k<insttypes.length; k++) {
                   8190:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  8191:             if (ishomedom == 1) {
1.151     raeburn  8192:                 document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
                   8193:                 document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150     raeburn  8194:             } else {
1.151     raeburn  8195:                 document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
                   8196:                 document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150     raeburn  8197: 
                   8198:             }
                   8199:         } else {
1.151     raeburn  8200:             document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
                   8201:             document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150     raeburn  8202:         }
1.151     raeburn  8203:         if ((insttypes[k] != '_LC_external') && 
                   8204:             ((insttypes[k] != '_LC_internetdom') ||
                   8205:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
                   8206:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
                   8207:             for (var m=0; m<alltargets.length; m++) {
                   8208:                 var idx = m+1;
                   8209:                 if (alltargets[m] != balancer) {
                   8210:                     document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  8211:                 }
                   8212:             }
                   8213:         }
                   8214:     }
                   8215:     return;
                   8216: }
                   8217: 
                   8218: function hideSpares() {
                   8219:     var alltargets = new Array('$alltargets');
                   8220:     var insttypes = new Array('$allinsttypes');
                   8221:     var offloadtypes = new Array('primary','default');
                   8222: 
                   8223:     document.getElementById('loadbalancing_targets').style.display='none';
                   8224:     document.getElementById('loadbalancing_disabled').style.display='block';
                   8225: 
                   8226:     var total = alltargets.length - 1;
                   8227:     for (var i=0; i<offloadtypes; i++) {
                   8228:         for (var j=0; j<total; j++) {
                   8229:            document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
                   8230:            document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
                   8231:            document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  8232:         }
1.150     raeburn  8233:     }
                   8234:     for (var k=0; k<insttypes.length; k++) {
1.151     raeburn  8235:         document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
                   8236:         document.getElementById('balancerule_'+insttypes[k]).style.display='none';
                   8237:         if (insttypes[k] != '_LC_external') {
                   8238:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
                   8239:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  8240:         }
                   8241:     }
                   8242:     return;
                   8243: }
                   8244: 
                   8245: function checkOffloads(item,type) {
                   8246:     var alltargets = new Array('$alltargets');
                   8247:     var offloadtypes = new Array('primary','default');
                   8248:     if (item.checked) {
                   8249:         var total = alltargets.length - 1;
                   8250:         var other;
                   8251:         if (type == offloadtypes[0]) {
1.151     raeburn  8252:             other = offloadtypes[1];
1.150     raeburn  8253:         } else {
1.151     raeburn  8254:             other = offloadtypes[0];
1.150     raeburn  8255:         }
                   8256:         for (var i=0; i<total; i++) {
                   8257:             var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
                   8258:             if (server == item.value) {
                   8259:                 if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
                   8260:                     document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
                   8261:                 }
                   8262:             }
                   8263:         }
                   8264:     }
                   8265:     return;
                   8266: }
                   8267: 
                   8268: function singleServerToggle(type) {
                   8269:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
                   8270:     if (offloadtoSelIdx == 0) {
                   8271:         document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
                   8272:         document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
                   8273: 
                   8274:     } else {
                   8275:         document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
                   8276:         document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
                   8277:     }
                   8278:     return;
                   8279: }
                   8280: 
                   8281: function balanceruleChange(formname,type) {
                   8282:     if (type == '_LC_external') {
                   8283:         return; 
                   8284:     }
                   8285:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
                   8286:     for (var i=0; i<typesRules.length; i++) {
                   8287:         if (formname.elements[typesRules[i]].checked) {
                   8288:             if (formname.elements[typesRules[i]].value != 'specific') {
                   8289:                 document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
                   8290:                 document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
                   8291:             } else {
                   8292:                 document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
                   8293:             }
                   8294:         }
                   8295:     }
                   8296:     return;
                   8297: }
                   8298: 
1.152     raeburn  8299: // ]]>
                   8300: </script>
                   8301: 
                   8302: END
                   8303: }
                   8304: 
                   8305: sub new_spares_js {
                   8306:     my @sparestypes = ('primary','default');
                   8307:     my $types = join("','",@sparestypes);
                   8308:     my $select = &mt('Select');
                   8309:     return <<"END";
                   8310: 
                   8311: <script type="text/javascript">
                   8312: // <![CDATA[
                   8313: 
                   8314: function updateNewSpares(formname,lonhost) {
                   8315:     var types = new Array('$types');
                   8316:     var include = new Array();
                   8317:     var exclude = new Array();
                   8318:     for (var i=0; i<types.length; i++) {
                   8319:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   8320:         for (var j=0; j<spareboxes.length; j++) {
                   8321:             if (formname.elements[spareboxes[j]].checked) {
                   8322:                 exclude.push(formname.elements[spareboxes[j]].value);
                   8323:             } else {
                   8324:                 include.push(formname.elements[spareboxes[j]].value);
                   8325:             }
                   8326:         }
                   8327:     }
                   8328:     for (var i=0; i<types.length; i++) {
                   8329:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   8330:         var selIdx = newSpare.selectedIndex;
                   8331:         var currnew = newSpare.options[selIdx].value;
                   8332:         var okSpares = new Array();
                   8333:         for (var j=0; j<newSpare.options.length; j++) {
                   8334:             var possible = newSpare.options[j].value;
                   8335:             if (possible != '') {
                   8336:                 if (exclude.indexOf(possible) == -1) {
                   8337:                     okSpares.push(possible);
                   8338:                 } else {
                   8339:                     if (currnew == possible) {
                   8340:                         selIdx = 0;
                   8341:                     }
                   8342:                 }
                   8343:             }
                   8344:         }
                   8345:         for (var k=0; k<include.length; k++) {
                   8346:             if (okSpares.indexOf(include[k]) == -1) {
                   8347:                 okSpares.push(include[k]);
                   8348:             }
                   8349:         }
                   8350:         okSpares.sort();
                   8351:         newSpare.options.length = 0;
                   8352:         if (selIdx == 0) {
                   8353:             newSpare.options[0] = new Option("$select","",true,true);
                   8354:         } else {
                   8355:             newSpare.options[0] = new Option("$select","",false,false);
                   8356:         }
                   8357:         for (var m=0; m<okSpares.length; m++) {
                   8358:             var idx = m+1;
                   8359:             var selThis = 0;
                   8360:             if (selIdx != 0) {
                   8361:                 if (okSpares[m] == currnew) {
                   8362:                     selThis = 1;
                   8363:                 }
                   8364:             }
                   8365:             if (selThis == 1) {
                   8366:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   8367:             } else {
                   8368:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   8369:             }
                   8370:         }
                   8371:     }
                   8372:     return;
                   8373: }
                   8374: 
                   8375: function checkNewSpares(lonhost,type) {
                   8376:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   8377:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   8378:     if (chosen != '') { 
                   8379:         var othertype;
                   8380:         var othernewSpare;
                   8381:         if (type == 'primary') {
                   8382:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   8383:         }
                   8384:         if (type == 'default') {
                   8385:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   8386:         }
                   8387:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   8388:             othernewSpare.selectedIndex = 0;
                   8389:         }
                   8390:     }
                   8391:     return;
                   8392: }
                   8393: 
                   8394: // ]]>
                   8395: </script>
                   8396: 
                   8397: END
                   8398: 
                   8399: }
                   8400: 
                   8401: sub common_domprefs_js {
                   8402:     return <<"END";
                   8403: 
                   8404: <script type="text/javascript">
                   8405: // <![CDATA[
                   8406: 
1.150     raeburn  8407: function getIndicesByName(formname,item) {
1.152     raeburn  8408:     var group = new Array();
1.150     raeburn  8409:     for (var i=0;i<formname.elements.length;i++) {
                   8410:         if (formname.elements[i].name == item) {
1.152     raeburn  8411:             group.push(formname.elements[i].id);
1.150     raeburn  8412:         }
                   8413:     }
1.152     raeburn  8414:     return group;
1.150     raeburn  8415: }
                   8416: 
                   8417: // ]]>
                   8418: </script>
                   8419: 
                   8420: END
1.152     raeburn  8421: 
1.150     raeburn  8422: }
                   8423: 
1.3       raeburn  8424: 1;

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