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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.190   ! raeburn     4: # $Id: domainprefs.pm,v 1.189 2013/02/02 00:22:51 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 
1.183     bisitz     48: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    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.171     raeburn   222:     my %existing;
                    223:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    224:         %existing = %{$domconfig{'loadbalancing'}};
                    225:     }
                    226:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   227:         push(@prefs_order,'loadbalancing');
                    228:     }
1.30      raeburn   229:     my %prefs = (
                    230:         'rolecolors' =>
                    231:                    { text => 'Default color schemes',
1.67      raeburn   232:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   233:                      header => [{col1 => 'Student Settings',
                    234:                                  col2 => '',},
                    235:                                 {col1 => 'Coordinator Settings',
                    236:                                  col2 => '',},
                    237:                                 {col1 => 'Author Settings',
                    238:                                  col2 => '',},
                    239:                                 {col1 => 'Administrator Settings',
                    240:                                  col2 => '',}],
                    241:                     },
1.110     raeburn   242:         'login' =>
1.30      raeburn   243:                     { text => 'Log-in page options',
1.67      raeburn   244:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   245:                       header => [{col1 => 'Log-in Page Items',
                    246:                                   col2 => '',},
                    247:                                  {col1 => 'Log-in Help',
                    248:                                   col2 => 'Value'}],
1.30      raeburn   249:                     },
1.43      raeburn   250:         'defaults' => 
1.141     raeburn   251:                     { text => 'Default authentication/language/timezone/portal',
1.67      raeburn   252:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   253:                       header => [{col1 => 'Setting',
                    254:                                   col2 => 'Value'}],
                    255:                     },
1.30      raeburn   256:         'quotas' => 
1.162     raeburn   257:                     { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67      raeburn   258:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   259:                       header => [{col1 => 'User affiliation',
1.72      raeburn   260:                                   col2 => 'Available tools',
                    261:                                   col3 => 'Portfolio quota',}],
1.30      raeburn   262:                     },
                    263:         'autoenroll' =>
                    264:                    { text => 'Auto-enrollment settings',
1.67      raeburn   265:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   266:                      header => [{col1 => 'Configuration setting',
                    267:                                  col2 => 'Value(s)'}],
                    268:                    },
                    269:         'autoupdate' => 
                    270:                    { text => 'Auto-update settings',
1.67      raeburn   271:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   272:                      header => [{col1 => 'Setting',
                    273:                                  col2 => 'Value',},
1.131     raeburn   274:                                 {col1 => 'Setting',
                    275:                                  col2 => 'Affiliation'},
1.43      raeburn   276:                                 {col1 => 'User population',
1.131     raeburn   277:                                  col2 => 'Updateable user data'}],
1.30      raeburn   278:                   },
1.125     raeburn   279:         'autocreate' => 
                    280:                   { text => 'Auto-course creation settings',
                    281:                      help => 'Domain_Configuration_Auto_Creation',
                    282:                      header => [{col1 => 'Configuration Setting',
                    283:                                  col2 => 'Value',}],
                    284:                   },
1.30      raeburn   285:         'directorysrch' => 
                    286:                   { text => 'Institutional directory searches',
1.67      raeburn   287:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   288:                     header => [{col1 => 'Setting',
                    289:                                 col2 => 'Value',}],
                    290:                   },
                    291:         'contacts' =>
                    292:                   { text => 'Contact Information',
1.67      raeburn   293:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   294:                     header => [{col1 => 'Setting',
                    295:                                 col2 => 'Value',}],
                    296:                   },
                    297: 
                    298:         'usercreation' => 
                    299:                   { text => 'User creation',
1.67      raeburn   300:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   301:                     header => [{col1 => 'Format rule type',
                    302:                                 col2 => 'Format rules in force'},
1.34      raeburn   303:                                {col1 => 'User account creation',
                    304:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   305:                                {col1 => 'Context',
1.43      raeburn   306:                                 col2 => 'Assignable authentication types'}],
1.30      raeburn   307:                   },
1.69      raeburn   308:         'usermodification' =>
1.33      raeburn   309:                   { text => 'User modification',
1.67      raeburn   310:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   311:                     header => [{col1 => 'Target user has role',
                    312:                                 col2 => 'User information updateable in author context'},
                    313:                                {col1 => 'Target user has role',
1.63      raeburn   314:                                 col2 => 'User information updateable in course context'},
                    315:                                {col1 => "Status of user",
                    316:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33      raeburn   317:                   },
1.69      raeburn   318:         'scantron' =>
1.95      www       319:                   { text => 'Bubblesheet format file',
1.67      raeburn   320:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   321:                     header => [ {col1 => 'Item',
                    322:                                  col2 => '',
                    323:                               }],
                    324:                   },
1.86      raeburn   325:         'requestcourses' => 
                    326:                  {text => 'Request creation of courses',
                    327:                   help => 'Domain_Configuration_Request_Courses',
                    328:                   header => [{col1 => 'User affiliation',
1.102     raeburn   329:                               col2 => 'Availability/Processing of requests',},
                    330:                              {col1 => 'Setting',
                    331:                               col2 => 'Value'}],
1.86      raeburn   332:                  },
1.163     raeburn   333:         'requestauthor' =>
                    334:                  {text => 'Request authoring space',
                    335:                   help => 'Domain_Configuration_Request_Author',
                    336:                   header => [{col1 => 'User affiliation',
                    337:                               col2 => 'Availability/Processing of requests',},
                    338:                              {col1 => 'Setting',
                    339:                               col2 => 'Value'}],
                    340:                  },
1.69      raeburn   341:         'coursecategories' =>
1.120     raeburn   342:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   343:                     help => 'Domain_Configuration_Cataloging_Courses',
1.69      raeburn   344:                     header => [{col1 => 'Category settings',
1.57      raeburn   345:                                 col2 => '',},
                    346:                                {col1 => 'Categories',
                    347:                                 col2 => '',
                    348:                                }],
1.69      raeburn   349:                   },
                    350:         'serverstatuses' =>
1.77      raeburn   351:                  {text   => 'Access to server status pages',
1.69      raeburn   352:                   help   => 'Domain_Configuration_Server_Status',
                    353:                   header => [{col1 => 'Status Page',
                    354:                               col2 => 'Other named users',
                    355:                               col3 => 'Specific IPs',
                    356:                             }],
                    357:                  },
1.118     jms       358:         'helpsettings' =>
                    359:                  {text   => 'Help page settings',
                    360:                   help   => 'Domain_Configuration_Help_Settings',
1.166     raeburn   361:                   header => [{col1 => 'Help Settings (logged-in users)',
                    362:                               col2 => 'Value'}],
1.118     jms       363:                  },
1.121     raeburn   364:         'coursedefaults' => 
                    365:                  {text => 'Course/Community defaults',
                    366:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   367:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    368:                               col2 => 'Value',},
                    369:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    370:                               col2 => 'Value',},],
1.121     raeburn   371:                  },
1.120     raeburn   372:         'privacy' => 
                    373:                  {text   => 'User Privacy',
                    374:                   help   => 'Domain_Configuration_User_Privacy',
                    375:                   header => [{col1 => 'Setting',
                    376:                               col2 => 'Value',}],
                    377:                  },
1.141     raeburn   378:         'usersessions' =>
1.145     raeburn   379:                  {text  => 'User session hosting/offloading',
1.137     raeburn   380:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   381:                   header => [{col1 => 'Domain server',
                    382:                               col2 => 'Servers to offload sessions to when busy'},
                    383:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   384:                               col2 => 'Rules'},
                    385:                              {col1 => "Hosting domain's own users elsewhere",
                    386:                               col2 => 'Rules'}],
                    387:                  },
1.150     raeburn   388:          'loadbalancing' =>
1.185     raeburn   389:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   390:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   391:                   header => [{col1 => 'Balancers',
1.150     raeburn   392:                               col2 => 'Default destinations',
1.183     bisitz    393:                               col3 => 'User affiliation',
1.150     raeburn   394:                               col4 => 'Overrides'},
                    395:                             ],
                    396:                  },
1.3       raeburn   397:     );
1.110     raeburn   398:     if (keys(%servers) > 1) {
                    399:         $prefs{'login'}  = { text   => 'Log-in page options',
                    400:                              help   => 'Domain_Configuration_Login_Page',
                    401:                             header => [{col1 => 'Log-in Service',
                    402:                                         col2 => 'Server Setting',},
                    403:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   404:                                         col2 => ''},
                    405:                                        {col1 => 'Log-in Help',
                    406:                                         col2 => 'Value'}],
1.110     raeburn   407:                            };
                    408:     }
1.174     foxr      409: 
1.6       raeburn   410:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   411:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   412:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   413:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   414:       text=>"Settings to display/modify"});
1.9       raeburn   415:     my $confname = $dom.'-domainconfig';
1.174     foxr      416: 
1.3       raeburn   417:     if ($phase eq 'process') {
1.91      raeburn   418:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30      raeburn   419:     } elsif ($phase eq 'display') {
1.165     raeburn   420:         my $js = &recaptcha_js();
1.171     raeburn   421:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   422:             my ($othertitle,$usertypes,$types) =
                    423:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   424:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    425:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   426:                    &new_spares_js().
                    427:                    &common_domprefs_js().
                    428:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   429:         }
1.150     raeburn   430:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   431:     } else {
1.180     raeburn   432: # check if domconfig user exists for the domain.
                    433:         my $servadm = $r->dir_config('lonAdmEMail');
                    434:         my ($configuserok,$author_ok,$switchserver) =
                    435:             &config_check($dom,$confname,$servadm);
                    436:         unless ($configuserok eq 'ok') {
1.181     raeburn   437:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    438:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
                    439:                            $confname).
                    440:                       '<br />'
                    441:             );
1.180     raeburn   442:             if ($switchserver) {
1.181     raeburn   443:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    444:                           '<br />'.
                    445:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    446:                           '<br />'.
                    447:                           &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
                    448:                           '<br />'.
                    449:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    450:                 );
                    451:             } else {
                    452:                 $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
                    453:                           '<br />'.
                    454:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    455:                 );
1.180     raeburn   456:             }
                    457:             $r->print(&Apache::loncommon::end_page());
                    458:             return OK;
                    459:         }
1.21      raeburn   460:         if (keys(%domconfig) == 0) {
                    461:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   462:             my @ids=&Apache::lonnet::current_machine_ids();
                    463:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   464:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   465:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   466:                 my $custom_img_count = 0;
                    467:                 foreach my $img (@loginimages) {
                    468:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    469:                         $custom_img_count ++;
                    470:                     }
                    471:                 }
                    472:                 foreach my $role (@roles) {
                    473:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    474:                         $custom_img_count ++;
                    475:                     }
                    476:                 }
                    477:                 if ($custom_img_count > 0) {
1.94      raeburn   478:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   479:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   480:                     $r->print(
                    481:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    482:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    483:     &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 />'.
                    484:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    485:                     if ($switch_server) {
1.30      raeburn   486:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   487:                     }
1.91      raeburn   488:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   489:                     return OK;
                    490:                 }
                    491:             }
                    492:         }
1.91      raeburn   493:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   494:     }
                    495:     return OK;
                    496: }
                    497: 
                    498: sub process_changes {
1.92      raeburn   499:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
                    500:     my %domconfig;
                    501:     if (ref($values) eq 'HASH') {
                    502:         %domconfig = %{$values};
                    503:     }
1.3       raeburn   504:     my $output;
                    505:     if ($action eq 'login') {
1.9       raeburn   506:         $output = &modify_login($r,$dom,$confname,%domconfig);
1.6       raeburn   507:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   508:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
                    509:                                      %domconfig);
1.3       raeburn   510:     } elsif ($action eq 'quotas') {
1.86      raeburn   511:         $output = &modify_quotas($dom,$action,%domconfig);
1.3       raeburn   512:     } elsif ($action eq 'autoenroll') {
                    513:         $output = &modify_autoenroll($dom,%domconfig);
                    514:     } elsif ($action eq 'autoupdate') {
                    515:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   516:     } elsif ($action eq 'autocreate') {
                    517:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   518:     } elsif ($action eq 'directorysrch') {
                    519:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   520:     } elsif ($action eq 'usercreation') {
1.28      raeburn   521:         $output = &modify_usercreation($dom,%domconfig);
1.33      raeburn   522:     } elsif ($action eq 'usermodification') {
                    523:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   524:     } elsif ($action eq 'contacts') {
                    525:         $output = &modify_contacts($dom,%domconfig);
1.43      raeburn   526:     } elsif ($action eq 'defaults') {
                    527:         $output = &modify_defaults($dom,$r);
1.46      raeburn   528:     } elsif ($action eq 'scantron') {
1.48      raeburn   529:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
                    530:     } elsif ($action eq 'coursecategories') {
                    531:         $output = &modify_coursecategories($dom,%domconfig);
1.69      raeburn   532:     } elsif ($action eq 'serverstatuses') {
                    533:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   534:     } elsif ($action eq 'requestcourses') {
                    535:         $output = &modify_quotas($dom,$action,%domconfig);
1.163     raeburn   536:     } elsif ($action eq 'requestauthor') {
                    537:         $output = &modify_quotas($dom,$action,%domconfig);
1.118     jms       538:     } elsif ($action eq 'helpsettings') {
1.122     jms       539:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   540:     } elsif ($action eq 'coursedefaults') {
                    541:         $output = &modify_coursedefaults($dom,%domconfig);
1.137     raeburn   542:     } elsif ($action eq 'usersessions') {
                    543:         $output = &modify_usersessions($dom,%domconfig);
1.150     raeburn   544:     } elsif ($action eq 'loadbalancing') {
                    545:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   546:     }
                    547:     return $output;
                    548: }
                    549: 
                    550: sub print_config_box {
1.9       raeburn   551:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   552:     my $rowtotal = 0;
1.49      raeburn   553:     my $output;
                    554:     if ($action eq 'coursecategories') {
                    555:         $output = &coursecategories_javascript($settings);
1.91      raeburn   556:     }
1.49      raeburn   557:     $output .= 
1.30      raeburn   558:          '<table class="LC_nested_outer">
1.3       raeburn   559:           <tr>
1.66      raeburn   560:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    561:            &mt($item->{text}).'&nbsp;'.
                    562:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    563:           '</tr>';
1.30      raeburn   564:     $rowtotal ++;
1.110     raeburn   565:     my $numheaders = 1;
                    566:     if (ref($item->{'header'}) eq 'ARRAY') {
                    567:         $numheaders = scalar(@{$item->{'header'}});
                    568:     }
                    569:     if ($numheaders > 1) {
1.64      raeburn   570:         my $colspan = '';
1.145     raeburn   571:         my $rightcolspan = '';
1.168     raeburn   572:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || 
                    573:             (($action eq 'login') && ($numheaders < 3))) {
1.64      raeburn   574:             $colspan = ' colspan="2"';
                    575:         }
1.145     raeburn   576:         if ($action eq 'usersessions') {
                    577:             $rightcolspan = ' colspan="3"'; 
                    578:         }
1.30      raeburn   579:         $output .= '
1.3       raeburn   580:           <tr>
                    581:            <td>
                    582:             <table class="LC_nested">
                    583:              <tr class="LC_info_row">
1.59      bisitz    584:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   585:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   586:              </tr>';
1.69      raeburn   587:         $rowtotal ++;
1.6       raeburn   588:         if ($action eq 'autoupdate') {
1.30      raeburn   589:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28      raeburn   590:         } elsif ($action eq 'usercreation') {
1.33      raeburn   591:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
                    592:         } elsif ($action eq 'usermodification') {
                    593:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57      raeburn   594:         } elsif ($action eq 'coursecategories') {
                    595:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   596:         } elsif ($action eq 'login') {
1.168     raeburn   597:             if ($numheaders == 3) {
                    598:                 $colspan = ' colspan="2"';
                    599:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    600:             } else {
                    601:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    602:             }
1.102     raeburn   603:         } elsif ($action eq 'requestcourses') {
                    604:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163     raeburn   605:         } elsif ($action eq 'requestauthor') {
                    606:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137     raeburn   607:         } elsif ($action eq 'usersessions') {
                    608:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
1.122     jms       609:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   610:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139     raeburn   611:         } elsif ($action eq 'coursedefaults') {
                    612:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6       raeburn   613:         }
1.30      raeburn   614:         $output .= '
1.6       raeburn   615:            </table>
                    616:           </td>
                    617:          </tr>
                    618:          <tr>
                    619:            <td>
                    620:             <table class="LC_nested">
                    621:              <tr class="LC_info_row">
1.59      bisitz    622:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57      raeburn   623:         $output .= '
1.59      bisitz    624:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   625:              </tr>';
                    626:             $rowtotal ++;
1.6       raeburn   627:         if ($action eq 'autoupdate') {
1.131     raeburn   628:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
                    629:            </table>
                    630:           </td>
                    631:          </tr>
                    632:          <tr>
                    633:            <td>
                    634:             <table class="LC_nested">
                    635:              <tr class="LC_info_row">
                    636:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    637:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    638:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
                    639:             $rowtotal ++;
1.28      raeburn   640:         } elsif ($action eq 'usercreation') {
1.34      raeburn   641:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                    642:            </table>
                    643:           </td>
                    644:          </tr>
                    645:          <tr>
                    646:            <td>
                    647:             <table class="LC_nested">
                    648:              <tr class="LC_info_row">
1.59      bisitz    649:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    650:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
1.34      raeburn   651:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
                    652:             $rowtotal ++;
1.33      raeburn   653:         } elsif ($action eq 'usermodification') {
1.63      raeburn   654:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
                    655:            </table>
                    656:           </td>
                    657:          </tr>
                    658:          <tr>
                    659:            <td>
                    660:             <table class="LC_nested">
                    661:              <tr class="LC_info_row">
                    662:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    663:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    664:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
                    665:             $rowtotal ++;
1.57      raeburn   666:         } elsif ($action eq 'coursecategories') {
                    667:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   668:         } elsif ($action eq 'login') {
1.168     raeburn   669:             if ($numheaders == 3) {
                    670:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    671:            </table>
                    672:           </td>
                    673:          </tr>
                    674:          <tr>
                    675:            <td>
                    676:             <table class="LC_nested">
                    677:              <tr class="LC_info_row">
                    678:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    679:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    680:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    681:                 $rowtotal ++;
                    682:             } else {
                    683:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    684:             }
1.102     raeburn   685:         } elsif ($action eq 'requestcourses') {
1.163     raeburn   686:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    687:         } elsif ($action eq 'requestauthor') {
                    688:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137     raeburn   689:         } elsif ($action eq 'usersessions') {
1.145     raeburn   690:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
                    691:            </table>
                    692:           </td>
                    693:          </tr>
                    694:          <tr>
                    695:            <td>
                    696:             <table class="LC_nested">
                    697:              <tr class="LC_info_row">
                    698:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    699:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    700:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
                    701:             $rowtotal ++;
1.139     raeburn   702:         } elsif ($action eq 'coursedefaults') {
                    703:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122     jms       704:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   705:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   706:            </table>
                    707:           </td>
                    708:          </tr>
                    709:          <tr>
                    710:            <td>
                    711:             <table class="LC_nested">
                    712:              <tr class="LC_info_row">
1.69      raeburn   713:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    714:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    715:               <td class="LC_right_item" valign="top">'.
                    716:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   717:              </tr>'.
1.30      raeburn   718:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   719:            </table>
                    720:           </td>
                    721:          </tr>
                    722:          <tr>
                    723:            <td>
                    724:             <table class="LC_nested">
                    725:              <tr class="LC_info_row">
1.59      bisitz    726:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    727:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   728:              </tr>'.
1.30      raeburn   729:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    730:             $rowtotal += 2;
1.6       raeburn   731:         }
1.3       raeburn   732:     } else {
1.30      raeburn   733:         $output .= '
1.3       raeburn   734:           <tr>
                    735:            <td>
                    736:             <table class="LC_nested">
1.30      raeburn   737:              <tr class="LC_info_row">';
1.24      raeburn   738:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   739:             $output .= '  
1.59      bisitz    740:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   741:         } elsif ($action eq 'serverstatuses') {
                    742:             $output .= '
                    743:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    744:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    745: 
1.6       raeburn   746:         } else {
1.30      raeburn   747:             $output .= '
1.69      raeburn   748:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    749:         }
1.72      raeburn   750:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    751:             $output .= '<td class="LC_left_item" valign="top">'.
                    752:                        &mt($item->{'header'}->[0]->{'col2'});
                    753:             if ($action eq 'serverstatuses') {
                    754:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    755:             } 
1.69      raeburn   756:         } else {
                    757:             $output .= '<td class="LC_right_item" valign="top">'.
                    758:                        &mt($item->{'header'}->[0]->{'col2'});
                    759:         }
                    760:         $output .= '</td>';
                    761:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   762:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    763:                 $output .= '<td class="LC_left_item" valign="top">'.
                    764:                             &mt($item->{'header'}->[0]->{'col3'});
                    765:             } else {
                    766:                 $output .= '<td class="LC_right_item" valign="top">'.
                    767:                            &mt($item->{'header'}->[0]->{'col3'});
                    768:             }
1.69      raeburn   769:             if ($action eq 'serverstatuses') {
                    770:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    771:             }
                    772:             $output .= '</td>';
1.6       raeburn   773:         }
1.150     raeburn   774:         if ($item->{'header'}->[0]->{'col4'}) {
                    775:             $output .= '<td class="LC_right_item" valign="top">'.
                    776:                        &mt($item->{'header'}->[0]->{'col4'});
                    777:         }
1.69      raeburn   778:         $output .= '</tr>';
1.48      raeburn   779:         $rowtotal ++;
1.168     raeburn   780:         if ($action eq 'quotas') {
1.86      raeburn   781:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3       raeburn   782:         } elsif ($action eq 'autoenroll') {
1.30      raeburn   783:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125     raeburn   784:         } elsif ($action eq 'autocreate') {
                    785:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23      raeburn   786:         } elsif ($action eq 'directorysrch') {
1.30      raeburn   787:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28      raeburn   788:         } elsif ($action eq 'contacts') {
1.30      raeburn   789:             $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43      raeburn   790:         } elsif ($action eq 'defaults') {
                    791:             $output .= &print_defaults($dom,\$rowtotal);
1.46      raeburn   792:         } elsif ($action eq 'scantron') {
                    793:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69      raeburn   794:         } elsif ($action eq 'serverstatuses') {
                    795:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118     jms       796:         } elsif ($action eq 'helpsettings') {
1.168     raeburn   797:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150     raeburn   798:         } elsif ($action eq 'loadbalancing') {
                    799:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121     raeburn   800:         }
1.3       raeburn   801:     }
1.30      raeburn   802:     $output .= '
1.3       raeburn   803:    </table>
                    804:   </td>
                    805:  </tr>
1.30      raeburn   806: </table><br />';
                    807:     return ($output,$rowtotal);
1.1       raeburn   808: }
                    809: 
1.3       raeburn   810: sub print_login {
1.168     raeburn   811:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn   812:     my ($css_class,$datatable);
1.6       raeburn   813:     my %choices = &login_choices();
1.110     raeburn   814: 
1.168     raeburn   815:     if ($caller eq 'service') {
1.149     raeburn   816:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   817:         my $choice = $choices{'disallowlogin'};
                    818:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   819:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   820:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   821:                       '<th>'.$choices{'server'}.'</th>'.
                    822:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    823:                       '<th>'.$choices{'custompath'}.'</th>'.
                    824:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   825:         my %disallowed;
                    826:         if (ref($settings) eq 'HASH') {
                    827:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    828:                %disallowed = %{$settings->{'loginvia'}};
                    829:             }
                    830:         }
                    831:         foreach my $lonhost (sort(keys(%servers))) {
                    832:             my $direct = 'selected="selected"';
1.128     raeburn   833:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    834:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    835:                     $direct = '';
                    836:                 }
1.110     raeburn   837:             }
1.115     raeburn   838:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   839:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   840:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    841:                           '</option>';
1.184     raeburn   842:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn   843:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   844:                 my $selected = '';
1.128     raeburn   845:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    846:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    847:                         $selected = 'selected="selected"';
                    848:                     }
1.110     raeburn   849:                 }
                    850:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    851:                               $servers{$hostid}.'</option>';
                    852:             }
1.128     raeburn   853:             $datatable .= '</select></td>'.
                    854:                           '<td><select name="'.$lonhost.'_serverpath">';
                    855:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    856:                 my $pathname = $path;
                    857:                 if ($path eq 'custom') {
                    858:                     $pathname = &mt('Custom Path').' ->';
                    859:                 }
                    860:                 my $selected = '';
                    861:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    862:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    863:                         $selected = 'selected="selected"';
                    864:                     }
                    865:                 } elsif ($path eq '') {
                    866:                     $selected = 'selected="selected"';
                    867:                 }
                    868:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    869:             }
                    870:             $datatable .= '</select></td>';
                    871:             my ($custom,$exempt);
                    872:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    873:                 $custom = $disallowed{$lonhost}{'custompath'};
                    874:                 $exempt = $disallowed{$lonhost}{'exempt'};
                    875:             }
                    876:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                    877:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                    878:                           '</tr>';
1.110     raeburn   879:         }
                    880:         $datatable .= '</table></td></tr>';
                    881:         return $datatable;
1.168     raeburn   882:     } elsif ($caller eq 'page') {
                    883:         my %defaultchecked = ( 
                    884:                                'coursecatalog' => 'on',
1.188     raeburn   885:                                'helpdesk'      => 'on',
1.168     raeburn   886:                                'adminmail'     => 'off',
                    887:                                'newuser'       => 'off',
                    888:                              );
1.188     raeburn   889:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn   890:         my (%checkedon,%checkedoff);
1.42      raeburn   891:         foreach my $item (@toggles) {
1.168     raeburn   892:             if ($defaultchecked{$item} eq 'on') { 
                    893:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn   894:                 $checkedoff{$item} = ' ';
1.168     raeburn   895:             } elsif ($defaultchecked{$item} eq 'off') {
                    896:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn   897:                 $checkedon{$item} = ' ';
                    898:             }
1.1       raeburn   899:         }
1.168     raeburn   900:         my @images = ('img','logo','domlogo','login');
                    901:         my @logintext = ('textcol','bgcol');
                    902:         my @bgs = ('pgbg','mainbg','sidebg');
                    903:         my @links = ('link','alink','vlink');
                    904:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                    905:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                    906:         my (%is_custom,%designs);
                    907:         my %defaults = (
                    908:                        font => $defaultdesign{'login.font'},
                    909:                        );
1.6       raeburn   910:         foreach my $item (@images) {
1.168     raeburn   911:             $defaults{$item} = $defaultdesign{'login.'.$item};
                    912:             $defaults{'showlogo'}{$item} = 1;
                    913:         }
                    914:         foreach my $item (@bgs) {
                    915:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   916:         }
1.41      raeburn   917:         foreach my $item (@logintext) {
1.168     raeburn   918:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn   919:         }
1.168     raeburn   920:         foreach my $item (@links) {
                    921:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   922:         }
1.168     raeburn   923:         if (ref($settings) eq 'HASH') {
                    924:             foreach my $item (@toggles) {
                    925:                 if ($settings->{$item} eq '1') {
                    926:                     $checkedon{$item} =  ' checked="checked" ';
                    927:                     $checkedoff{$item} = ' ';
                    928:                 } elsif ($settings->{$item} eq '0') {
                    929:                     $checkedoff{$item} =  ' checked="checked" ';
                    930:                     $checkedon{$item} = ' ';
                    931:                 }
                    932:             }
                    933:             foreach my $item (@images) {
                    934:                 if (defined($settings->{$item})) {
                    935:                     $designs{$item} = $settings->{$item};
                    936:                     $is_custom{$item} = 1;
                    937:                 }
                    938:                 if (defined($settings->{'showlogo'}{$item})) {
                    939:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                    940:                 }
                    941:             }
                    942:             foreach my $item (@logintext) {
                    943:                 if ($settings->{$item} ne '') {
                    944:                     $designs{'logintext'}{$item} = $settings->{$item};
                    945:                     $is_custom{$item} = 1;
                    946:                 }
                    947:             }
                    948:             if ($settings->{'font'} ne '') {
                    949:                 $designs{'font'} = $settings->{'font'};
                    950:                 $is_custom{'font'} = 1;
                    951:             }
                    952:             foreach my $item (@bgs) {
                    953:                 if ($settings->{$item} ne '') {
                    954:                     $designs{'bgs'}{$item} = $settings->{$item};
                    955:                     $is_custom{$item} = 1;
                    956:                 }
                    957:             }
                    958:             foreach my $item (@links) {
                    959:                 if ($settings->{$item} ne '') {
                    960:                     $designs{'links'}{$item} = $settings->{$item};
                    961:                     $is_custom{$item} = 1;
                    962:                 }
                    963:             }
                    964:         } else {
                    965:             if ($designhash{$dom.'.login.font'} ne '') {
                    966:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                    967:                 $is_custom{'font'} = 1;
                    968:             }
                    969:             foreach my $item (@images) {
                    970:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    971:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                    972:                     $is_custom{$item} = 1;
                    973:                 }
                    974:             }
                    975:             foreach my $item (@bgs) {
                    976:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    977:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                    978:                     $is_custom{$item} = 1;
                    979:                 }
1.6       raeburn   980:             }
1.168     raeburn   981:             foreach my $item (@links) {
                    982:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    983:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                    984:                     $is_custom{$item} = 1;
                    985:                 }
1.6       raeburn   986:             }
                    987:         }
1.168     raeburn   988:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                    989:                                                       logo => 'Institution Logo',
                    990:                                                       domlogo => 'Domain Logo',
                    991:                                                       login => 'Login box');
                    992:         my $itemcount = 1;
                    993:         foreach my $item (@toggles) {
                    994:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    995:             $datatable .=  
                    996:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                    997:                 '</td><td>'.
                    998:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                    999:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1000:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1001:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1002:                 '</tr>';
                   1003:             $itemcount ++;
1.6       raeburn  1004:         }
1.168     raeburn  1005:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1006:         $datatable .= '</tr></table></td></tr>';
                   1007:     } elsif ($caller eq 'help') {
                   1008:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1009:         my $switchserver = &check_switchserver($dom,$confname);
                   1010:         my $itemcount = 1;
                   1011:         $defaulturl = '/adm/loginproblems.html';
                   1012:         $defaulttype = 'default';
                   1013:         %lt = &Apache::lonlocal::texthash (
                   1014:                      del     => 'Delete?',
                   1015:                      rep     => 'Replace:',
                   1016:                      upl     => 'Upload:',
                   1017:                      default => 'Default',
                   1018:                      custom  => 'Custom',
                   1019:                                              );
                   1020:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1021:         my @currlangs;
                   1022:         if (ref($settings) eq 'HASH') {
                   1023:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1024:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1025:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1026:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1027:                     $type{$key} = 'custom';
                   1028:                     unless ($key eq 'nolang') {
                   1029:                         push(@currlangs,$key);
                   1030:                     }
                   1031:                 }
                   1032:             } elsif ($settings->{'helpurl'} ne '') {
                   1033:                 $type{'nolang'} = 'custom';
                   1034:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1035:             }
                   1036:         }
1.168     raeburn  1037:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1038:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1039:             $datatable .= '<tr'.$css_class.'>';
                   1040:             if ($url{$lang} eq '') {
                   1041:                 $url{$lang} = $defaulturl;
                   1042:             }
                   1043:             if ($type{$lang} eq '') {
                   1044:                 $type{$lang} = $defaulttype;
                   1045:             }
                   1046:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1047:             if ($lang eq 'nolang') {
                   1048:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1049:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1050:             } else {
                   1051:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1052:                                   $langchoices{$lang},
                   1053:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1054:             }
                   1055:             $datatable .= '</span></td>'."\n".
                   1056:                           '<td class="LC_left_item">';
                   1057:             if ($type{$lang} eq 'custom') {
                   1058:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1059:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1060:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1061:             } else {
                   1062:                 $datatable .= $lt{'upl'};
                   1063:             }
                   1064:             $datatable .='<br />';
                   1065:             if ($switchserver) {
                   1066:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1067:             } else {
                   1068:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1069:             }
1.168     raeburn  1070:             $datatable .= '</td></tr>';
                   1071:             $itemcount ++;
1.6       raeburn  1072:         }
1.168     raeburn  1073:         my @addlangs;
                   1074:         foreach my $lang (sort(keys(%langchoices))) {
                   1075:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1076:             push(@addlangs,$lang);
                   1077:         }
                   1078:         if (@addlangs > 0) {
                   1079:             my %toadd;
                   1080:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1081:             $toadd{''} = &mt('Select');
                   1082:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1083:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1084:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1085:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1086:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1087:             if ($switchserver) {
                   1088:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1089:             } else {
                   1090:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1091:             }
1.168     raeburn  1092:             $datatable .= '</td></tr>';
1.169     raeburn  1093:             $itemcount ++;
1.6       raeburn  1094:         }
1.169     raeburn  1095:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1       raeburn  1096:     }
1.6       raeburn  1097:     return $datatable;
                   1098: }
                   1099: 
                   1100: sub login_choices {
                   1101:     my %choices =
                   1102:         &Apache::lonlocal::texthash (
1.116     bisitz   1103:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1104:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1105:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1106:             disallowlogin => "Login page requests redirected",
                   1107:             hostid        => "Server",
1.128     raeburn  1108:             server        => "Redirect to:",
                   1109:             serverpath    => "Path",
                   1110:             custompath    => "Custom", 
                   1111:             exempt        => "Exempt IP(s)",
1.110     raeburn  1112:             directlogin   => "No redirect",
                   1113:             newuser       => "Link to create a user account",
                   1114:             img           => "Header",
                   1115:             logo          => "Main Logo",
                   1116:             domlogo       => "Domain Logo",
                   1117:             login         => "Log-in Header", 
                   1118:             textcol       => "Text color",
                   1119:             bgcol         => "Box color",
                   1120:             bgs           => "Background colors",
                   1121:             links         => "Link colors",
                   1122:             font          => "Font color",
                   1123:             pgbg          => "Header",
                   1124:             mainbg        => "Page",
                   1125:             sidebg        => "Login box",
                   1126:             link          => "Link",
                   1127:             alink         => "Active link",
                   1128:             vlink         => "Visited link",
1.6       raeburn  1129:         );
                   1130:     return %choices;
                   1131: }
                   1132: 
                   1133: sub print_rolecolors {
1.30      raeburn  1134:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1135:     my %choices = &color_font_choices();
                   1136:     my @bgs = ('pgbg','tabbg','sidebg');
                   1137:     my @links = ('link','alink','vlink');
                   1138:     my @images = ('img');
                   1139:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1140:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1141:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1142:     my (%is_custom,%designs);
                   1143:     my %defaults = (
                   1144:                    img => $defaultdesign{$role.'.img'},
                   1145:                    font => $defaultdesign{$role.'.font'},
1.97      tempelho 1146: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6       raeburn  1147:                    );
                   1148:     foreach my $item (@bgs) {
                   1149:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1150:     }
                   1151:     foreach my $item (@links) {
                   1152:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1153:     }
                   1154:     if (ref($settings) eq 'HASH') {
                   1155:         if (ref($settings->{$role}) eq 'HASH') {
                   1156:             if ($settings->{$role}->{'img'} ne '') {
                   1157:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1158:                 $is_custom{'img'} = 1;
                   1159:             }
                   1160:             if ($settings->{$role}->{'font'} ne '') {
                   1161:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1162:                 $is_custom{'font'} = 1;
                   1163:             }
1.97      tempelho 1164:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1165:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1166:                 $is_custom{'fontmenu'} = 1;
                   1167:             }
1.6       raeburn  1168:             foreach my $item (@bgs) {
                   1169:                 if ($settings->{$role}->{$item} ne '') {
                   1170:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1171:                     $is_custom{$item} = 1;
                   1172:                 }
                   1173:             }
                   1174:             foreach my $item (@links) {
                   1175:                 if ($settings->{$role}->{$item} ne '') {
                   1176:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1177:                     $is_custom{$item} = 1;
                   1178:                 }
                   1179:             }
                   1180:         }
                   1181:     } else {
                   1182:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1183:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1184:             $is_custom{'img'} = 1;
                   1185:         }
1.97      tempelho 1186:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1187:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1188:             $is_custom{'fontmenu'} = 1; 
                   1189:         }
1.6       raeburn  1190:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1191:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1192:             $is_custom{'font'} = 1;
                   1193:         }
                   1194:         foreach my $item (@bgs) {
                   1195:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1196:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1197:                 $is_custom{$item} = 1;
                   1198:             
                   1199:             }
                   1200:         }
                   1201:         foreach my $item (@links) {
                   1202:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1203:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1204:                 $is_custom{$item} = 1;
                   1205:             }
                   1206:         }
                   1207:     }
                   1208:     my $itemcount = 1;
1.30      raeburn  1209:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1210:     $datatable .= '</tr></table></td></tr>';
                   1211:     return $datatable;
                   1212: }
                   1213: 
                   1214: sub display_color_options {
1.9       raeburn  1215:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1216:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1217:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1218:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  1219:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1220:         '<td>'.$choices->{'font'}.'</td>';
                   1221:     if (!$is_custom->{'font'}) {
1.30      raeburn  1222:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1223:     } else {
                   1224:         $datatable .= '<td>&nbsp;</td>';
                   1225:     }
1.174     foxr     1226:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1227: 
1.8       raeburn  1228:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1229:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
                   1230:                   ' value="'.$current_color.'" />&nbsp;'. 
                   1231:                   '&nbsp;</td></tr>';
1.107     raeburn  1232:     unless ($role eq 'login') { 
                   1233:         $datatable .= '<tr'.$css_class.'>'.
                   1234:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1235:         if (!$is_custom->{'fontmenu'}) {
                   1236:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1237:         } else {
                   1238:             $datatable .= '<td>&nbsp;</td>';
                   1239:         }
1.174     foxr     1240: 	$current_color = $designs->{'fontmenu'} ? 
                   1241: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1242:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1243:                       '<input class="colorchooser" type="text" size="10" name="'
                   1244: 		      .$role.'_fontmenu"'.
                   1245:                       ' value="'.$current_color.'" />&nbsp;'.
                   1246:                       '&nbsp;</td></tr>';
1.97      tempelho 1247:     }
1.9       raeburn  1248:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1249:     foreach my $img (@{$images}) {
1.18      albertel 1250: 	$itemcount ++;
1.6       raeburn  1251:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1252:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1253:                       '<td>'.$choices->{$img};
1.41      raeburn  1254:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1255:         if ($role eq 'login') {
                   1256:             if ($img eq 'login') {
                   1257:                 $login_hdr_pick =
1.135     bisitz   1258:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1259:                 $logincolors =
                   1260:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
                   1261:                                             $designs);
                   1262:             } elsif ($img ne 'domlogo') {
                   1263:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1264:             }
                   1265:         }
                   1266:         $datatable .= '</td>';
1.6       raeburn  1267:         if ($designs->{$img} ne '') {
                   1268:             $imgfile = $designs->{$img};
1.18      albertel 1269: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1270:         } else {
                   1271:             $imgfile = $defaults->{$img};
                   1272:         }
                   1273:         if ($imgfile) {
1.9       raeburn  1274:             my ($showfile,$fullsize);
                   1275:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1276:                 my $urldir = $1;
                   1277:                 my $filename = $2;
                   1278:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1279:                 if (@info) {
                   1280:                     my $thumbfile = 'tn-'.$filename;
                   1281:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1282:                     if (@thumb) {
                   1283:                         $showfile = $urldir.'/'.$thumbfile;
                   1284:                     } else {
                   1285:                         $showfile = $imgfile;
                   1286:                     }
                   1287:                 } else {
                   1288:                     $showfile = '';
                   1289:                 }
                   1290:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1291:                 $showfile = $imgfile;
1.6       raeburn  1292:                 my $imgdir = $1;
                   1293:                 my $filename = $2;
1.159     raeburn  1294:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1295:                     $showfile = "/$imgdir/tn-".$filename;
                   1296:                 } else {
1.159     raeburn  1297:                     my $input = $londocroot.$imgfile;
                   1298:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1299:                     if (!-e $output) {
1.9       raeburn  1300:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1301:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1302:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1303:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1304:                                 my $size = $width.'x'.$height;
                   1305:                                 system("convert -sample $size $input $output");
1.159     raeburn  1306:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1307:                             }
                   1308:                         }
1.6       raeburn  1309:                     }
                   1310:                 }
1.16      raeburn  1311:             }
1.6       raeburn  1312:             if ($showfile) {
1.40      raeburn  1313:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1314:                     if ($showfile =~ m{^/res/}) {
                   1315:                         my $local_showfile =
                   1316:                             &Apache::lonnet::filelocation('',$showfile);
                   1317:                         &Apache::lonnet::repcopy($local_showfile);
                   1318:                     }
                   1319:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1320:                 }
                   1321:                 if ($imgfile) {
                   1322:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1323:                         if ($imgfile =~ m{^/res/}) {
                   1324:                             my $local_imgfile =
                   1325:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1326:                             &Apache::lonnet::repcopy($local_imgfile);
                   1327:                         }
                   1328:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1329:                     } else {
                   1330:                         $fullsize = $imgfile;
                   1331:                     }
                   1332:                 }
1.41      raeburn  1333:                 $datatable .= '<td>';
                   1334:                 if ($img eq 'login') {
1.135     bisitz   1335:                     $datatable .= $login_hdr_pick;
                   1336:                 } 
1.41      raeburn  1337:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1338:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1339:             } else {
                   1340:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1341:                               &mt('Upload:');
                   1342:             }
                   1343:         } else {
                   1344:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1345:                           &mt('Upload:');
                   1346:         }
1.9       raeburn  1347:         if ($switchserver) {
                   1348:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1349:         } else {
1.135     bisitz   1350:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1351:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1352:             }
1.9       raeburn  1353:         }
                   1354:         $datatable .= '</td></tr>';
1.6       raeburn  1355:     }
                   1356:     $itemcount ++;
                   1357:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1358:     $datatable .= '<tr'.$css_class.'>'.
                   1359:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1360:     my $bgs_def;
                   1361:     foreach my $item (@{$bgs}) {
                   1362:         if (!$is_custom->{$item}) {
1.70      raeburn  1363:             $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  1364:         }
                   1365:     }
                   1366:     if ($bgs_def) {
1.8       raeburn  1367:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1368:     } else {
                   1369:         $datatable .= '<td>&nbsp;</td>';
                   1370:     }
                   1371:     $datatable .= '<td class="LC_right_item">'.
                   1372:                   '<table border="0"><tr>';
1.174     foxr     1373: 
1.6       raeburn  1374:     foreach my $item (@{$bgs}) {
1.174     foxr     1375:         $datatable .= '<td align="center">';
                   1376: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1377:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1378:             $datatable .= '&nbsp;';
1.6       raeburn  1379:         }
1.174     foxr     1380:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1381:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1382:     }
                   1383:     $datatable .= '</tr></table></td></tr>';
                   1384:     $itemcount ++;
                   1385:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1386:     $datatable .= '<tr'.$css_class.'>'.
                   1387:                   '<td>'.$choices->{'links'}.'</td>';
                   1388:     my $links_def;
                   1389:     foreach my $item (@{$links}) {
                   1390:         if (!$is_custom->{$item}) {
1.30      raeburn  1391:             $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  1392:         }
                   1393:     }
                   1394:     if ($links_def) {
1.8       raeburn  1395:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1396:     } else {
                   1397:         $datatable .= '<td>&nbsp;</td>';
                   1398:     }
                   1399:     $datatable .= '<td class="LC_right_item">'.
                   1400:                   '<table border="0"><tr>';
                   1401:     foreach my $item (@{$links}) {
1.174     foxr     1402: 	my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
                   1403:         $datatable .= '<td align="center">'."\n";
                   1404: 
1.6       raeburn  1405:         if ($designs->{'links'}{$item}) {
1.174     foxr     1406:             $datatable.='&nbsp;';
1.6       raeburn  1407:         }
1.174     foxr     1408:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1409:                       '" /></td>';
                   1410:     }
1.30      raeburn  1411:     $$rowtotal += $itemcount;
1.3       raeburn  1412:     return $datatable;
                   1413: }
                   1414: 
1.70      raeburn  1415: sub logo_display_options {
                   1416:     my ($img,$defaults,$designs) = @_;
                   1417:     my $checkedon;
                   1418:     if (ref($defaults) eq 'HASH') {
                   1419:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1420:             if ($defaults->{'showlogo'}{$img}) {
                   1421:                 $checkedon = 'checked="checked" ';     
                   1422:             }
                   1423:         } 
                   1424:     }
                   1425:     if (ref($designs) eq 'HASH') {
                   1426:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1427:             if (defined($designs->{'showlogo'}{$img})) {
                   1428:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1429:                     $checkedon = '';
                   1430:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1431:                     $checkedon = 'checked="checked" ';
                   1432:                 }
                   1433:             }
                   1434:         }
                   1435:     }
                   1436:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1437:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1438:            &mt('show').'</label>'."\n";
                   1439: }
                   1440: 
1.41      raeburn  1441: sub login_header_options  {
1.135     bisitz   1442:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1443:     my $output = '';
1.41      raeburn  1444:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1445:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1446:         if (!$is_custom->{'textcol'}) {
                   1447:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1448:                        '&nbsp;&nbsp;&nbsp;';
                   1449:         }
                   1450:         if (!$is_custom->{'bgcol'}) {
                   1451:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1452:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1453:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1454:         }
                   1455:         $output .= '<br />';
                   1456:     }
                   1457:     $output .='<br />';
                   1458:     return $output;
                   1459: }
                   1460: 
                   1461: sub login_text_colors {
                   1462:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
                   1463:     my $color_menu = '<table border="0"><tr>';
                   1464:     foreach my $item (@{$logintext}) {
                   1465:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
                   1466:         $color_menu .= '<td align="center">'.$link;
                   1467:         if ($designs->{'logintext'}{$item}) {
                   1468:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1469:         }
                   1470:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
                   1471:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
                   1472:                        '<td>&nbsp;</td>';
                   1473:     }
                   1474:     $color_menu .= '</tr></table><br />';
                   1475:     return $color_menu;
                   1476: }
                   1477: 
                   1478: sub image_changes {
                   1479:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1480:     my $output;
1.135     bisitz   1481:     if ($img eq 'login') {
                   1482:             # suppress image for Log-in header
                   1483:     } elsif (!$is_custom) {
1.70      raeburn  1484:         if ($img ne 'domlogo') {
1.41      raeburn  1485:             $output .= &mt('Default image:').'<br />';
                   1486:         } else {
                   1487:             $output .= &mt('Default in use:').'<br />';
                   1488:         }
                   1489:     }
1.135     bisitz   1490:     if ($img eq 'login') { # suppress image for Log-in header
                   1491:         $output .= '<td>'.$logincolors;
1.41      raeburn  1492:     } else {
1.135     bisitz   1493:         if ($img_import) {
                   1494:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1495:         }
                   1496:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1497:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1498:         if ($is_custom) {
                   1499:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1500:                        '<input type="checkbox" name="'.
                   1501:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1502:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1503:         } else {
                   1504:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
                   1505:         }
1.41      raeburn  1506:     }
                   1507:     return $output;
                   1508: }
                   1509: 
1.6       raeburn  1510: sub color_pick {
                   1511:     my ($phase,$role,$item,$desc,$curcol) = @_;
                   1512:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
                   1513:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
                   1514:                ');">'.$desc.'</a>';
                   1515:     return $link;
                   1516: }
                   1517: 
1.3       raeburn  1518: sub print_quotas {
1.86      raeburn  1519:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1520:     my $context;
                   1521:     if ($action eq 'quotas') {
                   1522:         $context = 'tools';
                   1523:     } else {
                   1524:         $context = $action;
                   1525:     }
1.101     raeburn  1526:     my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44      raeburn  1527:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1528:     my $typecount = 0;
1.101     raeburn  1529:     my ($css_class,%titles);
1.86      raeburn  1530:     if ($context eq 'requestcourses') {
1.98      raeburn  1531:         @usertools = ('official','unofficial','community');
1.106     raeburn  1532:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1533:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1534:         %titles = &courserequest_titles();
1.163     raeburn  1535:     } elsif ($context eq 'requestauthor') {
                   1536:         @usertools = ('author');
                   1537:         @options = ('norequest','approval','automatic');
                   1538:         %titles = &authorrequest_titles(); 
1.86      raeburn  1539:     } else {
1.162     raeburn  1540:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1541:         %titles = &tool_titles();
1.86      raeburn  1542:     }
1.26      raeburn  1543:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1544:         foreach my $type (@{$types}) {
1.72      raeburn  1545:             my $currdefquota;
1.163     raeburn  1546:             unless (($context eq 'requestcourses') ||
                   1547:                     ($context eq 'requestauthor')) {
1.86      raeburn  1548:                 if (ref($settings) eq 'HASH') {
                   1549:                     if (ref($settings->{defaultquota}) eq 'HASH') {
                   1550:                         $currdefquota = $settings->{defaultquota}->{$type}; 
                   1551:                     } else {
                   1552:                         $currdefquota = $settings->{$type};
                   1553:                     }
1.78      raeburn  1554:                 }
1.72      raeburn  1555:             }
1.3       raeburn  1556:             if (defined($usertypes->{$type})) {
                   1557:                 $typecount ++;
                   1558:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1559:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1560:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1561:                               '<td class="LC_left_item">';
1.101     raeburn  1562:                 if ($context eq 'requestcourses') {
                   1563:                     $datatable .= '<table><tr>';
                   1564:                 }
                   1565:                 my %cell;  
1.72      raeburn  1566:                 foreach my $item (@usertools) {
1.101     raeburn  1567:                     if ($context eq 'requestcourses') {
                   1568:                         my ($curroption,$currlimit);
                   1569:                         if (ref($settings) eq 'HASH') {
                   1570:                             if (ref($settings->{$item}) eq 'HASH') {
                   1571:                                 $curroption = $settings->{$item}->{$type};
                   1572:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1573:                                     $currlimit = $1; 
                   1574:                                 }
                   1575:                             }
                   1576:                         }
                   1577:                         if (!$curroption) {
                   1578:                             $curroption = 'norequest';
                   1579:                         }
                   1580:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1581:                         foreach my $option (@options) {
                   1582:                             my $val = $option;
                   1583:                             if ($option eq 'norequest') {
                   1584:                                 $val = 0;  
                   1585:                             }
                   1586:                             if ($option eq 'validate') {
                   1587:                                 my $canvalidate = 0;
                   1588:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1589:                                     if ($validations{$item}{$type}) {
                   1590:                                         $canvalidate = 1;
                   1591:                                     }
                   1592:                                 }
                   1593:                                 next if (!$canvalidate);
                   1594:                             }
                   1595:                             my $checked = '';
                   1596:                             if ($option eq $curroption) {
                   1597:                                 $checked = ' checked="checked"';
                   1598:                             } elsif ($option eq 'autolimit') {
                   1599:                                 if ($curroption =~ /^autolimit/) {
                   1600:                                     $checked = ' checked="checked"';
                   1601:                                 }                       
                   1602:                             } 
                   1603:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1604:                                   '<input type="radio" name="crsreq_'.$item.
                   1605:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1606:                                   $titles{$option}.'</label>';
1.101     raeburn  1607:                             if ($option eq 'autolimit') {
1.127     raeburn  1608:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1609:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1610:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1611:                             }
1.127     raeburn  1612:                             $cell{$item} .= '</span> ';
1.103     raeburn  1613:                             if ($option eq 'autolimit') {
1.127     raeburn  1614:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1615:                             }
1.101     raeburn  1616:                         }
1.163     raeburn  1617:                     } elsif ($context eq 'requestauthor') {
                   1618:                         my $curroption;
                   1619:                         if (ref($settings) eq 'HASH') {
                   1620:                             $curroption = $settings->{$type};
                   1621:                         }
                   1622:                         if (!$curroption) {
                   1623:                             $curroption = 'norequest';
                   1624:                         }
                   1625:                         foreach my $option (@options) {
                   1626:                             my $val = $option;
                   1627:                             if ($option eq 'norequest') {
                   1628:                                 $val = 0;
                   1629:                             }
                   1630:                             my $checked = '';
                   1631:                             if ($option eq $curroption) {
                   1632:                                 $checked = ' checked="checked"';
                   1633:                             }
                   1634:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1635:                                   '<input type="radio" name="authorreq_'.$type.
                   1636:                                   '" value="'.$val.'"'.$checked.' />'.
                   1637:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1638:                         }
1.101     raeburn  1639:                     } else {
                   1640:                         my $checked = 'checked="checked" ';
                   1641:                         if (ref($settings) eq 'HASH') {
                   1642:                             if (ref($settings->{$item}) eq 'HASH') {
                   1643:                                 if ($settings->{$item}->{$type} == 0) {
                   1644:                                     $checked = '';
                   1645:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1646:                                     $checked =  'checked="checked" ';
                   1647:                                 }
1.78      raeburn  1648:                             }
1.72      raeburn  1649:                         }
1.101     raeburn  1650:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1651:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1652:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1653:                                       '</label></span>&nbsp; ';
1.72      raeburn  1654:                     }
1.101     raeburn  1655:                 }
                   1656:                 if ($context eq 'requestcourses') {
                   1657:                     $datatable .= '</tr><tr>';
                   1658:                     foreach my $item (@usertools) {
1.106     raeburn  1659:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1660:                     }
                   1661:                     $datatable .= '</tr></table>';
1.72      raeburn  1662:                 }
1.86      raeburn  1663:                 $datatable .= '</td>';
1.163     raeburn  1664:                 unless (($context eq 'requestcourses') ||
                   1665:                         ($context eq 'requestauthor')) {
1.86      raeburn  1666:                     $datatable .= 
                   1667:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1668:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1669:                               '" value="'.$currdefquota.
1.86      raeburn  1670:                               '" size="5" /> Mb</span></td>';
                   1671:                 }
                   1672:                 $datatable .= '</tr>';
1.3       raeburn  1673:             }
                   1674:         }
                   1675:     }
1.163     raeburn  1676:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1677:         $defaultquota = '20';
                   1678:         if (ref($settings) eq 'HASH') {
                   1679:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1680:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1681:             } elsif (defined($settings->{'default'})) {
                   1682:                 $defaultquota = $settings->{'default'};
                   1683:             }
1.3       raeburn  1684:         }
                   1685:     }
                   1686:     $typecount ++;
                   1687:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1688:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1689:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1690:                   '<td class="LC_left_item">';
1.101     raeburn  1691:     if ($context eq 'requestcourses') {
                   1692:         $datatable .= '<table><tr>';
                   1693:     }
                   1694:     my %defcell;
1.72      raeburn  1695:     foreach my $item (@usertools) {
1.101     raeburn  1696:         if ($context eq 'requestcourses') {
                   1697:             my ($curroption,$currlimit);
                   1698:             if (ref($settings) eq 'HASH') {
                   1699:                 if (ref($settings->{$item}) eq 'HASH') {
                   1700:                     $curroption = $settings->{$item}->{'default'};
                   1701:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1702:                         $currlimit = $1;
                   1703:                     }
                   1704:                 }
                   1705:             }
                   1706:             if (!$curroption) {
                   1707:                 $curroption = 'norequest';
                   1708:             }
                   1709:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1710:             foreach my $option (@options) {
                   1711:                 my $val = $option;
                   1712:                 if ($option eq 'norequest') {
                   1713:                     $val = 0;
                   1714:                 }
                   1715:                 if ($option eq 'validate') {
                   1716:                     my $canvalidate = 0;
                   1717:                     if (ref($validations{$item}) eq 'HASH') {
                   1718:                         if ($validations{$item}{'default'}) {
                   1719:                             $canvalidate = 1;
                   1720:                         }
                   1721:                     }
                   1722:                     next if (!$canvalidate);
                   1723:                 }
                   1724:                 my $checked = '';
                   1725:                 if ($option eq $curroption) {
                   1726:                     $checked = ' checked="checked"';
                   1727:                 } elsif ($option eq 'autolimit') {
                   1728:                     if ($curroption =~ /^autolimit/) {
                   1729:                         $checked = ' checked="checked"';
                   1730:                     }
                   1731:                 }
                   1732:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1733:                                   '<input type="radio" name="crsreq_'.$item.
                   1734:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1735:                                   $titles{$option}.'</label>';
                   1736:                 if ($option eq 'autolimit') {
1.127     raeburn  1737:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1738:                                        $item.'_limit_default" size="1" '.
                   1739:                                        'value="'.$currlimit.'" />';
                   1740:                 }
1.127     raeburn  1741:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1742:                 if ($option eq 'autolimit') {
1.127     raeburn  1743:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1744:                 }
1.101     raeburn  1745:             }
1.163     raeburn  1746:         } elsif ($context eq 'requestauthor') {
                   1747:             my $curroption;
                   1748:             if (ref($settings) eq 'HASH') {
1.172     raeburn  1749:                 $curroption = $settings->{'default'};
1.163     raeburn  1750:             }
                   1751:             if (!$curroption) {
                   1752:                 $curroption = 'norequest';
                   1753:             }
                   1754:             foreach my $option (@options) {
                   1755:                 my $val = $option;
                   1756:                 if ($option eq 'norequest') {
                   1757:                     $val = 0;
                   1758:                 }
                   1759:                 my $checked = '';
                   1760:                 if ($option eq $curroption) {
                   1761:                     $checked = ' checked="checked"';
                   1762:                 }
                   1763:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1764:                               '<input type="radio" name="authorreq_default"'.
                   1765:                               ' value="'.$val.'"'.$checked.' />'.
                   1766:                               $titles{$option}.'</label></span>&nbsp; ';
                   1767:             }
1.101     raeburn  1768:         } else {
                   1769:             my $checked = 'checked="checked" ';
                   1770:             if (ref($settings) eq 'HASH') {
                   1771:                 if (ref($settings->{$item}) eq 'HASH') {
                   1772:                     if ($settings->{$item}->{'default'} == 0) {
                   1773:                         $checked = '';
                   1774:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1775:                         $checked = 'checked="checked" ';
                   1776:                     }
1.78      raeburn  1777:                 }
1.72      raeburn  1778:             }
1.101     raeburn  1779:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1780:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1781:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1782:                           '</label></span>&nbsp; ';
                   1783:         }
                   1784:     }
                   1785:     if ($context eq 'requestcourses') {
                   1786:         $datatable .= '</tr><tr>';
                   1787:         foreach my $item (@usertools) {
1.106     raeburn  1788:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1789:         }
1.101     raeburn  1790:         $datatable .= '</tr></table>';
1.72      raeburn  1791:     }
1.86      raeburn  1792:     $datatable .= '</td>';
1.163     raeburn  1793:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1794:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1795:                       '<input type="text" name="defaultquota" value="'.
                   1796:                       $defaultquota.'" size="5" /> Mb</span></td>';
                   1797:     }
                   1798:     $datatable .= '</tr>';
1.72      raeburn  1799:     $typecount ++;
                   1800:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1801:     $datatable .= '<tr'.$css_class.'>'.
1.104     raeburn  1802:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
                   1803:     if ($context eq 'requestcourses') {
1.109     raeburn  1804:         $datatable .= &mt('(overrides affiliation, if set)').
                   1805:                       '</td>'.
                   1806:                       '<td class="LC_left_item">'.
                   1807:                       '<table><tr>';
1.101     raeburn  1808:     } else {
1.109     raeburn  1809:         $datatable .= &mt('(overrides affiliation, if checked)').
                   1810:                       '</td>'.
                   1811:                       '<td class="LC_left_item" colspan="2">'.
                   1812:                       '<br />';
1.101     raeburn  1813:     }
                   1814:     my %advcell;
1.72      raeburn  1815:     foreach my $item (@usertools) {
1.101     raeburn  1816:         if ($context eq 'requestcourses') {
                   1817:             my ($curroption,$currlimit);
                   1818:             if (ref($settings) eq 'HASH') {
                   1819:                 if (ref($settings->{$item}) eq 'HASH') {
                   1820:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   1821:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1822:                         $currlimit = $1;
                   1823:                     }
                   1824:                 }
                   1825:             }
                   1826:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  1827:             my $checked = '';
                   1828:             if ($curroption eq '') {
                   1829:                 $checked = ' checked="checked"';
                   1830:             }
                   1831:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1832:                                '<input type="radio" name="crsreq_'.$item.
                   1833:                                '__LC_adv" value=""'.$checked.' />'.
                   1834:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  1835:             foreach my $option (@options) {
                   1836:                 my $val = $option;
                   1837:                 if ($option eq 'norequest') {
                   1838:                     $val = 0;
                   1839:                 }
                   1840:                 if ($option eq 'validate') {
                   1841:                     my $canvalidate = 0;
                   1842:                     if (ref($validations{$item}) eq 'HASH') {
                   1843:                         if ($validations{$item}{'_LC_adv'}) {
                   1844:                             $canvalidate = 1;
                   1845:                         }
                   1846:                     }
                   1847:                     next if (!$canvalidate);
                   1848:                 }
                   1849:                 my $checked = '';
1.104     raeburn  1850:                 if ($val eq $curroption) {
1.101     raeburn  1851:                     $checked = ' checked="checked"';
                   1852:                 } elsif ($option eq 'autolimit') {
                   1853:                     if ($curroption =~ /^autolimit/) {
                   1854:                         $checked = ' checked="checked"';
                   1855:                     }
                   1856:                 }
                   1857:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1858:                                   '<input type="radio" name="crsreq_'.$item.
                   1859:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1860:                                   $titles{$option}.'</label>';
                   1861:                 if ($option eq 'autolimit') {
1.127     raeburn  1862:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1863:                                        $item.'_limit__LC_adv" size="1" '.
                   1864:                                        'value="'.$currlimit.'" />';
                   1865:                 }
1.127     raeburn  1866:                 $advcell{$item} .= '</span> ';
1.104     raeburn  1867:                 if ($option eq 'autolimit') {
1.127     raeburn  1868:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1869:                 }
1.101     raeburn  1870:             }
1.163     raeburn  1871:         } elsif ($context eq 'requestauthor') {
                   1872:             my $curroption;
                   1873:             if (ref($settings) eq 'HASH') {
                   1874:                 $curroption = $settings->{'_LC_adv'};
                   1875:             }
                   1876:             my $checked = '';
                   1877:             if ($curroption eq '') {
                   1878:                 $checked = ' checked="checked"';
                   1879:             }
                   1880:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1881:                           '<input type="radio" name="authorreq__LC_adv"'.
                   1882:                           ' value=""'.$checked.' />'.
                   1883:                           &mt('No override set').'</label></span>&nbsp; ';
                   1884:             foreach my $option (@options) {
                   1885:                 my $val = $option;
                   1886:                 if ($option eq 'norequest') {
                   1887:                     $val = 0;
                   1888:                 }
                   1889:                 my $checked = '';
                   1890:                 if ($val eq $curroption) {
                   1891:                     $checked = ' checked="checked"';
                   1892:                 }
                   1893:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  1894:                               '<input type="radio" name="authorreq__LC_adv"'.
                   1895:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  1896:                               $titles{$option}.'</label></span>&nbsp; ';
                   1897:             }
1.101     raeburn  1898:         } else {
                   1899:             my $checked = 'checked="checked" ';
                   1900:             if (ref($settings) eq 'HASH') {
                   1901:                 if (ref($settings->{$item}) eq 'HASH') {
                   1902:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   1903:                         $checked = '';
                   1904:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   1905:                         $checked = 'checked="checked" ';
                   1906:                     }
1.79      raeburn  1907:                 }
1.72      raeburn  1908:             }
1.101     raeburn  1909:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1910:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1911:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   1912:                           '</label></span>&nbsp; ';
                   1913:         }
                   1914:     }
                   1915:     if ($context eq 'requestcourses') {
                   1916:         $datatable .= '</tr><tr>';
                   1917:         foreach my $item (@usertools) {
1.106     raeburn  1918:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  1919:         }
1.101     raeburn  1920:         $datatable .= '</tr></table>';
1.72      raeburn  1921:     }
1.98      raeburn  1922:     $datatable .= '</td></tr>';
1.30      raeburn  1923:     $$rowtotal += $typecount;
1.3       raeburn  1924:     return $datatable;
                   1925: }
                   1926: 
1.163     raeburn  1927: sub print_requestmail {
                   1928:     my ($dom,$action,$settings,$rowtotal) = @_;
1.104     raeburn  1929:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102     raeburn  1930:     $now = time;
                   1931:     $rows = 0;
                   1932:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
                   1933:     foreach my $server (keys(%dompersonnel)) {
                   1934:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   1935:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   1936:             if (!grep(/^$uname:$udom$/,@domcoord)) {
                   1937:                 push(@domcoord,$uname.':'.$udom);
                   1938:             }
                   1939:         }
                   1940:     }
                   1941:     if (ref($settings) eq 'HASH') {
                   1942:         if (ref($settings->{'notify'}) eq 'HASH') {
                   1943:             if ($settings->{'notify'}{'approval'} ne '') {
1.104     raeburn  1944:                @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102     raeburn  1945:             }
                   1946:         }
                   1947:     }
1.104     raeburn  1948:     if (@currapproval) {
                   1949:         foreach my $dc (@currapproval) {
1.102     raeburn  1950:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
                   1951:                 push(@domcoord,$dc);
                   1952:             }
                   1953:         }
                   1954:     }
                   1955:     @domcoord = sort(@domcoord);
                   1956:     my $numinrow = 4;
                   1957:     my $numdc = @domcoord;
                   1958:     my $css_class = 'class="LC_odd_row"';
1.163     raeburn  1959:     my $text;
                   1960:     if ($action eq 'requestcourses') {
                   1961:         $text = &mt('Receive notification of course requests requiring approval');
                   1962:     } else {
                   1963:         $text = &mt('Receive notification of authoring space requests requiring approval')
                   1964:     }
                   1965:     $datatable = '<tr '.$css_class.'>'.
                   1966:                  ' <td>'.$text.'</td>'.
1.102     raeburn  1967:                  ' <td class="LC_left_item">';
                   1968:     if (@domcoord > 0) {
                   1969:         $datatable .= '<table>';
                   1970:         for (my $i=0; $i<$numdc; $i++) {
                   1971:             my $rem = $i%($numinrow);
                   1972:             if ($rem == 0) {
                   1973:                 if ($i > 0) {
                   1974:                     $datatable .= '</tr>';
                   1975:                 }
                   1976:                 $datatable .= '<tr>';
                   1977:                 $rows ++;
                   1978:             }
                   1979:             my $check = ' ';
1.104     raeburn  1980:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102     raeburn  1981:                 $check = ' checked="checked" ';
                   1982:             }
                   1983:             my ($uname,$udom) = split(':',$domcoord[$i]);
                   1984:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
                   1985:             if ($i == $numdc-1) {
                   1986:                 my $colsleft = $numinrow-$rem;
                   1987:                 if ($colsleft > 1) {
                   1988:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   1989:                 } else {
                   1990:                     $datatable .= '<td class="LC_left_item">';
                   1991:                 }
                   1992:             } else {
                   1993:                 $datatable .= '<td class="LC_left_item">';
                   1994:             }
                   1995:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1996:                           '<input type="checkbox" name="reqapprovalnotify" '.
                   1997:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175     bisitz   1998:                           $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102     raeburn  1999:         }
                   2000:         $datatable .= '</tr></table>';
                   2001:     } else {
                   2002:         $datatable .= &mt('There are no active Domain Coordinators');
                   2003:         $rows ++;
                   2004:     }
                   2005:     $datatable .='</td></tr>';
                   2006:     $$rowtotal += $rows;
                   2007:     return $datatable;
                   2008: }
                   2009: 
1.3       raeburn  2010: sub print_autoenroll {
1.30      raeburn  2011:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2012:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  2013:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  2014:     if (ref($settings) eq 'HASH') {
                   2015:         if (exists($settings->{'run'})) {
                   2016:             if ($settings->{'run'} eq '0') {
                   2017:                 $runoff = ' checked="checked" ';
                   2018:                 $runon = ' ';
                   2019:             } else {
                   2020:                 $runon = ' checked="checked" ';
                   2021:                 $runoff = ' ';
                   2022:             }
                   2023:         } else {
                   2024:             if ($autorun) {
                   2025:                 $runon = ' checked="checked" ';
                   2026:                 $runoff = ' ';
                   2027:             } else {
                   2028:                 $runoff = ' checked="checked" ';
                   2029:                 $runon = ' ';
                   2030:             }
                   2031:         }
1.129     raeburn  2032:         if (exists($settings->{'co-owners'})) {
                   2033:             if ($settings->{'co-owners'} eq '0') {
                   2034:                 $coownersoff = ' checked="checked" ';
                   2035:                 $coownerson = ' ';
                   2036:             } else {
                   2037:                 $coownerson = ' checked="checked" ';
                   2038:                 $coownersoff = ' ';
                   2039:             }
                   2040:         } else {
                   2041:             $coownersoff = ' checked="checked" ';
                   2042:             $coownerson = ' ';
                   2043:         }
1.3       raeburn  2044:         if (exists($settings->{'sender_domain'})) {
                   2045:             $defdom = $settings->{'sender_domain'};
                   2046:         }
1.14      raeburn  2047:     } else {
                   2048:         if ($autorun) {
                   2049:             $runon = ' checked="checked" ';
                   2050:             $runoff = ' ';
                   2051:         } else {
                   2052:             $runoff = ' checked="checked" ';
                   2053:             $runon = ' ';
                   2054:         }
1.3       raeburn  2055:     }
                   2056:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2057:     my $notif_sender;
                   2058:     if (ref($settings) eq 'HASH') {
                   2059:         $notif_sender = $settings->{'sender_uname'};
                   2060:     }
1.3       raeburn  2061:     my $datatable='<tr class="LC_odd_row">'.
                   2062:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2063:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2064:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2065:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2066:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2067:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2068:                   '</tr><tr>'.
                   2069:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2070:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2071:                   &mt('username').':&nbsp;'.
                   2072:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2073:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2074:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2075:                   '<tr class="LC_odd_row">'.
                   2076:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2077:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2078:                   '<input type="radio" name="autoassign_coowners"'.
                   2079:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2080:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2081:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2082:                   '</tr>';
                   2083:     $$rowtotal += 3;
1.3       raeburn  2084:     return $datatable;
                   2085: }
                   2086: 
                   2087: sub print_autoupdate {
1.30      raeburn  2088:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2089:     my $datatable;
                   2090:     if ($position eq 'top') {
                   2091:         my $updateon = ' ';
                   2092:         my $updateoff = ' checked="checked" ';
                   2093:         my $classlistson = ' ';
                   2094:         my $classlistsoff = ' checked="checked" ';
                   2095:         if (ref($settings) eq 'HASH') {
                   2096:             if ($settings->{'run'} eq '1') {
                   2097:                 $updateon = $updateoff;
                   2098:                 $updateoff = ' ';
                   2099:             }
                   2100:             if ($settings->{'classlists'} eq '1') {
                   2101:                 $classlistson = $classlistsoff;
                   2102:                 $classlistsoff = ' ';
                   2103:             }
                   2104:         }
                   2105:         my %title = (
                   2106:                    run => 'Auto-update active?',
                   2107:                    classlists => 'Update information in classlists?',
                   2108:                     );
                   2109:         $datatable = '<tr class="LC_odd_row">'. 
                   2110:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2111:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2112:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2113:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2114:                   '<label><input type="radio" name="autoupdate_run"'.
                   2115:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2116:                   '</tr><tr>'.
                   2117:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2118:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2119:                   '<label><input type="radio" name="classlists"'.
                   2120:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2121:                   '<label><input type="radio" name="classlists"'.
                   2122:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2123:                   '</tr>';
1.30      raeburn  2124:         $$rowtotal += 2;
1.131     raeburn  2125:     } elsif ($position eq 'middle') {
                   2126:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2127:         my $numinrow = 3;
                   2128:         my $locknamesettings;
                   2129:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2130:                                      $dom,$numinrow,$othertitle,
                   2131:                                     'lockablenames');
                   2132:         $$rowtotal ++;
1.3       raeburn  2133:     } else {
1.44      raeburn  2134:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2135:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2136:                       'permanentemail','id');
1.33      raeburn  2137:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2138:         my $numrows = 0;
1.26      raeburn  2139:         if (ref($types) eq 'ARRAY') {
                   2140:             if (@{$types} > 0) {
                   2141:                 $datatable = 
                   2142:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2143:                                          \@fields,$types,\$numrows);
1.30      raeburn  2144:                     $$rowtotal += @{$types}; 
1.26      raeburn  2145:             }
1.3       raeburn  2146:         }
                   2147:         $datatable .= 
                   2148:             &usertype_update_row($settings,{'default' => $othertitle},
                   2149:                                  \%fieldtitles,\@fields,['default'],
                   2150:                                  \$numrows);
1.30      raeburn  2151:         $$rowtotal ++;     
1.3       raeburn  2152:     }
                   2153:     return $datatable;
                   2154: }
                   2155: 
1.125     raeburn  2156: sub print_autocreate {
                   2157:     my ($dom,$settings,$rowtotal) = @_;
                   2158:     my (%createon,%createoff);
                   2159:     my $curr_dc;
                   2160:     my @types = ('xml','req');
                   2161:     if (ref($settings) eq 'HASH') {
                   2162:         foreach my $item (@types) {
                   2163:             $createoff{$item} = ' checked="checked" ';
                   2164:             $createon{$item} = ' ';
                   2165:             if (exists($settings->{$item})) {
                   2166:                 if ($settings->{$item}) {
                   2167:                     $createon{$item} = ' checked="checked" ';
                   2168:                     $createoff{$item} = ' ';
                   2169:                 }
                   2170:             }
                   2171:         }
                   2172:         $curr_dc = $settings->{'xmldc'};
                   2173:     } else {
                   2174:         foreach my $item (@types) {
                   2175:             $createoff{$item} = ' checked="checked" ';
                   2176:             $createon{$item} = ' ';
                   2177:         }
                   2178:     }
                   2179:     $$rowtotal += 2;
                   2180:     my $datatable='<tr class="LC_odd_row">'.
                   2181:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2182:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2183:                   '<input type="radio" name="autocreate_xml"'.
                   2184:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2185:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2186:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2187:                   '</td></tr><tr>'.
                   2188:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2189:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2190:                   '<input type="radio" name="autocreate_req"'.
                   2191:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2192:                   '<label><input type="radio" name="autocreate_req"'.
                   2193:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125     raeburn  2194:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
                   2195:     if ($numdc > 1) {
1.143     raeburn  2196:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                   2197:                       &mt('Course creation processed as: (choose Dom. Coord.)').
                   2198:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125     raeburn  2199:         $$rowtotal ++ ;
                   2200:     } else {
1.143     raeburn  2201:         $datatable .= $dctable.'</td></tr>';
1.125     raeburn  2202:     }
                   2203:     return $datatable;
                   2204: }
                   2205: 
1.23      raeburn  2206: sub print_directorysrch {
1.30      raeburn  2207:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  2208:     my $srchon = ' ';
                   2209:     my $srchoff = ' checked="checked" ';
1.25      raeburn  2210:     my ($exacton,$containson,$beginson);
1.24      raeburn  2211:     my $localon = ' ';
                   2212:     my $localoff = ' checked="checked" ';
1.23      raeburn  2213:     if (ref($settings) eq 'HASH') {
                   2214:         if ($settings->{'available'} eq '1') {
                   2215:             $srchon = $srchoff;
                   2216:             $srchoff = ' ';
                   2217:         }
1.24      raeburn  2218:         if ($settings->{'localonly'} eq '1') {
                   2219:             $localon = $localoff;
                   2220:             $localoff = ' ';
                   2221:         }
1.25      raeburn  2222:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2223:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   2224:                 if ($type eq 'exact') {
                   2225:                     $exacton = ' checked="checked" ';
                   2226:                 } elsif ($type eq 'contains') {
                   2227:                     $containson = ' checked="checked" ';
                   2228:                 } elsif ($type eq 'begins') {
                   2229:                     $beginson = ' checked="checked" ';
                   2230:                 }
                   2231:             }
                   2232:         } else {
                   2233:             if ($settings->{'searchtypes'} eq 'exact') {
                   2234:                 $exacton = ' checked="checked" ';
                   2235:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2236:                 $containson = ' checked="checked" ';
                   2237:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   2238:                 $exacton = ' checked="checked" ';
                   2239:                 $containson = ' checked="checked" ';
                   2240:             }
1.23      raeburn  2241:         }
                   2242:     }
                   2243:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  2244:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2245: 
                   2246:     my $numinrow = 4;
1.26      raeburn  2247:     my $cansrchrow = 0;
1.23      raeburn  2248:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2249:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2250:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2251:                   '<input type="radio" name="dirsrch_available"'.
                   2252:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2253:                   '<label><input type="radio" name="dirsrch_available"'.
                   2254:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2255:                   '</tr><tr>'.
1.30      raeburn  2256:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2257:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2258:                   '<input type="radio" name="dirsrch_localonly"'.
                   2259:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2260:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2261:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2262:                   '</tr>';
1.30      raeburn  2263:     $$rowtotal += 2;
1.26      raeburn  2264:     if (ref($usertypes) eq 'HASH') {
                   2265:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2266:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2267:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2268:             $cansrchrow = 1;
                   2269:         }
                   2270:     }
                   2271:     if ($cansrchrow) {
1.30      raeburn  2272:         $$rowtotal ++;
1.26      raeburn  2273:         $datatable .= '<tr>';
                   2274:     } else {
                   2275:         $datatable .= '<tr class="LC_odd_row">';
                   2276:     }
1.30      raeburn  2277:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2278:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2279:     foreach my $title (@{$titleorder}) {
                   2280:         if (defined($searchtitles->{$title})) {
                   2281:             my $check = ' ';
1.93      raeburn  2282:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2283:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2284:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2285:                         $check = ' checked="checked" ';
                   2286:                     }
1.25      raeburn  2287:                 }
                   2288:             }
                   2289:             $datatable .= '<td class="LC_left_item">'.
                   2290:                           '<span class="LC_nobreak"><label>'.
                   2291:                           '<input type="checkbox" name="searchby" '.
                   2292:                           'value="'.$title.'"'.$check.'/>'.
                   2293:                           $searchtitles->{$title}.'</label></span></td>';
                   2294:         }
                   2295:     }
1.26      raeburn  2296:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2297:     $$rowtotal ++;
1.26      raeburn  2298:     if ($cansrchrow) {
                   2299:         $datatable .= '<tr class="LC_odd_row">';
                   2300:     } else {
                   2301:         $datatable .= '<tr>';
                   2302:     }
1.30      raeburn  2303:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2304:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2305:                   '<span class="LC_nobreak"><label>'.
                   2306:                   '<input type="checkbox" name="searchtypes" '.
                   2307:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2308:                   '</label>&nbsp;'.
                   2309:                   '<label><input type="checkbox" name="searchtypes" '.
                   2310:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2311:                   '</label>&nbsp;'.
                   2312:                   '<label><input type="checkbox" name="searchtypes" '.
                   2313:                   $containson.' value="contains" />'.&mt('Contains').
                   2314:                   '</label></span></td></tr>';
1.30      raeburn  2315:     $$rowtotal ++;
1.25      raeburn  2316:     return $datatable;
                   2317: }
                   2318: 
1.28      raeburn  2319: sub print_contacts {
1.30      raeburn  2320:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2321:     my $datatable;
                   2322:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2323:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2324:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.190   ! raeburn  2325:                     'requestsmail','updatesmail');
1.28      raeburn  2326:     foreach my $type (@mailings) {
                   2327:         $otheremails{$type} = '';
                   2328:     }
1.134     raeburn  2329:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2330:     if (ref($settings) eq 'HASH') {
                   2331:         foreach my $item (@contacts) {
                   2332:             if (exists($settings->{$item})) {
                   2333:                 $to{$item} = $settings->{$item};
                   2334:             }
                   2335:         }
                   2336:         foreach my $type (@mailings) {
                   2337:             if (exists($settings->{$type})) {
                   2338:                 if (ref($settings->{$type}) eq 'HASH') {
                   2339:                     foreach my $item (@contacts) {
                   2340:                         if ($settings->{$type}{$item}) {
                   2341:                             $checked{$type}{$item} = ' checked="checked" ';
                   2342:                         }
                   2343:                     }
                   2344:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2345:                     if ($type eq 'helpdeskmail') {
                   2346:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2347:                     }
1.28      raeburn  2348:                 }
1.89      raeburn  2349:             } elsif ($type eq 'lonstatusmail') {
                   2350:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2351:             }
                   2352:         }
                   2353:     } else {
                   2354:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2355:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2356:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2357:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2358:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2359:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2360:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190   ! raeburn  2361:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2362:     }
                   2363:     my ($titles,$short_titles) = &contact_titles();
                   2364:     my $rownum = 0;
                   2365:     my $css_class;
                   2366:     foreach my $item (@contacts) {
1.69      raeburn  2367:         $rownum ++;
                   2368:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2369:         $datatable .= '<tr'.$css_class.'>'. 
                   2370:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2371:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2372:                   '<input type="text" name="'.$item.'" value="'.
                   2373:                   $to{$item}.'" /></td></tr>';
                   2374:     }
                   2375:     foreach my $type (@mailings) {
1.69      raeburn  2376:         $rownum ++;
                   2377:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2378:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2379:                       '<td><span class="LC_nobreak">'.
                   2380:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2381:                       '<td class="LC_left_item">'.
                   2382:                       '<span class="LC_nobreak">';
                   2383:         foreach my $item (@contacts) {
                   2384:             $datatable .= '<label>'.
                   2385:                           '<input type="checkbox" name="'.$type.'"'.
                   2386:                           $checked{$type}{$item}.
                   2387:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2388:                           '</label>&nbsp;';
                   2389:         }
                   2390:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2391:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2392:                       'value="'.$otheremails{$type}.'"  />';
                   2393:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2394:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2395:                           '<input type="text" name="'.$type.'_bcc" '.
                   2396:                           'value="'.$bccemails{$type}.'"  />';
                   2397:         }
                   2398:         $datatable .= '</td></tr>'."\n";
1.28      raeburn  2399:     }
1.30      raeburn  2400:     $$rowtotal += $rownum;
1.28      raeburn  2401:     return $datatable;
                   2402: }
                   2403: 
1.118     jms      2404: sub print_helpsettings {
1.168     raeburn  2405:     my ($dom,$confname,$settings,$rowtotal) = @_;
                   2406:     my ($datatable,$itemcount);
1.166     raeburn  2407:     $itemcount = 1;
1.168     raeburn  2408:     my (%choices,%defaultchecked,@toggles);
                   2409:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   2410:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   2411:                                  &mt('LON-CAPA bug tracker'),600,500));
                   2412:     %defaultchecked = ('submitbugs' => 'on');
                   2413:     @toggles = ('submitbugs',);
1.166     raeburn  2414: 
1.168     raeburn  2415:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2416:                                                  \%choices,$itemcount);
1.166     raeburn  2417:     return $datatable;
1.121     raeburn  2418: }
                   2419: 
                   2420: sub radiobutton_prefs {
                   2421:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
                   2422:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2423:                    (ref($choices) eq 'HASH'));
                   2424: 
1.170     raeburn  2425:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  2426: 
                   2427:     foreach my $item (@{$toggles}) {
                   2428:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2429:             $checkedon{$item} = ' checked="checked" ';
                   2430:             $checkedoff{$item} = ' ';
1.121     raeburn  2431:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2432:             $checkedoff{$item} = ' checked="checked" ';
                   2433:             $checkedon{$item} = ' ';
                   2434:         }
                   2435:     }
                   2436:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2437:         foreach my $item (@{$toggles}) {
1.118     jms      2438:             if ($settings->{$item} eq '1') {
                   2439:                 $checkedon{$item} =  ' checked="checked" ';
                   2440:                 $checkedoff{$item} = ' ';
                   2441:             } elsif ($settings->{$item} eq '0') {
                   2442:                 $checkedoff{$item} =  ' checked="checked" ';
                   2443:                 $checkedon{$item} = ' ';
                   2444:             }
                   2445:         }
1.121     raeburn  2446:     }
                   2447:     foreach my $item (@{$toggles}) {
1.118     jms      2448:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2449:         $datatable .=
                   2450:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118     jms      2451:             '</span></td>'.
                   2452:             '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2453:             '<label><input type="radio" name="'.
                   2454:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   2455:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   2456:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2457:             '</span></td>'.
                   2458:             '</tr>';
                   2459:         $itemcount ++;
1.121     raeburn  2460:     }
                   2461:     return ($datatable,$itemcount);
                   2462: }
                   2463: 
                   2464: sub print_coursedefaults {
1.139     raeburn  2465:     my ($position,$dom,$settings,$rowtotal) = @_;
1.121     raeburn  2466:     my ($css_class,$datatable);
                   2467:     my $itemcount = 1;
1.139     raeburn  2468:     if ($position eq 'top') {
                   2469:         my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2470:         %choices =
                   2471:             &Apache::lonlocal::texthash (
                   2472:                 canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
                   2473:         );
                   2474:         %defaultchecked = ('canuse_pdfforms' => 'off');
                   2475:         @toggles = ('canuse_pdfforms',);
                   2476:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121     raeburn  2477:                                                  \%choices,$itemcount);
1.139     raeburn  2478:         $$rowtotal += $itemcount;
                   2479:     } else {
                   2480:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2481:         my %choices =
                   2482:             &Apache::lonlocal::texthash (
                   2483:                 anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   2484:         );
                   2485:         my $currdefresponder;
                   2486:         if (ref($settings) eq 'HASH') {
                   2487:             $currdefresponder = $settings->{'anonsurvey_threshold'};
                   2488:         }
                   2489:         if (!$currdefresponder) {
                   2490:             $currdefresponder = 10;
                   2491:         } elsif ($currdefresponder < 1) {
                   2492:             $currdefresponder = 1;
                   2493:         }
                   2494:         $datatable .=
                   2495:                '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
                   2496:                 '</span></td>'.
                   2497:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2498:                 '<input type="text" name="anonsurvey_threshold"'.
                   2499:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
                   2500:                 '</td></tr>';
                   2501:     }
1.121     raeburn  2502:     return $datatable;
1.118     jms      2503: }
                   2504: 
1.137     raeburn  2505: sub print_usersessions {
                   2506:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2507:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  2508:     my (%by_ip,%by_location,@intdoms);
                   2509:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  2510: 
                   2511:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  2512:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  2513:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  2514:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  2515:     my $itemcount = 1;
                   2516:     if ($position eq 'top') {
1.152     raeburn  2517:         if (keys(%serverhomes) > 1) {
1.145     raeburn  2518:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.152     raeburn  2519:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145     raeburn  2520:         } else {
1.140     raeburn  2521:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2522:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  2523:         }
1.137     raeburn  2524:     } else {
1.145     raeburn  2525:         if (keys(%by_location) == 0) {
                   2526:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2527:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  2528:         } else {
                   2529:             my %lt = &usersession_titles();
                   2530:             my $numinrow = 5;
                   2531:             my $prefix;
                   2532:             my @types;
                   2533:             if ($position eq 'bottom') {
                   2534:                 $prefix = 'remote';
                   2535:                 @types = ('version','excludedomain','includedomain');
                   2536:             } else {
                   2537:                 $prefix = 'hosted';
                   2538:                 @types = ('excludedomain','includedomain');
                   2539:             }
                   2540:             my (%current,%checkedon,%checkedoff);
                   2541:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   2542:             my @locations = sort(keys(%by_location));
                   2543:             foreach my $type (@types) {
                   2544:                 $checkedon{$type} = '';
                   2545:                 $checkedoff{$type} = ' checked="checked"';
                   2546:             }
                   2547:             if (ref($settings) eq 'HASH') {
                   2548:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   2549:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   2550:                         $current{$key} = $settings->{$prefix}{$key};
                   2551:                         if ($key eq 'version') {
                   2552:                             if ($current{$key} ne '') {
                   2553:                                 $checkedon{$key} = ' checked="checked"';
                   2554:                                 $checkedoff{$key} = '';
                   2555:                             }
                   2556:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   2557:                             $checkedon{$key} = ' checked="checked"';
                   2558:                             $checkedoff{$key} = '';
                   2559:                         }
1.137     raeburn  2560:                     }
                   2561:                 }
                   2562:             }
1.145     raeburn  2563:             foreach my $type (@types) {
                   2564:                 next if ($type ne 'version' && !@locations);
                   2565:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2566:                 $datatable .= '<tr'.$css_class.'>
                   2567:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   2568:                                <span class="LC_nobreak">&nbsp;
                   2569:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   2570:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   2571:                 if ($type eq 'version') {
                   2572:                     my $selector = '<select name="'.$prefix.'_version">';
                   2573:                     foreach my $version (@lcversions) {
                   2574:                         my $selected = '';
                   2575:                         if ($current{'version'} eq $version) {
                   2576:                             $selected = ' selected="selected"';
                   2577:                         }
                   2578:                         $selector .= ' <option value="'.$version.'"'.
                   2579:                                      $selected.'>'.$version.'</option>';
                   2580:                     }
                   2581:                     $selector .= '</select> ';
                   2582:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   2583:                 } else {
                   2584:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   2585:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   2586:                                  ' />'.('&nbsp;'x2).
                   2587:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   2588:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   2589:                                  "\n".
                   2590:                                  '</div><div><table>';
                   2591:                     my $rem;
                   2592:                     for (my $i=0; $i<@locations; $i++) {
                   2593:                         my ($showloc,$value,$checkedtype);
                   2594:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   2595:                             my $ip = $by_location{$locations[$i]}->[0];
                   2596:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   2597:                                  $value = join(':',@{$by_ip{$ip}});
                   2598:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   2599:                                 if (ref($current{$type}) eq 'ARRAY') {
                   2600:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   2601:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   2602:                                             $checkedtype = ' checked="checked"';
                   2603:                                             last;
                   2604:                                         }
                   2605:                                     }
1.138     raeburn  2606:                                 }
                   2607:                             }
                   2608:                         }
1.145     raeburn  2609:                         $rem = $i%($numinrow);
                   2610:                         if ($rem == 0) {
                   2611:                             if ($i > 0) {
                   2612:                                 $datatable .= '</tr>';
                   2613:                             }
                   2614:                             $datatable .= '<tr>';
                   2615:                         }
                   2616:                         $datatable .= '<td class="LC_left_item">'.
                   2617:                                       '<span class="LC_nobreak"><label>'.
                   2618:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   2619:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   2620:                                       '</label></span></td>';
1.137     raeburn  2621:                     }
1.145     raeburn  2622:                     $rem = @locations%($numinrow);
                   2623:                     my $colsleft = $numinrow - $rem;
                   2624:                     if ($colsleft > 1 ) {
                   2625:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2626:                                       '&nbsp;</td>';
                   2627:                     } elsif ($colsleft == 1) {
                   2628:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  2629:                     }
1.145     raeburn  2630:                     $datatable .= '</tr></table>';
1.137     raeburn  2631:                 }
1.145     raeburn  2632:                 $datatable .= '</td></tr>';
                   2633:                 $itemcount ++;
1.137     raeburn  2634:             }
                   2635:         }
                   2636:     }
                   2637:     $$rowtotal += $itemcount;
                   2638:     return $datatable;
                   2639: }
                   2640: 
1.138     raeburn  2641: sub build_location_hashes {
                   2642:     my ($intdoms,$by_ip,$by_location) = @_;
                   2643:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   2644:                   (ref($by_location) eq 'HASH')); 
                   2645:     my %iphost = &Apache::lonnet::get_iphost();
                   2646:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   2647:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   2648:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   2649:         foreach my $id (@{$iphost{$primary_ip}}) {
                   2650:             my $intdom = &Apache::lonnet::internet_dom($id);
                   2651:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   2652:                 push(@{$intdoms},$intdom);
                   2653:             }
                   2654:         }
                   2655:     }
                   2656:     foreach my $ip (keys(%iphost)) {
                   2657:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   2658:             foreach my $id (@{$iphost{$ip}}) {
                   2659:                 my $location = &Apache::lonnet::internet_dom($id);
                   2660:                 if ($location) {
                   2661:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   2662:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2663:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   2664:                             push(@{$by_ip->{$ip}},$location);
                   2665:                         }
                   2666:                     } else {
                   2667:                         $by_ip->{$ip} = [$location];
                   2668:                     }
                   2669:                 }
                   2670:             }
                   2671:         }
                   2672:     }
                   2673:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   2674:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2675:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   2676:             my $first = $by_ip->{$ip}->[0];
                   2677:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   2678:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   2679:                     push(@{$by_location->{$first}},$ip);
                   2680:                 }
                   2681:             } else {
                   2682:                 $by_location->{$first} = [$ip];
                   2683:             }
                   2684:         }
                   2685:     }
                   2686:     return;
                   2687: }
                   2688: 
1.145     raeburn  2689: sub current_offloads_to {
                   2690:     my ($dom,$settings,$servers) = @_;
                   2691:     my (%spareid,%otherdomconfigs);
1.152     raeburn  2692:     if (ref($servers) eq 'HASH') {
1.145     raeburn  2693:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   2694:             my $gotspares;
1.152     raeburn  2695:             if (ref($settings) eq 'HASH') {
                   2696:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   2697:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   2698:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   2699:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   2700:                         $gotspares = 1;
                   2701:                     }
1.145     raeburn  2702:                 }
                   2703:             }
                   2704:             unless ($gotspares) {
                   2705:                 my $gotspares;
                   2706:                 my $serverhomeID =
                   2707:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   2708:                 my $serverhomedom =
                   2709:                     &Apache::lonnet::host_domain($serverhomeID);
                   2710:                 if ($serverhomedom ne $dom) {
                   2711:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   2712:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2713:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2714:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2715:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2716:                                 $gotspares = 1;
                   2717:                             }
                   2718:                         }
                   2719:                     } else {
                   2720:                         $otherdomconfigs{$serverhomedom} =
                   2721:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   2722:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   2723:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2724:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2725:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   2726:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2727:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2728:                                         $gotspares = 1;
                   2729:                                     }
                   2730:                                 }
                   2731:                             }
                   2732:                         }
                   2733:                     }
                   2734:                 }
                   2735:             }
                   2736:             unless ($gotspares) {
                   2737:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2738:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2739:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2740:                } else {
                   2741:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   2742:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   2743:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2744:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2745:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2746:                     } else {
1.150     raeburn  2747:                         my %what = (
                   2748:                              spareid => 1,
                   2749:                         );
                   2750:                         my ($result,$returnhash) = 
                   2751:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   2752:                         if ($result eq 'ok') { 
                   2753:                             if (ref($returnhash) eq 'HASH') {
                   2754:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   2755:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   2756:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   2757:                                 }
                   2758:                             }
1.145     raeburn  2759:                         }
                   2760:                     }
                   2761:                 }
                   2762:             }
                   2763:         }
                   2764:     }
                   2765:     return %spareid;
                   2766: }
                   2767: 
                   2768: sub spares_row {
1.152     raeburn  2769:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145     raeburn  2770:     my $css_class;
                   2771:     my $numinrow = 4;
                   2772:     my $itemcount = 1;
                   2773:     my $datatable;
1.152     raeburn  2774:     my %typetitles = &sparestype_titles();
                   2775:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  2776:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  2777:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   2778:             my ($othercontrol,$serverdom);
                   2779:             if ($serverhome ne $server) {
                   2780:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   2781:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2782:             } else {
                   2783:                 $serverdom = &Apache::lonnet::host_domain($server);
                   2784:                 if ($serverdom ne $dom) {
                   2785:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2786:                 }
                   2787:             }
                   2788:             next unless (ref($spareid->{$server}) eq 'HASH');
1.145     raeburn  2789:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2790:             $datatable .= '<tr'.$css_class.'>
                   2791:                            <td rowspan="2">
1.183     bisitz   2792:                             <span class="LC_nobreak">'.
                   2793:                           &mt('[_1] when busy, offloads to:'
                   2794:                               ,'<b>'.$server.'</b>').
                   2795:                           "\n";
1.145     raeburn  2796:             my (%current,%canselect);
1.152     raeburn  2797:             my @choices = 
                   2798:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   2799:             foreach my $type ('primary','default') {
                   2800:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  2801:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   2802:                         my @spares = @{$spareid->{$server}{$type}};
                   2803:                         if (@spares > 0) {
1.152     raeburn  2804:                             if ($othercontrol) {
                   2805:                                 $current{$type} = join(', ',@spares);
                   2806:                             } else {
                   2807:                                 $current{$type} .= '<table>';
                   2808:                                 my $numspares = scalar(@spares);
                   2809:                                 for (my $i=0;  $i<@spares; $i++) {
                   2810:                                     my $rem = $i%($numinrow);
                   2811:                                     if ($rem == 0) {
                   2812:                                         if ($i > 0) {
                   2813:                                             $current{$type} .= '</tr>';
                   2814:                                         }
                   2815:                                         $current{$type} .= '<tr>';
1.145     raeburn  2816:                                     }
1.152     raeburn  2817:                                     $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;'.
                   2818:                                                        $spareid->{$server}{$type}[$i].
                   2819:                                                        '</label></td>'."\n";
                   2820:                                 }
                   2821:                                 my $rem = @spares%($numinrow);
                   2822:                                 my $colsleft = $numinrow - $rem;
                   2823:                                 if ($colsleft > 1 ) {
                   2824:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   2825:                                                        '" class="LC_left_item">'.
                   2826:                                                        '&nbsp;</td>';
                   2827:                                 } elsif ($colsleft == 1) {
                   2828:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  2829:                                 }
1.152     raeburn  2830:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  2831:                             }
1.145     raeburn  2832:                         }
                   2833:                     }
                   2834:                     if ($current{$type} eq '') {
                   2835:                         $current{$type} = &mt('None specified');
                   2836:                     }
1.152     raeburn  2837:                     if ($othercontrol) {
                   2838:                         if ($type eq 'primary') {
                   2839:                             $canselect{$type} = $othercontrol;
                   2840:                         }
                   2841:                     } else {
                   2842:                         $canselect{$type} = 
                   2843:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   2844:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   2845:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   2846:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   2847:                         if (@choices > 0) {
                   2848:                             foreach my $lonhost (@choices) {
                   2849:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   2850:                             }
                   2851:                         }
                   2852:                         $canselect{$type} .= '</select>'."\n";
                   2853:                     }
                   2854:                 } else {
                   2855:                     $current{$type} = &mt('Could not be determined');
                   2856:                     if ($type eq 'primary') {
                   2857:                         $canselect{$type} =  $othercontrol;
                   2858:                     }
1.145     raeburn  2859:                 }
1.152     raeburn  2860:                 if ($type eq 'default') {
                   2861:                     $datatable .= '<tr'.$css_class.'>';
                   2862:                 }
                   2863:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   2864:                               '<td>'.$current{$type}.'</td>'."\n".
                   2865:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  2866:             }
                   2867:             $itemcount ++;
                   2868:         }
                   2869:     }
                   2870:     $$rowtotal += $itemcount;
                   2871:     return $datatable;
                   2872: }
                   2873: 
1.152     raeburn  2874: sub possible_newspares {
                   2875:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   2876:     my $serverhostname = &Apache::lonnet::hostname($server);
                   2877:     my %excluded;
                   2878:     if ($serverhostname ne '') {
                   2879:         %excluded = (
                   2880:                        $serverhostname => 1,
                   2881:                     );
                   2882:     }
                   2883:     if (ref($currspares) eq 'HASH') {
                   2884:         foreach my $type (keys(%{$currspares})) {
                   2885:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   2886:                 if (@{$currspares->{$type}} > 0) {
                   2887:                     foreach my $curr (@{$currspares->{$type}}) {
                   2888:                         my $hostname = &Apache::lonnet::hostname($curr);
                   2889:                         $excluded{$hostname} = 1;
                   2890:                     }
                   2891:                 }
                   2892:             }
                   2893:         }
                   2894:     }
                   2895:     my @choices;
                   2896:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   2897:         if (keys(%{$serverhomes}) > 1) {
                   2898:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   2899:                 unless ($excluded{$name}) {
                   2900:                     if (exists($altids->{$serverhomes->{$name}})) {
                   2901:                         push(@choices,$altids->{$serverhomes->{$name}});
                   2902:                     } else {
                   2903:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  2904:                     }
                   2905:                 }
                   2906:             }
                   2907:         }
                   2908:     }
1.152     raeburn  2909:     return sort(@choices);
1.145     raeburn  2910: }
                   2911: 
1.150     raeburn  2912: sub print_loadbalancing {
                   2913:     my ($dom,$settings,$rowtotal) = @_;
                   2914:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   2915:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2916:     my $numinrow = 1;
                   2917:     my $datatable;
                   2918:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171     raeburn  2919:     my (%currbalancer,%currtargets,%currrules,%existing);
                   2920:     if (ref($settings) eq 'HASH') {
                   2921:         %existing = %{$settings};
                   2922:     }
                   2923:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   2924:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   2925:                                   \%currtargets,\%currrules);
1.150     raeburn  2926:     } else {
                   2927:         return;
                   2928:     }
                   2929:     my ($othertitle,$usertypes,$types) =
                   2930:         &Apache::loncommon::sorted_inst_types($dom);
                   2931:     my $rownum = 6;
                   2932:     if (ref($types) eq 'ARRAY') {
                   2933:         $rownum += scalar(@{$types});
                   2934:     }
1.171     raeburn  2935:     my @css_class = ('LC_odd_row','LC_even_row');
                   2936:     my $balnum = 0;
                   2937:     my $islast;
                   2938:     my (@toshow,$disabledtext);
                   2939:     if (keys(%currbalancer) > 0) {
                   2940:         @toshow = sort(keys(%currbalancer));
                   2941:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   2942:             push(@toshow,'');
                   2943:         }
                   2944:     } else {
                   2945:         @toshow = ('');
                   2946:         $disabledtext = &mt('No existing load balancer');
                   2947:     }
                   2948:     foreach my $lonhost (@toshow) {
                   2949:         if ($balnum == scalar(@toshow)-1) {
                   2950:             $islast = 1;
                   2951:         } else {
                   2952:             $islast = 0;
                   2953:         }
                   2954:         my $cssidx = $balnum%2;
                   2955:         my $targets_div_style = 'display: none';
                   2956:         my $disabled_div_style = 'display: block';
                   2957:         my $homedom_div_style = 'display: none';
                   2958:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   2959:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   2960:                       '<p>';
                   2961:         if ($lonhost eq '') {
                   2962:             $datatable .= '<span class="LC_nobreak">'; 
                   2963:             if (keys(%currbalancer) > 0) {
                   2964:                 $datatable .= &mt('Add balancer:');
                   2965:             } else {
                   2966:                 $datatable .= &mt('Enable balancer:');
                   2967:             }
                   2968:             $datatable .= '&nbsp;'.
                   2969:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   2970:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   2971:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   2972:                           '<option value="" selected="selected">'.&mt('None').
                   2973:                           '</option>'."\n";
                   2974:             foreach my $server (sort(keys(%servers))) {
                   2975:                 next if ($currbalancer{$server});
                   2976:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   2977:             }
                   2978:             $datatable .= 
                   2979:                 '</select>'."\n".
                   2980:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   2981:         } else {
                   2982:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   2983:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   2984:                            &mt('Stop balancing').'</label>'.
                   2985:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   2986:             $targets_div_style = 'display: block';
                   2987:             $disabled_div_style = 'display: none';
                   2988:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   2989:                 $homedom_div_style = 'display: block';
                   2990:             }
                   2991:         }
                   2992:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   2993:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   2994:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   2995:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   2996:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   2997:         my @sparestypes = ('primary','default');
                   2998:         my %typetitles = &sparestype_titles();
                   2999:         foreach my $sparetype (@sparestypes) {
                   3000:             my $targettable;
                   3001:             for (my $i=0; $i<$numspares; $i++) {
                   3002:                 my $checked;
                   3003:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   3004:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   3005:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   3006:                             $checked = ' checked="checked"';
                   3007:                         }
                   3008:                     }
                   3009:                 }
                   3010:                 my ($chkboxval,$disabled);
                   3011:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   3012:                     $chkboxval = $spares[$i];
                   3013:                 }
                   3014:                 if (exists($currbalancer{$spares[$i]})) {
                   3015:                     $disabled = ' disabled="disabled"';
                   3016:                 }
                   3017:                 $targettable .= 
                   3018:                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
                   3019:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                   3020:                     '</span></label></td>';
                   3021:                 my $rem = $i%($numinrow);
                   3022:                 if ($rem == 0) {
                   3023:                     if (($i > 0) && ($i < $numspares-1)) {
                   3024:                         $targettable .= '</tr>';
                   3025:                     }
                   3026:                     if ($i < $numspares-1) {
                   3027:                         $targettable .= '<tr>';
1.150     raeburn  3028:                     }
                   3029:                 }
                   3030:             }
1.171     raeburn  3031:             if ($targettable ne '') {
                   3032:                 my $rem = $numspares%($numinrow);
                   3033:                 my $colsleft = $numinrow - $rem;
                   3034:                 if ($colsleft > 1 ) {
                   3035:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3036:                                     '&nbsp;</td>';
                   3037:                 } elsif ($colsleft == 1) {
                   3038:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   3039:                 }
                   3040:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   3041:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   3042:             }
                   3043:         }
                   3044:         $datatable .= '</div></td></tr>'.
                   3045:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   3046:                                            $othertitle,$usertypes,$types,\%servers,
                   3047:                                            \%currbalancer,$lonhost,
                   3048:                                            $targets_div_style,$homedom_div_style,
                   3049:                                            $css_class[$cssidx],$balnum,$islast);
                   3050:         $$rowtotal += $rownum;
                   3051:         $balnum ++;
                   3052:     }
                   3053:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   3054:     return $datatable;
                   3055: }
                   3056: 
                   3057: sub get_loadbalancers_config {
                   3058:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   3059:     return unless ((ref($servers) eq 'HASH') &&
                   3060:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   3061:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   3062:     if (keys(%{$existing}) > 0) {
                   3063:         my $oldlonhost;
                   3064:         foreach my $key (sort(keys(%{$existing}))) {
                   3065:             if ($key eq 'lonhost') {
                   3066:                 $oldlonhost = $existing->{'lonhost'};
                   3067:                 $currbalancer->{$oldlonhost} = 1;
                   3068:             } elsif ($key eq 'targets') {
                   3069:                 if ($oldlonhost) {
                   3070:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   3071:                 }
                   3072:             } elsif ($key eq 'rules') {
                   3073:                 if ($oldlonhost) {
                   3074:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   3075:                 }
                   3076:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   3077:                 $currbalancer->{$key} = 1;
                   3078:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   3079:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  3080:             }
                   3081:         }
1.171     raeburn  3082:     } else {
                   3083:         my ($balancerref,$targetsref) =
                   3084:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   3085:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   3086:             foreach my $server (sort(keys(%{$balancerref}))) {
                   3087:                 $currbalancer->{$server} = 1;
                   3088:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  3089:             }
                   3090:         }
                   3091:     }
1.171     raeburn  3092:     return;
1.150     raeburn  3093: }
                   3094: 
                   3095: sub loadbalancing_rules {
                   3096:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  3097:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   3098:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  3099:     my $output;
1.171     raeburn  3100:     my $num = 0;
1.150     raeburn  3101:     my ($alltypes,$othertypes,$titles) = 
                   3102:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   3103:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   3104:         foreach my $type (@{$alltypes}) {
1.171     raeburn  3105:             $num ++;
1.150     raeburn  3106:             my $current;
                   3107:             if (ref($currrules) eq 'HASH') {
                   3108:                 $current = $currrules->{$type};
                   3109:             }
                   3110:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  3111:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  3112:                     $current = '';
                   3113:                 }
                   3114:             }
                   3115:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  3116:                                              $servers,$currbalancer,$lonhost,$dom,
                   3117:                                              $targets_div_style,$homedom_div_style,
                   3118:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  3119:         }
                   3120:     }
                   3121:     return $output;
                   3122: }
                   3123: 
                   3124: sub loadbalancing_titles {
                   3125:     my ($dom,$intdom,$usertypes,$types) = @_;
                   3126:     my %othertypes = (
                   3127:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   3128:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   3129:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   3130:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
                   3131:                      );
                   3132:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   3133:     if (ref($types) eq 'ARRAY') {
                   3134:         unshift(@alltypes,@{$types},'default');
                   3135:     }
                   3136:     my %titles;
                   3137:     foreach my $type (@alltypes) {
                   3138:         if ($type =~ /^_LC_/) {
                   3139:             $titles{$type} = $othertypes{$type};
                   3140:         } elsif ($type eq 'default') {
                   3141:             $titles{$type} = &mt('All users from [_1]',$dom);
                   3142:             if (ref($types) eq 'ARRAY') {
                   3143:                 if (@{$types} > 0) {
                   3144:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   3145:                 }
                   3146:             }
                   3147:         } elsif (ref($usertypes) eq 'HASH') {
                   3148:             $titles{$type} = $usertypes->{$type};
                   3149:         }
                   3150:     }
                   3151:     return (\@alltypes,\%othertypes,\%titles);
                   3152: }
                   3153: 
                   3154: sub loadbalance_rule_row {
1.171     raeburn  3155:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   3156:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150     raeburn  3157:     my @rulenames = ('default','homeserver');
                   3158:     my %ruletitles = &offloadtype_text();
                   3159:     if ($type eq '_LC_external') {
                   3160:         push(@rulenames,'externalbalancer');
                   3161:     } else {
                   3162:         push(@rulenames,'specific');
                   3163:     }
1.161     raeburn  3164:     push(@rulenames,'none');
1.150     raeburn  3165:     my $style = $targets_div_style;
                   3166:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   3167:         $style = $homedom_div_style;
                   3168:     }
1.171     raeburn  3169:     my $space;
                   3170:     if ($islast && $num == 1) {
                   3171:         $space = '<div display="inline-block">&nbsp;</div>';
                   3172:     }
1.150     raeburn  3173:     my $output = 
1.171     raeburn  3174:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   3175:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   3176:         '<td valaign="top">'.$space.
                   3177:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  3178:     for (my $i=0; $i<@rulenames; $i++) {
                   3179:         my $rule = $rulenames[$i];
                   3180:         my ($checked,$extra);
                   3181:         if ($rulenames[$i] eq 'default') {
                   3182:             $rule = '';
                   3183:         }
                   3184:         if ($rulenames[$i] eq 'specific') {
                   3185:             if (ref($servers) eq 'HASH') {
                   3186:                 my $default;
                   3187:                 if (($current ne '') && (exists($servers->{$current}))) {
                   3188:                     $checked = ' checked="checked"';
                   3189:                 }
                   3190:                 unless ($checked) {
                   3191:                     $default = ' selected="selected"';
                   3192:                 }
1.171     raeburn  3193:                 $extra = 
                   3194:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3195:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3196:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   3197:                     '<option value=""'.$default.'></option>'."\n";
                   3198:                 foreach my $server (sort(keys(%{$servers}))) {
                   3199:                     if (ref($currbalancer) eq 'HASH') {
                   3200:                         next if (exists($currbalancer->{$server}));
                   3201:                     }
1.150     raeburn  3202:                     my $selected;
1.171     raeburn  3203:                     if ($server eq $current) {
1.150     raeburn  3204:                         $selected = ' selected="selected"';
                   3205:                     }
1.171     raeburn  3206:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  3207:                 }
                   3208:                 $extra .= '</select>';
                   3209:             }
                   3210:         } elsif ($rule eq $current) {
                   3211:             $checked = ' checked="checked"';
                   3212:         }
                   3213:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  3214:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   3215:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   3216:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150     raeburn  3217:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   3218:                    '</label>'.$extra.'</span><br />'."\n";
                   3219:     }
                   3220:     $output .= '</div></td></tr>'."\n";
                   3221:     return $output;
                   3222: }
                   3223: 
                   3224: sub offloadtype_text {
                   3225:     my %ruletitles = &Apache::lonlocal::texthash (
                   3226:            'default'          => 'Offloads to default destinations',
                   3227:            'homeserver'       => "Offloads to user's home server",
                   3228:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   3229:            'specific'         => 'Offloads to specific server',
1.161     raeburn  3230:            'none'             => 'No offload',
1.150     raeburn  3231:     );
                   3232:     return %ruletitles;
                   3233: }
                   3234: 
                   3235: sub sparestype_titles {
                   3236:     my %typestitles = &Apache::lonlocal::texthash (
                   3237:                           'primary' => 'primary',
                   3238:                           'default' => 'default',
                   3239:                       );
                   3240:     return %typestitles;
                   3241: }
                   3242: 
1.28      raeburn  3243: sub contact_titles {
                   3244:     my %titles = &Apache::lonlocal::texthash (
                   3245:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  3246:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  3247:                    'errormail'    => 'Error reports to be e-mailed to',
                   3248:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  3249:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   3250:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  3251:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.190   ! raeburn  3252:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.28      raeburn  3253:                  );
                   3254:     my %short_titles = &Apache::lonlocal::texthash (
                   3255:                            adminemail   => 'Admin E-mail address',
                   3256:                            supportemail => 'Support E-mail',
                   3257:                        );   
                   3258:     return (\%titles,\%short_titles);
                   3259: }
                   3260: 
1.72      raeburn  3261: sub tool_titles {
                   3262:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  3263:                      aboutme    => 'Personal web page',
1.86      raeburn  3264:                      blog       => 'Blog',
1.162     raeburn  3265:                      webdav     => 'WebDAV',
1.86      raeburn  3266:                      portfolio  => 'Portfolio',
1.88      bisitz   3267:                      official   => 'Official courses (with institutional codes)',
                   3268:                      unofficial => 'Unofficial courses',
1.98      raeburn  3269:                      community  => 'Communities',
1.86      raeburn  3270:                  );
1.72      raeburn  3271:     return %titles;
                   3272: }
                   3273: 
1.101     raeburn  3274: sub courserequest_titles {
                   3275:     my %titles = &Apache::lonlocal::texthash (
                   3276:                                    official   => 'Official',
                   3277:                                    unofficial => 'Unofficial',
                   3278:                                    community  => 'Communities',
                   3279:                                    norequest  => 'Not allowed',
1.104     raeburn  3280:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3281:                                    validate   => 'With validation',
                   3282:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3283:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3284:                  );
                   3285:     return %titles;
                   3286: }
                   3287: 
1.163     raeburn  3288: sub authorrequest_titles {
                   3289:     my %titles = &Apache::lonlocal::texthash (
                   3290:                                    norequest  => 'Not allowed',
                   3291:                                    approval   => 'Approval by Dom. Coord.',
                   3292:                                    automatic  => 'Automatic approval',
                   3293:                  );
                   3294:     return %titles;
                   3295: } 
                   3296: 
1.101     raeburn  3297: sub courserequest_conditions {
                   3298:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3299:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.101     raeburn  3300:        validate   => '(Processing of request subject to instittutional validation).',
                   3301:                  );
                   3302:     return %conditions;
                   3303: }
                   3304: 
                   3305: 
1.27      raeburn  3306: sub print_usercreation {
1.30      raeburn  3307:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3308:     my $numinrow = 4;
1.28      raeburn  3309:     my $datatable;
                   3310:     if ($position eq 'top') {
1.30      raeburn  3311:         $$rowtotal ++;
1.34      raeburn  3312:         my $rowcount = 0;
1.32      raeburn  3313:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3314:         if (ref($rules) eq 'HASH') {
                   3315:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3316:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3317:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3318:                 $$rowtotal ++;
1.32      raeburn  3319:                 $rowcount ++;
                   3320:             }
                   3321:         }
                   3322:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3323:         if (ref($idrules) eq 'HASH') {
                   3324:             if (keys(%{$idrules}) > 0) {
                   3325:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3326:                                                 $idruleorder,$numinrow,$rowcount);
                   3327:                 $$rowtotal ++;
                   3328:                 $rowcount ++;
1.28      raeburn  3329:             }
                   3330:         }
1.43      raeburn  3331:         my ($emailrules,$emailruleorder) = 
                   3332:             &Apache::lonnet::inst_userrules($dom,'email');
                   3333:         if (ref($emailrules) eq 'HASH') {
                   3334:             if (keys(%{$emailrules}) > 0) {
                   3335:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
                   3336:                                                 $emailruleorder,$numinrow,$rowcount);
                   3337:                 $$rowtotal ++;
                   3338:                 $rowcount ++;
                   3339:             }
                   3340:         }
1.39      raeburn  3341:         if ($rowcount == 0) {
                   3342:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3343:             $$rowtotal ++;
                   3344:             $rowcount ++;
                   3345:         }
1.34      raeburn  3346:     } elsif ($position eq 'middle') {
1.100     raeburn  3347:         my @creators = ('author','course','requestcrs','selfcreate');
1.37      raeburn  3348:         my ($rules,$ruleorder) =
                   3349:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3350:         my %lt = &usercreation_types();
                   3351:         my %checked;
1.50      raeburn  3352:         my @selfcreate; 
1.34      raeburn  3353:         if (ref($settings) eq 'HASH') {
                   3354:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3355:                 foreach my $item (@creators) {
                   3356:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3357:                 }
1.50      raeburn  3358:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3359:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3360:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3361:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3362:                         @selfcreate = ('email','login','sso');
                   3363:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3364:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3365:                     }
                   3366:                 }
1.34      raeburn  3367:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3368:                 foreach my $item (@creators) {
                   3369:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3370:                         $checked{$item} = 'none';
                   3371:                     }
                   3372:                 }
                   3373:             }
                   3374:         }
                   3375:         my $rownum = 0;
                   3376:         foreach my $item (@creators) {
                   3377:             $rownum ++;
1.50      raeburn  3378:             if ($item ne 'selfcreate') {  
                   3379:                 if ($checked{$item} eq '') {
1.43      raeburn  3380:                     $checked{$item} = 'any';
                   3381:                 }
1.34      raeburn  3382:             }
                   3383:             my $css_class;
                   3384:             if ($rownum%2) {
                   3385:                 $css_class = '';
                   3386:             } else {
                   3387:                 $css_class = ' class="LC_odd_row" ';
                   3388:             }
                   3389:             $datatable .= '<tr'.$css_class.'>'.
                   3390:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3391:                          '</span></td><td align="right">';
1.50      raeburn  3392:             my @options;
1.45      raeburn  3393:             if ($item eq 'selfcreate') {
1.43      raeburn  3394:                 push(@options,('email','login','sso'));
                   3395:             } else {
1.50      raeburn  3396:                 @options = ('any');
1.43      raeburn  3397:                 if (ref($rules) eq 'HASH') {
                   3398:                     if (keys(%{$rules}) > 0) {
                   3399:                         push(@options,('official','unofficial'));
                   3400:                     }
1.37      raeburn  3401:                 }
1.50      raeburn  3402:                 push(@options,'none');
1.37      raeburn  3403:             }
                   3404:             foreach my $option (@options) {
1.50      raeburn  3405:                 my $type = 'radio';
1.34      raeburn  3406:                 my $check = ' ';
1.50      raeburn  3407:                 if ($item eq 'selfcreate') {
                   3408:                     $type = 'checkbox';
                   3409:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
                   3410:                         $check = ' checked="checked" ';
                   3411:                     }
                   3412:                 } else {
                   3413:                     if ($checked{$item} eq $option) {
                   3414:                         $check = ' checked="checked" ';
                   3415:                     }
1.34      raeburn  3416:                 } 
                   3417:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3418:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3419:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3420:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3421:             }
                   3422:             $datatable .= '</td></tr>';
                   3423:         }
1.93      raeburn  3424:         my ($othertitle,$usertypes,$types) =
                   3425:             &Apache::loncommon::sorted_inst_types($dom);
1.165     raeburn  3426:         my $createsettings;
                   3427:         if (ref($settings) eq 'HASH') {
                   3428:             $createsettings = $settings->{cancreate};
                   3429:         }
1.93      raeburn  3430:         if (ref($usertypes) eq 'HASH') {
                   3431:             if (keys(%{$usertypes}) > 0) {
1.99      raeburn  3432:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93      raeburn  3433:                                              $dom,$numinrow,$othertitle,
                   3434:                                              'statustocreate');
                   3435:                 $$rowtotal ++;
1.169     raeburn  3436:                 $rownum ++;
1.93      raeburn  3437:             }
                   3438:         }
1.169     raeburn  3439:         $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28      raeburn  3440:     } else {
                   3441:         my @contexts = ('author','course','domain');
                   3442:         my @authtypes = ('int','krb4','krb5','loc');
                   3443:         my %checked;
                   3444:         if (ref($settings) eq 'HASH') {
                   3445:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3446:                 foreach my $item (@contexts) {
                   3447:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3448:                         foreach my $auth (@authtypes) {
                   3449:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3450:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3451:                             }
                   3452:                         }
                   3453:                     }
                   3454:                 }
1.27      raeburn  3455:             }
1.35      raeburn  3456:         } else {
                   3457:             foreach my $item (@contexts) {
1.36      raeburn  3458:                 foreach my $auth (@authtypes) {
1.35      raeburn  3459:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3460:                 }
                   3461:             }
1.27      raeburn  3462:         }
1.28      raeburn  3463:         my %title = &context_names();
                   3464:         my %authname = &authtype_names();
                   3465:         my $rownum = 0;
                   3466:         my $css_class; 
                   3467:         foreach my $item (@contexts) {
                   3468:             if ($rownum%2) {
                   3469:                 $css_class = '';
                   3470:             } else {
                   3471:                 $css_class = ' class="LC_odd_row" ';
                   3472:             }
1.30      raeburn  3473:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3474:                             '<td>'.$title{$item}.
                   3475:                             '</td><td class="LC_left_item">'.
                   3476:                             '<span class="LC_nobreak">';
                   3477:             foreach my $auth (@authtypes) {
                   3478:                 $datatable .= '<label>'. 
                   3479:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3480:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3481:                               $authname{$auth}.'</label>&nbsp;';
                   3482:             }
                   3483:             $datatable .= '</span></td></tr>';
                   3484:             $rownum ++;
1.27      raeburn  3485:         }
1.30      raeburn  3486:         $$rowtotal += $rownum;
1.27      raeburn  3487:     }
                   3488:     return $datatable;
                   3489: }
                   3490: 
1.165     raeburn  3491: sub captcha_choice {
1.169     raeburn  3492:     my ($context,$settings,$itemcount) = @_;
1.165     raeburn  3493:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
                   3494:     my %lt = &captcha_phrases();
                   3495:     $keyentry = 'hidden';
                   3496:     if ($context eq 'cancreate') {
                   3497:         $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169     raeburn  3498:     } elsif ($context eq 'login') {
                   3499:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  3500:     }
                   3501:     if (ref($settings) eq 'HASH') {
                   3502:         if ($settings->{'captcha'}) {
                   3503:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   3504:         } else {
                   3505:             $checked{'original'} = ' checked="checked"';
                   3506:         }
                   3507:         if ($settings->{'captcha'} eq 'recaptcha') {
                   3508:             $pubtext = $lt{'pub'};
                   3509:             $privtext = $lt{'priv'};
                   3510:             $keyentry = 'text';
                   3511:         }
                   3512:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   3513:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   3514:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   3515:         }
                   3516:     } else {
                   3517:         $checked{'original'} = ' checked="checked"';
                   3518:     }
1.169     raeburn  3519:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3520:     my $output = '<tr'.$css_class.'>'.
                   3521:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  3522:                  '<table><tr><td>'."\n";
                   3523:     foreach my $option ('original','recaptcha','notused') {
                   3524:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   3525:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   3526:                    $lt{$option}.'</label></span>';
                   3527:         unless ($option eq 'notused') {
                   3528:             $output .= ('&nbsp;'x2)."\n";
                   3529:         }
                   3530:     }
                   3531: #
                   3532: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   3533: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   3534: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu) 
                   3535: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   3536: #  
                   3537:     $output .= '</td></tr>'."\n".
                   3538:                '<tr><td>'."\n".
                   3539:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   3540:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   3541:                $currpub.'" size="40" /></span><br />'."\n".
                   3542:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   3543:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
                   3544:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
                   3545:                '</td></tr>';
                   3546:     return $output;
                   3547: }
                   3548: 
1.32      raeburn  3549: sub user_formats_row {
                   3550:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   3551:     my $output;
                   3552:     my %text = (
                   3553:                    'username' => 'new usernames',
                   3554:                    'id'       => 'IDs',
1.45      raeburn  3555:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  3556:                );
                   3557:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   3558:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  3559:               '<td><span class="LC_nobreak">';
                   3560:     if ($type eq 'email') {
                   3561:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   3562:     } else {
                   3563:         $output .= &mt("Format rules to check for $text{$type}: ");
                   3564:     }
                   3565:     $output .= '</span></td>'.
                   3566:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  3567:     my $rem;
                   3568:     if (ref($ruleorder) eq 'ARRAY') {
                   3569:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   3570:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   3571:                 my $rem = $i%($numinrow);
                   3572:                 if ($rem == 0) {
                   3573:                     if ($i > 0) {
                   3574:                         $output .= '</tr>';
                   3575:                     }
                   3576:                     $output .= '<tr>';
                   3577:                 }
                   3578:                 my $check = ' ';
1.39      raeburn  3579:                 if (ref($settings) eq 'HASH') {
                   3580:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   3581:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   3582:                             $check = ' checked="checked" ';
                   3583:                         }
1.27      raeburn  3584:                     }
                   3585:                 }
                   3586:                 $output .= '<td class="LC_left_item">'.
                   3587:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  3588:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  3589:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   3590:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   3591:             }
                   3592:         }
                   3593:         $rem = @{$ruleorder}%($numinrow);
                   3594:     }
                   3595:     my $colsleft = $numinrow - $rem;
                   3596:     if ($colsleft > 1 ) {
                   3597:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3598:                    '&nbsp;</td>';
                   3599:     } elsif ($colsleft == 1) {
                   3600:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   3601:     }
                   3602:     $output .= '</tr></table></td></tr>';
                   3603:     return $output;
                   3604: }
                   3605: 
1.34      raeburn  3606: sub usercreation_types {
                   3607:     my %lt = &Apache::lonlocal::texthash (
                   3608:                     author     => 'When adding a co-author',
                   3609:                     course     => 'When adding a user to a course',
1.100     raeburn  3610:                     requestcrs => 'When requesting a course',
1.45      raeburn  3611:                     selfcreate => 'User creates own account', 
1.34      raeburn  3612:                     any        => 'Any',
                   3613:                     official   => 'Institutional only ',
                   3614:                     unofficial => 'Non-institutional only',
1.85      schafran 3615:                     email      => 'E-mail address',
1.43      raeburn  3616:                     login      => 'Institutional Login',
                   3617:                     sso        => 'SSO', 
1.34      raeburn  3618:                     none       => 'None',
                   3619:     );
                   3620:     return %lt;
1.48      raeburn  3621: }
1.34      raeburn  3622: 
1.28      raeburn  3623: sub authtype_names {
                   3624:     my %lt = &Apache::lonlocal::texthash(
                   3625:                       int    => 'Internal',
                   3626:                       krb4   => 'Kerberos 4',
                   3627:                       krb5   => 'Kerberos 5',
                   3628:                       loc    => 'Local',
                   3629:                   );
                   3630:     return %lt;
                   3631: }
                   3632: 
                   3633: sub context_names {
                   3634:     my %context_title = &Apache::lonlocal::texthash(
                   3635:        author => 'Creating users when an Author',
                   3636:        course => 'Creating users when in a course',
                   3637:        domain => 'Creating users when a Domain Coordinator',
                   3638:     );
                   3639:     return %context_title;
                   3640: }
                   3641: 
1.33      raeburn  3642: sub print_usermodification {
                   3643:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3644:     my $numinrow = 4;
                   3645:     my ($context,$datatable,$rowcount);
                   3646:     if ($position eq 'top') {
                   3647:         $rowcount = 0;
                   3648:         $context = 'author'; 
                   3649:         foreach my $role ('ca','aa') {
                   3650:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3651:                                                    $numinrow,$rowcount);
                   3652:             $$rowtotal ++;
                   3653:             $rowcount ++;
                   3654:         }
1.63      raeburn  3655:     } elsif ($position eq 'middle') {
1.33      raeburn  3656:         $context = 'course';
                   3657:         $rowcount = 0;
                   3658:         foreach my $role ('st','ep','ta','in','cr') {
                   3659:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3660:                                                    $numinrow,$rowcount);
                   3661:             $$rowtotal ++;
                   3662:             $rowcount ++;
                   3663:         }
1.63      raeburn  3664:     } elsif ($position eq 'bottom') {
                   3665:         $context = 'selfcreate';
                   3666:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3667:         $usertypes->{'default'} = $othertitle;
                   3668:         if (ref($types) eq 'ARRAY') {
                   3669:             push(@{$types},'default');
                   3670:             $usertypes->{'default'} = $othertitle;
                   3671:             foreach my $status (@{$types}) {
                   3672:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
                   3673:                                                        $numinrow,$rowcount,$usertypes);
                   3674:                 $$rowtotal ++;
                   3675:                 $rowcount ++;
                   3676:             }
                   3677:         }
1.33      raeburn  3678:     }
                   3679:     return $datatable;
                   3680: }
                   3681: 
1.43      raeburn  3682: sub print_defaults {
                   3683:     my ($dom,$rowtotal) = @_;
1.68      raeburn  3684:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  3685:                  'datelocale_def','portal_def');
1.43      raeburn  3686:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  3687:     my $titles = &defaults_titles($dom);
1.43      raeburn  3688:     my $rownum = 0;
                   3689:     my ($datatable,$css_class);
                   3690:     foreach my $item (@items) {
                   3691:         if ($rownum%2) {
                   3692:             $css_class = '';
                   3693:         } else {
                   3694:             $css_class = ' class="LC_odd_row" ';
                   3695:         }
                   3696:         $datatable .= '<tr'.$css_class.'>'.
                   3697:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3698:                   '</span></td><td class="LC_right_item">';
                   3699:         if ($item eq 'auth_def') {
                   3700:             my @authtypes = ('internal','krb4','krb5','localauth');
                   3701:             my %shortauth = (
                   3702:                              internal => 'int',
                   3703:                              krb4 => 'krb4',
                   3704:                              krb5 => 'krb5',
                   3705:                              localauth  => 'loc'
                   3706:                            );
                   3707:             my %authnames = &authtype_names();
                   3708:             foreach my $auth (@authtypes) {
                   3709:                 my $checked = ' ';
                   3710:                 if ($domdefaults{$item} eq $auth) {
                   3711:                     $checked = ' checked="checked" ';
                   3712:                 }
                   3713:                 $datatable .= '<label><input type="radio" name="'.$item.
                   3714:                               '" value="'.$auth.'"'.$checked.'/>'.
                   3715:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   3716:             }
1.54      raeburn  3717:         } elsif ($item eq 'timezone_def') {
                   3718:             my $includeempty = 1;
                   3719:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68      raeburn  3720:         } elsif ($item eq 'datelocale_def') {
                   3721:             my $includeempty = 1;
                   3722:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167     raeburn  3723:         } elsif ($item eq 'lang_def') {
1.168     raeburn  3724:             my %langchoices = &get_languages_hash();
                   3725:             $langchoices{''} = 'No language preference';
1.167     raeburn  3726:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
                   3727:             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
                   3728:                                                           \%langchoices);
1.43      raeburn  3729:         } else {
1.141     raeburn  3730:             my $size;
                   3731:             if ($item eq 'portal_def') {
                   3732:                 $size = ' size="25"';
                   3733:             }
1.43      raeburn  3734:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141     raeburn  3735:                           $domdefaults{$item}.'"'.$size.' />';
1.43      raeburn  3736:         }
                   3737:         $datatable .= '</td></tr>';
                   3738:         $rownum ++;
                   3739:     }
                   3740:     $$rowtotal += $rownum;
                   3741:     return $datatable;
                   3742: }
                   3743: 
1.168     raeburn  3744: sub get_languages_hash {
                   3745:     my %langchoices;
                   3746:     foreach my $id (&Apache::loncommon::languageids()) {
                   3747:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   3748:         if ($code ne '') {
                   3749:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   3750:         }
                   3751:     }
                   3752:     return %langchoices;
                   3753: }
                   3754: 
1.43      raeburn  3755: sub defaults_titles {
1.141     raeburn  3756:     my ($dom) = @_;
1.43      raeburn  3757:     my %titles = &Apache::lonlocal::texthash (
                   3758:                    'auth_def'      => 'Default authentication type',
                   3759:                    'auth_arg_def'  => 'Default authentication argument',
                   3760:                    'lang_def'      => 'Default language',
1.54      raeburn  3761:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  3762:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  3763:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  3764:                  );
1.141     raeburn  3765:     if ($dom) {
                   3766:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   3767:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   3768:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   3769:         $protocol = 'http' if ($protocol ne 'https');
                   3770:         if ($uint_dom) {
                   3771:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   3772:                                          $uint_dom);
                   3773:         }
                   3774:     }
1.43      raeburn  3775:     return (\%titles);
                   3776: }
                   3777: 
1.46      raeburn  3778: sub print_scantronformat {
                   3779:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   3780:     my $itemcount = 1;
1.60      raeburn  3781:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   3782:         %confhash);
1.46      raeburn  3783:     my $switchserver = &check_switchserver($dom,$confname);
                   3784:     my %lt = &Apache::lonlocal::texthash (
1.95      www      3785:                 default => 'Default bubblesheet format file error',
                   3786:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  3787:              );
                   3788:     my %scantronfiles = (
                   3789:         default => 'default.tab',
                   3790:         custom => 'custom.tab',
                   3791:     );
                   3792:     foreach my $key (keys(%scantronfiles)) {
                   3793:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   3794:                               .$scantronfiles{$key};
                   3795:     }
                   3796:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   3797:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   3798:         if (!$switchserver) {
                   3799:             my $servadm = $r->dir_config('lonAdmEMail');
                   3800:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   3801:             if ($configuserok eq 'ok') {
                   3802:                 if ($author_ok eq 'ok') {
                   3803:                     my %legacyfile = (
                   3804:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   3805:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   3806:                     );
                   3807:                     my %md5chk;
                   3808:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3809:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   3810:                         chomp($md5chk{$type});
1.46      raeburn  3811:                     }
                   3812:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   3813:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3814:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  3815:                                 &legacy_scantronformat($r,$dom,$confname,
                   3816:                                                  $type,$legacyfile{$type},
                   3817:                                                  $scantronurls{$type},
                   3818:                                                  $scantronfiles{$type});
1.60      raeburn  3819:                             if ($error ne '') {
                   3820:                                 $error{$type} = $error;
                   3821:                             }
                   3822:                         }
                   3823:                         if (keys(%error) == 0) {
                   3824:                             $is_custom = 1;
                   3825:                             $confhash{'scantron'}{'scantronformat'} = 
                   3826:                                 $scantronurls{'custom'};
                   3827:                             my $putresult = 
                   3828:                                 &Apache::lonnet::put_dom('configuration',
                   3829:                                                          \%confhash,$dom);
                   3830:                             if ($putresult ne 'ok') {
                   3831:                                 $error{'custom'} = 
                   3832:                                     '<span class="LC_error">'.
                   3833:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3834:                             }
1.46      raeburn  3835:                         }
                   3836:                     } else {
1.60      raeburn  3837:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  3838:                             &legacy_scantronformat($r,$dom,$confname,
                   3839:                                           'default',$legacyfile{'default'},
                   3840:                                           $scantronurls{'default'},
                   3841:                                           $scantronfiles{'default'});
1.60      raeburn  3842:                         if ($error eq '') {
                   3843:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   3844:                             my $putresult =
                   3845:                                 &Apache::lonnet::put_dom('configuration',
                   3846:                                                          \%confhash,$dom);
                   3847:                             if ($putresult ne 'ok') {
                   3848:                                 $error{'default'} =
                   3849:                                     '<span class="LC_error">'.
                   3850:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3851:                             }
                   3852:                         } else {
                   3853:                             $error{'default'} = $error;
                   3854:                         }
1.46      raeburn  3855:                     }
                   3856:                 }
                   3857:             }
                   3858:         } else {
1.95      www      3859:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  3860:         }
                   3861:     }
                   3862:     if (ref($settings) eq 'HASH') {
                   3863:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   3864:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   3865:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   3866:                 $scantronurl = '';
                   3867:             } else {
                   3868:                 $scantronurl = $settings->{'scantronformat'};
                   3869:             }
                   3870:             $is_custom = 1;
                   3871:         } else {
                   3872:             $scantronurl = $scantronurls{'default'};
                   3873:         }
                   3874:     } else {
1.60      raeburn  3875:         if ($is_custom) {
                   3876:             $scantronurl = $scantronurls{'custom'};
                   3877:         } else {
                   3878:             $scantronurl = $scantronurls{'default'};
                   3879:         }
1.46      raeburn  3880:     }
                   3881:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3882:     $datatable .= '<tr'.$css_class.'>';
                   3883:     if (!$is_custom) {
1.65      raeburn  3884:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   3885:                       '<span class="LC_nobreak">';
1.46      raeburn  3886:         if ($scantronurl) {
                   3887:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3888:                           &mt('Default bubblesheet format file').'</a>';
1.46      raeburn  3889:         } else {
                   3890:             $datatable = &mt('File unavailable for display');
                   3891:         }
1.65      raeburn  3892:         $datatable .= '</span></td>';
1.60      raeburn  3893:         if (keys(%error) == 0) { 
                   3894:             $datatable .= '<td valign="bottom">';
                   3895:             if (!$switchserver) {
                   3896:                 $datatable .= &mt('Upload:').'<br />';
                   3897:             }
                   3898:         } else {
                   3899:             my $errorstr;
                   3900:             foreach my $key (sort(keys(%error))) {
                   3901:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3902:             }
                   3903:             $datatable .= '<td>'.$errorstr;
                   3904:         }
1.46      raeburn  3905:     } else {
                   3906:         if (keys(%error) > 0) {
                   3907:             my $errorstr;
                   3908:             foreach my $key (sort(keys(%error))) {
                   3909:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3910:             } 
1.60      raeburn  3911:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  3912:         } elsif ($scantronurl) {
1.65      raeburn  3913:             $datatable .= '<td><span class="LC_nobreak">'.
                   3914:                           '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3915:                           &mt('Custom bubblesheet format file').'</a><label>'.
1.65      raeburn  3916:                           '<input type="checkbox" name="scantronformat_del"'.
                   3917:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
                   3918:                           '<td><span class="LC_nobreak">&nbsp;'.
                   3919:                           &mt('Replace:').'</span><br />';
1.46      raeburn  3920:         }
                   3921:     }
                   3922:     if (keys(%error) == 0) {
                   3923:         if ($switchserver) {
                   3924:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3925:         } else {
1.65      raeburn  3926:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   3927:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  3928:         }
                   3929:     }
                   3930:     $datatable .= '</td></tr>';
                   3931:     $$rowtotal ++;
                   3932:     return $datatable;
                   3933: }
                   3934: 
                   3935: sub legacy_scantronformat {
                   3936:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   3937:     my ($url,$error);
                   3938:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   3939:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   3940:         (my $result,$url) =
                   3941:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   3942:                          '','',$newfile);
                   3943:         if ($result ne 'ok') {
1.130     raeburn  3944:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  3945:         }
                   3946:     }
                   3947:     return ($url,$error);
                   3948: }
1.43      raeburn  3949: 
1.49      raeburn  3950: sub print_coursecategories {
1.57      raeburn  3951:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   3952:     my $datatable;
                   3953:     if ($position eq 'top') {
                   3954:         my $toggle_cats_crs = ' ';
                   3955:         my $toggle_cats_dom = ' checked="checked" ';
                   3956:         my $can_cat_crs = ' ';
                   3957:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  3958:         my $toggle_catscomm_comm = ' ';
                   3959:         my $toggle_catscomm_dom = ' checked="checked" ';
                   3960:         my $can_catcomm_comm = ' ';
                   3961:         my $can_catcomm_dom = ' checked="checked" ';
                   3962: 
1.57      raeburn  3963:         if (ref($settings) eq 'HASH') {
                   3964:             if ($settings->{'togglecats'} eq 'crs') {
                   3965:                 $toggle_cats_crs = $toggle_cats_dom;
                   3966:                 $toggle_cats_dom = ' ';
                   3967:             }
                   3968:             if ($settings->{'categorize'} eq 'crs') {
                   3969:                 $can_cat_crs = $can_cat_dom;
                   3970:                 $can_cat_dom = ' ';
                   3971:             }
1.120     raeburn  3972:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   3973:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   3974:                 $toggle_catscomm_dom = ' ';
                   3975:             }
                   3976:             if ($settings->{'categorizecomm'} eq 'comm') {
                   3977:                 $can_catcomm_comm = $can_catcomm_dom;
                   3978:                 $can_catcomm_dom = ' ';
                   3979:             }
1.57      raeburn  3980:         }
                   3981:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  3982:                      togglecats     => 'Show/Hide a course in catalog',
                   3983:                      togglecatscomm => 'Show/Hide a community in catalog',
                   3984:                      categorize     => 'Assign a category to a course',
                   3985:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  3986:                     );
                   3987:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  3988:                      dom  => 'Set in Domain',
                   3989:                      crs  => 'Set in Course',
                   3990:                      comm => 'Set in Community',
1.57      raeburn  3991:                     );
                   3992:         $datatable = '<tr class="LC_odd_row">'.
                   3993:                   '<td>'.$title{'togglecats'}.'</td>'.
                   3994:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3995:                   '<input type="radio" name="togglecats"'.
                   3996:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3997:                   '<label><input type="radio" name="togglecats"'.
                   3998:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   3999:                   '</tr><tr>'.
                   4000:                   '<td>'.$title{'categorize'}.'</td>'.
                   4001:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4002:                   '<label><input type="radio" name="categorize"'.
                   4003:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4004:                   '<label><input type="radio" name="categorize"'.
                   4005:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  4006:                   '</tr><tr class="LC_odd_row">'.
                   4007:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   4008:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4009:                   '<input type="radio" name="togglecatscomm"'.
                   4010:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4011:                   '<label><input type="radio" name="togglecatscomm"'.
                   4012:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   4013:                   '</tr><tr>'.
                   4014:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   4015:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4016:                   '<label><input type="radio" name="categorizecomm"'.
                   4017:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4018:                   '<label><input type="radio" name="categorizecomm"'.
                   4019:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  4020:                   '</tr>';
1.120     raeburn  4021:         $$rowtotal += 4;
1.57      raeburn  4022:     } else {
                   4023:         my $css_class;
                   4024:         my $itemcount = 1;
                   4025:         my $cathash; 
                   4026:         if (ref($settings) eq 'HASH') {
                   4027:             $cathash = $settings->{'cats'};
                   4028:         }
                   4029:         if (ref($cathash) eq 'HASH') {
                   4030:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   4031:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   4032:                                                    \%allitems,\%idx,\@jsarray);
                   4033:             my $maxdepth = scalar(@cats);
                   4034:             my $colattrib = '';
                   4035:             if ($maxdepth > 2) {
                   4036:                 $colattrib = ' colspan="2" ';
                   4037:             }
                   4038:             my @path;
                   4039:             if (@cats > 0) {
                   4040:                 if (ref($cats[0]) eq 'ARRAY') {
                   4041:                     my $numtop = @{$cats[0]};
                   4042:                     my $maxnum = $numtop;
1.120     raeburn  4043:                     my %default_names = (
                   4044:                           instcode    => &mt('Official courses'),
                   4045:                           communities => &mt('Communities'),
                   4046:                     );
                   4047: 
                   4048:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   4049:                         ($cathash->{'instcode::0'} eq '') ||
                   4050:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   4051:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  4052:                         $maxnum ++;
                   4053:                     }
                   4054:                     my $lastidx;
                   4055:                     for (my $i=0; $i<$numtop; $i++) {
                   4056:                         my $parent = $cats[0][$i];
                   4057:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4058:                         my $item = &escape($parent).'::0';
                   4059:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   4060:                         $lastidx = $idx{$item};
                   4061:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4062:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   4063:                         for (my $k=0; $k<=$maxnum; $k++) {
                   4064:                             my $vpos = $k+1;
                   4065:                             my $selstr;
                   4066:                             if ($k == $i) {
                   4067:                                 $selstr = ' selected="selected" ';
                   4068:                             }
                   4069:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4070:                         }
                   4071:                         $datatable .= '</select></td><td>';
1.120     raeburn  4072:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   4073:                             $datatable .=  '<span class="LC_nobreak">'
                   4074:                                            .$default_names{$parent}.'</span>';
                   4075:                             if ($parent eq 'instcode') {
                   4076:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   4077:                                               .&mt('with institutional codes')
                   4078:                                               .')</span></td><td'.$colattrib.'>';
                   4079:                             } else {
                   4080:                                 $datatable .= '<table><tr><td>';
                   4081:                             }
                   4082:                             $datatable .= '<span class="LC_nobreak">'
                   4083:                                           .'<label><input type="radio" name="'
                   4084:                                           .$parent.'" value="1" checked="checked" />'
                   4085:                                           .&mt('Display').'</label>';
                   4086:                             if ($parent eq 'instcode') {
                   4087:                                 $datatable .= '&nbsp;';
                   4088:                             } else {
                   4089:                                 $datatable .= '</span></td></tr><tr><td>'
                   4090:                                               .'<span class="LC_nobreak">';
                   4091:                             }
                   4092:                             $datatable .= '<label><input type="radio" name="'
                   4093:                                           .$parent.'" value="0" />'
                   4094:                                           .&mt('Do not display').'</label></span>';
                   4095:                             if ($parent eq 'communities') {
                   4096:                                 $datatable .= '</td></tr></table>';
                   4097:                             }
                   4098:                             $datatable .= '</td>';
1.57      raeburn  4099:                         } else {
                   4100:                             $datatable .= $parent
                   4101:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                   4102:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   4103:                         }
                   4104:                         my $depth = 1;
                   4105:                         push(@path,$parent);
                   4106:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   4107:                         pop(@path);
                   4108:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   4109:                         $itemcount ++;
                   4110:                     }
1.48      raeburn  4111:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  4112:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   4113:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  4114:                     for (my $k=0; $k<=$maxnum; $k++) {
                   4115:                         my $vpos = $k+1;
                   4116:                         my $selstr;
1.57      raeburn  4117:                         if ($k == $numtop) {
1.48      raeburn  4118:                             $selstr = ' selected="selected" ';
                   4119:                         }
                   4120:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4121:                     }
1.59      bisitz   4122:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  4123:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   4124:                                   .'</tr>'."\n";
1.48      raeburn  4125:                     $itemcount ++;
1.120     raeburn  4126:                     foreach my $default ('instcode','communities') {
                   4127:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   4128:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4129:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   4130:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   4131:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   4132:                             for (my $k=0; $k<=$maxnum; $k++) {
                   4133:                                 my $vpos = $k+1;
                   4134:                                 my $selstr;
                   4135:                                 if ($k == $maxnum) {
                   4136:                                     $selstr = ' selected="selected" ';
                   4137:                                 }
                   4138:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  4139:                             }
1.120     raeburn  4140:                             $datatable .= '</select></span></td>'.
                   4141:                                           '<td><span class="LC_nobreak">'.
                   4142:                                           $default_names{$default}.'</span>';
                   4143:                             if ($default eq 'instcode') {
                   4144:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   4145:                                               .&mt('with institutional codes').')</span>';
                   4146:                             }
                   4147:                             $datatable .= '</td>'
                   4148:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   4149:                                           .&mt('Display').'</label>&nbsp;'
                   4150:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   4151:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  4152:                         }
                   4153:                     }
                   4154:                 }
1.57      raeburn  4155:             } else {
                   4156:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  4157:             }
                   4158:         } else {
1.57      raeburn  4159:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   4160:                           .&initialize_categories($itemcount);
1.48      raeburn  4161:         }
1.57      raeburn  4162:         $$rowtotal += $itemcount;
1.48      raeburn  4163:     }
                   4164:     return $datatable;
                   4165: }
                   4166: 
1.69      raeburn  4167: sub print_serverstatuses {
                   4168:     my ($dom,$settings,$rowtotal) = @_;
                   4169:     my $datatable;
                   4170:     my @pages = &serverstatus_pages();
                   4171:     my (%namedaccess,%machineaccess);
                   4172:     foreach my $type (@pages) {
                   4173:         $namedaccess{$type} = '';
                   4174:         $machineaccess{$type}= '';
                   4175:     }
                   4176:     if (ref($settings) eq 'HASH') {
                   4177:         foreach my $type (@pages) {
                   4178:             if (exists($settings->{$type})) {
                   4179:                 if (ref($settings->{$type}) eq 'HASH') {
                   4180:                     foreach my $key (keys(%{$settings->{$type}})) {
                   4181:                         if ($key eq 'namedusers') {
                   4182:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   4183:                         } elsif ($key eq 'machines') {
                   4184:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   4185:                         }
                   4186:                     }
                   4187:                 }
                   4188:             }
                   4189:         }
                   4190:     }
1.81      raeburn  4191:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  4192:     my $rownum = 0;
                   4193:     my $css_class;
                   4194:     foreach my $type (@pages) {
                   4195:         $rownum ++;
                   4196:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4197:         $datatable .= '<tr'.$css_class.'>'.
                   4198:                       '<td><span class="LC_nobreak">'.
                   4199:                       $titles->{$type}.'</span></td>'.
                   4200:                       '<td class="LC_left_item">'.
                   4201:                       '<input type="text" name="'.$type.'_namedusers" '.
                   4202:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   4203:                       '<td class="LC_right_item">'.
                   4204:                       '<span class="LC_nobreak">'.
                   4205:                       '<input type="text" name="'.$type.'_machines" '.
                   4206:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   4207:                       '</td></tr>'."\n";
                   4208:     }
                   4209:     $$rowtotal += $rownum;
                   4210:     return $datatable;
                   4211: }
                   4212: 
                   4213: sub serverstatus_pages {
                   4214:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189     raeburn  4215:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156     raeburn  4216:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69      raeburn  4217: }
                   4218: 
1.49      raeburn  4219: sub coursecategories_javascript {
                   4220:     my ($settings) = @_;
1.57      raeburn  4221:     my ($output,$jstext,$cathash);
1.49      raeburn  4222:     if (ref($settings) eq 'HASH') {
1.57      raeburn  4223:         $cathash = $settings->{'cats'};
                   4224:     }
                   4225:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  4226:         my (@cats,@jsarray,%idx);
1.57      raeburn  4227:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  4228:         if (@jsarray > 0) {
                   4229:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   4230:             for (my $i=0; $i<@jsarray; $i++) {
                   4231:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   4232:                     my $catstr = join('","',@{$jsarray[$i]});
                   4233:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   4234:                 }
                   4235:             }
                   4236:         }
                   4237:     } else {
                   4238:         $jstext  = '    var categories = Array(1);'."\n".
                   4239:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   4240:     }
1.120     raeburn  4241:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   4242:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   4243:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  4244:     $output = <<"ENDSCRIPT";
                   4245: <script type="text/javascript">
1.109     raeburn  4246: // <![CDATA[
1.49      raeburn  4247: function reorderCats(form,parent,item,idx) {
                   4248:     var changedVal;
                   4249: $jstext
                   4250:     var newpos = 'addcategory_pos';
                   4251:     var current = new Array;
                   4252:     if (parent == '') {
                   4253:         var has_instcode = 0;
                   4254:         var maxtop = categories[idx].length;
                   4255:         for (var j=0; j<maxtop; j++) {
                   4256:             if (categories[idx][j] == 'instcode::0') {
                   4257:                 has_instcode == 1;
                   4258:             }
                   4259:         }
                   4260:         if (has_instcode == 0) {
                   4261:             categories[idx][maxtop] = 'instcode_pos';
                   4262:         }
                   4263:     } else {
                   4264:         newpos += '_'+parent;
                   4265:     }
                   4266:     var maxh = 1 + categories[idx].length;
                   4267:     var current = new Array;
                   4268:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4269:     if (item == newpos) {
                   4270:         changedVal = newitemVal;
                   4271:     } else {
                   4272:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4273:         current[newitemVal] = newpos;
                   4274:     }
                   4275:     for (var i=0; i<categories[idx].length; i++) {
                   4276:         var elementName = categories[idx][i];
                   4277:         if (elementName != item) {
                   4278:             if (form.elements[elementName]) {
                   4279:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4280:                 current[currVal] = elementName;
                   4281:             }
                   4282:         }
                   4283:     }
                   4284:     var oldVal;
                   4285:     for (var j=0; j<maxh; j++) {
                   4286:         if (current[j] == undefined) {
                   4287:             oldVal = j;
                   4288:         }
                   4289:     }
                   4290:     if (oldVal < changedVal) {
                   4291:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4292:            var elementName = current[k];
                   4293:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4294:         }
                   4295:     } else {
                   4296:         for (var k=changedVal; k<oldVal; k++) {
                   4297:             var elementName = current[k];
                   4298:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4299:         }
                   4300:     }
                   4301:     return;
                   4302: }
1.120     raeburn  4303: 
                   4304: function categoryCheck(form) {
                   4305:     if (form.elements['addcategory_name'].value == 'instcode') {
                   4306:         alert('$instcode_reserved\\n$choose_again');
                   4307:         return false;
                   4308:     }
                   4309:     if (form.elements['addcategory_name'].value == 'communities') {
                   4310:         alert('$communities_reserved\\n$choose_again');
                   4311:         return false;
                   4312:     }
                   4313:     return true;
                   4314: }
                   4315: 
1.109     raeburn  4316: // ]]>
1.49      raeburn  4317: </script>
                   4318: 
                   4319: ENDSCRIPT
                   4320:     return $output;
                   4321: }
                   4322: 
1.48      raeburn  4323: sub initialize_categories {
                   4324:     my ($itemcount) = @_;
1.120     raeburn  4325:     my ($datatable,$css_class,$chgstr);
                   4326:     my %default_names = (
                   4327:                       instcode    => 'Official courses (with institutional codes)',
                   4328:                       communities => 'Communities',
                   4329:                         );
                   4330:     my $select0 = ' selected="selected"';
                   4331:     my $select1 = '';
                   4332:     foreach my $default ('instcode','communities') {
                   4333:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4334:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   4335:         if ($default eq 'communities') {
                   4336:             $select1 = $select0;
                   4337:             $select0 = '';
                   4338:         }
                   4339:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4340:                      .'<select name="'.$default.'_pos">'
                   4341:                      .'<option value="0"'.$select0.'>1</option>'
                   4342:                      .'<option value="1"'.$select1.'>2</option>'
                   4343:                      .'<option value="2">3</option></select>&nbsp;'
                   4344:                      .$default_names{$default}
                   4345:                      .'</span></td><td><span class="LC_nobreak">'
                   4346:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   4347:                      .&mt('Display').'</label>&nbsp;<label>'
                   4348:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  4349:                  .'</label></span></td></tr>';
1.120     raeburn  4350:         $itemcount ++;
                   4351:     }
1.48      raeburn  4352:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  4353:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4354:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4355:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4356:                   .'<option value="0">1</option>'
                   4357:                   .'<option value="1">2</option>'
                   4358:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4359:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4360:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4361:     return $datatable;
                   4362: }
                   4363: 
                   4364: sub build_category_rows {
1.49      raeburn  4365:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4366:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4367:     if (ref($cats) eq 'ARRAY') {
                   4368:         my $maxdepth = scalar(@{$cats});
                   4369:         if (ref($cats->[$depth]) eq 'HASH') {
                   4370:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4371:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4372:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4373:                 $text .= '<td><table class="LC_datatable">';
1.49      raeburn  4374:                 my ($idxnum,$parent_name,$parent_item);
                   4375:                 my $higher = $depth - 1;
                   4376:                 if ($higher == 0) {
                   4377:                     $parent_name = &escape($parent).'::'.$higher;
                   4378:                 } else {
                   4379:                     if (ref($path) eq 'ARRAY') {
                   4380:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4381:                     }
                   4382:                 }
                   4383:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4384:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4385:                     if ($j < $numchildren) {
1.48      raeburn  4386:                         $name = $cats->[$depth]{$parent}[$j];
                   4387:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4388:                         $idxnum = $idx->{$item};
                   4389:                     } else {
                   4390:                         $name = $parent_name;
                   4391:                         $item = $parent_item;
1.48      raeburn  4392:                     }
1.49      raeburn  4393:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4394:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  4395:                     for (my $i=0; $i<=$numchildren; $i++) {
                   4396:                         my $vpos = $i+1;
                   4397:                         my $selstr;
                   4398:                         if ($j == $i) {
                   4399:                             $selstr = ' selected="selected" ';
                   4400:                         }
                   4401:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   4402:                     }
                   4403:                     $text .= '</select>&nbsp;';
                   4404:                     if ($j < $numchildren) {
                   4405:                         my $deeper = $depth+1;
                   4406:                         $text .= $name.'&nbsp;'
                   4407:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   4408:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   4409:                         if(ref($path) eq 'ARRAY') {
                   4410:                             push(@{$path},$name);
1.49      raeburn  4411:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  4412:                             pop(@{$path});
                   4413:                         }
                   4414:                     } else {
1.59      bisitz   4415:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  4416:                         if ($j == $numchildren) {
                   4417:                             $text .= $name;
                   4418:                         } else {
                   4419:                             $text .= $item;
                   4420:                         }
                   4421:                         $text .= '" value="" />';
                   4422:                     }
                   4423:                     $text .= '</td></tr>';
                   4424:                 }
                   4425:                 $text .= '</table></td>';
                   4426:             } else {
                   4427:                 my $higher = $depth-1;
                   4428:                 if ($higher == 0) {
                   4429:                     $name = &escape($parent).'::'.$higher;
                   4430:                 } else {
                   4431:                     if (ref($path) eq 'ARRAY') {
                   4432:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4433:                     }
                   4434:                 }
                   4435:                 my $colspan;
                   4436:                 if ($parent ne 'instcode') {
                   4437:                     $colspan = $maxdepth - $depth - 1;
                   4438:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   4439:                 }
                   4440:             }
                   4441:         }
                   4442:     }
                   4443:     return $text;
                   4444: }
                   4445: 
1.33      raeburn  4446: sub modifiable_userdata_row {
1.63      raeburn  4447:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33      raeburn  4448:     my $rolename;
1.63      raeburn  4449:     if ($context eq 'selfcreate') {
                   4450:         if (ref($usertypes) eq 'HASH') {
                   4451:             $rolename = $usertypes->{$role};
                   4452:         } else {
                   4453:             $rolename = $role;
                   4454:         }
1.33      raeburn  4455:     } else {
1.63      raeburn  4456:         if ($role eq 'cr') {
                   4457:             $rolename = &mt('Custom role');
                   4458:         } else {
                   4459:             $rolename = &Apache::lonnet::plaintext($role);
                   4460:         }
1.33      raeburn  4461:     }
                   4462:     my @fields = ('lastname','firstname','middlename','generation',
                   4463:                   'permanentemail','id');
                   4464:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4465:     my $output;
                   4466:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4467:     $output = '<tr '.$css_class.'>'.
                   4468:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   4469:               '<td class="LC_left_item" colspan="2"><table>';
                   4470:     my $rem;
                   4471:     my %checks;
                   4472:     if (ref($settings) eq 'HASH') {
                   4473:         if (ref($settings->{$context}) eq 'HASH') {
                   4474:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   4475:                 foreach my $field (@fields) {
                   4476:                     if ($settings->{$context}->{$role}->{$field}) {
                   4477:                         $checks{$field} = ' checked="checked" ';
                   4478:                     }
                   4479:                 }
                   4480:             }
                   4481:         }
                   4482:     }
                   4483:     for (my $i=0; $i<@fields; $i++) {
                   4484:         my $rem = $i%($numinrow);
                   4485:         if ($rem == 0) {
                   4486:             if ($i > 0) {
                   4487:                 $output .= '</tr>';
                   4488:             }
                   4489:             $output .= '<tr>';
                   4490:         }
                   4491:         my $check = ' ';
                   4492:         if (exists($checks{$fields[$i]})) {
                   4493:             $check = $checks{$fields[$i]}
                   4494:         } else {
                   4495:             if ($role eq 'st') {
                   4496:                 if (ref($settings) ne 'HASH') {
                   4497:                     $check = ' checked="checked" '; 
                   4498:                 }
                   4499:             }
                   4500:         }
                   4501:         $output .= '<td class="LC_left_item">'.
                   4502:                    '<span class="LC_nobreak"><label>'.
                   4503:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   4504:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   4505:                    '</label></span></td>';
                   4506:         $rem = @fields%($numinrow);
                   4507:     }
                   4508:     my $colsleft = $numinrow - $rem;
                   4509:     if ($colsleft > 1 ) {
                   4510:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4511:                    '&nbsp;</td>';
                   4512:     } elsif ($colsleft == 1) {
                   4513:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4514:     }
                   4515:     $output .= '</tr></table></td></tr>';
                   4516:     return $output;
                   4517: }
1.28      raeburn  4518: 
1.93      raeburn  4519: sub insttypes_row {
                   4520:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
                   4521:     my %lt = &Apache::lonlocal::texthash (
                   4522:                       cansearch => 'Users allowed to search',
                   4523:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  4524:                       lockablenames => 'User preference to lock name',
1.93      raeburn  4525:              );
                   4526:     my $showdom;
                   4527:     if ($context eq 'cansearch') {
                   4528:         $showdom = ' ('.$dom.')';
                   4529:     }
1.165     raeburn  4530:     my $class = 'LC_left_item';
                   4531:     if ($context eq 'statustocreate') {
                   4532:         $class = 'LC_right_item';
                   4533:     }
1.25      raeburn  4534:     my $output =  '<tr class="LC_odd_row">'.
1.93      raeburn  4535:                   '<td>'.$lt{$context}.$showdom.
1.165     raeburn  4536:                   '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  4537:     my $rem;
                   4538:     if (ref($types) eq 'ARRAY') {
                   4539:         for (my $i=0; $i<@{$types}; $i++) {
                   4540:             if (defined($usertypes->{$types->[$i]})) {
                   4541:                 my $rem = $i%($numinrow);
                   4542:                 if ($rem == 0) {
                   4543:                     if ($i > 0) {
                   4544:                         $output .= '</tr>';
                   4545:                     }
                   4546:                     $output .= '<tr>';
1.23      raeburn  4547:                 }
1.26      raeburn  4548:                 my $check = ' ';
1.99      raeburn  4549:                 if (ref($settings) eq 'HASH') {
                   4550:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   4551:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   4552:                             $check = ' checked="checked" ';
                   4553:                         }
                   4554:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  4555:                         $check = ' checked="checked" ';
                   4556:                     }
1.23      raeburn  4557:                 }
1.26      raeburn  4558:                 $output .= '<td class="LC_left_item">'.
                   4559:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  4560:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  4561:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   4562:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  4563:             }
                   4564:         }
1.26      raeburn  4565:         $rem = @{$types}%($numinrow);
1.23      raeburn  4566:     }
                   4567:     my $colsleft = $numinrow - $rem;
1.131     raeburn  4568:     if (($rem == 0) && (@{$types} > 0)) {
                   4569:         $output .= '<tr>';
                   4570:     }
1.23      raeburn  4571:     if ($colsleft > 1) {
1.25      raeburn  4572:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  4573:     } else {
1.25      raeburn  4574:         $output .= '<td class="LC_left_item">';
1.23      raeburn  4575:     }
                   4576:     my $defcheck = ' ';
1.99      raeburn  4577:     if (ref($settings) eq 'HASH') {  
                   4578:         if (ref($settings->{$context}) eq 'ARRAY') {
                   4579:             if (grep(/^default$/,@{$settings->{$context}})) {
                   4580:                 $defcheck = ' checked="checked" ';
                   4581:             }
                   4582:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  4583:             $defcheck = ' checked="checked" ';
                   4584:         }
1.23      raeburn  4585:     }
1.25      raeburn  4586:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  4587:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  4588:                'value="default"'.$defcheck.'/>'.
                   4589:                $othertitle.'</label></span></td>'.
                   4590:                '</tr></table></td></tr>';
                   4591:     return $output;
1.23      raeburn  4592: }
                   4593: 
                   4594: sub sorted_searchtitles {
                   4595:     my %searchtitles = &Apache::lonlocal::texthash(
                   4596:                          'uname' => 'username',
                   4597:                          'lastname' => 'last name',
                   4598:                          'lastfirst' => 'last name, first name',
                   4599:                      );
                   4600:     my @titleorder = ('uname','lastname','lastfirst');
                   4601:     return (\%searchtitles,\@titleorder);
                   4602: }
                   4603: 
1.25      raeburn  4604: sub sorted_searchtypes {
                   4605:     my %srchtypes_desc = (
                   4606:                            exact    => 'is exact match',
                   4607:                            contains => 'contains ..',
                   4608:                            begins   => 'begins with ..',
                   4609:                          );
                   4610:     my @srchtypeorder = ('exact','begins','contains');
                   4611:     return (\%srchtypes_desc,\@srchtypeorder);
                   4612: }
                   4613: 
1.3       raeburn  4614: sub usertype_update_row {
                   4615:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   4616:     my $datatable;
                   4617:     my $numinrow = 4;
                   4618:     foreach my $type (@{$types}) {
                   4619:         if (defined($usertypes->{$type})) {
                   4620:             $$rownums ++;
                   4621:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   4622:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   4623:                           '</td><td class="LC_left_item"><table>';
                   4624:             for (my $i=0; $i<@{$fields}; $i++) {
                   4625:                 my $rem = $i%($numinrow);
                   4626:                 if ($rem == 0) {
                   4627:                     if ($i > 0) {
                   4628:                         $datatable .= '</tr>';
                   4629:                     }
                   4630:                     $datatable .= '<tr>';
                   4631:                 }
                   4632:                 my $check = ' ';
1.39      raeburn  4633:                 if (ref($settings) eq 'HASH') {
                   4634:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   4635:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   4636:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   4637:                                 $check = ' checked="checked" ';
                   4638:                             }
1.3       raeburn  4639:                         }
                   4640:                     }
                   4641:                 }
                   4642: 
                   4643:                 if ($i == @{$fields}-1) {
                   4644:                     my $colsleft = $numinrow - $rem;
                   4645:                     if ($colsleft > 1) {
                   4646:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   4647:                     } else {
                   4648:                         $datatable .= '<td>';
                   4649:                     }
                   4650:                 } else {
                   4651:                     $datatable .= '<td>';
                   4652:                 }
1.8       raeburn  4653:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4654:                               '<input type="checkbox" name="updateable_'.$type.
                   4655:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   4656:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  4657:             }
                   4658:             $datatable .= '</tr></table></td></tr>';
                   4659:         }
                   4660:     }
                   4661:     return $datatable;
1.1       raeburn  4662: }
                   4663: 
                   4664: sub modify_login {
1.9       raeburn  4665:     my ($r,$dom,$confname,%domconfig) = @_;
1.168     raeburn  4666:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   4667:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   4668:     %title = ( coursecatalog => 'Display course catalog',
                   4669:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  4670:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  4671:                newuser => 'Link for visitors to create a user account',
                   4672:                loginheader => 'Log-in box header');
                   4673:     @offon = ('off','on');
1.112     raeburn  4674:     if (ref($domconfig{login}) eq 'HASH') {
                   4675:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   4676:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   4677:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   4678:             }
                   4679:         }
                   4680:     }
1.9       raeburn  4681:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   4682:                                            \%domconfig,\%loginhash);
1.188     raeburn  4683:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  4684:     foreach my $item (@toggles) {
                   4685:         $loginhash{login}{$item} = $env{'form.'.$item};
                   4686:     }
1.41      raeburn  4687:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  4688:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   4689:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   4690:                                          \%loginhash);
                   4691:     }
1.110     raeburn  4692: 
1.149     raeburn  4693:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  4694:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  4695:     if (keys(%servers) > 1) {
                   4696:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  4697:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   4698:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   4699:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   4700:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   4701:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   4702:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4703:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4704:                         $changes{'loginvia'}{$lonhost} = 1;
                   4705:                     } else {
                   4706:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   4707:                         $changes{'loginvia'}{$lonhost} = 1;
                   4708:                     }
                   4709:                 } else {
                   4710:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4711:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4712:                         $changes{'loginvia'}{$lonhost} = 1;
                   4713:                     }
                   4714:                 }
                   4715:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   4716:                     foreach my $item (@loginvia_attribs) {
                   4717:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   4718:                     }
                   4719:                 } else {
                   4720:                     foreach my $item (@loginvia_attribs) {
                   4721:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4722:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4723:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   4724:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4725:                                 $new = '/';
                   4726:                             }
                   4727:                         }
                   4728:                         if (($item eq 'custompath') && 
                   4729:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4730:                             $new = '';
                   4731:                         }
                   4732:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   4733:                             $changes{'loginvia'}{$lonhost} = 1;
                   4734:                         }
                   4735:                         if ($item eq 'exempt') {
                   4736:                             $new =~ s/^\s+//;
                   4737:                             $new =~ s/\s+$//;
                   4738:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   4739:                             my @okips;
                   4740:                             foreach my $ip (@poss_ips) {
                   4741:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   4742:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   4743:                                         push(@okips,$ip); 
                   4744:                                     }
                   4745:                                 }
                   4746:                             }
                   4747:                             if (@okips > 0) {
                   4748:                                 $new = join(',',@okips); 
                   4749:                             } else {
                   4750:                                 $new = ''; 
                   4751:                             }
                   4752:                         }
                   4753:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4754:                     }
                   4755:                 }
1.112     raeburn  4756:             } else {
1.128     raeburn  4757:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4758:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  4759:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  4760:                     foreach my $item (@loginvia_attribs) {
                   4761:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4762:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4763:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4764:                                 $new = '/';
                   4765:                             }
                   4766:                         }
                   4767:                         if (($item eq 'custompath') && 
                   4768:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4769:                             $new = '';
                   4770:                         }
                   4771:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4772:                     }
1.110     raeburn  4773:                 }
                   4774:             }
                   4775:         }
                   4776:     }
1.119     raeburn  4777: 
1.168     raeburn  4778:     my $servadm = $r->dir_config('lonAdmEMail');
                   4779:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   4780:     if (ref($domconfig{'login'}) eq 'HASH') {
                   4781:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   4782:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   4783:                 if ($lang eq 'nolang') {
                   4784:                     push(@currlangs,$lang);
                   4785:                 } elsif (defined($langchoices{$lang})) {
                   4786:                     push(@currlangs,$lang);
                   4787:                 } else {
                   4788:                     next;
                   4789:                 }
                   4790:             }
                   4791:         }
                   4792:     }
                   4793:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   4794:     if (@currlangs > 0) {
                   4795:         foreach my $lang (@currlangs) {
                   4796:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   4797:                 $changes{'helpurl'}{$lang} = 1;
                   4798:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   4799:                 $changes{'helpurl'}{$lang} = 1;
                   4800:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   4801:                 push(@newlangs,$lang);
                   4802:             } else {
                   4803:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4804:             }
                   4805:         }
                   4806:     }
                   4807:     unless (grep(/^nolang$/,@currlangs)) {
                   4808:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   4809:             $changes{'helpurl'}{'nolang'} = 1;
                   4810:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   4811:             push(@newlangs,'nolang');
                   4812:         }
                   4813:     }
                   4814:     if ($env{'form.loginhelpurl_add_lang'}) {
                   4815:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   4816:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   4817:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   4818:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   4819:         }
                   4820:     }
                   4821:     if ((@newlangs > 0) || ($addedfile)) {
                   4822:         my $error;
                   4823:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   4824:         if ($configuserok eq 'ok') {
                   4825:             if ($switchserver) {
                   4826:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   4827:             } elsif ($author_ok eq 'ok') {
                   4828:                 my @allnew = @newlangs;
                   4829:                 if ($addedfile ne '') {
                   4830:                     push(@allnew,$addedfile);
                   4831:                 }
                   4832:                 foreach my $lang (@allnew) {
                   4833:                     my $formelem = 'loginhelpurl_'.$lang;
                   4834:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   4835:                         $formelem = 'loginhelpurl_add_file';
                   4836:                     }
                   4837:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   4838:                                                                "help/$lang",'','',$newfile{$lang});
                   4839:                     if ($result eq 'ok') {
                   4840:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   4841:                         $changes{'helpurl'}{$lang} = 1;
                   4842:                     } else {
                   4843:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   4844:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   4845:                         if ((grep(/^\Q$lang\E$/,@currlangs)) && 
                   4846:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   4847: 
                   4848:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4849:                         }
                   4850:                     }
                   4851:                 }
                   4852:             } else {
                   4853:                 $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2].  Error was: [_3].",$confname,$dom,$author_ok);
                   4854:             }
                   4855:         } else {
                   4856:             $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
                   4857:         }
                   4858:         if ($error) {
                   4859:             &Apache::lonnet::logthis($error);
                   4860:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   4861:         }
                   4862:     }
1.169     raeburn  4863:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  4864: 
                   4865:     my $defaulthelpfile = '/adm/loginproblems.html';
                   4866:     my $defaulttext = &mt('Default in use');
                   4867: 
1.1       raeburn  4868:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   4869:                                              $dom);
                   4870:     if ($putresult eq 'ok') {
1.188     raeburn  4871:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  4872:         my %defaultchecked = (
                   4873:                     'coursecatalog' => 'on',
1.188     raeburn  4874:                     'helpdesk'      => 'on',
1.42      raeburn  4875:                     'adminmail'     => 'off',
1.43      raeburn  4876:                     'newuser'       => 'off',
1.42      raeburn  4877:         );
1.55      raeburn  4878:         if (ref($domconfig{'login'}) eq 'HASH') {
                   4879:             foreach my $item (@toggles) {
                   4880:                 if ($defaultchecked{$item} eq 'on') { 
                   4881:                     if (($domconfig{'login'}{$item} eq '0') &&
                   4882:                         ($env{'form.'.$item} eq '1')) {
                   4883:                         $changes{$item} = 1;
                   4884:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4885:                               $domconfig{'login'}{$item} eq '1') &&
                   4886:                              ($env{'form.'.$item} eq '0')) {
                   4887:                         $changes{$item} = 1;
                   4888:                     }
                   4889:                 } elsif ($defaultchecked{$item} eq 'off') {
                   4890:                     if (($domconfig{'login'}{$item} eq '1') &&
                   4891:                         ($env{'form.'.$item} eq '0')) {
                   4892:                         $changes{$item} = 1;
                   4893:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4894:                               $domconfig{'login'}{$item} eq '0') &&
                   4895:                              ($env{'form.'.$item} eq '1')) {
                   4896:                         $changes{$item} = 1;
                   4897:                     }
1.42      raeburn  4898:                 }
                   4899:             }
1.41      raeburn  4900:         }
1.6       raeburn  4901:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  4902:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1       raeburn  4903:             $resulttext = &mt('Changes made:').'<ul>';
                   4904:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   4905:                 if ($item eq 'loginvia') {
1.112     raeburn  4906:                     if (ref($changes{$item}) eq 'HASH') {
                   4907:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   4908:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  4909:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   4910:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   4911:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   4912:                                     $protocol = 'http' if ($protocol ne 'https');
                   4913:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   4914: 
                   4915:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   4916:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   4917:                                     } else {
                   4918:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   4919:                                     }
                   4920:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   4921:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   4922:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   4923:                                     }
                   4924:                                     $resulttext .= '</li>';
                   4925:                                 } else {
                   4926:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   4927:                                 }
1.112     raeburn  4928:                             } else {
1.128     raeburn  4929:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  4930:                             }
                   4931:                         }
1.128     raeburn  4932:                         $resulttext .= '</ul></li>';
1.112     raeburn  4933:                     }
1.168     raeburn  4934:                 } elsif ($item eq 'helpurl') {
                   4935:                     if (ref($changes{$item}) eq 'HASH') {
                   4936:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   4937:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   4938:                                 my ($chg,$link);
                   4939:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   4940:                                 if ($lang eq 'nolang') {
                   4941:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   4942:                                 } else {
                   4943:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   4944:                                 }
                   4945:                                 $resulttext .= '<li>'.$chg.'</li>';
                   4946:                             } else {
                   4947:                                 my $chg;
                   4948:                                 if ($lang eq 'nolang') {
                   4949:                                     $chg = &mt('custom log-in help file for no preferred language');
                   4950:                                 } else {
                   4951:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   4952:                                 }
                   4953:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   4954:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   4955:                                                       '?inhibitmenu=yes',$chg,600,500).
                   4956:                                                '</li>';
                   4957:                             }
                   4958:                         }
                   4959:                     }
1.169     raeburn  4960:                 } elsif ($item eq 'captcha') {
                   4961:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   4962:                         my $chgtxt; 
                   4963:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   4964:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   4965:                         } else {
                   4966:                             my %captchas = &captcha_phrases();
                   4967:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   4968:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   4969:                             } else {
                   4970:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   4971:                             }
                   4972:                         }
                   4973:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   4974:                     }
                   4975:                 } elsif ($item eq 'recaptchakeys') {
                   4976:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   4977:                         my ($privkey,$pubkey);
                   4978:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   4979:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   4980:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   4981:                         }
                   4982:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   4983:                         if (!$pubkey) {
                   4984:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   4985:                         } else {
                   4986:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   4987:                         }
                   4988:                         if (!$privkey) {
                   4989:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   4990:                         } else {
                   4991:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   4992:                         }
                   4993:                         $chgtxt .= '</ul>';
                   4994:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   4995:                     }
1.41      raeburn  4996:                 } else {
                   4997:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   4998:                 }
1.1       raeburn  4999:             }
1.6       raeburn  5000:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  5001:         } else {
                   5002:             $resulttext = &mt('No changes made to log-in page settings');
                   5003:         }
                   5004:     } else {
1.11      albertel 5005:         $resulttext = '<span class="LC_error">'.
                   5006: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5007:     }
1.6       raeburn  5008:     if ($errors) {
1.9       raeburn  5009:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  5010:                        $errors.'</ul>';
                   5011:     }
                   5012:     return $resulttext;
                   5013: }
                   5014: 
                   5015: sub color_font_choices {
                   5016:     my %choices =
                   5017:         &Apache::lonlocal::texthash (
                   5018:             img => "Header",
                   5019:             bgs => "Background colors",
                   5020:             links => "Link colors",
1.55      raeburn  5021:             images => "Images",
1.6       raeburn  5022:             font => "Font color",
1.97      tempelho 5023:             fontmenu => "Font Menu",
1.76      raeburn  5024:             pgbg => "Page",
1.6       raeburn  5025:             tabbg => "Header",
                   5026:             sidebg => "Border",
                   5027:             link => "Link",
                   5028:             alink => "Active link",
                   5029:             vlink => "Visited link",
                   5030:         );
                   5031:     return %choices;
                   5032: }
                   5033: 
                   5034: sub modify_rolecolors {
1.9       raeburn  5035:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6       raeburn  5036:     my ($resulttext,%rolehash);
                   5037:     $rolehash{'rolecolors'} = {};
1.55      raeburn  5038:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   5039:         if ($domconfig{'rolecolors'} eq '') {
                   5040:             $domconfig{'rolecolors'} = {};
                   5041:         }
                   5042:     }
1.9       raeburn  5043:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  5044:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   5045:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   5046:                                              $dom);
                   5047:     if ($putresult eq 'ok') {
                   5048:         if (keys(%changes) > 0) {
1.41      raeburn  5049:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6       raeburn  5050:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   5051:                                              $rolehash{'rolecolors'});
                   5052:         } else {
                   5053:             $resulttext = &mt('No changes made to default color schemes');
                   5054:         }
                   5055:     } else {
1.11      albertel 5056:         $resulttext = '<span class="LC_error">'.
                   5057: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  5058:     }
                   5059:     if ($errors) {
                   5060:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   5061:                        $errors.'</ul>';
                   5062:     }
                   5063:     return $resulttext;
                   5064: }
                   5065: 
                   5066: sub modify_colors {
1.9       raeburn  5067:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  5068:     my (%changes,%choices);
1.51      raeburn  5069:     my @bgs;
1.6       raeburn  5070:     my @links = ('link','alink','vlink');
1.41      raeburn  5071:     my @logintext;
1.6       raeburn  5072:     my @images;
                   5073:     my $servadm = $r->dir_config('lonAdmEMail');
                   5074:     my $errors;
                   5075:     foreach my $role (@{$roles}) {
                   5076:         if ($role eq 'login') {
1.12      raeburn  5077:             %choices = &login_choices();
1.41      raeburn  5078:             @logintext = ('textcol','bgcol');
1.12      raeburn  5079:         } else {
                   5080:             %choices = &color_font_choices();
1.107     raeburn  5081:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12      raeburn  5082:         }
                   5083:         if ($role eq 'login') {
1.41      raeburn  5084:             @images = ('img','logo','domlogo','login');
1.51      raeburn  5085:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  5086:         } else {
                   5087:             @images = ('img');
1.51      raeburn  5088:             @bgs = ('pgbg','tabbg','sidebg'); 
1.6       raeburn  5089:         }
                   5090:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41      raeburn  5091:         foreach my $item (@bgs,@links,@logintext) {
1.6       raeburn  5092:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5093:         }
1.46      raeburn  5094:         my ($configuserok,$author_ok,$switchserver) = 
                   5095:             &config_check($dom,$confname,$servadm);
1.9       raeburn  5096:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  5097:         if (ref($domconfig->{$role}) ne 'HASH') {
                   5098:             $domconfig->{$role} = {};
                   5099:         }
1.8       raeburn  5100:         foreach my $img (@images) {
1.70      raeburn  5101:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   5102:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   5103:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   5104:                 } else { 
                   5105:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   5106:                 }
                   5107:             } 
1.18      albertel 5108: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   5109: 		 && !defined($domconfig->{$role}{$img})
                   5110: 		 && !$env{'form.'.$role.'_del_'.$img}
                   5111: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   5112: 		# import the old configured image from the .tab setting
                   5113: 		# if they haven't provided a new one 
                   5114: 		$domconfig->{$role}{$img} = 
                   5115: 		    $env{'form.'.$role.'_import_'.$img};
                   5116: 	    }
1.6       raeburn  5117:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  5118:                 my $error;
1.6       raeburn  5119:                 if ($configuserok eq 'ok') {
1.9       raeburn  5120:                     if ($switchserver) {
1.12      raeburn  5121:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  5122:                     } else {
                   5123:                         if ($author_ok eq 'ok') {
                   5124:                             my ($result,$logourl) = 
                   5125:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   5126:                                            $dom,$confname,$img,$width,$height);
                   5127:                             if ($result eq 'ok') {
                   5128:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  5129:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5130:                             } else {
1.12      raeburn  5131:                                 $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  5132:                             }
                   5133:                         } else {
1.46      raeburn  5134:                             $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  5135:                         }
                   5136:                     }
                   5137:                 } else {
1.46      raeburn  5138:                     $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  5139:                 }
                   5140:                 if ($error) {
1.8       raeburn  5141:                     &Apache::lonnet::logthis($error);
1.11      albertel 5142:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  5143:                 }
                   5144:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  5145:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   5146:                     my $error;
                   5147:                     if ($configuserok eq 'ok') {
                   5148: # is confname an author?
                   5149:                         if ($switchserver eq '') {
                   5150:                             if ($author_ok eq 'ok') {
                   5151:                                 my ($result,$logourl) = 
                   5152:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   5153:                                             $dom,$confname,$img,$width,$height);
                   5154:                                 if ($result eq 'ok') {
                   5155:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 5156: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5157:                                 }
                   5158:                             }
                   5159:                         }
                   5160:                     }
1.6       raeburn  5161:                 }
                   5162:             }
                   5163:         }
                   5164:         if (ref($domconfig) eq 'HASH') {
                   5165:             if (ref($domconfig->{$role}) eq 'HASH') {
                   5166:                 foreach my $img (@images) {
                   5167:                     if ($domconfig->{$role}{$img} ne '') {
                   5168:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5169:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5170:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5171:                         } else {
1.9       raeburn  5172:                             if ($confhash->{$role}{$img} eq '') {
                   5173:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   5174:                             }
1.6       raeburn  5175:                         }
                   5176:                     } else {
                   5177:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5178:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5179:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5180:                         } 
                   5181:                     }
1.70      raeburn  5182:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   5183:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   5184:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   5185:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   5186:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   5187:                             }
                   5188:                         } else {
                   5189:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5190:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   5191:                             }
                   5192:                         }
                   5193:                     }
                   5194:                 }
1.6       raeburn  5195:                 if ($domconfig->{$role}{'font'} ne '') {
                   5196:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   5197:                         $changes{$role}{'font'} = 1;
                   5198:                     }
                   5199:                 } else {
                   5200:                     if ($confhash->{$role}{'font'}) {
                   5201:                         $changes{$role}{'font'} = 1;
                   5202:                     }
                   5203:                 }
1.107     raeburn  5204:                 if ($role ne 'login') {
                   5205:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   5206:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   5207:                             $changes{$role}{'fontmenu'} = 1;
                   5208:                         }
                   5209:                     } else {
                   5210:                         if ($confhash->{$role}{'fontmenu'}) {
                   5211:                             $changes{$role}{'fontmenu'} = 1;
                   5212:                         }
1.97      tempelho 5213:                     }
                   5214:                 }
1.6       raeburn  5215:                 foreach my $item (@bgs) {
                   5216:                     if ($domconfig->{$role}{$item} ne '') {
                   5217:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5218:                             $changes{$role}{'bgs'}{$item} = 1;
                   5219:                         } 
                   5220:                     } else {
                   5221:                         if ($confhash->{$role}{$item}) {
                   5222:                             $changes{$role}{'bgs'}{$item} = 1;
                   5223:                         }
                   5224:                     }
                   5225:                 }
                   5226:                 foreach my $item (@links) {
                   5227:                     if ($domconfig->{$role}{$item} ne '') {
                   5228:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5229:                             $changes{$role}{'links'}{$item} = 1;
                   5230:                         }
                   5231:                     } else {
                   5232:                         if ($confhash->{$role}{$item}) {
                   5233:                             $changes{$role}{'links'}{$item} = 1;
                   5234:                         }
                   5235:                     }
                   5236:                 }
1.41      raeburn  5237:                 foreach my $item (@logintext) {
                   5238:                     if ($domconfig->{$role}{$item} ne '') {
                   5239:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5240:                             $changes{$role}{'logintext'}{$item} = 1;
                   5241:                         }
                   5242:                     } else {
                   5243:                         if ($confhash->{$role}{$item}) {
                   5244:                             $changes{$role}{'logintext'}{$item} = 1;
                   5245:                         }
                   5246:                     }
                   5247:                 }
1.6       raeburn  5248:             } else {
                   5249:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5250:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  5251:             }
                   5252:         } else {
                   5253:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5254:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  5255:         }
                   5256:     }
                   5257:     return ($errors,%changes);
                   5258: }
                   5259: 
1.46      raeburn  5260: sub config_check {
                   5261:     my ($dom,$confname,$servadm) = @_;
                   5262:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   5263:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   5264:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   5265:                                                    $confname,$servadm);
                   5266:     if ($configuserok eq 'ok') {
                   5267:         $switchserver = &check_switchserver($dom,$confname);
                   5268:         if ($switchserver eq '') {
                   5269:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   5270:         }
                   5271:     }
                   5272:     return ($configuserok,$author_ok,$switchserver);
                   5273: }
                   5274: 
1.6       raeburn  5275: sub default_change_checker {
1.41      raeburn  5276:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  5277:     foreach my $item (@{$links}) {
                   5278:         if ($confhash->{$role}{$item}) {
                   5279:             $changes->{$role}{'links'}{$item} = 1;
                   5280:         }
                   5281:     }
                   5282:     foreach my $item (@{$bgs}) {
                   5283:         if ($confhash->{$role}{$item}) {
                   5284:             $changes->{$role}{'bgs'}{$item} = 1;
                   5285:         }
                   5286:     }
1.41      raeburn  5287:     foreach my $item (@{$logintext}) {
                   5288:         if ($confhash->{$role}{$item}) {
                   5289:             $changes->{$role}{'logintext'}{$item} = 1;
                   5290:         }
                   5291:     }
1.6       raeburn  5292:     foreach my $img (@{$images}) {
                   5293:         if ($env{'form.'.$role.'_del_'.$img}) {
                   5294:             $confhash->{$role}{$img} = '';
1.12      raeburn  5295:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  5296:         }
1.70      raeburn  5297:         if ($role eq 'login') {
                   5298:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5299:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   5300:             }
                   5301:         }
1.6       raeburn  5302:     }
                   5303:     if ($confhash->{$role}{'font'}) {
                   5304:         $changes->{$role}{'font'} = 1;
                   5305:     }
1.48      raeburn  5306: }
1.6       raeburn  5307: 
                   5308: sub display_colorchgs {
                   5309:     my ($dom,$changes,$roles,$confhash) = @_;
                   5310:     my (%choices,$resulttext);
                   5311:     if (!grep(/^login$/,@{$roles})) {
                   5312:         $resulttext = &mt('Changes made:').'<br />';
                   5313:     }
                   5314:     foreach my $role (@{$roles}) {
                   5315:         if ($role eq 'login') {
                   5316:             %choices = &login_choices();
                   5317:         } else {
                   5318:             %choices = &color_font_choices();
                   5319:         }
                   5320:         if (ref($changes->{$role}) eq 'HASH') {
                   5321:             if ($role ne 'login') {
                   5322:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   5323:             }
                   5324:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   5325:                 if ($role ne 'login') {
                   5326:                     $resulttext .= '<ul>';
                   5327:                 }
                   5328:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   5329:                     if ($role ne 'login') {
                   5330:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   5331:                     }
                   5332:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  5333:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   5334:                             if ($confhash->{$role}{$key}{$item}) {
                   5335:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   5336:                             } else {
                   5337:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   5338:                             }
                   5339:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  5340:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   5341:                         } else {
1.12      raeburn  5342:                             my $newitem = $confhash->{$role}{$item};
                   5343:                             if ($key eq 'images') {
                   5344:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   5345:                             }
                   5346:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  5347:                         }
                   5348:                     }
                   5349:                     if ($role ne 'login') {
                   5350:                         $resulttext .= '</ul></li>';
                   5351:                     }
                   5352:                 } else {
                   5353:                     if ($confhash->{$role}{$key} eq '') {
                   5354:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   5355:                     } else {
                   5356:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   5357:                     }
                   5358:                 }
                   5359:                 if ($role ne 'login') {
                   5360:                     $resulttext .= '</ul>';
                   5361:                 }
                   5362:             }
                   5363:         }
                   5364:     }
1.3       raeburn  5365:     return $resulttext;
1.1       raeburn  5366: }
                   5367: 
1.9       raeburn  5368: sub thumb_dimensions {
                   5369:     return ('200','50');
                   5370: }
                   5371: 
1.16      raeburn  5372: sub check_dimensions {
                   5373:     my ($inputfile) = @_;
                   5374:     my ($fullwidth,$fullheight);
                   5375:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   5376:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   5377:             my $imageinfo = <PIPE>;
                   5378:             if (!close(PIPE)) {
                   5379:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   5380:             }
                   5381:             chomp($imageinfo);
                   5382:             my ($fullsize) = 
1.21      raeburn  5383:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  5384:             if ($fullsize) {
                   5385:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   5386:             }
                   5387:         }
                   5388:     }
                   5389:     return ($fullwidth,$fullheight);
                   5390: }
                   5391: 
1.9       raeburn  5392: sub check_configuser {
                   5393:     my ($uhome,$dom,$confname,$servadm) = @_;
                   5394:     my ($configuserok,%currroles);
                   5395:     if ($uhome eq 'no_host') {
                   5396:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   5397:         my $configpass = &LONCAPA::Enrollment::create_password();
                   5398:         $configuserok = 
                   5399:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   5400:                              $configpass,'','','','','',undef,$servadm);
                   5401:     } else {
                   5402:         $configuserok = 'ok';
                   5403:         %currroles = 
                   5404:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   5405:     }
                   5406:     return ($configuserok,%currroles);
                   5407: }
                   5408: 
                   5409: sub check_authorstatus {
                   5410:     my ($dom,$confname,%currroles) = @_;
                   5411:     my $author_ok;
1.40      raeburn  5412:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  5413:         my $start = time;
                   5414:         my $end = 0;
                   5415:         $author_ok = 
                   5416:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  5417:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  5418:     } else {
                   5419:         $author_ok = 'ok';
                   5420:     }
                   5421:     return $author_ok;
                   5422: }
                   5423: 
                   5424: sub publishlogo {
1.46      raeburn  5425:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  5426:     my ($output,$fname,$logourl);
                   5427:     if ($action eq 'upload') {
                   5428:         $fname=$env{'form.'.$formname.'.filename'};
                   5429:         chop($env{'form.'.$formname});
                   5430:     } else {
                   5431:         ($fname) = ($formname =~ /([^\/]+)$/);
                   5432:     }
1.46      raeburn  5433:     if ($savefileas ne '') {
                   5434:         $fname = $savefileas;
                   5435:     }
1.9       raeburn  5436:     $fname=&Apache::lonnet::clean_filename($fname);
                   5437: # See if there is anything left
                   5438:     unless ($fname) { return ('error: no uploaded file'); }
                   5439:     $fname="$subdir/$fname";
1.164     raeburn  5440:     my $docroot=$r->dir_config('lonDocRoot'); 
                   5441:     my $filepath="$docroot/priv";
                   5442:     my $relpath = "$dom/$confname";
1.9       raeburn  5443:     my ($fnamepath,$file,$fetchthumb);
                   5444:     $file=$fname;
                   5445:     if ($fname=~m|/|) {
                   5446:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   5447:     }
1.164     raeburn  5448:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  5449:     my $count;
1.164     raeburn  5450:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  5451:         $filepath.="/$parts[$count]";
                   5452:         if ((-e $filepath)!=1) {
                   5453:             mkdir($filepath,02770);
                   5454:         }
                   5455:     }
                   5456:     # Check for bad extension and disallow upload
                   5457:     if ($file=~/\.(\w+)$/ &&
                   5458:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   5459:         $output = 
                   5460:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
                   5461:     } elsif ($file=~/\.(\w+)$/ &&
                   5462:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   5463:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   5464:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46      raeburn  5465:         $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  5466:     } elsif (-d "$filepath/$file") {
                   5467:         $output = &mt('File name is a directory name - rename the file and re-upload');
                   5468:     } else {
                   5469:         my $source = $filepath.'/'.$file;
                   5470:         my $logfile;
                   5471:         if (!open($logfile,">>$source".'.log')) {
                   5472:             return (&mt('No write permission to Construction Space'));
                   5473:         }
                   5474:         print $logfile
                   5475: "\n================= Publish ".localtime()." ================\n".
                   5476: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   5477: # Save the file
                   5478:         if (!open(FH,'>'.$source)) {
                   5479:             &Apache::lonnet::logthis('Failed to create '.$source);
                   5480:             return (&mt('Failed to create file'));
                   5481:         }
                   5482:         if ($action eq 'upload') {
                   5483:             if (!print FH ($env{'form.'.$formname})) {
                   5484:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   5485:                 return (&mt('Failed to write file'));
                   5486:             }
                   5487:         } else {
                   5488:             my $original = &Apache::lonnet::filelocation('',$formname);
                   5489:             if(!copy($original,$source)) {
                   5490:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   5491:                 return (&mt('Failed to write file'));
                   5492:             }
                   5493:         }
                   5494:         close(FH);
                   5495:         chmod(0660, $source); # Permissions to rw-rw---.
                   5496: 
                   5497:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   5498:         my $copyfile=$targetdir.'/'.$file;
                   5499: 
                   5500:         my @parts=split(/\//,$targetdir);
                   5501:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   5502:         for (my $count=5;$count<=$#parts;$count++) {
                   5503:             $path.="/$parts[$count]";
                   5504:             if (!-e $path) {
                   5505:                 print $logfile "\nCreating directory ".$path;
                   5506:                 mkdir($path,02770);
                   5507:             }
                   5508:         }
                   5509:         my $versionresult;
                   5510:         if (-e $copyfile) {
                   5511:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   5512:         } else {
                   5513:             $versionresult = 'ok';
                   5514:         }
                   5515:         if ($versionresult eq 'ok') {
                   5516:             if (copy($source,$copyfile)) {
                   5517:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   5518:                 $output = 'ok';
                   5519:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  5520:                 push(@{$modified_urls},[$copyfile,$source]);
                   5521:                 my $metaoutput = 
                   5522:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   5523:                 unless ($registered_cleanup) {
                   5524:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5525:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5526:                     $registered_cleanup=1;
                   5527:                 }
1.9       raeburn  5528:             } else {
                   5529:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   5530:                 $output = &mt('Failed to copy file to RES space').", $!";
                   5531:             }
                   5532:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   5533:                 my $inputfile = $filepath.'/'.$file;
                   5534:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  5535:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   5536:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   5537:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   5538:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   5539:                         system("convert -sample $thumbsize $inputfile $outfile");
                   5540:                         chmod(0660, $filepath.'/tn-'.$file);
                   5541:                         if (-e $outfile) {
                   5542:                             my $copyfile=$targetdir.'/tn-'.$file;
                   5543:                             if (copy($outfile,$copyfile)) {
                   5544:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  5545:                                 my $thumb_metaoutput = 
                   5546:                                     &write_metadata($dom,$confname,$formname,
                   5547:                                                     $targetdir,'tn-'.$file,$logfile);
                   5548:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   5549:                                 unless ($registered_cleanup) {
                   5550:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5551:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5552:                                     $registered_cleanup=1;
                   5553:                                 }
1.16      raeburn  5554:                             } else {
                   5555:                                 print $logfile "\nUnable to write ".$copyfile.
                   5556:                                                ':'.$!."\n";
                   5557:                             }
                   5558:                         }
1.9       raeburn  5559:                     }
                   5560:                 }
                   5561:             }
                   5562:         } else {
                   5563:             $output = $versionresult;
                   5564:         }
                   5565:     }
                   5566:     return ($output,$logourl);
                   5567: }
                   5568: 
                   5569: sub logo_versioning {
                   5570:     my ($targetdir,$file,$logfile) = @_;
                   5571:     my $target = $targetdir.'/'.$file;
                   5572:     my ($maxversion,$fn,$extn,$output);
                   5573:     $maxversion = 0;
                   5574:     if ($file =~ /^(.+)\.(\w+)$/) {
                   5575:         $fn=$1;
                   5576:         $extn=$2;
                   5577:     }
                   5578:     opendir(DIR,$targetdir);
                   5579:     while (my $filename=readdir(DIR)) {
                   5580:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   5581:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   5582:         }
                   5583:     }
                   5584:     $maxversion++;
                   5585:     print $logfile "\nCreating old version ".$maxversion."\n";
                   5586:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   5587:     if (copy($target,$copyfile)) {
                   5588:         print $logfile "Copied old target to ".$copyfile."\n";
                   5589:         $copyfile=$copyfile.'.meta';
                   5590:         if (copy($target.'.meta',$copyfile)) {
                   5591:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   5592:             $output = 'ok';
                   5593:         } else {
                   5594:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   5595:             $output = &mt('Failed to copy old meta').", $!, ";
                   5596:         }
                   5597:     } else {
                   5598:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   5599:         $output = &mt('Failed to copy old target').", $!, ";
                   5600:     }
                   5601:     return $output;
                   5602: }
                   5603: 
                   5604: sub write_metadata {
                   5605:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   5606:     my (%metadatafields,%metadatakeys,$output);
                   5607:     $metadatafields{'title'}=$formname;
                   5608:     $metadatafields{'creationdate'}=time;
                   5609:     $metadatafields{'lastrevisiondate'}=time;
                   5610:     $metadatafields{'copyright'}='public';
                   5611:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   5612:                                          $env{'user.domain'};
                   5613:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   5614:     $metadatafields{'domain'}=$dom;
                   5615:     {
                   5616:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   5617:         my $mfh;
1.155     raeburn  5618:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  5619:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  5620:                 unless ($_=~/\./) {
                   5621:                     my $unikey=$_;
                   5622:                     $unikey=~/^([A-Za-z]+)/;
                   5623:                     my $tag=$1;
                   5624:                     $tag=~tr/A-Z/a-z/;
                   5625:                     print $mfh "\n\<$tag";
                   5626:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   5627:                         my $value=$metadatafields{$unikey.'.'.$_};
                   5628:                         $value=~s/\"/\'\'/g;
                   5629:                         print $mfh ' '.$_.'="'.$value.'"';
                   5630:                     }
                   5631:                     print $mfh '>'.
                   5632:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   5633:                             .'</'.$tag.'>';
                   5634:                 }
                   5635:             }
                   5636:             $output = 'ok';
                   5637:             print $logfile "\nWrote metadata";
                   5638:             close($mfh);
                   5639:         } else {
                   5640:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  5641:             $output = &mt('Could not write metadata');
                   5642:         }
                   5643:     }
1.155     raeburn  5644:     return $output;
                   5645: }
                   5646: 
                   5647: sub notifysubscribed {
                   5648:     foreach my $targetsource (@{$modified_urls}){
                   5649:         next unless (ref($targetsource) eq 'ARRAY');
                   5650:         my ($target,$source)=@{$targetsource};
                   5651:         if ($source ne '') {
                   5652:             if (open(my $logfh,'>>'.$source.'.log')) {
                   5653:                 print $logfh "\nCleanup phase: Notifications\n";
                   5654:                 my @subscribed=&subscribed_hosts($target);
                   5655:                 foreach my $subhost (@subscribed) {
                   5656:                     print $logfh "\nNotifying host ".$subhost.':';
                   5657:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   5658:                     print $logfh $reply;
                   5659:                 }
                   5660:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   5661:                 foreach my $subhost (@subscribedmeta) {
                   5662:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   5663:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   5664:                                                         $subhost);
                   5665:                     print $logfh $reply;
                   5666:                 }
                   5667:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  5668:                 close($logfh);
1.155     raeburn  5669:             }
                   5670:         }
                   5671:     }
                   5672:     return OK;
                   5673: }
                   5674: 
                   5675: sub subscribed_hosts {
                   5676:     my ($target) = @_;
                   5677:     my @subscribed;
                   5678:     if (open(my $fh,"<$target.subscription")) {
                   5679:         while (my $subline=<$fh>) {
                   5680:             if ($subline =~ /^($match_lonid):/) {
                   5681:                 my $host = $1;
                   5682:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   5683:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   5684:                         push(@subscribed,$host);
                   5685:                     }
                   5686:                 }
                   5687:             }
                   5688:         }
                   5689:     }
                   5690:     return @subscribed;
1.9       raeburn  5691: }
                   5692: 
                   5693: sub check_switchserver {
                   5694:     my ($dom,$confname) = @_;
                   5695:     my ($allowed,$switchserver);
                   5696:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   5697:     if ($home eq 'no_host') {
                   5698:         $home = &Apache::lonnet::domain($dom,'primary');
                   5699:     }
                   5700:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 5701:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   5702:     if (!$allowed) {
1.180     raeburn  5703: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  5704:     }
                   5705:     return $switchserver;
                   5706: }
                   5707: 
1.1       raeburn  5708: sub modify_quotas {
1.86      raeburn  5709:     my ($dom,$action,%domconfig) = @_;
1.101     raeburn  5710:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
                   5711:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86      raeburn  5712:     if ($action eq 'quotas') {
                   5713:         $context = 'tools'; 
1.163     raeburn  5714:     } else {
1.86      raeburn  5715:         $context = $action;
                   5716:     }
                   5717:     if ($context eq 'requestcourses') {
1.98      raeburn  5718:         @usertools = ('official','unofficial','community');
1.106     raeburn  5719:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  5720:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   5721:         %titles = &courserequest_titles();
                   5722:         $toolregexp = join('|',@usertools);
                   5723:         %conditions = &courserequest_conditions();
1.163     raeburn  5724:     } elsif ($context eq 'requestauthor') {
                   5725:         @usertools = ('author');
                   5726:         %titles = &authorrequest_titles();
1.86      raeburn  5727:     } else {
1.162     raeburn  5728:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  5729:         %titles = &tool_titles();
1.86      raeburn  5730:     }
1.72      raeburn  5731:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44      raeburn  5732:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5733:     foreach my $key (keys(%env)) {
1.101     raeburn  5734:         if ($context eq 'requestcourses') {
                   5735:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   5736:                 my $item = $1;
                   5737:                 my $type = $2;
                   5738:                 if ($type =~ /^limit_(.+)/) {
                   5739:                     $limithash{$item}{$1} = $env{$key};
                   5740:                 } else {
                   5741:                     $confhash{$item}{$type} = $env{$key};
                   5742:                 }
                   5743:             }
1.163     raeburn  5744:         } elsif ($context eq 'requestauthor') {
                   5745:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   5746:                 $confhash{$1} = $env{$key};
                   5747:             }
1.101     raeburn  5748:         } else {
1.86      raeburn  5749:             if ($key =~ /^form\.quota_(.+)$/) {
                   5750:                 $confhash{'defaultquota'}{$1} = $env{$key};
                   5751:             }
1.101     raeburn  5752:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
                   5753:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   5754:             }
1.72      raeburn  5755:         }
                   5756:     }
1.163     raeburn  5757:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102     raeburn  5758:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
                   5759:         @approvalnotify = sort(@approvalnotify);
                   5760:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
                   5761:         if (ref($domconfig{$action}) eq 'HASH') {
                   5762:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   5763:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   5764:                     $changes{'notify'}{'approval'} = 1;
                   5765:                 }
                   5766:             } else {
1.144     raeburn  5767:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5768:                     $changes{'notify'}{'approval'} = 1;
                   5769:                 }
                   5770:             }
                   5771:         } else {
1.144     raeburn  5772:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5773:                 $changes{'notify'}{'approval'} = 1;
                   5774:             }
                   5775:         }
                   5776:     } else {
1.86      raeburn  5777:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
                   5778:     }
1.72      raeburn  5779:     foreach my $item (@usertools) {
                   5780:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  5781:             my $unset; 
1.101     raeburn  5782:             if ($context eq 'requestcourses') {
1.104     raeburn  5783:                 $unset = '0';
                   5784:                 if ($type eq '_LC_adv') {
                   5785:                     $unset = '';
                   5786:                 }
1.101     raeburn  5787:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   5788:                     $confhash{$item}{$type} .= '=';
                   5789:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   5790:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   5791:                     }
                   5792:                 }
1.163     raeburn  5793:             } elsif ($context eq 'requestauthor') {
                   5794:                 $unset = '0';
                   5795:                 if ($type eq '_LC_adv') {
                   5796:                     $unset = '';
                   5797:                 }
1.72      raeburn  5798:             } else {
1.101     raeburn  5799:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   5800:                     $confhash{$item}{$type} = 1;
                   5801:                 } else {
                   5802:                     $confhash{$item}{$type} = 0;
                   5803:                 }
1.72      raeburn  5804:             }
1.86      raeburn  5805:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  5806:                 if ($action eq 'requestauthor') {
                   5807:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   5808:                         $changes{$type} = 1;
                   5809:                     }
                   5810:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  5811:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   5812:                         $changes{$item}{$type} = 1;
                   5813:                     }
                   5814:                 } else {
                   5815:                     if ($context eq 'requestcourses') {
1.104     raeburn  5816:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  5817:                             $changes{$item}{$type} = 1;
                   5818:                         }
                   5819:                     } else {
                   5820:                         if (!$confhash{$item}{$type}) {
                   5821:                             $changes{$item}{$type} = 1;
                   5822:                         }
                   5823:                     }
                   5824:                 }
                   5825:             } else {
                   5826:                 if ($context eq 'requestcourses') {
1.104     raeburn  5827:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  5828:                         $changes{$item}{$type} = 1;
                   5829:                     }
1.163     raeburn  5830:                 } elsif ($context eq 'requestauthor') {
                   5831:                     if ($confhash{$type} ne $unset) {
                   5832:                         $changes{$type} = 1;
                   5833:                     }
1.72      raeburn  5834:                 } else {
                   5835:                     if (!$confhash{$item}{$type}) {
                   5836:                         $changes{$item}{$type} = 1;
                   5837:                     }
                   5838:                 }
                   5839:             }
1.1       raeburn  5840:         }
                   5841:     }
1.163     raeburn  5842:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  5843:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5844:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5845:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   5846:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5847:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   5848:                             $changes{'defaultquota'}{$key} = 1;
                   5849:                         }
                   5850:                     } else {
                   5851:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  5852:                     }
                   5853:                 }
1.86      raeburn  5854:             } else {
                   5855:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   5856:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5857:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   5858:                             $changes{'defaultquota'}{$key} = 1;
                   5859:                         }
                   5860:                     } else {
                   5861:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  5862:                     }
1.1       raeburn  5863:                 }
                   5864:             }
                   5865:         }
1.86      raeburn  5866:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   5867:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   5868:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5869:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5870:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   5871:                             $changes{'defaultquota'}{$key} = 1;
                   5872:                         }
                   5873:                     } else {
                   5874:                         if (!exists($domconfig{'quotas'}{$key})) {
                   5875:                             $changes{'defaultquota'}{$key} = 1;
                   5876:                         }
1.72      raeburn  5877:                     }
                   5878:                 } else {
1.86      raeburn  5879:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  5880:                 }
1.1       raeburn  5881:             }
                   5882:         }
                   5883:     }
1.72      raeburn  5884: 
1.163     raeburn  5885:     if ($context eq 'requestauthor') {
                   5886:         $domdefaults{'requestauthor'} = \%confhash;
                   5887:     } else {
                   5888:         foreach my $key (keys(%confhash)) {
                   5889:             $domdefaults{$key} = $confhash{$key};
                   5890:         }
1.72      raeburn  5891:     }
1.163     raeburn  5892: 
1.1       raeburn  5893:     my %quotahash = (
1.86      raeburn  5894:                       $action => { %confhash }
1.1       raeburn  5895:                     );
                   5896:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   5897:                                              $dom);
                   5898:     if ($putresult eq 'ok') {
                   5899:         if (keys(%changes) > 0) {
1.72      raeburn  5900:             my $cachetime = 24*60*60;
                   5901:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   5902: 
1.1       raeburn  5903:             $resulttext = &mt('Changes made:').'<ul>';
1.163     raeburn  5904:             unless (($context eq 'requestcourses') || 
                   5905:                     ($context eq 'requestauthor')) {
1.86      raeburn  5906:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   5907:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   5908:                     foreach my $type (@{$types},'default') {
                   5909:                         if (defined($changes{'defaultquota'}{$type})) {
                   5910:                             my $typetitle = $usertypes->{$type};
                   5911:                             if ($type eq 'default') {
                   5912:                                 $typetitle = $othertitle;
                   5913:                             }
                   5914:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  5915:                         }
                   5916:                     }
1.86      raeburn  5917:                     $resulttext .= '</ul></li>';
1.72      raeburn  5918:                 }
                   5919:             }
1.80      raeburn  5920:             my %newenv;
1.72      raeburn  5921:             foreach my $item (@usertools) {
1.163     raeburn  5922:                 my (%haschgs,%inconf);
                   5923:                 if ($context eq 'requestauthor') {
                   5924:                     %haschgs = %changes;
                   5925:                     %inconf = %confhash; 
                   5926:                 } else {
                   5927:                     if (ref($changes{$item}) eq 'HASH') {
                   5928:                         %haschgs = %{$changes{$item}};
                   5929:                     }
                   5930:                     if (ref($confhash{$item}) eq 'HASH') {
                   5931:                         %inconf = %{$confhash{$item}};
                   5932:                     }
                   5933:                 }
                   5934:                 if (keys(%haschgs) > 0) {
1.80      raeburn  5935:                     my $newacc = 
                   5936:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   5937:                                                           $env{'user.domain'},
1.86      raeburn  5938:                                                           $item,'reload',$context);
1.163     raeburn  5939:                     if (($context eq 'requestcourses') || 
                   5940:                         ($context eq 'requestauthor')) {
1.108     raeburn  5941:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   5942:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  5943:                         }
                   5944:                     } else {
                   5945:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   5946:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   5947:                         }
1.80      raeburn  5948:                     }
1.163     raeburn  5949:                     unless ($context eq 'requestauthor') {
                   5950:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   5951:                     }
1.72      raeburn  5952:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  5953:                         if ($haschgs{$type}) {
1.72      raeburn  5954:                             my $typetitle = $usertypes->{$type};
                   5955:                             if ($type eq 'default') {
                   5956:                                 $typetitle = $othertitle;
                   5957:                             } elsif ($type eq '_LC_adv') {
                   5958:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   5959:                             }
1.163     raeburn  5960:                             if ($inconf{$type}) {
1.101     raeburn  5961:                                 if ($context eq 'requestcourses') {
                   5962:                                     my $cond;
1.163     raeburn  5963:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  5964:                                         if ($1 eq '') {
                   5965:                                             $cond = &mt('(Automatic processing of any request).');
                   5966:                                         } else {
                   5967:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   5968:                                         }
                   5969:                                     } else { 
1.163     raeburn  5970:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  5971:                                     }
                   5972:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  5973:                                 } elsif ($context eq 'requestauthor') {
                   5974:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   5975:                                                              $titles{$inconf{$type}},$typetitle);
                   5976: 
1.101     raeburn  5977:                                 } else {
                   5978:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   5979:                                 }
1.72      raeburn  5980:                             } else {
1.104     raeburn  5981:                                 if ($type eq '_LC_adv') {
1.163     raeburn  5982:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  5983:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5984:                                     } else { 
                   5985:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   5986:                                     }
                   5987:                                 } else {
                   5988:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5989:                                 }
1.72      raeburn  5990:                             }
                   5991:                         }
1.26      raeburn  5992:                     }
1.163     raeburn  5993:                     unless ($context eq 'requestauthor') {
                   5994:                         $resulttext .= '</ul></li>';
                   5995:                     }
1.26      raeburn  5996:                 }
1.1       raeburn  5997:             }
1.163     raeburn  5998:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  5999:                 if (ref($changes{'notify'}) eq 'HASH') {
                   6000:                     if ($changes{'notify'}{'approval'}) {
                   6001:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   6002:                             if ($confhash{'notify'}{'approval'}) {
                   6003:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   6004:                             } else {
1.163     raeburn  6005:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  6006:                             }
                   6007:                         }
                   6008:                     }
                   6009:                 }
                   6010:             }
1.1       raeburn  6011:             $resulttext .= '</ul>';
1.80      raeburn  6012:             if (keys(%newenv)) {
                   6013:                 &Apache::lonnet::appenv(\%newenv);
                   6014:             }
1.1       raeburn  6015:         } else {
1.86      raeburn  6016:             if ($context eq 'requestcourses') {
                   6017:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  6018:             } elsif ($context eq 'requestauthor') {
                   6019:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  6020:             } else {
1.90      weissno  6021:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  6022:             }
1.1       raeburn  6023:         }
                   6024:     } else {
1.11      albertel 6025:         $resulttext = '<span class="LC_error">'.
                   6026: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6027:     }
1.3       raeburn  6028:     return $resulttext;
1.1       raeburn  6029: }
                   6030: 
1.3       raeburn  6031: sub modify_autoenroll {
                   6032:     my ($dom,%domconfig) = @_;
1.1       raeburn  6033:     my ($resulttext,%changes);
                   6034:     my %currautoenroll;
                   6035:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   6036:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   6037:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   6038:         }
                   6039:     }
                   6040:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   6041:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  6042:                   sender => 'Sender for notification messages',
                   6043:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  6044:     my @offon = ('off','on');
1.17      raeburn  6045:     my $sender_uname = $env{'form.sender_uname'};
                   6046:     my $sender_domain = $env{'form.sender_domain'};
                   6047:     if ($sender_domain eq '') {
                   6048:         $sender_uname = '';
                   6049:     } elsif ($sender_uname eq '') {
                   6050:         $sender_domain = '';
                   6051:     }
1.129     raeburn  6052:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  6053:     my %autoenrollhash =  (
1.129     raeburn  6054:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   6055:                                        'sender_uname' => $sender_uname,
                   6056:                                        'sender_domain' => $sender_domain,
                   6057:                                        'co-owners' => $coowners,
1.1       raeburn  6058:                                 }
                   6059:                      );
1.4       raeburn  6060:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   6061:                                              $dom);
1.1       raeburn  6062:     if ($putresult eq 'ok') {
                   6063:         if (exists($currautoenroll{'run'})) {
                   6064:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   6065:                  $changes{'run'} = 1;
                   6066:              }
                   6067:         } elsif ($autorun) {
                   6068:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  6069:                  $changes{'run'} = 1;
1.1       raeburn  6070:             }
                   6071:         }
1.17      raeburn  6072:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  6073:             $changes{'sender'} = 1;
                   6074:         }
1.17      raeburn  6075:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  6076:             $changes{'sender'} = 1;
                   6077:         }
1.129     raeburn  6078:         if ($currautoenroll{'co-owners'} ne '') {
                   6079:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   6080:                 $changes{'coowners'} = 1;
                   6081:             }
                   6082:         } elsif ($coowners) {
                   6083:             $changes{'coowners'} = 1;
                   6084:         }      
1.1       raeburn  6085:         if (keys(%changes) > 0) {
                   6086:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  6087:             if ($changes{'run'}) {
1.1       raeburn  6088:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   6089:             }
                   6090:             if ($changes{'sender'}) {
1.17      raeburn  6091:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   6092:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   6093:                 } else {
                   6094:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   6095:                 }
1.1       raeburn  6096:             }
1.129     raeburn  6097:             if ($changes{'coowners'}) {
                   6098:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   6099:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   6100:             }
1.1       raeburn  6101:             $resulttext .= '</ul>';
                   6102:         } else {
                   6103:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   6104:         }
                   6105:     } else {
1.11      albertel 6106:         $resulttext = '<span class="LC_error">'.
                   6107: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6108:     }
1.3       raeburn  6109:     return $resulttext;
1.1       raeburn  6110: }
                   6111: 
                   6112: sub modify_autoupdate {
1.3       raeburn  6113:     my ($dom,%domconfig) = @_;
1.1       raeburn  6114:     my ($resulttext,%currautoupdate,%fields,%changes);
                   6115:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   6116:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   6117:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   6118:         }
                   6119:     }
                   6120:     my @offon = ('off','on');
                   6121:     my %title = &Apache::lonlocal::texthash (
                   6122:                    run => 'Auto-update:',
                   6123:                    classlists => 'Updates to user information in classlists?'
                   6124:                 );
1.44      raeburn  6125:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  6126:     my %fieldtitles = &Apache::lonlocal::texthash (
                   6127:                         id => 'Student/Employee ID',
1.20      raeburn  6128:                         permanentemail => 'E-mail address',
1.1       raeburn  6129:                         lastname => 'Last Name',
                   6130:                         firstname => 'First Name',
                   6131:                         middlename => 'Middle Name',
1.132     raeburn  6132:                         generation => 'Generation',
1.1       raeburn  6133:                       );
1.142     raeburn  6134:     $othertitle = &mt('All users');
1.1       raeburn  6135:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  6136:         $othertitle = &mt('Other users');
1.1       raeburn  6137:     }
                   6138:     foreach my $key (keys(%env)) {
                   6139:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  6140:             my ($usertype,$item) = ($1,$2);
                   6141:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   6142:                 if ($usertype eq 'default') {   
                   6143:                     push(@{$fields{$1}},$2);
                   6144:                 } elsif (ref($types) eq 'ARRAY') {
                   6145:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   6146:                         push(@{$fields{$1}},$2);
                   6147:                     }
                   6148:                 }
                   6149:             }
1.1       raeburn  6150:         }
                   6151:     }
1.131     raeburn  6152:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   6153:     @lockablenames = sort(@lockablenames);
                   6154:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   6155:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6156:         if (@changed) {
                   6157:             $changes{'lockablenames'} = 1;
                   6158:         }
                   6159:     } else {
                   6160:         if (@lockablenames) {
                   6161:             $changes{'lockablenames'} = 1;
                   6162:         }
                   6163:     }
1.1       raeburn  6164:     my %updatehash = (
                   6165:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   6166:                                       classlists => $env{'form.classlists'},
                   6167:                                       fields => {%fields},
1.131     raeburn  6168:                                       lockablenames => \@lockablenames,
1.1       raeburn  6169:                                     }
                   6170:                      );
                   6171:     foreach my $key (keys(%currautoupdate)) {
                   6172:         if (($key eq 'run') || ($key eq 'classlists')) {
                   6173:             if (exists($updatehash{autoupdate}{$key})) {
                   6174:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   6175:                     $changes{$key} = 1;
                   6176:                 }
                   6177:             }
                   6178:         } elsif ($key eq 'fields') {
                   6179:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  6180:                 foreach my $item (@{$types},'default') {
1.1       raeburn  6181:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   6182:                         my $change = 0;
                   6183:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   6184:                             if (!exists($fields{$item})) {
                   6185:                                 $change = 1;
1.132     raeburn  6186:                                 last;
1.1       raeburn  6187:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  6188:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  6189:                                     $change = 1;
1.132     raeburn  6190:                                     last;
1.1       raeburn  6191:                                 }
                   6192:                             }
                   6193:                         }
                   6194:                         if ($change) {
                   6195:                             push(@{$changes{$key}},$item);
                   6196:                         }
1.26      raeburn  6197:                     } 
1.1       raeburn  6198:                 }
                   6199:             }
1.131     raeburn  6200:         } elsif ($key eq 'lockablenames') {
                   6201:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   6202:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6203:                 if (@changed) {
                   6204:                     $changes{'lockablenames'} = 1;
                   6205:                 }
                   6206:             } else {
                   6207:                 if (@lockablenames) {
                   6208:                     $changes{'lockablenames'} = 1;
                   6209:                 }
                   6210:             }
                   6211:         }
                   6212:     }
                   6213:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   6214:         if (@lockablenames) {
                   6215:             $changes{'lockablenames'} = 1;
1.1       raeburn  6216:         }
                   6217:     }
1.26      raeburn  6218:     foreach my $item (@{$types},'default') {
                   6219:         if (defined($fields{$item})) {
                   6220:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  6221:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   6222:                     my $change = 0;
                   6223:                     if (ref($fields{$item}) eq 'ARRAY') {
                   6224:                         foreach my $type (@{$fields{$item}}) {
                   6225:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   6226:                                 $change = 1;
                   6227:                                 last;
                   6228:                             }
                   6229:                         }
                   6230:                     }
                   6231:                     if ($change) {
                   6232:                         push(@{$changes{'fields'}},$item);
                   6233:                     }
                   6234:                 } else {
1.26      raeburn  6235:                     push(@{$changes{'fields'}},$item);
                   6236:                 }
                   6237:             } else {
                   6238:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  6239:             }
                   6240:         }
                   6241:     }
                   6242:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   6243:                                              $dom);
                   6244:     if ($putresult eq 'ok') {
                   6245:         if (keys(%changes) > 0) {
                   6246:             $resulttext = &mt('Changes made:').'<ul>';
                   6247:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  6248:                 if ($key eq 'lockablenames') {
                   6249:                     $resulttext .= '<li>';
                   6250:                     if (@lockablenames) {
                   6251:                         $usertypes->{'default'} = $othertitle;
                   6252:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   6253:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   6254:                     } else {
                   6255:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   6256:                     }
                   6257:                     $resulttext .= '</li>';
                   6258:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  6259:                     foreach my $item (@{$changes{$key}}) {
                   6260:                         my @newvalues;
                   6261:                         foreach my $type (@{$fields{$item}}) {
                   6262:                             push(@newvalues,$fieldtitles{$type});
                   6263:                         }
1.3       raeburn  6264:                         my $newvaluestr;
                   6265:                         if (@newvalues > 0) {
                   6266:                             $newvaluestr = join(', ',@newvalues);
                   6267:                         } else {
                   6268:                             $newvaluestr = &mt('none');
1.6       raeburn  6269:                         }
1.1       raeburn  6270:                         if ($item eq 'default') {
1.26      raeburn  6271:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  6272:                         } else {
1.26      raeburn  6273:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  6274:                         }
                   6275:                     }
                   6276:                 } else {
                   6277:                     my $newvalue;
                   6278:                     if ($key eq 'run') {
                   6279:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   6280:                     } else {
                   6281:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  6282:                     }
1.1       raeburn  6283:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   6284:                 }
                   6285:             }
                   6286:             $resulttext .= '</ul>';
                   6287:         } else {
1.3       raeburn  6288:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  6289:         }
                   6290:     } else {
1.11      albertel 6291:         $resulttext = '<span class="LC_error">'.
                   6292: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6293:     }
1.3       raeburn  6294:     return $resulttext;
1.1       raeburn  6295: }
                   6296: 
1.125     raeburn  6297: sub modify_autocreate {
                   6298:     my ($dom,%domconfig) = @_;
                   6299:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   6300:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   6301:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   6302:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   6303:         }
                   6304:     }
                   6305:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   6306:                  req => 'Auto-creation of validated requests for official courses',
                   6307:                  xmldc => 'Identity of course creator of courses from XML files',
                   6308:                );
                   6309:     my @types = ('xml','req');
                   6310:     foreach my $item (@types) {
                   6311:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   6312:         $newvals{$item} =~ s/\D//g;
                   6313:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   6314:     }
                   6315:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   6316:     my %domcoords = &get_active_dcs($dom);
                   6317:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   6318:         $newvals{'xmldc'} = '';
                   6319:     } 
                   6320:     %autocreatehash =  (
                   6321:                         autocreate => { xml => $newvals{'xml'},
                   6322:                                         req => $newvals{'req'},
                   6323:                                       }
                   6324:                        );
                   6325:     if ($newvals{'xmldc'} ne '') {
                   6326:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   6327:     }
                   6328:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   6329:                                              $dom);
                   6330:     if ($putresult eq 'ok') {
                   6331:         my @items = @types;
                   6332:         if ($newvals{'xml'}) {
                   6333:             push(@items,'xmldc');
                   6334:         }
                   6335:         foreach my $item (@items) {
                   6336:             if (exists($currautocreate{$item})) {
                   6337:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   6338:                     $changes{$item} = 1;
                   6339:                 }
                   6340:             } elsif ($newvals{$item}) {
                   6341:                 $changes{$item} = 1;
                   6342:             }
                   6343:         }
                   6344:         if (keys(%changes) > 0) {
                   6345:             my @offon = ('off','on'); 
                   6346:             $resulttext = &mt('Changes made:').'<ul>';
                   6347:             foreach my $item (@types) {
                   6348:                 if ($changes{$item}) {
                   6349:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  6350:                     $resulttext .= '<li>'.
                   6351:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   6352:                                        '<b>','</b>').
                   6353:                                    '</li>';
1.125     raeburn  6354:                 }
                   6355:             }
                   6356:             if ($changes{'xmldc'}) {
                   6357:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   6358:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  6359:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  6360:             }
                   6361:             $resulttext .= '</ul>';
                   6362:         } else {
                   6363:             $resulttext = &mt('No changes made to auto-creation settings');
                   6364:         }
                   6365:     } else {
                   6366:         $resulttext = '<span class="LC_error">'.
                   6367:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6368:     }
                   6369:     return $resulttext;
                   6370: }
                   6371: 
1.23      raeburn  6372: sub modify_directorysrch {
                   6373:     my ($dom,%domconfig) = @_;
                   6374:     my ($resulttext,%changes);
                   6375:     my %currdirsrch;
                   6376:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   6377:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   6378:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   6379:         }
                   6380:     }
                   6381:     my %title = ( available => 'Directory search available',
1.24      raeburn  6382:                   localonly => 'Other domains can search',
1.23      raeburn  6383:                   searchby => 'Search types',
                   6384:                   searchtypes => 'Search latitude');
                   6385:     my @offon = ('off','on');
1.24      raeburn  6386:     my @otherdoms = ('Yes','No');
1.23      raeburn  6387: 
1.25      raeburn  6388:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  6389:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   6390:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   6391: 
1.44      raeburn  6392:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  6393:     if (keys(%{$usertypes}) == 0) {
                   6394:         @cansearch = ('default');
                   6395:     } else {
                   6396:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   6397:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   6398:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   6399:                     push(@{$changes{'cansearch'}},$type);
                   6400:                 }
1.23      raeburn  6401:             }
1.26      raeburn  6402:             foreach my $type (@cansearch) {
                   6403:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   6404:                     push(@{$changes{'cansearch'}},$type);
                   6405:                 }
1.23      raeburn  6406:             }
1.26      raeburn  6407:         } else {
                   6408:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  6409:         }
                   6410:     }
                   6411: 
                   6412:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   6413:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   6414:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   6415:                 push(@{$changes{'searchby'}},$by);
                   6416:             }
                   6417:         }
                   6418:         foreach my $by (@searchby) {
                   6419:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   6420:                 push(@{$changes{'searchby'}},$by);
                   6421:             }
                   6422:         }
                   6423:     } else {
                   6424:         push(@{$changes{'searchby'}},@searchby);
                   6425:     }
1.25      raeburn  6426: 
                   6427:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   6428:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   6429:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   6430:                 push(@{$changes{'searchtypes'}},$type);
                   6431:             }
                   6432:         }
                   6433:         foreach my $type (@searchtypes) {
                   6434:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   6435:                 push(@{$changes{'searchtypes'}},$type);
                   6436:             }
                   6437:         }
                   6438:     } else {
                   6439:         if (exists($currdirsrch{'searchtypes'})) {
                   6440:             foreach my $type (@searchtypes) {  
                   6441:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   6442:                     push(@{$changes{'searchtypes'}},$type);
                   6443:                 }
                   6444:             }
                   6445:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   6446:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   6447:             }   
                   6448:         } else {
                   6449:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   6450:         }
                   6451:     }
                   6452: 
1.23      raeburn  6453:     my %dirsrch_hash =  (
                   6454:             directorysrch => { available => $env{'form.dirsrch_available'},
                   6455:                                cansearch => \@cansearch,
1.24      raeburn  6456:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  6457:                                searchby => \@searchby,
1.25      raeburn  6458:                                searchtypes => \@searchtypes,
1.23      raeburn  6459:                              }
                   6460:             );
                   6461:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   6462:                                              $dom);
                   6463:     if ($putresult eq 'ok') {
                   6464:         if (exists($currdirsrch{'available'})) {
                   6465:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   6466:                  $changes{'available'} = 1;
                   6467:              }
                   6468:         } else {
                   6469:             if ($env{'form.dirsrch_available'} eq '1') {
                   6470:                 $changes{'available'} = 1;
                   6471:             }
                   6472:         }
1.24      raeburn  6473:         if (exists($currdirsrch{'localonly'})) {
                   6474:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   6475:                  $changes{'localonly'} = 1;
                   6476:              }
                   6477:         } else {
                   6478:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   6479:                 $changes{'localonly'} = 1;
                   6480:             }
                   6481:         }
1.23      raeburn  6482:         if (keys(%changes) > 0) {
                   6483:             $resulttext = &mt('Changes made:').'<ul>';
                   6484:             if ($changes{'available'}) {
                   6485:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   6486:             }
1.24      raeburn  6487:             if ($changes{'localonly'}) {
                   6488:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   6489:             }
                   6490: 
1.23      raeburn  6491:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   6492:                 my $chgtext;
1.26      raeburn  6493:                 if (ref($usertypes) eq 'HASH') {
                   6494:                     if (keys(%{$usertypes}) > 0) {
                   6495:                         foreach my $type (@{$types}) {
                   6496:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   6497:                                 $chgtext .= $usertypes->{$type}.'; ';
                   6498:                             }
                   6499:                         }
                   6500:                         if (grep(/^default$/,@cansearch)) {
                   6501:                             $chgtext .= $othertitle;
                   6502:                         } else {
                   6503:                             $chgtext =~ s/\; $//;
                   6504:                         }
1.178     raeburn  6505:                         $resulttext .= 
                   6506:                             '<li>'.
                   6507:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   6508:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   6509:                             '</li>';
1.23      raeburn  6510:                     }
                   6511:                 }
                   6512:             }
                   6513:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   6514:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   6515:                 my $chgtext;
                   6516:                 foreach my $type (@{$titleorder}) {
                   6517:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   6518:                         if (defined($searchtitles->{$type})) {
                   6519:                             $chgtext .= $searchtitles->{$type}.'; ';
                   6520:                         }
                   6521:                     }
                   6522:                 }
                   6523:                 $chgtext =~ s/\; $//;
                   6524:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   6525:             }
1.25      raeburn  6526:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   6527:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   6528:                 my $chgtext;
                   6529:                 foreach my $type (@{$srchtypeorder}) {
                   6530:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   6531:                         if (defined($srchtypes_desc->{$type})) {
                   6532:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   6533:                         }
                   6534:                     }
                   6535:                 }
                   6536:                 $chgtext =~ s/\; $//;
1.178     raeburn  6537:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  6538:             }
                   6539:             $resulttext .= '</ul>';
                   6540:         } else {
                   6541:             $resulttext = &mt('No changes made to institution directory search settings');
                   6542:         }
                   6543:     } else {
                   6544:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  6545:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   6546:     }
                   6547:     return $resulttext;
                   6548: }
                   6549: 
1.28      raeburn  6550: sub modify_contacts {
                   6551:     my ($dom,%domconfig) = @_;
                   6552:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   6553:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   6554:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   6555:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   6556:         }
                   6557:     }
1.134     raeburn  6558:     my (%others,%to,%bcc);
1.28      raeburn  6559:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  6560:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.190   ! raeburn  6561:                     'requestsmail','updatesmail');
1.28      raeburn  6562:     foreach my $type (@mailings) {
                   6563:         @{$newsetting{$type}} = 
                   6564:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   6565:         foreach my $item (@contacts) {
                   6566:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   6567:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   6568:             } else {
                   6569:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   6570:             }
                   6571:         }  
                   6572:         $others{$type} = $env{'form.'.$type.'_others'};
                   6573:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  6574:         if ($type eq 'helpdeskmail') {
                   6575:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   6576:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   6577:         }
1.28      raeburn  6578:     }
                   6579:     foreach my $item (@contacts) {
                   6580:         $to{$item} = $env{'form.'.$item};
                   6581:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   6582:     }
                   6583:     if (keys(%currsetting) > 0) {
                   6584:         foreach my $item (@contacts) {
                   6585:             if ($to{$item} ne $currsetting{$item}) {
                   6586:                 $changes{$item} = 1;
                   6587:             }
                   6588:         }
                   6589:         foreach my $type (@mailings) {
                   6590:             foreach my $item (@contacts) {
                   6591:                 if (ref($currsetting{$type}) eq 'HASH') {
                   6592:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   6593:                         push(@{$changes{$type}},$item);
                   6594:                     }
                   6595:                 } else {
                   6596:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   6597:                 }
                   6598:             }
                   6599:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   6600:                 push(@{$changes{$type}},'others');
                   6601:             }
1.134     raeburn  6602:             if ($type eq 'helpdeskmail') {   
                   6603:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   6604:                     push(@{$changes{$type}},'bcc'); 
                   6605:                 }
                   6606:             }
1.28      raeburn  6607:         }
                   6608:     } else {
                   6609:         my %default;
                   6610:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   6611:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   6612:         $default{'errormail'} = 'adminemail';
                   6613:         $default{'packagesmail'} = 'adminemail';
                   6614:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  6615:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  6616:         $default{'requestsmail'} = 'adminemail';
1.190   ! raeburn  6617:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  6618:         foreach my $item (@contacts) {
                   6619:            if ($to{$item} ne $default{$item}) {
                   6620:               $changes{$item} = 1;
                   6621:            } 
                   6622:         }
                   6623:         foreach my $type (@mailings) {
                   6624:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   6625:                
                   6626:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   6627:             }
                   6628:             if ($others{$type} ne '') {
                   6629:                 push(@{$changes{$type}},'others');
1.134     raeburn  6630:             }
                   6631:             if ($type eq 'helpdeskmail') {
                   6632:                 if ($bcc{$type} ne '') {
                   6633:                     push(@{$changes{$type}},'bcc');
                   6634:                 }
                   6635:             }
1.28      raeburn  6636:         }
                   6637:     }
                   6638:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   6639:                                              $dom);
                   6640:     if ($putresult eq 'ok') {
                   6641:         if (keys(%changes) > 0) {
                   6642:             my ($titles,$short_titles)  = &contact_titles();
                   6643:             $resulttext = &mt('Changes made:').'<ul>';
                   6644:             foreach my $item (@contacts) {
                   6645:                 if ($changes{$item}) {
                   6646:                     $resulttext .= '<li>'.$titles->{$item}.
                   6647:                                     &mt(' set to: ').
                   6648:                                     '<span class="LC_cusr_emph">'.
                   6649:                                     $to{$item}.'</span></li>';
                   6650:                 }
                   6651:             }
                   6652:             foreach my $type (@mailings) {
                   6653:                 if (ref($changes{$type}) eq 'ARRAY') {
                   6654:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   6655:                     my @text;
                   6656:                     foreach my $item (@{$newsetting{$type}}) {
                   6657:                         push(@text,$short_titles->{$item});
                   6658:                     }
                   6659:                     if ($others{$type} ne '') {
                   6660:                         push(@text,$others{$type});
                   6661:                     }
                   6662:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  6663:                                    join(', ',@text).'</span>';
                   6664:                     if ($type eq 'helpdeskmail') {
                   6665:                         if ($bcc{$type} ne '') {
                   6666:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   6667:                         }
                   6668:                     }
                   6669:                     $resulttext .= '</li>';
1.28      raeburn  6670:                 }
                   6671:             }
                   6672:             $resulttext .= '</ul>';
                   6673:         } else {
1.34      raeburn  6674:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  6675:         }
                   6676:     } else {
                   6677:         $resulttext = '<span class="LC_error">'.
                   6678:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   6679:     }
                   6680:     return $resulttext;
                   6681: }
                   6682: 
                   6683: sub modify_usercreation {
1.27      raeburn  6684:     my ($dom,%domconfig) = @_;
1.34      raeburn  6685:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43      raeburn  6686:     my $warningmsg;
1.27      raeburn  6687:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   6688:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   6689:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   6690:         }
                   6691:     }
                   6692:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  6693:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43      raeburn  6694:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100     raeburn  6695:     my @contexts = ('author','course','requestcrs','selfcreate');
1.34      raeburn  6696:     foreach my $item(@contexts) {
1.45      raeburn  6697:         if ($item eq 'selfcreate') {
1.50      raeburn  6698:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43      raeburn  6699:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   6700:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50      raeburn  6701:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                   6702:                     if (grep(/^login$/,@{$cancreate{$item}})) {
                   6703:                         $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.');   
                   6704:                     }
1.43      raeburn  6705:                 }
                   6706:             }
1.50      raeburn  6707:         } else {
                   6708:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43      raeburn  6709:         }
1.34      raeburn  6710:     }
1.93      raeburn  6711:     my ($othertitle,$usertypes,$types) = 
                   6712:         &Apache::loncommon::sorted_inst_types($dom);
                   6713:     if (ref($types) eq 'ARRAY') {
                   6714:         if (@{$types} > 0) {
                   6715:             @{$cancreate{'statustocreate'}} = 
                   6716:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103     raeburn  6717:         } else {
                   6718:             @{$cancreate{'statustocreate'}} = ();
1.93      raeburn  6719:         }
                   6720:         push(@contexts,'statustocreate');
                   6721:     }
1.165     raeburn  6722:     &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34      raeburn  6723:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   6724:         foreach my $item (@contexts) {
1.93      raeburn  6725:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                   6726:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50      raeburn  6727:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103     raeburn  6728:                         if (ref($cancreate{$item}) eq 'ARRAY') {
                   6729:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   6730:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6731:                                     push(@{$changes{'cancreate'}},$item);
                   6732:                                 }
1.50      raeburn  6733:                             }
                   6734:                         }
                   6735:                     }
                   6736:                 } else {
                   6737:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
                   6738:                         if (@{$cancreate{$item}} > 0) {
                   6739:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6740:                                 push(@{$changes{'cancreate'}},$item);
                   6741:                             }
                   6742:                         }
                   6743:                     } else {
                   6744:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                   6745:                             if (@{$cancreate{$item}} < 3) {
                   6746:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6747:                                     push(@{$changes{'cancreate'}},$item);
                   6748:                                 }
                   6749:                             }
                   6750:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                   6751:                             if (@{$cancreate{$item}} > 0) {
                   6752:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6753:                                     push(@{$changes{'cancreate'}},$item);
                   6754:                                 }
                   6755:                             }
                   6756:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                   6757:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6758:                                 push(@{$changes{'cancreate'}},$item);
                   6759:                             }
                   6760:                         }
                   6761:                     }
                   6762:                 }
                   6763:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6764:                     foreach my $type (@{$cancreate{$item}}) {
                   6765:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   6766:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   6767:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6768:                                     push(@{$changes{'cancreate'}},$item);
                   6769:                                 }
                   6770:                             }
                   6771:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                   6772:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                   6773:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                   6774:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6775:                                     push(@{$changes{'cancreate'}},$item);
                   6776:                                 }
                   6777:                             }
                   6778:                         }
                   6779:                     }
                   6780:                 }
                   6781:             } else {
                   6782:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   6783:                     push(@{$changes{'cancreate'}},$item);
                   6784:                 }
                   6785:             }
1.27      raeburn  6786:         }
1.34      raeburn  6787:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   6788:         foreach my $item (@contexts) {
1.43      raeburn  6789:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  6790:                 if ($cancreate{$item} ne 'any') {
                   6791:                     push(@{$changes{'cancreate'}},$item);
                   6792:                 }
                   6793:             } else {
                   6794:                 if ($cancreate{$item} ne 'none') {
                   6795:                     push(@{$changes{'cancreate'}},$item);
                   6796:                 }
1.27      raeburn  6797:             }
                   6798:         }
                   6799:     } else {
1.43      raeburn  6800:         foreach my $item (@contexts)  {
1.34      raeburn  6801:             push(@{$changes{'cancreate'}},$item);
                   6802:         }
1.27      raeburn  6803:     }
1.34      raeburn  6804: 
1.27      raeburn  6805:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   6806:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   6807:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   6808:                 push(@{$changes{'username_rule'}},$type);
                   6809:             }
                   6810:         }
                   6811:         foreach my $type (@username_rule) {
                   6812:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   6813:                 push(@{$changes{'username_rule'}},$type);
                   6814:             }
                   6815:         }
                   6816:     } else {
                   6817:         push(@{$changes{'username_rule'}},@username_rule);
                   6818:     }
                   6819: 
1.32      raeburn  6820:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   6821:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   6822:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   6823:                 push(@{$changes{'id_rule'}},$type);
                   6824:             }
                   6825:         }
                   6826:         foreach my $type (@id_rule) {
                   6827:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   6828:                 push(@{$changes{'id_rule'}},$type);
                   6829:             }
                   6830:         }
                   6831:     } else {
                   6832:         push(@{$changes{'id_rule'}},@id_rule);
                   6833:     }
                   6834: 
1.43      raeburn  6835:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   6836:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   6837:             if (!grep(/^\Q$type\E$/,@email_rule)) {
                   6838:                 push(@{$changes{'email_rule'}},$type);
                   6839:             }
                   6840:         }
                   6841:         foreach my $type (@email_rule) {
                   6842:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   6843:                 push(@{$changes{'email_rule'}},$type);
                   6844:             }
                   6845:         }
                   6846:     } else {
                   6847:         push(@{$changes{'email_rule'}},@email_rule);
                   6848:     }
                   6849: 
                   6850:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  6851:     my @authtypes = ('int','krb4','krb5','loc');
                   6852:     my %authhash;
1.43      raeburn  6853:     foreach my $item (@authen_contexts) {
1.28      raeburn  6854:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   6855:         foreach my $auth (@authtypes) {
                   6856:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   6857:                 $authhash{$item}{$auth} = 1;
                   6858:             } else {
                   6859:                 $authhash{$item}{$auth} = 0;
                   6860:             }
                   6861:         }
                   6862:     }
                   6863:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  6864:         foreach my $item (@authen_contexts) {
1.28      raeburn  6865:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   6866:                 foreach my $auth (@authtypes) {
                   6867:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   6868:                         push(@{$changes{'authtypes'}},$item);
                   6869:                         last;
                   6870:                     }
                   6871:                 }
                   6872:             }
                   6873:         }
                   6874:     } else {
1.43      raeburn  6875:         foreach my $item (@authen_contexts) {
1.28      raeburn  6876:             push(@{$changes{'authtypes'}},$item);
                   6877:         }
                   6878:     }
                   6879: 
1.27      raeburn  6880:     my %usercreation_hash =  (
1.28      raeburn  6881:             usercreation => {
1.34      raeburn  6882:                               cancreate     => \%cancreate,
1.27      raeburn  6883:                               username_rule => \@username_rule,
1.32      raeburn  6884:                               id_rule       => \@id_rule,
1.43      raeburn  6885:                               email_rule    => \@email_rule,
1.32      raeburn  6886:                               authtypes     => \%authhash,
1.27      raeburn  6887:                             }
                   6888:             );
                   6889: 
                   6890:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   6891:                                              $dom);
1.50      raeburn  6892: 
                   6893:     my %selfcreatetypes = (
                   6894:                              sso   => 'users authenticated by institutional single sign on',
                   6895:                              login => 'users authenticated by institutional log-in',
                   6896:                              email => 'users who provide a valid e-mail address for use as the username',
                   6897:                           );
1.27      raeburn  6898:     if ($putresult eq 'ok') {
                   6899:         if (keys(%changes) > 0) {
                   6900:             $resulttext = &mt('Changes made:').'<ul>';
                   6901:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  6902:                 my %lt = &usercreation_types();
                   6903:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  6904:                     my $chgtext;
1.165     raeburn  6905:                     unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100     raeburn  6906:                         $chgtext = $lt{$type}.', ';
                   6907:                     }
1.45      raeburn  6908:                     if ($type eq 'selfcreate') {
1.50      raeburn  6909:                         if (@{$cancreate{$type}} == 0) {
1.43      raeburn  6910:                             $chgtext .= &mt('creation of a new user account is not permitted.');
1.50      raeburn  6911:                         } else {
1.100     raeburn  6912:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50      raeburn  6913:                             foreach my $case (@{$cancreate{$type}}) {
                   6914:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   6915:                             }
                   6916:                             $chgtext .= '</ul>';
1.100     raeburn  6917:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   6918:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   6919:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   6920:                                         if (@{$cancreate{'statustocreate'}} == 0) {
                   6921:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6922:                                         }
                   6923:                                     }
                   6924:                                 }
                   6925:                             }
1.43      raeburn  6926:                         }
1.93      raeburn  6927:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  6928:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   6929:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   6930:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   6931:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  6932: 
                   6933:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  6934:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6935:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6936:                                     } 
1.96      raeburn  6937:                                 } elsif (ref($usertypes) eq 'HASH') {
                   6938:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6939:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   6940:                                     } else {
                   6941:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   6942:                                     }
                   6943:                                     $chgtext .= '<ul>';
                   6944:                                     foreach my $case (@{$cancreate{$type}}) {
                   6945:                                         if ($case eq 'default') {
                   6946:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   6947:                                         } else {
                   6948:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  6949:                                         }
                   6950:                                     }
1.100     raeburn  6951:                                     $chgtext .= '</ul>';
                   6952:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                   6953:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                   6954:                                     }
                   6955:                                 }
                   6956:                             } else {
                   6957:                                 if (@{$cancreate{$type}} == 0) {
                   6958:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   6959:                                 } else {
                   6960:                                     $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  6961:                                 }
                   6962:                             }
                   6963:                         }
1.165     raeburn  6964:                     } elsif ($type eq 'captcha') {
                   6965:                         if ($cancreate{$type} eq 'notused') {
                   6966:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   6967:                         } else {
                   6968:                             my %captchas = &captcha_phrases();
                   6969:                             if ($captchas{$cancreate{$type}}) {
                   6970:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
                   6971:                             } else {
                   6972:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.'); 
                   6973:                             }
                   6974:                         }
                   6975:                     } elsif ($type eq 'recaptchakeys') {
                   6976:                         my ($privkey,$pubkey);
                   6977:                         if (ref($cancreate{$type}) eq 'HASH') {
                   6978:                             $pubkey = $cancreate{$type}{'public'};
                   6979:                             $privkey = $cancreate{$type}{'private'};
                   6980:                         }
                   6981:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   6982:                         if (!$pubkey) {
                   6983:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   6984:                         } else {
                   6985:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   6986:                         }
                   6987:                         if (!$privkey) {
                   6988:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   6989:                         } else {
                   6990:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   6991:                         }
                   6992:                         $chgtext .= '</ul>';
1.43      raeburn  6993:                     } else {
                   6994:                         if ($cancreate{$type} eq 'none') {
                   6995:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   6996:                         } elsif ($cancreate{$type} eq 'any') {
                   6997:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   6998:                         } elsif ($cancreate{$type} eq 'official') {
                   6999:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   7000:                         } elsif ($cancreate{$type} eq 'unofficial') {
                   7001:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   7002:                         }
1.34      raeburn  7003:                     }
                   7004:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  7005:                 }
                   7006:             }
                   7007:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  7008:                 my ($rules,$ruleorder) = 
                   7009:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  7010:                 my $chgtext = '<ul>';
                   7011:                 foreach my $type (@username_rule) {
                   7012:                     if (ref($rules->{$type}) eq 'HASH') {
                   7013:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   7014:                     }
                   7015:                 }
                   7016:                 $chgtext .= '</ul>';
                   7017:                 if (@username_rule > 0) {
                   7018:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   7019:                 } else {
1.28      raeburn  7020:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  7021:                 }
                   7022:             }
1.32      raeburn  7023:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   7024:                 my ($idrules,$idruleorder) = 
                   7025:                     &Apache::lonnet::inst_userrules($dom,'id');
                   7026:                 my $chgtext = '<ul>';
                   7027:                 foreach my $type (@id_rule) {
                   7028:                     if (ref($idrules->{$type}) eq 'HASH') {
                   7029:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   7030:                     }
                   7031:                 }
                   7032:                 $chgtext .= '</ul>';
                   7033:                 if (@id_rule > 0) {
                   7034:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   7035:                 } else {
                   7036:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   7037:                 }
                   7038:             }
1.43      raeburn  7039:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   7040:                 my ($emailrules,$emailruleorder) =
                   7041:                     &Apache::lonnet::inst_userrules($dom,'email');
                   7042:                 my $chgtext = '<ul>';
                   7043:                 foreach my $type (@email_rule) {
                   7044:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   7045:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   7046:                     }
                   7047:                 }
                   7048:                 $chgtext .= '</ul>';
                   7049:                 if (@email_rule > 0) {
                   7050:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                   7051:                 } else {
                   7052:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                   7053:                 }
                   7054:             }
                   7055: 
1.28      raeburn  7056:             my %authname = &authtype_names();
                   7057:             my %context_title = &context_names();
                   7058:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   7059:                 my $chgtext = '<ul>';
                   7060:                 foreach my $type (@{$changes{'authtypes'}}) {
                   7061:                     my @allowed;
                   7062:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   7063:                     foreach my $auth (@authtypes) {
                   7064:                         if ($authhash{$type}{$auth}) {
                   7065:                             push(@allowed,$authname{$auth});
                   7066:                         }
                   7067:                     }
1.43      raeburn  7068:                     if (@allowed > 0) {
                   7069:                         $chgtext .= join(', ',@allowed).'</li>';
                   7070:                     } else {
                   7071:                         $chgtext .= &mt('none').'</li>';
                   7072:                     }
1.28      raeburn  7073:                 }
                   7074:                 $chgtext .= '</ul>';
                   7075:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   7076:                 $resulttext .= '</li>';
                   7077:             }
1.27      raeburn  7078:             $resulttext .= '</ul>';
                   7079:         } else {
1.28      raeburn  7080:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  7081:         }
                   7082:     } else {
                   7083:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  7084:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7085:     }
1.43      raeburn  7086:     if ($warningmsg ne '') {
                   7087:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   7088:     }
1.23      raeburn  7089:     return $resulttext;
                   7090: }
                   7091: 
1.165     raeburn  7092: sub process_captcha {
                   7093:     my ($container,$changes,$newsettings,$current) = @_;
                   7094:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   7095:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   7096:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   7097:         $newsettings->{'captcha'} = 'original';
                   7098:     }
                   7099:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169     raeburn  7100:         if ($container eq 'cancreate') { 
                   7101:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   7102:                 push(@{$changes->{'cancreate'}},'captcha');
                   7103:             } elsif (!defined($changes->{'cancreate'})) {
                   7104:                 $changes->{'cancreate'} = ['captcha'];
                   7105:             }
                   7106:         } else {
                   7107:             $changes->{'captcha'} = 1;
1.165     raeburn  7108:         }
                   7109:     }
                   7110:     my ($newpub,$newpriv,$currpub,$currpriv);
                   7111:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   7112:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   7113:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169     raeburn  7114:         $newpub =~ s/\W//g;
                   7115:         $newpriv =~ s/\W//g;
                   7116:         $newsettings->{'recaptchakeys'} = {
                   7117:                                              public  => $newpub,
                   7118:                                              private => $newpriv,
                   7119:                                           };
1.165     raeburn  7120:     }
                   7121:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   7122:         $currpub = $current->{'recaptchakeys'}{'public'};
                   7123:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.179     raeburn  7124:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   7125:             $newsettings->{'recaptchakeys'} = {
                   7126:                                                  public  => '',
                   7127:                                                  private => '',
                   7128:                                               }
                   7129:         }
1.165     raeburn  7130:     }
                   7131:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  7132:         if ($container eq 'cancreate') {
                   7133:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   7134:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   7135:             } elsif (!defined($changes->{'cancreate'})) {
                   7136:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   7137:             }
                   7138:         } else {
                   7139:             $changes->{'recaptchakeys'} = 1; 
1.165     raeburn  7140:         }
                   7141:     }
                   7142:     return;
                   7143: }
                   7144: 
1.33      raeburn  7145: sub modify_usermodification {
                   7146:     my ($dom,%domconfig) = @_;
                   7147:     my ($resulttext,%curr_usermodification,%changes);
                   7148:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   7149:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   7150:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   7151:         }
                   7152:     }
1.63      raeburn  7153:     my @contexts = ('author','course','selfcreate');
1.33      raeburn  7154:     my %context_title = (
                   7155:                            author => 'In author context',
                   7156:                            course => 'In course context',
1.63      raeburn  7157:                            selfcreate => 'When self creating account', 
1.33      raeburn  7158:                         );
                   7159:     my @fields = ('lastname','firstname','middlename','generation',
                   7160:                   'permanentemail','id');
                   7161:     my %roles = (
                   7162:                   author => ['ca','aa'],
                   7163:                   course => ['st','ep','ta','in','cr'],
                   7164:                 );
1.63      raeburn  7165:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7166:     if (ref($types) eq 'ARRAY') {
                   7167:         push(@{$types},'default');
                   7168:         $usertypes->{'default'} = $othertitle;
                   7169:     }
                   7170:     $roles{'selfcreate'} = $types;  
1.33      raeburn  7171:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7172:     my %modifyhash;
                   7173:     foreach my $context (@contexts) {
                   7174:         foreach my $role (@{$roles{$context}}) {
                   7175:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   7176:             foreach my $item (@fields) {
                   7177:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   7178:                     $modifyhash{$context}{$role}{$item} = 1;
                   7179:                 } else {
                   7180:                     $modifyhash{$context}{$role}{$item} = 0;
                   7181:                 }
                   7182:             }
                   7183:         }
                   7184:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   7185:             foreach my $role (@{$roles{$context}}) {
                   7186:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   7187:                     foreach my $field (@fields) {
                   7188:                         if ($modifyhash{$context}{$role}{$field} ne 
                   7189:                                 $curr_usermodification{$context}{$role}{$field}) {
                   7190:                             push(@{$changes{$context}},$role);
                   7191:                             last;
                   7192:                         }
                   7193:                     }
                   7194:                 }
                   7195:             }
                   7196:         } else {
                   7197:             foreach my $context (@contexts) {
                   7198:                 foreach my $role (@{$roles{$context}}) {
                   7199:                     push(@{$changes{$context}},$role);
                   7200:                 }
                   7201:             }
                   7202:         }
                   7203:     }
                   7204:     my %usermodification_hash =  (
                   7205:                                    usermodification => \%modifyhash,
                   7206:                                  );
                   7207:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   7208:                                              \%usermodification_hash,$dom);
                   7209:     if ($putresult eq 'ok') {
                   7210:         if (keys(%changes) > 0) {
                   7211:             $resulttext = &mt('Changes made: ').'<ul>';
                   7212:             foreach my $context (@contexts) {
                   7213:                 if (ref($changes{$context}) eq 'ARRAY') {
                   7214:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   7215:                     if (ref($changes{$context}) eq 'ARRAY') {
                   7216:                         foreach my $role (@{$changes{$context}}) {
                   7217:                             my $rolename;
1.63      raeburn  7218:                             if ($context eq 'selfcreate') {
                   7219:                                 $rolename = $role;
                   7220:                                 if (ref($usertypes) eq 'HASH') {
                   7221:                                     if ($usertypes->{$role} ne '') {
                   7222:                                         $rolename = $usertypes->{$role};
                   7223:                                     }
                   7224:                                 }
1.33      raeburn  7225:                             } else {
1.63      raeburn  7226:                                 if ($role eq 'cr') {
                   7227:                                     $rolename = &mt('Custom');
                   7228:                                 } else {
                   7229:                                     $rolename = &Apache::lonnet::plaintext($role);
                   7230:                                 }
1.33      raeburn  7231:                             }
                   7232:                             my @modifiable;
1.63      raeburn  7233:                             if ($context eq 'selfcreate') {
1.126     bisitz   7234:                                 $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  7235:                             } else {
                   7236:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   7237:                             }
1.33      raeburn  7238:                             foreach my $field (@fields) {
                   7239:                                 if ($modifyhash{$context}{$role}{$field}) {
                   7240:                                     push(@modifiable,$fieldtitles{$field});
                   7241:                                 }
                   7242:                             }
                   7243:                             if (@modifiable > 0) {
                   7244:                                 $resulttext .= join(', ',@modifiable);
                   7245:                             } else {
                   7246:                                 $resulttext .= &mt('none'); 
                   7247:                             }
                   7248:                             $resulttext .= '</li>';
                   7249:                         }
                   7250:                         $resulttext .= '</ul></li>';
                   7251:                     }
                   7252:                 }
                   7253:             }
                   7254:             $resulttext .= '</ul>';
                   7255:         } else {
                   7256:             $resulttext = &mt('No changes made to user modification settings');
                   7257:         }
                   7258:     } else {
                   7259:         $resulttext = '<span class="LC_error">'.
                   7260:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7261:     }
                   7262:     return $resulttext;
                   7263: }
                   7264: 
1.43      raeburn  7265: sub modify_defaults {
                   7266:     my ($dom,$r) = @_;
                   7267:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
                   7268:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  7269:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  7270:     my @authtypes = ('internal','krb4','krb5','localauth');
                   7271:     foreach my $item (@items) {
                   7272:         $newvalues{$item} = $env{'form.'.$item};
                   7273:         if ($item eq 'auth_def') {
                   7274:             if ($newvalues{$item} ne '') {
                   7275:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   7276:                     push(@errors,$item);
                   7277:                 }
                   7278:             }
                   7279:         } elsif ($item eq 'lang_def') {
                   7280:             if ($newvalues{$item} ne '') {
                   7281:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   7282:                     my $langcode = $1;
1.103     raeburn  7283:                     if ($langcode ne 'x_chef') {
                   7284:                         if (code2language($langcode) eq '') {
                   7285:                             push(@errors,$item);
                   7286:                         }
1.43      raeburn  7287:                     }
                   7288:                 } else {
                   7289:                     push(@errors,$item);
                   7290:                 }
                   7291:             }
1.54      raeburn  7292:         } elsif ($item eq 'timezone_def') {
                   7293:             if ($newvalues{$item} ne '') {
1.62      raeburn  7294:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  7295:                     push(@errors,$item);   
                   7296:                 }
                   7297:             }
1.68      raeburn  7298:         } elsif ($item eq 'datelocale_def') {
                   7299:             if ($newvalues{$item} ne '') {
                   7300:                 my @datelocale_ids = DateTime::Locale->ids();
                   7301:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   7302:                     push(@errors,$item);
                   7303:                 }
                   7304:             }
1.141     raeburn  7305:         } elsif ($item eq 'portal_def') {
                   7306:             if ($newvalues{$item} ne '') {
                   7307:                 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])\/?$/) {
                   7308:                     push(@errors,$item);
                   7309:                 }
                   7310:             }
1.43      raeburn  7311:         }
                   7312:         if (grep(/^\Q$item\E$/,@errors)) {
                   7313:             $newvalues{$item} = $domdefaults{$item};
                   7314:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   7315:             $changes{$item} = 1;
                   7316:         }
1.72      raeburn  7317:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  7318:     }
                   7319:     my %defaults_hash = (
1.72      raeburn  7320:                          defaults => \%newvalues,
                   7321:                         );
1.43      raeburn  7322:     my $title = &defaults_titles();
                   7323:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   7324:                                              $dom);
                   7325:     if ($putresult eq 'ok') {
                   7326:         if (keys(%changes) > 0) {
                   7327:             $resulttext = &mt('Changes made:').'<ul>';
                   7328:             my $version = $r->dir_config('lonVersion');
                   7329:             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";
                   7330:             foreach my $item (sort(keys(%changes))) {
                   7331:                 my $value = $env{'form.'.$item};
                   7332:                 if ($value eq '') {
                   7333:                     $value = &mt('none');
                   7334:                 } elsif ($item eq 'auth_def') {
                   7335:                     my %authnames = &authtype_names();
                   7336:                     my %shortauth = (
                   7337:                              internal => 'int',
                   7338:                              krb4 => 'krb4',
                   7339:                              krb5 => 'krb5',
                   7340:                              localauth  => 'loc',
                   7341:                     );
                   7342:                     $value = $authnames{$shortauth{$value}};
                   7343:                 }
                   7344:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   7345:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   7346:             }
                   7347:             $resulttext .= '</ul>';
                   7348:             $mailmsgtext .= "\n";
                   7349:             my $cachetime = 24*60*60;
1.72      raeburn  7350:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68      raeburn  7351:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54      raeburn  7352:                 my $sysmail = $r->dir_config('lonSysEMail');
                   7353:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
                   7354:             }
1.43      raeburn  7355:         } else {
1.54      raeburn  7356:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  7357:         }
                   7358:     } else {
                   7359:         $resulttext = '<span class="LC_error">'.
                   7360:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7361:     }
                   7362:     if (@errors > 0) {
                   7363:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   7364:         foreach my $item (@errors) {
                   7365:             $resulttext .= ' "'.$title->{$item}.'",';
                   7366:         }
                   7367:         $resulttext =~ s/,$//;
                   7368:     }
                   7369:     return $resulttext;
                   7370: }
                   7371: 
1.46      raeburn  7372: sub modify_scantron {
1.48      raeburn  7373:     my ($r,$dom,$confname,%domconfig) = @_;
1.46      raeburn  7374:     my ($resulttext,%confhash,%changes,$errors);
                   7375:     my $custom = 'custom.tab';
                   7376:     my $default = 'default.tab';
                   7377:     my $servadm = $r->dir_config('lonAdmEMail');
                   7378:     my ($configuserok,$author_ok,$switchserver) = 
                   7379:         &config_check($dom,$confname,$servadm);
                   7380:     if ($env{'form.scantronformat.filename'} ne '') {
                   7381:         my $error;
                   7382:         if ($configuserok eq 'ok') {
                   7383:             if ($switchserver) {
1.130     raeburn  7384:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  7385:             } else {
                   7386:                 if ($author_ok eq 'ok') {
                   7387:                     my ($result,$scantronurl) =
                   7388:                         &publishlogo($r,'upload','scantronformat',$dom,
                   7389:                                      $confname,'scantron','','',$custom);
                   7390:                     if ($result eq 'ok') {
                   7391:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  7392:                         $changes{'scantronformat'} = 1;
1.46      raeburn  7393:                     } else {
                   7394:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   7395:                     }
                   7396:                 } else {
                   7397:                     $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);
                   7398:                 }
                   7399:             }
                   7400:         } else {
                   7401:             $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);
                   7402:         }
                   7403:         if ($error) {
                   7404:             &Apache::lonnet::logthis($error);
                   7405:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7406:         }
                   7407:     }
1.48      raeburn  7408:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   7409:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   7410:             if ($env{'form.scantronformat_del'}) {
                   7411:                 $confhash{'scantron'}{'scantronformat'} = '';
                   7412:                 $changes{'scantronformat'} = 1;
1.46      raeburn  7413:             }
                   7414:         }
                   7415:     }
                   7416:     if (keys(%confhash) > 0) {
                   7417:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   7418:                                                  $dom);
                   7419:         if ($putresult eq 'ok') {
                   7420:             if (keys(%changes) > 0) {
1.48      raeburn  7421:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   7422:                     $resulttext = &mt('Changes made:').'<ul>';
                   7423:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  7424:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  7425:                     } else {
1.130     raeburn  7426:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  7427:                     }
1.48      raeburn  7428:                     $resulttext .= '</ul>';
                   7429:                 } else {
1.130     raeburn  7430:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  7431:                 }
                   7432:                 $resulttext .= '</ul>';
                   7433:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   7434:             } else {
1.130     raeburn  7435:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  7436:             }
                   7437:         } else {
                   7438:             $resulttext = '<span class="LC_error">'.
                   7439:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   7440:         }
                   7441:     } else {
1.130     raeburn  7442:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  7443:     }
                   7444:     if ($errors) {
                   7445:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7446:                        $errors.'</ul>';
                   7447:     }
                   7448:     return $resulttext;
                   7449: }
                   7450: 
1.48      raeburn  7451: sub modify_coursecategories {
                   7452:     my ($dom,%domconfig) = @_;
1.57      raeburn  7453:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   7454:         $cathash);
1.48      raeburn  7455:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  7456:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  7457:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   7458:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   7459:             $changes{'togglecats'} = 1;
                   7460:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   7461:         }
                   7462:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   7463:             $changes{'categorize'} = 1;
                   7464:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   7465:         }
1.120     raeburn  7466:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   7467:             $changes{'togglecatscomm'} = 1;
                   7468:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   7469:         }
                   7470:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   7471:             $changes{'categorizecomm'} = 1;
                   7472:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   7473:         }
1.57      raeburn  7474:     } else {
                   7475:         $changes{'togglecats'} = 1;
                   7476:         $changes{'categorize'} = 1;
1.124     raeburn  7477:         $changes{'togglecatscomm'} = 1;
                   7478:         $changes{'categorizecomm'} = 1;
1.87      raeburn  7479:         $domconfig{'coursecategories'} = {
                   7480:                                              togglecats => $env{'form.togglecats'},
                   7481:                                              categorize => $env{'form.categorize'},
1.124     raeburn  7482:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   7483:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  7484:                                          };
1.57      raeburn  7485:     }
                   7486:     if (ref($cathash) eq 'HASH') {
                   7487:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  7488:             push (@deletecategory,'instcode::0');
                   7489:         }
1.120     raeburn  7490:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   7491:             push(@deletecategory,'communities::0');
                   7492:         }
1.48      raeburn  7493:     }
1.57      raeburn  7494:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   7495:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  7496:         if (@deletecategory > 0) {
                   7497:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  7498:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  7499:             foreach my $item (@deletecategory) {
1.57      raeburn  7500:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   7501:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  7502:                     $deletions{$item} = 1;
1.57      raeburn  7503:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  7504:                 }
                   7505:             }
                   7506:         }
1.57      raeburn  7507:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  7508:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  7509:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  7510:                 $reorderings{$item} = 1;
1.57      raeburn  7511:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  7512:             }
                   7513:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   7514:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   7515:                 my $newdepth = $depth+1;
                   7516:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7517:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  7518:                 $adds{$newitem} = 1; 
                   7519:             }
                   7520:             if ($env{'form.subcat_'.$item} ne '') {
                   7521:                 my $newcat = $env{'form.subcat_'.$item};
                   7522:                 my $newdepth = $depth+1;
                   7523:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7524:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  7525:                 $adds{$newitem} = 1;
                   7526:             }
                   7527:         }
                   7528:     }
                   7529:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  7530:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  7531:             my $newitem = 'instcode::0';
1.57      raeburn  7532:             if ($cathash->{$newitem} eq '') {  
                   7533:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7534:                 $adds{$newitem} = 1;
                   7535:             }
                   7536:         } else {
                   7537:             my $newitem = 'instcode::0';
1.57      raeburn  7538:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7539:             $adds{$newitem} = 1;
                   7540:         }
                   7541:     }
1.120     raeburn  7542:     if ($env{'form.communities'} eq '1') {
                   7543:         if (ref($cathash) eq 'HASH') {
                   7544:             my $newitem = 'communities::0';
                   7545:             if ($cathash->{$newitem} eq '') {
                   7546:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7547:                 $adds{$newitem} = 1;
                   7548:             }
                   7549:         } else {
                   7550:             my $newitem = 'communities::0';
                   7551:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7552:             $adds{$newitem} = 1;
                   7553:         }
                   7554:     }
1.48      raeburn  7555:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  7556:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   7557:             ($env{'form.addcategory_name'} ne 'communities')) {
                   7558:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   7559:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   7560:             $adds{$newitem} = 1;
                   7561:         }
1.48      raeburn  7562:     }
1.57      raeburn  7563:     my $putresult;
1.48      raeburn  7564:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7565:         if (keys(%deletions) > 0) {
                   7566:             foreach my $key (keys(%deletions)) {
                   7567:                 if ($predelallitems{$key} ne '') {
                   7568:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   7569:                 }
                   7570:             }
                   7571:         }
                   7572:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  7573:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  7574:         if (ref($chkcats[0]) eq 'ARRAY') {
                   7575:             my $depth = 0;
                   7576:             my $chg = 0;
                   7577:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   7578:                 my $name = $chkcats[0][$i];
                   7579:                 my $item;
                   7580:                 if ($name eq '') {
                   7581:                     $chg ++;
                   7582:                 } else {
                   7583:                     $item = &escape($name).'::0';
                   7584:                     if ($chg) {
1.57      raeburn  7585:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  7586:                     }
                   7587:                     $depth ++; 
1.57      raeburn  7588:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  7589:                     $depth --;
                   7590:                 }
                   7591:             }
                   7592:         }
1.57      raeburn  7593:     }
                   7594:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7595:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  7596:         if ($putresult eq 'ok') {
1.57      raeburn  7597:             my %title = (
1.120     raeburn  7598:                          togglecats     => 'Show/Hide a course in catalog',
                   7599:                          categorize     => 'Assign a category to a course',
                   7600:                          togglecatscomm => 'Show/Hide a community in catalog',
                   7601:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  7602:                         );
                   7603:             my %level = (
1.120     raeburn  7604:                          dom  => 'set in Domain ("Modify Course/Community")',
                   7605:                          crs  => 'set in Course ("Course Configuration")',
                   7606:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  7607:                         );
1.48      raeburn  7608:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  7609:             if ($changes{'togglecats'}) {
                   7610:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   7611:             }
                   7612:             if ($changes{'categorize'}) {
                   7613:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  7614:             }
1.120     raeburn  7615:             if ($changes{'togglecatscomm'}) {
                   7616:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   7617:             }
                   7618:             if ($changes{'categorizecomm'}) {
                   7619:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   7620:             }
1.57      raeburn  7621:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7622:                 my $cathash;
                   7623:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   7624:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   7625:                 } else {
                   7626:                     $cathash = {};
                   7627:                 } 
                   7628:                 my (@cats,@trails,%allitems);
                   7629:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   7630:                 if (keys(%deletions) > 0) {
                   7631:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   7632:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   7633:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   7634:                     }
                   7635:                     $resulttext .= '</ul></li>';
                   7636:                 }
                   7637:                 if (keys(%reorderings) > 0) {
                   7638:                     my %sort_by_trail;
                   7639:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   7640:                     foreach my $key (keys(%reorderings)) {
                   7641:                         if ($allitems{$key} ne '') {
                   7642:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7643:                         }
1.48      raeburn  7644:                     }
1.57      raeburn  7645:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7646:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   7647:                     }
                   7648:                     $resulttext .= '</ul></li>';
1.48      raeburn  7649:                 }
1.57      raeburn  7650:                 if (keys(%adds) > 0) {
                   7651:                     my %sort_by_trail;
                   7652:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   7653:                     foreach my $key (keys(%adds)) {
                   7654:                         if ($allitems{$key} ne '') {
                   7655:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7656:                         }
                   7657:                     }
                   7658:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7659:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  7660:                     }
1.57      raeburn  7661:                     $resulttext .= '</ul></li>';
1.48      raeburn  7662:                 }
                   7663:             }
                   7664:             $resulttext .= '</ul>';
                   7665:         } else {
                   7666:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  7667:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  7668:         }
                   7669:     } else {
1.120     raeburn  7670:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  7671:     }
                   7672:     return $resulttext;
                   7673: }
                   7674: 
1.69      raeburn  7675: sub modify_serverstatuses {
                   7676:     my ($dom,%domconfig) = @_;
                   7677:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   7678:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   7679:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   7680:     }
                   7681:     my @pages = &serverstatus_pages();
                   7682:     foreach my $type (@pages) {
                   7683:         $newserverstatus{$type}{'namedusers'} = '';
                   7684:         $newserverstatus{$type}{'machines'} = '';
                   7685:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   7686:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   7687:             my @okusers;
                   7688:             foreach my $user (@users) {
                   7689:                 my ($uname,$udom) = split(/:/,$user);
                   7690:                 if (($udom =~ /^$match_domain$/) &&   
                   7691:                     (&Apache::lonnet::domain($udom)) &&
                   7692:                     ($uname =~ /^$match_username$/)) {
                   7693:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   7694:                         push(@okusers,$user);
                   7695:                     }
                   7696:                 }
                   7697:             }
                   7698:             if (@okusers > 0) {
                   7699:                  @okusers = sort(@okusers);
                   7700:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   7701:             }
                   7702:         }
                   7703:         if (defined($env{'form.'.$type.'_machines'})) {
                   7704:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   7705:             my @okmachines;
                   7706:             foreach my $ip (@machines) {
                   7707:                 my @parts = split(/\./,$ip);
                   7708:                 next if (@parts < 4);
                   7709:                 my $badip = 0;
                   7710:                 for (my $i=0; $i<4; $i++) {
                   7711:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   7712:                         $badip = 1;
                   7713:                         last;
                   7714:                     }
                   7715:                 }
                   7716:                 if (!$badip) {
                   7717:                     push(@okmachines,$ip);     
                   7718:                 }
                   7719:             }
                   7720:             @okmachines = sort(@okmachines);
                   7721:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   7722:         }
                   7723:     }
                   7724:     my %serverstatushash =  (
                   7725:                                 serverstatuses => \%newserverstatus,
                   7726:                             );
                   7727:     foreach my $type (@pages) {
1.83      raeburn  7728:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  7729:             my (@current,@new);
1.83      raeburn  7730:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  7731:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   7732:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   7733:                 }
                   7734:             }
                   7735:             if ($newserverstatus{$type}{$setting} ne '') {
                   7736:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  7737:             }
                   7738:             if (@current > 0) {
                   7739:                 if (@new > 0) {
                   7740:                     foreach my $item (@current) {
                   7741:                         if (!grep(/^\Q$item\E$/,@new)) {
                   7742:                             $changes{$type}{$setting} = 1;
1.82      raeburn  7743:                             last;
                   7744:                         }
                   7745:                     }
1.84      raeburn  7746:                     foreach my $item (@new) {
                   7747:                         if (!grep(/^\Q$item\E$/,@current)) {
                   7748:                             $changes{$type}{$setting} = 1;
                   7749:                             last;
1.82      raeburn  7750:                         }
                   7751:                     }
                   7752:                 } else {
1.83      raeburn  7753:                     $changes{$type}{$setting} = 1;
1.69      raeburn  7754:                 }
1.83      raeburn  7755:             } elsif (@new > 0) {
                   7756:                 $changes{$type}{$setting} = 1;
1.69      raeburn  7757:             }
                   7758:         }
                   7759:     }
                   7760:     if (keys(%changes) > 0) {
1.81      raeburn  7761:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7762:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   7763:                                                  \%serverstatushash,$dom);
                   7764:         if ($putresult eq 'ok') {
                   7765:             $resulttext .= &mt('Changes made:').'<ul>';
                   7766:             foreach my $type (@pages) {
1.84      raeburn  7767:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  7768:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  7769:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  7770:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   7771:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   7772:                         } else {
                   7773:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   7774:                         }
1.84      raeburn  7775:                     }
                   7776:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  7777:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   7778:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   7779:                         } else {
                   7780:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   7781:                         }
                   7782: 
                   7783:                     }
                   7784:                     $resulttext .= '</ul></li>';
                   7785:                 }
                   7786:             }
                   7787:             $resulttext .= '</ul>';
                   7788:         } else {
                   7789:             $resulttext = '<span class="LC_error">'.
                   7790:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   7791: 
                   7792:         }
                   7793:     } else {
                   7794:         $resulttext = &mt('No changes made to access to server status pages');
                   7795:     }
                   7796:     return $resulttext;
                   7797: }
                   7798: 
1.118     jms      7799: sub modify_helpsettings {
1.122     jms      7800:     my ($r,$dom,$confname,%domconfig) = @_;
1.166     raeburn  7801:     my ($resulttext,$errors,%changes,%helphash);
                   7802:     my %defaultchecked = ('submitbugs' => 'on');
                   7803:     my @offon = ('off','on');
1.118     jms      7804:     my @toggles = ('submitbugs');
                   7805:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   7806:         foreach my $item (@toggles) {
1.166     raeburn  7807:             if ($defaultchecked{$item} eq 'on') { 
                   7808:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7809:                     if ($env{'form.'.$item} eq '0') {
                   7810:                         $changes{$item} = 1;
                   7811:                     }
                   7812:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7813:                     $changes{$item} = 1;
                   7814:                 }
                   7815:             } elsif ($defaultchecked{$item} eq 'off') {
                   7816:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7817:                     if ($env{'form.'.$item} eq '1') {
                   7818:                         $changes{$item} = 1;
                   7819:                     }
                   7820:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7821:                     $changes{$item} = 1;
                   7822:                 }
                   7823:             }
                   7824:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { 
                   7825:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   7826:             }
                   7827:         }
1.118     jms      7828:     }
1.123     jms      7829:     my $putresult;
                   7830:     if (keys(%changes) > 0) {
1.166     raeburn  7831:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  7832:         if ($putresult eq 'ok') {
1.166     raeburn  7833:             $resulttext = &mt('Changes made:').'<ul>';
                   7834:             foreach my $item (sort(keys(%changes))) {
                   7835:                 if ($item eq 'submitbugs') {
                   7836:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   7837:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   7838:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                   7839:                 }
                   7840:             }
                   7841:             $resulttext .= '</ul>';
                   7842:         } else {
                   7843:             $resulttext = &mt('No changes made to help settings');
1.168     raeburn  7844:             $errors .= '<li><span class="LC_error">'.
                   7845:                        &mt('An error occurred storing the settings: [_1]',
                   7846:                            $putresult).'</span></li>';
1.166     raeburn  7847:         }
1.118     jms      7848:     }
                   7849:     if ($errors) {
1.168     raeburn  7850:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118     jms      7851:                        $errors.'</ul>';
                   7852:     }
                   7853:     return $resulttext;
                   7854: }
                   7855: 
1.121     raeburn  7856: sub modify_coursedefaults {
                   7857:     my ($dom,%domconfig) = @_;
                   7858:     my ($resulttext,$errors,%changes,%defaultshash);
                   7859:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   7860:     my @offon = ('off','on');
                   7861:     my @toggles = ('canuse_pdfforms');
                   7862: 
                   7863:     $defaultshash{'coursedefaults'} = {};
                   7864: 
                   7865:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   7866:         if ($domconfig{'coursedefaults'} eq '') {
                   7867:             $domconfig{'coursedefaults'} = {};
                   7868:         }
                   7869:     }
                   7870: 
                   7871:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   7872:         foreach my $item (@toggles) {
                   7873:             if ($defaultchecked{$item} eq 'on') {
                   7874:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7875:                     ($env{'form.'.$item} eq '0')) {
                   7876:                     $changes{$item} = 1;
                   7877:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
                   7878:                     $changes{$item} = 1;
                   7879:                 }
                   7880:             } elsif ($defaultchecked{$item} eq 'off') {
                   7881:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7882:                     ($env{'form.'.$item} eq '1')) {
                   7883:                     $changes{$item} = 1;
                   7884:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   7885:                     $changes{$item} = 1;
                   7886:                 }
                   7887:             }
                   7888:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   7889:         }
1.139     raeburn  7890:         my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
                   7891:         my $newdefresponder = $env{'form.anonsurvey_threshold'};
                   7892:         $newdefresponder =~ s/\D//g;
                   7893:         if ($newdefresponder eq '' || $newdefresponder < 1) {
                   7894:             $newdefresponder = 1;
                   7895:         }
                   7896:         $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
                   7897:         if ($currdefresponder ne $newdefresponder) {
                   7898:             unless ($currdefresponder eq '' && $newdefresponder == 10) {
                   7899:                 $changes{'anonsurvey_threshold'} = 1;
                   7900:             }
                   7901:         }
1.121     raeburn  7902:     }
                   7903:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7904:                                              $dom);
                   7905:     if ($putresult eq 'ok') {
                   7906:         if (keys(%changes) > 0) {
                   7907:             if ($changes{'canuse_pdfforms'}) {
                   7908:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7909:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   7910:                 my $cachetime = 24*60*60;
                   7911:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   7912:             }
                   7913:             $resulttext = &mt('Changes made:').'<ul>';
                   7914:             foreach my $item (sort(keys(%changes))) {
                   7915:                 if ($item eq 'canuse_pdfforms') {
                   7916:                     if ($env{'form.'.$item} eq '1') {
                   7917:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   7918:                     } else {
                   7919:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   7920:                     }
1.139     raeburn  7921:                 } elsif ($item eq 'anonsurvey_threshold') {
                   7922:                         $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140     raeburn  7923:                 }
1.121     raeburn  7924:             }
                   7925:             $resulttext .= '</ul>';
                   7926:         } else {
                   7927:             $resulttext = &mt('No changes made to course defaults');
                   7928:         }
                   7929:     } else {
                   7930:         $resulttext = '<span class="LC_error">'.
                   7931:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7932:     }
                   7933:     return $resulttext;
                   7934: }
                   7935: 
1.137     raeburn  7936: sub modify_usersessions {
                   7937:     my ($dom,%domconfig) = @_;
1.145     raeburn  7938:     my @hostingtypes = ('version','excludedomain','includedomain');
                   7939:     my @offloadtypes = ('primary','default');
                   7940:     my %types = (
                   7941:                   remote => \@hostingtypes,
                   7942:                   hosted => \@hostingtypes,
                   7943:                   spares => \@offloadtypes,
                   7944:                 );
                   7945:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  7946:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  7947:     my (%by_ip,%by_location,@intdoms);
                   7948:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   7949:     my @locations = sort(keys(%by_location));
1.137     raeburn  7950:     my (%defaultshash,%changes);
                   7951:     foreach my $prefix (@prefixes) {
                   7952:         $defaultshash{'usersessions'}{$prefix} = {};
                   7953:     }
                   7954:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7955:     my $resulttext;
1.138     raeburn  7956:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  7957:     foreach my $prefix (@prefixes) {
1.145     raeburn  7958:         next if ($prefix eq 'spares');
                   7959:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  7960:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   7961:             if ($type eq 'version') {
                   7962:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   7963:                 my $okvalue;
                   7964:                 if ($value ne '') {
                   7965:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   7966:                         $okvalue = $value;
                   7967:                     }
                   7968:                 }
                   7969:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7970:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7971:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   7972:                             if ($inuse == 0) {
                   7973:                                 $changes{$prefix}{$type} = 1;
                   7974:                             } else {
                   7975:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   7976:                                     $changes{$prefix}{$type} = 1;
                   7977:                                 }
                   7978:                                 if ($okvalue ne '') {
                   7979:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7980:                                 } 
                   7981:                             }
                   7982:                         } else {
                   7983:                             if (($inuse == 1) && ($okvalue ne '')) {
                   7984:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7985:                                 $changes{$prefix}{$type} = 1;
                   7986:                             }
                   7987:                         }
                   7988:                     } else {
                   7989:                         if (($inuse == 1) && ($okvalue ne '')) {
                   7990:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7991:                             $changes{$prefix}{$type} = 1;
                   7992:                         }
                   7993:                     }
                   7994:                 } else {
                   7995:                     if (($inuse == 1) && ($okvalue ne '')) {
                   7996:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7997:                         $changes{$prefix}{$type} = 1;
                   7998:                     }
                   7999:                 }
                   8000:             } else {
                   8001:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   8002:                 my @okvals;
                   8003:                 foreach my $val (@vals) {
1.138     raeburn  8004:                     if ($val =~ /:/) {
                   8005:                         my @items = split(/:/,$val);
                   8006:                         foreach my $item (@items) {
                   8007:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   8008:                                 push(@okvals,$item);
                   8009:                             }
                   8010:                         }
                   8011:                     } else {
                   8012:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   8013:                             push(@okvals,$val);
                   8014:                         }
1.137     raeburn  8015:                     }
                   8016:                 }
                   8017:                 @okvals = sort(@okvals);
                   8018:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8019:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   8020:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   8021:                             if ($inuse == 0) {
                   8022:                                 $changes{$prefix}{$type} = 1; 
                   8023:                             } else {
                   8024:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8025:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   8026:                                 if (@changed > 0) {
                   8027:                                     $changes{$prefix}{$type} = 1;
                   8028:                                 }
                   8029:                             }
                   8030:                         } else {
                   8031:                             if ($inuse == 1) {
                   8032:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8033:                                 $changes{$prefix}{$type} = 1;
                   8034:                             }
                   8035:                         } 
                   8036:                     } else {
                   8037:                         if ($inuse == 1) {
                   8038:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8039:                             $changes{$prefix}{$type} = 1;
                   8040:                         }
                   8041:                     }
                   8042:                 } else {
                   8043:                     if ($inuse == 1) {
                   8044:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8045:                         $changes{$prefix}{$type} = 1;
                   8046:                     }
                   8047:                 }
                   8048:             }
                   8049:         }
                   8050:     }
1.145     raeburn  8051: 
                   8052:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  8053:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  8054:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   8055:     my $savespares;
                   8056: 
                   8057:     foreach my $lonhost (sort(keys(%servers))) {
                   8058:         my $serverhomeID =
                   8059:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  8060:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  8061:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   8062:         my %spareschg;
                   8063:         foreach my $type (@{$types{'spares'}}) {
                   8064:             my @okspares;
                   8065:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   8066:             foreach my $server (@checked) {
1.152     raeburn  8067:                 if (&Apache::lonnet::hostname($server) ne '') {
                   8068:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   8069:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   8070:                             push(@okspares,$server);
                   8071:                         }
1.145     raeburn  8072:                     }
                   8073:                 }
                   8074:             }
                   8075:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   8076:             my $newspare;
1.152     raeburn  8077:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   8078:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  8079:                     $newspare = $new;
                   8080:                 }
                   8081:             }
1.152     raeburn  8082:             my @spares;
                   8083:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   8084:                 @spares = sort(@okspares,$newspare);
                   8085:             } else {
                   8086:                 @spares = sort(@okspares);
                   8087:             }
                   8088:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  8089:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   8090:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  8091:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  8092:                     if (@diffs > 0) {
                   8093:                         $spareschg{$type} = 1;
                   8094:                     }
                   8095:                 }
                   8096:             }
                   8097:         }
                   8098:         if (keys(%spareschg) > 0) {
                   8099:             $changes{'spares'}{$lonhost} = \%spareschg;
                   8100:         }
                   8101:     }
                   8102: 
                   8103:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8104:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   8105:             if (ref($changes{'spares'}) eq 'HASH') {
                   8106:                 if (keys(%{$changes{'spares'}}) > 0) {
                   8107:                     $savespares = 1;
                   8108:                 }
                   8109:             }
                   8110:         } else {
                   8111:             $savespares = 1;
                   8112:         }
                   8113:     }
                   8114: 
1.147     raeburn  8115:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   8116:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  8117:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   8118:                                                  $dom);
                   8119:         if ($putresult eq 'ok') {
                   8120:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8121:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   8122:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   8123:                 }
                   8124:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   8125:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   8126:                 }
                   8127:             }
                   8128:             my $cachetime = 24*60*60;
                   8129:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147     raeburn  8130:             if (keys(%changes) > 0) {
                   8131:                 my %lt = &usersession_titles();
                   8132:                 $resulttext = &mt('Changes made:').'<ul>';
                   8133:                 foreach my $prefix (@prefixes) {
                   8134:                     if (ref($changes{$prefix}) eq 'HASH') {
                   8135:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   8136:                         if ($prefix eq 'spares') {
                   8137:                             if (ref($changes{$prefix}) eq 'HASH') {
                   8138:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   8139:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  8140:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
                   8141:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147     raeburn  8142:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   8143:                                         foreach my $type (@{$types{$prefix}}) {
                   8144:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   8145:                                                 my $offloadto = &mt('None');
                   8146:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   8147:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   8148:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   8149:                                                     }
1.145     raeburn  8150:                                                 }
1.147     raeburn  8151:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  8152:                                             }
1.137     raeburn  8153:                                         }
                   8154:                                     }
1.147     raeburn  8155:                                     $resulttext .= '</li>';
1.137     raeburn  8156:                                 }
                   8157:                             }
1.147     raeburn  8158:                         } else {
                   8159:                             foreach my $type (@{$types{$prefix}}) {
                   8160:                                 if (defined($changes{$prefix}{$type})) {
                   8161:                                     my $newvalue;
                   8162:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8163:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   8164:                                             if ($type eq 'version') {
                   8165:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   8166:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   8167:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   8168:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   8169:                                                 }
1.145     raeburn  8170:                                             }
                   8171:                                         }
                   8172:                                     }
1.147     raeburn  8173:                                     if ($newvalue eq '') {
                   8174:                                         if ($type eq 'version') {
                   8175:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   8176:                                         } else {
                   8177:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   8178:                                         }
1.145     raeburn  8179:                                     } else {
1.147     raeburn  8180:                                         if ($type eq 'version') {
                   8181:                                             $newvalue .= ' '.&mt('(or later)'); 
                   8182:                                         }
                   8183:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  8184:                                     }
1.137     raeburn  8185:                                 }
                   8186:                             }
                   8187:                         }
1.147     raeburn  8188:                         $resulttext .= '</ul>';
1.137     raeburn  8189:                     }
                   8190:                 }
1.147     raeburn  8191:                 $resulttext .= '</ul>';
                   8192:             } else {
                   8193:                 $resulttext = $nochgmsg;
1.137     raeburn  8194:             }
                   8195:         } else {
                   8196:             $resulttext = '<span class="LC_error">'.
                   8197:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   8198:         }
                   8199:     } else {
1.147     raeburn  8200:         $resulttext = $nochgmsg;
1.137     raeburn  8201:     }
                   8202:     return $resulttext;
                   8203: }
                   8204: 
1.150     raeburn  8205: sub modify_loadbalancing {
                   8206:     my ($dom,%domconfig) = @_;
                   8207:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8208:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8209:     my ($othertitle,$usertypes,$types) =
                   8210:         &Apache::loncommon::sorted_inst_types($dom);
                   8211:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8212:     my @sparestypes = ('primary','default');
                   8213:     my %typetitles = &sparestype_titles();
                   8214:     my $resulttext;
1.171     raeburn  8215:     my (%currbalancer,%currtargets,%currrules,%existing);
                   8216:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8217:         %existing = %{$domconfig{'loadbalancing'}};
                   8218:     }
                   8219:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   8220:                               \%currtargets,\%currrules);
                   8221:     my ($saveloadbalancing,%defaultshash,%changes);
                   8222:     my ($alltypes,$othertypes,$titles) =
                   8223:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   8224:     my %ruletitles = &offloadtype_text();
                   8225:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   8226:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   8227:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   8228:         if ($balancer eq '') {
                   8229:             next;
                   8230:         }
                   8231:         if (!exists($servers{$balancer})) { 
                   8232:             if (exists($currbalancer{$balancer})) {
                   8233:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  8234:             }
1.171     raeburn  8235:             next;
                   8236:         }
                   8237:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   8238:             push(@{$changes{'delete'}},$balancer);
                   8239:             next;
                   8240:         }
                   8241:         if (!exists($currbalancer{$balancer})) {
                   8242:             push(@{$changes{'add'}},$balancer);
                   8243:         }
                   8244:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   8245:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   8246:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   8247:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8248:             $saveloadbalancing = 1;
                   8249:         }
                   8250:         foreach my $sparetype (@sparestypes) {
                   8251:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   8252:             my @offloadto;
                   8253:             foreach my $target (@targets) {
                   8254:                 if (($servers{$target}) && ($target ne $balancer)) {
                   8255:                     if ($sparetype eq 'default') {
                   8256:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   8257:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  8258:                         }
                   8259:                     }
1.171     raeburn  8260:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   8261:                         push(@offloadto,$target);
                   8262:                     }
1.150     raeburn  8263:                 }
1.171     raeburn  8264:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  8265:             }
                   8266:         }
1.171     raeburn  8267:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  8268:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  8269:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   8270:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  8271:                     if (@targetdiffs > 0) {
1.171     raeburn  8272:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  8273:                     }
1.171     raeburn  8274:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8275:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8276:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  8277:                     }
                   8278:                 }
                   8279:             }
                   8280:         } else {
1.171     raeburn  8281:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
                   8282:                 foreach my $sparetype (@sparestypes) { 
                   8283:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8284:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8285:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   8286:                         }
1.150     raeburn  8287:                     }
                   8288:                 }
                   8289:             }  
                   8290:         }
                   8291:         my $ishomedom;
1.171     raeburn  8292:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   8293:             $ishomedom = 1;
1.150     raeburn  8294:         }
                   8295:         if (ref($alltypes) eq 'ARRAY') {
                   8296:             foreach my $type (@{$alltypes}) {
                   8297:                 my $rule;
1.171     raeburn  8298:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
1.150     raeburn  8299:                          (!$ishomedom)) {
1.171     raeburn  8300:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   8301:                 }
                   8302:                 if ($rule eq 'specific') {
                   8303:                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150     raeburn  8304:                 }
1.171     raeburn  8305:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   8306:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   8307:                     if ($rule ne $currrules{$balancer}{$type}) {
                   8308:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  8309:                     }
                   8310:                 } elsif ($rule ne '') {
1.171     raeburn  8311:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  8312:                 }
                   8313:             }
                   8314:         }
1.171     raeburn  8315:     }
                   8316:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   8317:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   8318:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   8319:             $defaultshash{'loadbalancing'} = {};
                   8320:         }
                   8321:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   8322:                                                  \%defaultshash,$dom);
                   8323:  
                   8324:         if ($putresult eq 'ok') {
                   8325:             if (keys(%changes) > 0) {
                   8326:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   8327:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   8328:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150     raeburn  8329:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   8330:                     }
1.171     raeburn  8331:                 }
                   8332:                 if (ref($changes{'add'}) eq 'ARRAY') {
                   8333:                     foreach my $balancer (sort(@{$changes{'add'}})) {   
                   8334:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
                   8335:                     }
                   8336:                 }
                   8337:                 if (ref($changes{'curr'}) eq 'HASH') {
                   8338:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
                   8339:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   8340:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   8341:                                 my %offloadstr;
                   8342:                                 foreach my $sparetype (@sparestypes) {
                   8343:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8344:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8345:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   8346:                                         }
                   8347:                                     }
1.150     raeburn  8348:                                 }
1.171     raeburn  8349:                                 if (keys(%offloadstr) == 0) {
                   8350:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  8351:                                 } else {
1.171     raeburn  8352:                                     my $showoffload;
                   8353:                                     foreach my $sparetype (@sparestypes) {
                   8354:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   8355:                                         if (defined($offloadstr{$sparetype})) {
                   8356:                                             $showoffload .= $offloadstr{$sparetype};
                   8357:                                         } else {
                   8358:                                             $showoffload .= &mt('None');
                   8359:                                         }
                   8360:                                         $showoffload .= ('&nbsp;'x3);
                   8361:                                     }
                   8362:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  8363:                                 }
                   8364:                             }
                   8365:                         }
1.171     raeburn  8366:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   8367:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   8368:                                 foreach my $type (@{$alltypes}) {
                   8369:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   8370:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   8371:                                         my $balancetext;
                   8372:                                         if ($rule eq '') {
                   8373:                                             $balancetext =  $ruletitles{'default'};
                   8374:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
                   8375:                                             $balancetext =  $ruletitles{$rule};
                   8376:                                         } else {
                   8377:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   8378:                                         }
                   8379:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';     
1.150     raeburn  8380:                                     }
                   8381:                                 }
                   8382:                             }
                   8383:                         }
1.171     raeburn  8384:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150     raeburn  8385:                     }
1.171     raeburn  8386:                 }
                   8387:                 if ($resulttext ne '') {
                   8388:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  8389:                 } else {
                   8390:                     $resulttext = $nochgmsg;
                   8391:                 }
                   8392:             } else {
1.171     raeburn  8393:                 $resulttext = $nochgmsg;
1.150     raeburn  8394:             }
                   8395:         } else {
1.171     raeburn  8396:             $resulttext = '<span class="LC_error">'.
                   8397:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  8398:         }
                   8399:     } else {
1.171     raeburn  8400:         $resulttext = $nochgmsg;
1.150     raeburn  8401:     }
                   8402:     return $resulttext;
                   8403: }
                   8404: 
1.48      raeburn  8405: sub recurse_check {
                   8406:     my ($chkcats,$categories,$depth,$name) = @_;
                   8407:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   8408:         my $chg = 0;
                   8409:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   8410:             my $category = $chkcats->[$depth]{$name}[$j];
                   8411:             my $item;
                   8412:             if ($category eq '') {
                   8413:                 $chg ++;
                   8414:             } else {
                   8415:                 my $deeper = $depth + 1;
                   8416:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   8417:                 if ($chg) {
                   8418:                     $categories->{$item} -= $chg;
                   8419:                 }
                   8420:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   8421:                 $deeper --;
                   8422:             }
                   8423:         }
                   8424:     }
                   8425:     return;
                   8426: }
                   8427: 
                   8428: sub recurse_cat_deletes {
                   8429:     my ($item,$coursecategories,$deletions) = @_;
                   8430:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8431:     my $subdepth = $depth + 1;
                   8432:     if (ref($coursecategories) eq 'HASH') {
                   8433:         foreach my $subitem (keys(%{$coursecategories})) {
                   8434:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   8435:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   8436:                 delete($coursecategories->{$subitem});
                   8437:                 $deletions->{$subitem} = 1;
                   8438:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  8439:             }
1.48      raeburn  8440:         }
                   8441:     }
                   8442:     return;
                   8443: }
                   8444: 
1.125     raeburn  8445: sub get_active_dcs {
                   8446:     my ($dom) = @_;
                   8447:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
                   8448:     my %domcoords;
                   8449:     my $numdcs = 0;
                   8450:     my $now = time;
                   8451:     foreach my $server (keys(%dompersonnel)) {
                   8452:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   8453:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   8454:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
                   8455:             if (($end eq '') || ($end == 0) || ($end > $now)) {
                   8456:                 if ($start <= $now) {
                   8457:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
                   8458:                 }
                   8459:             }
                   8460:         }
                   8461:     }
                   8462:     return %domcoords;
                   8463: }
                   8464: 
                   8465: sub active_dc_picker {
                   8466:     my ($dom,$curr_dc) = @_;
                   8467:     my %domcoords = &get_active_dcs($dom); 
                   8468:     my @dcs = sort(keys(%domcoords));
                   8469:     my $numdcs = scalar(@dcs); 
                   8470:     my $datatable;
                   8471:     my $numinrow = 2;
                   8472:     if ($numdcs > 1) {
                   8473:         $datatable = '<table>';
                   8474:         for (my $i=0; $i<@dcs; $i++) {
                   8475:             my $rem = $i%($numinrow);
                   8476:             if ($rem == 0) {
                   8477:                 if ($i > 0) {
                   8478:                     $datatable .= '</tr>';
                   8479:                 }
                   8480:                 $datatable .= '<tr>';
                   8481:             }
                   8482:             my $check = ' ';
                   8483:             if ($curr_dc eq '') {
                   8484:                 if (!$i) { 
                   8485:                     $check = ' checked="checked" ';
                   8486:                 }
                   8487:             } elsif ($dcs[$i] eq $curr_dc) {
                   8488:                 $check = ' checked="checked" ';
                   8489:             }
                   8490:             if ($i == @dcs - 1) {
                   8491:                 my $colsleft = $numinrow - $rem;
                   8492:                 if ($colsleft > 1) {
                   8493:                     $datatable .= '<td colspan="'.$colsleft.'">';
                   8494:                 } else {
                   8495:                     $datatable .= '<td>';
                   8496:                 }
                   8497:             } else {
                   8498:                 $datatable .= '<td>';
                   8499:             }
                   8500:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
                   8501:             $datatable .= '<span class="LC_nobreak"><label>'.
                   8502:                           '<input type="radio" name="autocreate_xmldc"'.
                   8503:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
                   8504:                           &Apache::loncommon::plainname($dcname,$dcdom).
1.177     bisitz   8505:                           ' ('.$dcname.':'.$dcdom.')'.
1.125     raeburn  8506:                           '</label></span></td>';
                   8507:         }
                   8508:         $datatable .= '</tr></table>';
                   8509:     } elsif (@dcs) {
                   8510:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
                   8511:                       $dcs[0].'" />';
                   8512:     }
                   8513:     return ($numdcs,$datatable);
                   8514: }
                   8515: 
1.137     raeburn  8516: sub usersession_titles {
                   8517:     return &Apache::lonlocal::texthash(
                   8518:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   8519:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  8520:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  8521:                version => 'LON-CAPA version requirement',
1.138     raeburn  8522:                excludedomain => 'Allow all, but exclude specific domains',
                   8523:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  8524:                primary => 'Primary (checked first)',
1.154     raeburn  8525:                default => 'Default',
1.137     raeburn  8526:            );
                   8527: }
                   8528: 
1.152     raeburn  8529: sub id_for_thisdom {
                   8530:     my (%servers) = @_;
                   8531:     my %altids;
                   8532:     foreach my $server (keys(%servers)) {
                   8533:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   8534:         if ($serverhome ne $server) {
                   8535:             $altids{$serverhome} = $server;
                   8536:         }
                   8537:     }
                   8538:     return %altids;
                   8539: }
                   8540: 
1.150     raeburn  8541: sub count_servers {
                   8542:     my ($currbalancer,%servers) = @_;
                   8543:     my (@spares,$numspares);
                   8544:     foreach my $lonhost (sort(keys(%servers))) {
                   8545:         next if ($currbalancer eq $lonhost);
                   8546:         push(@spares,$lonhost);
                   8547:     }
                   8548:     if ($currbalancer) {
                   8549:         $numspares = scalar(@spares);
                   8550:     } else {
                   8551:         $numspares = scalar(@spares) - 1;
                   8552:     }
                   8553:     return ($numspares,@spares);
                   8554: }
                   8555: 
                   8556: sub lonbalance_targets_js {
1.171     raeburn  8557:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  8558:     my $select = &mt('Select');
                   8559:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   8560:     if (ref($servers) eq 'HASH') {
                   8561:         $alltargets = join("','",sort(keys(%{$servers})));
                   8562:         my @homedoms;
                   8563:         foreach my $server (sort(keys(%{$servers}))) {
                   8564:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   8565:                 push(@homedoms,'1');
                   8566:             } else {
                   8567:                 push(@homedoms,'0');
                   8568:             }
                   8569:         }
                   8570:         $allishome = join("','",@homedoms);
                   8571:     }
                   8572:     if (ref($types) eq 'ARRAY') {
                   8573:         if (@{$types} > 0) {
                   8574:             @alltypes = @{$types};
                   8575:         }
                   8576:     }
                   8577:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   8578:     $allinsttypes = join("','",@alltypes);
1.171     raeburn  8579:     my (%currbalancer,%currtargets,%currrules,%existing);
                   8580:     if (ref($settings) eq 'HASH') {
                   8581:         %existing = %{$settings};
                   8582:     }
                   8583:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   8584:                               \%currtargets,\%currrules);
                   8585:     my $balancers = join("','",sort(keys(%currbalancer))); 
1.150     raeburn  8586:     return <<"END";
                   8587: 
                   8588: <script type="text/javascript">
                   8589: // <![CDATA[
                   8590: 
1.171     raeburn  8591: currBalancers = new Array('$balancers');
                   8592: 
                   8593: function toggleTargets(balnum) {
                   8594:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   8595:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   8596:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   8597:     var prevbalancer = prevhostitem.value;
                   8598:     var baltotal = document.getElementById('loadbalancing_total').value;
                   8599:     prevhostitem.value = balancer;
                   8600:     if (prevbalancer != '') {
                   8601:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   8602:         if (prevIdx != -1) {
                   8603:             currBalancers.splice(prevIdx,1);
                   8604:         }
                   8605:     }
1.150     raeburn  8606:     if (balancer == '') {
1.171     raeburn  8607:         hideSpares(balnum);
1.150     raeburn  8608:     } else {
1.171     raeburn  8609:         var currIdx = currBalancers.indexOf(balancer);
                   8610:         if (currIdx == -1) {
                   8611:             currBalancers.push(balancer);
                   8612:         }
1.150     raeburn  8613:         var homedoms = new Array('$allishome');
1.171     raeburn  8614:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   8615:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  8616:     }
1.171     raeburn  8617:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  8618:     return;
                   8619: }
                   8620: 
1.171     raeburn  8621: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  8622:     var alltargets = new Array('$alltargets');
                   8623:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  8624:     var offloadtypes = new Array('primary','default');
                   8625: 
1.171     raeburn  8626:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   8627:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  8628:  
1.151     raeburn  8629:     for (var i=0; i<offloadtypes.length; i++) {
                   8630:         var count = 0;
                   8631:         for (var j=0; j<alltargets.length; j++) {
                   8632:             if (alltargets[j] != balancer) {
1.171     raeburn  8633:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   8634:                 item.value = alltargets[j];
                   8635:                 item.style.textAlign='left';
                   8636:                 item.style.textFace='normal';
                   8637:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   8638:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   8639:                     item.disabled = '';
                   8640:                 } else {
                   8641:                     item.disabled = 'disabled';
                   8642:                     item.checked = false;
                   8643:                 }
1.151     raeburn  8644:                 count ++;
                   8645:             }
1.150     raeburn  8646:         }
                   8647:     }
1.151     raeburn  8648:     for (var k=0; k<insttypes.length; k++) {
                   8649:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  8650:             if (ishomedom == 1) {
1.171     raeburn  8651:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   8652:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  8653:             } else {
1.171     raeburn  8654:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   8655:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  8656: 
                   8657:             }
                   8658:         } else {
1.171     raeburn  8659:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   8660:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  8661:         }
1.151     raeburn  8662:         if ((insttypes[k] != '_LC_external') && 
                   8663:             ((insttypes[k] != '_LC_internetdom') ||
                   8664:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  8665:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   8666:             item.options.length = 0;
                   8667:             item.options[0] = new Option("","",true,true);
                   8668:             var idx = 0;  
1.151     raeburn  8669:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  8670:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   8671:                     idx ++;
                   8672:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   8673:                     
1.150     raeburn  8674:                 }
                   8675:             }
                   8676:         }
                   8677:     }
                   8678:     return;
                   8679: }
                   8680: 
1.171     raeburn  8681: function hideSpares(balnum) {
1.150     raeburn  8682:     var alltargets = new Array('$alltargets');
                   8683:     var insttypes = new Array('$allinsttypes');
                   8684:     var offloadtypes = new Array('primary','default');
                   8685: 
1.171     raeburn  8686:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   8687:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  8688: 
                   8689:     var total = alltargets.length - 1;
                   8690:     for (var i=0; i<offloadtypes; i++) {
                   8691:         for (var j=0; j<total; j++) {
1.171     raeburn  8692:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   8693:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   8694:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  8695:         }
1.150     raeburn  8696:     }
                   8697:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  8698:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   8699:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  8700:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  8701:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   8702:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  8703:         }
                   8704:     }
                   8705:     return;
                   8706: }
                   8707: 
1.171     raeburn  8708: function checkOffloads(item,balnum,type) {
1.150     raeburn  8709:     var alltargets = new Array('$alltargets');
                   8710:     var offloadtypes = new Array('primary','default');
                   8711:     if (item.checked) {
                   8712:         var total = alltargets.length - 1;
                   8713:         var other;
                   8714:         if (type == offloadtypes[0]) {
1.151     raeburn  8715:             other = offloadtypes[1];
1.150     raeburn  8716:         } else {
1.151     raeburn  8717:             other = offloadtypes[0];
1.150     raeburn  8718:         }
                   8719:         for (var i=0; i<total; i++) {
1.171     raeburn  8720:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  8721:             if (server == item.value) {
1.171     raeburn  8722:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   8723:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  8724:                 }
                   8725:             }
                   8726:         }
                   8727:     }
                   8728:     return;
                   8729: }
                   8730: 
1.171     raeburn  8731: function singleServerToggle(balnum,type) {
                   8732:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  8733:     if (offloadtoSelIdx == 0) {
1.171     raeburn  8734:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   8735:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  8736: 
                   8737:     } else {
1.171     raeburn  8738:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   8739:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  8740:     }
                   8741:     return;
                   8742: }
                   8743: 
1.171     raeburn  8744: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  8745:     if (type == '_LC_external') {
1.171     raeburn  8746:         return;
1.150     raeburn  8747:     }
1.171     raeburn  8748:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  8749:     for (var i=0; i<typesRules.length; i++) {
                   8750:         if (formname.elements[typesRules[i]].checked) {
                   8751:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  8752:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   8753:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  8754:             } else {
1.171     raeburn  8755:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   8756:             }
                   8757:         }
                   8758:     }
                   8759:     return;
                   8760: }
                   8761: 
                   8762: function balancerDeleteChange(balnum) {
                   8763:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   8764:     var baltotal = document.getElementById('loadbalancing_total').value;
                   8765:     var addtarget;
                   8766:     var removetarget;
                   8767:     var action = 'delete';
                   8768:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   8769:         var lonhost = hostitem.value;
                   8770:         var currIdx = currBalancers.indexOf(lonhost);
                   8771:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   8772:             if (currIdx != -1) {
                   8773:                 currBalancers.splice(currIdx,1);
                   8774:             }
                   8775:             addtarget = lonhost;
                   8776:         } else {
                   8777:             if (currIdx == -1) {
                   8778:                 currBalancers.push(lonhost);
                   8779:             }
                   8780:             removetarget = lonhost;
                   8781:             action = 'undelete';
                   8782:         }
                   8783:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   8784:     }
                   8785:     return;
                   8786: }
                   8787: 
                   8788: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   8789:     if (baltotal > 1) {
                   8790:         var offloadtypes = new Array('primary','default');
                   8791:         var alltargets = new Array('$alltargets');
                   8792:         var insttypes = new Array('$allinsttypes');
                   8793:         for (var i=0; i<baltotal; i++) {
                   8794:             if (i != balnum) {
                   8795:                 for (var j=0; j<offloadtypes.length; j++) {
                   8796:                     var total = alltargets.length - 1;
                   8797:                     for (var k=0; k<total; k++) {
                   8798:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   8799:                         var server = serveritem.value;
                   8800:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   8801:                             if (server == addtarget) {
                   8802:                                 serveritem.disabled = '';
                   8803:                             }
                   8804:                         }
                   8805:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   8806:                             if (server == removetarget) {
                   8807:                                 serveritem.disabled = 'disabled';
                   8808:                                 serveritem.checked = false;
                   8809:                             }
                   8810:                         }
                   8811:                     }
                   8812:                 }
                   8813:                 for (var j=0; j<insttypes.length; j++) {
                   8814:                     if (insttypes[j] != '_LC_external') {
                   8815:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   8816:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   8817:                             var currSel = singleserver.selectedIndex;
                   8818:                             var currVal = singleserver.options[currSel].value;
                   8819:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   8820:                                 var numoptions = singleserver.options.length;
                   8821:                                 var needsnew = 1;
                   8822:                                 for (var k=0; k<numoptions; k++) {
                   8823:                                     if (singleserver.options[k] == addtarget) {
                   8824:                                         needsnew = 0;
                   8825:                                         break;
                   8826:                                     }
                   8827:                                 }
                   8828:                                 if (needsnew == 1) {
                   8829:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   8830:                                 }
                   8831:                             }
                   8832:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   8833:                                 singleserver.options.length = 0;
                   8834:                                 if ((currVal) && (currVal != removetarget)) {
                   8835:                                     singleserver.options[0] = new Option("","",false,false);
                   8836:                                 } else {
                   8837:                                     singleserver.options[0] = new Option("","",true,true);
                   8838:                                 }
                   8839:                                 var idx = 0;
                   8840:                                 for (var m=0; m<alltargets.length; m++) {
                   8841:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   8842:                                         idx ++;
                   8843:                                         if (currVal == alltargets[m]) {
                   8844:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   8845:                                         } else {
                   8846:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   8847:                                         }
                   8848:                                     }
                   8849:                                 }
                   8850:                             }
                   8851:                         }
                   8852:                     }
                   8853:                 }
1.150     raeburn  8854:             }
                   8855:         }
                   8856:     }
                   8857:     return;
                   8858: }
                   8859: 
1.152     raeburn  8860: // ]]>
                   8861: </script>
                   8862: 
                   8863: END
                   8864: }
                   8865: 
                   8866: sub new_spares_js {
                   8867:     my @sparestypes = ('primary','default');
                   8868:     my $types = join("','",@sparestypes);
                   8869:     my $select = &mt('Select');
                   8870:     return <<"END";
                   8871: 
                   8872: <script type="text/javascript">
                   8873: // <![CDATA[
                   8874: 
                   8875: function updateNewSpares(formname,lonhost) {
                   8876:     var types = new Array('$types');
                   8877:     var include = new Array();
                   8878:     var exclude = new Array();
                   8879:     for (var i=0; i<types.length; i++) {
                   8880:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   8881:         for (var j=0; j<spareboxes.length; j++) {
                   8882:             if (formname.elements[spareboxes[j]].checked) {
                   8883:                 exclude.push(formname.elements[spareboxes[j]].value);
                   8884:             } else {
                   8885:                 include.push(formname.elements[spareboxes[j]].value);
                   8886:             }
                   8887:         }
                   8888:     }
                   8889:     for (var i=0; i<types.length; i++) {
                   8890:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   8891:         var selIdx = newSpare.selectedIndex;
                   8892:         var currnew = newSpare.options[selIdx].value;
                   8893:         var okSpares = new Array();
                   8894:         for (var j=0; j<newSpare.options.length; j++) {
                   8895:             var possible = newSpare.options[j].value;
                   8896:             if (possible != '') {
                   8897:                 if (exclude.indexOf(possible) == -1) {
                   8898:                     okSpares.push(possible);
                   8899:                 } else {
                   8900:                     if (currnew == possible) {
                   8901:                         selIdx = 0;
                   8902:                     }
                   8903:                 }
                   8904:             }
                   8905:         }
                   8906:         for (var k=0; k<include.length; k++) {
                   8907:             if (okSpares.indexOf(include[k]) == -1) {
                   8908:                 okSpares.push(include[k]);
                   8909:             }
                   8910:         }
                   8911:         okSpares.sort();
                   8912:         newSpare.options.length = 0;
                   8913:         if (selIdx == 0) {
                   8914:             newSpare.options[0] = new Option("$select","",true,true);
                   8915:         } else {
                   8916:             newSpare.options[0] = new Option("$select","",false,false);
                   8917:         }
                   8918:         for (var m=0; m<okSpares.length; m++) {
                   8919:             var idx = m+1;
                   8920:             var selThis = 0;
                   8921:             if (selIdx != 0) {
                   8922:                 if (okSpares[m] == currnew) {
                   8923:                     selThis = 1;
                   8924:                 }
                   8925:             }
                   8926:             if (selThis == 1) {
                   8927:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   8928:             } else {
                   8929:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   8930:             }
                   8931:         }
                   8932:     }
                   8933:     return;
                   8934: }
                   8935: 
                   8936: function checkNewSpares(lonhost,type) {
                   8937:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   8938:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   8939:     if (chosen != '') { 
                   8940:         var othertype;
                   8941:         var othernewSpare;
                   8942:         if (type == 'primary') {
                   8943:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   8944:         }
                   8945:         if (type == 'default') {
                   8946:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   8947:         }
                   8948:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   8949:             othernewSpare.selectedIndex = 0;
                   8950:         }
                   8951:     }
                   8952:     return;
                   8953: }
                   8954: 
                   8955: // ]]>
                   8956: </script>
                   8957: 
                   8958: END
                   8959: 
                   8960: }
                   8961: 
                   8962: sub common_domprefs_js {
                   8963:     return <<"END";
                   8964: 
                   8965: <script type="text/javascript">
                   8966: // <![CDATA[
                   8967: 
1.150     raeburn  8968: function getIndicesByName(formname,item) {
1.152     raeburn  8969:     var group = new Array();
1.150     raeburn  8970:     for (var i=0;i<formname.elements.length;i++) {
                   8971:         if (formname.elements[i].name == item) {
1.152     raeburn  8972:             group.push(formname.elements[i].id);
1.150     raeburn  8973:         }
                   8974:     }
1.152     raeburn  8975:     return group;
1.150     raeburn  8976: }
                   8977: 
                   8978: // ]]>
                   8979: </script>
                   8980: 
                   8981: END
1.152     raeburn  8982: 
1.150     raeburn  8983: }
                   8984: 
1.165     raeburn  8985: sub recaptcha_js {
                   8986:     my %lt = &captcha_phrases();
                   8987:     return <<"END";
                   8988: 
                   8989: <script type="text/javascript">
                   8990: // <![CDATA[
                   8991: 
                   8992: function updateCaptcha(caller,context) {
                   8993:     var privitem;
                   8994:     var pubitem;
                   8995:     var privtext;
                   8996:     var pubtext;
                   8997:     if (document.getElementById(context+'_recaptchapub')) {
                   8998:         pubitem = document.getElementById(context+'_recaptchapub');
                   8999:     } else {
                   9000:         return;
                   9001:     }
                   9002:     if (document.getElementById(context+'_recaptchapriv')) {
                   9003:         privitem = document.getElementById(context+'_recaptchapriv');
                   9004:     } else {
                   9005:         return;
                   9006:     }
                   9007:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   9008:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   9009:     } else {
                   9010:         return;
                   9011:     }
                   9012:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   9013:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   9014:     } else {
                   9015:         return;
                   9016:     }
                   9017:     if (caller.checked) {
                   9018:         if (caller.value == 'recaptcha') {
                   9019:             pubitem.type = 'text';
                   9020:             privitem.type = 'text';
                   9021:             pubitem.size = '40';
                   9022:             privitem.size = '40';
                   9023:             pubtext.innerHTML = "$lt{'pub'}";
                   9024:             privtext.innerHTML = "$lt{'priv'}";
                   9025:         } else {
                   9026:             pubitem.type = 'hidden';
                   9027:             privitem.type = 'hidden';
                   9028:             pubtext.innerHTML = '';
                   9029:             privtext.innerHTML = '';
                   9030:         }
                   9031:     }
                   9032:     return;
                   9033: }
                   9034: 
                   9035: // ]]>
                   9036: </script>
                   9037: 
                   9038: END
                   9039: 
                   9040: }
                   9041: 
                   9042: sub captcha_phrases {
                   9043:     return &Apache::lonlocal::texthash (
                   9044:                  priv => 'Private key',
                   9045:                  pub  => 'Public key',
                   9046:                  original  => 'original (CAPTCHA)',
                   9047:                  recaptcha => 'successor (ReCAPTCHA)',
                   9048:                  notused   => 'unused',
                   9049:     );
                   9050: }
                   9051: 
1.3       raeburn  9052: 1;

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