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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.169   ! raeburn     4: # $Id: domainprefs.pm,v 1.168 2012/08/27 00:53:22 raeburn Exp $
1.2       albertel    5: #
1.1       raeburn     6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: #
                     28: ###############################################################
                     29: ##############################################################
                     30: 
1.101     raeburn    31: =pod
                     32: 
                     33: =head1 NAME
                     34: 
                     35: Apache::domainprefs.pm
                     36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Handles configuration of a LON-CAPA domain.  
                     40: 
                     41: This is part of the LearningOnline Network with CAPA project
                     42: described at http://www.lon-capa.org.
                     43: 
                     44: 
                     45: =head1 OVERVIEW
                     46: 
                     47: Each institution using LON-CAPA will typically have a single domain designated 
                     48: for use by individuals affliated with the institution.  Accordingly, each domain
                     49: may define a default set of logos and a color scheme which can be used to "brand"
                     50: the LON-CAPA instance. In addition, an institution will typically have a language
                     51: and timezone which are used for the majority of courses.
                     52: 
                     53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     54: host of other domain-wide settings which determine the types of functionality
                     55: available to users and courses in the domain.
                     56: 
                     57: There is also a mechanism to configure cataloging of courses in the domain, and
                     58: controls on the operation of automated processes which govern such things as
                     59: roster updates, user directory updates and processing of course requests.
                     60: 
                     61: The domain coordination manual which is built dynamically on install/update of 
                     62: LON-CAPA from the relevant help items provides more information about domain 
                     63: configuration.
                     64: 
                     65: Most of the domain settings are stored in the configuration.db GDBM file which is
                     66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     67: where $dom is the domain.  The configuration.db stores settings in a number of 
                     68: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     69: the domain as files (e.g., image files for logos etc., or plain text files for
                     70: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     71: session hosted on the primary library server in the domain, as these files are 
                     72: stored in author space belonging to a special $dom-domainconfig user.   
                     73: 
                     74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     75: the current settings, and provides an interface to make modifications.
                     76: 
                     77: =head1 SUBROUTINES
                     78: 
                     79: =over
                     80: 
                     81: =item print_quotas()
                     82: 
                     83: Inputs: 4 
                     84: 
                     85: $dom,$settings,$rowtotal,$action.
                     86: 
                     87: $dom is the domain, $settings is a reference to a hash of current settings for
                     88: the current context, $rowtotal is a reference to the scalar used to record the 
1.163     raeburn    89: number of rows displayed on the page, and $action is the context (quotas,  
                     90: requestcourses or requestauthor).
1.101     raeburn    91: 
                     92: The print_quotas routine was orginally created to display/store information
                     93: about default quota sizes for portfolio spaces for the different types of 
                     94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     95: but is now also used to manage availability of user tools: 
                     96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
                     97: used by course owners to request creation of a course.
                     98: 
                     99: Outputs: 1
                    100: 
                    101: $datatable  - HTML containing form elements which allow settings to be changed. 
                    102: 
                    103: In the case of course requests, radio buttons are displayed for each institutional
                    104: affiliate type (and also default, and _LC_adv) for each of the course types 
                    105: (official, unofficial and community).  In each case the radio buttons allow the 
                    106: selection of one of four values:
                    107: 
1.104     raeburn   108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   109: which have the following effects:
                    110: 
                    111: 0
                    112: 
                    113: =over
                    114: 
                    115: - course requests are not allowed for this course types/affiliation
                    116: 
                    117: =back
                    118: 
1.104     raeburn   119: approval 
1.101     raeburn   120: 
                    121: =over 
                    122: 
                    123: - course requests must be approved by a Doman Coordinator in the 
                    124: course's domain
                    125: 
                    126: =back
                    127: 
                    128: validate 
                    129: 
                    130: =over
                    131: 
                    132: - an institutional validation (e.g., check requestor is instructor
                    133: of record) needs to be passed before the course will be created.  The required
                    134: validation is in localenroll.pm on the primary library server for the course 
                    135: domain.
                    136: 
                    137: =back
                    138: 
                    139: autolimit 
                    140: 
                    141: =over
                    142:  
1.143     raeburn   143: - course requests will be processed automatically up to a limit of
1.101     raeburn   144: N requests for the course type for the particular requestor.
                    145: If N is undefined, there is no limit to the number of course requests
                    146: which a course owner may submit and have processed automatically. 
                    147: 
                    148: =back
                    149: 
                    150: =item modify_quotas() 
                    151: 
                    152: =back
                    153: 
                    154: =cut
                    155: 
1.1       raeburn   156: package Apache::domainprefs;
                    157: 
                    158: use strict;
                    159: use Apache::Constants qw(:common :http);
                    160: use Apache::lonnet;
                    161: use Apache::loncommon();
                    162: use Apache::lonhtmlcommon();
                    163: use Apache::lonlocal;
1.43      raeburn   164: use Apache::lonmsg();
1.91      raeburn   165: use Apache::lonconfigsettings;
1.69      raeburn   166: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   167: use LONCAPA::Enrollment;
1.81      raeburn   168: use LONCAPA::lonauthcgi();
1.9       raeburn   169: use File::Copy;
1.43      raeburn   170: use Locale::Language;
1.62      raeburn   171: use DateTime::TimeZone;
1.68      raeburn   172: use DateTime::Locale;
1.1       raeburn   173: 
1.155     raeburn   174: my $registered_cleanup;
                    175: my $modified_urls;
                    176: 
1.1       raeburn   177: sub handler {
                    178:     my $r=shift;
                    179:     if ($r->header_only) {
                    180:         &Apache::loncommon::content_type($r,'text/html');
                    181:         $r->send_http_header;
                    182:         return OK;
                    183:     }
                    184: 
1.91      raeburn   185:     my $context = 'domain';
1.1       raeburn   186:     my $dom = $env{'request.role.domain'};
1.5       albertel  187:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   188:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    189:         &Apache::loncommon::content_type($r,'text/html');
                    190:         $r->send_http_header;
                    191:     } else {
                    192:         $env{'user.error.msg'}=
                    193:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    194:         return HTTP_NOT_ACCEPTABLE;
                    195:     }
1.155     raeburn   196: 
                    197:     $registered_cleanup=0;
                    198:     @{$modified_urls}=();
                    199: 
1.1       raeburn   200:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    201:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   202:                                             ['phase','actions']);
1.30      raeburn   203:     my $phase = 'pickactions';
1.3       raeburn   204:     if ( exists($env{'form.phase'}) ) {
                    205:         $phase = $env{'form.phase'};
                    206:     }
1.150     raeburn   207:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   208:     my %domconfig =
1.6       raeburn   209:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   210:                 'quotas','autoenroll','autoupdate','autocreate',
                    211:                 'directorysrch','usercreation','usermodification',
                    212:                 'contacts','defaults','scantron','coursecategories',
                    213:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   214:                 'coursedefaults','usersessions','loadbalancing',
                    215:                 'requestauthor'],$dom);
1.43      raeburn   216:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   217:                        'autoupdate','autocreate','directorysrch','contacts',
1.48      raeburn   218:                        'usercreation','usermodification','scantron',
1.163     raeburn   219:                        'requestcourses','requestauthor','coursecategories',
                    220:                        'serverstatuses','helpsettings',
1.137     raeburn   221:                        'coursedefaults','usersessions');
1.150     raeburn   222:     if (keys(%servers) > 1) {
                    223:         push(@prefs_order,'loadbalancing');
                    224:     }
1.30      raeburn   225:     my %prefs = (
                    226:         'rolecolors' =>
                    227:                    { text => 'Default color schemes',
1.67      raeburn   228:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   229:                      header => [{col1 => 'Student Settings',
                    230:                                  col2 => '',},
                    231:                                 {col1 => 'Coordinator Settings',
                    232:                                  col2 => '',},
                    233:                                 {col1 => 'Author Settings',
                    234:                                  col2 => '',},
                    235:                                 {col1 => 'Administrator Settings',
                    236:                                  col2 => '',}],
                    237:                     },
1.110     raeburn   238:         'login' =>
1.30      raeburn   239:                     { text => 'Log-in page options',
1.67      raeburn   240:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   241:                       header => [{col1 => 'Log-in Page Items',
                    242:                                   col2 => '',},
                    243:                                  {col1 => 'Log-in Help',
                    244:                                   col2 => 'Value'}],
1.30      raeburn   245:                     },
1.43      raeburn   246:         'defaults' => 
1.141     raeburn   247:                     { text => 'Default authentication/language/timezone/portal',
1.67      raeburn   248:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   249:                       header => [{col1 => 'Setting',
                    250:                                   col2 => 'Value'}],
                    251:                     },
1.30      raeburn   252:         'quotas' => 
1.162     raeburn   253:                     { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67      raeburn   254:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   255:                       header => [{col1 => 'User affiliation',
1.72      raeburn   256:                                   col2 => 'Available tools',
                    257:                                   col3 => 'Portfolio quota',}],
1.30      raeburn   258:                     },
                    259:         'autoenroll' =>
                    260:                    { text => 'Auto-enrollment settings',
1.67      raeburn   261:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   262:                      header => [{col1 => 'Configuration setting',
                    263:                                  col2 => 'Value(s)'}],
                    264:                    },
                    265:         'autoupdate' => 
                    266:                    { text => 'Auto-update settings',
1.67      raeburn   267:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   268:                      header => [{col1 => 'Setting',
                    269:                                  col2 => 'Value',},
1.131     raeburn   270:                                 {col1 => 'Setting',
                    271:                                  col2 => 'Affiliation'},
1.43      raeburn   272:                                 {col1 => 'User population',
1.131     raeburn   273:                                  col2 => 'Updateable user data'}],
1.30      raeburn   274:                   },
1.125     raeburn   275:         'autocreate' => 
                    276:                   { text => 'Auto-course creation settings',
                    277:                      help => 'Domain_Configuration_Auto_Creation',
                    278:                      header => [{col1 => 'Configuration Setting',
                    279:                                  col2 => 'Value',}],
                    280:                   },
1.30      raeburn   281:         'directorysrch' => 
                    282:                   { text => 'Institutional directory searches',
1.67      raeburn   283:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   284:                     header => [{col1 => 'Setting',
                    285:                                 col2 => 'Value',}],
                    286:                   },
                    287:         'contacts' =>
                    288:                   { text => 'Contact Information',
1.67      raeburn   289:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   290:                     header => [{col1 => 'Setting',
                    291:                                 col2 => 'Value',}],
                    292:                   },
                    293: 
                    294:         'usercreation' => 
                    295:                   { text => 'User creation',
1.67      raeburn   296:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   297:                     header => [{col1 => 'Format rule type',
                    298:                                 col2 => 'Format rules in force'},
1.34      raeburn   299:                                {col1 => 'User account creation',
                    300:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   301:                                {col1 => 'Context',
1.43      raeburn   302:                                 col2 => 'Assignable authentication types'}],
1.30      raeburn   303:                   },
1.69      raeburn   304:         'usermodification' =>
1.33      raeburn   305:                   { text => 'User modification',
1.67      raeburn   306:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   307:                     header => [{col1 => 'Target user has role',
                    308:                                 col2 => 'User information updateable in author context'},
                    309:                                {col1 => 'Target user has role',
1.63      raeburn   310:                                 col2 => 'User information updateable in course context'},
                    311:                                {col1 => "Status of user",
                    312:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33      raeburn   313:                   },
1.69      raeburn   314:         'scantron' =>
1.95      www       315:                   { text => 'Bubblesheet format file',
1.67      raeburn   316:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   317:                     header => [ {col1 => 'Item',
                    318:                                  col2 => '',
                    319:                               }],
                    320:                   },
1.86      raeburn   321:         'requestcourses' => 
                    322:                  {text => 'Request creation of courses',
                    323:                   help => 'Domain_Configuration_Request_Courses',
                    324:                   header => [{col1 => 'User affiliation',
1.102     raeburn   325:                               col2 => 'Availability/Processing of requests',},
                    326:                              {col1 => 'Setting',
                    327:                               col2 => 'Value'}],
1.86      raeburn   328:                  },
1.163     raeburn   329:         'requestauthor' =>
                    330:                  {text => 'Request authoring space',
                    331:                   help => 'Domain_Configuration_Request_Author',
                    332:                   header => [{col1 => 'User affiliation',
                    333:                               col2 => 'Availability/Processing of requests',},
                    334:                              {col1 => 'Setting',
                    335:                               col2 => 'Value'}],
                    336:                  },
1.69      raeburn   337:         'coursecategories' =>
1.120     raeburn   338:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   339:                     help => 'Domain_Configuration_Cataloging_Courses',
1.69      raeburn   340:                     header => [{col1 => 'Category settings',
1.57      raeburn   341:                                 col2 => '',},
                    342:                                {col1 => 'Categories',
                    343:                                 col2 => '',
                    344:                                }],
1.69      raeburn   345:                   },
                    346:         'serverstatuses' =>
1.77      raeburn   347:                  {text   => 'Access to server status pages',
1.69      raeburn   348:                   help   => 'Domain_Configuration_Server_Status',
                    349:                   header => [{col1 => 'Status Page',
                    350:                               col2 => 'Other named users',
                    351:                               col3 => 'Specific IPs',
                    352:                             }],
                    353:                  },
1.118     jms       354:         'helpsettings' =>
                    355:                  {text   => 'Help page settings',
                    356:                   help   => 'Domain_Configuration_Help_Settings',
1.166     raeburn   357:                   header => [{col1 => 'Help Settings (logged-in users)',
                    358:                               col2 => 'Value'}],
1.118     jms       359:                  },
1.121     raeburn   360:         'coursedefaults' => 
                    361:                  {text => 'Course/Community defaults',
                    362:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   363:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    364:                               col2 => 'Value',},
                    365:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    366:                               col2 => 'Value',},],
1.121     raeburn   367:                  },
1.120     raeburn   368:         'privacy' => 
                    369:                  {text   => 'User Privacy',
                    370:                   help   => 'Domain_Configuration_User_Privacy',
                    371:                   header => [{col1 => 'Setting',
                    372:                               col2 => 'Value',}],
                    373:                  },
1.141     raeburn   374:         'usersessions' =>
1.145     raeburn   375:                  {text  => 'User session hosting/offloading',
1.137     raeburn   376:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   377:                   header => [{col1 => 'Domain server',
                    378:                               col2 => 'Servers to offload sessions to when busy'},
                    379:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   380:                               col2 => 'Rules'},
                    381:                              {col1 => "Hosting domain's own users elsewhere",
                    382:                               col2 => 'Rules'}],
                    383:                  },
1.150     raeburn   384:          'loadbalancing' =>
                    385:                  {text  => 'Dedicated Load Balancer',
                    386:                   help  => 'Domain_Configuration_Load_Balancing',
                    387:                   header => [{col1 => 'Server',
                    388:                               col2 => 'Default destinations',
                    389:                               col3 => 'User affliation',
                    390:                               col4 => 'Overrides'},
                    391:                             ],
                    392:                  },
1.3       raeburn   393:     );
1.110     raeburn   394:     if (keys(%servers) > 1) {
                    395:         $prefs{'login'}  = { text   => 'Log-in page options',
                    396:                              help   => 'Domain_Configuration_Login_Page',
                    397:                             header => [{col1 => 'Log-in Service',
                    398:                                         col2 => 'Server Setting',},
                    399:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   400:                                         col2 => ''},
                    401:                                        {col1 => 'Log-in Help',
                    402:                                         col2 => 'Value'}],
1.110     raeburn   403:                            };
                    404:     }
1.6       raeburn   405:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   406:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   407:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   408:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   409:       text=>"Settings to display/modify"});
1.9       raeburn   410:     my $confname = $dom.'-domainconfig';
1.3       raeburn   411:     if ($phase eq 'process') {
1.91      raeburn   412:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30      raeburn   413:     } elsif ($phase eq 'display') {
1.165     raeburn   414:         my $js = &recaptcha_js();
1.152     raeburn   415:         if (keys(%servers) > 1) {
                    416:             my ($othertitle,$usertypes,$types) =
                    417:                 &Apache::loncommon::sorted_inst_types($dom);
                    418:             $js = &lonbalance_targets_js($dom,$types,\%servers).
                    419:                   &new_spares_js().
1.153     raeburn   420:                   &common_domprefs_js().
                    421:                   &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   422:         }
1.150     raeburn   423:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   424:     } else {
1.21      raeburn   425:         if (keys(%domconfig) == 0) {
                    426:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   427:             my @ids=&Apache::lonnet::current_machine_ids();
                    428:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   429:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   430:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   431:                 my $custom_img_count = 0;
                    432:                 foreach my $img (@loginimages) {
                    433:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    434:                         $custom_img_count ++;
                    435:                     }
                    436:                 }
                    437:                 foreach my $role (@roles) {
                    438:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    439:                         $custom_img_count ++;
                    440:                     }
                    441:                 }
                    442:                 if ($custom_img_count > 0) {
1.94      raeburn   443:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   444:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   445:                     $r->print(
                    446:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    447:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    448:     &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 />'.
                    449:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    450:                     if ($switch_server) {
1.30      raeburn   451:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   452:                     }
1.91      raeburn   453:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   454:                     return OK;
                    455:                 }
                    456:             }
                    457:         }
1.91      raeburn   458:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   459:     }
                    460:     return OK;
                    461: }
                    462: 
                    463: sub process_changes {
1.92      raeburn   464:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
                    465:     my %domconfig;
                    466:     if (ref($values) eq 'HASH') {
                    467:         %domconfig = %{$values};
                    468:     }
1.3       raeburn   469:     my $output;
                    470:     if ($action eq 'login') {
1.9       raeburn   471:         $output = &modify_login($r,$dom,$confname,%domconfig);
1.6       raeburn   472:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   473:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
                    474:                                      %domconfig);
1.3       raeburn   475:     } elsif ($action eq 'quotas') {
1.86      raeburn   476:         $output = &modify_quotas($dom,$action,%domconfig);
1.3       raeburn   477:     } elsif ($action eq 'autoenroll') {
                    478:         $output = &modify_autoenroll($dom,%domconfig);
                    479:     } elsif ($action eq 'autoupdate') {
                    480:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   481:     } elsif ($action eq 'autocreate') {
                    482:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   483:     } elsif ($action eq 'directorysrch') {
                    484:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   485:     } elsif ($action eq 'usercreation') {
1.28      raeburn   486:         $output = &modify_usercreation($dom,%domconfig);
1.33      raeburn   487:     } elsif ($action eq 'usermodification') {
                    488:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   489:     } elsif ($action eq 'contacts') {
                    490:         $output = &modify_contacts($dom,%domconfig);
1.43      raeburn   491:     } elsif ($action eq 'defaults') {
                    492:         $output = &modify_defaults($dom,$r);
1.46      raeburn   493:     } elsif ($action eq 'scantron') {
1.48      raeburn   494:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
                    495:     } elsif ($action eq 'coursecategories') {
                    496:         $output = &modify_coursecategories($dom,%domconfig);
1.69      raeburn   497:     } elsif ($action eq 'serverstatuses') {
                    498:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   499:     } elsif ($action eq 'requestcourses') {
                    500:         $output = &modify_quotas($dom,$action,%domconfig);
1.163     raeburn   501:     } elsif ($action eq 'requestauthor') {
                    502:         $output = &modify_quotas($dom,$action,%domconfig);
1.118     jms       503:     } elsif ($action eq 'helpsettings') {
1.122     jms       504:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   505:     } elsif ($action eq 'coursedefaults') {
                    506:         $output = &modify_coursedefaults($dom,%domconfig);
1.137     raeburn   507:     } elsif ($action eq 'usersessions') {
                    508:         $output = &modify_usersessions($dom,%domconfig);
1.150     raeburn   509:     } elsif ($action eq 'loadbalancing') {
                    510:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   511:     }
                    512:     return $output;
                    513: }
                    514: 
                    515: sub print_config_box {
1.9       raeburn   516:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   517:     my $rowtotal = 0;
1.49      raeburn   518:     my $output;
                    519:     if ($action eq 'coursecategories') {
                    520:         $output = &coursecategories_javascript($settings);
1.91      raeburn   521:     }
1.49      raeburn   522:     $output .= 
1.30      raeburn   523:          '<table class="LC_nested_outer">
1.3       raeburn   524:           <tr>
1.66      raeburn   525:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    526:            &mt($item->{text}).'&nbsp;'.
                    527:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    528:           '</tr>';
1.30      raeburn   529:     $rowtotal ++;
1.110     raeburn   530:     my $numheaders = 1;
                    531:     if (ref($item->{'header'}) eq 'ARRAY') {
                    532:         $numheaders = scalar(@{$item->{'header'}});
                    533:     }
                    534:     if ($numheaders > 1) {
1.64      raeburn   535:         my $colspan = '';
1.145     raeburn   536:         my $rightcolspan = '';
1.168     raeburn   537:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || 
                    538:             (($action eq 'login') && ($numheaders < 3))) {
1.64      raeburn   539:             $colspan = ' colspan="2"';
                    540:         }
1.145     raeburn   541:         if ($action eq 'usersessions') {
                    542:             $rightcolspan = ' colspan="3"'; 
                    543:         }
1.30      raeburn   544:         $output .= '
1.3       raeburn   545:           <tr>
                    546:            <td>
                    547:             <table class="LC_nested">
                    548:              <tr class="LC_info_row">
1.59      bisitz    549:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   550:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   551:              </tr>';
1.69      raeburn   552:         $rowtotal ++;
1.6       raeburn   553:         if ($action eq 'autoupdate') {
1.30      raeburn   554:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28      raeburn   555:         } elsif ($action eq 'usercreation') {
1.33      raeburn   556:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
                    557:         } elsif ($action eq 'usermodification') {
                    558:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57      raeburn   559:         } elsif ($action eq 'coursecategories') {
                    560:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   561:         } elsif ($action eq 'login') {
1.168     raeburn   562:             if ($numheaders == 3) {
                    563:                 $colspan = ' colspan="2"';
                    564:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    565:             } else {
                    566:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    567:             }
1.102     raeburn   568:         } elsif ($action eq 'requestcourses') {
                    569:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163     raeburn   570:         } elsif ($action eq 'requestauthor') {
                    571:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137     raeburn   572:         } elsif ($action eq 'usersessions') {
                    573:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
1.122     jms       574:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   575:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139     raeburn   576:         } elsif ($action eq 'coursedefaults') {
                    577:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6       raeburn   578:         }
1.30      raeburn   579:         $output .= '
1.6       raeburn   580:            </table>
                    581:           </td>
                    582:          </tr>
                    583:          <tr>
                    584:            <td>
                    585:             <table class="LC_nested">
                    586:              <tr class="LC_info_row">
1.59      bisitz    587:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57      raeburn   588:         $output .= '
1.59      bisitz    589:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   590:              </tr>';
                    591:             $rowtotal ++;
1.6       raeburn   592:         if ($action eq 'autoupdate') {
1.131     raeburn   593:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
                    594:            </table>
                    595:           </td>
                    596:          </tr>
                    597:          <tr>
                    598:            <td>
                    599:             <table class="LC_nested">
                    600:              <tr class="LC_info_row">
                    601:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    602:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    603:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
                    604:             $rowtotal ++;
1.28      raeburn   605:         } elsif ($action eq 'usercreation') {
1.34      raeburn   606:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                    607:            </table>
                    608:           </td>
                    609:          </tr>
                    610:          <tr>
                    611:            <td>
                    612:             <table class="LC_nested">
                    613:              <tr class="LC_info_row">
1.59      bisitz    614:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    615:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
1.34      raeburn   616:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
                    617:             $rowtotal ++;
1.33      raeburn   618:         } elsif ($action eq 'usermodification') {
1.63      raeburn   619:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
                    620:            </table>
                    621:           </td>
                    622:          </tr>
                    623:          <tr>
                    624:            <td>
                    625:             <table class="LC_nested">
                    626:              <tr class="LC_info_row">
                    627:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    628:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    629:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
                    630:             $rowtotal ++;
1.57      raeburn   631:         } elsif ($action eq 'coursecategories') {
                    632:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   633:         } elsif ($action eq 'login') {
1.168     raeburn   634:             if ($numheaders == 3) {
                    635:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    636:            </table>
                    637:           </td>
                    638:          </tr>
                    639:          <tr>
                    640:            <td>
                    641:             <table class="LC_nested">
                    642:              <tr class="LC_info_row">
                    643:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    644:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    645:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    646:                 $rowtotal ++;
                    647:             } else {
                    648:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    649:             }
1.102     raeburn   650:         } elsif ($action eq 'requestcourses') {
1.163     raeburn   651:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    652:         } elsif ($action eq 'requestauthor') {
                    653:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137     raeburn   654:         } elsif ($action eq 'usersessions') {
1.145     raeburn   655:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
                    656:            </table>
                    657:           </td>
                    658:          </tr>
                    659:          <tr>
                    660:            <td>
                    661:             <table class="LC_nested">
                    662:              <tr class="LC_info_row">
                    663:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    664:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    665:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
                    666:             $rowtotal ++;
1.139     raeburn   667:         } elsif ($action eq 'coursedefaults') {
                    668:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122     jms       669:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   670:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   671:            </table>
                    672:           </td>
                    673:          </tr>
                    674:          <tr>
                    675:            <td>
                    676:             <table class="LC_nested">
                    677:              <tr class="LC_info_row">
1.69      raeburn   678:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    679:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    680:               <td class="LC_right_item" valign="top">'.
                    681:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   682:              </tr>'.
1.30      raeburn   683:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   684:            </table>
                    685:           </td>
                    686:          </tr>
                    687:          <tr>
                    688:            <td>
                    689:             <table class="LC_nested">
                    690:              <tr class="LC_info_row">
1.59      bisitz    691:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    692:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   693:              </tr>'.
1.30      raeburn   694:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    695:             $rowtotal += 2;
1.6       raeburn   696:         }
1.3       raeburn   697:     } else {
1.30      raeburn   698:         $output .= '
1.3       raeburn   699:           <tr>
                    700:            <td>
                    701:             <table class="LC_nested">
1.30      raeburn   702:              <tr class="LC_info_row">';
1.24      raeburn   703:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   704:             $output .= '  
1.59      bisitz    705:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   706:         } elsif ($action eq 'serverstatuses') {
                    707:             $output .= '
                    708:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    709:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    710: 
1.6       raeburn   711:         } else {
1.30      raeburn   712:             $output .= '
1.69      raeburn   713:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    714:         }
1.72      raeburn   715:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    716:             $output .= '<td class="LC_left_item" valign="top">'.
                    717:                        &mt($item->{'header'}->[0]->{'col2'});
                    718:             if ($action eq 'serverstatuses') {
                    719:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    720:             } 
1.69      raeburn   721:         } else {
                    722:             $output .= '<td class="LC_right_item" valign="top">'.
                    723:                        &mt($item->{'header'}->[0]->{'col2'});
                    724:         }
                    725:         $output .= '</td>';
                    726:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   727:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    728:                 $output .= '<td class="LC_left_item" valign="top">'.
                    729:                             &mt($item->{'header'}->[0]->{'col3'});
                    730:             } else {
                    731:                 $output .= '<td class="LC_right_item" valign="top">'.
                    732:                            &mt($item->{'header'}->[0]->{'col3'});
                    733:             }
1.69      raeburn   734:             if ($action eq 'serverstatuses') {
                    735:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    736:             }
                    737:             $output .= '</td>';
1.6       raeburn   738:         }
1.150     raeburn   739:         if ($item->{'header'}->[0]->{'col4'}) {
                    740:             $output .= '<td class="LC_right_item" valign="top">'.
                    741:                        &mt($item->{'header'}->[0]->{'col4'});
                    742:         }
1.69      raeburn   743:         $output .= '</tr>';
1.48      raeburn   744:         $rowtotal ++;
1.168     raeburn   745:         if ($action eq 'quotas') {
1.86      raeburn   746:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3       raeburn   747:         } elsif ($action eq 'autoenroll') {
1.30      raeburn   748:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125     raeburn   749:         } elsif ($action eq 'autocreate') {
                    750:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23      raeburn   751:         } elsif ($action eq 'directorysrch') {
1.30      raeburn   752:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28      raeburn   753:         } elsif ($action eq 'contacts') {
1.30      raeburn   754:             $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43      raeburn   755:         } elsif ($action eq 'defaults') {
                    756:             $output .= &print_defaults($dom,\$rowtotal);
1.46      raeburn   757:         } elsif ($action eq 'scantron') {
                    758:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69      raeburn   759:         } elsif ($action eq 'serverstatuses') {
                    760:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118     jms       761:         } elsif ($action eq 'helpsettings') {
1.168     raeburn   762:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150     raeburn   763:         } elsif ($action eq 'loadbalancing') {
                    764:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121     raeburn   765:         }
1.3       raeburn   766:     }
1.30      raeburn   767:     $output .= '
1.3       raeburn   768:    </table>
                    769:   </td>
                    770:  </tr>
1.30      raeburn   771: </table><br />';
                    772:     return ($output,$rowtotal);
1.1       raeburn   773: }
                    774: 
1.3       raeburn   775: sub print_login {
1.168     raeburn   776:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn   777:     my ($css_class,$datatable);
1.6       raeburn   778:     my %choices = &login_choices();
1.110     raeburn   779: 
1.168     raeburn   780:     if ($caller eq 'service') {
1.149     raeburn   781:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   782:         my $choice = $choices{'disallowlogin'};
                    783:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   784:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   785:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   786:                       '<th>'.$choices{'server'}.'</th>'.
                    787:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    788:                       '<th>'.$choices{'custompath'}.'</th>'.
                    789:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   790:         my %disallowed;
                    791:         if (ref($settings) eq 'HASH') {
                    792:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    793:                %disallowed = %{$settings->{'loginvia'}};
                    794:             }
                    795:         }
                    796:         foreach my $lonhost (sort(keys(%servers))) {
                    797:             my $direct = 'selected="selected"';
1.128     raeburn   798:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    799:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    800:                     $direct = '';
                    801:                 }
1.110     raeburn   802:             }
1.115     raeburn   803:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   804:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   805:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    806:                           '</option>';
                    807:             foreach my $hostid (keys(%servers)) {
1.115     raeburn   808:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   809:                 my $selected = '';
1.128     raeburn   810:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    811:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    812:                         $selected = 'selected="selected"';
                    813:                     }
1.110     raeburn   814:                 }
                    815:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    816:                               $servers{$hostid}.'</option>';
                    817:             }
1.128     raeburn   818:             $datatable .= '</select></td>'.
                    819:                           '<td><select name="'.$lonhost.'_serverpath">';
                    820:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    821:                 my $pathname = $path;
                    822:                 if ($path eq 'custom') {
                    823:                     $pathname = &mt('Custom Path').' ->';
                    824:                 }
                    825:                 my $selected = '';
                    826:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    827:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    828:                         $selected = 'selected="selected"';
                    829:                     }
                    830:                 } elsif ($path eq '') {
                    831:                     $selected = 'selected="selected"';
                    832:                 }
                    833:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    834:             }
                    835:             $datatable .= '</select></td>';
                    836:             my ($custom,$exempt);
                    837:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    838:                 $custom = $disallowed{$lonhost}{'custompath'};
                    839:                 $exempt = $disallowed{$lonhost}{'exempt'};
                    840:             }
                    841:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                    842:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                    843:                           '</tr>';
1.110     raeburn   844:         }
                    845:         $datatable .= '</table></td></tr>';
                    846:         return $datatable;
1.168     raeburn   847:     } elsif ($caller eq 'page') {
                    848:         my %defaultchecked = ( 
                    849:                                'coursecatalog' => 'on',
                    850:                                'adminmail'     => 'off',
                    851:                                'newuser'       => 'off',
                    852:                              );
                    853:         my @toggles = ('coursecatalog','adminmail','newuser');
                    854:         my (%checkedon,%checkedoff);
1.42      raeburn   855:         foreach my $item (@toggles) {
1.168     raeburn   856:             if ($defaultchecked{$item} eq 'on') { 
                    857:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn   858:                 $checkedoff{$item} = ' ';
1.168     raeburn   859:             } elsif ($defaultchecked{$item} eq 'off') {
                    860:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn   861:                 $checkedon{$item} = ' ';
                    862:             }
1.1       raeburn   863:         }
1.168     raeburn   864:         my @images = ('img','logo','domlogo','login');
                    865:         my @logintext = ('textcol','bgcol');
                    866:         my @bgs = ('pgbg','mainbg','sidebg');
                    867:         my @links = ('link','alink','vlink');
                    868:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                    869:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                    870:         my (%is_custom,%designs);
                    871:         my %defaults = (
                    872:                        font => $defaultdesign{'login.font'},
                    873:                        );
1.6       raeburn   874:         foreach my $item (@images) {
1.168     raeburn   875:             $defaults{$item} = $defaultdesign{'login.'.$item};
                    876:             $defaults{'showlogo'}{$item} = 1;
                    877:         }
                    878:         foreach my $item (@bgs) {
                    879:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   880:         }
1.41      raeburn   881:         foreach my $item (@logintext) {
1.168     raeburn   882:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn   883:         }
1.168     raeburn   884:         foreach my $item (@links) {
                    885:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   886:         }
1.168     raeburn   887:         if (ref($settings) eq 'HASH') {
                    888:             foreach my $item (@toggles) {
                    889:                 if ($settings->{$item} eq '1') {
                    890:                     $checkedon{$item} =  ' checked="checked" ';
                    891:                     $checkedoff{$item} = ' ';
                    892:                 } elsif ($settings->{$item} eq '0') {
                    893:                     $checkedoff{$item} =  ' checked="checked" ';
                    894:                     $checkedon{$item} = ' ';
                    895:                 }
                    896:             }
                    897:             foreach my $item (@images) {
                    898:                 if (defined($settings->{$item})) {
                    899:                     $designs{$item} = $settings->{$item};
                    900:                     $is_custom{$item} = 1;
                    901:                 }
                    902:                 if (defined($settings->{'showlogo'}{$item})) {
                    903:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                    904:                 }
                    905:             }
                    906:             foreach my $item (@logintext) {
                    907:                 if ($settings->{$item} ne '') {
                    908:                     $designs{'logintext'}{$item} = $settings->{$item};
                    909:                     $is_custom{$item} = 1;
                    910:                 }
                    911:             }
                    912:             if ($settings->{'font'} ne '') {
                    913:                 $designs{'font'} = $settings->{'font'};
                    914:                 $is_custom{'font'} = 1;
                    915:             }
                    916:             foreach my $item (@bgs) {
                    917:                 if ($settings->{$item} ne '') {
                    918:                     $designs{'bgs'}{$item} = $settings->{$item};
                    919:                     $is_custom{$item} = 1;
                    920:                 }
                    921:             }
                    922:             foreach my $item (@links) {
                    923:                 if ($settings->{$item} ne '') {
                    924:                     $designs{'links'}{$item} = $settings->{$item};
                    925:                     $is_custom{$item} = 1;
                    926:                 }
                    927:             }
                    928:         } else {
                    929:             if ($designhash{$dom.'.login.font'} ne '') {
                    930:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                    931:                 $is_custom{'font'} = 1;
                    932:             }
                    933:             foreach my $item (@images) {
                    934:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    935:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                    936:                     $is_custom{$item} = 1;
                    937:                 }
                    938:             }
                    939:             foreach my $item (@bgs) {
                    940:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    941:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                    942:                     $is_custom{$item} = 1;
                    943:                 }
1.6       raeburn   944:             }
1.168     raeburn   945:             foreach my $item (@links) {
                    946:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    947:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                    948:                     $is_custom{$item} = 1;
                    949:                 }
1.6       raeburn   950:             }
                    951:         }
1.168     raeburn   952:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                    953:                                                       logo => 'Institution Logo',
                    954:                                                       domlogo => 'Domain Logo',
                    955:                                                       login => 'Login box');
                    956:         my $itemcount = 1;
                    957:         foreach my $item (@toggles) {
                    958:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    959:             $datatable .=  
                    960:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                    961:                 '</td><td>'.
                    962:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                    963:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                    964:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                    965:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                    966:                 '</tr>';
                    967:             $itemcount ++;
1.6       raeburn   968:         }
1.168     raeburn   969:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                    970:         $datatable .= '</tr></table></td></tr>';
                    971:     } elsif ($caller eq 'help') {
                    972:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                    973:         my $switchserver = &check_switchserver($dom,$confname);
                    974:         my $itemcount = 1;
                    975:         $defaulturl = '/adm/loginproblems.html';
                    976:         $defaulttype = 'default';
                    977:         %lt = &Apache::lonlocal::texthash (
                    978:                      del     => 'Delete?',
                    979:                      rep     => 'Replace:',
                    980:                      upl     => 'Upload:',
                    981:                      default => 'Default',
                    982:                      custom  => 'Custom',
                    983:                                              );
                    984:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                    985:         my @currlangs;
                    986:         if (ref($settings) eq 'HASH') {
                    987:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                    988:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                    989:                     next if ($settings->{'helpurl'}{$key} eq '');
                    990:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                    991:                     $type{$key} = 'custom';
                    992:                     unless ($key eq 'nolang') {
                    993:                         push(@currlangs,$key);
                    994:                     }
                    995:                 }
                    996:             } elsif ($settings->{'helpurl'} ne '') {
                    997:                 $type{'nolang'} = 'custom';
                    998:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn   999:             }
                   1000:         }
1.168     raeburn  1001:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1002:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1003:             $datatable .= '<tr'.$css_class.'>';
                   1004:             if ($url{$lang} eq '') {
                   1005:                 $url{$lang} = $defaulturl;
                   1006:             }
                   1007:             if ($type{$lang} eq '') {
                   1008:                 $type{$lang} = $defaulttype;
                   1009:             }
                   1010:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1011:             if ($lang eq 'nolang') {
                   1012:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1013:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1014:             } else {
                   1015:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1016:                                   $langchoices{$lang},
                   1017:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1018:             }
                   1019:             $datatable .= '</span></td>'."\n".
                   1020:                           '<td class="LC_left_item">';
                   1021:             if ($type{$lang} eq 'custom') {
                   1022:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1023:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1024:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1025:             } else {
                   1026:                 $datatable .= $lt{'upl'};
                   1027:             }
                   1028:             $datatable .='<br />';
                   1029:             if ($switchserver) {
                   1030:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1031:             } else {
                   1032:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1033:             }
1.168     raeburn  1034:             $datatable .= '</td></tr>';
                   1035:             $itemcount ++;
1.6       raeburn  1036:         }
1.168     raeburn  1037:         my @addlangs;
                   1038:         foreach my $lang (sort(keys(%langchoices))) {
                   1039:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1040:             push(@addlangs,$lang);
                   1041:         }
                   1042:         if (@addlangs > 0) {
                   1043:             my %toadd;
                   1044:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1045:             $toadd{''} = &mt('Select');
                   1046:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1047:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1048:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1049:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1050:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1051:             if ($switchserver) {
                   1052:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1053:             } else {
                   1054:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1055:             }
1.168     raeburn  1056:             $datatable .= '</td></tr>';
1.169   ! raeburn  1057:             $itemcount ++;
1.6       raeburn  1058:         }
1.169   ! raeburn  1059:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1       raeburn  1060:     }
1.6       raeburn  1061:     return $datatable;
                   1062: }
                   1063: 
                   1064: sub login_choices {
                   1065:     my %choices =
                   1066:         &Apache::lonlocal::texthash (
1.116     bisitz   1067:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1068:             adminmail     => "Display Administrator's E-mail Address?",
                   1069:             disallowlogin => "Login page requests redirected",
                   1070:             hostid        => "Server",
1.128     raeburn  1071:             server        => "Redirect to:",
                   1072:             serverpath    => "Path",
                   1073:             custompath    => "Custom", 
                   1074:             exempt        => "Exempt IP(s)",
1.110     raeburn  1075:             directlogin   => "No redirect",
                   1076:             newuser       => "Link to create a user account",
                   1077:             img           => "Header",
                   1078:             logo          => "Main Logo",
                   1079:             domlogo       => "Domain Logo",
                   1080:             login         => "Log-in Header", 
                   1081:             textcol       => "Text color",
                   1082:             bgcol         => "Box color",
                   1083:             bgs           => "Background colors",
                   1084:             links         => "Link colors",
                   1085:             font          => "Font color",
                   1086:             pgbg          => "Header",
                   1087:             mainbg        => "Page",
                   1088:             sidebg        => "Login box",
                   1089:             link          => "Link",
                   1090:             alink         => "Active link",
                   1091:             vlink         => "Visited link",
1.6       raeburn  1092:         );
                   1093:     return %choices;
                   1094: }
                   1095: 
                   1096: sub print_rolecolors {
1.30      raeburn  1097:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1098:     my %choices = &color_font_choices();
                   1099:     my @bgs = ('pgbg','tabbg','sidebg');
                   1100:     my @links = ('link','alink','vlink');
                   1101:     my @images = ('img');
                   1102:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1103:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1104:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1105:     my (%is_custom,%designs);
                   1106:     my %defaults = (
                   1107:                    img => $defaultdesign{$role.'.img'},
                   1108:                    font => $defaultdesign{$role.'.font'},
1.97      tempelho 1109: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6       raeburn  1110:                    );
                   1111:     foreach my $item (@bgs) {
                   1112:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1113:     }
                   1114:     foreach my $item (@links) {
                   1115:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1116:     }
                   1117:     if (ref($settings) eq 'HASH') {
                   1118:         if (ref($settings->{$role}) eq 'HASH') {
                   1119:             if ($settings->{$role}->{'img'} ne '') {
                   1120:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1121:                 $is_custom{'img'} = 1;
                   1122:             }
                   1123:             if ($settings->{$role}->{'font'} ne '') {
                   1124:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1125:                 $is_custom{'font'} = 1;
                   1126:             }
1.97      tempelho 1127:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1128:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1129:                 $is_custom{'fontmenu'} = 1;
                   1130:             }
1.6       raeburn  1131:             foreach my $item (@bgs) {
                   1132:                 if ($settings->{$role}->{$item} ne '') {
                   1133:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1134:                     $is_custom{$item} = 1;
                   1135:                 }
                   1136:             }
                   1137:             foreach my $item (@links) {
                   1138:                 if ($settings->{$role}->{$item} ne '') {
                   1139:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1140:                     $is_custom{$item} = 1;
                   1141:                 }
                   1142:             }
                   1143:         }
                   1144:     } else {
                   1145:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1146:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1147:             $is_custom{'img'} = 1;
                   1148:         }
1.97      tempelho 1149:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1150:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1151:             $is_custom{'fontmenu'} = 1; 
                   1152:         }
1.6       raeburn  1153:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1154:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1155:             $is_custom{'font'} = 1;
                   1156:         }
                   1157:         foreach my $item (@bgs) {
                   1158:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1159:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1160:                 $is_custom{$item} = 1;
                   1161:             
                   1162:             }
                   1163:         }
                   1164:         foreach my $item (@links) {
                   1165:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1166:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1167:                 $is_custom{$item} = 1;
                   1168:             }
                   1169:         }
                   1170:     }
                   1171:     my $itemcount = 1;
1.30      raeburn  1172:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1173:     $datatable .= '</tr></table></td></tr>';
                   1174:     return $datatable;
                   1175: }
                   1176: 
                   1177: sub display_color_options {
1.9       raeburn  1178:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1179:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1180:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1181:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1182:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1183:         '<td>'.$choices->{'font'}.'</td>';
                   1184:     if (!$is_custom->{'font'}) {
1.30      raeburn  1185:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1186:     } else {
                   1187:         $datatable .= '<td>&nbsp;</td>';
                   1188:     }
                   1189:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8       raeburn  1190:     $datatable .= '<td><span class="LC_nobreak">'.
1.6       raeburn  1191:                   '<input type="text" size="10" name="'.$role.'_font"'.
1.8       raeburn  1192:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
1.30      raeburn  1193:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
                   1194:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
1.8       raeburn  1195:                   '</span></td></tr>';
1.107     raeburn  1196:     unless ($role eq 'login') { 
                   1197:         $datatable .= '<tr'.$css_class.'>'.
                   1198:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1199:         if (!$is_custom->{'fontmenu'}) {
                   1200:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1201:         } else {
                   1202:             $datatable .= '<td>&nbsp;</td>';
                   1203:         }
                   1204:         $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
                   1205:         $datatable .= '<td><span class="LC_nobreak">'.
                   1206:                       '<input type="text" size="10" name="'.$role.'_fontmenu"'.
                   1207:                       ' value="'.$designs->{'fontmenu'}.'" />&nbsp;'.$fontlink.
                   1208:                       '&nbsp;<span id="css_'.$role.'_fontmenu" style="background-color: '.
                   1209:                       $designs->{'fontmenu'}.';">&nbsp;&nbsp;&nbsp;</span>'.
                   1210:                       '</span></td></tr>';
1.97      tempelho 1211:     }
1.9       raeburn  1212:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1213:     foreach my $img (@{$images}) {
1.18      albertel 1214: 	$itemcount ++;
1.6       raeburn  1215:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1216:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1217:                       '<td>'.$choices->{$img};
1.41      raeburn  1218:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1219:         if ($role eq 'login') {
                   1220:             if ($img eq 'login') {
                   1221:                 $login_hdr_pick =
1.135     bisitz   1222:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1223:                 $logincolors =
                   1224:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
                   1225:                                             $designs);
                   1226:             } elsif ($img ne 'domlogo') {
                   1227:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1228:             }
                   1229:         }
                   1230:         $datatable .= '</td>';
1.6       raeburn  1231:         if ($designs->{$img} ne '') {
                   1232:             $imgfile = $designs->{$img};
1.18      albertel 1233: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1234:         } else {
                   1235:             $imgfile = $defaults->{$img};
                   1236:         }
                   1237:         if ($imgfile) {
1.9       raeburn  1238:             my ($showfile,$fullsize);
                   1239:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1240:                 my $urldir = $1;
                   1241:                 my $filename = $2;
                   1242:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1243:                 if (@info) {
                   1244:                     my $thumbfile = 'tn-'.$filename;
                   1245:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1246:                     if (@thumb) {
                   1247:                         $showfile = $urldir.'/'.$thumbfile;
                   1248:                     } else {
                   1249:                         $showfile = $imgfile;
                   1250:                     }
                   1251:                 } else {
                   1252:                     $showfile = '';
                   1253:                 }
                   1254:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1255:                 $showfile = $imgfile;
1.6       raeburn  1256:                 my $imgdir = $1;
                   1257:                 my $filename = $2;
1.159     raeburn  1258:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1259:                     $showfile = "/$imgdir/tn-".$filename;
                   1260:                 } else {
1.159     raeburn  1261:                     my $input = $londocroot.$imgfile;
                   1262:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1263:                     if (!-e $output) {
1.9       raeburn  1264:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1265:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1266:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1267:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1268:                                 my $size = $width.'x'.$height;
                   1269:                                 system("convert -sample $size $input $output");
1.159     raeburn  1270:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1271:                             }
                   1272:                         }
1.6       raeburn  1273:                     }
                   1274:                 }
1.16      raeburn  1275:             }
1.6       raeburn  1276:             if ($showfile) {
1.40      raeburn  1277:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1278:                     if ($showfile =~ m{^/res/}) {
                   1279:                         my $local_showfile =
                   1280:                             &Apache::lonnet::filelocation('',$showfile);
                   1281:                         &Apache::lonnet::repcopy($local_showfile);
                   1282:                     }
                   1283:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1284:                 }
                   1285:                 if ($imgfile) {
                   1286:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1287:                         if ($imgfile =~ m{^/res/}) {
                   1288:                             my $local_imgfile =
                   1289:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1290:                             &Apache::lonnet::repcopy($local_imgfile);
                   1291:                         }
                   1292:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1293:                     } else {
                   1294:                         $fullsize = $imgfile;
                   1295:                     }
                   1296:                 }
1.41      raeburn  1297:                 $datatable .= '<td>';
                   1298:                 if ($img eq 'login') {
1.135     bisitz   1299:                     $datatable .= $login_hdr_pick;
                   1300:                 } 
1.41      raeburn  1301:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1302:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1303:             } else {
                   1304:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1305:                               &mt('Upload:');
                   1306:             }
                   1307:         } else {
                   1308:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1309:                           &mt('Upload:');
                   1310:         }
1.9       raeburn  1311:         if ($switchserver) {
                   1312:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1313:         } else {
1.135     bisitz   1314:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1315:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1316:             }
1.9       raeburn  1317:         }
                   1318:         $datatable .= '</td></tr>';
1.6       raeburn  1319:     }
                   1320:     $itemcount ++;
                   1321:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1322:     $datatable .= '<tr'.$css_class.'>'.
                   1323:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1324:     my $bgs_def;
                   1325:     foreach my $item (@{$bgs}) {
                   1326:         if (!$is_custom->{$item}) {
1.70      raeburn  1327:             $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  1328:         }
                   1329:     }
                   1330:     if ($bgs_def) {
1.8       raeburn  1331:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1332:     } else {
                   1333:         $datatable .= '<td>&nbsp;</td>';
                   1334:     }
                   1335:     $datatable .= '<td class="LC_right_item">'.
                   1336:                   '<table border="0"><tr>';
                   1337:     foreach my $item (@{$bgs}) {
                   1338:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
                   1339:         $datatable .= '<td align="center">'.$link;
                   1340:         if ($designs->{'bgs'}{$item}) {
1.30      raeburn  1341:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn  1342:         }
                   1343:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41      raeburn  1344:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1345:     }
                   1346:     $datatable .= '</tr></table></td></tr>';
                   1347:     $itemcount ++;
                   1348:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1349:     $datatable .= '<tr'.$css_class.'>'.
                   1350:                   '<td>'.$choices->{'links'}.'</td>';
                   1351:     my $links_def;
                   1352:     foreach my $item (@{$links}) {
                   1353:         if (!$is_custom->{$item}) {
1.30      raeburn  1354:             $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  1355:         }
                   1356:     }
                   1357:     if ($links_def) {
1.8       raeburn  1358:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1359:     } else {
                   1360:         $datatable .= '<td>&nbsp;</td>';
                   1361:     }
                   1362:     $datatable .= '<td class="LC_right_item">'.
                   1363:                   '<table border="0"><tr>';
                   1364:     foreach my $item (@{$links}) {
1.30      raeburn  1365:         $datatable .= '<td align="center">'."\n".
                   1366:                       &color_pick($phase,$role,$item,$choices->{$item},
                   1367:                                   $designs->{'links'}{$item});
1.6       raeburn  1368:         if ($designs->{'links'}{$item}) {
1.30      raeburn  1369:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn  1370:         }
                   1371:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
                   1372:                       '" /></td>';
                   1373:     }
1.30      raeburn  1374:     $$rowtotal += $itemcount;
1.3       raeburn  1375:     return $datatable;
                   1376: }
                   1377: 
1.70      raeburn  1378: sub logo_display_options {
                   1379:     my ($img,$defaults,$designs) = @_;
                   1380:     my $checkedon;
                   1381:     if (ref($defaults) eq 'HASH') {
                   1382:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1383:             if ($defaults->{'showlogo'}{$img}) {
                   1384:                 $checkedon = 'checked="checked" ';     
                   1385:             }
                   1386:         } 
                   1387:     }
                   1388:     if (ref($designs) eq 'HASH') {
                   1389:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1390:             if (defined($designs->{'showlogo'}{$img})) {
                   1391:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1392:                     $checkedon = '';
                   1393:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1394:                     $checkedon = 'checked="checked" ';
                   1395:                 }
                   1396:             }
                   1397:         }
                   1398:     }
                   1399:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1400:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1401:            &mt('show').'</label>'."\n";
                   1402: }
                   1403: 
1.41      raeburn  1404: sub login_header_options  {
1.135     bisitz   1405:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1406:     my $output = '';
1.41      raeburn  1407:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1408:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1409:         if (!$is_custom->{'textcol'}) {
                   1410:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1411:                        '&nbsp;&nbsp;&nbsp;';
                   1412:         }
                   1413:         if (!$is_custom->{'bgcol'}) {
                   1414:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1415:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1416:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1417:         }
                   1418:         $output .= '<br />';
                   1419:     }
                   1420:     $output .='<br />';
                   1421:     return $output;
                   1422: }
                   1423: 
                   1424: sub login_text_colors {
                   1425:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
                   1426:     my $color_menu = '<table border="0"><tr>';
                   1427:     foreach my $item (@{$logintext}) {
                   1428:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
                   1429:         $color_menu .= '<td align="center">'.$link;
                   1430:         if ($designs->{'logintext'}{$item}) {
                   1431:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1432:         }
                   1433:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
                   1434:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
                   1435:                        '<td>&nbsp;</td>';
                   1436:     }
                   1437:     $color_menu .= '</tr></table><br />';
                   1438:     return $color_menu;
                   1439: }
                   1440: 
                   1441: sub image_changes {
                   1442:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1443:     my $output;
1.135     bisitz   1444:     if ($img eq 'login') {
                   1445:             # suppress image for Log-in header
                   1446:     } elsif (!$is_custom) {
1.70      raeburn  1447:         if ($img ne 'domlogo') {
1.41      raeburn  1448:             $output .= &mt('Default image:').'<br />';
                   1449:         } else {
                   1450:             $output .= &mt('Default in use:').'<br />';
                   1451:         }
                   1452:     }
1.135     bisitz   1453:     if ($img eq 'login') { # suppress image for Log-in header
                   1454:         $output .= '<td>'.$logincolors;
1.41      raeburn  1455:     } else {
1.135     bisitz   1456:         if ($img_import) {
                   1457:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1458:         }
                   1459:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1460:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1461:         if ($is_custom) {
                   1462:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1463:                        '<input type="checkbox" name="'.
                   1464:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1465:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1466:         } else {
                   1467:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
                   1468:         }
1.41      raeburn  1469:     }
                   1470:     return $output;
                   1471: }
                   1472: 
1.6       raeburn  1473: sub color_pick {
                   1474:     my ($phase,$role,$item,$desc,$curcol) = @_;
                   1475:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
                   1476:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
                   1477:                ');">'.$desc.'</a>';
                   1478:     return $link;
                   1479: }
                   1480: 
1.3       raeburn  1481: sub print_quotas {
1.86      raeburn  1482:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1483:     my $context;
                   1484:     if ($action eq 'quotas') {
                   1485:         $context = 'tools';
                   1486:     } else {
                   1487:         $context = $action;
                   1488:     }
1.101     raeburn  1489:     my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44      raeburn  1490:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1491:     my $typecount = 0;
1.101     raeburn  1492:     my ($css_class,%titles);
1.86      raeburn  1493:     if ($context eq 'requestcourses') {
1.98      raeburn  1494:         @usertools = ('official','unofficial','community');
1.106     raeburn  1495:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1496:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1497:         %titles = &courserequest_titles();
1.163     raeburn  1498:     } elsif ($context eq 'requestauthor') {
                   1499:         @usertools = ('author');
                   1500:         @options = ('norequest','approval','automatic');
                   1501:         %titles = &authorrequest_titles(); 
1.86      raeburn  1502:     } else {
1.162     raeburn  1503:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1504:         %titles = &tool_titles();
1.86      raeburn  1505:     }
1.26      raeburn  1506:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1507:         foreach my $type (@{$types}) {
1.72      raeburn  1508:             my $currdefquota;
1.163     raeburn  1509:             unless (($context eq 'requestcourses') ||
                   1510:                     ($context eq 'requestauthor')) {
1.86      raeburn  1511:                 if (ref($settings) eq 'HASH') {
                   1512:                     if (ref($settings->{defaultquota}) eq 'HASH') {
                   1513:                         $currdefquota = $settings->{defaultquota}->{$type}; 
                   1514:                     } else {
                   1515:                         $currdefquota = $settings->{$type};
                   1516:                     }
1.78      raeburn  1517:                 }
1.72      raeburn  1518:             }
1.3       raeburn  1519:             if (defined($usertypes->{$type})) {
                   1520:                 $typecount ++;
                   1521:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1522:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1523:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1524:                               '<td class="LC_left_item">';
1.101     raeburn  1525:                 if ($context eq 'requestcourses') {
                   1526:                     $datatable .= '<table><tr>';
                   1527:                 }
                   1528:                 my %cell;  
1.72      raeburn  1529:                 foreach my $item (@usertools) {
1.101     raeburn  1530:                     if ($context eq 'requestcourses') {
                   1531:                         my ($curroption,$currlimit);
                   1532:                         if (ref($settings) eq 'HASH') {
                   1533:                             if (ref($settings->{$item}) eq 'HASH') {
                   1534:                                 $curroption = $settings->{$item}->{$type};
                   1535:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1536:                                     $currlimit = $1; 
                   1537:                                 }
                   1538:                             }
                   1539:                         }
                   1540:                         if (!$curroption) {
                   1541:                             $curroption = 'norequest';
                   1542:                         }
                   1543:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1544:                         foreach my $option (@options) {
                   1545:                             my $val = $option;
                   1546:                             if ($option eq 'norequest') {
                   1547:                                 $val = 0;  
                   1548:                             }
                   1549:                             if ($option eq 'validate') {
                   1550:                                 my $canvalidate = 0;
                   1551:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1552:                                     if ($validations{$item}{$type}) {
                   1553:                                         $canvalidate = 1;
                   1554:                                     }
                   1555:                                 }
                   1556:                                 next if (!$canvalidate);
                   1557:                             }
                   1558:                             my $checked = '';
                   1559:                             if ($option eq $curroption) {
                   1560:                                 $checked = ' checked="checked"';
                   1561:                             } elsif ($option eq 'autolimit') {
                   1562:                                 if ($curroption =~ /^autolimit/) {
                   1563:                                     $checked = ' checked="checked"';
                   1564:                                 }                       
                   1565:                             } 
                   1566:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1567:                                   '<input type="radio" name="crsreq_'.$item.
                   1568:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1569:                                   $titles{$option}.'</label>';
1.101     raeburn  1570:                             if ($option eq 'autolimit') {
1.127     raeburn  1571:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1572:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1573:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1574:                             }
1.127     raeburn  1575:                             $cell{$item} .= '</span> ';
1.103     raeburn  1576:                             if ($option eq 'autolimit') {
1.127     raeburn  1577:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1578:                             }
1.101     raeburn  1579:                         }
1.163     raeburn  1580:                     } elsif ($context eq 'requestauthor') {
                   1581:                         my $curroption;
                   1582:                         if (ref($settings) eq 'HASH') {
                   1583:                             $curroption = $settings->{$type};
                   1584:                         }
                   1585:                         if (!$curroption) {
                   1586:                             $curroption = 'norequest';
                   1587:                         }
                   1588:                         foreach my $option (@options) {
                   1589:                             my $val = $option;
                   1590:                             if ($option eq 'norequest') {
                   1591:                                 $val = 0;
                   1592:                             }
                   1593:                             my $checked = '';
                   1594:                             if ($option eq $curroption) {
                   1595:                                 $checked = ' checked="checked"';
                   1596:                             }
                   1597:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1598:                                   '<input type="radio" name="authorreq_'.$type.
                   1599:                                   '" value="'.$val.'"'.$checked.' />'.
                   1600:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1601:                         }
1.101     raeburn  1602:                     } else {
                   1603:                         my $checked = 'checked="checked" ';
                   1604:                         if (ref($settings) eq 'HASH') {
                   1605:                             if (ref($settings->{$item}) eq 'HASH') {
                   1606:                                 if ($settings->{$item}->{$type} == 0) {
                   1607:                                     $checked = '';
                   1608:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1609:                                     $checked =  'checked="checked" ';
                   1610:                                 }
1.78      raeburn  1611:                             }
1.72      raeburn  1612:                         }
1.101     raeburn  1613:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1614:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1615:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1616:                                       '</label></span>&nbsp; ';
1.72      raeburn  1617:                     }
1.101     raeburn  1618:                 }
                   1619:                 if ($context eq 'requestcourses') {
                   1620:                     $datatable .= '</tr><tr>';
                   1621:                     foreach my $item (@usertools) {
1.106     raeburn  1622:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1623:                     }
                   1624:                     $datatable .= '</tr></table>';
1.72      raeburn  1625:                 }
1.86      raeburn  1626:                 $datatable .= '</td>';
1.163     raeburn  1627:                 unless (($context eq 'requestcourses') ||
                   1628:                         ($context eq 'requestauthor')) {
1.86      raeburn  1629:                     $datatable .= 
                   1630:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1631:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1632:                               '" value="'.$currdefquota.
1.86      raeburn  1633:                               '" size="5" /> Mb</span></td>';
                   1634:                 }
                   1635:                 $datatable .= '</tr>';
1.3       raeburn  1636:             }
                   1637:         }
                   1638:     }
1.163     raeburn  1639:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1640:         $defaultquota = '20';
                   1641:         if (ref($settings) eq 'HASH') {
                   1642:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1643:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1644:             } elsif (defined($settings->{'default'})) {
                   1645:                 $defaultquota = $settings->{'default'};
                   1646:             }
1.3       raeburn  1647:         }
                   1648:     }
                   1649:     $typecount ++;
                   1650:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1651:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1652:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1653:                   '<td class="LC_left_item">';
1.101     raeburn  1654:     if ($context eq 'requestcourses') {
                   1655:         $datatable .= '<table><tr>';
                   1656:     }
                   1657:     my %defcell;
1.72      raeburn  1658:     foreach my $item (@usertools) {
1.101     raeburn  1659:         if ($context eq 'requestcourses') {
                   1660:             my ($curroption,$currlimit);
                   1661:             if (ref($settings) eq 'HASH') {
                   1662:                 if (ref($settings->{$item}) eq 'HASH') {
                   1663:                     $curroption = $settings->{$item}->{'default'};
                   1664:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1665:                         $currlimit = $1;
                   1666:                     }
                   1667:                 }
                   1668:             }
                   1669:             if (!$curroption) {
                   1670:                 $curroption = 'norequest';
                   1671:             }
                   1672:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1673:             foreach my $option (@options) {
                   1674:                 my $val = $option;
                   1675:                 if ($option eq 'norequest') {
                   1676:                     $val = 0;
                   1677:                 }
                   1678:                 if ($option eq 'validate') {
                   1679:                     my $canvalidate = 0;
                   1680:                     if (ref($validations{$item}) eq 'HASH') {
                   1681:                         if ($validations{$item}{'default'}) {
                   1682:                             $canvalidate = 1;
                   1683:                         }
                   1684:                     }
                   1685:                     next if (!$canvalidate);
                   1686:                 }
                   1687:                 my $checked = '';
                   1688:                 if ($option eq $curroption) {
                   1689:                     $checked = ' checked="checked"';
                   1690:                 } elsif ($option eq 'autolimit') {
                   1691:                     if ($curroption =~ /^autolimit/) {
                   1692:                         $checked = ' checked="checked"';
                   1693:                     }
                   1694:                 }
                   1695:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1696:                                   '<input type="radio" name="crsreq_'.$item.
                   1697:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1698:                                   $titles{$option}.'</label>';
                   1699:                 if ($option eq 'autolimit') {
1.127     raeburn  1700:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1701:                                        $item.'_limit_default" size="1" '.
                   1702:                                        'value="'.$currlimit.'" />';
                   1703:                 }
1.127     raeburn  1704:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1705:                 if ($option eq 'autolimit') {
1.127     raeburn  1706:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1707:                 }
1.101     raeburn  1708:             }
1.163     raeburn  1709:         } elsif ($context eq 'requestauthor') {
                   1710:             my $curroption;
                   1711:             if (ref($settings) eq 'HASH') {
                   1712:                 if (ref($settings->{'requestauthor'}) eq 'HASH') {
                   1713:                     $curroption = $settings->{'requestauthor'};
                   1714:                 }
                   1715:             }
                   1716:             if (!$curroption) {
                   1717:                 $curroption = 'norequest';
                   1718:             }
                   1719:             foreach my $option (@options) {
                   1720:                 my $val = $option;
                   1721:                 if ($option eq 'norequest') {
                   1722:                     $val = 0;
                   1723:                 }
                   1724:                 my $checked = '';
                   1725:                 if ($option eq $curroption) {
                   1726:                     $checked = ' checked="checked"';
                   1727:                 }
                   1728:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1729:                               '<input type="radio" name="authorreq_default"'.
                   1730:                               ' value="'.$val.'"'.$checked.' />'.
                   1731:                               $titles{$option}.'</label></span>&nbsp; ';
                   1732:             }
1.101     raeburn  1733:         } else {
                   1734:             my $checked = 'checked="checked" ';
                   1735:             if (ref($settings) eq 'HASH') {
                   1736:                 if (ref($settings->{$item}) eq 'HASH') {
                   1737:                     if ($settings->{$item}->{'default'} == 0) {
                   1738:                         $checked = '';
                   1739:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1740:                         $checked = 'checked="checked" ';
                   1741:                     }
1.78      raeburn  1742:                 }
1.72      raeburn  1743:             }
1.101     raeburn  1744:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1745:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1746:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1747:                           '</label></span>&nbsp; ';
                   1748:         }
                   1749:     }
                   1750:     if ($context eq 'requestcourses') {
                   1751:         $datatable .= '</tr><tr>';
                   1752:         foreach my $item (@usertools) {
1.106     raeburn  1753:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1754:         }
1.101     raeburn  1755:         $datatable .= '</tr></table>';
1.72      raeburn  1756:     }
1.86      raeburn  1757:     $datatable .= '</td>';
1.163     raeburn  1758:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1759:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1760:                       '<input type="text" name="defaultquota" value="'.
                   1761:                       $defaultquota.'" size="5" /> Mb</span></td>';
                   1762:     }
                   1763:     $datatable .= '</tr>';
1.72      raeburn  1764:     $typecount ++;
                   1765:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1766:     $datatable .= '<tr'.$css_class.'>'.
1.104     raeburn  1767:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
                   1768:     if ($context eq 'requestcourses') {
1.109     raeburn  1769:         $datatable .= &mt('(overrides affiliation, if set)').
                   1770:                       '</td>'.
                   1771:                       '<td class="LC_left_item">'.
                   1772:                       '<table><tr>';
1.101     raeburn  1773:     } else {
1.109     raeburn  1774:         $datatable .= &mt('(overrides affiliation, if checked)').
                   1775:                       '</td>'.
                   1776:                       '<td class="LC_left_item" colspan="2">'.
                   1777:                       '<br />';
1.101     raeburn  1778:     }
                   1779:     my %advcell;
1.72      raeburn  1780:     foreach my $item (@usertools) {
1.101     raeburn  1781:         if ($context eq 'requestcourses') {
                   1782:             my ($curroption,$currlimit);
                   1783:             if (ref($settings) eq 'HASH') {
                   1784:                 if (ref($settings->{$item}) eq 'HASH') {
                   1785:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   1786:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1787:                         $currlimit = $1;
                   1788:                     }
                   1789:                 }
                   1790:             }
                   1791:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  1792:             my $checked = '';
                   1793:             if ($curroption eq '') {
                   1794:                 $checked = ' checked="checked"';
                   1795:             }
                   1796:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1797:                                '<input type="radio" name="crsreq_'.$item.
                   1798:                                '__LC_adv" value=""'.$checked.' />'.
                   1799:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  1800:             foreach my $option (@options) {
                   1801:                 my $val = $option;
                   1802:                 if ($option eq 'norequest') {
                   1803:                     $val = 0;
                   1804:                 }
                   1805:                 if ($option eq 'validate') {
                   1806:                     my $canvalidate = 0;
                   1807:                     if (ref($validations{$item}) eq 'HASH') {
                   1808:                         if ($validations{$item}{'_LC_adv'}) {
                   1809:                             $canvalidate = 1;
                   1810:                         }
                   1811:                     }
                   1812:                     next if (!$canvalidate);
                   1813:                 }
                   1814:                 my $checked = '';
1.104     raeburn  1815:                 if ($val eq $curroption) {
1.101     raeburn  1816:                     $checked = ' checked="checked"';
                   1817:                 } elsif ($option eq 'autolimit') {
                   1818:                     if ($curroption =~ /^autolimit/) {
                   1819:                         $checked = ' checked="checked"';
                   1820:                     }
                   1821:                 }
                   1822:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1823:                                   '<input type="radio" name="crsreq_'.$item.
                   1824:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1825:                                   $titles{$option}.'</label>';
                   1826:                 if ($option eq 'autolimit') {
1.127     raeburn  1827:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1828:                                        $item.'_limit__LC_adv" size="1" '.
                   1829:                                        'value="'.$currlimit.'" />';
                   1830:                 }
1.127     raeburn  1831:                 $advcell{$item} .= '</span> ';
1.104     raeburn  1832:                 if ($option eq 'autolimit') {
1.127     raeburn  1833:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1834:                 }
1.101     raeburn  1835:             }
1.163     raeburn  1836:         } elsif ($context eq 'requestauthor') {
                   1837:             my $curroption;
                   1838:             if (ref($settings) eq 'HASH') {
                   1839:                 $curroption = $settings->{'_LC_adv'};
                   1840:             }
                   1841:             my $checked = '';
                   1842:             if ($curroption eq '') {
                   1843:                 $checked = ' checked="checked"';
                   1844:             }
                   1845:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1846:                           '<input type="radio" name="authorreq__LC_adv"'.
                   1847:                           ' value=""'.$checked.' />'.
                   1848:                           &mt('No override set').'</label></span>&nbsp; ';
                   1849:             foreach my $option (@options) {
                   1850:                 my $val = $option;
                   1851:                 if ($option eq 'norequest') {
                   1852:                     $val = 0;
                   1853:                 }
                   1854:                 my $checked = '';
                   1855:                 if ($val eq $curroption) {
                   1856:                     $checked = ' checked="checked"';
                   1857:                 }
                   1858:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1859:                               '<input type="radio" name="crsreq_'.$item.
                   1860:                               '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1861:                               $titles{$option}.'</label></span>&nbsp; ';
                   1862:             }
1.101     raeburn  1863:         } else {
                   1864:             my $checked = 'checked="checked" ';
                   1865:             if (ref($settings) eq 'HASH') {
                   1866:                 if (ref($settings->{$item}) eq 'HASH') {
                   1867:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   1868:                         $checked = '';
                   1869:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   1870:                         $checked = 'checked="checked" ';
                   1871:                     }
1.79      raeburn  1872:                 }
1.72      raeburn  1873:             }
1.101     raeburn  1874:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1875:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1876:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   1877:                           '</label></span>&nbsp; ';
                   1878:         }
                   1879:     }
                   1880:     if ($context eq 'requestcourses') {
                   1881:         $datatable .= '</tr><tr>';
                   1882:         foreach my $item (@usertools) {
1.106     raeburn  1883:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  1884:         }
1.101     raeburn  1885:         $datatable .= '</tr></table>';
1.72      raeburn  1886:     }
1.98      raeburn  1887:     $datatable .= '</td></tr>';
1.30      raeburn  1888:     $$rowtotal += $typecount;
1.3       raeburn  1889:     return $datatable;
                   1890: }
                   1891: 
1.163     raeburn  1892: sub print_requestmail {
                   1893:     my ($dom,$action,$settings,$rowtotal) = @_;
1.104     raeburn  1894:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102     raeburn  1895:     $now = time;
                   1896:     $rows = 0;
                   1897:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
                   1898:     foreach my $server (keys(%dompersonnel)) {
                   1899:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   1900:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   1901:             if (!grep(/^$uname:$udom$/,@domcoord)) {
                   1902:                 push(@domcoord,$uname.':'.$udom);
                   1903:             }
                   1904:         }
                   1905:     }
                   1906:     if (ref($settings) eq 'HASH') {
                   1907:         if (ref($settings->{'notify'}) eq 'HASH') {
                   1908:             if ($settings->{'notify'}{'approval'} ne '') {
1.104     raeburn  1909:                @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102     raeburn  1910:             }
                   1911:         }
                   1912:     }
1.104     raeburn  1913:     if (@currapproval) {
                   1914:         foreach my $dc (@currapproval) {
1.102     raeburn  1915:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
                   1916:                 push(@domcoord,$dc);
                   1917:             }
                   1918:         }
                   1919:     }
                   1920:     @domcoord = sort(@domcoord);
                   1921:     my $numinrow = 4;
                   1922:     my $numdc = @domcoord;
                   1923:     my $css_class = 'class="LC_odd_row"';
1.163     raeburn  1924:     my $text;
                   1925:     if ($action eq 'requestcourses') {
                   1926:         $text = &mt('Receive notification of course requests requiring approval');
                   1927:     } else {
                   1928:         $text = &mt('Receive notification of authoring space requests requiring approval')
                   1929:     }
                   1930:     $datatable = '<tr '.$css_class.'>'.
                   1931:                  ' <td>'.$text.'</td>'.
1.102     raeburn  1932:                  ' <td class="LC_left_item">';
                   1933:     if (@domcoord > 0) {
                   1934:         $datatable .= '<table>';
                   1935:         for (my $i=0; $i<$numdc; $i++) {
                   1936:             my $rem = $i%($numinrow);
                   1937:             if ($rem == 0) {
                   1938:                 if ($i > 0) {
                   1939:                     $datatable .= '</tr>';
                   1940:                 }
                   1941:                 $datatable .= '<tr>';
                   1942:                 $rows ++;
                   1943:             }
                   1944:             my $check = ' ';
1.104     raeburn  1945:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102     raeburn  1946:                 $check = ' checked="checked" ';
                   1947:             }
                   1948:             my ($uname,$udom) = split(':',$domcoord[$i]);
                   1949:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
                   1950:             if ($i == $numdc-1) {
                   1951:                 my $colsleft = $numinrow-$rem;
                   1952:                 if ($colsleft > 1) {
                   1953:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   1954:                 } else {
                   1955:                     $datatable .= '<td class="LC_left_item">';
                   1956:                 }
                   1957:             } else {
                   1958:                 $datatable .= '<td class="LC_left_item">';
                   1959:             }
                   1960:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1961:                           '<input type="checkbox" name="reqapprovalnotify" '.
                   1962:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
                   1963:                           $fullname.'</label></span></td>';
                   1964:         }
                   1965:         $datatable .= '</tr></table>';
                   1966:     } else {
                   1967:         $datatable .= &mt('There are no active Domain Coordinators');
                   1968:         $rows ++;
                   1969:     }
                   1970:     $datatable .='</td></tr>';
                   1971:     $$rowtotal += $rows;
                   1972:     return $datatable;
                   1973: }
                   1974: 
1.3       raeburn  1975: sub print_autoenroll {
1.30      raeburn  1976:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  1977:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  1978:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  1979:     if (ref($settings) eq 'HASH') {
                   1980:         if (exists($settings->{'run'})) {
                   1981:             if ($settings->{'run'} eq '0') {
                   1982:                 $runoff = ' checked="checked" ';
                   1983:                 $runon = ' ';
                   1984:             } else {
                   1985:                 $runon = ' checked="checked" ';
                   1986:                 $runoff = ' ';
                   1987:             }
                   1988:         } else {
                   1989:             if ($autorun) {
                   1990:                 $runon = ' checked="checked" ';
                   1991:                 $runoff = ' ';
                   1992:             } else {
                   1993:                 $runoff = ' checked="checked" ';
                   1994:                 $runon = ' ';
                   1995:             }
                   1996:         }
1.129     raeburn  1997:         if (exists($settings->{'co-owners'})) {
                   1998:             if ($settings->{'co-owners'} eq '0') {
                   1999:                 $coownersoff = ' checked="checked" ';
                   2000:                 $coownerson = ' ';
                   2001:             } else {
                   2002:                 $coownerson = ' checked="checked" ';
                   2003:                 $coownersoff = ' ';
                   2004:             }
                   2005:         } else {
                   2006:             $coownersoff = ' checked="checked" ';
                   2007:             $coownerson = ' ';
                   2008:         }
1.3       raeburn  2009:         if (exists($settings->{'sender_domain'})) {
                   2010:             $defdom = $settings->{'sender_domain'};
                   2011:         }
1.14      raeburn  2012:     } else {
                   2013:         if ($autorun) {
                   2014:             $runon = ' checked="checked" ';
                   2015:             $runoff = ' ';
                   2016:         } else {
                   2017:             $runoff = ' checked="checked" ';
                   2018:             $runon = ' ';
                   2019:         }
1.3       raeburn  2020:     }
                   2021:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2022:     my $notif_sender;
                   2023:     if (ref($settings) eq 'HASH') {
                   2024:         $notif_sender = $settings->{'sender_uname'};
                   2025:     }
1.3       raeburn  2026:     my $datatable='<tr class="LC_odd_row">'.
                   2027:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2028:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2029:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2030:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2031:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2032:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2033:                   '</tr><tr>'.
                   2034:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2035:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2036:                   &mt('username').':&nbsp;'.
                   2037:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2038:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2039:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2040:                   '<tr class="LC_odd_row">'.
                   2041:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2042:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2043:                   '<input type="radio" name="autoassign_coowners"'.
                   2044:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2045:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2046:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2047:                   '</tr>';
                   2048:     $$rowtotal += 3;
1.3       raeburn  2049:     return $datatable;
                   2050: }
                   2051: 
                   2052: sub print_autoupdate {
1.30      raeburn  2053:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2054:     my $datatable;
                   2055:     if ($position eq 'top') {
                   2056:         my $updateon = ' ';
                   2057:         my $updateoff = ' checked="checked" ';
                   2058:         my $classlistson = ' ';
                   2059:         my $classlistsoff = ' checked="checked" ';
                   2060:         if (ref($settings) eq 'HASH') {
                   2061:             if ($settings->{'run'} eq '1') {
                   2062:                 $updateon = $updateoff;
                   2063:                 $updateoff = ' ';
                   2064:             }
                   2065:             if ($settings->{'classlists'} eq '1') {
                   2066:                 $classlistson = $classlistsoff;
                   2067:                 $classlistsoff = ' ';
                   2068:             }
                   2069:         }
                   2070:         my %title = (
                   2071:                    run => 'Auto-update active?',
                   2072:                    classlists => 'Update information in classlists?',
                   2073:                     );
                   2074:         $datatable = '<tr class="LC_odd_row">'. 
                   2075:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2076:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2077:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2078:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2079:                   '<label><input type="radio" name="autoupdate_run"'.
                   2080:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2081:                   '</tr><tr>'.
                   2082:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2083:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2084:                   '<label><input type="radio" name="classlists"'.
                   2085:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2086:                   '<label><input type="radio" name="classlists"'.
                   2087:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2088:                   '</tr>';
1.30      raeburn  2089:         $$rowtotal += 2;
1.131     raeburn  2090:     } elsif ($position eq 'middle') {
                   2091:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2092:         my $numinrow = 3;
                   2093:         my $locknamesettings;
                   2094:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2095:                                      $dom,$numinrow,$othertitle,
                   2096:                                     'lockablenames');
                   2097:         $$rowtotal ++;
1.3       raeburn  2098:     } else {
1.44      raeburn  2099:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2100:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2101:                       'permanentemail','id');
1.33      raeburn  2102:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2103:         my $numrows = 0;
1.26      raeburn  2104:         if (ref($types) eq 'ARRAY') {
                   2105:             if (@{$types} > 0) {
                   2106:                 $datatable = 
                   2107:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2108:                                          \@fields,$types,\$numrows);
1.30      raeburn  2109:                     $$rowtotal += @{$types}; 
1.26      raeburn  2110:             }
1.3       raeburn  2111:         }
                   2112:         $datatable .= 
                   2113:             &usertype_update_row($settings,{'default' => $othertitle},
                   2114:                                  \%fieldtitles,\@fields,['default'],
                   2115:                                  \$numrows);
1.30      raeburn  2116:         $$rowtotal ++;     
1.3       raeburn  2117:     }
                   2118:     return $datatable;
                   2119: }
                   2120: 
1.125     raeburn  2121: sub print_autocreate {
                   2122:     my ($dom,$settings,$rowtotal) = @_;
                   2123:     my (%createon,%createoff);
                   2124:     my $curr_dc;
                   2125:     my @types = ('xml','req');
                   2126:     if (ref($settings) eq 'HASH') {
                   2127:         foreach my $item (@types) {
                   2128:             $createoff{$item} = ' checked="checked" ';
                   2129:             $createon{$item} = ' ';
                   2130:             if (exists($settings->{$item})) {
                   2131:                 if ($settings->{$item}) {
                   2132:                     $createon{$item} = ' checked="checked" ';
                   2133:                     $createoff{$item} = ' ';
                   2134:                 }
                   2135:             }
                   2136:         }
                   2137:         $curr_dc = $settings->{'xmldc'};
                   2138:     } else {
                   2139:         foreach my $item (@types) {
                   2140:             $createoff{$item} = ' checked="checked" ';
                   2141:             $createon{$item} = ' ';
                   2142:         }
                   2143:     }
                   2144:     $$rowtotal += 2;
                   2145:     my $datatable='<tr class="LC_odd_row">'.
                   2146:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2147:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2148:                   '<input type="radio" name="autocreate_xml"'.
                   2149:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2150:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2151:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2152:                   '</td></tr><tr>'.
                   2153:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2154:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2155:                   '<input type="radio" name="autocreate_req"'.
                   2156:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2157:                   '<label><input type="radio" name="autocreate_req"'.
                   2158:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125     raeburn  2159:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
                   2160:     if ($numdc > 1) {
1.143     raeburn  2161:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                   2162:                       &mt('Course creation processed as: (choose Dom. Coord.)').
                   2163:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125     raeburn  2164:         $$rowtotal ++ ;
                   2165:     } else {
1.143     raeburn  2166:         $datatable .= $dctable.'</td></tr>';
1.125     raeburn  2167:     }
                   2168:     return $datatable;
                   2169: }
                   2170: 
1.23      raeburn  2171: sub print_directorysrch {
1.30      raeburn  2172:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  2173:     my $srchon = ' ';
                   2174:     my $srchoff = ' checked="checked" ';
1.25      raeburn  2175:     my ($exacton,$containson,$beginson);
1.24      raeburn  2176:     my $localon = ' ';
                   2177:     my $localoff = ' checked="checked" ';
1.23      raeburn  2178:     if (ref($settings) eq 'HASH') {
                   2179:         if ($settings->{'available'} eq '1') {
                   2180:             $srchon = $srchoff;
                   2181:             $srchoff = ' ';
                   2182:         }
1.24      raeburn  2183:         if ($settings->{'localonly'} eq '1') {
                   2184:             $localon = $localoff;
                   2185:             $localoff = ' ';
                   2186:         }
1.25      raeburn  2187:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2188:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   2189:                 if ($type eq 'exact') {
                   2190:                     $exacton = ' checked="checked" ';
                   2191:                 } elsif ($type eq 'contains') {
                   2192:                     $containson = ' checked="checked" ';
                   2193:                 } elsif ($type eq 'begins') {
                   2194:                     $beginson = ' checked="checked" ';
                   2195:                 }
                   2196:             }
                   2197:         } else {
                   2198:             if ($settings->{'searchtypes'} eq 'exact') {
                   2199:                 $exacton = ' checked="checked" ';
                   2200:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2201:                 $containson = ' checked="checked" ';
                   2202:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   2203:                 $exacton = ' checked="checked" ';
                   2204:                 $containson = ' checked="checked" ';
                   2205:             }
1.23      raeburn  2206:         }
                   2207:     }
                   2208:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  2209:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2210: 
                   2211:     my $numinrow = 4;
1.26      raeburn  2212:     my $cansrchrow = 0;
1.23      raeburn  2213:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2214:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2215:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2216:                   '<input type="radio" name="dirsrch_available"'.
                   2217:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2218:                   '<label><input type="radio" name="dirsrch_available"'.
                   2219:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2220:                   '</tr><tr>'.
1.30      raeburn  2221:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2222:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2223:                   '<input type="radio" name="dirsrch_localonly"'.
                   2224:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2225:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2226:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2227:                   '</tr>';
1.30      raeburn  2228:     $$rowtotal += 2;
1.26      raeburn  2229:     if (ref($usertypes) eq 'HASH') {
                   2230:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2231:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2232:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2233:             $cansrchrow = 1;
                   2234:         }
                   2235:     }
                   2236:     if ($cansrchrow) {
1.30      raeburn  2237:         $$rowtotal ++;
1.26      raeburn  2238:         $datatable .= '<tr>';
                   2239:     } else {
                   2240:         $datatable .= '<tr class="LC_odd_row">';
                   2241:     }
1.30      raeburn  2242:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2243:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2244:     foreach my $title (@{$titleorder}) {
                   2245:         if (defined($searchtitles->{$title})) {
                   2246:             my $check = ' ';
1.93      raeburn  2247:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2248:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2249:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2250:                         $check = ' checked="checked" ';
                   2251:                     }
1.25      raeburn  2252:                 }
                   2253:             }
                   2254:             $datatable .= '<td class="LC_left_item">'.
                   2255:                           '<span class="LC_nobreak"><label>'.
                   2256:                           '<input type="checkbox" name="searchby" '.
                   2257:                           'value="'.$title.'"'.$check.'/>'.
                   2258:                           $searchtitles->{$title}.'</label></span></td>';
                   2259:         }
                   2260:     }
1.26      raeburn  2261:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2262:     $$rowtotal ++;
1.26      raeburn  2263:     if ($cansrchrow) {
                   2264:         $datatable .= '<tr class="LC_odd_row">';
                   2265:     } else {
                   2266:         $datatable .= '<tr>';
                   2267:     }
1.30      raeburn  2268:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2269:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2270:                   '<span class="LC_nobreak"><label>'.
                   2271:                   '<input type="checkbox" name="searchtypes" '.
                   2272:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2273:                   '</label>&nbsp;'.
                   2274:                   '<label><input type="checkbox" name="searchtypes" '.
                   2275:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2276:                   '</label>&nbsp;'.
                   2277:                   '<label><input type="checkbox" name="searchtypes" '.
                   2278:                   $containson.' value="contains" />'.&mt('Contains').
                   2279:                   '</label></span></td></tr>';
1.30      raeburn  2280:     $$rowtotal ++;
1.25      raeburn  2281:     return $datatable;
                   2282: }
                   2283: 
1.28      raeburn  2284: sub print_contacts {
1.30      raeburn  2285:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2286:     my $datatable;
                   2287:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2288:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2289:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
                   2290:                     'requestsmail');
1.28      raeburn  2291:     foreach my $type (@mailings) {
                   2292:         $otheremails{$type} = '';
                   2293:     }
1.134     raeburn  2294:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2295:     if (ref($settings) eq 'HASH') {
                   2296:         foreach my $item (@contacts) {
                   2297:             if (exists($settings->{$item})) {
                   2298:                 $to{$item} = $settings->{$item};
                   2299:             }
                   2300:         }
                   2301:         foreach my $type (@mailings) {
                   2302:             if (exists($settings->{$type})) {
                   2303:                 if (ref($settings->{$type}) eq 'HASH') {
                   2304:                     foreach my $item (@contacts) {
                   2305:                         if ($settings->{$type}{$item}) {
                   2306:                             $checked{$type}{$item} = ' checked="checked" ';
                   2307:                         }
                   2308:                     }
                   2309:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2310:                     if ($type eq 'helpdeskmail') {
                   2311:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2312:                     }
1.28      raeburn  2313:                 }
1.89      raeburn  2314:             } elsif ($type eq 'lonstatusmail') {
                   2315:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2316:             }
                   2317:         }
                   2318:     } else {
                   2319:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2320:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2321:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2322:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2323:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2324:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2325:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2326:     }
                   2327:     my ($titles,$short_titles) = &contact_titles();
                   2328:     my $rownum = 0;
                   2329:     my $css_class;
                   2330:     foreach my $item (@contacts) {
1.69      raeburn  2331:         $rownum ++;
                   2332:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2333:         $datatable .= '<tr'.$css_class.'>'. 
                   2334:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2335:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2336:                   '<input type="text" name="'.$item.'" value="'.
                   2337:                   $to{$item}.'" /></td></tr>';
                   2338:     }
                   2339:     foreach my $type (@mailings) {
1.69      raeburn  2340:         $rownum ++;
                   2341:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2342:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2343:                       '<td><span class="LC_nobreak">'.
                   2344:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2345:                       '<td class="LC_left_item">'.
                   2346:                       '<span class="LC_nobreak">';
                   2347:         foreach my $item (@contacts) {
                   2348:             $datatable .= '<label>'.
                   2349:                           '<input type="checkbox" name="'.$type.'"'.
                   2350:                           $checked{$type}{$item}.
                   2351:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2352:                           '</label>&nbsp;';
                   2353:         }
                   2354:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2355:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2356:                       'value="'.$otheremails{$type}.'"  />';
                   2357:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2358:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2359:                           '<input type="text" name="'.$type.'_bcc" '.
                   2360:                           'value="'.$bccemails{$type}.'"  />';
                   2361:         }
                   2362:         $datatable .= '</td></tr>'."\n";
1.28      raeburn  2363:     }
1.30      raeburn  2364:     $$rowtotal += $rownum;
1.28      raeburn  2365:     return $datatable;
                   2366: }
                   2367: 
1.118     jms      2368: sub print_helpsettings {
1.168     raeburn  2369:     my ($dom,$confname,$settings,$rowtotal) = @_;
                   2370:     my ($datatable,$itemcount);
1.166     raeburn  2371:     $itemcount = 1;
1.168     raeburn  2372:     my (%choices,%defaultchecked,@toggles);
                   2373:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   2374:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   2375:                                  &mt('LON-CAPA bug tracker'),600,500));
                   2376:     %defaultchecked = ('submitbugs' => 'on');
                   2377:     @toggles = ('submitbugs',);
1.166     raeburn  2378: 
1.168     raeburn  2379:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2380:                                                  \%choices,$itemcount);
1.166     raeburn  2381:     return $datatable;
1.121     raeburn  2382: }
                   2383: 
                   2384: sub radiobutton_prefs {
                   2385:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
                   2386:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2387:                    (ref($choices) eq 'HASH'));
                   2388: 
1.166     raeburn  2389:     my (%checkedon,%checkedoff,$datatable,$css_class,$cell_colspan);
1.121     raeburn  2390: 
                   2391:     foreach my $item (@{$toggles}) {
                   2392:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2393:             $checkedon{$item} = ' checked="checked" ';
                   2394:             $checkedoff{$item} = ' ';
1.121     raeburn  2395:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2396:             $checkedoff{$item} = ' checked="checked" ';
                   2397:             $checkedon{$item} = ' ';
                   2398:         }
                   2399:     }
                   2400:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2401:         foreach my $item (@{$toggles}) {
1.118     jms      2402:             if ($settings->{$item} eq '1') {
                   2403:                 $checkedon{$item} =  ' checked="checked" ';
                   2404:                 $checkedoff{$item} = ' ';
                   2405:             } elsif ($settings->{$item} eq '0') {
                   2406:                 $checkedoff{$item} =  ' checked="checked" ';
                   2407:                 $checkedon{$item} = ' ';
                   2408:             }
                   2409:         }
1.121     raeburn  2410:     }
                   2411:     foreach my $item (@{$toggles}) {
1.118     jms      2412:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2413:         $datatable .=
                   2414:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118     jms      2415:             '</span></td>'.
                   2416:             '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2417:             '<label><input type="radio" name="'.
                   2418:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   2419:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   2420:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2421:             '</span></td>'.
                   2422:             '</tr>';
                   2423:         $itemcount ++;
1.121     raeburn  2424:     }
                   2425:     return ($datatable,$itemcount);
                   2426: }
                   2427: 
                   2428: sub print_coursedefaults {
1.139     raeburn  2429:     my ($position,$dom,$settings,$rowtotal) = @_;
1.121     raeburn  2430:     my ($css_class,$datatable);
                   2431:     my $itemcount = 1;
1.139     raeburn  2432:     if ($position eq 'top') {
                   2433:         my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2434:         %choices =
                   2435:             &Apache::lonlocal::texthash (
                   2436:                 canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
                   2437:         );
                   2438:         %defaultchecked = ('canuse_pdfforms' => 'off');
                   2439:         @toggles = ('canuse_pdfforms',);
                   2440:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121     raeburn  2441:                                                  \%choices,$itemcount);
1.139     raeburn  2442:         $$rowtotal += $itemcount;
                   2443:     } else {
                   2444:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2445:         my %choices =
                   2446:             &Apache::lonlocal::texthash (
                   2447:                 anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   2448:         );
                   2449:         my $currdefresponder;
                   2450:         if (ref($settings) eq 'HASH') {
                   2451:             $currdefresponder = $settings->{'anonsurvey_threshold'};
                   2452:         }
                   2453:         if (!$currdefresponder) {
                   2454:             $currdefresponder = 10;
                   2455:         } elsif ($currdefresponder < 1) {
                   2456:             $currdefresponder = 1;
                   2457:         }
                   2458:         $datatable .=
                   2459:                '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
                   2460:                 '</span></td>'.
                   2461:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2462:                 '<input type="text" name="anonsurvey_threshold"'.
                   2463:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
                   2464:                 '</td></tr>';
                   2465:     }
1.121     raeburn  2466:     return $datatable;
1.118     jms      2467: }
                   2468: 
1.137     raeburn  2469: sub print_usersessions {
                   2470:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2471:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  2472:     my (%by_ip,%by_location,@intdoms);
                   2473:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  2474: 
                   2475:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  2476:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  2477:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  2478:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  2479:     my $itemcount = 1;
                   2480:     if ($position eq 'top') {
1.152     raeburn  2481:         if (keys(%serverhomes) > 1) {
1.145     raeburn  2482:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.152     raeburn  2483:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145     raeburn  2484:         } else {
1.140     raeburn  2485:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2486:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  2487:         }
1.137     raeburn  2488:     } else {
1.145     raeburn  2489:         if (keys(%by_location) == 0) {
                   2490:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2491:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  2492:         } else {
                   2493:             my %lt = &usersession_titles();
                   2494:             my $numinrow = 5;
                   2495:             my $prefix;
                   2496:             my @types;
                   2497:             if ($position eq 'bottom') {
                   2498:                 $prefix = 'remote';
                   2499:                 @types = ('version','excludedomain','includedomain');
                   2500:             } else {
                   2501:                 $prefix = 'hosted';
                   2502:                 @types = ('excludedomain','includedomain');
                   2503:             }
                   2504:             my (%current,%checkedon,%checkedoff);
                   2505:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   2506:             my @locations = sort(keys(%by_location));
                   2507:             foreach my $type (@types) {
                   2508:                 $checkedon{$type} = '';
                   2509:                 $checkedoff{$type} = ' checked="checked"';
                   2510:             }
                   2511:             if (ref($settings) eq 'HASH') {
                   2512:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   2513:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   2514:                         $current{$key} = $settings->{$prefix}{$key};
                   2515:                         if ($key eq 'version') {
                   2516:                             if ($current{$key} ne '') {
                   2517:                                 $checkedon{$key} = ' checked="checked"';
                   2518:                                 $checkedoff{$key} = '';
                   2519:                             }
                   2520:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   2521:                             $checkedon{$key} = ' checked="checked"';
                   2522:                             $checkedoff{$key} = '';
                   2523:                         }
1.137     raeburn  2524:                     }
                   2525:                 }
                   2526:             }
1.145     raeburn  2527:             foreach my $type (@types) {
                   2528:                 next if ($type ne 'version' && !@locations);
                   2529:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2530:                 $datatable .= '<tr'.$css_class.'>
                   2531:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   2532:                                <span class="LC_nobreak">&nbsp;
                   2533:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   2534:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   2535:                 if ($type eq 'version') {
                   2536:                     my $selector = '<select name="'.$prefix.'_version">';
                   2537:                     foreach my $version (@lcversions) {
                   2538:                         my $selected = '';
                   2539:                         if ($current{'version'} eq $version) {
                   2540:                             $selected = ' selected="selected"';
                   2541:                         }
                   2542:                         $selector .= ' <option value="'.$version.'"'.
                   2543:                                      $selected.'>'.$version.'</option>';
                   2544:                     }
                   2545:                     $selector .= '</select> ';
                   2546:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   2547:                 } else {
                   2548:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   2549:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   2550:                                  ' />'.('&nbsp;'x2).
                   2551:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   2552:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   2553:                                  "\n".
                   2554:                                  '</div><div><table>';
                   2555:                     my $rem;
                   2556:                     for (my $i=0; $i<@locations; $i++) {
                   2557:                         my ($showloc,$value,$checkedtype);
                   2558:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   2559:                             my $ip = $by_location{$locations[$i]}->[0];
                   2560:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   2561:                                  $value = join(':',@{$by_ip{$ip}});
                   2562:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   2563:                                 if (ref($current{$type}) eq 'ARRAY') {
                   2564:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   2565:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   2566:                                             $checkedtype = ' checked="checked"';
                   2567:                                             last;
                   2568:                                         }
                   2569:                                     }
1.138     raeburn  2570:                                 }
                   2571:                             }
                   2572:                         }
1.145     raeburn  2573:                         $rem = $i%($numinrow);
                   2574:                         if ($rem == 0) {
                   2575:                             if ($i > 0) {
                   2576:                                 $datatable .= '</tr>';
                   2577:                             }
                   2578:                             $datatable .= '<tr>';
                   2579:                         }
                   2580:                         $datatable .= '<td class="LC_left_item">'.
                   2581:                                       '<span class="LC_nobreak"><label>'.
                   2582:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   2583:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   2584:                                       '</label></span></td>';
1.137     raeburn  2585:                     }
1.145     raeburn  2586:                     $rem = @locations%($numinrow);
                   2587:                     my $colsleft = $numinrow - $rem;
                   2588:                     if ($colsleft > 1 ) {
                   2589:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2590:                                       '&nbsp;</td>';
                   2591:                     } elsif ($colsleft == 1) {
                   2592:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  2593:                     }
1.145     raeburn  2594:                     $datatable .= '</tr></table>';
1.137     raeburn  2595:                 }
1.145     raeburn  2596:                 $datatable .= '</td></tr>';
                   2597:                 $itemcount ++;
1.137     raeburn  2598:             }
                   2599:         }
                   2600:     }
                   2601:     $$rowtotal += $itemcount;
                   2602:     return $datatable;
                   2603: }
                   2604: 
1.138     raeburn  2605: sub build_location_hashes {
                   2606:     my ($intdoms,$by_ip,$by_location) = @_;
                   2607:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   2608:                   (ref($by_location) eq 'HASH')); 
                   2609:     my %iphost = &Apache::lonnet::get_iphost();
                   2610:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   2611:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   2612:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   2613:         foreach my $id (@{$iphost{$primary_ip}}) {
                   2614:             my $intdom = &Apache::lonnet::internet_dom($id);
                   2615:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   2616:                 push(@{$intdoms},$intdom);
                   2617:             }
                   2618:         }
                   2619:     }
                   2620:     foreach my $ip (keys(%iphost)) {
                   2621:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   2622:             foreach my $id (@{$iphost{$ip}}) {
                   2623:                 my $location = &Apache::lonnet::internet_dom($id);
                   2624:                 if ($location) {
                   2625:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   2626:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2627:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   2628:                             push(@{$by_ip->{$ip}},$location);
                   2629:                         }
                   2630:                     } else {
                   2631:                         $by_ip->{$ip} = [$location];
                   2632:                     }
                   2633:                 }
                   2634:             }
                   2635:         }
                   2636:     }
                   2637:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   2638:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2639:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   2640:             my $first = $by_ip->{$ip}->[0];
                   2641:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   2642:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   2643:                     push(@{$by_location->{$first}},$ip);
                   2644:                 }
                   2645:             } else {
                   2646:                 $by_location->{$first} = [$ip];
                   2647:             }
                   2648:         }
                   2649:     }
                   2650:     return;
                   2651: }
                   2652: 
1.145     raeburn  2653: sub current_offloads_to {
                   2654:     my ($dom,$settings,$servers) = @_;
                   2655:     my (%spareid,%otherdomconfigs);
1.152     raeburn  2656:     if (ref($servers) eq 'HASH') {
1.145     raeburn  2657:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   2658:             my $gotspares;
1.152     raeburn  2659:             if (ref($settings) eq 'HASH') {
                   2660:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   2661:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   2662:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   2663:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   2664:                         $gotspares = 1;
                   2665:                     }
1.145     raeburn  2666:                 }
                   2667:             }
                   2668:             unless ($gotspares) {
                   2669:                 my $gotspares;
                   2670:                 my $serverhomeID =
                   2671:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   2672:                 my $serverhomedom =
                   2673:                     &Apache::lonnet::host_domain($serverhomeID);
                   2674:                 if ($serverhomedom ne $dom) {
                   2675:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   2676:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2677:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2678:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2679:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2680:                                 $gotspares = 1;
                   2681:                             }
                   2682:                         }
                   2683:                     } else {
                   2684:                         $otherdomconfigs{$serverhomedom} =
                   2685:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   2686:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   2687:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2688:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2689:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   2690:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2691:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2692:                                         $gotspares = 1;
                   2693:                                     }
                   2694:                                 }
                   2695:                             }
                   2696:                         }
                   2697:                     }
                   2698:                 }
                   2699:             }
                   2700:             unless ($gotspares) {
                   2701:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2702:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2703:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2704:                } else {
                   2705:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   2706:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   2707:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2708:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2709:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2710:                     } else {
1.150     raeburn  2711:                         my %what = (
                   2712:                              spareid => 1,
                   2713:                         );
                   2714:                         my ($result,$returnhash) = 
                   2715:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   2716:                         if ($result eq 'ok') { 
                   2717:                             if (ref($returnhash) eq 'HASH') {
                   2718:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   2719:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   2720:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   2721:                                 }
                   2722:                             }
1.145     raeburn  2723:                         }
                   2724:                     }
                   2725:                 }
                   2726:             }
                   2727:         }
                   2728:     }
                   2729:     return %spareid;
                   2730: }
                   2731: 
                   2732: sub spares_row {
1.152     raeburn  2733:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145     raeburn  2734:     my $css_class;
                   2735:     my $numinrow = 4;
                   2736:     my $itemcount = 1;
                   2737:     my $datatable;
1.152     raeburn  2738:     my %typetitles = &sparestype_titles();
                   2739:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  2740:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  2741:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   2742:             my ($othercontrol,$serverdom);
                   2743:             if ($serverhome ne $server) {
                   2744:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   2745:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2746:             } else {
                   2747:                 $serverdom = &Apache::lonnet::host_domain($server);
                   2748:                 if ($serverdom ne $dom) {
                   2749:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2750:                 }
                   2751:             }
                   2752:             next unless (ref($spareid->{$server}) eq 'HASH');
1.145     raeburn  2753:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2754:             $datatable .= '<tr'.$css_class.'>
                   2755:                            <td rowspan="2">
1.152     raeburn  2756:                             <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145     raeburn  2757:             my (%current,%canselect);
1.152     raeburn  2758:             my @choices = 
                   2759:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   2760:             foreach my $type ('primary','default') {
                   2761:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  2762:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   2763:                         my @spares = @{$spareid->{$server}{$type}};
                   2764:                         if (@spares > 0) {
1.152     raeburn  2765:                             if ($othercontrol) {
                   2766:                                 $current{$type} = join(', ',@spares);
                   2767:                             } else {
                   2768:                                 $current{$type} .= '<table>';
                   2769:                                 my $numspares = scalar(@spares);
                   2770:                                 for (my $i=0;  $i<@spares; $i++) {
                   2771:                                     my $rem = $i%($numinrow);
                   2772:                                     if ($rem == 0) {
                   2773:                                         if ($i > 0) {
                   2774:                                             $current{$type} .= '</tr>';
                   2775:                                         }
                   2776:                                         $current{$type} .= '<tr>';
1.145     raeburn  2777:                                     }
1.152     raeburn  2778:                                     $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;'.
                   2779:                                                        $spareid->{$server}{$type}[$i].
                   2780:                                                        '</label></td>'."\n";
                   2781:                                 }
                   2782:                                 my $rem = @spares%($numinrow);
                   2783:                                 my $colsleft = $numinrow - $rem;
                   2784:                                 if ($colsleft > 1 ) {
                   2785:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   2786:                                                        '" class="LC_left_item">'.
                   2787:                                                        '&nbsp;</td>';
                   2788:                                 } elsif ($colsleft == 1) {
                   2789:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  2790:                                 }
1.152     raeburn  2791:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  2792:                             }
1.145     raeburn  2793:                         }
                   2794:                     }
                   2795:                     if ($current{$type} eq '') {
                   2796:                         $current{$type} = &mt('None specified');
                   2797:                     }
1.152     raeburn  2798:                     if ($othercontrol) {
                   2799:                         if ($type eq 'primary') {
                   2800:                             $canselect{$type} = $othercontrol;
                   2801:                         }
                   2802:                     } else {
                   2803:                         $canselect{$type} = 
                   2804:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   2805:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   2806:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   2807:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   2808:                         if (@choices > 0) {
                   2809:                             foreach my $lonhost (@choices) {
                   2810:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   2811:                             }
                   2812:                         }
                   2813:                         $canselect{$type} .= '</select>'."\n";
                   2814:                     }
                   2815:                 } else {
                   2816:                     $current{$type} = &mt('Could not be determined');
                   2817:                     if ($type eq 'primary') {
                   2818:                         $canselect{$type} =  $othercontrol;
                   2819:                     }
1.145     raeburn  2820:                 }
1.152     raeburn  2821:                 if ($type eq 'default') {
                   2822:                     $datatable .= '<tr'.$css_class.'>';
                   2823:                 }
                   2824:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   2825:                               '<td>'.$current{$type}.'</td>'."\n".
                   2826:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  2827:             }
                   2828:             $itemcount ++;
                   2829:         }
                   2830:     }
                   2831:     $$rowtotal += $itemcount;
                   2832:     return $datatable;
                   2833: }
                   2834: 
1.152     raeburn  2835: sub possible_newspares {
                   2836:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   2837:     my $serverhostname = &Apache::lonnet::hostname($server);
                   2838:     my %excluded;
                   2839:     if ($serverhostname ne '') {
                   2840:         %excluded = (
                   2841:                        $serverhostname => 1,
                   2842:                     );
                   2843:     }
                   2844:     if (ref($currspares) eq 'HASH') {
                   2845:         foreach my $type (keys(%{$currspares})) {
                   2846:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   2847:                 if (@{$currspares->{$type}} > 0) {
                   2848:                     foreach my $curr (@{$currspares->{$type}}) {
                   2849:                         my $hostname = &Apache::lonnet::hostname($curr);
                   2850:                         $excluded{$hostname} = 1;
                   2851:                     }
                   2852:                 }
                   2853:             }
                   2854:         }
                   2855:     }
                   2856:     my @choices;
                   2857:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   2858:         if (keys(%{$serverhomes}) > 1) {
                   2859:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   2860:                 unless ($excluded{$name}) {
                   2861:                     if (exists($altids->{$serverhomes->{$name}})) {
                   2862:                         push(@choices,$altids->{$serverhomes->{$name}});
                   2863:                     } else {
                   2864:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  2865:                     }
                   2866:                 }
                   2867:             }
                   2868:         }
                   2869:     }
1.152     raeburn  2870:     return sort(@choices);
1.145     raeburn  2871: }
                   2872: 
1.150     raeburn  2873: sub print_loadbalancing {
                   2874:     my ($dom,$settings,$rowtotal) = @_;
                   2875:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   2876:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2877:     my $numinrow = 1;
                   2878:     my $datatable;
                   2879:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   2880:     my ($currbalancer,$currtargets,$currrules);
                   2881:     if (keys(%servers) > 1) {
                   2882:         if (ref($settings) eq 'HASH') {
                   2883:             $currbalancer = $settings->{'lonhost'};
                   2884:             $currtargets = $settings->{'targets'};
                   2885:             $currrules = $settings->{'rules'};
                   2886:         } else {
                   2887:             ($currbalancer,$currtargets) = 
                   2888:                 &Apache::lonnet::get_lonbalancer_config(\%servers);
                   2889:         }
                   2890:     } else {
                   2891:         return;
                   2892:     }
                   2893:     my ($othertitle,$usertypes,$types) =
                   2894:         &Apache::loncommon::sorted_inst_types($dom);
                   2895:     my $rownum = 6;
                   2896:     if (ref($types) eq 'ARRAY') {
                   2897:         $rownum += scalar(@{$types});
                   2898:     }
1.153     raeburn  2899:     my $css_class = ' class="LC_odd_row"';
1.150     raeburn  2900:     my $targets_div_style = 'display: none';
                   2901:     my $disabled_div_style = 'display: block';
                   2902:     my $homedom_div_style = 'display: none';
                   2903:     $datatable = '<tr'.$css_class.'>'.
                   2904:                  '<td rowspan="'.$rownum.'" valign="top">'.
                   2905:                  '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
                   2906:                  '<option value=""';
                   2907:     if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
                   2908:         $datatable .= ' selected="selected"';
                   2909:     } else {
                   2910:         $targets_div_style = 'display: block';
                   2911:         $disabled_div_style = 'display: none';
                   2912:         if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
                   2913:             $homedom_div_style = 'display: block'; 
                   2914:         }
                   2915:     }
                   2916:     $datatable .= '>'.&mt('None').'</option>'."\n";
                   2917:     foreach my $lonhost (sort(keys(%servers))) {
                   2918:         my $selected;
                   2919:         if ($lonhost eq $currbalancer) {
                   2920:             $selected .= ' selected="selected"';
                   2921:         }
                   2922:         $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
                   2923:     }
                   2924:     $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
                   2925:                   '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
                   2926:                   '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   2927:     my ($numspares,@spares) = &count_servers($currbalancer,%servers);
                   2928:     my @sparestypes = ('primary','default');
                   2929:     my %typetitles = &sparestype_titles();
                   2930:     foreach my $sparetype (@sparestypes) {
                   2931:         my $targettable;
                   2932:         for (my $i=0; $i<$numspares; $i++) {
                   2933:             my $checked;
                   2934:             if (ref($currtargets) eq 'HASH') {
                   2935:                 if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
                   2936:                     if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
                   2937:                         $checked = ' checked="checked"';
                   2938:                     }
                   2939:                 }
                   2940:             }
                   2941:             my $chkboxval;
                   2942:             if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
                   2943:                 $chkboxval = $spares[$i];
                   2944:             }
                   2945:             $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
                   2946:                       $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                   2947:                       '</span></label></td>';
                   2948:             my $rem = $i%($numinrow);
                   2949:             if ($rem == 0) {
                   2950:                 if ($i > 0) {
                   2951:                     $targettable .= '</tr>';
                   2952:                 }
                   2953:                 $targettable .= '<tr>';
                   2954:             }
                   2955:         }
                   2956:         if ($targettable ne '') {
                   2957:             my $rem = $numspares%($numinrow);
                   2958:             my $colsleft = $numinrow - $rem;
                   2959:             if ($colsleft > 1 ) {
                   2960:                 $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2961:                                 '&nbsp;</td>';
                   2962:             } elsif ($colsleft == 1) {
                   2963:                 $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   2964:             }
                   2965:             $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   2966:                            '<table><tr>'.$targettable.'</table><br />';
                   2967:         }
                   2968:     }
                   2969:     $datatable .= '</div></td></tr>'.
                   2970:                   &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
                   2971:                                        $usertypes,$types,\%servers,$currbalancer,
1.153     raeburn  2972:                                        $targets_div_style,$homedom_div_style,$css_class);
1.150     raeburn  2973:     $$rowtotal += $rownum;
                   2974:     return $datatable;
                   2975: }
                   2976: 
                   2977: sub loadbalancing_rules {
                   2978:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.153     raeburn  2979:         $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
1.150     raeburn  2980:     my $output;
                   2981:     my ($alltypes,$othertypes,$titles) = 
                   2982:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   2983:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   2984:         foreach my $type (@{$alltypes}) {
                   2985:             my $current;
                   2986:             if (ref($currrules) eq 'HASH') {
                   2987:                 $current = $currrules->{$type};
                   2988:             }
                   2989:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   2990:                 if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
                   2991:                     $current = '';
                   2992:                 }
                   2993:             }
                   2994:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
                   2995:                                              $servers,$currbalancer,$dom,
1.153     raeburn  2996:                                              $targets_div_style,$homedom_div_style,$css_class);
1.150     raeburn  2997:         }
                   2998:     }
                   2999:     return $output;
                   3000: }
                   3001: 
                   3002: sub loadbalancing_titles {
                   3003:     my ($dom,$intdom,$usertypes,$types) = @_;
                   3004:     my %othertypes = (
                   3005:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   3006:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   3007:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   3008:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
                   3009:                      );
                   3010:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   3011:     if (ref($types) eq 'ARRAY') {
                   3012:         unshift(@alltypes,@{$types},'default');
                   3013:     }
                   3014:     my %titles;
                   3015:     foreach my $type (@alltypes) {
                   3016:         if ($type =~ /^_LC_/) {
                   3017:             $titles{$type} = $othertypes{$type};
                   3018:         } elsif ($type eq 'default') {
                   3019:             $titles{$type} = &mt('All users from [_1]',$dom);
                   3020:             if (ref($types) eq 'ARRAY') {
                   3021:                 if (@{$types} > 0) {
                   3022:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   3023:                 }
                   3024:             }
                   3025:         } elsif (ref($usertypes) eq 'HASH') {
                   3026:             $titles{$type} = $usertypes->{$type};
                   3027:         }
                   3028:     }
                   3029:     return (\@alltypes,\%othertypes,\%titles);
                   3030: }
                   3031: 
                   3032: sub loadbalance_rule_row {
                   3033:     my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
1.153     raeburn  3034:         $homedom_div_style,$css_class) = @_;
1.150     raeburn  3035:     my @rulenames = ('default','homeserver');
                   3036:     my %ruletitles = &offloadtype_text();
                   3037:     if ($type eq '_LC_external') {
                   3038:         push(@rulenames,'externalbalancer');
                   3039:     } else {
                   3040:         push(@rulenames,'specific');
                   3041:     }
1.161     raeburn  3042:     push(@rulenames,'none');
1.150     raeburn  3043:     my $style = $targets_div_style;
                   3044:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   3045:         $style = $homedom_div_style;
                   3046:     }
                   3047:     my $output = 
1.153     raeburn  3048:         '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
1.150     raeburn  3049:         '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
                   3050:     for (my $i=0; $i<@rulenames; $i++) {
                   3051:         my $rule = $rulenames[$i];
                   3052:         my ($checked,$extra);
                   3053:         if ($rulenames[$i] eq 'default') {
                   3054:             $rule = '';
                   3055:         }
                   3056:         if ($rulenames[$i] eq 'specific') {
                   3057:             if (ref($servers) eq 'HASH') {
                   3058:                 my $default;
                   3059:                 if (($current ne '') && (exists($servers->{$current}))) {
                   3060:                     $checked = ' checked="checked"';
                   3061:                 }
                   3062:                 unless ($checked) {
                   3063:                     $default = ' selected="selected"';
                   3064:                 }
                   3065:                 $extra = ':&nbsp;<select name="loadbalancing_singleserver_'.$type.
                   3066:                          '" id="loadbalancing_singleserver_'.$type.
                   3067:                          '" onchange="singleServerToggle('."'$type'".')">'."\n".
                   3068:                          '<option value=""'.$default.'></option>'."\n";
                   3069:                 foreach my $lonhost (sort(keys(%{$servers}))) {
                   3070:                     next if ($lonhost eq $currbalancer);
                   3071:                     my $selected;
                   3072:                     if ($lonhost eq $current) {
                   3073:                         $selected = ' selected="selected"';
                   3074:                     }
                   3075:                     $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
                   3076:                 }
                   3077:                 $extra .= '</select>';
                   3078:             }
                   3079:         } elsif ($rule eq $current) {
                   3080:             $checked = ' checked="checked"';
                   3081:         }
                   3082:         $output .= '<span class="LC_nobreak"><label>'.
                   3083:                    '<input type="radio" name="loadbalancing_rules_'.$type.
                   3084:                    '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
                   3085:                    $rule.'" onclick="balanceruleChange('."this.form,'$type'".
                   3086:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   3087:                    '</label>'.$extra.'</span><br />'."\n";
                   3088:     }
                   3089:     $output .= '</div></td></tr>'."\n";
                   3090:     return $output;
                   3091: }
                   3092: 
                   3093: sub offloadtype_text {
                   3094:     my %ruletitles = &Apache::lonlocal::texthash (
                   3095:            'default'          => 'Offloads to default destinations',
                   3096:            'homeserver'       => "Offloads to user's home server",
                   3097:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   3098:            'specific'         => 'Offloads to specific server',
1.161     raeburn  3099:            'none'             => 'No offload',
1.150     raeburn  3100:     );
                   3101:     return %ruletitles;
                   3102: }
                   3103: 
                   3104: sub sparestype_titles {
                   3105:     my %typestitles = &Apache::lonlocal::texthash (
                   3106:                           'primary' => 'primary',
                   3107:                           'default' => 'default',
                   3108:                       );
                   3109:     return %typestitles;
                   3110: }
                   3111: 
1.28      raeburn  3112: sub contact_titles {
                   3113:     my %titles = &Apache::lonlocal::texthash (
                   3114:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  3115:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  3116:                    'errormail'    => 'Error reports to be e-mailed to',
                   3117:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  3118:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   3119:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  3120:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.28      raeburn  3121:                  );
                   3122:     my %short_titles = &Apache::lonlocal::texthash (
                   3123:                            adminemail   => 'Admin E-mail address',
                   3124:                            supportemail => 'Support E-mail',
                   3125:                        );   
                   3126:     return (\%titles,\%short_titles);
                   3127: }
                   3128: 
1.72      raeburn  3129: sub tool_titles {
                   3130:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  3131:                      aboutme    => 'Personal web page',
1.86      raeburn  3132:                      blog       => 'Blog',
1.162     raeburn  3133:                      webdav     => 'WebDAV',
1.86      raeburn  3134:                      portfolio  => 'Portfolio',
1.88      bisitz   3135:                      official   => 'Official courses (with institutional codes)',
                   3136:                      unofficial => 'Unofficial courses',
1.98      raeburn  3137:                      community  => 'Communities',
1.86      raeburn  3138:                  );
1.72      raeburn  3139:     return %titles;
                   3140: }
                   3141: 
1.101     raeburn  3142: sub courserequest_titles {
                   3143:     my %titles = &Apache::lonlocal::texthash (
                   3144:                                    official   => 'Official',
                   3145:                                    unofficial => 'Unofficial',
                   3146:                                    community  => 'Communities',
                   3147:                                    norequest  => 'Not allowed',
1.104     raeburn  3148:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3149:                                    validate   => 'With validation',
                   3150:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3151:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3152:                  );
                   3153:     return %titles;
                   3154: }
                   3155: 
1.163     raeburn  3156: sub authorrequest_titles {
                   3157:     my %titles = &Apache::lonlocal::texthash (
                   3158:                                    norequest  => 'Not allowed',
                   3159:                                    approval   => 'Approval by Dom. Coord.',
                   3160:                                    automatic  => 'Automatic approval',
                   3161:                  );
                   3162:     return %titles;
                   3163: } 
                   3164: 
1.101     raeburn  3165: sub courserequest_conditions {
                   3166:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3167:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.101     raeburn  3168:        validate   => '(Processing of request subject to instittutional validation).',
                   3169:                  );
                   3170:     return %conditions;
                   3171: }
                   3172: 
                   3173: 
1.27      raeburn  3174: sub print_usercreation {
1.30      raeburn  3175:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3176:     my $numinrow = 4;
1.28      raeburn  3177:     my $datatable;
                   3178:     if ($position eq 'top') {
1.30      raeburn  3179:         $$rowtotal ++;
1.34      raeburn  3180:         my $rowcount = 0;
1.32      raeburn  3181:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3182:         if (ref($rules) eq 'HASH') {
                   3183:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3184:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3185:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3186:                 $$rowtotal ++;
1.32      raeburn  3187:                 $rowcount ++;
                   3188:             }
                   3189:         }
                   3190:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3191:         if (ref($idrules) eq 'HASH') {
                   3192:             if (keys(%{$idrules}) > 0) {
                   3193:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3194:                                                 $idruleorder,$numinrow,$rowcount);
                   3195:                 $$rowtotal ++;
                   3196:                 $rowcount ++;
1.28      raeburn  3197:             }
                   3198:         }
1.43      raeburn  3199:         my ($emailrules,$emailruleorder) = 
                   3200:             &Apache::lonnet::inst_userrules($dom,'email');
                   3201:         if (ref($emailrules) eq 'HASH') {
                   3202:             if (keys(%{$emailrules}) > 0) {
                   3203:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
                   3204:                                                 $emailruleorder,$numinrow,$rowcount);
                   3205:                 $$rowtotal ++;
                   3206:                 $rowcount ++;
                   3207:             }
                   3208:         }
1.39      raeburn  3209:         if ($rowcount == 0) {
                   3210:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3211:             $$rowtotal ++;
                   3212:             $rowcount ++;
                   3213:         }
1.34      raeburn  3214:     } elsif ($position eq 'middle') {
1.100     raeburn  3215:         my @creators = ('author','course','requestcrs','selfcreate');
1.37      raeburn  3216:         my ($rules,$ruleorder) =
                   3217:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3218:         my %lt = &usercreation_types();
                   3219:         my %checked;
1.50      raeburn  3220:         my @selfcreate; 
1.34      raeburn  3221:         if (ref($settings) eq 'HASH') {
                   3222:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3223:                 foreach my $item (@creators) {
                   3224:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3225:                 }
1.50      raeburn  3226:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3227:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3228:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3229:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3230:                         @selfcreate = ('email','login','sso');
                   3231:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3232:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3233:                     }
                   3234:                 }
1.34      raeburn  3235:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3236:                 foreach my $item (@creators) {
                   3237:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3238:                         $checked{$item} = 'none';
                   3239:                     }
                   3240:                 }
                   3241:             }
                   3242:         }
                   3243:         my $rownum = 0;
                   3244:         foreach my $item (@creators) {
                   3245:             $rownum ++;
1.50      raeburn  3246:             if ($item ne 'selfcreate') {  
                   3247:                 if ($checked{$item} eq '') {
1.43      raeburn  3248:                     $checked{$item} = 'any';
                   3249:                 }
1.34      raeburn  3250:             }
                   3251:             my $css_class;
                   3252:             if ($rownum%2) {
                   3253:                 $css_class = '';
                   3254:             } else {
                   3255:                 $css_class = ' class="LC_odd_row" ';
                   3256:             }
                   3257:             $datatable .= '<tr'.$css_class.'>'.
                   3258:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3259:                          '</span></td><td align="right">';
1.50      raeburn  3260:             my @options;
1.45      raeburn  3261:             if ($item eq 'selfcreate') {
1.43      raeburn  3262:                 push(@options,('email','login','sso'));
                   3263:             } else {
1.50      raeburn  3264:                 @options = ('any');
1.43      raeburn  3265:                 if (ref($rules) eq 'HASH') {
                   3266:                     if (keys(%{$rules}) > 0) {
                   3267:                         push(@options,('official','unofficial'));
                   3268:                     }
1.37      raeburn  3269:                 }
1.50      raeburn  3270:                 push(@options,'none');
1.37      raeburn  3271:             }
                   3272:             foreach my $option (@options) {
1.50      raeburn  3273:                 my $type = 'radio';
1.34      raeburn  3274:                 my $check = ' ';
1.50      raeburn  3275:                 if ($item eq 'selfcreate') {
                   3276:                     $type = 'checkbox';
                   3277:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
                   3278:                         $check = ' checked="checked" ';
                   3279:                     }
                   3280:                 } else {
                   3281:                     if ($checked{$item} eq $option) {
                   3282:                         $check = ' checked="checked" ';
                   3283:                     }
1.34      raeburn  3284:                 } 
                   3285:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3286:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3287:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3288:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3289:             }
                   3290:             $datatable .= '</td></tr>';
                   3291:         }
1.93      raeburn  3292:         my ($othertitle,$usertypes,$types) =
                   3293:             &Apache::loncommon::sorted_inst_types($dom);
1.165     raeburn  3294:         my $createsettings;
                   3295:         if (ref($settings) eq 'HASH') {
                   3296:             $createsettings = $settings->{cancreate};
                   3297:         }
1.93      raeburn  3298:         if (ref($usertypes) eq 'HASH') {
                   3299:             if (keys(%{$usertypes}) > 0) {
1.99      raeburn  3300:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93      raeburn  3301:                                              $dom,$numinrow,$othertitle,
                   3302:                                              'statustocreate');
                   3303:                 $$rowtotal ++;
1.169   ! raeburn  3304:                 $rownum ++;
1.93      raeburn  3305:             }
                   3306:         }
1.169   ! raeburn  3307:         $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28      raeburn  3308:     } else {
                   3309:         my @contexts = ('author','course','domain');
                   3310:         my @authtypes = ('int','krb4','krb5','loc');
                   3311:         my %checked;
                   3312:         if (ref($settings) eq 'HASH') {
                   3313:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3314:                 foreach my $item (@contexts) {
                   3315:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3316:                         foreach my $auth (@authtypes) {
                   3317:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3318:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3319:                             }
                   3320:                         }
                   3321:                     }
                   3322:                 }
1.27      raeburn  3323:             }
1.35      raeburn  3324:         } else {
                   3325:             foreach my $item (@contexts) {
1.36      raeburn  3326:                 foreach my $auth (@authtypes) {
1.35      raeburn  3327:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3328:                 }
                   3329:             }
1.27      raeburn  3330:         }
1.28      raeburn  3331:         my %title = &context_names();
                   3332:         my %authname = &authtype_names();
                   3333:         my $rownum = 0;
                   3334:         my $css_class; 
                   3335:         foreach my $item (@contexts) {
                   3336:             if ($rownum%2) {
                   3337:                 $css_class = '';
                   3338:             } else {
                   3339:                 $css_class = ' class="LC_odd_row" ';
                   3340:             }
1.30      raeburn  3341:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3342:                             '<td>'.$title{$item}.
                   3343:                             '</td><td class="LC_left_item">'.
                   3344:                             '<span class="LC_nobreak">';
                   3345:             foreach my $auth (@authtypes) {
                   3346:                 $datatable .= '<label>'. 
                   3347:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3348:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3349:                               $authname{$auth}.'</label>&nbsp;';
                   3350:             }
                   3351:             $datatable .= '</span></td></tr>';
                   3352:             $rownum ++;
1.27      raeburn  3353:         }
1.30      raeburn  3354:         $$rowtotal += $rownum;
1.27      raeburn  3355:     }
                   3356:     return $datatable;
                   3357: }
                   3358: 
1.165     raeburn  3359: sub captcha_choice {
1.169   ! raeburn  3360:     my ($context,$settings,$itemcount) = @_;
1.165     raeburn  3361:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
                   3362:     my %lt = &captcha_phrases();
                   3363:     $keyentry = 'hidden';
                   3364:     if ($context eq 'cancreate') {
                   3365:         $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169   ! raeburn  3366:     } elsif ($context eq 'login') {
        !          3367:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  3368:     }
                   3369:     if (ref($settings) eq 'HASH') {
                   3370:         if ($settings->{'captcha'}) {
                   3371:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   3372:         } else {
                   3373:             $checked{'original'} = ' checked="checked"';
                   3374:         }
                   3375:         if ($settings->{'captcha'} eq 'recaptcha') {
                   3376:             $pubtext = $lt{'pub'};
                   3377:             $privtext = $lt{'priv'};
                   3378:             $keyentry = 'text';
                   3379:         }
                   3380:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   3381:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   3382:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   3383:         }
                   3384:     } else {
                   3385:         $checked{'original'} = ' checked="checked"';
                   3386:     }
1.169   ! raeburn  3387:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
        !          3388:     my $output = '<tr'.$css_class.'>'.
        !          3389:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  3390:                  '<table><tr><td>'."\n";
                   3391:     foreach my $option ('original','recaptcha','notused') {
                   3392:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   3393:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   3394:                    $lt{$option}.'</label></span>';
                   3395:         unless ($option eq 'notused') {
                   3396:             $output .= ('&nbsp;'x2)."\n";
                   3397:         }
                   3398:     }
                   3399: #
                   3400: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   3401: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   3402: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu) 
                   3403: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   3404: #  
                   3405:     $output .= '</td></tr>'."\n".
                   3406:                '<tr><td>'."\n".
                   3407:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   3408:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   3409:                $currpub.'" size="40" /></span><br />'."\n".
                   3410:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   3411:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
                   3412:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
                   3413:                '</td></tr>';
                   3414:     return $output;
                   3415: }
                   3416: 
1.32      raeburn  3417: sub user_formats_row {
                   3418:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   3419:     my $output;
                   3420:     my %text = (
                   3421:                    'username' => 'new usernames',
                   3422:                    'id'       => 'IDs',
1.45      raeburn  3423:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  3424:                );
                   3425:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   3426:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  3427:               '<td><span class="LC_nobreak">';
                   3428:     if ($type eq 'email') {
                   3429:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   3430:     } else {
                   3431:         $output .= &mt("Format rules to check for $text{$type}: ");
                   3432:     }
                   3433:     $output .= '</span></td>'.
                   3434:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  3435:     my $rem;
                   3436:     if (ref($ruleorder) eq 'ARRAY') {
                   3437:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   3438:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   3439:                 my $rem = $i%($numinrow);
                   3440:                 if ($rem == 0) {
                   3441:                     if ($i > 0) {
                   3442:                         $output .= '</tr>';
                   3443:                     }
                   3444:                     $output .= '<tr>';
                   3445:                 }
                   3446:                 my $check = ' ';
1.39      raeburn  3447:                 if (ref($settings) eq 'HASH') {
                   3448:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   3449:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   3450:                             $check = ' checked="checked" ';
                   3451:                         }
1.27      raeburn  3452:                     }
                   3453:                 }
                   3454:                 $output .= '<td class="LC_left_item">'.
                   3455:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  3456:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  3457:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   3458:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   3459:             }
                   3460:         }
                   3461:         $rem = @{$ruleorder}%($numinrow);
                   3462:     }
                   3463:     my $colsleft = $numinrow - $rem;
                   3464:     if ($colsleft > 1 ) {
                   3465:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3466:                    '&nbsp;</td>';
                   3467:     } elsif ($colsleft == 1) {
                   3468:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   3469:     }
                   3470:     $output .= '</tr></table></td></tr>';
                   3471:     return $output;
                   3472: }
                   3473: 
1.34      raeburn  3474: sub usercreation_types {
                   3475:     my %lt = &Apache::lonlocal::texthash (
                   3476:                     author     => 'When adding a co-author',
                   3477:                     course     => 'When adding a user to a course',
1.100     raeburn  3478:                     requestcrs => 'When requesting a course',
1.45      raeburn  3479:                     selfcreate => 'User creates own account', 
1.34      raeburn  3480:                     any        => 'Any',
                   3481:                     official   => 'Institutional only ',
                   3482:                     unofficial => 'Non-institutional only',
1.85      schafran 3483:                     email      => 'E-mail address',
1.43      raeburn  3484:                     login      => 'Institutional Login',
                   3485:                     sso        => 'SSO', 
1.34      raeburn  3486:                     none       => 'None',
                   3487:     );
                   3488:     return %lt;
1.48      raeburn  3489: }
1.34      raeburn  3490: 
1.28      raeburn  3491: sub authtype_names {
                   3492:     my %lt = &Apache::lonlocal::texthash(
                   3493:                       int    => 'Internal',
                   3494:                       krb4   => 'Kerberos 4',
                   3495:                       krb5   => 'Kerberos 5',
                   3496:                       loc    => 'Local',
                   3497:                   );
                   3498:     return %lt;
                   3499: }
                   3500: 
                   3501: sub context_names {
                   3502:     my %context_title = &Apache::lonlocal::texthash(
                   3503:        author => 'Creating users when an Author',
                   3504:        course => 'Creating users when in a course',
                   3505:        domain => 'Creating users when a Domain Coordinator',
                   3506:     );
                   3507:     return %context_title;
                   3508: }
                   3509: 
1.33      raeburn  3510: sub print_usermodification {
                   3511:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3512:     my $numinrow = 4;
                   3513:     my ($context,$datatable,$rowcount);
                   3514:     if ($position eq 'top') {
                   3515:         $rowcount = 0;
                   3516:         $context = 'author'; 
                   3517:         foreach my $role ('ca','aa') {
                   3518:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3519:                                                    $numinrow,$rowcount);
                   3520:             $$rowtotal ++;
                   3521:             $rowcount ++;
                   3522:         }
1.63      raeburn  3523:     } elsif ($position eq 'middle') {
1.33      raeburn  3524:         $context = 'course';
                   3525:         $rowcount = 0;
                   3526:         foreach my $role ('st','ep','ta','in','cr') {
                   3527:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3528:                                                    $numinrow,$rowcount);
                   3529:             $$rowtotal ++;
                   3530:             $rowcount ++;
                   3531:         }
1.63      raeburn  3532:     } elsif ($position eq 'bottom') {
                   3533:         $context = 'selfcreate';
                   3534:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3535:         $usertypes->{'default'} = $othertitle;
                   3536:         if (ref($types) eq 'ARRAY') {
                   3537:             push(@{$types},'default');
                   3538:             $usertypes->{'default'} = $othertitle;
                   3539:             foreach my $status (@{$types}) {
                   3540:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
                   3541:                                                        $numinrow,$rowcount,$usertypes);
                   3542:                 $$rowtotal ++;
                   3543:                 $rowcount ++;
                   3544:             }
                   3545:         }
1.33      raeburn  3546:     }
                   3547:     return $datatable;
                   3548: }
                   3549: 
1.43      raeburn  3550: sub print_defaults {
                   3551:     my ($dom,$rowtotal) = @_;
1.68      raeburn  3552:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  3553:                  'datelocale_def','portal_def');
1.43      raeburn  3554:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  3555:     my $titles = &defaults_titles($dom);
1.43      raeburn  3556:     my $rownum = 0;
                   3557:     my ($datatable,$css_class);
                   3558:     foreach my $item (@items) {
                   3559:         if ($rownum%2) {
                   3560:             $css_class = '';
                   3561:         } else {
                   3562:             $css_class = ' class="LC_odd_row" ';
                   3563:         }
                   3564:         $datatable .= '<tr'.$css_class.'>'.
                   3565:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3566:                   '</span></td><td class="LC_right_item">';
                   3567:         if ($item eq 'auth_def') {
                   3568:             my @authtypes = ('internal','krb4','krb5','localauth');
                   3569:             my %shortauth = (
                   3570:                              internal => 'int',
                   3571:                              krb4 => 'krb4',
                   3572:                              krb5 => 'krb5',
                   3573:                              localauth  => 'loc'
                   3574:                            );
                   3575:             my %authnames = &authtype_names();
                   3576:             foreach my $auth (@authtypes) {
                   3577:                 my $checked = ' ';
                   3578:                 if ($domdefaults{$item} eq $auth) {
                   3579:                     $checked = ' checked="checked" ';
                   3580:                 }
                   3581:                 $datatable .= '<label><input type="radio" name="'.$item.
                   3582:                               '" value="'.$auth.'"'.$checked.'/>'.
                   3583:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   3584:             }
1.54      raeburn  3585:         } elsif ($item eq 'timezone_def') {
                   3586:             my $includeempty = 1;
                   3587:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68      raeburn  3588:         } elsif ($item eq 'datelocale_def') {
                   3589:             my $includeempty = 1;
                   3590:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167     raeburn  3591:         } elsif ($item eq 'lang_def') {
1.168     raeburn  3592:             my %langchoices = &get_languages_hash();
                   3593:             $langchoices{''} = 'No language preference';
1.167     raeburn  3594:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
                   3595:             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
                   3596:                                                           \%langchoices);
1.43      raeburn  3597:         } else {
1.141     raeburn  3598:             my $size;
                   3599:             if ($item eq 'portal_def') {
                   3600:                 $size = ' size="25"';
                   3601:             }
1.43      raeburn  3602:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141     raeburn  3603:                           $domdefaults{$item}.'"'.$size.' />';
1.43      raeburn  3604:         }
                   3605:         $datatable .= '</td></tr>';
                   3606:         $rownum ++;
                   3607:     }
                   3608:     $$rowtotal += $rownum;
                   3609:     return $datatable;
                   3610: }
                   3611: 
1.168     raeburn  3612: sub get_languages_hash {
                   3613:     my %langchoices;
                   3614:     foreach my $id (&Apache::loncommon::languageids()) {
                   3615:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   3616:         if ($code ne '') {
                   3617:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   3618:         }
                   3619:     }
                   3620:     return %langchoices;
                   3621: }
                   3622: 
1.43      raeburn  3623: sub defaults_titles {
1.141     raeburn  3624:     my ($dom) = @_;
1.43      raeburn  3625:     my %titles = &Apache::lonlocal::texthash (
                   3626:                    'auth_def'      => 'Default authentication type',
                   3627:                    'auth_arg_def'  => 'Default authentication argument',
                   3628:                    'lang_def'      => 'Default language',
1.54      raeburn  3629:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  3630:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  3631:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  3632:                  );
1.141     raeburn  3633:     if ($dom) {
                   3634:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   3635:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   3636:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   3637:         $protocol = 'http' if ($protocol ne 'https');
                   3638:         if ($uint_dom) {
                   3639:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   3640:                                          $uint_dom);
                   3641:         }
                   3642:     }
1.43      raeburn  3643:     return (\%titles);
                   3644: }
                   3645: 
1.46      raeburn  3646: sub print_scantronformat {
                   3647:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   3648:     my $itemcount = 1;
1.60      raeburn  3649:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   3650:         %confhash);
1.46      raeburn  3651:     my $switchserver = &check_switchserver($dom,$confname);
                   3652:     my %lt = &Apache::lonlocal::texthash (
1.95      www      3653:                 default => 'Default bubblesheet format file error',
                   3654:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  3655:              );
                   3656:     my %scantronfiles = (
                   3657:         default => 'default.tab',
                   3658:         custom => 'custom.tab',
                   3659:     );
                   3660:     foreach my $key (keys(%scantronfiles)) {
                   3661:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   3662:                               .$scantronfiles{$key};
                   3663:     }
                   3664:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   3665:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   3666:         if (!$switchserver) {
                   3667:             my $servadm = $r->dir_config('lonAdmEMail');
                   3668:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   3669:             if ($configuserok eq 'ok') {
                   3670:                 if ($author_ok eq 'ok') {
                   3671:                     my %legacyfile = (
                   3672:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   3673:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   3674:                     );
                   3675:                     my %md5chk;
                   3676:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3677:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   3678:                         chomp($md5chk{$type});
1.46      raeburn  3679:                     }
                   3680:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   3681:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3682:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  3683:                                 &legacy_scantronformat($r,$dom,$confname,
                   3684:                                                  $type,$legacyfile{$type},
                   3685:                                                  $scantronurls{$type},
                   3686:                                                  $scantronfiles{$type});
1.60      raeburn  3687:                             if ($error ne '') {
                   3688:                                 $error{$type} = $error;
                   3689:                             }
                   3690:                         }
                   3691:                         if (keys(%error) == 0) {
                   3692:                             $is_custom = 1;
                   3693:                             $confhash{'scantron'}{'scantronformat'} = 
                   3694:                                 $scantronurls{'custom'};
                   3695:                             my $putresult = 
                   3696:                                 &Apache::lonnet::put_dom('configuration',
                   3697:                                                          \%confhash,$dom);
                   3698:                             if ($putresult ne 'ok') {
                   3699:                                 $error{'custom'} = 
                   3700:                                     '<span class="LC_error">'.
                   3701:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3702:                             }
1.46      raeburn  3703:                         }
                   3704:                     } else {
1.60      raeburn  3705:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  3706:                             &legacy_scantronformat($r,$dom,$confname,
                   3707:                                           'default',$legacyfile{'default'},
                   3708:                                           $scantronurls{'default'},
                   3709:                                           $scantronfiles{'default'});
1.60      raeburn  3710:                         if ($error eq '') {
                   3711:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   3712:                             my $putresult =
                   3713:                                 &Apache::lonnet::put_dom('configuration',
                   3714:                                                          \%confhash,$dom);
                   3715:                             if ($putresult ne 'ok') {
                   3716:                                 $error{'default'} =
                   3717:                                     '<span class="LC_error">'.
                   3718:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3719:                             }
                   3720:                         } else {
                   3721:                             $error{'default'} = $error;
                   3722:                         }
1.46      raeburn  3723:                     }
                   3724:                 }
                   3725:             }
                   3726:         } else {
1.95      www      3727:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  3728:         }
                   3729:     }
                   3730:     if (ref($settings) eq 'HASH') {
                   3731:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   3732:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   3733:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   3734:                 $scantronurl = '';
                   3735:             } else {
                   3736:                 $scantronurl = $settings->{'scantronformat'};
                   3737:             }
                   3738:             $is_custom = 1;
                   3739:         } else {
                   3740:             $scantronurl = $scantronurls{'default'};
                   3741:         }
                   3742:     } else {
1.60      raeburn  3743:         if ($is_custom) {
                   3744:             $scantronurl = $scantronurls{'custom'};
                   3745:         } else {
                   3746:             $scantronurl = $scantronurls{'default'};
                   3747:         }
1.46      raeburn  3748:     }
                   3749:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3750:     $datatable .= '<tr'.$css_class.'>';
                   3751:     if (!$is_custom) {
1.65      raeburn  3752:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   3753:                       '<span class="LC_nobreak">';
1.46      raeburn  3754:         if ($scantronurl) {
                   3755:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3756:                           &mt('Default bubblesheet format file').'</a>';
1.46      raeburn  3757:         } else {
                   3758:             $datatable = &mt('File unavailable for display');
                   3759:         }
1.65      raeburn  3760:         $datatable .= '</span></td>';
1.60      raeburn  3761:         if (keys(%error) == 0) { 
                   3762:             $datatable .= '<td valign="bottom">';
                   3763:             if (!$switchserver) {
                   3764:                 $datatable .= &mt('Upload:').'<br />';
                   3765:             }
                   3766:         } else {
                   3767:             my $errorstr;
                   3768:             foreach my $key (sort(keys(%error))) {
                   3769:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3770:             }
                   3771:             $datatable .= '<td>'.$errorstr;
                   3772:         }
1.46      raeburn  3773:     } else {
                   3774:         if (keys(%error) > 0) {
                   3775:             my $errorstr;
                   3776:             foreach my $key (sort(keys(%error))) {
                   3777:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3778:             } 
1.60      raeburn  3779:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  3780:         } elsif ($scantronurl) {
1.65      raeburn  3781:             $datatable .= '<td><span class="LC_nobreak">'.
                   3782:                           '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3783:                           &mt('Custom bubblesheet format file').'</a><label>'.
1.65      raeburn  3784:                           '<input type="checkbox" name="scantronformat_del"'.
                   3785:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
                   3786:                           '<td><span class="LC_nobreak">&nbsp;'.
                   3787:                           &mt('Replace:').'</span><br />';
1.46      raeburn  3788:         }
                   3789:     }
                   3790:     if (keys(%error) == 0) {
                   3791:         if ($switchserver) {
                   3792:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3793:         } else {
1.65      raeburn  3794:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   3795:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  3796:         }
                   3797:     }
                   3798:     $datatable .= '</td></tr>';
                   3799:     $$rowtotal ++;
                   3800:     return $datatable;
                   3801: }
                   3802: 
                   3803: sub legacy_scantronformat {
                   3804:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   3805:     my ($url,$error);
                   3806:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   3807:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   3808:         (my $result,$url) =
                   3809:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   3810:                          '','',$newfile);
                   3811:         if ($result ne 'ok') {
1.130     raeburn  3812:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  3813:         }
                   3814:     }
                   3815:     return ($url,$error);
                   3816: }
1.43      raeburn  3817: 
1.49      raeburn  3818: sub print_coursecategories {
1.57      raeburn  3819:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   3820:     my $datatable;
                   3821:     if ($position eq 'top') {
                   3822:         my $toggle_cats_crs = ' ';
                   3823:         my $toggle_cats_dom = ' checked="checked" ';
                   3824:         my $can_cat_crs = ' ';
                   3825:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  3826:         my $toggle_catscomm_comm = ' ';
                   3827:         my $toggle_catscomm_dom = ' checked="checked" ';
                   3828:         my $can_catcomm_comm = ' ';
                   3829:         my $can_catcomm_dom = ' checked="checked" ';
                   3830: 
1.57      raeburn  3831:         if (ref($settings) eq 'HASH') {
                   3832:             if ($settings->{'togglecats'} eq 'crs') {
                   3833:                 $toggle_cats_crs = $toggle_cats_dom;
                   3834:                 $toggle_cats_dom = ' ';
                   3835:             }
                   3836:             if ($settings->{'categorize'} eq 'crs') {
                   3837:                 $can_cat_crs = $can_cat_dom;
                   3838:                 $can_cat_dom = ' ';
                   3839:             }
1.120     raeburn  3840:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   3841:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   3842:                 $toggle_catscomm_dom = ' ';
                   3843:             }
                   3844:             if ($settings->{'categorizecomm'} eq 'comm') {
                   3845:                 $can_catcomm_comm = $can_catcomm_dom;
                   3846:                 $can_catcomm_dom = ' ';
                   3847:             }
1.57      raeburn  3848:         }
                   3849:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  3850:                      togglecats     => 'Show/Hide a course in catalog',
                   3851:                      togglecatscomm => 'Show/Hide a community in catalog',
                   3852:                      categorize     => 'Assign a category to a course',
                   3853:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  3854:                     );
                   3855:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  3856:                      dom  => 'Set in Domain',
                   3857:                      crs  => 'Set in Course',
                   3858:                      comm => 'Set in Community',
1.57      raeburn  3859:                     );
                   3860:         $datatable = '<tr class="LC_odd_row">'.
                   3861:                   '<td>'.$title{'togglecats'}.'</td>'.
                   3862:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3863:                   '<input type="radio" name="togglecats"'.
                   3864:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3865:                   '<label><input type="radio" name="togglecats"'.
                   3866:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   3867:                   '</tr><tr>'.
                   3868:                   '<td>'.$title{'categorize'}.'</td>'.
                   3869:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3870:                   '<label><input type="radio" name="categorize"'.
                   3871:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3872:                   '<label><input type="radio" name="categorize"'.
                   3873:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  3874:                   '</tr><tr class="LC_odd_row">'.
                   3875:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   3876:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3877:                   '<input type="radio" name="togglecatscomm"'.
                   3878:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3879:                   '<label><input type="radio" name="togglecatscomm"'.
                   3880:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   3881:                   '</tr><tr>'.
                   3882:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   3883:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3884:                   '<label><input type="radio" name="categorizecomm"'.
                   3885:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3886:                   '<label><input type="radio" name="categorizecomm"'.
                   3887:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  3888:                   '</tr>';
1.120     raeburn  3889:         $$rowtotal += 4;
1.57      raeburn  3890:     } else {
                   3891:         my $css_class;
                   3892:         my $itemcount = 1;
                   3893:         my $cathash; 
                   3894:         if (ref($settings) eq 'HASH') {
                   3895:             $cathash = $settings->{'cats'};
                   3896:         }
                   3897:         if (ref($cathash) eq 'HASH') {
                   3898:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   3899:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   3900:                                                    \%allitems,\%idx,\@jsarray);
                   3901:             my $maxdepth = scalar(@cats);
                   3902:             my $colattrib = '';
                   3903:             if ($maxdepth > 2) {
                   3904:                 $colattrib = ' colspan="2" ';
                   3905:             }
                   3906:             my @path;
                   3907:             if (@cats > 0) {
                   3908:                 if (ref($cats[0]) eq 'ARRAY') {
                   3909:                     my $numtop = @{$cats[0]};
                   3910:                     my $maxnum = $numtop;
1.120     raeburn  3911:                     my %default_names = (
                   3912:                           instcode    => &mt('Official courses'),
                   3913:                           communities => &mt('Communities'),
                   3914:                     );
                   3915: 
                   3916:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   3917:                         ($cathash->{'instcode::0'} eq '') ||
                   3918:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   3919:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  3920:                         $maxnum ++;
                   3921:                     }
                   3922:                     my $lastidx;
                   3923:                     for (my $i=0; $i<$numtop; $i++) {
                   3924:                         my $parent = $cats[0][$i];
                   3925:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3926:                         my $item = &escape($parent).'::0';
                   3927:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   3928:                         $lastidx = $idx{$item};
                   3929:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3930:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   3931:                         for (my $k=0; $k<=$maxnum; $k++) {
                   3932:                             my $vpos = $k+1;
                   3933:                             my $selstr;
                   3934:                             if ($k == $i) {
                   3935:                                 $selstr = ' selected="selected" ';
                   3936:                             }
                   3937:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3938:                         }
                   3939:                         $datatable .= '</select></td><td>';
1.120     raeburn  3940:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   3941:                             $datatable .=  '<span class="LC_nobreak">'
                   3942:                                            .$default_names{$parent}.'</span>';
                   3943:                             if ($parent eq 'instcode') {
                   3944:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   3945:                                               .&mt('with institutional codes')
                   3946:                                               .')</span></td><td'.$colattrib.'>';
                   3947:                             } else {
                   3948:                                 $datatable .= '<table><tr><td>';
                   3949:                             }
                   3950:                             $datatable .= '<span class="LC_nobreak">'
                   3951:                                           .'<label><input type="radio" name="'
                   3952:                                           .$parent.'" value="1" checked="checked" />'
                   3953:                                           .&mt('Display').'</label>';
                   3954:                             if ($parent eq 'instcode') {
                   3955:                                 $datatable .= '&nbsp;';
                   3956:                             } else {
                   3957:                                 $datatable .= '</span></td></tr><tr><td>'
                   3958:                                               .'<span class="LC_nobreak">';
                   3959:                             }
                   3960:                             $datatable .= '<label><input type="radio" name="'
                   3961:                                           .$parent.'" value="0" />'
                   3962:                                           .&mt('Do not display').'</label></span>';
                   3963:                             if ($parent eq 'communities') {
                   3964:                                 $datatable .= '</td></tr></table>';
                   3965:                             }
                   3966:                             $datatable .= '</td>';
1.57      raeburn  3967:                         } else {
                   3968:                             $datatable .= $parent
                   3969:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                   3970:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   3971:                         }
                   3972:                         my $depth = 1;
                   3973:                         push(@path,$parent);
                   3974:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   3975:                         pop(@path);
                   3976:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   3977:                         $itemcount ++;
                   3978:                     }
1.48      raeburn  3979:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  3980:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   3981:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  3982:                     for (my $k=0; $k<=$maxnum; $k++) {
                   3983:                         my $vpos = $k+1;
                   3984:                         my $selstr;
1.57      raeburn  3985:                         if ($k == $numtop) {
1.48      raeburn  3986:                             $selstr = ' selected="selected" ';
                   3987:                         }
                   3988:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3989:                     }
1.59      bisitz   3990:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  3991:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   3992:                                   .'</tr>'."\n";
1.48      raeburn  3993:                     $itemcount ++;
1.120     raeburn  3994:                     foreach my $default ('instcode','communities') {
                   3995:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   3996:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3997:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   3998:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   3999:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   4000:                             for (my $k=0; $k<=$maxnum; $k++) {
                   4001:                                 my $vpos = $k+1;
                   4002:                                 my $selstr;
                   4003:                                 if ($k == $maxnum) {
                   4004:                                     $selstr = ' selected="selected" ';
                   4005:                                 }
                   4006:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  4007:                             }
1.120     raeburn  4008:                             $datatable .= '</select></span></td>'.
                   4009:                                           '<td><span class="LC_nobreak">'.
                   4010:                                           $default_names{$default}.'</span>';
                   4011:                             if ($default eq 'instcode') {
                   4012:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   4013:                                               .&mt('with institutional codes').')</span>';
                   4014:                             }
                   4015:                             $datatable .= '</td>'
                   4016:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   4017:                                           .&mt('Display').'</label>&nbsp;'
                   4018:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   4019:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  4020:                         }
                   4021:                     }
                   4022:                 }
1.57      raeburn  4023:             } else {
                   4024:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  4025:             }
                   4026:         } else {
1.57      raeburn  4027:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   4028:                           .&initialize_categories($itemcount);
1.48      raeburn  4029:         }
1.57      raeburn  4030:         $$rowtotal += $itemcount;
1.48      raeburn  4031:     }
                   4032:     return $datatable;
                   4033: }
                   4034: 
1.69      raeburn  4035: sub print_serverstatuses {
                   4036:     my ($dom,$settings,$rowtotal) = @_;
                   4037:     my $datatable;
                   4038:     my @pages = &serverstatus_pages();
                   4039:     my (%namedaccess,%machineaccess);
                   4040:     foreach my $type (@pages) {
                   4041:         $namedaccess{$type} = '';
                   4042:         $machineaccess{$type}= '';
                   4043:     }
                   4044:     if (ref($settings) eq 'HASH') {
                   4045:         foreach my $type (@pages) {
                   4046:             if (exists($settings->{$type})) {
                   4047:                 if (ref($settings->{$type}) eq 'HASH') {
                   4048:                     foreach my $key (keys(%{$settings->{$type}})) {
                   4049:                         if ($key eq 'namedusers') {
                   4050:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   4051:                         } elsif ($key eq 'machines') {
                   4052:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   4053:                         }
                   4054:                     }
                   4055:                 }
                   4056:             }
                   4057:         }
                   4058:     }
1.81      raeburn  4059:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  4060:     my $rownum = 0;
                   4061:     my $css_class;
                   4062:     foreach my $type (@pages) {
                   4063:         $rownum ++;
                   4064:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4065:         $datatable .= '<tr'.$css_class.'>'.
                   4066:                       '<td><span class="LC_nobreak">'.
                   4067:                       $titles->{$type}.'</span></td>'.
                   4068:                       '<td class="LC_left_item">'.
                   4069:                       '<input type="text" name="'.$type.'_namedusers" '.
                   4070:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   4071:                       '<td class="LC_right_item">'.
                   4072:                       '<span class="LC_nobreak">'.
                   4073:                       '<input type="text" name="'.$type.'_machines" '.
                   4074:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   4075:                       '</td></tr>'."\n";
                   4076:     }
                   4077:     $$rowtotal += $rownum;
                   4078:     return $datatable;
                   4079: }
                   4080: 
                   4081: sub serverstatus_pages {
                   4082:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
                   4083:             'clusterstatus','metadata_keywords','metadata_harvest',
1.156     raeburn  4084:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69      raeburn  4085: }
                   4086: 
1.49      raeburn  4087: sub coursecategories_javascript {
                   4088:     my ($settings) = @_;
1.57      raeburn  4089:     my ($output,$jstext,$cathash);
1.49      raeburn  4090:     if (ref($settings) eq 'HASH') {
1.57      raeburn  4091:         $cathash = $settings->{'cats'};
                   4092:     }
                   4093:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  4094:         my (@cats,@jsarray,%idx);
1.57      raeburn  4095:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  4096:         if (@jsarray > 0) {
                   4097:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   4098:             for (my $i=0; $i<@jsarray; $i++) {
                   4099:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   4100:                     my $catstr = join('","',@{$jsarray[$i]});
                   4101:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   4102:                 }
                   4103:             }
                   4104:         }
                   4105:     } else {
                   4106:         $jstext  = '    var categories = Array(1);'."\n".
                   4107:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   4108:     }
1.120     raeburn  4109:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   4110:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   4111:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  4112:     $output = <<"ENDSCRIPT";
                   4113: <script type="text/javascript">
1.109     raeburn  4114: // <![CDATA[
1.49      raeburn  4115: function reorderCats(form,parent,item,idx) {
                   4116:     var changedVal;
                   4117: $jstext
                   4118:     var newpos = 'addcategory_pos';
                   4119:     var current = new Array;
                   4120:     if (parent == '') {
                   4121:         var has_instcode = 0;
                   4122:         var maxtop = categories[idx].length;
                   4123:         for (var j=0; j<maxtop; j++) {
                   4124:             if (categories[idx][j] == 'instcode::0') {
                   4125:                 has_instcode == 1;
                   4126:             }
                   4127:         }
                   4128:         if (has_instcode == 0) {
                   4129:             categories[idx][maxtop] = 'instcode_pos';
                   4130:         }
                   4131:     } else {
                   4132:         newpos += '_'+parent;
                   4133:     }
                   4134:     var maxh = 1 + categories[idx].length;
                   4135:     var current = new Array;
                   4136:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4137:     if (item == newpos) {
                   4138:         changedVal = newitemVal;
                   4139:     } else {
                   4140:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4141:         current[newitemVal] = newpos;
                   4142:     }
                   4143:     for (var i=0; i<categories[idx].length; i++) {
                   4144:         var elementName = categories[idx][i];
                   4145:         if (elementName != item) {
                   4146:             if (form.elements[elementName]) {
                   4147:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4148:                 current[currVal] = elementName;
                   4149:             }
                   4150:         }
                   4151:     }
                   4152:     var oldVal;
                   4153:     for (var j=0; j<maxh; j++) {
                   4154:         if (current[j] == undefined) {
                   4155:             oldVal = j;
                   4156:         }
                   4157:     }
                   4158:     if (oldVal < changedVal) {
                   4159:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4160:            var elementName = current[k];
                   4161:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4162:         }
                   4163:     } else {
                   4164:         for (var k=changedVal; k<oldVal; k++) {
                   4165:             var elementName = current[k];
                   4166:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4167:         }
                   4168:     }
                   4169:     return;
                   4170: }
1.120     raeburn  4171: 
                   4172: function categoryCheck(form) {
                   4173:     if (form.elements['addcategory_name'].value == 'instcode') {
                   4174:         alert('$instcode_reserved\\n$choose_again');
                   4175:         return false;
                   4176:     }
                   4177:     if (form.elements['addcategory_name'].value == 'communities') {
                   4178:         alert('$communities_reserved\\n$choose_again');
                   4179:         return false;
                   4180:     }
                   4181:     return true;
                   4182: }
                   4183: 
1.109     raeburn  4184: // ]]>
1.49      raeburn  4185: </script>
                   4186: 
                   4187: ENDSCRIPT
                   4188:     return $output;
                   4189: }
                   4190: 
1.48      raeburn  4191: sub initialize_categories {
                   4192:     my ($itemcount) = @_;
1.120     raeburn  4193:     my ($datatable,$css_class,$chgstr);
                   4194:     my %default_names = (
                   4195:                       instcode    => 'Official courses (with institutional codes)',
                   4196:                       communities => 'Communities',
                   4197:                         );
                   4198:     my $select0 = ' selected="selected"';
                   4199:     my $select1 = '';
                   4200:     foreach my $default ('instcode','communities') {
                   4201:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4202:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   4203:         if ($default eq 'communities') {
                   4204:             $select1 = $select0;
                   4205:             $select0 = '';
                   4206:         }
                   4207:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4208:                      .'<select name="'.$default.'_pos">'
                   4209:                      .'<option value="0"'.$select0.'>1</option>'
                   4210:                      .'<option value="1"'.$select1.'>2</option>'
                   4211:                      .'<option value="2">3</option></select>&nbsp;'
                   4212:                      .$default_names{$default}
                   4213:                      .'</span></td><td><span class="LC_nobreak">'
                   4214:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   4215:                      .&mt('Display').'</label>&nbsp;<label>'
                   4216:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  4217:                  .'</label></span></td></tr>';
1.120     raeburn  4218:         $itemcount ++;
                   4219:     }
1.48      raeburn  4220:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  4221:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4222:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4223:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4224:                   .'<option value="0">1</option>'
                   4225:                   .'<option value="1">2</option>'
                   4226:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4227:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4228:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4229:     return $datatable;
                   4230: }
                   4231: 
                   4232: sub build_category_rows {
1.49      raeburn  4233:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4234:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4235:     if (ref($cats) eq 'ARRAY') {
                   4236:         my $maxdepth = scalar(@{$cats});
                   4237:         if (ref($cats->[$depth]) eq 'HASH') {
                   4238:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4239:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4240:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4241:                 $text .= '<td><table class="LC_datatable">';
1.49      raeburn  4242:                 my ($idxnum,$parent_name,$parent_item);
                   4243:                 my $higher = $depth - 1;
                   4244:                 if ($higher == 0) {
                   4245:                     $parent_name = &escape($parent).'::'.$higher;
                   4246:                 } else {
                   4247:                     if (ref($path) eq 'ARRAY') {
                   4248:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4249:                     }
                   4250:                 }
                   4251:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4252:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4253:                     if ($j < $numchildren) {
1.48      raeburn  4254:                         $name = $cats->[$depth]{$parent}[$j];
                   4255:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4256:                         $idxnum = $idx->{$item};
                   4257:                     } else {
                   4258:                         $name = $parent_name;
                   4259:                         $item = $parent_item;
1.48      raeburn  4260:                     }
1.49      raeburn  4261:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4262:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  4263:                     for (my $i=0; $i<=$numchildren; $i++) {
                   4264:                         my $vpos = $i+1;
                   4265:                         my $selstr;
                   4266:                         if ($j == $i) {
                   4267:                             $selstr = ' selected="selected" ';
                   4268:                         }
                   4269:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   4270:                     }
                   4271:                     $text .= '</select>&nbsp;';
                   4272:                     if ($j < $numchildren) {
                   4273:                         my $deeper = $depth+1;
                   4274:                         $text .= $name.'&nbsp;'
                   4275:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   4276:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   4277:                         if(ref($path) eq 'ARRAY') {
                   4278:                             push(@{$path},$name);
1.49      raeburn  4279:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  4280:                             pop(@{$path});
                   4281:                         }
                   4282:                     } else {
1.59      bisitz   4283:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  4284:                         if ($j == $numchildren) {
                   4285:                             $text .= $name;
                   4286:                         } else {
                   4287:                             $text .= $item;
                   4288:                         }
                   4289:                         $text .= '" value="" />';
                   4290:                     }
                   4291:                     $text .= '</td></tr>';
                   4292:                 }
                   4293:                 $text .= '</table></td>';
                   4294:             } else {
                   4295:                 my $higher = $depth-1;
                   4296:                 if ($higher == 0) {
                   4297:                     $name = &escape($parent).'::'.$higher;
                   4298:                 } else {
                   4299:                     if (ref($path) eq 'ARRAY') {
                   4300:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4301:                     }
                   4302:                 }
                   4303:                 my $colspan;
                   4304:                 if ($parent ne 'instcode') {
                   4305:                     $colspan = $maxdepth - $depth - 1;
                   4306:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   4307:                 }
                   4308:             }
                   4309:         }
                   4310:     }
                   4311:     return $text;
                   4312: }
                   4313: 
1.33      raeburn  4314: sub modifiable_userdata_row {
1.63      raeburn  4315:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33      raeburn  4316:     my $rolename;
1.63      raeburn  4317:     if ($context eq 'selfcreate') {
                   4318:         if (ref($usertypes) eq 'HASH') {
                   4319:             $rolename = $usertypes->{$role};
                   4320:         } else {
                   4321:             $rolename = $role;
                   4322:         }
1.33      raeburn  4323:     } else {
1.63      raeburn  4324:         if ($role eq 'cr') {
                   4325:             $rolename = &mt('Custom role');
                   4326:         } else {
                   4327:             $rolename = &Apache::lonnet::plaintext($role);
                   4328:         }
1.33      raeburn  4329:     }
                   4330:     my @fields = ('lastname','firstname','middlename','generation',
                   4331:                   'permanentemail','id');
                   4332:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4333:     my $output;
                   4334:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4335:     $output = '<tr '.$css_class.'>'.
                   4336:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   4337:               '<td class="LC_left_item" colspan="2"><table>';
                   4338:     my $rem;
                   4339:     my %checks;
                   4340:     if (ref($settings) eq 'HASH') {
                   4341:         if (ref($settings->{$context}) eq 'HASH') {
                   4342:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   4343:                 foreach my $field (@fields) {
                   4344:                     if ($settings->{$context}->{$role}->{$field}) {
                   4345:                         $checks{$field} = ' checked="checked" ';
                   4346:                     }
                   4347:                 }
                   4348:             }
                   4349:         }
                   4350:     }
                   4351:     for (my $i=0; $i<@fields; $i++) {
                   4352:         my $rem = $i%($numinrow);
                   4353:         if ($rem == 0) {
                   4354:             if ($i > 0) {
                   4355:                 $output .= '</tr>';
                   4356:             }
                   4357:             $output .= '<tr>';
                   4358:         }
                   4359:         my $check = ' ';
                   4360:         if (exists($checks{$fields[$i]})) {
                   4361:             $check = $checks{$fields[$i]}
                   4362:         } else {
                   4363:             if ($role eq 'st') {
                   4364:                 if (ref($settings) ne 'HASH') {
                   4365:                     $check = ' checked="checked" '; 
                   4366:                 }
                   4367:             }
                   4368:         }
                   4369:         $output .= '<td class="LC_left_item">'.
                   4370:                    '<span class="LC_nobreak"><label>'.
                   4371:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   4372:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   4373:                    '</label></span></td>';
                   4374:         $rem = @fields%($numinrow);
                   4375:     }
                   4376:     my $colsleft = $numinrow - $rem;
                   4377:     if ($colsleft > 1 ) {
                   4378:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4379:                    '&nbsp;</td>';
                   4380:     } elsif ($colsleft == 1) {
                   4381:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4382:     }
                   4383:     $output .= '</tr></table></td></tr>';
                   4384:     return $output;
                   4385: }
1.28      raeburn  4386: 
1.93      raeburn  4387: sub insttypes_row {
                   4388:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
                   4389:     my %lt = &Apache::lonlocal::texthash (
                   4390:                       cansearch => 'Users allowed to search',
                   4391:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  4392:                       lockablenames => 'User preference to lock name',
1.93      raeburn  4393:              );
                   4394:     my $showdom;
                   4395:     if ($context eq 'cansearch') {
                   4396:         $showdom = ' ('.$dom.')';
                   4397:     }
1.165     raeburn  4398:     my $class = 'LC_left_item';
                   4399:     if ($context eq 'statustocreate') {
                   4400:         $class = 'LC_right_item';
                   4401:     }
1.25      raeburn  4402:     my $output =  '<tr class="LC_odd_row">'.
1.93      raeburn  4403:                   '<td>'.$lt{$context}.$showdom.
1.165     raeburn  4404:                   '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  4405:     my $rem;
                   4406:     if (ref($types) eq 'ARRAY') {
                   4407:         for (my $i=0; $i<@{$types}; $i++) {
                   4408:             if (defined($usertypes->{$types->[$i]})) {
                   4409:                 my $rem = $i%($numinrow);
                   4410:                 if ($rem == 0) {
                   4411:                     if ($i > 0) {
                   4412:                         $output .= '</tr>';
                   4413:                     }
                   4414:                     $output .= '<tr>';
1.23      raeburn  4415:                 }
1.26      raeburn  4416:                 my $check = ' ';
1.99      raeburn  4417:                 if (ref($settings) eq 'HASH') {
                   4418:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   4419:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   4420:                             $check = ' checked="checked" ';
                   4421:                         }
                   4422:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  4423:                         $check = ' checked="checked" ';
                   4424:                     }
1.23      raeburn  4425:                 }
1.26      raeburn  4426:                 $output .= '<td class="LC_left_item">'.
                   4427:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  4428:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  4429:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   4430:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  4431:             }
                   4432:         }
1.26      raeburn  4433:         $rem = @{$types}%($numinrow);
1.23      raeburn  4434:     }
                   4435:     my $colsleft = $numinrow - $rem;
1.131     raeburn  4436:     if (($rem == 0) && (@{$types} > 0)) {
                   4437:         $output .= '<tr>';
                   4438:     }
1.23      raeburn  4439:     if ($colsleft > 1) {
1.25      raeburn  4440:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  4441:     } else {
1.25      raeburn  4442:         $output .= '<td class="LC_left_item">';
1.23      raeburn  4443:     }
                   4444:     my $defcheck = ' ';
1.99      raeburn  4445:     if (ref($settings) eq 'HASH') {  
                   4446:         if (ref($settings->{$context}) eq 'ARRAY') {
                   4447:             if (grep(/^default$/,@{$settings->{$context}})) {
                   4448:                 $defcheck = ' checked="checked" ';
                   4449:             }
                   4450:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  4451:             $defcheck = ' checked="checked" ';
                   4452:         }
1.23      raeburn  4453:     }
1.25      raeburn  4454:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  4455:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  4456:                'value="default"'.$defcheck.'/>'.
                   4457:                $othertitle.'</label></span></td>'.
                   4458:                '</tr></table></td></tr>';
                   4459:     return $output;
1.23      raeburn  4460: }
                   4461: 
                   4462: sub sorted_searchtitles {
                   4463:     my %searchtitles = &Apache::lonlocal::texthash(
                   4464:                          'uname' => 'username',
                   4465:                          'lastname' => 'last name',
                   4466:                          'lastfirst' => 'last name, first name',
                   4467:                      );
                   4468:     my @titleorder = ('uname','lastname','lastfirst');
                   4469:     return (\%searchtitles,\@titleorder);
                   4470: }
                   4471: 
1.25      raeburn  4472: sub sorted_searchtypes {
                   4473:     my %srchtypes_desc = (
                   4474:                            exact    => 'is exact match',
                   4475:                            contains => 'contains ..',
                   4476:                            begins   => 'begins with ..',
                   4477:                          );
                   4478:     my @srchtypeorder = ('exact','begins','contains');
                   4479:     return (\%srchtypes_desc,\@srchtypeorder);
                   4480: }
                   4481: 
1.3       raeburn  4482: sub usertype_update_row {
                   4483:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   4484:     my $datatable;
                   4485:     my $numinrow = 4;
                   4486:     foreach my $type (@{$types}) {
                   4487:         if (defined($usertypes->{$type})) {
                   4488:             $$rownums ++;
                   4489:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   4490:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   4491:                           '</td><td class="LC_left_item"><table>';
                   4492:             for (my $i=0; $i<@{$fields}; $i++) {
                   4493:                 my $rem = $i%($numinrow);
                   4494:                 if ($rem == 0) {
                   4495:                     if ($i > 0) {
                   4496:                         $datatable .= '</tr>';
                   4497:                     }
                   4498:                     $datatable .= '<tr>';
                   4499:                 }
                   4500:                 my $check = ' ';
1.39      raeburn  4501:                 if (ref($settings) eq 'HASH') {
                   4502:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   4503:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   4504:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   4505:                                 $check = ' checked="checked" ';
                   4506:                             }
1.3       raeburn  4507:                         }
                   4508:                     }
                   4509:                 }
                   4510: 
                   4511:                 if ($i == @{$fields}-1) {
                   4512:                     my $colsleft = $numinrow - $rem;
                   4513:                     if ($colsleft > 1) {
                   4514:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   4515:                     } else {
                   4516:                         $datatable .= '<td>';
                   4517:                     }
                   4518:                 } else {
                   4519:                     $datatable .= '<td>';
                   4520:                 }
1.8       raeburn  4521:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4522:                               '<input type="checkbox" name="updateable_'.$type.
                   4523:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   4524:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  4525:             }
                   4526:             $datatable .= '</tr></table></td></tr>';
                   4527:         }
                   4528:     }
                   4529:     return $datatable;
1.1       raeburn  4530: }
                   4531: 
                   4532: sub modify_login {
1.9       raeburn  4533:     my ($r,$dom,$confname,%domconfig) = @_;
1.168     raeburn  4534:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   4535:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   4536:     %title = ( coursecatalog => 'Display course catalog',
                   4537:                adminmail => 'Display administrator E-mail address',
                   4538:                newuser => 'Link for visitors to create a user account',
                   4539:                loginheader => 'Log-in box header');
                   4540:     @offon = ('off','on');
1.112     raeburn  4541:     if (ref($domconfig{login}) eq 'HASH') {
                   4542:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   4543:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   4544:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   4545:             }
                   4546:         }
                   4547:     }
1.9       raeburn  4548:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   4549:                                            \%domconfig,\%loginhash);
1.118     jms      4550:     my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4551:     foreach my $item (@toggles) {
                   4552:         $loginhash{login}{$item} = $env{'form.'.$item};
                   4553:     }
1.41      raeburn  4554:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  4555:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   4556:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   4557:                                          \%loginhash);
                   4558:     }
1.110     raeburn  4559: 
1.149     raeburn  4560:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  4561:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  4562:     if (keys(%servers) > 1) {
                   4563:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  4564:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   4565:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   4566:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   4567:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   4568:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   4569:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4570:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4571:                         $changes{'loginvia'}{$lonhost} = 1;
                   4572:                     } else {
                   4573:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   4574:                         $changes{'loginvia'}{$lonhost} = 1;
                   4575:                     }
                   4576:                 } else {
                   4577:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4578:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4579:                         $changes{'loginvia'}{$lonhost} = 1;
                   4580:                     }
                   4581:                 }
                   4582:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   4583:                     foreach my $item (@loginvia_attribs) {
                   4584:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   4585:                     }
                   4586:                 } else {
                   4587:                     foreach my $item (@loginvia_attribs) {
                   4588:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4589:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4590:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   4591:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4592:                                 $new = '/';
                   4593:                             }
                   4594:                         }
                   4595:                         if (($item eq 'custompath') && 
                   4596:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4597:                             $new = '';
                   4598:                         }
                   4599:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   4600:                             $changes{'loginvia'}{$lonhost} = 1;
                   4601:                         }
                   4602:                         if ($item eq 'exempt') {
                   4603:                             $new =~ s/^\s+//;
                   4604:                             $new =~ s/\s+$//;
                   4605:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   4606:                             my @okips;
                   4607:                             foreach my $ip (@poss_ips) {
                   4608:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   4609:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   4610:                                         push(@okips,$ip); 
                   4611:                                     }
                   4612:                                 }
                   4613:                             }
                   4614:                             if (@okips > 0) {
                   4615:                                 $new = join(',',@okips); 
                   4616:                             } else {
                   4617:                                 $new = ''; 
                   4618:                             }
                   4619:                         }
                   4620:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4621:                     }
                   4622:                 }
1.112     raeburn  4623:             } else {
1.128     raeburn  4624:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4625:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  4626:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  4627:                     foreach my $item (@loginvia_attribs) {
                   4628:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4629:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4630:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4631:                                 $new = '/';
                   4632:                             }
                   4633:                         }
                   4634:                         if (($item eq 'custompath') && 
                   4635:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4636:                             $new = '';
                   4637:                         }
                   4638:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4639:                     }
1.110     raeburn  4640:                 }
                   4641:             }
                   4642:         }
                   4643:     }
1.119     raeburn  4644: 
1.168     raeburn  4645:     my $servadm = $r->dir_config('lonAdmEMail');
                   4646:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   4647:     if (ref($domconfig{'login'}) eq 'HASH') {
                   4648:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   4649:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   4650:                 if ($lang eq 'nolang') {
                   4651:                     push(@currlangs,$lang);
                   4652:                 } elsif (defined($langchoices{$lang})) {
                   4653:                     push(@currlangs,$lang);
                   4654:                 } else {
                   4655:                     next;
                   4656:                 }
                   4657:             }
                   4658:         }
                   4659:     }
                   4660:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   4661:     if (@currlangs > 0) {
                   4662:         foreach my $lang (@currlangs) {
                   4663:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   4664:                 $changes{'helpurl'}{$lang} = 1;
                   4665:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   4666:                 $changes{'helpurl'}{$lang} = 1;
                   4667:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   4668:                 push(@newlangs,$lang);
                   4669:             } else {
                   4670:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4671:             }
                   4672:         }
                   4673:     }
                   4674:     unless (grep(/^nolang$/,@currlangs)) {
                   4675:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   4676:             $changes{'helpurl'}{'nolang'} = 1;
                   4677:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   4678:             push(@newlangs,'nolang');
                   4679:         }
                   4680:     }
                   4681:     if ($env{'form.loginhelpurl_add_lang'}) {
                   4682:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   4683:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   4684:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   4685:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   4686:         }
                   4687:     }
                   4688:     if ((@newlangs > 0) || ($addedfile)) {
                   4689:         my $error;
                   4690:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   4691:         if ($configuserok eq 'ok') {
                   4692:             if ($switchserver) {
                   4693:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   4694:             } elsif ($author_ok eq 'ok') {
                   4695:                 my @allnew = @newlangs;
                   4696:                 if ($addedfile ne '') {
                   4697:                     push(@allnew,$addedfile);
                   4698:                 }
                   4699:                 foreach my $lang (@allnew) {
                   4700:                     my $formelem = 'loginhelpurl_'.$lang;
                   4701:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   4702:                         $formelem = 'loginhelpurl_add_file';
                   4703:                     }
                   4704:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   4705:                                                                "help/$lang",'','',$newfile{$lang});
                   4706:                     if ($result eq 'ok') {
                   4707:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   4708:                         $changes{'helpurl'}{$lang} = 1;
                   4709:                     } else {
                   4710:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   4711:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   4712:                         if ((grep(/^\Q$lang\E$/,@currlangs)) && 
                   4713:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   4714: 
                   4715:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4716:                         }
                   4717:                     }
                   4718:                 }
                   4719:             } else {
                   4720:                 $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);
                   4721:             }
                   4722:         } else {
                   4723:             $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);
                   4724:         }
                   4725:         if ($error) {
                   4726:             &Apache::lonnet::logthis($error);
                   4727:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   4728:         }
                   4729:     }
1.169   ! raeburn  4730:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  4731: 
                   4732:     my $defaulthelpfile = '/adm/loginproblems.html';
                   4733:     my $defaulttext = &mt('Default in use');
                   4734: 
1.1       raeburn  4735:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   4736:                                              $dom);
                   4737:     if ($putresult eq 'ok') {
1.118     jms      4738:         my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4739:         my %defaultchecked = (
                   4740:                     'coursecatalog' => 'on',
                   4741:                     'adminmail'     => 'off',
1.43      raeburn  4742:                     'newuser'       => 'off',
1.42      raeburn  4743:         );
1.55      raeburn  4744:         if (ref($domconfig{'login'}) eq 'HASH') {
                   4745:             foreach my $item (@toggles) {
                   4746:                 if ($defaultchecked{$item} eq 'on') { 
                   4747:                     if (($domconfig{'login'}{$item} eq '0') &&
                   4748:                         ($env{'form.'.$item} eq '1')) {
                   4749:                         $changes{$item} = 1;
                   4750:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4751:                               $domconfig{'login'}{$item} eq '1') &&
                   4752:                              ($env{'form.'.$item} eq '0')) {
                   4753:                         $changes{$item} = 1;
                   4754:                     }
                   4755:                 } elsif ($defaultchecked{$item} eq 'off') {
                   4756:                     if (($domconfig{'login'}{$item} eq '1') &&
                   4757:                         ($env{'form.'.$item} eq '0')) {
                   4758:                         $changes{$item} = 1;
                   4759:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4760:                               $domconfig{'login'}{$item} eq '0') &&
                   4761:                              ($env{'form.'.$item} eq '1')) {
                   4762:                         $changes{$item} = 1;
                   4763:                     }
1.42      raeburn  4764:                 }
                   4765:             }
1.41      raeburn  4766:         }
1.6       raeburn  4767:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  4768:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1       raeburn  4769:             $resulttext = &mt('Changes made:').'<ul>';
                   4770:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   4771:                 if ($item eq 'loginvia') {
1.112     raeburn  4772:                     if (ref($changes{$item}) eq 'HASH') {
                   4773:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   4774:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  4775:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   4776:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   4777:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   4778:                                     $protocol = 'http' if ($protocol ne 'https');
                   4779:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   4780: 
                   4781:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   4782:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   4783:                                     } else {
                   4784:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   4785:                                     }
                   4786:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   4787:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   4788:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   4789:                                     }
                   4790:                                     $resulttext .= '</li>';
                   4791:                                 } else {
                   4792:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   4793:                                 }
1.112     raeburn  4794:                             } else {
1.128     raeburn  4795:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  4796:                             }
                   4797:                         }
1.128     raeburn  4798:                         $resulttext .= '</ul></li>';
1.112     raeburn  4799:                     }
1.168     raeburn  4800:                 } elsif ($item eq 'helpurl') {
                   4801:                     if (ref($changes{$item}) eq 'HASH') {
                   4802:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   4803:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   4804:                                 my ($chg,$link);
                   4805:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   4806:                                 if ($lang eq 'nolang') {
                   4807:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   4808:                                 } else {
                   4809:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   4810:                                 }
                   4811:                                 $resulttext .= '<li>'.$chg.'</li>';
                   4812:                             } else {
                   4813:                                 my $chg;
                   4814:                                 if ($lang eq 'nolang') {
                   4815:                                     $chg = &mt('custom log-in help file for no preferred language');
                   4816:                                 } else {
                   4817:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   4818:                                 }
                   4819:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   4820:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   4821:                                                       '?inhibitmenu=yes',$chg,600,500).
                   4822:                                                '</li>';
                   4823:                             }
                   4824:                         }
                   4825:                     }
1.169   ! raeburn  4826:                 } elsif ($item eq 'captcha') {
        !          4827:                     if (ref($loginhash{'login'}) eq 'HASH') {
        !          4828:                         my $chgtxt; 
        !          4829:                         if ($loginhash{'login'}{$item} eq 'notused') {
        !          4830:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
        !          4831:                         } else {
        !          4832:                             my %captchas = &captcha_phrases();
        !          4833:                             if ($captchas{$loginhash{'login'}{$item}}) {
        !          4834:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
        !          4835:                             } else {
        !          4836:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
        !          4837:                             }
        !          4838:                         }
        !          4839:                         $resulttext .= '<li>'.$chgtxt.'</li>';
        !          4840:                     }
        !          4841:                 } elsif ($item eq 'recaptchakeys') {
        !          4842:                     if (ref($loginhash{'login'}) eq 'HASH') {
        !          4843:                         my ($privkey,$pubkey);
        !          4844:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
        !          4845:                             $pubkey = $loginhash{'login'}{$item}{'public'};
        !          4846:                             $privkey = $loginhash{'login'}{$item}{'private'};
        !          4847:                         }
        !          4848:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
        !          4849:                         if (!$pubkey) {
        !          4850:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
        !          4851:                         } else {
        !          4852:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
        !          4853:                         }
        !          4854:                         if (!$privkey) {
        !          4855:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
        !          4856:                         } else {
        !          4857:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
        !          4858:                         }
        !          4859:                         $chgtxt .= '</ul>';
        !          4860:                         $resulttext .= '<li>'.$chgtxt.'</li>';
        !          4861:                     }
1.41      raeburn  4862:                 } else {
                   4863:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   4864:                 }
1.1       raeburn  4865:             }
1.6       raeburn  4866:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  4867:         } else {
                   4868:             $resulttext = &mt('No changes made to log-in page settings');
                   4869:         }
                   4870:     } else {
1.11      albertel 4871:         $resulttext = '<span class="LC_error">'.
                   4872: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  4873:     }
1.6       raeburn  4874:     if ($errors) {
1.9       raeburn  4875:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  4876:                        $errors.'</ul>';
                   4877:     }
                   4878:     return $resulttext;
                   4879: }
                   4880: 
                   4881: sub color_font_choices {
                   4882:     my %choices =
                   4883:         &Apache::lonlocal::texthash (
                   4884:             img => "Header",
                   4885:             bgs => "Background colors",
                   4886:             links => "Link colors",
1.55      raeburn  4887:             images => "Images",
1.6       raeburn  4888:             font => "Font color",
1.97      tempelho 4889:             fontmenu => "Font Menu",
1.76      raeburn  4890:             pgbg => "Page",
1.6       raeburn  4891:             tabbg => "Header",
                   4892:             sidebg => "Border",
                   4893:             link => "Link",
                   4894:             alink => "Active link",
                   4895:             vlink => "Visited link",
                   4896:         );
                   4897:     return %choices;
                   4898: }
                   4899: 
                   4900: sub modify_rolecolors {
1.9       raeburn  4901:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6       raeburn  4902:     my ($resulttext,%rolehash);
                   4903:     $rolehash{'rolecolors'} = {};
1.55      raeburn  4904:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   4905:         if ($domconfig{'rolecolors'} eq '') {
                   4906:             $domconfig{'rolecolors'} = {};
                   4907:         }
                   4908:     }
1.9       raeburn  4909:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  4910:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   4911:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   4912:                                              $dom);
                   4913:     if ($putresult eq 'ok') {
                   4914:         if (keys(%changes) > 0) {
1.41      raeburn  4915:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6       raeburn  4916:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   4917:                                              $rolehash{'rolecolors'});
                   4918:         } else {
                   4919:             $resulttext = &mt('No changes made to default color schemes');
                   4920:         }
                   4921:     } else {
1.11      albertel 4922:         $resulttext = '<span class="LC_error">'.
                   4923: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  4924:     }
                   4925:     if ($errors) {
                   4926:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   4927:                        $errors.'</ul>';
                   4928:     }
                   4929:     return $resulttext;
                   4930: }
                   4931: 
                   4932: sub modify_colors {
1.9       raeburn  4933:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  4934:     my (%changes,%choices);
1.51      raeburn  4935:     my @bgs;
1.6       raeburn  4936:     my @links = ('link','alink','vlink');
1.41      raeburn  4937:     my @logintext;
1.6       raeburn  4938:     my @images;
                   4939:     my $servadm = $r->dir_config('lonAdmEMail');
                   4940:     my $errors;
                   4941:     foreach my $role (@{$roles}) {
                   4942:         if ($role eq 'login') {
1.12      raeburn  4943:             %choices = &login_choices();
1.41      raeburn  4944:             @logintext = ('textcol','bgcol');
1.12      raeburn  4945:         } else {
                   4946:             %choices = &color_font_choices();
1.107     raeburn  4947:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12      raeburn  4948:         }
                   4949:         if ($role eq 'login') {
1.41      raeburn  4950:             @images = ('img','logo','domlogo','login');
1.51      raeburn  4951:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  4952:         } else {
                   4953:             @images = ('img');
1.51      raeburn  4954:             @bgs = ('pgbg','tabbg','sidebg'); 
1.6       raeburn  4955:         }
                   4956:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41      raeburn  4957:         foreach my $item (@bgs,@links,@logintext) {
1.6       raeburn  4958:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   4959:         }
1.46      raeburn  4960:         my ($configuserok,$author_ok,$switchserver) = 
                   4961:             &config_check($dom,$confname,$servadm);
1.9       raeburn  4962:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  4963:         if (ref($domconfig->{$role}) ne 'HASH') {
                   4964:             $domconfig->{$role} = {};
                   4965:         }
1.8       raeburn  4966:         foreach my $img (@images) {
1.70      raeburn  4967:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   4968:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   4969:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   4970:                 } else { 
                   4971:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   4972:                 }
                   4973:             } 
1.18      albertel 4974: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   4975: 		 && !defined($domconfig->{$role}{$img})
                   4976: 		 && !$env{'form.'.$role.'_del_'.$img}
                   4977: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   4978: 		# import the old configured image from the .tab setting
                   4979: 		# if they haven't provided a new one 
                   4980: 		$domconfig->{$role}{$img} = 
                   4981: 		    $env{'form.'.$role.'_import_'.$img};
                   4982: 	    }
1.6       raeburn  4983:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  4984:                 my $error;
1.6       raeburn  4985:                 if ($configuserok eq 'ok') {
1.9       raeburn  4986:                     if ($switchserver) {
1.12      raeburn  4987:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  4988:                     } else {
                   4989:                         if ($author_ok eq 'ok') {
                   4990:                             my ($result,$logourl) = 
                   4991:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   4992:                                            $dom,$confname,$img,$width,$height);
                   4993:                             if ($result eq 'ok') {
                   4994:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  4995:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  4996:                             } else {
1.12      raeburn  4997:                                 $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  4998:                             }
                   4999:                         } else {
1.46      raeburn  5000:                             $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  5001:                         }
                   5002:                     }
                   5003:                 } else {
1.46      raeburn  5004:                     $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  5005:                 }
                   5006:                 if ($error) {
1.8       raeburn  5007:                     &Apache::lonnet::logthis($error);
1.11      albertel 5008:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  5009:                 }
                   5010:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  5011:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   5012:                     my $error;
                   5013:                     if ($configuserok eq 'ok') {
                   5014: # is confname an author?
                   5015:                         if ($switchserver eq '') {
                   5016:                             if ($author_ok eq 'ok') {
                   5017:                                 my ($result,$logourl) = 
                   5018:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   5019:                                             $dom,$confname,$img,$width,$height);
                   5020:                                 if ($result eq 'ok') {
                   5021:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 5022: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5023:                                 }
                   5024:                             }
                   5025:                         }
                   5026:                     }
1.6       raeburn  5027:                 }
                   5028:             }
                   5029:         }
                   5030:         if (ref($domconfig) eq 'HASH') {
                   5031:             if (ref($domconfig->{$role}) eq 'HASH') {
                   5032:                 foreach my $img (@images) {
                   5033:                     if ($domconfig->{$role}{$img} ne '') {
                   5034:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5035:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5036:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5037:                         } else {
1.9       raeburn  5038:                             if ($confhash->{$role}{$img} eq '') {
                   5039:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   5040:                             }
1.6       raeburn  5041:                         }
                   5042:                     } else {
                   5043:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5044:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5045:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5046:                         } 
                   5047:                     }
1.70      raeburn  5048:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   5049:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   5050:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   5051:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   5052:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   5053:                             }
                   5054:                         } else {
                   5055:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5056:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   5057:                             }
                   5058:                         }
                   5059:                     }
                   5060:                 }
1.6       raeburn  5061:                 if ($domconfig->{$role}{'font'} ne '') {
                   5062:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   5063:                         $changes{$role}{'font'} = 1;
                   5064:                     }
                   5065:                 } else {
                   5066:                     if ($confhash->{$role}{'font'}) {
                   5067:                         $changes{$role}{'font'} = 1;
                   5068:                     }
                   5069:                 }
1.107     raeburn  5070:                 if ($role ne 'login') {
                   5071:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   5072:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   5073:                             $changes{$role}{'fontmenu'} = 1;
                   5074:                         }
                   5075:                     } else {
                   5076:                         if ($confhash->{$role}{'fontmenu'}) {
                   5077:                             $changes{$role}{'fontmenu'} = 1;
                   5078:                         }
1.97      tempelho 5079:                     }
                   5080:                 }
1.6       raeburn  5081:                 foreach my $item (@bgs) {
                   5082:                     if ($domconfig->{$role}{$item} ne '') {
                   5083:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5084:                             $changes{$role}{'bgs'}{$item} = 1;
                   5085:                         } 
                   5086:                     } else {
                   5087:                         if ($confhash->{$role}{$item}) {
                   5088:                             $changes{$role}{'bgs'}{$item} = 1;
                   5089:                         }
                   5090:                     }
                   5091:                 }
                   5092:                 foreach my $item (@links) {
                   5093:                     if ($domconfig->{$role}{$item} ne '') {
                   5094:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5095:                             $changes{$role}{'links'}{$item} = 1;
                   5096:                         }
                   5097:                     } else {
                   5098:                         if ($confhash->{$role}{$item}) {
                   5099:                             $changes{$role}{'links'}{$item} = 1;
                   5100:                         }
                   5101:                     }
                   5102:                 }
1.41      raeburn  5103:                 foreach my $item (@logintext) {
                   5104:                     if ($domconfig->{$role}{$item} ne '') {
                   5105:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5106:                             $changes{$role}{'logintext'}{$item} = 1;
                   5107:                         }
                   5108:                     } else {
                   5109:                         if ($confhash->{$role}{$item}) {
                   5110:                             $changes{$role}{'logintext'}{$item} = 1;
                   5111:                         }
                   5112:                     }
                   5113:                 }
1.6       raeburn  5114:             } else {
                   5115:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5116:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  5117:             }
                   5118:         } else {
                   5119:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5120:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  5121:         }
                   5122:     }
                   5123:     return ($errors,%changes);
                   5124: }
                   5125: 
1.46      raeburn  5126: sub config_check {
                   5127:     my ($dom,$confname,$servadm) = @_;
                   5128:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   5129:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   5130:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   5131:                                                    $confname,$servadm);
                   5132:     if ($configuserok eq 'ok') {
                   5133:         $switchserver = &check_switchserver($dom,$confname);
                   5134:         if ($switchserver eq '') {
                   5135:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   5136:         }
                   5137:     }
                   5138:     return ($configuserok,$author_ok,$switchserver);
                   5139: }
                   5140: 
1.6       raeburn  5141: sub default_change_checker {
1.41      raeburn  5142:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  5143:     foreach my $item (@{$links}) {
                   5144:         if ($confhash->{$role}{$item}) {
                   5145:             $changes->{$role}{'links'}{$item} = 1;
                   5146:         }
                   5147:     }
                   5148:     foreach my $item (@{$bgs}) {
                   5149:         if ($confhash->{$role}{$item}) {
                   5150:             $changes->{$role}{'bgs'}{$item} = 1;
                   5151:         }
                   5152:     }
1.41      raeburn  5153:     foreach my $item (@{$logintext}) {
                   5154:         if ($confhash->{$role}{$item}) {
                   5155:             $changes->{$role}{'logintext'}{$item} = 1;
                   5156:         }
                   5157:     }
1.6       raeburn  5158:     foreach my $img (@{$images}) {
                   5159:         if ($env{'form.'.$role.'_del_'.$img}) {
                   5160:             $confhash->{$role}{$img} = '';
1.12      raeburn  5161:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  5162:         }
1.70      raeburn  5163:         if ($role eq 'login') {
                   5164:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5165:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   5166:             }
                   5167:         }
1.6       raeburn  5168:     }
                   5169:     if ($confhash->{$role}{'font'}) {
                   5170:         $changes->{$role}{'font'} = 1;
                   5171:     }
1.48      raeburn  5172: }
1.6       raeburn  5173: 
                   5174: sub display_colorchgs {
                   5175:     my ($dom,$changes,$roles,$confhash) = @_;
                   5176:     my (%choices,$resulttext);
                   5177:     if (!grep(/^login$/,@{$roles})) {
                   5178:         $resulttext = &mt('Changes made:').'<br />';
                   5179:     }
                   5180:     foreach my $role (@{$roles}) {
                   5181:         if ($role eq 'login') {
                   5182:             %choices = &login_choices();
                   5183:         } else {
                   5184:             %choices = &color_font_choices();
                   5185:         }
                   5186:         if (ref($changes->{$role}) eq 'HASH') {
                   5187:             if ($role ne 'login') {
                   5188:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   5189:             }
                   5190:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   5191:                 if ($role ne 'login') {
                   5192:                     $resulttext .= '<ul>';
                   5193:                 }
                   5194:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   5195:                     if ($role ne 'login') {
                   5196:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   5197:                     }
                   5198:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  5199:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   5200:                             if ($confhash->{$role}{$key}{$item}) {
                   5201:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   5202:                             } else {
                   5203:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   5204:                             }
                   5205:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  5206:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   5207:                         } else {
1.12      raeburn  5208:                             my $newitem = $confhash->{$role}{$item};
                   5209:                             if ($key eq 'images') {
                   5210:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   5211:                             }
                   5212:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  5213:                         }
                   5214:                     }
                   5215:                     if ($role ne 'login') {
                   5216:                         $resulttext .= '</ul></li>';
                   5217:                     }
                   5218:                 } else {
                   5219:                     if ($confhash->{$role}{$key} eq '') {
                   5220:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   5221:                     } else {
                   5222:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   5223:                     }
                   5224:                 }
                   5225:                 if ($role ne 'login') {
                   5226:                     $resulttext .= '</ul>';
                   5227:                 }
                   5228:             }
                   5229:         }
                   5230:     }
1.3       raeburn  5231:     return $resulttext;
1.1       raeburn  5232: }
                   5233: 
1.9       raeburn  5234: sub thumb_dimensions {
                   5235:     return ('200','50');
                   5236: }
                   5237: 
1.16      raeburn  5238: sub check_dimensions {
                   5239:     my ($inputfile) = @_;
                   5240:     my ($fullwidth,$fullheight);
                   5241:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   5242:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   5243:             my $imageinfo = <PIPE>;
                   5244:             if (!close(PIPE)) {
                   5245:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   5246:             }
                   5247:             chomp($imageinfo);
                   5248:             my ($fullsize) = 
1.21      raeburn  5249:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  5250:             if ($fullsize) {
                   5251:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   5252:             }
                   5253:         }
                   5254:     }
                   5255:     return ($fullwidth,$fullheight);
                   5256: }
                   5257: 
1.9       raeburn  5258: sub check_configuser {
                   5259:     my ($uhome,$dom,$confname,$servadm) = @_;
                   5260:     my ($configuserok,%currroles);
                   5261:     if ($uhome eq 'no_host') {
                   5262:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   5263:         my $configpass = &LONCAPA::Enrollment::create_password();
                   5264:         $configuserok = 
                   5265:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   5266:                              $configpass,'','','','','',undef,$servadm);
                   5267:     } else {
                   5268:         $configuserok = 'ok';
                   5269:         %currroles = 
                   5270:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   5271:     }
                   5272:     return ($configuserok,%currroles);
                   5273: }
                   5274: 
                   5275: sub check_authorstatus {
                   5276:     my ($dom,$confname,%currroles) = @_;
                   5277:     my $author_ok;
1.40      raeburn  5278:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  5279:         my $start = time;
                   5280:         my $end = 0;
                   5281:         $author_ok = 
                   5282:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  5283:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  5284:     } else {
                   5285:         $author_ok = 'ok';
                   5286:     }
                   5287:     return $author_ok;
                   5288: }
                   5289: 
                   5290: sub publishlogo {
1.46      raeburn  5291:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  5292:     my ($output,$fname,$logourl);
                   5293:     if ($action eq 'upload') {
                   5294:         $fname=$env{'form.'.$formname.'.filename'};
                   5295:         chop($env{'form.'.$formname});
                   5296:     } else {
                   5297:         ($fname) = ($formname =~ /([^\/]+)$/);
                   5298:     }
1.46      raeburn  5299:     if ($savefileas ne '') {
                   5300:         $fname = $savefileas;
                   5301:     }
1.9       raeburn  5302:     $fname=&Apache::lonnet::clean_filename($fname);
                   5303: # See if there is anything left
                   5304:     unless ($fname) { return ('error: no uploaded file'); }
                   5305:     $fname="$subdir/$fname";
1.164     raeburn  5306:     my $docroot=$r->dir_config('lonDocRoot'); 
                   5307:     my $filepath="$docroot/priv";
                   5308:     my $relpath = "$dom/$confname";
1.9       raeburn  5309:     my ($fnamepath,$file,$fetchthumb);
                   5310:     $file=$fname;
                   5311:     if ($fname=~m|/|) {
                   5312:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   5313:     }
1.164     raeburn  5314:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  5315:     my $count;
1.164     raeburn  5316:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  5317:         $filepath.="/$parts[$count]";
                   5318:         if ((-e $filepath)!=1) {
                   5319:             mkdir($filepath,02770);
                   5320:         }
                   5321:     }
                   5322:     # Check for bad extension and disallow upload
                   5323:     if ($file=~/\.(\w+)$/ &&
                   5324:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   5325:         $output = 
                   5326:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
                   5327:     } elsif ($file=~/\.(\w+)$/ &&
                   5328:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   5329:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   5330:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46      raeburn  5331:         $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  5332:     } elsif (-d "$filepath/$file") {
                   5333:         $output = &mt('File name is a directory name - rename the file and re-upload');
                   5334:     } else {
                   5335:         my $source = $filepath.'/'.$file;
                   5336:         my $logfile;
                   5337:         if (!open($logfile,">>$source".'.log')) {
                   5338:             return (&mt('No write permission to Construction Space'));
                   5339:         }
                   5340:         print $logfile
                   5341: "\n================= Publish ".localtime()." ================\n".
                   5342: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   5343: # Save the file
                   5344:         if (!open(FH,'>'.$source)) {
                   5345:             &Apache::lonnet::logthis('Failed to create '.$source);
                   5346:             return (&mt('Failed to create file'));
                   5347:         }
                   5348:         if ($action eq 'upload') {
                   5349:             if (!print FH ($env{'form.'.$formname})) {
                   5350:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   5351:                 return (&mt('Failed to write file'));
                   5352:             }
                   5353:         } else {
                   5354:             my $original = &Apache::lonnet::filelocation('',$formname);
                   5355:             if(!copy($original,$source)) {
                   5356:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   5357:                 return (&mt('Failed to write file'));
                   5358:             }
                   5359:         }
                   5360:         close(FH);
                   5361:         chmod(0660, $source); # Permissions to rw-rw---.
                   5362: 
                   5363:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   5364:         my $copyfile=$targetdir.'/'.$file;
                   5365: 
                   5366:         my @parts=split(/\//,$targetdir);
                   5367:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   5368:         for (my $count=5;$count<=$#parts;$count++) {
                   5369:             $path.="/$parts[$count]";
                   5370:             if (!-e $path) {
                   5371:                 print $logfile "\nCreating directory ".$path;
                   5372:                 mkdir($path,02770);
                   5373:             }
                   5374:         }
                   5375:         my $versionresult;
                   5376:         if (-e $copyfile) {
                   5377:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   5378:         } else {
                   5379:             $versionresult = 'ok';
                   5380:         }
                   5381:         if ($versionresult eq 'ok') {
                   5382:             if (copy($source,$copyfile)) {
                   5383:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   5384:                 $output = 'ok';
                   5385:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  5386:                 push(@{$modified_urls},[$copyfile,$source]);
                   5387:                 my $metaoutput = 
                   5388:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   5389:                 unless ($registered_cleanup) {
                   5390:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5391:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5392:                     $registered_cleanup=1;
                   5393:                 }
1.9       raeburn  5394:             } else {
                   5395:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   5396:                 $output = &mt('Failed to copy file to RES space').", $!";
                   5397:             }
                   5398:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   5399:                 my $inputfile = $filepath.'/'.$file;
                   5400:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  5401:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   5402:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   5403:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   5404:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   5405:                         system("convert -sample $thumbsize $inputfile $outfile");
                   5406:                         chmod(0660, $filepath.'/tn-'.$file);
                   5407:                         if (-e $outfile) {
                   5408:                             my $copyfile=$targetdir.'/tn-'.$file;
                   5409:                             if (copy($outfile,$copyfile)) {
                   5410:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  5411:                                 my $thumb_metaoutput = 
                   5412:                                     &write_metadata($dom,$confname,$formname,
                   5413:                                                     $targetdir,'tn-'.$file,$logfile);
                   5414:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   5415:                                 unless ($registered_cleanup) {
                   5416:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5417:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5418:                                     $registered_cleanup=1;
                   5419:                                 }
1.16      raeburn  5420:                             } else {
                   5421:                                 print $logfile "\nUnable to write ".$copyfile.
                   5422:                                                ':'.$!."\n";
                   5423:                             }
                   5424:                         }
1.9       raeburn  5425:                     }
                   5426:                 }
                   5427:             }
                   5428:         } else {
                   5429:             $output = $versionresult;
                   5430:         }
                   5431:     }
                   5432:     return ($output,$logourl);
                   5433: }
                   5434: 
                   5435: sub logo_versioning {
                   5436:     my ($targetdir,$file,$logfile) = @_;
                   5437:     my $target = $targetdir.'/'.$file;
                   5438:     my ($maxversion,$fn,$extn,$output);
                   5439:     $maxversion = 0;
                   5440:     if ($file =~ /^(.+)\.(\w+)$/) {
                   5441:         $fn=$1;
                   5442:         $extn=$2;
                   5443:     }
                   5444:     opendir(DIR,$targetdir);
                   5445:     while (my $filename=readdir(DIR)) {
                   5446:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   5447:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   5448:         }
                   5449:     }
                   5450:     $maxversion++;
                   5451:     print $logfile "\nCreating old version ".$maxversion."\n";
                   5452:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   5453:     if (copy($target,$copyfile)) {
                   5454:         print $logfile "Copied old target to ".$copyfile."\n";
                   5455:         $copyfile=$copyfile.'.meta';
                   5456:         if (copy($target.'.meta',$copyfile)) {
                   5457:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   5458:             $output = 'ok';
                   5459:         } else {
                   5460:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   5461:             $output = &mt('Failed to copy old meta').", $!, ";
                   5462:         }
                   5463:     } else {
                   5464:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   5465:         $output = &mt('Failed to copy old target').", $!, ";
                   5466:     }
                   5467:     return $output;
                   5468: }
                   5469: 
                   5470: sub write_metadata {
                   5471:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   5472:     my (%metadatafields,%metadatakeys,$output);
                   5473:     $metadatafields{'title'}=$formname;
                   5474:     $metadatafields{'creationdate'}=time;
                   5475:     $metadatafields{'lastrevisiondate'}=time;
                   5476:     $metadatafields{'copyright'}='public';
                   5477:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   5478:                                          $env{'user.domain'};
                   5479:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   5480:     $metadatafields{'domain'}=$dom;
                   5481:     {
                   5482:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   5483:         my $mfh;
1.155     raeburn  5484:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
                   5485:             foreach (sort keys %metadatafields) {
                   5486:                 unless ($_=~/\./) {
                   5487:                     my $unikey=$_;
                   5488:                     $unikey=~/^([A-Za-z]+)/;
                   5489:                     my $tag=$1;
                   5490:                     $tag=~tr/A-Z/a-z/;
                   5491:                     print $mfh "\n\<$tag";
                   5492:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   5493:                         my $value=$metadatafields{$unikey.'.'.$_};
                   5494:                         $value=~s/\"/\'\'/g;
                   5495:                         print $mfh ' '.$_.'="'.$value.'"';
                   5496:                     }
                   5497:                     print $mfh '>'.
                   5498:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   5499:                             .'</'.$tag.'>';
                   5500:                 }
                   5501:             }
                   5502:             $output = 'ok';
                   5503:             print $logfile "\nWrote metadata";
                   5504:             close($mfh);
                   5505:         } else {
                   5506:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  5507:             $output = &mt('Could not write metadata');
                   5508:         }
                   5509:     }
1.155     raeburn  5510:     return $output;
                   5511: }
                   5512: 
                   5513: sub notifysubscribed {
                   5514:     foreach my $targetsource (@{$modified_urls}){
                   5515:         next unless (ref($targetsource) eq 'ARRAY');
                   5516:         my ($target,$source)=@{$targetsource};
                   5517:         if ($source ne '') {
                   5518:             if (open(my $logfh,'>>'.$source.'.log')) {
                   5519:                 print $logfh "\nCleanup phase: Notifications\n";
                   5520:                 my @subscribed=&subscribed_hosts($target);
                   5521:                 foreach my $subhost (@subscribed) {
                   5522:                     print $logfh "\nNotifying host ".$subhost.':';
                   5523:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   5524:                     print $logfh $reply;
                   5525:                 }
                   5526:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   5527:                 foreach my $subhost (@subscribedmeta) {
                   5528:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   5529:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   5530:                                                         $subhost);
                   5531:                     print $logfh $reply;
                   5532:                 }
                   5533:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  5534:                 close($logfh);
1.155     raeburn  5535:             }
                   5536:         }
                   5537:     }
                   5538:     return OK;
                   5539: }
                   5540: 
                   5541: sub subscribed_hosts {
                   5542:     my ($target) = @_;
                   5543:     my @subscribed;
                   5544:     if (open(my $fh,"<$target.subscription")) {
                   5545:         while (my $subline=<$fh>) {
                   5546:             if ($subline =~ /^($match_lonid):/) {
                   5547:                 my $host = $1;
                   5548:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   5549:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   5550:                         push(@subscribed,$host);
                   5551:                     }
                   5552:                 }
                   5553:             }
                   5554:         }
                   5555:     }
                   5556:     return @subscribed;
1.9       raeburn  5557: }
                   5558: 
                   5559: sub check_switchserver {
                   5560:     my ($dom,$confname) = @_;
                   5561:     my ($allowed,$switchserver);
                   5562:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   5563:     if ($home eq 'no_host') {
                   5564:         $home = &Apache::lonnet::domain($dom,'primary');
                   5565:     }
                   5566:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 5567:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   5568:     if (!$allowed) {
                   5569: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9       raeburn  5570:     }
                   5571:     return $switchserver;
                   5572: }
                   5573: 
1.1       raeburn  5574: sub modify_quotas {
1.86      raeburn  5575:     my ($dom,$action,%domconfig) = @_;
1.101     raeburn  5576:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
                   5577:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86      raeburn  5578:     if ($action eq 'quotas') {
                   5579:         $context = 'tools'; 
1.163     raeburn  5580:     } else {
1.86      raeburn  5581:         $context = $action;
                   5582:     }
                   5583:     if ($context eq 'requestcourses') {
1.98      raeburn  5584:         @usertools = ('official','unofficial','community');
1.106     raeburn  5585:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  5586:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   5587:         %titles = &courserequest_titles();
                   5588:         $toolregexp = join('|',@usertools);
                   5589:         %conditions = &courserequest_conditions();
1.163     raeburn  5590:     } elsif ($context eq 'requestauthor') {
                   5591:         @usertools = ('author');
                   5592:         %titles = &authorrequest_titles();
1.86      raeburn  5593:     } else {
1.162     raeburn  5594:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  5595:         %titles = &tool_titles();
1.86      raeburn  5596:     }
1.72      raeburn  5597:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44      raeburn  5598:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5599:     foreach my $key (keys(%env)) {
1.101     raeburn  5600:         if ($context eq 'requestcourses') {
                   5601:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   5602:                 my $item = $1;
                   5603:                 my $type = $2;
                   5604:                 if ($type =~ /^limit_(.+)/) {
                   5605:                     $limithash{$item}{$1} = $env{$key};
                   5606:                 } else {
                   5607:                     $confhash{$item}{$type} = $env{$key};
                   5608:                 }
                   5609:             }
1.163     raeburn  5610:         } elsif ($context eq 'requestauthor') {
                   5611:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   5612:                 $confhash{$1} = $env{$key};
                   5613:             }
1.101     raeburn  5614:         } else {
1.86      raeburn  5615:             if ($key =~ /^form\.quota_(.+)$/) {
                   5616:                 $confhash{'defaultquota'}{$1} = $env{$key};
                   5617:             }
1.101     raeburn  5618:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
                   5619:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   5620:             }
1.72      raeburn  5621:         }
                   5622:     }
1.163     raeburn  5623:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102     raeburn  5624:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
                   5625:         @approvalnotify = sort(@approvalnotify);
                   5626:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
                   5627:         if (ref($domconfig{$action}) eq 'HASH') {
                   5628:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   5629:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   5630:                     $changes{'notify'}{'approval'} = 1;
                   5631:                 }
                   5632:             } else {
1.144     raeburn  5633:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5634:                     $changes{'notify'}{'approval'} = 1;
                   5635:                 }
                   5636:             }
                   5637:         } else {
1.144     raeburn  5638:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5639:                 $changes{'notify'}{'approval'} = 1;
                   5640:             }
                   5641:         }
                   5642:     } else {
1.86      raeburn  5643:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
                   5644:     }
1.72      raeburn  5645:     foreach my $item (@usertools) {
                   5646:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  5647:             my $unset; 
1.101     raeburn  5648:             if ($context eq 'requestcourses') {
1.104     raeburn  5649:                 $unset = '0';
                   5650:                 if ($type eq '_LC_adv') {
                   5651:                     $unset = '';
                   5652:                 }
1.101     raeburn  5653:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   5654:                     $confhash{$item}{$type} .= '=';
                   5655:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   5656:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   5657:                     }
                   5658:                 }
1.163     raeburn  5659:             } elsif ($context eq 'requestauthor') {
                   5660:                 $unset = '0';
                   5661:                 if ($type eq '_LC_adv') {
                   5662:                     $unset = '';
                   5663:                 }
1.72      raeburn  5664:             } else {
1.101     raeburn  5665:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   5666:                     $confhash{$item}{$type} = 1;
                   5667:                 } else {
                   5668:                     $confhash{$item}{$type} = 0;
                   5669:                 }
1.72      raeburn  5670:             }
1.86      raeburn  5671:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  5672:                 if ($action eq 'requestauthor') {
                   5673:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   5674:                         $changes{$type} = 1;
                   5675:                     }
                   5676:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  5677:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   5678:                         $changes{$item}{$type} = 1;
                   5679:                     }
                   5680:                 } else {
                   5681:                     if ($context eq 'requestcourses') {
1.104     raeburn  5682:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  5683:                             $changes{$item}{$type} = 1;
                   5684:                         }
                   5685:                     } else {
                   5686:                         if (!$confhash{$item}{$type}) {
                   5687:                             $changes{$item}{$type} = 1;
                   5688:                         }
                   5689:                     }
                   5690:                 }
                   5691:             } else {
                   5692:                 if ($context eq 'requestcourses') {
1.104     raeburn  5693:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  5694:                         $changes{$item}{$type} = 1;
                   5695:                     }
1.163     raeburn  5696:                 } elsif ($context eq 'requestauthor') {
                   5697:                     if ($confhash{$type} ne $unset) {
                   5698:                         $changes{$type} = 1;
                   5699:                     }
1.72      raeburn  5700:                 } else {
                   5701:                     if (!$confhash{$item}{$type}) {
                   5702:                         $changes{$item}{$type} = 1;
                   5703:                     }
                   5704:                 }
                   5705:             }
1.1       raeburn  5706:         }
                   5707:     }
1.163     raeburn  5708:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  5709:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5710:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5711:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   5712:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5713:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   5714:                             $changes{'defaultquota'}{$key} = 1;
                   5715:                         }
                   5716:                     } else {
                   5717:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  5718:                     }
                   5719:                 }
1.86      raeburn  5720:             } else {
                   5721:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   5722:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5723:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   5724:                             $changes{'defaultquota'}{$key} = 1;
                   5725:                         }
                   5726:                     } else {
                   5727:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  5728:                     }
1.1       raeburn  5729:                 }
                   5730:             }
                   5731:         }
1.86      raeburn  5732:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   5733:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   5734:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5735:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5736:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   5737:                             $changes{'defaultquota'}{$key} = 1;
                   5738:                         }
                   5739:                     } else {
                   5740:                         if (!exists($domconfig{'quotas'}{$key})) {
                   5741:                             $changes{'defaultquota'}{$key} = 1;
                   5742:                         }
1.72      raeburn  5743:                     }
                   5744:                 } else {
1.86      raeburn  5745:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  5746:                 }
1.1       raeburn  5747:             }
                   5748:         }
                   5749:     }
1.72      raeburn  5750: 
1.163     raeburn  5751:     if ($context eq 'requestauthor') {
                   5752:         $domdefaults{'requestauthor'} = \%confhash;
                   5753:     } else {
                   5754:         foreach my $key (keys(%confhash)) {
                   5755:             $domdefaults{$key} = $confhash{$key};
                   5756:         }
1.72      raeburn  5757:     }
1.163     raeburn  5758: 
1.1       raeburn  5759:     my %quotahash = (
1.86      raeburn  5760:                       $action => { %confhash }
1.1       raeburn  5761:                     );
                   5762:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   5763:                                              $dom);
                   5764:     if ($putresult eq 'ok') {
                   5765:         if (keys(%changes) > 0) {
1.72      raeburn  5766:             my $cachetime = 24*60*60;
                   5767:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   5768: 
1.1       raeburn  5769:             $resulttext = &mt('Changes made:').'<ul>';
1.163     raeburn  5770:             unless (($context eq 'requestcourses') || 
                   5771:                     ($context eq 'requestauthor')) {
1.86      raeburn  5772:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   5773:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   5774:                     foreach my $type (@{$types},'default') {
                   5775:                         if (defined($changes{'defaultquota'}{$type})) {
                   5776:                             my $typetitle = $usertypes->{$type};
                   5777:                             if ($type eq 'default') {
                   5778:                                 $typetitle = $othertitle;
                   5779:                             }
                   5780:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  5781:                         }
                   5782:                     }
1.86      raeburn  5783:                     $resulttext .= '</ul></li>';
1.72      raeburn  5784:                 }
                   5785:             }
1.80      raeburn  5786:             my %newenv;
1.72      raeburn  5787:             foreach my $item (@usertools) {
1.163     raeburn  5788:                 my (%haschgs,%inconf);
                   5789:                 if ($context eq 'requestauthor') {
                   5790:                     %haschgs = %changes;
                   5791:                     %inconf = %confhash; 
                   5792:                 } else {
                   5793:                     if (ref($changes{$item}) eq 'HASH') {
                   5794:                         %haschgs = %{$changes{$item}};
                   5795:                     }
                   5796:                     if (ref($confhash{$item}) eq 'HASH') {
                   5797:                         %inconf = %{$confhash{$item}};
                   5798:                     }
                   5799:                 }
                   5800:                 if (keys(%haschgs) > 0) {
1.80      raeburn  5801:                     my $newacc = 
                   5802:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   5803:                                                           $env{'user.domain'},
1.86      raeburn  5804:                                                           $item,'reload',$context);
1.163     raeburn  5805:                     if (($context eq 'requestcourses') || 
                   5806:                         ($context eq 'requestauthor')) {
1.108     raeburn  5807:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   5808:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  5809:                         }
                   5810:                     } else {
                   5811:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   5812:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   5813:                         }
1.80      raeburn  5814:                     }
1.163     raeburn  5815:                     unless ($context eq 'requestauthor') {
                   5816:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   5817:                     }
1.72      raeburn  5818:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  5819:                         if ($haschgs{$type}) {
1.72      raeburn  5820:                             my $typetitle = $usertypes->{$type};
                   5821:                             if ($type eq 'default') {
                   5822:                                 $typetitle = $othertitle;
                   5823:                             } elsif ($type eq '_LC_adv') {
                   5824:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   5825:                             }
1.163     raeburn  5826:                             if ($inconf{$type}) {
1.101     raeburn  5827:                                 if ($context eq 'requestcourses') {
                   5828:                                     my $cond;
1.163     raeburn  5829:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  5830:                                         if ($1 eq '') {
                   5831:                                             $cond = &mt('(Automatic processing of any request).');
                   5832:                                         } else {
                   5833:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   5834:                                         }
                   5835:                                     } else { 
1.163     raeburn  5836:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  5837:                                     }
                   5838:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
                   5839:                                 } else {
                   5840:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   5841:                                 }
1.72      raeburn  5842:                             } else {
1.104     raeburn  5843:                                 if ($type eq '_LC_adv') {
1.163     raeburn  5844:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  5845:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5846:                                     } else { 
                   5847:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   5848:                                     }
                   5849:                                 } else {
                   5850:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5851:                                 }
1.72      raeburn  5852:                             }
                   5853:                         }
1.26      raeburn  5854:                     }
1.163     raeburn  5855:                     unless ($context eq 'requestauthor') {
                   5856:                         $resulttext .= '</ul></li>';
                   5857:                     }
1.26      raeburn  5858:                 }
1.1       raeburn  5859:             }
1.163     raeburn  5860:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  5861:                 if (ref($changes{'notify'}) eq 'HASH') {
                   5862:                     if ($changes{'notify'}{'approval'}) {
                   5863:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   5864:                             if ($confhash{'notify'}{'approval'}) {
                   5865:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   5866:                             } else {
1.163     raeburn  5867:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  5868:                             }
                   5869:                         }
                   5870:                     }
                   5871:                 }
                   5872:             }
1.1       raeburn  5873:             $resulttext .= '</ul>';
1.80      raeburn  5874:             if (keys(%newenv)) {
                   5875:                 &Apache::lonnet::appenv(\%newenv);
                   5876:             }
1.1       raeburn  5877:         } else {
1.86      raeburn  5878:             if ($context eq 'requestcourses') {
                   5879:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  5880:             } elsif ($context eq 'requestauthor') {
                   5881:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  5882:             } else {
1.90      weissno  5883:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  5884:             }
1.1       raeburn  5885:         }
                   5886:     } else {
1.11      albertel 5887:         $resulttext = '<span class="LC_error">'.
                   5888: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5889:     }
1.3       raeburn  5890:     return $resulttext;
1.1       raeburn  5891: }
                   5892: 
1.3       raeburn  5893: sub modify_autoenroll {
                   5894:     my ($dom,%domconfig) = @_;
1.1       raeburn  5895:     my ($resulttext,%changes);
                   5896:     my %currautoenroll;
                   5897:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   5898:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   5899:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   5900:         }
                   5901:     }
                   5902:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   5903:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  5904:                   sender => 'Sender for notification messages',
                   5905:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  5906:     my @offon = ('off','on');
1.17      raeburn  5907:     my $sender_uname = $env{'form.sender_uname'};
                   5908:     my $sender_domain = $env{'form.sender_domain'};
                   5909:     if ($sender_domain eq '') {
                   5910:         $sender_uname = '';
                   5911:     } elsif ($sender_uname eq '') {
                   5912:         $sender_domain = '';
                   5913:     }
1.129     raeburn  5914:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  5915:     my %autoenrollhash =  (
1.129     raeburn  5916:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   5917:                                        'sender_uname' => $sender_uname,
                   5918:                                        'sender_domain' => $sender_domain,
                   5919:                                        'co-owners' => $coowners,
1.1       raeburn  5920:                                 }
                   5921:                      );
1.4       raeburn  5922:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   5923:                                              $dom);
1.1       raeburn  5924:     if ($putresult eq 'ok') {
                   5925:         if (exists($currautoenroll{'run'})) {
                   5926:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   5927:                  $changes{'run'} = 1;
                   5928:              }
                   5929:         } elsif ($autorun) {
                   5930:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  5931:                  $changes{'run'} = 1;
1.1       raeburn  5932:             }
                   5933:         }
1.17      raeburn  5934:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  5935:             $changes{'sender'} = 1;
                   5936:         }
1.17      raeburn  5937:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  5938:             $changes{'sender'} = 1;
                   5939:         }
1.129     raeburn  5940:         if ($currautoenroll{'co-owners'} ne '') {
                   5941:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   5942:                 $changes{'coowners'} = 1;
                   5943:             }
                   5944:         } elsif ($coowners) {
                   5945:             $changes{'coowners'} = 1;
                   5946:         }      
1.1       raeburn  5947:         if (keys(%changes) > 0) {
                   5948:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  5949:             if ($changes{'run'}) {
1.1       raeburn  5950:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   5951:             }
                   5952:             if ($changes{'sender'}) {
1.17      raeburn  5953:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   5954:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   5955:                 } else {
                   5956:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   5957:                 }
1.1       raeburn  5958:             }
1.129     raeburn  5959:             if ($changes{'coowners'}) {
                   5960:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   5961:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   5962:             }
1.1       raeburn  5963:             $resulttext .= '</ul>';
                   5964:         } else {
                   5965:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   5966:         }
                   5967:     } else {
1.11      albertel 5968:         $resulttext = '<span class="LC_error">'.
                   5969: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5970:     }
1.3       raeburn  5971:     return $resulttext;
1.1       raeburn  5972: }
                   5973: 
                   5974: sub modify_autoupdate {
1.3       raeburn  5975:     my ($dom,%domconfig) = @_;
1.1       raeburn  5976:     my ($resulttext,%currautoupdate,%fields,%changes);
                   5977:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   5978:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   5979:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   5980:         }
                   5981:     }
                   5982:     my @offon = ('off','on');
                   5983:     my %title = &Apache::lonlocal::texthash (
                   5984:                    run => 'Auto-update:',
                   5985:                    classlists => 'Updates to user information in classlists?'
                   5986:                 );
1.44      raeburn  5987:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5988:     my %fieldtitles = &Apache::lonlocal::texthash (
                   5989:                         id => 'Student/Employee ID',
1.20      raeburn  5990:                         permanentemail => 'E-mail address',
1.1       raeburn  5991:                         lastname => 'Last Name',
                   5992:                         firstname => 'First Name',
                   5993:                         middlename => 'Middle Name',
1.132     raeburn  5994:                         generation => 'Generation',
1.1       raeburn  5995:                       );
1.142     raeburn  5996:     $othertitle = &mt('All users');
1.1       raeburn  5997:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  5998:         $othertitle = &mt('Other users');
1.1       raeburn  5999:     }
                   6000:     foreach my $key (keys(%env)) {
                   6001:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  6002:             my ($usertype,$item) = ($1,$2);
                   6003:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   6004:                 if ($usertype eq 'default') {   
                   6005:                     push(@{$fields{$1}},$2);
                   6006:                 } elsif (ref($types) eq 'ARRAY') {
                   6007:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   6008:                         push(@{$fields{$1}},$2);
                   6009:                     }
                   6010:                 }
                   6011:             }
1.1       raeburn  6012:         }
                   6013:     }
1.131     raeburn  6014:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   6015:     @lockablenames = sort(@lockablenames);
                   6016:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   6017:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6018:         if (@changed) {
                   6019:             $changes{'lockablenames'} = 1;
                   6020:         }
                   6021:     } else {
                   6022:         if (@lockablenames) {
                   6023:             $changes{'lockablenames'} = 1;
                   6024:         }
                   6025:     }
1.1       raeburn  6026:     my %updatehash = (
                   6027:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   6028:                                       classlists => $env{'form.classlists'},
                   6029:                                       fields => {%fields},
1.131     raeburn  6030:                                       lockablenames => \@lockablenames,
1.1       raeburn  6031:                                     }
                   6032:                      );
                   6033:     foreach my $key (keys(%currautoupdate)) {
                   6034:         if (($key eq 'run') || ($key eq 'classlists')) {
                   6035:             if (exists($updatehash{autoupdate}{$key})) {
                   6036:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   6037:                     $changes{$key} = 1;
                   6038:                 }
                   6039:             }
                   6040:         } elsif ($key eq 'fields') {
                   6041:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  6042:                 foreach my $item (@{$types},'default') {
1.1       raeburn  6043:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   6044:                         my $change = 0;
                   6045:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   6046:                             if (!exists($fields{$item})) {
                   6047:                                 $change = 1;
1.132     raeburn  6048:                                 last;
1.1       raeburn  6049:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  6050:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  6051:                                     $change = 1;
1.132     raeburn  6052:                                     last;
1.1       raeburn  6053:                                 }
                   6054:                             }
                   6055:                         }
                   6056:                         if ($change) {
                   6057:                             push(@{$changes{$key}},$item);
                   6058:                         }
1.26      raeburn  6059:                     } 
1.1       raeburn  6060:                 }
                   6061:             }
1.131     raeburn  6062:         } elsif ($key eq 'lockablenames') {
                   6063:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   6064:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6065:                 if (@changed) {
                   6066:                     $changes{'lockablenames'} = 1;
                   6067:                 }
                   6068:             } else {
                   6069:                 if (@lockablenames) {
                   6070:                     $changes{'lockablenames'} = 1;
                   6071:                 }
                   6072:             }
                   6073:         }
                   6074:     }
                   6075:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   6076:         if (@lockablenames) {
                   6077:             $changes{'lockablenames'} = 1;
1.1       raeburn  6078:         }
                   6079:     }
1.26      raeburn  6080:     foreach my $item (@{$types},'default') {
                   6081:         if (defined($fields{$item})) {
                   6082:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  6083:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   6084:                     my $change = 0;
                   6085:                     if (ref($fields{$item}) eq 'ARRAY') {
                   6086:                         foreach my $type (@{$fields{$item}}) {
                   6087:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   6088:                                 $change = 1;
                   6089:                                 last;
                   6090:                             }
                   6091:                         }
                   6092:                     }
                   6093:                     if ($change) {
                   6094:                         push(@{$changes{'fields'}},$item);
                   6095:                     }
                   6096:                 } else {
1.26      raeburn  6097:                     push(@{$changes{'fields'}},$item);
                   6098:                 }
                   6099:             } else {
                   6100:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  6101:             }
                   6102:         }
                   6103:     }
                   6104:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   6105:                                              $dom);
                   6106:     if ($putresult eq 'ok') {
                   6107:         if (keys(%changes) > 0) {
                   6108:             $resulttext = &mt('Changes made:').'<ul>';
                   6109:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  6110:                 if ($key eq 'lockablenames') {
                   6111:                     $resulttext .= '<li>';
                   6112:                     if (@lockablenames) {
                   6113:                         $usertypes->{'default'} = $othertitle;
                   6114:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   6115:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   6116:                     } else {
                   6117:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   6118:                     }
                   6119:                     $resulttext .= '</li>';
                   6120:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  6121:                     foreach my $item (@{$changes{$key}}) {
                   6122:                         my @newvalues;
                   6123:                         foreach my $type (@{$fields{$item}}) {
                   6124:                             push(@newvalues,$fieldtitles{$type});
                   6125:                         }
1.3       raeburn  6126:                         my $newvaluestr;
                   6127:                         if (@newvalues > 0) {
                   6128:                             $newvaluestr = join(', ',@newvalues);
                   6129:                         } else {
                   6130:                             $newvaluestr = &mt('none');
1.6       raeburn  6131:                         }
1.1       raeburn  6132:                         if ($item eq 'default') {
1.26      raeburn  6133:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  6134:                         } else {
1.26      raeburn  6135:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  6136:                         }
                   6137:                     }
                   6138:                 } else {
                   6139:                     my $newvalue;
                   6140:                     if ($key eq 'run') {
                   6141:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   6142:                     } else {
                   6143:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  6144:                     }
1.1       raeburn  6145:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   6146:                 }
                   6147:             }
                   6148:             $resulttext .= '</ul>';
                   6149:         } else {
1.3       raeburn  6150:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  6151:         }
                   6152:     } else {
1.11      albertel 6153:         $resulttext = '<span class="LC_error">'.
                   6154: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6155:     }
1.3       raeburn  6156:     return $resulttext;
1.1       raeburn  6157: }
                   6158: 
1.125     raeburn  6159: sub modify_autocreate {
                   6160:     my ($dom,%domconfig) = @_;
                   6161:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   6162:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   6163:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   6164:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   6165:         }
                   6166:     }
                   6167:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   6168:                  req => 'Auto-creation of validated requests for official courses',
                   6169:                  xmldc => 'Identity of course creator of courses from XML files',
                   6170:                );
                   6171:     my @types = ('xml','req');
                   6172:     foreach my $item (@types) {
                   6173:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   6174:         $newvals{$item} =~ s/\D//g;
                   6175:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   6176:     }
                   6177:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   6178:     my %domcoords = &get_active_dcs($dom);
                   6179:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   6180:         $newvals{'xmldc'} = '';
                   6181:     } 
                   6182:     %autocreatehash =  (
                   6183:                         autocreate => { xml => $newvals{'xml'},
                   6184:                                         req => $newvals{'req'},
                   6185:                                       }
                   6186:                        );
                   6187:     if ($newvals{'xmldc'} ne '') {
                   6188:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   6189:     }
                   6190:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   6191:                                              $dom);
                   6192:     if ($putresult eq 'ok') {
                   6193:         my @items = @types;
                   6194:         if ($newvals{'xml'}) {
                   6195:             push(@items,'xmldc');
                   6196:         }
                   6197:         foreach my $item (@items) {
                   6198:             if (exists($currautocreate{$item})) {
                   6199:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   6200:                     $changes{$item} = 1;
                   6201:                 }
                   6202:             } elsif ($newvals{$item}) {
                   6203:                 $changes{$item} = 1;
                   6204:             }
                   6205:         }
                   6206:         if (keys(%changes) > 0) {
                   6207:             my @offon = ('off','on'); 
                   6208:             $resulttext = &mt('Changes made:').'<ul>';
                   6209:             foreach my $item (@types) {
                   6210:                 if ($changes{$item}) {
                   6211:                     my $newtxt = $offon[$newvals{$item}];
                   6212:                     $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
                   6213:                 }
                   6214:             }
                   6215:             if ($changes{'xmldc'}) {
                   6216:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   6217:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
                   6218:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
                   6219:             }
                   6220:             $resulttext .= '</ul>';
                   6221:         } else {
                   6222:             $resulttext = &mt('No changes made to auto-creation settings');
                   6223:         }
                   6224:     } else {
                   6225:         $resulttext = '<span class="LC_error">'.
                   6226:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6227:     }
                   6228:     return $resulttext;
                   6229: }
                   6230: 
1.23      raeburn  6231: sub modify_directorysrch {
                   6232:     my ($dom,%domconfig) = @_;
                   6233:     my ($resulttext,%changes);
                   6234:     my %currdirsrch;
                   6235:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   6236:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   6237:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   6238:         }
                   6239:     }
                   6240:     my %title = ( available => 'Directory search available',
1.24      raeburn  6241:                   localonly => 'Other domains can search',
1.23      raeburn  6242:                   searchby => 'Search types',
                   6243:                   searchtypes => 'Search latitude');
                   6244:     my @offon = ('off','on');
1.24      raeburn  6245:     my @otherdoms = ('Yes','No');
1.23      raeburn  6246: 
1.25      raeburn  6247:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  6248:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   6249:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   6250: 
1.44      raeburn  6251:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  6252:     if (keys(%{$usertypes}) == 0) {
                   6253:         @cansearch = ('default');
                   6254:     } else {
                   6255:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   6256:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   6257:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   6258:                     push(@{$changes{'cansearch'}},$type);
                   6259:                 }
1.23      raeburn  6260:             }
1.26      raeburn  6261:             foreach my $type (@cansearch) {
                   6262:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   6263:                     push(@{$changes{'cansearch'}},$type);
                   6264:                 }
1.23      raeburn  6265:             }
1.26      raeburn  6266:         } else {
                   6267:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  6268:         }
                   6269:     }
                   6270: 
                   6271:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   6272:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   6273:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   6274:                 push(@{$changes{'searchby'}},$by);
                   6275:             }
                   6276:         }
                   6277:         foreach my $by (@searchby) {
                   6278:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   6279:                 push(@{$changes{'searchby'}},$by);
                   6280:             }
                   6281:         }
                   6282:     } else {
                   6283:         push(@{$changes{'searchby'}},@searchby);
                   6284:     }
1.25      raeburn  6285: 
                   6286:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   6287:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   6288:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   6289:                 push(@{$changes{'searchtypes'}},$type);
                   6290:             }
                   6291:         }
                   6292:         foreach my $type (@searchtypes) {
                   6293:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   6294:                 push(@{$changes{'searchtypes'}},$type);
                   6295:             }
                   6296:         }
                   6297:     } else {
                   6298:         if (exists($currdirsrch{'searchtypes'})) {
                   6299:             foreach my $type (@searchtypes) {  
                   6300:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   6301:                     push(@{$changes{'searchtypes'}},$type);
                   6302:                 }
                   6303:             }
                   6304:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   6305:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   6306:             }   
                   6307:         } else {
                   6308:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   6309:         }
                   6310:     }
                   6311: 
1.23      raeburn  6312:     my %dirsrch_hash =  (
                   6313:             directorysrch => { available => $env{'form.dirsrch_available'},
                   6314:                                cansearch => \@cansearch,
1.24      raeburn  6315:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  6316:                                searchby => \@searchby,
1.25      raeburn  6317:                                searchtypes => \@searchtypes,
1.23      raeburn  6318:                              }
                   6319:             );
                   6320:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   6321:                                              $dom);
                   6322:     if ($putresult eq 'ok') {
                   6323:         if (exists($currdirsrch{'available'})) {
                   6324:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   6325:                  $changes{'available'} = 1;
                   6326:              }
                   6327:         } else {
                   6328:             if ($env{'form.dirsrch_available'} eq '1') {
                   6329:                 $changes{'available'} = 1;
                   6330:             }
                   6331:         }
1.24      raeburn  6332:         if (exists($currdirsrch{'localonly'})) {
                   6333:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   6334:                  $changes{'localonly'} = 1;
                   6335:              }
                   6336:         } else {
                   6337:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   6338:                 $changes{'localonly'} = 1;
                   6339:             }
                   6340:         }
1.23      raeburn  6341:         if (keys(%changes) > 0) {
                   6342:             $resulttext = &mt('Changes made:').'<ul>';
                   6343:             if ($changes{'available'}) {
                   6344:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   6345:             }
1.24      raeburn  6346:             if ($changes{'localonly'}) {
                   6347:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   6348:             }
                   6349: 
1.23      raeburn  6350:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   6351:                 my $chgtext;
1.26      raeburn  6352:                 if (ref($usertypes) eq 'HASH') {
                   6353:                     if (keys(%{$usertypes}) > 0) {
                   6354:                         foreach my $type (@{$types}) {
                   6355:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   6356:                                 $chgtext .= $usertypes->{$type}.'; ';
                   6357:                             }
                   6358:                         }
                   6359:                         if (grep(/^default$/,@cansearch)) {
                   6360:                             $chgtext .= $othertitle;
                   6361:                         } else {
                   6362:                             $chgtext =~ s/\; $//;
                   6363:                         }
                   6364:                         $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23      raeburn  6365:                     }
                   6366:                 }
                   6367:             }
                   6368:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   6369:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   6370:                 my $chgtext;
                   6371:                 foreach my $type (@{$titleorder}) {
                   6372:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   6373:                         if (defined($searchtitles->{$type})) {
                   6374:                             $chgtext .= $searchtitles->{$type}.'; ';
                   6375:                         }
                   6376:                     }
                   6377:                 }
                   6378:                 $chgtext =~ s/\; $//;
                   6379:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   6380:             }
1.25      raeburn  6381:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   6382:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   6383:                 my $chgtext;
                   6384:                 foreach my $type (@{$srchtypeorder}) {
                   6385:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   6386:                         if (defined($srchtypes_desc->{$type})) {
                   6387:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   6388:                         }
                   6389:                     }
                   6390:                 }
                   6391:                 $chgtext =~ s/\; $//;
                   6392:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23      raeburn  6393:             }
                   6394:             $resulttext .= '</ul>';
                   6395:         } else {
                   6396:             $resulttext = &mt('No changes made to institution directory search settings');
                   6397:         }
                   6398:     } else {
                   6399:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  6400:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   6401:     }
                   6402:     return $resulttext;
                   6403: }
                   6404: 
1.28      raeburn  6405: sub modify_contacts {
                   6406:     my ($dom,%domconfig) = @_;
                   6407:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   6408:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   6409:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   6410:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   6411:         }
                   6412:     }
1.134     raeburn  6413:     my (%others,%to,%bcc);
1.28      raeburn  6414:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  6415:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
                   6416:                     'requestsmail');
1.28      raeburn  6417:     foreach my $type (@mailings) {
                   6418:         @{$newsetting{$type}} = 
                   6419:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   6420:         foreach my $item (@contacts) {
                   6421:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   6422:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   6423:             } else {
                   6424:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   6425:             }
                   6426:         }  
                   6427:         $others{$type} = $env{'form.'.$type.'_others'};
                   6428:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  6429:         if ($type eq 'helpdeskmail') {
                   6430:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   6431:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   6432:         }
1.28      raeburn  6433:     }
                   6434:     foreach my $item (@contacts) {
                   6435:         $to{$item} = $env{'form.'.$item};
                   6436:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   6437:     }
                   6438:     if (keys(%currsetting) > 0) {
                   6439:         foreach my $item (@contacts) {
                   6440:             if ($to{$item} ne $currsetting{$item}) {
                   6441:                 $changes{$item} = 1;
                   6442:             }
                   6443:         }
                   6444:         foreach my $type (@mailings) {
                   6445:             foreach my $item (@contacts) {
                   6446:                 if (ref($currsetting{$type}) eq 'HASH') {
                   6447:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   6448:                         push(@{$changes{$type}},$item);
                   6449:                     }
                   6450:                 } else {
                   6451:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   6452:                 }
                   6453:             }
                   6454:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   6455:                 push(@{$changes{$type}},'others');
                   6456:             }
1.134     raeburn  6457:             if ($type eq 'helpdeskmail') {   
                   6458:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   6459:                     push(@{$changes{$type}},'bcc'); 
                   6460:                 }
                   6461:             }
1.28      raeburn  6462:         }
                   6463:     } else {
                   6464:         my %default;
                   6465:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   6466:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   6467:         $default{'errormail'} = 'adminemail';
                   6468:         $default{'packagesmail'} = 'adminemail';
                   6469:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  6470:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  6471:         $default{'requestsmail'} = 'adminemail';
1.28      raeburn  6472:         foreach my $item (@contacts) {
                   6473:            if ($to{$item} ne $default{$item}) {
                   6474:               $changes{$item} = 1;
                   6475:            } 
                   6476:         }
                   6477:         foreach my $type (@mailings) {
                   6478:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   6479:                
                   6480:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   6481:             }
                   6482:             if ($others{$type} ne '') {
                   6483:                 push(@{$changes{$type}},'others');
1.134     raeburn  6484:             }
                   6485:             if ($type eq 'helpdeskmail') {
                   6486:                 if ($bcc{$type} ne '') {
                   6487:                     push(@{$changes{$type}},'bcc');
                   6488:                 }
                   6489:             }
1.28      raeburn  6490:         }
                   6491:     }
                   6492:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   6493:                                              $dom);
                   6494:     if ($putresult eq 'ok') {
                   6495:         if (keys(%changes) > 0) {
                   6496:             my ($titles,$short_titles)  = &contact_titles();
                   6497:             $resulttext = &mt('Changes made:').'<ul>';
                   6498:             foreach my $item (@contacts) {
                   6499:                 if ($changes{$item}) {
                   6500:                     $resulttext .= '<li>'.$titles->{$item}.
                   6501:                                     &mt(' set to: ').
                   6502:                                     '<span class="LC_cusr_emph">'.
                   6503:                                     $to{$item}.'</span></li>';
                   6504:                 }
                   6505:             }
                   6506:             foreach my $type (@mailings) {
                   6507:                 if (ref($changes{$type}) eq 'ARRAY') {
                   6508:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   6509:                     my @text;
                   6510:                     foreach my $item (@{$newsetting{$type}}) {
                   6511:                         push(@text,$short_titles->{$item});
                   6512:                     }
                   6513:                     if ($others{$type} ne '') {
                   6514:                         push(@text,$others{$type});
                   6515:                     }
                   6516:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  6517:                                    join(', ',@text).'</span>';
                   6518:                     if ($type eq 'helpdeskmail') {
                   6519:                         if ($bcc{$type} ne '') {
                   6520:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   6521:                         }
                   6522:                     }
                   6523:                     $resulttext .= '</li>';
1.28      raeburn  6524:                 }
                   6525:             }
                   6526:             $resulttext .= '</ul>';
                   6527:         } else {
1.34      raeburn  6528:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  6529:         }
                   6530:     } else {
                   6531:         $resulttext = '<span class="LC_error">'.
                   6532:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   6533:     }
                   6534:     return $resulttext;
                   6535: }
                   6536: 
                   6537: sub modify_usercreation {
1.27      raeburn  6538:     my ($dom,%domconfig) = @_;
1.34      raeburn  6539:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43      raeburn  6540:     my $warningmsg;
1.27      raeburn  6541:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   6542:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   6543:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   6544:         }
                   6545:     }
                   6546:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  6547:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43      raeburn  6548:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100     raeburn  6549:     my @contexts = ('author','course','requestcrs','selfcreate');
1.34      raeburn  6550:     foreach my $item(@contexts) {
1.45      raeburn  6551:         if ($item eq 'selfcreate') {
1.50      raeburn  6552:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43      raeburn  6553:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   6554:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50      raeburn  6555:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                   6556:                     if (grep(/^login$/,@{$cancreate{$item}})) {
                   6557:                         $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.');   
                   6558:                     }
1.43      raeburn  6559:                 }
                   6560:             }
1.50      raeburn  6561:         } else {
                   6562:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43      raeburn  6563:         }
1.34      raeburn  6564:     }
1.93      raeburn  6565:     my ($othertitle,$usertypes,$types) = 
                   6566:         &Apache::loncommon::sorted_inst_types($dom);
                   6567:     if (ref($types) eq 'ARRAY') {
                   6568:         if (@{$types} > 0) {
                   6569:             @{$cancreate{'statustocreate'}} = 
                   6570:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103     raeburn  6571:         } else {
                   6572:             @{$cancreate{'statustocreate'}} = ();
1.93      raeburn  6573:         }
                   6574:         push(@contexts,'statustocreate');
                   6575:     }
1.165     raeburn  6576:     &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34      raeburn  6577:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   6578:         foreach my $item (@contexts) {
1.93      raeburn  6579:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                   6580:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50      raeburn  6581:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103     raeburn  6582:                         if (ref($cancreate{$item}) eq 'ARRAY') {
                   6583:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   6584:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6585:                                     push(@{$changes{'cancreate'}},$item);
                   6586:                                 }
1.50      raeburn  6587:                             }
                   6588:                         }
                   6589:                     }
                   6590:                 } else {
                   6591:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
                   6592:                         if (@{$cancreate{$item}} > 0) {
                   6593:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6594:                                 push(@{$changes{'cancreate'}},$item);
                   6595:                             }
                   6596:                         }
                   6597:                     } else {
                   6598:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                   6599:                             if (@{$cancreate{$item}} < 3) {
                   6600:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6601:                                     push(@{$changes{'cancreate'}},$item);
                   6602:                                 }
                   6603:                             }
                   6604:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                   6605:                             if (@{$cancreate{$item}} > 0) {
                   6606:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6607:                                     push(@{$changes{'cancreate'}},$item);
                   6608:                                 }
                   6609:                             }
                   6610:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                   6611:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6612:                                 push(@{$changes{'cancreate'}},$item);
                   6613:                             }
                   6614:                         }
                   6615:                     }
                   6616:                 }
                   6617:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6618:                     foreach my $type (@{$cancreate{$item}}) {
                   6619:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   6620:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   6621:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6622:                                     push(@{$changes{'cancreate'}},$item);
                   6623:                                 }
                   6624:                             }
                   6625:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                   6626:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                   6627:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                   6628:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6629:                                     push(@{$changes{'cancreate'}},$item);
                   6630:                                 }
                   6631:                             }
                   6632:                         }
                   6633:                     }
                   6634:                 }
                   6635:             } else {
                   6636:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   6637:                     push(@{$changes{'cancreate'}},$item);
                   6638:                 }
                   6639:             }
1.27      raeburn  6640:         }
1.34      raeburn  6641:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   6642:         foreach my $item (@contexts) {
1.43      raeburn  6643:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  6644:                 if ($cancreate{$item} ne 'any') {
                   6645:                     push(@{$changes{'cancreate'}},$item);
                   6646:                 }
                   6647:             } else {
                   6648:                 if ($cancreate{$item} ne 'none') {
                   6649:                     push(@{$changes{'cancreate'}},$item);
                   6650:                 }
1.27      raeburn  6651:             }
                   6652:         }
                   6653:     } else {
1.43      raeburn  6654:         foreach my $item (@contexts)  {
1.34      raeburn  6655:             push(@{$changes{'cancreate'}},$item);
                   6656:         }
1.27      raeburn  6657:     }
1.34      raeburn  6658: 
1.27      raeburn  6659:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   6660:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   6661:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   6662:                 push(@{$changes{'username_rule'}},$type);
                   6663:             }
                   6664:         }
                   6665:         foreach my $type (@username_rule) {
                   6666:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   6667:                 push(@{$changes{'username_rule'}},$type);
                   6668:             }
                   6669:         }
                   6670:     } else {
                   6671:         push(@{$changes{'username_rule'}},@username_rule);
                   6672:     }
                   6673: 
1.32      raeburn  6674:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   6675:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   6676:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   6677:                 push(@{$changes{'id_rule'}},$type);
                   6678:             }
                   6679:         }
                   6680:         foreach my $type (@id_rule) {
                   6681:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   6682:                 push(@{$changes{'id_rule'}},$type);
                   6683:             }
                   6684:         }
                   6685:     } else {
                   6686:         push(@{$changes{'id_rule'}},@id_rule);
                   6687:     }
                   6688: 
1.43      raeburn  6689:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   6690:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   6691:             if (!grep(/^\Q$type\E$/,@email_rule)) {
                   6692:                 push(@{$changes{'email_rule'}},$type);
                   6693:             }
                   6694:         }
                   6695:         foreach my $type (@email_rule) {
                   6696:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   6697:                 push(@{$changes{'email_rule'}},$type);
                   6698:             }
                   6699:         }
                   6700:     } else {
                   6701:         push(@{$changes{'email_rule'}},@email_rule);
                   6702:     }
                   6703: 
                   6704:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  6705:     my @authtypes = ('int','krb4','krb5','loc');
                   6706:     my %authhash;
1.43      raeburn  6707:     foreach my $item (@authen_contexts) {
1.28      raeburn  6708:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   6709:         foreach my $auth (@authtypes) {
                   6710:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   6711:                 $authhash{$item}{$auth} = 1;
                   6712:             } else {
                   6713:                 $authhash{$item}{$auth} = 0;
                   6714:             }
                   6715:         }
                   6716:     }
                   6717:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  6718:         foreach my $item (@authen_contexts) {
1.28      raeburn  6719:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   6720:                 foreach my $auth (@authtypes) {
                   6721:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   6722:                         push(@{$changes{'authtypes'}},$item);
                   6723:                         last;
                   6724:                     }
                   6725:                 }
                   6726:             }
                   6727:         }
                   6728:     } else {
1.43      raeburn  6729:         foreach my $item (@authen_contexts) {
1.28      raeburn  6730:             push(@{$changes{'authtypes'}},$item);
                   6731:         }
                   6732:     }
                   6733: 
1.27      raeburn  6734:     my %usercreation_hash =  (
1.28      raeburn  6735:             usercreation => {
1.34      raeburn  6736:                               cancreate     => \%cancreate,
1.27      raeburn  6737:                               username_rule => \@username_rule,
1.32      raeburn  6738:                               id_rule       => \@id_rule,
1.43      raeburn  6739:                               email_rule    => \@email_rule,
1.32      raeburn  6740:                               authtypes     => \%authhash,
1.27      raeburn  6741:                             }
                   6742:             );
                   6743: 
                   6744:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   6745:                                              $dom);
1.50      raeburn  6746: 
                   6747:     my %selfcreatetypes = (
                   6748:                              sso   => 'users authenticated by institutional single sign on',
                   6749:                              login => 'users authenticated by institutional log-in',
                   6750:                              email => 'users who provide a valid e-mail address for use as the username',
                   6751:                           );
1.27      raeburn  6752:     if ($putresult eq 'ok') {
                   6753:         if (keys(%changes) > 0) {
                   6754:             $resulttext = &mt('Changes made:').'<ul>';
                   6755:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  6756:                 my %lt = &usercreation_types();
                   6757:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  6758:                     my $chgtext;
1.165     raeburn  6759:                     unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100     raeburn  6760:                         $chgtext = $lt{$type}.', ';
                   6761:                     }
1.45      raeburn  6762:                     if ($type eq 'selfcreate') {
1.50      raeburn  6763:                         if (@{$cancreate{$type}} == 0) {
1.43      raeburn  6764:                             $chgtext .= &mt('creation of a new user account is not permitted.');
1.50      raeburn  6765:                         } else {
1.100     raeburn  6766:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50      raeburn  6767:                             foreach my $case (@{$cancreate{$type}}) {
                   6768:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   6769:                             }
                   6770:                             $chgtext .= '</ul>';
1.100     raeburn  6771:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   6772:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   6773:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   6774:                                         if (@{$cancreate{'statustocreate'}} == 0) {
                   6775:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6776:                                         }
                   6777:                                     }
                   6778:                                 }
                   6779:                             }
1.43      raeburn  6780:                         }
1.93      raeburn  6781:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  6782:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   6783:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   6784:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   6785:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  6786: 
                   6787:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  6788:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6789:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6790:                                     } 
1.96      raeburn  6791:                                 } elsif (ref($usertypes) eq 'HASH') {
                   6792:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6793:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   6794:                                     } else {
                   6795:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   6796:                                     }
                   6797:                                     $chgtext .= '<ul>';
                   6798:                                     foreach my $case (@{$cancreate{$type}}) {
                   6799:                                         if ($case eq 'default') {
                   6800:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   6801:                                         } else {
                   6802:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  6803:                                         }
                   6804:                                     }
1.100     raeburn  6805:                                     $chgtext .= '</ul>';
                   6806:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                   6807:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                   6808:                                     }
                   6809:                                 }
                   6810:                             } else {
                   6811:                                 if (@{$cancreate{$type}} == 0) {
                   6812:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   6813:                                 } else {
                   6814:                                     $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  6815:                                 }
                   6816:                             }
                   6817:                         }
1.165     raeburn  6818:                     } elsif ($type eq 'captcha') {
                   6819:                         if ($cancreate{$type} eq 'notused') {
                   6820:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   6821:                         } else {
                   6822:                             my %captchas = &captcha_phrases();
                   6823:                             if ($captchas{$cancreate{$type}}) {
                   6824:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
                   6825:                             } else {
                   6826:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.'); 
                   6827:                             }
                   6828:                         }
                   6829:                     } elsif ($type eq 'recaptchakeys') {
                   6830:                         my ($privkey,$pubkey);
                   6831:                         if (ref($cancreate{$type}) eq 'HASH') {
                   6832:                             $pubkey = $cancreate{$type}{'public'};
                   6833:                             $privkey = $cancreate{$type}{'private'};
                   6834:                         }
                   6835:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   6836:                         if (!$pubkey) {
                   6837:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   6838:                         } else {
                   6839:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   6840:                         }
                   6841:                         if (!$privkey) {
                   6842:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   6843:                         } else {
                   6844:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   6845:                         }
                   6846:                         $chgtext .= '</ul>';
1.43      raeburn  6847:                     } else {
                   6848:                         if ($cancreate{$type} eq 'none') {
                   6849:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   6850:                         } elsif ($cancreate{$type} eq 'any') {
                   6851:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   6852:                         } elsif ($cancreate{$type} eq 'official') {
                   6853:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   6854:                         } elsif ($cancreate{$type} eq 'unofficial') {
                   6855:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   6856:                         }
1.34      raeburn  6857:                     }
                   6858:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  6859:                 }
                   6860:             }
                   6861:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  6862:                 my ($rules,$ruleorder) = 
                   6863:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  6864:                 my $chgtext = '<ul>';
                   6865:                 foreach my $type (@username_rule) {
                   6866:                     if (ref($rules->{$type}) eq 'HASH') {
                   6867:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   6868:                     }
                   6869:                 }
                   6870:                 $chgtext .= '</ul>';
                   6871:                 if (@username_rule > 0) {
                   6872:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   6873:                 } else {
1.28      raeburn  6874:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  6875:                 }
                   6876:             }
1.32      raeburn  6877:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   6878:                 my ($idrules,$idruleorder) = 
                   6879:                     &Apache::lonnet::inst_userrules($dom,'id');
                   6880:                 my $chgtext = '<ul>';
                   6881:                 foreach my $type (@id_rule) {
                   6882:                     if (ref($idrules->{$type}) eq 'HASH') {
                   6883:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   6884:                     }
                   6885:                 }
                   6886:                 $chgtext .= '</ul>';
                   6887:                 if (@id_rule > 0) {
                   6888:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   6889:                 } else {
                   6890:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   6891:                 }
                   6892:             }
1.43      raeburn  6893:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   6894:                 my ($emailrules,$emailruleorder) =
                   6895:                     &Apache::lonnet::inst_userrules($dom,'email');
                   6896:                 my $chgtext = '<ul>';
                   6897:                 foreach my $type (@email_rule) {
                   6898:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   6899:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   6900:                     }
                   6901:                 }
                   6902:                 $chgtext .= '</ul>';
                   6903:                 if (@email_rule > 0) {
                   6904:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                   6905:                 } else {
                   6906:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                   6907:                 }
                   6908:             }
                   6909: 
1.28      raeburn  6910:             my %authname = &authtype_names();
                   6911:             my %context_title = &context_names();
                   6912:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   6913:                 my $chgtext = '<ul>';
                   6914:                 foreach my $type (@{$changes{'authtypes'}}) {
                   6915:                     my @allowed;
                   6916:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   6917:                     foreach my $auth (@authtypes) {
                   6918:                         if ($authhash{$type}{$auth}) {
                   6919:                             push(@allowed,$authname{$auth});
                   6920:                         }
                   6921:                     }
1.43      raeburn  6922:                     if (@allowed > 0) {
                   6923:                         $chgtext .= join(', ',@allowed).'</li>';
                   6924:                     } else {
                   6925:                         $chgtext .= &mt('none').'</li>';
                   6926:                     }
1.28      raeburn  6927:                 }
                   6928:                 $chgtext .= '</ul>';
                   6929:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   6930:                 $resulttext .= '</li>';
                   6931:             }
1.27      raeburn  6932:             $resulttext .= '</ul>';
                   6933:         } else {
1.28      raeburn  6934:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  6935:         }
                   6936:     } else {
                   6937:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  6938:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6939:     }
1.43      raeburn  6940:     if ($warningmsg ne '') {
                   6941:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   6942:     }
1.23      raeburn  6943:     return $resulttext;
                   6944: }
                   6945: 
1.165     raeburn  6946: sub process_captcha {
                   6947:     my ($container,$changes,$newsettings,$current) = @_;
                   6948:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   6949:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   6950:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   6951:         $newsettings->{'captcha'} = 'original';
                   6952:     }
                   6953:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169   ! raeburn  6954:         if ($container eq 'cancreate') { 
        !          6955:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
        !          6956:                 push(@{$changes->{'cancreate'}},'captcha');
        !          6957:             } elsif (!defined($changes->{'cancreate'})) {
        !          6958:                 $changes->{'cancreate'} = ['captcha'];
        !          6959:             }
        !          6960:         } else {
        !          6961:             $changes->{'captcha'} = 1;
1.165     raeburn  6962:         }
                   6963:     }
                   6964:     my ($newpub,$newpriv,$currpub,$currpriv);
                   6965:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   6966:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   6967:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169   ! raeburn  6968:         $newpub =~ s/\W//g;
        !          6969:         $newpriv =~ s/\W//g;
        !          6970:         $newsettings->{'recaptchakeys'} = {
        !          6971:                                              public  => $newpub,
        !          6972:                                              private => $newpriv,
        !          6973:                                           };
1.165     raeburn  6974:     }
                   6975:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   6976:         $currpub = $current->{'recaptchakeys'}{'public'};
                   6977:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.169   ! raeburn  6978:         $newsettings->{'recaptchakeys'} = {
        !          6979:                                              public  => '',
        !          6980:                                              private => '',
        !          6981:                                           }
1.165     raeburn  6982:     }
                   6983:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169   ! raeburn  6984:         if ($container eq 'cancreate') {
        !          6985:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
        !          6986:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
        !          6987:             } elsif (!defined($changes->{'cancreate'})) {
        !          6988:                 $changes->{'cancreate'} = ['recaptchakeys'];
        !          6989:             }
        !          6990:         } else {
        !          6991:             $changes->{'recaptchakeys'} = 1; 
1.165     raeburn  6992:         }
                   6993:     }
                   6994:     return;
                   6995: }
                   6996: 
1.33      raeburn  6997: sub modify_usermodification {
                   6998:     my ($dom,%domconfig) = @_;
                   6999:     my ($resulttext,%curr_usermodification,%changes);
                   7000:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   7001:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   7002:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   7003:         }
                   7004:     }
1.63      raeburn  7005:     my @contexts = ('author','course','selfcreate');
1.33      raeburn  7006:     my %context_title = (
                   7007:                            author => 'In author context',
                   7008:                            course => 'In course context',
1.63      raeburn  7009:                            selfcreate => 'When self creating account', 
1.33      raeburn  7010:                         );
                   7011:     my @fields = ('lastname','firstname','middlename','generation',
                   7012:                   'permanentemail','id');
                   7013:     my %roles = (
                   7014:                   author => ['ca','aa'],
                   7015:                   course => ['st','ep','ta','in','cr'],
                   7016:                 );
1.63      raeburn  7017:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7018:     if (ref($types) eq 'ARRAY') {
                   7019:         push(@{$types},'default');
                   7020:         $usertypes->{'default'} = $othertitle;
                   7021:     }
                   7022:     $roles{'selfcreate'} = $types;  
1.33      raeburn  7023:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7024:     my %modifyhash;
                   7025:     foreach my $context (@contexts) {
                   7026:         foreach my $role (@{$roles{$context}}) {
                   7027:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   7028:             foreach my $item (@fields) {
                   7029:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   7030:                     $modifyhash{$context}{$role}{$item} = 1;
                   7031:                 } else {
                   7032:                     $modifyhash{$context}{$role}{$item} = 0;
                   7033:                 }
                   7034:             }
                   7035:         }
                   7036:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   7037:             foreach my $role (@{$roles{$context}}) {
                   7038:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   7039:                     foreach my $field (@fields) {
                   7040:                         if ($modifyhash{$context}{$role}{$field} ne 
                   7041:                                 $curr_usermodification{$context}{$role}{$field}) {
                   7042:                             push(@{$changes{$context}},$role);
                   7043:                             last;
                   7044:                         }
                   7045:                     }
                   7046:                 }
                   7047:             }
                   7048:         } else {
                   7049:             foreach my $context (@contexts) {
                   7050:                 foreach my $role (@{$roles{$context}}) {
                   7051:                     push(@{$changes{$context}},$role);
                   7052:                 }
                   7053:             }
                   7054:         }
                   7055:     }
                   7056:     my %usermodification_hash =  (
                   7057:                                    usermodification => \%modifyhash,
                   7058:                                  );
                   7059:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   7060:                                              \%usermodification_hash,$dom);
                   7061:     if ($putresult eq 'ok') {
                   7062:         if (keys(%changes) > 0) {
                   7063:             $resulttext = &mt('Changes made: ').'<ul>';
                   7064:             foreach my $context (@contexts) {
                   7065:                 if (ref($changes{$context}) eq 'ARRAY') {
                   7066:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   7067:                     if (ref($changes{$context}) eq 'ARRAY') {
                   7068:                         foreach my $role (@{$changes{$context}}) {
                   7069:                             my $rolename;
1.63      raeburn  7070:                             if ($context eq 'selfcreate') {
                   7071:                                 $rolename = $role;
                   7072:                                 if (ref($usertypes) eq 'HASH') {
                   7073:                                     if ($usertypes->{$role} ne '') {
                   7074:                                         $rolename = $usertypes->{$role};
                   7075:                                     }
                   7076:                                 }
1.33      raeburn  7077:                             } else {
1.63      raeburn  7078:                                 if ($role eq 'cr') {
                   7079:                                     $rolename = &mt('Custom');
                   7080:                                 } else {
                   7081:                                     $rolename = &Apache::lonnet::plaintext($role);
                   7082:                                 }
1.33      raeburn  7083:                             }
                   7084:                             my @modifiable;
1.63      raeburn  7085:                             if ($context eq 'selfcreate') {
1.126     bisitz   7086:                                 $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  7087:                             } else {
                   7088:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   7089:                             }
1.33      raeburn  7090:                             foreach my $field (@fields) {
                   7091:                                 if ($modifyhash{$context}{$role}{$field}) {
                   7092:                                     push(@modifiable,$fieldtitles{$field});
                   7093:                                 }
                   7094:                             }
                   7095:                             if (@modifiable > 0) {
                   7096:                                 $resulttext .= join(', ',@modifiable);
                   7097:                             } else {
                   7098:                                 $resulttext .= &mt('none'); 
                   7099:                             }
                   7100:                             $resulttext .= '</li>';
                   7101:                         }
                   7102:                         $resulttext .= '</ul></li>';
                   7103:                     }
                   7104:                 }
                   7105:             }
                   7106:             $resulttext .= '</ul>';
                   7107:         } else {
                   7108:             $resulttext = &mt('No changes made to user modification settings');
                   7109:         }
                   7110:     } else {
                   7111:         $resulttext = '<span class="LC_error">'.
                   7112:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7113:     }
                   7114:     return $resulttext;
                   7115: }
                   7116: 
1.43      raeburn  7117: sub modify_defaults {
                   7118:     my ($dom,$r) = @_;
                   7119:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
                   7120:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  7121:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  7122:     my @authtypes = ('internal','krb4','krb5','localauth');
                   7123:     foreach my $item (@items) {
                   7124:         $newvalues{$item} = $env{'form.'.$item};
                   7125:         if ($item eq 'auth_def') {
                   7126:             if ($newvalues{$item} ne '') {
                   7127:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   7128:                     push(@errors,$item);
                   7129:                 }
                   7130:             }
                   7131:         } elsif ($item eq 'lang_def') {
                   7132:             if ($newvalues{$item} ne '') {
                   7133:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   7134:                     my $langcode = $1;
1.103     raeburn  7135:                     if ($langcode ne 'x_chef') {
                   7136:                         if (code2language($langcode) eq '') {
                   7137:                             push(@errors,$item);
                   7138:                         }
1.43      raeburn  7139:                     }
                   7140:                 } else {
                   7141:                     push(@errors,$item);
                   7142:                 }
                   7143:             }
1.54      raeburn  7144:         } elsif ($item eq 'timezone_def') {
                   7145:             if ($newvalues{$item} ne '') {
1.62      raeburn  7146:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  7147:                     push(@errors,$item);   
                   7148:                 }
                   7149:             }
1.68      raeburn  7150:         } elsif ($item eq 'datelocale_def') {
                   7151:             if ($newvalues{$item} ne '') {
                   7152:                 my @datelocale_ids = DateTime::Locale->ids();
                   7153:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   7154:                     push(@errors,$item);
                   7155:                 }
                   7156:             }
1.141     raeburn  7157:         } elsif ($item eq 'portal_def') {
                   7158:             if ($newvalues{$item} ne '') {
                   7159:                 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])\/?$/) {
                   7160:                     push(@errors,$item);
                   7161:                 }
                   7162:             }
1.43      raeburn  7163:         }
                   7164:         if (grep(/^\Q$item\E$/,@errors)) {
                   7165:             $newvalues{$item} = $domdefaults{$item};
                   7166:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   7167:             $changes{$item} = 1;
                   7168:         }
1.72      raeburn  7169:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  7170:     }
                   7171:     my %defaults_hash = (
1.72      raeburn  7172:                          defaults => \%newvalues,
                   7173:                         );
1.43      raeburn  7174:     my $title = &defaults_titles();
                   7175:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   7176:                                              $dom);
                   7177:     if ($putresult eq 'ok') {
                   7178:         if (keys(%changes) > 0) {
                   7179:             $resulttext = &mt('Changes made:').'<ul>';
                   7180:             my $version = $r->dir_config('lonVersion');
                   7181:             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";
                   7182:             foreach my $item (sort(keys(%changes))) {
                   7183:                 my $value = $env{'form.'.$item};
                   7184:                 if ($value eq '') {
                   7185:                     $value = &mt('none');
                   7186:                 } elsif ($item eq 'auth_def') {
                   7187:                     my %authnames = &authtype_names();
                   7188:                     my %shortauth = (
                   7189:                              internal => 'int',
                   7190:                              krb4 => 'krb4',
                   7191:                              krb5 => 'krb5',
                   7192:                              localauth  => 'loc',
                   7193:                     );
                   7194:                     $value = $authnames{$shortauth{$value}};
                   7195:                 }
                   7196:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   7197:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   7198:             }
                   7199:             $resulttext .= '</ul>';
                   7200:             $mailmsgtext .= "\n";
                   7201:             my $cachetime = 24*60*60;
1.72      raeburn  7202:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68      raeburn  7203:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54      raeburn  7204:                 my $sysmail = $r->dir_config('lonSysEMail');
                   7205:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
                   7206:             }
1.43      raeburn  7207:         } else {
1.54      raeburn  7208:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  7209:         }
                   7210:     } else {
                   7211:         $resulttext = '<span class="LC_error">'.
                   7212:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7213:     }
                   7214:     if (@errors > 0) {
                   7215:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   7216:         foreach my $item (@errors) {
                   7217:             $resulttext .= ' "'.$title->{$item}.'",';
                   7218:         }
                   7219:         $resulttext =~ s/,$//;
                   7220:     }
                   7221:     return $resulttext;
                   7222: }
                   7223: 
1.46      raeburn  7224: sub modify_scantron {
1.48      raeburn  7225:     my ($r,$dom,$confname,%domconfig) = @_;
1.46      raeburn  7226:     my ($resulttext,%confhash,%changes,$errors);
                   7227:     my $custom = 'custom.tab';
                   7228:     my $default = 'default.tab';
                   7229:     my $servadm = $r->dir_config('lonAdmEMail');
                   7230:     my ($configuserok,$author_ok,$switchserver) = 
                   7231:         &config_check($dom,$confname,$servadm);
                   7232:     if ($env{'form.scantronformat.filename'} ne '') {
                   7233:         my $error;
                   7234:         if ($configuserok eq 'ok') {
                   7235:             if ($switchserver) {
1.130     raeburn  7236:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  7237:             } else {
                   7238:                 if ($author_ok eq 'ok') {
                   7239:                     my ($result,$scantronurl) =
                   7240:                         &publishlogo($r,'upload','scantronformat',$dom,
                   7241:                                      $confname,'scantron','','',$custom);
                   7242:                     if ($result eq 'ok') {
                   7243:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  7244:                         $changes{'scantronformat'} = 1;
1.46      raeburn  7245:                     } else {
                   7246:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   7247:                     }
                   7248:                 } else {
                   7249:                     $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);
                   7250:                 }
                   7251:             }
                   7252:         } else {
                   7253:             $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);
                   7254:         }
                   7255:         if ($error) {
                   7256:             &Apache::lonnet::logthis($error);
                   7257:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7258:         }
                   7259:     }
1.48      raeburn  7260:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   7261:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   7262:             if ($env{'form.scantronformat_del'}) {
                   7263:                 $confhash{'scantron'}{'scantronformat'} = '';
                   7264:                 $changes{'scantronformat'} = 1;
1.46      raeburn  7265:             }
                   7266:         }
                   7267:     }
                   7268:     if (keys(%confhash) > 0) {
                   7269:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   7270:                                                  $dom);
                   7271:         if ($putresult eq 'ok') {
                   7272:             if (keys(%changes) > 0) {
1.48      raeburn  7273:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   7274:                     $resulttext = &mt('Changes made:').'<ul>';
                   7275:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  7276:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  7277:                     } else {
1.130     raeburn  7278:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  7279:                     }
1.48      raeburn  7280:                     $resulttext .= '</ul>';
                   7281:                 } else {
1.130     raeburn  7282:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  7283:                 }
                   7284:                 $resulttext .= '</ul>';
                   7285:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   7286:             } else {
1.130     raeburn  7287:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  7288:             }
                   7289:         } else {
                   7290:             $resulttext = '<span class="LC_error">'.
                   7291:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   7292:         }
                   7293:     } else {
1.130     raeburn  7294:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  7295:     }
                   7296:     if ($errors) {
                   7297:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7298:                        $errors.'</ul>';
                   7299:     }
                   7300:     return $resulttext;
                   7301: }
                   7302: 
1.48      raeburn  7303: sub modify_coursecategories {
                   7304:     my ($dom,%domconfig) = @_;
1.57      raeburn  7305:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   7306:         $cathash);
1.48      raeburn  7307:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  7308:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  7309:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   7310:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   7311:             $changes{'togglecats'} = 1;
                   7312:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   7313:         }
                   7314:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   7315:             $changes{'categorize'} = 1;
                   7316:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   7317:         }
1.120     raeburn  7318:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   7319:             $changes{'togglecatscomm'} = 1;
                   7320:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   7321:         }
                   7322:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   7323:             $changes{'categorizecomm'} = 1;
                   7324:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   7325:         }
1.57      raeburn  7326:     } else {
                   7327:         $changes{'togglecats'} = 1;
                   7328:         $changes{'categorize'} = 1;
1.124     raeburn  7329:         $changes{'togglecatscomm'} = 1;
                   7330:         $changes{'categorizecomm'} = 1;
1.87      raeburn  7331:         $domconfig{'coursecategories'} = {
                   7332:                                              togglecats => $env{'form.togglecats'},
                   7333:                                              categorize => $env{'form.categorize'},
1.124     raeburn  7334:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   7335:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  7336:                                          };
1.57      raeburn  7337:     }
                   7338:     if (ref($cathash) eq 'HASH') {
                   7339:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  7340:             push (@deletecategory,'instcode::0');
                   7341:         }
1.120     raeburn  7342:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   7343:             push(@deletecategory,'communities::0');
                   7344:         }
1.48      raeburn  7345:     }
1.57      raeburn  7346:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   7347:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  7348:         if (@deletecategory > 0) {
                   7349:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  7350:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  7351:             foreach my $item (@deletecategory) {
1.57      raeburn  7352:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   7353:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  7354:                     $deletions{$item} = 1;
1.57      raeburn  7355:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  7356:                 }
                   7357:             }
                   7358:         }
1.57      raeburn  7359:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  7360:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  7361:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  7362:                 $reorderings{$item} = 1;
1.57      raeburn  7363:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  7364:             }
                   7365:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   7366:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   7367:                 my $newdepth = $depth+1;
                   7368:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7369:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  7370:                 $adds{$newitem} = 1; 
                   7371:             }
                   7372:             if ($env{'form.subcat_'.$item} ne '') {
                   7373:                 my $newcat = $env{'form.subcat_'.$item};
                   7374:                 my $newdepth = $depth+1;
                   7375:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7376:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  7377:                 $adds{$newitem} = 1;
                   7378:             }
                   7379:         }
                   7380:     }
                   7381:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  7382:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  7383:             my $newitem = 'instcode::0';
1.57      raeburn  7384:             if ($cathash->{$newitem} eq '') {  
                   7385:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7386:                 $adds{$newitem} = 1;
                   7387:             }
                   7388:         } else {
                   7389:             my $newitem = 'instcode::0';
1.57      raeburn  7390:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7391:             $adds{$newitem} = 1;
                   7392:         }
                   7393:     }
1.120     raeburn  7394:     if ($env{'form.communities'} eq '1') {
                   7395:         if (ref($cathash) eq 'HASH') {
                   7396:             my $newitem = 'communities::0';
                   7397:             if ($cathash->{$newitem} eq '') {
                   7398:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7399:                 $adds{$newitem} = 1;
                   7400:             }
                   7401:         } else {
                   7402:             my $newitem = 'communities::0';
                   7403:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7404:             $adds{$newitem} = 1;
                   7405:         }
                   7406:     }
1.48      raeburn  7407:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  7408:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   7409:             ($env{'form.addcategory_name'} ne 'communities')) {
                   7410:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   7411:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   7412:             $adds{$newitem} = 1;
                   7413:         }
1.48      raeburn  7414:     }
1.57      raeburn  7415:     my $putresult;
1.48      raeburn  7416:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7417:         if (keys(%deletions) > 0) {
                   7418:             foreach my $key (keys(%deletions)) {
                   7419:                 if ($predelallitems{$key} ne '') {
                   7420:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   7421:                 }
                   7422:             }
                   7423:         }
                   7424:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  7425:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  7426:         if (ref($chkcats[0]) eq 'ARRAY') {
                   7427:             my $depth = 0;
                   7428:             my $chg = 0;
                   7429:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   7430:                 my $name = $chkcats[0][$i];
                   7431:                 my $item;
                   7432:                 if ($name eq '') {
                   7433:                     $chg ++;
                   7434:                 } else {
                   7435:                     $item = &escape($name).'::0';
                   7436:                     if ($chg) {
1.57      raeburn  7437:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  7438:                     }
                   7439:                     $depth ++; 
1.57      raeburn  7440:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  7441:                     $depth --;
                   7442:                 }
                   7443:             }
                   7444:         }
1.57      raeburn  7445:     }
                   7446:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7447:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  7448:         if ($putresult eq 'ok') {
1.57      raeburn  7449:             my %title = (
1.120     raeburn  7450:                          togglecats     => 'Show/Hide a course in catalog',
                   7451:                          categorize     => 'Assign a category to a course',
                   7452:                          togglecatscomm => 'Show/Hide a community in catalog',
                   7453:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  7454:                         );
                   7455:             my %level = (
1.120     raeburn  7456:                          dom  => 'set in Domain ("Modify Course/Community")',
                   7457:                          crs  => 'set in Course ("Course Configuration")',
                   7458:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  7459:                         );
1.48      raeburn  7460:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  7461:             if ($changes{'togglecats'}) {
                   7462:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   7463:             }
                   7464:             if ($changes{'categorize'}) {
                   7465:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  7466:             }
1.120     raeburn  7467:             if ($changes{'togglecatscomm'}) {
                   7468:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   7469:             }
                   7470:             if ($changes{'categorizecomm'}) {
                   7471:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   7472:             }
1.57      raeburn  7473:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7474:                 my $cathash;
                   7475:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   7476:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   7477:                 } else {
                   7478:                     $cathash = {};
                   7479:                 } 
                   7480:                 my (@cats,@trails,%allitems);
                   7481:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   7482:                 if (keys(%deletions) > 0) {
                   7483:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   7484:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   7485:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   7486:                     }
                   7487:                     $resulttext .= '</ul></li>';
                   7488:                 }
                   7489:                 if (keys(%reorderings) > 0) {
                   7490:                     my %sort_by_trail;
                   7491:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   7492:                     foreach my $key (keys(%reorderings)) {
                   7493:                         if ($allitems{$key} ne '') {
                   7494:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7495:                         }
1.48      raeburn  7496:                     }
1.57      raeburn  7497:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7498:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   7499:                     }
                   7500:                     $resulttext .= '</ul></li>';
1.48      raeburn  7501:                 }
1.57      raeburn  7502:                 if (keys(%adds) > 0) {
                   7503:                     my %sort_by_trail;
                   7504:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   7505:                     foreach my $key (keys(%adds)) {
                   7506:                         if ($allitems{$key} ne '') {
                   7507:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7508:                         }
                   7509:                     }
                   7510:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7511:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  7512:                     }
1.57      raeburn  7513:                     $resulttext .= '</ul></li>';
1.48      raeburn  7514:                 }
                   7515:             }
                   7516:             $resulttext .= '</ul>';
                   7517:         } else {
                   7518:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  7519:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  7520:         }
                   7521:     } else {
1.120     raeburn  7522:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  7523:     }
                   7524:     return $resulttext;
                   7525: }
                   7526: 
1.69      raeburn  7527: sub modify_serverstatuses {
                   7528:     my ($dom,%domconfig) = @_;
                   7529:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   7530:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   7531:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   7532:     }
                   7533:     my @pages = &serverstatus_pages();
                   7534:     foreach my $type (@pages) {
                   7535:         $newserverstatus{$type}{'namedusers'} = '';
                   7536:         $newserverstatus{$type}{'machines'} = '';
                   7537:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   7538:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   7539:             my @okusers;
                   7540:             foreach my $user (@users) {
                   7541:                 my ($uname,$udom) = split(/:/,$user);
                   7542:                 if (($udom =~ /^$match_domain$/) &&   
                   7543:                     (&Apache::lonnet::domain($udom)) &&
                   7544:                     ($uname =~ /^$match_username$/)) {
                   7545:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   7546:                         push(@okusers,$user);
                   7547:                     }
                   7548:                 }
                   7549:             }
                   7550:             if (@okusers > 0) {
                   7551:                  @okusers = sort(@okusers);
                   7552:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   7553:             }
                   7554:         }
                   7555:         if (defined($env{'form.'.$type.'_machines'})) {
                   7556:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   7557:             my @okmachines;
                   7558:             foreach my $ip (@machines) {
                   7559:                 my @parts = split(/\./,$ip);
                   7560:                 next if (@parts < 4);
                   7561:                 my $badip = 0;
                   7562:                 for (my $i=0; $i<4; $i++) {
                   7563:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   7564:                         $badip = 1;
                   7565:                         last;
                   7566:                     }
                   7567:                 }
                   7568:                 if (!$badip) {
                   7569:                     push(@okmachines,$ip);     
                   7570:                 }
                   7571:             }
                   7572:             @okmachines = sort(@okmachines);
                   7573:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   7574:         }
                   7575:     }
                   7576:     my %serverstatushash =  (
                   7577:                                 serverstatuses => \%newserverstatus,
                   7578:                             );
                   7579:     foreach my $type (@pages) {
1.83      raeburn  7580:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  7581:             my (@current,@new);
1.83      raeburn  7582:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  7583:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   7584:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   7585:                 }
                   7586:             }
                   7587:             if ($newserverstatus{$type}{$setting} ne '') {
                   7588:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  7589:             }
                   7590:             if (@current > 0) {
                   7591:                 if (@new > 0) {
                   7592:                     foreach my $item (@current) {
                   7593:                         if (!grep(/^\Q$item\E$/,@new)) {
                   7594:                             $changes{$type}{$setting} = 1;
1.82      raeburn  7595:                             last;
                   7596:                         }
                   7597:                     }
1.84      raeburn  7598:                     foreach my $item (@new) {
                   7599:                         if (!grep(/^\Q$item\E$/,@current)) {
                   7600:                             $changes{$type}{$setting} = 1;
                   7601:                             last;
1.82      raeburn  7602:                         }
                   7603:                     }
                   7604:                 } else {
1.83      raeburn  7605:                     $changes{$type}{$setting} = 1;
1.69      raeburn  7606:                 }
1.83      raeburn  7607:             } elsif (@new > 0) {
                   7608:                 $changes{$type}{$setting} = 1;
1.69      raeburn  7609:             }
                   7610:         }
                   7611:     }
                   7612:     if (keys(%changes) > 0) {
1.81      raeburn  7613:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7614:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   7615:                                                  \%serverstatushash,$dom);
                   7616:         if ($putresult eq 'ok') {
                   7617:             $resulttext .= &mt('Changes made:').'<ul>';
                   7618:             foreach my $type (@pages) {
1.84      raeburn  7619:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  7620:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  7621:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  7622:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   7623:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   7624:                         } else {
                   7625:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   7626:                         }
1.84      raeburn  7627:                     }
                   7628:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  7629:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   7630:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   7631:                         } else {
                   7632:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   7633:                         }
                   7634: 
                   7635:                     }
                   7636:                     $resulttext .= '</ul></li>';
                   7637:                 }
                   7638:             }
                   7639:             $resulttext .= '</ul>';
                   7640:         } else {
                   7641:             $resulttext = '<span class="LC_error">'.
                   7642:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   7643: 
                   7644:         }
                   7645:     } else {
                   7646:         $resulttext = &mt('No changes made to access to server status pages');
                   7647:     }
                   7648:     return $resulttext;
                   7649: }
                   7650: 
1.118     jms      7651: sub modify_helpsettings {
1.122     jms      7652:     my ($r,$dom,$confname,%domconfig) = @_;
1.166     raeburn  7653:     my ($resulttext,$errors,%changes,%helphash);
                   7654:     my %defaultchecked = ('submitbugs' => 'on');
                   7655:     my @offon = ('off','on');
1.118     jms      7656:     my @toggles = ('submitbugs');
                   7657:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   7658:         foreach my $item (@toggles) {
1.166     raeburn  7659:             if ($defaultchecked{$item} eq 'on') { 
                   7660:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7661:                     if ($env{'form.'.$item} eq '0') {
                   7662:                         $changes{$item} = 1;
                   7663:                     }
                   7664:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7665:                     $changes{$item} = 1;
                   7666:                 }
                   7667:             } elsif ($defaultchecked{$item} eq 'off') {
                   7668:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7669:                     if ($env{'form.'.$item} eq '1') {
                   7670:                         $changes{$item} = 1;
                   7671:                     }
                   7672:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7673:                     $changes{$item} = 1;
                   7674:                 }
                   7675:             }
                   7676:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { 
                   7677:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   7678:             }
                   7679:         }
1.118     jms      7680:     }
1.123     jms      7681:     my $putresult;
                   7682:     if (keys(%changes) > 0) {
1.166     raeburn  7683:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  7684:         if ($putresult eq 'ok') {
1.166     raeburn  7685:             $resulttext = &mt('Changes made:').'<ul>';
                   7686:             foreach my $item (sort(keys(%changes))) {
                   7687:                 if ($item eq 'submitbugs') {
                   7688:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   7689:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   7690:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                   7691:                 }
                   7692:             }
                   7693:             $resulttext .= '</ul>';
                   7694:         } else {
                   7695:             $resulttext = &mt('No changes made to help settings');
1.168     raeburn  7696:             $errors .= '<li><span class="LC_error">'.
                   7697:                        &mt('An error occurred storing the settings: [_1]',
                   7698:                            $putresult).'</span></li>';
1.166     raeburn  7699:         }
1.118     jms      7700:     }
                   7701:     if ($errors) {
1.168     raeburn  7702:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118     jms      7703:                        $errors.'</ul>';
                   7704:     }
                   7705:     return $resulttext;
                   7706: }
                   7707: 
1.121     raeburn  7708: sub modify_coursedefaults {
                   7709:     my ($dom,%domconfig) = @_;
                   7710:     my ($resulttext,$errors,%changes,%defaultshash);
                   7711:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   7712:     my @offon = ('off','on');
                   7713:     my @toggles = ('canuse_pdfforms');
                   7714: 
                   7715:     $defaultshash{'coursedefaults'} = {};
                   7716: 
                   7717:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   7718:         if ($domconfig{'coursedefaults'} eq '') {
                   7719:             $domconfig{'coursedefaults'} = {};
                   7720:         }
                   7721:     }
                   7722: 
                   7723:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   7724:         foreach my $item (@toggles) {
                   7725:             if ($defaultchecked{$item} eq 'on') {
                   7726:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7727:                     ($env{'form.'.$item} eq '0')) {
                   7728:                     $changes{$item} = 1;
                   7729:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
                   7730:                     $changes{$item} = 1;
                   7731:                 }
                   7732:             } elsif ($defaultchecked{$item} eq 'off') {
                   7733:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7734:                     ($env{'form.'.$item} eq '1')) {
                   7735:                     $changes{$item} = 1;
                   7736:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   7737:                     $changes{$item} = 1;
                   7738:                 }
                   7739:             }
                   7740:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   7741:         }
1.139     raeburn  7742:         my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
                   7743:         my $newdefresponder = $env{'form.anonsurvey_threshold'};
                   7744:         $newdefresponder =~ s/\D//g;
                   7745:         if ($newdefresponder eq '' || $newdefresponder < 1) {
                   7746:             $newdefresponder = 1;
                   7747:         }
                   7748:         $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
                   7749:         if ($currdefresponder ne $newdefresponder) {
                   7750:             unless ($currdefresponder eq '' && $newdefresponder == 10) {
                   7751:                 $changes{'anonsurvey_threshold'} = 1;
                   7752:             }
                   7753:         }
1.121     raeburn  7754:     }
                   7755:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7756:                                              $dom);
                   7757:     if ($putresult eq 'ok') {
                   7758:         if (keys(%changes) > 0) {
                   7759:             if ($changes{'canuse_pdfforms'}) {
                   7760:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7761:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   7762:                 my $cachetime = 24*60*60;
                   7763:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   7764:             }
                   7765:             $resulttext = &mt('Changes made:').'<ul>';
                   7766:             foreach my $item (sort(keys(%changes))) {
                   7767:                 if ($item eq 'canuse_pdfforms') {
                   7768:                     if ($env{'form.'.$item} eq '1') {
                   7769:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   7770:                     } else {
                   7771:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   7772:                     }
1.139     raeburn  7773:                 } elsif ($item eq 'anonsurvey_threshold') {
                   7774:                         $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140     raeburn  7775:                 }
1.121     raeburn  7776:             }
                   7777:             $resulttext .= '</ul>';
                   7778:         } else {
                   7779:             $resulttext = &mt('No changes made to course defaults');
                   7780:         }
                   7781:     } else {
                   7782:         $resulttext = '<span class="LC_error">'.
                   7783:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7784:     }
                   7785:     return $resulttext;
                   7786: }
                   7787: 
1.137     raeburn  7788: sub modify_usersessions {
                   7789:     my ($dom,%domconfig) = @_;
1.145     raeburn  7790:     my @hostingtypes = ('version','excludedomain','includedomain');
                   7791:     my @offloadtypes = ('primary','default');
                   7792:     my %types = (
                   7793:                   remote => \@hostingtypes,
                   7794:                   hosted => \@hostingtypes,
                   7795:                   spares => \@offloadtypes,
                   7796:                 );
                   7797:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  7798:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  7799:     my (%by_ip,%by_location,@intdoms);
                   7800:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   7801:     my @locations = sort(keys(%by_location));
1.137     raeburn  7802:     my (%defaultshash,%changes);
                   7803:     foreach my $prefix (@prefixes) {
                   7804:         $defaultshash{'usersessions'}{$prefix} = {};
                   7805:     }
                   7806:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7807:     my $resulttext;
1.138     raeburn  7808:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  7809:     foreach my $prefix (@prefixes) {
1.145     raeburn  7810:         next if ($prefix eq 'spares');
                   7811:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  7812:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   7813:             if ($type eq 'version') {
                   7814:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   7815:                 my $okvalue;
                   7816:                 if ($value ne '') {
                   7817:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   7818:                         $okvalue = $value;
                   7819:                     }
                   7820:                 }
                   7821:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7822:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7823:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   7824:                             if ($inuse == 0) {
                   7825:                                 $changes{$prefix}{$type} = 1;
                   7826:                             } else {
                   7827:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   7828:                                     $changes{$prefix}{$type} = 1;
                   7829:                                 }
                   7830:                                 if ($okvalue ne '') {
                   7831:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7832:                                 } 
                   7833:                             }
                   7834:                         } else {
                   7835:                             if (($inuse == 1) && ($okvalue ne '')) {
                   7836:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7837:                                 $changes{$prefix}{$type} = 1;
                   7838:                             }
                   7839:                         }
                   7840:                     } else {
                   7841:                         if (($inuse == 1) && ($okvalue ne '')) {
                   7842:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7843:                             $changes{$prefix}{$type} = 1;
                   7844:                         }
                   7845:                     }
                   7846:                 } else {
                   7847:                     if (($inuse == 1) && ($okvalue ne '')) {
                   7848:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7849:                         $changes{$prefix}{$type} = 1;
                   7850:                     }
                   7851:                 }
                   7852:             } else {
                   7853:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   7854:                 my @okvals;
                   7855:                 foreach my $val (@vals) {
1.138     raeburn  7856:                     if ($val =~ /:/) {
                   7857:                         my @items = split(/:/,$val);
                   7858:                         foreach my $item (@items) {
                   7859:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   7860:                                 push(@okvals,$item);
                   7861:                             }
                   7862:                         }
                   7863:                     } else {
                   7864:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   7865:                             push(@okvals,$val);
                   7866:                         }
1.137     raeburn  7867:                     }
                   7868:                 }
                   7869:                 @okvals = sort(@okvals);
                   7870:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7871:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7872:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   7873:                             if ($inuse == 0) {
                   7874:                                 $changes{$prefix}{$type} = 1; 
                   7875:                             } else {
                   7876:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7877:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   7878:                                 if (@changed > 0) {
                   7879:                                     $changes{$prefix}{$type} = 1;
                   7880:                                 }
                   7881:                             }
                   7882:                         } else {
                   7883:                             if ($inuse == 1) {
                   7884:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7885:                                 $changes{$prefix}{$type} = 1;
                   7886:                             }
                   7887:                         } 
                   7888:                     } else {
                   7889:                         if ($inuse == 1) {
                   7890:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7891:                             $changes{$prefix}{$type} = 1;
                   7892:                         }
                   7893:                     }
                   7894:                 } else {
                   7895:                     if ($inuse == 1) {
                   7896:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7897:                         $changes{$prefix}{$type} = 1;
                   7898:                     }
                   7899:                 }
                   7900:             }
                   7901:         }
                   7902:     }
1.145     raeburn  7903: 
                   7904:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  7905:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  7906:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   7907:     my $savespares;
                   7908: 
                   7909:     foreach my $lonhost (sort(keys(%servers))) {
                   7910:         my $serverhomeID =
                   7911:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  7912:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  7913:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   7914:         my %spareschg;
                   7915:         foreach my $type (@{$types{'spares'}}) {
                   7916:             my @okspares;
                   7917:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   7918:             foreach my $server (@checked) {
1.152     raeburn  7919:                 if (&Apache::lonnet::hostname($server) ne '') {
                   7920:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   7921:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   7922:                             push(@okspares,$server);
                   7923:                         }
1.145     raeburn  7924:                     }
                   7925:                 }
                   7926:             }
                   7927:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   7928:             my $newspare;
1.152     raeburn  7929:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   7930:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  7931:                     $newspare = $new;
                   7932:                 }
                   7933:             }
1.152     raeburn  7934:             my @spares;
                   7935:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   7936:                 @spares = sort(@okspares,$newspare);
                   7937:             } else {
                   7938:                 @spares = sort(@okspares);
                   7939:             }
                   7940:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  7941:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   7942:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  7943:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  7944:                     if (@diffs > 0) {
                   7945:                         $spareschg{$type} = 1;
                   7946:                     }
                   7947:                 }
                   7948:             }
                   7949:         }
                   7950:         if (keys(%spareschg) > 0) {
                   7951:             $changes{'spares'}{$lonhost} = \%spareschg;
                   7952:         }
                   7953:     }
                   7954: 
                   7955:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7956:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   7957:             if (ref($changes{'spares'}) eq 'HASH') {
                   7958:                 if (keys(%{$changes{'spares'}}) > 0) {
                   7959:                     $savespares = 1;
                   7960:                 }
                   7961:             }
                   7962:         } else {
                   7963:             $savespares = 1;
                   7964:         }
                   7965:     }
                   7966: 
1.147     raeburn  7967:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   7968:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  7969:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7970:                                                  $dom);
                   7971:         if ($putresult eq 'ok') {
                   7972:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   7973:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   7974:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   7975:                 }
                   7976:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   7977:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   7978:                 }
                   7979:             }
                   7980:             my $cachetime = 24*60*60;
                   7981:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147     raeburn  7982:             if (keys(%changes) > 0) {
                   7983:                 my %lt = &usersession_titles();
                   7984:                 $resulttext = &mt('Changes made:').'<ul>';
                   7985:                 foreach my $prefix (@prefixes) {
                   7986:                     if (ref($changes{$prefix}) eq 'HASH') {
                   7987:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   7988:                         if ($prefix eq 'spares') {
                   7989:                             if (ref($changes{$prefix}) eq 'HASH') {
                   7990:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   7991:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  7992:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
                   7993:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147     raeburn  7994:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   7995:                                         foreach my $type (@{$types{$prefix}}) {
                   7996:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   7997:                                                 my $offloadto = &mt('None');
                   7998:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   7999:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   8000:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   8001:                                                     }
1.145     raeburn  8002:                                                 }
1.147     raeburn  8003:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  8004:                                             }
1.137     raeburn  8005:                                         }
                   8006:                                     }
1.147     raeburn  8007:                                     $resulttext .= '</li>';
1.137     raeburn  8008:                                 }
                   8009:                             }
1.147     raeburn  8010:                         } else {
                   8011:                             foreach my $type (@{$types{$prefix}}) {
                   8012:                                 if (defined($changes{$prefix}{$type})) {
                   8013:                                     my $newvalue;
                   8014:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8015:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   8016:                                             if ($type eq 'version') {
                   8017:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   8018:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   8019:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   8020:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   8021:                                                 }
1.145     raeburn  8022:                                             }
                   8023:                                         }
                   8024:                                     }
1.147     raeburn  8025:                                     if ($newvalue eq '') {
                   8026:                                         if ($type eq 'version') {
                   8027:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   8028:                                         } else {
                   8029:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   8030:                                         }
1.145     raeburn  8031:                                     } else {
1.147     raeburn  8032:                                         if ($type eq 'version') {
                   8033:                                             $newvalue .= ' '.&mt('(or later)'); 
                   8034:                                         }
                   8035:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  8036:                                     }
1.137     raeburn  8037:                                 }
                   8038:                             }
                   8039:                         }
1.147     raeburn  8040:                         $resulttext .= '</ul>';
1.137     raeburn  8041:                     }
                   8042:                 }
1.147     raeburn  8043:                 $resulttext .= '</ul>';
                   8044:             } else {
                   8045:                 $resulttext = $nochgmsg;
1.137     raeburn  8046:             }
                   8047:         } else {
                   8048:             $resulttext = '<span class="LC_error">'.
                   8049:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   8050:         }
                   8051:     } else {
1.147     raeburn  8052:         $resulttext = $nochgmsg;
1.137     raeburn  8053:     }
                   8054:     return $resulttext;
                   8055: }
                   8056: 
1.150     raeburn  8057: sub modify_loadbalancing {
                   8058:     my ($dom,%domconfig) = @_;
                   8059:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8060:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8061:     my ($othertitle,$usertypes,$types) =
                   8062:         &Apache::loncommon::sorted_inst_types($dom);
                   8063:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8064:     my @sparestypes = ('primary','default');
                   8065:     my %typetitles = &sparestype_titles();
                   8066:     my $resulttext;
                   8067:     if (keys(%servers) > 1) {
                   8068:         my ($currbalancer,$currtargets,$currrules);
                   8069:         if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8070:             $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
                   8071:             $currtargets = $domconfig{'loadbalancing'}{'targets'};
                   8072:             $currrules = $domconfig{'loadbalancing'}{'rules'};
                   8073:         } else {
                   8074:             ($currbalancer,$currtargets) = 
                   8075:                 &Apache::lonnet::get_lonbalancer_config(\%servers);
                   8076:         }
                   8077:         my ($saveloadbalancing,%defaultshash,%changes);
                   8078:         my ($alltypes,$othertypes,$titles) =
                   8079:             &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   8080:         my %ruletitles = &offloadtype_text();
                   8081:         my $balancer = $env{'form.loadbalancing_lonhost'};
                   8082:         if (!$servers{$balancer}) {
                   8083:             undef($balancer);
                   8084:         }
                   8085:         if ($currbalancer ne $balancer) {
                   8086:             $changes{'lonhost'} = 1;
                   8087:         }
                   8088:         $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
                   8089:         if ($balancer ne '') {
                   8090:             unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8091:                 $saveloadbalancing = 1;
                   8092:             }
                   8093:             foreach my $sparetype (@sparestypes) {
                   8094:                 my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151     raeburn  8095:                 my @offloadto;
1.150     raeburn  8096:                 foreach my $target (@targets) {
                   8097:                     if (($servers{$target}) && ($target ne $balancer)) {
                   8098:                         if ($sparetype eq 'default') {
                   8099:                             if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
                   8100:                                 next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
                   8101:                             }
                   8102:                         }
                   8103:                         unless(grep(/^\Q$target\E$/,@offloadto)) {
                   8104:                             push(@offloadto,$target);
                   8105:                         }
                   8106:                     }
                   8107:                     $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
                   8108:                 }
                   8109:             }
                   8110:         } else {
                   8111:             foreach my $sparetype (@sparestypes) {
                   8112:                 $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
                   8113:             }
                   8114:         }
                   8115:         if (ref($currtargets) eq 'HASH') {
                   8116:             foreach my $sparetype (@sparestypes) {
                   8117:                 if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
                   8118:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
                   8119:                     if (@targetdiffs > 0) {
                   8120:                         $changes{'targets'} = 1;
                   8121:                     }
                   8122:                 } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8123:                     if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   8124:                         $changes{'targets'} = 1;
                   8125:                     }
                   8126:                 }
                   8127:             }
                   8128:         } else {
                   8129:             foreach my $sparetype (@sparestypes) {
                   8130:                 if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8131:                     if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   8132:                         $changes{'targets'} = 1;  
                   8133:                     }
                   8134:                 }
                   8135:             }  
                   8136:         }
                   8137:         my $ishomedom;
                   8138:         if ($balancer ne '') {
                   8139:             if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   8140:                 $ishomedom = 1;
                   8141:             }
                   8142:         }
                   8143:         if (ref($alltypes) eq 'ARRAY') {
                   8144:             foreach my $type (@{$alltypes}) {
                   8145:                 my $rule;
                   8146:                 if ($balancer ne '') {
                   8147:                     unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
                   8148:                          (!$ishomedom)) {
                   8149:                         $rule = $env{'form.loadbalancing_rules_'.$type};
                   8150:                     }
                   8151:                     if ($rule eq 'specific') {
                   8152:                         $rule = $env{'form.loadbalancing_singleserver_'.$type};
                   8153:                     }
                   8154:                 }
                   8155:                 $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
                   8156:                 if (ref($currrules) eq 'HASH') {
                   8157:                     if ($rule ne $currrules->{$type}) {
                   8158:                         $changes{'rules'}{$type} = 1;
                   8159:                     }
                   8160:                 } elsif ($rule ne '') {
                   8161:                     $changes{'rules'}{$type} = 1;
                   8162:                 }
                   8163:             }
                   8164:         }
                   8165:         my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   8166:         if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   8167:             my $putresult = &Apache::lonnet::put_dom('configuration',
                   8168:                                                      \%defaultshash,$dom);
                   8169:             if ($putresult eq 'ok') {
                   8170:                 if (keys(%changes) > 0) {
                   8171:                     if ($changes{'lonhost'}) {
                   8172:                         if ($currbalancer ne '') {
                   8173:                             &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
                   8174:                         }
                   8175:                         if ($balancer eq '') {
                   8176:                             $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>'; 
                   8177:                         } else {
                   8178:                             &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   8179:                             $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
                   8180:                         }
                   8181:                     } else {
                   8182:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   8183:                     }
                   8184:                     if (($changes{'targets'}) && ($balancer ne '')) {
                   8185:                         my %offloadstr;
                   8186:                         foreach my $sparetype (@sparestypes) {
                   8187:                             if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8188:                                 if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   8189:                                     $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
                   8190:                                 }
                   8191:                             }
                   8192:                         }
                   8193:                         if (keys(%offloadstr) == 0) {
                   8194:                             $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
                   8195:                         } else {
                   8196:                             my $showoffload;
                   8197:                             foreach my $sparetype (@sparestypes) {
                   8198:                                 $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   8199:                                 if (defined($offloadstr{$sparetype})) {
                   8200:                                     $showoffload .= $offloadstr{$sparetype};
                   8201:                                 } else {
                   8202:                                     $showoffload .= &mt('None');
                   8203:                                 }
                   8204:                                 $showoffload .= ('&nbsp;'x3);
                   8205:                             }
                   8206:                             $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
                   8207:                         }
                   8208:                     }
                   8209:                     if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
                   8210:                         if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   8211:                             foreach my $type (@{$alltypes}) {
                   8212:                                 if ($changes{'rules'}{$type}) {
                   8213:                                     my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
                   8214:                                     my $balancetext;
                   8215:                                     if ($rule eq '') {
                   8216:                                         $balancetext =  $ruletitles{'default'};
                   8217:                                     } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
                   8218:                                         $balancetext =  $ruletitles{$rule};
                   8219:                                     } else {
                   8220:                                         $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
                   8221:                                     }
                   8222:                                     $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';     
                   8223:                                 }
                   8224:                             }
                   8225:                         }
                   8226:                     }
                   8227:                     if ($resulttext ne '') {
                   8228:                         $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
                   8229:                     } else {
                   8230:                         $resulttext = $nochgmsg;
                   8231:                     }
                   8232:                 } else {
                   8233:                     $resulttext = $nochgmsg;
                   8234:                     if ($balancer ne '') {
                   8235:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   8236:                     }
                   8237:                 }
                   8238:             } else {
                   8239:                 $resulttext = '<span class="LC_error">'.
                   8240:                               &mt('An error occurred: [_1]',$putresult).'</span>';
                   8241:             }
                   8242:         } else {
                   8243:             $resulttext = $nochgmsg;
                   8244:         }
                   8245:     } else {
                   8246:         $resulttext =  &mt('Load Balancing unavailable as this domain only has one server.');
                   8247:     }
                   8248:     return $resulttext;
                   8249: }
                   8250: 
1.48      raeburn  8251: sub recurse_check {
                   8252:     my ($chkcats,$categories,$depth,$name) = @_;
                   8253:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   8254:         my $chg = 0;
                   8255:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   8256:             my $category = $chkcats->[$depth]{$name}[$j];
                   8257:             my $item;
                   8258:             if ($category eq '') {
                   8259:                 $chg ++;
                   8260:             } else {
                   8261:                 my $deeper = $depth + 1;
                   8262:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   8263:                 if ($chg) {
                   8264:                     $categories->{$item} -= $chg;
                   8265:                 }
                   8266:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   8267:                 $deeper --;
                   8268:             }
                   8269:         }
                   8270:     }
                   8271:     return;
                   8272: }
                   8273: 
                   8274: sub recurse_cat_deletes {
                   8275:     my ($item,$coursecategories,$deletions) = @_;
                   8276:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8277:     my $subdepth = $depth + 1;
                   8278:     if (ref($coursecategories) eq 'HASH') {
                   8279:         foreach my $subitem (keys(%{$coursecategories})) {
                   8280:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   8281:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   8282:                 delete($coursecategories->{$subitem});
                   8283:                 $deletions->{$subitem} = 1;
                   8284:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  8285:             }
1.48      raeburn  8286:         }
                   8287:     }
                   8288:     return;
                   8289: }
                   8290: 
1.125     raeburn  8291: sub get_active_dcs {
                   8292:     my ($dom) = @_;
                   8293:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
                   8294:     my %domcoords;
                   8295:     my $numdcs = 0;
                   8296:     my $now = time;
                   8297:     foreach my $server (keys(%dompersonnel)) {
                   8298:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   8299:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   8300:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
                   8301:             if (($end eq '') || ($end == 0) || ($end > $now)) {
                   8302:                 if ($start <= $now) {
                   8303:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
                   8304:                 }
                   8305:             }
                   8306:         }
                   8307:     }
                   8308:     return %domcoords;
                   8309: }
                   8310: 
                   8311: sub active_dc_picker {
                   8312:     my ($dom,$curr_dc) = @_;
                   8313:     my %domcoords = &get_active_dcs($dom); 
                   8314:     my @dcs = sort(keys(%domcoords));
                   8315:     my $numdcs = scalar(@dcs); 
                   8316:     my $datatable;
                   8317:     my $numinrow = 2;
                   8318:     if ($numdcs > 1) {
                   8319:         $datatable = '<table>';
                   8320:         for (my $i=0; $i<@dcs; $i++) {
                   8321:             my $rem = $i%($numinrow);
                   8322:             if ($rem == 0) {
                   8323:                 if ($i > 0) {
                   8324:                     $datatable .= '</tr>';
                   8325:                 }
                   8326:                 $datatable .= '<tr>';
                   8327:             }
                   8328:             my $check = ' ';
                   8329:             if ($curr_dc eq '') {
                   8330:                 if (!$i) { 
                   8331:                     $check = ' checked="checked" ';
                   8332:                 }
                   8333:             } elsif ($dcs[$i] eq $curr_dc) {
                   8334:                 $check = ' checked="checked" ';
                   8335:             }
                   8336:             if ($i == @dcs - 1) {
                   8337:                 my $colsleft = $numinrow - $rem;
                   8338:                 if ($colsleft > 1) {
                   8339:                     $datatable .= '<td colspan="'.$colsleft.'">';
                   8340:                 } else {
                   8341:                     $datatable .= '<td>';
                   8342:                 }
                   8343:             } else {
                   8344:                 $datatable .= '<td>';
                   8345:             }
                   8346:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
                   8347:             $datatable .= '<span class="LC_nobreak"><label>'.
                   8348:                           '<input type="radio" name="autocreate_xmldc"'.
                   8349:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
                   8350:                           &Apache::loncommon::plainname($dcname,$dcdom).
                   8351:                           '</label></span></td>';
                   8352:         }
                   8353:         $datatable .= '</tr></table>';
                   8354:     } elsif (@dcs) {
                   8355:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
                   8356:                       $dcs[0].'" />';
                   8357:     }
                   8358:     return ($numdcs,$datatable);
                   8359: }
                   8360: 
1.137     raeburn  8361: sub usersession_titles {
                   8362:     return &Apache::lonlocal::texthash(
                   8363:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   8364:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  8365:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  8366:                version => 'LON-CAPA version requirement',
1.138     raeburn  8367:                excludedomain => 'Allow all, but exclude specific domains',
                   8368:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  8369:                primary => 'Primary (checked first)',
1.154     raeburn  8370:                default => 'Default',
1.137     raeburn  8371:            );
                   8372: }
                   8373: 
1.152     raeburn  8374: sub id_for_thisdom {
                   8375:     my (%servers) = @_;
                   8376:     my %altids;
                   8377:     foreach my $server (keys(%servers)) {
                   8378:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   8379:         if ($serverhome ne $server) {
                   8380:             $altids{$serverhome} = $server;
                   8381:         }
                   8382:     }
                   8383:     return %altids;
                   8384: }
                   8385: 
1.150     raeburn  8386: sub count_servers {
                   8387:     my ($currbalancer,%servers) = @_;
                   8388:     my (@spares,$numspares);
                   8389:     foreach my $lonhost (sort(keys(%servers))) {
                   8390:         next if ($currbalancer eq $lonhost);
                   8391:         push(@spares,$lonhost);
                   8392:     }
                   8393:     if ($currbalancer) {
                   8394:         $numspares = scalar(@spares);
                   8395:     } else {
                   8396:         $numspares = scalar(@spares) - 1;
                   8397:     }
                   8398:     return ($numspares,@spares);
                   8399: }
                   8400: 
                   8401: sub lonbalance_targets_js {
                   8402:     my ($dom,$types,$servers) = @_;
                   8403:     my $select = &mt('Select');
                   8404:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   8405:     if (ref($servers) eq 'HASH') {
                   8406:         $alltargets = join("','",sort(keys(%{$servers})));
                   8407:         my @homedoms;
                   8408:         foreach my $server (sort(keys(%{$servers}))) {
                   8409:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   8410:                 push(@homedoms,'1');
                   8411:             } else {
                   8412:                 push(@homedoms,'0');
                   8413:             }
                   8414:         }
                   8415:         $allishome = join("','",@homedoms);
                   8416:     }
                   8417:     if (ref($types) eq 'ARRAY') {
                   8418:         if (@{$types} > 0) {
                   8419:             @alltypes = @{$types};
                   8420:         }
                   8421:     }
                   8422:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   8423:     $allinsttypes = join("','",@alltypes);
                   8424:     return <<"END";
                   8425: 
                   8426: <script type="text/javascript">
                   8427: // <![CDATA[
                   8428: 
                   8429: function toggleTargets() {
                   8430:     var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
                   8431:     if (balancer == '') {
                   8432:         hideSpares();
                   8433:     } else {
                   8434:         var homedoms = new Array('$allishome');
                   8435:         var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
                   8436:         showSpares(balancer,ishomedom);
                   8437:     }
                   8438:     return;
                   8439: }
                   8440: 
                   8441: function showSpares(balancer,ishomedom) {
                   8442:     var alltargets = new Array('$alltargets');
                   8443:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  8444:     var offloadtypes = new Array('primary','default');
                   8445: 
1.150     raeburn  8446:     document.getElementById('loadbalancing_targets').style.display='block';
                   8447:     document.getElementById('loadbalancing_disabled').style.display='none';
1.152     raeburn  8448:  
1.151     raeburn  8449:     for (var i=0; i<offloadtypes.length; i++) {
                   8450:         var count = 0;
                   8451:         for (var j=0; j<alltargets.length; j++) {
                   8452:             if (alltargets[j] != balancer) {
                   8453:                 document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
                   8454:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
                   8455:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
                   8456:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   8457:                 count ++;
                   8458:             }
1.150     raeburn  8459:         }
                   8460:     }
1.151     raeburn  8461:     for (var k=0; k<insttypes.length; k++) {
                   8462:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  8463:             if (ishomedom == 1) {
1.151     raeburn  8464:                 document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
                   8465:                 document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150     raeburn  8466:             } else {
1.151     raeburn  8467:                 document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
                   8468:                 document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150     raeburn  8469: 
                   8470:             }
                   8471:         } else {
1.151     raeburn  8472:             document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
                   8473:             document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150     raeburn  8474:         }
1.151     raeburn  8475:         if ((insttypes[k] != '_LC_external') && 
                   8476:             ((insttypes[k] != '_LC_internetdom') ||
                   8477:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
                   8478:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
                   8479:             for (var m=0; m<alltargets.length; m++) {
                   8480:                 var idx = m+1;
                   8481:                 if (alltargets[m] != balancer) {
                   8482:                     document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  8483:                 }
                   8484:             }
                   8485:         }
                   8486:     }
                   8487:     return;
                   8488: }
                   8489: 
                   8490: function hideSpares() {
                   8491:     var alltargets = new Array('$alltargets');
                   8492:     var insttypes = new Array('$allinsttypes');
                   8493:     var offloadtypes = new Array('primary','default');
                   8494: 
                   8495:     document.getElementById('loadbalancing_targets').style.display='none';
                   8496:     document.getElementById('loadbalancing_disabled').style.display='block';
                   8497: 
                   8498:     var total = alltargets.length - 1;
                   8499:     for (var i=0; i<offloadtypes; i++) {
                   8500:         for (var j=0; j<total; j++) {
                   8501:            document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
                   8502:            document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
                   8503:            document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  8504:         }
1.150     raeburn  8505:     }
                   8506:     for (var k=0; k<insttypes.length; k++) {
1.151     raeburn  8507:         document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
                   8508:         document.getElementById('balancerule_'+insttypes[k]).style.display='none';
                   8509:         if (insttypes[k] != '_LC_external') {
                   8510:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
                   8511:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  8512:         }
                   8513:     }
                   8514:     return;
                   8515: }
                   8516: 
                   8517: function checkOffloads(item,type) {
                   8518:     var alltargets = new Array('$alltargets');
                   8519:     var offloadtypes = new Array('primary','default');
                   8520:     if (item.checked) {
                   8521:         var total = alltargets.length - 1;
                   8522:         var other;
                   8523:         if (type == offloadtypes[0]) {
1.151     raeburn  8524:             other = offloadtypes[1];
1.150     raeburn  8525:         } else {
1.151     raeburn  8526:             other = offloadtypes[0];
1.150     raeburn  8527:         }
                   8528:         for (var i=0; i<total; i++) {
                   8529:             var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
                   8530:             if (server == item.value) {
                   8531:                 if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
                   8532:                     document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
                   8533:                 }
                   8534:             }
                   8535:         }
                   8536:     }
                   8537:     return;
                   8538: }
                   8539: 
                   8540: function singleServerToggle(type) {
                   8541:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
                   8542:     if (offloadtoSelIdx == 0) {
                   8543:         document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
                   8544:         document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
                   8545: 
                   8546:     } else {
                   8547:         document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
                   8548:         document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
                   8549:     }
                   8550:     return;
                   8551: }
                   8552: 
                   8553: function balanceruleChange(formname,type) {
                   8554:     if (type == '_LC_external') {
                   8555:         return; 
                   8556:     }
                   8557:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
                   8558:     for (var i=0; i<typesRules.length; i++) {
                   8559:         if (formname.elements[typesRules[i]].checked) {
                   8560:             if (formname.elements[typesRules[i]].value != 'specific') {
                   8561:                 document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
                   8562:                 document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
                   8563:             } else {
                   8564:                 document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
                   8565:             }
                   8566:         }
                   8567:     }
                   8568:     return;
                   8569: }
                   8570: 
1.152     raeburn  8571: // ]]>
                   8572: </script>
                   8573: 
                   8574: END
                   8575: }
                   8576: 
                   8577: sub new_spares_js {
                   8578:     my @sparestypes = ('primary','default');
                   8579:     my $types = join("','",@sparestypes);
                   8580:     my $select = &mt('Select');
                   8581:     return <<"END";
                   8582: 
                   8583: <script type="text/javascript">
                   8584: // <![CDATA[
                   8585: 
                   8586: function updateNewSpares(formname,lonhost) {
                   8587:     var types = new Array('$types');
                   8588:     var include = new Array();
                   8589:     var exclude = new Array();
                   8590:     for (var i=0; i<types.length; i++) {
                   8591:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   8592:         for (var j=0; j<spareboxes.length; j++) {
                   8593:             if (formname.elements[spareboxes[j]].checked) {
                   8594:                 exclude.push(formname.elements[spareboxes[j]].value);
                   8595:             } else {
                   8596:                 include.push(formname.elements[spareboxes[j]].value);
                   8597:             }
                   8598:         }
                   8599:     }
                   8600:     for (var i=0; i<types.length; i++) {
                   8601:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   8602:         var selIdx = newSpare.selectedIndex;
                   8603:         var currnew = newSpare.options[selIdx].value;
                   8604:         var okSpares = new Array();
                   8605:         for (var j=0; j<newSpare.options.length; j++) {
                   8606:             var possible = newSpare.options[j].value;
                   8607:             if (possible != '') {
                   8608:                 if (exclude.indexOf(possible) == -1) {
                   8609:                     okSpares.push(possible);
                   8610:                 } else {
                   8611:                     if (currnew == possible) {
                   8612:                         selIdx = 0;
                   8613:                     }
                   8614:                 }
                   8615:             }
                   8616:         }
                   8617:         for (var k=0; k<include.length; k++) {
                   8618:             if (okSpares.indexOf(include[k]) == -1) {
                   8619:                 okSpares.push(include[k]);
                   8620:             }
                   8621:         }
                   8622:         okSpares.sort();
                   8623:         newSpare.options.length = 0;
                   8624:         if (selIdx == 0) {
                   8625:             newSpare.options[0] = new Option("$select","",true,true);
                   8626:         } else {
                   8627:             newSpare.options[0] = new Option("$select","",false,false);
                   8628:         }
                   8629:         for (var m=0; m<okSpares.length; m++) {
                   8630:             var idx = m+1;
                   8631:             var selThis = 0;
                   8632:             if (selIdx != 0) {
                   8633:                 if (okSpares[m] == currnew) {
                   8634:                     selThis = 1;
                   8635:                 }
                   8636:             }
                   8637:             if (selThis == 1) {
                   8638:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   8639:             } else {
                   8640:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   8641:             }
                   8642:         }
                   8643:     }
                   8644:     return;
                   8645: }
                   8646: 
                   8647: function checkNewSpares(lonhost,type) {
                   8648:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   8649:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   8650:     if (chosen != '') { 
                   8651:         var othertype;
                   8652:         var othernewSpare;
                   8653:         if (type == 'primary') {
                   8654:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   8655:         }
                   8656:         if (type == 'default') {
                   8657:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   8658:         }
                   8659:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   8660:             othernewSpare.selectedIndex = 0;
                   8661:         }
                   8662:     }
                   8663:     return;
                   8664: }
                   8665: 
                   8666: // ]]>
                   8667: </script>
                   8668: 
                   8669: END
                   8670: 
                   8671: }
                   8672: 
                   8673: sub common_domprefs_js {
                   8674:     return <<"END";
                   8675: 
                   8676: <script type="text/javascript">
                   8677: // <![CDATA[
                   8678: 
1.150     raeburn  8679: function getIndicesByName(formname,item) {
1.152     raeburn  8680:     var group = new Array();
1.150     raeburn  8681:     for (var i=0;i<formname.elements.length;i++) {
                   8682:         if (formname.elements[i].name == item) {
1.152     raeburn  8683:             group.push(formname.elements[i].id);
1.150     raeburn  8684:         }
                   8685:     }
1.152     raeburn  8686:     return group;
1.150     raeburn  8687: }
                   8688: 
                   8689: // ]]>
                   8690: </script>
                   8691: 
                   8692: END
1.152     raeburn  8693: 
1.150     raeburn  8694: }
                   8695: 
1.165     raeburn  8696: sub recaptcha_js {
                   8697:     my %lt = &captcha_phrases();
                   8698:     return <<"END";
                   8699: 
                   8700: <script type="text/javascript">
                   8701: // <![CDATA[
                   8702: 
                   8703: function updateCaptcha(caller,context) {
                   8704:     var privitem;
                   8705:     var pubitem;
                   8706:     var privtext;
                   8707:     var pubtext;
                   8708:     if (document.getElementById(context+'_recaptchapub')) {
                   8709:         pubitem = document.getElementById(context+'_recaptchapub');
                   8710:     } else {
                   8711:         return;
                   8712:     }
                   8713:     if (document.getElementById(context+'_recaptchapriv')) {
                   8714:         privitem = document.getElementById(context+'_recaptchapriv');
                   8715:     } else {
                   8716:         return;
                   8717:     }
                   8718:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   8719:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   8720:     } else {
                   8721:         return;
                   8722:     }
                   8723:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   8724:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   8725:     } else {
                   8726:         return;
                   8727:     }
                   8728:     if (caller.checked) {
                   8729:         if (caller.value == 'recaptcha') {
                   8730:             pubitem.type = 'text';
                   8731:             privitem.type = 'text';
                   8732:             pubitem.size = '40';
                   8733:             privitem.size = '40';
                   8734:             pubtext.innerHTML = "$lt{'pub'}";
                   8735:             privtext.innerHTML = "$lt{'priv'}";
                   8736:         } else {
                   8737:             pubitem.type = 'hidden';
                   8738:             privitem.type = 'hidden';
                   8739:             pubtext.innerHTML = '';
                   8740:             privtext.innerHTML = '';
                   8741:         }
                   8742:     }
                   8743:     return;
                   8744: }
                   8745: 
                   8746: // ]]>
                   8747: </script>
                   8748: 
                   8749: END
                   8750: 
                   8751: }
                   8752: 
                   8753: sub captcha_phrases {
                   8754:     return &Apache::lonlocal::texthash (
                   8755:                  priv => 'Private key',
                   8756:                  pub  => 'Public key',
                   8757:                  original  => 'original (CAPTCHA)',
                   8758:                  recaptcha => 'successor (ReCAPTCHA)',
                   8759:                  notused   => 'unused',
                   8760:     );
                   8761: }
                   8762: 
1.3       raeburn  8763: 1;

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